[PATCH v2 09/10] erofs-utils: enable mapfile for `--tar=f`

Gao Xiang hsiangkao at linux.alibaba.com
Tue Jun 18 18:24:14 AEST 2024


The data offsets in the tar streams can always be looked up now:
    mkfs.erofs --tar=f,MAPFILE IMAGE TARBALL

Signed-off-by: Gao Xiang <hsiangkao at linux.alibaba.com>
---
 lib/tar.c   |  3 ++-
 mkfs/main.c | 31 ++++++++++++++++++++++---------
 2 files changed, 24 insertions(+), 10 deletions(-)

diff --git a/lib/tar.c b/lib/tar.c
index 8d2caa5..532e566 100644
--- a/lib/tar.c
+++ b/lib/tar.c
@@ -858,7 +858,8 @@ restart:
 			eh.link = strndup(th->linkname, sizeof(th->linkname));
 	}
 
-	if (tar->index_mode && !tar->mapfile &&
+	/* EROFS metadata index referring to the original tar data */
+	if (tar->index_mode && sbi->extra_devices &&
 	    erofs_blkoff(sbi, data_offset)) {
 		erofs_err("invalid tar data alignment @ %llu", tar_offset);
 		ret = -EIO;
diff --git a/mkfs/main.c b/mkfs/main.c
index 6e9120f..5378b23 100644
--- a/mkfs/main.c
+++ b/mkfs/main.c
@@ -423,6 +423,27 @@ static int mkfs_apply_zfeature_bits(uintmax_t bits)
 	return 0;
 }
 
+static void mkfs_parse_tar_cfg(char *cfg)
+{
+	char *p;
+
+	tar_mode = true;
+	if (!cfg)
+		return;
+	p = strchr(cfg, ',');
+	if (p) {
+		*p = '\0';
+		if ((*++p) != '\0')
+			erofstar.mapfile = strdup(p);
+	}
+	if (!strcmp(cfg, "headerball"))
+		erofstar.headeronly_mode = true;
+
+	if (erofstar.headeronly_mode || !strcmp(optarg, "i") ||
+	    !strcmp(optarg, "0"))
+		erofstar.index_mode = true;
+}
+
 static int mkfs_parse_one_compress_alg(char *alg,
 				       struct erofs_compr_opts *copts)
 {
@@ -729,15 +750,7 @@ static int mkfs_parse_options_cfg(int argc, char *argv[])
 			cfg.c_extra_ea_name_prefixes = true;
 			break;
 		case 20:
-			if (optarg && (!strcmp(optarg, "i") || (!strcmp(optarg, "headerball") ||
-				!strcmp(optarg, "0") || !memcmp(optarg, "0,", 2)))) {
-				erofstar.index_mode = true;
-				if (!memcmp(optarg, "0,", 2))
-					erofstar.mapfile = strdup(optarg + 2);
-				if (!strcmp(optarg, "headerball"))
-					erofstar.headeronly_mode = true;
-			}
-			tar_mode = true;
+			mkfs_parse_tar_cfg(optarg);
 			break;
 		case 21:
 			erofstar.aufs = true;
-- 
2.39.3



More information about the Linux-erofs mailing list