diff options
Diffstat (limited to 'rbutil')
-rw-r--r-- | rbutil/rbutilqt/base/autodetection.cpp | 231 | ||||
-rw-r--r-- | rbutil/rbutilqt/base/autodetection.h | 2 | ||||
-rw-r--r-- | rbutil/rbutilqt/base/bootloaderinstallipod.cpp | 4 | ||||
-rw-r--r-- | rbutil/rbutilqt/base/bootloaderinstallsansa.cpp | 4 | ||||
-rw-r--r-- | rbutil/rbutilqt/base/utils.cpp | 222 | ||||
-rw-r--r-- | rbutil/rbutilqt/base/utils.h | 3 | ||||
-rw-r--r-- | rbutil/rbutilqt/configure.cpp | 2 | ||||
-rw-r--r-- | rbutil/rbutilqt/sysinfo.cpp | 2 |
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 @@ | |||
25 | #include "../ipodpatcher/ipodpatcher.h" | 25 | #include "../ipodpatcher/ipodpatcher.h" |
26 | #include "../sansapatcher/sansapatcher.h" | 26 | #include "../sansapatcher/sansapatcher.h" |
27 | 27 | ||
28 | #if defined(Q_OS_LINUX) || defined(Q_OS_MACX) | ||
29 | #include <stdio.h> | ||
30 | #endif | ||
31 | #if defined(Q_OS_LINUX) | ||
32 | #include <mntent.h> | ||
33 | #endif | ||
34 | #if defined(Q_OS_MACX) | ||
35 | #include <sys/param.h> | ||
36 | #include <sys/ucred.h> | ||
37 | #include <sys/mount.h> | ||
38 | #endif | ||
39 | #if defined(Q_OS_WIN32) | ||
40 | #if defined(UNICODE) | ||
41 | #define _UNICODE | ||
42 | #endif | ||
43 | #include <stdio.h> | ||
44 | #include <tchar.h> | ||
45 | #include <windows.h> | ||
46 | #include <setupapi.h> | ||
47 | #include <winioctl.h> | ||
48 | #endif | ||
49 | |||
50 | #if defined(Q_OS_OPENBSD) | ||
51 | #include <sys/param.h> | ||
52 | #include <sys/mount.h> | ||
53 | #endif | ||
54 | 28 | ||
55 | #include "system.h" | 29 | #include "system.h" |
56 | #include "utils.h" | 30 | #include "utils.h" |
@@ -69,7 +43,7 @@ bool Autodetection::detect() | |||
69 | detectUsb(); | 43 | detectUsb(); |
70 | 44 | ||
71 | // Try detection via rockbox.info / rbutil.log | 45 | // Try detection via rockbox.info / rbutil.log |
72 | QStringList mounts = mountpoints(); | 46 | QStringList mounts = Utils::mountpoints(); |
73 | 47 | ||
74 | for(int i=0; i< mounts.size();i++) | 48 | for(int i=0; i< mounts.size();i++) |
75 | { | 49 | { |
@@ -183,7 +157,7 @@ bool Autodetection::detect() | |||
183 | #ifdef Q_OS_MACX | 157 | #ifdef Q_OS_MACX |
184 | mp.append("s2"); | 158 | mp.append("s2"); |
185 | #endif | 159 | #endif |
186 | m_mountpoint = resolveMountPoint(mp); | 160 | m_mountpoint = Utils::resolveMountPoint(mp); |
187 | return true; | 161 | return true; |
188 | } | 162 | } |
189 | else { | 163 | else { |
@@ -208,7 +182,7 @@ bool Autodetection::detect() | |||
208 | #ifdef Q_OS_MACX | 182 | #ifdef Q_OS_MACX |
209 | mp.append("s1"); | 183 | mp.append("s1"); |
210 | #endif | 184 | #endif |
211 | m_mountpoint = resolveMountPoint(mp); | 185 | m_mountpoint = Utils::resolveMountPoint(mp); |
212 | return true; | 186 | return true; |
213 | } | 187 | } |
214 | else { | 188 | else { |
@@ -224,205 +198,6 @@ bool Autodetection::detect() | |||
224 | } | 198 | } |
225 | 199 | ||
226 | 200 | ||
227 | QStringList Autodetection::mountpoints() | ||
228 | { | ||
229 | QStringList tempList; | ||
230 | #if defined(Q_OS_WIN32) | ||
231 | QFileInfoList list = QDir::drives(); | ||
232 | for(int i=0; i<list.size();i++) | ||
233 | { | ||
234 | tempList << list.at(i).absolutePath(); | ||
235 | qDebug() << "[Autodetection] Mounted on" << list.at(i).absolutePath(); | ||
236 | } | ||
237 | |||
238 | #elif defined(Q_OS_MACX) || defined(Q_OS_OPENBSD) | ||
239 | int num; | ||
240 | struct statfs *mntinf; | ||
241 | |||
242 | num = getmntinfo(&mntinf, MNT_WAIT); | ||
243 | while(num--) { | ||
244 | tempList << QString(mntinf->f_mntonname); | ||
245 | qDebug() << "[Autodetection] Mounted on" << mntinf->f_mntonname | ||
246 | << "is" << mntinf->f_mntfromname << "type" << mntinf->f_fstypename; | ||
247 | mntinf++; | ||
248 | } | ||
249 | #elif defined(Q_OS_LINUX) | ||
250 | |||
251 | FILE *mn = setmntent("/etc/mtab", "r"); | ||
252 | if(!mn) | ||
253 | return QStringList(""); | ||
254 | |||
255 | struct mntent *ent; | ||
256 | while((ent = getmntent(mn))) { | ||
257 | tempList << QString(ent->mnt_dir); | ||
258 | qDebug() << "[Autodetection] Mounted on" << ent->mnt_dir | ||
259 | << "is" << ent->mnt_fsname << "type" << ent->mnt_type; | ||
260 | } | ||
261 | endmntent(mn); | ||
262 | |||
263 | #else | ||
264 | #error Unknown Platform | ||
265 | #endif | ||
266 | return tempList; | ||
267 | } | ||
268 | |||
269 | |||
270 | /** resolve device name to mount point / drive letter | ||
271 | * @param device device name / disk number | ||
272 | * @return mount point / drive letter | ||
273 | */ | ||
274 | QString Autodetection::resolveMountPoint(QString device) | ||
275 | { | ||
276 | qDebug() << "[Autodetect] resolving mountpoint:" << device; | ||
277 | |||
278 | #if defined(Q_OS_LINUX) | ||
279 | FILE *mn = setmntent("/etc/mtab", "r"); | ||
280 | if(!mn) | ||
281 | return QString(""); | ||
282 | |||
283 | struct mntent *ent; | ||
284 | while((ent = getmntent(mn))) { | ||
285 | // Check for valid filesystem. Allow hfs too, as an Ipod might be a | ||
286 | // MacPod. | ||
287 | if(QString(ent->mnt_fsname) == device) { | ||
288 | QString result; | ||
289 | if(QString(ent->mnt_type).contains("vfat", Qt::CaseInsensitive) | ||
290 | || QString(ent->mnt_type).contains("hfs", Qt::CaseInsensitive)) { | ||
291 | qDebug() << "[Autodetect] resolved mountpoint is:" << ent->mnt_dir; | ||
292 | result = QString(ent->mnt_dir); | ||
293 | } | ||
294 | else { | ||
295 | qDebug() << "[Autodetect] mountpoint is wrong filesystem!"; | ||
296 | } | ||
297 | endmntent(mn); | ||
298 | return result; | ||
299 | } | ||
300 | } | ||
301 | endmntent(mn); | ||
302 | |||
303 | #endif | ||
304 | |||
305 | #if defined(Q_OS_MACX) || defined(Q_OS_OPENBSD) | ||
306 | int num; | ||
307 | struct statfs *mntinf; | ||
308 | |||
309 | num = getmntinfo(&mntinf, MNT_WAIT); | ||
310 | while(num--) { | ||
311 | // Check for valid filesystem. Allow hfs too, as an Ipod might be a | ||
312 | // MacPod. | ||
313 | if(QString(mntinf->f_mntfromname) == device) { | ||
314 | if(QString(mntinf->f_fstypename).contains("msdos", Qt::CaseInsensitive) | ||
315 | || QString(mntinf->f_fstypename).contains("hfs", Qt::CaseInsensitive)) { | ||
316 | qDebug() << "[Autodetect] resolved mountpoint is:" << mntinf->f_mntonname; | ||
317 | return QString(mntinf->f_mntonname); | ||
318 | } | ||
319 | else { | ||
320 | qDebug() << "[Autodetect] mountpoint is wrong filesystem!"; | ||
321 | return QString(); | ||
322 | } | ||
323 | } | ||
324 | mntinf++; | ||
325 | } | ||
326 | #endif | ||
327 | |||
328 | #if defined(Q_OS_WIN32) | ||
329 | QString result; | ||
330 | unsigned int driveno = device.replace(QRegExp("^.*([0-9]+)"), "\\1").toInt(); | ||
331 | |||
332 | int letter; | ||
333 | for(letter = 'A'; letter <= 'Z'; letter++) { | ||
334 | if(resolveDevicename(QString(letter)).toUInt() == driveno) { | ||
335 | result = letter; | ||
336 | qDebug() << "[Autodetect] resolved mountpoint is:" << result; | ||
337 | break; | ||
338 | } | ||
339 | } | ||
340 | if(!result.isEmpty()) | ||
341 | return result + ":/"; | ||
342 | #endif | ||
343 | qDebug() << "[Autodetect] resolving mountpoint failed!"; | ||
344 | return QString(""); | ||
345 | } | ||
346 | |||
347 | |||
348 | /** Resolve mountpoint to devicename / disk number | ||
349 | * @param path mountpoint path / drive letter | ||
350 | * @return devicename / disk number | ||
351 | */ | ||
352 | QString Autodetection::resolveDevicename(QString path) | ||
353 | { | ||
354 | qDebug() << "[Autodetect] resolving device name" << path; | ||
355 | #if defined(Q_OS_LINUX) | ||
356 | FILE *mn = setmntent("/etc/mtab", "r"); | ||
357 | if(!mn) | ||
358 | return QString(""); | ||
359 | |||
360 | struct mntent *ent; | ||
361 | while((ent = getmntent(mn))) { | ||
362 | // check for valid filesystem type. | ||
363 | // Linux can handle hfs (and hfsplus), so consider it a valid file | ||
364 | // system. Otherwise resolving the device name would fail, which in | ||
365 | // turn would make it impossible to warn about a MacPod. | ||
366 | if(QString(ent->mnt_dir) == path | ||
367 | && (QString(ent->mnt_type).contains("vfat", Qt::CaseInsensitive) | ||
368 | || QString(ent->mnt_type).contains("hfs", Qt::CaseInsensitive))) { | ||
369 | endmntent(mn); | ||
370 | qDebug() << "[Autodetect] device name is" << ent->mnt_fsname; | ||
371 | return QString(ent->mnt_fsname); | ||
372 | } | ||
373 | } | ||
374 | endmntent(mn); | ||
375 | |||
376 | #endif | ||
377 | |||
378 | #if defined(Q_OS_MACX) || defined(Q_OS_OPENBSD) | ||
379 | int num; | ||
380 | struct statfs *mntinf; | ||
381 | |||
382 | num = getmntinfo(&mntinf, MNT_WAIT); | ||
383 | while(num--) { | ||
384 | // check for valid filesystem type. OS X can handle hfs (hfs+ is | ||
385 | // treated as hfs), BSD should be the same. | ||
386 | if(QString(mntinf->f_mntonname) == path | ||
387 | && (QString(mntinf->f_fstypename).contains("msdos", Qt::CaseInsensitive) | ||
388 | || QString(mntinf->f_fstypename).contains("hfs", Qt::CaseInsensitive))) { | ||
389 | qDebug() << "[Autodetect] device name is" << mntinf->f_mntfromname; | ||
390 | return QString(mntinf->f_mntfromname); | ||
391 | } | ||
392 | mntinf++; | ||
393 | } | ||
394 | #endif | ||
395 | |||
396 | #if defined(Q_OS_WIN32) | ||
397 | DWORD written; | ||
398 | HANDLE h; | ||
399 | TCHAR uncpath[MAX_PATH]; | ||
400 | UCHAR buffer[0x400]; | ||
401 | PVOLUME_DISK_EXTENTS extents = (PVOLUME_DISK_EXTENTS)buffer; | ||
402 | |||
403 | _stprintf(uncpath, _TEXT("\\\\.\\%c:"), path.toAscii().at(0)); | ||
404 | h = CreateFile(uncpath, GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, | ||
405 | NULL, OPEN_EXISTING, 0, NULL); | ||
406 | if(h == INVALID_HANDLE_VALUE) { | ||
407 | //qDebug() << "error getting extents for" << uncpath; | ||
408 | return ""; | ||
409 | } | ||
410 | // get the extents | ||
411 | if(DeviceIoControl(h, IOCTL_VOLUME_GET_VOLUME_DISK_EXTENTS, | ||
412 | NULL, 0, extents, sizeof(buffer), &written, NULL)) { | ||
413 | if(extents->NumberOfDiskExtents > 1) { | ||
414 | qDebug() << "[Autodetect] resolving device name: volume spans multiple disks!"; | ||
415 | return ""; | ||
416 | } | ||
417 | qDebug() << "[Autodetect] device name is" << extents->Extents[0].DiskNumber; | ||
418 | return QString("%1").arg(extents->Extents[0].DiskNumber); | ||
419 | } | ||
420 | #endif | ||
421 | return QString(""); | ||
422 | |||
423 | } | ||
424 | |||
425 | |||
426 | /** @brief detect devices based on usb pid / vid. | 201 | /** @brief detect devices based on usb pid / vid. |
427 | * @return true upon success, false otherwise. | 202 | * @return true upon success, false otherwise. |
428 | */ | 203 | */ |
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: | |||
38 | QString getMountPoint() {return m_mountpoint;} | 38 | QString getMountPoint() {return m_mountpoint;} |
39 | QString errdev(void) { return m_errdev; } | 39 | QString errdev(void) { return m_errdev; } |
40 | QString incompatdev(void) { return m_incompat; } | 40 | QString incompatdev(void) { return m_incompat; } |
41 | static QStringList mountpoints(void); | ||
42 | static QString resolveDevicename(QString path); | ||
43 | 41 | ||
44 | private: | 42 | private: |
45 | QString resolveMountPoint(QString); | 43 | 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 @@ | |||
22 | #include "bootloaderinstallipod.h" | 22 | #include "bootloaderinstallipod.h" |
23 | 23 | ||
24 | #include "../ipodpatcher/ipodpatcher.h" | 24 | #include "../ipodpatcher/ipodpatcher.h" |
25 | #include "autodetection.h" | 25 | #include "utils.h" |
26 | 26 | ||
27 | 27 | ||
28 | BootloaderInstallIpod::BootloaderInstallIpod(QObject *parent) | 28 | BootloaderInstallIpod::BootloaderInstallIpod(QObject *parent) |
@@ -226,7 +226,7 @@ BootloaderInstallBase::Capabilities BootloaderInstallIpod::capabilities(void) | |||
226 | bool BootloaderInstallIpod::ipodInitialize(struct ipod_t *ipod) | 226 | bool BootloaderInstallIpod::ipodInitialize(struct ipod_t *ipod) |
227 | { | 227 | { |
228 | if(!m_blfile.isEmpty()) { | 228 | if(!m_blfile.isEmpty()) { |
229 | QString devicename = Autodetection::resolveDevicename(m_blfile); | 229 | QString devicename = Utils::resolveDevicename(m_blfile); |
230 | if(devicename.isEmpty()) { | 230 | if(devicename.isEmpty()) { |
231 | emit logItem(tr("Error: could not retrieve device name"), LOGERROR); | 231 | emit logItem(tr("Error: could not retrieve device name"), LOGERROR); |
232 | return false; | 232 | 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 @@ | |||
22 | #include "bootloaderinstallsansa.h" | 22 | #include "bootloaderinstallsansa.h" |
23 | 23 | ||
24 | #include "../sansapatcher/sansapatcher.h" | 24 | #include "../sansapatcher/sansapatcher.h" |
25 | #include "autodetection.h" | 25 | #include "utils.h" |
26 | 26 | ||
27 | BootloaderInstallSansa::BootloaderInstallSansa(QObject *parent) | 27 | BootloaderInstallSansa::BootloaderInstallSansa(QObject *parent) |
28 | : BootloaderInstallBase(parent) | 28 | : BootloaderInstallBase(parent) |
@@ -242,7 +242,7 @@ BootloaderInstallBase::BootloaderType BootloaderInstallSansa::installed(void) | |||
242 | bool BootloaderInstallSansa::sansaInitialize(struct sansa_t *sansa) | 242 | bool BootloaderInstallSansa::sansaInitialize(struct sansa_t *sansa) |
243 | { | 243 | { |
244 | if(!m_blfile.isEmpty()) { | 244 | if(!m_blfile.isEmpty()) { |
245 | QString devicename = Autodetection::resolveDevicename(m_blfile); | 245 | QString devicename = Utils::resolveDevicename(m_blfile); |
246 | if(devicename.isEmpty()) { | 246 | if(devicename.isEmpty()) { |
247 | emit logItem(tr("Error: could not retrieve device name"), LOGERROR); | 247 | emit logItem(tr("Error: could not retrieve device name"), LOGERROR); |
248 | return false; | 248 | 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 @@ | |||
32 | #include <cstdlib> | 32 | #include <cstdlib> |
33 | #include <stdio.h> | 33 | #include <stdio.h> |
34 | 34 | ||
35 | #if defined(Q_OS_LINUX) || defined(Q_OS_MACX) | ||
36 | #include <sys/statvfs.h> | ||
37 | #endif | ||
38 | #if defined(Q_OS_LINUX) || defined(Q_OS_MACX) | ||
39 | #include <stdio.h> | ||
40 | #endif | ||
41 | #if defined(Q_OS_LINUX) | ||
42 | #include <mntent.h> | ||
43 | #endif | ||
44 | #if defined(Q_OS_MACX) || defined(Q_OS_OPENBSD) | ||
45 | #include <sys/param.h> | ||
46 | #include <sys/ucred.h> | ||
47 | #include <sys/mount.h> | ||
48 | #endif | ||
35 | #if defined(Q_OS_WIN32) | 49 | #if defined(Q_OS_WIN32) |
36 | #include <windows.h> | 50 | #include <stdio.h> |
37 | #include <tchar.h> | 51 | #include <tchar.h> |
52 | #include <windows.h> | ||
53 | #include <setupapi.h> | ||
38 | #include <winioctl.h> | 54 | #include <winioctl.h> |
39 | #endif | 55 | #endif |
40 | #if defined(Q_OS_LINUX) || defined(Q_OS_MACX) | 56 | |
41 | #include <sys/statvfs.h> | ||
42 | #endif | ||
43 | 57 | ||
44 | // recursive function to delete a dir with files | 58 | // recursive function to delete a dir with files |
45 | bool Utils::recursiveRmdir( const QString &dirName ) | 59 | bool Utils::recursiveRmdir( const QString &dirName ) |
@@ -327,3 +341,203 @@ int Utils::compareVersionStrings(QString s1, QString s2) | |||
327 | return 0; | 341 | return 0; |
328 | } | 342 | } |
329 | 343 | ||
344 | |||
345 | /** Resolve mountpoint to devicename / disk number | ||
346 | * @param path mountpoint path / drive letter | ||
347 | * @return devicename / disk number | ||
348 | */ | ||
349 | QString Utils::resolveDevicename(QString path) | ||
350 | { | ||
351 | qDebug() << "[Utils] resolving device name" << path; | ||
352 | #if defined(Q_OS_LINUX) | ||
353 | FILE *mn = setmntent("/etc/mtab", "r"); | ||
354 | if(!mn) | ||
355 | return QString(""); | ||
356 | |||
357 | struct mntent *ent; | ||
358 | while((ent = getmntent(mn))) { | ||
359 | // check for valid filesystem type. | ||
360 | // Linux can handle hfs (and hfsplus), so consider it a valid file | ||
361 | // system. Otherwise resolving the device name would fail, which in | ||
362 | // turn would make it impossible to warn about a MacPod. | ||
363 | if(QString(ent->mnt_dir) == path | ||
364 | && (QString(ent->mnt_type).contains("vfat", Qt::CaseInsensitive) | ||
365 | || QString(ent->mnt_type).contains("hfs", Qt::CaseInsensitive))) { | ||
366 | endmntent(mn); | ||
367 | qDebug() << "[Utils] device name is" << ent->mnt_fsname; | ||
368 | return QString(ent->mnt_fsname); | ||
369 | } | ||
370 | } | ||
371 | endmntent(mn); | ||
372 | |||
373 | #endif | ||
374 | |||
375 | #if defined(Q_OS_MACX) || defined(Q_OS_OPENBSD) | ||
376 | int num; | ||
377 | struct statfs *mntinf; | ||
378 | |||
379 | num = getmntinfo(&mntinf, MNT_WAIT); | ||
380 | while(num--) { | ||
381 | // check for valid filesystem type. OS X can handle hfs (hfs+ is | ||
382 | // treated as hfs), BSD should be the same. | ||
383 | if(QString(mntinf->f_mntonname) == path | ||
384 | && (QString(mntinf->f_fstypename).contains("msdos", Qt::CaseInsensitive) | ||
385 | || QString(mntinf->f_fstypename).contains("hfs", Qt::CaseInsensitive))) { | ||
386 | qDebug() << "[Utils] device name is" << mntinf->f_mntfromname; | ||
387 | return QString(mntinf->f_mntfromname); | ||
388 | } | ||
389 | mntinf++; | ||
390 | } | ||
391 | #endif | ||
392 | |||
393 | #if defined(Q_OS_WIN32) | ||
394 | DWORD written; | ||
395 | HANDLE h; | ||
396 | TCHAR uncpath[MAX_PATH]; | ||
397 | UCHAR buffer[0x400]; | ||
398 | PVOLUME_DISK_EXTENTS extents = (PVOLUME_DISK_EXTENTS)buffer; | ||
399 | |||
400 | _stprintf(uncpath, _TEXT("\\\\.\\%c:"), path.toAscii().at(0)); | ||
401 | h = CreateFile(uncpath, GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, | ||
402 | NULL, OPEN_EXISTING, 0, NULL); | ||
403 | if(h == INVALID_HANDLE_VALUE) { | ||
404 | //qDebug() << "error getting extents for" << uncpath; | ||
405 | return ""; | ||
406 | } | ||
407 | // get the extents | ||
408 | if(DeviceIoControl(h, IOCTL_VOLUME_GET_VOLUME_DISK_EXTENTS, | ||
409 | NULL, 0, extents, sizeof(buffer), &written, NULL)) { | ||
410 | if(extents->NumberOfDiskExtents > 1) { | ||
411 | qDebug() << "[Utils] resolving device name: volume spans multiple disks!"; | ||
412 | return ""; | ||
413 | } | ||
414 | qDebug() << "[Utils] device name is" << extents->Extents[0].DiskNumber; | ||
415 | return QString("%1").arg(extents->Extents[0].DiskNumber); | ||
416 | } | ||
417 | #endif | ||
418 | return QString(""); | ||
419 | |||
420 | } | ||
421 | |||
422 | |||
423 | /** resolve device name to mount point / drive letter | ||
424 | * @param device device name / disk number | ||
425 | * @return mount point / drive letter | ||
426 | */ | ||
427 | QString Utils::resolveMountPoint(QString device) | ||
428 | { | ||
429 | qDebug() << "[Utils] resolving mountpoint:" << device; | ||
430 | |||
431 | #if defined(Q_OS_LINUX) | ||
432 | FILE *mn = setmntent("/etc/mtab", "r"); | ||
433 | if(!mn) | ||
434 | return QString(""); | ||
435 | |||
436 | struct mntent *ent; | ||
437 | while((ent = getmntent(mn))) { | ||
438 | // Check for valid filesystem. Allow hfs too, as an Ipod might be a | ||
439 | // MacPod. | ||
440 | if(QString(ent->mnt_fsname) == device) { | ||
441 | QString result; | ||
442 | if(QString(ent->mnt_type).contains("vfat", Qt::CaseInsensitive) | ||
443 | || QString(ent->mnt_type).contains("hfs", Qt::CaseInsensitive)) { | ||
444 | qDebug() << "[Utils] resolved mountpoint is:" << ent->mnt_dir; | ||
445 | result = QString(ent->mnt_dir); | ||
446 | } | ||
447 | else { | ||
448 | qDebug() << "[Utils] mountpoint is wrong filesystem!"; | ||
449 | } | ||
450 | endmntent(mn); | ||
451 | return result; | ||
452 | } | ||
453 | } | ||
454 | endmntent(mn); | ||
455 | |||
456 | #endif | ||
457 | |||
458 | #if defined(Q_OS_MACX) || defined(Q_OS_OPENBSD) | ||
459 | int num; | ||
460 | struct statfs *mntinf; | ||
461 | |||
462 | num = getmntinfo(&mntinf, MNT_WAIT); | ||
463 | while(num--) { | ||
464 | // Check for valid filesystem. Allow hfs too, as an Ipod might be a | ||
465 | // MacPod. | ||
466 | if(QString(mntinf->f_mntfromname) == device) { | ||
467 | if(QString(mntinf->f_fstypename).contains("msdos", Qt::CaseInsensitive) | ||
468 | || QString(mntinf->f_fstypename).contains("hfs", Qt::CaseInsensitive)) { | ||
469 | qDebug() << "[Utils] resolved mountpoint is:" << mntinf->f_mntonname; | ||
470 | return QString(mntinf->f_mntonname); | ||
471 | } | ||
472 | else { | ||
473 | qDebug() << "[Utils] mountpoint is wrong filesystem!"; | ||
474 | return QString(); | ||
475 | } | ||
476 | } | ||
477 | mntinf++; | ||
478 | } | ||
479 | #endif | ||
480 | |||
481 | #if defined(Q_OS_WIN32) | ||
482 | QString result; | ||
483 | unsigned int driveno = device.replace(QRegExp("^.*([0-9]+)"), "\\1").toInt(); | ||
484 | |||
485 | int letter; | ||
486 | for(letter = 'A'; letter <= 'Z'; letter++) { | ||
487 | if(resolveDevicename(QString(letter)).toUInt() == driveno) { | ||
488 | result = letter; | ||
489 | qDebug() << "[Utils] resolved mountpoint is:" << result; | ||
490 | break; | ||
491 | } | ||
492 | } | ||
493 | if(!result.isEmpty()) | ||
494 | return result + ":/"; | ||
495 | #endif | ||
496 | qDebug() << "[Utils] resolving mountpoint failed!"; | ||
497 | return QString(""); | ||
498 | } | ||
499 | |||
500 | |||
501 | QStringList Utils::mountpoints() | ||
502 | { | ||
503 | QStringList tempList; | ||
504 | #if defined(Q_OS_WIN32) | ||
505 | QFileInfoList list = QDir::drives(); | ||
506 | for(int i=0; i<list.size();i++) | ||
507 | { | ||
508 | tempList << list.at(i).absolutePath(); | ||
509 | qDebug() << "[Utils] Mounted on" << list.at(i).absolutePath(); | ||
510 | } | ||
511 | |||
512 | #elif defined(Q_OS_MACX) || defined(Q_OS_OPENBSD) | ||
513 | int num; | ||
514 | struct statfs *mntinf; | ||
515 | |||
516 | num = getmntinfo(&mntinf, MNT_WAIT); | ||
517 | while(num--) { | ||
518 | tempList << QString(mntinf->f_mntonname); | ||
519 | qDebug() << "[Utils] Mounted on" << mntinf->f_mntonname | ||
520 | << "is" << mntinf->f_mntfromname << "type" << mntinf->f_fstypename; | ||
521 | mntinf++; | ||
522 | } | ||
523 | #elif defined(Q_OS_LINUX) | ||
524 | |||
525 | FILE *mn = setmntent("/etc/mtab", "r"); | ||
526 | if(!mn) | ||
527 | return QStringList(""); | ||
528 | |||
529 | struct mntent *ent; | ||
530 | while((ent = getmntent(mn))) { | ||
531 | tempList << QString(ent->mnt_dir); | ||
532 | qDebug() << "[Utils] Mounted on" << ent->mnt_dir | ||
533 | << "is" << ent->mnt_fsname << "type" << ent->mnt_type; | ||
534 | } | ||
535 | endmntent(mn); | ||
536 | |||
537 | #else | ||
538 | #error Unknown Platform | ||
539 | #endif | ||
540 | return tempList; | ||
541 | } | ||
542 | |||
543 | |||
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: | |||
45 | static QString checkEnvironment(bool permission); | 45 | static QString checkEnvironment(bool permission); |
46 | static int compareVersionStrings(QString s1, QString s2); | 46 | static int compareVersionStrings(QString s1, QString s2); |
47 | static QString filesystemName(QString path); | 47 | static QString filesystemName(QString path); |
48 | static QStringList mountpoints(void); | ||
49 | static QString resolveDevicename(QString path); | ||
50 | static QString resolveMountPoint(QString device); | ||
48 | }; | 51 | }; |
49 | 52 | ||
50 | #endif | 53 | #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() | |||
587 | // unwanted item. | 587 | // unwanted item. |
588 | ui.mountPoint->blockSignals(true); | 588 | ui.mountPoint->blockSignals(true); |
589 | ui.mountPoint->clear(); | 589 | ui.mountPoint->clear(); |
590 | QStringList mps = Autodetection::mountpoints(); | 590 | QStringList mps = Utils::mountpoints(); |
591 | for(int i = 0; i < mps.size(); ++i) { | 591 | for(int i = 0; i < mps.size(); ++i) { |
592 | // add mountpoint as user data so we can change the displayed string | 592 | // add mountpoint as user data so we can change the displayed string |
593 | // later (to include volume label or similar) | 593 | // 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() | |||
61 | info += "<hr/>"; | 61 | info += "<hr/>"; |
62 | 62 | ||
63 | info += "<b>" + tr("Filesystem") + "</b><br/>"; | 63 | info += "<b>" + tr("Filesystem") + "</b><br/>"; |
64 | QStringList drives = Autodetection::mountpoints(); | 64 | QStringList drives = Utils::mountpoints(); |
65 | for(int i = 0; i < drives.size(); i++) { | 65 | for(int i = 0; i < drives.size(); i++) { |
66 | info += tr("%1, %4 %2 GiB of %3 GiB available") | 66 | info += tr("%1, %4 %2 GiB of %3 GiB available") |
67 | .arg(QDir::toNativeSeparators(drives.at(i))) | 67 | .arg(QDir::toNativeSeparators(drives.at(i))) |