Macos OSX:获取设备的BSD名称的变通方法
我们一直在使用中描述的解决方案将USB设备从IOKit映射到其相应的BSD设备位置。这方面的代码是:Macos OSX:获取设备的BSD名称的变通方法,macos,iokit,Macos,Iokit,我们一直在使用中描述的解决方案将USB设备从IOKit映射到其相应的BSD设备位置。这方面的代码是: CFTypeRef name = IORegistryEntrySearchCFProperty(usbDevice, kIOServicePlane, CFSTR(kIOBSDNameKey),
CFTypeRef name = IORegistryEntrySearchCFProperty(usbDevice,
kIOServicePlane,
CFSTR(kIOBSDNameKey),
kCFAllocatorDefault,
kIORegistryIterateRecursively);
由于在测试版中引入了回归,该解决方案不再适用于El Capitan。根据位于的线程,苹果已经确认了这个错误,但还没有发布修复程序,所以我需要一个解决方法。到目前为止,我只知道从根目录解析整个I/O注册表并查找我的特定设备
有人知道更简单的解决方法吗?最近也遇到了这个问题。问题并不是从为我过滤bsdName开始的,它实际上首先与从USB查询中获取结果有关。事实证明,在El Capitan中,iOubDevice有点被弃用,取而代之的是iOubHostDevice。以下是我为得到我需要的东西所做的:
// -- Begin Relevant Changes Part! ---
// Get current version
auto current_supported_version = __MAC_OS_X_VERSION_MAX_ALLOWED;
// El Capitan is 101100 (in AvailabilityInternal.h)
auto el_capitan = 101100;
// IOUSBDevice has become IOUSBHostDevice in El Capitan...
auto service_matcher = current_supported_version < el_capitan ? "IOUSBDevice" : "IOUSBHostDevice";
// Create matching dict to search
CFMutableDictionaryRef matchingDict = IOServiceMatching(service_matcher);
// -- End Relevant Changes Part! ---
// The rest of this is just example implementation code.
if (matchingDict == NULL)
{
// IOServiceMatching Failed
}
// Fill it with other stuff if necessary (vendor id, etc...)
// Do actual search
io_iterator_t iter;
kern_return_t kr;
kr = IOServiceGetMatchingServices(kIOMasterPortDefault, matchingDict, &iter);
if (kr != KERN_SUCCESS)
{
// IOServiceGetMatchingServices Failed
}
io_service_t service;
while ((service = IOIteratorNext(iter)))
{
// Ought to work now, regardless of version of OSX being ran.
CFStringRef bsdName = (CFStringRef) IORegistryEntrySearchCFProperty(
service,
kIOServicePlane,
CFSTR(kIOBSDNameKey),
kCFAllocatorDefault,
kIORegistryIterateRecursively
);
}
/--开始相关更改部分---
//获取当前版本
自动当前支持的版本=\uuuuuMac\uOS\uX\uVersion\uMax\uAllowed;
//El Capitan是101100(在Availability Internal.h中)
自动el_capitan=101100;
//IOUSBDevice已成为El Capitan的IousbHost设备。。。
自动服务匹配器=当前支持的版本
您尝试过磁盘仲裁方法吗?看起来磁盘仲裁可以让我们在连接USB设备时识别。知道它是否提供了查找特定IO服务USB设备条目的功能吗?我们需要获取有关USB设备的特定属性,因此仅装载点是不够的。在e上,如果您有一个DADisk对象,您可以通过DadiskCopyOmedia获取对其IOMedia对象的引用。从那里,你应该能够找到你需要的东西。