Skip to contentSkip to conversation

erofs-utils: Address doc and flag-parsing snags

PATCH In review Luke T. Shumaker 2 participants 5 messages Nov 2, 2023 – Nov 5, 2023 Library code

lore
Share & tools
lore
#0 lore raw

cover erofs-utils: Address doc and flag-parsing snags

From: "Luke T. Shumaker" <[email protected]>

Hi all,

This patchset addresses snags that I hit while adopting erofs for our system images.

- The first patch is really just setting a baseline for the next two.

- The second patch is improving the --help text to address the snag that I had to read the source code to understand how to use the mkfs.erofs -z flag, and also setting the stage for the third patch. In doing this I broadly improved the --help text overall, not just for mkfs.erofs.

- The third patch is adding no-op -a, -A, and -y flags to fsck.erofs, to address the snag that I was seeing errors in the boot scroll.

I didn't touch erofsfuse in any of these, not because it isn't worthy of the changes from the first two patches, just that I decided it would have been too much work at the moment.

Luke T. Shumaker (3):
erofs-utils: have each non-fuse command take -h, --help, -V, and
--version
erofs-utils: improve the usage and version text of non-fuse commands
erofs-utils: fsck: Add -a, -A, and -y flags

 dump/main.c              |  47 +++++++------
 fsck/main.c              |  81 ++++++++++++++--------
 include/erofs/compress.h |   2 +-
 lib/compressor.c         |  13 +---
 lib/compressor.h         |   9 ++-
 man/dump.erofs.1         |   5 +-
 man/fsck.erofs.1         |   8 ++-
 man/mkfs.erofs.1         |  15 ++--
 mkfs/main.c              | 144 +++++++++++++++++++++++++--------------
 9 files changed, 202 insertions(+), 122 deletions(-)
Signature · 2 lines
Happy hacking,
~ Luke T. Shumaker
#1 lore raw

PATCH 1/3 erofs-utils: have each non-fuse command take -h, --help, -V, and --version

From: "Luke T. Shumaker" <[email protected]>

Consistency is nice.

erofsfuse isn't included here because adjusting its flag handling is more involved because of the interaction with libfuse; I anticipate similar changes to erofsfuse in a future patchset.

---
 dump/main.c      | 11 ++++++-----
 fsck/main.c      | 11 ++++++-----
 man/dump.erofs.1 |  5 ++++-
 man/fsck.erofs.1 |  4 ++--
 man/mkfs.erofs.1 |  5 ++++-
 mkfs/main.c      | 18 ++++++++++++++----
 6 files changed, 36 insertions(+), 18 deletions(-)
dump/main.c +6 -5
index 5425b7b..a952f32 100644
@@ -74,7 +74,8 @@ struct erofs_statistics {
 static struct erofs_statistics stats;
 
 static struct option long_options[] = {
-	{"help", no_argument, NULL, 1},
+	{"version", no_argument, NULL, 'V'},
+	{"help", no_argument, NULL, 'h'},
 	{"nid", required_argument, NULL, 2},
 	{"device", required_argument, NULL, 3},
 	{"path", required_argument, NULL, 4},
@@ -110,14 +111,14 @@ static void usage(void)
 	fputs("usage: [options] IMAGE\n\n"
 	      "Dump erofs layout from IMAGE, and [options] are:\n"
 	      " -S              show statistic information of the image\n"
-	      " -V              print the version number of dump.erofs and exit.\n"
+	      " -V, --version   print the version number of dump.erofs and exit.\n"
 	      " -e              show extent info (INODE required)\n"
 	      " -s              show information about superblock\n"
 	      " --device=X      specify an extra device to be used together\n"
 	      " --ls            show directory contents (INODE required)\n"
 	      " --nid=#         show the target inode info of nid #\n"
 	      " --path=X        show the target inode info of path X\n"
-	      " --help          display this help and exit.\n",
+	      " -h, --help      display this help and exit.\n",
 	      stderr);
 }
 
@@ -130,7 +131,7 @@ static int erofsdump_parse_options_cfg(int argc, char **argv)
 {
 	int opt, err;
 
-	while ((opt = getopt_long(argc, argv, "SVes",
+	while ((opt = getopt_long(argc, argv, "SVesh",
 				  long_options, NULL)) != -1) {
 		switch (opt) {
 		case 'e':
@@ -153,7 +154,7 @@ static int erofsdump_parse_options_cfg(int argc, char **argv)
 			dumpcfg.nid = (erofs_nid_t)atoll(optarg);
 			++dumpcfg.totalshow;
 			break;
-		case 1:
+		case 'h':
 			usage();
 			exit(0);
 		case 3:
fsck/main.c +6 -5
index 3f86da4..2ac3547 100644
@@ -35,7 +35,8 @@ struct erofsfsck_cfg {
 static struct erofsfsck_cfg fsckcfg;
 
 static struct option long_options[] = {
-	{"help", no_argument, 0, 1},
+	{"version", no_argument, 0, 'V'},
+	{"help", no_argument, 0, 'h'},
 	{"extract", optional_argument, 0, 2},
 	{"device", required_argument, 0, 3},
 	{"force", no_argument, 0, 4},
@@ -78,12 +79,12 @@ static void usage(void)
 {
 	fputs("usage: [options] IMAGE\n\n"
 	      "Check erofs filesystem compatibility and integrity of IMAGE, and [options] are:\n"
-	      " -V                     print the version number of fsck.erofs and exit\n"
+	      " -V, --version          print the version number of fsck.erofs and exit\n"
 	      " -d#                    set output message level to # (maximum 9)\n"
 	      " -p                     print total compression ratio of all files\n"
 	      " --device=X             specify an extra device to be used together\n"
 	      " --extract[=X]          check if all files are well encoded, optionally extract to X\n"
-	      " --help                 display this help and exit\n"
+	      " -h, --help             display this help and exit\n"
 	      "\nExtraction options (--extract=X is required):\n"
 	      " --force                allow extracting to root\n"
 	      " --overwrite            overwrite files that already exist\n"
@@ -109,7 +110,7 @@ static int erofsfsck_parse_options_cfg(int argc, char **argv)
 	int opt, ret;
 	bool has_opt_preserve = false;
 
-	while ((opt = getopt_long(argc, argv, "Vd:p",
+	while ((opt = getopt_long(argc, argv, "Vd:ph",
 				  long_options, NULL)) != -1) {
 		switch (opt) {
 		case 'V':
@@ -126,7 +127,7 @@ static int erofsfsck_parse_options_cfg(int argc, char **argv)
 		case 'p':
 			fsckcfg.print_comp_ratio = true;
 			break;
-		case 1:
+		case 'h':
 			usage();
 			exit(0);
 		case 2:
man/dump.erofs.1 +4 -1
index 7316f4b..6237ead 100644
@@ -45,9 +45,12 @@ or
 .I path
 required.
 .TP
-.BI \-V
+\fB\-V\fR, \fB\-\-version\fR
 Print the version number and exit.
 .TP
+\fB\-h\fR, \fB\-\-help\fR
+Display help string and exit.
+.TP
 .BI \-s
 Show superblock information.
 This is the default if no options are specified.
man/fsck.erofs.1 +2 -2
index 364219a..a226995 100644
@@ -10,7 +10,7 @@ fsck.erofs is used to scan an EROFS filesystem \fIIMAGE\fR and check the
 integrity of it.
 .SH OPTIONS
 .TP
-.B \-V
+\fB\-V\fR, \fB\-\-version\fR
 Print the version number of fsck.erofs and exit.
 .TP
 .BI "\-d " #
@@ -32,7 +32,7 @@ Check if all files are well encoded. This read all compressed files,
 and hence create more I/O load,
 so it might take too much time depending on the image.
 .TP
-.B \-\-help
+\fB\-h\fR, \fB\-\-help\fR
 Display help string and exit.
 .SH AUTHOR
 This version of \fBfsck.erofs\fR is written by
man/mkfs.erofs.1 +4 -1
index 00ac2ac..970ff28 100644
@@ -163,7 +163,10 @@ set to \fIGID\fR + \fIGID-OFFSET\fR.
 .B \-\-gzip
 Filter tarball streams through gzip.
 .TP
-.B \-\-help
+\fB\-V\fR, \fB\-\-version\fR
+Print the version number and exit.
+.TP
+\fB\-h\fR, \fB\-\-help\fR
 Display help string and exit.
 .TP
 .B "\-\-ignore-mtime"
mkfs/main.c +14 -4
index 637d1b9..d86a548 100644
@@ -34,7 +34,8 @@
 #define EROFS_SUPER_END (EROFS_SUPER_OFFSET + sizeof(struct erofs_super_block))
 
 static struct option long_options[] = {
-	{"help", no_argument, 0, 1},
+	{"version", no_argument, 0, 'V'},
+	{"help", no_argument, 0, 'h'},
 	{"exclude-path", required_argument, NULL, 2},
 	{"exclude-regex", required_argument, NULL, 3},
 #ifdef HAVE_LIBSELINUX
@@ -91,6 +92,7 @@ static void usage(void)
 {
 	fputs("usage: [options] FILE SOURCE(s)\n"
 	      "Generate EROFS image (FILE) from DIRECTORY, TARBALL and/or EROFS images.  And [options] are:\n"
+	      " -V, --version         print the version number of mkfs.erofs and exit\n"
 	      " -b#                   set block size to # (# = page size by default)\n"
 	      " -d#                   set output message level to # (maximum 9)\n"
 	      " -x#                   set xattr tolerance to # (< 0, disable xattrs; default 2)\n"
@@ -117,7 +119,7 @@ static void usage(void)
 #ifdef HAVE_ZLIB
 	      " --gzip                try to filter the tarball stream through gzip\n"
 #endif
-	      " --help                display this help and exit\n"
+	      " -h, --help            display this help and exit\n"
 	      " --ignore-mtime        use build time instead of strict per-file modification time\n"
 	      " --max-extent-bytes=#  set maximum decompressed extent size # in bytes\n"
 	      " --preserve-mtime      keep per-file modification time strictly\n"
@@ -141,6 +143,11 @@ static void usage(void)
 	print_available_compressors(stderr, ", ");
 }
 
+static void version(void)
+{
+	printf("mkfs.erofs %s\n", cfg.c_version);
+}
+
 static unsigned int pclustersize_packed, pclustersize_max;
 static struct erofs_tarfile erofstar = {
 	.global.xattrs = LIST_HEAD_INIT(erofstar.global.xattrs)
@@ -309,7 +316,7 @@ static int mkfs_parse_options_cfg(int argc, char *argv[])
 	int opt, i, err;
 	bool quiet = false;
 
-	while ((opt = getopt_long(argc, argv, "C:E:L:T:U:b:d:x:z:",
+	while ((opt = getopt_long(argc, argv, "C:E:L:T:U:b:d:x:z:Vh",
 				  long_options, NULL)) != -1) {
 		switch (opt) {
 		case 'z':
@@ -534,7 +541,10 @@ static int mkfs_parse_options_cfg(int argc, char *argv[])
 		case 517:
 			gzip_supported = true;
 			break;
-		case 1:
+		case 'V':
+			version();
+			exit(0);
+		case 'h':
 			usage();
 			exit(0);
 
Signature · 1 line
2.42.0
#2 lore raw

PATCH 2/3 erofs-utils: improve the usage and version text of non-fuse commands

In reply to Luke T. Shumaker

From: "Luke T. Shumaker" <[email protected]>

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.

---
 dump/main.c              |  40 +++++++-----
 fsck/main.c              |  68 ++++++++++++--------
 include/erofs/compress.h |   2 +-
 lib/compressor.c         |  13 +---
 lib/compressor.h         |   9 ++-
 man/mkfs.erofs.1         |  10 +--
 mkfs/main.c              | 132 ++++++++++++++++++++++++---------------
 7 files changed, 163 insertions(+), 111 deletions(-)
dump/main.c +23 -17
index a952f32..293093d 100644
@@ -106,25 +106,31 @@ static struct erofsdump_feature feature_lists[] = {
 
 static int erofsdump_readdir(struct erofs_dir_context *ctx);
 
-static void usage(void)
+static void usage(int argc, char **argv)
 {
-	fputs("usage: [options] IMAGE\n\n"
-	      "Dump erofs layout from IMAGE, and [options] are:\n"
-	      " -S              show statistic information of the image\n"
-	      " -V, --version   print the version number of dump.erofs and exit.\n"
-	      " -e              show extent info (INODE required)\n"
-	      " -s              show information about superblock\n"
-	      " --device=X      specify an extra device to be used together\n"
-	      " --ls            show directory contents (INODE required)\n"
-	      " --nid=#         show the target inode info of nid #\n"
-	      " --path=X        show the target inode info of path X\n"
-	      " -h, --help      display this help and exit.\n",
-	      stderr);
+	//	"         1         2         3         4         5         6         7         8  "
+	//	"12345678901234567890123456789012345678901234567890123456789012345678901234567890\n"
+	printf(
+		"Usage: %s [OPTIONS] IMAGE\n"
+		"Dump erofs layout from IMAGE.\n"
+		"\n"
+		"General options:\n"
+		" -V, --version   print the version number of dump.erofs and exit\n"
+		" -h, --help      display this help and exit\n"
+		"\n"
+		" -S              show statistic information of the image\n"
+		" -e              show extent info (INODE required)\n"
+		" -s              show information about superblock\n"
+		" --device=X      specify an extra device to be used together\n"
+		" --ls            show directory contents (INODE required)\n"
+		" --nid=#         show the target inode info of nid #\n"
+		" --path=X        show the target inode info of path X\n",
+		argv[0]);
 }
 
 static void erofsdump_print_version(void)
 {
-	printf("dump.erofs %s\n", cfg.c_version);
+	printf("dump.erofs (erofs-utils) %s\n", cfg.c_version);
 }
 
 static int erofsdump_parse_options_cfg(int argc, char **argv)
@@ -155,7 +161,7 @@ static int erofsdump_parse_options_cfg(int argc, char **argv)
 			++dumpcfg.totalshow;
 			break;
 		case 'h':
-			usage();
+			usage(argc, argv);
 			exit(0);
 		case 3:
 			err = blob_open_ro(&sbi, optarg);
@@ -663,7 +669,7 @@ int main(int argc, char **argv)
 	err = erofsdump_parse_options_cfg(argc, argv);
 	if (err) {
 		if (err == -EINVAL)
-			usage();
+			fprintf(stderr, "Try '%s --help' for more information.\n", argv[0]);
 		goto exit;
 	}
 
@@ -690,7 +696,7 @@ int main(int argc, char **argv)
 		erofsdump_print_statistic();
 
 	if (dumpcfg.show_extent && !dumpcfg.show_inode) {
-		usage();
+		fprintf(stderr, "Try '%s --help' for more information.\n", argv[0]);
 		goto exit_put_super;
 	}
 
fsck/main.c +41 -27

106 lines not on this page · raw message

include/erofs/compress.h +1 -1
index 46cff03..046640b 100644
@@ -24,7 +24,7 @@ int z_erofs_compress_init(struct erofs_sb_info *sbi,
 int z_erofs_compress_exit(void);
 
 const char *z_erofs_list_supported_algorithms(int i, unsigned int *mask);
-const char *z_erofs_list_available_compressors(int *i);
+const struct erofs_algorithm *z_erofs_list_available_compressors(int *i);
 
 static inline bool erofs_is_packed_inode(struct erofs_inode *inode)
 {
lib/compressor.c +3 -10
index 93f5617..47079d4 100644
@@ -10,14 +10,7 @@
 
 #define EROFS_CONFIG_COMPR_DEF_BOUNDARY		(128)
 
-static const struct erofs_algorithm {
-	char *name;
-	const struct erofs_compressor *c;
-	unsigned int id;
-
-	/* its name won't be shown as a supported algorithm */
-	bool optimisor;
-} erofs_algs[] = {
+static const struct erofs_algorithm erofs_algs[] = {
 	{ "lz4",
 #if LZ4_ENABLED
 		&erofs_compressor_lz4,
@@ -65,12 +58,12 @@ const char *z_erofs_list_supported_algorithms(int i, unsigned int *mask)
 	return "";
 }
 
-const char *z_erofs_list_available_compressors(int *i)
+const struct erofs_algorithm *z_erofs_list_available_compressors(int *i)
 {
 	for (;*i < ARRAY_SIZE(erofs_algs); ++*i) {
 		if (!erofs_algs[*i].c)
 			continue;
-		return erofs_algs[(*i)++].name;
+		return &erofs_algs[(*i)++];
 	}
 	return NULL;
 }
lib/compressor.h +8 -1
index 9fa01d1..db848f1 100644
@@ -24,7 +24,14 @@ struct erofs_compressor {
 				 void *dst, unsigned int dstsize);
 };
 
-struct erofs_algorithm;
+struct erofs_algorithm {
+	char *name;
+	const struct erofs_compressor *c;
+	unsigned int id;
+
+	/* its name won't be shown as a supported algorithm */
+	bool optimisor;
+};
 
 struct erofs_compress {
 	struct erofs_sb_info *sbi;
man/mkfs.erofs.1 +6 -4
index 970ff28..45be11a 100644
@@ -21,10 +21,12 @@ from \fISOURCE\fR directory.
 .SH OPTIONS
 .TP
 .BI "\-z " compression-algorithm \fR[\fP, # \fR][\fP: ... \fR]\fP
-Set a primary algorithm for data compression, which can be set with an optional
-compression level (1 to 12 for LZ4HC, 0 to 9 for LZMA and 100 to 109 for LZMA
-extreme compression) separated by a comma.  Alternative algorithms could be
-specified and separated by colons.
+Set a primary algorithm for data compression, which can be set with an
+optional compression level. Alternative algorithms could be specified
+and separated by colons.  See the output of
+.B mkfs.erofs \-\-help
+for a listing of the algorithms that \fBmkfs.erofs\fR is compiled with
+and what their respective level ranges are.
 .TP
 .BI "\-b " block-size
 Set the fundamental block size of the filesystem in bytes.  In other words,
mkfs/main.c +81 -51

189 lines not on this page · raw message

Signature · 1 line
2.42.0
#3 lore raw

PATCH 3/3 erofs-utils: fsck: Add -a, -A, and -y flags

In reply to Luke T. Shumaker

From: "Luke T. Shumaker" <[email protected]>

Other fsck.${filesystem} commands generally take -a or -p and sometimes -A to automatically repair a filesystem, and -y to either repair agree to all prompts about repairing.

For example:

- fsck.ext{2,3,4} takes -a or -p to repair, and -y to agree
- fsck.xfs takes -y to repair; and -a, -A, or -p to silence a warning about repairing
- fsck.btrfs takes -a, -A, -p, or -y to silence a warning about repairing

So, like fsck.btrfs, we should accept these flags as no-ops, for compatibility with programs that expect to be able to pass these to fsck. In particular, Arch Linux's mkinitcpio (when fsck is enabled) unconditionally passes -a to fsck.

Naturally, I'd have liked to include '-p' in the list, but it already does something different for fsck.erofs. I'd like to call out the fsck.ext4 manual, which says:

-a This option does the same thing as the -p option. It is
provided for backwards compatibility only; it is suggested that people use -p option whenever possible.

---
 fsck/main.c      | 8 +++++++-
 man/fsck.erofs.1 | 4 ++++
 2 files changed, 11 insertions(+), 1 deletion(-)
fsck/main.c +7 -1
index aeea892..26cd131 100644
@@ -98,6 +98,8 @@ static void usage(int argc, char **argv)
 		" --extract[=X]          check if all files are well encoded, optionally\n"
 		"                        extract to X\n"
 		"\n"
+		" -a, -A, -y             no-op, for compatibility with fsck of other filesystems\n"
+		"\n"
 		"Extraction options (--extract=X is required):\n"
 		" --force                allow extracting to root\n"
 		" --overwrite            overwrite files that already exist\n"
@@ -124,7 +126,7 @@ static int erofsfsck_parse_options_cfg(int argc, char **argv)
 	int opt, ret;
 	bool has_opt_preserve = false;
 
-	while ((opt = getopt_long(argc, argv, "Vd:ph",
+	while ((opt = getopt_long(argc, argv, "Vd:phaAy",
 				  long_options, NULL)) != -1) {
 		switch (opt) {
 		case 'V':
@@ -144,6 +146,10 @@ static int erofsfsck_parse_options_cfg(int argc, char **argv)
 		case 'h':
 			usage(argc, argv);
 			exit(0);
+		case 'a':
+		case 'A':
+		case 'y':
+			break;
 		case 2:
 			fsckcfg.check_decomp = true;
 			if (optarg) {
man/fsck.erofs.1 +4 -0
index a226995..c94fff9 100644
@@ -34,6 +34,10 @@ so it might take too much time depending on the image.
 .TP
 \fB\-h\fR, \fB\-\-help\fR
 Display help string and exit.
+.TP
+\fB\-a\fR, \fB\-A\fR, \fB-y\R
+These options do nothing at all; they are provided only for compatibility with
+the fsck programs of other filesystems.
 .SH AUTHOR
 This version of \fBfsck.erofs\fR is written by
 Daeho Jeong <[email protected]>.
Signature · 1 line
2.42.0
#4 lore raw
In reply to Luke T. Shumaker
Quoted 15 lines · Luke T. Shumaker

From: "Luke T. Shumaker" <[email protected]>

Hi all,

This patchset addresses snags that I hit while adopting erofs for our system images.

- The first patch is really just setting a baseline for the next two.

- The second patch is improving the --help text to address the snag that I had to read the source code to understand how to use the mkfs.erofs -z flag, and also setting the stage for the third patch. In doing this I broadly improved the --help text overall, not just for mkfs.erofs.

Quoted 7 lines

- The third patch is adding no-op -a, -A, and -y flags to fsck.erofs, to address the snag that I was seeing errors in the boot scroll.

I didn't touch erofsfuse in any of these, not because it isn't worthy of the changes from the first two patches, just that I decided it would have been too much work at the moment.

Thanks, applied for testing.

Thanks,
Gao Xiang

Quoted 18 lines

Luke T. Shumaker (3):
erofs-utils: have each non-fuse command take -h, --help, -V, and
--version
erofs-utils: improve the usage and version text of non-fuse commands
erofs-utils: fsck: Add -a, -A, and -y flags

  dump/main.c              |  47 +++++++------
  fsck/main.c              |  81 ++++++++++++++--------
  include/erofs/compress.h |   2 +-
  lib/compressor.c         |  13 +---
  lib/compressor.h         |   9 ++-
  man/dump.erofs.1         |   5 +-
  man/fsck.erofs.1         |   8 ++-
  man/mkfs.erofs.1         |  15 ++--
  mkfs/main.c              | 144 +++++++++++++++++++++++++--------------
  9 files changed, 202 insertions(+), 122 deletions(-)