All of lore.kernel.org
 help / color / mirror / Atom feed
From: Li Guifu <blucerlee@gmail.com>
To: Gao Xiang <gaoxiang25@huawei.com>, Li Guifu <bluce.liguifu@huawei.com>
Cc: linux-erofs@lists.ozlabs.org
Subject: Re: [PATCH] erofs-utils: list available compressors for help command
Date: Wed, 23 Oct 2019 00:05:18 +0800	[thread overview]
Message-ID: <6a0f0b47-1bb7-7e82-770f-8b039ab634f4@gmail.com> (raw)
In-Reply-To: <20191022042002.61999-1-gaoxiang25@huawei.com>

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@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)
> 

  reply	other threads:[~2019-10-22 16:05 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-10-22  4:20 [PATCH] erofs-utils: list available compressors for help command Gao Xiang
2019-10-22 16:05 ` Li Guifu [this message]
2019-10-22 16:36   ` [PATCH v2] " Li Guifu
2019-10-22 16:50     ` Gao Xiang via Linux-erofs
2019-10-22 18:59       ` [PATCH v3] " Gao Xiang via Linux-erofs

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=6a0f0b47-1bb7-7e82-770f-8b039ab634f4@gmail.com \
    --to=blucerlee@gmail.com \
    --cc=bluce.liguifu@huawei.com \
    --cc=gaoxiang25@huawei.com \
    --cc=linux-erofs@lists.ozlabs.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.