Skip to content

Commit

Permalink
Changes the global statics to consts
Browse files Browse the repository at this point in the history
Also runs the source through a newer version of rustfmt
  • Loading branch information
Michael Daffin committed Dec 5, 2017
1 parent ce02632 commit 11151a8
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 11 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
target/
/Cargo.lock
test.img
30 changes: 19 additions & 11 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: u16 = 0x4C00;
static LOOP_CLR_FD: u16 = 0x4C01;
static LOOP_SET_STATUS64: u16 = 0x4C04;
static LOOP_CTL_GET_FREE: u16 = 0x4C82;
const LOOP_SET_FD: u16 = 0x4C00;
const LOOP_CLR_FD: u16 = 0x4C01;
const LOOP_SET_STATUS64: u16 = 0x4C04;
const 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 @@ -67,7 +67,9 @@ impl LoopControl {
if result < 0 {
Err(io::Error::last_os_error())
} else {
Ok(try!(LoopDevice::open(&format!("{}{}", LOOP_PREFIX, result))))
Ok(try!(
LoopDevice::open(&format!("{}{}", LOOP_PREFIX, result))
))
}
}
}
Expand Down Expand Up @@ -103,9 +105,12 @@ impl LoopDevice {

// Attach the file
unsafe {
if ioctl(self.device.as_raw_fd() as c_int,
LOOP_SET_FD.into(),
bf.as_raw_fd() as c_int) < 0 {
if ioctl(
self.device.as_raw_fd() as c_int,
LOOP_SET_FD.into(),
bf.as_raw_fd() as c_int,
) < 0
{
return Err(io::Error::last_os_error());
}
}
Expand All @@ -114,9 +119,12 @@ impl LoopDevice {
let mut info: loop_info64 = Default::default();
info.lo_offset = offset;
unsafe {
if ioctl(self.device.as_raw_fd() as c_int,
LOOP_SET_STATUS64.into(),
&mut info) < 0 {
if ioctl(
self.device.as_raw_fd() as c_int,
LOOP_SET_STATUS64.into(),
&mut info,
) < 0
{
try!(self.detach());
return Err(io::Error::last_os_error());
}
Expand Down

0 comments on commit 11151a8

Please sign in to comment.