Another new change in sysfs that will be in the 2.6.18 kernel release, is
the addition of another symlink in all device and class device directories.
Kay Sievers has written a patch that adds the symlink "
subsystem"
to these directories. This symlink points back to either the class that
the device is associated with, or the bus that the device is associated
with.
This symlink is identical to the information that the kernel has always
been emitting to userspace through the hotplug interface whenever a device
was created or removed from the system. Userspace uses the subsystem
information in order to determine what to do with the device.
If you look at the older hotplug package, it is broken down into a set of
different scripts that run depending on the subsystem that is being
addressed:
$ ls /etc/hotplug/*.rc
/etc/hotplug/input.rc
/etc/hotplug/isapnp.rc
/etc/hotplug/pci.rc
/etc/hotplug/pnp.rc
/etc/hotplug/usb.rc
And udev rules also act on the subsystem type in order to determine what to
do with the device:
$ head -n 3 /etc/udev/rules.d/05-udev-early.rules
# ignore these events until someone needs them
SUBSYSTEM=="drivers", OPTIONS="ignore_device"
SUBSYSTEM=="module", OPTIONS="ignore_device"
But before this kernel patch, if a program wanted to walk through sysfs and
try to determine the subsystem that a specific device was associated with,
they had to do the following steps:
- If this is a device, look for the bus symlink and follow
it.
- If this is a class device, go up a directory and see if this is a class
directory. If not, go up another directory, until the class is found.
Now, with the subsystem symlink, this logic can be greatly simplified, as
only this symlink needs to be followed in order to determine the subsystem
that the device is associated with:
$ tree /sys/class/tty/ttyS0/
/sys/class/tty/ttyS0/
|-- dev
|-- device -> ../../../devices/platform/serial8250
|-- subsystem -> ../../../class/tty
`-- uevent
$ tree /sys/devices/pci0000:00/0000:00:00.0/
/sys/devices/pci0000:00/0000:00:00.0/
|-- broken_parity_status
|-- bus -> ../../../bus/pci
|-- class
|-- config
|-- device
|-- driver -> ../../../bus/pci/drivers/e752x_edac
|-- enable
|-- irq
|-- local_cpus
|-- modalias
|-- power
| |-- state
| `-- wakeup
|-- resource
|-- subsystem -> ../../../bus/pci
|-- subsystem_device
|-- subsystem_vendor
|-- uevent
`-- vendor
(
Log in to post comments)