Allow setting boot, esp and bios-grub flags in sfdisk backend.

This commit is contained in:
Andrius Štikonas 2017-11-08 00:01:24 +00:00
parent 80de99fc73
commit d3cde41df0
3 changed files with 40 additions and 10 deletions

View File

@ -323,7 +323,7 @@ bool LibPartedPartitionTable::setPartitionSystemType(Report& report, const Parti
return ped_partition_set_system(pedPartition, pedFsType) != 0; 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; PedPartition* pedPartition;
if (partition.roles().has(PartitionRole::Extended)) if (partition.roles().has(PartitionRole::Extended))
@ -336,17 +336,17 @@ bool LibPartedPartitionTable::setFlag(Report& report, const Partition& partition
return false; return false;
} }
const PedPartitionFlag f = LibPartedBackend::getPedFlag(partitionManagerFlag); const PedPartitionFlag f = LibPartedBackend::getPedFlag(flag);
// ignore flags that don't exist for this partition // ignore flags that don't exist for this partition
if (!ped_partition_is_flag_available(pedPartition, f)) { 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; return true;
} }
// Workaround: libparted claims the hidden flag is available for extended partitions, but // 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. // 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; return true;
if (!ped_partition_set_flag(pedPartition, f, state ? 1 : 0)) if (!ped_partition_set_flag(pedPartition, f, state ? 1 : 0))

View File

@ -50,7 +50,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 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 flag, bool state) override;
private: private:
PedDevice* pedDevice() { PedDevice* pedDevice() {

View File

@ -164,12 +164,42 @@ bool SfdiskPartitionTable::setPartitionSystemType(Report& report, const Partitio
return true; 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) if (flag == PartitionTable::FlagBoot && state == true) {
Q_UNUSED(partition) ExternalCommand sfdiskCommand(report, QStringLiteral("sfdisk"), { QStringLiteral("--activate"), m_deviceNode, QString::number(partition.number()) } );
Q_UNUSED(partitionManagerFlag) if (sfdiskCommand.run(-1) && sfdiskCommand.exitCode() == 0)
Q_UNUSED(state) 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; return true;
} }