diff options
author | Alex Crichton <alex@alexcrichton.com> | 2015-11-04 23:06:44 -0800 |
---|---|---|
committer | Alex Crichton <alex@alexcrichton.com> | 2015-11-04 23:06:44 -0800 |
commit | e4bb63a9b2c45ce30d979b8328762aa386ec4e31 (patch) | |
tree | 1736f0c5f7665b53a3b9e07cb5ec7b5ef1f48385 | |
parent | c003614b61137decde6d7b7f7a4a8db151a11570 (diff) | |
parent | fe3968fb8f2674a83caa66d8f0efc4c6be2e00e0 (diff) | |
download | rust-libc-e4bb63a9b2c45ce30d979b8328762aa386ec4e31.tar.gz |
Merge pull request #38 from danburkert/fs
bind additional filesystem APIs
-rw-r--r-- | libc-test/build.rs | 1 | ||||
-rw-r--r-- | src/unix/bsd/apple/mod.rs | 47 | ||||
-rw-r--r-- | src/unix/bsd/freebsdlike/mod.rs | 16 | ||||
-rw-r--r-- | src/unix/bsd/mod.rs | 5 | ||||
-rw-r--r-- | src/unix/bsd/openbsdlike/mod.rs | 14 | ||||
-rw-r--r-- | src/unix/mod.rs | 2 | ||||
-rw-r--r-- | src/unix/notbsd/linux/mod.rs | 37 | ||||
-rw-r--r-- | src/unix/notbsd/linux/notmips/mod.rs | 3 | ||||
-rw-r--r-- | src/unix/notbsd/linux/notmusl.rs | 1 |
9 files changed, 123 insertions, 3 deletions
diff --git a/libc-test/build.rs b/libc-test/build.rs index f1b1bd470d..508a3c82e1 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 b7cf3b176c..c80986690a 100644 --- a/src/unix/bsd/apple/mod.rs +++ b/src/unix/bsd/apple/mod.rs @@ -134,6 +134,33 @@ s! { pub ss_size: ::size_t, pub ss_flags: ::c_int, } + + pub struct fstore_t { + pub fst_flags: ::c_uint, + pub fst_posmode: ::c_int, + pub fst_offset: ::off_t, + pub fst_length: ::off_t, + pub fst_bytesalloc: ::off_t, + } + + pub struct radvisory { + 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; @@ -196,7 +223,6 @@ pub const F_LOCK: ::c_int = 1; pub const F_TEST: ::c_int = 3; pub const F_TLOCK: ::c_int = 2; pub const F_ULOCK: ::c_int = 0; -pub const F_DUPFD_CLOEXEC: ::c_int = 67; pub const SIGHUP: ::c_int = 1; pub const SIGINT: ::c_int = 2; pub const SIGQUIT: ::c_int = 3; @@ -342,10 +368,27 @@ pub const EQFULL: ::c_int = 106; pub const ELAST: ::c_int = 106; pub const F_DUPFD: ::c_int = 0; +pub const F_DUPFD_CLOEXEC: ::c_int = 67; pub const F_GETFD: ::c_int = 1; pub const F_SETFD: ::c_int = 2; pub const F_GETFL: ::c_int = 3; pub const F_SETFL: ::c_int = 4; +pub const F_PREALLOCATE: ::c_int = 42; +pub const F_RDADVISE: ::c_int = 44; +pub const F_RDAHEAD: ::c_int = 45; +pub const F_NOCACHE: ::c_int = 48; +pub const F_GETPATH: ::c_int = 50; +pub const F_FULLFSYNC: ::c_int = 51; +pub const F_FREEZE_FS: ::c_int = 53; +pub const F_THAW_FS: ::c_int = 54; +pub const F_GLOBAL_NOCACHE: ::c_int = 55; +pub const F_NODIRECT: ::c_int = 62; + +pub const F_ALLOCATECONTIG: ::c_uint = 0x02; +pub const F_ALLOCATEALL: ::c_uint = 0x04; + +pub const F_PEOFPOSMODE: ::c_int = 3; +pub const F_VOLPOSMODE: ::c_int = 4; pub const O_ACCMODE: ::c_int = 3; @@ -491,8 +534,6 @@ pub const LOCK_UN: ::c_int = 8; pub const O_DSYNC: ::c_int = 4194304; pub const O_SYNC: ::c_int = 128; pub const O_NONBLOCK: ::c_int = 4; -pub const F_GETPATH: ::c_int = 50; -pub const F_FULLFSYNC: ::c_int = 51; pub const MAP_COPY: ::c_int = 0x0002; pub const MAP_RENAME: ::c_int = 0x0020; diff --git a/src/unix/bsd/freebsdlike/mod.rs b/src/unix/bsd/freebsdlike/mod.rs index 14d9f55a65..5f1092048b 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; @@ -520,6 +534,8 @@ extern { -> ::c_int; pub fn clock_gettime(clk_id: ::c_int, tp: *mut ::timespec) -> ::c_int; pub fn pthread_set_name_np(tid: ::pthread_t, name: *const ::c_char); + pub fn posix_fallocate(fd: ::c_int, offset: ::off_t, + len: ::off_t) -> ::c_int; } cfg_if! { diff --git a/src/unix/bsd/mod.rs b/src/unix/bsd/mod.rs index 76f1ee766a..91d20320db 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 ea4b99ce6f..1582860dbb 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 f1e4ffa607..488313fd89 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 4c45991b0a..62e2262113 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; @@ -281,6 +312,12 @@ extern { offset: ::off64_t, whence: ::c_int) -> ::c_int; pub fn ftello64(stream: *mut ::FILE) -> ::off64_t; + pub fn fallocate(fd: ::c_int, mode: ::c_int, + offset: ::off_t, len: ::off_t) -> ::c_int; + pub fn posix_fallocate(fd: ::c_int, offset: ::off_t, + len: ::off_t) -> ::c_int; + pub fn readahead(fd: ::c_int, offset: ::off64_t, + count: ::size_t) -> ::ssize_t; } cfg_if! { diff --git a/src/unix/notbsd/linux/notmips/mod.rs b/src/unix/notbsd/linux/notmips/mod.rs index f974a56387..79c8d5617e 100644 --- a/src/unix/notbsd/linux/notmips/mod.rs +++ b/src/unix/notbsd/linux/notmips/mod.rs @@ -179,6 +179,9 @@ pub const SIGCHLD: ::c_int = 17; pub const SIGBUS: ::c_int = 7; pub const SIG_SETMASK: ::c_int = 2; +pub const FALLOC_FL_KEEP_SIZE: ::c_int = 0x01; +pub const FALLOC_FL_PUNCH_HOLE: ::c_int = 0x02; + extern { pub fn getnameinfo(sa: *const ::sockaddr, salen: ::socklen_t, diff --git a/src/unix/notbsd/linux/notmusl.rs b/src/unix/notbsd/linux/notmusl.rs index 65dea9db6a..5f23d80f14 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, |