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 tty_ioctl(int dev, int cmd, int arg);
14
15 typedef int (*ioctl_ptr)(int dev,int cmd,int arg);
16
17 #define NRDEVS ((sizeof (ioctl_table))/(sizeof (ioctl_ptr)))
18
19 static ioctl_ptr ioctl_table[]={
20 NULL,
21 NULL,
22 NULL,
23 NULL,
24 tty_ioctl,
25 tty_ioctl,
26 NULL,
27 NULL};
28
29
30 int sys_ioctl(unsigned int fd, unsigned int cmd, unsigned long arg)
31 {
32 struct file * filp;
33 int dev,mode;
34
35 if (fd >= NR_OPEN || !(filp = current->filp[fd]))
36 return -EBADF;
37 mode=filp->f_inode->i_mode;
38 if (!S_ISCHR(mode) && !S_ISBLK(mode))
39 return -EINVAL;
40 dev = filp->f_inode->i_zone[0];
41 if (MAJOR(dev) >= NRDEVS)
42 return -ENODEV;
43 if (!ioctl_table[MAJOR(dev)])
44 return -ENOTTY;
45 return ioctl_table[MAJOR(dev)](dev,cmd,arg);
46 }