2 * D header file for POSIX.
4 * License: $(HTTP www.boost.org/LICENSE_1_0.txt, Boost License 1.0).
7 module core.sys.posix.sys.ioccom;
15 /* OSX ioctl's (based on FreeBSD) encode the command in the lower 16-bits
16 * and the size of any in/out parameters in the lower 13 bits of the upper
17 * 16-bits of a 32 bit unsigned integer. The high 3 bits of the upper
18 * 16-bits encode the in/out status of the parameter.
20 enum uint IOCPARM_MASK = 0x1fff; // parameter length, at most 13 bits
21 uint IOCPARM_LEN(uint x) // to extract the encoded parameter length
23 return ((x >> 16) & IOCPARM_MASK);
25 uint IOCBASECMD(uint x) // to extract the encoded command
27 return (x & ~(IOCPARM_MASK << 16));
29 uint IOCGROUP(uint x) // to extract the encoded group
31 return ((x >> 8) & 0xff);
34 enum uint IOCPARM_MAX = (IOCPARM_MASK + 1); // max size of ioctl args
36 enum uint IOC_VOID = 0x20000000; // no parameters
37 enum uint IOC_OUT = 0x40000000; // copy parameters back
38 enum uint IOC_IN = 0x80000000; // copy parameters into
39 enum uint IOC_INOUT = (IOC_IN | IOC_OUT); // copy parameter into and get back
40 enum uint IOC_DIRMASK = 0xe0000000; // mask to extract above direction parameters
42 // encode the ioctl info into 32 bits
43 uint _IOC(T=typeof(null))(uint inorout, uint group, uint num, size_t len)
45 return (inorout | ((len & IOCPARM_MASK) << 16) | (group << 8) | num);
48 // encode a command with no parameters
49 uint _IO(char g, int n)
51 return _IOC(IOC_VOID, cast(uint)g, cast(uint)n, cast(size_t)0);
53 // encode a command that returns info
54 uint _IOR(T)(char g, int n)
56 return _IOC!(T)(IOC_OUT, cast(uint)g, cast(uint)n, T.sizeof);
58 // encode a command that takes info
59 uint _IOW(T)(char g, int n)
61 return _IOC!(T)(IOC_IN, cast(uint)g, cast(uint)n, T.sizeof);
63 // encode a command that takes info and returns info
64 uint _IOWR(T)(char g, int n)
66 return _IOC!(T)(IOC_INOUT, cast(uint)g, cast(uint)n, T.sizeof);
69 else version (FreeBSD)
71 /* FreeBSD ioctl's encode the command in the lower 16-bits
72 * and the size of any in/out parameters in the lower 13 bits of the upper
73 * 16-bits of a 32 bit unsigned integer. The high 3 bits of the upper
74 * 16-bits encode the in/out status of the parameter.
76 enum uint IOCPARM_SHIFT = 13; // number of bits for ioctl size
77 enum uint IOCPARM_MASK = ((1 << IOCPARM_SHIFT) - 1); // parameter length mask
78 uint IOCPARM_LEN(uint x) // to extract the encoded parameter length
80 return ((x >> 16) & IOCPARM_MASK);
82 uint IOCBASECMD(uint x) // to extract the encoded command
84 return (x & ~(IOCPARM_MASK << 16));
86 uint IOCGROUP(uint x) // to extract the encoded group
88 return ((x >> 8) & 0xff);
91 enum uint IOCPARM_MAX = (1 << IOCPARM_SHIFT); // max size of ioctl args
93 enum uint IOC_VOID = 0x20000000; // no parameters
94 enum uint IOC_OUT = 0x40000000; // copy parameters back
95 enum uint IOC_IN = 0x80000000; // copy parameters into
96 enum uint IOC_INOUT = (IOC_IN | IOC_OUT);
97 enum uint IOC_DIRMASK = (IOC_VOID|IOC_OUT|IOC_IN);
99 // encode the ioctl info into 32 bits
100 uint _IOC(uint inorout, uint group, uint num, size_t len)
102 return (inorout | ((len & IOCPARM_MASK) << 16) | (group << 8) | num);
105 // encode a command with no parameters
106 uint _IO(char g, int n)
108 return _IOC(IOC_VOID, cast(uint)g, cast(uint)n, cast(size_t)0);
110 uint _IOWINT(char g, int n)
112 return _IOC(IOC_VOID, cast(uint)g, cast(uint)n, int.sizeof);
114 // encode a command that returns info
115 uint _IOR(T)(char g, int n)
117 return _IOC(IOC_OUT, cast(uint)g, cast(uint)n, T.sizeof);
119 // encode a command that takes info
120 uint _IOW(T)(char g, int n)
122 return _IOC(IOC_IN, cast(uint)g, cast(uint)n, T.sizeof);
124 // encode a command that takes info and returns info
125 uint _IOWR(T)(char g, int n)
127 return _IOC(IOC_INOUT, cast(uint)g, cast(uint)n, T.sizeof);