#ioctl #identifier #linux #devices #unix #call #header

ioctl-id

Rust identifiers for ioctl(2) calls on Unix-like systems

2 unstable releases

0.2.0 Jun 24, 2024
0.1.0 Jun 24, 2024

#450 in Unix APIs

Apache-2.0

40KB
334 lines

Crate ioctl-id

Rust identifiers for ioctl(2) calls on Unix-like systems.

This brings definitions from the ioctl.h header into Rust as constant functions for use in writing other Rust-based libraries for interacting with character and block devices.

Platform Support

Operating System Supported Platforms Untested Platforms
FreeBSD (in progress)
Linux arm*, aarch64, i686, x86_64 mips*, ppc*, sparc*
MacOS arm64, x86_64

lib.rs:

Provides constant functions to compute for ioctl(2) identifiers.

Currently, this supports Linux and macOS. The long term goal is to support ioctl identifiers for other BSD variants.

Usage Notes

IoctlId is an alias for the type to pass into the ioctl(2) request. This is either a u32 or u64, depending on the target OS and architecture.

The [io()], [ior()], [iow()], and [iowr()] functions take a type parameter, similar to the _IO(), _IOR(), _IOW(), and _IOWR() macros.

For example, the following C code:

struct my_ioctl_data {
    unsigned int a;
};

#define MY_IOCTL _IOR(0x12, 0x34, struct my_ioctl_data)

Would be written in Rust as:

use ioctl_id::*;

#[repr(C)]
struct MyIoctlData {
   a: u32,
}

const MY_IOCTL: IoctlId = ior::<MyIoctlData>(0x12, 0x34);

No runtime deps