From: Darrick J. Wong Date: Sat, 26 Jul 2025 16:28:48 +0000 (-0700) Subject: fuse2fs: fix punching post-EOF blocks during truncate X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=86a24ae12c4fb81ec0b27ae1b63d3e5b05c7d46f;p=thirdparty%2Fe2fsprogs.git fuse2fs: fix punching post-EOF blocks during truncate ext2fs_punch() can update the inode that's passed in, so we need to write it back. This should fix some fstests failures where the test file system ends up with inodes where all extent records fit within the inode but inexplicably have extents beyond EOF. While we're at it, add the fuse2fs prefix to the two helper functions. Cc: linux-ext4@vger.kernel.org # v1.47.3 Fixes: 4581ac60eb53ec ("fuse2fs: fix post-EOF preallocation clearing on truncation") Signed-off-by: Darrick J. Wong Link: https://lore.kernel.org/r/20250726162848.GQ2672022@frogsfrogsfrogs Signed-off-by: Theodore Ts'o --- diff --git a/misc/fuse2fs.c b/misc/fuse2fs.c index 18d8f426..c6b1684f 100644 --- a/misc/fuse2fs.c +++ b/misc/fuse2fs.c @@ -2461,7 +2461,8 @@ out: return ret; } -static int punch_posteof(struct fuse2fs *ff, ext2_ino_t ino, off_t new_size) +static int fuse2fs_punch_posteof(struct fuse2fs *ff, ext2_ino_t ino, + off_t new_size) { ext2_filsys fs = ff->fs; struct ext2_inode_large inode; @@ -2477,10 +2478,14 @@ static int punch_posteof(struct fuse2fs *ff, ext2_ino_t ino, off_t new_size) if (err) return translate_error(fs, ino, err); + err = fuse2fs_write_inode(fs, ino, &inode); + if (err) + return translate_error(fs, ino, err); + return 0; } -static int truncate_helper(struct fuse2fs *ff, ext2_ino_t ino, off_t new_size) +static int fuse2fs_truncate(struct fuse2fs *ff, ext2_ino_t ino, off_t new_size) { ext2_filsys fs = ff->fs; ext2_file_t file; @@ -2523,7 +2528,7 @@ out_close: * we should clear out post-EOF preallocations. */ if (new_size == old_isize) - return punch_posteof(ff, ino, new_size); + return fuse2fs_punch_posteof(ff, ino, new_size); return 0; } @@ -2559,7 +2564,7 @@ static int op_truncate(const char *path, off_t len if (ret) goto out; - ret = truncate_helper(ff, ino, len); + ret = fuse2fs_truncate(ff, ino, len); if (ret) goto out; @@ -2659,7 +2664,7 @@ static int __op_open(struct fuse2fs *ff, const char *path, } if (fp->flags & O_TRUNC) { - ret = truncate_helper(ff, file->ino, 0); + ret = fuse2fs_truncate(ff, file->ino, 0); if (ret) goto out; }