3

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?

5
  • 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.
    – Bratchley
    Mar 22, 2013 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. Mar 22, 2013 at 13:03
  • Making sure I understand, is this what you're trying to do? dpaste.org/R7fqP
    – Bratchley
    Mar 22, 2013 at 13:46
  • I'm afraid, not really. Here, we end up in the PCI device entry, but I need the USB device Mar 22, 2013 at 14:02
  • @don_crissti I need to get a USB device path from SCSI device path to retrieve certain USB-related parameters. I need to do it in a Python script, so udevadm monitor is not likely to help me. Apr 29, 2013 at 9:48

0

You must log in to answer this question.

Browse other questions tagged .