diff mbox series

[1/3] mkfs: fix file size setting when interpreting a protofile

Message ID 173862239048.2460098.9569795439422233357.stgit@frogsfrogsfrogs (mailing list archive)
State New
Headers show
Series [1/3] mkfs: fix file size setting when interpreting a protofile | expand

Commit Message

Darrick J. Wong Feb. 3, 2025, 10:40 p.m. UTC
From: Darrick J. Wong <djwong@kernel.org>

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" <djwong@kernel.org>
---
 mkfs/proto.c |    5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)

Comments

Christoph Hellwig Feb. 4, 2025, 4:53 a.m. UTC | #1
Looks good:

Reviewed-by: Christoph Hellwig <hch@lst.de>
diff mbox series

Patch

diff --git a/mkfs/proto.c b/mkfs/proto.c
index 4e9e28d4eea1ca..6dd3a2005b15b3 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)