diff options
-rw-r--r-- | src/sys/ioctl/mod.rs | 18 | ||||
-rw-r--r-- | src/sys/ioctl/platform/bsd.rs | 17 | ||||
-rw-r--r-- | src/sys/ioctl/platform/linux.rs | 36 |
3 files changed, 42 insertions, 29 deletions
diff --git a/src/sys/ioctl/mod.rs b/src/sys/ioctl/mod.rs index 330ff8cd..a2eb79b5 100644 --- a/src/sys/ioctl/mod.rs +++ b/src/sys/ioctl/mod.rs @@ -174,40 +174,40 @@ macro_rules! ioctl { pub unsafe fn $name(fd: $crate::libc::c_int, data: *mut u8) -> $crate::Result<$crate::libc::c_int> { - convert_ioctl_res!($crate::libc::ioctl(fd, $nr as $crate::libc::c_ulong, data)) + convert_ioctl_res!($crate::libc::ioctl(fd, $nr as $crate::sys::ioctl::ioctl_num_type, data)) } ); (bad none $name:ident with $nr:expr) => ( pub unsafe fn $name(fd: $crate::libc::c_int) -> $crate::Result<$crate::libc::c_int> { - convert_ioctl_res!($crate::libc::ioctl(fd, $nr as $crate::libc::c_ulong)) + convert_ioctl_res!($crate::libc::ioctl(fd, $nr as $crate::sys::ioctl::ioctl_num_type)) } ); (none $name:ident with $ioty:expr, $nr:expr) => ( pub unsafe fn $name(fd: $crate::libc::c_int) -> $crate::Result<$crate::libc::c_int> { - convert_ioctl_res!($crate::libc::ioctl(fd, io!($ioty, $nr) as $crate::libc::c_ulong)) + convert_ioctl_res!($crate::libc::ioctl(fd, io!($ioty, $nr) as $crate::sys::ioctl::ioctl_num_type)) } ); (read $name:ident with $ioty:expr, $nr:expr; $ty:ty) => ( pub unsafe fn $name(fd: $crate::libc::c_int, val: *mut $ty) -> $crate::Result<$crate::libc::c_int> { - convert_ioctl_res!($crate::libc::ioctl(fd, ior!($ioty, $nr, ::std::mem::size_of::<$ty>()) as $crate::libc::c_ulong, val)) + convert_ioctl_res!($crate::libc::ioctl(fd, ior!($ioty, $nr, ::std::mem::size_of::<$ty>()) as $crate::sys::ioctl::ioctl_num_type, val)) } ); (write $name:ident with $ioty:expr, $nr:expr; $ty:ty) => ( pub unsafe fn $name(fd: $crate::libc::c_int, val: $ty) -> $crate::Result<$crate::libc::c_int> { - convert_ioctl_res!($crate::libc::ioctl(fd, iow!($ioty, $nr, ::std::mem::size_of::<$ty>()) as $crate::libc::c_ulong, val)) + convert_ioctl_res!($crate::libc::ioctl(fd, iow!($ioty, $nr, ::std::mem::size_of::<$ty>()) as $crate::sys::ioctl::ioctl_num_type, val)) } ); (readwrite $name:ident with $ioty:expr, $nr:expr; $ty:ty) => ( pub unsafe fn $name(fd: $crate::libc::c_int, val: *mut $ty) -> $crate::Result<$crate::libc::c_int> { - convert_ioctl_res!($crate::libc::ioctl(fd, iorw!($ioty, $nr, ::std::mem::size_of::<$ty>()) as $crate::libc::c_ulong, val)) + convert_ioctl_res!($crate::libc::ioctl(fd, iorw!($ioty, $nr, ::std::mem::size_of::<$ty>()) as $crate::sys::ioctl::ioctl_num_type, val)) } ); (read buf $name:ident with $ioty:expr, $nr:expr; $ty:ty) => ( @@ -215,14 +215,14 @@ macro_rules! ioctl { val: *mut $ty, len: usize) -> $crate::Result<$crate::libc::c_int> { - convert_ioctl_res!($crate::libc::ioctl(fd, ior!($ioty, $nr, len) as $crate::libc::c_ulong, val)) + convert_ioctl_res!($crate::libc::ioctl(fd, ior!($ioty, $nr, len) as $crate::sys::ioctl::ioctl_num_type, val)) } ); (write buf $name:ident with $ioty:expr, $nr:expr; $ty:ty) => ( pub unsafe fn $name(fd: $crate::libc::c_int, val: *const $ty, len: usize) -> $crate::Result<$crate::libc::c_int> { - convert_ioctl_res!($crate::libc::ioctl(fd, iow!($ioty, $nr, len) as $crate::libc::c_ulong, val)) + convert_ioctl_res!($crate::libc::ioctl(fd, iow!($ioty, $nr, len) as $crate::sys::ioctl::ioctl_num_type, val)) } ); (readwrite buf $name:ident with $ioty:expr, $nr:expr; $ty:ty) => ( @@ -230,7 +230,7 @@ macro_rules! ioctl { val: *mut $ty, len: usize) -> $crate::Result<$crate::libc::c_int> { - convert_ioctl_res!($crate::libc::ioctl(fd, iorw!($ioty, $nr, len) as $crate::libc::c_ulong, val)) + convert_ioctl_res!($crate::libc::ioctl(fd, iorw!($ioty, $nr, len) as $crate::sys::ioctl::ioctl_num_type, val)) } ); } diff --git a/src/sys/ioctl/platform/bsd.rs b/src/sys/ioctl/platform/bsd.rs index df3716b9..ea39da3d 100644 --- a/src/sys/ioctl/platform/bsd.rs +++ b/src/sys/ioctl/platform/bsd.rs @@ -1,14 +1,19 @@ +/// The datatype used for the ioctl number +#[doc(hidden)] +pub type ioctl_num_type = ::libc::c_ulong; + mod consts { + use ::sys::ioctl::platform::ioctl_num_type; #[doc(hidden)] - pub const VOID: u32 = 0x20000000; + pub const VOID: ioctl_num_type = 0x20000000; #[doc(hidden)] - pub const OUT: u32 = 0x40000000; + pub const OUT: ioctl_num_type = 0x40000000; #[doc(hidden)] - pub const IN: u32 = 0x80000000; + pub const IN: ioctl_num_type = 0x80000000; #[doc(hidden)] - pub const INOUT: u32 = (IN|OUT); + pub const INOUT: ioctl_num_type = (IN|OUT); #[doc(hidden)] - pub const IOCPARM_MASK: u32 = 0x1fff; + pub const IOCPARM_MASK: ioctl_num_type = 0x1fff; } pub use self::consts::*; @@ -17,7 +22,7 @@ pub use self::consts::*; #[doc(hidden)] macro_rules! ioc { ($inout:expr, $group:expr, $num:expr, $len:expr) => ( - $inout | (($len as u32 & $crate::sys::ioctl::IOCPARM_MASK) << 16) | (($group as u32) << 8) | ($num as u32) + $inout | (($len as $crate::sys::ioctl::ioctl_num_type & $crate::sys::ioctl::IOCPARM_MASK) << 16) | (($group as $crate::sys::ioctl::ioctl_num_type) << 8) | ($num as $crate::sys::ioctl::ioctl_num_type) ) } diff --git a/src/sys/ioctl/platform/linux.rs b/src/sys/ioctl/platform/linux.rs index e3a130a9..6daa9257 100644 --- a/src/sys/ioctl/platform/linux.rs +++ b/src/sys/ioctl/platform/linux.rs @@ -1,7 +1,15 @@ +/// The datatype used for the ioctl number +#[cfg(any(target_os = "android", target_env = "musl"))] #[doc(hidden)] -pub const NRBITS: u32 = 8; +pub type ioctl_num_type = ::libc::c_int; +#[cfg(not(any(target_os = "android", target_env = "musl")))] #[doc(hidden)] -pub const TYPEBITS: u32 = 8; +pub type ioctl_num_type = ::libc::c_ulong; + +#[doc(hidden)] +pub const NRBITS: ioctl_num_type = 8; +#[doc(hidden)] +pub const TYPEBITS: ioctl_num_type = 8; #[cfg(any(target_arch = "mips", target_arch = "mips64", target_arch = "powerpc", target_arch = "powerpc64"))] mod consts { @@ -50,32 +58,32 @@ mod consts { pub use self::consts::*; #[doc(hidden)] -pub const NRSHIFT: u32 = 0; +pub const NRSHIFT: ioctl_num_type = 0; #[doc(hidden)] -pub const TYPESHIFT: u32 = NRSHIFT + NRBITS as u32; +pub const TYPESHIFT: ioctl_num_type = NRSHIFT + NRBITS as ioctl_num_type; #[doc(hidden)] -pub const SIZESHIFT: u32 = TYPESHIFT + TYPEBITS as u32; +pub const SIZESHIFT: ioctl_num_type = TYPESHIFT + TYPEBITS as ioctl_num_type; #[doc(hidden)] -pub const DIRSHIFT: u32 = SIZESHIFT + SIZEBITS as u32; +pub const DIRSHIFT: ioctl_num_type = SIZESHIFT + SIZEBITS as ioctl_num_type; #[doc(hidden)] -pub const NRMASK: u32 = (1 << NRBITS) - 1; +pub const NRMASK: ioctl_num_type = (1 << NRBITS) - 1; #[doc(hidden)] -pub const TYPEMASK: u32 = (1 << TYPEBITS) - 1; +pub const TYPEMASK: ioctl_num_type = (1 << TYPEBITS) - 1; #[doc(hidden)] -pub const SIZEMASK: u32 = (1 << SIZEBITS) - 1; +pub const SIZEMASK: ioctl_num_type = (1 << SIZEBITS) - 1; #[doc(hidden)] -pub const DIRMASK: u32 = (1 << DIRBITS) - 1; +pub const DIRMASK: ioctl_num_type = (1 << DIRBITS) - 1; /// Encode an ioctl command. #[macro_export] #[doc(hidden)] macro_rules! ioc { ($dir:expr, $ty:expr, $nr:expr, $sz:expr) => ( - (($dir as u32) << $crate::sys::ioctl::DIRSHIFT) | - (($ty as u32) << $crate::sys::ioctl::TYPESHIFT) | - (($nr as u32) << $crate::sys::ioctl::NRSHIFT) | - (($sz as u32) << $crate::sys::ioctl::SIZESHIFT)) + (($dir as $crate::sys::ioctl::ioctl_num_type & $crate::sys::ioctl::DIRMASK) << $crate::sys::ioctl::DIRSHIFT) | + (($ty as $crate::sys::ioctl::ioctl_num_type & $crate::sys::ioctl::TYPEMASK) << $crate::sys::ioctl::TYPESHIFT) | + (($nr as $crate::sys::ioctl::ioctl_num_type & $crate::sys::ioctl::NRMASK) << $crate::sys::ioctl::NRSHIFT) | + (($sz as $crate::sys::ioctl::ioctl_num_type & $crate::sys::ioctl::SIZEMASK) << $crate::sys::ioctl::SIZESHIFT)) } /// Encode an ioctl command that has no associated data. |