This source file includes following definitions.
- sys_ioctl
1
2
3
4
5
6
7 #include <string.h>
8 #include <errno.h>
9 #include <sys/stat.h>
10
11 #include <linux/sched.h>
12
13 extern int hd_ioctl(int dev, int cmd, int arg);
14 extern int tty_ioctl(int dev, int cmd, int arg);
15 extern int pipe_ioctl(struct inode *pino, int cmd, int arg);
16
17 typedef int (*ioctl_ptr)(int dev,int cmd,int arg);
18
19 #define NRDEVS ((sizeof (ioctl_table))/(sizeof (ioctl_ptr)))
20
21 static ioctl_ptr ioctl_table[]={
22 NULL,
23 NULL,
24 NULL,
25 hd_ioctl,
26 tty_ioctl,
27 tty_ioctl,
28 NULL,
29 NULL};
30
31
32 int sys_ioctl(unsigned int fd, unsigned int cmd, unsigned long arg)
33 {
34 struct file * filp;
35 int dev,mode;
36
37 if (fd >= NR_OPEN || !(filp = current->filp[fd]))
38 return -EBADF;
39 if (filp->f_inode->i_pipe)
40 return (filp->f_mode&1)?pipe_ioctl(filp->f_inode,cmd,arg):-EBADF;
41 mode=filp->f_inode->i_mode;
42 if (!S_ISCHR(mode) && !S_ISBLK(mode))
43 return -EINVAL;
44 dev = filp->f_inode->i_rdev;
45 if (MAJOR(dev) >= NRDEVS)
46 return -ENODEV;
47 if (!ioctl_table[MAJOR(dev)])
48 return -ENOTTY;
49 return ioctl_table[MAJOR(dev)](dev,cmd,arg);
50 }