Skip to content

Commit

Permalink
mount: Add inspect_filesystem_by_uuid
Browse files Browse the repository at this point in the history
This patch adds a new function that identifies a filesystem by
partition UUID.

Signed-off-by: Yohei Ueda <[email protected]>
  • Loading branch information
yoheiueda committed Jul 17, 2024
1 parent ec088bd commit b08f5c7
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
2 changes: 2 additions & 0 deletions lib/src/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1688,7 +1688,9 @@ fn test_gather_root_args() {
// A basic filesystem using a UUID
let inspect = Filesystem {
source: "/dev/vda4".into(),
target: "/".into(),
fstype: "xfs".into(),
maj_min: "252:4".into(),
options: "rw".into(),
uuid: Some("965eb3c7-5a3f-470d-aaa2-1bcf04334bc6".into()),
};
Expand Down
11 changes: 10 additions & 1 deletion lib/src/mount.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ use crate::task::Task;
pub(crate) struct Filesystem {
// Note if you add an entry to this list, you need to change the --output invocation below too
pub(crate) source: String,
pub(crate) target: String,
#[serde(rename = "maj:min")]
pub(crate) maj_min: String,
pub(crate) fstype: String,
pub(crate) options: String,
pub(crate) uuid: Option<String>,
Expand All @@ -29,7 +32,7 @@ fn run_findmnt(args: &[&str], path: &str) -> Result<Filesystem> {
"-J",
"-v",
// If you change this you probably also want to change the Filesystem struct above
"--output=SOURCE,FSTYPE,OPTIONS,UUID",
"--output=SOURCE,TARGET,MAJ:MIN,FSTYPE,OPTIONS,UUID",
])
.args(args)
.arg(path)
Expand All @@ -49,6 +52,12 @@ pub(crate) fn inspect_filesystem(path: &Utf8Path) -> Result<Filesystem> {
run_findmnt(&["--mountpoint"], path.as_str())
}

#[context("Inspecting filesystem by UUID {uuid}")]
/// Inspect a filesystem by partition UUID
pub(crate) fn inspect_filesystem_by_uuid(uuid: &str) -> Result<Filesystem> {
run_findmnt(&["--source"], &(format!("UUID={uuid}")))
}

/// 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 b08f5c7

Please sign in to comment.