Skip to content

Commit 04b8a34

Browse files
committed
sys/statfs: use statfs from libc
1 parent 818a5e8 commit 04b8a34

File tree

1 file changed

+5
-30
lines changed

1 file changed

+5
-30
lines changed

src/sys/statfs.rs

Lines changed: 5 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use {Errno, Result, NixPath};
22
use std::os::unix::io::AsRawFd;
3+
use libc;
34

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

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

27-
#[repr(C)]
28-
#[derive(Debug,Copy,Clone)]
29-
pub struct Statfs {
30-
pub f_type: FsType,
31-
pub f_bsize: BlockSize,
32-
pub f_blocks: u64,
33-
pub f_bfree: u64,
34-
pub f_bavail: u64,
35-
pub f_files: u64,
36-
pub f_ffree: u64,
37-
pub f_fsid: u64,
38-
pub f_namelen: NameLen,
39-
pub f_frsize: FragmentSize,
40-
pub f_spare: [SwordType; 5],
41-
}
42-
4328
pub const ADFS_SUPER_MAGIC : FsType = 0xadf5;
4429
pub const AFFS_SUPER_MAGIC : FsType = 0xADFF;
4530
pub const BEFS_SUPER_MAGIC : FsType = 0x42465331;
@@ -87,30 +72,20 @@ pub mod vfs {
8772
pub const _XIAFS_SUPER_MAGIC : FsType = 0x012FD16D;
8873
}
8974

90-
mod ffi {
91-
use libc::{c_int,c_char};
92-
use sys::statfs::vfs;
93-
94-
extern {
95-
pub fn statfs(path: * const c_char, buf: *mut vfs::Statfs) -> c_int;
96-
pub fn fstatfs(fd: c_int, buf: *mut vfs::Statfs) -> c_int;
97-
}
98-
}
99-
100-
pub fn statfs<P: ?Sized + NixPath>(path: &P, stat: &mut vfs::Statfs) -> Result<()> {
75+
pub fn statfs<P: ?Sized + NixPath>(path: &P, stat: &mut libc::statfs) -> Result<()> {
10176
unsafe {
10277
Errno::clear();
10378
let res = try!(
104-
path.with_nix_path(|path| ffi::statfs(path.as_ptr(), stat))
79+
path.with_nix_path(|path| libc::statfs(path.as_ptr(), stat))
10580
);
10681

10782
Errno::result(res).map(drop)
10883
}
10984
}
11085

111-
pub fn fstatfs<T: AsRawFd>(fd: &T, stat: &mut vfs::Statfs) -> Result<()> {
86+
pub fn fstatfs<T: AsRawFd>(fd: &T, stat: &mut libc::statfs) -> Result<()> {
11287
unsafe {
11388
Errno::clear();
114-
Errno::result(ffi::fstatfs(fd.as_raw_fd(), stat)).map(drop)
89+
Errno::result(libc::fstatfs(fd.as_raw_fd(), stat)).map(drop)
11590
}
11691
}

0 commit comments

Comments
 (0)