From: Kay Sievers <kay.sievers@vrfy.org>
To: linux-hotplug@vger.kernel.org
Subject: Re: Figuring out devnodes from a usb device
Date: Tue, 03 Aug 2010 09:13:13 +0000 [thread overview]
Message-ID: <1280826793.3629.13.camel@yio.site> (raw)
In-Reply-To: <4C55D1CF.5090206@felipebalbi.com>
On Tue, Aug 3, 2010 at 09:28, Felipe Balbi <me@felipebalbi.com> wrote:
>>> For example, if I attach a usb mass storage device I want to
>>> figure out which /dev/sdXX I'm supposed to use when trying to read/write
>>> to that particular device. Similarly for ACM, Network and all other devices.
>>
>> For each type of device, you are going to have to do it differently.
>> And note that network devices don't have device nodes, so that makes it
>> harder to make a "general" case here.
>>
>>> Is there any way to achieve that with libudev ?
That's not provided by libudev, but would be possible to do.
It would need an 'udev enumerator' that starts at a given device,
and returns a list of all the children, which can be investigated
individually. All current 'enumerators' only operate on specific
properties of a device, not on parent-child relations.
All devices belonging to a specific USB device are sysfs child devices of
it. It's a simple tree you can walk. The child devices may have their own
device nodes (here: mouse2, event10), and may also belong to different
subsystems (here: input, hid).
That should work for all interfaces a device provides and which is
currently bound by a kernel driver. Note, that not all drivers use a device
node as the interface. No device node does never mean, that there is no
active driver.
$ tree -d /sys/bus/usb/devices/5-2.1.2
/sys/bus/usb/devices/5-2.1.2
├── 5-2.1.2:1.0
│ ├── 0003:046D:C045.0009
│ │ ├── driver -> ../../../../../../../../../bus/hid/drivers/generic-usb
│ │ ├── power
│ │ └── subsystem -> ../../../../../../../../../bus/hid
│ ├── driver -> ../../../../../../../../bus/usb/drivers/usbhid
│ ├── ep_81
│ │ └── power
│ ├── input
│ │ └── input16
│ │ ├── capabilities
│ │ ├── device -> ../../../5-2.1.2:1.0
│ │ ├── event10
│ │ │ ├── device -> ../../input16
│ │ │ ├── power
│ │ │ └── subsystem -> ../../../../../../../../../../../class/input
│ │ ├── id
│ │ ├── mouse2
│ │ │ ├── device -> ../../input16
│ │ │ ├── power
│ │ │ └── subsystem -> ../../../../../../../../../../../class/input
│ │ ├── power
│ │ └── subsystem -> ../../../../../../../../../../class/input
│ ├── power
│ └── subsystem -> ../../../../../../../../bus/usb
├── driver -> ../../../../../../../bus/usb/drivers/usb
├── ep_00
│ └── power
├── power
└── subsystem -> ../../../../../../../bus/usb
Kay
next prev parent reply other threads:[~2010-08-03 9:13 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-08-01 19:58 Figuring out devnodes from a usb device Felipe Balbi
2010-08-02 22:29 ` Greg KH
2010-08-03 7:28 ` Felipe Balbi
2010-08-03 9:13 ` Kay Sievers [this message]
2010-08-03 19:53 ` Greg KH
2010-08-03 20:20 ` Felipe Balbi
2010-08-03 20:32 ` Greg KH
2010-08-04 5:09 ` Felipe Balbi
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1280826793.3629.13.camel@yio.site \
--to=kay.sievers@vrfy.org \
--cc=linux-hotplug@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).