root/fs/ioctl.c

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

DEFINITIONS

This source file includes following definitions.
  1. file_ioctl
  2. sys_ioctl

   1 /*
   2  *  linux/fs/ioctl.c
   3  *
   4  *  Copyright (C) 1991, 1992  Linus Torvalds
   5  */
   6 
   7 #include <asm/segment.h>
   8 
   9 #include <linux/sched.h>
  10 #include <linux/mm.h>
  11 #include <linux/errno.h>
  12 #include <linux/string.h>
  13 #include <linux/stat.h>
  14 #include <linux/termios.h>
  15 #include <linux/fcntl.h> /* for f_flags values */
  16 
  17 static int file_ioctl(struct file *filp,unsigned int cmd,unsigned long arg)
     /* [previous][next][first][last][top][bottom][index][help] */
  18 {
  19         int error;
  20         int block;
  21 
  22         switch (cmd) {
  23                 case FIBMAP:
  24                         if (filp->f_inode->i_op == NULL)
  25                                 return -EBADF;
  26                         if (filp->f_inode->i_op->bmap == NULL)
  27                                 return -EINVAL;
  28                         error = verify_area(VERIFY_WRITE,(void *) arg,4);
  29                         if (error)
  30                                 return error;
  31                         block = get_fs_long((long *) arg);
  32                         block = filp->f_inode->i_op->bmap(filp->f_inode,block);
  33                         put_fs_long(block,(long *) arg);
  34                         return 0;
  35                 case FIGETBSZ:
  36                         if (filp->f_inode->i_sb == NULL)
  37                                 return -EBADF;
  38                         error = verify_area(VERIFY_WRITE,(void *) arg,4);
  39                         if (error)
  40                                 return error;
  41                         put_fs_long(filp->f_inode->i_sb->s_blocksize,
  42                             (long *) arg);
  43                         return 0;
  44                 case FIONREAD:
  45                         error = verify_area(VERIFY_WRITE,(void *) arg,sizeof(int));
  46                         if (error)
  47                                 return error;
  48                         put_fs_long(filp->f_inode->i_size - filp->f_pos,
  49                             (int *) arg);
  50                         return 0;
  51         }
  52         if (filp->f_op && filp->f_op->ioctl)
  53                 return filp->f_op->ioctl(filp->f_inode, filp, cmd,arg);
  54         return -EINVAL;
  55 }
  56 
  57 
  58 asmlinkage int sys_ioctl(unsigned int fd, unsigned int cmd, unsigned long arg)
     /* [previous][next][first][last][top][bottom][index][help] */
  59 {       
  60         struct file * filp;
  61         int on;
  62 
  63         if (fd >= NR_OPEN || !(filp = current->files->fd[fd]))
  64                 return -EBADF;
  65         switch (cmd) {
  66                 case FIOCLEX:
  67                         FD_SET(fd, &current->files->close_on_exec);
  68                         return 0;
  69 
  70                 case FIONCLEX:
  71                         FD_CLR(fd, &current->files->close_on_exec);
  72                         return 0;
  73 
  74                 case FIONBIO:
  75                         on = get_fs_long((unsigned long *) arg);
  76                         if (on)
  77                                 filp->f_flags |= O_NONBLOCK;
  78                         else
  79                                 filp->f_flags &= ~O_NONBLOCK;
  80                         return 0;
  81 
  82                 case FIOASYNC: /* O_SYNC is not yet implemented,
  83                                   but it's here for completeness. */
  84                         on = get_fs_long ((unsigned long *) arg);
  85                         if (on)
  86                                 filp->f_flags |= O_SYNC;
  87                         else
  88                                 filp->f_flags &= ~O_SYNC;
  89                         return 0;
  90 
  91                 default:
  92                         if (filp->f_inode && S_ISREG(filp->f_inode->i_mode))
  93                                 return file_ioctl(filp,cmd,arg);
  94 
  95                         if (filp->f_op && filp->f_op->ioctl)
  96                                 return filp->f_op->ioctl(filp->f_inode, filp, cmd,arg);
  97 
  98                         return -EINVAL;
  99         }
 100 }

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