1 /* SPDX-License-Identifier: GPL-2.0+ */
2 /*
3  * erofs-utils/lib/compressor.h
4  *
5  * Copyright (C) 2018-2019 HUAWEI, Inc.
6  *             http://www.huawei.com/
7  * Created by Gao Xiang <gaoxiang25@huawei.com>
8  */
9 #ifndef __EROFS_LIB_COMPRESSOR_H
10 #define __EROFS_LIB_COMPRESSOR_H
11 
12 #include "erofs/defs.h"
13 
14 struct erofs_compress;
15 
16 struct erofs_compressor {
17 	const char *name;
18 
19 	int default_level;
20 	int best_level;
21 
22 	int (*init)(struct erofs_compress *c);
23 	int (*exit)(struct erofs_compress *c);
24 
25 	int (*compress_destsize)(struct erofs_compress *c,
26 				 int compress_level,
27 				 void *src, unsigned int *srcsize,
28 				 void *dst, unsigned int dstsize);
29 };
30 
31 struct erofs_compress {
32 	struct erofs_compressor *alg;
33 
34 	unsigned int compress_threshold;
35 
36 	/* *_destsize specific */
37 	unsigned int destsize_alignsize;
38 	unsigned int destsize_redzone_begin;
39 	unsigned int destsize_redzone_end;
40 
41 	void *private_data;
42 };
43 
44 /* list of compression algorithms */
45 extern struct erofs_compressor erofs_compressor_lz4;
46 extern struct erofs_compressor erofs_compressor_lz4hc;
47 
48 int erofs_compress_destsize(struct erofs_compress *c, int compression_level,
49 			    void *src, unsigned int *srcsize,
50 			    void *dst, unsigned int dstsize);
51 
52 int erofs_compressor_init(struct erofs_compress *c, char *alg_name);
53 int erofs_compressor_exit(struct erofs_compress *c);
54 
55 #endif
56 
57