Skip to contentSkip to conversation

How can I specify a specific 'sub-device' of a device for udev naming?

DISCUSSION Jonathan Steinert 3 participants 8 messages Mar 1, 2004 – Mar 4, 2004

lore
Share & tools
lore
#0 lore raw

Morning everybody,

I'm trying to find how I can write a rule which allows me to say "The usb-serial bus interface inside the usb device with a sysfs serial of "304087" should be named "foo"

I'll paste my udevinfo output for the device in question (A Belkin USB to serial dongle) at the bottom, but I am running into a similar issue with my Griffin Powermate.

The rule I came up with, which does not work nor seem correct in the first place is:

BUS="usb-serial", SYSFS{serial}="304087", NAME="foo"

Since this does not work, I am asuming that the sysfs attributes to not trickle down a driver chain for matching in more specific devices.

This does leave me puzzled about two things:

1) Why does udev have a flag to crawl up the sysfs tree (Asuming my observations of udev are correct) but no flag to show the attributes of only the device I specify? or only 'n' layers down for that matter?

2) How can I write a rule to match the usb-serial interface of a usb device with a particular serial number?

I have no idea what to call this act, apart from 'walking' the sysfs tree when checking the rules, so after reading all the documentation with udev that I noticed, and all of the messages on the list that I thought might be related I've come up with nothing.

Can anyone fill me in on this, possibly telling me what this is called, and what I am getting wrong?

Thanks much,

Jonathan Steinert

root@yuumi:/dev# udevinfo -a -p /sys/class/tty/ttyUSB0

device '/sys/class/tty/ttyUSB0' has major:minor 188:0
looking at class device '/sys/class/tty/ttyUSB0':

    SYSFS{dev}="188:0"

follow the class device's "device"
looking at the device chain at
'/sys/devices/pci0000:00/0000:00:1d.2/usb2/2-1/2-1:1.0/ttyUSB0':

    BUS="usb-serial"
    ID="ttyUSB0"
    SYSFS{detach_state}="0"

looking at the device chain at
'/sys/devices/pci0000:00/0000:00:1d.2/usb2/2-1/2-1:1.0':

    BUS="usb"
    ID="2-1:1.0"
    SYSFS{detach_state}="0"
    SYSFS{bInterfaceNumber}="00"
    SYSFS{bAlternateSetting}=" 0"
    SYSFS{bNumEndpoints}="03"
    SYSFS{bInterfaceClass}="ff"
    SYSFS{bInterfaceSubClass}="ff"
    SYSFS{bInterfaceProtocol}="ff"
    SYSFS{iInterface}="00"

looking at the device chain at
'/sys/devices/pci0000:00/0000:00:1d.2/usb2/2-1':

    BUS="usb"
    ID="2-1"
    SYSFS{detach_state}="0"
    SYSFS{bNumConfigurations}="1"
    SYSFS{bNumInterfaces}=" 1"
    SYSFS{bConfigurationValue}="1"
    SYSFS{bmAttributes}="a0"
    SYSFS{bMaxPower}="100mA"
    SYSFS{idVendor}="050d"
    SYSFS{idProduct}="0109"
    SYSFS{bcdDevice}="0102"
    SYSFS{bDeviceClass}="00"
    SYSFS{bDeviceSubClass}="00"
    SYSFS{bDeviceProtocol}="00"
    SYSFS{speed}="12"
    SYSFS{manufacturer}="Belkin USB PDA Adapter"
    SYSFS{product}="Belkin Components"
    SYSFS{serial}="304087"

looking at the device chain at
'/sys/devices/pci0000:00/0000:00:1d.2/usb2':

    BUS="usb"
    ID="usb2"
    SYSFS{detach_state}="0"
    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{bNumConfigurations}="1"
    SYSFS{speed}="12"
    SYSFS{manufacturer}="Linux 2.6.3 uhci_hcd"
    SYSFS{product}="UHCI Host Controller"
    SYSFS{serial}="0000:00:1d.2"

looking at the device chain at '/sys/devices/pci0000:00/0000:00:1d.2':

    BUS="pci"
    ID="0000:00:1d.2"
    SYSFS{detach_state}="0"
    SYSFS{vendor}="0x8086"
    SYSFS{device}="0x2487"
    SYSFS{subsystem_vendor}="0x8086"
    SYSFS{subsystem_device}="0x4541"
    SYSFS{class}="0x0c0300"
    SYSFS{irq}="11"

looking at the device chain at '/sys/devices/pci0000:00':

    BUS=""
    ID="pci0000:00"
    SYSFS{detach_state}="0"

-------------------------------------------------------
SF.Net is sponsored by: Speed Start Your Linux Apps Now. Build and deploy apps & Web services for Linux with
a free DVD software kit from IBM. Click Now!
http://ads.osdn.com/?ad_id56&alloc_id438&op=click
_______________________________________________
Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel

#1 lore raw

Re: How can I specify a specific 'sub-device' of a device for udev

Quoted 6 lines · Jonathan Steinert

Morning everybody,

I'm trying to find how I can write a rule which allows me to say "The usb-serial bus interface inside the usb device with a sysfs serial of "304087" should be named "foo"

Quoted 8 lines

I'll paste my udevinfo output for the device in question (A Belkin USB to serial dongle) at the bottom, but I am running into a similar issue with my Griffin Powermate.

The rule I came up with, which does not work nor seem correct in the first place is:

BUS="usb-serial", SYSFS{serial}="304087", NAME="foo"

Yes, the rule is incorrect. It's not on the same device.

Quoted 2 lines

Since this does not work, I am asuming that the sysfs attributes to not trickle down a driver chain for matching in more specific devices.

It walks down, just like udevinfo does. But you can only match attributes of _one_ device not combine attributes from different devices on the chain.

Quoted 5 lines

This does leave me puzzled about two things:

1) Why does udev have a flag to crawl up the sysfs tree (Asuming my observations of udev are correct) but no flag to show the attributes of only the device I specify? or only 'n' layers down for that matter?

Do you really need this? Why?

Quoted 6 lines

2) How can I write a rule to match the usb-serial interface of a usb device with a particular serial number?

looking at the device chain at
'/sys/devices/pci0000:00/0000:00:1d.2/usb2/2-1':

    BUS="usb"

...

Quoted 1 line
    SYSFS{serial}="304087"

Your serial number belongs the "usb"-device and not the virtual "usb-serial"-device. A match for the "hardware" behind your serial device should work fine:

BUS="usb", SYSFS{serial}="304087", NAME="foo"

If you really need to match this particular device interface, you may use its bus-id:

BUS="usb", ID="2-1:1.0", NAME="foo"

hope that helps,
Kay

-------------------------------------------------------
SF.Net is sponsored by: Speed Start Your Linux Apps Now. Build and deploy apps & Web services for Linux with
a free DVD software kit from IBM. Click Now!
http://ads.osdn.com/?ad_id56&alloc_id438&op=click
_______________________________________________
Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel

#2 lore raw

Re: How can I specify a specific 'sub-device' of a device for udev

In reply to Jonathan Steinert
Quoted 8 lines · Kay Sievers

On Mon, 2004-03-01 at 07:08, Jonathan Steinert wrote:

This does leave me puzzled about two things:

Quoted 4 lines

1) Why does udev have a flag to crawl up the sysfs tree (Asuming my observations of udev are correct) but no flag to show the attributes of only the device I specify? or only 'n' layers down for that matter?

Do you really need this? Why?

That's not quite what I intended with the question. My observation is that udevinfo shows you all the attributes as you walk up the tree, but udev has no way to match attributes as you walk up the tree.

I'm not sure if this is intended to confuse people, but it most certainly makes me think that there should be a way to match attributes as you walk up the tree with udev, otherwise why does it show it to you?

Quoted 12 lines
Quoted 9 lines

2) How can I write a rule to match the usb-serial interface of a usb device with a particular serial number?

looking at the device chain at
'/sys/devices/pci0000:00/0000:00:1d.2/usb2/2-1':

   BUS="usb"

...

Quoted 8 lines
Quoted 1 line
   SYSFS{serial}="304087"

Your serial number belongs the "usb"-device and not the virtual "usb-serial"-device. A match for the "hardware" behind your serial device should work fine:

BUS="usb", SYSFS{serial}="304087", NAME="foo"

Sure, but matching this usb device does not yield me a tty.

Quoted 5 lines

If you really need to match this particular device interface, you may use its bus-id:

BUS="usb", ID="2-1:1.0", NAME="foo"

The bus ID is dependant on the order it was plugged into the device chain, so this is kinda useless for detecting a particular device or particular kind of device. Plus this is once again a usb device, not a usb-serial device, and as such will not yield me a tty.

Quoted 5 lines

hope that helps,
Kay

It does help me to know that there is no (current) way to make udev do this, however now I'd like to ask for ways to match the usb-serial device which is on an interface of this particular usb device. This is ultimately the problem I am trying to solve.

Thanks much,

Jonathan Steinert

-------------------------------------------------------
SF.Net is sponsored by: Speed Start Your Linux Apps Now. Build and deploy apps & Web services for Linux with
a free DVD software kit from IBM. Click Now!
http://ads.osdn.com/?ad_id56&alloc_id438&op=click
_______________________________________________
Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel

#3 lore raw

Re: How can I specify a specific 'sub-device' of a device for udev

In reply to Jonathan Steinert
Quoted 10 lines · Jonathan Steinert
Quoted 8 lines · Kay Sievers

On Mon, 2004-03-01 at 07:08, Jonathan Steinert wrote:

This does leave me puzzled about two things:

Quoted 4 lines

1) Why does udev have a flag to crawl up the sysfs tree (Asuming my observations of udev are correct) but no flag to show the attributes of only the device I specify? or only 'n' layers down for that matter?

Do you really need this? Why?

Quoted 7 lines

That's not quite what I intended with the question. My observation is that udevinfo shows you all the attributes as you walk up the tree, but udev has no way to match attributes as you walk up the tree.

I'm not sure if this is intended to confuse people, but it most certainly makes me think that there should be a way to match attributes as you walk up the tree with udev, otherwise why does it show it to you?

udevinfo prints all attributes in sections, you can select and combine any attribute within _one_ section, thats why we print it all. Unfortunally, I see this doesn't solve your problem.

could you please send a:

tree /sys/devices/pci0000:00/0000:00:1d.2/usb2/2-1

I want to have a look if we can do something for you :)

thanks,
Kay

-------------------------------------------------------
SF.Net is sponsored by: Speed Start Your Linux Apps Now. Build and deploy apps & Web services for Linux with
a free DVD software kit from IBM. Click Now!
http://ads.osdn.com/?ad_id56&alloc_id438&op=click
_______________________________________________
Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel

#4 lore raw

Re: How can I specify a specific 'sub-device' of a device for udev

In reply to Jonathan Steinert
Quoted 31 lines · Kay Sievers
Quoted 14 lines · Jonathan Steinert
Quoted 10 lines · Kay Sievers

On Mon, 2004-03-01 at 07:08, Jonathan Steinert wrote:

This does leave me puzzled about two things:

Quoted 4 lines

1) Why does udev have a flag to crawl up the sysfs tree (Asuming my observations of udev are correct) but no flag to show the attributes of only the device I specify? or only 'n' layers down for that matter?

Do you really need this? Why?

Quoted 9 lines

That's not quite what I intended with the question. My observation is that udevinfo shows you all the attributes as you walk up the tree, but udev has no way to match attributes as you walk up the tree.

I'm not sure if this is intended to confuse people, but it most certainly makes me think that there should be a way to match attributes as you walk up the tree with udev, otherwise why does it show it to you?

udevinfo prints all attributes in sections, you can select and combine any attribute within _one_ section, thats why we print it all. Unfortunally, I see this doesn't solve your problem.

Quoted 11 lines

could you please send a:

tree /sys/devices/pci0000:00/0000:00:1d.2/usb2/2-1

I want to have a look if we can do something for you :)

thanks,
Kay

Sure thing, here you go...

root@yuumi:/sys/devices/pci0000:00/0000:00:1d.2/usb2/2-1# tree .
.
|-- 2-1:1.0
|   |-- bAlternateSetting
|   |-- bInterfaceClass
|   |-- bInterfaceNumber
|   |-- bInterfaceProtocol
|   |-- bInterfaceSubClass
|   |-- bNumEndpoints
|   |-- detach_state
|   |-- iInterface
|   |-- power
|   |   `-- state
|   `-- ttyUSB0
|       |-- detach_state
|       `-- power
|           `-- state
|-- bConfigurationValue
|-- bDeviceClass
|-- bDeviceProtocol
|-- bDeviceSubClass
|-- bMaxPower
|-- bNumConfigurations
|-- bNumInterfaces
|-- bcdDevice
|-- bmAttributes
|-- detach_state
|-- idProduct
|-- idVendor
|-- manufacturer
|-- power
|   `-- state
|-- product
|-- serial
`-- speed

5 directories, 28 files

Thanks for taking the time to look, and help

--Jonathan Steinert

-------------------------------------------------------
SF.Net is sponsored by: Speed Start Your Linux Apps Now. Build and deploy apps & Web services for Linux with
a free DVD software kit from IBM. Click Now!
http://ads.osdn.com/?ad_id56&alloc_id438&op=click
_______________________________________________
Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel

#5 lore raw
In reply to Jonathan Steinert
Quoted 16 lines · Jonathan Steinert
Quoted 15 lines · Kay Sievers
Quoted 7 lines · Jonathan Steinert

2) How can I write a rule to match the usb-serial interface of a usb device with a particular serial number?

looking at the device chain at
'/sys/devices/pci0000:00/0000:00:1d.2/usb2/2-1':
BUS="usb"

...

Quoted 1 line

SYSFS{serial}="304087"

Quoted 7 lines
Quoted 5 lines

Your serial number belongs the "usb"-device and not the virtual "usb-serial"-device. A match for the "hardware" behind your serial device should work fine:

BUS="usb", SYSFS{serial}="304087", NAME="foo"

Sure, but matching this usb device does not yield me a tty.

What do you get instead?

I took a look on your 'tree' and it has only one interface. So, if you match with the SYSFS{serial}="304087" there should still the tty be created.
Matching any device along the chain of your "node-device" with a rule, will still create only the "node-device", nothing else.

Maybe I'm a bit confused and if I get the subject completly wrong please tell me :)

Kay

-------------------------------------------------------
SF.Net is sponsored by: Speed Start Your Linux Apps Now. Build and deploy apps & Web services for Linux with
a free DVD software kit from IBM. Click Now!
http://ads.osdn.com/?ad_id56&alloc_id438&op=click
_______________________________________________
Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel

#6 lore raw

Re: How can I specify a specific 'sub-device' of a device for udev

In reply to Jonathan Steinert
Quoted 15 lines · Kay Sievers
Quoted 3 lines · Jonathan Steinert

Sure, but matching this usb device does not yield me a tty.

What do you get instead?

I took a look on your 'tree' and it has only one interface. So, if you match with the SYSFS{serial}="304087" there should still the tty be created.
Matching any device along the chain of your "node-device" with a rule, will still create only the "node-device", nothing else.

Quoted 6 lines

Maybe I'm a bit confused and if I get the subject completly wrong please tell me :)

Kay

Right, I'll admit defeat there... I asumed the wrong things about udev and ended up burning myself on that one.

However, I'd like to ask... since you (I think) asume that each physical device maps to only one node; What will happen when someone wants to name multiple devices based on an attribute higher in the than the unique branch?

The first example I came up with is my Griffin iMic (a usb sound card dongle) which creates multiple device nodes. The trouble is that I think ALSA is supposed to handle this situation and not udev.

The next best example I can think of would be naming USB devices based on which hub they are plugged in to. The hub must be identified by some sort of serial number or other attribute, but then there may be more than one device plugged into that hub.

I'm just throwing this question out to see how it could be solved, so I can't give you specific attributes till I build the system I want this for.

Thanks a ton for helping me out with the usb-serial device too.

--Jonathan Steinert

-------------------------------------------------------
This SF.Net email is sponsored by: IBM Linux Tutorials
Free Linux tutorial presented by Daniel Robbins, President and CEO of GenToo technologies. Learn everything from fundamentals to system administration.http://ads.osdn.com/?ad_id70&alloc_id638&op=click
_______________________________________________
Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel

#7 lore raw
In reply to Jonathan Steinert
Quoted 5 lines · Jonathan Steinert

However, I'd like to ask... since you (I think) asume that each physical device maps to only one node; What will happen when someone wants to name multiple devices based on an attribute higher in the than the unique branch?

Well, it's a bit hard if you want to do that, isn't it :)

usb to serial devices have the same "issue", as well as many other types of devices. The trick is in coming up with a unique name rule for those kinds of devices.

Quoted 8 lines

The first example I came up with is my Griffin iMic (a usb sound card dongle) which creates multiple device nodes. The trouble is that I think ALSA is supposed to handle this situation and not udev.

The next best example I can think of would be naming USB devices based on which hub they are plugged in to. The hub must be identified by some sort of serial number or other attribute, but then there may be more than one device plugged into that hub.

Well, you can always go on the position of the usb device (plugged into which port of which hub.) But again, you are back to the "multiple virtual devices per physical device" issue.

We are a whole lot better off than before, when we could never even determine this information. It's up to the individual driver writers to help expose unique information for their devices that can help out in creating "good enough" rules.

Quoted 2 lines

I'm just throwing this question out to see how it could be solved, so I can't give you specific attributes till I build the system I want this for.

There is no "general" solution for this. It's going to be a individual one as every system ends up being different.

thanks,

greg k-h

-------------------------------------------------------
This SF.Net email is sponsored by: IBM Linux Tutorials
Free Linux tutorial presented by Daniel Robbins, President and CEO of GenToo technologies. Learn everything from fundamentals to system administration.http://ads.osdn.com/?ad_id70&alloc_id638&op=click
_______________________________________________
Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel