Commit aa81a7c7 authored by Erez Zadok's avatar Erez Zadok Committed by Linus Torvalds

VFS: factor out three helpers for FIBMAP/FIONBIO/FIOASYNC file ioctls

Factor out file-specific ioctl code into smaller helper functions, away from
file_ioctl().  This helps code readability and also reduces indentation inside
case statements.
Signed-off-by: default avatarErez Zadok <ezk@cs.sunysb.edu>
Cc: Christoph Hellwig <hch@lst.de>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent deb21db7
......@@ -52,32 +52,34 @@ long vfs_ioctl(struct file *filp, unsigned int cmd,
return error;
}
static int file_ioctl(struct file *filp, unsigned int cmd,
unsigned long arg)
static int ioctl_fibmap(struct file *filp, int __user *p)
{
int error;
int block;
struct inode *inode = filp->f_path.dentry->d_inode;
int __user *p = (int __user *)arg;
switch (cmd) {
case FIBMAP:
{
struct address_space *mapping = filp->f_mapping;
int res;
int res, block;
/* do we support this mess? */
if (!mapping->a_ops->bmap)
return -EINVAL;
if (!capable(CAP_SYS_RAWIO))
return -EPERM;
error = get_user(block, p);
if (error)
return error;
res = get_user(block, p);
if (res)
return res;
lock_kernel();
res = mapping->a_ops->bmap(mapping, block);
unlock_kernel();
return put_user(res, p);
}
}
static int file_ioctl(struct file *filp, unsigned int cmd,
unsigned long arg)
{
struct inode *inode = filp->f_path.dentry->d_inode;
int __user *p = (int __user *)arg;
switch (cmd) {
case FIBMAP:
return ioctl_fibmap(filp, p);
case FIGETBSZ:
return put_user(inode->i_sb->s_blocksize, p);
case FIONREAD:
......@@ -87,32 +89,14 @@ static int file_ioctl(struct file *filp, unsigned int cmd,
return vfs_ioctl(filp, cmd, arg);
}
/*
* When you add any new common ioctls to the switches above and below
* please update compat_sys_ioctl() too.
*
* do_vfs_ioctl() is not for drivers and not intended to be EXPORT_SYMBOL()'d.
* It's just a simple helper for sys_ioctl and compat_sys_ioctl.
*/
int do_vfs_ioctl(struct file *filp, unsigned int fd, unsigned int cmd,
unsigned long arg)
static int ioctl_fionbio(struct file *filp, int __user *argp)
{
unsigned int flag;
int on, error = 0;
switch (cmd) {
case FIOCLEX:
set_close_on_exec(fd, 1);
break;
case FIONCLEX:
set_close_on_exec(fd, 0);
break;
int on, error;
case FIONBIO:
error = get_user(on, (int __user *)arg);
error = get_user(on, argp);
if (error)
break;
return error;
flag = O_NONBLOCK;
#ifdef __sparc__
/* SunOS compatibility item. */
......@@ -123,12 +107,18 @@ int do_vfs_ioctl(struct file *filp, unsigned int fd, unsigned int cmd,
filp->f_flags |= flag;
else
filp->f_flags &= ~flag;
break;
return error;
}
case FIOASYNC:
error = get_user(on, (int __user *)arg);
static int ioctl_fioasync(unsigned int fd, struct file *filp,
int __user *argp)
{
unsigned int flag;
int on, error;
error = get_user(on, argp);
if (error)
break;
return error;
flag = on ? FASYNC : 0;
/* Did FASYNC state change ? */
......@@ -140,13 +130,44 @@ int do_vfs_ioctl(struct file *filp, unsigned int fd, unsigned int cmd,
} else
error = -ENOTTY;
}
if (error != 0)
break;
if (error)
return error;
if (on)
filp->f_flags |= FASYNC;
else
filp->f_flags &= ~FASYNC;
return error;
}
/*
* When you add any new common ioctls to the switches above and below
* please update compat_sys_ioctl() too.
*
* do_vfs_ioctl() is not for drivers and not intended to be EXPORT_SYMBOL()'d.
* It's just a simple helper for sys_ioctl and compat_sys_ioctl.
*/
int do_vfs_ioctl(struct file *filp, unsigned int fd, unsigned int cmd,
unsigned long arg)
{
int error = 0;
int __user *argp = (int __user *)arg;
switch (cmd) {
case FIOCLEX:
set_close_on_exec(fd, 1);
break;
case FIONCLEX:
set_close_on_exec(fd, 0);
break;
case FIONBIO:
error = ioctl_fionbio(filp, argp);
break;
case FIOASYNC:
error = ioctl_fioasync(fd, filp, argp);
break;
case FIOQSIZE:
......
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