Skip to content

Commit

Permalink
New helper - current_umask()
Browse files Browse the repository at this point in the history
current->fs->umask is what most of fs_struct users are doing.
Put that into a helper function.

Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
  • Loading branch information
Al Viro committed Apr 1, 2009
1 parent f1191b5 commit ce3b0f8
Show file tree
Hide file tree
Showing 26 changed files with 39 additions and 31 deletions.
2 changes: 1 addition & 1 deletion arch/powerpc/platforms/cell/spufs/inode.c
Original file line number Diff line number Diff line change
Expand Up @@ -635,7 +635,7 @@ long spufs_create(struct nameidata *nd, unsigned int flags, mode_t mode,
if (dentry->d_inode)
goto out_dput;

mode &= ~current->fs->umask;
mode &= ~current_umask();

if (flags & SPU_CREATE_GANG)
ret = spufs_create_gang(nd->path.dentry->d_inode,
Expand Down
2 changes: 1 addition & 1 deletion fs/btrfs/acl.c
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ int btrfs_init_acl(struct inode *inode, struct inode *dir)
}

if (!acl)
inode->i_mode &= ~current->fs->umask;
inode->i_mode &= ~current_umask();
}

if (IS_POSIXACL(dir) && acl) {
Expand Down
2 changes: 1 addition & 1 deletion fs/btrfs/ioctl.c
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ static noinline int btrfs_mksubvol(struct path *parent, char *name,
goto out_dput;

if (!IS_POSIXACL(parent->dentry->d_inode))
mode &= ~current->fs->umask;
mode &= ~current_umask();

error = mnt_want_write(parent->mnt);
if (error)
Expand Down
4 changes: 2 additions & 2 deletions fs/cifs/dir.c
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ cifs_create(struct inode *inode, struct dentry *direntry, int mode,
return -ENOMEM;
}

mode &= ~current->fs->umask;
mode &= ~current_umask();
if (oplockEnabled)
oplock = REQ_OPLOCK;

Expand Down Expand Up @@ -479,7 +479,7 @@ int cifs_mknod(struct inode *inode, struct dentry *direntry, int mode,
rc = -ENOMEM;
else if (pTcon->unix_ext) {
struct cifs_unix_set_info_args args = {
.mode = mode & ~current->fs->umask,
.mode = mode & ~current_umask(),
.ctime = NO_CHANGE_64,
.atime = NO_CHANGE_64,
.mtime = NO_CHANGE_64,
Expand Down
4 changes: 2 additions & 2 deletions fs/cifs/inode.c
Original file line number Diff line number Diff line change
Expand Up @@ -1125,7 +1125,7 @@ int cifs_mkdir(struct inode *inode, struct dentry *direntry, int mode)
goto mkdir_out;
}

mode &= ~current->fs->umask;
mode &= ~current_umask();
rc = CIFSPOSIXCreate(xid, pTcon, SMB_O_DIRECTORY | SMB_O_CREAT,
mode, NULL /* netfid */, pInfo, &oplock,
full_path, cifs_sb->local_nls,
Expand Down Expand Up @@ -1204,7 +1204,7 @@ int cifs_mkdir(struct inode *inode, struct dentry *direntry, int mode)
if ((direntry->d_inode) && (direntry->d_inode->i_nlink < 2))
direntry->d_inode->i_nlink = 2;

mode &= ~current->fs->umask;
mode &= ~current_umask();
/* must turn on setgid bit if parent dir has it */
if (inode->i_mode & S_ISGID)
mode |= S_ISGID;
Expand Down
2 changes: 1 addition & 1 deletion fs/ext2/acl.c
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ ext2_init_acl(struct inode *inode, struct inode *dir)
return PTR_ERR(acl);
}
if (!acl)
inode->i_mode &= ~current->fs->umask;
inode->i_mode &= ~current_umask();
}
if (test_opt(inode->i_sb, POSIX_ACL) && acl) {
struct posix_acl *clone;
Expand Down
2 changes: 1 addition & 1 deletion fs/ext3/acl.c
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ ext3_init_acl(handle_t *handle, struct inode *inode, struct inode *dir)
return PTR_ERR(acl);
}
if (!acl)
inode->i_mode &= ~current->fs->umask;
inode->i_mode &= ~current_umask();
}
if (test_opt(inode->i_sb, POSIX_ACL) && acl) {
struct posix_acl *clone;
Expand Down
2 changes: 1 addition & 1 deletion fs/ext4/acl.c
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ ext4_init_acl(handle_t *handle, struct inode *inode, struct inode *dir)
return PTR_ERR(acl);
}
if (!acl)
inode->i_mode &= ~current->fs->umask;
inode->i_mode &= ~current_umask();
}
if (test_opt(inode->i_sb, POSIX_ACL) && acl) {
struct posix_acl *clone;
Expand Down
2 changes: 1 addition & 1 deletion fs/fat/inode.c
Original file line number Diff line number Diff line change
Expand Up @@ -930,7 +930,7 @@ static int parse_options(char *options, int is_vfat, int silent, int *debug,

opts->fs_uid = current_uid();
opts->fs_gid = current_gid();
opts->fs_fmask = opts->fs_dmask = current->fs->umask;
opts->fs_fmask = current_umask();
opts->allow_utime = -1;
opts->codepage = fat_default_codepage;
opts->iocharset = fat_default_iocharset;
Expand Down
6 changes: 6 additions & 0 deletions fs/fs_struct.c
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,12 @@ int unshare_fs_struct(void)
}
EXPORT_SYMBOL_GPL(unshare_fs_struct);

int current_umask(void)
{
return current->fs->umask;
}
EXPORT_SYMBOL(current_umask);

/* to be mentioned only in INIT_TASK */
struct fs_struct init_fs = {
.users = 1,
Expand Down
2 changes: 1 addition & 1 deletion fs/generic_acl.c
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ generic_acl_init(struct inode *inode, struct inode *dir,
mode_t mode = inode->i_mode;
int error;

inode->i_mode = mode & ~current->fs->umask;
inode->i_mode = mode & ~current_umask();
if (!S_ISLNK(inode->i_mode))
acl = ops->getacl(dir, ACL_TYPE_DEFAULT);
if (acl) {
Expand Down
2 changes: 1 addition & 1 deletion fs/gfs2/acl.c
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ int gfs2_acl_create(struct gfs2_inode *dip, struct gfs2_inode *ip)
if (error)
return error;
if (!acl) {
mode &= ~current->fs->umask;
mode &= ~current_umask();
if (mode != ip->i_inode.i_mode)
error = munge_mode(ip, mode);
return error;
Expand Down
2 changes: 1 addition & 1 deletion fs/hfsplus/options.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ void hfsplus_fill_defaults(struct hfsplus_sb_info *opts)

opts->creator = HFSPLUS_DEF_CR_TYPE;
opts->type = HFSPLUS_DEF_CR_TYPE;
opts->umask = current->fs->umask;
opts->umask = current_umask();
opts->uid = current_uid();
opts->gid = current_gid();
opts->part = -1;
Expand Down
2 changes: 1 addition & 1 deletion fs/hpfs/super.c
Original file line number Diff line number Diff line change
Expand Up @@ -477,7 +477,7 @@ static int hpfs_fill_super(struct super_block *s, void *options, int silent)

uid = current_uid();
gid = current_gid();
umask = current->fs->umask;
umask = current_umask();
lowercase = 0;
conv = CONV_BINARY;
eas = 2;
Expand Down
2 changes: 1 addition & 1 deletion fs/jffs2/acl.c
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ int jffs2_init_acl_pre(struct inode *dir_i, struct inode *inode, int *i_mode)
return PTR_ERR(acl);

if (!acl) {
*i_mode &= ~current->fs->umask;
*i_mode &= ~current_umask();
} else {
if (S_ISDIR(*i_mode))
jffs2_iset_acl(inode, &f->i_acl_default, acl);
Expand Down
2 changes: 1 addition & 1 deletion fs/jfs/acl.c
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ int jfs_init_acl(tid_t tid, struct inode *inode, struct inode *dir)
cleanup:
posix_acl_release(acl);
} else
inode->i_mode &= ~current->fs->umask;
inode->i_mode &= ~current_umask();

JFS_IP(inode)->mode2 = (JFS_IP(inode)->mode2 & 0xffff0000) |
inode->i_mode;
Expand Down
6 changes: 3 additions & 3 deletions fs/namei.c
Original file line number Diff line number Diff line change
Expand Up @@ -1578,7 +1578,7 @@ static int __open_namei_create(struct nameidata *nd, struct path *path,
struct dentry *dir = nd->path.dentry;

if (!IS_POSIXACL(dir->d_inode))
mode &= ~current->fs->umask;
mode &= ~current_umask();
error = security_path_mknod(&nd->path, path->dentry, mode, 0);
if (error)
goto out_unlock;
Expand Down Expand Up @@ -1989,7 +1989,7 @@ SYSCALL_DEFINE4(mknodat, int, dfd, const char __user *, filename, int, mode,
goto out_unlock;
}
if (!IS_POSIXACL(nd.path.dentry->d_inode))
mode &= ~current->fs->umask;
mode &= ~current_umask();
error = may_mknod(mode);
if (error)
goto out_dput;
Expand Down Expand Up @@ -2067,7 +2067,7 @@ SYSCALL_DEFINE3(mkdirat, int, dfd, const char __user *, pathname, int, mode)
goto out_unlock;

if (!IS_POSIXACL(nd.path.dentry->d_inode))
mode &= ~current->fs->umask;
mode &= ~current_umask();
error = mnt_want_write(nd.path.mnt);
if (error)
goto out_dput;
Expand Down
6 changes: 3 additions & 3 deletions fs/nfs/nfs3proc.c
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ nfs3_proc_create(struct inode *dir, struct dentry *dentry, struct iattr *sattr,
data->arg.create.verifier[1] = current->pid;
}

sattr->ia_mode &= ~current->fs->umask;
sattr->ia_mode &= ~current_umask();

for (;;) {
status = nfs3_do_create(dir, dentry, data);
Expand Down Expand Up @@ -528,7 +528,7 @@ nfs3_proc_mkdir(struct inode *dir, struct dentry *dentry, struct iattr *sattr)

dprintk("NFS call mkdir %s\n", dentry->d_name.name);

sattr->ia_mode &= ~current->fs->umask;
sattr->ia_mode &= ~current_umask();

data = nfs3_alloc_createdata();
if (data == NULL)
Expand Down Expand Up @@ -639,7 +639,7 @@ nfs3_proc_mknod(struct inode *dir, struct dentry *dentry, struct iattr *sattr,
dprintk("NFS call mknod %s %u:%u\n", dentry->d_name.name,
MAJOR(rdev), MINOR(rdev));

sattr->ia_mode &= ~current->fs->umask;
sattr->ia_mode &= ~current_umask();

data = nfs3_alloc_createdata();
if (data == NULL)
Expand Down
2 changes: 1 addition & 1 deletion fs/nfs/nfs4proc.c
Original file line number Diff line number Diff line change
Expand Up @@ -1509,7 +1509,7 @@ nfs4_atomic_open(struct inode *dir, struct dentry *dentry, struct nameidata *nd)
attr.ia_mode = nd->intent.open.create_mode;
attr.ia_valid = ATTR_MODE;
if (!IS_POSIXACL(dir))
attr.ia_mode &= ~current->fs->umask;
attr.ia_mode &= ~current_umask();
} else {
attr.ia_valid = 0;
BUG_ON(nd->intent.open.flags & O_CREAT);
Expand Down
2 changes: 1 addition & 1 deletion fs/ocfs2/acl.c
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ int ocfs2_init_acl(handle_t *handle,
return PTR_ERR(acl);
}
if (!acl)
inode->i_mode &= ~current->fs->umask;
inode->i_mode &= ~current_umask();
}
if ((osb->s_mount_opt & OCFS2_MOUNT_POSIX_ACL) && acl) {
struct posix_acl *clone;
Expand Down
2 changes: 1 addition & 1 deletion fs/omfs/inode.c
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,7 @@ static int omfs_fill_super(struct super_block *sb, void *data, int silent)

sbi->s_uid = current_uid();
sbi->s_gid = current_gid();
sbi->s_dmask = sbi->s_fmask = current->fs->umask;
sbi->s_dmask = sbi->s_fmask = current_umask();

if (!parse_options((char *) data, sbi))
goto end;
Expand Down
2 changes: 1 addition & 1 deletion fs/reiserfs/xattr_acl.c
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,7 @@ reiserfs_inherit_default_acl(struct reiserfs_transaction_handle *th,
} else {
apply_umask:
/* no ACL, apply umask */
inode->i_mode &= ~current->fs->umask;
inode->i_mode &= ~current_umask();
}

return err;
Expand Down
4 changes: 2 additions & 2 deletions fs/xfs/linux-2.6/xfs_iops.c
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ xfs_vn_mknod(
xfs_dentry_to_name(&name, dentry);

if (IS_POSIXACL(dir) && !default_acl)
mode &= ~current->fs->umask;
mode &= ~current_umask();

switch (mode & S_IFMT) {
case S_IFCHR:
Expand Down Expand Up @@ -416,7 +416,7 @@ xfs_vn_symlink(
mode_t mode;

mode = S_IFLNK |
(irix_symlink_mode ? 0777 & ~current->fs->umask : S_IRWXUGO);
(irix_symlink_mode ? 0777 & ~current_umask() : S_IRWXUGO);
xfs_dentry_to_name(&name, dentry);

error = xfs_symlink(XFS_I(dir), &name, symname, mode, &cip, NULL);
Expand Down
2 changes: 2 additions & 0 deletions include/linux/fs.h
Original file line number Diff line number Diff line change
Expand Up @@ -1741,6 +1741,8 @@ extern void drop_collected_mounts(struct vfsmount *);

extern int vfs_statfs(struct dentry *, struct kstatfs *);

extern int current_umask(void);

/* /sys/fs */
extern struct kobject *fs_kobj;

Expand Down
2 changes: 1 addition & 1 deletion ipc/mqueue.c
Original file line number Diff line number Diff line change
Expand Up @@ -602,7 +602,7 @@ static struct file *do_create(struct dentry *dir, struct dentry *dentry,
dentry->d_fsdata = attr;
}

mode &= ~current->fs->umask;
mode &= ~current_umask();
ret = mnt_want_write(mqueue_mnt);
if (ret)
goto out;
Expand Down
2 changes: 1 addition & 1 deletion net/unix/af_unix.c
Original file line number Diff line number Diff line change
Expand Up @@ -832,7 +832,7 @@ static int unix_bind(struct socket *sock, struct sockaddr *uaddr, int addr_len)
* All right, let's create it.
*/
mode = S_IFSOCK |
(SOCK_INODE(sock)->i_mode & ~current->fs->umask);
(SOCK_INODE(sock)->i_mode & ~current_umask());
err = mnt_want_write(nd.path.mnt);
if (err)
goto out_mknod_dput;
Expand Down

0 comments on commit ce3b0f8

Please sign in to comment.