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);