[Solved] USB storage persistent mount point



  • Hi

    My eLinux system with mdev does not automatically mount attached storage.
    I am using a QFileSystemWatcher to monitor /dev and react on changes. This works perfectly and I automatically mount and unmount USB storage attached and removed.

    I now need it to have it always use the same mount point based on the physical connector the USB storage has been attached to.
    The only way to et the information needed for this mapping I found is to use this linux command
    find /sys/bus/usb/devices/usb*/ -name dev
    and then parse the output from the result

    /sys/bus/usb/devices/usb1/dev
    /sys/bus/usb/devices/usb1/usb_device/usbdev1.1/dev
    /sys/bus/usb/devices/usb1/1-1/1-1:1.0/host19/target19:0:0/19:0:0:0/scsi_generic/sg1/dev
    /sys/bus/usb/devices/usb1/1-1/1-1:1.0/host19/target19:0:0/19:0:0:0/block/sdb/dev
    /sys/bus/usb/devices/usb1/1-1/1-1:1.0/host19/target19:0:0/19:0:0:0/block/sdb/sdb1/dev
    /sys/bus/usb/devices/usb1/1-1/usb_device/usbdev1.13/dev
    /sys/bus/usb/devices/usb1/1-1/dev
    /sys/bus/usb/devices/usb2/dev
    /sys/bus/usb/devices/usb2/usb_device/usbdev2.1/dev
    /sys/bus/usb/devices/usb2/2-1/dev
    /sys/bus/usb/devices/usb2/2-1/usb_device/usbdev2.2/dev
    /sys/bus/usb/devices/usb2/2-1/2-1.4/dev
    /sys/bus/usb/devices/usb2/2-1/2-1.4/2-1.4:1.0/input/input1/mouse1/dev
    /sys/bus/usb/devices/usb2/2-1/2-1.4/2-1.4:1.0/input/input1/js1/dev
    /sys/bus/usb/devices/usb2/2-1/2-1.4/2-1.4:1.0/input/input1/event1/dev
    /sys/bus/usb/devices/usb2/2-1/2-1.4/usb_device/usbdev2.3/dev
    /sys/bus/usb/devices/usb2/2-1/2-1.3/2-1.3:1.0/host18/target18:0:0/18:0:0:0/scsi_generic/sg0/dev
    /sys/bus/usb/devices/usb2/2-1/2-1.3/2-1.3:1.0/host18/target18:0:0/18:0:0:0/block/sda/dev
    /sys/bus/usb/devices/usb2/2-1/2-1.3/2-1.3:1.0/host18/target18:0:0/18:0:0:0/block/sda/sda1/dev
    /sys/bus/usb/devices/usb2/2-1/2-1.3/dev
    /sys/bus/usb/devices/usb2/2-1/2-1.3/usb_device/usbdev2.10/dev
    /sys/bus/usb/devices/usb3/dev
    /sys/bus/usb/devices/usb3/usb_device/usbdev3.1/dev
    

    Did I miss an an easier way?
    Any hints on getting the output of this command back into Qt and how to parse, i.e.
    getting the usb2 when having sda as input
    from the QFileSystemWatcher or
    getting usb1 when having sdb as input?

    Is there a Qt way of running this find shell command?


  • Lifetime Qt Champion

    Hi,

    You can use QDir to get the content of the directory. Maybe KDE's Solid library could be handy in your case.

    Hope it helps



  • @SGaist
    I'm not sure, but I believe solid needs udev. I'm using busybox with mdev.
    However, I found a solution with find and grep.
    If I know I have to find where, for instance, sda is connected on my 4 ports:

    find /sys/bus/usb/devices/usb*/ -name dev -path "*usb1*sd*" | grep -E sda
    find /sys/bus/usb/devices/usb*/ -name dev -path "*usb2-1.1*sd*" | grep -E sda
    find /sys/bus/usb/devices/usb*/ -name dev -path "*usb2-1.2*sd*" | grep -E sda
    find /sys/bus/usb/devices/usb*/ -name dev -path "*usb2-1.4*sd*" | grep -E sda

    The return value is 1 if there is no entry matching and 0 if there is.
    I wrapped this in a function with sd_ as variable and it works as supposed.

    Cheers,
    McL


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.