57 lines
1.3 KiB
Rust
57 lines
1.3 KiB
Rust
|
use sc::*;
|
||
|
use std::{io, ffi::CString};
|
||
|
|
||
|
mod mntent;
|
||
|
mod mntentries;
|
||
|
mod mntflags;
|
||
|
|
||
|
pub use self::{
|
||
|
mntent::MntEntry,
|
||
|
mntentries::MntEntries,
|
||
|
mntflags::{Flags as MntFlags, ParseFlagsError},
|
||
|
};
|
||
|
|
||
|
/// Wraps the Linux SYS_mount syscall in a nicer interface
|
||
|
pub fn mount(
|
||
|
dev: &str,
|
||
|
mountpoint: &str,
|
||
|
fstype: &str,
|
||
|
flags: u32,
|
||
|
opts: Option<&str>,
|
||
|
) -> io::Result<()> {
|
||
|
let ret = unsafe {
|
||
|
if let Some(opts) = opts {
|
||
|
syscall!(
|
||
|
MOUNT,
|
||
|
CString::new(dev)?.as_ptr(),
|
||
|
CString::new(mountpoint)?.as_ptr(),
|
||
|
CString::new(fstype)?.as_ptr(),
|
||
|
flags as usize,
|
||
|
CString::new(opts)?.as_ptr()
|
||
|
)
|
||
|
} else {
|
||
|
syscall!(
|
||
|
MOUNT,
|
||
|
CString::new(dev)?.as_ptr(),
|
||
|
CString::new(mountpoint)?.as_ptr(),
|
||
|
CString::new(fstype)?.as_ptr(),
|
||
|
flags as usize
|
||
|
)
|
||
|
}
|
||
|
};
|
||
|
if ret == 0 {
|
||
|
Ok(())
|
||
|
} else {
|
||
|
Err(io::Error::last_os_error())
|
||
|
}
|
||
|
}
|
||
|
|
||
|
pub fn swapon(dev: &str, flags: usize) -> io::Result<()> {
|
||
|
let ret = unsafe { syscall!(SWAPON, CString::new(dev)?.as_ptr(), flags) };
|
||
|
if ret == 0 {
|
||
|
Ok(())
|
||
|
} else {
|
||
|
Err(io::Error::last_os_error())
|
||
|
}
|
||
|
}
|