Skip to content

Commit e4bb63a

Browse files
committed
Merge pull request rust-lang#38 from danburkert/fs
bind additional filesystem APIs
2 parents c003614 + fe3968f commit e4bb63a

File tree

9 files changed

+123
-3
lines changed

9 files changed

+123
-3
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: 44 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,33 @@ s! {
134134
pub ss_size: ::size_t,
135135
pub ss_flags: ::c_int,
136136
}
137+
138+
pub struct fstore_t {
139+
pub fst_flags: ::c_uint,
140+
pub fst_posmode: ::c_int,
141+
pub fst_offset: ::off_t,
142+
pub fst_length: ::off_t,
143+
pub fst_bytesalloc: ::off_t,
144+
}
145+
146+
pub struct radvisory {
147+
pub ra_offset: ::off_t,
148+
pub ra_count: ::c_int,
149+
}
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+
}
137164
}
138165

139166
pub const EXIT_FAILURE: ::c_int = 1;
@@ -196,7 +223,6 @@ pub const F_LOCK: ::c_int = 1;
196223
pub const F_TEST: ::c_int = 3;
197224
pub const F_TLOCK: ::c_int = 2;
198225
pub const F_ULOCK: ::c_int = 0;
199-
pub const F_DUPFD_CLOEXEC: ::c_int = 67;
200226
pub const SIGHUP: ::c_int = 1;
201227
pub const SIGINT: ::c_int = 2;
202228
pub const SIGQUIT: ::c_int = 3;
@@ -342,10 +368,27 @@ pub const EQFULL: ::c_int = 106;
342368
pub const ELAST: ::c_int = 106;
343369

344370
pub const F_DUPFD: ::c_int = 0;
371+
pub const F_DUPFD_CLOEXEC: ::c_int = 67;
345372
pub const F_GETFD: ::c_int = 1;
346373
pub const F_SETFD: ::c_int = 2;
347374
pub const F_GETFL: ::c_int = 3;
348375
pub const F_SETFL: ::c_int = 4;
376+
pub const F_PREALLOCATE: ::c_int = 42;
377+
pub const F_RDADVISE: ::c_int = 44;
378+
pub const F_RDAHEAD: ::c_int = 45;
379+
pub const F_NOCACHE: ::c_int = 48;
380+
pub const F_GETPATH: ::c_int = 50;
381+
pub const F_FULLFSYNC: ::c_int = 51;
382+
pub const F_FREEZE_FS: ::c_int = 53;
383+
pub const F_THAW_FS: ::c_int = 54;
384+
pub const F_GLOBAL_NOCACHE: ::c_int = 55;
385+
pub const F_NODIRECT: ::c_int = 62;
386+
387+
pub const F_ALLOCATECONTIG: ::c_uint = 0x02;
388+
pub const F_ALLOCATEALL: ::c_uint = 0x04;
389+
390+
pub const F_PEOFPOSMODE: ::c_int = 3;
391+
pub const F_VOLPOSMODE: ::c_int = 4;
349392

350393
pub const O_ACCMODE: ::c_int = 3;
351394

@@ -491,8 +534,6 @@ pub const LOCK_UN: ::c_int = 8;
491534
pub const O_DSYNC: ::c_int = 4194304;
492535
pub const O_SYNC: ::c_int = 128;
493536
pub const O_NONBLOCK: ::c_int = 4;
494-
pub const F_GETPATH: ::c_int = 50;
495-
pub const F_FULLFSYNC: ::c_int = 51;
496537

497538
pub const MAP_COPY: ::c_int = 0x0002;
498539
pub const MAP_RENAME: ::c_int = 0x0020;

src/unix/bsd/freebsdlike/mod.rs

Lines changed: 16 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;
@@ -520,6 +534,8 @@ extern {
520534
-> ::c_int;
521535
pub fn clock_gettime(clk_id: ::c_int, tp: *mut ::timespec) -> ::c_int;
522536
pub fn pthread_set_name_np(tid: ::pthread_t, name: *const ::c_char);
537+
pub fn posix_fallocate(fd: ::c_int, offset: ::off_t,
538+
len: ::off_t) -> ::c_int;
523539
}
524540

525541
cfg_if! {

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: 37 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

@@ -281,6 +312,12 @@ extern {
281312
offset: ::off64_t,
282313
whence: ::c_int) -> ::c_int;
283314
pub fn ftello64(stream: *mut ::FILE) -> ::off64_t;
315+
pub fn fallocate(fd: ::c_int, mode: ::c_int,
316+
offset: ::off_t, len: ::off_t) -> ::c_int;
317+
pub fn posix_fallocate(fd: ::c_int, offset: ::off_t,
318+
len: ::off_t) -> ::c_int;
319+
pub fn readahead(fd: ::c_int, offset: ::off64_t,
320+
count: ::size_t) -> ::ssize_t;
284321
}
285322

286323
cfg_if! {

src/unix/notbsd/linux/notmips/mod.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,9 @@ pub const SIGCHLD: ::c_int = 17;
179179
pub const SIGBUS: ::c_int = 7;
180180
pub const SIG_SETMASK: ::c_int = 2;
181181

182+
pub const FALLOC_FL_KEEP_SIZE: ::c_int = 0x01;
183+
pub const FALLOC_FL_PUNCH_HOLE: ::c_int = 0x02;
184+
182185
extern {
183186
pub fn getnameinfo(sa: *const ::sockaddr,
184187
salen: ::socklen_t,

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)