xref: /haiku/headers/compatibility/bsd/sys/ioccom.h (revision 1acbe440b8dd798953bec31d18ee589aa3f71b73)
1 /**
2  * @file sys/ioccom.h
3  * @brief Definitions & maros common to ioctl
4  */
5 
6 #ifndef _SYS_IOCCOM_H
7 #define _SYS_IOCCOM_H
8 
9 /**
10  * @defgroup IOCTL_common sys/ioccom.h
11  * @brief Definitions & maros common to ioctl()
12  * @ingroup OpenBeOS_POSIX
13  * @ingroup IOCTL
14  * Ioctl values passed as the command (2nd) variable have the
15  * command encoded in the lower word and the size of any parameters
16  * in the upper word (in or out).
17  * The high 3 bits are used to encode whether it's in or out.
18  * Due to this you can't just give an ioctl value, you need to encode
19  * it using macros described in
20  * @ref IOCTL_macros
21  * @{
22  */
23 
24 /** @defgroup IOCTL_parm ioctl() parameter definitions
25  * @ingroup IOCTL_common
26  * @{
27  */
28 /** @def IOC_VOID */
29 #define IOC_VOID         (ulong)0x20000000
30 /** @def IOC_OUT ioctl expects data (output) */
31 #define IOC_OUT          (ulong)0x40000000
32 /** @def IOC_IN ioctl passes a value in */
33 #define IOC_IN           (ulong)0x80000000
34 /** @def IOC_INOUT ioctl passes data in and out */
35 #define IOC_INOUT        (IOC_IN|IOC_OUT)
36 /** @def IOC_DIRMASK */
37 #define IOC_DIRMASK      (ulong)0xe0000000
38 /** @} */
39 
40 /**
41  * @defgroup IOCTL_macros IOCTL macros
42  * These should be used to define the values passed in as cmd to
43  * ioctl()
44  * @ingroup IOCTL_common
45  * @{
46  */
47 /** @def IOCPARM_MASK mask used to for following macros */
48 #define IOCPARM_MASK     0x1fff
49 /** @def IOCPARM_LEN(x) length of the data passed as param */
50 #define IOCPARM_LEN(x)   (((x) >> 16) & IOCPARM_MASK)
51 /** @def IOCBASECMD(x) the base command encoded in the ioctl value */
52 #define IOCBASECMD(x)    ((x) & ~(IOCPARM_MASK << 16))
53 /** @def IOCGROUP(x) which group of ioctl() commands does this belong to? */
54 #define IOCGROUP(x)      (((x) >> 8) & 0xff)
55 /** @def IOCPARM_MAX Maximum size of parameter that can be passed (20 bytes) */
56 #define IOCPARM_MAX      20
57 
58 /**
59  * @defgroup IOCTL_createmacros macro's to create ioctl() values
60  * @brief these macro's should be used to create new ioctl() values
61  * @ingroup IOCTL_common
62  * @{
63  */
64 /** @def _IOC(inout, group, num , len) create a new ioctl */
65 #define _IOC(inout, group, num, len) \
66 	(inout | ((len & IOCPARM_MASK)<<16) | ((group) << 8) | (num))
67 /** @def _IO(g,n) create a new void ioctl for group g, number n */
68 #define _IO(g,n)          _IOC(IOC_VOID, (g), (n), 0)
69 /** @def _IOR(g,n,t) create a ioctl() that reads a value of type t*/
70 #define _IOR(g,n,t)       _IOC(IOC_OUT,  (g), (n), sizeof(t))
71 /** @def _IOW(g,n,t) ioctl() that writes value of type t, group g, number n */
72 #define _IOW(g,n,t)       _IOC(IOC_IN ,  (g), (n), sizeof(t))
73 /** @def _IOWR(g,n,t) ioctl() that reads/writes value of type t
74  * @note this isn't _IORW as this causes name conflicts on some systems */
75 #define _IOWR(g,n,t)      _IOC(IOC_INOUT,  (g), (n), sizeof(t))
76 /** @} */
77 
78 /** @} */
79 
80 #endif /* _SYS_IOCCOM_H */
81