diff options
author | Clement Tsang <34804052+ClementTsang@users.noreply.github.com> | 2023-04-10 05:52:46 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-04-10 05:52:46 -0400 |
commit | 9edde9b133dd56bfe99bccaa93345626ed26d53c (patch) | |
tree | a3f234330f5c7b5467f3c5c40a9b9b50a7611050 /src/app/data_harvester/disks/unix/usage.rs | |
parent | b2801b16a95b6ce93a9350445ee7e4221c7f002c (diff) |
refactor: migrate disk collection code off of heim, remove heim (#1064)
Migrates existing heim-based disk data collection code off of it to either sysinfo or vendored code based on heim/sysinfo/other sources. This also allows us to remove heim completely from bottom.
---
* refactor: fix some refresh code
* remove async from the freebsd code
* some file/implementation organization
Turns out sysinfo lacks a lot of data I need. I can still use it for the
Windows disk usage implementation, but I'm probably going to manually
implement macos/linux usage and all io usage stats.
* more restructuring
* Some other fixes
* remove futures
* ready for some big changes?
* big changes
* linux io + reads
* use lossy conversion for mount point
* add windows refresh
* so long heim, and thanks for all the fish
* fix filter behaviour, remove string allocation when reading lines
* rename unix -> system for more accurate file struct representation
* fix freebsd
* port generic unix partition code
* add bindings and fix errors
* finish macOS bindings for I/O
* disable conform check, this seems to... make disk I/O work on macOS?????
* fix linux
* add safety comments
* more comments
* update changelog
* changelog
* We're going full 0.9.0 for this
* update lock
* fix some typing
* bleh
* some file management
* hoist out get_disk_usage
* fix some stuff for Windows
* typing and remove dead code allow lint
* unify typing
* fix
* fix 2
* macOS fix
* Add bindings file for windows
* add windows implementation
* fix macos
Diffstat (limited to 'src/app/data_harvester/disks/unix/usage.rs')
-rw-r--r-- | src/app/data_harvester/disks/unix/usage.rs | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/src/app/data_harvester/disks/unix/usage.rs b/src/app/data_harvester/disks/unix/usage.rs new file mode 100644 index 00000000..d9e75323 --- /dev/null +++ b/src/app/data_harvester/disks/unix/usage.rs @@ -0,0 +1,32 @@ +pub struct Usage(libc::statvfs); + +// Note that x86 returns `u32` values while x86-64 returns `u64`s, so we convert everything +// to `u64` for consistency. +#[allow(clippy::useless_conversion)] +impl Usage { + pub(crate) fn new(vfs: libc::statvfs) -> Self { + Self(vfs) + } + + /// Returns the total number of bytes available. + pub fn total(&self) -> u64 { + u64::from(self.0.f_blocks) * u64::from(self.0.f_frsize) + } + + /// Returns the available number of bytes used. Note this is not necessarily the same as [`free`]. + pub fn available(&self) -> u64 { + u64::from(self.0.f_bfree) * u64::from(self.0.f_frsize) + } + + #[allow(dead_code)] + /// Returns the total number of bytes used. Equal to `total - available` on Unix. + pub fn used(&self) -> u64 { + let avail_to_root = u64::from(self.0.f_bfree) * u64::from(self.0.f_frsize); + self.total() - avail_to_root + } + + /// Returns the total number of bytes free. Note this is not necessarily the same as [`available`]. + pub fn free(&self) -> u64 { + u64::from(self.0.f_bavail) * u64::from(self.0.f_frsize) + } +} |