[libcalamares] Introduce new function getPartitionTable

This commit is contained in:
Gaël PORTAY 2020-10-28 10:11:57 -04:00
parent c963d8905f
commit bf9c9a64f1
3 changed files with 20 additions and 14 deletions

View File

@ -16,6 +16,7 @@
#include <kpmcore/core/device.h>
#include <kpmcore/core/partition.h>
#include <kpmcore/core/partitiontable.h>
namespace CalamaresUtils
{
@ -26,6 +27,19 @@ namespace Partition
using ::Device;
using ::Partition;
const PartitionTable*
getPartitionTable( const Partition* partition )
{
const PartitionNode* root = partition;
while ( root && !root->isRoot() )
{
root = root->parent();
}
return dynamic_cast< const PartitionTable* >( root );
}
bool
isPartitionFreeSpace( const Partition* partition )
{

View File

@ -24,6 +24,7 @@
class Device;
class Partition;
class PartitionTable;
namespace CalamaresUtils
{
@ -32,6 +33,10 @@ namespace Partition
using ::Device;
using ::Partition;
using ::PartitionTable;
/** @brief Get partition table */
const PartitionTable* getPartitionTable( const Partition* partition );
/** @brief Is this a free-space area? */
bool isPartitionFreeSpace( const Partition* );

View File

@ -454,20 +454,7 @@ isEfiBootable( const Partition* candidate )
}
/* 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 )
{
cWarning() << "No root of partition table found.";
return false;
}
const PartitionTable* table = dynamic_cast< const PartitionTable* >( root );
const PartitionTable* table = CalamaresUtils::Partition::getPartitionTable( candidate );
if ( !table )
{
cWarning() << "Root of partition table is not a PartitionTable object";