From 85a76f8eb2fefe68c1f3d0292cb5d08f03aaf60c Mon Sep 17 00:00:00 2001 From: Dan Burkert <dan@danburkert.com> Date: Wed, 4 Nov 2015 20:26:27 -0800 Subject: [PATCH] statvfs(3) bindings --- libc-test/build.rs | 1 + src/unix/bsd/apple/mod.rs | 14 ++++++++++++++ src/unix/bsd/freebsdlike/mod.rs | 14 ++++++++++++++ src/unix/bsd/mod.rs | 5 +++++ src/unix/bsd/openbsdlike/mod.rs | 14 ++++++++++++++ src/unix/mod.rs | 2 ++ src/unix/notbsd/linux/mod.rs | 31 +++++++++++++++++++++++++++++++ src/unix/notbsd/linux/notmusl.rs | 1 + 8 files changed, 82 insertions(+) diff --git a/libc-test/build.rs b/libc-test/build.rs index f1b1bd47..508a3c82 100644 --- a/libc-test/build.rs +++ b/libc-test/build.rs @@ -86,6 +86,7 @@ fn main() { } else if !windows { cfg.header("glob.h"); cfg.header("ifaddrs.h"); + cfg.header("sys/statvfs.h"); if !musl { cfg.header("execinfo.h"); diff --git a/src/unix/bsd/apple/mod.rs b/src/unix/bsd/apple/mod.rs index ad8fcf2d..c8098669 100644 --- a/src/unix/bsd/apple/mod.rs +++ b/src/unix/bsd/apple/mod.rs @@ -147,6 +147,20 @@ s! { pub ra_offset: ::off_t, pub ra_count: ::c_int, } + + pub struct statvfs { + pub f_bsize: ::c_ulong, + pub f_frsize: ::c_ulong, + pub f_blocks: ::fsblkcnt_t, + pub f_bfree: ::fsblkcnt_t, + pub f_bavail: ::fsblkcnt_t, + pub f_files: ::fsfilcnt_t, + pub f_ffree: ::fsfilcnt_t, + pub f_favail: ::fsfilcnt_t, + pub f_fsid: ::c_ulong, + pub f_flag: ::c_ulong, + pub f_namemax: ::c_ulong, + } } pub const EXIT_FAILURE: ::c_int = 1; diff --git a/src/unix/bsd/freebsdlike/mod.rs b/src/unix/bsd/freebsdlike/mod.rs index 376fce65..5f109204 100644 --- a/src/unix/bsd/freebsdlike/mod.rs +++ b/src/unix/bsd/freebsdlike/mod.rs @@ -85,6 +85,20 @@ s! { pub ss_size: ::size_t, pub ss_flags: ::c_int, } + + pub struct statvfs { + pub f_bavail: ::fsblkcnt_t, + pub f_bfree: ::fsblkcnt_t, + pub f_blocks: ::fsblkcnt_t, + pub f_favail: ::fsfilcnt_t, + pub f_ffree: ::fsfilcnt_t, + pub f_files: ::fsfilcnt_t, + pub f_bsize: ::c_ulong, + pub f_flag: ::c_ulong, + pub f_frsize: ::c_ulong, + pub f_fsid: ::c_ulong, + pub f_namemax: ::c_ulong, + } } pub const EXIT_FAILURE: ::c_int = 1; diff --git a/src/unix/bsd/mod.rs b/src/unix/bsd/mod.rs index 76f1ee76..91d20320 100644 --- a/src/unix/bsd/mod.rs +++ b/src/unix/bsd/mod.rs @@ -6,6 +6,8 @@ pub type blkcnt_t = i64; pub type socklen_t = u32; pub type sa_family_t = u8; pub type pthread_t = ::uintptr_t; +pub type fsblkcnt_t = ::c_uint; +pub type fsfilcnt_t = ::c_uint; s! { pub struct sockaddr { @@ -102,6 +104,9 @@ pub const IPV6_V6ONLY: ::c_int = 27; pub const FD_SETSIZE: usize = 1024; +pub const ST_RDONLY: ::c_ulong = 1; +pub const ST_NOSUID: ::c_ulong = 2; + f! { pub fn FD_CLR(fd: ::c_int, set: *mut fd_set) -> () { let fd = fd as usize; diff --git a/src/unix/bsd/openbsdlike/mod.rs b/src/unix/bsd/openbsdlike/mod.rs index ea4b99ce..1582860d 100644 --- a/src/unix/bsd/openbsdlike/mod.rs +++ b/src/unix/bsd/openbsdlike/mod.rs @@ -92,6 +92,20 @@ s! { pub st_birthtime: ::time_t, pub st_birthtime_nsec: ::c_long, } + + pub struct statvfs { + pub f_bsize: ::c_ulong, + pub f_frsize: ::c_ulong, + pub f_blocks: ::fsblkcnt_t, + pub f_bfree: ::fsblkcnt_t, + pub f_bavail: ::fsblkcnt_t, + pub f_files: ::fsfilcnt_t, + pub f_ffree: ::fsfilcnt_t, + pub f_favail: ::fsfilcnt_t, + pub f_fsid: ::c_ulong, + pub f_flag: ::c_ulong, + pub f_namemax: ::c_ulong, + } } pub const EXIT_FAILURE : ::c_int = 1; diff --git a/src/unix/mod.rs b/src/unix/mod.rs index f1e4ffa6..488313fd 100644 --- a/src/unix/mod.rs +++ b/src/unix/mod.rs @@ -558,6 +558,8 @@ extern { whence: ::c_int) -> ::c_int; pub fn ftello(stream: *mut ::FILE) -> ::off_t; pub fn timegm(tm: *mut ::tm) -> time_t; + pub fn statvfs(path: *const c_char, buf: *mut statvfs) -> ::c_int; + pub fn fstatvfs(fd: ::c_int, buf: *mut statvfs) -> ::c_int; } cfg_if! { diff --git a/src/unix/notbsd/linux/mod.rs b/src/unix/notbsd/linux/mod.rs index 478f5de2..e48be8bc 100644 --- a/src/unix/notbsd/linux/mod.rs +++ b/src/unix/notbsd/linux/mod.rs @@ -9,6 +9,8 @@ pub type ino64_t = u64; pub type off64_t = i64; pub type blkcnt64_t = i64; pub type rlim64_t = u64; +pub type fsblkcnt_t = ::c_ulong; +pub type fsfilcnt_t = ::c_ulong; pub enum fpos64_t {} // TODO: fill this out with a struct @@ -99,6 +101,23 @@ s! { pub pw_dir: *mut ::c_char, pub pw_shell: *mut ::c_char, } + + pub struct statvfs { + pub f_bsize: ::c_ulong, + pub f_frsize: ::c_ulong, + pub f_blocks: ::fsblkcnt_t, + pub f_bfree: ::fsblkcnt_t, + pub f_bavail: ::fsblkcnt_t, + pub f_files: ::fsfilcnt_t, + pub f_ffree: ::fsfilcnt_t, + pub f_favail: ::fsfilcnt_t, + pub f_fsid: ::c_ulong, + #[cfg(target_pointer_width = "32")] + pub __f_unused: ::c_int, + pub f_flag: ::c_ulong, + pub f_namemax: ::c_ulong, + __f_spare: [::c_int; 6], + } } pub const FILENAME_MAX: ::c_uint = 4096; @@ -218,6 +237,18 @@ pub const F_TEST: ::c_int = 3; pub const F_TLOCK: ::c_int = 2; pub const F_ULOCK: ::c_int = 0; +pub const ST_RDONLY: ::c_ulong = 1; +pub const ST_NOSUID: ::c_ulong = 2; +pub const ST_NODEV: ::c_ulong = 4; +pub const ST_NOEXEC: ::c_ulong = 8; +pub const ST_SYNCHRONOUS: ::c_ulong = 16; +pub const ST_MANDLOCK: ::c_ulong = 64; +pub const ST_WRITE: ::c_ulong = 128; +pub const ST_APPEND: ::c_ulong = 256; +pub const ST_IMMUTABLE: ::c_ulong = 512; +pub const ST_NOATIME: ::c_ulong = 1024; +pub const ST_NODIRATIME: ::c_ulong = 2048; + #[cfg(any(target_arch = "x86", target_arch = "x86_64"))] pub const MAP_32BIT: ::c_int = 0x0040; diff --git a/src/unix/notbsd/linux/notmusl.rs b/src/unix/notbsd/linux/notmusl.rs index 65dea9db..5f23d80f 100644 --- a/src/unix/notbsd/linux/notmusl.rs +++ b/src/unix/notbsd/linux/notmusl.rs @@ -21,6 +21,7 @@ pub const _SC_2_C_VERSION: ::c_int = 96; pub const RUSAGE_THREAD: ::c_int = 1; pub const O_ACCMODE: ::c_int = 3; pub const RUSAGE_CHILDREN: ::c_int = -1; +pub const ST_RELATIME: ::c_ulong = 4096; extern { pub fn sysctl(name: *mut ::c_int, -- GitLab