root/include/asm-i386/ioctl.h

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

INCLUDED FROM


   1 /* $Id: ioctl.h,v 1.5 1993/07/19 21:53:50 root Exp root $
   2  *
   3  * linux/ioctl.h for Linux by H.H. Bergman.
   4  */
   5 
   6 #ifndef _ASMI386_IOCTL_H
   7 #define _ASMI386_IOCTL_H
   8 
   9 #include <asm/page.h>           /* for PAGE_SIZE */
  10 
  11 /* ioctl command encoding: 32 bits total, command in lower 16 bits,
  12  * size of the parameter structure in the lower 14 bits of the
  13  * upper 16 bits.
  14  * Encoding the size of the parameter structure in the ioctl request
  15  * is useful for catching programs compiled with old versions
  16  * and to avoid overwriting user space outside the user buffer area.
  17  * The highest 2 bits are reserved for indicating the ``access mode''.
  18  * NOTE: This limits the max parameter size to 16kB -1 !
  19  */
  20 
  21 #define IOC_VOID        0x00000000      /* param in size field */
  22 #define IOC_IN          0x40000000      /* user --> kernel */
  23 #define IOC_OUT         0x80000000      /* kernel --> user */
  24 #define IOC_INOUT       (IOC_IN | IOC_OUT)      /* both */
  25 #define IOCSIZE_MASK    0x3fff0000      /* size (max 16k-1 bytes) */
  26 #define IOCSIZE_SHIFT   16              /* how to get the size */
  27 #define IOCSIZE_MAX     ((PAGE_SIZE-1)&(IOCSIZE_MASK >> IOCSIZE_SHIFT))
  28 #define IOCCMD_MASK     0x0000ffff      /* command code */
  29 #define IOCCMD_SHIFT    0
  30 #define IOCPARM_MASK IOCCMD_MASK
  31 #define IOCPARM_SHIFT IOCCMD_SHIFT
  32 
  33 #define IOC_SIZE(cmd)   (((cmd) & IOCSIZE_MASK) >> IOCSIZE_SHIFT)
  34 #define IOCBASECMD(cmd) ((cmd) & ~IOCPARM_MASK)
  35 #define IOCGROUP(cmd)   (((cmd) >> 8) & 0xFF)
  36 
  37 /* _IO(magic, subcode); size field is zero and the 
  38  * subcode determines the command.
  39  */
  40 #define _IO(c,d)        (IOC_VOID | ((c)<<8) | (d)) /* param encoded */
  41 
  42 /* _IOXX(magic, subcode, arg_t); where arg_t is the type of the
  43  * (last) argument field in the ioctl call, if present.
  44  */
  45 #define _IOW(c,d,t)     (IOC_IN | ((sizeof(t)<<16) & IOCSIZE_MASK) | \
  46                                   ((c)<<8) | (d))
  47 #define _IOR(c,d,t)     (IOC_OUT | ((sizeof(t)<<16) & IOCSIZE_MASK) | \
  48                                    ((c)<<8) | (d))
  49 /* WR rather than RW to avoid conflict with stdio.h */
  50 #define _IOWR(c,d,t)    (IOC_INOUT | ((sizeof(t)<<16) & IOCSIZE_MASK) | \
  51                                      ((c)<<8) | (d))
  52 
  53 /*
  54  * The following is for compatibility across the various Linux
  55  * platforms.  The i386 ioctl numbering scheme doesn't really enforce
  56  * a type field.  De facto, however, the top 8 bits of the lower 16
  57  * bits are indeed used as a type field, so we might just as well make
  58  * this explicit here.  Please be sure to use the decoding macros
  59  * below from now on.
  60  */
  61 #define _IOC_NRBITS     8
  62 #define _IOC_TYPEBITS   8
  63 #define _IOC_SIZEBITS   14
  64 #define _IOC_DIRBITS    2
  65 
  66 #define _IOC_NRMASK     ((1 << _IOC_NRBITS)-1)
  67 #define _IOC_TYPEMASK   ((1 << _IOC_TYPEBITS)-1)
  68 #define _IOC_SIZEMASK   ((1 << _IOC_SIZEBITS)-1)
  69 #define _IOC_DIRMASK    ((1 << _IOC_DIRBITS)-1)
  70 
  71 #define _IOC_NRSHIFT    0
  72 #define _IOC_TYPESHIFT  (_IOC_NRSHIFT+_IOC_NRBITS)
  73 #define _IOC_SIZESHIFT  (_IOC_TYPESHIFT+_IOC_TYPEBITS)
  74 #define _IOC_DIRSHIFT   (_IOC_SIZESHIFT+_IOC_SIZEBITS)
  75 
  76 /*
  77  * Direction bits.
  78  */
  79 #define _IOC_NONE       0U
  80 #define _IOC_READ       1U
  81 #define _IOC_WRITE      2U
  82 
  83 /* used to decode ioctl numbers.. */
  84 #define _IOC_DIR(nr)            (((nr) >> _IOC_DIRSHIFT) & _IOC_DIRMASK)
  85 #define _IOC_TYPE(nr)           (((nr) >> _IOC_TYPESHIFT) & _IOC_TYPEMASK)
  86 #define _IOC_NR(nr)             (((nr) >> _IOC_NRSHIFT) & _IOC_NRMASK)
  87 #define _IOC_SIZE(nr)           (((nr) >> _IOC_SIZESHIFT) & _IOC_SIZEMASK)
  88 
  89 #endif /* _ASMI386_IOCTL_H */

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