@@ -499,8 +499,8 @@ impl Vfs {
499
499
Ok ( ( inode, parent) )
500
500
}
501
501
502
- /// Get the mounted backend file system alongside the path if there's one.
503
- pub fn get_rootfs ( & self , path : & str ) -> VfsResult < Option < Arc < BackFileSystem > > > {
502
+ /// Get the mounted backend file system and its fs_idx alongside the path if there's one.
503
+ pub fn get_rootfs ( & self , path : & str ) -> VfsResult < Option < ( Arc < BackFileSystem > , u8 ) > > {
504
504
// Serialize mount operations. Do not expect poisoned lock here.
505
505
let _guard = self . lock . lock ( ) . unwrap ( ) ;
506
506
let inode = match self . root . path_walk ( path) . map_err ( VfsError :: PathWalk ) ? {
@@ -509,9 +509,10 @@ impl Vfs {
509
509
} ;
510
510
511
511
if let Some ( mnt) = self . mountpoints . load ( ) . get ( & inode) {
512
- Ok ( Some ( self . get_fs_by_idx ( mnt. fs_idx ) . map_err ( |e| {
513
- VfsError :: NotFound ( format ! ( "fs index {}, {:?}" , mnt. fs_idx, e) )
514
- } ) ?) )
512
+ let fs = self
513
+ . get_fs_by_idx ( mnt. fs_idx )
514
+ . map_err ( |e| VfsError :: NotFound ( format ! ( "fs index {}, {:?}" , mnt. fs_idx, e) ) ) ?;
515
+ Ok ( Some ( ( fs, mnt. fs_idx ) ) )
515
516
} else {
516
517
// Pseudo fs dir inode exists, but that no backend is ever mounted
517
518
// is a normal case.
@@ -1589,9 +1590,9 @@ mod tests {
1589
1590
assert ! ( vfs. mount( Box :: new( fs1) , "/x/y/z" ) . is_ok( ) ) ;
1590
1591
assert ! ( vfs. mount( Box :: new( fs2) , "/x/y" ) . is_ok( ) ) ;
1591
1592
1592
- let m1 = vfs. get_rootfs ( "/x/y/z" ) . unwrap ( ) . unwrap ( ) ;
1593
+ let ( m1 , _ ) = vfs. get_rootfs ( "/x/y/z" ) . unwrap ( ) . unwrap ( ) ;
1593
1594
assert ! ( m1. as_any( ) . is:: <FakeFileSystemOne >( ) ) ;
1594
- let m2 = vfs. get_rootfs ( "/x/y" ) . unwrap ( ) . unwrap ( ) ;
1595
+ let ( m2 , _ ) = vfs. get_rootfs ( "/x/y" ) . unwrap ( ) . unwrap ( ) ;
1595
1596
assert ! ( m2. as_any( ) . is:: <FakeFileSystemTwo >( ) ) ;
1596
1597
1597
1598
assert ! ( vfs. umount( "/x/y/z" ) . is_ok( ) ) ;
@@ -1612,7 +1613,7 @@ mod tests {
1612
1613
assert ! ( vfs. mount( Box :: new( fs1) , "/x/y" ) . is_ok( ) ) ;
1613
1614
assert ! ( vfs. mount( Box :: new( fs2) , "/x/y" ) . is_ok( ) ) ;
1614
1615
1615
- let m1 = vfs. get_rootfs ( "/x/y" ) . unwrap ( ) . unwrap ( ) ;
1616
+ let ( m1 , _ ) = vfs. get_rootfs ( "/x/y" ) . unwrap ( ) . unwrap ( ) ;
1616
1617
assert ! ( m1. as_any( ) . is:: <FakeFileSystemTwo >( ) ) ;
1617
1618
1618
1619
assert ! ( vfs. umount( "/x/y" ) . is_ok( ) ) ;
0 commit comments