diff options
Diffstat (limited to 'src/fs/ioctl.c')
-rw-r--r-- | src/fs/ioctl.c | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/src/fs/ioctl.c b/src/fs/ioctl.c new file mode 100644 index 0000000..47ce3cb --- /dev/null +++ b/src/fs/ioctl.c | |||
@@ -0,0 +1,46 @@ | |||
1 | /* | ||
2 | * linux/fs/ioctl.c | ||
3 | * | ||
4 | * (C) 1991 Linus Torvalds | ||
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, /* nodev */ | ||
21 | NULL, /* /dev/mem */ | ||
22 | NULL, /* /dev/fd */ | ||
23 | NULL, /* /dev/hd */ | ||
24 | tty_ioctl, /* /dev/ttyx */ | ||
25 | tty_ioctl, /* /dev/tty */ | ||
26 | NULL, /* /dev/lp */ | ||
27 | NULL}; /* named pipes */ | ||
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 | } | ||