From: Darrick J. Wong Date: Mon, 3 Feb 2025 22:40:24 +0000 (-0800) Subject: mkfs: fix file size setting when interpreting a protofile X-Git-Tag: v6.13.0~3 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=a62ea4ad9cacac5fa82c0df45b3f7248cf255d9c;p=thirdparty%2Fxfsprogs-dev.git mkfs: fix file size setting when interpreting a protofile When we're copying a regular file into the filesystem, we should set the size of the new file to the size indicated by the stat data, not the highest offset written, because we now use SEEK_DATA/HOLE to ignore sparse regions. Fixes: 73fb78e5ee8940 ("mkfs: support copying in large or sparse files") Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig --- diff --git a/mkfs/proto.c b/mkfs/proto.c index 4e9e28d4..6dd3a200 100644 --- a/mkfs/proto.c +++ b/mkfs/proto.c @@ -313,7 +313,6 @@ writefile( struct xfs_mount *mp = ip->i_mount; struct stat statbuf; off_t data_pos; - off_t eof = 0; int error; /* do not try to read from non-regular files */ @@ -340,8 +339,6 @@ writefile( } writefile_range(ip, fname, fd, data_pos, hole_pos - data_pos); - eof = hole_pos; - data_pos = lseek(fd, hole_pos, SEEK_DATA); } if (data_pos < 0 && errno != ENXIO) @@ -354,7 +351,7 @@ writefile( fail(_("error creating isize transaction"), error); libxfs_trans_ijoin(tp, ip, 0); - ip->i_disk_size = eof; + ip->i_disk_size = statbuf.st_size; libxfs_trans_log_inode(tp, ip, XFS_ILOG_CORE); error = -libxfs_trans_commit(tp); if (error)