Annotation of linux/fs/ioctl.c, revision 1.1.1.6

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: 
1.1.1.6 ! root       13: extern int hd_ioctl(int dev, int cmd, int arg);
1.1       root       14: extern int tty_ioctl(int dev, int cmd, int arg);
1.1.1.5   root       15: extern int pipe_ioctl(struct inode *pino, int cmd, int arg);
1.1       root       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,           /* nodev */
                     23:        NULL,           /* /dev/mem */
                     24:        NULL,           /* /dev/fd */
1.1.1.6 ! root       25:        hd_ioctl,       /* /dev/hd */
1.1       root       26:        tty_ioctl,      /* /dev/ttyx */
                     27:        tty_ioctl,      /* /dev/tty */
                     28:        NULL,           /* /dev/lp */
                     29:        NULL};          /* named pipes */
                     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;
1.1.1.4   root       39:        if (filp->f_inode->i_pipe)
                     40:                return (filp->f_mode&1)?pipe_ioctl(filp->f_inode,cmd,arg):-EBADF;
1.1       root       41:        mode=filp->f_inode->i_mode;
                     42:        if (!S_ISCHR(mode) && !S_ISBLK(mode))
                     43:                return -EINVAL;
1.1.1.5   root       44:        dev = filp->f_inode->i_rdev;
1.1       root       45:        if (MAJOR(dev) >= NRDEVS)
1.1.1.3   root       46:                return -ENODEV;
1.1       root       47:        if (!ioctl_table[MAJOR(dev)])
                     48:                return -ENOTTY;
                     49:        return ioctl_table[MAJOR(dev)](dev,cmd,arg);
                     50: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.