Skip to content

Commit 45653cc

Browse files
committed
sys/statfs: use statfs from libc
1 parent 818a5e8 commit 45653cc

File tree

1 file changed

+7
-40
lines changed

1 file changed

+7
-40
lines changed

src/sys/statfs.rs

Lines changed: 7 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,22 @@
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")]
67
pub mod hwdep {
7-
use libc::{c_uint};
8+
use libc::c_uint;
89
pub type FsType = c_uint;
9-
pub type BlockSize = c_uint;
10-
pub type NameLen = c_uint;
11-
pub type FragmentSize = c_uint;
12-
pub type SwordType = c_uint;
1310
}
1411

1512
#[cfg(target_pointer_width = "64")]
1613
pub mod hwdep {
17-
use libc::{c_long};
14+
use libc::c_long;
1815
pub type FsType = c_long;
19-
pub type BlockSize = c_long;
20-
pub type NameLen = c_long;
21-
pub type FragmentSize = c_long;
22-
pub type SwordType = c_long;
2316
}
2417

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

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-
4320
pub const ADFS_SUPER_MAGIC : FsType = 0xadf5;
4421
pub const AFFS_SUPER_MAGIC : FsType = 0xADFF;
4522
pub const BEFS_SUPER_MAGIC : FsType = 0x42465331;
@@ -87,30 +64,20 @@ pub mod vfs {
8764
pub const _XIAFS_SUPER_MAGIC : FsType = 0x012FD16D;
8865
}
8966

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<()> {
67+
pub fn statfs<P: ?Sized + NixPath>(path: &P, stat: &mut libc::statfs) -> Result<()> {
10168
unsafe {
10269
Errno::clear();
10370
let res = try!(
104-
path.with_nix_path(|path| ffi::statfs(path.as_ptr(), stat))
71+
path.with_nix_path(|path| libc::statfs(path.as_ptr(), stat))
10572
);
10673

10774
Errno::result(res).map(drop)
10875
}
10976
}
11077

111-
pub fn fstatfs<T: AsRawFd>(fd: &T, stat: &mut vfs::Statfs) -> Result<()> {
78+
pub fn fstatfs<T: AsRawFd>(fd: &T, stat: &mut libc::statfs) -> Result<()> {
11279
unsafe {
11380
Errno::clear();
114-
Errno::result(ffi::fstatfs(fd.as_raw_fd(), stat)).map(drop)
81+
Errno::result(libc::fstatfs(fd.as_raw_fd(), stat)).map(drop)
11582
}
11683
}

0 commit comments

Comments
 (0)