[PATCH] erofs-utils: list available compressors for help command
Li Guifu
blucerlee at gmail.com
Wed Oct 23 03:05:18 AEDT 2019
Hi Gao Xiang
What do you think put the compressor's name into structure of
erofs_compressor ?
So compressor's name will be matched to its implement not represented
at two place.
On 2019/10/22 12:20, Gao Xiang wrote:
> Users can get knowledge of supported compression
> algorithms then.
>
> Signed-off-by: Gao Xiang <gaoxiang25 at huawei.com>
> ---
> include/erofs/compress.h | 2 ++
> lib/compressor.c | 17 +++++++++++++++++
> mkfs/main.c | 15 +++++++++++++++
> 3 files changed, 34 insertions(+)
>
> diff --git a/include/erofs/compress.h b/include/erofs/compress.h
> index e0abb8f1c422..fa918732b532 100644
> --- a/include/erofs/compress.h
> +++ b/include/erofs/compress.h
> @@ -21,5 +21,7 @@ int erofs_write_compressed_file(struct erofs_inode *inode);
> int z_erofs_compress_init(void);
> int z_erofs_compress_exit(void);
>
> +const char *z_erofs_list_available_compressors(unsigned int i);
> +
> #endif
>
> diff --git a/lib/compressor.c b/lib/compressor.c
> index 8cc2f438479b..c593c769d46f 100644
> --- a/lib/compressor.c
> +++ b/lib/compressor.c
> @@ -36,6 +36,23 @@ int erofs_compress_destsize(struct erofs_compress *c,
> return ret;
> }
>
> +const char *z_erofs_list_available_compressors(unsigned int i)
> +{
> + static const char *compressors[] = {
> +#if LZ4_ENABLED
> +#if LZ4HC_ENABLED
> + "lz4hc",
> +#endif
> + "lz4",
> +#endif
> + NULL,
> + };
> +
> + if (i >= ARRAY_SIZE(compressors))
> + return NULL;
> + return compressors[i];
> +}
> +
> int erofs_compressor_init(struct erofs_compress *c,
> char *alg_name)
> {
> diff --git a/mkfs/main.c b/mkfs/main.c
> index 31cf1c2408d1..1161b3f0f7cc 100644
> --- a/mkfs/main.c
> +++ b/mkfs/main.c
> @@ -29,6 +29,19 @@ static struct option long_options[] = {
> {0, 0, 0, 0},
> };
>
> +static void print_available_compressors(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)
> {
> fprintf(stderr, "usage: [options] FILE DIRECTORY\n\n");
> @@ -39,6 +52,8 @@ static void usage(void)
> fprintf(stderr, " -EX[,...] X=extended options\n");
> fprintf(stderr, " -T# set a fixed UNIX timestamp # to all files\n");
> fprintf(stderr, " --help display this help and exit\n");
> + fprintf(stderr, "\nAvailable compressors are: ");
> + print_available_compressors(stderr, ", ");
> }
>
> static int parse_extended_opts(const char *opts)
>
More information about the Linux-erofs
mailing list