Skip to contentSkip to conversation

erofs-utils: mkfs: fix image reproducibility of `-E(all-)fragments`

PATCH Superseded Gao Xiang 2 participants 8 messages May 31, 2025 – Jun 3, 2025 Library code

lore
Share & tools
lore

Gao Xiang

author
#0 lore raw

PATCH 1/1 erofs-utils: mkfs: fix image reproducibility of `-E(all-)fragments`

The timestamp of the packed inode should be fixed to the build time.

Fixes 9fa9b017f773 ("erofs-utils: mkfs: support fragments")
---
 lib/inode.c | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)
lib/inode.c +10 -4
index 7a10624..ca49a80 100644
@@ -910,7 +910,8 @@ out:
 	return 0;
 }
 
-static bool erofs_should_use_inode_extended(struct erofs_inode *inode)
+static bool erofs_should_use_inode_extended(struct erofs_inode *inode,
+					    const char *path)
 {
 	if (cfg.c_force_inodeversion == FORCE_INODE_EXTENDED)
 		return true;
@@ -924,7 +925,8 @@ static bool erofs_should_use_inode_extended(struct erofs_inode *inode)
 		return true;
 	if (inode->i_nlink > USHRT_MAX)
 		return true;
-	if ((inode->i_mtime != inode->sbi->build_time ||
+	if (path != EROFS_PACKED_INODE &&
+	    (inode->i_mtime != inode->sbi->build_time ||
 	     inode->i_mtime_nsec != inode->sbi->build_time_nsec) &&
 	    !cfg.c_ignore_mtime)
 		return true;
@@ -1016,6 +1018,10 @@ int __erofs_fill_inode(struct erofs_inode *inode, struct stat *st,
 		erofs_err("gid overflow @ %s", path);
 	inode->i_gid += cfg.c_gid_offset;
 
+	if (path == EROFS_PACKED_INODE) {
+		inode->i_mtime = sbi->build_time;
+		inode->i_mtime_nsec = 0;
+	}
 	inode->i_mtime = st->st_mtime;
 	inode->i_mtime_nsec = ST_MTIM_NSEC(st);
 
@@ -1065,7 +1071,7 @@ static int erofs_fill_inode(struct erofs_inode *inode, struct stat *st,
 	if (!inode->i_srcpath)
 		return -ENOMEM;
 
-	if (erofs_should_use_inode_extended(inode)) {
+	if (erofs_should_use_inode_extended(inode, path)) {
 		if (cfg.c_force_inodeversion == FORCE_INODE_COMPACT) {
 			erofs_err("file %s cannot be in compact form",
 				  inode->i_srcpath);
@@ -1610,7 +1616,7 @@ static int erofs_rebuild_handle_inode(struct erofs_inode *inode,
 	erofs_update_progressinfo("Processing %s ...", trimmed);
 	free(trimmed);
 
-	if (erofs_should_use_inode_extended(inode)) {
+	if (erofs_should_use_inode_extended(inode, inode->i_srcpath)) {
 		if (cfg.c_force_inodeversion == FORCE_INODE_COMPACT) {
 			erofs_err("file %s cannot be in compact form",
 				  inode->i_srcpath);
Signature · 1 line
2.43.5
#1 lore raw

Hi, Xiang,

Quoted 33 lines · Gao Xiang

The timestamp of the packed inode should be fixed to the build time.

Fixes 9fa9b017f773 ("erofs-utils: mkfs: support fragments")
---
  lib/inode.c | 14 ++++++++++----
  1 file changed, 10 insertions(+), 4 deletions(-)
lib/inode.c +4 -2
index 7a10624..ca49a80 100644
@@ -910,7 +910,8 @@ out:
  	return 0;
  }
 
-static bool erofs_should_use_inode_extended(struct erofs_inode *inode)
+static bool erofs_should_use_inode_extended(struct erofs_inode *inode,
+					    const char *path)
  {
  	if (cfg.c_force_inodeversion == FORCE_INODE_EXTENDED)
  		return true;
@@ -924,7 +925,8 @@ static bool erofs_should_use_inode_extended(struct erofs_inode *inode)
  		return true;
  	if (inode->i_nlink > USHRT_MAX)
  		return true;
-	if ((inode->i_mtime != inode->sbi->build_time ||
+	if (path != EROFS_PACKED_INODE &&
+	    (inode->i_mtime != inode->sbi->build_time ||
  	     inode->i_mtime_nsec != inode->sbi->build_time_nsec) &&
  	    !cfg.c_ignore_mtime)
  		return true;

lib/inode.c int __erofs_fill_inode(struct erofs_inode *inode, struct stat *st, · line 1026

Quoted 9 lines
lib/inode.c +4 -0
@@ -1016,6 +1018,10 @@ int __erofs_fill_inode(struct erofs_inode *inode, struct stat *st,
  		erofs_err("gid overflow @ %s", path);
  	inode->i_gid += cfg.c_gid_offset;
 
+	if (path == EROFS_PACKED_INODE) {
+		inode->i_mtime = sbi->build_time;
+		inode->i_mtime_nsec = 0;
+	}
  	inode->i_mtime = st->st_mtime;
  	inode->i_mtime_nsec = ST_MTIM_NSEC(st);

Should we put the condition in here? Because it will be reassigned if we do like this.

And what about assigning sbi->build_time_nsec to inode->i_mtime_nsec like the FIXED case?

Thanks,
Hongbo

Quoted 19 lines
lib/inode.c +2 -2
@@ -1065,7 +1071,7 @@ static int erofs_fill_inode(struct erofs_inode *inode, struct stat *st,
  	if (!inode->i_srcpath)
  		return -ENOMEM;
 
-	if (erofs_should_use_inode_extended(inode)) {
+	if (erofs_should_use_inode_extended(inode, path)) {
  		if (cfg.c_force_inodeversion == FORCE_INODE_COMPACT) {
  			erofs_err("file %s cannot be in compact form",
  				  inode->i_srcpath);
@@ -1610,7 +1616,7 @@ static int erofs_rebuild_handle_inode(struct erofs_inode *inode,
  	erofs_update_progressinfo("Processing %s ...", trimmed);
  	free(trimmed);
 
-	if (erofs_should_use_inode_extended(inode)) {
+	if (erofs_should_use_inode_extended(inode, inode->i_srcpath)) {
  		if (cfg.c_force_inodeversion == FORCE_INODE_COMPACT) {
  			erofs_err("file %s cannot be in compact form",
  				  inode->i_srcpath);
author
#2 lore raw

Hi Hongbo,

Quoted 37 lines · Hongbo Li

Hi, Xiang,

Quoted 34 lines · Gao Xiang

The timestamp of the packed inode should be fixed to the build time.

Fixes 9fa9b017f773 ("erofs-utils: mkfs: support fragments")

---
  lib/inode.c | 14 ++++++++++----

  1 file changed, 10 insertions(+), 4 deletions(-)
lib/inode.c +4 -2
index 7a10624..ca49a80 100644
@@ -910,7 +910,8 @@ out:
       return 0;
   }
-static bool erofs_should_use_inode_extended(struct erofs_inode *inode)
+static bool erofs_should_use_inode_extended(struct erofs_inode *inode,
+                        const char *path)
   {
       if (cfg.c_force_inodeversion == FORCE_INODE_EXTENDED)
           return true;
@@ -924,7 +925,8 @@ static bool erofs_should_use_inode_extended(struct erofs_inode *inode)
           return true;
       if (inode->i_nlink > USHRT_MAX)
           return true;
-    if ((inode->i_mtime != inode->sbi->build_time ||
+    if (path != EROFS_PACKED_INODE &&
+        (inode->i_mtime != inode->sbi->build_time ||

           inode->i_mtime_nsec != inode->sbi->build_time_nsec) && !cfg.c_ignore_mtime)
          return true;

lib/inode.c +0 -0
@@ -1016,6 +1018,10 @@ int __erofs_fill_inode(struct erofs_inode *inode, struct stat *st,
           erofs_err("gid overflow @ %s", path);
       inode->i_gid += cfg.c_gid_offset;
Quoted 8 lines

lib/inode.c int __erofs_fill_inode(struct erofs_inode *inode, struct stat *st, · line 1026

Quoted 6 lines
lib/inode.c +4 -0
+    if (path == EROFS_PACKED_INODE) {
+        inode->i_mtime = sbi->build_time;
+        inode->i_mtime_nsec = 0;
+    }
       inode->i_mtime = st->st_mtime;
       inode->i_mtime_nsec = ST_MTIM_NSEC(st);

Should we put the condition in here? Because it will be reassigned if we do like this.

Oh, that is my fault, I will fix it soon.

Quoted 2 lines

And what about assigning sbi->build_time_nsec to inode->i_mtime_nsec like the FIXED case?

I just would like a quick fix for this because I have other features to work on.

If you want to improve that, could you submit a patch?

Thanks,
Gao Xiang

Quoted 4 lines

Thanks,
Hongbo

#3 lore raw
Quoted 54 lines · Gao Xiang

Hi Hongbo,

Quoted 39 lines · Hongbo Li

Hi, Xiang,

Quoted 36 lines · Gao Xiang

The timestamp of the packed inode should be fixed to the build time.

Fixes 9fa9b017f773 ("erofs-utils: mkfs: support fragments")

---
  lib/inode.c | 14 ++++++++++----

  1 file changed, 10 insertions(+), 4 deletions(-)
lib/inode.c +4 -2
index 7a10624..ca49a80 100644
@@ -910,7 +910,8 @@ out:
       return 0;
   }
-static bool erofs_should_use_inode_extended(struct erofs_inode *inode)
+static bool erofs_should_use_inode_extended(struct erofs_inode *inode,
+                        const char *path)
   {
       if (cfg.c_force_inodeversion == FORCE_INODE_EXTENDED)
           return true;
@@ -924,7 +925,8 @@ static bool 
 erofs_should_use_inode_extended(struct erofs_inode *inode)
           return true;
       if (inode->i_nlink > USHRT_MAX)
           return true;
-    if ((inode->i_mtime != inode->sbi->build_time ||
+    if (path != EROFS_PACKED_INODE &&
+        (inode->i_mtime != inode->sbi->build_time ||

           inode->i_mtime_nsec != inode->sbi->build_time_nsec) && !cfg.c_ignore_mtime)
          return true;

lib/inode.c +0 -0
@@ -1016,6 +1018,10 @@ int __erofs_fill_inode(struct erofs_inode 
 *inode, struct stat *st,
           erofs_err("gid overflow @ %s", path);
       inode->i_gid += cfg.c_gid_offset;
Quoted 8 lines

lib/inode.c int __erofs_fill_inode(struct erofs_inode *inode, struct stat *st, · line 1026

Quoted 6 lines
lib/inode.c +4 -0
+    if (path == EROFS_PACKED_INODE) {
+        inode->i_mtime = sbi->build_time;
+        inode->i_mtime_nsec = 0;
+    }
       inode->i_mtime = st->st_mtime;
       inode->i_mtime_nsec = ST_MTIM_NSEC(st);

Should we put the condition in here? Because it will be reassigned if we do like this.

Oh, that is my fault, I will fix it soon.

Quoted 1 line
Quoted 7 lines
Quoted 1 line

And what about assigning sbi->build_time_nsec to inode->i_mtime_nsec like the FIXED case?

I just would like a quick fix for this because I have other features to work on.

If you want to improve that, could you submit a patch?

Ok, I send the new one based on your v2.

Thanks,
Hongbo

Quoted 7 lines

Thanks,
Gao Xiang

Quoted 4 lines

Thanks,
Hongbo

author
#4 lore raw

PATCH v2 1/1 erofs-utils: mkfs: fix image reproducibility of `-E(all-)fragments`

In reply to Hongbo Li

The timestamp of the packed inode should be fixed to the build time.

Fixes 9fa9b017f773 ("erofs-utils: mkfs: support fragments")

---
change since v1:
- fix time assignment (assign i_mtime_nsec too) [Hongbo];

 lib/inode.c | 16 +++++++++++-----
 1 file changed, 11 insertions(+), 5 deletions(-)
lib/inode.c +11 -5
index 7a10624..9095ebc 100644
@@ -910,7 +910,8 @@ out:
 	return 0;
 }
 
-static bool erofs_should_use_inode_extended(struct erofs_inode *inode)
+static bool erofs_should_use_inode_extended(struct erofs_inode *inode,
+					    const char *path)
 {
 	if (cfg.c_force_inodeversion == FORCE_INODE_EXTENDED)
 		return true;
@@ -924,7 +925,8 @@ static bool erofs_should_use_inode_extended(struct erofs_inode *inode)
 		return true;
 	if (inode->i_nlink > USHRT_MAX)
 		return true;
-	if ((inode->i_mtime != inode->sbi->build_time ||
+	if (path != EROFS_PACKED_INODE &&
+	    (inode->i_mtime != inode->sbi->build_time ||
 	     inode->i_mtime_nsec != inode->sbi->build_time_nsec) &&
 	    !cfg.c_ignore_mtime)
 		return true;
@@ -1016,6 +1018,11 @@ int __erofs_fill_inode(struct erofs_inode *inode, struct stat *st,
 		erofs_err("gid overflow @ %s", path);
 	inode->i_gid += cfg.c_gid_offset;
 
+	if (path == EROFS_PACKED_INODE) {
+		inode->i_mtime = sbi->build_time;
+		inode->i_mtime_nsec = sbi->build_time_nsec;
+		return 0;
+	}
 	inode->i_mtime = st->st_mtime;
 	inode->i_mtime_nsec = ST_MTIM_NSEC(st);
 
@@ -1029,7 +1036,6 @@ int __erofs_fill_inode(struct erofs_inode *inode, struct stat *st,
 	default:
 		break;
 	}
-
 	return 0;
 }
 
@@ -1065,7 +1071,7 @@ static int erofs_fill_inode(struct erofs_inode *inode, struct stat *st,
 	if (!inode->i_srcpath)
 		return -ENOMEM;
 
-	if (erofs_should_use_inode_extended(inode)) {
+	if (erofs_should_use_inode_extended(inode, path)) {
 		if (cfg.c_force_inodeversion == FORCE_INODE_COMPACT) {
 			erofs_err("file %s cannot be in compact form",
 				  inode->i_srcpath);
@@ -1610,7 +1616,7 @@ static int erofs_rebuild_handle_inode(struct erofs_inode *inode,
 	erofs_update_progressinfo("Processing %s ...", trimmed);
 	free(trimmed);
 
-	if (erofs_should_use_inode_extended(inode)) {
+	if (erofs_should_use_inode_extended(inode, inode->i_srcpath)) {
 		if (cfg.c_force_inodeversion == FORCE_INODE_COMPACT) {
 			erofs_err("file %s cannot be in compact form",
 				  inode->i_srcpath);
Signature · 1 line
2.43.5
#5 lore raw

PATCH v3 1/1 erofs-utils: mkfs: fix image reproducibility of `-E(all-)fragments`

From: Gao Xiang <[email protected]>

The timestamp of the packed inode should be fixed to the build time.

Fixes 9fa9b017f773 ("erofs-utils: mkfs: support fragments")
[hongbo: minor adjust]

---
change since v2:
- compare path with strcmp;

change since v1:
- fix time assignment (assign i_mtime_nsec too) [Hongbo];

---
 lib/inode.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
lib/inode.c +7 -2
index 108aa9e..46eb686 100644
@@ -929,7 +929,8 @@ static bool erofs_should_use_inode_extended(struct erofs_inode *inode)
 		return true;
 	if (inode->i_nlink > USHRT_MAX)
 		return true;
-	if ((inode->i_mtime != inode->sbi->build_time ||
+	if (strcmp(inode->i_srcpath, EROFS_PACKED_INODE) &&
+	    (inode->i_mtime != inode->sbi->build_time ||
 	     inode->i_mtime_nsec != inode->sbi->build_time_nsec) &&
 	    !cfg.c_ignore_mtime)
 		return true;
@@ -1021,6 +1022,11 @@ int __erofs_fill_inode(struct erofs_inode *inode, struct stat *st,
 		erofs_err("gid overflow @ %s", path);
 	inode->i_gid += cfg.c_gid_offset;
 
+	if (path == EROFS_PACKED_INODE) {
+		inode->i_mtime = sbi->build_time;
+		inode->i_mtime_nsec = sbi->build_time_nsec;
+		return 0;
+	}
 	inode->i_mtime = st->st_mtime;
 	inode->i_mtime_nsec = ST_MTIM_NSEC(st);
 
@@ -1034,7 +1040,6 @@ int __erofs_fill_inode(struct erofs_inode *inode, struct stat *st,
 	default:
 		break;
 	}
-
 	return 0;
 }
 
Signature · 1 line
2.22.0
author
#6 lore raw

Hi Hongbo,

Quoted 23 lines · Hongbo Li

From: Gao Xiang <[email protected]>

The timestamp of the packed inode should be fixed to the build time.

Fixes 9fa9b017f773 ("erofs-utils: mkfs: support fragments")
[hongbo: minor adjust]

---
change since v2:
- compare path with strcmp;

change since v1:
- fix time assignment (assign i_mtime_nsec too) [Hongbo];

---
  lib/inode.c | 9 +++++++--
  1 file changed, 7 insertions(+), 2 deletions(-)
lib/inode.c +0 -0
index 108aa9e..46eb686 100644

lib/inode.c static bool erofs_should_use_inode_extended(struct erofs_inode *inode) · line 932

Quoted 5 lines
lib/inode.c +1 -1
@@ -929,7 +929,8 @@ static bool erofs_should_use_inode_extended(struct erofs_inode *inode)
  		return true;
  	if (inode->i_nlink > USHRT_MAX)
  		return true;
-	if ((inode->i_mtime != inode->sbi->build_time ||
+	if (strcmp(inode->i_srcpath, EROFS_PACKED_INODE) &&

EROFS_PACKED_INODE is a hard-coded pointer rather than a real path name that should be compared in the string.

Otherwise, the same path name could be matched but that is unexpected.

Thanks,
Gao Xiang

Reviewed-by on v2 1/1
#7 lore raw
In reply to Gao Xiang
Quoted 11 lines · Gao Xiang

The timestamp of the packed inode should be fixed to the build time.

Fixes 9fa9b017f773 ("erofs-utils: mkfs: support fragments")

---
change since v1:
- fix time assignment (assign i_mtime_nsec too) [Hongbo];

  lib/inode.c | 16 +++++++++++-----
  1 file changed, 11 insertions(+), 5 deletions(-)

Thanks,
Hongbo

Quoted 62 lines
lib/inode.c +11 -5
index 7a10624..9095ebc 100644
@@ -910,7 +910,8 @@ out:
  	return 0;
  }
 
-static bool erofs_should_use_inode_extended(struct erofs_inode *inode)
+static bool erofs_should_use_inode_extended(struct erofs_inode *inode,
+					    const char *path)
  {
  	if (cfg.c_force_inodeversion == FORCE_INODE_EXTENDED)
  		return true;
@@ -924,7 +925,8 @@ static bool erofs_should_use_inode_extended(struct erofs_inode *inode)
  		return true;
  	if (inode->i_nlink > USHRT_MAX)
  		return true;
-	if ((inode->i_mtime != inode->sbi->build_time ||
+	if (path != EROFS_PACKED_INODE &&
+	    (inode->i_mtime != inode->sbi->build_time ||
  	     inode->i_mtime_nsec != inode->sbi->build_time_nsec) &&
  	    !cfg.c_ignore_mtime)
  		return true;
@@ -1016,6 +1018,11 @@ int __erofs_fill_inode(struct erofs_inode *inode, struct stat *st,
  		erofs_err("gid overflow @ %s", path);
  	inode->i_gid += cfg.c_gid_offset;
 
+	if (path == EROFS_PACKED_INODE) {
+		inode->i_mtime = sbi->build_time;
+		inode->i_mtime_nsec = sbi->build_time_nsec;
+		return 0;
+	}
  	inode->i_mtime = st->st_mtime;
  	inode->i_mtime_nsec = ST_MTIM_NSEC(st);
 
@@ -1029,7 +1036,6 @@ int __erofs_fill_inode(struct erofs_inode *inode, struct stat *st,
  	default:
  		break;
  	}
-
  	return 0;
  }
 
@@ -1065,7 +1071,7 @@ static int erofs_fill_inode(struct erofs_inode *inode, struct stat *st,
  	if (!inode->i_srcpath)
  		return -ENOMEM;
 
-	if (erofs_should_use_inode_extended(inode)) {
+	if (erofs_should_use_inode_extended(inode, path)) {
  		if (cfg.c_force_inodeversion == FORCE_INODE_COMPACT) {
  			erofs_err("file %s cannot be in compact form",
  				  inode->i_srcpath);
@@ -1610,7 +1616,7 @@ static int erofs_rebuild_handle_inode(struct erofs_inode *inode,
  	erofs_update_progressinfo("Processing %s ...", trimmed);
  	free(trimmed);
 
-	if (erofs_should_use_inode_extended(inode)) {
+	if (erofs_should_use_inode_extended(inode, inode->i_srcpath)) {
  		if (cfg.c_force_inodeversion == FORCE_INODE_COMPACT) {
  			erofs_err("file %s cannot be in compact form",
  				  inode->i_srcpath);