From mboxrd@z Thu Jan 1 00:00:00 1970 From: Dmitry Monakhov Subject: [PATCH 01/19] vfs: Add inode uid,gid,mode initialization with helper function Date: Wed, 17 Feb 2010 21:34:45 +0300 Message-ID: <1266431685-8781-1-git-send-email-dmonakhov@openvz.org> References: <1266431353-8549-1-git-send-email-dmonakhov@openvz.org> Cc: viro@ZenIV.linux.org.uk, Dmitry Monakhov To: linux-fsdevel@vger.kernel.org Return-path: Received: from fg-out-1718.google.com ([72.14.220.156]:35098 "EHLO fg-out-1718.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751863Ab0BQSe4 (ORCPT ); Wed, 17 Feb 2010 13:34:56 -0500 Received: by fg-out-1718.google.com with SMTP id 19so346960fgg.1 for ; Wed, 17 Feb 2010 10:34:55 -0800 (PST) In-Reply-To: <1266431353-8549-1-git-send-email-dmonakhov@openvz.org> Sender: linux-fsdevel-owner@vger.kernel.org List-ID: Signed-off-by: Dmitry Monakhov --- fs/namei.c | 19 +++++++++++++++++++ include/linux/fs.h | 3 ++- 2 files changed, 21 insertions(+), 1 deletions(-) diff --git a/fs/namei.c b/fs/namei.c index d62fdc8..bbe9578 100644 --- a/fs/namei.c +++ b/fs/namei.c @@ -1435,6 +1435,25 @@ void unlock_rename(struct dentry *p1, struct dentry *p2) mutex_unlock(&p1->d_inode->i_sb->s_vfs_rename_mutex); } } +/** + * Init uid,gid,mode for new inode according to posix standards + * @inode: New inode + * @dir: Directory inode + * @mode: mode of the new inode + */ +inline void inode_init_owner(struct inode *inode, const struct inode *dir, + int 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); int vfs_create(struct inode *dir, struct dentry *dentry, int mode, struct nameidata *nd) diff --git a/include/linux/fs.h b/include/linux/fs.h index b1bcb27..b2d7cb3 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -1426,7 +1426,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, + int mode); /* * VFS FS_IOC_FIEMAP helper definitions. */ -- 1.6.6