Use `errno` workspace crate for `mount` and `stat` workspace crates

This commit is contained in:
Nathan Fisher 2023-02-13 00:41:58 -05:00
parent 05ce5422c0
commit 83fcb52d80
5 changed files with 23 additions and 16 deletions

1
Cargo.lock generated
View File

@ -428,6 +428,7 @@ name = "mount"
version = "0.1.0"
dependencies = [
"blkid",
"errno 0.1.0",
"sc",
]

View File

@ -8,3 +8,7 @@ edition = "2021"
[dependencies]
blkid = "1.0"
sc = { workspace = true }
[dependencies.errno]
package = "errno"
path = "../errno"

View File

@ -1,5 +1,6 @@
use errno::Errno;
use sc::*;
use std::{ffi::CString, io};
use std::{ffi::CString, error::Error};
mod mntent;
mod mntentries;
@ -18,7 +19,7 @@ pub fn mount(
fstype: &str,
flags: u32,
opts: Option<&str>,
) -> io::Result<()> {
) -> Result<(), Box<dyn Error>> {
let ret = unsafe {
if let Some(opts) = opts {
syscall!(
@ -42,33 +43,33 @@ pub fn mount(
if ret == 0 {
Ok(())
} else {
Err(io::Error::last_os_error())
Err(Errno::from(ret).into())
}
}
pub fn swapon(dev: &str, flags: usize) -> io::Result<()> {
pub fn swapon(dev: &str, flags: usize) -> Result<(), Box<dyn Error>> {
let ret = unsafe { syscall!(SWAPON, CString::new(dev)?.as_ptr(), flags) };
if ret == 0 {
Ok(())
} else {
Err(io::Error::last_os_error())
Err(Errno::from(ret).into())
}
}
pub fn swapoff(path: &str) -> io::Result<()> {
pub fn swapoff(path: &str) -> Result<(), Box<dyn Error>> {
let ret = unsafe { syscall!(SWAPOFF, CString::new(path)?.as_ptr()) };
if ret == 0 {
Ok(())
} else {
Err(io::Error::last_os_error())
Err(Errno::from(ret).into())
}
}
pub fn umount(special: &str, flags: u32) -> io::Result<()> {
pub fn umount(special: &str, flags: u32) -> Result<(), Box<dyn Error>> {
let ret = unsafe { syscall!(UMOUNT2, CString::new(special)?.as_ptr(), flags) };
if ret == 0 {
Ok(())
} else {
Err(io::Error::last_os_error())
Err(Errno::from(ret).into())
}
}

View File

@ -10,7 +10,7 @@ use std::{
fs::File,
io::{self, BufRead, BufReader},
path::PathBuf,
str::FromStr,
str::FromStr, error::Error,
};
/// The information for a mount broken out into a struct
@ -26,7 +26,7 @@ pub struct MntEntry {
impl MntEntry {
/// Mount the mount specified by this entry
pub fn mount(&self) -> io::Result<()> {
pub fn mount(&self) -> Result<(), Box<dyn Error>> {
let dev = self.device()?;
let dev = dev.to_string_lossy();
let (flags, opts) = self

View File

@ -1,8 +1,9 @@
use errno::Errno;
use sc::*;
use std::{ffi::CString, io};
use std::{ffi::CString, error::Error};
#[inline(always)]
pub fn mknod(path: &str, mode: u32, dev: u64) -> io::Result<()> {
pub fn mknod(path: &str, mode: u32, dev: u64) -> Result<(), Box<dyn Error>> {
let ret = unsafe {
syscall!(
MKNODAT,
@ -15,12 +16,12 @@ pub fn mknod(path: &str, mode: u32, dev: u64) -> io::Result<()> {
if ret == 0 {
Ok(())
} else {
Err(io::Error::last_os_error())
Err(Errno::from(ret).into())
}
}
#[inline(always)]
pub fn mkfifo(path: &str, mode: u32) -> io::Result<()> {
pub fn mkfifo(path: &str, mode: u32) -> Result<(), Box<dyn Error>> {
let ret = unsafe {
syscall!(
MKNODAT,
@ -33,6 +34,6 @@ pub fn mkfifo(path: &str, mode: u32) -> io::Result<()> {
if ret == 0 {
Ok(())
} else {
Err(io::Error::last_os_error())
Err(Errno::from(ret).into())
}
}