无法从英特尔处理器的 macOS Monterey 12 Bate4 获取 USB bsdname
Unable to get USB bsdname from macOS Monterey 12 Bate4 of Intel processor
我无法从英特尔处理器的 macOS Monterey 12 Bate4 获取 USB bsdname:我使用“IORegistryEntrySearchCFProperty”函数获取 io_service_t 的 bsdName,它在 macOS Big Sur 的 M1 和英特尔 MBP。
它在 macOS Monterey App M1 上也运行良好。但它总是在 macOS Monterey Intel MBP 上返回 nil。
涉及到以下代码:
void getBsdName(io_service_t usbDevice)
{
CFStringRef bsdName = NULL;
for(int i = 0; i < 500; i++)
{
bsdName = (CFStringRef)IORegistryEntrySearchCFProperty(usbDevice,
kIOServicePlane,
CFSTR( kIOBSDNameKey ),
kCFAllocatorDefault,
kIORegistryIterateRecursively );
if(!bsdName) {
// If don't get a bsd name, keep waiting in 5s.
usleep(10000);
continue;
}
printf("[%s]: Found bsd name for device %d.\n”, __func__, usbDevice);
break;
}
}
有人知道为什么会这样吗?如何让它在 MacOS 12 intel 处理器上运行?或者还有其他方法吗?
我也把同样的问题上传到苹果论坛,请查看这个link:Apple_forum_thread_686377
我通过其他方式解决了这个问题。
因为我正在寻找的设备是一个 IOMedia 对象。我通过枚举 kIOMediaClass 对象找到了它的 BSD 名称。然后我查找了 IOMedia 的父设备以确定我感兴趣的 USB 设备。
bool getBsdName(io_object_t mediaDevice)
{
// your code... ...
CFStringRef mediaDevBsdName = NULL;
mediaDevBsdName = (CFStringRef)IORegistryEntryCreateCFProperty(mediaDevice,
CFSTR(kIOBSDNameKey),
kCFAllocatorDefault,0);
// your code... ...
}
如果在为 IOServiceGetMatchingServices 调用 IORegistryEntryCreateCFProperty 创建匹配字典时使用“IOUSBHostDevice”而不是 kIOUSBDeviceClassName 将正确递归。
Intel 版本的 Monterey 不再支持字典中的“IOClassNameOverride”=“IOUSBDevice”条目,或者至少我认为是这样。
我无法从英特尔处理器的 macOS Monterey 12 Bate4 获取 USB bsdname:我使用“IORegistryEntrySearchCFProperty”函数获取 io_service_t 的 bsdName,它在 macOS Big Sur 的 M1 和英特尔 MBP。 它在 macOS Monterey App M1 上也运行良好。但它总是在 macOS Monterey Intel MBP 上返回 nil。 涉及到以下代码:
void getBsdName(io_service_t usbDevice)
{
CFStringRef bsdName = NULL;
for(int i = 0; i < 500; i++)
{
bsdName = (CFStringRef)IORegistryEntrySearchCFProperty(usbDevice,
kIOServicePlane,
CFSTR( kIOBSDNameKey ),
kCFAllocatorDefault,
kIORegistryIterateRecursively );
if(!bsdName) {
// If don't get a bsd name, keep waiting in 5s.
usleep(10000);
continue;
}
printf("[%s]: Found bsd name for device %d.\n”, __func__, usbDevice);
break;
}
}
有人知道为什么会这样吗?如何让它在 MacOS 12 intel 处理器上运行?或者还有其他方法吗?
我也把同样的问题上传到苹果论坛,请查看这个link:Apple_forum_thread_686377
我通过其他方式解决了这个问题。
因为我正在寻找的设备是一个 IOMedia 对象。我通过枚举 kIOMediaClass 对象找到了它的 BSD 名称。然后我查找了 IOMedia 的父设备以确定我感兴趣的 USB 设备。
bool getBsdName(io_object_t mediaDevice)
{
// your code... ...
CFStringRef mediaDevBsdName = NULL;
mediaDevBsdName = (CFStringRef)IORegistryEntryCreateCFProperty(mediaDevice,
CFSTR(kIOBSDNameKey),
kCFAllocatorDefault,0);
// your code... ...
}
如果在为 IOServiceGetMatchingServices 调用 IORegistryEntryCreateCFProperty 创建匹配字典时使用“IOUSBHostDevice”而不是 kIOUSBDeviceClassName 将正确递归。
Intel 版本的 Monterey 不再支持字典中的“IOClassNameOverride”=“IOUSBDevice”条目,或者至少我认为是这样。