Linux-EROFS Archive on lore.kernel.org
 help / color / Atom feed
* [PATCH] erofs-utils: list available compressors for help command
@ 2019-10-22  4:20 Gao Xiang
  2019-10-22 16:05 ` Li Guifu
  0 siblings, 1 reply; 5+ messages in thread
From: Gao Xiang @ 2019-10-22  4:20 UTC (permalink / raw)
  To: Li Guifu; +Cc: linux-erofs

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


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] erofs-utils: list available compressors for help command
  2019-10-22  4:20 [PATCH] erofs-utils: list available compressors for help command Gao Xiang
@ 2019-10-22 16:05 ` Li Guifu
  2019-10-22 16:36   ` [PATCH v2] " Li Guifu
  0 siblings, 1 reply; 5+ messages in thread
From: Li Guifu @ 2019-10-22 16:05 UTC (permalink / raw)
  To: Gao Xiang, Li Guifu; +Cc: linux-erofs

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

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH v2] erofs-utils: list available compressors for help command
  2019-10-22 16:05 ` Li Guifu
@ 2019-10-22 16:36   ` " Li Guifu
  2019-10-22 16:50     ` Gao Xiang via Linux-erofs
  0 siblings, 1 reply; 5+ messages in thread
From: Li Guifu @ 2019-10-22 16:36 UTC (permalink / raw)
  To: linux-erofs

From: Gao Xiang <gaoxiang25@huawei.com>

Users can get knowledge of supported compression
algorithms then.

Signed-off-by: Gao Xiang <gaoxiang25@huawei.com>
Signed-off-by: Li Guifu <blucerlee@gmail.com>
---
 include/erofs/compress.h |  2 ++
 lib/compressor.c         | 23 ++++++++++++++---------
 lib/compressor.h         |  1 +
 lib/compressor_lz4.c     |  1 +
 lib/compressor_lz4hc.c   |  1 +
 mkfs/main.c              | 15 +++++++++++++++
 6 files changed, 34 insertions(+), 9 deletions(-)

diff --git a/include/erofs/compress.h b/include/erofs/compress.h
index e0abb8f..fa91873 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 8cc2f43..6502437 100644
--- a/lib/compressor.c
+++ b/lib/compressor.c
@@ -12,6 +12,15 @@
 
 #define EROFS_CONFIG_COMPR_DEF_BOUNDARY		(128)
 
+static struct erofs_compressor *compressors[] = {
+#if LZ4_ENABLED
+#if LZ4HC_ENABLED
+		&erofs_compressor_lz4hc,
+#endif
+		&erofs_compressor_lz4,
+#endif
+};
+
 int erofs_compress_destsize(struct erofs_compress *c,
 			    int compression_level,
 			    void *src,
@@ -36,18 +45,14 @@ int erofs_compress_destsize(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_init(struct erofs_compress *c,
 			  char *alg_name)
 {
-	static struct erofs_compressor *compressors[] = {
-#if LZ4_ENABLED
-#if LZ4HC_ENABLED
-		&erofs_compressor_lz4hc,
-#endif
-		&erofs_compressor_lz4,
-#endif
-	};
-
 	int ret, i;
 
 	/* should be written in "minimum compression ratio * 100" */
diff --git a/lib/compressor.h b/lib/compressor.h
index 6429b2a..4b76c4c 100644
--- a/lib/compressor.h
+++ b/lib/compressor.h
@@ -14,6 +14,7 @@
 struct erofs_compress;
 
 struct erofs_compressor {
+	const char *name;
 	int default_level;
 	int best_level;
 
diff --git a/lib/compressor_lz4.c b/lib/compressor_lz4.c
index 0d33223..a9cbb80 100644
--- a/lib/compressor_lz4.c
+++ b/lib/compressor_lz4.c
@@ -39,6 +39,7 @@ static int compressor_lz4_init(struct erofs_compress *c,
 }
 
 struct erofs_compressor erofs_compressor_lz4 = {
+	.name = "lz4",
 	.default_level = 0,
 	.best_level = 0,
 	.init = compressor_lz4_init,
diff --git a/lib/compressor_lz4hc.c b/lib/compressor_lz4hc.c
index 14e0175..a160c1a 100644
--- a/lib/compressor_lz4hc.c
+++ b/lib/compressor_lz4hc.c
@@ -52,6 +52,7 @@ static int compressor_lz4hc_init(struct erofs_compress *c,
 }
 
 struct erofs_compressor erofs_compressor_lz4hc = {
+	.name = "lz4hc",
 	.default_level = LZ4HC_CLEVEL_DEFAULT,
 	.best_level = LZ4HC_CLEVEL_MAX,
 	.init = compressor_lz4hc_init,
diff --git a/mkfs/main.c b/mkfs/main.c
index 31cf1c2..1161b3f 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)
-- 
2.17.1


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v2] erofs-utils: list available compressors for help command
  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
  0 siblings, 1 reply; 5+ messages in thread
From: Gao Xiang via Linux-erofs @ 2019-10-22 16:50 UTC (permalink / raw)
  To: Li Guifu; +Cc: linux-erofs

Hi Guifu,

On Wed, Oct 23, 2019 at 12:36:16AM +0800, Li Guifu wrote:
> From: Gao Xiang <gaoxiang25@huawei.com>
> 
> Users can get knowledge of supported compression
> algorithms then.
> 
> Signed-off-by: Gao Xiang <gaoxiang25@huawei.com>
> Signed-off-by: Li Guifu <blucerlee@gmail.com>
> ---

That is a good idea, how about adding some changelogs
at this place (you could try this from now on), e.g:

changes since v1:
 - update according to
   https://lore.kernel.org/r/6a0f0b47-1bb7-7e82-770f-8b039ab634f4@gmail.com

>  include/erofs/compress.h |  2 ++
>  lib/compressor.c         | 23 ++++++++++++++---------
>  lib/compressor.h         |  1 +
>  lib/compressor_lz4.c     |  1 +
>  lib/compressor_lz4hc.c   |  1 +
>  mkfs/main.c              | 15 +++++++++++++++
>  6 files changed, 34 insertions(+), 9 deletions(-)
> 
> diff --git a/include/erofs/compress.h b/include/erofs/compress.h
> index e0abb8f..fa91873 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 8cc2f43..6502437 100644
> --- a/lib/compressor.c
> +++ b/lib/compressor.c
> @@ -12,6 +12,15 @@
>  
>  #define EROFS_CONFIG_COMPR_DEF_BOUNDARY		(128)
>  
> +static struct erofs_compressor *compressors[] = {
> +#if LZ4_ENABLED
> +#if LZ4HC_ENABLED
> +		&erofs_compressor_lz4hc,
> +#endif
> +		&erofs_compressor_lz4,
> +#endif
> +};
> +
>  int erofs_compress_destsize(struct erofs_compress *c,
>  			    int compression_level,
>  			    void *src,
> @@ -36,18 +45,14 @@ int erofs_compress_destsize(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;

no need extra parentheses

	return i >= ARRAY_SIZE(compressors) ? NULL : compressors[i]->name;

> +}
> +
>  int erofs_compressor_init(struct erofs_compress *c,
>  			  char *alg_name)
>  {
> -	static struct erofs_compressor *compressors[] = {
> -#if LZ4_ENABLED
> -#if LZ4HC_ENABLED
> -		&erofs_compressor_lz4hc,
> -#endif
> -		&erofs_compressor_lz4,
> -#endif
> -	};
> -
>  	int ret, i;
>  
>  	/* should be written in "minimum compression ratio * 100" */
> diff --git a/lib/compressor.h b/lib/compressor.h
> index 6429b2a..4b76c4c 100644
> --- a/lib/compressor.h
> +++ b/lib/compressor.h
> @@ -14,6 +14,7 @@
>  struct erofs_compress;
>  
>  struct erofs_compressor {
> +	const char *name;

add a blank line?

>  	int default_level;
>  	int best_level;
>  
> diff --git a/lib/compressor_lz4.c b/lib/compressor_lz4.c
> index 0d33223..a9cbb80 100644
> --- a/lib/compressor_lz4.c
> +++ b/lib/compressor_lz4.c
> @@ -39,6 +39,7 @@ static int compressor_lz4_init(struct erofs_compress *c,

How about moving
 32 static int compressor_lz4_init(struct erofs_compress *c,
 33                                  char *alg_name)
 34 {
 35         if (alg_name && strcmp(alg_name, "lz4"))
 36                 return -EINVAL;

to compress.c?

>  }
>  
>  struct erofs_compressor erofs_compressor_lz4 = {
> +	.name = "lz4",
>  	.default_level = 0,
>  	.best_level = 0,
>  	.init = compressor_lz4_init,
> diff --git a/lib/compressor_lz4hc.c b/lib/compressor_lz4hc.c
> index 14e0175..a160c1a 100644
> --- a/lib/compressor_lz4hc.c
> +++ b/lib/compressor_lz4hc.c
> @@ -52,6 +52,7 @@ static int compressor_lz4hc_init(struct erofs_compress *c,

ditto.

Thanks,
Gao Xiang

>  }
>  
>  struct erofs_compressor erofs_compressor_lz4hc = {
> +	.name = "lz4hc",
>  	.default_level = LZ4HC_CLEVEL_DEFAULT,
>  	.best_level = LZ4HC_CLEVEL_MAX,
>  	.init = compressor_lz4hc_init,
> diff --git a/mkfs/main.c b/mkfs/main.c
> index 31cf1c2..1161b3f 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)
> -- 
> 2.17.1
> 

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH v3] erofs-utils: list available compressors for help command
  2019-10-22 16:50     ` Gao Xiang via Linux-erofs
@ 2019-10-22 18:59       ` " Gao Xiang via Linux-erofs
  0 siblings, 0 replies; 5+ messages in thread
From: Gao Xiang via Linux-erofs @ 2019-10-22 18:59 UTC (permalink / raw)
  To: Li Guifu, linux-erofs; +Cc: Miao Xie

From: Gao Xiang <gaoxiang25@huawei.com>

Users can get knowledge of supported compression
algorithms then.

Signed-off-by: Gao Xiang <gaoxiang25@huawei.com>
Signed-off-by: Li Guifu <blucerlee@gmail.com>
Signed-off-by: Gao Xiang <hsiangkao@aol.com>
---
 include/erofs/compress.h |  2 ++
 lib/compressor.c         | 29 ++++++++++++++++++-----------
 lib/compressor.h         |  4 +++-
 lib/compressor_lz4.c     |  6 ++----
 lib/compressor_lz4hc.c   |  7 ++-----
 mkfs/main.c              | 15 +++++++++++++++
 6 files changed, 42 insertions(+), 21 deletions(-)

diff --git a/include/erofs/compress.h b/include/erofs/compress.h
index e0abb8f..fa91873 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 8cc2f43..b2434e0 100644
--- a/lib/compressor.c
+++ b/lib/compressor.c
@@ -12,6 +12,15 @@
 
 #define EROFS_CONFIG_COMPR_DEF_BOUNDARY		(128)
 
+static struct erofs_compressor *compressors[] = {
+#if LZ4_ENABLED
+#if LZ4HC_ENABLED
+		&erofs_compressor_lz4hc,
+#endif
+		&erofs_compressor_lz4,
+#endif
+};
+
 int erofs_compress_destsize(struct erofs_compress *c,
 			    int compression_level,
 			    void *src,
@@ -36,18 +45,13 @@ int erofs_compress_destsize(struct erofs_compress *c,
 	return ret;
 }
 
-int erofs_compressor_init(struct erofs_compress *c,
-			  char *alg_name)
+const char *z_erofs_list_available_compressors(unsigned int i)
 {
-	static struct erofs_compressor *compressors[] = {
-#if LZ4_ENABLED
-#if LZ4HC_ENABLED
-		&erofs_compressor_lz4hc,
-#endif
-		&erofs_compressor_lz4,
-#endif
-	};
+	return i >= ARRAY_SIZE(compressors) ? NULL : compressors[i]->name;
+}
 
+int erofs_compressor_init(struct erofs_compress *c, char *alg_name)
+{
 	int ret, i;
 
 	/* should be written in "minimum compression ratio * 100" */
@@ -65,7 +69,10 @@ int erofs_compressor_init(struct erofs_compress *c,
 
 	ret = -EINVAL;
 	for (i = 0; i < ARRAY_SIZE(compressors); ++i) {
-		ret = compressors[i]->init(c, alg_name);
+		if (alg_name && strcmp(alg_name, compressors[i]->name))
+			continue;
+
+		ret = compressors[i]->init(c);
 		if (!ret) {
 			DBG_BUGON(!c->alg);
 			return 0;
diff --git a/lib/compressor.h b/lib/compressor.h
index 6429b2a..b2471c4 100644
--- a/lib/compressor.h
+++ b/lib/compressor.h
@@ -14,10 +14,12 @@
 struct erofs_compress;
 
 struct erofs_compressor {
+	const char *name;
+
 	int default_level;
 	int best_level;
 
-	int (*init)(struct erofs_compress *c, char *alg_name);
+	int (*init)(struct erofs_compress *c);
 	int (*exit)(struct erofs_compress *c);
 
 	int (*compress_destsize)(struct erofs_compress *c,
diff --git a/lib/compressor_lz4.c b/lib/compressor_lz4.c
index 0d33223..8540a0d 100644
--- a/lib/compressor_lz4.c
+++ b/lib/compressor_lz4.c
@@ -29,16 +29,14 @@ static int compressor_lz4_exit(struct erofs_compress *c)
 	return 0;
 }
 
-static int compressor_lz4_init(struct erofs_compress *c,
-				 char *alg_name)
+static int compressor_lz4_init(struct erofs_compress *c)
 {
-	if (alg_name && strcmp(alg_name, "lz4"))
-		return -EINVAL;
 	c->alg = &erofs_compressor_lz4;
 	return 0;
 }
 
 struct erofs_compressor erofs_compressor_lz4 = {
+	.name = "lz4",
 	.default_level = 0,
 	.best_level = 0,
 	.init = compressor_lz4_init,
diff --git a/lib/compressor_lz4hc.c b/lib/compressor_lz4hc.c
index 14e0175..6680563 100644
--- a/lib/compressor_lz4hc.c
+++ b/lib/compressor_lz4hc.c
@@ -37,12 +37,8 @@ static int compressor_lz4hc_exit(struct erofs_compress *c)
 	return 0;
 }
 
-static int compressor_lz4hc_init(struct erofs_compress *c,
-				 char *alg_name)
+static int compressor_lz4hc_init(struct erofs_compress *c)
 {
-	if (alg_name && strcmp(alg_name, "lz4hc"))
-		return -EINVAL;
-
 	c->alg = &erofs_compressor_lz4hc;
 
 	c->private_data = LZ4_createStreamHC();
@@ -52,6 +48,7 @@ static int compressor_lz4hc_init(struct erofs_compress *c,
 }
 
 struct erofs_compressor erofs_compressor_lz4hc = {
+	.name = "lz4hc",
 	.default_level = LZ4HC_CLEVEL_DEFAULT,
 	.best_level = LZ4HC_CLEVEL_MAX,
 	.init = compressor_lz4hc_init,
diff --git a/mkfs/main.c b/mkfs/main.c
index 31cf1c2..1161b3f 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)
-- 
2.17.1


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, back to index

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-10-22  4:20 [PATCH] erofs-utils: list available compressors for help command Gao Xiang
2019-10-22 16:05 ` Li Guifu
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

Linux-EROFS Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-erofs/0 linux-erofs/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-erofs linux-erofs/ https://lore.kernel.org/linux-erofs \
		linux-erofs@lists.ozlabs.org linux-erofs@ozlabs.org
	public-inbox-index linux-erofs

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.ozlabs.lists.linux-erofs


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git