| 1 |
//! Header: `sys/ioccom.h` |
| 2 |
//! |
| 3 |
//! https://github.com/freebsd/freebsd-src/blob/main/sys/sys/ioccom.h |
| 4 |
|
| 5 |
use crate::prelude::*; |
| 6 |
|
| 7 |
const IOCPARM_SHIFT: c_ulong = 13; |
| 8 |
const IOCPARM_MASK: c_ulong = (1 << IOCPARM_SHIFT) - 1; |
| 9 |
|
| 10 |
const IOCPARM_MAX: c_ulong = 1 << IOCPARM_SHIFT; |
| 11 |
|
| 12 |
pub(crate) const IOC_VOID: c_ulong = 0x20000000; |
| 13 |
pub(crate) const IOC_OUT: c_ulong = 0x40000000; |
| 14 |
pub(crate) const IOC_IN: c_ulong = 0x80000000; |
| 15 |
pub(crate) const IOC_INOUT: c_ulong = IOC_IN | IOC_OUT; |
| 16 |
pub(crate) const IOC_DIRMASK: c_ulong = IOC_VOID | IOC_OUT | IOC_IN; |
| 17 |
|
| 18 |
pub(crate) const fn _IOC(inout: c_ulong, group: c_ulong, num: c_ulong, len: c_ulong) -> c_ulong { |
| 19 |
debug_assert!(inout <= IOC_DIRMASK); |
| 20 |
debug_assert!(group <= 0xff); |
| 21 |
debug_assert!(num <= 0xff); |
| 22 |
debug_assert!(len <= IOCPARM_MAX); |
| 23 |
|
| 24 |
inout | ((len & IOCPARM_MASK) << 16) | (group << 8) | num |
| 25 |
} |
| 26 |
|
| 27 |
pub const fn _IO(g: c_ulong, n: c_ulong) -> c_ulong { |
| 28 |
_IOC(IOC_VOID, g, n, 0) |
| 29 |
} |
| 30 |
|
| 31 |
/// Build an ioctl number for an ioctl that passes an `int` by value. |
| 32 |
pub const fn _IOWINT(g: c_ulong, n: c_ulong) -> c_ulong { |
| 33 |
_IOC(IOC_VOID, g, n, mem::size_of::<c_int>() as c_ulong) |
| 34 |
} |
| 35 |
|
| 36 |
/// Build an ioctl number for an read-only ioctl. |
| 37 |
pub 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 |
|
| 41 |
/// Build an ioctl number for an write-only ioctl. |
| 42 |
pub 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 |
|
| 46 |
/// Build an ioctl number for a read-write ioctl. |
| 47 |
pub 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 |
} |