Skip to content

Commit aead99a

Browse files
committed
Auto merge of #2051 - asomers:aio_writev, r=Amanieu
Add aio_readv and aio_writev They are new in FreeBSD 13. While I'm here, refactor freebsd to add a new FreeBSD 13 module.
2 parents 4af2342 + c070417 commit aead99a

File tree

6 files changed

+295
-24
lines changed

6 files changed

+295
-24
lines changed

.cirrus.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ task:
3131
task:
3232
name: nightly x86_64-unknown-freebsd-13
3333
freebsd_instance:
34-
image: freebsd-13-0-current-amd64-v20201001
34+
image: freebsd-13-0-alpha3-amd64
3535
setup_script:
3636
- pkg install -y curl
3737
- curl https://sh.rustup.rs -sSf --output rustup.sh

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// APIs that had breaking changes after FreeBSD 11
1+
// APIs that were changed after FreeBSD 11
22

33
// The type of `nlink_t` changed from `u16` to `u64` in FreeBSD 12:
44
pub type nlink_t = u16;
@@ -190,6 +190,7 @@ cfg_if! {
190190
}
191191

192192
pub const ELAST: ::c_int = 96;
193+
pub const RAND_MAX: ::c_int = 0x7fff_fffd;
193194

194195
extern "C" {
195196
// Return type ::c_int was removed in FreeBSD 12

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

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// APIs that changed in FreeBSD12
1+
// APIs in FreeBSD 12 that have changed since 11.
22

33
pub type nlink_t = u64;
44
pub type dev_t = u64;
@@ -200,17 +200,11 @@ pub const F_SEAL_WRITE: ::c_int = 0x0008;
200200
pub const GRND_NONBLOCK: ::c_uint = 0x1;
201201
pub const GRND_RANDOM: ::c_uint = 0x2;
202202

203+
pub const RAND_MAX: ::c_int = 0x7fff_fffd;
204+
203205
pub const SO_DOMAIN: ::c_int = 0x1019;
204206

205-
cfg_if! {
206-
if #[cfg(not(freebsd13))] {
207-
pub const ELAST: ::c_int = 96;
208-
} else {
209-
pub const EINTEGRITY: ::c_int = 97;
210-
pub const ELAST: ::c_int = 97;
211-
pub const GRND_INSECURE: ::c_uint = 0x4;
212-
}
213-
}
207+
pub const ELAST: ::c_int = 96;
214208

215209
extern "C" {
216210
pub fn setgrent();
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#[repr(C)]
2+
#[cfg_attr(feature = "extra_traits", derive(Debug, Eq, Hash, PartialEq))]
3+
pub struct stat {
4+
pub st_dev: ::dev_t,
5+
pub st_ino: ::ino_t,
6+
pub st_nlink: ::nlink_t,
7+
pub st_mode: ::mode_t,
8+
st_padding0: i16,
9+
pub st_uid: ::uid_t,
10+
pub st_gid: ::gid_t,
11+
st_padding1: i32,
12+
pub st_rdev: ::dev_t,
13+
pub st_atime: ::time_t,
14+
pub st_atime_nsec: ::c_long,
15+
pub st_mtime: ::time_t,
16+
pub st_mtime_nsec: ::c_long,
17+
pub st_ctime: ::time_t,
18+
pub st_ctime_nsec: ::c_long,
19+
pub st_birthtime: ::time_t,
20+
pub st_birthtime_nsec: ::c_long,
21+
pub st_size: ::off_t,
22+
pub st_blocks: ::blkcnt_t,
23+
pub st_blksize: ::blksize_t,
24+
pub st_flags: ::fflags_t,
25+
pub st_gen: u64,
26+
pub st_spare: [u64; 10],
27+
}
28+
29+
impl ::Copy for ::stat {}
30+
impl ::Clone for ::stat {
31+
fn clone(&self) -> ::stat {
32+
*self
33+
}
34+
}
Lines changed: 250 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,250 @@
1+
// APIs in FreeBSD 13 that have changed since 11.
2+
3+
pub type nlink_t = u64;
4+
pub type dev_t = u64;
5+
pub type ino_t = ::c_ulong;
6+
pub type shmatt_t = ::c_uint;
7+
8+
s! {
9+
pub struct shmid_ds {
10+
pub shm_perm: ::ipc_perm,
11+
pub shm_segsz: ::size_t,
12+
pub shm_lpid: ::pid_t,
13+
pub shm_cpid: ::pid_t,
14+
pub shm_nattch: ::shmatt_t,
15+
pub shm_atime: ::time_t,
16+
pub shm_dtime: ::time_t,
17+
pub shm_ctime: ::time_t,
18+
}
19+
20+
pub struct kevent {
21+
pub ident: ::uintptr_t,
22+
pub filter: ::c_short,
23+
pub flags: ::c_ushort,
24+
pub fflags: ::c_uint,
25+
pub data: ::intptr_t,
26+
pub udata: *mut ::c_void,
27+
pub ext: [u64; 4],
28+
}
29+
}
30+
31+
s_no_extra_traits! {
32+
pub struct dirent {
33+
pub d_fileno: ::ino_t,
34+
pub d_off: ::off_t,
35+
pub d_reclen: u16,
36+
pub d_type: u8,
37+
d_pad0: u8,
38+
pub d_namlen: u16,
39+
d_pad1: u16,
40+
pub d_name: [::c_char; 256],
41+
}
42+
43+
pub struct statfs {
44+
pub f_version: u32,
45+
pub f_type: u32,
46+
pub f_flags: u64,
47+
pub f_bsize: u64,
48+
pub f_iosize: u64,
49+
pub f_blocks: u64,
50+
pub f_bfree: u64,
51+
pub f_bavail: i64,
52+
pub f_files: u64,
53+
pub f_ffree: i64,
54+
pub f_syncwrites: u64,
55+
pub f_asyncwrites: u64,
56+
pub f_syncreads: u64,
57+
pub f_asyncreads: u64,
58+
f_spare: [u64; 10],
59+
pub f_namemax: u32,
60+
pub f_owner: ::uid_t,
61+
pub f_fsid: ::fsid_t,
62+
f_charspare: [::c_char; 80],
63+
pub f_fstypename: [::c_char; 16],
64+
pub f_mntfromname: [::c_char; 1024],
65+
pub f_mntonname: [::c_char; 1024],
66+
}
67+
}
68+
69+
cfg_if! {
70+
if #[cfg(feature = "extra_traits")] {
71+
impl PartialEq for statfs {
72+
fn eq(&self, other: &statfs) -> bool {
73+
self.f_version == other.f_version
74+
&& self.f_type == other.f_type
75+
&& self.f_flags == other.f_flags
76+
&& self.f_bsize == other.f_bsize
77+
&& self.f_iosize == other.f_iosize
78+
&& self.f_blocks == other.f_blocks
79+
&& self.f_bfree == other.f_bfree
80+
&& self.f_bavail == other.f_bavail
81+
&& self.f_files == other.f_files
82+
&& self.f_ffree == other.f_ffree
83+
&& self.f_syncwrites == other.f_syncwrites
84+
&& self.f_asyncwrites == other.f_asyncwrites
85+
&& self.f_syncreads == other.f_syncreads
86+
&& self.f_asyncreads == other.f_asyncreads
87+
&& self.f_namemax == other.f_namemax
88+
&& self.f_owner == other.f_owner
89+
&& self.f_fsid == other.f_fsid
90+
&& self.f_fstypename == other.f_fstypename
91+
&& self
92+
.f_mntfromname
93+
.iter()
94+
.zip(other.f_mntfromname.iter())
95+
.all(|(a,b)| a == b)
96+
&& self
97+
.f_mntonname
98+
.iter()
99+
.zip(other.f_mntonname.iter())
100+
.all(|(a,b)| a == b)
101+
}
102+
}
103+
impl Eq for statfs {}
104+
impl ::fmt::Debug for statfs {
105+
fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result {
106+
f.debug_struct("statfs")
107+
.field("f_bsize", &self.f_bsize)
108+
.field("f_iosize", &self.f_iosize)
109+
.field("f_blocks", &self.f_blocks)
110+
.field("f_bfree", &self.f_bfree)
111+
.field("f_bavail", &self.f_bavail)
112+
.field("f_files", &self.f_files)
113+
.field("f_ffree", &self.f_ffree)
114+
.field("f_syncwrites", &self.f_syncwrites)
115+
.field("f_asyncwrites", &self.f_asyncwrites)
116+
.field("f_syncreads", &self.f_syncreads)
117+
.field("f_asyncreads", &self.f_asyncreads)
118+
.field("f_namemax", &self.f_namemax)
119+
.field("f_owner", &self.f_owner)
120+
.field("f_fsid", &self.f_fsid)
121+
.field("f_fstypename", &self.f_fstypename)
122+
.field("f_mntfromname", &&self.f_mntfromname[..])
123+
.field("f_mntonname", &&self.f_mntonname[..])
124+
.finish()
125+
}
126+
}
127+
impl ::hash::Hash for statfs {
128+
fn hash<H: ::hash::Hasher>(&self, state: &mut H) {
129+
self.f_version.hash(state);
130+
self.f_type.hash(state);
131+
self.f_flags.hash(state);
132+
self.f_bsize.hash(state);
133+
self.f_iosize.hash(state);
134+
self.f_blocks.hash(state);
135+
self.f_bfree.hash(state);
136+
self.f_bavail.hash(state);
137+
self.f_files.hash(state);
138+
self.f_ffree.hash(state);
139+
self.f_syncwrites.hash(state);
140+
self.f_asyncwrites.hash(state);
141+
self.f_syncreads.hash(state);
142+
self.f_asyncreads.hash(state);
143+
self.f_namemax.hash(state);
144+
self.f_owner.hash(state);
145+
self.f_fsid.hash(state);
146+
self.f_charspare.hash(state);
147+
self.f_fstypename.hash(state);
148+
self.f_mntfromname.hash(state);
149+
self.f_mntonname.hash(state);
150+
}
151+
}
152+
153+
impl PartialEq for dirent {
154+
fn eq(&self, other: &dirent) -> bool {
155+
self.d_fileno == other.d_fileno
156+
&& self.d_off == other.d_off
157+
&& self.d_reclen == other.d_reclen
158+
&& self.d_type == other.d_type
159+
&& self.d_namlen == other.d_namlen
160+
&& self
161+
.d_name[..self.d_namlen as _]
162+
.iter()
163+
.zip(other.d_name.iter())
164+
.all(|(a,b)| a == b)
165+
}
166+
}
167+
impl Eq for dirent {}
168+
impl ::fmt::Debug for dirent {
169+
fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result {
170+
f.debug_struct("dirent")
171+
.field("d_fileno", &self.d_fileno)
172+
.field("d_off", &self.d_off)
173+
.field("d_reclen", &self.d_reclen)
174+
.field("d_type", &self.d_type)
175+
.field("d_namlen", &self.d_namlen)
176+
.field("d_name", &&self.d_name[..self.d_namlen as _])
177+
.finish()
178+
}
179+
}
180+
impl ::hash::Hash for dirent {
181+
fn hash<H: ::hash::Hasher>(&self, state: &mut H) {
182+
self.d_fileno.hash(state);
183+
self.d_off.hash(state);
184+
self.d_reclen.hash(state);
185+
self.d_type.hash(state);
186+
self.d_namlen.hash(state);
187+
self.d_name[..self.d_namlen as _].hash(state);
188+
}
189+
}
190+
}
191+
}
192+
193+
pub const F_ADD_SEALS: ::c_int = 19;
194+
pub const F_GET_SEALS: ::c_int = 20;
195+
pub const F_SEAL_SEAL: ::c_int = 0x0001;
196+
pub const F_SEAL_SHRINK: ::c_int = 0x0002;
197+
pub const F_SEAL_GROW: ::c_int = 0x0004;
198+
pub const F_SEAL_WRITE: ::c_int = 0x0008;
199+
200+
pub const GRND_NONBLOCK: ::c_uint = 0x1;
201+
pub const GRND_RANDOM: ::c_uint = 0x2;
202+
203+
pub const RAND_MAX: ::c_int = 0x7fff_ffff;
204+
205+
pub const SO_DOMAIN: ::c_int = 0x1019;
206+
207+
pub const EINTEGRITY: ::c_int = 97;
208+
pub const ELAST: ::c_int = 97;
209+
pub const GRND_INSECURE: ::c_uint = 0x4;
210+
211+
extern "C" {
212+
pub fn aio_readv(aiocbp: *mut ::aiocb) -> ::c_int;
213+
pub fn aio_writev(aiocbp: *mut ::aiocb) -> ::c_int;
214+
pub fn setgrent();
215+
pub fn mprotect(
216+
addr: *mut ::c_void,
217+
len: ::size_t,
218+
prot: ::c_int,
219+
) -> ::c_int;
220+
pub fn freelocale(loc: ::locale_t);
221+
pub fn msgrcv(
222+
msqid: ::c_int,
223+
msgp: *mut ::c_void,
224+
msgsz: ::size_t,
225+
msgtyp: ::c_long,
226+
msgflg: ::c_int,
227+
) -> ::ssize_t;
228+
pub fn clock_nanosleep(
229+
clk_id: ::clockid_t,
230+
flags: ::c_int,
231+
rqtp: *const ::timespec,
232+
rmtp: *mut ::timespec,
233+
) -> ::c_int;
234+
235+
pub fn fdatasync(fd: ::c_int) -> ::c_int;
236+
237+
pub fn getrandom(
238+
buf: *mut ::c_void,
239+
buflen: ::size_t,
240+
flags: ::c_uint,
241+
) -> ::ssize_t;
242+
}
243+
244+
cfg_if! {
245+
if #[cfg(any(target_arch = "x86_64",
246+
target_arch = "aarch64"))] {
247+
mod b64;
248+
pub use self::b64::*;
249+
}
250+
}

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

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -335,14 +335,6 @@ pub const EXTATTR_NAMESPACE_EMPTY: ::c_int = 0;
335335
pub const EXTATTR_NAMESPACE_USER: ::c_int = 1;
336336
pub const EXTATTR_NAMESPACE_SYSTEM: ::c_int = 2;
337337

338-
cfg_if! {
339-
if #[cfg(any(freebsd10, freebsd11, freebsd12))] {
340-
pub const RAND_MAX: ::c_int = 0x7fff_fffd;
341-
} else {
342-
pub const RAND_MAX: ::c_int = 0x7fff_ffff;
343-
}
344-
}
345-
346338
pub const PTHREAD_STACK_MIN: ::size_t = MINSIGSTKSZ;
347339
pub const PTHREAD_MUTEX_ADAPTIVE_NP: ::c_int = 4;
348340
pub const SIGSTKSZ: ::size_t = MINSIGSTKSZ + 32768;
@@ -1539,10 +1531,10 @@ extern "C" {
15391531
}
15401532

15411533
cfg_if! {
1542-
if #[cfg(freebsd12)] {
1543-
mod freebsd12;
1544-
pub use self::freebsd12::*;
1545-
} else if #[cfg(freebsd13)] {
1534+
if #[cfg(freebsd13)] {
1535+
mod freebsd13;
1536+
pub use self::freebsd13::*;
1537+
} else if #[cfg(freebsd12)] {
15461538
mod freebsd12;
15471539
pub use self::freebsd12::*;
15481540
} else if #[cfg(any(freebsd10, freebsd11))] {

0 commit comments

Comments
 (0)