mirror of
https://github.com/adulau/aha.git
synced 2024-12-28 11:46:19 +00:00
VFS: apply coding standards to fs/ioctl.c
Signed-off-by: Erez Zadok <ezk@cs.sunysb.edu> Cc: Christoph Hellwig <hch@lst.de> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
This commit is contained in:
parent
4aa323bd83
commit
c9845ff1df
1 changed files with 83 additions and 79 deletions
162
fs/ioctl.c
162
fs/ioctl.c
|
@ -12,8 +12,8 @@
|
||||||
#include <linux/fs.h>
|
#include <linux/fs.h>
|
||||||
#include <linux/security.h>
|
#include <linux/security.h>
|
||||||
#include <linux/module.h>
|
#include <linux/module.h>
|
||||||
|
#include <linux/uaccess.h>
|
||||||
|
|
||||||
#include <asm/uaccess.h>
|
|
||||||
#include <asm/ioctls.h>
|
#include <asm/ioctls.h>
|
||||||
|
|
||||||
static long do_ioctl(struct file *filp, unsigned int cmd,
|
static long do_ioctl(struct file *filp, unsigned int cmd,
|
||||||
|
@ -45,31 +45,31 @@ static int file_ioctl(struct file *filp, unsigned int cmd,
|
||||||
{
|
{
|
||||||
int error;
|
int error;
|
||||||
int block;
|
int block;
|
||||||
struct inode * inode = filp->f_path.dentry->d_inode;
|
struct inode *inode = filp->f_path.dentry->d_inode;
|
||||||
int __user *p = (int __user *)arg;
|
int __user *p = (int __user *)arg;
|
||||||
|
|
||||||
switch (cmd) {
|
switch (cmd) {
|
||||||
case FIBMAP:
|
case FIBMAP:
|
||||||
{
|
{
|
||||||
struct address_space *mapping = filp->f_mapping;
|
struct address_space *mapping = filp->f_mapping;
|
||||||
int res;
|
int res;
|
||||||
/* 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;
|
||||||
if ((error = get_user(block, p)) != 0)
|
error = get_user(block, p);
|
||||||
return error;
|
if (error)
|
||||||
|
return error;
|
||||||
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);
|
||||||
}
|
}
|
||||||
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:
|
||||||
return put_user(i_size_read(inode) - filp->f_pos, p);
|
return put_user(i_size_read(inode) - filp->f_pos, p);
|
||||||
}
|
}
|
||||||
|
|
||||||
return do_ioctl(filp, cmd, arg);
|
return do_ioctl(filp, cmd, arg);
|
||||||
|
@ -82,81 +82,85 @@ static int file_ioctl(struct file *filp, unsigned int cmd,
|
||||||
* vfs_ioctl() is not for drivers and not intended to be EXPORT_SYMBOL()'d.
|
* 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.
|
* It's just a simple helper for sys_ioctl and compat_sys_ioctl.
|
||||||
*/
|
*/
|
||||||
int vfs_ioctl(struct file *filp, unsigned int fd, unsigned int cmd, unsigned long arg)
|
int 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 = 0;
|
||||||
|
|
||||||
switch (cmd) {
|
switch (cmd) {
|
||||||
case FIOCLEX:
|
case FIOCLEX:
|
||||||
set_close_on_exec(fd, 1);
|
set_close_on_exec(fd, 1);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case FIONCLEX:
|
case FIONCLEX:
|
||||||
set_close_on_exec(fd, 0);
|
set_close_on_exec(fd, 0);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case FIONBIO:
|
case FIONBIO:
|
||||||
if ((error = get_user(on, (int __user *)arg)) != 0)
|
error = get_user(on, (int __user *)arg);
|
||||||
break;
|
if (error)
|
||||||
flag = O_NONBLOCK;
|
break;
|
||||||
|
flag = O_NONBLOCK;
|
||||||
#ifdef __sparc__
|
#ifdef __sparc__
|
||||||
/* SunOS compatibility item. */
|
/* SunOS compatibility item. */
|
||||||
if(O_NONBLOCK != O_NDELAY)
|
if (O_NONBLOCK != O_NDELAY)
|
||||||
flag |= O_NDELAY;
|
flag |= O_NDELAY;
|
||||||
#endif
|
#endif
|
||||||
if (on)
|
if (on)
|
||||||
filp->f_flags |= flag;
|
filp->f_flags |= flag;
|
||||||
else
|
else
|
||||||
filp->f_flags &= ~flag;
|
filp->f_flags &= ~flag;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case FIOASYNC:
|
||||||
|
error = get_user(on, (int __user *)arg);
|
||||||
|
if (error)
|
||||||
break;
|
break;
|
||||||
|
flag = on ? FASYNC : 0;
|
||||||
|
|
||||||
case FIOASYNC:
|
/* Did FASYNC state change ? */
|
||||||
if ((error = get_user(on, (int __user *)arg)) != 0)
|
if ((flag ^ filp->f_flags) & FASYNC) {
|
||||||
break;
|
if (filp->f_op && filp->f_op->fasync) {
|
||||||
flag = on ? FASYNC : 0;
|
lock_kernel();
|
||||||
|
error = filp->f_op->fasync(fd, filp, on);
|
||||||
/* Did FASYNC state change ? */
|
unlock_kernel();
|
||||||
if ((flag ^ filp->f_flags) & FASYNC) {
|
} else
|
||||||
if (filp->f_op && filp->f_op->fasync) {
|
|
||||||
lock_kernel();
|
|
||||||
error = filp->f_op->fasync(fd, filp, on);
|
|
||||||
unlock_kernel();
|
|
||||||
}
|
|
||||||
else error = -ENOTTY;
|
|
||||||
}
|
|
||||||
if (error != 0)
|
|
||||||
break;
|
|
||||||
|
|
||||||
if (on)
|
|
||||||
filp->f_flags |= FASYNC;
|
|
||||||
else
|
|
||||||
filp->f_flags &= ~FASYNC;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case FIOQSIZE:
|
|
||||||
if (S_ISDIR(filp->f_path.dentry->d_inode->i_mode) ||
|
|
||||||
S_ISREG(filp->f_path.dentry->d_inode->i_mode) ||
|
|
||||||
S_ISLNK(filp->f_path.dentry->d_inode->i_mode)) {
|
|
||||||
loff_t res = inode_get_bytes(filp->f_path.dentry->d_inode);
|
|
||||||
error = copy_to_user((loff_t __user *)arg, &res, sizeof(res)) ? -EFAULT : 0;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
error = -ENOTTY;
|
error = -ENOTTY;
|
||||||
|
}
|
||||||
|
if (error != 0)
|
||||||
break;
|
break;
|
||||||
default:
|
|
||||||
if (S_ISREG(filp->f_path.dentry->d_inode->i_mode))
|
if (on)
|
||||||
error = file_ioctl(filp, cmd, arg);
|
filp->f_flags |= FASYNC;
|
||||||
else
|
else
|
||||||
error = do_ioctl(filp, cmd, arg);
|
filp->f_flags &= ~FASYNC;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case FIOQSIZE:
|
||||||
|
if (S_ISDIR(filp->f_path.dentry->d_inode->i_mode) ||
|
||||||
|
S_ISREG(filp->f_path.dentry->d_inode->i_mode) ||
|
||||||
|
S_ISLNK(filp->f_path.dentry->d_inode->i_mode)) {
|
||||||
|
loff_t res =
|
||||||
|
inode_get_bytes(filp->f_path.dentry->d_inode);
|
||||||
|
error = copy_to_user((loff_t __user *)arg, &res,
|
||||||
|
sizeof(res)) ? -EFAULT : 0;
|
||||||
|
} else
|
||||||
|
error = -ENOTTY;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
if (S_ISREG(filp->f_path.dentry->d_inode->i_mode))
|
||||||
|
error = file_ioctl(filp, cmd, arg);
|
||||||
|
else
|
||||||
|
error = do_ioctl(filp, cmd, arg);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
|
|
||||||
asmlinkage long sys_ioctl(unsigned int fd, unsigned int cmd, unsigned long arg)
|
asmlinkage long sys_ioctl(unsigned int fd, unsigned int cmd, unsigned long arg)
|
||||||
{
|
{
|
||||||
struct file * filp;
|
struct file *filp;
|
||||||
int error = -EBADF;
|
int error = -EBADF;
|
||||||
int fput_needed;
|
int fput_needed;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue