]> git.proxmox.com Git - systemd.git/blame - src/journal/compress.h
Merge tag 'upstream/229'
[systemd.git] / src / journal / compress.h
CommitLineData
663996b3
MS
1#pragma once
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
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
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
16 Lesser General Public License for more details.
17
18 You should have received a copy of the GNU Lesser General Public License
19 along with systemd; If not, see <http://www.gnu.org/licenses/>.
20***/
21
e842803a 22#include <unistd.h>
663996b3 23
5eef597e 24#include "journal-def.h"
663996b3 25
5eef597e
MP
26const char* object_compressed_to_string(int compression);
27int object_compressed_from_string(const char *compression);
663996b3 28
4c89c718
MP
29int compress_blob_xz(const void *src, uint64_t src_size,
30 void *dst, size_t dst_alloc_size, size_t *dst_size);
31int compress_blob_lz4(const void *src, uint64_t src_size,
32 void *dst, size_t dst_alloc_size, size_t *dst_size);
e842803a 33
4c89c718
MP
34static inline int compress_blob(const void *src, uint64_t src_size,
35 void *dst, size_t dst_alloc_size, size_t *dst_size) {
5eef597e
MP
36 int r;
37#ifdef HAVE_LZ4
4c89c718 38 r = compress_blob_lz4(src, src_size, dst, dst_alloc_size, dst_size);
5eef597e
MP
39 if (r == 0)
40 return OBJECT_COMPRESSED_LZ4;
41#else
4c89c718 42 r = compress_blob_xz(src, src_size, dst, dst_alloc_size, dst_size);
5eef597e
MP
43 if (r == 0)
44 return OBJECT_COMPRESSED_XZ;
45#endif
46 return r;
47}
48
49int decompress_blob_xz(const void *src, uint64_t src_size,
50 void **dst, size_t *dst_alloc_size, size_t* dst_size, size_t dst_max);
51int decompress_blob_lz4(const void *src, uint64_t src_size,
52 void **dst, size_t *dst_alloc_size, size_t* dst_size, size_t dst_max);
53int decompress_blob(int compression,
54 const void *src, uint64_t src_size,
55 void **dst, size_t *dst_alloc_size, size_t* dst_size, size_t dst_max);
56
57int decompress_startswith_xz(const void *src, uint64_t src_size,
58 void **buffer, size_t *buffer_size,
59 const void *prefix, size_t prefix_len,
60 uint8_t extra);
61int decompress_startswith_lz4(const void *src, uint64_t src_size,
62 void **buffer, size_t *buffer_size,
63 const void *prefix, size_t prefix_len,
64 uint8_t extra);
65int decompress_startswith(int compression,
66 const void *src, uint64_t src_size,
67 void **buffer, size_t *buffer_size,
68 const void *prefix, size_t prefix_len,
69 uint8_t extra);
70
6300502b
MP
71int compress_stream_xz(int fdf, int fdt, uint64_t max_bytes);
72int compress_stream_lz4(int fdf, int fdt, uint64_t max_bytes);
5eef597e 73
6300502b
MP
74int decompress_stream_xz(int fdf, int fdt, uint64_t max_size);
75int decompress_stream_lz4(int fdf, int fdt, uint64_t max_size);
5eef597e
MP
76
77#ifdef HAVE_LZ4
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
6300502b 85int decompress_stream(const char *filename, int fdf, int fdt, uint64_t max_bytes);