From f4a13b204139cb47bd75d997bcc463fdd9a85461 Mon Sep 17 00:00:00 2001 From: Teo Mrnjavac Date: Thu, 28 May 2015 19:08:53 +0200 Subject: [PATCH] Add EFI System Partition scanning support to PartitionCoreModule. --- .../partition/core/PartitionCoreModule.cpp | 58 +++++++++++++++++++ .../partition/core/PartitionCoreModule.h | 4 ++ 2 files changed, 62 insertions(+) diff --git a/src/modules/partition/core/PartitionCoreModule.cpp b/src/modules/partition/core/PartitionCoreModule.cpp index 2fe301b97..2950d1a2b 100644 --- a/src/modules/partition/core/PartitionCoreModule.cpp +++ b/src/modules/partition/core/PartitionCoreModule.cpp @@ -47,6 +47,8 @@ // Qt #include +#include +#include static bool hasRootPartition( Device* device ) @@ -124,6 +126,10 @@ PartitionCoreModule::init() m_deviceModel->init( devices ); m_bootLoaderModel->init( devices ); + + if ( QDir( "/sys/firmware/efi/efivars" ).exists() ) + scanForEfiSystemPartitions(); //FIXME: this should be removed in favor of + // proper KPM support for EFI } PartitionCoreModule::~PartitionCoreModule() @@ -327,6 +333,12 @@ PartitionCoreModule::hasRootMountPoint() const return m_hasRootMountPoint; } +QList< Partition* > +PartitionCoreModule::efiSystemPartitions() const +{ + return m_efiSystemPartitions; +} + void PartitionCoreModule::dumpQueue() const { @@ -384,6 +396,52 @@ PartitionCoreModule::updateIsDirty() isDirtyChanged( m_isDirty ); } +void +PartitionCoreModule::scanForEfiSystemPartitions() +{ + m_efiSystemPartitions.clear(); + + QList< Device* > devices; + for ( int row = 0; row < deviceModel()->rowCount(); ++row ) + { + Device* device = deviceModel()->deviceForIndex( + deviceModel()->index( row ) ); + devices.append( device ); + } + + //FIXME: Unfortunately right now we have to call sgdisk manually because + // the KPM submodule does not expose the ESP flag from libparted. + // The following findPartitions call and lambda should be scrapped and + // rewritten based on libKPM. -- Teo 5/2015 + QList< Partition* > efiSystemPartitions = + PMUtils::findPartitions( devices, + []( Partition* partition ) -> bool + { + QProcess process; + process.setProgram( "sgdisk" ); + process.setArguments( { "-i", + QString::number( partition->number() ), + partition->devicePath() } ); + process.setProcessChannelMode( QProcess::MergedChannels ); + process.start(); + if ( process.waitForFinished() ) + { + if ( process.readAllStandardOutput() + .contains( "C12A7328-F81F-11D2-BA4B-00A0C93EC93B" ) ) + { + cDebug() << "Found EFI system partition at" << partition->partitionPath(); + return true; + } + } + return false; + } ); + + if ( efiSystemPartitions.isEmpty() ) + cDebug() << "WARNING: system is EFI but no EFI system partitions found."; + + m_efiSystemPartitions = efiSystemPartitions; +} + PartitionCoreModule::DeviceInfo* PartitionCoreModule::infoForDevice( Device* device ) const { diff --git a/src/modules/partition/core/PartitionCoreModule.h b/src/modules/partition/core/PartitionCoreModule.h index 52dee17a8..e0029a0ae 100644 --- a/src/modules/partition/core/PartitionCoreModule.h +++ b/src/modules/partition/core/PartitionCoreModule.h @@ -91,6 +91,8 @@ public: bool hasRootMountPoint() const; + QList< Partition* > efiSystemPartitions() const; + void revert(); void clearJobs(); @@ -134,6 +136,7 @@ private: bool isDirty() const; }; QList< DeviceInfo* > m_deviceInfos; + QList< Partition* > m_efiSystemPartitions; DeviceModel* m_deviceModel; BootLoaderModel* m_bootLoaderModel; @@ -144,6 +147,7 @@ private: void init(); void updateHasRootMountPoint(); void updateIsDirty(); + void scanForEfiSystemPartitions(); DeviceInfo* infoForDevice( Device* ) const;