Skip to content

Commit 84b3a7b

Browse files
committed
Auto merge of #2477 - Fanael:linux-openat2, r=JohnTitor
linux: Add open_how and related flags This makes `openat2` usable.
2 parents e43066f + 93e85a3 commit 84b3a7b

File tree

5 files changed

+49
-0
lines changed

5 files changed

+49
-0
lines changed

build.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,11 @@ fn main() {
7272
println!("cargo:rustc-cfg=libc_cfg_target_vendor");
7373
}
7474

75+
// Rust >= 1.40 supports #[non_exhaustive].
76+
if rustc_minor_ver >= 40 || rustc_dep_of_std {
77+
println!("cargo:rustc-cfg=libc_non_exhaustive");
78+
}
79+
7580
if rustc_minor_ver >= 51 || rustc_dep_of_std {
7681
println!("cargo:rustc-cfg=libc_ptr_addr_of");
7782
}

libc-test/build.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2689,6 +2689,8 @@ fn test_linux(target: &str) {
26892689
"linux/netfilter_ipv6.h",
26902690
"linux/netfilter_ipv6/ip6_tables.h",
26912691
"linux/netlink.h",
2692+
// FIXME: requires more recent kernel headers:
2693+
// "linux/openat2.h",
26922694
"linux/quota.h",
26932695
"linux/random.h",
26942696
"linux/reboot.h",
@@ -2830,6 +2832,9 @@ fn test_linux(target: &str) {
28302832
// Requires glibc 2.33 or newer.
28312833
"mallinfo2" => true,
28322834

2835+
// Might differ between kernel versions
2836+
"open_how" => true,
2837+
28332838
_ => false,
28342839
}
28352840
});
@@ -2972,6 +2977,14 @@ fn test_linux(target: &str) {
29722977
| "CLOSE_RANGE_UNSHARE"
29732978
| "CLOSE_RANGE_CLOEXEC" => true,
29742979

2980+
// FIXME: requires more recent kernel headers:
2981+
| "RESOLVE_BENEATH"
2982+
| "RESOLVE_CACHED"
2983+
| "RESOLVE_IN_ROOT"
2984+
| "RESOLVE_NO_MAGICLINKS"
2985+
| "RESOLVE_NO_SYMLINKS"
2986+
| "RESOLVE_NO_XDEV" => true,
2987+
29752988
// FIXME: Not currently available in headers on ARM, MIPS and musl.
29762989
"NETLINK_GET_STRICT_CHK" if arm || mips || musl => true,
29772990

libc-test/semver/linux.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1753,6 +1753,12 @@ RENAME_NOREPLACE
17531753
RENAME_WHITEOUT
17541754
REP_CNT
17551755
REP_MAX
1756+
RESOLVE_BENEATH
1757+
RESOLVE_CACHED
1758+
RESOLVE_IN_ROOT
1759+
RESOLVE_NO_MAGICLINKS
1760+
RESOLVE_NO_SYMLINKS
1761+
RESOLVE_NO_XDEV
17561762
RLIMIT_AS
17571763
RLIMIT_CORE
17581764
RLIMIT_CPU
@@ -2850,6 +2856,7 @@ nlmsgerr
28502856
nlmsghdr
28512857
off64_t
28522858
open64
2859+
open_how
28532860
open_memstream
28542861
openat
28552862
openat64

src/unix/linux_like/linux/mod.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1825,6 +1825,14 @@ pub const MFD_HUGETLB: ::c_uint = 0x0004;
18251825
pub const CLOSE_RANGE_UNSHARE: ::c_uint = 1 << 1;
18261826
pub const CLOSE_RANGE_CLOEXEC: ::c_uint = 1 << 2;
18271827

1828+
// linux/openat2.h
1829+
pub const RESOLVE_NO_XDEV: ::__u64 = 0x01;
1830+
pub const RESOLVE_NO_MAGICLINKS: ::__u64 = 0x02;
1831+
pub const RESOLVE_NO_SYMLINKS: ::__u64 = 0x04;
1832+
pub const RESOLVE_BENEATH: ::__u64 = 0x08;
1833+
pub const RESOLVE_IN_ROOT: ::__u64 = 0x10;
1834+
pub const RESOLVE_CACHED: ::__u64 = 0x20;
1835+
18281836
// these are used in the p_type field of Elf32_Phdr and Elf64_Phdr, which has
18291837
// the type Elf32Word and Elf64Word respectively. Luckily, both of those are u32
18301838
// so we can use that type here to avoid having to cast.
@@ -3945,3 +3953,10 @@ cfg_if! {
39453953
}
39463954
}
39473955
expand_align!();
3956+
3957+
cfg_if! {
3958+
if #[cfg(libc_non_exhaustive)] {
3959+
mod non_exhaustive;
3960+
pub use self::non_exhaustive::*;
3961+
}
3962+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
s! {
2+
// linux/openat2.h
3+
#[non_exhaustive]
4+
pub struct open_how {
5+
pub flags: ::__u64,
6+
pub mode: ::__u64,
7+
pub resolve: ::__u64,
8+
}
9+
}

0 commit comments

Comments
 (0)