linux-erofs.lists.ozlabs.org archive mirror
 help / color / mirror / 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 related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2019-10-22 19:03 UTC | newest]

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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).