summaryrefslogtreecommitdiffstats
path: root/rbutil/rbutilqt/base/autodetection.cpp
diff options
context:
space:
mode:
authorDominik Riebeling <Dominik.Riebeling@gmail.com>2009-04-30 19:14:24 +0000
committerDominik Riebeling <Dominik.Riebeling@gmail.com>2009-04-30 19:14:24 +0000
commitf679cf91cf94363d10f99db5cbae872401ed5612 (patch)
tree8925a97c85a19c19a7979b464d0529dbd30dd430 /rbutil/rbutilqt/base/autodetection.cpp
parent549fc95b8d0f9ecfb6c18ad6c9a75503458e645d (diff)
downloadrockbox-f679cf91cf94363d10f99db5cbae872401ed5612.tar.gz
rockbox-f679cf91cf94363d10f99db5cbae872401ed5612.tar.bz2
rockbox-f679cf91cf94363d10f99db5cbae872401ed5612.zip
Bootloader installation for ipod and sansa: override the scanning with the device pointed to by the mountpoint. This allows selecting the correct player if two of the same brand are connected (FS#10096).
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@20832 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'rbutil/rbutilqt/base/autodetection.cpp')
-rw-r--r--rbutil/rbutilqt/base/autodetection.cpp115
1 files changed, 89 insertions, 26 deletions
diff --git a/rbutil/rbutilqt/base/autodetection.cpp b/rbutil/rbutilqt/base/autodetection.cpp
index ee42a8c09e..276c270499 100644
--- a/rbutil/rbutilqt/base/autodetection.cpp
+++ b/rbutil/rbutilqt/base/autodetection.cpp
@@ -238,6 +238,11 @@ QStringList Autodetection::mountpoints()
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() << "Autodetection::resolveMountPoint(QString)" << device;
@@ -289,39 +294,97 @@ QString Autodetection::resolveMountPoint(QString device)
QString result;
unsigned int driveno = device.replace(QRegExp("^.*([0-9]+)"), "\\1").toInt();
- for(int letter = 'A'; letter <= 'Z'; letter++) {
- DWORD written;
- HANDLE h;
- TCHAR uncpath[MAX_PATH];
- UCHAR buffer[0x400];
- PVOLUME_DISK_EXTENTS extents = (PVOLUME_DISK_EXTENTS)buffer;
-
- _stprintf(uncpath, _TEXT("\\\\.\\%c:"), letter);
- 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;
- continue;
+ int letter;
+ for(letter = 'A'; letter <= 'Z'; letter++) {
+ if(resolveDevicename(QString(letter)).toUInt() == driveno) {
+ result = letter;
+ break;
}
- // get the extents
- if(DeviceIoControl(h, IOCTL_VOLUME_GET_VOLUME_DISK_EXTENTS,
- NULL, 0, extents, sizeof(buffer), &written, NULL)) {
- for(unsigned int a = 0; a < extents->NumberOfDiskExtents; a++) {
- qDebug() << "Disk:" << extents->Extents[a].DiskNumber;
- if(extents->Extents[a].DiskNumber == driveno) {
- result = letter;
- qDebug("drive found for volume %i: %c", driveno, letter);
- break;
- }
- }
+ }
+ qDebug() << "Autodetection::resolveMountPoint(QString)" << "->" << result;
+ if(!result.isEmpty())
+ return result + ":/";
+#endif
+ return QString("");
+}
+
+/** Resolve mountpoint to devicename / disk number
+ * @param path mountpoint path / drive letter
+ * @return devicename / disk number
+ */
+QString Autodetection::resolveDevicename(QString path)
+{
+ qDebug() << __func__;
+#if defined(Q_OS_LINUX)
+ FILE *mn = setmntent("/etc/mtab", "r");
+ if(!mn)
+ return QString("");
+
+ struct mntent *ent;
+ while((ent = getmntent(mn))) {
+ if(QString(ent->mnt_dir).startsWith(path)
+ && QString(ent->mnt_type).contains("vfat", Qt::CaseInsensitive)) {
+ endmntent(mn);
+ return QString(ent->mnt_fsname);
}
+ }
+ endmntent(mn);
+
+#endif
+#if defined(Q_OS_MACX)
+ int num;
+ struct statfs *mntinf;
+
+ num = getmntinfo(&mntinf, MNT_WAIT);
+ while(num--) {
+ if(QString(mntinf->f_mntonname).startsWith(path)
+ && QString(mntinf->f_fstypename).contains("vfat", Qt::CaseInsensitive))
+ return QString(mntinf->f_mntfromname);
+ mntinf++;
+ }
+#endif
+
+#if defined(Q_OS_OPENBSD)
+ int num;
+ struct statfs *mntinf;
+
+ num = getmntinfo(&mntinf, MNT_WAIT);
+ while(num--) {
+ if(QString(mntinf->f_mntonname).startsWith(device)
+ && QString(mntinf->f_fstypename).contains("msdos", Qt::CaseInsensitive))
+ 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() << "volume spans multiple disks!";
+ return "";
+ }
+ //qDebug() << "Disk:" << extents->Extents[0].DiskNumber;
+ return QString("%1").arg(extents->Extents[0].DiskNumber);
}
- if(!result.isEmpty())
- return result + ":/";
#endif
return QString("");
+
}