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