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 = verify_area(VERIFY_READ, (unsigned int *)arg,
  76                                 sizeof(unsigned int));
  77                         if(on)  
  78                                 return on;
  79                         on = get_user((unsigned int *) arg);
  80                         if (on)
  81                                 filp->f_flags |= O_NONBLOCK;
  82                         else
  83                                 filp->f_flags &= ~O_NONBLOCK;
  84                         return 0;
  85 
  86                 case FIOASYNC: /* O_SYNC is not yet implemented,
  87                                   but it's here for completeness. */
  88                         on = verify_area(VERIFY_READ, (unsigned int *)arg,
  89                                 sizeof(unsigned int));
  90                         if(on)  
  91                                 return on;
  92                         on = get_user ((unsigned int *) arg);
  93                         if (on)
  94                                 filp->f_flags |= O_SYNC;
  95                         else
  96                                 filp->f_flags &= ~O_SYNC;
  97                         return 0;
  98 
  99                 default:
 100                         if (filp->f_inode && S_ISREG(filp->f_inode->i_mode))
 101                                 return file_ioctl(filp, cmd, arg);
 102 
 103                         if (filp->f_op && filp->f_op->ioctl)
 104                                 return filp->f_op->ioctl(filp->f_inode, filp, cmd, arg);
 105 
 106                         return -EINVAL;
 107         }
 108 }

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