From bf9c9a64f1b6900b81eb15dbe1f0ccbe7f35c1cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=ABl=20PORTAY?= Date: Wed, 28 Oct 2020 10:11:57 -0400 Subject: [PATCH] [libcalamares] Introduce new function getPartitionTable --- src/libcalamares/partition/PartitionQuery.cpp | 14 ++++++++++++++ src/libcalamares/partition/PartitionQuery.h | 5 +++++ src/modules/partition/core/PartUtils.cpp | 15 +-------------- 3 files changed, 20 insertions(+), 14 deletions(-) diff --git a/src/libcalamares/partition/PartitionQuery.cpp b/src/libcalamares/partition/PartitionQuery.cpp index 4c9c1549d..0356f920c 100644 --- a/src/libcalamares/partition/PartitionQuery.cpp +++ b/src/libcalamares/partition/PartitionQuery.cpp @@ -16,6 +16,7 @@ #include #include +#include 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 ) { diff --git a/src/libcalamares/partition/PartitionQuery.h b/src/libcalamares/partition/PartitionQuery.h index 9ef5f41f6..364c747fe 100644 --- a/src/libcalamares/partition/PartitionQuery.h +++ b/src/libcalamares/partition/PartitionQuery.h @@ -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* ); diff --git a/src/modules/partition/core/PartUtils.cpp b/src/modules/partition/core/PartUtils.cpp index 92bcbace0..065f88d99 100644 --- a/src/modules/partition/core/PartUtils.cpp +++ b/src/modules/partition/core/PartUtils.cpp @@ -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";