Signed-off-by: Dmitry Monakhov <dmonakhov@xxxxxxxxxx> --- 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 -- To unsubscribe from this list: send the line "unsubscribe linux-fsdevel" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html