Skip to content

Commit

Permalink
sys/statfs: use statfs from libc
Browse files Browse the repository at this point in the history
  • Loading branch information
Mic92 committed Mar 25, 2017
1 parent 818a5e8 commit 04b8a34
Showing 1 changed file with 5 additions and 30 deletions.
35 changes: 5 additions & 30 deletions src/sys/statfs.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use {Errno, Result, NixPath};
use std::os::unix::io::AsRawFd;
use libc;

pub mod vfs {
#[cfg(target_pointer_width = "32")]
Expand All @@ -24,22 +25,6 @@ pub mod vfs {

use sys::statfs::vfs::hwdep::*;

#[repr(C)]
#[derive(Debug,Copy,Clone)]
pub struct Statfs {
pub f_type: FsType,
pub f_bsize: BlockSize,
pub f_blocks: u64,
pub f_bfree: u64,
pub f_bavail: u64,
pub f_files: u64,
pub f_ffree: u64,
pub f_fsid: u64,
pub f_namelen: NameLen,
pub f_frsize: FragmentSize,
pub f_spare: [SwordType; 5],
}

pub const ADFS_SUPER_MAGIC : FsType = 0xadf5;
pub const AFFS_SUPER_MAGIC : FsType = 0xADFF;
pub const BEFS_SUPER_MAGIC : FsType = 0x42465331;
Expand Down Expand Up @@ -87,30 +72,20 @@ pub mod vfs {
pub const _XIAFS_SUPER_MAGIC : FsType = 0x012FD16D;
}

mod ffi {
use libc::{c_int,c_char};
use sys::statfs::vfs;

extern {
pub fn statfs(path: * const c_char, buf: *mut vfs::Statfs) -> c_int;
pub fn fstatfs(fd: c_int, buf: *mut vfs::Statfs) -> c_int;
}
}

pub fn statfs<P: ?Sized + NixPath>(path: &P, stat: &mut vfs::Statfs) -> Result<()> {
pub fn statfs<P: ?Sized + NixPath>(path: &P, stat: &mut libc::statfs) -> Result<()> {
unsafe {
Errno::clear();
let res = try!(
path.with_nix_path(|path| ffi::statfs(path.as_ptr(), stat))
path.with_nix_path(|path| libc::statfs(path.as_ptr(), stat))
);

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

pub fn fstatfs<T: AsRawFd>(fd: &T, stat: &mut vfs::Statfs) -> Result<()> {
pub fn fstatfs<T: AsRawFd>(fd: &T, stat: &mut libc::statfs) -> Result<()> {
unsafe {
Errno::clear();
Errno::result(ffi::fstatfs(fd.as_raw_fd(), stat)).map(drop)
Errno::result(libc::fstatfs(fd.as_raw_fd(), stat)).map(drop)
}
}

0 comments on commit 04b8a34

Please sign in to comment.