diff mbox

[V9fs-developer,1/2,9p] Add a helper function to get egid for a file create.

Message ID 1275430547-32523-2-git-send-email-jvrao@linux.vnet.ibm.com (mailing list archive)
State Superseded
Delegated to: Eric Van Hensbergen
Headers show

Commit Message

jvrao June 1, 2010, 10:15 p.m. UTC
None
diff mbox

Patch

diff --git a/fs/9p/vfs_inode.c b/fs/9p/vfs_inode.c
index 0c9f103..03e751b 100644
--- a/fs/9p/vfs_inode.c
+++ b/fs/9p/vfs_inode.c
@@ -236,6 +236,43 @@  void v9fs_destroy_inode(struct inode *inode)
 #endif
 
 /**
+ * v9fs_get_egid - Helper function to get the gid for creating a new file
+ * system object. This checks the S_ISGID to determine the owning group of the
+ * new file system object.
+ */
+
+gid_t v9fs_get_egid(struct v9fs_session_info *v9ses, struct p9_fid *dfid,
+		struct dentry *dir_dentry)
+{
+	if (v9ses->cache != CACHE_LOOSE && v9ses->cache != CACHE_FSCACHE) {
+		/* No caching. Get attributes from server */
+		if (v9fs_proto_dotl(v9ses)) {
+			struct p9_stat_dotl *st;
+			st = p9_client_getattr_dotl(dfid);
+			if (IS_ERR(st))
+				return PTR_ERR(st);
+			v9fs_stat2inode_dotl(st, dir_dentry->d_inode);
+			kfree(st);
+		} else {
+			struct p9_wstat *st;
+			st = p9_client_stat(dfid);
+			if (IS_ERR(st))
+				return PTR_ERR(st);
+			v9fs_stat2inode(st, dir_dentry->d_inode,
+					dir_dentry->d_inode->i_sb);
+			kfree(st);
+		}
+	}
+
+	if (dir_dentry->d_inode->i_mode & S_ISGID) {
+		/* set_gid bit is set.*/
+		return dir_dentry->d_inode->i_gid;
+	}
+
+	return current_fsgid();
+}
+
+/**
  * v9fs_get_inode - helper function to setup an inode
  * @sb: superblock
  * @mode: mode to setup inode with