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