LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Slackware (https://www.linuxquestions.org/questions/slackware-14/)
-   -   which device in /dev is mapped to an USB device (https://www.linuxquestions.org/questions/slackware-14/which-device-in-dev-is-mapped-to-an-usb-device-348331/)

malo_umoran 07-30-2005 10:12 AM

which device in /dev is mapped to an USB device
 
Hi,

How can I find which device (example: /dev/sda) is mapped to an USB device?

I can find it dmesg, but is there a file in /proc or in /sys which shows something like:

Bus 003 Device 059: ID 0781:5151 => /dev/sda

Thanks

M.

rjlee 07-30-2005 07:14 PM

The usbfs filesystem is usually mounted on /proc/bus/usb (although you may need to mount this yourself). If contains a file called devices that tells you a lot about USB devices on your system, but it doesn't tell you /dev device names.

Actually, the filenames in /dev are purely arbitrary; what matters are the major and minor device IDs — which you can see by
Code:

ls -l /dev/file
You could potentially have multiple files per device, if they each have the same numbers. Unfortunately, these numbers aren't listed in the devices file either, although they are listed in /usr/src/linux/Documentation/devices.txt

I think the device number can be found in a file like /sys/class/usb_host/usb1/device/usb1/1-1/devnum (although I'm not entirely certain is this is a major or minor device number, or something else entirely).

Hope that's of some help,

— Robert J. Lee

malo_umoran 07-31-2005 10:29 AM

thanks for the information.

I already knew these things, but I had no success in finding out the device.

for example, my UBS stick is mostly /dev/sda, but sometimes it is /dev/sdb without any obvious reason for me.

M.

urka58 07-31-2005 11:33 AM

Hi,
device nodes are managed by hotplug/udev (assuming you're using 2.6 series kernel)
This system,basically, creates a device node just for devices that are actually connected. The name of the nodes is given chonologically. In other words if you plug in two removable devices (ie a camera as first and a pendrive then) that will use the same bus type, they will have respectively assigned the sda1 and sdb1 nodes.
In order they have assigned always the same device node name (as it will be just a symlink) you should edit your
/etc/udev/rules.d/ directory adding a file called 01-udev.rules containing a line like
BUS="scsi", KERNEL="sd[a-z][0-9]", NAME="%k", SYSFS{model}="JUMPDRIVE ", SYSFS{vendor}="LEXAR ", SYMLINK="pendrive"

those parameters can be obtained by the command
udevinfo -a -p `udevinfo -q path -n /dev/sda1`

Some useful suggestions can be found @
/usr/doc/udev-050/docs/writing_udev_rules

Hope this helps
ciao

malo_umoran 07-31-2005 01:12 PM

thanks, it helped ...

I knew about UDEV, but I didn't have any special rules about /dev/sd* devices, so I ignored it. But I got it now ...


If someone needs it:

I want my hotplug scripts to be able to recognize which device in /dev/ they got. /etc/hotplug/usb.agent delivers global variable $DEVPATH to every script.

so if I need to find out device name in a script, I can use $DEVPATH to find it. I use this only for "usb-storage" (block) device, but it can probably be used for other devices also.


when hotplug runs my_usb_script in /etc/hotplug/usb/, I should be able to find the device name with $DEVPATH.

Code:

sleep 5
USB_DEVICE=`udevinfo -as | grep -B 4 "$DEVPATH" | grep /sys/block | sed -re "s/^DEVPATH\s+'\/sys\/block\/(.*)'/\/dev\/\1/"`

USB_DEVICE is now /dev/sda or /dev/sdb or /dev/sdc... I had to put "sleep 5" before this, because hotplug/udev needs a litle bit to make a device etc.


I have USB-stick with a openssl key for a encrypted partition (dm-crypt). now when I put USB-stick in an USB slot, zenity asks me for a password in a popup windows and my encrypted partiton gets mounted. when I pull it out, the partition is again encrypted and umounted.

M.


All times are GMT -5. The time now is 08:38 PM.