void QStorageInfoPrivate::initRootPath() { rootPath = QFileInfo(rootPath).canonicalFilePath(); if (rootPath.isEmpty()) return; QStorageIterator it; if (!it.isValid()) { rootPath = QStringLiteral("/"); return; } int maxLength = 0; const QString oldRootPath = rootPath; rootPath.clear(); while (it.next()) { const QString mountDir = it.rootPath(); const QByteArray fsName = it.fileSystemType(); if (isPseudoFs(mountDir, fsName)) continue; // we try to find most suitable entry if (oldRootPath.startsWith(mountDir) && maxLength < mountDir.length()) { maxLength = mountDir.length(); rootPath = mountDir; device = it.device(); fileSystemType = fsName; } } }
QList<QStorageInfo> QStorageInfoPrivate::mountedVolumes() { QStorageIterator it; if (!it.isValid()) return QList<QStorageInfo>() << root(); QList<QStorageInfo> volumes; while (it.next()) { const QString mountDir = it.rootPath(); const QByteArray fsName = it.fileSystemType(); if (isPseudoFs(mountDir, fsName)) continue; volumes.append(QStorageInfo(mountDir)); } return volumes; }
static bool isPseudoFs(const QStorageIterator &it) { 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; } QByteArray type = it.fileSystemType(); if (type == "tmpfs") return false; #if defined(Q_OS_LINUX) if (type == "rootfs" || type == "rpc_pipefs") return true; #endif if (!it.device().startsWith('/')) return true; return false; }