From 2e9166d2d4c44540a7f4aa4be54e9e21bd8667c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andrius=20=C5=A0tikonas?= Date: Sat, 23 Jul 2016 22:01:38 +0100 Subject: [PATCH] Improve comment of major device numbers. Exclude read-only block devices. --- src/plugins/libparted/libpartedbackend.cpp | 22 +++++++++++++++++++--- src/plugins/libparted/libpartedbackend.h | 2 +- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/src/plugins/libparted/libpartedbackend.cpp b/src/plugins/libparted/libpartedbackend.cpp index d28a025..e70510e 100644 --- a/src/plugins/libparted/libpartedbackend.cpp +++ b/src/plugins/libparted/libpartedbackend.cpp @@ -308,21 +308,37 @@ Device* LibPartedBackend::scanDevice(const QString& deviceNode) return d; } -QList LibPartedBackend::scanDevices(bool excludeLoop) +QList LibPartedBackend::scanDevices(bool excludeReadOnly) { QList result; - + // FIXME: cat /sys/block/loop0/ro + // linux.git/tree/Documentation/devices.txt + QString blockDeviceMajorNumbers = QStringLiteral( + "3,22,33,34,56,57,88,89,90,91,128,129,130,131,132,133,134,135," // MFM, RLL and IDE hard disk/CD-ROM interface + "7," // loop devices + "8,65,66,67,68,69,70,71," // SCSI disk devices + "80,81,82,83,84,85,86,87," // I2O hard disk + "179," // MMC block devices + "259" // Block Extended Major (include NVMe) + ); ExternalCommand cmd(QStringLiteral("lsblk"), { QStringLiteral("--nodeps"), QStringLiteral("--noheadings"), QStringLiteral("--output"), QString::fromLatin1("name"), QStringLiteral("--paths"), - QStringLiteral("--include"), excludeLoop ? QStringLiteral("3,8,22,33,34,65,66,67,68,69,70,71,179,259") : QStringLiteral("3,7,8,22,33,34,65,66,67,68,69,70,71,179,259") }); + QStringLiteral("--include"), blockDeviceMajorNumbers}); if (cmd.run(-1) && cmd.exitCode() == 0) { QStringList devices = cmd.output().split(QString::fromLatin1("\n")); devices.removeLast(); quint32 totalDevices = devices.length(); for (quint32 i = 0; i < totalDevices; ++i) { + if (excludeReadOnly) { + QFile f(QStringLiteral("/sys/block/%1/ro").arg(QString(devices[i]).remove(QStringLiteral("/dev/")))); + if (f.open(QIODevice::ReadOnly)) + if (f.readLine().trimmed().toInt() == 1) + continue; + } + emitScanProgress(devices[i], i * 100 / totalDevices); result.append(scanDevice(devices[i])); } diff --git a/src/plugins/libparted/libpartedbackend.h b/src/plugins/libparted/libpartedbackend.h index 5b3906d..cae8664 100644 --- a/src/plugins/libparted/libpartedbackend.h +++ b/src/plugins/libparted/libpartedbackend.h @@ -65,7 +65,7 @@ public: CoreBackendDevice* openDeviceExclusive(const QString& deviceNode) override; bool closeDevice(CoreBackendDevice* core_device) override; Device* scanDevice(const QString& deviceNode) override; - QList scanDevices(bool excludeLoop = false) override; + QList scanDevices(bool excludeReadOnly = true) override; FileSystem::Type detectFileSystem(const QString& partitionPath) override; static QString lastPartedExceptionMessage();