IOKit を使用して、マウント ポイントの BSD デバイス名を取得する方法を既に理解しましたが、その名前の USB デバイスを取得する方法を理解できませんでした。
次のようにデバイスを列挙できることがわかりました (コードが奇妙に見える場合は、それが Java であるためです)。
int kr;
IOKit ioKit = IOKit.INSTANCE;
CoreFoundation coreFoundation = CoreFoundation.INSTANCE;
CFDictionary.CFMutableDictionaryRef matchingDict =
ioKit.IOServiceMatching(IOUSBLib.kIOUSBDeviceClassName);
if (matchingDict == null)
{
logger.error("Couldn't create a USB matching dictionary");
return null;
}
PointerByReference iterator = new PointerByReference();
kr = ioKit.IOServiceGetMatchingServices(null, matchingDict, iterator);
if (kr != IOReturn.kIOReturnSuccess)
{
logger.error(String.format("Couldn't enumerate devices: %08x", kr));
return null;
}
while (true)
{
Pointer device = ioKit.IOIteratorNext(iterator.getValue()); // returns an io_object_t
if (device == null)
{
break; // end of the iterator.
}
// do stuff with the device here
kr = ioKit.IOObjectRelease(usbRef);
if (kr != IOReturn.kIOReturnSuccess)
{
logger.warn(String.format("Couldn't release device object: %08x", kr));
}
}
これは多くのデバイスを返しますが、どれも BSD Name プロパティまたはそれに似たものを持っていないようです。しかし、私が欲しかったデバイスは返されます。System Profiler を見ると、ターゲットにしているデバイスが表示され、そこに BSD 名が表示されます。
彼らはどのようにそれを手に入れていますか?
または、このようなことをループして、BSD デバイスから USB デバイスに直接移動する必要を回避する方法はありますか?