From ddc39eb3a46d699c23d39f0e914978199eb98cc6 Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Thu, 19 Oct 2023 08:24:36 -0700 Subject: [PATCH] QStorageInfo/Linux: fix mountedVolumes() for paths mounted over This fixes a similar problem as the previous commit. Because Linux allows one to mount over non-empty paths, it's possible to make mountpoints unreachable, and yet they will still be present in the /proc/self/mountinfo listing. Because we have the device ID from the scan, we can confirm that the mountpoint matches the MountInfo. # mkdir -p /tmp/foo/bar # mount -t tmpfs /tmp/foo/bar # mount -t tmpfs -o size=1M /tmp/foo # mkdir /tmp/foo/bar $ ./tests/manual/qstorageinfo/qstorageinfo | awk 'NR==1 || /tmp\/foo/' Filesystem (Type) Size Available BSize Label Mounted on tmpfs RW 1024 1024 4096 /tmp/foo Change-Id: I79e700614d034281bf55fffd178f8b99b10a8b69 Reviewed-by: Ahmad Samir Reviewed-by: Edward Welbourne --- src/corelib/io/qstorageinfo_linux.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/corelib/io/qstorageinfo_linux.cpp b/src/corelib/io/qstorageinfo_linux.cpp index fab5a44fad..840cb845a5 100644 --- a/src/corelib/io/qstorageinfo_linux.cpp +++ b/src/corelib/io/qstorageinfo_linux.cpp @@ -178,6 +178,8 @@ QList QStorageInfoPrivate::mountedVolumes() d.retrieveVolumeInfo(); if (d.bytesTotal == 0 && d.rootPath != u'/') continue; + if (info.stDev != deviceIdForPath(d.rootPath)) + continue; // probably something mounted over this mountpoint d.name = retrieveLabel(d.device); volumes.emplace_back(QStorageInfo(*new QStorageInfoPrivate(std::move(d)))); }