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                 default:
  44                         return -EINVAL;
  45         }
  46 }
  47 
  48 
  49 int sys_ioctl(unsigned int fd, unsigned int cmd, unsigned long arg)
     /* [previous][next][first][last][top][bottom][index][help] */
  50 {       
  51         struct file * filp;
  52         int on;
  53 
  54         if (fd >= NR_OPEN || !(filp = current->filp[fd]))
  55                 return -EBADF;
  56         switch (cmd) {
  57                 case FIOCLEX:
  58                         FD_SET(fd, &current->close_on_exec);
  59                         return 0;
  60 
  61                 case FIONCLEX:
  62                         FD_CLR(fd, &current->close_on_exec);
  63                         return 0;
  64 
  65                 case FIONBIO:
  66                         on = get_fs_long((unsigned long *) arg);
  67                         if (on)
  68                                 filp->f_flags |= O_NONBLOCK;
  69                         else
  70                                 filp->f_flags &= ~O_NONBLOCK;
  71                         return 0;
  72 
  73                 case FIOASYNC: /* O_SYNC is not yet implemented,
  74                                   but it's here for completeness. */
  75                         on = get_fs_long ((unsigned long *) arg);
  76                         if (on)
  77                                 filp->f_flags |= O_SYNC;
  78                         else
  79                                 filp->f_flags &= ~O_SYNC;
  80                         return 0;
  81 
  82                 default:
  83                         if (filp->f_inode && S_ISREG(filp->f_inode->i_mode))
  84                                 return file_ioctl(filp,cmd,arg);
  85 
  86                         if (filp->f_op && filp->f_op->ioctl)
  87                                 return filp->f_op->ioctl(filp->f_inode, filp, cmd,arg);
  88 
  89                         return -EINVAL;
  90         }
  91 }

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