1 /* $Id: cygwin-ioctl.h,v 1.3 2003/12/03 05:12:41 phil Exp $
3 * linux/ioctl.h for Linux by H.H. Bergman.
6 #ifndef _ASMI386_IOCTL_H
7 #define _ASMI386_IOCTL_H
9 /* ioctl command encoding: 32 bits total, command in lower 16 bits,
10 * size of the parameter structure in the lower 14 bits of the
12 * Encoding the size of the parameter structure in the ioctl request
13 * is useful for catching programs compiled with old versions
14 * and to avoid overwriting user space outside the user buffer area.
15 * The highest 2 bits are reserved for indicating the ``access mode''.
16 * NOTE: This limits the max parameter size to 16kB -1 !
20 * The following is for compatibility across the various Linux
21 * platforms. The i386 ioctl numbering scheme doesn't really enforce
22 * a type field. De facto, however, the top 8 bits of the lower 16
23 * bits are indeed used as a type field, so we might just as well make
24 * this explicit here. Please be sure to use the decoding macros
35 #define _IOC_TYPEBITS 8
36 #define _IOC_SIZEBITS 14
37 #define _IOC_DIRBITS 2
39 #define _IOC_NRMASK ((1 << _IOC_NRBITS)-1)
40 #define _IOC_TYPEMASK ((1 << _IOC_TYPEBITS)-1)
41 #define _IOC_SIZEMASK ((1 << _IOC_SIZEBITS)-1)
42 #define _IOC_DIRMASK ((1 << _IOC_DIRBITS)-1)
44 #define _IOC_NRSHIFT 0
45 #define _IOC_TYPESHIFT (_IOC_NRSHIFT+_IOC_NRBITS)
46 #define _IOC_SIZESHIFT (_IOC_TYPESHIFT+_IOC_TYPEBITS)
47 #define _IOC_DIRSHIFT (_IOC_SIZESHIFT+_IOC_SIZEBITS)
56 #define _IOC(dir,type,nr,size) \
57 (((dir) << _IOC_DIRSHIFT) | \
58 ((type) << _IOC_TYPESHIFT) | \
59 ((nr) << _IOC_NRSHIFT) | \
60 ((size) << _IOC_SIZESHIFT))
62 /* used to create numbers */
63 #define _IO(type,nr) _IOC(_IOC_NONE,(type),(nr),0)
64 #define _IOR(type,nr,size) _IOC(_IOC_READ,(type),(nr),sizeof(size))
65 #define _IOW(type,nr,size) _IOC(_IOC_WRITE,(type),(nr),sizeof(size))
66 #define _IOWR(type,nr,size) _IOC(_IOC_READ|_IOC_WRITE,(type),(nr),sizeof(size))
68 /* used to decode ioctl numbers.. */
69 #define _IOC_DIR(nr) (((nr) >> _IOC_DIRSHIFT) & _IOC_DIRMASK)
70 #define _IOC_TYPE(nr) (((nr) >> _IOC_TYPESHIFT) & _IOC_TYPEMASK)
71 #define _IOC_NR(nr) (((nr) >> _IOC_NRSHIFT) & _IOC_NRMASK)
72 #define _IOC_SIZE(nr) (((nr) >> _IOC_SIZESHIFT) & _IOC_SIZEMASK)
74 /* ...and for the drivers/sound files... */
76 #define IOC_IN (_IOC_WRITE << _IOC_DIRSHIFT)
77 #define IOC_OUT (_IOC_READ << _IOC_DIRSHIFT)
78 #define IOC_INOUT ((_IOC_WRITE|_IOC_READ) << _IOC_DIRSHIFT)
79 #define IOCSIZE_MASK (_IOC_SIZEMASK << _IOC_SIZESHIFT)
80 #define IOCSIZE_SHIFT (_IOC_SIZESHIFT)
82 #endif /* _ASMI386_IOCTL_H */