From 5ce21366d799c92e1f01abde9d42e0959622c628 Mon Sep 17 00:00:00 2001 From: Dominik Riebeling Date: Mon, 1 Apr 2013 20:37:13 +0200 Subject: [PATCH] Extend Utils::mountpoints() to allow filtering for supported types. Instead of trying every mountpoint during autodetection allow filtering out filesystems that are not supported when retrieving the system mountpoints. Change-Id: Ic23a5c804cb7c78c146dbc1af7443c67ce12464e --- rbutil/rbutilqt/base/autodetection.cpp | 2 +- rbutil/rbutilqt/base/utils.cpp | 52 +++++++++++++++++++++----- rbutil/rbutilqt/base/utils.h | 6 ++- 3 files changed, 48 insertions(+), 12 deletions(-) diff --git a/rbutil/rbutilqt/base/autodetection.cpp b/rbutil/rbutilqt/base/autodetection.cpp index 4144cca19d..fa2fe63cb8 100644 --- a/rbutil/rbutilqt/base/autodetection.cpp +++ b/rbutil/rbutilqt/base/autodetection.cpp @@ -42,7 +42,7 @@ bool Autodetection::detect() detectUsb(); // Try detection via rockbox.info / rbutil.log - QStringList mounts = Utils::mountpoints(); + QStringList mounts = Utils::mountpoints(Utils::MountpointsSupported); qDebug() << "[Autodetect] paths to check:" << mounts; for(int i=0; i< mounts.size();i++) diff --git a/rbutil/rbutilqt/base/utils.cpp b/rbutil/rbutilqt/base/utils.cpp index 3a19397efb..92eacbe313 100644 --- a/rbutil/rbutilqt/base/utils.cpp +++ b/rbutil/rbutilqt/base/utils.cpp @@ -568,39 +568,71 @@ QString Utils::resolveMountPoint(QString device) } -QStringList Utils::mountpoints() +QStringList Utils::mountpoints(enum MountpointsFilter type) { + QStringList supported; QStringList tempList; #if defined(Q_OS_WIN32) + supported << "FAT32" << "FAT16" << "FAT12"; QFileInfoList list = QDir::drives(); for(int i=0; if_mntonname); - qDebug() << "[Utils] Mounted on" << mntinf->f_mntonname - << "is" << mntinf->f_mntfromname << "type" << mntinf->f_fstypename; + if(type == MountpointsAll || supported.contains(mntinf->f_fstypename)) { + tempList << QString(mntinf->f_mntonname); + qDebug() << "[Utils] Added:" << mntinf->f_mntonname + << "is" << mntinf->f_mntfromname << "type" << mntinf->f_fstypename; + } + else { + qDebug() << "[Utils] Ignored:" << mntinf->f_mntonname + << "is" << mntinf->f_mntfromname << "type" << mntinf->f_fstypename; + } mntinf++; } #elif defined(Q_OS_LINUX) - + supported << "vfat" << "msdos"; FILE *mn = setmntent("/etc/mtab", "r"); if(!mn) return QStringList(""); struct mntent *ent; while((ent = getmntent(mn))) { - tempList << QString(ent->mnt_dir); - qDebug() << "[Utils] Mounted on" << ent->mnt_dir - << "is" << ent->mnt_fsname << "type" << ent->mnt_type; + if(type == MountpointsAll || supported.contains(ent->mnt_type)) { + tempList << QString(ent->mnt_dir); + qDebug() << "[Utils] Added:" << ent->mnt_dir + << "is" << ent->mnt_fsname << "type" << ent->mnt_type; + } + else { + qDebug() << "[Utils] Ignored:" << ent->mnt_dir + << "is" << ent->mnt_fsname << "type" << ent->mnt_type; + } } endmntent(mn); diff --git a/rbutil/rbutilqt/base/utils.h b/rbutil/rbutilqt/base/utils.h index db52bfb4e9..9905341ad1 100644 --- a/rbutil/rbutilqt/base/utils.h +++ b/rbutil/rbutilqt/base/utils.h @@ -35,6 +35,10 @@ public: FilesystemFree, FilesystemClusterSize, }; + enum MountpointsFilter { + MountpointsAll, + MountpointsSupported, + }; static bool recursiveRmdir(const QString &dirName); static QString resolvePathCase(QString path); @@ -46,7 +50,7 @@ public: static QString checkEnvironment(bool permission); static int compareVersionStrings(QString s1, QString s2); static QString filesystemName(QString path); - static QStringList mountpoints(void); + static QStringList mountpoints(enum MountpointsFilter type = MountpointsAll); static QString resolveDevicename(QString path); static QString resolveMountPoint(QString device); static QStringList findRunningProcess(QStringList names);