diff --git a/src/backend/corebackend.h b/src/backend/corebackend.h index 59725a2..7829ce2 100644 --- a/src/backend/corebackend.h +++ b/src/backend/corebackend.h @@ -100,11 +100,25 @@ public: /** * Scan a single device in the system. - * @param deviceNode The path to the device that is to be scanned (e.g. /dev/sda) + * @param deviceNode The path to the device that is to be scanned (e.g. /dev/sda1) * @return FileSystem type of the device on deviceNode */ virtual FileSystem::Type detectFileSystem(const QString& deviceNode) = 0; + /** + * Read a file system label + * @param deviceNode The path to the device that is to be scanned (e.g. /dev/sda1) + * @return FileSystem label on deviceNode + */ + virtual QString readLabel(const QString& deviceNode) const = 0; + + /** + * Read a file system UUID + * @param deviceNode The path to the device that is to be scanned (e.g. /dev/sda1) + * @return FileSystem UUID on deviceNode + */ + virtual QString readUUID(const QString& deviceNode) const = 0; + /** * Scan a single device in the system. * @param deviceNode The path to the device that is to be scanned (e.g. /dev/sda) diff --git a/src/backend/corebackenddevice.h b/src/backend/corebackenddevice.h index 2928b0c..600adc6 100644 --- a/src/backend/corebackenddevice.h +++ b/src/backend/corebackenddevice.h @@ -19,8 +19,6 @@ #define KPMCORE_COREBACKENDDEVICE_H -#include "util/libpartitionmanagerexport.h" - #include class CoreBackendPartition; @@ -37,7 +35,7 @@ class Report; * * @author Volker Lanz */ -class LIBKPMCORE_EXPORT CoreBackendDevice +class CoreBackendDevice { public: CoreBackendDevice(const QString& deviceNode); diff --git a/src/backend/corebackendpartitiontable.h b/src/backend/corebackendpartitiontable.h index 1e402ac..aae5fca 100644 --- a/src/backend/corebackendpartitiontable.h +++ b/src/backend/corebackendpartitiontable.h @@ -21,7 +21,6 @@ #include "core/partitiontable.h" #include "fs/filesystem.h" -#include "util/libpartitionmanagerexport.h" #include @@ -33,7 +32,7 @@ class Partition; * Interface class to represent a partition table in the backend. * @author Volker Lanz */ -class LIBKPMCORE_EXPORT CoreBackendPartitionTable +class CoreBackendPartitionTable { public: virtual ~CoreBackendPartitionTable() {} diff --git a/src/core/operationrunner.h b/src/core/operationrunner.h index 06aee79..f91468d 100644 --- a/src/core/operationrunner.h +++ b/src/core/operationrunner.h @@ -45,9 +45,9 @@ public: public: void run(); - LIBKPMCORE_EXPORT qint32 numJobs() const; - LIBKPMCORE_EXPORT qint32 numOperations() const; - LIBKPMCORE_EXPORT qint32 numProgressSub() const; + qint32 numJobs() const; + qint32 numOperations() const; + qint32 numProgressSub() const; bool isCancelling() const { return m_Cancelling; /**< @return if the user has requested cancelling */ } diff --git a/src/fs/btrfs.cpp b/src/fs/btrfs.cpp index bc81b9a..e202213 100644 --- a/src/fs/btrfs.cpp +++ b/src/fs/btrfs.cpp @@ -51,12 +51,12 @@ btrfs::btrfs(qint64 firstsector, qint64 lastsector, qint64 sectorsused, const QS void btrfs::init() { m_Create = findExternal(QStringLiteral("mkfs.btrfs")) ? cmdSupportFileSystem : cmdSupportNone; - m_Check = findExternal(QStringLiteral("btrfsck"), QStringList(), 1) ? cmdSupportFileSystem : cmdSupportNone; - m_Grow = (m_Check != cmdSupportNone && findExternal(QStringLiteral("btrfs"))) ? cmdSupportFileSystem : cmdSupportNone; - m_GetUsed = findExternal(QStringLiteral("btrfs")) ? cmdSupportFileSystem : cmdSupportNone; + m_Check = findExternal(QStringLiteral("btrfs")) ? cmdSupportFileSystem : cmdSupportNone; + m_Grow = m_Check; + m_GetUsed = m_Check; m_Shrink = (m_Grow != cmdSupportNone && m_GetUsed != cmdSupportNone) ? cmdSupportFileSystem : cmdSupportNone; - m_SetLabel = findExternal(QStringLiteral("btrfs")) ? cmdSupportFileSystem : cmdSupportNone; + m_SetLabel = m_Check; m_UpdateUUID = findExternal(QStringLiteral("btrfstune")) ? cmdSupportFileSystem : cmdSupportNone; m_Copy = (m_Check != cmdSupportNone) ? cmdSupportCore : cmdSupportNone; @@ -122,7 +122,7 @@ qint64 btrfs::readUsedCapacity(const QString& deviceNode) const bool btrfs::check(Report& report, const QString& deviceNode) const { - ExternalCommand cmd(report, QStringLiteral("btrfsck"), { deviceNode }); + ExternalCommand cmd(report, QStringLiteral("btrfs"), { QStringLiteral("check"), QStringLiteral("--repair"), deviceNode }); return cmd.run(-1) && cmd.exitCode() == 0; } diff --git a/src/fs/filesystem.cpp b/src/fs/filesystem.cpp index 117dd26..fa4e640 100644 --- a/src/fs/filesystem.cpp +++ b/src/fs/filesystem.cpp @@ -29,8 +29,6 @@ #include "util/capacity.h" #include "util/helpers.h" -#include - #include #include @@ -102,27 +100,6 @@ qint64 FileSystem::readUsedCapacity(const QString& deviceNode) const return -1; } -static QString readBlkIdValue(const QString& deviceNode, const QString& tag) -{ - blkid_cache cache; - QString rval; - - if (blkid_get_cache(&cache, nullptr) == 0) { - blkid_dev dev; - - char* label = nullptr; - if ((dev = blkid_get_dev(cache, deviceNode.toLocal8Bit().constData(), BLKID_DEV_NORMAL)) != nullptr && - (label = blkid_get_tag_value(cache, tag.toLocal8Bit().constData(), deviceNode.toLocal8Bit().constData()))) { - rval = QString::fromLocal8Bit(label); - free(label); - } - - blkid_put_cache(cache); - } - - return rval; -} - FileSystem::Type FileSystem::detectFileSystem(const QString& partitionPath) { return CoreBackendManager::self()->backend()->detectFileSystem(partitionPath); @@ -169,7 +146,7 @@ bool FileSystem::detectMountStatus(FileSystem* fs, const QString& partitionPath) */ QString FileSystem::readLabel(const QString& deviceNode) const { - return readBlkIdValue(deviceNode, QStringLiteral("LABEL")); + return CoreBackendManager::self()->backend()->readLabel(deviceNode); } /** Creates a new FileSystem @@ -364,7 +341,7 @@ bool FileSystem::updateUUID(Report& report, const QString& deviceNode) const */ QString FileSystem::readUUID(const QString& deviceNode) const { - return readBlkIdValue(deviceNode, QStringLiteral("UUID")); + return CoreBackendManager::self()->backend()->readUUID(deviceNode); } /** Give implementations of FileSystem a chance to update the boot sector after the diff --git a/src/fs/filesystem.h b/src/fs/filesystem.h index cdce228..27451a7 100644 --- a/src/fs/filesystem.h +++ b/src/fs/filesystem.h @@ -18,8 +18,8 @@ *************************************************************************/ #if !defined(KPMCORE_FILESYSTEM_H) - #define KPMCORE_FILESYSTEM_H + #include "util/libpartitionmanagerexport.h" #include diff --git a/src/plugins/dummy/CMakeLists.txt b/src/plugins/dummy/CMakeLists.txt index b935d6e..e4895ff 100644 --- a/src/plugins/dummy/CMakeLists.txt +++ b/src/plugins/dummy/CMakeLists.txt @@ -17,6 +17,7 @@ set (pmdummybackendplugin_SRCS dummybackend.cpp dummydevice.cpp dummypartitiontable.cpp + ${CMAKE_SOURCE_DIR}/src/backend/corebackenddevice.cpp ) add_library(pmdummybackendplugin SHARED ${pmdummybackendplugin_SRCS}) diff --git a/src/plugins/dummy/dummybackend.cpp b/src/plugins/dummy/dummybackend.cpp index 7e54880..5abc6f2 100644 --- a/src/plugins/dummy/dummybackend.cpp +++ b/src/plugins/dummy/dummybackend.cpp @@ -77,6 +77,20 @@ FileSystem::Type DummyBackend::detectFileSystem(const QString& deviceNode) return FileSystem::Unknown; } +QString DummyBackend::readLabel(const QString& deviceNode) const +{ + Q_UNUSED(deviceNode) + + return QString(); +} + +QString DummyBackend::readUUID(const QString& deviceNode) const +{ + Q_UNUSED(deviceNode) + + return QString(); +} + CoreBackendDevice* DummyBackend::openDevice(const Device& d) { DummyDevice* device = new DummyDevice(d.deviceNode()); diff --git a/src/plugins/dummy/dummybackend.h b/src/plugins/dummy/dummybackend.h index d027171..12aad6b 100644 --- a/src/plugins/dummy/dummybackend.h +++ b/src/plugins/dummy/dummybackend.h @@ -50,6 +50,8 @@ public: bool closeDevice(CoreBackendDevice* coreDevice) override; Device* scanDevice(const QString& deviceNode) override; FileSystem::Type detectFileSystem(const QString& deviceNode) override; + QString readLabel(const QString& deviceNode) const override; + QString readUUID(const QString& deviceNode) const override; }; #endif diff --git a/src/plugins/libparted/CMakeLists.txt b/src/plugins/libparted/CMakeLists.txt index a123e44..6e21439 100644 --- a/src/plugins/libparted/CMakeLists.txt +++ b/src/plugins/libparted/CMakeLists.txt @@ -29,6 +29,7 @@ set (pmlibpartedbackendplugin_SRCS libpartedbackend.cpp libparteddevice.cpp libpartedpartitiontable.cpp + ${CMAKE_SOURCE_DIR}/src/backend/corebackenddevice.cpp ) add_library(pmlibpartedbackendplugin SHARED ${pmlibpartedbackendplugin_SRCS}) diff --git a/src/plugins/libparted/libpartedbackend.cpp b/src/plugins/libparted/libpartedbackend.cpp index 582fa0f..7c0e59a 100644 --- a/src/plugins/libparted/libpartedbackend.cpp +++ b/src/plugins/libparted/libpartedbackend.cpp @@ -524,6 +524,37 @@ FileSystem::Type LibPartedBackend::detectFileSystem(const QString& partitionPath return rval; } +static QString readBlkIdValue(const QString& deviceNode, const QString& tag) +{ + blkid_cache cache; + QString rval; + + if (blkid_get_cache(&cache, nullptr) == 0) { + blkid_dev dev; + + char* label = nullptr; + if ((dev = blkid_get_dev(cache, deviceNode.toLocal8Bit().constData(), BLKID_DEV_NORMAL)) != nullptr && + (label = blkid_get_tag_value(cache, tag.toLocal8Bit().constData(), deviceNode.toLocal8Bit().constData()))) { + rval = QString::fromLocal8Bit(label); + free(label); + } + + blkid_put_cache(cache); + } + + return rval; +} + +QString LibPartedBackend::readLabel(const QString& deviceNode) const +{ + return readBlkIdValue(deviceNode, QStringLiteral("LABEL")); +} + +QString LibPartedBackend::readUUID(const QString& deviceNode) const +{ + return readBlkIdValue(deviceNode, QStringLiteral("UUID")); +} + CoreBackendDevice* LibPartedBackend::openDevice(const Device& d) { LibPartedDevice* device = new LibPartedDevice(d.deviceNode()); diff --git a/src/plugins/libparted/libpartedbackend.h b/src/plugins/libparted/libpartedbackend.h index a5d5450..93ed320 100644 --- a/src/plugins/libparted/libpartedbackend.h +++ b/src/plugins/libparted/libpartedbackend.h @@ -67,6 +67,8 @@ public: DiskDevice* scanDevice(const QString& deviceNode) override; QList scanDevices(bool excludeReadOnly = false) override; FileSystem::Type detectFileSystem(const QString& partitionPath) override; + QString readLabel(const QString& deviceNode) const override; + QString readUUID(const QString& deviceNode) const override; static QString lastPartedExceptionMessage(); diff --git a/src/plugins/sfdisk/CMakeLists.txt b/src/plugins/sfdisk/CMakeLists.txt index 6b21c07..7c03787 100644 --- a/src/plugins/sfdisk/CMakeLists.txt +++ b/src/plugins/sfdisk/CMakeLists.txt @@ -17,6 +17,7 @@ set (pmsfdiskbackendplugin_SRCS sfdiskbackend.cpp sfdiskdevice.cpp sfdiskpartitiontable.cpp + ${CMAKE_SOURCE_DIR}/src/backend/corebackenddevice.cpp ) add_library(pmsfdiskbackendplugin SHARED ${pmsfdiskbackendplugin_SRCS}) diff --git a/src/plugins/sfdisk/pmsfdiskbackendplugin.desktop b/src/plugins/sfdisk/pmsfdiskbackendplugin.desktop index 18d85e7..10857d0 100644 --- a/src/plugins/sfdisk/pmsfdiskbackendplugin.desktop +++ b/src/plugins/sfdisk/pmsfdiskbackendplugin.desktop @@ -4,10 +4,12 @@ Name=KDE Partition Manager sfdisk Backend Name[ca]=Dorsal «sfdisk» del gestor de particions del KDE Name[ca@valencia]=Dorsal «sfdisk» del gestor de particions del KDE Name[de]=KDE-Partitionsverwaltung sfdisk-Backend +Name[es]=Motor sfdisk para el gestor de particiones de KDE Name[gl]=Infraestrutura de sfdisk do xestor de particións de KDE Name[nl]=Sfdisk-backend van KDE-partitiebeheerder Name[pl]=Silnik sfdisk zarządzania partycjami KDE Name[pt]=Infra-Estrutura do 'sfdisk' do Gestor de Partições do KDE +Name[sl]=Zaledje sfdisk za upravljalnik razdelkov za KDE Name[sr]=Позадина sfdisk‑а за КДЕ‑ов менаџер партиција Name[sr@ijekavian]=Позадина sfdisk‑а за КДЕ‑ов менаџер партиција Name[sr@ijekavianlatin]=Pozadina sfdisk‑a za KDE‑ov menadžer particija @@ -19,10 +21,12 @@ Comment=A KDE Partition Manager sfdisk backend. Comment[ca]=Un dorsal «sfdisk» del gestor de particions del KDE. Comment[ca@valencia]=Un dorsal «sfdisk» del gestor de particions del KDE. Comment[de]=Ein sfdisk-Backend für die KDE-Partitionsverwaltung. +Comment[es]=Motor sfdisk para el gestor de particiones de KDE. Comment[gl]=Unha infraestrutura de sfdisk do xestor de particións de KDE. Comment[nl]=Sfdisk-backend van KDE-partitiebeheerder Comment[pl]=Silnik sfdisk zarządzania partycjami KDE. Comment[pt]=A infra-estrutura do 'sfdisk' do Gestor de Partições do KDE. +Comment[sl]=Zaledje sfdisk za upravljalnik razdelkov za KDE Comment[sr]=Позадина sfdisk‑а за КДЕ‑ов менаџер партиција Comment[sr@ijekavian]=Позадина sfdisk‑а за КДЕ‑ов менаџер партиција Comment[sr@ijekavianlatin]=Pozadina sfdisk‑a za KDE‑ov menadžer particija diff --git a/src/plugins/sfdisk/sfdiskbackend.cpp b/src/plugins/sfdisk/sfdiskbackend.cpp index 9849628..33ef5ff 100644 --- a/src/plugins/sfdisk/sfdiskbackend.cpp +++ b/src/plugins/sfdisk/sfdiskbackend.cpp @@ -358,6 +358,35 @@ FileSystem::Type SfdiskBackend::detectFileSystem(const QString& partitionPath) return rval; } +QString SfdiskBackend::readLabel(const QString& deviceNode) const +{ + ExternalCommand udevCommand(QStringLiteral("udevadm"), { + QStringLiteral("info"), + QStringLiteral("--query=property"), + deviceNode }); + + QRegularExpression re(QStringLiteral("ID_FS_LABEL=(\\w+)")); + QRegularExpressionMatch reFileSystemLabel = re.match(udevCommand.output()); + if (reFileSystemLabel.hasMatch()) + return reFileSystemLabel.captured(1); + + return QString(); +} + +QString SfdiskBackend::readUUID(const QString& deviceNode) const +{ + ExternalCommand udevCommand(QStringLiteral("udevadm"), { + QStringLiteral("info"), + QStringLiteral("--query=property"), + deviceNode }); + QRegularExpression re(QStringLiteral("ID_FS_UUID=(\\w+)")); + QRegularExpressionMatch reFileSystemUUID = re.match(udevCommand.output()); + if (reFileSystemUUID.hasMatch()) + return reFileSystemUUID.captured(1); + + return QString(); +} + PartitionTable::Flags SfdiskBackend::availableFlags(PartitionTable::TableType type) { PartitionTable::Flags flags; diff --git a/src/plugins/sfdisk/sfdiskbackend.h b/src/plugins/sfdisk/sfdiskbackend.h index ad421f7..5cb3291 100644 --- a/src/plugins/sfdisk/sfdiskbackend.h +++ b/src/plugins/sfdisk/sfdiskbackend.h @@ -52,6 +52,8 @@ public: bool closeDevice(CoreBackendDevice* coreDevice) override; Device* scanDevice(const QString& deviceNode) override; FileSystem::Type detectFileSystem(const QString& partitionPath) override; + QString readLabel(const QString& deviceNode) const override; + QString readUUID(const QString& deviceNode) const override; private: static void readSectorsUsed(const Device& d, Partition& p, const QString& mountPoint); diff --git a/src/plugins/sfdisk/sfdiskpartitiontable.cpp b/src/plugins/sfdisk/sfdiskpartitiontable.cpp index 58e1e0e..79c2a55 100644 --- a/src/plugins/sfdisk/sfdiskpartitiontable.cpp +++ b/src/plugins/sfdisk/sfdiskpartitiontable.cpp @@ -193,6 +193,7 @@ static QLatin1String getPartitionType(FileSystem::Type t, PartitionTable::TableT type = 1; break; default:; + return QLatin1String(); } for (quint32 i = 0; i < sizeof(typemap) / sizeof(typemap[0]); i++) if (typemap[i].type == t)