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 <gaoxiang25@huawei.com> 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 18 int (*init)(struct erofs_compress *c); 19 int (*exit)(struct erofs_compress *c); 20 int (*setlevel)(struct erofs_compress *c, int compression_level); 21 22 int (*compress_destsize)(const struct erofs_compress *c, 23 const void *src, unsigned int *srcsize, 24 void *dst, unsigned int dstsize); 25 }; 26 27 struct erofs_algorithm; 28 29 struct erofs_compress { 30 struct erofs_sb_info *sbi; 31 const struct erofs_algorithm *alg; 32 33 unsigned int compress_threshold; 34 unsigned int compression_level; 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 const struct erofs_compressor erofs_compressor_lz4; 46 extern const struct erofs_compressor erofs_compressor_lz4hc; 47 extern const struct erofs_compressor erofs_compressor_lzma; 48 extern const struct erofs_compressor erofs_compressor_deflate; 49 extern const struct erofs_compressor erofs_compressor_libdeflate; 50 51 int z_erofs_get_compress_algorithm_id(const struct erofs_compress *c); 52 int erofs_compress_destsize(const struct erofs_compress *c, 53 const void *src, unsigned int *srcsize, 54 void *dst, unsigned int dstsize, bool inblocks); 55 56 int erofs_compressor_setlevel(struct erofs_compress *c, int compression_level); 57 int erofs_compressor_init(struct erofs_sb_info *sbi, 58 struct erofs_compress *c, char *alg_name); 59 int erofs_compressor_exit(struct erofs_compress *c); 60 61 #endif 62