1,059 瀏覽數

Linux – udev(6) 比對(Matching) sysfs 屬性(attributes)

使用 udevinfo 看得到的最多的資訊就是 SYSFS{key}.

[root@benjr ~]# udevinfo -ap /sys/block/hdc
Udevinfo starts with the device specified by the devpath and then
walks up the chain of parent devices. It prints for every device
found, all possible attributes in the udev rules key format.
A rule to match, can be composed by the attributes of the device
and the attributes from one single parent device.
  looking at device '/block/hdc':
    KERNEL=="hdc"
    SUBSYSTEM=="block"
    SYSFS{stat}=="       0        0        0        0        0        0        0        0        0        0        0"
    SYSFS{size}=="8388604"
    SYSFS{removable}=="1"
    SYSFS{range}=="1"
    SYSFS{dev}=="22:0"

  looking at parent device '/devices/ide1/1.0':
    ID=="1.0"
    BUS=="ide"
    DRIVER=="ide-cdrom"
    SYSFS{modalias}=="ide:m-cdrom"
    SYSFS{drivename}=="hdc"
    SYSFS{media}=="cdrom"

  looking at parent device '/devices/ide1':
    ID=="ide1"
    BUS==""
    DRIVER==""

SYSFS 是存在 /sys 的一個檔案值,如 SYSFS{dev} 就是儲存在 /sys/block/hdc/dev .這個值也是可以拿來比對(matching)的條件,不過在使用上和一般 Rules 一樣. 比如 /etc/udev/rules.d/50-udev.rules 就使用了 SYSFS{removable}=="1", SYSFS{device/media}=="cdrom" 當做比對條件.

KERNEL=="hd[a-z]", BUS=="ide", SYSFS{removable}=="1", SYSFS{device/media}=="cdrom", SYMLINK+="cdrom cdrom-%k"

網友的想法

  1. 自動參照通知: Linux – udev | Benjr.tw

發表迴響