Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. [Solved] USB storage persistent mount point
Forum Updated to NodeBB v4.3 + New Features

[Solved] USB storage persistent mount point

Scheduled Pinned Locked Moved Mobile and Embedded
usbmountstoragedevices
3 Posts 2 Posters 2.8k Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • McLionM Offline
    McLionM Offline
    McLion
    wrote on last edited by McLion
    #1

    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?

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      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

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      McLionM 1 Reply Last reply
      0
      • SGaistS SGaist

        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

        McLionM Offline
        McLionM Offline
        McLion
        wrote on last edited by
        #3

        @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

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved