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, ...@@ -52,32 +52,34 @@ long vfs_ioctl(struct file *filp, unsigned int cmd,
return error; return error;
} }
static int file_ioctl(struct file *filp, unsigned int cmd, static int ioctl_fibmap(struct file *filp, int __user *p)
unsigned long arg)
{ {
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; struct address_space *mapping = filp->f_mapping;
int res; int res, block;
/* do we support this mess? */ /* do we support this mess? */
if (!mapping->a_ops->bmap) if (!mapping->a_ops->bmap)
return -EINVAL; return -EINVAL;
if (!capable(CAP_SYS_RAWIO)) if (!capable(CAP_SYS_RAWIO))
return -EPERM; return -EPERM;
error = get_user(block, p); res = get_user(block, p);
if (error) if (res)
return error; return res;
lock_kernel(); lock_kernel();
res = mapping->a_ops->bmap(mapping, block); res = mapping->a_ops->bmap(mapping, block);
unlock_kernel(); unlock_kernel();
return put_user(res, p); 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: case FIGETBSZ:
return put_user(inode->i_sb->s_blocksize, p); return put_user(inode->i_sb->s_blocksize, p);
case FIONREAD: case FIONREAD:
...@@ -87,32 +89,14 @@ static int file_ioctl(struct file *filp, unsigned int cmd, ...@@ -87,32 +89,14 @@ static int file_ioctl(struct file *filp, unsigned int cmd,
return vfs_ioctl(filp, cmd, arg); return vfs_ioctl(filp, cmd, arg);
} }
/* static int ioctl_fionbio(struct file *filp, int __user *argp)
* 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)
{ {
unsigned int flag; unsigned int flag;
int on, error = 0; int on, error;
switch (cmd) {
case FIOCLEX:
set_close_on_exec(fd, 1);
break;
case FIONCLEX:
set_close_on_exec(fd, 0);
break;
case FIONBIO: error = get_user(on, argp);
error = get_user(on, (int __user *)arg);
if (error) if (error)
break; return error;
flag = O_NONBLOCK; flag = O_NONBLOCK;
#ifdef __sparc__ #ifdef __sparc__
/* SunOS compatibility item. */ /* SunOS compatibility item. */
...@@ -123,12 +107,18 @@ int do_vfs_ioctl(struct file *filp, unsigned int fd, unsigned int cmd, ...@@ -123,12 +107,18 @@ int do_vfs_ioctl(struct file *filp, unsigned int fd, unsigned int cmd,
filp->f_flags |= flag; filp->f_flags |= flag;
else else
filp->f_flags &= ~flag; filp->f_flags &= ~flag;
break; return error;
}
case FIOASYNC: static int ioctl_fioasync(unsigned int fd, struct file *filp,
error = get_user(on, (int __user *)arg); int __user *argp)
{
unsigned int flag;
int on, error;
error = get_user(on, argp);
if (error) if (error)
break; return error;
flag = on ? FASYNC : 0; flag = on ? FASYNC : 0;
/* Did FASYNC state change ? */ /* Did FASYNC state change ? */
...@@ -140,13 +130,44 @@ int do_vfs_ioctl(struct file *filp, unsigned int fd, unsigned int cmd, ...@@ -140,13 +130,44 @@ int do_vfs_ioctl(struct file *filp, unsigned int fd, unsigned int cmd,
} else } else
error = -ENOTTY; error = -ENOTTY;
} }
if (error != 0) if (error)
break; return error;
if (on) if (on)
filp->f_flags |= FASYNC; filp->f_flags |= FASYNC;
else else
filp->f_flags &= ~FASYNC; 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; break;
case FIOQSIZE: 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