summaryrefslogtreecommitdiff
path: root/src/sys/statvfs.rs
diff options
context:
space:
mode:
authorAlexander Polakov <plhk@sdf.org>2015-09-17 19:11:58 +0300
committerCarl Lerche <me@carllerche.com>2015-09-28 14:43:17 -0700
commitbdaee6bd8ac4eb7ed0906233e0f073cabbf0dd3f (patch)
tree34aaedf83e8fb32ce32d4bbeac8aec138f5d1905 /src/sys/statvfs.rs
parentc17d5b32a77e49bc2c53b21f25a7ebf9be607cba (diff)
downloadnix-bdaee6bd8ac4eb7ed0906233e0f073cabbf0dd3f.zip
statfs() & fstatfs()
Diffstat (limited to 'src/sys/statvfs.rs')
-rw-r--r--src/sys/statvfs.rs70
1 files changed, 70 insertions, 0 deletions
diff --git a/src/sys/statvfs.rs b/src/sys/statvfs.rs
new file mode 100644
index 00000000..c5338109
--- /dev/null
+++ b/src/sys/statvfs.rs
@@ -0,0 +1,70 @@
+use {Result, NixPath, from_ffi};
+use errno::Errno;
+use std::os::unix::io::AsRawFd;
+
+pub mod vfs {
+ use libc::{c_ulong,c_int};
+
+ bitflags!(
+ #[repr(C)]
+ #[derive(Default)]
+ flags FsFlags: c_ulong {
+ const RDONLY = 1,
+ const NOSUID = 2,
+ const NODEV = 4,
+ const NOEXEC = 8,
+ const SYNCHRONOUS = 16,
+ const MANDLOCK = 64,
+ const WRITE = 128,
+ const APPEND = 256,
+ const IMMUTABLE = 512,
+ const NOATIME = 1024,
+ const NODIRATIME = 2048,
+ const RELATIME = 4096,
+ }
+ );
+
+ #[repr(C)]
+ #[derive(Debug,Copy,Clone)]
+ pub struct Statvfs {
+ pub f_bsize: c_ulong,
+ pub f_frsize: c_ulong,
+ pub f_blocks: u64,
+ pub f_bfree: u64,
+ pub f_bavail: u64,
+ pub f_files: u64,
+ pub f_ffree: u64,
+ pub f_favail: u64,
+ pub f_fsid: c_ulong,
+ pub f_flag: FsFlags,
+ pub f_namemax: c_ulong,
+ f_spare: [c_int; 6],
+ }
+}
+
+mod ffi {
+ use libc::{c_char, c_int};
+ use sys::statvfs::vfs;
+
+ extern {
+ pub fn statvfs(path: * const c_char, buf: *mut vfs::Statvfs) -> c_int;
+ pub fn fstatvfs(fd: c_int, buf: *mut vfs::Statvfs) -> c_int;
+ }
+}
+
+pub fn statvfs<P: ?Sized + NixPath>(path: &P, stat: &mut vfs::Statvfs) -> Result<()> {
+ unsafe {
+ Errno::clear();
+ let res = try!(
+ path.with_nix_path(|path| ffi::statvfs(path.as_ptr(), stat))
+ );
+ from_ffi(res)
+ }
+}
+
+pub fn fstatvfs<T: AsRawFd>(fd: &T, stat: &mut vfs::Statvfs) -> Result<()> {
+ unsafe {
+ Errno::clear();
+ from_ffi(ffi::fstatvfs(fd.as_raw_fd(), stat))
+ }
+}