以编程方式“拔出并重新插入”USB设备以在OS X中加载新驱动程序?

时间:2012-10-08 17:52:50

标签: macos installer usb driver iokit

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

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

2 个答案:

答案 0 :(得分:2)

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

答案 1 :(得分:0)

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