Debian Codegraph @

src/collection/disks/unix.rs

raw symbols SCIP
1 //! Disk stats for Unix-like systems that aren't supported through other means.
2 //! Officially, for now, this means Linux and macOS.
3
4 mod file_systemsrust-analyzer cargo bottom 0.14.9 collection/disks/unix/file_systems/;
5
6 mod usagerust-analyzer cargo bottom 0.14.9 collection/disks/unix/usage/;
7
8 cfg_selectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/cfg_select!! {
9 target_os = "linux" => {
10 mod linuxrust-analyzer cargo bottom 0.14.9 collection/disks/unix/linux/;
11 pub use linuxrust-analyzer cargo bottom 0.14.9 collection/disks/unix/linux/::*;
12 }
13 target_os = "macos" => {
14 mod other;
15 use other::*;
16
17 mod macos;
18 pub use macos::*;
19 }
20 _ => {
21 mod other;
22 use other::*;
23 }
24 }
25
26 use file_systemsrust-analyzer cargo bottom 0.14.9 collection/disks/unix/file_systems/::*;
27 use usagerust-analyzer cargo bottom 0.14.9 collection/disks/unix/usage/::*;
28
29 use superrust-analyzer cargo bottom 0.14.9 collection/disks/::{DiskHarvestrust-analyzer cargo bottom 0.14.9 collection/disks/DiskHarvest#, keep_disk_entryrust-analyzer cargo bottom 0.14.9 collection/disks/keep_disk_entry().};
30 use craterust-analyzer cargo bottom 0.14.9 crate/::collectionrust-analyzer cargo bottom 0.14.9 collection/::DataCollectorrust-analyzer cargo bottom 0.14.9 collection/DataCollector#;
31
32 /// Returns the disk usage of the mounted (and for now, physical) disks.
33 pub fn get_disk_usagerust-analyzer cargo bottom 0.14.9 collection/disks/unix/get_disk_usage().(collector: &DataCollectorrust-analyzer cargo bottom 0.14.9 collection/DataCollector#) -> anyhowrust-analyzer cargo anyhow 1.0.104 crate/::Resultrust-analyzer cargo anyhow 1.0.104 Result#<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<DiskHarvestrust-analyzer cargo bottom 0.14.9 collection/disks/DiskHarvest#>> {
34 let disk_filter = &collector.filtersrust-analyzer cargo bottom 0.14.9 collection/DataCollector#filters..disk_filterrust-analyzer cargo bottom 0.14.9 app/DataFilters#disk_filter.;
35 let mount_filter = &collector.filtersrust-analyzer cargo bottom 0.14.9 collection/DataCollector#filters..mount_filterrust-analyzer cargo bottom 0.14.9 app/DataFilters#mount_filter.;
36 let mut vec_disks: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<DiskHarvestrust-analyzer cargo bottom 0.14.9 collection/disks/DiskHarvest#> = Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T>`]new().();
37
38 #[cfg(target_os = "linux")]
39 let mut mounted_names = stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::collectionsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/::HashSetrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/HashSet#::newrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/impl#[`HashSet<T>`]new().();
40
41 for partition in physical_partitionsrust-analyzer cargo bottom 0.14.9 collection/disks/unix/linux/partition/physical_partitions().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch(). {
42 let name = partition.get_device_namerust-analyzer cargo bottom 0.14.9 collection/disks/unix/linux/partition/impl#[Partition]get_device_name().();
43 let mount_point = partition.mount_pointrust-analyzer cargo bottom 0.14.9 collection/disks/unix/linux/partition/impl#[Partition]mount_point().().to_string_lossyrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]to_string_lossy().().to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().();
44
45 #[cfg(target_os = "linux")]
46 if collector.include_unmounted_disksrust-analyzer cargo bottom 0.14.9 collection/DataCollector#include_unmounted_disks.
47 && let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(base) = name.rsplitrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]rsplit().('/').nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/iter/impl#[`RSplit<'a, P>`][Iterator]next().()
48 {
49 mounted_names.insertrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/impl#[`HashSet<T, S, A>`]insert().(base.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().());
50 }
51
52 // Precedence ordering in the case where name and mount filters disagree,
53 // "allow" takes precedence over "deny".
54 //
55 // For implementation, we do this as follows:
56 // 1. Is the entry allowed through any filter? That is, does it match an entry
57 // in a filter where `is_list_ignored` is `false`? If so, we always keep this
58 // entry.
59 // 2. Is the entry denied through any filter? That is, does it match an entry in
60 // a filter where `is_list_ignored` is `true`? If so, we always deny this
61 // entry.
62 // 3. Anything else is allowed.
63
64 if keep_disk_entryrust-analyzer cargo bottom 0.14.9 collection/disks/keep_disk_entry().(&name, &mount_point, disk_filter, mount_filter) {
65 // The usage line can fail in some cases (for example, if you use Void Linux +
66 // LUKS, see https://github.com/ClementTsang/bottom/issues/419 for details).
67 if let Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(usage) = partition.usagerust-analyzer cargo bottom 0.14.9 collection/disks/unix/linux/partition/impl#[Partition]usage().() {
68 let total = usage.totalrust-analyzer cargo bottom 0.14.9 collection/disks/unix/usage/impl#[Usage]total().();
69
70 vec_disks.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(DiskHarvestrust-analyzer cargo bottom 0.14.9 collection/disks/DiskHarvest# {
71 free_spacerust-analyzer cargo bottom 0.14.9 collection/disks/DiskHarvest#free_space.: Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(usage.freerust-analyzer cargo bottom 0.14.9 collection/disks/unix/usage/impl#[Usage]free().()),
72 used_spacerust-analyzer cargo bottom 0.14.9 collection/disks/DiskHarvest#used_space.: Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(total rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`Sub<Self>`]sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`Sub<Self>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`Sub<Self>`]sub().usage.availablerust-analyzer cargo bottom 0.14.9 collection/disks/unix/usage/impl#[Usage]available().()),
73 total_spacerust-analyzer cargo bottom 0.14.9 collection/disks/DiskHarvest#total_space.: Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(total),
74 mount_pointrust-analyzer cargo bottom 0.14.9 collection/disks/DiskHarvest#mount_point.,
75 namerust-analyzer cargo bottom 0.14.9 collection/disks/DiskHarvest#name.,
76 });
77 } else {
78 vec_disks.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(DiskHarvestrust-analyzer cargo bottom 0.14.9 collection/disks/DiskHarvest# {
79 free_spacerust-analyzer cargo bottom 0.14.9 collection/disks/DiskHarvest#free_space.: Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#,
80 used_spacerust-analyzer cargo bottom 0.14.9 collection/disks/DiskHarvest#used_space.: Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#,
81 total_spacerust-analyzer cargo bottom 0.14.9 collection/disks/DiskHarvest#total_space.: Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#,
82 mount_pointrust-analyzer cargo bottom 0.14.9 collection/disks/DiskHarvest#mount_point.,
83 namerust-analyzer cargo bottom 0.14.9 collection/disks/DiskHarvest#name.,
84 });
85 }
86 }
87 }
88
89 #[cfg(target_os = "linux")]
90 {
91 // If we're including unmounted disks, then we'll add any disks that we previously
92 // did not mark as mounted.
93 if collector.include_unmounted_disksrust-analyzer cargo bottom 0.14.9 collection/DataCollector#include_unmounted_disks. {
94 for disk in unmounted_disksrust-analyzer cargo bottom 0.14.9 collection/disks/unix/linux/unmounted/unmounted_disks().(&mounted_names) {
95 if keep_disk_entryrust-analyzer cargo bottom 0.14.9 collection/disks/keep_disk_entry().(&disk.namerust-analyzer cargo bottom 0.14.9 collection/disks/DiskHarvest#name., &disk.mount_pointrust-analyzer cargo bottom 0.14.9 collection/disks/DiskHarvest#mount_point., disk_filter, &Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#) {
96 vec_disks.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(disk);
97 }
98 }
99 }
100 }
101
102 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(vec_disks)
103 }