哪些udev规则会被执行用于USB设备?

3

我对udev不熟悉。我需要查看在Linux机器上插入USB设备时执行的规则。udev是否提供任何日志记录?


请访问 https://superuser.com/a/1501568/111302 以获取答案。 - MarcH
3个回答

0

这正是

udevadm trigger --verbose ...

将会告诉你。它将触发udev规则的重新评估,您可以使用其他标志,例如--subsystem-match--attr-match来缩小USB设备的范围。

man udevadm

要查找您的USB设备的这些属性,请使用

lsusb -v

2
它没有告诉我们针对这个USB设备执行了哪些规则? - kayle

0
尝试类似这样的命令:udevadm test /dev/bus/usb/001/045

我尝试了这个,它显示为“读取规则文件”,并显示所有规则文件。我需要知道确切地为此设备执行了哪个规则文件。感谢您的贡献 :) - kayle
1
这并没有提供问题的答案。如果您想对作者进行批评或请求澄清,请在他们的帖子下留言。 - Mathias
udevadm test 显示的所有文件都会为每个设备读取。但是,每个设备只使用每个文件中匹配的行。 - Henrik Carlqvist
@Mathias 我的回答并不是任何批评或请求澄清,只是试图显示列出已使用 udev 规则文件的方法。我的回答缺少什么来回答这个问题? - Henrik Carlqvist

0

Carlqvist的回答是正确的,但它忽略了大部分细节。以下是一个真实案例...

问题: 我的USB键盘在gNewsense设置中可以使用,但在SourceMage中无法使用。下面是我尝试找出在gNewsense中应用于此键盘的udev规则。

1)获取基本信息

# lsusb
[...omitted...]
Bus 007 Device 006: ID 413c:2003 Dell Computer Corp. Keyboard
[...omitted...]

现在我知道了...

USB设备节点(不同于键盘设备)是/dev/bus/usb/007/006,idVendor=413c,idProduct=2003。如果键盘没有任何标志或印记,我将无法搜索到人性化的文本。

现在,键盘和鼠标都在/dev/input/*下,这是你必须知道或从网页中获取的信息。我很幸运,有一个/dev/input/by-id/usb-Dell_Dell_USB_Keyboard-event-kbd的符号链接。

在我的情况下,它是指向/dev/input/event0的符号链接。

2)这将获取键盘的“其他”设备路径(内核或udev内部)。

# udevadm info --query=path --name=/dev/input/by-id/usb-Dell_Dell_USB_Keyboard-event-kbd
/devices/pci0000:00/0000:00:1d.1/usb7/7-1/7-1:1.0/input/input9/event0

3) 现在,是什么规则使得这个键盘工作?

请注意,grep idVendor和idProduct可能已经足够了,但通常有通配符和默认内置情况来完成大部分工作。

udevadm test命令将告诉您所有规则,以处理此事件期间(将USB键盘插入USB连接器的事件)的顺序。

parse_file开头的行会显示实际上被挂钩到(e)udev中的规则脚本文件,按照它们被读取的顺序(较低的数字前缀应该是第一个)。这通常是一堆垃圾文件,所以现在先忽略它们。

udev_node_mknod开头的行很有趣,因为那时udev实际上会创建设备节点。

udev_rules_apply_to_event开头的行可能是您感兴趣的。它提供了触发udev中某些更改的规则脚本文件和行号。

这是我的输出。会有很多噪音(我已省略),但您仍然可以跟踪并查看dev节点的创建过程。

# udevadm test /devices/pci0000:00/0000:00:1d.1/usb7/7-1/7-1:1.0/input/input9/event0
[...]
parse_file: reading '/lib/udev/rules.d/69-cd-sensors.rules' as rules file
add_rule: IMPORT found builtin 'usb_id', replacing /lib/udev/rules.d/69-cd-sensors.rules:78
[...]
udev_rules_apply_to_event: IMPORT builtin 'input_id' /lib/udev/rules.d/50-udev-default.rules:4
[...]
udev_builtin_add_property: ID_INPUT_KEY=1
udev_builtin_add_property: ID_INPUT_KEYBOARD=1
[...]
udev_rules_apply_to_event: IMPORT builtin 'usb_id' /lib/udev/rules.d/60-persistent-input.rules:7
builtin_usb_id: /sys/devices/pci0000:00/0000:00:1d.1/usb7/7-1/7-1:1.0: if_class 3 protocol 0
udev_builtin_add_property: ID_VENDOR=Dell
udev_builtin_add_property: ID_VENDOR_ENC=Dell
udev_builtin_add_property: ID_VENDOR_ID=413c
udev_builtin_add_property: ID_MODEL=Dell_USB_Keyboard
udev_builtin_add_property: ID_MODEL_ENC=Dell\x20USB\x20Keyboard
udev_builtin_add_property: ID_MODEL_ID=2003
[...]
udev_rules_apply_to_event: LINK 'input/by-id/usb-Dell_Dell_USB_Keyboard-event-kbd' /lib/udev/rules.d/60-persistent-input.rules:24
udev_rules_apply_to_event: IMPORT builtin 'path_id' /lib/udev/rules.d/60-persistent-input.rules:31
udev_builtin_add_property: ID_PATH=pci-0000:00:1d.1-usb-0:1:1.0
udev_builtin_add_property: ID_PATH_TAG=pci-0000_00_1d_1-usb-0_1_1_0
udev_rules_apply_to_event: LINK 'input/by-path/pci-0000:00:1d.1-usb-0:1:1.0-event-kbd' /lib/udev/rules.d/60-persistent-input.rules:33
udev_rules_apply_to_event: IMPORT builtin skip 'usb_id' /lib/udev/rules.d/95-keymap.rules:13
udev_event_execute_rules: no node name set, will use kernel supplied name 'input/event0'
udev_node_add: creating device node '/dev/input/event0', devnum=13:64, mode=01600, uid=0, gid=0
udev_node_mknod: preserve file '/dev/input/event0', because it has correct dev_t
udev_node_mknod: preserve permissions /dev/input/event0, 021600, uid=0, gid=0
node_symlink: preserve already existing symlink '/dev/char/13:64' to '../input/event0'
link_find_prioritized: found 'c13:64' claiming '/run/udev/links/input\x2fby-id\x2fusb-Dell_Dell_USB_Keyboard-event-kbd'
link_update: creating link '/dev/input/by-id/usb-Dell_Dell_USB_Keyboard-event-kbd' to '/dev/input/event0'
node_symlink: preserve already existing symlink '/dev/input/by-id/usb-Dell_Dell_USB_Keyboard-event-kbd' to '../event0'
link_find_prioritized: found 'c13:64' claiming '/run/udev/links/input\x2fby-path\x2fpci-0000:00:1d.1-usb-0:1:1.0-event-kbd'
link_update: creating link '/dev/input/by-path/pci-0000:00:1d.1-usb-0:1:1.0-event-kbd' to '/dev/input/event0'
node_symlink: preserve already existing symlink '/dev/input/by-path/pci-0000:00:1d.1-usb-0:1:1.0-event-kbd' to '../event0'
udev_device_update_db: created db file '/run/udev/data/c13:64' for '/devices/pci0000:00/0000:00:1d.1/usb7/7-1/7-1:1.0/input/input9/event0'
.INPUT_CLASS=kbd
ACTION=add
[...]
[end]

udevadm can be called with the --debug flag to have additional lines. So something like that: udevadm --debug test /devices/pci0.... - benjarobin

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接