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