From 26f24693cd5c357ba3654423f902a0871396ab89 Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Wed, 17 Jan 2024 11:52:59 -0800 Subject: [PATCH] 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. Change-Id: I76ffba14ece04f24b43efffd17ab3a79e54e636d Reviewed-by: Ahmad Samir Reviewed-by: Edward Welbourne (cherry picked from commit 96e5d0d5c19c09a2b0db5bd067deac06232a48ed) --- src/corelib/io/qstorageinfo_linux.cpp | 32 +++++++-------------------- src/corelib/io/qstorageinfo_p.h | 1 - 2 files changed, 8 insertions(+), 25 deletions(-) diff --git a/src/corelib/io/qstorageinfo_linux.cpp b/src/corelib/io/qstorageinfo_linux.cpp index 8d8751db6a2..9cd6a8da5a8 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 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 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 QStorageInfoPrivate::mountedVolumes() diff --git a/src/corelib/io/qstorageinfo_p.h b/src/corelib/io/qstorageinfo_p.h index 20f80ac0d13..3af4b81ca4b 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: