@@ -10,8 +10,6 @@ use heim_runtime as rt;
10
10
11
11
use crate :: FileSystem ;
12
12
13
- static PROC_MOUNTS : & str = "/proc/mounts" ;
14
-
15
13
#[ derive( Debug ) ]
16
14
pub struct Partition {
17
15
device : Option < String > ,
@@ -46,22 +44,43 @@ impl FromStr for Partition {
46
44
fn from_str ( line : & str ) -> Result < Partition > {
47
45
// Example: `/dev/sda3 /home ext4 rw,relatime,data=ordered 0 0`
48
46
let mut parts = line. splitn ( 5 , ' ' ) ;
47
+ let mount_root = rt:: linux:: procfs_root ( ) . join ( "mounts" ) ;
49
48
let device = match parts. next ( ) {
50
49
Some ( device) if device == "none" => None ,
51
50
Some ( device) => Some ( device. to_string ( ) ) ,
52
- None => return Err ( Error :: missing_key ( "device" , PROC_MOUNTS ) ) ,
51
+ None => {
52
+ return Err ( Error :: missing_key (
53
+ "device" ,
54
+ format ! ( "{}" , mount_root. display( ) ) ,
55
+ ) )
56
+ }
53
57
} ;
54
58
let mount_point = match parts. next ( ) {
55
59
Some ( point) => PathBuf :: from ( point) ,
56
- None => return Err ( Error :: missing_key ( "mount point" , PROC_MOUNTS ) ) ,
60
+ None => {
61
+ return Err ( Error :: missing_key (
62
+ "mount point" ,
63
+ format ! ( "{}" , mount_root. display( ) ) ,
64
+ ) )
65
+ }
57
66
} ;
58
67
let fs_type = match parts. next ( ) {
59
68
Some ( fs) => FileSystem :: from_str ( fs) ?,
60
- _ => return Err ( Error :: missing_key ( "file-system type" , PROC_MOUNTS ) ) ,
69
+ _ => {
70
+ return Err ( Error :: missing_key (
71
+ "file-system type" ,
72
+ format ! ( "{}" , mount_root. display( ) ) ,
73
+ ) )
74
+ }
61
75
} ;
62
76
let options = match parts. next ( ) {
63
77
Some ( opts) => opts. to_string ( ) ,
64
- None => return Err ( Error :: missing_key ( "options" , PROC_MOUNTS ) ) ,
78
+ None => {
79
+ return Err ( Error :: missing_key (
80
+ "options" ,
81
+ format ! ( "{}" , mount_root. display( ) ) ,
82
+ ) )
83
+ }
65
84
} ;
66
85
67
86
Ok ( Partition {
@@ -76,7 +95,7 @@ impl FromStr for Partition {
76
95
// Returns stream with known physical (only!) partitions
77
96
async fn known_filesystems ( ) -> Result < HashSet < FileSystem > > {
78
97
rt:: spawn_blocking ( || {
79
- let file = fs:: File :: open ( "/proc/ filesystems") ?;
98
+ let file = fs:: File :: open ( rt :: linux :: procfs_root ( ) . join ( " filesystems") ) ?;
80
99
let reader = io:: BufReader :: new ( file) ;
81
100
let mut acc = HashSet :: with_capacity ( 4 ) ;
82
101
@@ -105,7 +124,7 @@ async fn known_filesystems() -> Result<HashSet<FileSystem>> {
105
124
}
106
125
107
126
pub async fn partitions ( ) -> Result < impl Stream < Item = Result < Partition > > > {
108
- let lines = rt:: fs:: read_lines ( PROC_MOUNTS ) . await ?;
127
+ let lines = rt:: fs:: read_lines ( rt :: linux :: procfs_root ( ) . join ( "mounts" ) ) . await ?;
109
128
let stream = lines
110
129
. map_err ( Error :: from)
111
130
. try_filter_map ( |line| async move {
0 commit comments