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
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.as_ref().map(|s| {
json!({
"bsize": s.bsize,
"blocks": s.blocks,
"bavail": s.bavail,
"bfree": s.bfree,
"size": units.fmt(s.size()),
"used": units.fmt(s.used()),
"used-percent": format!("{:.0}%", 100.0*s.use_share()),
"available": units.fmt(s.available()),
})
});
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,
})
})
.collect(),
)
}