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