]> git.ipfire.org Git - thirdparty/systemd.git/blame - src/journal/compress.h
Merge pull request #1226 from poettering/coccinelle-fixes3
[thirdparty/systemd.git] / src / journal / compress.h
CommitLineData
e4e61fdb
LP
1/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
2
c2f1db8f 3#pragma once
e4e61fdb
LP
4
5/***
6 This file is part of systemd.
7
8 Copyright 2011 Lennart Poettering
9
10 systemd is free software; you can redistribute it and/or modify it
5430f7f2
LP
11 under the terms of the GNU Lesser General Public License as published by
12 the Free Software Foundation; either version 2.1 of the License, or
e4e61fdb
LP
13 (at your option) any later version.
14
15 systemd is distributed in the hope that it will be useful, but
16 WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
5430f7f2 18 Lesser General Public License for more details.
e4e61fdb 19
5430f7f2 20 You should have received a copy of the GNU Lesser General Public License
e4e61fdb
LP
21 along with systemd; If not, see <http://www.gnu.org/licenses/>.
22***/
23
355b59e2 24#include <unistd.h>
e4e61fdb 25
d89c8fdf 26#include "journal-def.h"
e4e61fdb 27
d89c8fdf
ZJS
28const char* object_compressed_to_string(int compression);
29int object_compressed_from_string(const char *compression);
e4e61fdb 30
fa1c4b51
ZJS
31int compress_blob_xz(const void *src, uint64_t src_size, void *dst, size_t *dst_size);
32int compress_blob_lz4(const void *src, uint64_t src_size, void *dst, size_t *dst_size);
355b59e2 33
fa1c4b51 34static inline int compress_blob(const void *src, uint64_t src_size, void *dst, size_t *dst_size) {
d89c8fdf
ZJS
35 int r;
36#ifdef HAVE_LZ4
37 r = compress_blob_lz4(src, src_size, dst, dst_size);
38 if (r == 0)
39 return OBJECT_COMPRESSED_LZ4;
40#else
41 r = compress_blob_xz(src, src_size, dst, dst_size);
42 if (r == 0)
43 return OBJECT_COMPRESSED_XZ;
44#endif
45 return r;
46}
47
48int decompress_blob_xz(const void *src, uint64_t src_size,
fa1c4b51 49 void **dst, size_t *dst_alloc_size, size_t* dst_size, size_t dst_max);
d89c8fdf 50int decompress_blob_lz4(const void *src, uint64_t src_size,
fa1c4b51 51 void **dst, size_t *dst_alloc_size, size_t* dst_size, size_t dst_max);
d89c8fdf
ZJS
52int decompress_blob(int compression,
53 const void *src, uint64_t src_size,
fa1c4b51 54 void **dst, size_t *dst_alloc_size, size_t* dst_size, size_t dst_max);
d89c8fdf
ZJS
55
56int decompress_startswith_xz(const void *src, uint64_t src_size,
fa1c4b51
ZJS
57 void **buffer, size_t *buffer_size,
58 const void *prefix, size_t prefix_len,
d89c8fdf
ZJS
59 uint8_t extra);
60int decompress_startswith_lz4(const void *src, uint64_t src_size,
fa1c4b51
ZJS
61 void **buffer, size_t *buffer_size,
62 const void *prefix, size_t prefix_len,
d89c8fdf
ZJS
63 uint8_t extra);
64int decompress_startswith(int compression,
65 const void *src, uint64_t src_size,
fa1c4b51
ZJS
66 void **buffer, size_t *buffer_size,
67 const void *prefix, size_t prefix_len,
d89c8fdf
ZJS
68 uint8_t extra);
69
70int compress_stream_xz(int fdf, int fdt, off_t max_bytes);
71int compress_stream_lz4(int fdf, int fdt, off_t max_bytes);
72
73int decompress_stream_xz(int fdf, int fdt, off_t max_size);
74int decompress_stream_lz4(int fdf, int fdt, off_t max_size);
75
76#ifdef HAVE_LZ4
77# define compress_stream compress_stream_lz4
78# define COMPRESSED_EXT ".lz4"
79#else
80# define compress_stream compress_stream_xz
81# define COMPRESSED_EXT ".xz"
82#endif
83
84int decompress_stream(const char *filename, int fdf, int fdt, off_t max_bytes);