Skip to contentSkip to conversation

btrfs: Handle SGID bit when creating inodes

PATCH In review Chris Ball 2 participants 2 messages Feb 1, 2009 Btrfs file system

lore
Share & tools
lore

Chris Ball

author
#0 lore raw

PATCH 1/1 btrfs: Handle SGID bit when creating inodes

Before this patch, new files/dirs would ignore the SGID bit on their parent directory and always be owned by the creating user's uid/gid.

---
 fs/btrfs/inode.c |    9 ++++++++-
 1 files changed, 8 insertions(+), 1 deletions(-)
fs/btrfs/inode.c +8 -1
index ebd7d6c..ce25bb3 100644
@@ -3470,7 +3470,14 @@ static struct inode *btrfs_new_inode(struct btrfs_trans_handle *trans,
 		root->highest_inode = objectid;
 
 	inode->i_uid = current_fsuid();
-	inode->i_gid = current_fsgid();
+
+	if (dir->i_mode & S_ISGID) {
+		inode->i_gid = dir->i_gid;
+		if (S_ISDIR(mode))
+			mode |= S_ISGID;
+	} else
+		inode->i_gid = current_fsgid();
+
 	inode->i_mode = mode;
 	inode->i_ino = objectid;
 	inode_set_bytes(inode, 0);
Signature · 4 lines
1.6.1.2

-- 
Chris Ball   <[email protected]>
#1 lore raw
Quoted 4 lines · Chris Ball

Before this patch, new files/dirs would ignore the SGID bit on their parent directory and always be owned by the creating user's uid/gid.

Looks good, thanks much for taking care of this,

Josef