udev - udevinfo with device chain walk
PATCH 1/1 udev - udevinfo with device chain walk
udevinfo is now capable to print "all" attributes along the device chain of a sysfs device. Just like udev itself it walks the chain upwards and prints all usable attributes in the udev key format.
So it should be easy to find unique attributes to compose a rule.
All multiline attribute values and values containing non printable characters are skipped now. I hope nothing useful gets lost with this :)
NOTE:
The BUS value corresponding with the attributes is printed for every device. Don't specify BUS= in a rule and mix SYSFS_attributes from different busses, the rule can't match.
thanks,
Kay
./udevinfo /sys/block/sda/sda1
device '/sys/block/sda/sda1' has major:minor 8:1
looking at class device '/sys/block/sda/sda1':
SYSFS_dev="8:1"
SYSFS_start="32"
SYSFS_size="160"
SYSFS_stat=" 0 0 0 0"follow the class device's "device"
looking at the device chain at '/sys/devices/pci0000:00/0000:00:1d.0/usb1/1-1/1-1.3/1-1.3:1.0/host32/32:0:0:0':
BUS="scsi"
ID="32:0:0:0"
SYSFS_detach_state="0"
SYSFS_type="0"
SYSFS_model="USB 2 HS-CF"
SYSFS_vendor="SMSC "
SYSFS_max_sectors="240"
SYSFS_device_blocked="0"
SYSFS_queue_depth="1"
SYSFS_scsi_level="3"
SYSFS_rev="1.25"
SYSFS_online="1"looking at the device chain at '/sys/devices/pci0000:00/0000:00:1d.0/usb1/1-1/1-1.3/1-1.3:1.0/host32':
BUS=""
ID="host32"
SYSFS_detach_state="0"looking at the device chain at '/sys/devices/pci0000:00/0000:00:1d.0/usb1/1-1/1-1.3/1-1.3:1.0':
BUS="usb"
ID="1-1.3:1.0"
SYSFS_detach_state="0"
SYSFS_bInterfaceNumber="00"
SYSFS_bAlternateSetting=" 0"
SYSFS_bNumEndpoints="02"
SYSFS_bInterfaceClass="08"
SYSFS_bInterfaceSubClass="06"
SYSFS_bInterfaceProtocol="50"
SYSFS_iInterface="00"looking at the device chain at '/sys/devices/pci0000:00/0000:00:1d.0/usb1/1-1/1-1.3':
BUS="usb"
ID="1-1.3"
SYSFS_detach_state="0"
SYSFS_bNumConfigurations="1"
SYSFS_bNumInterfaces=" 1"
SYSFS_bConfigurationValue="1"
SYSFS_bmAttributes="80"
SYSFS_bMaxPower=" 96mA"
SYSFS_idVendor="0424"
SYSFS_idProduct="20fc"
SYSFS_bcdDevice="0125"
SYSFS_bDeviceClass="00"
SYSFS_bDeviceSubClass="00"
SYSFS_bDeviceProtocol="00"
SYSFS_speed="12"
SYSFS_manufacturer="SMSC"
SYSFS_product="USB 2 Flash Media Device"
SYSFS_serial="0305037000C2"looking at the device chain at '/sys/devices/pci0000:00/0000:00:1d.0/usb1/1-1':
BUS="usb"
ID="1-1"
SYSFS_detach_state="0"
SYSFS_bNumConfigurations="1"
SYSFS_bNumInterfaces=" 1"
SYSFS_bConfigurationValue="1"
SYSFS_bmAttributes="e0"
SYSFS_bMaxPower=" 64mA"
SYSFS_idVendor="03eb"
SYSFS_idProduct="3301"
SYSFS_bcdDevice="0300"
SYSFS_bDeviceClass="09"
SYSFS_bDeviceSubClass="00"
SYSFS_bDeviceProtocol="00"
SYSFS_speed="12"
SYSFS_product="Standard USB Hub"looking at the device chain at '/sys/devices/pci0000:00/0000:00:1d.0/usb1':
BUS="usb"
ID="usb1"
SYSFS_detach_state="0"
SYSFS_bNumConfigurations="1"
SYSFS_bNumInterfaces=" 1"
SYSFS_bConfigurationValue="1"
SYSFS_bmAttributes="40"
SYSFS_bMaxPower=" 0mA"
SYSFS_idVendor="0000"
SYSFS_idProduct="0000"
SYSFS_bcdDevice="0206"
SYSFS_bDeviceClass="09"
SYSFS_bDeviceSubClass="00"
SYSFS_bDeviceProtocol="00"
SYSFS_speed="12"
SYSFS_manufacturer="Linux 2.6.2-rc1-p4 uhci_hcd"
SYSFS_product="UHCI Host Controller"
SYSFS_serial="0000:00:1d.0"looking at the device chain at '/sys/devices/pci0000:00/0000:00:1d.0':
BUS="pci"
ID="0000:00:1d.0"
SYSFS_detach_state="0"
SYSFS_vendor="0x8086"
SYSFS_device="0x2482"
SYSFS_subsystem_vendor="0x1014"
SYSFS_subsystem_device="0x0220"
SYSFS_class="0x0c0300"
SYSFS_irq="9" looking at the device chain at '/sys/devices/pci0000:00':
BUS=""
ID="pci0000:00"
SYSFS_detach_state="0"extras/udevinfo/udevinfo.c +40 -13
@@ -22,6 +22,7 @@#include <stdlib.h> #include <string.h> #include <stdio.h> +#include <ctype.h> #include "libsysfs.h"
@@ -54,9 +55,23 @@if (attr->value !=NULL ) {strncpy (value, attr->value,VALUE_SIZE ); len =strlen (value); -if (value[len-1 ] =='\n' ) +if (len ==0 ) +continue ; + +/* remove trailing newline */ +if (value[len-1 ] =='\n' ) { value[len-1 ] ='\0' ; -printf (" SYSFS_%s=\"%s\"\n" , attr->name, value); + len--; + } + +/* skip nonprintable values */ +while (len) { +if (isprint (value[len-1 ]) ==0 ) +break ; + len--; + } +if (len ==0 ) +printf (" SYSFS_%s=\"%s\"\n" , attr->name, value); } }printf ("\n" );
@@ -74,7 +89,8 @@struct sysfs_class_device *class_dev;struct sysfs_class_device *class_dev_parent;struct sysfs_attribute *attr; -struct sysfs_device *sysfs_device; +struct sysfs_device *sysfs_dev; +struct sysfs_device *sysfs_dev_parent;char *path;int retval =0 ;
@@ -98,33 +114,44 @@ retval =-1 ; goto exit; } -printf ("\ndevice '%s' has major:minor %s\n" , class_dev->path, attr->value); +printf ("\ndevice '%s' has major:minor %s" , class_dev->path, attr->value);sysfs_close_attribute (attr);/* open sysfs class device directory and print all attributes */ -printf ("looking at class device '%s':\n" , class_dev->path); +printf (" looking at class device '%s':\n" , class_dev->path);if (print_all_attributes (class_dev->path) !=0 ) {printf ("couldn't open class device directory\n" ); retval =-1 ; goto exit; } -/* get the device (if parent exists use it instead) */ +/* get the device link (if parent exists look here) */ class_dev_parent =sysfs_get_classdev_parent (class_dev);if (class_dev_parent !=NULL ) {//sysfs_close_class_device(class_dev); class_dev = class_dev_parent; } - sysfs_device =sysfs_get_classdev_device (class_dev); -if (sysfs_device !=NULL ) { -printf ("follow class device's \"device\" link '%s':\n" , class_dev->path); -printf (" BUS=\"%s\"\n" , sysfs_device->bus); -printf (" ID=\"%s\"\n" , sysfs_device->bus_id); + sysfs_dev =sysfs_get_classdev_device (class_dev); +if (sysfs_dev !=NULL ) +printf ("follow the class device's \"device\"\n" ); + +/* look the device chain upwards */ +while (sysfs_dev !=NULL ) { +printf (" looking at the device chain at '%s':\n" , sysfs_dev->path); +printf (" BUS=\"%s\"\n" , sysfs_dev->bus); +printf (" ID=\"%s\"\n" , sysfs_dev->bus_id);/* open sysfs device directory and print all attributes */ -print_all_attributes (sysfs_device->path); -sysfs_close_device (sysfs_device); +print_all_attributes (sysfs_dev->path); + + sysfs_dev_parent =sysfs_get_device_parent (sysfs_dev); +if (sysfs_dev_parent ==NULL ) +break ; + +//sysfs_close_device(sysfs_dev); + sysfs_dev = sysfs_dev_parent; } +sysfs_close_device (sysfs_dev); exit://sysfs_close_class_device(class_dev);
Quoted 5 lines · Kay Sievers
udevinfo is now capable to print "all" attributes along the device chain of a sysfs device. Just like udev itself it walks the chain upwards and prints all usable attributes in the udev key format.
So it should be easy to find unique attributes to compose a rule.
Quoted 7 lines
All multiline attribute values and values containing non printable characters are skipped now. I hope nothing useful gets lost with this :)
NOTE:
The BUS value corresponding with the attributes is printed for every device. Don't specify BUS= in a rule and mixSYSFS_attributesfrom different busses, the rule can't match.
ver nice, applied, thanks.
greg k-h
-------------------------------------------------------
The SF.Net email is sponsored by EclipseCon 2004
Premiere Conference on Open Tools Development and Integration See the breadth of Eclipse activity. February 3-5 in Anaheim, CA.
http://www.eclipsecon.org/osdn
_______________________________________________
Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel
Ananth, I think this is pointing out a bug in libsysfs, see below:
Quoted 128 lines · Kay Sievers
udevinfo is now capable to print "all" attributes along the device chain of a sysfs device. Just like udev itself it walks the chain upwards and prints all usable attributes in the udev key format.
So it should be easy to find unique attributes to compose a rule.All multiline attribute values and values containing non printable characters are skipped now. I hope nothing useful gets lost with this :)
NOTE:
The BUS value corresponding with the attributes is printed for every device. Don't specify BUS= in a rule and mixSYSFS_attributesfrom different busses, the rule can't match.thanks,
Kay./udevinfo
/sys/block/sda/sda1device '
/sys/block/sda/sda1' has major:minor 8:1
looking at class device '/sys/block/sda/sda1':SYSFS_dev="8:1" SYSFS_start="32" SYSFS_size="160" SYSFS_stat=" 0 0 0 0"follow the class device's "device"
looking at the device chain at '/sys/devices/pci0000:00/0000:00:1d.0/usb1/1-1/1-1.3/1-1.3:1.0/host32/32:0:0:0':BUS="scsi" ID="32:0:0:0" SYSFS_detach_state="0" SYSFS_type="0" SYSFS_model="USB 2 HS-CF" SYSFS_vendor="SMSC " SYSFS_max_sectors="240" SYSFS_device_blocked="0" SYSFS_queue_depth="1" SYSFS_scsi_level="3" SYSFS_rev="1.25" SYSFS_online="1"looking at the device chain at '/sys/devices/pci0000:00/0000:00:1d.0/usb1/1-1/1-1.3/1-1.3:1.0/host32':
BUS="" ID="host32" SYSFS_detach_state="0"looking at the device chain at '/sys/devices/pci0000:00/0000:00:1d.0/usb1/1-1/1-1.3/1-1.3:1.0':
BUS="usb" ID="1-1.3:1.0" SYSFS_detach_state="0" SYSFS_bInterfaceNumber="00" SYSFS_bAlternateSetting=" 0" SYSFS_bNumEndpoints="02" SYSFS_bInterfaceClass="08" SYSFS_bInterfaceSubClass="06" SYSFS_bInterfaceProtocol="50" SYSFS_iInterface="00"looking at the device chain at '/sys/devices/pci0000:00/0000:00:1d.0/usb1/1-1/1-1.3':
BUS="usb" ID="1-1.3" SYSFS_detach_state="0" SYSFS_bNumConfigurations="1" SYSFS_bNumInterfaces=" 1" SYSFS_bConfigurationValue="1" SYSFS_bmAttributes="80" SYSFS_bMaxPower=" 96mA" SYSFS_idVendor="0424" SYSFS_idProduct="20fc" SYSFS_bcdDevice="0125" SYSFS_bDeviceClass="00" SYSFS_bDeviceSubClass="00" SYSFS_bDeviceProtocol="00" SYSFS_speed="12" SYSFS_manufacturer="SMSC" SYSFS_product="USB 2 Flash Media Device" SYSFS_serial="0305037000C2"looking at the device chain at '/sys/devices/pci0000:00/0000:00:1d.0/usb1/1-1':
BUS="usb" ID="1-1" SYSFS_detach_state="0" SYSFS_bNumConfigurations="1" SYSFS_bNumInterfaces=" 1" SYSFS_bConfigurationValue="1" SYSFS_bmAttributes="e0" SYSFS_bMaxPower=" 64mA" SYSFS_idVendor="03eb" SYSFS_idProduct="3301" SYSFS_bcdDevice="0300" SYSFS_bDeviceClass="09" SYSFS_bDeviceSubClass="00" SYSFS_bDeviceProtocol="00" SYSFS_speed="12" SYSFS_product="Standard USB Hub"looking at the device chain at '/sys/devices/pci0000:00/0000:00:1d.0/usb1':
BUS="usb" ID="usb1" SYSFS_detach_state="0" SYSFS_bNumConfigurations="1" SYSFS_bNumInterfaces=" 1" SYSFS_bConfigurationValue="1" SYSFS_bmAttributes="40" SYSFS_bMaxPower=" 0mA" SYSFS_idVendor="0000" SYSFS_idProduct="0000" SYSFS_bcdDevice="0206" SYSFS_bDeviceClass="09" SYSFS_bDeviceSubClass="00" SYSFS_bDeviceProtocol="00" SYSFS_speed="12" SYSFS_manufacturer="Linux 2.6.2-rc1-p4 uhci_hcd" SYSFS_product="UHCI Host Controller" SYSFS_serial="0000:00:1d.0"looking at the device chain at '/sys/devices/pci0000:00/0000:00:1d.0':
BUS="pci" ID="0000:00:1d.0" SYSFS_detach_state="0" SYSFS_vendor="0x8086" SYSFS_device="0x2482" SYSFS_subsystem_vendor="0x1014" SYSFS_subsystem_device="0x0220" SYSFS_class="0x0c0300" SYSFS_irq="9"
Quoted 4 lines
looking at the device chain at '
/sys/devices/pci0000:00':BUS="" ID="pci0000:00" SYSFS_detach_state="0"
This device should show up on with BUS="pci", right?
thanks,
greg k-h
-------------------------------------------------------
The SF.Net email is sponsored by EclipseCon 2004
Premiere Conference on Open Tools Development and Integration See the breadth of Eclipse activity. February 3-5 in Anaheim, CA.
http://www.eclipsecon.org/osdn
_______________________________________________
Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel
Quoted 11 lines · Greg KH
Ananth, I think this is pointing out a bug in libsysfs, see below:
Quoted 5 lines · Kay Sievers
looking at the device chain at '
/sys/devices/pci0000:00':BUS="" ID="pci0000:00" SYSFS_detach_state="0"This device should show up on with BUS="pci", right?
Right.. it does not show up here since the device pci0000:00 does not have a link under the "bus" subsystem. This is presently the case for all "root" devices (entries under /sys/devices). Will fix this.
Thanks,
Ananth
-------------------------------------------------------
The SF.Net email is sponsored by EclipseCon 2004
Premiere Conference on Open Tools Development and Integration See the breadth of Eclipse activity. February 3-5 in Anaheim, CA.
http://www.eclipsecon.org/osdn
_______________________________________________
Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel
Quoted 11 lines · Ananth N Mavinakayanahalli
Quoted 10 lines · Greg KH
Ananth, I think this is pointing out a bug in libsysfs, see below:
Quoted 5 lines · Kay Sievers
looking at the device chain at '
/sys/devices/pci0000:00':BUS="" ID="pci0000:00" SYSFS_detach_state="0"
Quoted 5 lines
Quoted 1 line
This device should show up on with BUS="pci", right?
Right.. it does not show up here since the device pci0000:00 does not have a link under the "bus" subsystem. This is presently the case for all "root" devices (entries under
/sys/devices). Will fix this.
Hm, looks like libsysfs is correct, as that device does not show up in the sys/bus/pci/devices directory. I think I have patch in my kernel tree to help fix that up...
Nevermind, sorry for the false alarm.
greg k-h
-------------------------------------------------------
The SF.Net email is sponsored by EclipseCon 2004
Premiere Conference on Open Tools Development and Integration See the breadth of Eclipse activity. February 3-5 in Anaheim, CA.
http://www.eclipsecon.org/osdn
_______________________________________________
Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel