Skip to content

Commit

Permalink
Add FSCONFIG_CMD_CREATE_EXCL (#1139)
Browse files Browse the repository at this point in the history
Introduced by Linux 6.6
  • Loading branch information
rusty-snake authored Jan 30, 2025
1 parent b77cbc8 commit 237b8ac
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 0 deletions.
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 @@ -146,6 +146,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 @@ -144,6 +144,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)
}

0 comments on commit 237b8ac

Please sign in to comment.