chiark / gitweb /
136dda6d390c3411701e92d5bd8aecc450e86134
[elogind.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 <inttypes.h>
25 #include <stdbool.h>
26 #include <unistd.h>
27
28 #include "journal-def.h"
29
30 const char* object_compressed_to_string(int compression);
31 int object_compressed_from_string(const char *compression);
32
33 int compress_blob_xz(const void *src, uint64_t src_size, void *dst, size_t *dst_size);
34 int compress_blob_lz4(const void *src, uint64_t src_size, void *dst, size_t *dst_size);
35
36 static inline int compress_blob(const void *src, uint64_t src_size, void *dst, size_t *dst_size) {
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
50 int decompress_blob_xz(const void *src, uint64_t src_size,
51                        void **dst, size_t *dst_alloc_size, size_t* dst_size, size_t dst_max);
52 int decompress_blob_lz4(const void *src, uint64_t src_size,
53                         void **dst, size_t *dst_alloc_size, size_t* dst_size, size_t dst_max);
54 int decompress_blob(int compression,
55                     const void *src, uint64_t src_size,
56                     void **dst, size_t *dst_alloc_size, size_t* dst_size, size_t dst_max);
57
58 int decompress_startswith_xz(const void *src, uint64_t src_size,
59                              void **buffer, size_t *buffer_size,
60                              const void *prefix, size_t prefix_len,
61                              uint8_t extra);
62 int decompress_startswith_lz4(const void *src, uint64_t src_size,
63                               void **buffer, size_t *buffer_size,
64                               const void *prefix, size_t prefix_len,
65                               uint8_t extra);
66 int decompress_startswith(int compression,
67                           const void *src, uint64_t src_size,
68                           void **buffer, size_t *buffer_size,
69                           const void *prefix, size_t prefix_len,
70                           uint8_t extra);
71
72 int compress_stream_xz(int fdf, int fdt, off_t max_bytes);
73 int compress_stream_lz4(int fdf, int fdt, off_t max_bytes);
74
75 int decompress_stream_xz(int fdf, int fdt, off_t max_size);
76 int 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
86 int decompress_stream(const char *filename, int fdf, int fdt, off_t max_bytes);