From d9f6b6d1f836c25a8179ae7a6df18ee9cceebfb1 Mon Sep 17 00:00:00 2001
From: Thiago Macieira <thiago.macieira@intel.com>
Date: Tue, 17 Nov 2015 22:25:04 -0800
Subject: [PATCH] QStorageInfo: update the detection of pseudo filesystems

Allow tmpfs filesystems to be reported, as they're often usable by the
user, mounted in /tmp and in /run (the fs for $XDG_RUNTIME_DIR).

But disallow anything whose device is not a pathname. This catches most
of everything else that wasn't specifically tested for before, like
virtual fuse filesystems, like GVFS.

Change-Id: I3e15a26e0e424169ac2bffff1417b7cee0f8ec97
Reviewed-by: Ivan Komissarov <ABBAPOH@gmail.com>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
---
 src/corelib/io/qstorageinfo_unix.cpp | 5 ++++-
 tests/manual/qstorageinfo/main.cpp   | 7 ++++---
 2 files changed, 8 insertions(+), 4 deletions(-)

diff --git a/src/corelib/io/qstorageinfo_unix.cpp b/src/corelib/io/qstorageinfo_unix.cpp
index bbcc29c50b0..bf998993d8a 100644
--- a/src/corelib/io/qstorageinfo_unix.cpp
+++ b/src/corelib/io/qstorageinfo_unix.cpp
@@ -160,12 +160,15 @@ static bool isPseudoFs(const QStorageIterator &it)
 
     QByteArray type = it.fileSystemType();
     if (type == "tmpfs")
-        return true;
+        return false;
 #if defined(Q_OS_LINUX)
     if (type == "rootfs" || type == "rpc_pipefs")
         return true;
 #endif
 
+    if (!it.device().startsWith('/'))
+        return true;
+
     return false;
 }
 
diff --git a/tests/manual/qstorageinfo/main.cpp b/tests/manual/qstorageinfo/main.cpp
index 884e5559ce4..5c106ff45b4 100644
--- a/tests/manual/qstorageinfo/main.cpp
+++ b/tests/manual/qstorageinfo/main.cpp
@@ -66,10 +66,11 @@ int main(int argc, char *argv[])
 
     printf("Filesystem (Type)            Size  Available BSize  Label            Mounted on\n");
     foreach (const QStorageInfo &info, volumes) {
-        const QString fsAndType = info.device() + QLatin1String(" (") +
-                                  info.fileSystemType() + QLatin1Char(')');
+        QByteArray fsAndType = info.device();
+        if (info.fileSystemType() != fsAndType)
+            fsAndType += " (" + info.fileSystemType() + ')';
 
-        printf("%-19s R%c ", qPrintable(fsAndType), info.isReadOnly() ? 'O' : 'W');
+        printf("%-19s R%c ", fsAndType.constData(), info.isReadOnly() ? 'O' : 'W');
         if (fsAndType.size() > 19)
             printf("\n%23s", "");
 
-- 
GitLab