vfs: create a generic checking function for FS_IOC_FSSETXATTR
Create a generic checking function for the incoming FS_IOC_FSSETXATTR fsxattr values so that we can standardize some of the implementation behaviors. Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com> Reviewed-by: Jan Kara <jack@suse.cz>
This commit is contained in:
@@ -375,9 +375,7 @@ static int btrfs_ioctl_fsgetxattr(struct file *file, void __user *arg)
|
||||
struct btrfs_inode *binode = BTRFS_I(file_inode(file));
|
||||
struct fsxattr fa;
|
||||
|
||||
memset(&fa, 0, sizeof(fa));
|
||||
fa.fsx_xflags = btrfs_inode_flags_to_xflags(binode->flags);
|
||||
|
||||
simple_fill_fsxattr(&fa, btrfs_inode_flags_to_xflags(binode->flags));
|
||||
if (copy_to_user(arg, &fa, sizeof(fa)))
|
||||
return -EFAULT;
|
||||
|
||||
@@ -390,7 +388,7 @@ static int btrfs_ioctl_fssetxattr(struct file *file, void __user *arg)
|
||||
struct btrfs_inode *binode = BTRFS_I(inode);
|
||||
struct btrfs_root *root = binode->root;
|
||||
struct btrfs_trans_handle *trans;
|
||||
struct fsxattr fa;
|
||||
struct fsxattr fa, old_fa;
|
||||
unsigned old_flags;
|
||||
unsigned old_i_flags;
|
||||
int ret = 0;
|
||||
@@ -401,7 +399,6 @@ static int btrfs_ioctl_fssetxattr(struct file *file, void __user *arg)
|
||||
if (btrfs_root_readonly(root))
|
||||
return -EROFS;
|
||||
|
||||
memset(&fa, 0, sizeof(fa));
|
||||
if (copy_from_user(&fa, arg, sizeof(fa)))
|
||||
return -EFAULT;
|
||||
|
||||
@@ -421,13 +418,11 @@ static int btrfs_ioctl_fssetxattr(struct file *file, void __user *arg)
|
||||
old_flags = binode->flags;
|
||||
old_i_flags = inode->i_flags;
|
||||
|
||||
/* We need the capabilities to change append-only or immutable inode */
|
||||
if (((old_flags & (BTRFS_INODE_APPEND | BTRFS_INODE_IMMUTABLE)) ||
|
||||
(fa.fsx_xflags & (FS_XFLAG_APPEND | FS_XFLAG_IMMUTABLE))) &&
|
||||
!capable(CAP_LINUX_IMMUTABLE)) {
|
||||
ret = -EPERM;
|
||||
simple_fill_fsxattr(&old_fa,
|
||||
btrfs_inode_flags_to_xflags(binode->flags));
|
||||
ret = vfs_ioc_fssetxattr_check(inode, &old_fa, &fa);
|
||||
if (ret)
|
||||
goto out_unlock;
|
||||
}
|
||||
|
||||
if (fa.fsx_xflags & FS_XFLAG_SYNC)
|
||||
binode->flags |= BTRFS_INODE_SYNC;
|
||||
|
Reference in New Issue
Block a user