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:
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
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).