diff --git a/libc-test/build.rs b/libc-test/build.rs index f1b1bd470ddb15cf52e495c4b4c580e5707ec7eb..508a3c82e15170ac384eb5b83e5fdcf053b97840 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 ad8fcf2d0ee8c194f99804feb84612b19187cf95..c80986690a7228a5f1f8b65b751022a125706371 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 376fce65fbdd30d6695cb7ca6903c564ab56814e..5f1092048b5b1d858528c6cb5ce971b881b5d37f 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 76f1ee766aeb2ad031a14810dccb76cff79d91c4..91d20320db0678c62bf0cb90fb73355986a19f6d 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 ea4b99ce6fccd7610e98b52f25caa13d908094a0..1582860dbb00ca3cb470a6e3d83b670cfa073103 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 f1e4ffa607a28c2d6c808f46f84239646c28f2a7..488313fd893a01fd870ce8b721258743db9e275b 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 478f5de27493fc0249cc0e17eaad5d70e9553282..e48be8bc968503471915ebcc2f528e1ec3f4554d 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 65dea9db6ab00094c7148903fe0a5f38c7375549..5f23d80f14ef302b74fa021412227bfc0d394f30 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,