[PATCH RFC 1/4] erofs-utils: lib: introduce --meta_fix format option

Hongbo Li lihongbo22 at huawei.com
Tue Apr 22 22:36:09 AEST 2025


The option --meta_fix format option allow the mkfs.erofs
can fix the metadata area at the front of the image file.
It makes the disk format easier.

Now we only allow to fix the metadata area at the front
in EROFS_INODE_FLAG_PLAIN layout.

Signed-off-by: Hongbo Li <lihongbo22 at huawei.com>
---
 include/erofs/config.h |  1 +
 mkfs/main.c            | 22 ++++++++++++++++++++++
 2 files changed, 23 insertions(+)

diff --git a/include/erofs/config.h b/include/erofs/config.h
index 92c1467..ac6dd9b 100644
--- a/include/erofs/config.h
+++ b/include/erofs/config.h
@@ -66,6 +66,7 @@ struct erofs_configure {
 	bool c_xattr_name_filter;
 	bool c_ovlfs_strip;
 	bool c_hard_dereference;
+	bool c_meta_fix;
 
 #ifdef HAVE_LIBSELINUX
 	struct selabel_handle *sehnd;
diff --git a/mkfs/main.c b/mkfs/main.c
index 6d1a2de..42635c6 100644
--- a/mkfs/main.c
+++ b/mkfs/main.c
@@ -87,6 +87,7 @@ static struct option long_options[] = {
 	{"sort", required_argument, NULL, 527},
 	{"hard-dereference", no_argument, NULL, 528},
 	{"dsunit", required_argument, NULL, 529},
+	{"meta_fix", no_argument, NULL, 530},
 	{0, 0, 0, 0},
 };
 
@@ -191,6 +192,7 @@ static void usage(int argc, char **argv)
 		"                                            headerball=file data is omited in the source stream)\n"
 		" --ovlfs-strip=<0,1>   strip overlayfs metadata in the target image (e.g. whiteouts)\n"
 		" --quiet               quiet execution (do not write anything to standard output.)\n"
+		" --meta_fix            make metadata area fixed at the front of the image file\n"
 #ifndef NDEBUG
 		" --random-pclusterblks randomize pclusterblks for big pcluster (debugging only)\n"
 		" --random-algorithms   randomize per-file algorithms (debugging only)\n"
@@ -886,6 +888,9 @@ static int mkfs_parse_options_cfg(int argc, char *argv[])
 				return -EINVAL;
 			}
 			break;
+		case 530:
+			cfg.c_meta_fix = true;
+			break;
 		case 'V':
 			version();
 			exit(0);
@@ -903,6 +908,23 @@ static int mkfs_parse_options_cfg(int argc, char *argv[])
 		return -EINVAL;
 	}
 
+	if (cfg.c_meta_fix) {
+		if (cfg.c_compr_opts[0].alg) {
+			erofs_err("--meta_fix cannot be used with compress case");
+			return -EINVAL;
+		}
+
+		if (cfg.c_chunkbits) {
+			erofs_err("--meta_fix cannot be used with --chunksize");
+			return -EINVAL;
+		}
+
+		if (cfg.c_inline_data) {
+			erofs_info("--meta_fix force to turn off the inline_data");
+			cfg.c_inline_data = false;
+		}
+	}
+
 	/* TODO: can be implemented with (deviceslot) mapped_blkaddr */
 	if (cfg.c_blobdev_path &&
 	    cfg.c_force_chunkformat == FORCE_INODE_BLOCK_MAP) {
-- 
2.22.0



More information about the Linux-erofs mailing list