4 * Copyright (C) 1991, 1992 Linus Torvalds
7 #include <linux/config.h>
8 #include <linux/syscalls.h>
10 #include <linux/smp_lock.h>
11 #include <linux/file.h>
13 #include <linux/security.h>
14 #include <linux/module.h>
15 #include <linux/proc_fs.h>
16 #include <linux/vserver/inode.h>
17 #include <linux/vserver/xid.h>
18 #include <linux/module.h>
20 #include <asm/uaccess.h>
21 #include <asm/ioctls.h>
23 #ifdef CONFIG_VSERVER_LEGACY
24 extern int vx_proc_ioctl(struct inode *, struct file *,
25 unsigned int, unsigned long);
28 static int file_ioctl(struct file *filp,unsigned int cmd,unsigned long arg)
32 struct inode * inode = filp->f_dentry->d_inode;
33 int __user *p = (int __user *)arg;
38 struct address_space *mapping = filp->f_mapping;
40 /* do we support this mess? */
41 if (!mapping->a_ops->bmap)
43 if (!capable(CAP_SYS_RAWIO))
45 if ((error = get_user(block, p)) != 0)
48 res = mapping->a_ops->bmap(mapping, block);
49 return put_user(res, p);
52 if (inode->i_sb == NULL)
54 return put_user(inode->i_sb->s_blocksize, p);
56 return put_user(i_size_read(inode) - filp->f_pos, p);
58 if (filp->f_op && filp->f_op->ioctl)
59 return filp->f_op->ioctl(inode, filp, cmd, arg);
64 asmlinkage long sys_ioctl(unsigned int fd, unsigned int cmd, unsigned long arg)
68 int on, error = -EBADF;
74 error = security_file_ioctl(filp, cmd, arg);
83 set_close_on_exec(fd, 1);
87 set_close_on_exec(fd, 0);
91 if ((error = get_user(on, (int __user *)arg)) != 0)
95 /* SunOS compatibility item. */
96 if(O_NONBLOCK != O_NDELAY)
100 filp->f_flags |= flag;
102 filp->f_flags &= ~flag;
106 if ((error = get_user(on, (int __user *)arg)) != 0)
108 flag = on ? FASYNC : 0;
110 /* Did FASYNC state change ? */
111 if ((flag ^ filp->f_flags) & FASYNC) {
112 if (filp->f_op && filp->f_op->fasync)
113 error = filp->f_op->fasync(fd, filp, on);
114 else error = -ENOTTY;
120 filp->f_flags |= FASYNC;
122 filp->f_flags &= ~FASYNC;
126 if (S_ISDIR(filp->f_dentry->d_inode->i_mode) ||
127 S_ISREG(filp->f_dentry->d_inode->i_mode) ||
128 S_ISLNK(filp->f_dentry->d_inode->i_mode)) {
129 loff_t res = inode_get_bytes(filp->f_dentry->d_inode);
130 error = copy_to_user((loff_t __user *)arg, &res, sizeof(res)) ? -EFAULT : 0;
135 #ifdef CONFIG_VSERVER_LEGACY
136 #ifndef CONFIG_INOXID_NONE
138 struct inode *inode = filp->f_dentry->d_inode;
140 /* fixme: if stealth, return -ENOTTY */
142 if (capable(CAP_CONTEXT))
143 error = put_user(inode->i_xid, (int *) arg);
147 struct inode *inode = filp->f_dentry->d_inode;
150 /* fixme: if stealth, return -ENOTTY */
152 if (!capable(CAP_CONTEXT))
155 if (IS_RDONLY(inode))
158 if (!(inode->i_sb->s_flags & MS_TAGXID))
161 if (get_user(xid, (int *) arg))
164 inode->i_xid = (xid & 0xFFFF);
165 inode->i_ctime = CURRENT_TIME;
166 mark_inode_dirty(inode);
173 if (filp->f_dentry->d_inode->i_sb->s_magic == PROC_SUPER_MAGIC)
174 error = vx_proc_ioctl(filp->f_dentry->d_inode, filp, cmd, arg);
179 if (S_ISREG(filp->f_dentry->d_inode->i_mode))
180 error = file_ioctl(filp, cmd, arg);
181 else if (filp->f_op && filp->f_op->ioctl)
182 error = filp->f_op->ioctl(filp->f_dentry->d_inode, filp, cmd, arg);
192 * Platforms implementing 32 bit compatibility ioctl handlers in
193 * modules need this exported
196 EXPORT_SYMBOL(sys_ioctl);