#macro #numbers #ioctl #unix #systems #generate #io

ioctl-macros

Rust macros that can be used to generate ioctl numbers on unix systems

1 unstable release

Uses old Rust 2015

0.1.0 Jun 26, 2016

#29 in #ioctl

MIT/Apache

4KB
65 lines

ioctl-macros-rs

Rust macros that can be used to generate ioctl numbers on unix systems. This crate uses your target system's headers to automatically find the _IO, _IOR, _IOW, and _IOWR C definitions and create Rust bindings for them. The result is an extremely small crate that works on any system supporting the above C macros. It has been tested with Linux, OpenBSD, FreeBSD, and NetBSD. Feel free to report any issues.

Usage

The crate provides four macros; io!, ior!, iow!, and iowr!. They are used the same way you would use the C macros above.

The first argument is the identifying letter. For Linux, you can find a list here on the official kernel.org website. The second argument is the sequence number. Unfortunately they are not very well documented, so you may need to dig into some of your system's headers to find them. The third argument (in the case of the read/write macros) is the type of data that you'll be passing along to your ioctl function.

// This definition is found in <linux/joystick.h> as:
// #define JSIOCGVERSION _IOR('j', 0x01, __u32)
let JSIOCGVERSION = ior!('j', 0x01, u32)

// This definition is found in <libdrm/drm.h> as:
// #define DRM_IOCTL_SET_MASTER _IO('d', 0x1e)
let DRM_IOCTL_SET_MASTER = io!('d', 0x1e)

No runtime deps

~12KB