From a1bd120d13e586ea1c424048fd2c8420a442852a Mon Sep 17 00:00:00 2001 From: Dmitry Monakhov Date: Thu, 4 Mar 2010 17:29:14 +0300 Subject: [PATCH] vfs: Add inode uid,gid,mode init helper Signed-off-by: Dmitry Monakhov Signed-off-by: Al Viro --- fs/inode.c | 20 ++++++++++++++++++++ include/linux/fs.h | 3 ++- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/fs/inode.c b/fs/inode.c index 498b10f04c3c..2bee20ae3d65 100644 --- a/fs/inode.c +++ b/fs/inode.c @@ -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); diff --git a/include/linux/fs.h b/include/linux/fs.h index 9626c5fbb0e1..8a733862a411 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -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. */ -- 2.30.2