rustix/ioctl/
bsd.rs

1//! `ioctl` opcode behavior for BSD platforms.
2
3use super::{Direction, Opcode};
4
5pub(super) const fn compose_opcode(
6    dir: Direction,
7    group: Opcode,
8    num: Opcode,
9    size: Opcode,
10) -> Opcode {
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`
22pub const NONE: Opcode = 0x2000_0000;
23// `IOC_OUT` (“out” is from the perspective of the kernel)
24pub const READ: Opcode = 0x4000_0000;
25// `IOC_IN` (“in” is from the perspective of the kernel)
26pub const WRITE: Opcode = 0x8000_0000;
27pub const IOCPARAM_MASK: Opcode = 0x1FFF;