Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: migrate disk collection code off of heim, remove heim #1064

Merged
merged 39 commits into from
Apr 10, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
acd79e5
refactor: fix some refresh code
ClementTsang Mar 9, 2023
e58746d
remove async from the freebsd code
ClementTsang Mar 11, 2023
7754d02
some file/implementation organization
ClementTsang Mar 14, 2023
577bf72
more restructuring
ClementTsang Mar 16, 2023
5e1592c
Some other fixes
ClementTsang Mar 19, 2023
b2594ce
remove futures
ClementTsang Mar 19, 2023
48158e7
ready for some big changes?
ClementTsang Mar 23, 2023
4d5f250
big changes
ClementTsang Mar 26, 2023
69675dc
linux io + reads
ClementTsang Apr 1, 2023
ecf0ac2
use lossy conversion for mount point
ClementTsang Apr 1, 2023
8724780
add windows refresh
ClementTsang Apr 1, 2023
794eda3
so long heim, and thanks for all the fish
ClementTsang Apr 1, 2023
c53a32e
fix filter behaviour, remove string allocation when reading lines
ClementTsang Apr 3, 2023
042c530
rename unix -> system for more accurate file struct representation
ClementTsang Apr 4, 2023
7e0a2be
fix freebsd
ClementTsang Apr 4, 2023
37f4fd7
port generic unix partition code
ClementTsang Apr 5, 2023
b10d124
add bindings and fix errors
ClementTsang Apr 5, 2023
ad1d8f9
finish macOS bindings for I/O
ClementTsang Apr 5, 2023
9c8df52
disable conform check, this seems to... make disk I/O work on macOS?????
ClementTsang Apr 5, 2023
c027da9
fix linux
ClementTsang Apr 5, 2023
32e38ae
add safety comments
ClementTsang Apr 5, 2023
2628254
more comments
ClementTsang Apr 5, 2023
72485bc
update changelog
ClementTsang Apr 5, 2023
6d6bec0
changelog
ClementTsang Apr 5, 2023
096190d
We're going full 0.9.0 for this
ClementTsang Apr 5, 2023
e92cba7
update lock
ClementTsang Apr 5, 2023
c396659
fix some typing
ClementTsang Apr 6, 2023
eff2f16
bleh
ClementTsang Apr 6, 2023
461cde4
some file management
ClementTsang Apr 6, 2023
7f0c669
hoist out get_disk_usage
ClementTsang Apr 6, 2023
12559df
fix some stuff for Windows
ClementTsang Apr 6, 2023
30ea987
typing and remove dead code allow lint
ClementTsang Apr 6, 2023
0f4287b
unify typing
ClementTsang Apr 6, 2023
661c578
fix
ClementTsang Apr 6, 2023
111133c
fix 2
ClementTsang Apr 6, 2023
a30aac1
macOS fix
ClementTsang Apr 7, 2023
4d22589
Add bindings file for windows
ClementTsang Apr 9, 2023
0765343
add windows implementation
ClementTsang Apr 10, 2023
e5d241a
fix macos
ClementTsang Apr 10, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
add bindings and fix errors
  • Loading branch information
ClementTsang committed Apr 9, 2023
commit b10d124a575773ed88fd0ebf3e55506658ef6454
2 changes: 1 addition & 1 deletion src/app/data_harvester/disks/system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ pub fn get_disk_usage(
let mut vec_disks: Vec<DiskHarvest> = Vec::new();

for partition in physical_partitions()? {
let name = partition.device().to_string();
let name = partition.get_device_name();
let mount_point = partition.mount_point().to_string_lossy().to_string();

// Precedence ordering in the case where name and mount filters disagree, "allow" takes precedence over "deny".
Expand Down
2 changes: 1 addition & 1 deletion src/app/data_harvester/disks/system/macos/io_counters.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ impl IoCounters {
}
}

/// Returns an iterator of disk I/O stats. Pulls data from `/proc/diskstats`.
/// Returns an iterator of disk I/O stats. Pulls data through IOKit.
pub fn io_stats() -> anyhow::Result<Vec<anyhow::Result<IoCounters>>> {
Ok(vec![])
}
36 changes: 36 additions & 0 deletions src/app/data_harvester/disks/system/macos/io_kit_bindings.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
//! C FFI bindings for [IOKit](https://developer.apple.com/documentation/iokit/).
//!
//! Based on [heim's implementation](https://github.com/heim-rs/heim/blob/master/heim-common/src/sys/macos/iokit/ffi.rs).
//!
//! Ideally, we can remove this if sysinfo ever gains disk I/O capabilities... it even already
//! does all of these bindings!

use mach2::{kern_return::kern_return_t, port::mach_port_t};

pub type io_object_t = mach_port_t;

extern "C" {
/// See <https://developer.apple.com/documentation/iokit/kiomasterportdefault> for more info.
///
/// Note this is deprecated in favour of [`kIOMainPortDefault`] for macOS 12.0+.
pub static kIOMasterPortDefault: mach_port_t;

/// See <https://developer.apple.com/documentation/iokit/kiomainportdefault> for more info.
pub static kIOMainPortDefault: mach_port_t;

/// Returns the mach port used to initiate communication with IOKit. The port should be
/// deallocated with [`IOObjectRelease`]. See <https://developer.apple.com/documentation/iokit/1514652-iomasterport>
/// for more info.
///
/// Note this is deprecated in favour of [`IOMainPort`] for macOS 12.0+.
pub fn IOMasterPort(bootstrapPort: mach_port_t, masterPort: *mut mach_port_t) -> kern_return_t;

/// Returns the mach port used to initiate communication with IOKit. The port should be
/// deallocated with [`IOObjectRelease`]. See <https://developer.apple.com/documentation/iokit/3753260-iomainport>
/// for more info.
pub fn IOMainPort(bootstrapPort: mach_port_t, masterPort: *mut mach_port_t) -> kern_return_t;

/// Releases an object handle previously returned by IOKitLib. See <https://developer.apple.com/documentation/iokit/1514627-ioobjectrelease>
/// for more info.
pub fn IOObjectRelease(object: io_object_t) -> kern_return_t;
}
2 changes: 2 additions & 0 deletions src/app/data_harvester/disks/system/macos/mod.rs
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
mod io_counters;
pub(crate) use io_counters::*;

mod io_kit_bindings;
6 changes: 6 additions & 0 deletions src/app/data_harvester/disks/system/other/partition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,12 @@ impl Partition {
bail!("statvfs failed to get the disk usage for disk {path:?}")
}
}

/// Returns the device name.
#[inline]
pub fn get_device_name(&self) -> String {
self.device.clone()
}
}

fn partitions_iter() -> anyhow::Result<impl Iterator<Item = Partition>> {
Expand Down