10

我正在 OS X 中为 USB 设备安装 IOKit 驱动程序的安装程序,我试图让它不需要在最后重新启动。安装程序正确安装驱动程序并重建 kext 缓存,运行后,如果我拔下并重新插入 USB 设备,它会正确加载新驱动程序,一切正常。

但是,我不想要求用户在物理上拔下设备以加载新驱动程序。必须有一种方法可以让 OS X 以编程方式加载新驱动程序 - 实际上模拟设备被拔出并重新插入,或类似的东西。我该怎么做呢?到目前为止,几个小时的谷歌搜索没有任何结果,所以任何帮助都将不胜感激!

4

2 回答 2

3

IOUSBDeviceInterface187::USBDeviceReEnumerate() 会做你想做的事。唯一的障碍是找到所有感兴趣的设备并使用IOServiceGetMatchingServices().

/*!
@function USBDeviceReEnumerate
@abstract   Tells the IOUSBFamily to reenumerate the device.
@discussion This function will send a terminate message to all clients of the IOUSBDevice (such as 
            IOUSBInterfaces and their drivers, as well as the current User Client), emulating an unplug 
            of the device. The IOUSBFamily will then enumerate the device as if it had just 
            been plugged in. This call should be used by clients wishing to take advantage 
            of the Device Firmware Update Class specification.  The device must be open to use this function. 
@availability This function is only available with IOUSBDeviceInterface187 and above.
@param      self Pointer to the IOUSBDeviceInterface.
@param      options A UInt32 reserved for future use. Ignored in current implementation. Set to zero.
@result     Returns kIOReturnSuccess if successful, kIOReturnNoDevice if there is no connection to an IOService,
            or kIOReturnNotOpen if the device is not open for exclusive access.
*/

IOReturn (*USBDeviceReEnumerate)(void *self, UInt32 options);

查看 IOKit/usb/IOUSBLib.h

于 2015-10-13T17:16:15.437 回答
0

看看diskutil,尤其是mountunmount选项。这些将以软件方式弹出和安装设备。您可以使用diskutil list获取所有当前安装的设备的列表。如果您需要有关 diskutil 的更多信息,请查看手册页。

于 2012-10-08T18:56:38.490 回答