Skip to contentSkip to conversation

erofs-utils: mkfs: fix fingerprint not set in certain modes

PATCH In review Yuezhang Mo 2 participants 4 messages Apr 10 Library code

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 erofs-utils: mkfs: fix fingerprint not set in certain modes

In certain modes, such as "--tar=f --sort=none", data is written to the image before fingerprint calculation. In this case, ->datasource will be set to EROFS_INODE_DATA_SOURCE_NONE.

The original erofs_set_inode_fingerprint() function only attempts to read data from a local file or disk buffer; it cannot handle the EROFS_INODE_DATA_SOURCE_NONE case, causing fingerprint setting to be skipped.

This patch adds handling for the EROFS_INODE_DATA_SOURCE_NONE case, reading data from the image and calculating the fingerprint.

---
 lib/inode.c | 20 ++++++++++++++------
 1 file changed, 14 insertions(+), 6 deletions(-)
lib/inode.c +14 -6
index 2cfc6c5..51d5266 100644
@@ -1975,6 +1975,13 @@ static int erofs_set_inode_fingerprint(struct erofs_inode *inode, int fd,
 
 	if (!ishare_xattr_prefix_id)
 		return 0;
+
+	if (inode->datasource == EROFS_INODE_DATA_SOURCE_NONE) {
+		ret = erofs_iopen(&vf, inode);
+		if (ret)
+			return ret;
+	}
+
 	erofs_sha256_init(&md);
 	do {
 		u8 buf[32768];
@@ -2018,12 +2025,6 @@ static int erofs_mkfs_begin_nondirectory(const struct erofs_mkfs_btctx *btctx,
 			goto out;
 		}
 
-		if (S_ISREG(inode->i_mode) && inode->i_size) {
-			ret = erofs_set_inode_fingerprint(inode, ctx.fd, ctx.fpos);
-			if (ret < 0)
-				return ret;
-		}
-
 		if (inode->sbi->available_compr_algs &&
 		    erofs_file_is_compressible(im, inode)) {
 			ctx.ictx = erofs_prepare_compressed_file(im, inode);
@@ -2037,6 +2038,13 @@ static int erofs_mkfs_begin_nondirectory(const struct erofs_mkfs_btctx *btctx,
 		}
 	}
 out:
+	if (S_ISREG(inode->i_mode) && inode->i_size &&
+	    inode->datasource != EROFS_INODE_DATA_SOURCE_RESVSP) {
+		ret = erofs_set_inode_fingerprint(inode, ctx.fd, ctx.fpos);
+		if (ret < 0)
+			return ret;
+	}
+
 	return erofs_mkfs_go(btctx, EROFS_MKFS_JOB_NDIR, &ctx, sizeof(ctx));
 }
 
Signature · 1 line
2.43.0
#1 lore raw

Hi Yuezhang,

Quoted 38 lines · Yuezhang Mo

In certain modes, such as "--tar=f --sort=none", data is written to the image before fingerprint calculation. In this case, ->datasource will be set to EROFS_INODE_DATA_SOURCE_NONE.

The original erofs_set_inode_fingerprint() function only attempts to read data from a local file or disk buffer; it cannot handle the EROFS_INODE_DATA_SOURCE_NONE case, causing fingerprint setting to be skipped.

This patch adds handling for the EROFS_INODE_DATA_SOURCE_NONE case, reading data from the image and calculating the fingerprint.

---
  lib/inode.c | 20 ++++++++++++++------
  1 file changed, 14 insertions(+), 6 deletions(-)
lib/inode.c +7 -0
index 2cfc6c5..51d5266 100644
@@ -1975,6 +1975,13 @@ static int erofs_set_inode_fingerprint(struct erofs_inode *inode, int fd,
 
  	if (!ishare_xattr_prefix_id)
  		return 0;
+
+	if (inode->datasource == EROFS_INODE_DATA_SOURCE_NONE) {
+		ret = erofs_iopen(&vf, inode);
+		if (ret)
+			return ret;
+	}
+
  	erofs_sha256_init(&md);
  	do {
  		u8 buf[32768];

lib/inode.c static int erofs_mkfs_begin_nondirectory(const struct erofs_mkfs_btctx *btctx, · line 2025

Quoted 8 lines
lib/inode.c +0 -5
@@ -2018,12 +2025,6 @@ static int erofs_mkfs_begin_nondirectory(const struct erofs_mkfs_btctx *btctx,
  			goto out;
  		}
 
-		if (S_ISREG(inode->i_mode) && inode->i_size) {
-			ret = erofs_set_inode_fingerprint(inode, ctx.fd, ctx.fpos);
-			if (ret < 0)
-				return ret;
-		}

I vaguely remembered we have to leave it here since otherwise it may impact compressed files.

Also EROFS_INODE_DATA_SOURCE_NONE means that mkfs
dump will change nothing about that, so I suggest

apply erofs_set_inode_fingerprint() to every
EROFS_INODE_DATA_SOURCE_NONE user
(e.g. in lib/tar.c) instead.

Thanks,
Gao Xiang

#2 lore raw
Quoted 51 lines · Yuezhang Mo
Quoted 38 lines

In certain modes, such as "--tar=f --sort=none", data is written to the image before fingerprint calculation. In this case, ->datasource will be set to EROFS_INODE_DATA_SOURCE_NONE.

The original erofs_set_inode_fingerprint() function only attempts to read data from a local file or disk buffer; it cannot handle the EROFS_INODE_DATA_SOURCE_NONE case, causing fingerprint setting to be skipped.

This patch adds handling for the EROFS_INODE_DATA_SOURCE_NONE case, reading data from the image and calculating the fingerprint.

---
  lib/inode.c | 20 ++++++++++++++------
  1 file changed, 14 insertions(+), 6 deletions(-)
lib/inode.c +7 -0
index 2cfc6c5..51d5266 100644
@@ -1975,6 +1975,13 @@ static int erofs_set_inode_fingerprint(struct erofs_inode *inode, int fd,
 
      if (!ishare_xattr_prefix_id)
              return 0;
+
+     if (inode->datasource == EROFS_INODE_DATA_SOURCE_NONE) {
+             ret = erofs_iopen(&vf, inode);
+             if (ret)
+                     return ret;
+     }
+
      erofs_sha256_init(&md);
      do {
              u8 buf[32768];

lib/inode.c static int erofs_mkfs_begin_nondirectory(const struct erofs_mkfs_btctx *btctx, · line 2025

Quoted 8 lines
lib/inode.c +0 -5
@@ -2018,12 +2025,6 @@ static int erofs_mkfs_begin_nondirectory(const struct erofs_mkfs_btctx *btctx,
                      goto out;
              }
 
-             if (S_ISREG(inode->i_mode) && inode->i_size) {
-                     ret = erofs_set_inode_fingerprint(inode, ctx.fd, ctx.fpos);
-                     if (ret < 0)
-                             return ret;
-             }

I vaguely remembered we have to leave it here since otherwise it may impact compressed files.

Quoted 7 lines

Also EROFS_INODE_DATA_SOURCE_NONE means that mkfs
dump will change nothing about that, so I suggest

apply erofs_set_inode_fingerprint() to every
EROFS_INODE_DATA_SOURCE_NONE user
(e.g. in lib/tar.c) instead.

Hi Xiang,

This will bring a bit big code change.

How about changing it like this? It maintains the original order and the change is simple.

@@ -1975,6 +1975,13 @@ static int erofs_set_inode_fingerprint(struct erofs_inode *inode, int fd,

        if (!ishare_xattr_prefix_id)
                return 0;

+
+ if (inode->datasource == EROFS_INODE_DATA_SOURCE_NONE) {
+ ret = erofs_iopen(&vf, inode);
+ if (ret)
+ return ret;
+ }
+

        erofs_sha256_init(&md);
        do {
                u8 buf[32768];
@@ -2014,6 +2021,8 @@ static int erofs_mkfs_begin_nondirectory(const struct erofs_mkfs_btctx *btctx,
                        if (ctx.fd < 0)
                                return -errno;
                        break;
+               case EROFS_INODE_DATA_SOURCE_NONE:
+                       break;
                default:
                        goto out;
                }
@@ -2024,6 +2033,9 @@ static int erofs_mkfs_begin_nondirectory(const struct erofs_mkfs_btctx *btctx,
                                return ret;
                }

+ if (inode->datasource == EROFS_INODE_DATA_SOURCE_NONE)
+ goto out;
+

                if (inode->sbi->available_compr_algs &&
                    erofs_file_is_compressible(im, inode)) {
                        ctx.ictx = erofs_prepare_compressed_file(im, inode);

Thanks.

#3 lore raw
Quoted 59 lines · On 2026/4/10 17:00, [email protected] wrote:
Quoted 51 lines · Yuezhang Mo
Quoted 38 lines

In certain modes, such as "--tar=f --sort=none", data is written to the image before fingerprint calculation. In this case, ->datasource will be set to EROFS_INODE_DATA_SOURCE_NONE.

The original erofs_set_inode_fingerprint() function only attempts to read data from a local file or disk buffer; it cannot handle the EROFS_INODE_DATA_SOURCE_NONE case, causing fingerprint setting to be skipped.

This patch adds handling for the EROFS_INODE_DATA_SOURCE_NONE case, reading data from the image and calculating the fingerprint.

---
   lib/inode.c | 20 ++++++++++++++------
   1 file changed, 14 insertions(+), 6 deletions(-)
lib/inode.c +7 -0
index 2cfc6c5..51d5266 100644
@@ -1975,6 +1975,13 @@ static int erofs_set_inode_fingerprint(struct erofs_inode *inode, int fd,
 
       if (!ishare_xattr_prefix_id)
               return 0;
+
+     if (inode->datasource == EROFS_INODE_DATA_SOURCE_NONE) {
+             ret = erofs_iopen(&vf, inode);
+             if (ret)
+                     return ret;
+     }
+
       erofs_sha256_init(&md);
       do {
               u8 buf[32768];

lib/inode.c static int erofs_mkfs_begin_nondirectory(const struct erofs_mkfs_btctx *btctx, · line 2025

Quoted 8 lines
lib/inode.c +0 -5
@@ -2018,12 +2025,6 @@ static int erofs_mkfs_begin_nondirectory(const struct erofs_mkfs_btctx *btctx,
                       goto out;
               }
 
-             if (S_ISREG(inode->i_mode) && inode->i_size) {
-                     ret = erofs_set_inode_fingerprint(inode, ctx.fd, ctx.fpos);
-                     if (ret < 0)
-                             return ret;
-             }

I vaguely remembered we have to leave it here since otherwise it may impact compressed files.

Quoted 7 lines

Also EROFS_INODE_DATA_SOURCE_NONE means that mkfs
dump will change nothing about that, so I suggest

apply erofs_set_inode_fingerprint() to every
EROFS_INODE_DATA_SOURCE_NONE user
(e.g. in lib/tar.c) instead.

Quoted 6 lines

Hi Xiang,

This will bring a bit big code change.

How about changing it like this? It maintains the original order and the change is simple.

EROFS_INODE_DATA_SOURCE_NONE should assume that metadata is done as-is, that is the current design principle.

using erofs_iopen() to reuse erofs_pread() is really unexpected for me TBH.

Thanks,
Gao Xiang