Skip to content

Commit

Permalink
Replace DiskArbitration.framework with CoreFoundation
Browse files Browse the repository at this point in the history
for obtaining disk info on macOS
  • Loading branch information
complexspaces committed Oct 30, 2022
1 parent f672f66 commit c445b0d
Show file tree
Hide file tree
Showing 6 changed files with 247 additions and 243 deletions.
2 changes: 0 additions & 2 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ fn main() {

if is_apple {
if !is_ios {
// DiskArbitration is not available on iOS: https://developer.apple.com/documentation/diskarbitration
println!("cargo:rustc-link-lib=framework=DiskArbitration");
// IOKit is not available on iOS: https://developer.apple.com/documentation/iokit
println!("cargo:rustc-link-lib=framework=IOKit");
}
Expand Down
14 changes: 0 additions & 14 deletions src/apple/ffi.rs
Original file line number Diff line number Diff line change
@@ -1,22 +1,8 @@
// Take a look at the license at the top of the repository in the LICENSE file.

use libc::c_void;

// Reexport items defined in either macos or ios ffi module.
pub use crate::sys::inner::ffi::*;

#[repr(C)]
pub struct __DADisk(c_void);
#[repr(C)]
pub struct __DASession(c_void);

// #[allow(non_camel_case_types)]
// pub type io_name_t = [u8; 128];
// #[allow(non_camel_case_types)]
// pub type io_registry_entry_t = io_object_t;

// pub type IOOptionBits = u32;

#[cfg_attr(feature = "debug", derive(Eq, Hash, PartialEq))]
#[derive(Clone)]
#[repr(C)]
Expand Down
31 changes: 3 additions & 28 deletions src/apple/macos/component/x86.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Take a look at the license at the top of the repository in the LICENSE file.

use crate::sys::ffi;
use crate::sys::{ffi, macos::utils::IOReleaser};
use crate::ComponentExt;

use libc::{c_char, c_int, c_void};
Expand Down Expand Up @@ -253,31 +253,6 @@ fn get_temperature(con: ffi::io_connect_t, key: &[i8]) -> Option<f32> {
}
}

#[repr(transparent)]
pub(crate) struct IoObject(ffi::io_object_t);

impl IoObject {
fn new(obj: ffi::io_object_t) -> Option<Self> {
if obj == 0 {
None
} else {
Some(Self(obj))
}
}

fn inner(&self) -> ffi::io_object_t {
self.0
}
}

impl Drop for IoObject {
fn drop(&mut self) {
unsafe {
ffi::IOObjectRelease(self.0);
}
}
}

pub(crate) struct IoService(ffi::io_connect_t);

impl IoService {
Expand Down Expand Up @@ -309,15 +284,15 @@ impl IoService {
sysinfo_debug!("Error: IOServiceGetMatchingServices() = {}", result);
return None;
}
let iterator = match IoObject::new(iterator) {
let iterator = match IOReleaser::new(iterator) {
Some(i) => i,
None => {
sysinfo_debug!("Error: IOServiceGetMatchingServices() succeeded but returned invalid descriptor");
return None;
}
};

let device = match IoObject::new(ffi::IOIteratorNext(iterator.inner())) {
let device = match IOReleaser::new(ffi::IOIteratorNext(iterator.inner())) {
Some(d) => d,
None => {
sysinfo_debug!("Error: no SMC found");
Expand Down
Loading

0 comments on commit c445b0d

Please sign in to comment.