Linux 如何确定连接的 USB 设备是否为 USB 闪存驱动器?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9993050/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-06 05:34:51  来源:igfitidea点击:

How do I determine if a connected USB device is a USB flash drive?

linuxlinux-kernellinux-device-driverusb-flash-drive

提问by Boy

how do you determine what kind of media has been attached to the system?

您如何确定系统连接了哪种介质?

I have Ubuntu, and when I inserted an SD-card, it notices that it is in fact an SD card. Same counts for USB sticks.

我有 Ubuntu,当我插入 SD 卡时,它注意到它实际上是一个 SD 卡。USB 记忆棒的计数相同。

But how can I determine on low level when a new device is inserted, what kind of type it is?

但是,当插入新设备时,如何在低级别确定它是哪种类型?

There seems to be no information to be found on this at all.

似乎根本找不到这方面的信息。

edit: just to be more complete: I said it is a Linux environment, but actually it is Android in an Embedded environment. I tagged it Linux because I am indeed trying to check from command line.

编辑:为了更完整:我说它是Linux环境,但实际上它是嵌入式环境中的Android。我将它标记为 Linux,因为我确实在尝试从命令行进行检查。

The udevadm command is not available, and lsusb -vv shows:

udevadm 命令不可用,并且 lsusb -vv 显示:

Bus 001 Device 001: ID 1d6b:0002
Bus 001 Device 002: ID 0424:2640
Bus 001 Device 003: ID 0424:4040
Bus 002 Device 001: ID 1d6b:0001

which is very little info.

这是很少的信息。

采纳答案by hovanessyan

The lsusbcommand lists the USB devices registered in the system. Try lsusb -vvfor more detailed info. You can use the -sflag to target specific device.

lsusb命令列出系统中注册的 USB 设备。尝试lsusb -vv获取更详细的信息。您可以使用该-s标志来定位特定设备。

UPDATE: It depends on the permissions of your account, some details require higher privileges. For example here's the output for my mouse:

更新:这取决于您帐户的权限,某些细节需要更高的权限。例如,这是我鼠标的输出:

Bus 003 Device 003: ID 04f3:0230 Elan Microelectronics Corp. 
Device Descriptor:
  bLength                18
  bDescriptorType         1
  bcdUSB               1.10
  bDeviceClass            0 (Defined at Interface level)
  bDeviceSubClass         0 
  bDeviceProtocol         0 
  bMaxPacketSize0         8
  idVendor           0x04f3 Elan Microelectronics Corp.
  idProduct          0x0230 
  bcdDevice           24.58
  iManufacturer           0 
  iProduct                2 USB+PS/2 Optical Mouse
  iSerial                 0 
  bNumConfigurations      1
  Configuration Descriptor:
    bLength                 9
    bDescriptorType         2
    wTotalLength           34
    bNumInterfaces          1
    bConfigurationValue     1
    iConfiguration          0 
    bmAttributes         0xa0
      (Bus Powered)
      Remote Wakeup
    MaxPower              100mA
    Interface Descriptor:
      bLength                 9
      bDescriptorType         4
      bInterfaceNumber        0
      bAlternateSetting       0
      bNumEndpoints           1
      bInterfaceClass         3 Human Interface Device
      bInterfaceSubClass      1 Boot Interface Subclass
      bInterfaceProtocol      2 Mouse
      iInterface              0 
        HID Device Descriptor:
          bLength                 9
          bDescriptorType        33
          bcdHID               1.11
          bCountryCode            0 Not supported
          bNumDescriptors         1
          bDescriptorType        34 Report
          wDescriptorLength      52
         Report Descriptors: 
           ** UNAVAILABLE **
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x81  EP 1 IN
        bmAttributes            3
          Transfer Type            Interrupt
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0004  1x 4 bytes
        bInterval              10
Device Status:     0x0000

回答by Ilya Matveychikov

It may be useful to run such a command:

运行这样的命令可能很有用:

$ udevadm info -a -p $(udevadm info -q path -n /dev/sdX)

The output may looks like follows:

输出可能如下所示:

[...]
  looking at parent device '/devices/pci0000:00/0000:00:1a.0/usb1/1-1/1-1.5':
    KERNELS=="1-1.5"
    SUBSYSTEMS=="usb"
    DRIVERS=="usb"
    ATTRS{configuration}==""
    ATTRS{bNumInterfaces}==" 1"
    ATTRS{bConfigurationValue}=="1"
    ATTRS{bmAttributes}=="80"
    ATTRS{bMaxPower}=="200mA"
    ATTRS{urbnum}=="6519"
    ATTRS{idVendor}=="13fe"
    ATTRS{idProduct}=="1d00"
    ATTRS{bcdDevice}=="0100"
    ATTRS{bDeviceClass}=="00"
    ATTRS{bDeviceSubClass}=="00"
    ATTRS{bDeviceProtocol}=="00"
    ATTRS{bNumConfigurations}=="1"
    ATTRS{bMaxPacketSize0}=="64"
    ATTRS{speed}=="480"
    ATTRS{busnum}=="1"
    ATTRS{devnum}=="3"
    ATTRS{devpath}=="1.5"
    ATTRS{version}==" 2.00"
    ATTRS{maxchild}=="0"
    ATTRS{quirks}=="0x0"
    ATTRS{avoid_reset_quirk}=="0"
    ATTRS{authorized}=="1"
    ATTRS{manufacturer}=="Kingston"
    ATTRS{product}=="DataTraveler 2.0"
    ATTRS{serial}=="5B7A08A1010F"
[...]

You can see some ATTRSthat describes the device.

您可以看到一些ATTRS描述设备的内容。

回答by j?rgensen

how to determine if USB device is a USB stick

如何判断USB设备是否是U盘

SCNR. USB devices usually do not advertise their shape. Think of:

SCNR。USB 设备通常不会宣传其形状。考虑到:

  • stick-based CDROM devices out there?— usually in form of a mobile connections device to ship its own windows drivers
  • sticks for wireless keyboard/mice/HIDs/etc, or for audio Hymans
  • that fat MP3 player that blocks all the other USB ports nearby
  • 基于棒的 CDROM 设备在那里? - 通常以移动连接设备的形式提供自己的 Windows 驱动程序
  • 用于无线键盘/鼠标/HID/等,或用于音频插孔
  • 那个阻止附近所有其他 USB 端口的胖 MP3 播放器