ksud: Add userspace cli to load module

This commit is contained in:
tiann
2023-01-04 14:41:55 +08:00
parent 3f9b1cb74b
commit 35aae8b0eb
13 changed files with 1554 additions and 0 deletions

View File

@@ -0,0 +1,24 @@
use std::path::Path;
use anyhow::{Result, ensure};
use subprocess::Exec;
pub fn mount_image(src: &str, target: &str) -> Result<()> {
let result = Exec::shell(format!("mount {} {}", src, target)).join()?;
ensure!(result.success(), "mount: {} -> {} failed.", src, target);
Ok(())
}
pub fn umount_dir(src: &str) -> Result<()> {
let result = Exec::shell(format!("umount {}", src)).join()?;
ensure!(result.success(), "umount: {} failed", src);
Ok(())
}
pub fn ensure_clean_dir(dir: &str) -> Result<()> {
let path = Path::new(dir);
if path.exists() {
std::fs::remove_dir_all(path)?;
}
Ok(std::fs::create_dir_all(path)?)
}