diff options
Diffstat (limited to 'sys_util/src/ioctl.rs')
-rw-r--r-- | sys_util/src/ioctl.rs | 62 |
1 files changed, 40 insertions, 22 deletions
diff --git a/sys_util/src/ioctl.rs b/sys_util/src/ioctl.rs index edfa3be..31d21c9 100644 --- a/sys_util/src/ioctl.rs +++ b/sys_util/src/ioctl.rs @@ -12,47 +12,65 @@ use libc; /// Raw macro to declare a function that returns an ioctl number. #[macro_export] macro_rules! ioctl_ioc_nr { - ($name:ident, $dir:expr, $ty:expr, $nr:expr, $size:expr) => ( + ($name:ident, $dir:expr, $ty:expr, $nr:expr, $size:expr) => { #[allow(non_snake_case)] pub fn $name() -> ::std::os::raw::c_ulong { - (($dir << $crate::ioctl::_IOC_DIRSHIFT) | - ($ty << $crate::ioctl::_IOC_TYPESHIFT) | - ($nr<< $crate::ioctl::_IOC_NRSHIFT) | - ($size << $crate::ioctl::_IOC_SIZESHIFT)) as ::std::os::raw::c_ulong + (($dir << $crate::ioctl::_IOC_DIRSHIFT) + | ($ty << $crate::ioctl::_IOC_TYPESHIFT) + | ($nr << $crate::ioctl::_IOC_NRSHIFT) + | ($size << $crate::ioctl::_IOC_SIZESHIFT)) as ::std::os::raw::c_ulong } - ) + }; } /// Declare an ioctl that transfers no data. #[macro_export] macro_rules! ioctl_io_nr { - ($name:ident, $ty:expr, $nr:expr) => ( + ($name:ident, $ty:expr, $nr:expr) => { ioctl_ioc_nr!($name, $crate::ioctl::_IOC_NONE, $ty, $nr, 0); - ) + }; } /// Declare an ioctl that reads data. #[macro_export] macro_rules! ioctl_ior_nr { - ($name:ident, $ty:expr, $nr:expr, $size:ty) => ( - ioctl_ioc_nr!($name, $crate::ioctl::_IOC_READ, $ty, $nr, ::std::mem::size_of::<$size>() as u32); - ) + ($name:ident, $ty:expr, $nr:expr, $size:ty) => { + ioctl_ioc_nr!( + $name, + $crate::ioctl::_IOC_READ, + $ty, + $nr, + ::std::mem::size_of::<$size>() as u32 + ); + }; } /// Declare an ioctl that writes data. #[macro_export] macro_rules! ioctl_iow_nr { - ($name:ident, $ty:expr, $nr:expr, $size:ty) => ( - ioctl_ioc_nr!($name, $crate::ioctl::_IOC_WRITE, $ty, $nr, ::std::mem::size_of::<$size>() as u32); - ) + ($name:ident, $ty:expr, $nr:expr, $size:ty) => { + ioctl_ioc_nr!( + $name, + $crate::ioctl::_IOC_WRITE, + $ty, + $nr, + ::std::mem::size_of::<$size>() as u32 + ); + }; } /// Declare an ioctl that reads and writes data. #[macro_export] macro_rules! ioctl_iowr_nr { - ($name:ident, $ty:expr, $nr:expr, $size:ty) => ( - ioctl_ioc_nr!($name, $crate::ioctl::_IOC_READ | $crate::ioctl::_IOC_WRITE, $ty, $nr, ::std::mem::size_of::<$size>() as u32); - ) + ($name:ident, $ty:expr, $nr:expr, $size:ty) => { + ioctl_ioc_nr!( + $name, + $crate::ioctl::_IOC_READ | $crate::ioctl::_IOC_WRITE, + $ty, + $nr, + ::std::mem::size_of::<$size>() as u32 + ); + }; } pub const _IOC_NRBITS: c_uint = 8; @@ -109,12 +127,12 @@ pub unsafe fn ioctl_with_mut_ptr<F: AsRawFd, T>(fd: &F, nr: c_ulong, arg: *mut T #[cfg(test)] mod tests { const TUNTAP: ::std::os::raw::c_uint = 0x54; - const VHOST: ::std::os::raw::c_uint = 0xaf; + const VHOST: ::std::os::raw::c_uint = 0xaf; - ioctl_io_nr!(VHOST_SET_OWNER, VHOST, 0x01); - ioctl_ior_nr!(TUNGETFEATURES, TUNTAP, 0xcf, ::std::os::raw::c_uint); - ioctl_iow_nr!(TUNSETQUEUE, TUNTAP, 0xd9, ::std::os::raw::c_int); - ioctl_iowr_nr!(VHOST_GET_VRING_BASE, VHOST, 0x12, ::std::os::raw::c_int); + ioctl_io_nr!(VHOST_SET_OWNER, VHOST, 0x01); + ioctl_ior_nr!(TUNGETFEATURES, TUNTAP, 0xcf, ::std::os::raw::c_uint); + ioctl_iow_nr!(TUNSETQUEUE, TUNTAP, 0xd9, ::std::os::raw::c_int); + ioctl_iowr_nr!(VHOST_GET_VRING_BASE, VHOST, 0x12, ::std::os::raw::c_int); #[test] fn ioctl_macros() { |