コード例 #1
0
QList<QStorageInfo> QStorageInfoPrivate::mountedVolumes()
{
    QStorageIterator it;
    if (!it.isValid())
        return QList<QStorageInfo>() << root();

    QList<QStorageInfo> volumes;

    while (it.next()) {
        if (isPseudoFs(it))
            continue;

        const QString mountDir = it.rootPath();
        volumes.append(QStorageInfo(mountDir));
    }

    return volumes;
}
コード例 #2
0
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;
}
コード例 #3
0
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;
        }
    }
}
コード例 #4
0
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;
}