我有 2 个相同的 USB 设备。仅创建了一个持久符号链接:
/dev/v4l/by-id/usb-fushicai_usbtv007_300000000002-video-index0
我认为这是因为 /usr/lib/udev/rules.d/60-persistent-v4l.rules 用于ATTR{index}
区分它们,但它始终为零:
for d in /dev/video*; do echo $d; udevadm info -a $d | grep 'ATTRS.manufacturer\|ATTR.index\|ATTR.name'; echo ; done
/dev/video0
ATTR{index}=="0"
ATTR{name}=="Loopback video device 0"
/dev/video1
ATTR{index}=="0"
ATTR{name}=="Loopback video device 1"
/dev/video2
ATTR{index}=="0"
ATTR{name}=="Loopback video device 2"
/dev/video3
ATTR{index}=="0"
ATTR{name}=="Loopback video device 3"
/dev/video4
ATTR{index}=="0"
ATTR{name}=="usbtv"
ATTRS{manufacturer}=="fushicai"
ATTRS{manufacturer}=="Linux 4.2.5-1-ARCH ehci_hcd"
/dev/video5
ATTR{index}=="0"
ATTR{name}=="usbtv"
ATTRS{manufacturer}=="fushicai"
ATTRS{manufacturer}=="Linux 4.2.5-1-ARCH ehci_hcd"
/dev/video6
ATTR{index}=="0"
ATTR{name}=="stk1160"
ATTRS{manufacturer}=="Syntek Semiconductor"
ATTRS{manufacturer}=="Linux 4.2.5-1-ARCH xhci-hcd"
谁分配了此属性?如何解决此问题?
完整输出以供比较。 http://pastebin.com/0zcf7Szk http://pastebin.com/UgWgqpJz
如您所见,唯一的区别是插入的 USB 端口。
答案1
编写了一个脚本,通过模式查找未占用的设备索引。它接受类似 printf 模式/dev/v4l/by-id/usb-fushicai_usbtv007_300000000002-video-index%d
并查找第一个不存在的文件。
从 systemd 包中获取现有规则并将其重写为使用脚本结果而不是ATTR{index}
。由于ATTR{index}
不可修改,决定使用我自己的目录作为符号链接。
/etc/udev/rules.d/65-persistent-v4l-my.rules:
ACTION=="remove", GOTO="my_fix_v4l_index_end"
SUBSYSTEM!="video4linux", GOTO="my_fix_v4l_index_end"
ENV{MAJOR}=="", GOTO="my_fix_v4l_index_end"
IMPORT{program}="v4l_id $devnode"
SUBSYSTEMS=="usb", IMPORT{builtin}="usb_id"
KERNEL=="video*", ENV{ID_SERIAL}=="?*", ENV{UNOCCUPIED_PATTERN}="v4l/by-id-my/$env{ID_BUS}-$env{ID_SERIAL}-video-index%%d"
IMPORT{program}="/usr/local/bin/find-unoccupied-device-index /dev/$env{UNOCCUPIED_PATTERN}"
KERNEL=="video*", ENV{ID_SERIAL}=="?*", SYMLINK+="v4l/by-id-my/$env{ID_BUS}-$env{ID_SERIAL}-video-index$env{UNOCCUPIED_INDEX}"
LABEL="my_fix_v4l_index_end"
在 /usr/local/bin/find-未占用设备索引中:
#!/bin/bash
set -e
if [ $# != 1 ]; then
>&2 echo "usage: ${0##*/} prefix-%d-suffix"
exit 1
fi
echo "pattern: $1" >&2
for ((i=0;;i++)); do
filename=`printf "$1" $i`
[ -e "$filename" ] || break
done
echo "unoccupied index: $i" >&2
echo "UNOCCUPIED_INDEX=$i"