[PATCH v2 2/4] erofs-utils: lib: unify all identical compressor print function
Guo Xuenan
guoxuenan at huawei.com
Sun Jul 23 01:04:32 AEST 2023
{dump,fsck}.erofs use the same compressor print function,
available compressors means which algothrims are currently
supported by binary tools.
supported compressors including all algothrims that are ready
for your erofs binary tools.
Signed-off-by: Guo Xuenan <guoxuenan at huawei.com>
---
fsck/main.c | 15 +--------------
include/erofs/compress.h | 3 ++-
lib/compressor.c | 41 ++++++++++++++++++++++++++++++++++++----
mkfs/main.c | 15 +--------------
4 files changed, 41 insertions(+), 33 deletions(-)
diff --git a/fsck/main.c b/fsck/main.c
index 39a5534..6e0dcb5 100644
--- a/fsck/main.c
+++ b/fsck/main.c
@@ -59,19 +59,6 @@ struct erofsfsck_hardlink_entry {
static struct list_head erofsfsck_link_hashtable[NR_HARDLINK_HASHTABLE];
-static void print_available_decompressors(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)
{
fputs("usage: [options] IMAGE\n\n"
@@ -94,7 +81,7 @@ static void usage(void)
" --no-preserve-owner extract as yourself\n"
" --no-preserve-perms apply user's umask when extracting permissions\n"
"\nSupported algorithms are: ", stderr);
- print_available_decompressors(stderr, ", ");
+ erofs_print_available_compressors(stderr);
}
static void erofsfsck_print_version(void)
diff --git a/include/erofs/compress.h b/include/erofs/compress.h
index f1ad84a..67bedf2 100644
--- a/include/erofs/compress.h
+++ b/include/erofs/compress.h
@@ -23,7 +23,8 @@ int z_erofs_compress_init(struct erofs_sb_info *sbi,
struct erofs_buffer_head *bh);
int z_erofs_compress_exit(void);
-const char *z_erofs_list_available_compressors(unsigned int i);
+void erofs_print_available_compressors(FILE *f);
+void erofs_print_supported_compressors(FILE *f, unsigned int mask);
static inline bool erofs_is_packed_inode(struct erofs_inode *inode)
{
diff --git a/lib/compressor.c b/lib/compressor.c
index 6288297..2cc2464 100644
--- a/lib/compressor.c
+++ b/lib/compressor.c
@@ -60,11 +60,13 @@ static void erofs_init_compressor(struct erofs_sb_info *sbi,
static void erofs_compressor_register(struct erofs_sb_info *sbi,
const char *name, const struct erofs_compressor *alg)
{
+ struct erofs_supported_algorithm *cur;
int i;
for (i = 0; i < ARRAY_SIZE(erofs_supported_algorithms); i++) {
- if (!strcmp(erofs_supported_algorithms[i].name, name)) {
- erofs_init_compressor(sbi, &erofs_supported_algorithms[i].handle, alg);
+ cur = &erofs_supported_algorithms[i];
+ if (!strcmp(cur->name, name)) {
+ erofs_init_compressor(sbi, &cur->handle, alg);
return;
}
}
@@ -116,9 +118,40 @@ int erofs_compress_destsize(const struct erofs_compress *c,
return ret;
}
-const char *z_erofs_list_available_compressors(unsigned int i)
+void erofs_print_supported_compressors(FILE *f, unsigned int mask)
{
- return i >= ARRAY_SIZE(compressors) ? NULL : compressors[i]->name;
+ unsigned int algnum = ARRAY_SIZE(erofs_supported_algorithms);
+ unsigned int i = 0;
+ int comma = false;
+ const char *s;
+
+ while (i < algnum) {
+ s = erofs_supported_algorithms[i].name;
+ if (s && (mask & (1 << erofs_supported_algorithms[i++].algtype))) {
+ if (comma)
+ fputs(", ", f);
+ else
+ comma = true;
+ fputs(s, f);
+ }
+ }
+ fputc('\n', f);
+}
+
+void erofs_print_available_compressors(FILE *f)
+{
+ unsigned int algnum = ARRAY_SIZE(erofs_supported_algorithms);
+ unsigned int i = 0;
+ const char *s;
+
+ while (i < algnum &&
+ erofs_supported_algorithms[i].handle.alg &&
+ (s = erofs_supported_algorithms[i].name)) {
+ if (i++)
+ fputs(", ", f);
+ fputs(s, f);
+ }
+ fputc('\n', f);
}
int erofs_compressor_setlevel(struct erofs_compress *c, int compression_level)
diff --git a/mkfs/main.c b/mkfs/main.c
index 92a07fd..54e7d99 100644
--- a/mkfs/main.c
+++ b/mkfs/main.c
@@ -66,19 +66,6 @@ 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)
{
fputs("usage: [options] FILE DIRECTORY\n\n"
@@ -126,7 +113,7 @@ static void usage(void)
" --block-list-file=X X=block_list file\n"
#endif
"\nAvailable compressors are: ", stderr);
- print_available_compressors(stderr, ", ");
+ erofs_print_available_compressors(stderr);
}
static unsigned int pclustersize_packed, pclustersize_max;
--
2.34.3
More information about the Linux-erofs
mailing list