1 // APIs that were changed after FreeBSD 11
2 
3 // The type of `nlink_t` changed from `u16` to `u64` in FreeBSD 12:
4 pub type nlink_t = u16;
5 // Type of `dev_t` changed from `u32` to `u64` in FreeBSD 12:
6 pub type dev_t = u32;
7 // Type of `ino_t` changed from `unsigned int` to `unsigned long` in FreeBSD 12:
8 pub type ino_t = u32;
9 
10 s! {
11     pub struct kevent {
12         pub ident: ::uintptr_t,
13         pub filter: ::c_short,
14         pub flags: ::c_ushort,
15         pub fflags: ::c_uint,
16         pub data: ::intptr_t,
17         pub udata: *mut ::c_void,
18     }
19 
20     pub struct shmid_ds {
21         pub shm_perm: ::ipc_perm,
22         pub shm_segsz: ::size_t,
23         pub shm_lpid: ::pid_t,
24         pub shm_cpid: ::pid_t,
25         // Type of shm_nattc changed from `int` to `shmatt_t` (aka `unsigned
26         // int`) in FreeBSD 12:
27         pub shm_nattch: ::c_int,
28         pub shm_atime: ::time_t,
29         pub shm_dtime: ::time_t,
30         pub shm_ctime: ::time_t,
31     }
32 
33     pub struct kinfo_proc {
34         /// Size of this structure.
35         pub ki_structsize: ::c_int,
36         /// Reserved: layout identifier.
37         pub ki_layout: ::c_int,
38         /// Address of command arguments.
39         pub ki_args: *mut ::pargs,
40         // This is normally "struct proc".
41         /// Address of proc.
42         pub ki_paddr: *mut ::c_void,
43         // This is normally "struct user".
44         /// Kernel virtual address of u-area.
45         pub ki_addr: *mut ::c_void,
46         // This is normally "struct vnode".
47         /// Pointer to trace file.
48         pub ki_tracep: *mut ::c_void,
49         // This is normally "struct vnode".
50         /// Pointer to executable file.
51         pub ki_textvp: *mut ::c_void,
52         // This is normally "struct filedesc".
53         /// Pointer to open file info.
54         pub ki_fd: *mut ::c_void,
55         // This is normally "struct vmspace".
56         /// Pointer to kernel vmspace struct.
57         pub ki_vmspace: *mut ::c_void,
58         /// Sleep address.
59         pub ki_wchan: *mut ::c_void,
60         /// Process identifier.
61         pub ki_pid: ::pid_t,
62         /// Parent process ID.
63         pub ki_ppid: ::pid_t,
64         /// Process group ID.
65         pub ki_pgid: ::pid_t,
66         /// tty process group ID.
67         pub ki_tpgid: ::pid_t,
68         /// Process session ID.
69         pub ki_sid: ::pid_t,
70         /// Terminal session ID.
71         pub ki_tsid: ::pid_t,
72         /// Job control counter.
73         pub ki_jobc: ::c_short,
74         /// Unused (just here for alignment).
75         pub ki_spare_short1: ::c_short,
76         /// Controlling tty dev.
77         pub ki_tdev: ::dev_t,
78         /// Signals arrived but not delivered.
79         pub ki_siglist: ::sigset_t,
80         /// Current signal mask.
81         pub ki_sigmask: ::sigset_t,
82         /// Signals being ignored.
83         pub ki_sigignore: ::sigset_t,
84         /// Signals being caught by user.
85         pub ki_sigcatch: ::sigset_t,
86         /// Effective user ID.
87         pub ki_uid: ::uid_t,
88         /// Real user ID.
89         pub ki_ruid: ::uid_t,
90         /// Saved effective user ID.
91         pub ki_svuid: ::uid_t,
92         /// Real group ID.
93         pub ki_rgid: ::gid_t,
94         /// Saved effective group ID.
95         pub ki_svgid: ::gid_t,
96         /// Number of groups.
97         pub ki_ngroups: ::c_short,
98         /// Unused (just here for alignment).
99         pub ki_spare_short2: ::c_short,
100         /// Groups.
101         pub ki_groups: [::gid_t; ::KI_NGROUPS],
102         /// Virtual size.
103         pub ki_size: ::vm_size_t,
104         /// Current resident set size in pages.
105         pub ki_rssize: ::segsz_t,
106         /// Resident set size before last swap.
107         pub ki_swrss: ::segsz_t,
108         /// Text size (pages) XXX.
109         pub ki_tsize: ::segsz_t,
110         /// Data size (pages) XXX.
111         pub ki_dsize: ::segsz_t,
112         /// Stack size (pages).
113         pub ki_ssize: ::segsz_t,
114         /// Exit status for wait & stop signal.
115         pub ki_xstat: ::u_short,
116         /// Accounting flags.
117         pub ki_acflag: ::u_short,
118         /// %cpu for process during `ki_swtime`.
119         pub ki_pctcpu: ::fixpt_t,
120         /// Time averaged value of `ki_cpticks`.
121         pub ki_estcpu: ::u_int,
122         /// Time since last blocked.
123         pub ki_slptime: ::u_int,
124         /// Time swapped in or out.
125         pub ki_swtime: ::u_int,
126         /// Number of copy-on-write faults.
127         pub ki_cow: ::u_int,
128         /// Real time in microsec.
129         pub ki_runtime: u64,
130         /// Starting time.
131         pub ki_start: ::timeval,
132         /// Time used by process children.
133         pub ki_childtime: ::timeval,
134         /// P_* flags.
135         pub ki_flag: ::c_long,
136         /// KI_* flags (below).
137         pub ki_kiflag: ::c_long,
138         /// Kernel trace points.
139         pub ki_traceflag: ::c_int,
140         /// S* process status.
141         pub ki_stat: ::c_char,
142         /// Process "nice" value.
143         pub ki_nice: i8, // signed char
144         /// Process lock (prevent swap) count.
145         pub ki_lock: ::c_char,
146         /// Run queue index.
147         pub ki_rqindex: ::c_char,
148         /// Which cpu we are on.
149         pub ki_oncpu_old: ::c_uchar,
150         /// Last cpu we were on.
151         pub ki_lastcpu_old: ::c_uchar,
152         /// Thread name.
153         pub ki_tdname: [::c_char; ::TDNAMLEN + 1],
154         /// Wchan message.
155         pub ki_wmesg: [::c_char; ::WMESGLEN + 1],
156         /// Setlogin name.
157         pub ki_login: [::c_char; ::LOGNAMELEN + 1],
158         /// Lock name.
159         pub ki_lockname: [::c_char; ::LOCKNAMELEN + 1],
160         /// Command name.
161         pub ki_comm: [::c_char; ::COMMLEN + 1],
162         /// Emulation name.
163         pub ki_emul: [::c_char; ::KI_EMULNAMELEN + 1],
164         /// Login class.
165         pub ki_loginclass: [::c_char; ::LOGINCLASSLEN + 1],
166         /// More thread name.
167         pub ki_moretdname: [::c_char; ::MAXCOMLEN - ::TDNAMLEN + 1],
168         /// Spare string space.
169         pub ki_sparestrings: [[::c_char; 23]; 2], // little hack to allow PartialEq
170         /// Spare room for growth.
171         pub ki_spareints: [::c_int; ::KI_NSPARE_INT],
172         /// Which cpu we are on.
173         pub ki_oncpu: ::c_int,
174         /// Last cpu we were on.
175         pub ki_lastcpu: ::c_int,
176         /// PID of tracing process.
177         pub ki_tracer: ::c_int,
178         /// P2_* flags.
179         pub ki_flag2: ::c_int,
180         /// Default FIB number.
181         pub ki_fibnum: ::c_int,
182         /// Credential flags.
183         pub ki_cr_flags: ::u_int,
184         /// Process jail ID.
185         pub ki_jid: ::c_int,
186         /// Number of threads in total.
187         pub ki_numthreads: ::c_int,
188         // Thread ID.
189         pub ki_tid: ::lwpid_t,
190         /// Process priority.
191         pub ki_pri: ::priority,
192         /// Process rusage statistics.
193         pub ki_rusage: ::rusage,
194         /// rusage of children processes.
195         pub ki_rusage_ch: ::rusage,
196         // This is normally "struct pcb".
197         /// Kernel virtual addr of pcb.
198         pub ki_pcb: *mut ::c_void,
199         /// Kernel virtual addr of stack.
200         pub ki_kstack: *mut ::c_void,
201         /// User convenience pointer.
202         pub ki_udata: *mut ::c_void,
203         // This is normally "struct thread".
204         pub ki_tdaddr: *mut ::c_void,
205         pub ki_spareptrs: [*mut ::c_void; ::KI_NSPARE_PTR],
206         pub ki_sparelongs: [::c_long; ::KI_NSPARE_LONG],
207         /// PS_* flags.
208         pub ki_sflag: ::c_long,
209         /// kthread flag.
210         pub ki_tdflags: ::c_long,
211     }
212 }
213 
214 s_no_extra_traits! {
215     pub struct dirent {
216         pub d_fileno: ::ino_t,
217         pub d_reclen: u16,
218         pub d_type: u8,
219         // Type of `d_namlen` changed from `char` to `u16` in FreeBSD 12:
220         pub d_namlen: u8,
221         pub d_name: [::c_char; 256],
222     }
223 
224     pub struct statfs {
225         pub f_version: u32,
226         pub f_type: u32,
227         pub f_flags: u64,
228         pub f_bsize: u64,
229         pub f_iosize: u64,
230         pub f_blocks: u64,
231         pub f_bfree: u64,
232         pub f_bavail: i64,
233         pub f_files: u64,
234         pub f_ffree: i64,
235         pub f_syncwrites: u64,
236         pub f_asyncwrites: u64,
237         pub f_syncreads: u64,
238         pub f_asyncreads: u64,
239         f_spare: [u64; 10],
240         pub f_namemax: u32,
241         pub f_owner: ::uid_t,
242         pub f_fsid: ::fsid_t,
243         f_charspare: [::c_char; 80],
244         pub f_fstypename: [::c_char; 16],
245         // Array length changed from 88 to 1024 in FreeBSD 12:
246         pub f_mntfromname: [::c_char; 88],
247         // Array length changed from 88 to 1024 in FreeBSD 12:
248         pub f_mntonname: [::c_char; 88],
249     }
250 }
251 
252 cfg_if! {
253     if #[cfg(feature = "extra_traits")] {
254         impl PartialEq for statfs {
255             fn eq(&self, other: &statfs) -> bool {
256                 self.f_version == other.f_version
257                     && self.f_type == other.f_type
258                     && self.f_flags == other.f_flags
259                     && self.f_bsize == other.f_bsize
260                     && self.f_iosize == other.f_iosize
261                     && self.f_blocks == other.f_blocks
262                     && self.f_bfree == other.f_bfree
263                     && self.f_bavail == other.f_bavail
264                     && self.f_files == other.f_files
265                     && self.f_ffree == other.f_ffree
266                     && self.f_syncwrites == other.f_syncwrites
267                     && self.f_asyncwrites == other.f_asyncwrites
268                     && self.f_syncreads == other.f_syncreads
269                     && self.f_asyncreads == other.f_asyncreads
270                     && self.f_namemax == other.f_namemax
271                     && self.f_owner == other.f_owner
272                     && self.f_fsid == other.f_fsid
273                     && self.f_fstypename == other.f_fstypename
274                     && self
275                     .f_mntfromname
276                     .iter()
277                     .zip(other.f_mntfromname.iter())
278                     .all(|(a,b)| a == b)
279                     && self
280                     .f_mntonname
281                     .iter()
282                     .zip(other.f_mntonname.iter())
283                     .all(|(a,b)| a == b)
284             }
285         }
286         impl Eq for statfs {}
287         impl ::fmt::Debug for statfs {
288             fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result {
289                 f.debug_struct("statfs")
290                     .field("f_bsize", &self.f_bsize)
291                     .field("f_iosize", &self.f_iosize)
292                     .field("f_blocks", &self.f_blocks)
293                     .field("f_bfree", &self.f_bfree)
294                     .field("f_bavail", &self.f_bavail)
295                     .field("f_files", &self.f_files)
296                     .field("f_ffree", &self.f_ffree)
297                     .field("f_syncwrites", &self.f_syncwrites)
298                     .field("f_asyncwrites", &self.f_asyncwrites)
299                     .field("f_syncreads", &self.f_syncreads)
300                     .field("f_asyncreads", &self.f_asyncreads)
301                     .field("f_namemax", &self.f_namemax)
302                     .field("f_owner", &self.f_owner)
303                     .field("f_fsid", &self.f_fsid)
304                     .field("f_fstypename", &self.f_fstypename)
305                     .field("f_mntfromname", &&self.f_mntfromname[..])
306                     .field("f_mntonname", &&self.f_mntonname[..])
307                     .finish()
308             }
309         }
310         impl ::hash::Hash for statfs {
311             fn hash<H: ::hash::Hasher>(&self, state: &mut H) {
312                 self.f_version.hash(state);
313                 self.f_type.hash(state);
314                 self.f_flags.hash(state);
315                 self.f_bsize.hash(state);
316                 self.f_iosize.hash(state);
317                 self.f_blocks.hash(state);
318                 self.f_bfree.hash(state);
319                 self.f_bavail.hash(state);
320                 self.f_files.hash(state);
321                 self.f_ffree.hash(state);
322                 self.f_syncwrites.hash(state);
323                 self.f_asyncwrites.hash(state);
324                 self.f_syncreads.hash(state);
325                 self.f_asyncreads.hash(state);
326                 self.f_namemax.hash(state);
327                 self.f_owner.hash(state);
328                 self.f_fsid.hash(state);
329                 self.f_fstypename.hash(state);
330                 self.f_mntfromname.hash(state);
331                 self.f_mntonname.hash(state);
332             }
333         }
334 
335         impl PartialEq for dirent {
336             fn eq(&self, other: &dirent) -> bool {
337                 self.d_fileno == other.d_fileno
338                     && self.d_reclen == other.d_reclen
339                     && self.d_type == other.d_type
340                     && self.d_namlen == other.d_namlen
341                     && self
342                     .d_name[..self.d_namlen as _]
343                     .iter()
344                     .zip(other.d_name.iter())
345                     .all(|(a,b)| a == b)
346             }
347         }
348         impl Eq for dirent {}
349         impl ::fmt::Debug for dirent {
350             fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result {
351                 f.debug_struct("dirent")
352                     .field("d_fileno", &self.d_fileno)
353                     .field("d_reclen", &self.d_reclen)
354                     .field("d_type", &self.d_type)
355                     .field("d_namlen", &self.d_namlen)
356                     .field("d_name", &&self.d_name[..self.d_namlen as _])
357                     .finish()
358             }
359         }
360         impl ::hash::Hash for dirent {
361             fn hash<H: ::hash::Hasher>(&self, state: &mut H) {
362                 self.d_fileno.hash(state);
363                 self.d_reclen.hash(state);
364                 self.d_type.hash(state);
365                 self.d_namlen.hash(state);
366                 self.d_name[..self.d_namlen as _].hash(state);
367             }
368         }
369     }
370 }
371 
372 pub const ELAST: ::c_int = 96;
373 pub const RAND_MAX: ::c_int = 0x7fff_fffd;
374 pub const KI_NSPARE_PTR: usize = 6;
375 pub const MINCORE_SUPER: ::c_int = 0x20;
376 
377 extern "C" {
378     // Return type ::c_int was removed in FreeBSD 12
setgrent() -> ::c_int379     pub fn setgrent() -> ::c_int;
380 
381     // Type of `addr` argument changed from `const void*` to `void*`
382     // in FreeBSD 12
mprotect(addr: *const ::c_void, len: ::size_t, prot: ::c_int) -> ::c_int383     pub fn mprotect(addr: *const ::c_void, len: ::size_t, prot: ::c_int) -> ::c_int;
384 
385     // Return type ::c_int was removed in FreeBSD 12
freelocale(loc: ::locale_t) -> ::c_int386     pub fn freelocale(loc: ::locale_t) -> ::c_int;
387 
388     // Return type ::c_int changed to ::ssize_t in FreeBSD 12:
msgrcv( msqid: ::c_int, msgp: *mut ::c_void, msgsz: ::size_t, msgtyp: ::c_long, msgflg: ::c_int, ) -> ::c_int389     pub fn msgrcv(
390         msqid: ::c_int,
391         msgp: *mut ::c_void,
392         msgsz: ::size_t,
393         msgtyp: ::c_long,
394         msgflg: ::c_int,
395     ) -> ::c_int;
396 
fdatasync(fd: ::c_int) -> ::c_int397     pub fn fdatasync(fd: ::c_int) -> ::c_int;
398 }
399 
400 cfg_if! {
401     if #[cfg(any(target_arch = "x86_64",
402                  target_arch = "aarch64"))] {
403         mod b64;
404         pub use self::b64::*;
405     }
406 }
407