-
Notifications
You must be signed in to change notification settings - Fork 994
/
mod.rs
323 lines (308 loc) · 11.5 KB
/
mod.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
// APIs that were changed after FreeBSD 11
// The type of `nlink_t` changed from `u16` to `u64` in FreeBSD 12:
pub type nlink_t = u16;
// Type of `dev_t` changed from `u32` to `u64` in FreeBSD 12:
pub type dev_t = u32;
// Type of `ino_t` changed from `unsigned int` to `unsigned long` in FreeBSD 12:
pub type ino_t = u32;
s! {
pub struct kevent {
pub ident: ::uintptr_t,
pub filter: ::c_short,
pub flags: ::c_ushort,
pub fflags: ::c_uint,
pub data: ::intptr_t,
pub udata: *mut ::c_void,
}
pub struct shmid_ds {
pub shm_perm: ::ipc_perm,
pub shm_segsz: ::size_t,
pub shm_lpid: ::pid_t,
pub shm_cpid: ::pid_t,
// Type of shm_nattc changed from `int` to `shmatt_t` (aka `unsigned
// int`) in FreeBSD 12:
pub shm_nattch: ::c_int,
pub shm_atime: ::time_t,
pub shm_dtime: ::time_t,
pub shm_ctime: ::time_t,
}
pub struct kinfo_proc {
pub ki_structsize: ::c_int,
pub ki_layout: ::c_int,
pub ki_args: *mut ::pargs,
// This is normally "struct proc".
pub ki_paddr: *mut ::c_void,
// This is normally "struct user".
pub ki_addr: *mut ::c_void,
// This is normally "struct vnode".
pub ki_tracep: *mut ::c_void,
// This is normally "struct vnode".
pub ki_textvp: *mut ::c_void,
// This is normally "struct filedesc".
pub ki_fd: *mut ::c_void,
// This is normally "struct vmspace".
pub ki_vmspace: *mut ::c_void,
pub ki_wchan: *mut ::c_void,
pub ki_pid: ::pid_t,
pub ki_ppid: ::pid_t,
pub ki_pgid: ::pid_t,
pub ki_tpgid: ::pid_t,
pub ki_sid: ::pid_t,
pub ki_tsid: ::pid_t,
pub ki_jobc: ::c_short,
pub ki_spare_short1: ::c_short,
pub ki_tdev: ::dev_t,
pub ki_siglist: ::sigset_t,
pub ki_sigmask: ::sigset_t,
pub ki_sigignore: ::sigset_t,
pub ki_sigcatch: ::sigset_t,
pub ki_uid: ::uid_t,
pub ki_ruid: ::uid_t,
pub ki_svuid: ::uid_t,
pub ki_rgid: ::gid_t,
pub ki_svgid: ::gid_t,
pub ki_ngroups: ::c_short,
pub ki_spare_short2: ::c_short,
pub ki_groups: [::gid_t; ::KI_NGROUPS],
pub ki_size: ::vm_size_t,
pub ki_rssize: ::segsz_t,
pub ki_swrss: ::segsz_t,
pub ki_tsize: ::segsz_t,
pub ki_dsize: ::segsz_t,
pub ki_ssize: ::segsz_t,
pub ki_xstat: ::u_short,
pub ki_acflag: ::u_short,
pub ki_pctcpu: ::fixpt_t,
pub ki_estcpu: ::u_int,
pub ki_slptime: ::u_int,
pub ki_swtime: ::u_int,
pub ki_cow: ::u_int,
pub ki_runtime: u64,
pub ki_start: ::timeval,
pub ki_childtime: ::timeval,
pub ki_flag: ::c_long,
pub ki_kiflag: ::c_long,
pub ki_traceflag: ::c_int,
pub ki_stat: ::c_char,
pub ki_nice: i8, // signed char
pub ki_lock: ::c_char,
pub ki_rqindex: ::c_char,
pub ki_oncpu_old: ::c_uchar,
pub ki_lastcpu_old: ::c_uchar,
pub ki_tdname: [::c_char; ::TDNAMLEN + 1],
pub ki_wmesg: [::c_char; ::WMESGLEN + 1],
pub ki_login: [::c_char; ::LOGNAMELEN + 1],
pub ki_lockname: [::c_char; ::LOCKNAMELEN + 1],
pub ki_comm: [::c_char; ::COMMLEN + 1],
pub ki_emul: [::c_char; ::KI_EMULNAMELEN + 1],
pub ki_loginclass: [::c_char; ::LOGINCLASSLEN + 1],
pub ki_moretdname: [::c_char; ::MAXCOMLEN - ::TDNAMLEN + 1],
pub ki_sparestrings: [[::c_char; 23]; 2], // little hack to allow PartialEq
pub ki_spareints: [::c_int; ::KI_NSPARE_INT],
pub ki_oncpu: ::c_int,
pub ki_lastcpu: ::c_int,
pub ki_tracer: ::c_int,
pub ki_flag2: ::c_int,
pub ki_fibnum: ::c_int,
pub ki_cr_flags: ::u_int,
pub ki_jid: ::c_int,
pub ki_numthreads: ::c_int,
pub ki_tid: ::lwpid_t,
pub ki_pri: ::priority,
pub ki_rusage: ::rusage,
pub ki_rusage_ch: ::rusage,
// This is normally "struct pcb".
pub ki_pcb: *mut ::c_void,
pub ki_kstack: *mut ::c_void,
pub ki_udata: *mut ::c_void,
// This is normally "struct thread".
pub ki_tdaddr: *mut ::c_void,
pub ki_spareptrs: [*mut ::c_void; ::KI_NSPARE_PTR],
pub ki_sparelongs: [::c_long; ::KI_NSPARE_LONG],
pub ki_sflag: ::c_long,
pub ki_tdflags: ::c_long,
}
}
s_no_extra_traits! {
pub struct dirent {
pub d_fileno: ::ino_t,
pub d_reclen: u16,
pub d_type: u8,
// Type of `d_namlen` changed from `char` to `u16` in FreeBSD 12:
pub d_namlen: u8,
pub d_name: [::c_char; 256],
}
pub struct statfs {
pub f_version: u32,
pub f_type: u32,
pub f_flags: u64,
pub f_bsize: u64,
pub f_iosize: u64,
pub f_blocks: u64,
pub f_bfree: u64,
pub f_bavail: i64,
pub f_files: u64,
pub f_ffree: i64,
pub f_syncwrites: u64,
pub f_asyncwrites: u64,
pub f_syncreads: u64,
pub f_asyncreads: u64,
f_spare: [u64; 10],
pub f_namemax: u32,
pub f_owner: ::uid_t,
pub f_fsid: ::fsid_t,
f_charspare: [::c_char; 80],
pub f_fstypename: [::c_char; 16],
// Array length changed from 88 to 1024 in FreeBSD 12:
pub f_mntfromname: [::c_char; 88],
// Array length changed from 88 to 1024 in FreeBSD 12:
pub f_mntonname: [::c_char; 88],
}
}
cfg_if! {
if #[cfg(feature = "extra_traits")] {
impl PartialEq for statfs {
fn eq(&self, other: &statfs) -> bool {
self.f_version == other.f_version
&& self.f_type == other.f_type
&& self.f_flags == other.f_flags
&& self.f_bsize == other.f_bsize
&& self.f_iosize == other.f_iosize
&& self.f_blocks == other.f_blocks
&& self.f_bfree == other.f_bfree
&& self.f_bavail == other.f_bavail
&& self.f_files == other.f_files
&& self.f_ffree == other.f_ffree
&& self.f_syncwrites == other.f_syncwrites
&& self.f_asyncwrites == other.f_asyncwrites
&& self.f_syncreads == other.f_syncreads
&& self.f_asyncreads == other.f_asyncreads
&& self.f_namemax == other.f_namemax
&& self.f_owner == other.f_owner
&& self.f_fsid == other.f_fsid
&& self.f_fstypename == other.f_fstypename
&& self
.f_mntfromname
.iter()
.zip(other.f_mntfromname.iter())
.all(|(a,b)| a == b)
&& self
.f_mntonname
.iter()
.zip(other.f_mntonname.iter())
.all(|(a,b)| a == b)
}
}
impl Eq for statfs {}
impl ::fmt::Debug for statfs {
fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result {
f.debug_struct("statfs")
.field("f_bsize", &self.f_bsize)
.field("f_iosize", &self.f_iosize)
.field("f_blocks", &self.f_blocks)
.field("f_bfree", &self.f_bfree)
.field("f_bavail", &self.f_bavail)
.field("f_files", &self.f_files)
.field("f_ffree", &self.f_ffree)
.field("f_syncwrites", &self.f_syncwrites)
.field("f_asyncwrites", &self.f_asyncwrites)
.field("f_syncreads", &self.f_syncreads)
.field("f_asyncreads", &self.f_asyncreads)
.field("f_namemax", &self.f_namemax)
.field("f_owner", &self.f_owner)
.field("f_fsid", &self.f_fsid)
.field("f_fstypename", &self.f_fstypename)
.field("f_mntfromname", &&self.f_mntfromname[..])
.field("f_mntonname", &&self.f_mntonname[..])
.finish()
}
}
impl ::hash::Hash for statfs {
fn hash<H: ::hash::Hasher>(&self, state: &mut H) {
self.f_version.hash(state);
self.f_type.hash(state);
self.f_flags.hash(state);
self.f_bsize.hash(state);
self.f_iosize.hash(state);
self.f_blocks.hash(state);
self.f_bfree.hash(state);
self.f_bavail.hash(state);
self.f_files.hash(state);
self.f_ffree.hash(state);
self.f_syncwrites.hash(state);
self.f_asyncwrites.hash(state);
self.f_syncreads.hash(state);
self.f_asyncreads.hash(state);
self.f_namemax.hash(state);
self.f_owner.hash(state);
self.f_fsid.hash(state);
self.f_fstypename.hash(state);
self.f_mntfromname.hash(state);
self.f_mntonname.hash(state);
}
}
impl PartialEq for dirent {
fn eq(&self, other: &dirent) -> bool {
self.d_fileno == other.d_fileno
&& self.d_reclen == other.d_reclen
&& self.d_type == other.d_type
&& self.d_namlen == other.d_namlen
&& self
.d_name[..self.d_namlen as _]
.iter()
.zip(other.d_name.iter())
.all(|(a,b)| a == b)
}
}
impl Eq for dirent {}
impl ::fmt::Debug for dirent {
fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result {
f.debug_struct("dirent")
.field("d_fileno", &self.d_fileno)
.field("d_reclen", &self.d_reclen)
.field("d_type", &self.d_type)
.field("d_namlen", &self.d_namlen)
.field("d_name", &&self.d_name[..self.d_namlen as _])
.finish()
}
}
impl ::hash::Hash for dirent {
fn hash<H: ::hash::Hasher>(&self, state: &mut H) {
self.d_fileno.hash(state);
self.d_reclen.hash(state);
self.d_type.hash(state);
self.d_namlen.hash(state);
self.d_name[..self.d_namlen as _].hash(state);
}
}
}
}
pub const ELAST: ::c_int = 96;
pub const RAND_MAX: ::c_int = 0x7fff_fffd;
pub const KI_NSPARE_PTR: usize = 6;
pub const MINCORE_SUPER: ::c_int = 0x20;
extern "C" {
// Return type ::c_int was removed in FreeBSD 12
pub fn setgrent() -> ::c_int;
// Type of `addr` argument changed from `const void*` to `void*`
// in FreeBSD 12
pub fn mprotect(addr: *const ::c_void, len: ::size_t, prot: ::c_int) -> ::c_int;
// Return type ::c_int was removed in FreeBSD 12
pub fn freelocale(loc: ::locale_t) -> ::c_int;
// Return type ::c_int changed to ::ssize_t in FreeBSD 12:
pub fn msgrcv(
msqid: ::c_int,
msgp: *mut ::c_void,
msgsz: ::size_t,
msgtyp: ::c_long,
msgflg: ::c_int,
) -> ::c_int;
pub fn fdatasync(fd: ::c_int) -> ::c_int;
}
cfg_if! {
if #[cfg(any(target_arch = "x86_64",
target_arch = "aarch64"))] {
mod b64;
pub use self::b64::*;
}
}