Skip to content

Commit

Permalink
Auto merge of #2477 - Fanael:linux-openat2, r=JohnTitor
Browse files Browse the repository at this point in the history
linux: Add open_how and related flags

This makes `openat2` usable.
  • Loading branch information
bors committed Nov 8, 2021
2 parents e43066f + 93e85a3 commit 84b3a7b
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 0 deletions.
5 changes: 5 additions & 0 deletions build.rs
Expand Up @@ -72,6 +72,11 @@ fn main() {
println!("cargo:rustc-cfg=libc_cfg_target_vendor");
}

// Rust >= 1.40 supports #[non_exhaustive].
if rustc_minor_ver >= 40 || rustc_dep_of_std {
println!("cargo:rustc-cfg=libc_non_exhaustive");
}

if rustc_minor_ver >= 51 || rustc_dep_of_std {
println!("cargo:rustc-cfg=libc_ptr_addr_of");
}
Expand Down
13 changes: 13 additions & 0 deletions libc-test/build.rs
Expand Up @@ -2689,6 +2689,8 @@ fn test_linux(target: &str) {
"linux/netfilter_ipv6.h",
"linux/netfilter_ipv6/ip6_tables.h",
"linux/netlink.h",
// FIXME: requires more recent kernel headers:
// "linux/openat2.h",
"linux/quota.h",
"linux/random.h",
"linux/reboot.h",
Expand Down Expand Up @@ -2830,6 +2832,9 @@ fn test_linux(target: &str) {
// Requires glibc 2.33 or newer.
"mallinfo2" => true,

// Might differ between kernel versions
"open_how" => true,

_ => false,
}
});
Expand Down Expand Up @@ -2972,6 +2977,14 @@ fn test_linux(target: &str) {
| "CLOSE_RANGE_UNSHARE"
| "CLOSE_RANGE_CLOEXEC" => true,

// FIXME: requires more recent kernel headers:
| "RESOLVE_BENEATH"
| "RESOLVE_CACHED"
| "RESOLVE_IN_ROOT"
| "RESOLVE_NO_MAGICLINKS"
| "RESOLVE_NO_SYMLINKS"
| "RESOLVE_NO_XDEV" => true,

// FIXME: Not currently available in headers on ARM, MIPS and musl.
"NETLINK_GET_STRICT_CHK" if arm || mips || musl => true,

Expand Down
7 changes: 7 additions & 0 deletions libc-test/semver/linux.txt
Expand Up @@ -1753,6 +1753,12 @@ RENAME_NOREPLACE
RENAME_WHITEOUT
REP_CNT
REP_MAX
RESOLVE_BENEATH
RESOLVE_CACHED
RESOLVE_IN_ROOT
RESOLVE_NO_MAGICLINKS
RESOLVE_NO_SYMLINKS
RESOLVE_NO_XDEV
RLIMIT_AS
RLIMIT_CORE
RLIMIT_CPU
Expand Down Expand Up @@ -2850,6 +2856,7 @@ nlmsgerr
nlmsghdr
off64_t
open64
open_how
open_memstream
openat
openat64
Expand Down
15 changes: 15 additions & 0 deletions src/unix/linux_like/linux/mod.rs
Expand Up @@ -1825,6 +1825,14 @@ pub const MFD_HUGETLB: ::c_uint = 0x0004;
pub const CLOSE_RANGE_UNSHARE: ::c_uint = 1 << 1;
pub const CLOSE_RANGE_CLOEXEC: ::c_uint = 1 << 2;

// linux/openat2.h
pub const RESOLVE_NO_XDEV: ::__u64 = 0x01;
pub const RESOLVE_NO_MAGICLINKS: ::__u64 = 0x02;
pub const RESOLVE_NO_SYMLINKS: ::__u64 = 0x04;
pub const RESOLVE_BENEATH: ::__u64 = 0x08;
pub const RESOLVE_IN_ROOT: ::__u64 = 0x10;
pub const RESOLVE_CACHED: ::__u64 = 0x20;

// these are used in the p_type field of Elf32_Phdr and Elf64_Phdr, which has
// the type Elf32Word and Elf64Word respectively. Luckily, both of those are u32
// so we can use that type here to avoid having to cast.
Expand Down Expand Up @@ -3945,3 +3953,10 @@ cfg_if! {
}
}
expand_align!();

cfg_if! {
if #[cfg(libc_non_exhaustive)] {
mod non_exhaustive;
pub use self::non_exhaustive::*;
}
}
9 changes: 9 additions & 0 deletions src/unix/linux_like/linux/non_exhaustive.rs
@@ -0,0 +1,9 @@
s! {
// linux/openat2.h
#[non_exhaustive]
pub struct open_how {
pub flags: ::__u64,
pub mode: ::__u64,
pub resolve: ::__u64,
}
}

0 comments on commit 84b3a7b

Please sign in to comment.