use sc::*; use std::{ffi::CString, io}; 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()) } } pub fn swapoff(path: &str) -> io::Result<()> { let ret = unsafe { syscall!(SWAPOFF, CString::new(path)?.as_ptr()) }; if ret == 0 { Ok(()) } else { Err(io::Error::last_os_error()) } } pub fn umount(special: &str, flags: u32) -> io::Result<()> { let ret = unsafe { syscall!(UMOUNT2, CString::new(special)?.as_ptr(), flags) }; if ret == 0 { Ok(()) } else { Err(io::Error::last_os_error()) } }