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

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