From 94b6c95c4443d8266e52663fb5ba787085bf1b5a Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Tue, 9 Jan 2018 10:53:33 -0500 Subject: [PATCH] [partition] Introduce function for checking various flag-combinations for ESP boot. --- src/modules/partition/core/PartUtils.cpp | 22 ++++++++++++++++++++++ src/modules/partition/core/PartUtils.h | 5 +++++ 2 files changed, 27 insertions(+) diff --git a/src/modules/partition/core/PartUtils.cpp b/src/modules/partition/core/PartUtils.cpp index 4a7253f92..a8e004979 100644 --- a/src/modules/partition/core/PartUtils.cpp +++ b/src/modules/partition/core/PartUtils.cpp @@ -340,4 +340,26 @@ isEfiSystem() return QDir( "/sys/firmware/efi/efivars" ).exists(); } +bool +isEfiBootable( const Partition* candidate ) +{ + /* If bit 17 is set, old-style Esp flag, it's OK */ + if ( candidate->activeFlags().testFlag( PartitionTable::FlagEsp ) ) + return true; + + + /* Otherwise, if it's a GPT table, Boot (bit 0) is the same as Esp */ + const PartitionNode* root = candidate; + while ( root && !root->isRoot() ) + root = root->parent(); + + // Strange case: no root found, no partition table node? + if ( !root ) + return false; + + const PartitionTable* table = dynamic_cast( root ); + return table && ( table->type() == PartitionTable::TableType::gpt ) && + candidate->activeFlags().testFlag( PartitionTable::FlagBoot ); +} + } // nmamespace PartUtils diff --git a/src/modules/partition/core/PartUtils.h b/src/modules/partition/core/PartUtils.h index 144e9e45b..c81258712 100644 --- a/src/modules/partition/core/PartUtils.h +++ b/src/modules/partition/core/PartUtils.h @@ -67,6 +67,11 @@ OsproberEntryList runOsprober( PartitionCoreModule* core ); */ bool isEfiSystem(); +/** + * @brief Is the given @p partition bootable in EFI? Depending on + * the partition table layout, this may mean different flags. + */ +bool isEfiBootable( const Partition* candidate ); } #endif // PARTUTILS_H