Skip to content

Commit ccbc503

Browse files
yoheiuedacgwalters
authored andcommitted
mount: Add inspect_filesystem_by_uuid
This patch adds a new function that identifies a filesystem by partition UUID. Signed-off-by: Yohei Ueda <[email protected]> Signed-off-by: Colin Walters <[email protected]>
1 parent 8e5d76b commit ccbc503

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

lib/src/install.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1688,7 +1688,9 @@ fn test_gather_root_args() {
16881688
// A basic filesystem using a UUID
16891689
let inspect = Filesystem {
16901690
source: "/dev/vda4".into(),
1691+
target: "/".into(),
16911692
fstype: "xfs".into(),
1693+
maj_min: "252:4".into(),
16921694
options: "rw".into(),
16931695
uuid: Some("965eb3c7-5a3f-470d-aaa2-1bcf04334bc6".into()),
16941696
};

lib/src/mount.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ use crate::task::Task;
1212
pub(crate) struct Filesystem {
1313
// Note if you add an entry to this list, you need to change the --output invocation below too
1414
pub(crate) source: String,
15+
pub(crate) target: String,
16+
#[serde(rename = "maj:min")]
17+
pub(crate) maj_min: String,
1518
pub(crate) fstype: String,
1619
pub(crate) options: String,
1720
pub(crate) uuid: Option<String>,
@@ -29,7 +32,7 @@ fn run_findmnt(args: &[&str], path: &str) -> Result<Filesystem> {
2932
"-J",
3033
"-v",
3134
// If you change this you probably also want to change the Filesystem struct above
32-
"--output=SOURCE,FSTYPE,OPTIONS,UUID",
35+
"--output=SOURCE,TARGET,MAJ:MIN,FSTYPE,OPTIONS,UUID",
3336
])
3437
.args(args)
3538
.arg(path)
@@ -49,6 +52,12 @@ pub(crate) fn inspect_filesystem(path: &Utf8Path) -> Result<Filesystem> {
4952
run_findmnt(&["--mountpoint"], path.as_str())
5053
}
5154

55+
#[context("Inspecting filesystem by UUID {uuid}")]
56+
/// Inspect a filesystem by partition UUID
57+
pub(crate) fn inspect_filesystem_by_uuid(uuid: &str) -> Result<Filesystem> {
58+
run_findmnt(&["--source"], &(format!("UUID={uuid}")))
59+
}
60+
5261
/// Mount a device to the target path.
5362
pub(crate) fn mount(dev: &str, target: &Utf8Path) -> Result<()> {
5463
Task::new_and_run(

0 commit comments

Comments
 (0)