| 1 |
//! `ioctl` opcode behavior for BSD platforms. |
| 2 |
|
| 3 |
use super::{Direction, RawOpcode}; |
| 4 |
|
| 5 |
pub(super) const fn compose_opcode( |
| 6 |
dir: Direction, |
| 7 |
group: RawOpcode, |
| 8 |
num: RawOpcode, |
| 9 |
size: RawOpcode, |
| 10 |
) -> RawOpcode { |
| 11 |
let dir = match dir { |
| 12 |
Direction::None => NONE, |
| 13 |
Direction::Read => READ, |
| 14 |
Direction::Write => WRITE, |
| 15 |
Direction::ReadWrite => READ | WRITE, |
| 16 |
}; |
| 17 |
|
| 18 |
dir | num | (group << 8) | ((size & IOCPARAM_MASK) << 16) |
| 19 |
} |
| 20 |
|
| 21 |
// `IOC_VOID` |
| 22 |
pub const NONE: RawOpcode = 0x2000_0000; |
| 23 |
// `IOC_OUT` ("out" is from the perspective of the kernel) |
| 24 |
pub const READ: RawOpcode = 0x4000_0000; |
| 25 |
// `IOC_IN` |
| 26 |
pub const WRITE: RawOpcode = 0x8000_0000; |
| 27 |
pub const IOCPARAM_MASK: RawOpcode = 0x1FFF; |