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?