summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThiago Macieira <thiago.macieira@intel.com>2024-01-17 11:52:59 -0800
committerThiago Macieira <thiago.macieira@intel.com>2024-01-22 11:40:19 -0800
commit96e5d0d5c19c09a2b0db5bd067deac06232a48ed (patch)
tree09af030dd2e4ad92b4d68a4119c5423d45abf02d
parent264b7a67330fb1a3fd0f896603e75ada46326875 (diff)
QStorageInfo/Linux: merge doStat() and initRootPath()
The doStat() function was too simple. Plus, we can now avoid having to come up with an non-zero-but-unused device ID for some corner cases. Pick-to: 6.7 Change-Id: I76ffba14ece04f24b43efffd17ab3a79e54e636d Reviewed-by: Ahmad Samir <a.samirh78@gmail.com> Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
-rw-r--r--src/corelib/io/qstorageinfo_linux.cpp32
-rw-r--r--src/corelib/io/qstorageinfo_p.h1
2 files changed, 8 insertions, 25 deletions
diff --git a/src/corelib/io/qstorageinfo_linux.cpp b/src/corelib/io/qstorageinfo_linux.cpp
index 8d8751db6a..9cd6a8da5a 100644
--- a/src/corelib/io/qstorageinfo_linux.cpp
+++ b/src/corelib/io/qstorageinfo_linux.cpp
@@ -134,16 +134,6 @@ static inline QString retrieveLabel(const QByteArray &device, quint64 deviceId)
return QString();
}
-void QStorageInfoPrivate::doStat()
-{
- retrieveVolumeInfo();
- quint64 deviceId = initRootPath();
- if (!deviceId)
- return;
-
- name = retrieveLabel(device, deviceId);
-}
-
void QStorageInfoPrivate::retrieveVolumeInfo()
{
struct statfs64 statfs_buf;
@@ -173,25 +163,20 @@ static std::vector<MountInfo> parseMountInfo(FilterMountInfo filter = FilterMoun
return doParseMountInfo(mountinfo, filter);
}
-quint64 QStorageInfoPrivate::initRootPath()
+void QStorageInfoPrivate::doStat()
{
+ retrieveVolumeInfo();
+ if (!ready)
+ return;
+
rootPath = QFileInfo(rootPath).canonicalFilePath();
if (rootPath.isEmpty())
- return 0;
+ return;
std::vector<MountInfo> infos = parseMountInfo();
if (infos.empty()) {
rootPath = u'/';
-
- // Need to return something non-zero here for this unlikely condition.
- // Linux currently uses 20 bits for the minor portion[1] in a 32-bit
- // integer; glibc, MUSL, and 64-bit Bionic use a 64-bit userspace
- // dev_t, so this value will not match a real device from the kernel.
- // 32-bit Bionic still has a 32-bit dev_t, but its makedev() macro[2]
- // returns 64-bit content too.
- // [1] https://codebrowser.dev/linux/linux/include/linux/kdev_t.h.html#_M/MINORBITS
- // [2] https://android.googlesource.com/platform/bionic/+/ndk-r19/libc/include/sys/sysmacros.h#39
- return makedev(0, -1);
+ return;
}
// We iterate over the /proc/self/mountinfo list backwards because then any
@@ -226,9 +211,8 @@ quint64 QStorageInfoPrivate::initRootPath()
if (best) {
auto stDev = best->stDev;
setFromMountInfo(std::move(*best));
- return stDev;
+ name = retrieveLabel(device, stDev);
}
- return 0;
}
QList<QStorageInfo> QStorageInfoPrivate::mountedVolumes()
diff --git a/src/corelib/io/qstorageinfo_p.h b/src/corelib/io/qstorageinfo_p.h
index 20f80ac0d1..3af4b81ca4 100644
--- a/src/corelib/io/qstorageinfo_p.h
+++ b/src/corelib/io/qstorageinfo_p.h
@@ -60,7 +60,6 @@ protected:
void retrieveUrlProperties(bool initRootPath = false);
void retrieveLabel();
#elif defined(Q_OS_LINUX)
- quint64 initRootPath();
void retrieveVolumeInfo();
public: