-
-
Notifications
You must be signed in to change notification settings - Fork 302
-
-
Notifications
You must be signed in to change notification settings - Fork 302
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
get_disks() doesn't return all mounted disks on Mac OS #375
Comments
That's intriguing. I'll need to check what's going there. |
Thanks Guillaume. I updated the report by fixing a problem in the code that was mixing 0.3 and 0.15 versions of the example code and tested under Windows 10, which has a different problem. |
In utils.rs lines 41 & 42 ...
It seems you are only considering an entry in /Volumes to be a mountpoint if it is a symlink. On my system my boot drive is a symlink but the other drives are directories. So unless this check is here for a specific reason not apparent to me it seems to be wrong to filter out non-symlinks. |
I only have my own Mac to check that so if you're telling me that it works in your case, then we can simply remove this check. |
My friend has also checked it on his Mac and confirms: I have a usb drive, a network drive and a timemachine snapshot |
Testing with a USB key is a good idea! I'll give it a try. |
It seems that on Mac a USB key is treated identically to USB hard drive or SSD but on Windows USB hard drives and SSDs are included but USB keys are rejected. Technically a separate bug but as the crate currently doesn't list any external drives on Mac I won't open a new issue yet. |
So a good example why I didn't take into account folders. On my computer I have in my
Obviously,
As you can see, there is a |
So after spending quite some time on this, the only thing I could find for the moment was #[repr(C)]
pub struct NSWorkspace {
__private: c_void,
}
extern "C" {
fn NSWorkspaceSharedWorkspace() -> *mut NSWorkspace;
fn NSWorkspaceMountedLocalVolumePaths(ws: *mut NSWorkspace) -> *mut c_void;
fn getFileSystemInfoForPath(
ws: *mut NSWorkspace,
path: ffi::CFStringRef,
isRemovable: *mut ffi::Boolean,
isWritable: *mut ffi::Boolean,
isUnmountable: *mut ffi::Boolean,
description: ffi::CFStringRef,
type_: ffi::CFStringRef,
) -> ffi::Boolean;
}
pub(crate) fn get_disks() -> Vec<Disk> {
unsafe {
let ws = NSWorkspaceSharedWorkspace();
let vols = NSWorkspaceMountedLocalVolumePaths(ws);
for x in 0..ffi::CFArrayGetCount(vols as _) {
let path = ffi::CFArrayGetValueAtIndex(vols as _, x);
let mut isRemovable = 0;
let mut isWritable = 0;
let mut isUnmountable = 0;
let description = ffi::CFStringCreateWithCStringNoCopy(
ws,
ptr::null_mut(),
[0].as_ptr() as *const c_char,
ffi::kCFStringEncodingMacRoman,
ffi::kCFAllocatorNull as *mut c_void,
);
let res = getFileSystemInfoForPath(path as _, &mut isRemovable, &mut isWritable, &mut isUnmountable, description, ::std::ptr::null_mut());
if res == 0 {
continue;
}
let tmp = std::ffi::CStr::from_ptr(ffi::CFStringGetCharactersPtr(path as _) as _);
let tmp_d = std::ffi::CStr::from_ptr(ffi::CFStringGetCharactersPtr(description)as _);
println!("==> {:?} {:?} w: {:?} r: {:?} u: {:?}", tmp.to_str().unwrap(), tmp_d.to_str().unwrap(), isWritable, isRemovable, isUnmountable);
}
}
vec![]
} If anyone is interested into trying to fix more things... |
The
The first is a hard drive with one MS partition, the second is a USB stick, the third is my boot drive, and the last is a microSD card attached via a USB adapter. Except for the boot drive, they are all connected via a $5 USB 2 hub. The SD card and the USB stick are not partitioned. So the only pattern I can see is that unpartitioned drive with MS filesystems get I'm starting to think that I have to admit that so far I'm not very good at reading mscOS API code or Objective C though. It uses the Disk Arbitration system. |
Another way to fool the current code is to make a random symlink in the
Current |
Here's some proof of concept code I managed to get working in very terrible Swift. It doesn't seem to have false positives or false negatives for anything that might be in
|
We definitely shouldn't do that, I'll try to find another way. ;) |
@hippietrail Just for your information, I'm almost done rewriting the code in rust. My last issue is with |
I have a hunch that some things in Swift come from its runtime library that wrap or abstract around some system calls. I haven't found a Swift equivalent of The Rust Book yet though so I haven't learned much but I believe I ran into this problem when I was looking at app notifications. Perhaps it wraps an Objective C system call in a Swift dictionary/associative array? Or maybe not. Here it seems to be used directly from ObjC. |
Yes, that's why I mentioned But the problem is that it's still a method from the |
Since it's all about passing messages to emulate objects and methods, I might be able to have the |
I've just started learning Rust. I'm on a 2013 MacBook Air running macOS Sierra and rustc 1.48.0
I modified the sysinfo example to just print out the disks in the system. My boot disk is an external USB 3.0 SSD. (The internal SSD has been missing since I got the laptop.) Running the code with just the boot disk reports just the boot disk. Attaching my USB 3.0 HD with several partitions including Mac, FAT, and NTFS; still only the boot disk is listed. I added more refresh_* calls but it made no difference. Code:
Output:
UPDATE
It turns out I had my .toml set up to use version "0.3" of sysinfo, which I must've got from Googling. I changed it to "0.15" to get the latest version. Instead of fixing the problem it now prints out nothing at all. Not even my boot disk is listed.
UPDATE 2
It looks like I had code that was still using System::new() from the 0.3 example so I changed it to System::new_all() to match the 0.15 version. Now on my Mac the boot disk shows up again but neither of two different USB hard drives, nor any of their partitions.
On my Windows 10 machine there's a different problem. The internal SSDs show up and the external USB HDs that don't show up on the Mac do show up, but my SDHC card does not show up.
The text was updated successfully, but these errors were encountered: