Re: How to associate lsusb bus/device with /dev entry?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Just out of curiosity...  Why did you post two nearly identical 
versions of this message?

On Wed, 29 Aug 2012, Mathew Binkley wrote:

> Hi all.  How can you associate a USB Bus:Device info with a /dev/entry?

There is no general way to do this because most USB devices don't have 
entries under /dev.  However I gather that you're talking about USB 
mass storage devices in particular; for these it is possible.

> Below I have copy/pasted lsusb and /sys/block entries for two drives 
> plugged into the same USB bus.
> 
> When there was only one USB key, I could simply take the Bus number 
> (with leading 0's trimmed off) and
> 
>     ls -alh /sys/block | grep /usbB/  # B is the bus number
> 
> That heuristic fails when there is more than one drive on the same bus. 
>   The "lsusb" Device number has no discernible match in the 
> corresponding /sys/block path
> 
> Can anyone give me any advice?

There is no direct way.  You have to do a search.

> ---
> 
> lsusb:
> 
> Bus 003 Device 013: ID 0930:6545 Toshiba Corp. Kingston DataTraveler 102 
> Flash Drive / HEMA Flash Drive 2 GB / PNY Attache 4GB Stick
> 
> Bus 003 Device 015: ID 0781:5406 SanDisk Corp. Cruzer Micro U3
> 
> 
> /sys/block:
> 
> sdc -> 
> /sys/devices/pci0000:00/0000:00:16.2/usb3/3-3/3-3:1.0/host16/target16:0:0/16:0:0:0/block/sdc
> 
> sdd -> 
> /sys/devices/pci0000:00/0000:00:16.2/usb3/3-4/3-4:1.0/host18/target18:0:0/18:0:0:0/block/sdd

>From the /sys/block/sdX directory, go up 6 levels and read the contents 
of the "busnum" and "devnum" files there.  You'll have to look through 
the various sdX entries to find the proper match.

Here an example from my system (this is a DVD drive rather than a flash
drive, so I'm using srX instead of sdX, but the idea is the same):

lsusb:
Bus 001 Device 002: ID 059f:0202 LaCie, Ltd StudioDrive USB2

/sys/block/sr0 -> ../devices/pci0000:00/0000:00:1f.1/ata2/host1/target1:0:0/1:0:0:0/block/sr0/
/sys/block/sr1 -> ../devices/pci0000:00/0000:00:1d.7/usb1/1-4/1-4:2.0/host2/target2:0:0/2:0:0:0/block/sr1/

$ cat /sys/block/sr0/../../../../../../busnum
cat: /sys/block/sr0/../../../../../../busnum: No such file or directory
$ cat /sys/block/sr1/../../../../../../busnum
1
$ cat /sys/block/sr1/../../../../../../devnum
2

The busnum and devnum values for sr1 match the Bus and Device values 
from lsusb, so the LaCie StudioDrive is /dev/sr1.

Of course, you could tell just by looking at the full path that the sr0
device wasn't USB.  But if it was, the busnum/devnum values would be 
different from those of the LaCie drive.

Alan Stern

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Linux Media]     [Linux Input]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [Old Linux USB Devel Archive]

  Powered by Linux