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
我想嘗試看着那被運行代碼時,你彈出USB大容量存儲設備 - 我不知道是否有相應的USB通信或如果它只是告訴USB子系統忽略端口,直到物理拔掉。在前一種情況下(「USB彈出」消息),除了斷電或USB重置之外,可能沒有簡單的方法來「解除彈出」,這兩種方式都可能對其他USB設備有問題。但希望這是一個開始尋找的地方。 –
我讀了一些名爲'pmount'的東西,它可以卸載更多的任意USB設備,但我不知道它是否包含您的設備。唯一的缺點是它默認沒有OS X。 – rien333
我相當肯定你不能直接從用戶空間做到這一點。但是,在內核中,您可以嘗試在佔用設備的現有客戶端上調用terminate()。 – pmdj