From: Gao Xiang <gaoxiang25@huawei.com>
To: Li Guifu <bluce.liguifu@huawei.com>
Cc: linux-erofs@lists.ozlabs.org
Subject: [PATCH] erofs-utils: list available compressors for help command
Date: Tue, 22 Oct 2019 12:20:02 +0800 [thread overview]
Message-ID: <20191022042002.61999-1-gaoxiang25@huawei.com> (raw)
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
next reply other threads:[~2019-10-22 4:17 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-10-22 4:20 Gao Xiang [this message]
2019-10-22 16:05 ` [PATCH] erofs-utils: list available compressors for help command 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
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=20191022042002.61999-1-gaoxiang25@huawei.com \
--to=gaoxiang25@huawei.com \
--cc=bluce.liguifu@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 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).