From mboxrd@z Thu Jan 1 00:00:00 1970 From: Kay Sievers Date: Tue, 03 Aug 2010 09:13:13 +0000 Subject: Re: Figuring out devnodes from a usb device Message-Id: <1280826793.3629.13.camel@yio.site> List-Id: References: <4C55D1CF.5090206@felipebalbi.com> In-Reply-To: <4C55D1CF.5090206@felipebalbi.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit To: linux-hotplug@vger.kernel.org On Tue, Aug 3, 2010 at 09:28, Felipe Balbi 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