Skip to content

Commit 2082741

Browse files
committed
mount: Make path optional in run_findmnt
This allows retrieving all mounts. Signed-off-by: ckyrouac <[email protected]>
1 parent 93b22f4 commit 2082741

File tree

1 file changed

+13
-14
lines changed

1 file changed

+13
-14
lines changed

mount/src/mount.rs

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -50,24 +50,23 @@ pub struct Findmnt {
5050
pub filesystems: Vec<Filesystem>,
5151
}
5252

53-
fn run_findmnt(args: &[&str], path: &str) -> Result<Findmnt> {
54-
let o: Findmnt = Command::new("findmnt")
55-
.args([
56-
"-J",
57-
"-v",
58-
// If you change this you probably also want to change the Filesystem struct above
59-
"--output=SOURCE,TARGET,MAJ:MIN,FSTYPE,OPTIONS,UUID",
60-
])
61-
.args(args)
62-
.arg(path)
63-
.log_debug()
64-
.run_and_parse_json()?;
53+
pub fn run_findmnt(args: &[&str], path: Option<&str>) -> Result<Findmnt> {
54+
let mut cmd = Command::new("findmnt");
55+
cmd.args([
56+
"-J",
57+
"-v",
58+
// If you change this you probably also want to change the Filesystem struct above
59+
"--output=SOURCE,TARGET,MAJ:MIN,FSTYPE,OPTIONS,UUID",
60+
])
61+
.args(args)
62+
.args(path);
63+
let o: Findmnt = cmd.log_debug().run_and_parse_json()?;
6564
Ok(o)
6665
}
6766

6867
// Retrieve a mounted filesystem from a device given a matching path
6968
fn findmnt_filesystem(args: &[&str], path: &str) -> Result<Filesystem> {
70-
let o = run_findmnt(args, path)?;
69+
let o = run_findmnt(args, Some(path))?;
7170
o.filesystems
7271
.into_iter()
7372
.next()
@@ -90,7 +89,7 @@ pub fn inspect_filesystem_by_uuid(uuid: &str) -> Result<Filesystem> {
9089
// Check if a specified device contains an already mounted filesystem
9190
// in the root mount namespace
9291
pub fn is_mounted_in_pid1_mountns(path: &str) -> Result<bool> {
93-
let o = run_findmnt(&["-N"], "1")?;
92+
let o = run_findmnt(&["-N"], Some("1"))?;
9493

9594
let mounted = o.filesystems.iter().any(|fs| is_source_mounted(path, fs));
9695

0 commit comments

Comments
 (0)