From a9c5b02d4f3fa6c9e1148cc0e8982b2bd19926ee Mon Sep 17 00:00:00 2001 From: Colin Walters Date: Tue, 27 Feb 2024 17:30:35 -0500 Subject: [PATCH] mount: Factor out a run_findmnt helper Prep for adding more API. Signed-off-by: Colin Walters --- lib/src/mount.rs | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/lib/src/mount.rs b/lib/src/mount.rs index 776796269..431d4f13f 100644 --- a/lib/src/mount.rs +++ b/lib/src/mount.rs @@ -22,8 +22,7 @@ pub(crate) struct Findmnt { pub(crate) filesystems: Vec, } -#[context("Inspecting filesystem {path}")] -pub(crate) fn inspect_filesystem(path: &Utf8Path) -> Result { +fn run_findmnt(args: &[&str], path: &str) -> Result { let desc = format!("Inspecting {path}"); let o = Task::new(desc, "findmnt") .args([ @@ -31,8 +30,9 @@ pub(crate) fn inspect_filesystem(path: &Utf8Path) -> Result { "-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")?; @@ -42,6 +42,13 @@ pub(crate) fn inspect_filesystem(path: &Utf8Path) -> Result { .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 { + 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(