libsquashfs: include/sqfs/compressor.h Source File

libsquashfs 1.3.2 A new set of tools and libraries for working with SquashFS images

Loading...
Searching...
No Matches
compressor.h
Go to the documentation of this file.
1/* SPDX-License-Identifier: LGPL-3.0-or-later */
2/*
3 * compressor.h - This file is part of libsquashfs
4 *
5 * Copyright (C) 2019 David Oberhollenzer <goliath@infraroot.at>
6 *
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU Lesser General Public License as published
9 * by the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
19 */
20#ifndef SQFS_COMPRESSOR_H
21#define SQFS_COMPRESSOR_H
22
23#include "sqfs/predef.h"
24#include "sqfs/super.h"
25
31
40 struct sqfs_compressor_t {
41 sqfs_object_t base;
42
49 void (*get_configuration)(const sqfs_compressor_t *cmp,
50 sqfs_compressor_config_t *cfg);
51
66 int (*write_options)(sqfs_compressor_t *cmp, sqfs_file_t *file);
67
76 int (*read_options)(sqfs_compressor_t *cmp, sqfs_file_t *file);
77
92 sqfs_s32 (*do_block)(sqfs_compressor_t *cmp, const sqfs_u8 *in,
93 sqfs_u32 size, sqfs_u8 *out, sqfs_u32 outsize);
94};
95
106 struct sqfs_compressor_config_t {
110 sqfs_u16 id;
111
115 sqfs_u16 flags;
116
120 sqfs_u32 block_size;
121
127 sqfs_u32 level;
128
132 union {
136 struct {
142 sqfs_u16 window_size;
143
144 sqfs_u8 padd0[14];
145 } gzip;
146
150 struct {
157 sqfs_u16 algorithm;
158
159 sqfs_u8 padd0[14];
160 } lzo;
161
165 struct {
175 sqfs_u32 dict_size;
176
187 sqfs_u8 lc;
188
199 sqfs_u8 lp;
200
213 sqfs_u8 pb;
214
215 sqfs_u8 padd0[9];
216 } xz, lzma;
217
218 sqfs_u64 padd0[2];
219 } opt;
220};
221
227 typedef enum {
231 SQFS_COMP_FLAG_LZ4_HC = 0x0001,
232 SQFS_COMP_FLAG_LZ4_ALL = 0x0001,
233
242 SQFS_COMP_FLAG_LZMA_EXTREME = 0x0001,
243 SQFS_COMP_FLAG_LZMA_ALL = 0x0001,
244
248 SQFS_COMP_FLAG_XZ_X86 = 0x0001,
249
253 SQFS_COMP_FLAG_XZ_POWERPC = 0x0002,
254
258 SQFS_COMP_FLAG_XZ_IA64 = 0x0004,
259
263 SQFS_COMP_FLAG_XZ_ARM = 0x0008,
264
268 SQFS_COMP_FLAG_XZ_ARMTHUMB = 0x0010,
269
273 SQFS_COMP_FLAG_XZ_SPARC = 0x0020,
274
278 SQFS_COMP_FLAG_XZ_EXTREME = 0x0100,
279
280 SQFS_COMP_FLAG_XZ_ALL = 0x013F,
281
285 SQFS_COMP_FLAG_GZIP_DEFAULT = 0x0001,
286
290 SQFS_COMP_FLAG_GZIP_FILTERED = 0x0002,
291
295 SQFS_COMP_FLAG_GZIP_HUFFMAN = 0x0004,
296
300 SQFS_COMP_FLAG_GZIP_RLE = 0x0008,
301
305 SQFS_COMP_FLAG_GZIP_FIXED = 0x0010,
306 SQFS_COMP_FLAG_GZIP_ALL = 0x001F,
307
312 SQFS_COMP_FLAG_UNCOMPRESS = 0x8000,
313 SQFS_COMP_FLAG_GENERIC_ALL = 0x8000,
314} SQFS_COMP_FLAG;
315
321 typedef enum {
322 SQFS_LZO1X_1 = 0,
323 SQFS_LZO1X_1_11 = 1,
324 SQFS_LZO1X_1_12 = 2,
325 SQFS_LZO1X_1_15 = 3,
326 SQFS_LZO1X_999 = 4,
327} SQFS_LZO_ALGORITHM;
328
329#define SQFS_GZIP_DEFAULT_LEVEL (9)
330#define SQFS_GZIP_DEFAULT_WINDOW (15)
331
332#define SQFS_LZO_DEFAULT_ALG SQFS_LZO1X_999
333#define SQFS_LZO_DEFAULT_LEVEL (8)
334
335#define SQFS_ZSTD_DEFAULT_LEVEL (15)
336
337#define SQFS_GZIP_MIN_LEVEL (1)
338#define SQFS_GZIP_MAX_LEVEL (9)
339
340#define SQFS_LZO_MIN_LEVEL (0)
341#define SQFS_LZO_MAX_LEVEL (9)
342
343#define SQFS_ZSTD_MIN_LEVEL (1)
344#define SQFS_ZSTD_MAX_LEVEL (22)
345
346#define SQFS_GZIP_MIN_WINDOW (8)
347#define SQFS_GZIP_MAX_WINDOW (15)
348
349#define SQFS_XZ_MIN_LEVEL (0)
350#define SQFS_XZ_MAX_LEVEL (9)
351#define SQFS_XZ_DEFAULT_LEVEL (6)
352
353#define SQFS_XZ_MIN_LC 0
354#define SQFS_XZ_MAX_LC 4
355#define SQFS_XZ_DEFAULT_LC 3
356
357#define SQFS_XZ_MIN_LP 0
358#define SQFS_XZ_MAX_LP 4
359#define SQFS_XZ_DEFAULT_LP 0
360
361#define SQFS_XZ_MIN_PB 0
362#define SQFS_XZ_MAX_PB 4
363#define SQFS_XZ_DEFAULT_PB 2
364
365#define SQFS_LZMA_MIN_LEVEL (0)
366#define SQFS_LZMA_MAX_LEVEL (9)
367#define SQFS_LZMA_DEFAULT_LEVEL (5)
368
369#define SQFS_LZMA_MIN_LC 0
370#define SQFS_LZMA_MAX_LC 4
371#define SQFS_LZMA_DEFAULT_LC 3
372
373#define SQFS_LZMA_MIN_LP 0
374#define SQFS_LZMA_MAX_LP 4
375#define SQFS_LZMA_DEFAULT_LP 0
376
377#define SQFS_LZMA_MIN_PB 0
378#define SQFS_LZMA_MAX_PB 4
379#define SQFS_LZMA_DEFAULT_PB 2
380
381#define SQFS_LZMA_MIN_DICT_SIZE SQFS_META_BLOCK_SIZE
382#define SQFS_LZMA_MAX_DICT_SIZE SQFS_MAX_BLOCK_SIZE
383
384#define SQFS_XZ_MIN_DICT_SIZE SQFS_META_BLOCK_SIZE
385#define SQFS_XZ_MAX_DICT_SIZE SQFS_MAX_BLOCK_SIZE
386
387#ifdef __cplusplus
388extern "C" {
389#endif
390
405SQFS_API int sqfs_compressor_config_init(sqfs_compressor_config_t *cfg,
406 SQFS_COMPRESSOR id,
407 size_t block_size, sqfs_u16 flags);
408
423SQFS_API int sqfs_compressor_create(const sqfs_compressor_config_t *cfg,
424 sqfs_compressor_t **out);
425
434SQFS_API const char *sqfs_compressor_name_from_id(SQFS_COMPRESSOR id);
435
444SQFS_API int sqfs_compressor_id_from_name(const char *name);
445
446#ifdef __cplusplus
447}
448#endif
449
450#endif /* SQFS_COMPRESSOR_H */
SQFS_COMP_FLAG
SQFS_COMP_FLAG
Flags for configuring the compressor.
Definition compressor.h:227
SQFS_COMP_FLAG_XZ_SPARC
@ SQFS_COMP_FLAG_XZ_SPARC
For XZ, set this to select the Sparc BCJ filter.
Definition compressor.h:273
SQFS_COMP_FLAG_UNCOMPRESS
@ SQFS_COMP_FLAG_UNCOMPRESS
Set this if the compressor should actually extract instead of compress data.
Definition compressor.h:312
SQFS_COMP_FLAG_LZMA_EXTREME
@ SQFS_COMP_FLAG_LZMA_EXTREME
Tell the LZMAv1 compressor to try the "extreme" option.
Definition compressor.h:242
SQFS_COMP_FLAG_GZIP_HUFFMAN
@ SQFS_COMP_FLAG_GZIP_HUFFMAN
For zlib deflate, set this to try the huffman only strategy.
Definition compressor.h:295
SQFS_COMP_FLAG_GZIP_DEFAULT
@ SQFS_COMP_FLAG_GZIP_DEFAULT
For zlib deflate, set this to try the default strategy.
Definition compressor.h:285
SQFS_COMP_FLAG_GZIP_FILTERED
@ SQFS_COMP_FLAG_GZIP_FILTERED
For zlib deflate, set this to try the "filtered" strategy.
Definition compressor.h:290
SQFS_COMP_FLAG_XZ_POWERPC
@ SQFS_COMP_FLAG_XZ_POWERPC
For XZ, set this to select the PowerPC BCJ filter.
Definition compressor.h:253
SQFS_COMP_FLAG_XZ_ARM
@ SQFS_COMP_FLAG_XZ_ARM
For XZ, set this to select the ARM BCJ filter.
Definition compressor.h:263
SQFS_COMP_FLAG_GZIP_RLE
@ SQFS_COMP_FLAG_GZIP_RLE
For zlib deflate, set this to try the RLE strategy.
Definition compressor.h:300
SQFS_COMP_FLAG_XZ_IA64
@ SQFS_COMP_FLAG_XZ_IA64
For XZ, set this to select the Itanium BCJ filter.
Definition compressor.h:258
SQFS_COMP_FLAG_XZ_X86
@ SQFS_COMP_FLAG_XZ_X86
For XZ, set this to select the x86 BCJ filter.
Definition compressor.h:248
SQFS_COMP_FLAG_GZIP_FIXED
@ SQFS_COMP_FLAG_GZIP_FIXED
For zlib deflate, set this to try the fixed strategy.
Definition compressor.h:305
SQFS_COMP_FLAG_LZ4_HC
@ SQFS_COMP_FLAG_LZ4_HC
For LZ4, set this to use high compression mode.
Definition compressor.h:231
SQFS_COMP_FLAG_XZ_EXTREME
@ SQFS_COMP_FLAG_XZ_EXTREME
Tell the XZ compressor to try the "extreme" option.
Definition compressor.h:278
SQFS_COMP_FLAG_XZ_ARMTHUMB
@ SQFS_COMP_FLAG_XZ_ARMTHUMB
For XZ, set this to select the ARM Thumb BCJ filter.
Definition compressor.h:268
sqfs_compressor_config_init
SQFS_API int sqfs_compressor_config_init(sqfs_compressor_config_t *cfg, SQFS_COMPRESSOR id, size_t block_size, sqfs_u16 flags)
Initialize a compressor configuration.
sqfs_compressor_id_from_name
SQFS_API int sqfs_compressor_id_from_name(const char *name)
Get the compressor ID using just the name of the backend.
SQFS_LZO_ALGORITHM
SQFS_LZO_ALGORITHM
The available LZO algorithms.
Definition compressor.h:321
sqfs_compressor_create
SQFS_API int sqfs_compressor_create(const sqfs_compressor_config_t *cfg, sqfs_compressor_t **out)
Create an instance of a compressor implementation.
sqfs_compressor_name_from_id
SQFS_API const char * sqfs_compressor_name_from_id(SQFS_COMPRESSOR id)
Get the name of a compressor backend from its ID.
predef.h
Includes forward declarations of data structures, macros and integer types.
sqfs_compressor_config_t
Configuration parameters for instantiating a compressor backend.
Definition compressor.h:106
sqfs_compressor_config_t::algorithm
sqfs_u16 algorithm
Which variant of lzo should be used.
Definition compressor.h:157
sqfs_compressor_config_t::dict_size
sqfs_u32 dict_size
LZMA dictionary size.
Definition compressor.h:175
sqfs_compressor_config_t::window_size
sqfs_u16 window_size
Deflate window size. Value between 8 and 15.
Definition compressor.h:142
sqfs_compressor_config_t::opt
union sqfs_compressor_config_t::@150056005226065037302057340160327270357105346253 opt
Backend specific options for fine tuing.
sqfs_compressor_config_t::gzip
struct sqfs_compressor_config_t::@150056005226065037302057340160327270357105346253::@131364336301033274301241022131047010054300023164 gzip
Options for the zlib compressor.
sqfs_compressor_config_t::pb
sqfs_u8 pb
Number of position bits.
Definition compressor.h:213
sqfs_compressor_config_t::flags
sqfs_u16 flags
A combination of SQFS_COMP_FLAG flags.
Definition compressor.h:115
sqfs_compressor_config_t::lp
sqfs_u8 lp
Number of literal position bits.
Definition compressor.h:199
sqfs_compressor_config_t::lzo
struct sqfs_compressor_config_t::@150056005226065037302057340160327270357105346253::@157005000110020252063361334134302071023100306053 lzo
Options for the lzo compressor.
sqfs_compressor_config_t::level
sqfs_u32 level
Compression level.
Definition compressor.h:127
sqfs_compressor_config_t::lc
sqfs_u8 lc
Number of literal context bits.
Definition compressor.h:187
sqfs_compressor_config_t::id
sqfs_u16 id
An SQFS_COMPRESSOR identifier.
Definition compressor.h:110
sqfs_compressor_config_t::block_size
sqfs_u32 block_size
The intended data block size.
Definition compressor.h:120
sqfs_compressor_config_t::xz
struct sqfs_compressor_config_t::@150056005226065037302057340160327270357105346253::@375230311347275227221245242071002237315353015313 xz
Options for the LZMA and XZ (LZMA v2) compressors.
sqfs_compressor_t
Encapsultes a compressor with a simple interface to compress or extract chunks of data.
Definition compressor.h:40
sqfs_compressor_t::do_block
sqfs_s32(* do_block)(sqfs_compressor_t *cmp, const sqfs_u8 *in, sqfs_u32 size, sqfs_u8 *out, sqfs_u32 outsize)
Compress or uncompress a chunk of data.
Definition compressor.h:92
sqfs_compressor_t::read_options
int(* read_options)(sqfs_compressor_t *cmp, sqfs_file_t *file)
Read compressor options from disk.
Definition compressor.h:76
sqfs_compressor_t::get_configuration
void(* get_configuration)(const sqfs_compressor_t *cmp, sqfs_compressor_config_t *cfg)
Get the current compressor configuration.
Definition compressor.h:49
sqfs_compressor_t::write_options
int(* write_options)(sqfs_compressor_t *cmp, sqfs_file_t *file)
Write compressor options to disk if non-default settings have been used.
Definition compressor.h:66
sqfs_file_t
Abstracts file I/O to make it easy to embedd SquashFS.
Definition io.h:94
sqfs_object_t
Base interface for all libsquashfs in-memory data structures.
Definition predef.h:126
super.h
Contains on-disk data structures, identifiers and functions for the SquashFS super block.
SQFS_COMPRESSOR
SQFS_COMPRESSOR
Set in sqfs_super_t to identify the compresser used by the filesystem.
Definition super.h:194