From: "Darrick J. Wong" <djwong@kernel.org>
To: tytso@mit.edu
Cc: linux-ext4@vger.kernel.org
Subject: [PATCH 3/8] fuse2fs: refactor uid/gid setting
Date: Sun, 06 Jul 2025 11:31:31 -0700 [thread overview]
Message-ID: <175182663023.1984706.1635443008190304976.stgit@frogsfrogsfrogs> (raw)
In-Reply-To: <175182662934.1984706.3737778061161342509.stgit@frogsfrogsfrogs>
From: Darrick J. Wong <djwong@kernel.org>
Don't open-code the uid and gid update logic.
Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
---
misc/fuse2fs.c | 42 ++++++++++++++++++++++--------------------
1 file changed, 22 insertions(+), 20 deletions(-)
diff --git a/misc/fuse2fs.c b/misc/fuse2fs.c
index d209bc790fbd36..86fef7765e5e46 100644
--- a/misc/fuse2fs.c
+++ b/misc/fuse2fs.c
@@ -1053,6 +1053,18 @@ static int propagate_default_acls(struct fuse2fs *ff, ext2_ino_t parent,
return ret;
}
+static inline void fuse2fs_set_uid(struct ext2_inode_large *inode, uid_t uid)
+{
+ inode->i_uid = uid;
+ ext2fs_set_i_uid_high(*inode, uid >> 16);
+}
+
+static inline void fuse2fs_set_gid(struct ext2_inode_large *inode, gid_t gid)
+{
+ inode->i_gid = gid;
+ ext2fs_set_i_gid_high(*inode, gid >> 16);
+}
+
static int op_mknod(const char *path, mode_t mode, dev_t dev)
{
struct fuse_context *ctxt = fuse_get_context();
@@ -1145,10 +1157,8 @@ static int op_mknod(const char *path, mode_t mode, dev_t dev)
inode.i_links_count = 1;
inode.i_extra_isize = sizeof(struct ext2_inode_large) -
EXT2_GOOD_OLD_INODE_SIZE;
- inode.i_uid = ctxt->uid;
- ext2fs_set_i_uid_high(inode, ctxt->uid >> 16);
- inode.i_gid = ctxt->gid;
- ext2fs_set_i_gid_high(inode, ctxt->gid >> 16);
+ fuse2fs_set_uid(&inode, ctxt->uid);
+ fuse2fs_set_gid(&inode, ctxt->gid);
err = ext2fs_write_new_inode(fs, child, EXT2_INODE(&inode));
if (err) {
@@ -1262,10 +1272,8 @@ static int op_mkdir(const char *path, mode_t mode)
goto out2;
}
- inode.i_uid = ctxt->uid;
- ext2fs_set_i_uid_high(inode, ctxt->uid >> 16);
- inode.i_gid = ctxt->gid;
- ext2fs_set_i_gid_high(inode, ctxt->gid >> 16);
+ fuse2fs_set_uid(&inode, ctxt->uid);
+ fuse2fs_set_gid(&inode, ctxt->gid);
inode.i_mode = LINUX_S_IFDIR | (mode & ~S_ISUID) |
parent_sgid;
inode.i_generation = ff->next_generation++;
@@ -1691,10 +1699,8 @@ static int op_symlink(const char *src, const char *dest)
goto out2;
}
- inode.i_uid = ctxt->uid;
- ext2fs_set_i_uid_high(inode, ctxt->uid >> 16);
- inode.i_gid = ctxt->gid;
- ext2fs_set_i_gid_high(inode, ctxt->gid >> 16);
+ fuse2fs_set_uid(&inode, ctxt->uid);
+ fuse2fs_set_gid(&inode, ctxt->gid);
inode.i_generation = ff->next_generation++;
init_times(&inode);
@@ -2243,8 +2249,7 @@ static int op_chown(const char *path, uid_t owner, gid_t group
ret = -EPERM;
goto out;
}
- inode.i_uid = owner;
- ext2fs_set_i_uid_high(inode, owner >> 16);
+ fuse2fs_set_uid(&inode, owner);
}
if (group != (gid_t) ~0) {
@@ -2256,8 +2261,7 @@ static int op_chown(const char *path, uid_t owner, gid_t group
}
/* XXX: We /should/ check group membership but FUSE */
- inode.i_gid = group;
- ext2fs_set_i_gid_high(inode, group >> 16);
+ fuse2fs_set_gid(&inode, group);
}
ret = update_ctime(fs, ino, &inode);
@@ -3300,10 +3304,8 @@ static int op_create(const char *path, mode_t mode, struct fuse_file_info *fp)
inode.i_links_count = 1;
inode.i_extra_isize = sizeof(struct ext2_inode_large) -
EXT2_GOOD_OLD_INODE_SIZE;
- inode.i_uid = ctxt->uid;
- ext2fs_set_i_uid_high(inode, ctxt->uid >> 16);
- inode.i_gid = ctxt->gid;
- ext2fs_set_i_gid_high(inode, ctxt->gid >> 16);
+ fuse2fs_set_uid(&inode, ctxt->uid);
+ fuse2fs_set_gid(&inode, ctxt->gid);
if (ext2fs_has_feature_extents(fs->super)) {
ext2_extent_handle_t handle;
next prev parent reply other threads:[~2025-07-06 18:31 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-07-06 18:30 [PATCHSET] fuse2fs: more bug fixes Darrick J. Wong
2025-07-06 18:31 ` [PATCH 1/8] libext2fs: fix off-by-one bug in punch_extent_blocks Darrick J. Wong
2025-07-06 18:31 ` [PATCH 2/8] libext2fs: fix arguments passed to ->block_alloc_stats_range Darrick J. Wong
2025-07-06 18:31 ` Darrick J. Wong [this message]
2025-07-06 18:31 ` [PATCH 4/8] fuse2fs: fix gid inheritance on sgid parent directories Darrick J. Wong
2025-07-06 18:32 ` [PATCH 5/8] fuse2fs: don't truncate when creating a new file Darrick J. Wong
2025-07-06 18:32 ` [PATCH 6/8] fuse2fs: fix incorrect EOFS input handling in FITRIM Darrick J. Wong
2025-07-06 18:32 ` [PATCH 7/8] fuse2fs: fix incorrect unit conversion at the end of FITRIM Darrick J. Wong
2025-07-06 18:32 ` [PATCH 8/8] fuse2fs: don't try to mount after option parsing errors Darrick J. Wong
2025-07-07 16:05 ` [PATCH 9/8] fuse2fs: fix relatime comparisons Darrick J. Wong
2025-07-08 17:33 ` [PATCH 10/8] fuse2fs: fix lockfile creation, again Darrick J. Wong
2025-07-09 16:51 ` [PATCH 11/8] fuse2fs: fix race condition in op_destroy Darrick J. Wong
2025-07-09 16:52 ` [PATCH 12/8] fuse2fs: fix races in statfs Darrick J. Wong
2025-07-17 14:59 ` [PATCH 13/8] fuse2fs: fix ST_RDONLY setting Darrick J. Wong
2025-07-17 14:59 ` [PATCH 14/8] libext2fs: fix data read corruption in ext2fs_file_read_inline_data Darrick J. Wong
2025-07-17 14:59 ` [PATCH 15/8] libext2fs: fix data corruption when writing to inline data files Darrick J. Wong
2025-07-17 22:01 ` [PATCH 16/8] fuse2fs: fix clean_block_middle when punching byte 0 of a block Darrick J. Wong
2025-07-17 22:01 ` [PATCH 17/8] fuse2fs: fix punch-out range calculation in fuse2fs_punch_range Darrick J. Wong
2025-07-22 19:40 ` [PATCH 18/8] fuse2fs: fix logging redirection Darrick J. Wong
2025-07-25 15:56 ` [PATCH 19/8] fuse2fs: don't record every errno in the superblock as an fs failure Darrick J. Wong
2025-07-26 16:28 ` [PATCH 20/8] fuse2fs: fix punching post-EOF blocks during truncate Darrick J. Wong
2025-07-30 17:23 ` [PATCH 21/8] fuse2fs: fix block parameter truncation on 32-bit Darrick J. Wong
2025-07-31 14:47 ` [PATCHSET] fuse2fs: more bug fixes Theodore Ts'o
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=175182663023.1984706.1635443008190304976.stgit@frogsfrogsfrogs \
--to=djwong@kernel.org \
--cc=linux-ext4@vger.kernel.org \
--cc=tytso@mit.edu \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox