]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/journal/compress.h
Merge pull request #2138 from stefwalter/journal-combine
[thirdparty/systemd.git] / src / journal / compress.h
1 /*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
2
3 #pragma once
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
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
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
18 Lesser General Public License for more details.
19
20 You should have received a copy of the GNU Lesser General Public License
21 along with systemd; If not, see <http://www.gnu.org/licenses/>.
22 ***/
23
24 #include <unistd.h>
25
26 #include "journal-def.h"
27
28 const char* object_compressed_to_string(int compression);
29 int object_compressed_from_string(const char *compression);
30
31 int compress_blob_xz(const void *src, uint64_t src_size,
32 void *dst, size_t dst_alloc_size, size_t *dst_size);
33 int compress_blob_lz4(const void *src, uint64_t src_size,
34 void *dst, size_t dst_alloc_size, size_t *dst_size);
35
36 static inline int compress_blob(const void *src, uint64_t src_size,
37 void *dst, size_t dst_alloc_size, size_t *dst_size) {
38 int r;
39 #ifdef HAVE_LZ4
40 r = compress_blob_lz4(src, src_size, dst, dst_alloc_size, dst_size);
41 if (r == 0)
42 return OBJECT_COMPRESSED_LZ4;
43 #else
44 r = compress_blob_xz(src, src_size, dst, dst_alloc_size, dst_size);
45 if (r == 0)
46 return OBJECT_COMPRESSED_XZ;
47 #endif
48 return r;
49 }
50
51 int decompress_blob_xz(const void *src, uint64_t src_size,
52 void **dst, size_t *dst_alloc_size, size_t* dst_size, size_t dst_max);
53 int decompress_blob_lz4(const void *src, uint64_t src_size,
54 void **dst, size_t *dst_alloc_size, size_t* dst_size, size_t dst_max);
55 int decompress_blob(int compression,
56 const void *src, uint64_t src_size,
57 void **dst, size_t *dst_alloc_size, size_t* dst_size, size_t dst_max);
58
59 int decompress_startswith_xz(const void *src, uint64_t src_size,
60 void **buffer, size_t *buffer_size,
61 const void *prefix, size_t prefix_len,
62 uint8_t extra);
63 int decompress_startswith_lz4(const void *src, uint64_t src_size,
64 void **buffer, size_t *buffer_size,
65 const void *prefix, size_t prefix_len,
66 uint8_t extra);
67 int decompress_startswith(int compression,
68 const void *src, uint64_t src_size,
69 void **buffer, size_t *buffer_size,
70 const void *prefix, size_t prefix_len,
71 uint8_t extra);
72
73 int compress_stream_xz(int fdf, int fdt, uint64_t max_bytes);
74 int compress_stream_lz4(int fdf, int fdt, uint64_t max_bytes);
75
76 int decompress_stream_xz(int fdf, int fdt, uint64_t max_size);
77 int decompress_stream_lz4(int fdf, int fdt, uint64_t max_size);
78
79 #ifdef HAVE_LZ4
80 # define compress_stream compress_stream_lz4
81 # define COMPRESSED_EXT ".lz4"
82 #else
83 # define compress_stream compress_stream_xz
84 # define COMPRESSED_EXT ".xz"
85 #endif
86
87 int decompress_stream(const char *filename, int fdf, int fdt, uint64_t max_bytes);