我们一直在使用OSX: How to get a volume name (or bsd name) from a IOUSBDeviceInterface or location id中描述的解决方案将USB设备从IOKit映射到相应的BSD设备位置。代码是:
functB(location);
由于Beta版本中引入了回归,此解决方案不再适用于El Capitan。根据{{3}}的帖子,Apple确认了这个bug,但还没有发布修复,所以我需要一个解决方法。到目前为止,我所知道的唯一一个涉及从根解析整个I / O注册表并查找我的特定设备。
有没有人知道更简单的解决方法?
答案 0 :(得分:1)
最近遇到了这个问题。这个问题并没有开始为我过滤bsdName,它实际上与从USB查询获取结果有关。原来在El Capitan IOUSBDevice有点不赞成使用IOUSBHostDevice。这就是我为了得到我需要而做的事情:
// -- 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
);
}