您应该弄清楚您的外部端口与哪个USB总线连接。在我的电脑上所有外部USB端口都连接到Bus 01
要做这个检查lsusb -t的输出,然后附上一个usb设备并再次检查输出lsusb -t。那么你知道什么是 '不会忽略' 你的三个外部USB端口在你的设备内部USB结构树:
内部USB端口:
/: Bus 04.Port 1: Dev 1, Class=root_hub, Driver=ohci_hcd/5p, 12M
/: Bus 03.Port 1: Dev 1, Class=root_hub, Driver=ohci_hcd/5p, 12M
/: Bus 02.Port 1: Dev 1, Class=root_hub, Driver=ehci_hcd/5p, 480M
|__ Port 1: Dev 64, If 0, Class='bInterfaceClass 0x0e not yet handled', Driver=uvcvideo, 480M
|__ Port 1: Dev 64, If 1, Class='bInterfaceClass 0x0e not yet handled', Driver=uvcvideo, 480M
外部USB端口:
/: Bus 01.Port 1: Dev 1, Class=root_hub, Driver=ehci_hcd/5p, 480M
|__ Port 3: Dev 116, If 0, Class='bInterfaceClass 0xe0 not yet handled', Driver=rndis_host, 480M
|__ Port 3: Dev 116, If 1, Class=data, Driver=rndis_host, 480M
USB记忆棒连接到外部端口#2
/: Bus 01.Port 1: Dev 1, Class=root_hub, Driver=ehci_hcd/5p, 480M
|__ Port 2: Dev 119, If 0, Class=stor., Driver=usb-storage, 480M
|__ Port 3: Dev 116, If 0, Class='bInterfaceClass 0xe0 not yet handled', Driver=rndis_host, 480M
|__ Port 3: Dev 116, If 1, Class=data, Driver=rndis_host, 480M
此程序后,您的'地址'您的外部USB端口
在dmesg连接的USB设备总是与包含USB总线和端口号的行出现:
[186067.360139] usb 1-1: new high-speed USB device number 123 using ehci_hcd是总线001的端口001
[186067.360139] usb 1-2: new high-speed USB device number 123 using ehci_hcd是总线001的端口002
[186067.360139] usb 1-3: new high-speed USB device number 123 using ehci_hcd是总线001端口003
你可以得到的端口号直接使用命令
dmesg | grep -o -P 'usb 1.{0,3}' | tail -1 | head -c 7 | tail -c 1(如果您的所有外部端口上Bus 001)
因此,您可以获得最新USB设备(您的设备)所连接的USB端口号,您可以在udev脚本中使用该端口号(if ...)
你也可以找到在/dev/bus/usb/文件系统正即总线01端口1 USB总线树结构/dev/bus/usb/001/001