Skip to content

Commit 85a76f8

Browse files
committed
statvfs(3) bindings
1 parent 2ce4377 commit 85a76f8

File tree

8 files changed

+82
-0
lines changed

8 files changed

+82
-0
lines changed

libc-test/build.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ fn main() {
8686
} else if !windows {
8787
cfg.header("glob.h");
8888
cfg.header("ifaddrs.h");
89+
cfg.header("sys/statvfs.h");
8990

9091
if !musl {
9192
cfg.header("execinfo.h");

src/unix/bsd/apple/mod.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,20 @@ s! {
147147
pub ra_offset: ::off_t,
148148
pub ra_count: ::c_int,
149149
}
150+
151+
pub struct statvfs {
152+
pub f_bsize: ::c_ulong,
153+
pub f_frsize: ::c_ulong,
154+
pub f_blocks: ::fsblkcnt_t,
155+
pub f_bfree: ::fsblkcnt_t,
156+
pub f_bavail: ::fsblkcnt_t,
157+
pub f_files: ::fsfilcnt_t,
158+
pub f_ffree: ::fsfilcnt_t,
159+
pub f_favail: ::fsfilcnt_t,
160+
pub f_fsid: ::c_ulong,
161+
pub f_flag: ::c_ulong,
162+
pub f_namemax: ::c_ulong,
163+
}
150164
}
151165

152166
pub const EXIT_FAILURE: ::c_int = 1;

src/unix/bsd/freebsdlike/mod.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,20 @@ s! {
8585
pub ss_size: ::size_t,
8686
pub ss_flags: ::c_int,
8787
}
88+
89+
pub struct statvfs {
90+
pub f_bavail: ::fsblkcnt_t,
91+
pub f_bfree: ::fsblkcnt_t,
92+
pub f_blocks: ::fsblkcnt_t,
93+
pub f_favail: ::fsfilcnt_t,
94+
pub f_ffree: ::fsfilcnt_t,
95+
pub f_files: ::fsfilcnt_t,
96+
pub f_bsize: ::c_ulong,
97+
pub f_flag: ::c_ulong,
98+
pub f_frsize: ::c_ulong,
99+
pub f_fsid: ::c_ulong,
100+
pub f_namemax: ::c_ulong,
101+
}
88102
}
89103

90104
pub const EXIT_FAILURE: ::c_int = 1;

src/unix/bsd/mod.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ pub type blkcnt_t = i64;
66
pub type socklen_t = u32;
77
pub type sa_family_t = u8;
88
pub type pthread_t = ::uintptr_t;
9+
pub type fsblkcnt_t = ::c_uint;
10+
pub type fsfilcnt_t = ::c_uint;
911

1012
s! {
1113
pub struct sockaddr {
@@ -102,6 +104,9 @@ pub const IPV6_V6ONLY: ::c_int = 27;
102104

103105
pub const FD_SETSIZE: usize = 1024;
104106

107+
pub const ST_RDONLY: ::c_ulong = 1;
108+
pub const ST_NOSUID: ::c_ulong = 2;
109+
105110
f! {
106111
pub fn FD_CLR(fd: ::c_int, set: *mut fd_set) -> () {
107112
let fd = fd as usize;

src/unix/bsd/openbsdlike/mod.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,20 @@ s! {
9292
pub st_birthtime: ::time_t,
9393
pub st_birthtime_nsec: ::c_long,
9494
}
95+
96+
pub struct statvfs {
97+
pub f_bsize: ::c_ulong,
98+
pub f_frsize: ::c_ulong,
99+
pub f_blocks: ::fsblkcnt_t,
100+
pub f_bfree: ::fsblkcnt_t,
101+
pub f_bavail: ::fsblkcnt_t,
102+
pub f_files: ::fsfilcnt_t,
103+
pub f_ffree: ::fsfilcnt_t,
104+
pub f_favail: ::fsfilcnt_t,
105+
pub f_fsid: ::c_ulong,
106+
pub f_flag: ::c_ulong,
107+
pub f_namemax: ::c_ulong,
108+
}
95109
}
96110

97111
pub const EXIT_FAILURE : ::c_int = 1;

src/unix/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -558,6 +558,8 @@ extern {
558558
whence: ::c_int) -> ::c_int;
559559
pub fn ftello(stream: *mut ::FILE) -> ::off_t;
560560
pub fn timegm(tm: *mut ::tm) -> time_t;
561+
pub fn statvfs(path: *const c_char, buf: *mut statvfs) -> ::c_int;
562+
pub fn fstatvfs(fd: ::c_int, buf: *mut statvfs) -> ::c_int;
561563
}
562564

563565
cfg_if! {

src/unix/notbsd/linux/mod.rs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ pub type ino64_t = u64;
99
pub type off64_t = i64;
1010
pub type blkcnt64_t = i64;
1111
pub type rlim64_t = u64;
12+
pub type fsblkcnt_t = ::c_ulong;
13+
pub type fsfilcnt_t = ::c_ulong;
1214

1315
pub enum fpos64_t {} // TODO: fill this out with a struct
1416

@@ -99,6 +101,23 @@ s! {
99101
pub pw_dir: *mut ::c_char,
100102
pub pw_shell: *mut ::c_char,
101103
}
104+
105+
pub struct statvfs {
106+
pub f_bsize: ::c_ulong,
107+
pub f_frsize: ::c_ulong,
108+
pub f_blocks: ::fsblkcnt_t,
109+
pub f_bfree: ::fsblkcnt_t,
110+
pub f_bavail: ::fsblkcnt_t,
111+
pub f_files: ::fsfilcnt_t,
112+
pub f_ffree: ::fsfilcnt_t,
113+
pub f_favail: ::fsfilcnt_t,
114+
pub f_fsid: ::c_ulong,
115+
#[cfg(target_pointer_width = "32")]
116+
pub __f_unused: ::c_int,
117+
pub f_flag: ::c_ulong,
118+
pub f_namemax: ::c_ulong,
119+
__f_spare: [::c_int; 6],
120+
}
102121
}
103122

104123
pub const FILENAME_MAX: ::c_uint = 4096;
@@ -218,6 +237,18 @@ pub const F_TEST: ::c_int = 3;
218237
pub const F_TLOCK: ::c_int = 2;
219238
pub const F_ULOCK: ::c_int = 0;
220239

240+
pub const ST_RDONLY: ::c_ulong = 1;
241+
pub const ST_NOSUID: ::c_ulong = 2;
242+
pub const ST_NODEV: ::c_ulong = 4;
243+
pub const ST_NOEXEC: ::c_ulong = 8;
244+
pub const ST_SYNCHRONOUS: ::c_ulong = 16;
245+
pub const ST_MANDLOCK: ::c_ulong = 64;
246+
pub const ST_WRITE: ::c_ulong = 128;
247+
pub const ST_APPEND: ::c_ulong = 256;
248+
pub const ST_IMMUTABLE: ::c_ulong = 512;
249+
pub const ST_NOATIME: ::c_ulong = 1024;
250+
pub const ST_NODIRATIME: ::c_ulong = 2048;
251+
221252
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
222253
pub const MAP_32BIT: ::c_int = 0x0040;
223254

src/unix/notbsd/linux/notmusl.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ pub const _SC_2_C_VERSION: ::c_int = 96;
2121
pub const RUSAGE_THREAD: ::c_int = 1;
2222
pub const O_ACCMODE: ::c_int = 3;
2323
pub const RUSAGE_CHILDREN: ::c_int = -1;
24+
pub const ST_RELATIME: ::c_ulong = 4096;
2425

2526
extern {
2627
pub fn sysctl(name: *mut ::c_int,

0 commit comments

Comments
 (0)