summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYang Li <yang.12.li@nokia.com>2012-02-27 17:06:12 +0100
committerQt by Nokia <qt-info@nokia.com>2012-03-08 01:30:10 +0100
commit057c96a65671b2085573eb26f21e4c00b67a6775 (patch)
tree5c2ea82d6e67824608b7fad1b2fcf5b841770f6e
parent0f02ed803cb922bdf32de66f9806ac7fa4cb05c0 (diff)
Fixed checking for removable drives.
Change-Id: Id6b2bce282992b7eea209280f894e130a0e39d72 Reviewed-by: Xizhi Zhu <xizhi.zhu@nokia.com>
-rw-r--r--src/systeminfo/qstorageinfo_linux.cpp29
1 files changed, 23 insertions, 6 deletions
diff --git a/src/systeminfo/qstorageinfo_linux.cpp b/src/systeminfo/qstorageinfo_linux.cpp
index e0f70394..9e253020 100644
--- a/src/systeminfo/qstorageinfo_linux.cpp
+++ b/src/systeminfo/qstorageinfo_linux.cpp
@@ -228,12 +228,29 @@ QStorageInfo::DriveType QStorageInfoPrivate::driveType(const QString &drive)
fsName = fsName.section(QString(QStringLiteral("/")), 2, 3);
if (!fsName.isEmpty()) {
if (fsName.length() > 3) {
- if (fsName.right(1) == QString(QStringLiteral("p"))) {
- fsName.chop(1);
- } else {
- if (QDir(QStringLiteral("/dev/")).entryList(QStringList() << (fsName + QStringLiteral("p*"))).isEmpty()) {
- type = QStorageInfo::RemovableDrive;
- break;
+ // only take the parent of the device
+ if (fsName.at(fsName.size() -1).isDigit() && fsName.at(fsName.size() - 2) == QChar(QLatin1Char('p')))
+ fsName.chop(2);
+ if (fsName.startsWith(QString(QStringLiteral("mmc")))) {
+ // "removable" attribute is set only for removable media, and we may have internal mmc cards
+ fsName = QString(QStringLiteral("/sys/block/")) + fsName + QString(QStringLiteral("/device/uevent"));
+ QFile file(fsName);
+ if (file.open(QIODevice::ReadOnly)) {
+ QByteArray buf = file.readLine();
+ while (buf.size() > 0) {
+ if (qstrncmp(buf.constData(), "MMC_TYPE=", 9) == 0) {
+ if (qstrncmp(buf.constData() + 9, "MMC", 3) == 0)
+ type = QStorageInfo::InternalDrive;
+ else if (qstrncmp(buf.constData() + 9, "SD", 2) == 0)
+ type = QStorageInfo::RemovableDrive;
+ if (type != QStorageInfo::UnknownDrive) {
+ endmntent(fsDescription);
+ return type;
+ }
+ break; // fall back to check the "removable" attribute
+ }
+ buf = file.readLine();
+ }
}
}
}