Posted by: Airtower | 2010-06-28

Get USB device information from sysfs

The Linux kernel names USB devices depending on their location on the bus. When I plug my USB flash drive into my computer, a line like this will appear in the kernel log:

usb 1-4: new high speed USB device using ehci_hcd and address 7

“1-4” is the kernel’s name for the device: “1” is the root hub number, “4” the number of the hub port. With this information, it is easy to find the device in sysfs:

/sys/bus/usb/devices/1-4/

Using files in this directory, I can check what kind of device it is or how much power it requests from the bus.

$ cat /sys/bus/usb/devices/1-4/product
Mass Storage Device
$ cat /sys/bus/usb/devices/1-4/bMaxPower
100mA

There’s a lot more, including the device’s vendor ID, product ID and serial number. You might be wondering “Why not just use lsusb?” Most of the time, you can do that. In cases were you can’t, like an embedded system without usbutils, knowing the sysfs path can be really useful. I actually needed this today, and it’s interesting anyways. 😉

If you want to know more about this topic, I would recommend reading “Linux Device Drivers“, chapter 13 (the sysfs part starts at page 333).

Advertisements

Leave a Comment

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Categories

%d bloggers like this: