Re: /sys/bus/usb/devices/2-5 to /dev/... mapping

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

 



On Thu, 2 Apr 2015, Pieter Roodnat wrote:

> Hi Alan,

Hello.

> Sorry for bothering you like this, but i am getting pretty desperate and on what i see here
> http://www.spinics.net/lists/linux-usb/msg60916.html
> you are a real expert on this topic.
> So i boldly ask you the following, hoping you are willing to share your expertise with some advice:

Is there any reason you didn't post your message to the linux-usb 
mailing list, so that others could benefit from this exchange in the 
same way that you benefitted from the earlier exchange with Dave 
Mielke?  I hope you don't mind that I have CC'ed the mailing list for 
this reply.

> I have idVendor and idProduct codes of a device (2357:f000).

Have you considered what will happen in the future when you have two 
devices with the same idVendor and idProduct codes?

> By crawling (in C code)�"/sys/bus/usb/devices" i find the directory�"/sys/bus/usb/devices/2-5/" containing files with exactly those names and contents.
> Since i need to do a "ioctl(fd, CDROMEJECT, 0)" on that device, i need to figure out the "/dev/..." device file name for that.

Wait a minute -- you can't do a CDROMEJECT operation on a USB device.  
USB drivers don't understand commands that are meant for CD drivers.  
Do you mean that this device is a USB-connected CDROM drive?

> From the many files in the�"/sys/bus/usb/devices/2-5/" directory, none contain that and there does not seem to be a direct way get it either as you already wrote in your e-mail from the link above and the contents of some files is:
> devpath -> "5"
> dev -> "189:138"
> busnum -> "2"
> devnum -> "11" � (this one seems to increment per re-connect of the device)
> 
> Since this is not a ttyUSB* the same trick as your explaining e-mail does not apply.
> In this case it is a sr* device (for a (virtual) CD-ROM device) that in my case gets a device name like "/dev/sr2" for example.

Okay, that makes more sense.

> And that device name is what i want to get from the fixed xxxx:xxxx (idVendor:idProduct) i have.

If you're using udev, you should keep in mind that udev can assign arbitrary
names to devices.  In that case you're best off using udev itself to answer
your question.

However, I'll assume you're not interested in using udev.  You can get what
you want from /sys with a little searching.

Since you know you're looking for an sr device, you should search through
all the entries matching /sys/block/sr*.  For each one, check the contents
of the idVendor and idProduct files six directory levels up.

For example, on my computer sr0 is an ATAPI drive, so it doesn't have
the sort of vendor and product IDs you're looking for.  sr1 is a USB
drive.  Here's what I get:

$ for a in /sys/block/sr* ; do
>  echo $a `cat $a/../../../../../../idVendor` \
>    `cat $a/../../../../../../idProduct` ; done
cat: /sys/block/sr0/../../../../../../idVendor: No such file or directory
cat: /sys/block/sr0/../../../../../../idProduct: No such file or directory
/sys/block/sr0
/sys/block/sr1 059f 0202

This shows that sr1 is the USB device with vendor ID 059f and product 
ID 0202.

> Best regards and thanks in advance,
> 
> Pieter Roodnat
> 
> p.s.
> Suggestion for Linux kernel>= 3.x would be sufficient it that makes it easier for you.
> Requiring /proc and/or /sys is fine by me, but no /(s)bin commands and such.

Hope this helps,

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