erofs-utils: lib: add a way to request supported algorithms
PATCH 1/2 erofs-utils: lib: add a way to request supported algorithms
dump.erofs needs to print supported algorithms instead of available compressors.
In addition, clean up erofs_get_compress_algorithm_id() too.
Cc Guo Xuenan <[email protected]>
Signed-off-by Gao Xiang <[email protected]>
--- include/erofs/compress.h | 1 + lib/compress.c | 33 ++++----------- lib/compressor.c | 84 +++++++++++++++++++++++++++---------- lib/compressor.h | 7 ++-- lib/compressor_deflate.c | 2 - lib/compressor_libdeflate.c | 2 - lib/compressor_liblzma.c | 2 - lib/compressor_lz4.c | 2 - lib/compressor_lz4hc.c | 3 -- 9 files changed, 77 insertions(+), 59 deletions(-)
include/erofs/compress.h +1 -0
@@ -23,6 +23,7 @@ int z_erofs_compress_init(struct erofs_sb_info *sbi, struct erofs_buffer_head *bh);int z_erofs_compress_exit (void ); +const char *z_erofs_list_supported_algorithms (int i,unsigned int *mask);const char *z_erofs_list_available_compressors (unsigned int i);static inline bool erofs_is_packed_inode (struct erofs_inode *inode)
lib/compress.c +9 -24
@@ -1030,17 +1030,6 @@ err_free_meta:return ret; } -static int erofs_get_compress_algorithm_id (const char *name) -{ -if (!strcmp (name,"lz4" ) || !strcmp (name,"lz4hc" )) -return Z_EROFS_COMPRESSION_LZ4 ; -if (!strcmp (name,"lzma" )) -return Z_EROFS_COMPRESSION_LZMA ; -if (!strcmp (name,"deflate" ) || !strcmp (name,"libdeflate" )) -return Z_EROFS_COMPRESSION_DEFLATE ; -return -ENOTSUP ; -} -static int z_erofs_build_compr_cfgs (struct erofs_sb_info *sbi,struct erofs_buffer_head *sb_bh) {
@@ -1123,23 +1112,21 @@ int z_erofs_compress_init(struct erofs_sb_info *sbi, struct erofs_buffer_head *sint i, ret;for (i =0 ; cfg.c_compr_alg[i]; ++i) { - ret =erofs_compressor_init (sbi, &erofs_ccfg[i].handle, - cfg.c_compr_alg[i]); +struct erofs_compress *c = &erofs_ccfg[i].handle; + + ret =erofs_compressor_init (sbi, c, cfg.c_compr_alg[i]);if (ret)return ret; - ret =erofs_compressor_setlevel (&erofs_ccfg[i].handle, - cfg.c_compr_level[i]); + ret =erofs_compressor_setlevel (c, cfg.c_compr_level[i]);if (ret)return ret; - ret =erofs_get_compress_algorithm_id (cfg.c_compr_alg[i]); -if (ret <0 ) -return ret; - erofs_ccfg[i].algorithmtype = ret; + erofs_ccfg[i].algorithmtype = +z_erofs_get_compress_algorithm_id (c); erofs_ccfg[i].enable = true; - sbi->available_compr_algs |=1 << ret; -if (ret !=Z_EROFS_COMPRESSION_LZ4 ) + sbi->available_compr_algs |=1 << erofs_ccfg[i].algorithmtype; +if (erofs_ccfg[i].algorithmtype !=Z_EROFS_COMPRESSION_LZ4 )erofs_sb_set_compr_cfgs (sbi); }
@@ -1172,10 +1159,8 @@ int z_erofs_compress_init(struct erofs_sb_info *sbi, struct erofs_buffer_head *sreturn -EINVAL ; } -if (erofs_sb_has_compr_cfgs (sbi)) { - sbi->available_compr_algs |=1 << ret; +if (erofs_sb_has_compr_cfgs (sbi))return z_erofs_build_compr_cfgs (sbi, sb_bh); - }return 0 ; }
lib/compressor.c +63 -21
132 lines not on this page · raw message
lib/compressor.h +4 -3
@@ -12,8 +12,6 @@struct erofs_compress ;struct erofs_compressor { -const char *name; -int default_level;int best_level;
@@ -26,9 +24,11 @@ struct erofs_compressor { void *dst, unsigned int dstsize); }; +struct erofs_algorithm ; +struct erofs_compress {struct erofs_sb_info *sbi; -const struct erofs_compressor *alg; +const struct erofs_algorithm *alg;unsigned int compress_threshold;unsigned int compression_level;
@@ -48,6 +48,7 @@ extern const struct erofs_compressor erofs_compressor_lzma;extern const struct erofs_compressor erofs_compressor_deflate;extern const struct erofs_compressor erofs_compressor_libdeflate; +int z_erofs_get_compress_algorithm_id (const struct erofs_compress *c);int erofs_compress_destsize (const struct erofs_compress *c,const void *src,unsigned int *srcsize,void *dst,unsigned int dstsize,bool inblocks);
lib/compressor_deflate.c +0 -2
@@ -36,7 +36,6 @@ static int compressor_deflate_exit(struct erofs_compress *c)static int compressor_deflate_init (struct erofs_compress *c) { - c->alg = &erofs_compressor_deflate; c->private_data =NULL ;erofs_warn ("EXPERIMENTAL DEFLATE algorithm in use. Use at your own risk!" );
@@ -68,7 +67,6 @@ static int erofs_compressor_deflate_setlevel(struct erofs_compress *c, }const struct erofs_compressor erofs_compressor_deflate = { - .name ="deflate" , .default_level =1 , .best_level =9 , .init = compressor_deflate_init,
lib/compressor_libdeflate.c +0 -2
@@ -82,7 +82,6 @@ static int compressor_libdeflate_exit(struct erofs_compress *c)static int compressor_libdeflate_init (struct erofs_compress *c) { - c->alg = &erofs_compressor_libdeflate; c->private_data =NULL ;erofs_warn ("EXPERIMENTAL libdeflate compressor in use. Use at your own risk!" );
@@ -104,7 +103,6 @@ static int erofs_compressor_libdeflate_setlevel(struct erofs_compress *c, }const struct erofs_compressor erofs_compressor_libdeflate = { - .name ="libdeflate" , .default_level =1 , .best_level =12 , .init = compressor_libdeflate_init,
lib/compressor_liblzma.c +0 -2
@@ -88,7 +88,6 @@ static int erofs_compressor_liblzma_init(struct erofs_compress *c) {struct erofs_liblzma_context *ctx; - c->alg = &erofs_compressor_lzma; ctx =malloc (sizeof (*ctx));if (!ctx)return -ENOMEM ;
@@ -100,7 +99,6 @@ static int erofs_compressor_liblzma_init(struct erofs_compress *c) }const struct erofs_compressor erofs_compressor_lzma = { - .name ="lzma" , .default_level =LZMA_PRESET_DEFAULT , .best_level =109 , .init = erofs_compressor_liblzma_init,
lib/compressor_lz4.c +0 -2
@@ -32,13 +32,11 @@ static int compressor_lz4_exit(struct erofs_compress *c)static int compressor_lz4_init (struct erofs_compress *c) { - c->alg = &erofs_compressor_lz4; c->sbi->lz4_max_distance =LZ4_DISTANCE_MAX ;return 0 ; }const struct erofs_compressor erofs_compressor_lz4 = { - .name ="lz4" , .default_level =0 , .best_level =0 , .init = compressor_lz4_init,
lib/compressor_lz4hc.c +0 -3
@@ -38,8 +38,6 @@ static int compressor_lz4hc_exit(struct erofs_compress *c)static int compressor_lz4hc_init (struct erofs_compress *c) { - c->alg = &erofs_compressor_lz4hc; - c->private_data =LZ4_createStreamHC ();if (!c->private_data)return -ENOMEM ;
@@ -60,7 +58,6 @@ static int compressor_lz4hc_setlevel(struct erofs_compress *c, }const struct erofs_compressor erofs_compressor_lz4hc = { - .name ="lz4hc" , .default_level =LZ4HC_CLEVEL_DEFAULT , .best_level =LZ4HC_CLEVEL_MAX , .init = compressor_lz4hc_init,
Signature · 1 line
2.24.4
PATCH 2/2 erofs-utils: dump: print more superblock fields
From: Guo Xuenan <[email protected]>
Let's print compression algorithms and sb_extslots as well as update feature information for dump.erosf
The proposed superblock dump is shown as below:
Filesystem magic number: 0xE0F5E1E2 Filesystem blocks: 4624 Filesystem inode metadata start block: 0 Filesystem shared xattr metadata start block: 0 Filesystem root nid: 37 Filesystem compr_algs: lz4, lz4hc, lzma Filesystem sb_extslots: 0 Filesystem inode count: 6131 Filesystem created: Wed Jun 7 17:15:44 2023 Filesystem features: sb_csum mtime 0padding compr_cfgs big_pcluster Filesystem UUID: not available
Signed-off-by Guo Xuenan <[email protected]>
Signed-off-by Gao Xiang <[email protected]>
--- dump/main.c | 29 +++++++++++++++++++++++++++++ include/erofs/internal.h | 1 + lib/super.c | 6 ++++++ 3 files changed, 36 insertions(+)
dump/main.c +29 -0
@@ -92,12 +92,14 @@ static struct erofsdump_feature feature_lists[] = { { true, EROFS_FEATURE_COMPAT_SB_CHKSUM, "sb_csum" }, { true, EROFS_FEATURE_COMPAT_MTIME, "mtime" }, { false, EROFS_FEATURE_INCOMPAT_ZERO_PADDING, "0padding" }, + { false, EROFS_FEATURE_INCOMPAT_COMPR_CFGS, "compr_cfgs" }, { false, EROFS_FEATURE_INCOMPAT_BIG_PCLUSTER, "big_pcluster" }, { false, EROFS_FEATURE_INCOMPAT_CHUNKED_FILE, "chunked_file" }, { false, EROFS_FEATURE_INCOMPAT_DEVICE_TABLE, "device_table" }, { false, EROFS_FEATURE_INCOMPAT_ZTAILPACKING, "ztailpacking" }, { false, EROFS_FEATURE_INCOMPAT_FRAGMENTS, "fragments" }, { false, EROFS_FEATURE_INCOMPAT_DEDUPE, "dedupe" }, + { false, EROFS_FEATURE_INCOMPAT_XATTR_PREFIXES, "xattr_prefixes" }, };static int erofsdump_readdir (struct erofs_dir_context *ctx);
@@ -588,6 +590,23 @@ static void erofsdump_print_statistic(void)erofsdump_filetype_distribution (file_types,OTHERFILETYPE ); } +static void erofsdump_print_supported_compressors (FILE *f,unsigned int mask) +{ +unsigned int i =0 ; +bool comma = false; +const char *s; + +while ((s =z_erofs_list_supported_algorithms (i++, &mask)) !=NULL ) { +if (*s =='\0' ) +continue ; +if (comma) +fputs (", " , f); +fputs (s, f); + comma = true; + } +fputc ('\n' , f); +} +static void erofsdump_show_superblock (void ) {time_t time = sbi.build_time;
@@ -607,6 +626,16 @@ static void erofsdump_show_superblock(void)if (erofs_sb_has_fragments (&sbi) && sbi.packed_nid >0 )fprintf (stdout,"Filesystem packed nid: %llu\n" , sbi.packed_nid |0ULL ); +if (erofs_sb_has_compr_cfgs (&sbi)) { +fprintf (stdout,"Filesystem compr_algs: " ); +erofsdump_print_supported_compressors (stdout, + sbi.available_compr_algs); + }else { +fprintf (stdout,"Filesystem lz4_max_distance: %u\n" , + sbi.lz4_max_distance |0U ); + } +fprintf (stdout,"Filesystem sb_extslots: %u\n" , + sbi.extslots |0U );fprintf (stdout,"Filesystem inode count: %llu\n" , sbi.inos |0ULL ); fprintf(stdout, "Filesystem created: %s",
include/erofs/internal.h +1 -0
@@ -74,6 +74,7 @@ struct erofs_sb_info {u64 build_time;u32 build_time_nsec; +u8 extslots;unsigned char islotbits;unsigned char blkszbits;
lib/super.c +6 -0
@@ -106,11 +106,17 @@ int erofs_read_superblock(struct erofs_sb_info *sbi) sbi->packed_nid =le64_to_cpu (dsb->packed_nid); sbi->inos =le64_to_cpu (dsb->inos); sbi->checksum =le32_to_cpu (dsb->checksum); + sbi->extslots = dsb->sb_extslots; sbi->build_time =le64_to_cpu (dsb->build_time); sbi->build_time_nsec =le32_to_cpu (dsb->build_time_nsec);memcpy (&sbi->uuid, dsb->uuid,sizeof (dsb->uuid)); + +if (erofs_sb_has_compr_cfgs (sbi)) + sbi->available_compr_algs =le16_to_cpu (dsb->u1.available_compr_algs); +else + sbi->lz4_max_distance =le16_to_cpu (dsb->u1.lz4_max_distance);return erofs_init_devices (sbi, dsb); }
Signature · 1 line
2.24.4