@@ -50,24 +50,25 @@ 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+ if let Some ( path) = path {
63+ cmd. arg ( path) ;
64+ }
65+ let o: Findmnt = cmd. log_debug ( ) . run_and_parse_json ( ) ?;
6566 Ok ( o)
6667}
6768
6869// Retrieve a mounted filesystem from a device given a matching path
6970fn findmnt_filesystem ( args : & [ & str ] , path : & str ) -> Result < Filesystem > {
70- let o = run_findmnt ( args, path) ?;
71+ let o = run_findmnt ( args, Some ( path) ) ?;
7172 o. filesystems
7273 . into_iter ( )
7374 . next ( )
@@ -90,7 +91,7 @@ pub fn inspect_filesystem_by_uuid(uuid: &str) -> Result<Filesystem> {
9091// Check if a specified device contains an already mounted filesystem
9192// in the root mount namespace
9293pub fn is_mounted_in_pid1_mountns ( path : & str ) -> Result < bool > {
93- let o = run_findmnt ( & [ "-N" ] , "1" ) ?;
94+ let o = run_findmnt ( & [ "-N" ] , Some ( "1" ) ) ?;
9495
9596 let mounted = o. filesystems . iter ( ) . any ( |fs| is_source_mounted ( path, fs) ) ;
9697
0 commit comments