linux usb设备如何和u盘对应

3 篇文章 0 订阅
1 篇文章 0 订阅

已知 usb 的 pid vid,如何对加载的u盘进行管理

思路,找到 U盘的厂商信息中的pid和 vid 对应关系,然后控制 U盘的加载
但是 U盘信息中没有pid 和 vid

root@li-PC:/sys/kernel/debug/usb# df
文件系统          1K-块     已用     可用 已用% 挂载点
udev             945652        0   945652    0% /dev
tmpfs            195140     1528   193612    1% /run
/dev/sda2      37924256 13317744 22650368   38% /
tmpfs            975692    45420   930272    5% /dev/shm
tmpfs              5120        4     5116    1% /run/lock
tmpfs            975692        0   975692    0% /sys/fs/cgroup
tmpfs            195136       20   195116    1% /run/user/1001
/dev/sdc1      61438976   106624 61332352    1% /media/bkdrong/新加卷

root@li-PC:/sys/kernel/debug/usb# lsusb -v
显示的部分内容
Bus 001 Device 003: ID 090c:1000 Silicon Motion, Inc. - Taiwan (formerly Feiya Technology Corp.) Flash Drive
Device Descriptor:
  bLength                18
  bDescriptorType         1
  bcdUSB               2.10
  bDeviceClass            0 (Defined at Interface level)
  bDeviceSubClass         0
  bDeviceProtocol         0
  bMaxPacketSize0        64
  idVendor           0x090c Silicon Motion, Inc. - Taiwan (formerly Feiya Technology Corp.)
  idProduct          0x1000 Flash Drive
  bcdDevice           11.00
  iManufacturer           1 aigo
  iProduct                2 MiniKing
  iSerial                 3 AA00000000007330
  bNumConfigurations      1
  Configuration Descriptor:
    bLength                 9
    bDescriptorType         2
    wTotalLength           32
    bNumInterfaces          1
    bConfigurationValue     1
    iConfiguration          0
    bmAttributes         0x80
      (Bus Powered)
    MaxPower              300mA
    Interface Descriptor:
      bLength                 9
      bDescriptorType         4
      bInterfaceNumber        0
      bAlternateSetting       0
      bNumEndpoints           2
      bInterfaceClass         8 Mass Storage
      bInterfaceSubClass      6 SCSI
      bInterfaceProtocol     80 Bulk-Only
      iInterface              0
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x01  EP 1 OUT
        bmAttributes            2
          Transfer Type            Bulk
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0200  1x 512 bytes
        bInterval               0
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x82  EP 2 IN
        bmAttributes            2
          Transfer Type            Bulk
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0200  1x 512 bytes
        bInterval               0

  • 这里面包含了vid 和 pid 还有 序列号信息
root@li-PC:/dev/disk/by-id# ls -l
总用量 0
lrwxrwxrwx 1 root root  9 4月  12 15:08 ata-VMware_Virtual_SATA_CDRW_Drive_01000000000000000001 -> ../../sr0
lrwxrwxrwx 1 root root  9 4月  12 15:40 usb-aigo_MiniKing_AA00000000007330-0:0 -> ../../sdc
lrwxrwxrwx 1 root root 10 4月  12 15:40 usb-aigo_MiniKing_AA00000000007330-0:0-part1 -> ../../sdc1

中每一个设备永久的描述符中含有 序列号,并且和设备 /dev/sdc … 有个对应关系。

pid+vid <-> usb序列号 <-> u盘的设备名
这样就将 pid +vid 和 u盘的设备名相对应,就可以进行管理了。

书以博客以记之.

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值