Skip to content

Commit 197e329

Browse files
Luke T. Shumakerhsiangkao
authored andcommitted
erofs-utils: improve the usage and version text of non-fuse commands
For each command: - Change the format of --help to be closer to the usual GNU format - Have the --version text mention that it is part of erofs-utils - Include compile-time feature flags in -V - Have --help and --version print on stdout not stderr - Exit with 0 from --help and --version - Have flag errors print a message saying to use --help instead of printing the full help text For fsck.erofs: - Consolidate the descriptions of --[no-]preserve[-<owner|perms> - Clarify the range that -d accepts For mkfs.erofs: - Print supported algorithms and their level ranges+defaults - Clarify the range that -d accepts For mkfs.erofs to have access to the algorithms' level ranges and defaults, it is necessary to modify z_erofs_list_available_compressors() to return the full `struct erofs_algorithm` instead of just the `->name`. Signed-off-by: Luke T. Shumaker <lukeshu@umorpha.io> Link: https://lore.kernel.org/r/20231102193122.140921-3-lukeshu@lukeshu.com Signed-off-by: Gao Xiang <hsiangkao@linux.alibaba.com>
1 parent f528b82 commit 197e329

File tree

7 files changed

+163
-111
lines changed

7 files changed

+163
-111
lines changed

dump/main.c

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -106,25 +106,31 @@ static struct erofsdump_feature feature_lists[] = {
106106

107107
static int erofsdump_readdir(struct erofs_dir_context *ctx);
108108

109-
static void usage(void)
109+
static void usage(int argc, char **argv)
110110
{
111-
fputs("usage: [options] IMAGE\n\n"
112-
"Dump erofs layout from IMAGE, and [options] are:\n"
113-
" -S show statistic information of the image\n"
114-
" -V, --version print the version number of dump.erofs and exit.\n"
115-
" -e show extent info (INODE required)\n"
116-
" -s show information about superblock\n"
117-
" --device=X specify an extra device to be used together\n"
118-
" --ls show directory contents (INODE required)\n"
119-
" --nid=# show the target inode info of nid #\n"
120-
" --path=X show the target inode info of path X\n"
121-
" -h, --help display this help and exit.\n",
122-
stderr);
111+
// " 1 2 3 4 5 6 7 8 "
112+
// "12345678901234567890123456789012345678901234567890123456789012345678901234567890\n"
113+
printf(
114+
"Usage: %s [OPTIONS] IMAGE\n"
115+
"Dump erofs layout from IMAGE.\n"
116+
"\n"
117+
"General options:\n"
118+
" -V, --version print the version number of dump.erofs and exit\n"
119+
" -h, --help display this help and exit\n"
120+
"\n"
121+
" -S show statistic information of the image\n"
122+
" -e show extent info (INODE required)\n"
123+
" -s show information about superblock\n"
124+
" --device=X specify an extra device to be used together\n"
125+
" --ls show directory contents (INODE required)\n"
126+
" --nid=# show the target inode info of nid #\n"
127+
" --path=X show the target inode info of path X\n",
128+
argv[0]);
123129
}
124130

125131
static void erofsdump_print_version(void)
126132
{
127-
printf("dump.erofs %s\n", cfg.c_version);
133+
printf("dump.erofs (erofs-utils) %s\n", cfg.c_version);
128134
}
129135

130136
static int erofsdump_parse_options_cfg(int argc, char **argv)
@@ -155,7 +161,7 @@ static int erofsdump_parse_options_cfg(int argc, char **argv)
155161
++dumpcfg.totalshow;
156162
break;
157163
case 'h':
158-
usage();
164+
usage(argc, argv);
159165
exit(0);
160166
case 3:
161167
err = blob_open_ro(&sbi, optarg);
@@ -663,7 +669,7 @@ int main(int argc, char **argv)
663669
err = erofsdump_parse_options_cfg(argc, argv);
664670
if (err) {
665671
if (err == -EINVAL)
666-
usage();
672+
fprintf(stderr, "Try '%s --help' for more information.\n", argv[0]);
667673
goto exit;
668674
}
669675

@@ -690,7 +696,7 @@ int main(int argc, char **argv)
690696
erofsdump_print_statistic();
691697

692698
if (dumpcfg.show_extent && !dumpcfg.show_inode) {
693-
usage();
699+
fprintf(stderr, "Try '%s --help' for more information.\n", argv[0]);
694700
goto exit_put_super;
695701
}
696702

fsck/main.c

Lines changed: 41 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include "erofs/compress.h"
1515
#include "erofs/decompress.h"
1616
#include "erofs/dir.h"
17+
#include "../lib/compressor.h"
1718

1819
static int erofsfsck_check_inode(erofs_nid_t pnid, erofs_nid_t nid);
1920

@@ -64,45 +65,58 @@ static void print_available_decompressors(FILE *f, const char *delim)
6465
{
6566
int i = 0;
6667
bool comma = false;
67-
const char *s;
68+
const struct erofs_algorithm *s;
6869

6970
while ((s = z_erofs_list_available_compressors(&i)) != NULL) {
7071
if (comma)
7172
fputs(delim, f);
72-
fputs(s, f);
73+
fputs(s->name, f);
7374
comma = true;
7475
}
7576
fputc('\n', f);
7677
}
7778

78-
static void usage(void)
79+
static void usage(int argc, char **argv)
7980
{
80-
fputs("usage: [options] IMAGE\n\n"
81-
"Check erofs filesystem compatibility and integrity of IMAGE, and [options] are:\n"
82-
" -V, --version print the version number of fsck.erofs and exit\n"
83-
" -d# set output message level to # (maximum 9)\n"
84-
" -p print total compression ratio of all files\n"
85-
" --device=X specify an extra device to be used together\n"
86-
" --extract[=X] check if all files are well encoded, optionally extract to X\n"
87-
" -h, --help display this help and exit\n"
88-
"\nExtraction options (--extract=X is required):\n"
89-
" --force allow extracting to root\n"
90-
" --overwrite overwrite files that already exist\n"
91-
" --preserve extract with the same ownership and permissions as on the filesystem\n"
92-
" (default for superuser)\n"
93-
" --preserve-owner extract with the same ownership as on the filesystem\n"
94-
" --preserve-perms extract with the same permissions as on the filesystem\n"
95-
" --no-preserve extract as yourself and apply user's umask on permissions\n"
96-
" (default for ordinary users)\n"
97-
" --no-preserve-owner extract as yourself\n"
98-
" --no-preserve-perms apply user's umask when extracting permissions\n"
99-
"\nSupported algorithms are: ", stderr);
100-
print_available_decompressors(stderr, ", ");
81+
// " 1 2 3 4 5 6 7 8 "
82+
// "12345678901234567890123456789012345678901234567890123456789012345678901234567890\n"
83+
printf(
84+
"Usage: %s [OPTIONS] IMAGE\n"
85+
"Check erofs filesystem compatibility and integrity of IMAGE.\n"
86+
"\n"
87+
"This version of fsck.erofs is capable of checking images that use any of the\n"
88+
"following algorithms: ", argv[0]);
89+
print_available_decompressors(stdout, ", ");
90+
printf("\n"
91+
"General options:\n"
92+
" -V, --version print the version number of fsck.erofs and exit\n"
93+
" -h, --help display this help and exit\n"
94+
"\n"
95+
" -d<0-9> set output verbosity; 0=quiet, 9=verbose (default=%i)\n"
96+
" -p print total compression ratio of all files\n"
97+
" --device=X specify an extra device to be used together\n"
98+
" --extract[=X] check if all files are well encoded, optionally\n"
99+
" extract to X\n"
100+
"\n"
101+
"Extraction options (--extract=X is required):\n"
102+
" --force allow extracting to root\n"
103+
" --overwrite overwrite files that already exist\n"
104+
" --[no-]preserve same as --[no-]preserve-owner --[no-]preserve-perms\n"
105+
" --[no-]preserve-owner whether to preserve the ownership from the\n"
106+
" filesystem (default for superuser), or to extract as\n"
107+
" yourself (default for ordinary users)\n"
108+
" --[no-]preserve-perms whether to preserve the exact permissions from the\n"
109+
" filesystem without applying umask (default for\n"
110+
" superuser), or to modify the permissions by applying\n"
111+
" umask (default for ordinary users)\n",
112+
EROFS_WARN);
101113
}
102114

103115
static void erofsfsck_print_version(void)
104116
{
105-
printf("fsck.erofs %s\n", cfg.c_version);
117+
printf("fsck.erofs (erofs-utils) %s\navailable decompressors: ",
118+
cfg.c_version);
119+
print_available_decompressors(stdout, ", ");
106120
}
107121

108122
static int erofsfsck_parse_options_cfg(int argc, char **argv)
@@ -128,7 +142,7 @@ static int erofsfsck_parse_options_cfg(int argc, char **argv)
128142
fsckcfg.print_comp_ratio = true;
129143
break;
130144
case 'h':
131-
usage();
145+
usage(argc, argv);
132146
exit(0);
133147
case 2:
134148
fsckcfg.check_decomp = true;
@@ -919,7 +933,7 @@ int main(int argc, char *argv[])
919933
err = erofsfsck_parse_options_cfg(argc, argv);
920934
if (err) {
921935
if (err == -EINVAL)
922-
usage();
936+
fprintf(stderr, "Try '%s --help' for more information.\n", argv[0]);
923937
goto exit;
924938
}
925939

include/erofs/compress.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ int z_erofs_compress_init(struct erofs_sb_info *sbi,
2424
int z_erofs_compress_exit(void);
2525

2626
const char *z_erofs_list_supported_algorithms(int i, unsigned int *mask);
27-
const char *z_erofs_list_available_compressors(int *i);
27+
const struct erofs_algorithm *z_erofs_list_available_compressors(int *i);
2828

2929
static inline bool erofs_is_packed_inode(struct erofs_inode *inode)
3030
{

lib/compressor.c

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,7 @@
88
#include "compressor.h"
99
#include "erofs/print.h"
1010

11-
static const struct erofs_algorithm {
12-
char *name;
13-
const struct erofs_compressor *c;
14-
unsigned int id;
15-
16-
/* its name won't be shown as a supported algorithm */
17-
bool optimisor;
18-
} erofs_algs[] = {
11+
static const struct erofs_algorithm erofs_algs[] = {
1912
{ "lz4",
2013
#if LZ4_ENABLED
2114
&erofs_compressor_lz4,
@@ -63,12 +56,12 @@ const char *z_erofs_list_supported_algorithms(int i, unsigned int *mask)
6356
return "";
6457
}
6558

66-
const char *z_erofs_list_available_compressors(int *i)
59+
const struct erofs_algorithm *z_erofs_list_available_compressors(int *i)
6760
{
6861
for (;*i < ARRAY_SIZE(erofs_algs); ++*i) {
6962
if (!erofs_algs[*i].c)
7063
continue;
71-
return erofs_algs[(*i)++].name;
64+
return &erofs_algs[(*i)++];
7265
}
7366
return NULL;
7467
}

lib/compressor.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,14 @@ struct erofs_compressor {
2424
void *dst, unsigned int dstsize);
2525
};
2626

27-
struct erofs_algorithm;
27+
struct erofs_algorithm {
28+
char *name;
29+
const struct erofs_compressor *c;
30+
unsigned int id;
31+
32+
/* its name won't be shown as a supported algorithm */
33+
bool optimisor;
34+
};
2835

2936
struct erofs_compress {
3037
struct erofs_sb_info *sbi;

man/mkfs.erofs.1

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,12 @@ from \fISOURCE\fR directory.
2121
.SH OPTIONS
2222
.TP
2323
.BI "\-z " compression-algorithm \fR[\fP, # \fR][\fP: ... \fR]\fP
24-
Set a primary algorithm for data compression, which can be set with an optional
25-
compression level (1 to 12 for LZ4HC, 0 to 9 for LZMA and 100 to 109 for LZMA
26-
extreme compression) separated by a comma. Alternative algorithms could be
27-
specified and separated by colons.
24+
Set a primary algorithm for data compression, which can be set with an
25+
optional compression level. Alternative algorithms could be specified
26+
and separated by colons. See the output of
27+
.B mkfs.erofs \-\-help
28+
for a listing of the algorithms that \fBmkfs.erofs\fR is compiled with
29+
and what their respective level ranges are.
2830
.TP
2931
.BI "\-b " block-size
3032
Set the fundamental block size of the filesystem in bytes. In other words,

0 commit comments

Comments
 (0)