[][src]Function vmm_sys_util::ioctl::ioctl_with_val

pub unsafe fn ioctl_with_val<F: AsRawFd>(
    fd: &F,
    req: c_ulong,
    arg: c_ulong
) -> c_int

Run an ioctl with a single value argument.

Arguments

  • fd: an open file descriptor corresponding to the device on which to call the ioctl.
  • req: a device-dependent request code.
  • arg: a single value passed to ioctl.

Safety

The caller should ensure to pass a valid file descriptor and have the return value checked.

Examples

#[macro_use] extern crate vmm_sys_util;
use vmm_sys_util::ioctl::ioctl_with_val;

const KVMIO: c_uint = 0xAE;
const KVM_CAP_USER_MEMORY: u32 = 3;
ioctl_io_nr!(KVM_CHECK_EXTENSION, KVMIO, 0x03);

let open_flags = O_RDWR | O_CLOEXEC;
let kvm_fd = unsafe { open("/dev/kvm\0".as_ptr() as *const c_char, open_flags) };

let ret = unsafe {
    ioctl_with_val(
        &File::from_raw_fd(kvm_fd),
        KVM_CHECK_EXTENSION(),
        KVM_CAP_USER_MEMORY as c_ulong,
    )
};
assert!(ret > 0);