[PATCH v2] erofs-utils: mkfs: support set fingerprint for tar sort=none mode

Yuezhang Mo Yuezhang.Mo at sony.com
Wed Apr 22 17:37:06 AEST 2026


If "--tar=f" and "--sort=none" are enabled, ->datasource will be set
to "EROFS_INODE_DATA_SOURCE_NONE".

In erofs_mkfs_begin_nondirectory(), erofs_set_inode_fingerprint() is
only be called if ->datasource is EROFS_INODE_DATA_SOURCE_LOCALPATH
or EROFS_INODE_DATA_SOURCE_DISKBUF.

EROFS_INODE_DATA_SOURCE_NONE means that metadata is done and mkfs
dump will change nothing, so use erofs_setxattr() to set fingerprint
at settings ->datasource to EROFS_INODE_DATA_SOURCE_NONE.

Signed-off-by: Yuezhang Mo <Yuezhang.Mo at sony.com>
Reviewed-by: Friendy Su <friendy.su at sony.com>
Reviewed-by: Daniel Palmer <daniel.palmer at sony.com>
---

v1: https://lore.kernel.org/all/20260410060539.417457-2-Yuezhang.Mo@sony.com/

 lib/tar.c | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)

diff --git a/lib/tar.c b/lib/tar.c
index 87a6a61..6171272 100644
--- a/lib/tar.c
+++ b/lib/tar.c
@@ -21,6 +21,7 @@
 #include "liberofs_cache.h"
 #include "liberofs_gzran.h"
 #include "liberofs_rebuild.h"
+#include "sha256.h"
 
 /* This file is a tape/volume header.  Ignore it on extraction.  */
 #define GNUTYPE_VOLHDR 'V'
@@ -631,10 +632,13 @@ static int tarerofs_write_uncompressed_file(struct erofs_inode *inode,
 					    struct erofs_tarfile *tar)
 {
 	struct erofs_sb_info *sbi = inode->sbi;
+	u8 ishare_xattr_prefix_id = sbi->ishare_xattr_prefix_id;
 	erofs_blk_t nblocks;
 	erofs_off_t pos;
 	void *buf;
 	int ret;
+	struct sha256_state md;
+	u8 out[32 + sizeof("sha256:") - 1];
 
 	inode->datalayout = EROFS_INODE_FLAT_PLAIN;
 	nblocks = DIV_ROUND_UP(inode->i_size, 1U << sbi->blkszbits);
@@ -643,6 +647,9 @@ static int tarerofs_write_uncompressed_file(struct erofs_inode *inode,
 	if (ret)
 		return ret;
 
+	if (ishare_xattr_prefix_id)
+		erofs_sha256_init(&md);
+
 	for (pos = 0; pos < inode->i_size; pos += ret) {
 		ret = erofs_iostream_read(&tar->ios, &buf, inode->i_size - pos);
 		if (ret <= 0) {
@@ -656,11 +663,23 @@ static int tarerofs_write_uncompressed_file(struct erofs_inode *inode,
 			ret = -EIO;
 			break;
 		}
+		if (ishare_xattr_prefix_id)
+			erofs_sha256_process(&md, buf, ret);
 	}
 	inode->idata_size = 0;
 	inode->datasource = EROFS_INODE_DATA_SOURCE_NONE;
 	if (ret < 0)
 		return ret;
+
+	if (ishare_xattr_prefix_id) {
+		erofs_sha256_done(&md, out + sizeof("sha256:") - 1);
+		memcpy(out, "sha256:", sizeof("sha256:") - 1);
+		ret = erofs_setxattr(inode, ishare_xattr_prefix_id, "",
+				     out, sizeof(out));
+		if (ret < 0)
+			return ret;
+	}
+
 	return 0;
 }
 
-- 
2.43.0



More information about the Linux-erofs mailing list