Merge branch 'master' into kauth

This commit is contained in:
Andrius Štikonas 2018-01-31 15:15:25 +00:00
commit 9ea7cab92a
18 changed files with 116 additions and 40 deletions

View File

@ -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)

View File

@ -19,8 +19,6 @@
#define KPMCORE_COREBACKENDDEVICE_H
#include "util/libpartitionmanagerexport.h"
#include <QString>
class CoreBackendPartition;
@ -37,7 +35,7 @@ class Report;
*
* @author Volker Lanz <vl@fidra.de>
*/
class LIBKPMCORE_EXPORT CoreBackendDevice
class CoreBackendDevice
{
public:
CoreBackendDevice(const QString& deviceNode);

View File

@ -21,7 +21,6 @@
#include "core/partitiontable.h"
#include "fs/filesystem.h"
#include "util/libpartitionmanagerexport.h"
#include <QtGlobal>
@ -33,7 +32,7 @@ class Partition;
* Interface class to represent a partition table in the backend.
* @author Volker Lanz <vl@fidra.de>
*/
class LIBKPMCORE_EXPORT CoreBackendPartitionTable
class CoreBackendPartitionTable
{
public:
virtual ~CoreBackendPartitionTable() {}

View File

@ -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 */
}

View File

@ -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;
}

View File

@ -29,8 +29,6 @@
#include "util/capacity.h"
#include "util/helpers.h"
#include <blkid/blkid.h>
#include <KLocalizedString>
#include <QFileInfo>
@ -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

View File

@ -18,8 +18,8 @@
*************************************************************************/
#if !defined(KPMCORE_FILESYSTEM_H)
#define KPMCORE_FILESYSTEM_H
#include "util/libpartitionmanagerexport.h"
#include <QColor>

View File

@ -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})

View File

@ -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());

View File

@ -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

View File

@ -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})

View File

@ -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());

View File

@ -67,6 +67,8 @@ public:
DiskDevice* scanDevice(const QString& deviceNode) override;
QList<Device*> 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();

View File

@ -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})

View File

@ -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 sfdiska za KDEov 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 sfdiska za KDEov menadžer particija

View File

@ -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;

View File

@ -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);

View File

@ -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)