|
1 | 1 | use {Errno, Result, NixPath};
|
2 | 2 | use std::os::unix::io::AsRawFd;
|
| 3 | +use libc; |
3 | 4 |
|
4 |
| -pub mod vfs { |
5 |
| - #[cfg(target_pointer_width = "32")] |
6 |
| - pub mod hwdep { |
7 |
| - use libc::{c_uint}; |
8 |
| - 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; |
13 |
| - } |
14 |
| - |
15 |
| - #[cfg(target_pointer_width = "64")] |
16 |
| - pub mod hwdep { |
17 |
| - use libc::{c_long}; |
18 |
| - 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; |
23 |
| - } |
24 |
| - |
25 |
| - use sys::statfs::vfs::hwdep::*; |
26 |
| - |
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 |
| - |
43 |
| - pub const ADFS_SUPER_MAGIC : FsType = 0xadf5; |
44 |
| - pub const AFFS_SUPER_MAGIC : FsType = 0xADFF; |
45 |
| - pub const BEFS_SUPER_MAGIC : FsType = 0x42465331; |
46 |
| - pub const BFS_MAGIC : FsType = 0x1BADFACE; |
47 |
| - pub const CIFS_MAGIC_NUMBER : FsType = 0xFF534D42; |
48 |
| - pub const CODA_SUPER_MAGIC : FsType = 0x73757245; |
49 |
| - pub const COH_SUPER_MAGIC : FsType = 0x012FF7B7; |
50 |
| - pub const CRAMFS_MAGIC : FsType = 0x28cd3d45; |
51 |
| - pub const DEVFS_SUPER_MAGIC : FsType = 0x1373; |
52 |
| - pub const EFS_SUPER_MAGIC : FsType = 0x00414A53; |
53 |
| - pub const EXT_SUPER_MAGIC : FsType = 0x137D; |
54 |
| - pub const EXT2_OLD_SUPER_MAGIC : FsType = 0xEF51; |
55 |
| - pub const EXT2_SUPER_MAGIC : FsType = 0xEF53; |
56 |
| - pub const EXT3_SUPER_MAGIC : FsType = 0xEF53; |
57 |
| - pub const EXT4_SUPER_MAGIC : FsType = 0xEF53; |
58 |
| - pub const HFS_SUPER_MAGIC : FsType = 0x4244; |
59 |
| - pub const HPFS_SUPER_MAGIC : FsType = 0xF995E849; |
60 |
| - pub const HUGETLBFS_MAGIC : FsType = 0x958458f6; |
61 |
| - pub const ISOFS_SUPER_MAGIC : FsType = 0x9660; |
62 |
| - pub const JFFS2_SUPER_MAGIC : FsType = 0x72b6; |
63 |
| - pub const JFS_SUPER_MAGIC : FsType = 0x3153464a; |
64 |
| - pub const MINIX_SUPER_MAGIC : FsType = 0x137F; /* orig. minix */ |
65 |
| - pub const MINIX_SUPER_MAGIC2 : FsType = 0x138F; /* 30 char minix */ |
66 |
| - pub const MINIX2_SUPER_MAGIC : FsType = 0x2468; /* minix V2 */ |
67 |
| - pub const MINIX2_SUPER_MAGIC2 : FsType = 0x2478; /* minix V2, 30 char names */ |
68 |
| - pub const MSDOS_SUPER_MAGIC : FsType = 0x4d44; |
69 |
| - pub const NCP_SUPER_MAGIC : FsType = 0x564c; |
70 |
| - pub const NFS_SUPER_MAGIC : FsType = 0x6969; |
71 |
| - pub const NTFS_SB_MAGIC : FsType = 0x5346544e; |
72 |
| - pub const OPENPROM_SUPER_MAGIC : FsType = 0x9fa1; |
73 |
| - pub const PROC_SUPER_MAGIC : FsType = 0x9fa0; |
74 |
| - pub const QNX4_SUPER_MAGIC : FsType = 0x002f; |
75 |
| - pub const REISERFS_SUPER_MAGIC : FsType = 0x52654973; |
76 |
| - pub const ROMFS_MAGIC : FsType = 0x7275; |
77 |
| - pub const SMB_SUPER_MAGIC : FsType = 0x517B; |
78 |
| - pub const SYSV2_SUPER_MAGIC : FsType = 0x012FF7B6; |
79 |
| - pub const SYSV4_SUPER_MAGIC : FsType = 0x012FF7B5; |
80 |
| - pub const TMPFS_MAGIC : FsType = 0x01021994; |
81 |
| - pub const UDF_SUPER_MAGIC : FsType = 0x15013346; |
82 |
| - pub const UFS_MAGIC : FsType = 0x00011954; |
83 |
| - pub const USBDEVICE_SUPER_MAGIC : FsType = 0x9fa2; |
84 |
| - pub const VXFS_SUPER_MAGIC : FsType = 0xa501FCF5; |
85 |
| - pub const XENIX_SUPER_MAGIC : FsType = 0x012FF7B4; |
86 |
| - pub const XFS_SUPER_MAGIC : FsType = 0x58465342; |
87 |
| - pub const _XIAFS_SUPER_MAGIC : FsType = 0x012FD16D; |
88 |
| -} |
89 |
| - |
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<()> { |
| 5 | +pub fn statfs<P: ?Sized + NixPath>(path: &P, stat: &mut libc::statfs) -> Result<()> { |
101 | 6 | unsafe {
|
102 | 7 | Errno::clear();
|
103 | 8 | let res = try!(
|
104 |
| - path.with_nix_path(|path| ffi::statfs(path.as_ptr(), stat)) |
| 9 | + path.with_nix_path(|path| libc::statfs(path.as_ptr(), stat)) |
105 | 10 | );
|
106 | 11 |
|
107 | 12 | Errno::result(res).map(drop)
|
108 | 13 | }
|
109 | 14 | }
|
110 | 15 |
|
111 |
| -pub fn fstatfs<T: AsRawFd>(fd: &T, stat: &mut vfs::Statfs) -> Result<()> { |
| 16 | +pub fn fstatfs<T: AsRawFd>(fd: &T, stat: &mut libc::statfs) -> Result<()> { |
112 | 17 | unsafe {
|
113 | 18 | Errno::clear();
|
114 |
| - Errno::result(ffi::fstatfs(fd.as_raw_fd(), stat)).map(drop) |
| 19 | + Errno::result(libc::fstatfs(fd.as_raw_fd(), stat)).map(drop) |
115 | 20 | }
|
116 | 21 | }
|
0 commit comments