pub struct NoArgs { /* private fields */ }
Expand description
Indicates that an Ioctl
does not take any arguments.
This is used as the type parameter of Ioctl
by the _IO
and _IOC
functions.
Ioctl<NoArgs>
comes with its own, separate IOCTL.ioctl(fd)
method that only takes the file
descriptor as an argument.
Since NoArgs
is the default value for Ioctl
’s type parameter, it can typically be
omitted.
§Example
The uinput ioctls UI_DEV_CREATE
and UI_DEV_DESTROY
do not take any arguments, while
UI_DEV_SETUP
does take an argument.
From linux/uinput.h
:
/* ioctl */
#define UINPUT_IOCTL_BASE 'U'
#define UI_DEV_CREATE _IO(UINPUT_IOCTL_BASE, 1)
#define UI_DEV_DESTROY _IO(UINPUT_IOCTL_BASE, 2)
...
#define UI_DEV_SETUP _IOW(UINPUT_IOCTL_BASE, 3, struct uinput_setup)
use std::{mem, fs::File, ffi::c_char};
use libc::uinput_setup;
use linux_ioctl::*;
const UINPUT_IOCTL_BASE: u8 = b'U';
const UI_DEV_CREATE: Ioctl<NoArgs> = _IO(UINPUT_IOCTL_BASE, 1);
const UI_DEV_DESTROY: Ioctl<NoArgs> = _IO(UINPUT_IOCTL_BASE, 2);
const UI_DEV_SETUP: Ioctl<*const uinput_setup> = _IOW(UINPUT_IOCTL_BASE, 3);
let uinput = File::options().write(true).open("/dev/uinput")?;
let mut setup: libc::uinput_setup = unsafe { mem::zeroed() };
setup.name[0] = b'A' as c_char; // (must not be blank)
unsafe {
UI_DEV_SETUP.ioctl(&uinput, &setup)?;
UI_DEV_CREATE.ioctl(&uinput)?;
// ...use the device...
UI_DEV_DESTROY.ioctl(&uinput)?;
}