erofs-utils: lib: add a way to request supported algorithms
PATCH v2 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.
---
changes since v1:
- fix available compressors print.
fsck/main.c | 8 ++-- include/erofs/compress.h | 3 +- lib/compress.c | 33 ++++---------- lib/compressor.c | 90 ++++++++++++++++++++++++++++--------- 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 -- mkfs/main.c | 8 ++-- 11 files changed, 94 insertions(+), 66 deletions(-)
fsck/main.c +5 -3
@@ -61,13 +61,15 @@ static struct list_head erofsfsck_link_hashtable[NR_HARDLINK_HASHTABLE];static void print_available_decompressors (FILE *f,const char *delim) { -unsigned int i =0 ; +int i =0 ; +bool comma = false;const char *s; -while ((s =z_erofs_list_available_compressors (i)) !=NULL ) { -if (i++) +while ((s =z_erofs_list_available_compressors (&i)) !=NULL ) { +if (comma)fputs (delim, f);fputs (s, f); + comma = true; }fputc ('\n' , f); }
include/erofs/compress.h +2 -1
@@ -23,7 +23,8 @@ 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_available_compressors (unsigned int i); +const char *z_erofs_list_supported_algorithms (int i,unsigned int *mask); +const char *z_erofs_list_available_compressors (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 +69 -21
138 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,
mkfs/main.c +5 -3
@@ -68,13 +68,15 @@ static struct option long_options[] = {static void print_available_compressors (FILE *f,const char *delim) { -unsigned int i =0 ; +int i =0 ; +bool comma = false;const char *s; -while ((s =z_erofs_list_available_compressors (i)) !=NULL ) { -if (i++) +while ((s =z_erofs_list_available_compressors (&i)) !=NULL ) { +if (comma)fputs (delim, f);fputs (s, f); + comma = true; }fputc ('\n' , f); }
Signature · 1 line
2.24.4
PATCH v2 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
---
no change.
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
Thanks
Xuenan
Quoted 430 lines · Gao Xiang
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]>---
changes since v1:
- fixavailable compressorsprint.fsck/main.c | 8 ++-- include/erofs/compress.h | 3 +- lib/compress.c | 33 ++++---------- lib/compressor.c | 90 ++++++++++++++++++++++++++++--------- 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 -- mkfs/main.c | 8 ++-- 11 files changed, 94 insertions(+), 66 deletions(-)fsck/main.c +5
-3@@ -61,13 +61,15 @@ static struct list_head erofsfsck_link_hashtable[NR_HARDLINK_HASHTABLE];static void print_available_decompressors (FILE *f,const char *delim) { -unsigned int i =0 ; +int i =0 ; +bool comma = false;const char *s; -while ((s =z_erofs_list_available_compressors (i)) !=NULL ) { -if (i++) +while ((s =z_erofs_list_available_compressors (&i)) !=NULL ) { +if (comma)fputs (delim, f);fputs (s, f); + comma = true; }fputc ('\n' , f); }include/erofs/compress.h +2
-1@@ -23,7 +23,8 @@ 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_available_compressors (unsigned int i); +const char *z_erofs_list_supported_algorithms (int i,unsigned int *mask); +const char *z_erofs_list_available_compressors (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 +69
-21@@ -10,22 +10,72 @@#define EROFS_CONFIG_COMPR_DEF_BOUNDARY (128) -static const struct erofs_compressor *compressors[] = { +static const struct erofs_algorithm { +char *name; +const struct erofs_compressor *c; +unsigned int id; + +/* its name won't be shown as a supported algorithm */ +bool optimisor; +} erofs_algs[] = { + {"lz4" , #if LZ4_ENABLED -#if LZ4HC_ENABLED - &erofs_compressor_lz4hc, -#endif &erofs_compressor_lz4, +#else +NULL , #endif +Z_EROFS_COMPRESSION_LZ4 , false }, + +#if LZ4HC_ENABLED + {"lz4hc" , &erofs_compressor_lz4hc, +Z_EROFS_COMPRESSION_LZ4 , true }, +#endif + + {"lzma" , #if HAVE_LIBLZMA &erofs_compressor_lzma, +#else +NULL , #endif - &erofs_compressor_deflate, +Z_EROFS_COMPRESSION_LZMA , false }, + + {"deflate" , &erofs_compressor_deflate, +Z_EROFS_COMPRESSION_DEFLATE , false }, + #if HAVE_LIBDEFLATE - &erofs_compressor_libdeflate, + {"libdeflate" , &erofs_compressor_libdeflate, +Z_EROFS_COMPRESSION_DEFLATE , true }, #endif }; +int z_erofs_get_compress_algorithm_id (const struct erofs_compress *c) +{ +DBG_BUGON (!c->alg); +return c->alg->id; +} + +const char *z_erofs_list_supported_algorithms (int i,unsigned int *mask) +{ +if (i >=ARRAY_SIZE (erofs_algs)) +return NULL ; +if (!erofs_algs[i].optimisor && (*mask & (1 << erofs_algs[i].id))) { + *mask ^=1 << erofs_algs[i].id; +return erofs_algs[i].name; + } +return "" ; +} + +const char *z_erofs_list_available_compressors (int *i) +{ +for (;*i <ARRAY_SIZE (erofs_algs); ++*i) { +if (!erofs_algs[*i].c) +continue ; +return erofs_algs[(*i)++].name; + } + +return NULL ; +} +int erofs_compress_destsize (const struct erofs_compress *c,const void *src,unsigned int *srcsize,void *dst,unsigned int dstsize,bool inblocks)@@ -34,11 +84,11 @@ int erofs_compress_destsize(const struct erofs_compress *c,int ret;DBG_BUGON (!c->alg); -if (!c->alg->compress_destsize) +if (!c->alg->c->compress_destsize)return -ENOTSUP ; uncompressed_capacity = *srcsize; - ret = c->alg->compress_destsize (c, src, srcsize, dst, dstsize); + ret = c->alg->c->compress_destsize (c, src, srcsize, dst, dstsize);if (ret <0 )return ret;@@ -55,16 +105,11 @@ int erofs_compress_destsize(const struct erofs_compress *c,return ret; } -const char *z_erofs_list_available_compressors (unsigned int i) -{ -return i >=ARRAY_SIZE (compressors) ?NULL : compressors[i]->name; -} -int erofs_compressor_setlevel (struct erofs_compress *c,int compression_level) {DBG_BUGON (!c->alg); -if (c->alg->setlevel) -return c->alg->setlevel (c, compression_level); +if (c->alg->c->setlevel) +return c->alg->c->setlevel (c, compression_level);if (compression_level >=0 )return -EINVAL ;@@ -93,13 +138,16 @@ int erofs_compressor_init(struct erofs_sb_info *sbi, } ret = -EINVAL ; -for (i =0 ; i <ARRAY_SIZE (compressors); ++i) { -if (alg_name &&strcmp (alg_name, compressors[i]->name)) +for (i =0 ; i <ARRAY_SIZE (erofs_algs); ++i) { +if (alg_name &&strcmp (alg_name, erofs_algs[i].name)) +continue ; + +if (!erofs_algs[i].c)continue ; - ret = compressors[i]->init (c); + ret = erofs_algs[i].c->init (c);if (!ret) { -DBG_BUGON (!c->alg); + c->alg = &erofs_algs[i];return 0 ; } }@@ -109,7 +157,7 @@ int erofs_compressor_init(struct erofs_sb_info *sbi,int erofs_compressor_exit (struct erofs_compress *c) { -if (c->alg && c->alg->exit) -return c->alg->exit (c); +if (c->alg && c->alg->c->exit) +return c->alg->c->exit (c);return 0 ; }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,mkfs/main.c +5
-3@@ -68,13 +68,15 @@ static struct option long_options[] = {static void print_available_compressors (FILE *f,const char *delim) { -unsigned int i =0 ; +int i =0 ; +bool comma = false;const char *s; -while ((s =z_erofs_list_available_compressors (i)) !=NULL ) { -if (i++) +while ((s =z_erofs_list_available_compressors (&i)) !=NULL ) { +if (comma)fputs (delim, f);fputs (s, f); + comma = true; }fputc ('\n' , f); }
Signature · 2 lines
Best regards Guo Xuenan
Thanks
Xuenan
Quoted 430 lines · Gao Xiang
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]>---
changes since v1:
- fixavailable compressorsprint.fsck/main.c | 8 ++-- include/erofs/compress.h | 3 +- lib/compress.c | 33 ++++---------- lib/compressor.c | 90 ++++++++++++++++++++++++++++--------- 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 -- mkfs/main.c | 8 ++-- 11 files changed, 94 insertions(+), 66 deletions(-)fsck/main.c +5
-3@@ -61,13 +61,15 @@ static struct list_head erofsfsck_link_hashtable[NR_HARDLINK_HASHTABLE];static void print_available_decompressors (FILE *f,const char *delim) { -unsigned int i =0 ; +int i =0 ; +bool comma = false;const char *s; -while ((s =z_erofs_list_available_compressors (i)) !=NULL ) { -if (i++) +while ((s =z_erofs_list_available_compressors (&i)) !=NULL ) { +if (comma)fputs (delim, f);fputs (s, f); + comma = true; }fputc ('\n' , f); }include/erofs/compress.h +2
-1@@ -23,7 +23,8 @@ 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_available_compressors (unsigned int i); +const char *z_erofs_list_supported_algorithms (int i,unsigned int *mask); +const char *z_erofs_list_available_compressors (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 +69
-21@@ -10,22 +10,72 @@#define EROFS_CONFIG_COMPR_DEF_BOUNDARY (128) -static const struct erofs_compressor *compressors[] = { +static const struct erofs_algorithm { +char *name; +const struct erofs_compressor *c; +unsigned int id; + +/* its name won't be shown as a supported algorithm */ +bool optimisor; +} erofs_algs[] = { + {"lz4" , #if LZ4_ENABLED -#if LZ4HC_ENABLED - &erofs_compressor_lz4hc, -#endif &erofs_compressor_lz4, +#else +NULL , #endif +Z_EROFS_COMPRESSION_LZ4 , false }, + +#if LZ4HC_ENABLED + {"lz4hc" , &erofs_compressor_lz4hc, +Z_EROFS_COMPRESSION_LZ4 , true }, +#endif + + {"lzma" , #if HAVE_LIBLZMA &erofs_compressor_lzma, +#else +NULL , #endif - &erofs_compressor_deflate, +Z_EROFS_COMPRESSION_LZMA , false }, + + {"deflate" , &erofs_compressor_deflate, +Z_EROFS_COMPRESSION_DEFLATE , false }, + #if HAVE_LIBDEFLATE - &erofs_compressor_libdeflate, + {"libdeflate" , &erofs_compressor_libdeflate, +Z_EROFS_COMPRESSION_DEFLATE , true }, #endif }; +int z_erofs_get_compress_algorithm_id (const struct erofs_compress *c) +{ +DBG_BUGON (!c->alg); +return c->alg->id; +} + +const char *z_erofs_list_supported_algorithms (int i,unsigned int *mask) +{ +if (i >=ARRAY_SIZE (erofs_algs)) +return NULL ; +if (!erofs_algs[i].optimisor && (*mask & (1 << erofs_algs[i].id))) { + *mask ^=1 << erofs_algs[i].id; +return erofs_algs[i].name; + } +return "" ; +} + +const char *z_erofs_list_available_compressors (int *i) +{ +for (;*i <ARRAY_SIZE (erofs_algs); ++*i) { +if (!erofs_algs[*i].c) +continue ; +return erofs_algs[(*i)++].name; + } + +return NULL ; +} +int erofs_compress_destsize (const struct erofs_compress *c,const void *src,unsigned int *srcsize,void *dst,unsigned int dstsize,bool inblocks)@@ -34,11 +84,11 @@ int erofs_compress_destsize(const struct erofs_compress *c,int ret;DBG_BUGON (!c->alg); -if (!c->alg->compress_destsize) +if (!c->alg->c->compress_destsize)return -ENOTSUP ; uncompressed_capacity = *srcsize; - ret = c->alg->compress_destsize (c, src, srcsize, dst, dstsize); + ret = c->alg->c->compress_destsize (c, src, srcsize, dst, dstsize);if (ret <0 )return ret;@@ -55,16 +105,11 @@ int erofs_compress_destsize(const struct erofs_compress *c,return ret; } -const char *z_erofs_list_available_compressors (unsigned int i) -{ -return i >=ARRAY_SIZE (compressors) ?NULL : compressors[i]->name; -} -int erofs_compressor_setlevel (struct erofs_compress *c,int compression_level) {DBG_BUGON (!c->alg); -if (c->alg->setlevel) -return c->alg->setlevel (c, compression_level); +if (c->alg->c->setlevel) +return c->alg->c->setlevel (c, compression_level);if (compression_level >=0 )return -EINVAL ;@@ -93,13 +138,16 @@ int erofs_compressor_init(struct erofs_sb_info *sbi, } ret = -EINVAL ; -for (i =0 ; i <ARRAY_SIZE (compressors); ++i) { -if (alg_name &&strcmp (alg_name, compressors[i]->name)) +for (i =0 ; i <ARRAY_SIZE (erofs_algs); ++i) { +if (alg_name &&strcmp (alg_name, erofs_algs[i].name)) +continue ; + +if (!erofs_algs[i].c)continue ; - ret = compressors[i]->init (c); + ret = erofs_algs[i].c->init (c);if (!ret) { -DBG_BUGON (!c->alg); + c->alg = &erofs_algs[i];return 0 ; } }@@ -109,7 +157,7 @@ int erofs_compressor_init(struct erofs_sb_info *sbi,int erofs_compressor_exit (struct erofs_compress *c) { -if (c->alg && c->alg->exit) -return c->alg->exit (c); +if (c->alg && c->alg->c->exit) +return c->alg->c->exit (c);return 0 ; }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,mkfs/main.c +5
-3@@ -68,13 +68,15 @@ static struct option long_options[] = {static void print_available_compressors (FILE *f,const char *delim) { -unsigned int i =0 ; +int i =0 ; +bool comma = false;const char *s; -while ((s =z_erofs_list_available_compressors (i)) !=NULL ) { -if (i++) +while ((s =z_erofs_list_available_compressors (&i)) !=NULL ) { +if (comma)fputs (delim, f);fputs (s, f); + comma = true; }fputc ('\n' , f); }
Signature · 3 lines
Guo Xuenan [OS Kernel Lab] ----------------------------- Email: [email protected]