[PATCH 4/9] fuse2fs: consolidate file handle checking in op_ioctl

Darrick J. Wong
2025-09-16T00:00:06Z

Reduce code size by checking the file handle in op_ioctl dispatch
instead of every single ioctl implementation.

Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
---
misc/fuse2fs.c | 7 +------
1 file changed, 1 insertion(+), 6 deletions(-)

diff --git a/misc/fuse2fs.c b/misc/fuse2fs.c
index 5a33e161ae8f9d..f264adbb3fe159 100644
--- a/misc/fuse2fs.c
+++ b/misc/fuse2fs.c
@@ -3944,7 +3944,6 @@ static int ioctl_getflags(struct fuse2fs *ff, struct fuse2fs_file_handle *fh,
errcode_t err;
struct ext2_inode_large inode;

- FUSE2FS_CHECK_HANDLE(ff, fh);
dbg_printf(ff, "%s: ino=%d\n", __func__, fh->ino);
err = fuse2fs_read_inode(fs, fh->ino, &inode);
if (err)
@@ -3964,7 +3963,6 @@ static int ioctl_setflags(struct fuse2fs *ff, struct fuse2fs_file_handle *fh,
__u32 flags = *(__u32 *)data;
struct fuse_context *ctxt = fuse_get_context();

- FUSE2FS_CHECK_HANDLE(ff, fh);
dbg_printf(ff, "%s: ino=%d\n", __func__, fh->ino);
err = fuse2fs_read_inode(fs, fh->ino, &inode);
if (err)
@@ -3995,7 +3993,6 @@ static int ioctl_getversion(struct fuse2fs *ff, struct fuse2fs_file_handle *fh,
errcode_t err;
struct ext2_inode_large inode;

- FUSE2FS_CHECK_HANDLE(ff, fh);
dbg_printf(ff, "%s: ino=%d\n", __func__, fh->ino);
err = fuse2fs_read_inode(fs, fh->ino, &inode);
if (err)
@@ -4015,7 +4012,6 @@ static int ioctl_setversion(struct fuse2fs *ff, struct fuse2fs_file_handle *fh,
__u32 generation = *(__u32 *)data;
struct fuse_context *ctxt = fuse_get_context();

- FUSE2FS_CHECK_HANDLE(ff, fh);
dbg_printf(ff, "%s: ino=%d\n", __func__, fh->ino);
err = fuse2fs_read_inode(fs, fh->ino, &inode);
if (err)
@@ -4069,7 +4065,6 @@ static int ioctl_fsgetxattr(struct fuse2fs *ff, struct fuse2fs_file_handle *fh,
struct fsxattr *fsx = data;
unsigned int inode_size;

- FUSE2FS_CHECK_HANDLE(ff, fh);
dbg_printf(ff, "%s: ino=%d\n", __func__, fh->ino);
err = fuse2fs_read_inode(fs, fh->ino, &inode);
if (err)
@@ -4142,7 +4137,6 @@ static int ioctl_fssetxattr(struct fuse2fs *ff, struct fuse2fs_file_handle *fh,
struct fsxattr *fsx = data;
unsigned int inode_size;

- FUSE2FS_CHECK_HANDLE(ff, fh);
dbg_printf(ff, "%s: ino=%d\n", __func__, fh->ino);
err = fuse2fs_read_inode(fs, fh->ino, &inode);
if (err)
@@ -4285,6 +4279,7 @@ static int op_ioctl(const char *path EXT2FS_ATTR((unused)),
int ret = 0;

FUSE2FS_CHECK_CONTEXT(ff);
+ FUSE2FS_CHECK_HANDLE(ff, fh);
pthread_mutex_lock(&ff->bfl);
switch ((unsigned long) cmd) {
#ifdef SUPPORT_I_FLAGS