On 2026/1/16 17:23, Yifan Zhao wrote:
`-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 <[email protected]>
---
  lib/importer.c | 17 +++++++++++++++++
  mkfs/main.c    | 15 ---------------
  2 files changed, 17 insertions(+), 15 deletions(-)

diff --git a/lib/importer.c b/lib/importer.c
index 958a433..b62ec20 100644
--- a/lib/importer.c
+++ b/lib/importer.c
@@ -2,6 +2,7 @@
  /*
   * Copyright (C) 2025 Alibaba Cloud
   */
+#include <sys/time.h>
  #include "erofs/importer.h"
  #include "erofs/config.h"
  #include "erofs/dedupe.h"
@@ -43,6 +44,8 @@ int erofs_importer_init(struct erofs_importer *im)
        struct erofs_sb_info *sbi = im->sbi;
        struct erofs_importer_params *params = im->params;
        const char *subsys = NULL;
+       struct timeval t;
+       s64 mkfs_time = 0;
        int err;
erofs_importer_global_init();
@@ -83,6 +86,20 @@ int erofs_importer_init(struct erofs_importer *im)
if (params->dot_omitted)
                erofs_sb_set_48bit(sbi);
+
+       sbi->fixed_nsec = 0;
+       if (cfg.c_unix_timestamp != -1) {
+               mkfs_time = cfg.c_unix_timestamp;

I mean we could

        if (params->mkfs_time != -1) {
                mkfs_time = params->mkfs_time;
                if (erofs_sb_has_48bit(sbi)) {
                        sbi->epoch = max_t(s64, 0, mkfs_time - UINT32_MAX);
                        sbi->build_time = mkfs_time - sbi->epoch;
                } else {
                        sbi->epoch = mkfs_time;
                }

        }

+       } else if (!gettimeofday(&t, NULL)) {
+               mkfs_time = t.tv_sec;
+       }
+       if (erofs_sb_has_48bit(sbi)) {
+               sbi->epoch = max_t(s64, 0, mkfs_time - UINT32_MAX);
+               sbi->build_time = mkfs_time - sbi->epoch;
+       } else {
+               sbi->epoch = mkfs_time;
+       }
+
        return 0;
out_err:
diff --git a/mkfs/main.c b/mkfs/main.c
index 620b1ed..6ee7f54 100644
--- a/mkfs/main.c
+++ b/mkfs/main.c
@@ -1710,9 +1710,7 @@ int main(int argc, char **argv)
        };
        struct erofs_inode *root = NULL;
        bool tar_index_512b = false;
-       struct timeval t;
        FILE *blklst = NULL;
-       s64 mkfs_time = 0;
        int err;
        u32 crc;
@@ -1736,19 +1734,6 @@ int main(int argc, char **argv)
                goto exit;
        }
- 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;
-       }

And here

        if (cfg.c_unix_timestamp != -1) {
                params->mkfs_time = cfg.c_unix_timestamp;
        else
                params->mkfs_time = !gettimeofday(&t, NULL) ...

        }

Thanks,
Gao Xiang

-
        err = erofs_dev_open(&g_sbi, cfg.c_img_path, O_RDWR |
                                (incremental_mode ? 0 : O_TRUNC));
        if (err) {


Reply via email to