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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
use std::{
fs::File,
io::{self, BufRead, BufReader},
};
#[derive(Clone, Debug)]
#[allow(clippy::module_name_repetitions)]
pub struct SupportedFilesystems {
nodev: Vec<bool>,
fs: Vec<String>,
}
impl SupportedFilesystems {
pub fn new() -> io::Result<Self> {
let mut fss = Vec::with_capacity(64);
let mut nodevs = Vec::with_capacity(64);
for line in BufReader::new(File::open("/proc/filesystems")?).lines() {
let line = line?;
let mut line = line.split_whitespace();
let (nodev, fs) = match (line.next(), line.next()) {
(Some(fs), None) => (false, fs),
(Some("nodev"), Some(fs)) => (true, fs),
_ => continue,
};
nodevs.push(nodev);
fss.push(fs.to_owned());
}
Ok(SupportedFilesystems {
nodev: nodevs,
fs: fss,
})
}
#[must_use]
pub fn is_supported(&self, fs: &str) -> bool {
self.fs.iter().any(|s| s.as_str() == fs)
}
#[must_use]
pub fn nodev_file_systems<'a>(&'a self) -> Box<dyn Iterator<Item = &str> + 'a> {
let iter = self.nodev.iter().enumerate().filter_map(move |(id, &x)| {
if x {
Some(self.fs[id].as_str())
} else {
None
}
});
Box::new(iter)
}
#[must_use]
pub fn dev_file_systems<'a>(&'a self) -> Box<dyn Iterator<Item = &str> + 'a> {
let iter = self.nodev.iter().enumerate().filter_map(move |(id, &x)| {
if x {
None
} else {
Some(self.fs[id].as_str())
}
});
Box::new(iter)
}
}