sfdisk: simplify scanDevice by moving out partition setup logic.
This commit is contained in:
parent
ffb7147f01
commit
dc604c4d31
|
@ -276,7 +276,8 @@ void SfdiskBackend::scanDevicePartitions(Device& d, const QJsonArray& jsonPartit
|
|||
else
|
||||
r = PartitionRole::Logical;
|
||||
|
||||
FileSystem* fs = FileSystemFactory::create(type, start, start + size - 1, d.logicalSize());
|
||||
auto lastSector = start + size - 1;
|
||||
FileSystem* fs = FileSystemFactory::create(type, start, lastSector, d.logicalSize());
|
||||
fs->scan(partitionNode);
|
||||
|
||||
QString mountPoint;
|
||||
|
@ -294,22 +295,13 @@ void SfdiskBackend::scanDevicePartitions(Device& d, const QJsonArray& jsonPartit
|
|||
mounted = FileSystem::detectMountStatus(fs, partitionNode);
|
||||
}
|
||||
|
||||
Partition* part = new Partition(parent, d, PartitionRole(r), fs, start, start + size - 1, partitionNode, availableFlags(d.partitionTable()->type()), mountPoint, mounted, activeFlags);
|
||||
Partition* part = new Partition(parent, d, PartitionRole(r), fs, start, lastSector, partitionNode, availableFlags(d.partitionTable()->type()), mountPoint, mounted, activeFlags);
|
||||
|
||||
if (!part->roles().has(PartitionRole::Luks))
|
||||
readSectorsUsed(d, *part, mountPoint);
|
||||
setupPartitionInfo(d, part, partitionObject, mountPoint);
|
||||
|
||||
if (fs->supportGetLabel() != FileSystem::cmdSupportNone)
|
||||
fs->setLabel(fs->readLabel(part->deviceNode()));
|
||||
|
||||
if (d.partitionTable()->type() == PartitionTable::TableType::gpt) {
|
||||
part->setLabel(partitionObject[QLatin1String("name")].toString());
|
||||
part->setUUID(partitionObject[QLatin1String("uuid")].toString());
|
||||
part->setType(partitionObject[QLatin1String("type")].toString());
|
||||
QString attrs = partitionObject[QLatin1String("attrs")].toString();
|
||||
part->setAttributes(SfdiskGptAttributes::toULongLong(attrs.split(QLatin1Char(' '))));
|
||||
}
|
||||
|
||||
if (fs->supportGetUUID() != FileSystem::cmdSupportNone)
|
||||
fs->setUUID(fs->readUUID(part->deviceNode()));
|
||||
|
||||
|
@ -326,6 +318,20 @@ void SfdiskBackend::scanDevicePartitions(Device& d, const QJsonArray& jsonPartit
|
|||
PartitionAlignment::isAligned(d, *part);
|
||||
}
|
||||
|
||||
void SfdiskBackend::setupPartitionInfo(const Device &d, Partition *partition, const QJsonObject& partitionObject, const QString mountPoint)
|
||||
{
|
||||
if (!partition->roles().has(PartitionRole::Luks))
|
||||
readSectorsUsed(d, *partition, mountPoint);
|
||||
|
||||
if (d.partitionTable()->type() == PartitionTable::TableType::gpt) {
|
||||
partition->setLabel(partitionObject[QLatin1String("name")].toString());
|
||||
partition->setUUID(partitionObject[QLatin1String("uuid")].toString());
|
||||
partition->setType(partitionObject[QLatin1String("type")].toString());
|
||||
QString attrs = partitionObject[QLatin1String("attrs")].toString();
|
||||
partition->setAttributes(SfdiskGptAttributes::toULongLong(attrs.split(QLatin1Char(' '))));
|
||||
}
|
||||
}
|
||||
|
||||
bool SfdiskBackend::updateDevicePartitionTable(Device &d, const QJsonObject &jsonPartitionTable)
|
||||
{
|
||||
QString tableType = jsonPartitionTable[QLatin1String("label")].toString();
|
||||
|
|
|
@ -27,6 +27,7 @@
|
|||
#include <QVariant>
|
||||
|
||||
class Device;
|
||||
class Partition;
|
||||
class KPluginFactory;
|
||||
class QString;
|
||||
|
||||
|
@ -59,6 +60,7 @@ public:
|
|||
private:
|
||||
static void readSectorsUsed(const Device& d, Partition& p, const QString& mountPoint);
|
||||
void scanDevicePartitions(Device& d, const QJsonArray& jsonPartitions);
|
||||
void setupPartitionInfo(const Device& d, Partition* partition, const QJsonObject& partitionObject, const QString mountPoint);
|
||||
bool updateDevicePartitionTable(Device& d, const QJsonObject& jsonPartitionTable);
|
||||
static PartitionTable::Flags availableFlags(PartitionTable::TableType type);
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue