Skip to content

Commit 5ac35c8

Browse files
committed
Auto merge of #1039 - alesharik:master, r=alexcrichton
Implement statfs for dragonfly, freebsd and openbsd
2 parents 73c0263 + ce4c140 commit 5ac35c8

File tree

6 files changed

+264
-5
lines changed

6 files changed

+264
-5
lines changed

Cargo.lock

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

libc-test/build.rs

+7-2
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,7 @@ fn main() {
343343
}
344344
}
345345

346-
cfg.type_name(move |ty, is_struct| {
346+
cfg.type_name(move |ty, is_struct, is_union| {
347347
match ty {
348348
// Just pass all these through, no need for a "struct" prefix
349349
"FILE" |
@@ -360,6 +360,10 @@ fn main() {
360360
// OSX calls this something else
361361
"sighandler_t" if bsdlike => "sig_t".to_string(),
362362

363+
t if is_union => {
364+
format!("union {}", t)
365+
}
366+
363367
t if t.ends_with("_t") => t.to_string(),
364368

365369
// Windows uppercase structs don't have `struct` in front, there's a
@@ -816,9 +820,10 @@ fn main() {
816820
cfg.skip_struct(|s| {
817821
s != "termios2"
818822
});
819-
cfg.type_name(move |ty, is_struct| {
823+
cfg.type_name(move |ty, is_struct, is_union| {
820824
match ty {
821825
t if is_struct => format!("struct {}", t),
826+
t if is_union => format!("union {}", t),
822827
t => t.to_string(),
823828
}
824829
});

src/macros.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,11 @@ macro_rules! __cfg_if_apply {
3535
}
3636

3737
macro_rules! s {
38-
($($(#[$attr:meta])* pub struct $i:ident { $($field:tt)* })*) => ($(
38+
($($(#[$attr:meta])* pub $t:ident $i:ident { $($field:tt)* })*) => ($(
3939
__item! {
4040
#[repr(C)]
4141
$(#[$attr])*
42-
pub struct $i { $($field)* }
42+
pub $t $i { $($field)* }
4343
}
4444
impl ::dox::Copy for $i {}
4545
impl ::dox::Clone for $i {

src/unix/bsd/freebsdlike/dragonfly/mod.rs

+24
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,27 @@ s! {
115115
pub f_uid_uuid: ::uuid_t,
116116
}
117117

118+
pub struct statfs {
119+
pub f_bsize: ::c_long,
120+
pub f_iosize: ::c_long,
121+
pub f_blocks: ::c_long,
122+
pub f_bfree: ::c_long,
123+
pub f_bavail: ::c_long,
124+
pub f_files: ::c_long,
125+
pub f_ffree: ::c_long,
126+
pub f_fsid: ::fsid_t,
127+
pub f_owner: ::uid_t,
128+
pub f_type: ::int32_t,
129+
pub f_flags: ::int32_t,
130+
pub f_syncwrites: ::c_long,
131+
pub f_asyncwrites: ::c_long,
132+
pub f_fstypename: [::c_char; 16],
133+
pub f_mntonname: [::c_char; 90],
134+
pub f_syncreads: ::c_long,
135+
pub f_asyncreads: ::c_long,
136+
pub f_mntfromname: [::c_char; 90],
137+
}
138+
118139
pub struct stat {
119140
pub st_ino: ::ino_t,
120141
pub st_nlink: ::nlink_t,
@@ -760,4 +781,7 @@ extern {
760781

761782
pub fn lwp_rtprio(function: ::c_int, pid: ::pid_t, lwpid: lwpid_t,
762783
rtp: *mut super::rtprio) -> ::c_int;
784+
785+
pub fn statfs(path: *const ::c_char, buf: *mut statfs) -> ::c_int;
786+
pub fn fstatfs(fd: ::c_int, buf: *mut statfs) -> ::c_int;
763787
}

src/unix/bsd/freebsdlike/freebsd/mod.rs

+28
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,31 @@ s! {
9999
pub f_namemax: ::c_ulong,
100100
}
101101

102+
pub struct statfs {
103+
pub f_version: ::uint32_t,
104+
pub f_type: ::uint32_t,
105+
pub f_flags: ::uint64_t,
106+
pub f_bsize: ::uint64_t,
107+
pub f_iosize: ::uint64_t,
108+
pub f_blocks: ::uint64_t,
109+
pub f_bfree: ::uint64_t,
110+
pub f_bavail: ::int64_t,
111+
pub f_files: ::uint64_t,
112+
pub f_ffree: ::int64_t,
113+
pub f_syncwrites: ::uint64_t,
114+
pub f_asyncwrites: ::uint64_t,
115+
pub f_syncreads: ::uint64_t,
116+
pub f_asyncreads: ::uint64_t,
117+
f_spare: [::uint64_t; 10],
118+
pub f_namemax: ::uint32_t,
119+
pub f_owner: ::uid_t,
120+
pub f_fsid: ::fsid_t,
121+
f_charspare: [::c_char; 80],
122+
pub f_fstypename: [::c_char; 16],
123+
pub f_mntfromname: [::c_char; 88],
124+
pub f_mntonname: [::c_char; 88],
125+
}
126+
102127
// internal structure has changed over time
103128
pub struct _sem {
104129
data: [u32; 4],
@@ -994,6 +1019,9 @@ extern {
9941019
fd: ::c_int,
9951020
newfd: ::c_int,
9961021
) -> ::c_int;
1022+
1023+
pub fn statfs(path: *const ::c_char, buf: *mut statfs) -> ::c_int;
1024+
pub fn fstatfs(fd: ::c_int, buf: *mut statfs) -> ::c_int;
9971025
}
9981026

9991027
cfg_if! {

src/unix/bsd/netbsdlike/openbsdlike/openbsd/mod.rs

+202
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,207 @@ s! {
2525
pub int_p_sign_posn: ::c_char,
2626
pub int_n_sign_posn: ::c_char,
2727
}
28+
29+
pub struct statfs {
30+
pub f_flags: ::uint32_t,
31+
pub f_bsize: ::uint32_t,
32+
pub f_iosize: ::uint32_t,
33+
pub f_blocks: ::uint64_t,
34+
pub f_bfree: ::uint64_t,
35+
pub f_bavail: ::int64_t,
36+
pub f_files: ::uint64_t,
37+
pub f_ffree: ::uint64_t,
38+
pub f_favail: ::int64_t,
39+
pub f_syncwrites: ::uint64_t,
40+
pub f_syncreads: ::uint64_t,
41+
pub f_asyncwrites: ::uint64_t,
42+
pub f_asyncreads: ::uint64_t,
43+
pub f_fsid: ::fsid_t,
44+
pub f_namemax: ::uint32_t,
45+
pub f_owner: ::uid_t,
46+
pub f_ctime: ::uint64_t,
47+
pub f_fstypename: [::c_char; 16],
48+
pub f_mntonname: [::c_char; 90],
49+
pub f_mntfromname: [::c_char; 90],
50+
pub f_mntfromspec: [::c_char; 90],
51+
pub mount_info: mount_info,
52+
}
53+
54+
pub union mount_info {
55+
pub ufs_args: ufs_args,
56+
pub mfs_args: mfs_args,
57+
pub nfs_args: nfs_args,
58+
pub iso_args: iso_args,
59+
pub msdosfs_args: msdosfs_args,
60+
pub ntfs_args: ntfs_args,
61+
pub tmpfs_args: tmpfs_args,
62+
align: [::c_char; 160],
63+
}
64+
65+
pub struct ufs_args {
66+
pub fspec: *mut ::c_char,
67+
pub export_info: export_args,
68+
}
69+
70+
pub struct mfs_args {
71+
pub fspec: *mut ::c_char,
72+
pub export_info: export_args,
73+
// https://github.com/openbsd/src/blob/master/sys/sys/types.h#L134
74+
pub base: *mut ::c_char,
75+
pub size: ::c_ulong,
76+
}
77+
78+
pub struct iso_args {
79+
pub fspec: *mut ::c_char,
80+
pub export_info: export_args,
81+
pub flags: ::c_int,
82+
pub sess: ::c_int,
83+
}
84+
85+
pub struct nfs_args {
86+
pub version: ::c_int,
87+
pub addr: *mut ::sockaddr,
88+
pub addrlen: ::c_int,
89+
pub sotype: ::c_int,
90+
pub proto: ::c_int,
91+
pub fh: *mut ::c_uchar,
92+
pub fhsize: ::c_int,
93+
pub flags: ::c_int,
94+
pub wsize: ::c_int,
95+
pub rsize: ::c_int,
96+
pub readdirsize: ::c_int,
97+
pub timeo: ::c_int,
98+
pub retrans: ::c_int,
99+
pub maxgrouplist: ::c_int,
100+
pub readahead: ::c_int,
101+
pub leaseterm: ::c_int,
102+
pub deadthresh: ::c_int,
103+
pub hostname: *mut ::c_char,
104+
pub acregmin: ::c_int,
105+
pub acregmax: ::c_int,
106+
pub acdirmin: ::c_int,
107+
pub acdirmax: ::c_int,
108+
}
109+
110+
pub struct msdosfs_args {
111+
pub fspec: *mut ::c_char,
112+
pub export_info: export_args,
113+
pub uid: ::uid_t,
114+
pub gid: ::gid_t,
115+
pub mask: ::mode_t,
116+
pub flags: ::c_int,
117+
}
118+
119+
pub struct ntfs_args {
120+
pub fspec: *mut ::c_char,
121+
pub export_info: export_args,
122+
pub uid: ::uid_t,
123+
pub gid: ::gid_t,
124+
pub mode: ::mode_t,
125+
pub flag: ::c_ulong,
126+
}
127+
128+
pub struct udf_args {
129+
pub fspec: *mut ::c_char,
130+
pub lastblock: ::uint32_t,
131+
}
132+
133+
pub struct tmpfs_args {
134+
pub ta_version: ::c_int,
135+
pub ta_nodes_max: ::ino_t,
136+
pub ta_size_max: ::off_t,
137+
pub ta_root_uid: ::uid_t,
138+
pub ta_root_gid: ::gid_t,
139+
pub ta_root_mode: ::mode_t,
140+
}
141+
142+
pub struct fusefs_args {
143+
pub name: *mut ::c_char,
144+
pub fd: ::c_int,
145+
pub max_read: ::c_int,
146+
pub allow_other: ::c_int,
147+
}
148+
149+
pub struct xucred {
150+
pub cr_uid: ::uid_t,
151+
pub cr_gid: ::gid_t,
152+
pub cr_ngroups: ::c_short,
153+
//https://github.com/openbsd/src/blob/master/sys/sys/syslimits.h#L44
154+
pub cr_groups: [::gid_t; 16],
155+
}
156+
157+
pub struct export_args {
158+
pub ex_flags: ::c_int,
159+
pub ex_root: ::uid_t,
160+
pub ex_anon: xucred,
161+
pub ex_addr: *mut ::sockaddr,
162+
pub ex_addrlen: ::c_int,
163+
pub ex_mask: *mut ::sockaddr,
164+
pub ex_masklen: ::c_int,
165+
}
28166
}
29167

168+
//https://github.com/openbsd/src/blob/master/sys/sys/mount.h
169+
pub const ISOFSMNT_NORRIP: ::c_int = 0x1; // disable Rock Ridge Ext
170+
pub const ISOFSMNT_GENS: ::c_int = 0x2; // enable generation numbers
171+
pub const ISOFSMNT_EXTATT: ::c_int = 0x4; // enable extended attr
172+
pub const ISOFSMNT_NOJOLIET: ::c_int = 0x8; // disable Joliet Ext
173+
pub const ISOFSMNT_SESS: ::c_int = 0x10; // use iso_args.sess
174+
175+
pub const NFS_ARGSVERSION: ::c_int = 4; // change when nfs_args changes
176+
177+
pub const NFSMNT_RESVPORT: ::c_int = 0; // always use reserved ports
178+
pub const NFSMNT_SOFT: ::c_int = 0x1; // soft mount (hard is default)
179+
pub const NFSMNT_WSIZE: ::c_int = 0x2; // set write size
180+
pub const NFSMNT_RSIZE: ::c_int = 0x4; // set read size
181+
pub const NFSMNT_TIMEO: ::c_int = 0x8; // set initial timeout
182+
pub const NFSMNT_RETRANS: ::c_int = 0x10; // set number of request retries
183+
pub const NFSMNT_MAXGRPS: ::c_int = 0x20; // set maximum grouplist size
184+
pub const NFSMNT_INT: ::c_int = 0x40; // allow interrupts on hard mount
185+
pub const NFSMNT_NOCONN: ::c_int = 0x80; // Don't Connect the socket
186+
pub const NFSMNT_NQNFS: ::c_int = 0x100; // Use Nqnfs protocol
187+
pub const NFSMNT_NFSV3: ::c_int = 0x200; // Use NFS Version 3 protocol
188+
pub const NFSMNT_KERB: ::c_int = 0x400; // Use Kerberos authentication
189+
pub const NFSMNT_DUMBTIMR: ::c_int = 0x800; // Don't estimate rtt dynamically
190+
pub const NFSMNT_LEASETERM: ::c_int = 0x1000; // set lease term (nqnfs)
191+
pub const NFSMNT_READAHEAD: ::c_int = 0x2000; // set read ahead
192+
pub const NFSMNT_DEADTHRESH: ::c_int = 0x4000; // set dead server retry thresh
193+
pub const NFSMNT_NOAC: ::c_int = 0x8000; // disable attribute cache
194+
pub const NFSMNT_RDIRPLUS: ::c_int = 0x10000; // Use Readdirplus for V3
195+
pub const NFSMNT_READDIRSIZE: ::c_int = 0x20000; // Set readdir size
196+
197+
/* Flags valid only in mount syscall arguments */
198+
pub const NFSMNT_ACREGMIN: ::c_int = 0x40000; // acregmin field valid
199+
pub const NFSMNT_ACREGMAX: ::c_int = 0x80000; // acregmax field valid
200+
pub const NFSMNT_ACDIRMIN: ::c_int = 0x100000; // acdirmin field valid
201+
pub const NFSMNT_ACDIRMAX: ::c_int = 0x200000; // acdirmax field valid
202+
203+
/* Flags valid only in kernel */
204+
pub const NFSMNT_INTERNAL: ::c_int = 0xfffc0000; // Bits set internally
205+
pub const NFSMNT_HASWRITEVERF: ::c_int = 0x40000; // Has write verifier for V3
206+
pub const NFSMNT_GOTPATHCONF: ::c_int = 0x80000; // Got the V3 pathconf info
207+
pub const NFSMNT_GOTFSINFO: ::c_int = 0x100000; // Got the V3 fsinfo
208+
pub const NFSMNT_MNTD: ::c_int = 0x200000; // Mnt server for mnt point
209+
pub const NFSMNT_DISMINPROG: ::c_int = 0x400000; // Dismount in progress
210+
pub const NFSMNT_DISMNT: ::c_int = 0x800000; // Dismounted
211+
pub const NFSMNT_SNDLOCK: ::c_int = 0x1000000; // Send socket lock
212+
pub const NFSMNT_WANTSND: ::c_int = 0x2000000; // Want above
213+
pub const NFSMNT_RCVLOCK: ::c_int = 0x4000000; // Rcv socket lock
214+
pub const NFSMNT_WANTRCV: ::c_int = 0x8000000; // Want above
215+
pub const NFSMNT_WAITAUTH: ::c_int = 0x10000000; // Wait for authentication
216+
pub const NFSMNT_HASAUTH: ::c_int = 0x20000000; // Has authenticator
217+
pub const NFSMNT_WANTAUTH: ::c_int = 0x40000000; // Wants an authenticator
218+
pub const NFSMNT_AUTHERR: ::c_int = 0x80000000; // Authentication error
219+
220+
pub const MSDOSFSMNT_SHORTNAME: ::c_int = 0x1; // Force old DOS short names only
221+
pub const MSDOSFSMNT_LONGNAME: ::c_int = 0x2; // Force Win'95 long names
222+
pub const MSDOSFSMNT_NOWIN95: ::c_int = 0x4; // Completely ignore Win95 entries
223+
224+
pub const NTFS_MFLAG_CASEINS: ::c_int = 0x1;
225+
pub const NTFS_MFLAG_ALLNAMES: ::c_int = 0x2;
226+
227+
pub const TMPFS_ARGS_VERSION: ::c_int = 1;
228+
30229
pub const MAP_STACK : ::c_int = 0x4000;
31230

32231
// https://github.com/openbsd/src/blob/master/sys/net/if.h#L187
@@ -59,6 +258,9 @@ extern {
59258
pub fn strtonum(nptr: *const ::c_char, minval: ::c_longlong,
60259
maxval: ::c_longlong,
61260
errstr: *mut *const ::c_char) -> ::c_longlong;
261+
262+
pub fn statfs(path: *const ::c_char, buf: *mut statfs) -> ::c_int;
263+
pub fn fstatfs(fd: ::c_int, buf: *mut statfs) -> ::c_int;
62264
}
63265

64266
cfg_if! {

0 commit comments

Comments
 (0)