2

我想获取 USB 磁盘的名称及其在 Linux 中的路径,例如。“/media/Disk_data”。以下是我的方法

    private static void dumpDevice(Device device) throws LibUsbException {

        final int address = LibUsb.getDeviceAddress(device);
        final int busNumber = LibUsb.getBusNumber(device);

        System.out.println(String.format("Device %03d/%03d", busNumber, address));

        DeviceDescriptor deviceDescriptor = new DeviceDescriptor();
        LibUsb.getDeviceDescriptor(device, deviceDescriptor);

        for (byte i = 0; i < deviceDescriptor.bNumConfigurations(); i += 1)
        {
            final ConfigDescriptor descriptor = new ConfigDescriptor();
            final int result = LibUsb.getConfigDescriptor(device, i, descriptor);
            if (result < 0)
            {
                throw new LibUsbException(" abc Unable to read config descriptor",
                    result);
            }
            try
            {
                if(descriptor.dump().contains("Mass Storage")){
                    System.out.println("\nConfigDescriptor.dump() -> "+descriptor.dump());
                }
            }
            finally
            {
                // Ensure that the config descriptor is freed
                LibUsb.freeConfigDescriptor(descriptor);
            }
        }
}

我正在使用 usb4java-1.2.0.jar。它为我提供了有关“Disk_data”USB 驱动器配置的所有信息。但我没有得到它的路径。如何使用这个库获取这个特定磁盘的名称和整个路径?

4

0 回答 0