root/fs/ioctl.c

/* [previous][next][first][last][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. sys_ioctl

   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 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,           /* nodev */
  23         NULL,           /* /dev/mem */
  24         NULL,           /* /dev/fd */
  25         hd_ioctl,       /* /dev/hd */
  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)
     /* [previous][next][first][last][top][bottom][index][help] */
  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 }

/* [previous][next][first][last][top][bottom][index][help] */