From 1f24df1a4265040443109a982acb88de5849ccb8 Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Fri, 3 Apr 2020 02:27:03 +0200 Subject: Fixes to macOS drive finding. --- src/lib/cross_osx.cc | 52 ++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 48 insertions(+), 4 deletions(-) diff --git a/src/lib/cross_osx.cc b/src/lib/cross_osx.cc index 7197eef79..f26127e7a 100644 --- a/src/lib/cross_osx.cc +++ b/src/lib/cross_osx.cc @@ -32,6 +32,7 @@ extern "C" { #include #include #include +#include #include #include #include @@ -131,6 +132,7 @@ openssl_path () boost::filesystem::path disk_writer_path () { + return "/Users/carl/dcpomatic/src/dcpomatic/build/src/tools/dcpomatic2_disk_writer"; boost::filesystem::path path = app_contents(); path /= "MacOS"; path /= "dcpomatic2_disk_writer"; @@ -239,18 +241,60 @@ running_32_on_64 () } static void -disk_appeared(DADiskRef disk, void* context) +disk_appeared (DADiskRef disk, void* context) { const char* name = DADiskGetBSDName (disk); - if (name) { - vector* drives = reinterpret_cast*> (context); - drives->push_back (Drive(name, 0, false, optional(), optional())); + if (!name) { + return; } + + vector* drives = reinterpret_cast*> (context); + + CFDictionaryRef description = DADiskCopyDescription (disk); + + optional vendor; + void const* str = CFDictionaryGetValue (description, kDADiskDescriptionDeviceVendorKey); + if (str) { + vendor = CFStringGetCStringPtr ((CFStringRef) str, kCFStringEncodingUTF8); + } + + optional model; + str = CFDictionaryGetValue (description, kDADiskDescriptionDeviceModelKey); + if (str) { + model = CFStringGetCStringPtr ((CFStringRef) str, kCFStringEncodingUTF8); + } + + str = CFDictionaryGetValue (description, kDADiskDescriptionMediaPathKey); + if (str) { + if (strncmp(str, "IoDeviceTree:", 13) != 0) { + return; + } + } + + io_service_t service = DADiskCopyIOMedia (disk); + CFTypeRef whole_media_ref = IORegistryEntryCreateCFProperty (service, CFSTR(kIOMediaWholeKey), kCFAllocatorDefault, 0); + bool whole_media = false; + if (whole_media_ref) { + whole_media = CFBooleanGetValue((CFBooleanRef) whole_media); + CFRelease (whole_media_ref); + } + IOObjectRelease (service); + if (!whole_media) { + return; + } + + unsigned long size; + CFNumberGetValue ((CFNumberRef) CFDictionaryGetValue (description, kDADiskDescriptionMediaSizeKey), kCFNumberLongType, &size); + + CFRelease (description); + + drives->push_back (Drive(name, size, false, vendor, model)); } vector get_drives () { +std::cout << "get_drives!\n"; vector drives; DASessionRef session = DASessionCreate(kCFAllocatorDefault); -- cgit v1.2.3