Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Is there a way to determine if a mount is a network file system?

Is there a way to determine if a mount is a network file system?

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 1 Posters 1.1k Views 1 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.
  • l3u_L Offline
    l3u_L Offline
    l3u_
    wrote on last edited by
    #1

    Hi all :-)

    I'm trying to determine if some directory is a network file system or not. On Linux, this seems to be possible via QStorageInfo. If I go through QStorageInfo::mountedVolumes(), I can check fileSystemType(). So I e. g. get "nfs4", "cifs" or "fuse.sshfs" for network mounts.

    On Windows however, for a Samba share, I get "NTFS", as if the share was a normal local file system.

    So, when on Windows, I can't use this to know if it's a local or a remote file system. Is there any way to ascertain this cross-platform?

    Thanks for all help!

    1 Reply Last reply
    0
    • l3u_L Offline
      l3u_L Offline
      l3u_
      wrote on last edited by l3u_
      #2

      Okay, meanwhile I can write something here myself. In my feature request about this at https://bugreports.qt.io/browse/QTBUG-83321 , some approach emerged that at least fits my needs: Using QStorageInfo::device(), one can find out if a mount is using a physical device or something else (like a Samba share or whatever.)

      This can be checked using the following enum:

      enum DeviceType {
          Physical,
          Other,
          Unknown
      };
      

      and the following function:

      DeviceType deviceType(const QStorageInfo &volume) const
      {
      #ifdef Q_OS_LINUX
          if (QString::fromLatin1(volume.device()).startsWith(QLatin1String("/"))) {
              return DeviceType::Physical;
          } else {
              return DeviceType::Other;
          }
      #endif
      #ifdef Q_OS_WIN
          if (QString::fromLatin1(volume.device()).startsWith(QLatin1String("\\\\?\\Volume"))) {
              return DeviceType::Physical;
          } else {
              return DeviceType::Other;
          }
      #endif
      #ifdef Q_OS_MACOS
          if (! QString::fromLatin1(volume.device()).startsWith(QLatin1String("//"))) {
              return DeviceType::Physical;
          } else {
              return DeviceType::Other;
          }
      #endif
          return DeviceType::Unknown;
      }
      

      This reliably works for me on Linux, Windows and macOS.

      1 Reply Last reply
      1

      • Login

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