vfs: Add inode uid,gid,mode init helper
authorDmitry Monakhov <dmonakhov@openvz.org>
Thu, 4 Mar 2010 14:29:14 +0000 (17:29 +0300)
committerAl Viro <viro@zeniv.linux.org.uk>
Fri, 21 May 2010 22:31:22 +0000 (18:31 -0400)
Signed-off-by: Dmitry Monakhov <dmonakhov@openvz.org>
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
fs/inode.c
include/linux/fs.h

index 498b10f04c3c7a4a7e5bc527deb9eaccd6385ab2..2bee20ae3d65ba74f970129ec8d147ab7cd4fe50 100644 (file)
@@ -1606,3 +1606,23 @@ void init_special_inode(struct inode *inode, umode_t mode, dev_t rdev)
                                  inode->i_ino);
 }
 EXPORT_SYMBOL(init_special_inode);
+
+/**
+ * Init uid,gid,mode for new inode according to posix standards
+ * @inode: New inode
+ * @dir: Directory inode
+ * @mode: mode of the new inode
+ */
+void inode_init_owner(struct inode *inode, const struct inode *dir,
+                       mode_t mode)
+{
+       inode->i_uid = current_fsuid();
+       if (dir && 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;
+}
+EXPORT_SYMBOL(inode_init_owner);
index 9626c5fbb0e18f75eb825a9791b58ef03f581bdb..8a733862a411d24519fffa901082a82200d79eb8 100644 (file)
@@ -1428,7 +1428,8 @@ extern void dentry_unhash(struct dentry *dentry);
  * VFS file helper functions.
  */
 extern int file_permission(struct file *, int);
-
+extern void inode_init_owner(struct inode *inode, const struct inode *dir,
+                       mode_t mode);
 /*
  * VFS FS_IOC_FIEMAP helper definitions.
  */