From ded2ae1785935fb1da631ba4790a45de76d8e2f1 Mon Sep 17 00:00:00 2001 From: Rain Date: Fri, 20 Sep 2024 03:05:09 +0000 Subject: [PATCH] [solarish/freebsd] add a few missing constants and functions Add: * `O_RSYNC` on Solaris and illumos, based on the source code at [1]. This was added a long time ago, and the blame indicates that the constant is shared with Solaris. * `POLLRDHUP` on illumos, based on the source code at [2]. This was also added a long time ago, but is not in the man page (I'll track that down separately, but it has been supported and used for many years). I cannot verify whether this is in Solaris. * `POLLRDHUP` on FreeBSD, based on this man page [3]. This was added in 2021 [4]. * `posix_fadvise` on illumos, based on this man page [5]. The related constants are on GitHub [6]. `posix_fadvise` seems to exist on Solaris [7] but I haven't been able to verify any of the constants so I've left it out of this PR. * `posix_fallocate` on illumos (man page [8]) and Solaris (man page [9]). [1]: https://github.com/illumos/illumos-gate/blame/f389e29fb4a3b48598f4e25151eb570247c6deed/usr/src/uts/common/sys/fcntl.h#L70 [2]: https://github.com/illumos/illumos-gate/blame/f389e29fb4a3b48598f4e25151eb570247c6deed/usr/src/uts/common/sys/poll.h#L66 [3]: https://man.freebsd.org/cgi/man.cgi?poll [4]: https://cgit.freebsd.org/src/commit/sys/sys/poll.h?id=3aaaa2efde896e19d229ee2cf09fe7e6ab0fbf6e [5]: https://illumos.org/man/3C/posix_fadvise [6]: https://github.com/illumos/illumos-gate/blob/f389e29fb4a3b48598f4e25151eb570247c6deed/usr/src/uts/common/sys/fcntl.h#L407-L412 [7]: https://docs.oracle.com/cd/E88353_01/html/E37843/posix-fadvise-3c.html [8]: https://illumos.org/man/3C/posix_fallocate [9]: https://docs.oracle.com/cd/E88353_01/html/E37843/posix-fallocate-3c.html (backport ) (cherry picked from commit 52e81a8c2abf553b3319169ccc8d2e95a0e98e92) --- libc-test/semver/freebsd.txt | 1 + libc-test/semver/illumos.txt | 10 ++++++++++ src/unix/bsd/freebsdlike/freebsd/mod.rs | 1 + src/unix/solarish/illumos.rs | 10 ++++++++++ src/unix/solarish/mod.rs | 2 ++ 5 files changed, 24 insertions(+) diff --git a/libc-test/semver/freebsd.txt b/libc-test/semver/freebsd.txt index ed4da63788e26..d4b53860b5a53 100644 --- a/libc-test/semver/freebsd.txt +++ b/libc-test/semver/freebsd.txt @@ -1023,6 +1023,7 @@ PL_FLAG_SI PM_STR POLLINIGNEOF POLLRDBAND +POLLRDHUP POLLRDNORM POLLSTANDARD POLLWRBAND diff --git a/libc-test/semver/illumos.txt b/libc-test/semver/illumos.txt index 02cf4e75d688d..64c25d4b4f969 100644 --- a/libc-test/semver/illumos.txt +++ b/libc-test/semver/illumos.txt @@ -1,3 +1,13 @@ +O_RSYNC +POLLRDHUP +POSIX_FADV_DONTNEED +POSIX_FADV_NOREUSE +POSIX_FADV_NORMAL +POSIX_FADV_RANDOM +POSIX_FADV_SEQUENTIAL +POSIX_FADV_WILLNEED +posix_fadvise +posix_fallocate pthread_attr_get_np pthread_attr_getstackaddr pthread_attr_setstack diff --git a/src/unix/bsd/freebsdlike/freebsd/mod.rs b/src/unix/bsd/freebsdlike/freebsd/mod.rs index f8be7be51f325..a15987df10775 100644 --- a/src/unix/bsd/freebsdlike/freebsd/mod.rs +++ b/src/unix/bsd/freebsdlike/freebsd/mod.rs @@ -2894,6 +2894,7 @@ pub const POSIX_FADV_DONTNEED: ::c_int = 4; pub const POSIX_FADV_NOREUSE: ::c_int = 5; pub const POLLINIGNEOF: ::c_short = 0x2000; +pub const POLLRDHUP: ::c_short = 0x4000; pub const EVFILT_READ: i16 = -1; pub const EVFILT_WRITE: i16 = -2; diff --git a/src/unix/solarish/illumos.rs b/src/unix/solarish/illumos.rs index 6e96272352bee..614fd12eb07eb 100644 --- a/src/unix/solarish/illumos.rs +++ b/src/unix/solarish/illumos.rs @@ -28,6 +28,8 @@ pub const EFD_SEMAPHORE: ::c_int = 0x1; pub const EFD_NONBLOCK: ::c_int = 0x800; pub const EFD_CLOEXEC: ::c_int = 0x80000; +pub const POLLRDHUP: ::c_short = 0x4000; + pub const TCP_KEEPIDLE: ::c_int = 34; pub const TCP_KEEPCNT: ::c_int = 35; pub const TCP_KEEPINTVL: ::c_int = 36; @@ -56,6 +58,13 @@ pub const SOL_FILTER: ::c_int = 0xfffc; pub const MADV_PURGE: ::c_int = 9; +pub const POSIX_FADV_NORMAL: ::c_int = 0; +pub const POSIX_FADV_RANDOM: ::c_int = 1; +pub const POSIX_FADV_SEQUENTIAL: ::c_int = 2; +pub const POSIX_FADV_WILLNEED: ::c_int = 3; +pub const POSIX_FADV_DONTNEED: ::c_int = 4; +pub const POSIX_FADV_NOREUSE: ::c_int = 5; + pub const B1000000: ::speed_t = 24; pub const B1152000: ::speed_t = 25; pub const B1500000: ::speed_t = 26; @@ -96,6 +105,7 @@ extern "C" { stackaddr: *mut ::c_void, ) -> ::c_int; + pub fn posix_fadvise(fd: ::c_int, offset: ::off_t, len: ::off_t, advice: ::c_int) -> ::c_int; pub fn preadv(fd: ::c_int, iov: *const ::iovec, iovcnt: ::c_int, offset: ::off_t) -> ::ssize_t; pub fn pwritev(fd: ::c_int, iov: *const ::iovec, iovcnt: ::c_int, offset: ::off_t) -> ::ssize_t; diff --git a/src/unix/solarish/mod.rs b/src/unix/solarish/mod.rs index 3afd3f37840a0..1cc6c429bc2d1 100644 --- a/src/unix/solarish/mod.rs +++ b/src/unix/solarish/mod.rs @@ -1307,6 +1307,7 @@ pub const O_RDWR: ::c_int = 2; pub const O_NDELAY: ::c_int = 0x04; pub const O_APPEND: ::c_int = 8; pub const O_DSYNC: ::c_int = 0x40; +pub const O_RSYNC: ::c_int = 0x8000; pub const O_CREAT: ::c_int = 256; pub const O_EXCL: ::c_int = 1024; pub const O_NOCTTY: ::c_int = 2048; @@ -2846,6 +2847,7 @@ extern "C" { #[cfg_attr(target_os = "illumos", link_name = "_globfree_ext")] pub fn globfree(pglob: *mut ::glob_t); + pub fn posix_fallocate(fd: ::c_int, offset: ::off_t, len: ::off_t) -> ::c_int; pub fn posix_madvise(addr: *mut ::c_void, len: ::size_t, advice: ::c_int) -> ::c_int; pub fn shmat(shmid: ::c_int, shmaddr: *const ::c_void, shmflg: ::c_int) -> *mut ::c_void;