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

Yuezhang Mo <[email protected]>
Newsgroups org.ozlabs.lists.linux-erofs
Message-ID <[email protected]>
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 <[email protected]>
Reviewed-by: Friendy Su <[email protected]>
Reviewed-by: Daniel Palmer <[email protected]>
---

v1: https://lore.kernel.org/all/[email protected]/

 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
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.