summaryrefslogtreecommitdiff
path: root/vendor/rustix/src/ioctl/bsd.rs
blob: 965b31d12b18cc955fa934b4b190783ac69ad353 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
//! `ioctl` opcode behavior for BSD platforms.

use super::{Direction, Opcode};

pub(super) const fn compose_opcode(
    dir: Direction,
    group: Opcode,
    num: Opcode,
    size: Opcode,
) -> Opcode {
    let dir = match dir {
        Direction::None => NONE,
        Direction::Read => READ,
        Direction::Write => WRITE,
        Direction::ReadWrite => READ | WRITE,
    };

    dir | num | (group << 8) | ((size & IOCPARAM_MASK) << 16)
}

// `IOC_VOID`
pub const NONE: Opcode = 0x2000_0000;
// `IOC_OUT` (“out” is from the perspective of the kernel)
pub const READ: Opcode = 0x4000_0000;
// `IOC_IN` (“in” is from the perspective of the kernel)
pub const WRITE: Opcode = 0x8000_0000;
pub const IOCPARAM_MASK: Opcode = 0x1FFF;