Commit 52656e6c authored by Jaegeuk Kim's avatar Jaegeuk Kim

f2fs: clean up f2fs_ioctl functions

This patch cleans up f2fs_ioctl functions for better readability.
Signed-off-by: default avatarJaegeuk Kim <jaegeuk@kernel.org>
parent 8a21984d
...@@ -805,20 +805,21 @@ static inline __u32 f2fs_mask_flags(umode_t mode, __u32 flags) ...@@ -805,20 +805,21 @@ static inline __u32 f2fs_mask_flags(umode_t mode, __u32 flags)
return flags & F2FS_OTHER_FLMASK; 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 inode *inode = file_inode(filp);
struct f2fs_inode_info *fi = F2FS_I(inode); struct f2fs_inode_info *fi = F2FS_I(inode);
unsigned int flags; unsigned int flags = fi->i_flags & FS_FL_USER_VISIBLE;
int ret; return put_user(flags, (int __user *)arg);
}
switch (cmd) { static int f2fs_ioc_setflags(struct file *filp, unsigned long arg)
case F2FS_IOC_GETFLAGS: {
flags = fi->i_flags & FS_FL_USER_VISIBLE; struct inode *inode = file_inode(filp);
return put_user(flags, (int __user *) arg); struct f2fs_inode_info *fi = F2FS_I(inode);
case F2FS_IOC_SETFLAGS: unsigned int flags = fi->i_flags & FS_FL_USER_VISIBLE;
{
unsigned int oldflags; unsigned int oldflags;
int ret;
ret = mnt_want_write_file(filp); ret = mnt_want_write_file(filp);
if (ret) if (ret)
...@@ -829,7 +830,7 @@ long f2fs_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) ...@@ -829,7 +830,7 @@ long f2fs_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
goto out; goto out;
} }
if (get_user(flags, (int __user *) arg)) { if (get_user(flags, (int __user *)arg)) {
ret = -EFAULT; ret = -EFAULT;
goto out; goto out;
} }
...@@ -859,13 +860,15 @@ long f2fs_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) ...@@ -859,13 +860,15 @@ long f2fs_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
out: out:
mnt_drop_write_file(filp); mnt_drop_write_file(filp);
return ret; return ret;
} }
case FITRIM:
{ 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 super_block *sb = inode->i_sb;
struct request_queue *q = bdev_get_queue(sb->s_bdev); struct request_queue *q = bdev_get_queue(sb->s_bdev);
struct fstrim_range range; struct fstrim_range range;
int ret = 0; int ret;
if (!capable(CAP_SYS_ADMIN)) if (!capable(CAP_SYS_ADMIN))
return -EPERM; return -EPERM;
...@@ -886,9 +889,18 @@ long f2fs_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) ...@@ -886,9 +889,18 @@ long f2fs_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
if (copy_to_user((struct fstrim_range __user *)arg, &range, if (copy_to_user((struct fstrim_range __user *)arg, &range,
sizeof(range))) sizeof(range)))
return -EFAULT; return -EFAULT;
return 0; 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: default:
return -ENOTTY; return -ENOTTY;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment