1,008 瀏覽數

Linux – udev(7) 階層式的裝置名稱

在 /sys 裝置目錄下面裝置是以樹狀結構建立存放的.而且同一個裝置會依據屬性分別屬於不同裝置的子結點,比如一顆硬碟 sda 會分別屬於 /block/ 的子結點和 /devices/pci-bus/ 的子結點.

[root@benjr ~]# udevinfo -ap /sys/block/sda/
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/sda':
    KERNEL=="sda"
    SUBSYSTEM=="block"
    SYSFS{stat}=="   66506    30435  1907086   288822   205862   430773  5092764 11282351        0  1204560 11571133"
    SYSFS{size}=="286748000"
    SYSFS{removable}=="0"
    SYSFS{range}=="16"
    SYSFS{dev}=="8:0"
  looking at parent device '/devices/pci0000:00/0000:00:1c.2/0000:0c:00.0/host0/port-0:0/end_device-0:0/target0:0:0/0:0:0:0':
    ID=="0:0:0:0"
    BUS=="scsi"
    DRIVER=="sd"
    SYSFS{dh_state}=="detached"
    SYSFS{ioerr_cnt}=="0×0"
    SYSFS{iodone_cnt}=="0x42ea2"
    SYSFS{iorequest_cnt}=="0x42ea2"
    SYSFS{iocounterbits}=="32"
    SYSFS{timeout}=="60"
    SYSFS{state}=="running"
    SYSFS{rev}=="SB04"
    SYSFS{model}=="MBB2147RC       "
    SYSFS{vendor}=="IBM-ESXS"
    SYSFS{scsi_level}=="6"
    SYSFS{type}=="0"
    SYSFS{queue_type}=="simple"
    SYSFS{queue_depth}=="64"
    SYSFS{device_blocked}=="0"
  looking at parent device '/devices/pci0000:00/0000:00:1c.2/0000:0c:00.0/host0/port-0:0/end_device-0:0/target0:0:0':
    ID=="target0:0:0"
    BUS==""
    DRIVER==""
  looking at parent device '/devices/pci0000:00/0000:00:1c.2/0000:0c:00.0/host0/port-0:0/end_device-0:0':
    ID=="end_device-0:0"
    BUS==""
    DRIVER==""
  looking at parent device '/devices/pci0000:00/0000:00:1c.2/0000:0c:00.0/host0/port-0:0':
    ID=="port-0:0"
    BUS==""
    DRIVER==""
  looking at parent device '/devices/pci0000:00/0000:00:1c.2/0000:0c:00.0/host0':
    ID=="host0"
    BUS==""
    DRIVER==""
  looking at parent device '/devices/pci0000:00/0000:00:1c.2/0000:0c:00.0':
    ID=="0000:0c:00.0"
    BUS=="pci"
    DRIVER=="mptsas"
    SYSFS{broken_parity_status}=="0"
    SYSFS{enable}=="1"
    SYSFS{modalias}=="pci:v00001000d00000056sv00001014sd00000306bc01sc00i00"
    SYSFS{local_cpus}=="00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000"
    SYSFS{irq}=="169"
    SYSFS{class}=="0×010000"
    SYSFS{subsystem_device}=="0×0306"
    SYSFS{subsystem_vendor}=="0×1014"
    SYSFS{device}=="0×0056"
    SYSFS{vendor}=="0×1000"
  looking at parent device '/devices/pci0000:00/0000:00:1c.2':
    ID=="0000:00:1c.2"
    BUS=="pci"
    DRIVER=="pcieport-driver"
    SYSFS{broken_parity_status}=="0"
    SYSFS{enable}=="1"
    SYSFS{modalias}=="pci:v00008086d00002940sv00000000sd00000000bc06sc04i00"
    SYSFS{local_cpus}=="00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000000"
    SYSFS{irq}=="217"
    SYSFS{class}=="0×060400"
    SYSFS{subsystem_device}=="0×0000"
    SYSFS{subsystem_vendor}=="0×0000"
    SYSFS{device}=="0×2940"
    SYSFS{vendor}=="0×8086"
  looking at parent device '/devices/pci0000:00':
    ID=="pci0000:00"
    BUS==""
    DRIVER=="";

這些資料對於要寫 rules 是很有用的.你可以依據不同的屬性加以區別出不同的裝置並為各裝置命名!!

網友的想法

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

發表迴響