我有两种具有相同 udev 属性的游戏手柄。一种是 USB NES 控制器,另一种是 USB SNES 控制器。两者的 udev 信息相同。
P: /devices/pci0000:00/0000:00:1c.6/0000:0e:00.0/usb3/3-1/3-1:1.0/input/input18/js2
N: input/js2
S: input/by-id/usb-0079_USB_Gamepad-joystick
S: input/by-path/pci-0000:0e:00.0-usb-0:1:1.0-joystick
E: DEVLINKS=/dev/input/by-id/usb-0079_USB_Gamepad-joystick /dev/input/by-path/pci-0000:0e:00.0-usb-0:1:1.0-joystick
E: DEVNAME=/dev/input/js2
E: DEVPATH=/devices/pci0000:00/0000:00:1c.6/0000:0e:00.0/usb3/3-1/3-1:1.0/input/input18/js2
E: ID_BUS=usb
E: ID_FOR_SEAT=input-pci-0000_0e_00_0-usb-0_1_1_0
E: ID_INPUT=1
E: ID_INPUT_JOYSTICK=1
E: ID_MODEL=USB_Gamepad
E: ID_MODEL_ENC=USB\x20Gamepad\x20
E: ID_MODEL_ID=0011
E: ID_PATH=pci-0000:0e:00.0-usb-0:1:1.0
E: ID_PATH_TAG=pci-0000_0e_00_0-usb-0_1_1_0
E: ID_REVISION=0106
E: ID_SERIAL=0079_USB_Gamepad
E: ID_TYPE=hid
E: ID_USB_DRIVER=usbhid
E: ID_USB_INTERFACES=:030000:
E: ID_USB_INTERFACE_NUM=00
E: ID_VENDOR=0079
E: ID_VENDOR_ENC=0079
E: ID_VENDOR_ID=0079
E: MAJOR=13
E: MINOR=2
E: SUBSYSTEM=input
E: TAGS=:seat:uaccess:
E: USEC_INITIALIZED=738808992
应用程序使用 ID_MODEL 值来识别控制器并分配按钮映射。我有几个游戏手柄可以做同样的事情,但在本例中我将其保留为 2 个。
我如何让 udev 重命名或为具有相同信息的不同设备设置别名?该规则是什么样的?
looking at device '/devices/pci0000:00/0000:00:1c.6/0000:0e:00.0/usb3/3-1/3-1:1.0/input/input32/js2':
KERNEL=="js2"
SUBSYSTEM=="input"
DRIVER==""
looking at parent device '/devices/pci0000:00/0000:00:1c.6/0000:0e:00.0/usb3/3-1/3-1:1.0/input/input32':
KERNELS=="input32"
SUBSYSTEMS=="input"
DRIVERS==""
ATTRS{name}=="USB Gamepad "
ATTRS{phys}=="usb-0000:0e:00.0-1/input0"
ATTRS{uniq}==""
ATTRS{properties}=="0"
looking at parent device '/devices/pci0000:00/0000:00:1c.6/0000:0e:00.0/usb3/3-1/3-1:1.0':
KERNELS=="3-1:1.0"
SUBSYSTEMS=="usb"
DRIVERS=="usbhid"
ATTRS{bInterfaceClass}=="03"
ATTRS{bInterfaceSubClass}=="00"
ATTRS{bInterfaceProtocol}=="00"
ATTRS{bNumEndpoints}=="01"
ATTRS{supports_autosuspend}=="1"
ATTRS{bAlternateSetting}==" 0"
ATTRS{bInterfaceNumber}=="00"
looking at parent device '/devices/pci0000:00/0000:00:1c.6/0000:0e:00.0/usb3/3-1':
KERNELS=="3-1"
SUBSYSTEMS=="usb"
DRIVERS=="usb"
ATTRS{bDeviceSubClass}=="00"
ATTRS{bDeviceProtocol}=="00"
ATTRS{devpath}=="1"
ATTRS{idVendor}=="0079"
ATTRS{speed}=="1.5"
ATTRS{bNumInterfaces}==" 1"
ATTRS{bConfigurationValue}=="1"
ATTRS{bMaxPacketSize0}=="8"
ATTRS{busnum}=="3"
ATTRS{devnum}=="15"
ATTRS{configuration}==""
ATTRS{bMaxPower}=="100mA"
ATTRS{authorized}=="1"
ATTRS{bmAttributes}=="80"
ATTRS{bNumConfigurations}=="1"
ATTRS{maxchild}=="0"
ATTRS{bcdDevice}=="0106"
ATTRS{avoid_reset_quirk}=="0"
ATTRS{quirks}=="0x0"
ATTRS{version}==" 1.00"
ATTRS{urbnum}=="13"
ATTRS{ltm_capable}=="no"
ATTRS{removable}=="unknown"
ATTRS{idProduct}=="0011"
ATTRS{bDeviceClass}=="00"
ATTRS{product}=="USB Gamepad "
looking at parent device '/devices/pci0000:00/0000:00:1c.6/0000:0e:00.0/usb3':
KERNELS=="usb3"
SUBSYSTEMS=="usb"
DRIVERS=="usb"
ATTRS{bDeviceSubClass}=="00"
ATTRS{bDeviceProtocol}=="01"
ATTRS{devpath}=="0"
ATTRS{idVendor}=="1d6b"
ATTRS{speed}=="480"
ATTRS{bNumInterfaces}==" 1"
ATTRS{bConfigurationValue}=="1"
ATTRS{bMaxPacketSize0}=="64"
ATTRS{authorized_default}=="1"
ATTRS{busnum}=="3"
ATTRS{devnum}=="1"
ATTRS{configuration}==""
ATTRS{bMaxPower}=="0mA"
ATTRS{authorized}=="1"
ATTRS{bmAttributes}=="e0"
ATTRS{bNumConfigurations}=="1"
ATTRS{maxchild}=="2"
ATTRS{bcdDevice}=="0313"
ATTRS{avoid_reset_quirk}=="0"
ATTRS{quirks}=="0x0"
ATTRS{serial}=="0000:0e:00.0"
ATTRS{version}==" 2.00"
ATTRS{urbnum}=="241"
ATTRS{ltm_capable}=="no"
ATTRS{manufacturer}=="Linux 3.13.0-74-generic xhci_hcd"
ATTRS{removable}=="unknown"
ATTRS{idProduct}=="0002"
ATTRS{bDeviceClass}=="09"
ATTRS{product}=="xHCI Host Controller"
looking at parent device '/devices/pci0000:00/0000:00:1c.6/0000:0e:00.0':
KERNELS=="0000:0e:00.0"
SUBSYSTEMS=="pci"
DRIVERS=="xhci_hcd"
ATTRS{irq}=="18"
ATTRS{subsystem_vendor}=="0x17aa"
ATTRS{broken_parity_status}=="0"
ATTRS{class}=="0x0c0330"
ATTRS{consistent_dma_mask_bits}=="64"
ATTRS{dma_mask_bits}=="64"
ATTRS{local_cpus}=="00000000,00000000,00000000,00000000,00000000,00000000,00000000,000000ff"
ATTRS{device}=="0x0194"
ATTRS{enable}=="1"
ATTRS{msi_bus}==""
ATTRS{local_cpulist}=="0-7"
ATTRS{vendor}=="0x1033"
ATTRS{subsystem_device}=="0x21cf"
ATTRS{numa_node}=="-1"
ATTRS{d3cold_allowed}=="1"
looking at parent device '/devices/pci0000:00/0000:00:1c.6':
KERNELS=="0000:00:1c.6"
SUBSYSTEMS=="pci"
DRIVERS=="pcieport"
ATTRS{irq}=="18"
ATTRS{subsystem_vendor}=="0x17aa"
ATTRS{broken_parity_status}=="0"
ATTRS{class}=="0x060400"
ATTRS{consistent_dma_mask_bits}=="32"
ATTRS{dma_mask_bits}=="32"
ATTRS{local_cpus}=="00000000,00000000,00000000,00000000,00000000,00000000,00000000,000000ff"
ATTRS{device}=="0x1c1c"
ATTRS{enable}=="2"
ATTRS{msi_bus}=="1"
ATTRS{local_cpulist}=="0-7"
ATTRS{vendor}=="0x8086"
ATTRS{subsystem_device}=="0x21cf"
ATTRS{numa_node}=="-1"
ATTRS{d3cold_allowed}=="0"
looking at parent device '/devices/pci0000:00':
KERNELS=="pci0000:00"
SUBSYSTEMS==""
DRIVERS==""
答案1
不同物理设备的 vendor_id、product_id 和 serial_nbr 可能完全相同。要检查,请/var/log/messages
在插入设备后逐个查找,以便在它们之间出现一些 id 差异时能够区分它们。
A)如果除了产品 ID 和供应商 ID 之外,设备间的序列号也相同,请阅读这里(正如@ChrisObrian在之前的文章中指出的那样回答)。他的回答原则上与 @Grumbel 在此线程中提供的答案相同。这也可能使您的帖子成为复制无论如何,向上搜索 devpath 以查找匹配的设备名称,您的 udev 规则可以是:
SUBSYSTEMS=="input", ATTRS{name}=="USB Gamepad ", KERNELS=="input[0-9]*", SYMLINK+="gamepad_Z"
B)如果序列号不相同,您将有以下简单的 udev 规则(每个设备一个):
SUBSYSTEM=="input", ATTRS{idVendor}=="0079", ATTRS{idProduct}=="XXXX", ATTRS{serial}=="YYYYYY", SYMLINK+="gamepad_Z"
您必须在其中填写 XXXX 和 YYYYYY 来自输出udevadmin info ...
或/var/log/messages
插入设备时的适当值。
笔记:在上述两种情况下,您可以任意选择 Z。Yr 设备将显示为/dev/gamepad_Z
始终指向相同的物理设备。
答案2
如果您无法通过其他方式区分设备,您可以始终使用 USB 路径ID_PATH
,因为这是设备所连接的实际 USB 端口的名称。然后,您只需始终将设备插入同一个 USB 端口即可。