From: Li Guifu <blucerlee@gmail.com>
To: linux-erofs@lists.ozlabs.org
Subject: [PATCH v2] erofs-utils: list available compressors for help command
Date: Wed, 23 Oct 2019 00:36:16 +0800 [thread overview]
Message-ID: <20191022163616.4118-1-blucerlee@gmail.com> (raw)
In-Reply-To: <6a0f0b47-1bb7-7e82-770f-8b039ab634f4@gmail.com>
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
next prev parent reply other threads:[~2019-10-22 16:36 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
2019-10-22 16:36 ` Li Guifu [this message]
2019-10-22 16:50 ` [PATCH v2] " 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=20191022163616.4118-1-blucerlee@gmail.com \
--to=blucerlee@gmail.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