mirror of
https://github.com/Rockbox/rockbox.git
synced 2025-11-13 23:22:34 -05:00
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
This commit is contained in:
parent
f84602aa68
commit
5ce21366d7
3 changed files with 48 additions and 12 deletions
|
|
@ -42,7 +42,7 @@ bool Autodetection::detect()
|
||||||
detectUsb();
|
detectUsb();
|
||||||
|
|
||||||
// Try detection via rockbox.info / rbutil.log
|
// Try detection via rockbox.info / rbutil.log
|
||||||
QStringList mounts = Utils::mountpoints();
|
QStringList mounts = Utils::mountpoints(Utils::MountpointsSupported);
|
||||||
qDebug() << "[Autodetect] paths to check:" << mounts;
|
qDebug() << "[Autodetect] paths to check:" << mounts;
|
||||||
|
|
||||||
for(int i=0; i< mounts.size();i++)
|
for(int i=0; i< mounts.size();i++)
|
||||||
|
|
|
||||||
|
|
@ -568,39 +568,71 @@ QString Utils::resolveMountPoint(QString device)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
QStringList Utils::mountpoints()
|
QStringList Utils::mountpoints(enum MountpointsFilter type)
|
||||||
{
|
{
|
||||||
|
QStringList supported;
|
||||||
QStringList tempList;
|
QStringList tempList;
|
||||||
#if defined(Q_OS_WIN32)
|
#if defined(Q_OS_WIN32)
|
||||||
|
supported << "FAT32" << "FAT16" << "FAT12";
|
||||||
QFileInfoList list = QDir::drives();
|
QFileInfoList list = QDir::drives();
|
||||||
for(int i=0; i<list.size();i++)
|
for(int i=0; i<list.size();i++)
|
||||||
{
|
{
|
||||||
tempList << list.at(i).absolutePath();
|
wchar_t t[32];
|
||||||
qDebug() << "[Utils] Mounted on" << list.at(i).absolutePath();
|
memset(t, 0, 32);
|
||||||
|
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();
|
||||||
|
qDebug() << "[Utils] Added:" << list.at(i).absolutePath()
|
||||||
|
<< "type" << fstype;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
qDebug() << "[Utils] Ignored:" << list.at(i).absolutePath()
|
||||||
|
<< "type" << fstype;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#elif defined(Q_OS_MACX) || defined(Q_OS_OPENBSD)
|
#elif defined(Q_OS_MACX) || defined(Q_OS_OPENBSD)
|
||||||
|
supported << "vfat" << "msdos";
|
||||||
int num;
|
int num;
|
||||||
struct statfs *mntinf;
|
struct statfs *mntinf;
|
||||||
|
|
||||||
num = getmntinfo(&mntinf, MNT_WAIT);
|
num = getmntinfo(&mntinf, MNT_WAIT);
|
||||||
while(num--) {
|
while(num--) {
|
||||||
tempList << QString(mntinf->f_mntonname);
|
if(type == MountpointsAll || supported.contains(mntinf->f_fstypename)) {
|
||||||
qDebug() << "[Utils] Mounted on" << mntinf->f_mntonname
|
tempList << QString(mntinf->f_mntonname);
|
||||||
<< "is" << mntinf->f_mntfromname << "type" << mntinf->f_fstypename;
|
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++;
|
mntinf++;
|
||||||
}
|
}
|
||||||
#elif defined(Q_OS_LINUX)
|
#elif defined(Q_OS_LINUX)
|
||||||
|
supported << "vfat" << "msdos";
|
||||||
FILE *mn = setmntent("/etc/mtab", "r");
|
FILE *mn = setmntent("/etc/mtab", "r");
|
||||||
if(!mn)
|
if(!mn)
|
||||||
return QStringList("");
|
return QStringList("");
|
||||||
|
|
||||||
struct mntent *ent;
|
struct mntent *ent;
|
||||||
while((ent = getmntent(mn))) {
|
while((ent = getmntent(mn))) {
|
||||||
tempList << QString(ent->mnt_dir);
|
if(type == MountpointsAll || supported.contains(ent->mnt_type)) {
|
||||||
qDebug() << "[Utils] Mounted on" << ent->mnt_dir
|
tempList << QString(ent->mnt_dir);
|
||||||
<< "is" << ent->mnt_fsname << "type" << ent->mnt_type;
|
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);
|
endmntent(mn);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -35,6 +35,10 @@ public:
|
||||||
FilesystemFree,
|
FilesystemFree,
|
||||||
FilesystemClusterSize,
|
FilesystemClusterSize,
|
||||||
};
|
};
|
||||||
|
enum MountpointsFilter {
|
||||||
|
MountpointsAll,
|
||||||
|
MountpointsSupported,
|
||||||
|
};
|
||||||
|
|
||||||
static bool recursiveRmdir(const QString &dirName);
|
static bool recursiveRmdir(const QString &dirName);
|
||||||
static QString resolvePathCase(QString path);
|
static QString resolvePathCase(QString path);
|
||||||
|
|
@ -46,7 +50,7 @@ public:
|
||||||
static QString checkEnvironment(bool permission);
|
static QString checkEnvironment(bool permission);
|
||||||
static int compareVersionStrings(QString s1, QString s2);
|
static int compareVersionStrings(QString s1, QString s2);
|
||||||
static QString filesystemName(QString path);
|
static QString filesystemName(QString path);
|
||||||
static QStringList mountpoints(void);
|
static QStringList mountpoints(enum MountpointsFilter type = MountpointsAll);
|
||||||
static QString resolveDevicename(QString path);
|
static QString resolveDevicename(QString path);
|
||||||
static QString resolveMountPoint(QString device);
|
static QString resolveMountPoint(QString device);
|
||||||
static QStringList findRunningProcess(QStringList names);
|
static QStringList findRunningProcess(QStringList names);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue