Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I have a USB flash drive connected to a hub. Its storage device partition devpath in sysfs is /devices/pci0000:00/0000:00:12.2/usb6/6-1/6-1.2/6-1.2:1.0/host10/target10:0:0/10:0:0:0/block/sdb/sdb1. I would like to retrieve the corresponding USB device path (i.e. /devices/pci0000:00/0000:00:12.2/usb6/6-1/6-1.2, or even better /sys/bus/usb/devices/6-1.2). I'm going to do it in some scripting language (shell, python, whatever) for any device inserted into the PC. EDIT: I get the original partition's devpath from udev, and I need to trace it back to the USB device entry.

The most simple&stupid approach is to navigate the path upwards, up to the 6-1.2 entry. It has a few serious and obvious drawbacks, though. First, the device may or may not be connected to a hub, and thus its devpath may change. Second, the device may or may not have partitions, which also changes the devpath. I also need a generic solution, not just for the 6-1.2 device.

Apparently, there are no symlinks leading to the actual device entry from the .../block/sdb/sdb1 directory. Is there any elegant way to do what I want at all?

share|improve this question
    
When you say "device path" what kernel object are you seeking? I inserted a USB key to one of my servers and was able to see a link to the device object in /sys/block/sdl so I think it might be useful to see what information you're trying to tease out of sysfs. –  Joel Davis Mar 22 '13 at 12:47
    
I need a path to the USB device entry itself (the one that contains idVendor, idProduct and other USB thingies). The original devpath I'm talking about is passed to my script from udev. –  Roman D Mar 22 '13 at 13:03
    
Making sure I understand, is this what you're trying to do? dpaste.org/R7fqP –  Joel Davis Mar 22 '13 at 13:46
    
I'm afraid, not really. Here, we end up in the PCI device entry, but I need the USB device –  Roman D Mar 22 '13 at 14:02
    
@RomanD - could you explain why you need /sys/bus/usb/devices/... path ? Also, isn't the path you need the first one that is displayed if you run udevadm monitor --udev --subsystem-match=usb and then insert your flash drive ? –  don_crissti Apr 19 '13 at 0:07

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.