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

Darrick J. Wong
2025-11-06T22:37:12Z

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 07bb4cdb889c17..171eff246e272c 100644
--- a/misc/fuse2fs.c
+++ b/misc/fuse2fs.c
@@ -4216,7 +4216,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)
@@ -4236,7 +4235,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)
@@ -4267,7 +4265,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)
@@ -4287,7 +4284,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)
@@ -4341,7 +4337,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)
@@ -4414,7 +4409,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)
@@ -4557,6 +4551,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