xref: /aosp_15_r20/external/erofs-utils/lib/compressor.h (revision 33b1fccf6a0fada2c2875d400ed01119b7676ee5)
1 /* SPDX-License-Identifier: GPL-2.0+ OR Apache-2.0 */
2 /*
3  * Copyright (C) 2018-2019 HUAWEI, Inc.
4  *             http://www.huawei.com/
5  * Created by Gao Xiang <[email protected]>
6  */
7 #ifndef __EROFS_LIB_COMPRESSOR_H
8 #define __EROFS_LIB_COMPRESSOR_H
9 
10 #include "erofs/defs.h"
11 
12 struct erofs_compress;
13 
14 struct erofs_compressor {
15 	int default_level;
16 	int best_level;
17 	u32 default_dictsize;
18 	u32 max_dictsize;
19 
20 	int (*init)(struct erofs_compress *c);
21 	int (*exit)(struct erofs_compress *c);
22 	void (*reset)(struct erofs_compress *c);
23 	int (*setlevel)(struct erofs_compress *c, int compression_level);
24 	int (*setdictsize)(struct erofs_compress *c, u32 dict_size);
25 
26 	int (*compress_destsize)(const struct erofs_compress *c,
27 				 const void *src, unsigned int *srcsize,
28 				 void *dst, unsigned int dstsize);
29 };
30 
31 struct erofs_algorithm {
32 	char *name;
33 	const struct erofs_compressor *c;
34 	unsigned int id;
35 
36 	/* its name won't be shown as a supported algorithm */
37 	bool optimisor;
38 };
39 
40 struct erofs_compress {
41 	struct erofs_sb_info *sbi;
42 	const struct erofs_algorithm *alg;
43 
44 	unsigned int compress_threshold;
45 	unsigned int compression_level;
46 	unsigned int dict_size;
47 
48 	void *private_data;
49 };
50 
51 /* list of compression algorithms */
52 extern const struct erofs_compressor erofs_compressor_lz4;
53 extern const struct erofs_compressor erofs_compressor_lz4hc;
54 extern const struct erofs_compressor erofs_compressor_lzma;
55 extern const struct erofs_compressor erofs_compressor_deflate;
56 extern const struct erofs_compressor erofs_compressor_libdeflate;
57 extern const struct erofs_compressor erofs_compressor_libzstd;
58 
59 int z_erofs_get_compress_algorithm_id(const struct erofs_compress *c);
60 int erofs_compress_destsize(const struct erofs_compress *c,
61 			    const void *src, unsigned int *srcsize,
62 			    void *dst, unsigned int dstsize);
63 
64 int erofs_compressor_init(struct erofs_sb_info *sbi, struct erofs_compress *c,
65 			  char *alg_name, int compression_level, u32 dict_size);
66 int erofs_compressor_exit(struct erofs_compress *c);
67 void erofs_compressor_reset(struct erofs_compress *c);
68 
69 #endif
70