diff --git a/README.md b/README.md index 8649fb9..15e4127 100644 --- a/README.md +++ b/README.md @@ -71,9 +71,7 @@ back to a default backend suitable for the current platform. Calling KPMcore functions before the library is initialized will result in undefined behavior. -### Devices [FIXME: WIP] - -#### Backend device scanner +### Devices After the backend is initialized you can scan for available devices. If you only want devices from the loaded backend you can call @@ -87,8 +85,7 @@ read only devices. #### KPMcore device scanner -Alternatively, you can use KPMcore device scanner which also finds -LVM Volume Groups. +Alternatively, you can use KPMcore device scanner ``` #include @@ -102,6 +99,6 @@ LVM Volume Groups. QList devices = operationStack->previewDevices(); ``` -When `deviceScanner` scans for the devices in a background thread. After +Then `deviceScanner` scans for the devices in a background thread. After scanning is complete `DeviceScanner::finished()` signal will be emitted. Then the devices can accessed using `operationStack->previewDevices()`. diff --git a/src/core/devicescanner.cpp b/src/core/devicescanner.cpp index 82826c4..7024290 100644 --- a/src/core/devicescanner.cpp +++ b/src/core/devicescanner.cpp @@ -23,7 +23,6 @@ #include "core/operationstack.h" #include "core/device.h" -#include "core/lvmdevice.h" #include "core/diskdevice.h" #include "fs/lvm2_pv.h" @@ -65,27 +64,10 @@ void DeviceScanner::scan() clear(); const QList deviceList = CoreBackendManager::self()->backend()->scanDevices(); - const QList lvmList = LvmDevice::scanSystemLVM(); - - // Some LVM operations require additional information about LVM physical volumes which we store in LVM::pvList - LVM::pvList = FS::lvm2_pv::getPVs(deviceList); for (const auto &d : deviceList) operationStack().addDevice(d); - // Display alphabetically sorted disk devices above LVM VGs operationStack().sortDevices(); - - // Look for LVM physical volumes in LVM VGs - for (const auto &d : lvmList) { - operationStack().addDevice(d); - LVM::pvList.append(FS::lvm2_pv::getPVinNode(d->partitionTable())); - } - - // Inform LvmDevice about which physical volumes form that particular LvmDevice - for (const auto &d : lvmList) - for (const auto &p : qAsConst(LVM::pvList)) - if (p.vgName() == d->name()) - d->physicalVolumes().append(p.partition()); } diff --git a/src/core/lvmdevice.cpp b/src/core/lvmdevice.cpp index fa7287b..e95b2a5 100644 --- a/src/core/lvmdevice.cpp +++ b/src/core/lvmdevice.cpp @@ -171,15 +171,30 @@ Partition* LvmDevice::scanPartition(const QString& lvPath, PartitionTable* pTabl /** scan and construct list of initialized LvmDevice objects. * - * @return list of initialized LvmDevices + * @param devices list of initialized Devices */ -QList LvmDevice::scanSystemLVM() +void LvmDevice::scanSystemLVM(QList& devices) { QList lvmList; for (const auto &vgName : getVGs()) { lvmList.append(new LvmDevice(vgName)); } - return lvmList; + + // Some LVM operations require additional information about LVM physical volumes which we store in LVM::pvList + LVM::pvList = FS::lvm2_pv::getPVs(devices); + + // Look for LVM physical volumes in LVM VGs + for (const auto &d : lvmList) { + devices.append(d); + LVM::pvList.append(FS::lvm2_pv::getPVinNode(d->partitionTable())); + } + + // Inform LvmDevice about which physical volumes form that particular LvmDevice + for (const auto &d : lvmList) + for (const auto &p : qAsConst(LVM::pvList)) + if (p.vgName() == d->name()) + d->physicalVolumes().append(p.partition()); + } qint64 LvmDevice::mappedSector(const QString& lvPath, qint64 sector) const diff --git a/src/core/lvmdevice.h b/src/core/lvmdevice.h index 5ff69ec..8a49263 100644 --- a/src/core/lvmdevice.h +++ b/src/core/lvmdevice.h @@ -58,7 +58,7 @@ public: static QVector s_DirtyPVs; public: - static QList scanSystemLVM(); + static void scanSystemLVM(QList& devices); static const QStringList getVGs(); static const QStringList getLVs(const QString& vgName); diff --git a/src/core/operationstack.cpp b/src/core/operationstack.cpp index cd15ad3..8e7bd57 100644 --- a/src/core/operationstack.cpp +++ b/src/core/operationstack.cpp @@ -554,6 +554,10 @@ void OperationStack::addDevice(Device* d) static bool deviceLessThan(const Device* d1, const Device* d2) { + // Display alphabetically sorted disk devices above LVM VGs + if (d1->type() == Device::LVM_Device && d2->type() == Device::Disk_Device ) + return false; + return d1->deviceNode() <= d2->deviceNode(); } diff --git a/src/plugins/libparted/libpartedbackend.cpp b/src/plugins/libparted/libpartedbackend.cpp index e9fdffd..2081fe9 100644 --- a/src/plugins/libparted/libpartedbackend.cpp +++ b/src/plugins/libparted/libpartedbackend.cpp @@ -24,7 +24,7 @@ #include "plugins/libparted/libparteddevice.h" #include "plugins/libparted/pedflags.h" -#include "core/diskdevice.h" +#include "core/lvmdevice.h" #include "core/partition.h" #include "core/partitiontable.h" #include "core/partitionalignment.h" @@ -384,7 +384,7 @@ void LibPartedBackend::scanDevicePartitions(Device& d, PedDisk* pedDisk) @param deviceNode the device node (e.g. "/dev/sda") @return the created Device object. callers need to free this. */ -Device* LibPartedBackend::scanDevice(const QString& deviceNode) +DiskDevice* LibPartedBackend::scanDevice(const QString& deviceNode) { PedDevice* pedDevice = ped_device_get(deviceNode.toLocal8Bit().constData()); @@ -456,6 +456,8 @@ QList LibPartedBackend::scanDevices(bool excludeReadOnly) result.append(device); } } + + LvmDevice::scanSystemLVM(result); } return result; diff --git a/src/plugins/libparted/libpartedbackend.h b/src/plugins/libparted/libpartedbackend.h index c7e2a15..69664a5 100644 --- a/src/plugins/libparted/libpartedbackend.h +++ b/src/plugins/libparted/libpartedbackend.h @@ -23,6 +23,7 @@ #include "backend/corebackend.h" #include "core/partitiontable.h" +#include "core/diskdevice.h" #include "util/libpartitionmanagerexport.h" #include "fs/filesystem.h" @@ -63,7 +64,7 @@ public: CoreBackendDevice* openDevice(const QString& deviceNode) override; CoreBackendDevice* openDeviceExclusive(const QString& deviceNode) override; bool closeDevice(CoreBackendDevice* core_device) override; - Device* scanDevice(const QString& deviceNode) override; + DiskDevice* scanDevice(const QString& deviceNode) override; QList scanDevices(bool excludeReadOnly = false) override; FileSystem::Type detectFileSystem(const QString& partitionPath) override;