[partition] Introduce function for checking various flag-combinations for ESP boot.

This commit is contained in:
Adriaan de Groot 2018-01-09 10:53:33 -05:00
parent 3ff68bce98
commit 94b6c95c44
2 changed files with 27 additions and 0 deletions

View File

@ -340,4 +340,26 @@ isEfiSystem()
return QDir( "/sys/firmware/efi/efivars" ).exists(); 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<const PartitionTable*>( root );
return table && ( table->type() == PartitionTable::TableType::gpt ) &&
candidate->activeFlags().testFlag( PartitionTable::FlagBoot );
}
} // nmamespace PartUtils } // nmamespace PartUtils

View File

@ -67,6 +67,11 @@ OsproberEntryList runOsprober( PartitionCoreModule* core );
*/ */
bool isEfiSystem(); 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 #endif // PARTUTILS_H