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