Qt 6.x
The Qt SDK
Loading...
Searching...
No Matches
qstorageinfo_p.h
Go to the documentation of this file.
1// Copyright (C) 2014 Ivan Komissarov <ABBAPOH@gmail.com>
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#ifndef QSTORAGEINFO_P_H
5#define QSTORAGEINFO_P_H
6
7//
8// W A R N I N G
9// -------------
10//
11// This file is not part of the Qt API. It exists purely as an
12// implementation detail. This header file may change from version to
13// version without notice, or even be removed.
14//
15// We mean it.
16//
17
18#include <QtCore/qloggingcategory.h>
19#include <QtCore/qsystemdetection.h>
20#include <QtCore/qtenvironmentvariables.h>
21#include <QtCore/private/qglobal_p.h>
22#include "qstorageinfo.h"
23
25
26inline Q_LOGGING_CATEGORY(lcStorageInfo, "qt.core.qstorageinfo", QtWarningMsg)
27
28class QStorageInfoPrivate : public QSharedData
29{
30public:
31 inline QStorageInfoPrivate() : QSharedData(),
32 bytesTotal(-1), bytesFree(-1), bytesAvailable(-1), blockSize(-1),
33 readOnly(false), ready(false), valid(false)
34 {}
35
36 void initRootPath();
37 void doStat();
38
39 static QList<QStorageInfo> mountedVolumes();
40
41 static QStorageInfo root()
42 {
43#ifdef Q_OS_WIN
45#else
46 return QStorageInfo(QStringLiteral("/"));
47#endif
48 };
49
50protected:
51#if defined(Q_OS_WIN)
52 void retrieveVolumeInfo();
53 void retrieveDiskFreeSpace();
54 bool queryStorageProperty();
55 void queryFileFsSectorSizeInformation();
56#elif defined(Q_OS_DARWIN)
57 void retrievePosixInfo();
58 void retrieveUrlProperties(bool initRootPath = false);
59 void retrieveLabel();
60#elif defined(Q_OS_UNIX)
61 void retrieveVolumeInfo();
62#endif
63
64public:
65 QString rootPath;
67 QByteArray subvolume;
68 QByteArray fileSystemType;
70
71 qint64 bytesTotal;
72 qint64 bytesFree;
73 qint64 bytesAvailable;
75
76 bool readOnly;
77 bool ready;
78 bool valid;
79};
80
81// Common helper functions
82template <typename String>
83static bool isParentOf(const String &parent, const QString &dirName)
84{
85 return dirName.startsWith(parent) &&
86 (dirName.size() == parent.size() || dirName.at(parent.size()) == u'/' ||
87 parent.size() == 1);
88}
89
90static inline bool shouldIncludeFs(const QString &mountDir, const QByteArray &fsType)
91{
92#if defined(Q_OS_ANDROID)
93 // "rootfs" is the filesystem type of "/" on Android
94 static constexpr char RootFsStr[] = "";
95#else
96 // "rootfs" is a type of ramfs on Linux, used in the initrd on some distros
97 static constexpr char RootFsStr[] = "rootfs";
98#endif
99
100 using namespace Qt::StringLiterals;
101 /*
102 * This function implements a heuristic algorithm to determine whether a
103 * given mount should be reported to the user. Our objective is to list
104 * only entries that the end-user would find useful.
105 *
106 * We therefore ignore:
107 * - mounted in /dev, /proc, /sys: special mounts
108 * (this will catch /sys/fs/cgroup, /proc/sys/fs/binfmt_misc, /dev/pts,
109 * some of which are tmpfs on Linux)
110 * - mounted in /var/run or /var/lock: most likely pseudofs
111 * (on earlier systemd versions, /var/run was a bind-mount of /run, so
112 * everything would be unnecessarily duplicated)
113 * - filesystem type is "rootfs": artifact of the root-pivot on some Linux
114 * initrd
115 * - if the filesystem total size is zero, it's a pseudo-fs (not checked here).
116 */
117
118 if (isParentOf("/dev"_L1, mountDir)
119 || isParentOf("/proc"_L1, mountDir)
120 || isParentOf("/sys"_L1, mountDir)
121 || isParentOf("/var/run"_L1, mountDir)
122 || isParentOf("/var/lock"_L1, mountDir)) {
123 return false;
124 }
125
126 if (!fsType.isEmpty() && fsType == RootFsStr)
127 return false;
128
129 // size checking in QStorageInfo::mountedVolumes()
130 return true;
131}
132
134
135#endif // QSTORAGEINFO_P_H
IOBluetoothDevice * device
\inmodule QtCore
Definition qbytearray.h:57
bool isEmpty() const noexcept
Returns true if the byte array has size 0; otherwise returns false.
Definition qbytearray.h:106
static QString fromNativeSeparators(const QString &pathName)
Definition qdir.cpp:962
static QString decodeName(const QByteArray &localFileName)
This does the reverse of QFile::encodeName() using localFileName.
Definition qfile.h:162
Definition qlist.h:74
\inmodule QtCore
Definition qshareddata.h:19
\inmodule QtCore
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:127
bool startsWith(const QString &s, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Returns true if the string starts with s; otherwise returns false.
Definition qstring.cpp:5299
qsizetype size() const
Returns the number of characters in this string.
Definition qstring.h:182
const QChar at(qsizetype i) const
Returns the character at the given index position in the string.
Definition qstring.h:1079
Combined button and popup list for selecting options.
const int blockSize
@ QtWarningMsg
Definition qlogging.h:31
#define Q_LOGGING_CATEGORY(name,...)
GLuint name
static QString retrieveLabel(const QByteArray &device)
static bool shouldIncludeFs(const QString &mountDir, const QByteArray &fsType)
QT_BEGIN_NAMESPACE static Q_LOGGING_CATEGORY(lcStorageInfo, "qt.core.qstorageinfo", QtWarningMsg) class QStorageInfoPrivate bool isParentOf(const String &parent, const QString &dirName)
#define QStringLiteral(str)
Q_CORE_EXPORT QByteArray qgetenv(const char *varName)
unsigned long ulong
Definition qtypes.h:30
long long qint64
Definition qtypes.h:55
IUIAutomationTreeWalker __RPC__deref_out_opt IUIAutomationElement ** parent