Skip to content
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

Add FSCONFIG_CMD_CREATE_EXCL #1139

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ once_cell = { version = "1.5.2", optional = true }
# libc backend can be selected via adding `--cfg=rustix_use_libc` to
# `RUSTFLAGS` or enabling the `use-libc` cargo feature.
[target.'cfg(all(not(rustix_use_libc), not(miri), target_os = "linux", target_endian = "little", any(target_arch = "arm", all(target_arch = "aarch64", target_pointer_width = "64"), target_arch = "riscv64", all(rustix_use_experimental_asm, target_arch = "powerpc64"), all(rustix_use_experimental_asm, target_arch = "mips"), all(rustix_use_experimental_asm, target_arch = "mips32r6"), all(rustix_use_experimental_asm, target_arch = "mips64"), all(rustix_use_experimental_asm, target_arch = "mips64r6"), target_arch = "x86", all(target_arch = "x86_64", target_pointer_width = "64"))))'.dependencies]
linux-raw-sys = { version = "0.4.14", default-features = false, features = ["general", "errno", "ioctl", "no_std", "elf"] }
linux-raw-sys = { version = "0.6.5", default-features = false, features = ["general", "errno", "ioctl", "no_std", "elf"] }
libc_errno = { package = "errno", version = "0.3.8", default-features = false, optional = true }
libc = { version = "0.2.156", default-features = false, optional = true }

Expand Down
14 changes: 14 additions & 0 deletions src/backend/libc/mount/syscalls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -270,3 +270,17 @@ pub(crate) fn fsconfig_reconfigure(fs_fd: BorrowedFd<'_>) -> io::Result<()> {
))
}
}

#[cfg(linux_kernel)]
#[cfg(feature = "mount")]
pub(crate) fn fsconfig_create_excl(fs_fd: BorrowedFd<'_>) -> io::Result<()> {
unsafe {
ret(fsconfig(
borrowed_fd(fs_fd),
super::types::FsConfigCmd::CreateExclusive as _,
null(),
null(),
0,
))
}
}
3 changes: 3 additions & 0 deletions src/backend/libc/mount/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,9 @@ pub(crate) enum FsConfigCmd {

/// `FSCONFIG_CMD_RECONFIGURE`
Reconfigure = 7,

/// `FSCONFIG_CMD_CREATE_EXCL`
CreateExclusive = 8,
}

#[cfg(feature = "mount")]
Expand Down
15 changes: 15 additions & 0 deletions src/backend/linux_raw/mount/syscalls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -237,3 +237,18 @@ pub(crate) fn fsconfig_reconfigure(fs_fd: BorrowedFd<'_>) -> io::Result<()> {
))
}
}

#[cfg(feature = "mount")]
#[inline]
pub(crate) fn fsconfig_create_excl(fs_fd: BorrowedFd<'_>) -> io::Result<()> {
unsafe {
ret(syscall_readonly!(
__NR_fsconfig,
fs_fd,
super::types::FsConfigCmd::CreateExclusive,
zero(),
zero(),
zero()
))
}
}
3 changes: 3 additions & 0 deletions src/backend/linux_raw/mount/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,9 @@ pub(crate) enum FsConfigCmd {

/// `FSCONFIG_CMD_RECONFIGURE`
Reconfigure = linux_raw_sys::general::fsconfig_command::FSCONFIG_CMD_RECONFIGURE as u32,

/// `FSCONFIG_CMD_CREATE_EXCL`
CreateExclusive = linux_raw_sys::general::fsconfig_command::FSCONFIG_CMD_CREATE_EXCL as u32,
}

#[cfg(feature = "mount")]
Expand Down
12 changes: 12 additions & 0 deletions src/mount/fsopen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -217,3 +217,15 @@ pub fn fsconfig_create(fs_fd: BorrowedFd<'_>) -> io::Result<()> {
pub fn fsconfig_reconfigure(fs_fd: BorrowedFd<'_>) -> io::Result<()> {
backend::mount::syscalls::fsconfig_reconfigure(fs_fd)
}

/// `fsconfig(fs_fd, FSCONFIG_CMD_CREATE_EXCL, key, NULL, 0)`
///
/// # References
/// - [Unfinished draft]
///
/// [Unfinished draft]: https://github.com/sunfishcode/linux-mount-api-documentation/blob/main/fsconfig.md
#[inline]
#[doc(alias = "fsconfig")]
pub fn fsconfig_create_exclusive(fs_fd: BorrowedFd<'_>) -> io::Result<()> {
backend::mount::syscalls::fsconfig_create_excl(fs_fd)
}
Loading