libc/new/apple/xnu/sys/
ioccom.rs1use crate::prelude::*;
6
7const IOCPARM_MASK: c_ulong = 0x1fff;
8
9const IOCPARM_MAX: c_ulong = IOCPARM_MASK + 1;
10
11pub(crate) const IOC_VOID: u32 = 0x20000000;
14pub(crate) const IOC_OUT: u32 = 0x40000000;
15pub(crate) const IOC_IN: u32 = 0x80000000;
16pub(crate) const IOC_INOUT: u32 = IOC_IN | IOC_OUT;
17pub(crate) const IOC_DIRMASK: u32 = 0xe0000000;
18
19pub(crate) const fn _IOC(inout: u32, group: c_ulong, num: c_ulong, len: c_ulong) -> c_ulong {
21 debug_assert!(inout <= IOC_DIRMASK);
22 debug_assert!(group <= 0xff);
23 debug_assert!(num <= 0xff);
24 debug_assert!(len <= IOCPARM_MAX);
25
26 assert!(size_of::<u32>() <= size_of::<c_ulong>());
28
29 (inout as c_ulong) | ((len & IOCPARM_MASK) << 16) | (group << 8) | num
30}
31
32pub const fn _IO(g: c_ulong, n: c_ulong) -> c_ulong {
33 _IOC(IOC_VOID, g, n, 0)
34}
35
36pub const fn _IOR<T>(g: c_ulong, n: c_ulong) -> c_ulong {
38 _IOC(IOC_OUT, g, n, mem::size_of::<T>() as c_ulong)
39}
40
41pub const fn _IOW<T>(g: c_ulong, n: c_ulong) -> c_ulong {
43 _IOC(IOC_IN, g, n, mem::size_of::<T>() as c_ulong)
44}
45
46pub const fn _IOWR<T>(g: c_ulong, n: c_ulong) -> c_ulong {
48 _IOC(IOC_INOUT, g, n, mem::size_of::<T>() as c_ulong)
49}