On Mon, 2 Aug 2004, Photon Software (Marko Röder) wrote:

> It's not the problem for _me_ to find the proper device to mount. Need this 
> information for an app that should determine whether the device is plugged or 
> not and if plugged it should have a closer look at the files on it.
> 
> @/proc/bus/usb/devices:
> It's the iRiver device.
> 
> @/proc/scsi/scsi
> Here it's the TOSHIBA disk.
> 
> Thx a lot,
> Marko Roeder

Okay.  It's awkward, I admit, but it can be programmed if you really want 
to.

The device you're interested in is the iRiver.  In /proc/bus/usb/devices
it shows up with Bus=04 and Prnt=01.  You're lucky here that it's plugged
directly into the computer and not into an external hub.  (The USB
connector on the computer is always numbered 01.)  The other important
piece of information is Port=04.  Add 1 to this to get 5 for the actual
port number -- for some unknown reason the port values given in
/proc/bus/usb/devices are always reduced by one.

Put the bus and port numbers together like this: "usb4/4-5" (the bus
number gets in there twice).

Now search through /sys/block/sd* for the "device" symbolic links.  Here's 
what your links point to:

/sys/block/sda/device: 
../../devices/pci0000:00/0000:00:03.2/usb3/3-2/3-2:1.0/host0/0:0:0:0
/sys/block/sdb/device: 
../../devices/pci0000:00/0000:00:03.2/usb3/3-2/3-2:1.0/host0/0:0:0:1
/sys/block/sdc/device: 
../../devices/pci0000:00/0000:00:03.3/usb4/4-5/4-5:2.0/host1/1:0:0:0

Notice which entry contains the string "usb4/4-5"; that's the one you
want.  As a check, notice that the sdc link also contains the string 
"host1"; this matches the "host scsi1" line in your usb-storage-1 file and
the "Host: scsi1" entry in /proc/scsi/scsi (which is the TOSHIBA disk).

Things can get more complicated than this.  For instance, your other USB
storage device ("Manufacturer=Generic") has Bus=03, Prnt=01, and Port=01.  
That gives the string "usb3/3-2", which matches both sda and sdb.  Of
course the reason is because this device has two Logical Units, so it
shows up as two disks.  And not surprisingly, the usb-storage-0 file (with
"Generic" as the manufacturer) contains "host scsi0" to match the "host0"
string in the symbolic links.


What if you had your drive plugged into an external hub?  Then you would
need to do some more computation.  For example, the drive might have
Bus=04 and Prnt=02, with Port=00.  You would need to find the entry in
/proc/bus/usb/devices for the external hub, the entry with Bus=04 and
Dev#= 2 (that is, the Dev# of the hub must be the same as the Prnt --
short for Parent -- value of the drive).  Let's say the hub has Prnt=01,
meaning that the hub's parent is the computer, and port=02.  Then adding
one to the port numbers, you put together the search string like this:
"usb4/4-3/4-3.1"

In other words, each element of the search string refers to a device on
the path starting with the computer's USB port and and ending with the
drive.  The computer port name has the form "usbN" where N is the bus
number.  The remaining elements have the form "N-A/N-A.B/N-A.B.C" and so
on, where A, B, C, etc. are the port numbers.  A is the port number on the
computer's USB controller, B is the port number on the first intermediate
hub, C is the port number on the next hub, ...

Alan Stern






-------------------------------------------------------
This SF.Net email is sponsored by OSTG. Have you noticed the changes on
Linux.com, ITManagersJournal and NewsForge in the past few weeks? Now,
one more big change to announce. We are now OSTG- Open Source Technology
Group. Come see the changes on the new OSTG site. www.ostg.com
_______________________________________________
[EMAIL PROTECTED]
To unsubscribe, use the last form field at:
https://lists.sourceforge.net/lists/listinfo/linux-usb-devel

Reply via email to