rbutilqt: Simplify Utils::mountpoints() using QStorageInfo

rockbox-gerrit-noreply--- via rockbox-cvs <[email protected]> Tue, 7 Jul 2026 22:58:23 -0400
Newsgroups gmane.comp.systems.archos.rockbox.cvs
Message-ID <[email protected]>
commit 3967180c6217c9a0ca3f6ff805ab71ca22575e77
Author: Vencislav Atanasov <[email protected]>
Date:   Wed Jul 8 00:11:34 2026 +0300

    rbutilqt: Simplify Utils::mountpoints() using QStorageInfo
    
    Co-authored-by: Qwen3.7-Plus
    Change-Id: I5832963d1a176754315dc28ffab75fa0a06f0334

diff --git a/utils/rbutilqt/base/utils.cpp b/utils/rbutilqt/base/utils.cpp
index 297c78207e..8a88a5db0e 100644
--- a/utils/rbutilqt/base/utils.cpp
+++ b/utils/rbutilqt/base/utils.cpp
@@ -512,75 +512,36 @@ QString Utils::resolveMountPoint(QString device)
 QStringList Utils::mountpoints(enum MountpointsFilter type)
 {
     QStringList supported;
-    QStringList tempList;
-#if defined(Q_OS_WIN32)
-    supported << "FAT32" << "FAT16" << "FAT12" << "FAT" << "HFS";
-    QFileInfoList list = QDir::drives();
-    for(int i=0; i<list.size();i++)
-    {
-        wchar_t t[32];
-        memset(t, 0, sizeof(t));
-        if(GetVolumeInformationW((LPCWSTR)list.at(i).absolutePath().utf16(),
-                NULL, 0, NULL, NULL, NULL, t, 32) == 0) {
-            // on error empty retrieved type -- don't rely on
-            // GetVolumeInformation not changing it.
-            memset(t, 0, sizeof(t));
-        }
-
-        QString fstype = QString::fromWCharArray(t);
-        if(type == MountpointsAll || supported.contains(fstype)) {
-            tempList << list.at(i).absolutePath();
-            LOG_INFO() << "Added:" << list.at(i).absolutePath()
-                     << "type" << fstype;
-        }
-        else {
-            LOG_INFO() << "Ignored:" << list.at(i).absolutePath()
-                     << "type" << fstype;
-        }
-    }
+    QStringList paths;
 
+    // Note: QStorageInfo::fileSystemType() result is platform-dependant!
+#if defined(Q_OS_WIN32)
+    supported = {"FAT32", "FAT16", "FAT12", "FAT", "HFS"};
 #elif defined(Q_OS_MACOS) || defined(Q_OS_OPENBSD)
-    supported << "vfat" << "msdos" << "hfs";
-    int num;
-    struct statfs *mntinf;
-
-    num = getmntinfo(&mntinf, MNT_WAIT);
-    while(num--) {
-        if(type == MountpointsAll || supported.contains(mntinf->f_fstypename)) {
-            tempList << QString(mntinf->f_mntonname);
-            LOG_INFO() << "Added:" << mntinf->f_mntonname
-                     << "is" << mntinf->f_mntfromname << "type" << mntinf->f_fstypename;
-        }
-        else {
-            LOG_INFO() << "Ignored:" << mntinf->f_mntonname
-                     << "is" << mntinf->f_mntfromname << "type" << mntinf->f_fstypename;
-        }
-        mntinf++;
-    }
+    supported = {"vfat", "msdos", "hfs"}; // vfat might not be needed
 #elif defined(Q_OS_LINUX)
-    supported << "vfat" << "msdos" << "hfsplus";
-    FILE *mn = setmntent("/etc/mtab", "r");
-    if(!mn)
-        return QStringList("");
+    supported = {"vfat", "msdos", "hfsplus"}; // hfs might be needed, too
+#else
+#error Unknown Platform
+#endif
 
-    struct mntent *ent;
-    while((ent = getmntent(mn))) {
-        if(type == MountpointsAll || supported.contains(ent->mnt_type)) {
-            tempList << QString(ent->mnt_dir);
-            LOG_INFO() << "Added:" << ent->mnt_dir
-                     << "is" << ent->mnt_fsname << "type" << ent->mnt_type;
+    for (const QStorageInfo &storage : QStorageInfo::mountedVolumes()) {
+        if (!storage.isValid() || storage.isReadOnly()) {
+            continue;
         }
-        else {
-            LOG_INFO() << "Ignored:" << ent->mnt_dir
-                     << "is" << ent->mnt_fsname << "type" << ent->mnt_type;
+
+        QString fsType = QString::fromLocal8Bit(storage.fileSystemType());
+        QString rootPath = storage.rootPath();
+
+        if (type == MountpointsAll || supported.contains(fsType, Qt::CaseInsensitive)) {
+            paths << rootPath;
+            LOG_INFO() << "Added:" << rootPath << "type" << fsType;
+        } else {
+            LOG_INFO() << "Ignored:" << rootPath << "type" << fsType;
         }
     }
-    endmntent(mn);
 
-#else
-#error Unknown Platform
-#endif
-    return tempList;
+    return paths;
 }
 
 
-- 
rockbox-cvs mailing list
[email protected]
https://lists.haxx.se/mailman/listinfo/rockbox-cvs