Skip to content

Commit

Permalink
use u16 for ioctl() request and convert it to required type
Browse files Browse the repository at this point in the history
Fixes: #6
Signed-off-by: Igor Gnatenko <[email protected]>
  • Loading branch information
cuviper authored and ignatenkobrain committed Nov 30, 2017
1 parent b3d3d29 commit 88a23e8
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ use std::path::{Path, PathBuf};
use libc::{c_int, ioctl, uint8_t, uint32_t, uint64_t};
use std::default::Default;

static LOOP_SET_FD: u64 = 0x4C00;
static LOOP_CLR_FD: u64 = 0x4C01;
static LOOP_SET_STATUS64: u64 = 0x4C04;
static LOOP_CTL_GET_FREE: u64 = 0x4C82;
static LOOP_SET_FD: u16 = 0x4C00;
static LOOP_CLR_FD: u16 = 0x4C01;
static LOOP_SET_STATUS64: u16 = 0x4C04;
static LOOP_CTL_GET_FREE: u16 = 0x4C82;

const LOOP_CONTROL: &'static str = "/dev/loop-control";
const LOOP_PREFIX: &'static str = "/dev/loop";
Expand Down Expand Up @@ -62,7 +62,7 @@ impl LoopControl {
pub fn next_free(&self) -> io::Result<LoopDevice> {
let result;
unsafe {
result = ioctl(self.dev_file.as_raw_fd() as c_int, LOOP_CTL_GET_FREE);
result = ioctl(self.dev_file.as_raw_fd() as c_int, LOOP_CTL_GET_FREE.into());
}
if result < 0 {
Err(io::Error::last_os_error())
Expand Down Expand Up @@ -104,7 +104,7 @@ impl LoopDevice {
// Attach the file
unsafe {
if ioctl(self.device.as_raw_fd() as c_int,
LOOP_SET_FD,
LOOP_SET_FD.into(),
bf.as_raw_fd() as c_int) < 0 {
return Err(io::Error::last_os_error());
}
Expand All @@ -115,7 +115,7 @@ impl LoopDevice {
info.lo_offset = offset;
unsafe {
if ioctl(self.device.as_raw_fd() as c_int,
LOOP_SET_STATUS64,
LOOP_SET_STATUS64.into(),
&mut info) < 0 {
try!(self.detach());
return Err(io::Error::last_os_error());
Expand Down Expand Up @@ -143,7 +143,7 @@ impl LoopDevice {
/// ```
pub fn detach(&self) -> io::Result<()> {
unsafe {
if ioctl(self.device.as_raw_fd() as c_int, LOOP_CLR_FD, 0) < 0 {
if ioctl(self.device.as_raw_fd() as c_int, LOOP_CLR_FD.into(), 0) < 0 {
return Err(io::Error::last_os_error());
}
}
Expand Down

0 comments on commit 88a23e8

Please sign in to comment.