From a62ea4ad9cacac5fa82c0df45b3f7248cf255d9c Mon Sep 17 00:00:00 2001 From: "Darrick J. Wong" Date: Mon, 3 Feb 2025 14:40:24 -0800 Subject: [PATCH] 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 --- mkfs/proto.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) 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) -- 2.47.3