1
0
Fork 0
forked from len0rd/rockbox

Add w32 mountpoint resolving based on disc number correctly this time.

git-svn-id: svn://svn.rockbox.org/rockbox/trunk@17873 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
Dominik Riebeling 2008-06-29 09:50:20 +00:00
parent 6f6fcfc3a8
commit 788d01ef7f
3 changed files with 44 additions and 53 deletions

View file

@ -39,8 +39,10 @@
#include <tchar.h> #include <tchar.h>
#include <windows.h> #include <windows.h>
#include <setupapi.h> #include <setupapi.h>
#include <winioctl.h>
#endif #endif
#include "detect.h" #include "detect.h"
#include "utils.h"
Autodetection::Autodetection(QObject* parent): QObject(parent) Autodetection::Autodetection(QObject* parent): QObject(parent)
{ {
@ -157,14 +159,12 @@ bool Autodetection::detect()
if(n == 1) { if(n == 1) {
qDebug() << "Ipod found:" << ipod.modelstr << "at" << ipod.diskname; qDebug() << "Ipod found:" << ipod.modelstr << "at" << ipod.diskname;
m_device = ipod.targetname; m_device = ipod.targetname;
#if !defined(Q_OS_WIN32)
m_mountpoint = resolveMountPoint(ipod.diskname); m_mountpoint = resolveMountPoint(ipod.diskname);
#endif
#if defined(Q_OS_WIN32)
m_mountpoint = getMountpointByDevice(ipod.diskname);
#endif
return true; return true;
} }
else {
qDebug() << "ipodpatcher: no Ipod found." << n;
}
//try sansapatcher //try sansapatcher
struct sansa_t sansa; struct sansa_t sansa;
@ -172,14 +172,12 @@ bool Autodetection::detect()
if(n == 1) { if(n == 1) {
qDebug() << "Sansa found:" << sansa.targetname << "at" << sansa.diskname; qDebug() << "Sansa found:" << sansa.targetname << "at" << sansa.diskname;
m_device = QString("sansa%1").arg(sansa.targetname); m_device = QString("sansa%1").arg(sansa.targetname);
#if !defined(Q_OS_WIN32)
m_mountpoint = resolveMountPoint(sansa.diskname); m_mountpoint = resolveMountPoint(sansa.diskname);
#endif
#if defined(Q_OS_WIN32)
m_mountpoint = getMountpointByDevice(sansa.diskname);
#endif
return true; return true;
} }
else {
qDebug() << "sansapatcher: no Sansa found." << n;
}
if(m_mountpoint.isEmpty() && m_device.isEmpty() && m_errdev.isEmpty() && m_incompat.isEmpty()) if(m_mountpoint.isEmpty() && m_device.isEmpty() && m_errdev.isEmpty() && m_incompat.isEmpty())
return false; return false;
@ -256,8 +254,43 @@ QString Autodetection::resolveMountPoint(QString device)
mntinf++; mntinf++;
} }
#endif #endif
return QString("");
#if defined(Q_OS_WIN32)
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;
}
// 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;
}
}
}
}
return result + ":/";
#endif
return QString("");
} }

View file

@ -99,41 +99,3 @@ QString resolvePathCase(QString path)
return realpath; return realpath;
} }
#if defined(Q_OS_WIN32)
QString getMountpointByDevice(int drive)
{
QString result;
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;
}
// get the extents
if(DeviceIoControl(h, IOCTL_VOLUME_GET_VOLUME_DISK_EXTENTS,
NULL, 0, extents, sizeof(buffer), &written, NULL)) {
for(int a = 0; a < extents->NumberOfDiskExtents; a++) {
qDebug() << "Disk:" << extents->Extents[a].DiskNumber;
if(extents->Extents[a].DiskNumber == drive) {
result = letter;
qDebug("found: %c", letter);
break;
}
}
}
}
return result;
}
#endif

View file

@ -29,9 +29,5 @@
bool recRmdir( const QString &dirName ); bool recRmdir( const QString &dirName );
QString resolvePathCase(QString path); QString resolvePathCase(QString path);
#if defined(Q_OS_WIN32)
QString getMountpointByDevice(int drive);
#endif
#endif #endif