Skip to content

Add constants and types for nsfs ioctls #4436

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 4, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 15 additions & 6 deletions libc-test/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3825,6 +3825,7 @@ fn test_linux(target: &str) {
"linux/netfilter_ipv6.h",
"linux/netfilter_ipv6/ip6_tables.h",
"linux/netlink.h",
"linux/nsfs.h",
"linux/openat2.h",
// FIXME(linux): some items require Linux >= 5.6:
"linux/ptp_clock.h",
Expand Down Expand Up @@ -4118,6 +4119,9 @@ fn test_linux(target: &str) {
// FIXME(linux): Requires >= 6.12 kernel headers.
"dmabuf_cmsg" | "dmabuf_token" => true,

// FIXME(linux): Requires >= 6.12 kernel headers.
"mnt_ns_info" => true,

// FIXME(linux): Requires >= 6.4 kernel headers.
"ptrace_sud_config" => true,

Expand Down Expand Up @@ -4516,6 +4520,11 @@ fn test_linux(target: &str) {
true
}

// FIXME(linux): Requires >= 6.11 kernel headers.
"NS_GET_MNTNS_ID" | "NS_GET_PID_FROM_PIDNS" | "NS_GET_TGID_FROM_PIDNS" | "NS_GET_PID_IN_PIDNS" | "NS_GET_TGID_IN_PIDNS" => true,
// FIXME(linux): Requires >= 6.12 kernel headers.
"MNT_NS_INFO_SIZE_VER0" | "NS_MNT_GET_INFO" | "NS_MNT_GET_NEXT" | "NS_MNT_GET_PREV" => true,

// FIXME(linux): Requires >= 6.6 kernel headers.
"SYS_fchmodat2" => true,

Expand Down Expand Up @@ -4868,8 +4877,8 @@ fn test_linux_like_apis(target: &str) {
"strerror_r" => false,
_ => true,
})
.skip_const(|_| true)
.skip_struct(|_| true);
.skip_const(|_| true)
.skip_struct(|_| true);
cfg.generate(src_hotfix_dir().join("lib.rs"), "linux_strerror_r.rs");
}

Expand Down Expand Up @@ -4943,10 +4952,10 @@ fn test_linux_like_apis(target: &str) {
.skip_const(|_| true)
.skip_struct(|_| true)
.skip_const(move |name| match name {
"IPV6_FLOWINFO"
| "IPV6_FLOWLABEL_MGR"
| "IPV6_FLOWINFO_SEND"
| "IPV6_FLOWINFO_FLOWLABEL"
"IPV6_FLOWINFO"
| "IPV6_FLOWLABEL_MGR"
| "IPV6_FLOWINFO_SEND"
| "IPV6_FLOWINFO_FLOWLABEL"
| "IPV6_FLOWINFO_PRIORITY" => false,
_ => true,
})
Expand Down
13 changes: 13 additions & 0 deletions libc-test/semver/linux.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1667,6 +1667,7 @@ MMAP_PAGE_ZERO
MNT_DETACH
MNT_EXPIRE
MNT_FORCE
MNT_NS_INFO_SIZE_VER0
MODULE_INIT_IGNORE_MODVERSIONS
MODULE_INIT_IGNORE_VERMAGIC
MON_1
Expand Down Expand Up @@ -2022,6 +2023,18 @@ NLM_F_REQUEST
NLM_F_ROOT
NOEXPR
NOSTR
NS_GET_MNTNS_ID
NS_GET_NSTYPE
NS_GET_OWNER_UID
NS_GET_PARENT
NS_GET_PID_FROM_PIDNS
NS_GET_PID_IN_PIDNS
NS_GET_TGID_FROM_PIDNS
NS_GET_TGID_IN_PIDNS
NS_GET_USERNS
NS_MNT_GET_INFO
NS_MNT_GET_NEXT
NS_MNT_GET_PREV
NTF_PROXY
NTF_ROUTER
NTF_SELF
Expand Down
28 changes: 28 additions & 0 deletions src/unix/linux_like/linux/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1376,6 +1376,13 @@ s! {
pub userns_fd: crate::__u64,
}

// linux/nsfs.h
pub struct mnt_ns_info {
pub size: crate::__u32,
pub nr_mounts: crate::__u32,
pub mnt_ns_id: crate::__u64,
}

// linux/pidfd.h

pub struct pidfd_info {
Expand Down Expand Up @@ -3172,6 +3179,27 @@ pub const MREMAP_MAYMOVE: c_int = 1;
pub const MREMAP_FIXED: c_int = 2;
pub const MREMAP_DONTUNMAP: c_int = 4;

// linux/nsfs.h
const NSIO: c_uint = 0xb7;

pub const NS_GET_USERNS: c_uint = _IO(NSIO, 0x1);
pub const NS_GET_PARENT: c_uint = _IO(NSIO, 0x2);
pub const NS_GET_NSTYPE: c_uint = _IO(NSIO, 0x3);
pub const NS_GET_OWNER_UID: c_uint = _IO(NSIO, 0x4);

pub const NS_GET_MNTNS_ID: c_uint = _IOR::<__u64>(NSIO, 0x5);

pub const NS_GET_PID_FROM_PIDNS: c_uint = _IOR::<c_int>(NSIO, 0x6);
pub const NS_GET_TGID_FROM_PIDNS: c_uint = _IOR::<c_int>(NSIO, 0x7);
pub const NS_GET_PID_IN_PIDNS: c_uint = _IOR::<c_int>(NSIO, 0x8);
pub const NS_GET_TGID_IN_PIDNS: c_uint = _IOR::<c_int>(NSIO, 0x9);

pub const MNT_NS_INFO_SIZE_VER0: c_uint = 16;

pub const NS_MNT_GET_INFO: c_uint = _IOR::<mnt_ns_info>(NSIO, 10);
pub const NS_MNT_GET_NEXT: c_uint = _IOR::<mnt_ns_info>(NSIO, 11);
pub const NS_MNT_GET_PREV: c_uint = _IOR::<mnt_ns_info>(NSIO, 12);

// linux/pidfd.h
pub const PIDFD_NONBLOCK: c_uint = O_NONBLOCK as c_uint;
pub const PIDFD_THREAD: c_uint = O_EXCL as c_uint;
Expand Down
Loading