VirtualBox

Ignore:
Timestamp:
Jan 13, 2016 10:21:15 PM (9 years ago)
Author:
vboxsync
Message:

Main/IOKit: Fixes for El Capitan, use the new IOUSBHostDevice class to get access to all required data like checking whether a USB MSD is mounted on the host and marking it as unavailable

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Main/src-server/darwin/iokit.cpp

    r59122 r59330  
    5050#include <iprt/thread.h>
    5151#include <iprt/uuid.h>
     52#include <iprt/system.h>
    5253#ifdef STANDALONE_TESTCASE
    5354# include <iprt/initterm.h>
     
    7677#define VBOXUSBDEVICE_CLASS_NAME "org_virtualbox_VBoxUSBDevice"
    7778
     79/** Define the constant for the IOUSBHostDevice class name added in El Capitan. */
     80#ifndef kIOUSBHostDeviceClassName
     81# define kIOUSBHostDeviceClassName "IOUSBHostDevice"
     82#endif
     83
     84/** The major darwin version indicating OS X El Captian, used to take care of the USB changes. */
     85#define VBOX_OSX_EL_CAPTIAN_VER 15
    7886
    7987/*********************************************************************************************************************************
     
    8290/** The IO Master Port. */
    8391static mach_port_t g_MasterPort = NULL;
     92/** Major darwin version as returned by uname -r.
     93 * Used to  changes to */
     94uint32_t g_uMajorDarwin = 0;
    8495
    8596
     
    95106        kern_return_t krc = IOMasterPort(MACH_PORT_NULL, &g_MasterPort);
    96107        AssertReturn(krc == KERN_SUCCESS, false);
     108
     109        /* Get the darwin version we are running on. */
     110        char aszVersion[16] = { 0 };
     111        int rc = RTSystemQueryOSInfo(RTSYSOSINFO_RELEASE, &aszVersion[0], sizeof(aszVersion));
     112        if (RT_SUCCESS(rc))
     113        {
     114            /* Make sure it is zero terminated (paranoia). */
     115            aszVersion[15] = '\0';
     116            rc = RTStrToUInt32Ex(&aszVersion[0], NULL, 10, &g_uMajorDarwin);
     117            if (   rc != VINF_SUCCESS
     118                && rc != VWRN_TRAILING_CHARS)
     119                LogRel(("IOKit: Failed to convert the major part of the version string \"%s\" into an integer\n", &aszVersion[0]));
     120        }
     121        else
     122            LogRel(("IOKit: Failed to query the OS release version with %Rrc\n", rc));
    97123    }
    98124    return true;
     
    517543} DARWINUSBNOTIFY, *PDARWINUSBNOTIFY;
    518544
     545/**
     546 * Returns the correct class name to identify USB devices. El Capitan
     547 * introduced a reworked USb stack with changed names.
     548 * The old names are still available but the objects don't reveal all the
     549 * information required.
     550 */
     551DECLINLINE(const char *)darwinGetUsbDeviceClassName(void)
     552{
     553    return   g_uMajorDarwin >= VBOX_OSX_EL_CAPTIAN_VER
     554           ? kIOUSBHostDeviceClassName
     555           : kIOUSBDeviceClassName;
     556}
    519557
    520558/**
     
    619657            kern_return_t rc = IOServiceAddMatchingNotification(pNotify->NotifyPort,
    620658                                                                kIOPublishNotification,
    621                                                                 IOServiceMatching(kIOUSBDeviceClassName),
     659                                                                IOServiceMatching(darwinGetUsbDeviceClassName()),
    622660                                                                darwinUSBAttachNotification1,
    623661                                                                pNotify,
     
    628666                rc = IOServiceAddMatchingNotification(pNotify->NotifyPort,
    629667                                                      kIOMatchedNotification,
    630                                                       IOServiceMatching(kIOUSBDeviceClassName),
     668                                                      IOServiceMatching(darwinGetUsbDeviceClassName()),
    631669                                                      darwinUSBAttachNotification2,
    632670                                                      pNotify,
     
    637675                    rc = IOServiceAddMatchingNotification(pNotify->NotifyPort,
    638676                                                          kIOTerminatedNotification,
    639                                                           IOServiceMatching(kIOUSBDeviceClassName),
     677                                                          IOServiceMatching(darwinGetUsbDeviceClassName()),
    640678                                                          darwinUSBDetachNotification,
    641679                                                          pNotify,
     
    820858                        fUserClientOnly = false;
    821859
    822                         if (!strcmp(szName, "IOUSBMassStorageClass"))
     860                        if (   !strcmp(szName, "IOUSBMassStorageClass")
     861                            || !strcmp(szName, "IOUSBMassStorageInterfaceNub"))
    823862                        {
    824863                            /* Only permit capturing MSDs that aren't mounted, at least
     
    906945     * Create a matching dictionary for searching for USB Devices in the IOKit.
    907946     */
    908     CFMutableDictionaryRef RefMatchingDict = IOServiceMatching(kIOUSBDeviceClassName);
     947    CFMutableDictionaryRef RefMatchingDict = IOServiceMatching(darwinGetUsbDeviceClassName());
    909948    AssertReturn(RefMatchingDict, NULL);
    910949
     
    9811020                darwinDictGetU8(PropsRef, CFSTR("PortNum"), &pCur->bPort); /* Not present in 10.11 beta 3, so ignore failure. (Is set to zero.) */
    9821021                uint8_t bSpeed;
    983                 AssertBreak(darwinDictGetU8(PropsRef,  CFSTR(kUSBDevicePropertySpeed),  &bSpeed));
    984                 Assert(bSpeed <= 3);
    985                 pCur->enmSpeed = bSpeed == 3 ? USBDEVICESPEED_SUPER
     1022                AssertBreak(darwinDictGetU8(PropsRef,
     1023                                              g_uMajorDarwin >= VBOX_OSX_EL_CAPTIAN_VER
     1024                                            ? CFSTR("USBSpeed")
     1025                                            : CFSTR(kUSBDevicePropertySpeed),
     1026                                            &bSpeed));
     1027                Assert(bSpeed <= 4);
     1028                pCur->enmSpeed = bSpeed == 3 || bSpeed == 4 ? USBDEVICESPEED_SUPER
    9861029                               : bSpeed == 2 ? USBDEVICESPEED_HIGH
    9871030                               : bSpeed == 1 ? USBDEVICESPEED_FULL
     
    11341177     */
    11351178
    1136     CFMutableDictionaryRef RefMatchingDict = IOServiceMatching(kIOUSBDeviceClassName);
     1179    CFMutableDictionaryRef RefMatchingDict = IOServiceMatching(darwinGetUsbDeviceClassName());
    11371180    AssertReturn(RefMatchingDict, NULL);
    11381181
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette