Skip to content

Commit

Permalink
Remove incorrect mount API and allow null data arg (#1112)
Browse files Browse the repository at this point in the history
* Remove incorrect mount API

Signed-off-by: Alex Saveau <[email protected]>

* Address review comments

Signed-off-by: Alex Saveau <[email protected]>

---------

Signed-off-by: Alex Saveau <[email protected]>
  • Loading branch information
SUPERCILEX authored Feb 8, 2025
1 parent 3ae4069 commit 3cb6c90
Showing 1 changed file with 4 additions and 37 deletions.
41 changes: 4 additions & 37 deletions src/mount/mount_unmount.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,63 +14,30 @@ use crate::{backend, io};
///
/// [Linux]: https://man7.org/linux/man-pages/man2/mount.2.html
#[inline]
pub fn mount<Source: path::Arg, Target: path::Arg, Fs: path::Arg, Data: path::Arg>(
pub fn mount<'a, Source: path::Arg, Target: path::Arg, Fs: path::Arg>(
source: Source,
target: Target,
file_system_type: Fs,
flags: MountFlags,
data: Data,
data: impl Into<Option<&'a CStr>>,
) -> io::Result<()> {
source.into_with_c_str(|source| {
target.into_with_c_str(|target| {
file_system_type.into_with_c_str(|file_system_type| {
data.into_with_c_str(|data| {
option_into_with_c_str(data.into(), |data| {
backend::mount::syscalls::mount(
Some(source),
target,
Some(file_system_type),
MountFlagsArg(flags.bits()),
Some(data),
data,
)
})
})
})
})
}

/// `mount2(source, target, filesystemtype, mountflags, data)`
///
/// This is same as the [`mount`], except it adds support for the source,
/// target, and data being omitted, and the data is passed as a `CStr` rather
/// than a `path::Arg`.
///
/// # References
/// - [Linux]
///
/// [Linux]: https://man7.org/linux/man-pages/man2/mount.2.html
#[inline]
pub fn mount2<Source: path::Arg, Target: path::Arg, Fs: path::Arg>(
source: Option<Source>,
target: Target,
file_system_type: Option<Fs>,
flags: MountFlags,
data: Option<&CStr>,
) -> io::Result<()> {
option_into_with_c_str(source, |source| {
target.into_with_c_str(|target| {
option_into_with_c_str(file_system_type, |file_system_type| {
backend::mount::syscalls::mount(
source,
target,
file_system_type,
MountFlagsArg(flags.bits()),
data,
)
})
})
})
}

/// `mount(NULL, target, NULL, MS_REMOUNT | mountflags, data)`
///
/// # References
Expand Down

0 comments on commit 3cb6c90

Please sign in to comment.