]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/commitdiff
mkfs: fix file size setting when interpreting a protofile
authorDarrick J. Wong <djwong@kernel.org>
Mon, 3 Feb 2025 22:40:24 +0000 (14:40 -0800)
committerAndrey Albershteyn <aalbersh@kernel.org>
Wed, 5 Feb 2025 17:20:02 +0000 (18:20 +0100)
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>
Reviewed-by: Christoph Hellwig <hch@lst.de>
mkfs/proto.c

index 4e9e28d4eea1ca6934ffde9c497db0f502978fe9..6dd3a2005b15b35219b4fc073e0b8ee7f5fe6f23 100644 (file)
@@ -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)