From 3b15884f83b76e9a5c6405dd30c4072790964a72 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Mon, 28 Aug 2017 05:36:21 -0400 Subject: [PATCH] Refactor check for EFI system. The TODO stands, to delegate this to KPMCore. --- src/modules/partition/core/PartUtils.cpp | 10 ++++++++-- src/modules/partition/core/PartUtils.h | 5 +++++ src/modules/partition/core/PartitionActions.cpp | 5 ++--- src/modules/partition/core/PartitionCoreModule.cpp | 4 ++-- src/modules/partition/gui/BootInfoWidget.cpp | 9 +++------ src/modules/partition/gui/ChoicePage.cpp | 6 +++--- src/modules/partition/gui/CreatePartitionDialog.cpp | 5 +++-- .../partition/gui/EditExistingPartitionDialog.cpp | 3 ++- src/modules/partition/gui/PartitionPage.cpp | 3 ++- src/modules/partition/gui/PartitionViewStep.cpp | 2 +- 10 files changed, 31 insertions(+), 21 deletions(-) diff --git a/src/modules/partition/core/PartUtils.cpp b/src/modules/partition/core/PartUtils.cpp index 6aeffa7fb..df230311a 100644 --- a/src/modules/partition/core/PartUtils.cpp +++ b/src/modules/partition/core/PartUtils.cpp @@ -151,7 +151,7 @@ canBeResized( PartitionCoreModule* core, const QString& partitionPath ) } -FstabEntryList +static FstabEntryList lookForFstabEntries( const QString& partitionPath ) { FstabEntryList fstabEntries; @@ -195,7 +195,7 @@ lookForFstabEntries( const QString& partitionPath ) } -QString +static QString findPartitionPathForMountPoint( const FstabEntryList& fstab, const QString& mountPoint ) { @@ -328,4 +328,10 @@ runOsprober( PartitionCoreModule* core ) return osproberEntries; } +bool +isEfiSystem() +{ + return QDir( "/sys/firmware/efi/efivars" ).exists(); +} + } // nmamespace PartUtils diff --git a/src/modules/partition/core/PartUtils.h b/src/modules/partition/core/PartUtils.h index 21d995965..c8d0714f0 100644 --- a/src/modules/partition/core/PartUtils.h +++ b/src/modules/partition/core/PartUtils.h @@ -62,6 +62,11 @@ bool canBeResized( PartitionCoreModule* core, const QString& partitionPath ); */ OsproberEntryList runOsprober( PartitionCoreModule* core ); +/** + * @brief Is this system EFI-enabled? Decides based on /sys/firmware/efi + */ +bool isEfiSystem(); + } #endif // PARTUTILS_H diff --git a/src/modules/partition/core/PartitionActions.cpp b/src/modules/partition/core/PartitionActions.cpp index dbb7e4000..14e7bf010 100644 --- a/src/modules/partition/core/PartitionActions.cpp +++ b/src/modules/partition/core/PartitionActions.cpp @@ -22,6 +22,7 @@ #include "core/KPMHelpers.h" #include "core/PartitionInfo.h" #include "core/PartitionCoreModule.h" +#include "core/PartUtils.h" #include "utils/CalamaresUtilsSystem.h" #include "JobQueue.h" @@ -118,9 +119,7 @@ doAutopartition( PartitionCoreModule* core, Device* dev, const QString& luksPass { Calamares::GlobalStorage* gs = Calamares::JobQueue::instance()->globalStorage(); - bool isEfi = false; - if ( QDir( "/sys/firmware/efi/efivars" ).exists() ) - isEfi = true; + bool isEfi = PartUtils::isEfiSystem(); QString defaultFsType = gs->value( "defaultFileSystemType" ).toString(); if ( FileSystem::typeForName( defaultFsType ) == FileSystem::Unknown ) diff --git a/src/modules/partition/core/PartitionCoreModule.cpp b/src/modules/partition/core/PartitionCoreModule.cpp index 26cc0f597..ac22b2b7a 100644 --- a/src/modules/partition/core/PartitionCoreModule.cpp +++ b/src/modules/partition/core/PartitionCoreModule.cpp @@ -167,7 +167,7 @@ PartitionCoreModule::doInit() //FIXME: this should be removed in favor of // proper KPM support for EFI - if ( QDir( "/sys/firmware/efi/efivars" ).exists() ) + if ( PartUtils::isEfiSystem() ) scanForEfiSystemPartitions(); } @@ -461,7 +461,7 @@ PartitionCoreModule::refresh() //FIXME: this should be removed in favor of // proper KPM support for EFI - if ( QDir( "/sys/firmware/efi/efivars" ).exists() ) + if ( PartUtils::isEfiSystem() ) scanForEfiSystemPartitions(); } diff --git a/src/modules/partition/gui/BootInfoWidget.cpp b/src/modules/partition/gui/BootInfoWidget.cpp index 605144271..c24f28121 100644 --- a/src/modules/partition/gui/BootInfoWidget.cpp +++ b/src/modules/partition/gui/BootInfoWidget.cpp @@ -18,8 +18,9 @@ #include "BootInfoWidget.h" +#include "core/PartUtils.h" -#include +#include "utils/CalamaresUtilsGui.h" #include #include @@ -64,12 +65,8 @@ BootInfoWidget::BootInfoWidget( QWidget* parent ) "may also show up as BIOS if started in compatibility " "mode." ) ); - bool isEfi = false; - if ( QDir( "/sys/firmware/efi/efivars" ).exists() ) - isEfi = true; - QString bootToolTip; - if ( isEfi ) + if ( PartUtils::isEfiSystem() ) { m_bootLabel->setText( "EFI " ); bootToolTip = tr( "This system was started with an EFI " diff --git a/src/modules/partition/gui/ChoicePage.cpp b/src/modules/partition/gui/ChoicePage.cpp index 16a4547fc..76c65a027 100644 --- a/src/modules/partition/gui/ChoicePage.cpp +++ b/src/modules/partition/gui/ChoicePage.cpp @@ -146,7 +146,7 @@ void ChoicePage::init( PartitionCoreModule* core ) { m_core = core; - m_isEfi = QDir( "/sys/firmware/efi/efivars" ).exists(); + m_isEfi = PartUtils::isEfiSystem(); setupChoices(); @@ -680,7 +680,7 @@ ChoicePage::doReplaceSelectedPartition( const QModelIndex& current ) m_core->revertDevice( selectedDevice() ); } - // if the partition is unallocated(free space), we don't replace it but create new one + // if the partition is unallocated(free space), we don't replace it but create new one // with the same first and last sector Partition* selectedPartition = static_cast< Partition* >( current.data( PartitionModel::PartitionPtrRole ) @@ -1311,7 +1311,7 @@ ChoicePage::setupActions() m_grp->setExclusive( true ); } - bool isEfi = QDir( "/sys/firmware/efi/efivars" ).exists(); + bool isEfi = PartUtils::isEfiSystem(); bool efiSystemPartitionFound = !m_core->efiSystemPartitions().isEmpty(); if ( isEfi && !efiSystemPartitionFound ) diff --git a/src/modules/partition/gui/CreatePartitionDialog.cpp b/src/modules/partition/gui/CreatePartitionDialog.cpp index 4cd22bf68..90cf92051 100644 --- a/src/modules/partition/gui/CreatePartitionDialog.cpp +++ b/src/modules/partition/gui/CreatePartitionDialog.cpp @@ -21,6 +21,7 @@ #include "core/ColorUtils.h" #include "core/PartitionInfo.h" +#include "core/PartUtils.h" #include "core/KPMHelpers.h" #include "gui/PartitionSizeController.h" @@ -66,12 +67,12 @@ CreatePartitionDialog::CreatePartitionDialog( Device* device, PartitionNode* par m_ui->encryptWidget->hide(); QStringList mountPoints = { "/", "/boot", "/home", "/opt", "/usr", "/var" }; - if ( QDir( "/sys/firmware/efi/efivars" ).exists() ) + if ( PartUtils::isEfiSystem() ) mountPoints << Calamares::JobQueue::instance()->globalStorage()->value( "efiSystemPartition" ).toString(); mountPoints.removeDuplicates(); mountPoints.sort(); m_ui->mountPointComboBox->addItems( mountPoints ); - + if ( device->partitionTable()->type() == PartitionTable::msdos || device->partitionTable()->type() == PartitionTable::msdos_sectorbased ) initMbrPartitionTypeUi(); diff --git a/src/modules/partition/gui/EditExistingPartitionDialog.cpp b/src/modules/partition/gui/EditExistingPartitionDialog.cpp index 1909e48e8..e213b8731 100644 --- a/src/modules/partition/gui/EditExistingPartitionDialog.cpp +++ b/src/modules/partition/gui/EditExistingPartitionDialog.cpp @@ -26,6 +26,7 @@ #include #include #include +#include "core/PartUtils.h" #include #include @@ -56,7 +57,7 @@ EditExistingPartitionDialog::EditExistingPartitionDialog( Device* device, Partit m_ui->setupUi( this ); QStringList mountPoints = { "/", "/boot", "/home", "/opt", "/usr", "/var" }; - if ( QDir( "/sys/firmware/efi/efivars" ).exists() ) + if ( PartUtils::isEfiSystem() ) mountPoints << Calamares::JobQueue::instance()->globalStorage()->value( "efiSystemPartition" ).toString(); mountPoints.removeDuplicates(); mountPoints.sort(); diff --git a/src/modules/partition/gui/PartitionPage.cpp b/src/modules/partition/gui/PartitionPage.cpp index 1d807a939..5d541c4e2 100644 --- a/src/modules/partition/gui/PartitionPage.cpp +++ b/src/modules/partition/gui/PartitionPage.cpp @@ -25,6 +25,7 @@ #include "core/PartitionCoreModule.h" #include "core/PartitionInfo.h" #include "core/PartitionModel.h" +#include "core/PartUtils.h" #include "core/KPMHelpers.h" #include "gui/CreatePartitionDialog.h" #include "gui/EditExistingPartitionDialog.h" @@ -59,7 +60,7 @@ PartitionPage::PartitionPage( PartitionCoreModule* core, QWidget* parent ) , m_core( core ) , m_isEfi( false ) { - m_isEfi = QDir( "/sys/firmware/efi/efivars" ).exists(); + m_isEfi = PartUtils::isEfiSystem(); m_ui->setupUi( this ); m_ui->partitionLabelsView->setVisible( diff --git a/src/modules/partition/gui/PartitionViewStep.cpp b/src/modules/partition/gui/PartitionViewStep.cpp index b7dd7724a..7f113ce88 100644 --- a/src/modules/partition/gui/PartitionViewStep.cpp +++ b/src/modules/partition/gui/PartitionViewStep.cpp @@ -386,7 +386,7 @@ PartitionViewStep::onLeave() if ( m_widget->currentWidget() == m_manualPartitionPage ) { - if ( QDir( "/sys/firmware/efi/efivars" ).exists() ) + if ( PartUtils::isEfiSystem() ) { QString espMountPoint = Calamares::JobQueue::instance()->globalStorage()-> value( "efiSystemPartition").toString();