[PATCH v2 2/4] erofs-utils: lib: unify all identical compressor print function
Gao Xiang
hsiangkao at linux.alibaba.com
Thu Jun 15 20:46:49 AEST 2023
On 2023/6/15 18:17, Guo Xuenan via Linux-erofs wrote:
> {dump,fsck}.erofs use the same compressor print function,
> available compressors means which algothrims are currently
> supported by binary tools.
> supported compressors including all algothrims that are ready
> for your erofs binary tools.
>
> Signed-off-by: Guo Xuenan <guoxuenan at huawei.com>
> ---
> fsck/main.c | 15 +-----------
> include/erofs/compress.h | 3 ++-
> lib/compressor.c | 51 ++++++++++++++++++++++++++--------------
> mkfs/main.c | 15 +-----------
> 4 files changed, 38 insertions(+), 46 deletions(-)
>
> diff --git a/fsck/main.c b/fsck/main.c
> index f816bec..e559050 100644
> --- a/fsck/main.c
> +++ b/fsck/main.c
> @@ -49,19 +49,6 @@ static struct option long_options[] = {
> {0, 0, 0, 0},
> };
>
> -static void print_available_decompressors(FILE *f, const char *delim)
> -{
> - unsigned int i = 0;
> - const char *s;
> -
> - while ((s = z_erofs_list_available_compressors(i)) != NULL) {
> - if (i++)
> - fputs(delim, f);
> - fputs(s, f);
> - }
> - fputc('\n', f);
> -}
> -
> static void usage(void)
> {
> fputs("usage: [options] IMAGE\n\n"
> @@ -84,7 +71,7 @@ static void usage(void)
> " --no-preserve-owner extract as yourself\n"
> " --no-preserve-perms apply user's umask when extracting permissions\n"
> "\nSupported algorithms are: ", stderr);
> - print_available_decompressors(stderr, ", ");
> + erofs_print_available_compressors(stderr);
> }
>
> static void erofsfsck_print_version(void)
> diff --git a/include/erofs/compress.h b/include/erofs/compress.h
> index 08af9e3..f1b9bbd 100644
> --- a/include/erofs/compress.h
> +++ b/include/erofs/compress.h
> @@ -22,7 +22,8 @@ int erofs_write_compressed_file(struct erofs_inode *inode, int fd);
> int z_erofs_compress_init(struct erofs_buffer_head *bh);
> int z_erofs_compress_exit(void);
>
> -const char *z_erofs_list_available_compressors(unsigned int i);
> +void erofs_print_available_compressors(FILE *f);
> +void erofs_print_supported_compressors(FILE *f, unsigned int mask);
>
> static inline bool erofs_is_packed_inode(struct erofs_inode *inode)
> {
> diff --git a/lib/compressor.c b/lib/compressor.c
> index 88a2fb0..da8d1b9 100644
> --- a/lib/compressor.c
> +++ b/lib/compressor.c
> @@ -10,18 +10,6 @@
>
> #define EROFS_CONFIG_COMPR_DEF_BOUNDARY (128)
>
> -static const struct erofs_compressor *compressors[] = {
> -#if LZ4_ENABLED
> -#if LZ4HC_ENABLED
> - &erofs_compressor_lz4hc,
> -#endif
> - &erofs_compressor_lz4,
> -#endif
> -#if HAVE_LIBLZMA
> - &erofs_compressor_lzma,
> -#endif
> -};
> -
> /* for compressors type configuration */
> static struct erofs_supported_algothrim {
> int algtype;
> @@ -119,9 +107,38 @@ int erofs_compress_destsize(const struct erofs_compress *c,
> return ret;
> }
>
> -const char *z_erofs_list_available_compressors(unsigned int i)
> +void erofs_print_supported_compressors(FILE *f, unsigned int mask)
> {
> - return i >= ARRAY_SIZE(compressors) ? NULL : compressors[i]->name;
> + unsigned int i = 0;
> + int comma = false;
> + const char *s;
> +
> + while (i < erofs_ccfg.erofs_ccfg_num) {
> + s = erofs_ccfg.compressors[i].name;
> + if (s && (mask & (1 << erofs_ccfg.compressors[i++].algorithmtype))) {
> + if (comma)
> + fputs(", ", f);
> + else
> + comma = true;
> + fputs(s, f);
> + }
> + }
> + fputc('\n', f);
> +}
> +
> +void erofs_print_available_compressors(FILE *f)
> +{
Should just erofs_print_supported_compressors(f, ~0) and avoid this helper?
Thanks,
Gao Xiang
More information about the Linux-erofs
mailing list