Allow setting boot, esp and bios-grub flags in sfdisk backend.
This commit is contained in:
parent
80de99fc73
commit
d3cde41df0
|
@ -323,7 +323,7 @@ bool LibPartedPartitionTable::setPartitionSystemType(Report& report, const Parti
|
|||
return ped_partition_set_system(pedPartition, pedFsType) != 0;
|
||||
}
|
||||
|
||||
bool LibPartedPartitionTable::setFlag(Report& report, const Partition& partition, PartitionTable::Flag partitionManagerFlag, bool state)
|
||||
bool LibPartedPartitionTable::setFlag(Report& report, const Partition& partition, PartitionTable::Flag flag, bool state)
|
||||
{
|
||||
PedPartition* pedPartition;
|
||||
if (partition.roles().has(PartitionRole::Extended))
|
||||
|
@ -336,17 +336,17 @@ bool LibPartedPartitionTable::setFlag(Report& report, const Partition& partition
|
|||
return false;
|
||||
}
|
||||
|
||||
const PedPartitionFlag f = LibPartedBackend::getPedFlag(partitionManagerFlag);
|
||||
const PedPartitionFlag f = LibPartedBackend::getPedFlag(flag);
|
||||
|
||||
// ignore flags that don't exist for this partition
|
||||
if (!ped_partition_is_flag_available(pedPartition, f)) {
|
||||
report.line() << xi18nc("@info:progress", "The flag \"%1\" is not available on the partition's partition table.", PartitionTable::flagName(partitionManagerFlag));
|
||||
report.line() << xi18nc("@info:progress", "The flag \"%1\" is not available on the partition's partition table.", PartitionTable::flagName(flag));
|
||||
return true;
|
||||
}
|
||||
|
||||
// Workaround: libparted claims the hidden flag is available for extended partitions, but
|
||||
// throws an error when we try to set or clear it. So skip this combination.
|
||||
if (pedPartition->type == PED_PARTITION_EXTENDED && partitionManagerFlag == PartitionTable::FlagHidden)
|
||||
if (pedPartition->type == PED_PARTITION_EXTENDED && flag == PartitionTable::FlagHidden)
|
||||
return true;
|
||||
|
||||
if (!ped_partition_set_flag(pedPartition, f, state ? 1 : 0))
|
||||
|
|
|
@ -50,7 +50,7 @@ public:
|
|||
bool resizeFileSystem(Report& report, const Partition& partition, qint64 newLength) override;
|
||||
FileSystem::Type detectFileSystemBySector(Report& report, const Device& device, qint64 sector) 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 flag, bool state) override;
|
||||
|
||||
private:
|
||||
PedDevice* pedDevice() {
|
||||
|
|
|
@ -164,12 +164,42 @@ bool SfdiskPartitionTable::setPartitionSystemType(Report& report, const Partitio
|
|||
return true;
|
||||
}
|
||||
|
||||
bool SfdiskPartitionTable::setFlag(Report& report, const Partition& partition, PartitionTable::Flag partitionManagerFlag, bool state)
|
||||
bool SfdiskPartitionTable::setFlag(Report& report, const Partition& partition, PartitionTable::Flag flag, bool state)
|
||||
{
|
||||
Q_UNUSED(report)
|
||||
Q_UNUSED(partition)
|
||||
Q_UNUSED(partitionManagerFlag)
|
||||
Q_UNUSED(state)
|
||||
if (flag == PartitionTable::FlagBoot && state == true) {
|
||||
ExternalCommand sfdiskCommand(report, QStringLiteral("sfdisk"), { QStringLiteral("--activate"), m_deviceNode, QString::number(partition.number()) } );
|
||||
if (sfdiskCommand.run(-1) && sfdiskCommand.exitCode() == 0)
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
} else if (flag == PartitionTable::FlagBoot && state == false) {
|
||||
ExternalCommand sfdiskCommand(report, QStringLiteral("sfdisk"), { QStringLiteral("--activate"), m_deviceNode, QStringLiteral("-") } );
|
||||
if (sfdiskCommand.run(-1) && sfdiskCommand.exitCode() == 0)
|
||||
return true;
|
||||
// FIXME: Do not return false since we have no way of checking if partition table is MBR
|
||||
}
|
||||
|
||||
if (flag == PartitionTable::FlagEsp && state == true) {
|
||||
ExternalCommand sfdiskCommand(report, QStringLiteral("sfdisk"), { QStringLiteral("--part-type"), m_deviceNode, QString::number(partition.number()),
|
||||
QStringLiteral("C12A7328-F81F-11D2-BA4B-00A0C93EC93B") } );
|
||||
if (sfdiskCommand.run(-1) && sfdiskCommand.exitCode() == 0)
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
if (flag == PartitionTable::FlagEsp && state == false)
|
||||
setPartitionSystemType(report, partition);
|
||||
|
||||
if (flag == PartitionTable::FlagBiosGrub && state == true) {
|
||||
ExternalCommand sfdiskCommand(report, QStringLiteral("sfdisk"), { QStringLiteral("--part-type"), m_deviceNode, QString::number(partition.number()),
|
||||
QStringLiteral("21686148-6449-6E6F-744E-656564454649") } );
|
||||
if (sfdiskCommand.run(-1) && sfdiskCommand.exitCode() == 0)
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
if (flag == PartitionTable::FlagBiosGrub && state == false)
|
||||
setPartitionSystemType(report, partition);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue