]> git.ipfire.org Git - thirdparty/systemd.git/blame - src/journal/compress.h
man: bring resolved.conf up-to-date
[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
24#include <inttypes.h>
25#include <stdbool.h>
355b59e2 26#include <unistd.h>
e4e61fdb 27
d89c8fdf 28#include "journal-def.h"
e4e61fdb 29
d89c8fdf
ZJS
30const char* object_compressed_to_string(int compression);
31int object_compressed_from_string(const char *compression);
e4e61fdb 32
fa1c4b51
ZJS
33int compress_blob_xz(const void *src, uint64_t src_size, void *dst, size_t *dst_size);
34int compress_blob_lz4(const void *src, uint64_t src_size, void *dst, size_t *dst_size);
355b59e2 35
fa1c4b51 36static inline int compress_blob(const void *src, uint64_t src_size, void *dst, size_t *dst_size) {
d89c8fdf
ZJS
37 int r;
38#ifdef HAVE_LZ4
39 r = compress_blob_lz4(src, src_size, dst, dst_size);
40 if (r == 0)
41 return OBJECT_COMPRESSED_LZ4;
42#else
43 r = compress_blob_xz(src, src_size, dst, dst_size);
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
72int compress_stream_xz(int fdf, int fdt, off_t max_bytes);
73int compress_stream_lz4(int fdf, int fdt, off_t max_bytes);
74
75int decompress_stream_xz(int fdf, int fdt, off_t max_size);
76int decompress_stream_lz4(int fdf, int fdt, off_t max_size);
77
78#ifdef HAVE_LZ4
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
86int decompress_stream(const char *filename, int fdf, int fdt, off_t max_bytes);