|
|
1.1.1.2 root 1: /*
2: * linux/fs/ioctl.c
3: *
4: * (C) 1991 Linus Torvalds
5: */
6:
1.1 root 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);
1.1.1.5 ! root 14: extern int pipe_ioctl(struct inode *pino, int cmd, int arg);
1.1 root 15:
16: typedef int (*ioctl_ptr)(int dev,int cmd,int arg);
17:
18: #define NRDEVS ((sizeof (ioctl_table))/(sizeof (ioctl_ptr)))
19:
20: static ioctl_ptr ioctl_table[]={
21: NULL, /* nodev */
22: NULL, /* /dev/mem */
23: NULL, /* /dev/fd */
24: NULL, /* /dev/hd */
25: tty_ioctl, /* /dev/ttyx */
26: tty_ioctl, /* /dev/tty */
27: NULL, /* /dev/lp */
28: NULL}; /* named pipes */
29:
30:
31: int sys_ioctl(unsigned int fd, unsigned int cmd, unsigned long arg)
32: {
33: struct file * filp;
34: int dev,mode;
35:
36: if (fd >= NR_OPEN || !(filp = current->filp[fd]))
37: return -EBADF;
1.1.1.4 root 38: if (filp->f_inode->i_pipe)
39: return (filp->f_mode&1)?pipe_ioctl(filp->f_inode,cmd,arg):-EBADF;
1.1 root 40: mode=filp->f_inode->i_mode;
41: if (!S_ISCHR(mode) && !S_ISBLK(mode))
42: return -EINVAL;
1.1.1.5 ! root 43: dev = filp->f_inode->i_rdev;
1.1 root 44: if (MAJOR(dev) >= NRDEVS)
1.1.1.3 root 45: return -ENODEV;
1.1 root 46: if (!ioctl_table[MAJOR(dev)])
47: return -ENOTTY;
48: return ioctl_table[MAJOR(dev)](dev,cmd,arg);
49: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.