summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/sys/quota.rs182
-rw-r--r--src/sys/statfs.rs192
-rw-r--r--src/sys/statvfs.rs276
3 files changed, 325 insertions, 325 deletions
diff --git a/src/sys/quota.rs b/src/sys/quota.rs
index 199d08e2..4786f80d 100644
--- a/src/sys/quota.rs
+++ b/src/sys/quota.rs
@@ -8,119 +8,119 @@ use libc::{c_int, c_char};
target_arch = "arm")),
)]
pub mod quota {
- use libc::c_int;
-
- pub struct QuotaCmd(pub QuotaSubCmd, pub QuotaType);
- pub type QuotaSubCmd = c_int;
-
- impl QuotaCmd {
- pub fn as_int(&self) -> c_int {
- ((self.0 << 8) | (self.1 & 0x00ff)) as c_int
- }
- }
-
- // linux quota version >= 2
- pub const Q_SYNC: QuotaSubCmd = 0x800001;
- pub const Q_QUOTAON: QuotaSubCmd = 0x800002;
- pub const Q_QUOTAOFF: QuotaSubCmd = 0x800003;
- pub const Q_GETFMT: QuotaSubCmd = 0x800004;
- pub const Q_GETINFO: QuotaSubCmd = 0x800005;
- pub const Q_SETINFO: QuotaSubCmd = 0x800006;
- pub const Q_GETQUOTA: QuotaSubCmd = 0x800007;
- pub const Q_SETQUOTA: QuotaSubCmd = 0x800008;
-
- pub type QuotaType = c_int;
-
- pub const USRQUOTA: QuotaType = 0;
- pub const GRPQUOTA: QuotaType = 1;
-
- pub type QuotaFmt = c_int;
-
- pub const QFMT_VFS_OLD: QuotaFmt = 1;
- pub const QFMT_VFS_V0: QuotaFmt = 2;
- pub const QFMT_VFS_V1: QuotaFmt = 4;
-
- bitflags!(
- #[derive(Default)]
- flags QuotaValidFlags: u32 {
- const QIF_BLIMITS = 1,
- const QIF_SPACE = 2,
- const QIF_ILIMITS = 4,
- const QIF_INODES = 8,
- const QIF_BTIME = 16,
- const QIF_ITIME = 32,
- const QIF_LIMITS = QIF_BLIMITS.bits | QIF_ILIMITS.bits,
- const QIF_USAGE = QIF_SPACE.bits | QIF_INODES.bits,
- const QIF_TIMES = QIF_BTIME.bits | QIF_ITIME.bits,
- const QIF_ALL = QIF_LIMITS.bits | QIF_USAGE.bits | QIF_TIMES.bits
- }
- );
-
- #[repr(C)]
- #[derive(Default,Debug,Copy,Clone)]
- pub struct Dqblk {
- pub bhardlimit: u64,
- pub bsoftlimit: u64,
- pub curspace: u64,
- pub ihardlimit: u64,
- pub isoftlimit: u64,
- pub curinodes: u64,
- pub btime: u64,
- pub itime: u64,
- pub valid: QuotaValidFlags,
- }
+ use libc::c_int;
+
+ pub struct QuotaCmd(pub QuotaSubCmd, pub QuotaType);
+ pub type QuotaSubCmd = c_int;
+
+ impl QuotaCmd {
+ pub fn as_int(&self) -> c_int {
+ ((self.0 << 8) | (self.1 & 0x00ff)) as c_int
+ }
+ }
+
+ // linux quota version >= 2
+ pub const Q_SYNC: QuotaSubCmd = 0x800001;
+ pub const Q_QUOTAON: QuotaSubCmd = 0x800002;
+ pub const Q_QUOTAOFF: QuotaSubCmd = 0x800003;
+ pub const Q_GETFMT: QuotaSubCmd = 0x800004;
+ pub const Q_GETINFO: QuotaSubCmd = 0x800005;
+ pub const Q_SETINFO: QuotaSubCmd = 0x800006;
+ pub const Q_GETQUOTA: QuotaSubCmd = 0x800007;
+ pub const Q_SETQUOTA: QuotaSubCmd = 0x800008;
+
+ pub type QuotaType = c_int;
+
+ pub const USRQUOTA: QuotaType = 0;
+ pub const GRPQUOTA: QuotaType = 1;
+
+ pub type QuotaFmt = c_int;
+
+ pub const QFMT_VFS_OLD: QuotaFmt = 1;
+ pub const QFMT_VFS_V0: QuotaFmt = 2;
+ pub const QFMT_VFS_V1: QuotaFmt = 4;
+
+ bitflags!(
+ #[derive(Default)]
+ flags QuotaValidFlags: u32 {
+ const QIF_BLIMITS = 1,
+ const QIF_SPACE = 2,
+ const QIF_ILIMITS = 4,
+ const QIF_INODES = 8,
+ const QIF_BTIME = 16,
+ const QIF_ITIME = 32,
+ const QIF_LIMITS = QIF_BLIMITS.bits | QIF_ILIMITS.bits,
+ const QIF_USAGE = QIF_SPACE.bits | QIF_INODES.bits,
+ const QIF_TIMES = QIF_BTIME.bits | QIF_ITIME.bits,
+ const QIF_ALL = QIF_LIMITS.bits | QIF_USAGE.bits | QIF_TIMES.bits
+ }
+ );
+
+ #[repr(C)]
+ #[derive(Default,Debug,Copy,Clone)]
+ pub struct Dqblk {
+ pub bhardlimit: u64,
+ pub bsoftlimit: u64,
+ pub curspace: u64,
+ pub ihardlimit: u64,
+ pub isoftlimit: u64,
+ pub curinodes: u64,
+ pub btime: u64,
+ pub itime: u64,
+ pub valid: QuotaValidFlags,
+ }
}
mod ffi {
- use libc::{c_int, c_char};
+ use libc::{c_int, c_char};
- extern {
- pub fn quotactl(cmd: c_int, special: * const c_char, id: c_int, data: *mut c_char) -> c_int;
- }
+ extern {
+ pub fn quotactl(cmd: c_int, special: * const c_char, id: c_int, data: *mut c_char) -> c_int;
+ }
}
use std::ptr;
fn quotactl<P: ?Sized + NixPath>(cmd: quota::QuotaCmd, special: Option<&P>, id: c_int, addr: *mut c_char) -> Result<()> {
- unsafe {
- Errno::clear();
- let res = try!(
- match special {
- Some(dev) => dev.with_nix_path(|path| ffi::quotactl(cmd.as_int(), path.as_ptr(), id, addr)),
- None => Ok(ffi::quotactl(cmd.as_int(), ptr::null(), id, addr)),
- }
- );
- from_ffi(res)
- }
+ unsafe {
+ Errno::clear();
+ let res = try!(
+ match special {
+ Some(dev) => dev.with_nix_path(|path| ffi::quotactl(cmd.as_int(), path.as_ptr(), id, addr)),
+ None => Ok(ffi::quotactl(cmd.as_int(), ptr::null(), id, addr)),
+ }
+ );
+ from_ffi(res)
+ }
}
pub fn quotactl_on<P: ?Sized + NixPath>(which: quota::QuotaType, special: &P, format: quota::QuotaFmt, quota_file: &P) -> Result<()> {
- try!(quota_file.with_nix_path(|path| {
- let mut path_copy = path.to_bytes_with_nul().to_owned();
- let p: *mut c_char = path_copy.as_mut_ptr() as *mut c_char;
- quotactl(quota::QuotaCmd(quota::Q_QUOTAON, which), Some(special), format as c_int, p)
- }))
+ try!(quota_file.with_nix_path(|path| {
+ let mut path_copy = path.to_bytes_with_nul().to_owned();
+ let p: *mut c_char = path_copy.as_mut_ptr() as *mut c_char;
+ quotactl(quota::QuotaCmd(quota::Q_QUOTAON, which), Some(special), format as c_int, p)
+ }))
}
pub fn quotactl_off<P: ?Sized + NixPath>(which: quota::QuotaType, special: &P) -> Result<()> {
- quotactl(quota::QuotaCmd(quota::Q_QUOTAOFF, which), Some(special), 0, ptr::null_mut())
+ quotactl(quota::QuotaCmd(quota::Q_QUOTAOFF, which), Some(special), 0, ptr::null_mut())
}
pub fn quotactl_sync<P: ?Sized + NixPath>(which: quota::QuotaType, special: Option<&P>) -> Result<()> {
- quotactl(quota::QuotaCmd(quota::Q_SYNC, which), special, 0, ptr::null_mut())
+ quotactl(quota::QuotaCmd(quota::Q_SYNC, which), special, 0, ptr::null_mut())
}
pub fn quotactl_get<P: ?Sized + NixPath>(which: quota::QuotaType, special: &P, id: c_int, dqblk: &mut quota::Dqblk) -> Result<()> {
- use std::mem;
- unsafe {
- quotactl(quota::QuotaCmd(quota::Q_GETQUOTA, which), Some(special), id, mem::transmute(dqblk))
- }
+ use std::mem;
+ unsafe {
+ quotactl(quota::QuotaCmd(quota::Q_GETQUOTA, which), Some(special), id, mem::transmute(dqblk))
+ }
}
pub fn quotactl_set<P: ?Sized + NixPath>(which: quota::QuotaType, special: &P, id: c_int, dqblk: &quota::Dqblk) -> Result<()> {
- use std::mem;
- let mut dqblk_copy = *dqblk;
- unsafe {
- quotactl(quota::QuotaCmd(quota::Q_SETQUOTA, which), Some(special), id, mem::transmute(&mut dqblk_copy))
- }
+ use std::mem;
+ let mut dqblk_copy = *dqblk;
+ unsafe {
+ quotactl(quota::QuotaCmd(quota::Q_SETQUOTA, which), Some(special), id, mem::transmute(&mut dqblk_copy))
+ }
}
diff --git a/src/sys/statfs.rs b/src/sys/statfs.rs
index 6c4c10e1..bd4233c8 100644
--- a/src/sys/statfs.rs
+++ b/src/sys/statfs.rs
@@ -3,114 +3,114 @@ use errno::Errno;
use std::os::unix::io::AsRawFd;
pub mod vfs {
- #[cfg(target_pointer_width = "32")]
+ #[cfg(target_pointer_width = "32")]
pub mod hwdep {
- use libc::{c_uint};
- pub type FsType = c_uint;
- pub type BlockSize = c_uint;
- pub type NameLen = c_uint;
- pub type FragmentSize = c_uint;
- pub type SwordType = c_uint;
- }
+ use libc::{c_uint};
+ pub type FsType = c_uint;
+ pub type BlockSize = c_uint;
+ pub type NameLen = c_uint;
+ pub type FragmentSize = c_uint;
+ pub type SwordType = c_uint;
+ }
- #[cfg(target_pointer_width = "64")]
- pub mod hwdep {
- use libc::{c_long};
- pub type FsType = c_long;
- pub type BlockSize = c_long;
- pub type NameLen = c_long;
- pub type FragmentSize = c_long;
- pub type SwordType = c_long;
- }
+ #[cfg(target_pointer_width = "64")]
+ pub mod hwdep {
+ use libc::{c_long};
+ pub type FsType = c_long;
+ pub type BlockSize = c_long;
+ pub type NameLen = c_long;
+ pub type FragmentSize = c_long;
+ pub type SwordType = c_long;
+ }
- use sys::statfs::vfs::hwdep::*;
+ 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;
- pub const BFS_MAGIC : FsType = 0x1BADFACE;
- pub const CIFS_MAGIC_NUMBER : FsType = 0xFF534D42;
- pub const CODA_SUPER_MAGIC : FsType = 0x73757245;
- pub const COH_SUPER_MAGIC : FsType = 0x012FF7B7;
- pub const CRAMFS_MAGIC : FsType = 0x28cd3d45;
- pub const DEVFS_SUPER_MAGIC : FsType = 0x1373;
- pub const EFS_SUPER_MAGIC : FsType = 0x00414A53;
- pub const EXT_SUPER_MAGIC : FsType = 0x137D;
- pub const EXT2_OLD_SUPER_MAGIC : FsType = 0xEF51;
- pub const EXT2_SUPER_MAGIC : FsType = 0xEF53;
- pub const EXT3_SUPER_MAGIC : FsType = 0xEF53;
- pub const EXT4_SUPER_MAGIC : FsType = 0xEF53;
- pub const HFS_SUPER_MAGIC : FsType = 0x4244;
- pub const HPFS_SUPER_MAGIC : FsType = 0xF995E849;
- pub const HUGETLBFS_MAGIC : FsType = 0x958458f6;
- pub const ISOFS_SUPER_MAGIC : FsType = 0x9660;
- pub const JFFS2_SUPER_MAGIC : FsType = 0x72b6;
- pub const JFS_SUPER_MAGIC : FsType = 0x3153464a;
- pub const MINIX_SUPER_MAGIC : FsType = 0x137F; /* orig. minix */
- pub const MINIX_SUPER_MAGIC2 : FsType = 0x138F; /* 30 char minix */
- pub const MINIX2_SUPER_MAGIC : FsType = 0x2468; /* minix V2 */
- pub const MINIX2_SUPER_MAGIC2 : FsType = 0x2478; /* minix V2, 30 char names */
- pub const MSDOS_SUPER_MAGIC : FsType = 0x4d44;
- pub const NCP_SUPER_MAGIC : FsType = 0x564c;
- pub const NFS_SUPER_MAGIC : FsType = 0x6969;
- pub const NTFS_SB_MAGIC : FsType = 0x5346544e;
- pub const OPENPROM_SUPER_MAGIC : FsType = 0x9fa1;
- pub const PROC_SUPER_MAGIC : FsType = 0x9fa0;
- pub const QNX4_SUPER_MAGIC : FsType = 0x002f;
- pub const REISERFS_SUPER_MAGIC : FsType = 0x52654973;
- pub const ROMFS_MAGIC : FsType = 0x7275;
- pub const SMB_SUPER_MAGIC : FsType = 0x517B;
- pub const SYSV2_SUPER_MAGIC : FsType = 0x012FF7B6;
- pub const SYSV4_SUPER_MAGIC : FsType = 0x012FF7B5;
- pub const TMPFS_MAGIC : FsType = 0x01021994;
- pub const UDF_SUPER_MAGIC : FsType = 0x15013346;
- pub const UFS_MAGIC : FsType = 0x00011954;
- pub const USBDEVICE_SUPER_MAGIC : FsType = 0x9fa2;
- pub const VXFS_SUPER_MAGIC : FsType = 0xa501FCF5;
- pub const XENIX_SUPER_MAGIC : FsType = 0x012FF7B4;
- pub const XFS_SUPER_MAGIC : FsType = 0x58465342;
- pub const _XIAFS_SUPER_MAGIC : FsType = 0x012FD16D;
+ #[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;
+ pub const BFS_MAGIC : FsType = 0x1BADFACE;
+ pub const CIFS_MAGIC_NUMBER : FsType = 0xFF534D42;
+ pub const CODA_SUPER_MAGIC : FsType = 0x73757245;
+ pub const COH_SUPER_MAGIC : FsType = 0x012FF7B7;
+ pub const CRAMFS_MAGIC : FsType = 0x28cd3d45;
+ pub const DEVFS_SUPER_MAGIC : FsType = 0x1373;
+ pub const EFS_SUPER_MAGIC : FsType = 0x00414A53;
+ pub const EXT_SUPER_MAGIC : FsType = 0x137D;
+ pub const EXT2_OLD_SUPER_MAGIC : FsType = 0xEF51;
+ pub const EXT2_SUPER_MAGIC : FsType = 0xEF53;
+ pub const EXT3_SUPER_MAGIC : FsType = 0xEF53;
+ pub const EXT4_SUPER_MAGIC : FsType = 0xEF53;
+ pub const HFS_SUPER_MAGIC : FsType = 0x4244;
+ pub const HPFS_SUPER_MAGIC : FsType = 0xF995E849;
+ pub const HUGETLBFS_MAGIC : FsType = 0x958458f6;
+ pub const ISOFS_SUPER_MAGIC : FsType = 0x9660;
+ pub const JFFS2_SUPER_MAGIC : FsType = 0x72b6;
+ pub const JFS_SUPER_MAGIC : FsType = 0x3153464a;
+ pub const MINIX_SUPER_MAGIC : FsType = 0x137F; /* orig. minix */
+ pub const MINIX_SUPER_MAGIC2 : FsType = 0x138F; /* 30 char minix */
+ pub const MINIX2_SUPER_MAGIC : FsType = 0x2468; /* minix V2 */
+ pub const MINIX2_SUPER_MAGIC2 : FsType = 0x2478; /* minix V2, 30 char names */
+ pub const MSDOS_SUPER_MAGIC : FsType = 0x4d44;
+ pub const NCP_SUPER_MAGIC : FsType = 0x564c;
+ pub const NFS_SUPER_MAGIC : FsType = 0x6969;
+ pub const NTFS_SB_MAGIC : FsType = 0x5346544e;
+ pub const OPENPROM_SUPER_MAGIC : FsType = 0x9fa1;
+ pub const PROC_SUPER_MAGIC : FsType = 0x9fa0;
+ pub const QNX4_SUPER_MAGIC : FsType = 0x002f;
+ pub const REISERFS_SUPER_MAGIC : FsType = 0x52654973;
+ pub const ROMFS_MAGIC : FsType = 0x7275;
+ pub const SMB_SUPER_MAGIC : FsType = 0x517B;
+ pub const SYSV2_SUPER_MAGIC : FsType = 0x012FF7B6;
+ pub const SYSV4_SUPER_MAGIC : FsType = 0x012FF7B5;
+ pub const TMPFS_MAGIC : FsType = 0x01021994;
+ pub const UDF_SUPER_MAGIC : FsType = 0x15013346;
+ pub const UFS_MAGIC : FsType = 0x00011954;
+ pub const USBDEVICE_SUPER_MAGIC : FsType = 0x9fa2;
+ pub const VXFS_SUPER_MAGIC : FsType = 0xa501FCF5;
+ pub const XENIX_SUPER_MAGIC : FsType = 0x012FF7B4;
+ pub const XFS_SUPER_MAGIC : FsType = 0x58465342;
+ pub const _XIAFS_SUPER_MAGIC : FsType = 0x012FD16D;
}
mod ffi {
- use libc::{c_int,c_char};
- use sys::statfs::vfs;
+ 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;
- }
+ 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<()> {
- unsafe {
- Errno::clear();
- let res = try!(
- path.with_nix_path(|path| ffi::statfs(path.as_ptr(), stat))
- );
- from_ffi(res)
- }
+ unsafe {
+ Errno::clear();
+ let res = try!(
+ path.with_nix_path(|path| ffi::statfs(path.as_ptr(), stat))
+ );
+ from_ffi(res)
+ }
}
pub fn fstatfs<T: AsRawFd>(fd: &T, stat: &mut vfs::Statfs) -> Result<()> {
- unsafe {
- Errno::clear();
- from_ffi(ffi::fstatfs(fd.as_raw_fd(), stat))
- }
+ unsafe {
+ Errno::clear();
+ from_ffi(ffi::fstatfs(fd.as_raw_fd(), stat))
+ }
}
diff --git a/src/sys/statvfs.rs b/src/sys/statvfs.rs
index 1459384d..0d996afe 100644
--- a/src/sys/statvfs.rs
+++ b/src/sys/statvfs.rs
@@ -7,156 +7,156 @@ use errno::Errno;
use std::os::unix::io::AsRawFd;
pub mod vfs {
- //! Structs related to the `statvfs` and `fstatvfs` functions
- //!
- //! The `Statvfs` struct has some wrappers methods around the `statvfs` and
- //! `fstatvfs` calls.
-
- use libc::{c_ulong,c_int};
- use std::os::unix::io::AsRawFd;
- use {Result, NixPath};
-
- use super::{statvfs, fstatvfs};
-
- bitflags!(
- /// Mount Flags
- #[repr(C)]
- #[derive(Default)]
- flags FsFlags: c_ulong {
- /// Read Only
- const RDONLY = 1,
- /// Do not allow the set-uid bits to have an effect
- const NOSUID = 2,
- /// Do not interpret character or block-special devices
- const NODEV = 4,
- /// Do not allow execution of binaries on the filesystem
- const NOEXEC = 8,
- /// All IO should be done synchronously
- const SYNCHRONOUS = 16,
- /// Allow mandatory locks on the filesystem
- const MANDLOCK = 64,
- const WRITE = 128,
- const APPEND = 256,
- const IMMUTABLE = 512,
- /// Do not update access times on files
- const NOATIME = 1024,
- /// Do not update access times on files
- const NODIRATIME = 2048,
- /// Update access time relative to modify/change time
- const RELATIME = 4096,
- }
- );
-
- /// The posix statvfs struct
- ///
- /// http://linux.die.net/man/2/statvfs
- #[repr(C)]
- #[derive(Debug,Copy,Clone)]
- pub struct Statvfs {
- /// Filesystem block size. This is the value that will lead to
- /// most efficient use of the filesystem
- pub f_bsize: c_ulong,
- /// Fragment Size -- actual minimum unit of allocation on this
- /// filesystem
- pub f_frsize: c_ulong,
- /// Total number of blocks on the filesystem
- pub f_blocks: u64,
- /// Number of unused blocks on the filesystem, including those
- /// reserved for root
- pub f_bfree: u64,
- /// Number of blocks available to non-root users
- pub f_bavail: u64,
- /// Total number of inodes available on the filesystem
- pub f_files: u64,
- /// Number of inodes available on the filesystem
- pub f_ffree: u64,
- /// Number of inodes available to non-root users
- pub f_favail: u64,
- /// File System ID
- pub f_fsid: c_ulong,
- /// Mount Flags
- pub f_flag: FsFlags,
- /// Maximum filename length
- pub f_namemax: c_ulong,
- /// Reserved extra space, OS-dependent
- f_spare: [c_int; 6],
- }
-
- impl Statvfs {
- /// Create a new `Statvfs` object and fill it with information about
- /// the mount that contains `path`
- pub fn for_path<P: ?Sized + NixPath>(path: &P) -> Result<Statvfs> {
- let mut stat = Statvfs::default();
- let res = statvfs(path, &mut stat);
- res.map(|_| stat)
- }
-
- /// Replace information in this struct with information about `path`
- pub fn update_with_path<P: ?Sized + NixPath>(&mut self, path: &P) -> Result<()> {
- statvfs(path, self)
- }
-
- /// Create a new `Statvfs` object and fill it with information from fd
- pub fn for_fd<T: AsRawFd>(fd: &T) -> Result<Statvfs> {
- let mut stat = Statvfs::default();
- let res = fstatvfs(fd, &mut stat);
- res.map(|_| stat)
- }
-
- /// Replace information in this struct with information about `fd`
- pub fn update_with_fd<T: AsRawFd>(&mut self, fd: &T) -> Result<()> {
- fstatvfs(fd, self)
- }
- }
-
- impl Default for Statvfs {
- /// Create a statvfs object initialized to all zeros
- fn default() -> Self {
- Statvfs {
- f_bsize: 0,
- f_frsize: 0,
- f_blocks: 0,
- f_bfree: 0,
- f_bavail: 0,
- f_files: 0,
- f_ffree: 0,
- f_favail: 0,
- f_fsid: 0,
- f_flag: FsFlags::default(),
- f_namemax: 0,
- f_spare: [0, 0, 0, 0, 0, 0],
- }
- }
- }
+ //! Structs related to the `statvfs` and `fstatvfs` functions
+ //!
+ //! The `Statvfs` struct has some wrappers methods around the `statvfs` and
+ //! `fstatvfs` calls.
+
+ use libc::{c_ulong,c_int};
+ use std::os::unix::io::AsRawFd;
+ use {Result, NixPath};
+
+ use super::{statvfs, fstatvfs};
+
+ bitflags!(
+ /// Mount Flags
+ #[repr(C)]
+ #[derive(Default)]
+ flags FsFlags: c_ulong {
+ /// Read Only
+ const RDONLY = 1,
+ /// Do not allow the set-uid bits to have an effect
+ const NOSUID = 2,
+ /// Do not interpret character or block-special devices
+ const NODEV = 4,
+ /// Do not allow execution of binaries on the filesystem
+ const NOEXEC = 8,
+ /// All IO should be done synchronously
+ const SYNCHRONOUS = 16,
+ /// Allow mandatory locks on the filesystem
+ const MANDLOCK = 64,
+ const WRITE = 128,
+ const APPEND = 256,
+ const IMMUTABLE = 512,
+ /// Do not update access times on files
+ const NOATIME = 1024,
+ /// Do not update access times on files
+ const NODIRATIME = 2048,
+ /// Update access time relative to modify/change time
+ const RELATIME = 4096,
+ }
+ );
+
+ /// The posix statvfs struct
+ ///
+ /// http://linux.die.net/man/2/statvfs
+ #[repr(C)]
+ #[derive(Debug,Copy,Clone)]
+ pub struct Statvfs {
+ /// Filesystem block size. This is the value that will lead to
+ /// most efficient use of the filesystem
+ pub f_bsize: c_ulong,
+ /// Fragment Size -- actual minimum unit of allocation on this
+ /// filesystem
+ pub f_frsize: c_ulong,
+ /// Total number of blocks on the filesystem
+ pub f_blocks: u64,
+ /// Number of unused blocks on the filesystem, including those
+ /// reserved for root
+ pub f_bfree: u64,
+ /// Number of blocks available to non-root users
+ pub f_bavail: u64,
+ /// Total number of inodes available on the filesystem
+ pub f_files: u64,
+ /// Number of inodes available on the filesystem
+ pub f_ffree: u64,
+ /// Number of inodes available to non-root users
+ pub f_favail: u64,
+ /// File System ID
+ pub f_fsid: c_ulong,
+ /// Mount Flags
+ pub f_flag: FsFlags,
+ /// Maximum filename length
+ pub f_namemax: c_ulong,
+ /// Reserved extra space, OS-dependent
+ f_spare: [c_int; 6],
+ }
+
+ impl Statvfs {
+ /// Create a new `Statvfs` object and fill it with information about
+ /// the mount that contains `path`
+ pub fn for_path<P: ?Sized + NixPath>(path: &P) -> Result<Statvfs> {
+ let mut stat = Statvfs::default();
+ let res = statvfs(path, &mut stat);
+ res.map(|_| stat)
+ }
+
+ /// Replace information in this struct with information about `path`
+ pub fn update_with_path<P: ?Sized + NixPath>(&mut self, path: &P) -> Result<()> {
+ statvfs(path, self)
+ }
+
+ /// Create a new `Statvfs` object and fill it with information from fd
+ pub fn for_fd<T: AsRawFd>(fd: &T) -> Result<Statvfs> {
+ let mut stat = Statvfs::default();
+ let res = fstatvfs(fd, &mut stat);
+ res.map(|_| stat)
+ }
+
+ /// Replace information in this struct with information about `fd`
+ pub fn update_with_fd<T: AsRawFd>(&mut self, fd: &T) -> Result<()> {
+ fstatvfs(fd, self)
+ }
+ }
+
+ impl Default for Statvfs {
+ /// Create a statvfs object initialized to all zeros
+ fn default() -> Self {
+ Statvfs {
+ f_bsize: 0,
+ f_frsize: 0,
+ f_blocks: 0,
+ f_bfree: 0,
+ f_bavail: 0,
+ f_files: 0,
+ f_ffree: 0,
+ f_favail: 0,
+ f_fsid: 0,
+ f_flag: FsFlags::default(),
+ f_namemax: 0,
+ f_spare: [0, 0, 0, 0, 0, 0],
+ }
+ }
+ }
}
mod ffi {
- use libc::{c_char, c_int};
- use sys::statvfs::vfs;
+ 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;
- }
+ 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;
+ }
}
/// Fill an existing `Statvfs` object with information about the `path`
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)
- }
+ unsafe {
+ Errno::clear();
+ let res = try!(
+ path.with_nix_path(|path| ffi::statvfs(path.as_ptr(), stat))
+ );
+ from_ffi(res)
+ }
}
/// Fill an existing `Statvfs` object with information about `fd`
pub fn fstatvfs<T: AsRawFd>(fd: &T, stat: &mut vfs::Statvfs) -> Result<()> {
- unsafe {
- Errno::clear();
- from_ffi(ffi::fstatvfs(fd.as_raw_fd(), stat))
- }
+ unsafe {
+ Errno::clear();
+ from_ffi(ffi::fstatvfs(fd.as_raw_fd(), stat))
+ }
}
#[cfg(test)]