From: Darrick J. Wong Date: Thu, 24 Apr 2025 21:41:34 +0000 (-0700) Subject: fuse2fs: implement zero range X-Git-Tag: v1.47.3-rc1~97 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=44e024fd9cea41097c9f16bfbc73bc6aaac21f00;p=thirdparty%2Fe2fsprogs.git fuse2fs: implement zero range Implement FALLOC_FL_ZERO_RANGE. Signed-off-by: Darrick J. Wong Link: https://lore.kernel.org/r/174553064980.1160461.9850792727586596449.stgit@frogsfrogsfrogs Signed-off-by: Theodore Ts'o --- diff --git a/misc/fuse2fs.c b/misc/fuse2fs.c index 7bd9bfa8..751e66b0 100644 --- a/misc/fuse2fs.c +++ b/misc/fuse2fs.c @@ -123,6 +123,12 @@ static ext2_filsys global_fs; /* Try not to use this directly */ # define FL_PUNCH_HOLE_FLAG (0) #endif +#ifdef FALLOC_FL_ZERO_RANGE +# define FL_ZERO_RANGE_FLAG FALLOC_FL_ZERO_RANGE +#else +# define FL_ZERO_RANGE_FLAG (0) +#endif + errcode_t ext2fs_run_ext3_journal(ext2_filsys *fs); #ifdef CONFIG_JBD_DEBUG /* Enabled by configure --enable-jbd-debug */ @@ -3619,6 +3625,16 @@ static int punch_helper(struct fuse_file_info *fp, int mode, off_t offset, return 0; } +static int zero_helper(struct fuse_file_info *fp, int mode, off_t offset, + off_t len) +{ + int ret = punch_helper(fp, mode | FL_KEEP_SIZE_FLAG, offset, len); + + if (!ret) + ret = fallocate_helper(fp, mode, offset, len); + return ret; +} + static int op_fallocate(const char *path EXT2FS_ATTR((unused)), int mode, off_t offset, off_t len, struct fuse_file_info *fp) @@ -3637,7 +3653,9 @@ static int op_fallocate(const char *path EXT2FS_ATTR((unused)), int mode, ret = -EROFS; goto out; } - if (mode & FL_PUNCH_HOLE_FLAG) + if (mode & FL_ZERO_RANGE_FLAG) + ret = zero_helper(fp, mode, offset, len); + else if (mode & FL_PUNCH_HOLE_FLAG) ret = punch_helper(fp, mode, offset, len); else ret = fallocate_helper(fp, mode, offset, len);