Debian Codegraph @

src/collection/disks/unix/usage.rs

raw symbols SCIP
1 pub struct Usage(libc::statvfs);
2
3 // Note that x86 returns `u32` values while x86-64 returns `u64`s, so we convert
4 // everything to `u64` for consistency.
5 #[allow(clippy::useless_conversion)]
6 impl Usage {
7 pub(crate) fn new(vfs: libc::statvfs) -> Self {
8 Self(vfs)
9 }
10
11 /// Returns the total number of bytes available.
12 pub fn total(&self) -> u64 {
13 u64::from(self.0.f_blocks) * u64::from(self.0.f_frsize)
14 }
15
16 /// Returns the available number of bytes used. Note this is not necessarily
17 /// the same as [`Usage::free`].
18 pub fn available(&self) -> u64 {
19 u64::from(self.0.f_bfree) * u64::from(self.0.f_frsize)
20 }
21
22 #[expect(dead_code)]
23 /// Returns the total number of bytes used. Equal to `total - available` on
24 /// Unix.
25 pub fn used(&self) -> u64 {
26 let avail_to_root = u64::from(self.0.f_bfree) * u64::from(self.0.f_frsize);
27 self.total() - avail_to_root
28 }
29
30 /// Returns the total number of bytes free. Note this is not necessarily the
31 /// same as [`Usage::available`].
32 pub fn free(&self) -> u64 {
33 u64::from(self.0.f_bavail) * u64::from(self.0.f_frsize)
34 }
35 }