erofs-utils: mkfs: support set fingerprint for tar sort=none mode
PATCH v2 1/1 erofs-utils: mkfs: support set fingerprint for tar sort=none mode
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.
---
v1: https://lore.kernel.org/all/[email protected]/
lib/tar.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+)
lib/tar.c +19 -0
@@ -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 ; }
Signature · 1 line
2.43.0
Quoted 7 lines · Yuezhang Mo
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 isEROFS_INODE_DATA_SOURCE_LOCALPATHorEROFS_INODE_DATA_SOURCE_DISKBUF.
Quoted 7 lines
EROFS_INODE_DATA_SOURCE_NONEmeans that metadata is done and mkfs dump will change nothing, so useerofs_setxattr()to set fingerprint at settings ->datasource toEROFS_INODE_DATA_SOURCE_NONE.Signed-off-by Yuezhang Mo <[email protected]>Reviewed-by Friendy Su <[email protected]>Reviewed-by Daniel Palmer <[email protected]>
Thanks, will apply.
Thanks,
Gao Xiang