Is there a way to determine if a mount is a network file system?
-
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 throughQStorageInfo::mountedVolumes(), I can checkfileSystemType(). 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!
-
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.