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 
  15 static int file_ioctl(struct file *filp,unsigned int cmd,unsigned long arg)
     /* [previous][next][first][last][top][bottom][index][help] */
  16 {
  17         int block;
  18 
  19         switch (cmd) {
  20                 case FIBMAP:
  21                         if (filp->f_inode->i_op == NULL)
  22                                 return -EBADF;
  23                         if (filp->f_inode->i_op->bmap == NULL)
  24                                 return -EINVAL;
  25                         verify_area((void *) arg,4);
  26                         block = get_fs_long((long *) arg);
  27                         block = filp->f_inode->i_op->bmap(filp->f_inode,block);
  28                         put_fs_long(block,(long *) arg);
  29                         return 0;
  30                 case FIGETBSZ:
  31                         if (filp->f_inode->i_sb == NULL)
  32                                 return -EBADF;
  33                         verify_area((void *) arg,4);
  34                         put_fs_long(filp->f_inode->i_sb->s_blocksize,
  35                             (long *) arg);
  36                         return 0;
  37                 case FIONREAD:
  38                         verify_area((void *) arg,4);
  39                         put_fs_long(filp->f_inode->i_size - filp->f_pos,
  40                             (long *) arg);
  41                         return 0;
  42                 default:
  43                         return -EINVAL;
  44         }
  45 }
  46 
  47 
  48 int sys_ioctl(unsigned int fd, unsigned int cmd, unsigned long arg)
     /* [previous][next][first][last][top][bottom][index][help] */
  49 {       
  50         struct file * filp;
  51 
  52         if (fd >= NR_OPEN || !(filp = current->filp[fd]))
  53                 return -EBADF;
  54         if (filp->f_inode && S_ISREG(filp->f_inode->i_mode))
  55                 return file_ioctl(filp,cmd,arg);
  56         if (filp->f_op && filp->f_op->ioctl)
  57                 return filp->f_op->ioctl(filp->f_inode, filp, cmd,arg);
  58         return -EINVAL;
  59 }

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