pub const fn _IOC<T: ?Sized>(dir: Dir, ty: u8, nr: u8, size: usize) -> Ioctl<T>
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
: Direction of the ioctl. One of_IOC_NONE
,_IOC_READ
,_IOC_WRITE
, or_IOC_READ | _IOC_WRITE
(aka_IOC_READ_WRITE
).ty
: theioctl
group or type to identify the driver or subsystem. You can find a list here.nr
: theioctl
number within its group.size
: the size of theioctl
’s indirect argument.ioctl
s that take an argument directly (without passing a pointer to it) typically set this to 0.
§Panics
This function may panic when size
exceeds the (platform-specific) 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)
}
// Use it like this:
unsafe {
let mut buffer = [0 as c_char; 16];
UI_GET_SYSNAME(16).ioctl(fd, buffer.as_mut_ptr())?;
}