diff options
author | Jaegeuk Kim <jaegeuk@kernel.org> | 2014-09-24 15:37:02 -0700 |
---|---|---|
committer | Jaegeuk Kim <jaegeuk@kernel.org> | 2014-09-30 15:34:56 -0700 |
commit | 52656e6cf7be6955e3ea01dbb835b43119278a12 (patch) | |
tree | 10f23bba874605e3e1882ccdaaf055d1ed073442 /fs | |
parent | 8a21984d5d86540ba32b4b346d8fe6426018b7a7 (diff) | |
download | op-kernel-dev-52656e6cf7be6955e3ea01dbb835b43119278a12.zip op-kernel-dev-52656e6cf7be6955e3ea01dbb835b43119278a12.tar.gz |
f2fs: clean up f2fs_ioctl functions
This patch cleans up f2fs_ioctl functions for better readability.
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
Diffstat (limited to 'fs')
-rw-r--r-- | fs/f2fs/file.c | 138 |
1 files changed, 75 insertions, 63 deletions
diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c index 1184207..735e9a2 100644 --- a/fs/f2fs/file.c +++ b/fs/f2fs/file.c @@ -805,90 +805,102 @@ static inline __u32 f2fs_mask_flags(umode_t mode, __u32 flags) return flags & F2FS_OTHER_FLMASK; } -long f2fs_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) +static int f2fs_ioc_getflags(struct file *filp, unsigned long arg) { struct inode *inode = file_inode(filp); struct f2fs_inode_info *fi = F2FS_I(inode); - unsigned int flags; - int ret; + unsigned int flags = fi->i_flags & FS_FL_USER_VISIBLE; + return put_user(flags, (int __user *)arg); +} - switch (cmd) { - case F2FS_IOC_GETFLAGS: - flags = fi->i_flags & FS_FL_USER_VISIBLE; - return put_user(flags, (int __user *) arg); - case F2FS_IOC_SETFLAGS: - { - unsigned int oldflags; +static int f2fs_ioc_setflags(struct file *filp, unsigned long arg) +{ + struct inode *inode = file_inode(filp); + struct f2fs_inode_info *fi = F2FS_I(inode); + unsigned int flags = fi->i_flags & FS_FL_USER_VISIBLE; + unsigned int oldflags; + int ret; - ret = mnt_want_write_file(filp); - if (ret) - return ret; + ret = mnt_want_write_file(filp); + if (ret) + return ret; - if (!inode_owner_or_capable(inode)) { - ret = -EACCES; - goto out; - } + if (!inode_owner_or_capable(inode)) { + ret = -EACCES; + goto out; + } - if (get_user(flags, (int __user *) arg)) { - ret = -EFAULT; - goto out; - } + if (get_user(flags, (int __user *)arg)) { + ret = -EFAULT; + goto out; + } - flags = f2fs_mask_flags(inode->i_mode, flags); + flags = f2fs_mask_flags(inode->i_mode, flags); - mutex_lock(&inode->i_mutex); + mutex_lock(&inode->i_mutex); - oldflags = fi->i_flags; + oldflags = fi->i_flags; - if ((flags ^ oldflags) & (FS_APPEND_FL | FS_IMMUTABLE_FL)) { - if (!capable(CAP_LINUX_IMMUTABLE)) { - mutex_unlock(&inode->i_mutex); - ret = -EPERM; - goto out; - } + if ((flags ^ oldflags) & (FS_APPEND_FL | FS_IMMUTABLE_FL)) { + if (!capable(CAP_LINUX_IMMUTABLE)) { + mutex_unlock(&inode->i_mutex); + ret = -EPERM; + goto out; } + } - flags = flags & FS_FL_USER_MODIFIABLE; - flags |= oldflags & ~FS_FL_USER_MODIFIABLE; - fi->i_flags = flags; - mutex_unlock(&inode->i_mutex); + flags = flags & FS_FL_USER_MODIFIABLE; + flags |= oldflags & ~FS_FL_USER_MODIFIABLE; + fi->i_flags = flags; + mutex_unlock(&inode->i_mutex); - f2fs_set_inode_flags(inode); - inode->i_ctime = CURRENT_TIME; - mark_inode_dirty(inode); + f2fs_set_inode_flags(inode); + inode->i_ctime = CURRENT_TIME; + mark_inode_dirty(inode); out: - mnt_drop_write_file(filp); - return ret; - } - case FITRIM: - { - struct super_block *sb = inode->i_sb; - struct request_queue *q = bdev_get_queue(sb->s_bdev); - struct fstrim_range range; - int ret = 0; + mnt_drop_write_file(filp); + return ret; +} - if (!capable(CAP_SYS_ADMIN)) - return -EPERM; +static int f2fs_ioc_fitrim(struct file *filp, unsigned long arg) +{ + struct inode *inode = file_inode(filp); + struct super_block *sb = inode->i_sb; + struct request_queue *q = bdev_get_queue(sb->s_bdev); + struct fstrim_range range; + int ret; - if (!blk_queue_discard(q)) - return -EOPNOTSUPP; + if (!capable(CAP_SYS_ADMIN)) + return -EPERM; - if (copy_from_user(&range, (struct fstrim_range __user *)arg, - sizeof(range))) - return -EFAULT; + if (!blk_queue_discard(q)) + return -EOPNOTSUPP; - range.minlen = max((unsigned int)range.minlen, - q->limits.discard_granularity); - ret = f2fs_trim_fs(F2FS_SB(sb), &range); - if (ret < 0) - return ret; + if (copy_from_user(&range, (struct fstrim_range __user *)arg, + sizeof(range))) + return -EFAULT; - if (copy_to_user((struct fstrim_range __user *)arg, &range, - sizeof(range))) - return -EFAULT; + range.minlen = max((unsigned int)range.minlen, + q->limits.discard_granularity); + ret = f2fs_trim_fs(F2FS_SB(sb), &range); + if (ret < 0) + return ret; - return 0; - } + if (copy_to_user((struct fstrim_range __user *)arg, &range, + sizeof(range))) + return -EFAULT; + return 0; +} + +long f2fs_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) +{ + switch (cmd) { + case F2FS_IOC_GETFLAGS: + return f2fs_ioc_getflags(filp, arg); + case F2FS_IOC_SETFLAGS: + return f2fs_ioc_setflags(filp, arg); + case FITRIM: + return f2fs_ioc_fitrim(filp, arg); default: return -ENOTTY; } |