udev doesn't know about devices further up the tree.
Hi,
I wrote my first udev rule the other day.
It reads:
KERNEL=="sd*", PROGRAM="/home/huggie/bin/camera %k", SYMLINK+="%c" where bin/camera does:
DEV=$1
DISK=echo $DEV|sed -e 's/.*\(sd.\).*/\1/;'
udevinfo -a -p /block/$DISK/$DEV|grep manuf|grep PENTAX >/dev/null 2>&1 && \
echo camera && exit 0i.e. basically if the usb device (or any device because I'm not that fussy) above the block device is made by PENTAX then echo camera otherwise I just echo $DEV back again.
But it strikes me as a bug that I have to spawn out of udevd to run udevinfo in order to just name the device based on what it is.
Why aren't SYSFS attributes from higher up the device path available somehow when writing rules?
Here's the udevinfo output:
udevinfo starts with the device the node belongs to and then walks up the device chain, to print for every device found, all possibly useful attributes in the udev key format.
Only attributes within one device section may be used together in one rule, to match the device for which the node will be created.
looking at device '/block/sdc/sdc1':
KERNEL=="sdc1"
SUBSYSTEM=="block"
SYSFS{stat}==" 350 350 0 0"
SYSFS{size}=="1002455"
SYSFS{start}=="41"
SYSFS{dev}=="8:33"looking at device '/block/sdc':
ID=="sdc"
BUS=="block"
DRIVER==""
SYSFS{stat}==" 23 328 358 302 0 0 0 0 0 302 302"
SYSFS{size}=="1002496"
SYSFS{removable}=="1"
SYSFS{range}=="16"
SYSFS{dev}=="8:32"looking at device '/devices/pci0000:00/0000:00:02.0/usb2/2-2/2-2.2/2-2.2:1.0/host16/target16:0:0/16:0:0:0':
ID=="16:0:0:0"
BUS=="scsi"
DRIVER=="sd"
SYSFS{ioerr_cnt}=="0x0"
SYSFS{iodone_cnt}=="0x27"
SYSFS{iorequest_cnt}=="0x27"
SYSFS{iocounterbits}=="32"
SYSFS{timeout}=="30"
SYSFS{state}=="running"
SYSFS{rev}=="1.00"
SYSFS{model}=="DIGITAL_CAMERA "
SYSFS{vendor}=="PENTAX "
SYSFS{scsi_level}=="3"
SYSFS{type}=="0"
SYSFS{queue_type}=="none"
SYSFS{queue_depth}=="1"
SYSFS{device_blocked}=="0"
SYSFS{max_sectors}=="240"looking at device '/devices/pci0000:00/0000:00:02.0/usb2/2-2/2-2.2/2-2.2:1.0/host16/target16:0:0':
ID=="target16:0:0"
BUS==""
DRIVER==""looking at device '/devices/pci0000:00/0000:00:02.0/usb2/2-2/2-2.2/2-2.2:1.0/host16':
ID=="host16"
BUS==""
DRIVER==""looking at device '/devices/pci0000:00/0000:00:02.0/usb2/2-2/2-2.2/2-2.2:1.0':
ID=="2-2.2:1.0"
BUS=="usb"
DRIVER=="usb-storage"
SYSFS{modalias}=="usb:v0A17p004Cd1000dc00dsc00dp00ic08isc05ip50"
SYSFS{bInterfaceProtocol}=="50"
SYSFS{bInterfaceSubClass}=="05"
SYSFS{bInterfaceClass}=="08"
SYSFS{bNumEndpoints}=="03"
SYSFS{bAlternateSetting}==" 0"
SYSFS{bInterfaceNumber}=="00"looking at device '/devices/pci0000:00/0000:00:02.0/usb2/2-2/2-2.2':
ID=="2-2.2"
BUS=="usb"
DRIVER=="usb"
SYSFS{configuration}==""
SYSFS{product}=="PENTAX OPTIO S5n"
SYSFS{manufacturer}=="PENTAX"
SYSFS{maxchild}=="0"
SYSFS{version}==" 2.00"
SYSFS{devnum}=="16"
SYSFS{speed}=="12"
SYSFS{bMaxPacketSize0}=="64"
SYSFS{bNumConfigurations}=="2"
SYSFS{bDeviceProtocol}=="00"
SYSFS{bDeviceSubClass}=="00"
SYSFS{bDeviceClass}=="00"
SYSFS{bcdDevice}=="1000"
SYSFS{idProduct}=="004c"
SYSFS{idVendor}=="0a17"
SYSFS{bMaxPower}=="100mA"
SYSFS{bmAttributes}=="c0"
SYSFS{bConfigurationValue}=="1"
SYSFS{bNumInterfaces}==" 1"looking at device '/devices/pci0000:00/0000:00:02.0/usb2/2-2':
ID=="2-2"
BUS=="usb"
DRIVER=="usb"
SYSFS{configuration}==""
SYSFS{product}=="USB Hub"
SYSFS{maxchild}=="4"
SYSFS{version}==" 1.10"
SYSFS{devnum}=="3"
SYSFS{speed}=="12"
SYSFS{bMaxPacketSize0}=="8"
SYSFS{bNumConfigurations}=="1"
SYSFS{bDeviceProtocol}=="00"
SYSFS{bDeviceSubClass}=="00"
SYSFS{bDeviceClass}=="09"
SYSFS{bcdDevice}=="0305"
SYSFS{idProduct}=="0604"
SYSFS{idVendor}=="05e3"
SYSFS{bMaxPower}=="100mA"
SYSFS{bmAttributes}=="e0"
SYSFS{bConfigurationValue}=="1"
SYSFS{bNumInterfaces}==" 1"looking at device '/devices/pci0000:00/0000:00:02.0/usb2':
ID=="usb2"
BUS=="usb"
DRIVER=="usb"
SYSFS{configuration}==""
SYSFS{serial}=="0000:00:02.0"
SYSFS{product}=="OHCI Host Controller"
SYSFS{manufacturer}=="Linux 2.6.16.11 ohci_hcd"
SYSFS{maxchild}=="10"
SYSFS{version}==" 1.10"
SYSFS{devnum}=="1"
SYSFS{speed}=="12"
SYSFS{bMaxPacketSize0}=="64"
SYSFS{bNumConfigurations}=="1"
SYSFS{bDeviceProtocol}=="00"
SYSFS{bDeviceSubClass}=="00"
SYSFS{bDeviceClass}=="09"
SYSFS{bcdDevice}=="0206"
SYSFS{idProduct}=="0000"
SYSFS{idVendor}=="0000"
SYSFS{bMaxPower}==" 0mA"
SYSFS{bmAttributes}=="e0"
SYSFS{bConfigurationValue}=="1"
SYSFS{bNumInterfaces}==" 1"looking at device '/devices/pci0000:00/0000:00:02.0':
ID=="0000:00:02.0"
BUS=="pci"
DRIVER=="ohci_hcd"
SYSFS{modalias}=="pci:v000010DEd0000005Asv00001043sd0000815Abc0Csc03i10"
SYSFS{local_cpus}=="ff"
SYSFS{irq}=="21"
SYSFS{class}=="0x0c0310"
SYSFS{subsystem_device}=="0x815a"
SYSFS{subsystem_vendor}=="0x1043"
SYSFS{device}=="0x005a"
SYSFS{vendor}=="0x10de"looking at device '/devices/pci0000:00':
ID=="pci0000:00"
BUS==""
DRIVER==""Simon.
Signature · 2 lines
[ "And what do we burn apart from witches?" "*More* witches!" ]
Black Cat Networks. http://www.blackcatnetworks.co.uk/_______________________________________________
Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel
Quoted 14 lines · Simon Huggins
I wrote my first udev rule the other day.
It reads:
KERNEL="sd*", PROGRAM="/home/huggie/bin/camera %k", SYMLINK+="%c" where bin/camera does:
DEV=$1
DISK=echo $DEV|sed -e 's/.*\(sd.\).*/\1/;'udevinfo -a -p /block/$DISK/$DEV|grep manuf|grep PENTAX >/dev/null 2>&1 && \ echo camera && exit 0i.e. basically if the usb device (or any device because I'm not that fussy) above the block device is made by PENTAX then echo camera otherwise I just echo $DEV back again.
Quoted 6 lines
But it strikes me as a bug that I have to spawn out of udevd to run udevinfo in order to just name the device based on what it is.
Why aren't SYSFS attributes from higher up the device path available somehow when writing rules?
Adding a single SYSFS attribute:
SYSFS{vendor}="PENTAX"
or
SYSFS{manufacturer}="PENTAX"
should do it and will try to find the value on all devices up the chain, but you can't mix SYSFS, BUS or ID values from different devices.
Kay
_______________________________________________
Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel
Quoted 16 lines · Kay Sievers
Quoted 8 lines · Simon Huggins
I wrote my first udev rule the other day.
It reads:
KERNEL=="sd*", PROGRAM="/home/huggie/bin/camera %k", SYMLINK+="%c" where bin/camera does:
DEV=$1
DISK=echo $DEV|sed -e 's/.*\(sd.\).*/\1/;'udevinfo -a -p /block/$DISK/$DEV|grep manuf|grep PENTAX >/dev/null 2>&1 && \ echo camera && exit 0Quoted 7 lines
i.e. basically if the usb device (or any device because I'm not that fussy) above the block device is made by PENTAX then echo camera otherwise I just echo $DEV back again.
But it strikes me as a bug that I have to spawn out of udevd to run udevinfo in order to just name the device based on what it is. Why aren't SYSFS attributes from higher up the device path available somehow when writing rules?
Quoted 7 lines
Adding a single SYSFS attribute:
SYSFS{vendor}=="PENTAX"
or
SYSFS{manufacturer}=="PENTAX"should do it and will try to find the value on all devices up the chain, but you can't mix SYSFS, BUS or ID values from different devices.
Hmm, ok it's working now. I must have fucked up the rule somehow originally sorry for wasting your time.
Can I suggest that the part in
http://www.reactivated.net/writing_udev_rules.html
which says:
This is to demonstrate that you generally can not mix-and-match attributes from different sections of the udevinfo output - your rule will not work.
be reworded or removed then. I'm not quite sure what it should say - I just failed and then read more of the docs and came across this and thought that what I was trying was never going to work.
I now have:
KERNEL=="sd*", SUBSYSTEM=="block", SYSFS{manufacturer}=="PENTAX", SYMLINK+="camera"
which appears to work fine yet the block and the PENTAX are indeed in different sections of the udevinfo output.
Signature · 4 lines
,--huggie-at-earth-dot-li--------stuff-thing-stuff----------DF5CE2B4--. _| "Don't worry, understanding of the topic being discussed has been |_ | optional for a long time on debian-devel@." -- Md | `- http://www.earth.li/~huggie/ - http://www.blackcatnetworks.co.uk/ -'
_______________________________________________
Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel
Quoted 40 lines · Simon Huggins
Quoted 16 lines · Kay Sievers
Quoted 8 lines · Simon Huggins
I wrote my first udev rule the other day.
It reads:
KERNEL="sd*", PROGRAM="/home/huggie/bin/camera %k", SYMLINK+="%c" where bin/camera does:
DEV=$1
DISK=echo $DEV|sed -e 's/.*\(sd.\).*/\1/;'udevinfo -a -p /block/$DISK/$DEV|grep manuf|grep PENTAX >/dev/null 2>&1 && \ echo camera && exit 0Quoted 7 lines
i.e. basically if the usb device (or any device because I'm not that fussy) above the block device is made by PENTAX then echo camera otherwise I just echo $DEV back again.
But it strikes me as a bug that I have to spawn out of udevd to run udevinfo in order to just name the device based on what it is. Why aren't SYSFS attributes from higher up the device path available somehow when writing rules?Quoted 7 lines
Adding a single SYSFS attribute:
SYSFS{vendor}="PENTAX"
or
SYSFS{manufacturer}="PENTAX"should do it and will try to find the value on all devices up the chain, but you can't mix SYSFS, BUS or ID values from different devices.
Hmm, ok it's working now. I must have fucked up the rule somehow originally sorry for wasting your time.
Can I suggest that the part in
http://www.reactivated.net/writing_udev_rules.html
which says:This is to demonstrate that you generally can not mix-and-match attributes from different sections of the udevinfo output - your rule will not work.
be reworded or removed then. I'm not quite sure what it should say - I just failed and then read more of the docs and came across this and thought that what I was trying was never going to work.
Quoted 5 lines
I now have:
KERNEL="sd*", SUBSYSTEM="block", SYSFS{manufacturer}="PENTAX", SYMLINK+="camera"
which appears to work fine yet the block and the PENTAX are indeed in different sections of the udevinfo output.
Right, I means, you can't mix attributes of different parent devices. The attributes for the device itself, which "block" belongs to, will always match. Say:
SYSFS{vendor}="PENTAX", SYSFS{manufacturer}="PENTAX"
would not match, even when both single keys are matching.
Kay
_______________________________________________
Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel