summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--rbutil/rbutilqt/base/autodetection.cpp231
-rw-r--r--rbutil/rbutilqt/base/autodetection.h2
-rw-r--r--rbutil/rbutilqt/base/bootloaderinstallipod.cpp4
-rw-r--r--rbutil/rbutilqt/base/bootloaderinstallsansa.cpp4
-rw-r--r--rbutil/rbutilqt/base/utils.cpp222
-rw-r--r--rbutil/rbutilqt/base/utils.h3
-rw-r--r--rbutil/rbutilqt/configure.cpp2
-rw-r--r--rbutil/rbutilqt/sysinfo.cpp2
8 files changed, 230 insertions, 240 deletions
diff --git a/rbutil/rbutilqt/base/autodetection.cpp b/rbutil/rbutilqt/base/autodetection.cpp
index 2bd61ff5ba..1a78ae54a8 100644
--- a/rbutil/rbutilqt/base/autodetection.cpp
+++ b/rbutil/rbutilqt/base/autodetection.cpp
@@ -25,32 +25,6 @@
#include "../ipodpatcher/ipodpatcher.h"
#include "../sansapatcher/sansapatcher.h"
-#if defined(Q_OS_LINUX) || defined(Q_OS_MACX)
-#include <stdio.h>
-#endif
-#if defined(Q_OS_LINUX)
-#include <mntent.h>
-#endif
-#if defined(Q_OS_MACX)
-#include <sys/param.h>
-#include <sys/ucred.h>
-#include <sys/mount.h>
-#endif
-#if defined(Q_OS_WIN32)
-#if defined(UNICODE)
-#define _UNICODE
-#endif
-#include <stdio.h>
-#include <tchar.h>
-#include <windows.h>
-#include <setupapi.h>
-#include <winioctl.h>
-#endif
-
-#if defined(Q_OS_OPENBSD)
-#include <sys/param.h>
-#include <sys/mount.h>
-#endif
#include "system.h"
#include "utils.h"
@@ -69,7 +43,7 @@ bool Autodetection::detect()
detectUsb();
// Try detection via rockbox.info / rbutil.log
- QStringList mounts = mountpoints();
+ QStringList mounts = Utils::mountpoints();
for(int i=0; i< mounts.size();i++)
{
@@ -183,7 +157,7 @@ bool Autodetection::detect()
#ifdef Q_OS_MACX
mp.append("s2");
#endif
- m_mountpoint = resolveMountPoint(mp);
+ m_mountpoint = Utils::resolveMountPoint(mp);
return true;
}
else {
@@ -208,7 +182,7 @@ bool Autodetection::detect()
#ifdef Q_OS_MACX
mp.append("s1");
#endif
- m_mountpoint = resolveMountPoint(mp);
+ m_mountpoint = Utils::resolveMountPoint(mp);
return true;
}
else {
@@ -224,205 +198,6 @@ bool Autodetection::detect()
}
-QStringList Autodetection::mountpoints()
-{
- QStringList tempList;
-#if defined(Q_OS_WIN32)
- QFileInfoList list = QDir::drives();
- for(int i=0; i<list.size();i++)
- {
- tempList << list.at(i).absolutePath();
- qDebug() << "[Autodetection] Mounted on" << list.at(i).absolutePath();
- }
-
-#elif defined(Q_OS_MACX) || defined(Q_OS_OPENBSD)
- int num;
- struct statfs *mntinf;
-
- num = getmntinfo(&mntinf, MNT_WAIT);
- while(num--) {
- tempList << QString(mntinf->f_mntonname);
- qDebug() << "[Autodetection] Mounted on" << mntinf->f_mntonname
- << "is" << mntinf->f_mntfromname << "type" << mntinf->f_fstypename;
- mntinf++;
- }
-#elif defined(Q_OS_LINUX)
-
- FILE *mn = setmntent("/etc/mtab", "r");
- if(!mn)
- return QStringList("");
-
- struct mntent *ent;
- while((ent = getmntent(mn))) {
- tempList << QString(ent->mnt_dir);
- qDebug() << "[Autodetection] Mounted on" << ent->mnt_dir
- << "is" << ent->mnt_fsname << "type" << ent->mnt_type;
- }
- endmntent(mn);
-
-#else
-#error Unknown Platform
-#endif
- return tempList;
-}
-
-
-/** resolve device name to mount point / drive letter
- * @param device device name / disk number
- * @return mount point / drive letter
- */
-QString Autodetection::resolveMountPoint(QString device)
-{
- qDebug() << "[Autodetect] resolving mountpoint:" << device;
-
-#if defined(Q_OS_LINUX)
- FILE *mn = setmntent("/etc/mtab", "r");
- if(!mn)
- return QString("");
-
- struct mntent *ent;
- while((ent = getmntent(mn))) {
- // Check for valid filesystem. Allow hfs too, as an Ipod might be a
- // MacPod.
- if(QString(ent->mnt_fsname) == device) {
- QString result;
- if(QString(ent->mnt_type).contains("vfat", Qt::CaseInsensitive)
- || QString(ent->mnt_type).contains("hfs", Qt::CaseInsensitive)) {
- qDebug() << "[Autodetect] resolved mountpoint is:" << ent->mnt_dir;
- result = QString(ent->mnt_dir);
- }
- else {
- qDebug() << "[Autodetect] mountpoint is wrong filesystem!";
- }
- endmntent(mn);
- return result;
- }
- }
- endmntent(mn);
-
-#endif
-
-#if defined(Q_OS_MACX) || defined(Q_OS_OPENBSD)
- int num;
- struct statfs *mntinf;
-
- num = getmntinfo(&mntinf, MNT_WAIT);
- while(num--) {
- // Check for valid filesystem. Allow hfs too, as an Ipod might be a
- // MacPod.
- if(QString(mntinf->f_mntfromname) == device) {
- if(QString(mntinf->f_fstypename).contains("msdos", Qt::CaseInsensitive)
- || QString(mntinf->f_fstypename).contains("hfs", Qt::CaseInsensitive)) {
- qDebug() << "[Autodetect] resolved mountpoint is:" << mntinf->f_mntonname;
- return QString(mntinf->f_mntonname);
- }
- else {
- qDebug() << "[Autodetect] mountpoint is wrong filesystem!";
- return QString();
- }
- }
- mntinf++;
- }
-#endif
-
-#if defined(Q_OS_WIN32)
- QString result;
- unsigned int driveno = device.replace(QRegExp("^.*([0-9]+)"), "\\1").toInt();
-
- int letter;
- for(letter = 'A'; letter <= 'Z'; letter++) {
- if(resolveDevicename(QString(letter)).toUInt() == driveno) {
- result = letter;
- qDebug() << "[Autodetect] resolved mountpoint is:" << result;
- break;
- }
- }
- if(!result.isEmpty())
- return result + ":/";
-#endif
- qDebug() << "[Autodetect] resolving mountpoint failed!";
- return QString("");
-}
-
-
-/** Resolve mountpoint to devicename / disk number
- * @param path mountpoint path / drive letter
- * @return devicename / disk number
- */
-QString Autodetection::resolveDevicename(QString path)
-{
- qDebug() << "[Autodetect] resolving device name" << path;
-#if defined(Q_OS_LINUX)
- FILE *mn = setmntent("/etc/mtab", "r");
- if(!mn)
- return QString("");
-
- struct mntent *ent;
- while((ent = getmntent(mn))) {
- // check for valid filesystem type.
- // Linux can handle hfs (and hfsplus), so consider it a valid file
- // system. Otherwise resolving the device name would fail, which in
- // turn would make it impossible to warn about a MacPod.
- if(QString(ent->mnt_dir) == path
- && (QString(ent->mnt_type).contains("vfat", Qt::CaseInsensitive)
- || QString(ent->mnt_type).contains("hfs", Qt::CaseInsensitive))) {
- endmntent(mn);
- qDebug() << "[Autodetect] device name is" << ent->mnt_fsname;
- return QString(ent->mnt_fsname);
- }
- }
- endmntent(mn);
-
-#endif
-
-#if defined(Q_OS_MACX) || defined(Q_OS_OPENBSD)
- int num;
- struct statfs *mntinf;
-
- num = getmntinfo(&mntinf, MNT_WAIT);
- while(num--) {
- // check for valid filesystem type. OS X can handle hfs (hfs+ is
- // treated as hfs), BSD should be the same.
- if(QString(mntinf->f_mntonname) == path
- && (QString(mntinf->f_fstypename).contains("msdos", Qt::CaseInsensitive)
- || QString(mntinf->f_fstypename).contains("hfs", Qt::CaseInsensitive))) {
- qDebug() << "[Autodetect] device name is" << mntinf->f_mntfromname;
- return QString(mntinf->f_mntfromname);
- }
- mntinf++;
- }
-#endif
-
-#if defined(Q_OS_WIN32)
- DWORD written;
- HANDLE h;
- TCHAR uncpath[MAX_PATH];
- UCHAR buffer[0x400];
- PVOLUME_DISK_EXTENTS extents = (PVOLUME_DISK_EXTENTS)buffer;
-
- _stprintf(uncpath, _TEXT("\\\\.\\%c:"), path.toAscii().at(0));
- h = CreateFile(uncpath, GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE,
- NULL, OPEN_EXISTING, 0, NULL);
- if(h == INVALID_HANDLE_VALUE) {
- //qDebug() << "error getting extents for" << uncpath;
- return "";
- }
- // get the extents
- if(DeviceIoControl(h, IOCTL_VOLUME_GET_VOLUME_DISK_EXTENTS,
- NULL, 0, extents, sizeof(buffer), &written, NULL)) {
- if(extents->NumberOfDiskExtents > 1) {
- qDebug() << "[Autodetect] resolving device name: volume spans multiple disks!";
- return "";
- }
- qDebug() << "[Autodetect] device name is" << extents->Extents[0].DiskNumber;
- return QString("%1").arg(extents->Extents[0].DiskNumber);
- }
-#endif
- return QString("");
-
-}
-
-
/** @brief detect devices based on usb pid / vid.
* @return true upon success, false otherwise.
*/
diff --git a/rbutil/rbutilqt/base/autodetection.h b/rbutil/rbutilqt/base/autodetection.h
index c6b33ac313..6c98dc1998 100644
--- a/rbutil/rbutilqt/base/autodetection.h
+++ b/rbutil/rbutilqt/base/autodetection.h
@@ -38,8 +38,6 @@ public:
QString getMountPoint() {return m_mountpoint;}
QString errdev(void) { return m_errdev; }
QString incompatdev(void) { return m_incompat; }
- static QStringList mountpoints(void);
- static QString resolveDevicename(QString path);
private:
QString resolveMountPoint(QString);
diff --git a/rbutil/rbutilqt/base/bootloaderinstallipod.cpp b/rbutil/rbutilqt/base/bootloaderinstallipod.cpp
index 14f3fa5ddf..af25de4e29 100644
--- a/rbutil/rbutilqt/base/bootloaderinstallipod.cpp
+++ b/rbutil/rbutilqt/base/bootloaderinstallipod.cpp
@@ -22,7 +22,7 @@
#include "bootloaderinstallipod.h"
#include "../ipodpatcher/ipodpatcher.h"
-#include "autodetection.h"
+#include "utils.h"
BootloaderInstallIpod::BootloaderInstallIpod(QObject *parent)
@@ -226,7 +226,7 @@ BootloaderInstallBase::Capabilities BootloaderInstallIpod::capabilities(void)
bool BootloaderInstallIpod::ipodInitialize(struct ipod_t *ipod)
{
if(!m_blfile.isEmpty()) {
- QString devicename = Autodetection::resolveDevicename(m_blfile);
+ QString devicename = Utils::resolveDevicename(m_blfile);
if(devicename.isEmpty()) {
emit logItem(tr("Error: could not retrieve device name"), LOGERROR);
return false;
diff --git a/rbutil/rbutilqt/base/bootloaderinstallsansa.cpp b/rbutil/rbutilqt/base/bootloaderinstallsansa.cpp
index 0dc94c553c..05e7c96eea 100644
--- a/rbutil/rbutilqt/base/bootloaderinstallsansa.cpp
+++ b/rbutil/rbutilqt/base/bootloaderinstallsansa.cpp
@@ -22,7 +22,7 @@
#include "bootloaderinstallsansa.h"
#include "../sansapatcher/sansapatcher.h"
-#include "autodetection.h"
+#include "utils.h"
BootloaderInstallSansa::BootloaderInstallSansa(QObject *parent)
: BootloaderInstallBase(parent)
@@ -242,7 +242,7 @@ BootloaderInstallBase::BootloaderType BootloaderInstallSansa::installed(void)
bool BootloaderInstallSansa::sansaInitialize(struct sansa_t *sansa)
{
if(!m_blfile.isEmpty()) {
- QString devicename = Autodetection::resolveDevicename(m_blfile);
+ QString devicename = Utils::resolveDevicename(m_blfile);
if(devicename.isEmpty()) {
emit logItem(tr("Error: could not retrieve device name"), LOGERROR);
return false;
diff --git a/rbutil/rbutilqt/base/utils.cpp b/rbutil/rbutilqt/base/utils.cpp
index d52eba4250..721aecc044 100644
--- a/rbutil/rbutilqt/base/utils.cpp
+++ b/rbutil/rbutilqt/base/utils.cpp
@@ -32,14 +32,28 @@
#include <cstdlib>
#include <stdio.h>
+#if defined(Q_OS_LINUX) || defined(Q_OS_MACX)
+#include <sys/statvfs.h>
+#endif
+#if defined(Q_OS_LINUX) || defined(Q_OS_MACX)
+#include <stdio.h>
+#endif
+#if defined(Q_OS_LINUX)
+#include <mntent.h>
+#endif
+#if defined(Q_OS_MACX) || defined(Q_OS_OPENBSD)
+#include <sys/param.h>
+#include <sys/ucred.h>
+#include <sys/mount.h>
+#endif
#if defined(Q_OS_WIN32)
-#include <windows.h>
+#include <stdio.h>
#include <tchar.h>
+#include <windows.h>
+#include <setupapi.h>
#include <winioctl.h>
#endif
-#if defined(Q_OS_LINUX) || defined(Q_OS_MACX)
-#include <sys/statvfs.h>
-#endif
+
// recursive function to delete a dir with files
bool Utils::recursiveRmdir( const QString &dirName )
@@ -327,3 +341,203 @@ int Utils::compareVersionStrings(QString s1, QString s2)
return 0;
}
+
+/** Resolve mountpoint to devicename / disk number
+ * @param path mountpoint path / drive letter
+ * @return devicename / disk number
+ */
+QString Utils::resolveDevicename(QString path)
+{
+ qDebug() << "[Utils] resolving device name" << path;
+#if defined(Q_OS_LINUX)
+ FILE *mn = setmntent("/etc/mtab", "r");
+ if(!mn)
+ return QString("");
+
+ struct mntent *ent;
+ while((ent = getmntent(mn))) {
+ // check for valid filesystem type.
+ // Linux can handle hfs (and hfsplus), so consider it a valid file
+ // system. Otherwise resolving the device name would fail, which in
+ // turn would make it impossible to warn about a MacPod.
+ if(QString(ent->mnt_dir) == path
+ && (QString(ent->mnt_type).contains("vfat", Qt::CaseInsensitive)
+ || QString(ent->mnt_type).contains("hfs", Qt::CaseInsensitive))) {
+ endmntent(mn);
+ qDebug() << "[Utils] device name is" << ent->mnt_fsname;
+ return QString(ent->mnt_fsname);
+ }
+ }
+ endmntent(mn);
+
+#endif
+
+#if defined(Q_OS_MACX) || defined(Q_OS_OPENBSD)
+ int num;
+ struct statfs *mntinf;
+
+ num = getmntinfo(&mntinf, MNT_WAIT);
+ while(num--) {
+ // check for valid filesystem type. OS X can handle hfs (hfs+ is
+ // treated as hfs), BSD should be the same.
+ if(QString(mntinf->f_mntonname) == path
+ && (QString(mntinf->f_fstypename).contains("msdos", Qt::CaseInsensitive)
+ || QString(mntinf->f_fstypename).contains("hfs", Qt::CaseInsensitive))) {
+ qDebug() << "[Utils] device name is" << mntinf->f_mntfromname;
+ return QString(mntinf->f_mntfromname);
+ }
+ mntinf++;
+ }
+#endif
+
+#if defined(Q_OS_WIN32)
+ DWORD written;
+ HANDLE h;
+ TCHAR uncpath[MAX_PATH];
+ UCHAR buffer[0x400];
+ PVOLUME_DISK_EXTENTS extents = (PVOLUME_DISK_EXTENTS)buffer;
+
+ _stprintf(uncpath, _TEXT("\\\\.\\%c:"), path.toAscii().at(0));
+ h = CreateFile(uncpath, GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE,
+ NULL, OPEN_EXISTING, 0, NULL);
+ if(h == INVALID_HANDLE_VALUE) {
+ //qDebug() << "error getting extents for" << uncpath;
+ return "";
+ }
+ // get the extents
+ if(DeviceIoControl(h, IOCTL_VOLUME_GET_VOLUME_DISK_EXTENTS,
+ NULL, 0, extents, sizeof(buffer), &written, NULL)) {
+ if(extents->NumberOfDiskExtents > 1) {
+ qDebug() << "[Utils] resolving device name: volume spans multiple disks!";
+ return "";
+ }
+ qDebug() << "[Utils] device name is" << extents->Extents[0].DiskNumber;
+ return QString("%1").arg(extents->Extents[0].DiskNumber);
+ }
+#endif
+ return QString("");
+
+}
+
+
+/** resolve device name to mount point / drive letter
+ * @param device device name / disk number
+ * @return mount point / drive letter
+ */
+QString Utils::resolveMountPoint(QString device)
+{
+ qDebug() << "[Utils] resolving mountpoint:" << device;
+
+#if defined(Q_OS_LINUX)
+ FILE *mn = setmntent("/etc/mtab", "r");
+ if(!mn)
+ return QString("");
+
+ struct mntent *ent;
+ while((ent = getmntent(mn))) {
+ // Check for valid filesystem. Allow hfs too, as an Ipod might be a
+ // MacPod.
+ if(QString(ent->mnt_fsname) == device) {
+ QString result;
+ if(QString(ent->mnt_type).contains("vfat", Qt::CaseInsensitive)
+ || QString(ent->mnt_type).contains("hfs", Qt::CaseInsensitive)) {
+ qDebug() << "[Utils] resolved mountpoint is:" << ent->mnt_dir;
+ result = QString(ent->mnt_dir);
+ }
+ else {
+ qDebug() << "[Utils] mountpoint is wrong filesystem!";
+ }
+ endmntent(mn);
+ return result;
+ }
+ }
+ endmntent(mn);
+
+#endif
+
+#if defined(Q_OS_MACX) || defined(Q_OS_OPENBSD)
+ int num;
+ struct statfs *mntinf;
+
+ num = getmntinfo(&mntinf, MNT_WAIT);
+ while(num--) {
+ // Check for valid filesystem. Allow hfs too, as an Ipod might be a
+ // MacPod.
+ if(QString(mntinf->f_mntfromname) == device) {
+ if(QString(mntinf->f_fstypename).contains("msdos", Qt::CaseInsensitive)
+ || QString(mntinf->f_fstypename).contains("hfs", Qt::CaseInsensitive)) {
+ qDebug() << "[Utils] resolved mountpoint is:" << mntinf->f_mntonname;
+ return QString(mntinf->f_mntonname);
+ }
+ else {
+ qDebug() << "[Utils] mountpoint is wrong filesystem!";
+ return QString();
+ }
+ }
+ mntinf++;
+ }
+#endif
+
+#if defined(Q_OS_WIN32)
+ QString result;
+ unsigned int driveno = device.replace(QRegExp("^.*([0-9]+)"), "\\1").toInt();
+
+ int letter;
+ for(letter = 'A'; letter <= 'Z'; letter++) {
+ if(resolveDevicename(QString(letter)).toUInt() == driveno) {
+ result = letter;
+ qDebug() << "[Utils] resolved mountpoint is:" << result;
+ break;
+ }
+ }
+ if(!result.isEmpty())
+ return result + ":/";
+#endif
+ qDebug() << "[Utils] resolving mountpoint failed!";
+ return QString("");
+}
+
+
+QStringList Utils::mountpoints()
+{
+ QStringList tempList;
+#if defined(Q_OS_WIN32)
+ QFileInfoList list = QDir::drives();
+ for(int i=0; i<list.size();i++)
+ {
+ tempList << list.at(i).absolutePath();
+ qDebug() << "[Utils] Mounted on" << list.at(i).absolutePath();
+ }
+
+#elif defined(Q_OS_MACX) || defined(Q_OS_OPENBSD)
+ int num;
+ struct statfs *mntinf;
+
+ num = getmntinfo(&mntinf, MNT_WAIT);
+ while(num--) {
+ tempList << QString(mntinf->f_mntonname);
+ qDebug() << "[Utils] Mounted on" << mntinf->f_mntonname
+ << "is" << mntinf->f_mntfromname << "type" << mntinf->f_fstypename;
+ mntinf++;
+ }
+#elif defined(Q_OS_LINUX)
+
+ 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;
+ }
+ endmntent(mn);
+
+#else
+#error Unknown Platform
+#endif
+ return tempList;
+}
+
+
diff --git a/rbutil/rbutilqt/base/utils.h b/rbutil/rbutilqt/base/utils.h
index 20ac36eec1..659bbc4ed4 100644
--- a/rbutil/rbutilqt/base/utils.h
+++ b/rbutil/rbutilqt/base/utils.h
@@ -45,6 +45,9 @@ public:
static QString checkEnvironment(bool permission);
static int compareVersionStrings(QString s1, QString s2);
static QString filesystemName(QString path);
+ static QStringList mountpoints(void);
+ static QString resolveDevicename(QString path);
+ static QString resolveMountPoint(QString device);
};
#endif
diff --git a/rbutil/rbutilqt/configure.cpp b/rbutil/rbutilqt/configure.cpp
index 7dfd325255..9e1978974f 100644
--- a/rbutil/rbutilqt/configure.cpp
+++ b/rbutil/rbutilqt/configure.cpp
@@ -587,7 +587,7 @@ void Config::refreshMountpoint()
// unwanted item.
ui.mountPoint->blockSignals(true);
ui.mountPoint->clear();
- QStringList mps = Autodetection::mountpoints();
+ QStringList mps = Utils::mountpoints();
for(int i = 0; i < mps.size(); ++i) {
// add mountpoint as user data so we can change the displayed string
// later (to include volume label or similar)
diff --git a/rbutil/rbutilqt/sysinfo.cpp b/rbutil/rbutilqt/sysinfo.cpp
index 0217c22a3e..bd3f7b2e7f 100644
--- a/rbutil/rbutilqt/sysinfo.cpp
+++ b/rbutil/rbutilqt/sysinfo.cpp
@@ -61,7 +61,7 @@ QString Sysinfo::getInfo()
info += "<hr/>";
info += "<b>" + tr("Filesystem") + "</b><br/>";
- QStringList drives = Autodetection::mountpoints();
+ QStringList drives = Utils::mountpoints();
for(int i = 0; i < drives.size(); i++) {
info += tr("%1, %4 %2 GiB of %3 GiB available")
.arg(QDir::toNativeSeparators(drives.at(i)))