Function _IOR

Source
pub const fn _IOR<T>(ty: u8, nr: u8) -> Ioctl<*mut T>
Expand description

Creates an Ioctl that reads data of type T from the kernel.

By default, a pointer to the data will be passed to ioctl(2), and the kernel will fill the destination with data.

§Errors

This method will cause a compile-time assertion failure if the size of T exceeds the ioctl argument size limit. This typically means that the wrong type T was specified.

§Examples

From linux/random.h:

/* ioctl()'s for the random number generator */

/* Get the entropy count. */
#define RNDGETENTCNT	_IOR( 'R', 0x00, int )
use std::fs::File;
use std::ffi::c_int;
use linux_ioctl::*;

const RNDGETENTCNT: Ioctl<*mut c_int> = _IOR(b'R', 0x00);

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

let mut entropy = 0;
unsafe { RNDGETENTCNT.ioctl(&file, &mut entropy)? };

println!("{entropy} bits of entropy in /dev/urandom");