From mboxrd@z Thu Jan 1 00:00:00 1970 From: Dmitry Monakhov Subject: [PATCH 01/19] vfs: Add inode uid,gid,mode init helper v2 Date: Thu, 4 Mar 2010 17:29:14 +0300 Message-ID: <1267712954-9134-1-git-send-email-dmonakhov@openvz.org> References: <1267712897-9088-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 mail-bw0-f209.google.com ([209.85.218.209]:60276 "EHLO mail-bw0-f209.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751634Ab0CDO3X (ORCPT ); Thu, 4 Mar 2010 09:29:23 -0500 Received: by bwz1 with SMTP id 1so414841bwz.21 for ; Thu, 04 Mar 2010 06:29:21 -0800 (PST) In-Reply-To: <1267712897-9088-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 644cc66..ad1eb1c 100644 --- a/fs/namei.c +++ b/fs/namei.c @@ -1391,6 +1391,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 + */ +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 cd32f1b..22e4b53 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