Skip to content

Commit

Permalink
mount: Factor out a run_findmnt helper
Browse files Browse the repository at this point in the history
Prep for adding more API.

Signed-off-by: Colin Walters <[email protected]>
  • Loading branch information
cgwalters committed Feb 27, 2024
1 parent b7f70be commit a9c5b02
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions lib/src/mount.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,17 @@ pub(crate) struct Findmnt {
pub(crate) filesystems: Vec<Filesystem>,
}

#[context("Inspecting filesystem {path}")]
pub(crate) fn inspect_filesystem(path: &Utf8Path) -> Result<Filesystem> {
fn run_findmnt(args: &[&str], path: &str) -> Result<Filesystem> {
let desc = format!("Inspecting {path}");
let o = Task::new(desc, "findmnt")
.args([
"-J",
"-v",
// If you change this you probably also want to change the Filesystem struct above
"--output=SOURCE,FSTYPE,OPTIONS,UUID",
path.as_str(),
])
.args(args)
.arg(path)
.quiet()
.read()?;
let o: Findmnt = serde_json::from_str(&o).context("Parsing findmnt output")?;
Expand All @@ -42,6 +42,13 @@ pub(crate) fn inspect_filesystem(path: &Utf8Path) -> Result<Filesystem> {
.ok_or_else(|| anyhow!("findmnt returned no data for {path}"))
}

#[context("Inspecting filesystem {path}")]
/// Inspect a target which must be a mountpoint root - it is an error
/// if the target is not the mount root.
pub(crate) fn inspect_filesystem(path: &Utf8Path) -> Result<Filesystem> {
run_findmnt(&["--mountpoint"], path.as_str())
}

/// Mount a device to the target path.
pub(crate) fn mount(dev: &str, target: &Utf8Path) -> Result<()> {
Task::new_and_run(
Expand Down

0 comments on commit a9c5b02

Please sign in to comment.