Skip to content

Commit

Permalink
Auto merge of #356 - brianp:mount-libc, r=posborne
Browse files Browse the repository at this point in the history
mount: Use bindings from libc instead of our own

Ref #264

Changing internal usage of `ffi::mount` and `ffi:umount` to make use of libc.
  • Loading branch information
homu committed Apr 17, 2016
2 parents b7c2f88 + 2f54367 commit ec37fa8
Showing 1 changed file with 4 additions and 20 deletions.
24 changes: 4 additions & 20 deletions src/mount.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use libc::{c_ulong, c_int};
use libc;
use {Errno, Result, NixPath};

bitflags!(
Expand Down Expand Up @@ -48,23 +49,6 @@ bitflags!(
}
);

mod ffi {
use libc::{c_char, c_int, c_ulong, c_void};

extern {
pub fn mount(
source: *const c_char,
target: *const c_char,
fstype: *const c_char,
flags: c_ulong,
data: *const c_void) -> c_int;

pub fn umount(target: *const c_char) -> c_int;

pub fn umount2(target: *const c_char, flags: c_int) -> c_int;
}
}

pub fn mount<P1: ?Sized + NixPath, P2: ?Sized + NixPath, P3: ?Sized + NixPath, P4: ?Sized + NixPath>(
source: Option<&P1>,
target: &P2,
Expand All @@ -79,7 +63,7 @@ pub fn mount<P1: ?Sized + NixPath, P2: ?Sized + NixPath, P3: ?Sized + NixPath, P
fstype.with_nix_path(|fstype| {
data.with_nix_path(|data| {
unsafe {
ffi::mount(source.as_ptr(),
libc::mount(source.as_ptr(),
target.as_ptr(),
fstype.as_ptr(),
flags.bits,
Expand All @@ -95,15 +79,15 @@ pub fn mount<P1: ?Sized + NixPath, P2: ?Sized + NixPath, P3: ?Sized + NixPath, P

pub fn umount<P: ?Sized + NixPath>(target: &P) -> Result<()> {
let res = try!(target.with_nix_path(|cstr| {
unsafe { ffi::umount(cstr.as_ptr()) }
unsafe { libc::umount(cstr.as_ptr()) }
}));

Errno::result(res).map(drop)
}

pub fn umount2<P: ?Sized + NixPath>(target: &P, flags: MntFlags) -> Result<()> {
let res = try!(target.with_nix_path(|cstr| {
unsafe { ffi::umount2(cstr.as_ptr(), flags.bits) }
unsafe { libc::umount2(cstr.as_ptr(), flags.bits) }
}));

Errno::result(res).map(drop)
Expand Down

0 comments on commit ec37fa8

Please sign in to comment.