pub const fn _IOC(dir: u32, ty: u8, nr: u8, size: usize) -> Ioctl<NoArgs>Expand description
Manually constructs an Ioctl from its components.
Also see Ioctl::from_raw for a way to interface with “legacy” ioctls that don’t yet follow
this scheme.
Prefer to use _IO, _IOR, _IOW, or _IOWR where possible.
§Arguments
dir: must be one of_IOC_NONE,_IOC_READ,_IOC_WRITE, or an ORed-together combination. 0 is not valid on all architectures.ty: theioctlgroup or type to identify the driver or subsystem. You can find a list here.nr: theioctlnumber within its group.size: the size of theioctl’s indirect argument.ioctls that take an argument directly (without passing a pointer to it) typically set this to 0.
§Panics
This function may panic when dir is not one of _IOC_NONE, _IOC_READ, _IOC_WRITE,
or an ORed-together combination of those constants.
It may also panic when size exceeds the maximum parameter size.
§Example
UI_GET_SYSNAME is a polymorphic ioctl that can be invoked with a variety of buffer lengths.
This function can be used to bind to it.
From linux/uinput.h:
/* ioctl */
#define UINPUT_IOCTL_BASE 'U'
...
#define UI_GET_SYSNAME(len) _IOC(_IOC_READ, UINPUT_IOCTL_BASE, 44, len)use std::ffi::c_char;
use linux_ioctl::*;
const UINPUT_IOCTL_BASE: u8 = b'U';
const fn UI_GET_SYSNAME(len: usize) -> Ioctl<*mut c_char> {
_IOC(_IOC_READ, UINPUT_IOCTL_BASE, 44, len).with_arg()
}
// Use it like this:
unsafe {
let mut buffer = [0 as c_char; 16];
UI_GET_SYSNAME(16).ioctl(fd, buffer.as_mut_ptr())?;
}