Function _IO

Source
pub const fn _IO(ty: u8, nr: u8) -> Ioctl<NoArgs>
Expand description

Creates an Ioctl that doesn’t read or write any userspace data.

This type of ioctl can return an int to userspace via the return value of the ioctl syscall. By default, the returned Ioctl takes no argument. Ioctl::with_arg can be used to pass a direct argument to the ioctl.

§Example

KVM_GET_API_VERSION is an ioctl that does not take any arguments. The API version is returned as the return value of the ioctl(2) function.

From linux/kvm.h:

#define KVMIO 0xAE
...
#define KVM_GET_API_VERSION       _IO(KVMIO,   0x00)
use std::fs::File;
use linux_ioctl::*;

const KVMIO: u8 = 0xAE;
const KVM_GET_API_VERSION: Ioctl<NoArgs> = _IO(KVMIO, 0x00);

let file = File::open("/dev/kvm")?;

let version = unsafe { KVM_GET_API_VERSION.ioctl(&file)? };
println!("KVM API version: {version}");