Qt World Summit: Submit your Presentation

[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


    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


    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.