1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
use crate::*;
/// A mount point
#[derive(Debug, Clone)]
pub struct Mount {
pub info: MountInfo,
pub fs_label: Option<String>,
pub disk: Option<Disk>,
pub stats: Result<Stats, StatsError>,
pub uuid: Option<String>,
pub part_uuid: Option<String>,
}
impl Mount {
/// Return inodes information, when available and consistent
pub fn inodes(&self) -> Option<&Inodes> {
self.stats
.as_ref()
.ok()
.and_then(|stats| stats.inodes.as_ref())
}
/// Return the stats, if they could be fetched and
/// make sense.
///
/// Most often, you don't care *why* there are no stats,
/// because the error cases are mostly non storage volumes,
/// so it's a best practice to no try to analyze the error
/// but just use this option returning method.
///
/// The most interesting case is when a network volume is
/// unreachable, which you can test with is_unreachable().
pub fn stats(&self) -> Option<&Stats> {
self.stats.as_ref().ok()
}
/// Tell whether the reason we have no stats is because the
/// filesystem is unreachable
pub fn is_unreachable(&self) -> bool {
matches!(self.stats, Err(StatsError::Unreachable))
}
}