1use super::*;
2
3#[derive(Debug, Clone)]
5pub struct Mount {
6 pub info: MountInfo,
7 pub fs_label: Option<String>,
8 pub disk: Option<Disk>,
9 pub stats: Result<Stats, StatsError>,
10 pub uuid: Option<String>,
11 pub part_uuid: Option<String>,
12}
13
14impl Mount {
15 pub fn inodes(&self) -> Option<&Inodes> {
17 self.stats
18 .as_ref()
19 .ok()
20 .and_then(|stats| stats.inodes.as_ref())
21 }
22 pub fn stats(&self) -> Option<&Stats> {
33 self.stats.as_ref().ok()
34 }
35 pub fn is_unreachable(&self) -> bool {
38 matches!(self.stats, Err(StatsError::Unreachable))
39 }
40}
41
42#[derive(Debug, Clone)]
43pub struct ReadOptions {
44 remote_stats: bool,
45}
46impl Default for ReadOptions {
47 fn default() -> Self {
48 Self {
49 remote_stats: true,
50 }
51 }
52}
53impl ReadOptions {
54 pub fn remote_stats(&mut self, v: bool) {
55 self.remote_stats = v;
56 }
57}
58
59pub fn read_mounts(options: &ReadOptions) -> Result<Vec<Mount>, Error> {
61 let by_label = read_by("label").ok();
62 let by_uuid = read_by("uuid").ok();
63 let by_partuuid = read_by("partuuid").ok();
64
65 let bd_list = BlockDeviceList::read()?;
69 read_mountinfo()?
70 .drain(..)
71 .map(|info| {
72 let top_bd = bd_list.find_top(
73 info.dev,
74 info.dm_name(),
75 info.fs_name(),
76 );
77 let fs_label = get_label(&info.fs, by_label.as_deref());
78 let uuid = get_label(&info.fs, by_uuid.as_deref());
79 let part_uuid = get_label(&info.fs, by_partuuid.as_deref());
80 let disk = top_bd.map(|bd| Disk::new(bd.name.clone()));
81 let stats = if !options.remote_stats && info.is_remote() {
82 Err(StatsError::Excluded)
83 } else {
84 Stats::from(&info.mount_point)
85 };
86 Ok(Mount {
87 info,
88 fs_label,
89 disk,
90 stats,
91 uuid,
92 part_uuid,
93 })
94 })
95 .collect()
96}