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
|
use {
crate::units::Units,
lfs_core::*,
serde_json::{json, Value},
};
pub fn output_value(mounts: &[Mount], units: Units) -> Value {
Value::Array(
mounts
.iter()
.map(|mount| {
let stats = mount.stats().map(|s| {
let inodes = s.inodes.as_ref().map(|inodes| {
json!({
"files": inodes.files,
"free": inodes.ffree,
"avail": inodes.favail,
"used-percent": format!("{:.0}%", 100.0*inodes.use_share()),
})
});
json!({
"bsize": s.bsize,
"blocks": s.blocks,
"bfree": s.bfree,
"bavail": s.bavail,
"size": units.fmt(s.size()),
"used": units.fmt(s.used()),
"used-percent": format!("{:.0}%", 100.0*s.use_share()),
"available": units.fmt(s.available()),
"inodes": inodes,
})
});
let disk = mount.disk.as_ref().map(|d| {
json!({
"type": d.disk_type(),
"rotational": d.rotational,
"removable": d.removable,
"crypted": d.crypted,
"ram": d.ram,
})
});
json!({
"id": mount.info.id,
"dev": {
"major": mount.info.dev.major,
"minor": mount.info.dev.minor,
},
"fs": mount.info.fs,
"fs-label": mount.fs_label,
"fs-type": mount.info.fs_type,
"mount-point": mount.info.mount_point,
"disk": disk,
"stats": stats,
"bound": mount.info.bound,
"remote": mount.info.is_remote(),
"unreachable": mount.is_unreachable(),
})
})
.collect(),
)
}
|