1use {
2 crate::units::Units,
3 lfs_core::*,
4 serde_json::{
5 Value,
6 json,
7 },
8};
9
10pub fn output_value(
11 mounts: &[&Mount],
12 units: Units,
13) -> Value {
14 Value::Array(
15 mounts
16 .iter()
17 .map(|mount| {
18 let stats = mount.stats().map(|s| {
19 let inodes = s.inodes.as_ref().map(|inodes| {
20 json!({
21 "files": inodes.files,
22 "free": inodes.ffree,
23 "avail": inodes.favail,
24 "used-percent": format!("{:.0}%", 100.0*inodes.use_share()),
25 })
26 });
27 #[cfg(not(windows))]
28 {
29 json!({
30 "bsize": s.bsize,
31 "blocks": s.blocks,
32 "bused": s.bused,
33 "bfree": s.bfree,
34 "bavail": s.bavail,
35 "size": units.fmt(s.size()),
36 "used": units.fmt(s.used()),
37 "used-percent": format!("{:.0}%", 100.0*s.use_share()),
38 "available": units.fmt(s.available()),
39 "inodes": inodes,
40 })
41 }
42 #[cfg(windows)]
43 {
44 json!({
45 "size": units.fmt(s.size()),
46 "used": units.fmt(s.used()),
47 "used-percent": format!("{:.0}%", 100.0*s.use_share()),
48 "available": units.fmt(s.available()),
49 "free": units.fmt(s.available()),
50 "inodes": inodes,
51 })
52 }
53 });
54 let disk = mount.disk.as_ref().map(|d| {
55 json!({
56 "type": d.disk_type(),
57 "rotational": d.rotational,
58 "removable": d.removable,
59 "crypted": d.crypted,
60 "ram": d.ram,
61 })
62 });
63 let dev = {
64 #[cfg(not(windows))]
65 {
66 json!({
67 "major": mount.info.dev.major,
68 "minor": mount.info.dev.minor,
69 })
70 }
71 #[cfg(windows)]
72 {
73 mount.info.dev.to_string()
74 }
75 };
76 json!({
77 "id": mount.info.id,
78 "dev": dev,
79 "fs": mount.info.fs,
80 "fs-label": mount.fs_label,
81 "fs-type": mount.info.fs_type,
82 "mount-point": mount.info.mount_point,
83 "options": mount.info.options_string(),
84 "disk": disk,
85 "stats": stats,
86 "bound": mount.info.bound,
87 "remote": mount.is_remote(),
88 "unreachable": mount.is_unreachable(),
89 })
90 })
91 .collect(),
92 )
93}