Store the generated partitition UUID after creation
The GPT UUID are generated by the backends automatically once a partition is created. This reads the UUID that was generated after the creation of a partition and stores it back to the object Partition.
This commit is contained in:
parent
1dde035705
commit
e12f0ec391
|
@ -103,6 +103,16 @@ public:
|
||||||
*/
|
*/
|
||||||
virtual bool updateGeometry(Report& report, const Partition& partition, qint64 sector_start, qint64 sector_end) = 0;
|
virtual bool updateGeometry(Report& report, const Partition& partition, qint64 sector_start, qint64 sector_end) = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the UUID of a partition in the partition table (GPT only).
|
||||||
|
* The partition UUID is known as PARTUUID by several utilities. The device-manager links
|
||||||
|
* the device under /dev/disk/by-partuuid/<uuid>.
|
||||||
|
* @param report the report to write information to
|
||||||
|
* @param partition the partition to get the UUID for
|
||||||
|
* @return the partition UUID
|
||||||
|
*/
|
||||||
|
virtual QString getPartitionUUID(Report& report, const Partition& partition) = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the label of a partition in the partition table (GPT only).
|
* Set the label of a partition in the partition table (GPT only).
|
||||||
* The label is set in the GPT partition name entry. The partition name is known as PARTLABEL by
|
* The label is set in the GPT partition name entry. The partition name is known as PARTLABEL by
|
||||||
|
|
|
@ -64,6 +64,10 @@ bool CreatePartitionJob::run(Report& parent)
|
||||||
partition().setPartitionPath(partitionPath);
|
partition().setPartitionPath(partitionPath);
|
||||||
partition().setState(Partition::State::None);
|
partition().setState(Partition::State::None);
|
||||||
backendPartitionTable->commit();
|
backendPartitionTable->commit();
|
||||||
|
// The UUID is supported by GPT only; it is generated automatically once the creation of a partition.
|
||||||
|
// Store the generated UUID to the partition object if no UUID is set.
|
||||||
|
if (m_Device.partitionTable()->type() == PartitionTable::gpt && partition().uuid().isEmpty())
|
||||||
|
partition().setUUID(backendPartitionTable->getPartitionUUID(*report, partition()));
|
||||||
} else
|
} else
|
||||||
report->line() << xi18nc("@info/plain", "Failed to add partition <filename>%1</filename> to device <filename>%2</filename>.", partition().deviceNode(), device().deviceNode());
|
report->line() << xi18nc("@info/plain", "Failed to add partition <filename>%1</filename> to device <filename>%2</filename>.", partition().deviceNode(), device().deviceNode());
|
||||||
} else
|
} else
|
||||||
|
|
|
@ -117,6 +117,14 @@ bool DummyPartitionTable::setPartitionLabel(Report& report, const Partition& par
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString DummyPartitionTable::getPartitionUUID(Report& report, const Partition& partition)
|
||||||
|
{
|
||||||
|
Q_UNUSED(report)
|
||||||
|
Q_UNUSED(partition)
|
||||||
|
|
||||||
|
return QString();
|
||||||
|
}
|
||||||
|
|
||||||
bool DummyPartitionTable::setPartitionUUID(Report& report, const Partition& partition, const QString& uuid)
|
bool DummyPartitionTable::setPartitionUUID(Report& report, const Partition& partition, const QString& uuid)
|
||||||
{
|
{
|
||||||
Q_UNUSED(report)
|
Q_UNUSED(report)
|
||||||
|
|
|
@ -47,6 +47,7 @@ public:
|
||||||
bool resizeFileSystem(Report& report, const Partition& partition, qint64 newLength) override;
|
bool resizeFileSystem(Report& report, const Partition& partition, qint64 newLength) override;
|
||||||
FileSystem::Type detectFileSystemBySector(Report& report, const Device& device, qint64 sector) override;
|
FileSystem::Type detectFileSystemBySector(Report& report, const Device& device, qint64 sector) override;
|
||||||
bool setPartitionLabel(Report& report, const Partition& partition, const QString& label) override;
|
bool setPartitionLabel(Report& report, const Partition& partition, const QString& label) override;
|
||||||
|
QString getPartitionUUID(Report& report, const Partition& partition) override;
|
||||||
bool setPartitionUUID(Report& report, const Partition& partition, const QString& uuid) override;
|
bool setPartitionUUID(Report& report, const Partition& partition, const QString& uuid) override;
|
||||||
bool setPartitionSystemType(Report& report, const Partition& partition) override;
|
bool setPartitionSystemType(Report& report, const Partition& partition) override;
|
||||||
bool setFlag(Report& report, const Partition& partition, PartitionTable::Flag partitionManagerFlag, bool state) override;
|
bool setFlag(Report& report, const Partition& partition, PartitionTable::Flag partitionManagerFlag, bool state) override;
|
||||||
|
|
|
@ -222,6 +222,21 @@ bool SfdiskPartitionTable::setPartitionLabel(Report& report, const Partition& pa
|
||||||
return sfdiskCommand.run(-1) && sfdiskCommand.exitCode() == 0;
|
return sfdiskCommand.run(-1) && sfdiskCommand.exitCode() == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString SfdiskPartitionTable::getPartitionUUID(Report& report, const Partition& partition)
|
||||||
|
{
|
||||||
|
ExternalCommand sfdiskCommand(report, QStringLiteral("sfdisk"), { QStringLiteral("--list"), QStringLiteral("--output"), QStringLiteral("Device,UUID"),
|
||||||
|
m_device->deviceNode() });
|
||||||
|
if (sfdiskCommand.run(-1) && sfdiskCommand.exitCode() == 0) {
|
||||||
|
QRegularExpression re(m_device->deviceNode() + QString::number(partition.number()) + QStringLiteral(" +(.+)"));
|
||||||
|
QRegularExpressionMatch rem = re.match(sfdiskCommand.output());
|
||||||
|
|
||||||
|
if (rem.hasMatch())
|
||||||
|
return rem.captured(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
return QString();
|
||||||
|
}
|
||||||
|
|
||||||
bool SfdiskPartitionTable::setPartitionUUID(Report& report, const Partition& partition, const QString& uuid)
|
bool SfdiskPartitionTable::setPartitionUUID(Report& report, const Partition& partition, const QString& uuid)
|
||||||
{
|
{
|
||||||
if (uuid.isEmpty())
|
if (uuid.isEmpty())
|
||||||
|
|
|
@ -47,6 +47,7 @@ public:
|
||||||
bool resizeFileSystem(Report& report, const Partition& partition, qint64 newLength) override;
|
bool resizeFileSystem(Report& report, const Partition& partition, qint64 newLength) override;
|
||||||
FileSystem::Type detectFileSystemBySector(Report& report, const Device& device, qint64 sector) override;
|
FileSystem::Type detectFileSystemBySector(Report& report, const Device& device, qint64 sector) override;
|
||||||
bool setPartitionLabel(Report& report, const Partition& partition, const QString& label) override;
|
bool setPartitionLabel(Report& report, const Partition& partition, const QString& label) override;
|
||||||
|
QString getPartitionUUID(Report& report, const Partition& partition) override;
|
||||||
bool setPartitionUUID(Report& report, const Partition& partition, const QString& uuid) override;
|
bool setPartitionUUID(Report& report, const Partition& partition, const QString& uuid) override;
|
||||||
bool setPartitionSystemType(Report& report, const Partition& partition) override;
|
bool setPartitionSystemType(Report& report, const Partition& partition) override;
|
||||||
bool setFlag(Report& report, const Partition& partition, PartitionTable::Flag flag, bool state) override;
|
bool setFlag(Report& report, const Partition& partition, PartitionTable::Flag flag, bool state) override;
|
||||||
|
|
Loading…
Reference in New Issue