Add support for setting the GPT partition name.
Hello,
This PR intends to add the support for GPT partition name using the sfdisk
backend.
sfdisk
sets the partition name using the property name= at creation; it can be set later using the option --part-label. See the examples below:
$ cat <<EOF | sfdisk disk.img
label: gpt
name=efi, type=C12A7328-F81F-11D2-BA4B-00A0C93EC93B, size=64M # named efi
type=0FC63DAF-8483-4772-8E79-3D69D8477DE4 # not named yet
EOF
(...)
$ sfdisk --part-label disk.img 2 rootfs
(...)
$ sfdisk --dump disk.img
(...)
disk.img1 : start= 2048, size= 131072, type=C12A7328-F81F-11D2-BA4B-00A0C93EC93B, uuid=D08E5B2A-4649-9F4A-AEA3-6C3048888EAA, name="efi"
disk.img2 : start= 133120, size= 1963999, type=0FC63DAF-8483-4772-8E79-3D69D8477DE4, uuid=0BEEFE82-19EA-DC4C-BB6A-27B6DA0C3BD2, name="rootfs"
Note that the partition name is also known as PARTLABEL
.
I have an earlier version of that PR that added the method bool setPartitionName(Report& report, const Partition& partition)
to the interface CoreBackendPartitionTable
. The class SfdiskPartitionTable
implements the method and the class CreatePartitionJob
used it to name the partition if the partition has a label set.
I do not know which one you prefer.
/**
* Set the name of a partition.
* @param report the report to write information to
* @param partition the partition to set the system type for
* @return true on success
*/
virtual bool setPartitionName(Report& report, const Partition& partition) = 0;
bool SfdiskPartitionTable::setPartitionName(Report& report, const Partition& partition)
{
const QString& partitionName = partition.label();
if (partitionName.isEmpty())
return true;
ExternalCommand sfdiskCommand(report, QStringLiteral("sfdisk"), { QStringLiteral("--part-label"), m_device->deviceNode(), QString::number(partition.number()),
partitionName } );
return sfdiskCommand.run(-1) && sfdiskCommand.exitCode() == 0;
}
bool CreatePartitionJob::run(Report& parent)
{
// ...
if (!partition().label().isEmpty()) {
if (backendPartitionTable->setPartitionName(*report, partition())) {
rval = true;
backendPartitionTable->commit();
} else
report->line() << xi18nc("@info:progress", "Failed to set the name for the partition <filename>%1</filename>.", partition().deviceNode());
}
// ...
}
Regards, Gaël