fp might be NULL.
[minix.git] / include / minix / ioctl.h
blob6f1bf0193214f960adc6c46b0eb9388a747c2ef1
1 /* minix/ioctl.h - Ioctl helper definitions. Author: Kees J. Bot
2 * 23 Nov 2002
4 * This file is included by every header file that defines ioctl codes.
5 */
7 #ifndef _M_IOCTL_H
8 #define _M_IOCTL_H
10 #ifndef _TYPES_H
11 #include <sys/types.h>
12 #endif
14 #if _EM_WSIZE >= 4
15 /* Ioctls have the command encoded in the low-order word, and the size
16 * of the parameter in the high-order word. The 3 high bits of the high-
17 * order word are used to encode the in/out/void status of the parameter.
19 #define _IOCPARM_MASK 0x0FFF
20 #define _IOCPARM_MASK_BIG 0x0FFFFF
21 #define _IOC_VOID 0x20000000
22 #define _IOCTYPE_MASK 0xFFFF
23 #define _IOC_IN 0x40000000
24 #define _IOC_OUT 0x80000000
25 #define _IOC_INOUT (_IOC_IN | _IOC_OUT)
27 /* Flag indicating ioctl format with only one type field, and more bits
28 * for the size field (using mask _IOCPARM_MASK_BIG).
30 #define _IOC_BIG 0x10000000
32 #define _IO(x,y) ((x << 8) | y | _IOC_VOID)
33 #define _IOR(x,y,t) ((x << 8) | y | ((sizeof(t) & _IOCPARM_MASK) << 16) |\
34 _IOC_OUT)
35 #define _IOW(x,y,t) ((x << 8) | y | ((sizeof(t) & _IOCPARM_MASK) << 16) |\
36 _IOC_IN)
37 #define _IORW(x,y,t) ((x << 8) | y | ((sizeof(t) & _IOCPARM_MASK) << 16) |\
38 _IOC_INOUT)
40 #define _IOW_BIG(y,t) (y | ((sizeof(t) & _IOCPARM_MASK_BIG) << 8) \
41 | _IOC_IN | _IOC_BIG)
42 #define _IOR_BIG(y,t) (y | ((sizeof(t) & _IOCPARM_MASK_BIG) << 8) \
43 | _IOC_OUT | _IOC_BIG)
44 #define _IORW_BIG(y,t) (y | ((sizeof(t) & _IOCPARM_MASK_BIG) << 8) \
45 | _IOC_INOUT | _IOC_BIG)
47 /* Decode an ioctl call. */
48 #define _MINIX_IOCTL_SIZE(i) (((i) >> 16) & _IOCPARM_MASK)
49 #define _MINIX_IOCTL_IOR(i) ((i) & _IOC_OUT)
50 #define _MINIX_IOCTL_IORW(i) ((i) & _IOC_INOUT)
51 #define _MINIX_IOCTL_IOW(i) ((i) & _IOC_IN)
53 /* Recognize and decode size of a 'big' ioctl call. */
54 #define _MINIX_IOCTL_BIG(i) ((i) & _IOC_BIG)
55 #define _MINIX_IOCTL_SIZE_BIG(i) (((i) >> 8) & _IOCPARM_MASK_BIG)
57 #else
58 /* No fancy encoding on a 16-bit machine. */
60 #define _IO(x,y) ((x << 8) | y)
61 #define _IOR(x,y,t) _IO(x,y)
62 #define _IOW(x,y,t) _IO(x,y)
63 #define _IORW(x,y,t) _IO(x,y)
64 #endif
66 int ioctl(int _fd, int _request, void *_data);
68 #endif /* _M_IOCTL_H */