udev -在一个符号链接下收集usb类



我有4端口USB集线器连接多个USB设备具有相同/类似(一个或多个类可能是/可能不可用)的功能,我想在一个符号链接目录下收集设备类与端口/路径标识

它应该看起来像:

/dev/usb_port0
└── tty*
└── hidraw*
└── sd*
└── ...
/dev/usb_port1
└── tty*
└── hidraw*
└── sd*
└── ...
/dev/usb_port-n
└── tty*
└── hidraw*
└── sd*
└── ...   

Device-A连接端口2 - hidraw类:

$ udevadm info --attribute-walk /dev/hidraw0
looking at device '/devices/platform/scb/fd500000.pcie/pci0000:00/0000:00:00.0/0000:01:00.0/usb1/1-1/1-1.4/1-1.4.2/1-1.4.2:1.3/0003:0D28:0204.0016/hidraw/hidraw0':
KERNEL=="hidraw0"
SUBSYSTEM=="hidraw"
DRIVER==""
looking at parent device '/devices/platform/scb/fd500000.pcie/pci0000:00/0000:00:00.0/0000:01:00.0/usb1/1-1/1-1.4/1-1.4.2/1-1.4.2:1.3/0003:0D28:0204.0016':
KERNELS=="0003:0D28:0204.0016"
SUBSYSTEMS=="hid"
DRIVERS=="hid-generic"
ATTRS{country}=="00"
looking at parent device '/devices/platform/scb/fd500000.pcie/pci0000:00/0000:00:00.0/0000:01:00.0/usb1/1-1/1-1.4/1-1.4.2/1-1.4.2:1.3':
KERNELS=="1-1.4.2:1.3"
SUBSYSTEMS=="usb"
DRIVERS=="usbhid"
...
looking at parent device '/devices/platform/scb/fd500000.pcie/pci0000:00/0000:00:00.0/0000:01:00.0/usb1/1-1/1-1.4/1-1.4.2':
KERNELS=="1-1.4.2"
SUBSYSTEMS=="usb"
DRIVERS=="usb"
...
ATTRS{product}=="DAPLink CMSIS-DAP"
looking at parent device '/devices/platform/scb/fd500000.pcie/pci0000:00/0000:00:00.0/0000:01:00.0/usb1/1-1/1-1.4':
KERNELS=="1-1.4"
SUBSYSTEMS=="usb"
DRIVERS=="usb"
...
ATTRS{product}=="USB2.0 Hub             "
ATTRS{manufacturer}=="VIA Labs, Inc.         "

设备a连接端口2 - tty类:

udevadm info --attribute-walk /dev/ttyACM0
looking at device '/devices/platform/scb/fd500000.pcie/pci0000:00/0000:00:00.0/0000:01:00.0/usb1/1-1/1-1.4/1-1.4.2/1-1.4.2:1.1/tty/ttyACM0':
KERNEL=="ttyACM0"
SUBSYSTEM=="tty"
DRIVER==""
looking at parent device '/devices/platform/scb/fd500000.pcie/pci0000:00/0000:00:00.0/0000:01:00.0/usb1/1-1/1-1.4/1-1.4.2/1-1.4.2:1.1':
KERNELS=="1-1.4.2:1.1"
SUBSYSTEMS=="usb"
DRIVERS=="cdc_acm"
...
looking at parent device '/devices/platform/scb/fd500000.pcie/pci0000:00/0000:00:00.0/0000:01:00.0/usb1/1-1/1-1.4/1-1.4.2':
KERNELS=="1-1.4.2"
SUBSYSTEMS=="usb"
DRIVERS=="usb"
...
ATTRS{product}=="DAPLink CMSIS-DAP"
looking at parent device '/devices/platform/scb/fd500000.pcie/pci0000:00/0000:00:00.0/0000:01:00.0/usb1/1-1/1-1.4':
KERNELS=="1-1.4"
SUBSYSTEMS=="usb"
DRIVERS=="usb"
...
ATTRS{manufacturer}=="VIA Labs, Inc.         "
ATTRS{product}=="USB2.0 Hub     
"

udev规则:/etc/udev/rules.d/90-port-2.rules

ACTION!="add|change", GOTO="debug_rules"
DEVPATH!="*1-1.4.2", GOTO="debug_rules"
ACTION=="add", GROUP="usb", MODE="0666", SYMLINK+="usbdev/%k-%n"
LABEL="debug_rules"

$ journalctl -f | grep usbdev说:

systemd-udevd[5608]: 1-1.4.2: /etc/udev/rules.d/90-port-2.rules:4 LINK 'usbdev/1-1.4.2-2'
systemd-udevd[5608]: 1-1.4.2: Creating symlink '/dev/usbdev/1-1.4.2-2' to '../bus/usb/001/029'
systemd-udevd[5612]: 1-1.4.2: Updating old name, '/dev/usbdev/1-1.4.2-2' no longer belonging to '/devices/platform/scb/fd500000.pcie/pci0000:00/0000:00:00.0/0000:01:00.0/usb1/1-1/1-1.4/1-1.4.2'
systemd-udevd[5612]: 1-1.4.2: No reference left, removing '/dev/usbdev/1-1.4.2-2'

请问,你知道如何实现这个方法吗?

在udev管理页和调试注销后,我找到了答案。

我以前的规则missbind行动

ACTION!="add|change", GOTO="debug_rules"

ACTION!="add|bind", GOTO="debug_rules"

KERNELS=="1-1.4.2:*", SUBSYSTEM=="hidraw|tty|scsi_generic", OWNER="ubuntu", GROUP="usb", SYMLINK+="usbport/2/%k", , MODE="0666", OPTIONS+="last_rule", GOTO="debug_rules"

和符号链接是(树视图)

/dev/usbport/
└── 2
├── hidraw0 -> ../../hidraw0
├── sg0 -> ../../sg0
└── ttyACM0 -> ../../ttyACM0

相关内容

  • 没有找到相关文章

最新更新