[PATCH v4] erofs-utils: lib: fix incorrect mtime under -Edot-omitted

Yifan Zhao zhaoyifan28 at huawei.com
Sat Jan 17 13:43:56 AEDT 2026


`-Edot-omitted` enables `-E48bits`, which requires specific
configurations for g_sbi.{epoch, build_time}. Currently, the call to
`erofs_sb_set_48bit()` occurs too late in the execution flow, causing
the aforementioned logic to be bypassed and resulting in incorrect
mtimes for all inodes.

This patch moves time initialization logic into `erofs_importer_init()`
to resolve this issue.

Signed-off-by: Yifan Zhao <zhaoyifan28 at huawei.com>
---
 include/erofs/importer.h |  1 +
 lib/importer.c           | 10 ++++++++++
 mkfs/main.c              | 16 ++++------------
 3 files changed, 15 insertions(+), 12 deletions(-)

diff --git a/include/erofs/importer.h b/include/erofs/importer.h
index 60160d6..2dea963 100644
--- a/include/erofs/importer.h
+++ b/include/erofs/importer.h
@@ -41,6 +41,7 @@ struct erofs_importer_params {
 	u32 pclusterblks_def;
 	u32 pclusterblks_packed;
 	s32 pclusterblks_metabox;
+	s64 mkfs_time;
 	char force_inodeversion;
 	bool ignore_mtime;
 	bool no_datainline;
diff --git a/lib/importer.c b/lib/importer.c
index 958a433..45c9963 100644
--- a/lib/importer.c
+++ b/lib/importer.c
@@ -83,6 +83,16 @@ int erofs_importer_init(struct erofs_importer *im)
 
 	if (params->dot_omitted)
 		erofs_sb_set_48bit(sbi);
+
+	if (params->mkfs_time != -1) {
+		if (erofs_sb_has_48bit(sbi)) {
+			sbi->epoch = max_t(s64, 0, params->mkfs_time - UINT32_MAX);
+			sbi->build_time = params->mkfs_time - sbi->epoch;
+		} else {
+			sbi->epoch = params->mkfs_time;
+		}
+	}
+
 	return 0;
 
 out_err:
diff --git a/mkfs/main.c b/mkfs/main.c
index bc001a6..34d03ca 100644
--- a/mkfs/main.c
+++ b/mkfs/main.c
@@ -1731,7 +1731,6 @@ int main(int argc, char **argv)
 	bool tar_index_512b = false;
 	struct timeval t;
 	FILE *blklst = NULL;
-	s64 mkfs_time = 0;
 	int err;
 	u32 crc;
 
@@ -1756,17 +1755,10 @@ int main(int argc, char **argv)
 	}
 
 	g_sbi.fixed_nsec = 0;
-	if (cfg.c_unix_timestamp != -1) {
-		mkfs_time = cfg.c_unix_timestamp;
-	} else if (!gettimeofday(&t, NULL)) {
-		mkfs_time = t.tv_sec;
-	}
-	if (erofs_sb_has_48bit(&g_sbi)) {
-		g_sbi.epoch = max_t(s64, 0, mkfs_time - UINT32_MAX);
-		g_sbi.build_time = mkfs_time - g_sbi.epoch;
-	} else {
-		g_sbi.epoch = mkfs_time;
-	}
+	if (cfg.c_unix_timestamp != -1)
+		importer_params.mkfs_time = cfg.c_unix_timestamp;
+	else
+		importer_params.mkfs_time = !gettimeofday(&t, NULL) ? t.tv_sec : -1;
 
 	err = erofs_dev_open(&g_sbi, cfg.c_img_path, O_RDWR |
 				(incremental_mode ? 0 : O_TRUNC));
-- 
2.47.3



More information about the Linux-erofs mailing list