diff --git a/src/lib.rs b/src/lib.rs index 058a01a..ff8eec0 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -37,6 +37,11 @@ mod bindings { include!(concat!(env!("OUT_DIR"), "/bindings.rs")); } +#[cfg(not(target_os = "android"))] +type IoctlRequest = libc::c_ulong; +#[cfg(target_os = "android")] +type IoctlRequest = libc::c_int; + const LOOP_CONTROL: &str = "/dev/loop-control"; #[cfg(not(target_os = "android"))] const LOOP_PREFIX: &str = "/dev/loop"; @@ -72,7 +77,10 @@ impl LoopControl { /// ``` pub fn next_free(&self) -> io::Result { let dev_num = ioctl_to_error(unsafe { - ioctl(self.dev_file.as_raw_fd() as c_int, LOOP_CTL_GET_FREE.into()) + ioctl( + self.dev_file.as_raw_fd() as c_int, + LOOP_CTL_GET_FREE as IoctlRequest, + ) })?; LoopDevice::open(&format!("{}{}", LOOP_PREFIX, dev_num)) } @@ -205,7 +213,7 @@ impl LoopDevice { ioctl_to_error(unsafe { ioctl( self.device.as_raw_fd() as c_int, - LOOP_SET_FD.into(), + LOOP_SET_FD as IoctlRequest, bf.as_raw_fd() as c_int, ) })?; @@ -213,7 +221,7 @@ impl LoopDevice { if let Err(err) = ioctl_to_error(unsafe { ioctl( self.device.as_raw_fd() as c_int, - LOOP_SET_STATUS64.into(), + LOOP_SET_STATUS64 as IoctlRequest, &info, ) }) { @@ -252,7 +260,13 @@ impl LoopDevice { /// ld.detach().unwrap(); /// ``` pub fn detach(&self) -> io::Result<()> { - ioctl_to_error(unsafe { ioctl(self.device.as_raw_fd() as c_int, LOOP_CLR_FD.into(), 0) })?; + ioctl_to_error(unsafe { + ioctl( + self.device.as_raw_fd() as c_int, + LOOP_CLR_FD as IoctlRequest, + 0, + ) + })?; Ok(()) } @@ -262,7 +276,7 @@ impl LoopDevice { ioctl_to_error(unsafe { ioctl( self.device.as_raw_fd() as c_int, - LOOP_SET_CAPACITY.into(), + LOOP_SET_CAPACITY as IoctlRequest, 0, ) })?;