summaryrefslogtreecommitdiffstats
path: root/src/corelib/io/qstorageinfo_unix.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/corelib/io/qstorageinfo_unix.cpp')
-rw-r--r--src/corelib/io/qstorageinfo_unix.cpp80
1 files changed, 51 insertions, 29 deletions
diff --git a/src/corelib/io/qstorageinfo_unix.cpp b/src/corelib/io/qstorageinfo_unix.cpp
index c02d82a711..ae5c42ffd1 100644
--- a/src/corelib/io/qstorageinfo_unix.cpp
+++ b/src/corelib/io/qstorageinfo_unix.cpp
@@ -1,31 +1,38 @@
/****************************************************************************
**
** Copyright (C) 2014 Ivan Komissarov <ABBAPOH@gmail.com>
-** Contact: http://www.qt.io/licensing/
+** Copyright (C) 2016 Intel Corporation.
+** Contact: https://www.qt.io/licensing/
**
** This file is part of the QtCore module of the Qt Toolkit.
**
-** $QT_BEGIN_LICENSE:LGPL21$
+** $QT_BEGIN_LICENSE:LGPL$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see http://www.qt.io/terms-conditions. For further
-** information use the contact form at http://www.qt.io/contact-us.
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 2.1 or version 3 as published by the Free
-** Software Foundation and appearing in the file LICENSE.LGPLv21 and
-** LICENSE.LGPLv3 included in the packaging of this file. Please review the
-** following information to ensure the GNU Lesser General Public License
-** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
-** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+** General Public License version 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
**
-** As a special exception, The Qt Company gives you certain additional
-** rights. These rights are described in The Qt Company LGPL Exception
-** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or (at your option) the GNU General
+** Public license version 3 or any later version approved by the KDE Free
+** Qt Foundation. The licenses are as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-2.0.html and
+** https://www.gnu.org/licenses/gpl-3.0.html.
**
** $QT_END_LICENSE$
**
@@ -147,29 +154,41 @@ static bool isParentOf(const String &parent, const QString &dirName)
parent.size() == 1);
}
-static bool isPseudoFs(const QStorageIterator &it)
-{
+static bool shouldIncludeFs(const QStorageIterator &it)
+{
+ /*
+ * This function implements a heuristic algorithm to determine whether a
+ * given mount should be reported to the user. Our objective is to list
+ * only entries that the end-user would find useful.
+ *
+ * We therefore ignore:
+ * - mounted in /dev, /proc, /sys: special mounts
+ * (this will catch /sys/fs/cgroup, /proc/sys/fs/binfmt_misc, /dev/pts,
+ * some of which are tmpfs on Linux)
+ * - mounted in /var/run or /var/lock: most likely pseudofs
+ * (on earlier systemd versions, /var/run was a bind-mount of /run, so
+ * everything would be unnecessarily duplicated)
+ * - filesystem type is "rootfs": artifact of the root-pivot on some Linux
+ * initrd
+ * - if the filesystem total size is zero, it's a pseudo-fs (not checked here).
+ */
+
QString mountDir = it.rootPath();
if (isParentOf(QLatin1String("/dev"), mountDir)
|| isParentOf(QLatin1String("/proc"), mountDir)
|| isParentOf(QLatin1String("/sys"), mountDir)
|| isParentOf(QLatin1String("/var/run"), mountDir)
|| isParentOf(QLatin1String("/var/lock"), mountDir)) {
- return true;
+ return false;
}
- QByteArray type = it.fileSystemType();
- if (type == "tmpfs")
+#ifdef Q_OS_LINUX
+ if (it.fileSystemType() == "rootfs")
return false;
-#if defined(Q_OS_LINUX)
- if (type == "rootfs" || type == "rpc_pipefs")
- return true;
#endif
- if (!it.device().startsWith('/'))
- return true;
-
- return false;
+ // size checking in mountedVolumes()
+ return true;
}
#if defined(Q_OS_BSD4)
@@ -522,7 +541,7 @@ void QStorageInfoPrivate::retrieveVolumeInfo()
valid = true;
ready = true;
-#if defined(Q_OS_BSD4) && !defined(Q_OS_NETBSD)
+#if defined(Q_OS_INTEGRITY) || (defined(Q_OS_BSD4) && !defined(Q_OS_NETBSD))
bytesTotal = statfs_buf.f_blocks * statfs_buf.f_bsize;
bytesFree = statfs_buf.f_bfree * statfs_buf.f_bsize;
bytesAvailable = statfs_buf.f_bavail * statfs_buf.f_bsize;
@@ -532,7 +551,7 @@ void QStorageInfoPrivate::retrieveVolumeInfo()
bytesAvailable = statfs_buf.f_bavail * statfs_buf.f_frsize;
#endif
blockSize = statfs_buf.f_bsize;
-#if defined(Q_OS_ANDROID) || defined (Q_OS_BSD4)
+#if defined(Q_OS_ANDROID) || defined(Q_OS_BSD4) || defined(Q_OS_INTEGRITY)
#if defined(_STATFS_F_FLAGS)
readOnly = (statfs_buf.f_flags & ST_RDONLY) != 0;
#endif
@@ -551,11 +570,14 @@ QList<QStorageInfo> QStorageInfoPrivate::mountedVolumes()
QList<QStorageInfo> volumes;
while (it.next()) {
- if (isPseudoFs(it))
+ if (!shouldIncludeFs(it))
continue;
const QString mountDir = it.rootPath();
- volumes.append(QStorageInfo(mountDir));
+ QStorageInfo info(mountDir);
+ if (info.bytesTotal() == 0)
+ continue;
+ volumes.append(info);
}
return volumes;