linux-ioctl-0.2.3 has been yanked.
linux-ioctl
Simple porting tools for Linux-style ioctl(2) driver interfaces.
Example
Let's use uinput to create a userspace input device.
From linux/uinput.h:
/* ioctl */
...
use ;
use uinput_setup;
use *;
const UINPUT_IOCTL_BASE: u8 = b'U';
const UI_DEV_CREATE: = _IO;
const UI_DEV_DESTROY: = _IO;
const UI_DEV_SETUP: = _IOW;
let uinput = options.write.open?;
let mut setup: uinput_setup = unsafe ;
setup.name = b'A' as c_char; // (must not be blank)
unsafe
# Ok
Why?
I mainly wrote this crate because I was unhappy with the alternatives:
libc::ioctl- The raw
ioctlfunction provides no built-in error conversion and requires knowing theioctlrequest number. libcdoes provideconst fns that mirror the_IOxmacros, but they are only exposed on Linux and have no type safety.
- The raw
nix::ioctl_X!- Looks nothing like the
ioctldefinitions found in C headers. - Requires very frequent conscious
nixupdates because it publishes A LOT of breaking changes.
- Looks nothing like the
- Other crates for this are either abandoned or also frequently publish breaking changes that I'd have to consciously migrate to.
- Instead, I want a crate that tries to only cover
ioctls, and has a decently designed API that doesn't see much breakage.
- Instead, I want a crate that tries to only cover
- Almost none of these alternatives except
libcmake translation of C headers to Rust very easy.- The Rust code required to do the thing often looks completely different to the equivalent C definitions.
- As
ioctls are a low-level interface often accessed by directly porting a C header, it is beneficial if the result is easy to visually compare to the original C code.
Thus, this library was born in an attempt to address these problems.
Rust Support
This library targets the latest Rust version.
Older Rust versions are supported by equally older versions of this crate. For example, to use a version of Rust that was succeeded 6 months ago, you'd also use an at least 6 month old version of this library.
Compatibility with older Rust versions may be provided on a best-effort basis.