From 759ccae9f6eeb49fdac54ff7f12d9366c4133c29 Mon Sep 17 00:00:00 2001 From: Teo Mrnjavac Date: Fri, 22 Apr 2016 16:49:58 +0200 Subject: [PATCH] Tentative LUKS support for EraseAutopartition. Partitioning only, install doesn't work yet. --- .../partition/core/PartitionActions.cpp | 66 ++++++++++++++----- src/modules/partition/core/PartitionActions.h | 11 +++- 2 files changed, 58 insertions(+), 19 deletions(-) diff --git a/src/modules/partition/core/PartitionActions.cpp b/src/modules/partition/core/PartitionActions.cpp index 67d73782f..00cf32abe 100644 --- a/src/modules/partition/core/PartitionActions.cpp +++ b/src/modules/partition/core/PartitionActions.cpp @@ -98,7 +98,7 @@ swapSuggestion( const qint64 availableSpaceB ) void -doAutopartition( PartitionCoreModule* core, Device* dev ) +doAutopartition( PartitionCoreModule* core, Device* dev, const QString& luksPassphrase ) { bool isEfi = false; if ( QDir( "/sys/firmware/efi/efivars" ).exists() ) @@ -167,28 +167,60 @@ doAutopartition( PartitionCoreModule* core, Device* dev ) lastSectorForRoot -= suggestedSwapSizeB / dev->logicalSectorSize() + 1; } - Partition* rootPartition = KPMHelpers::createNewPartition( - dev->partitionTable(), - *dev, - PartitionRole( PartitionRole::Primary ), - FileSystem::Ext4, - firstFreeSector, - lastSectorForRoot - ); + Partition* rootPartition = nullptr; + if ( luksPassphrase.isEmpty() ) + { + rootPartition = KPMHelpers::createNewPartition( + dev->partitionTable(), + *dev, + PartitionRole( PartitionRole::Primary ), + FileSystem::Ext4, + firstFreeSector, + lastSectorForRoot + ); + } + else + { + rootPartition = KPMHelpers::createNewEncryptedPartition( + dev->partitionTable(), + *dev, + PartitionRole( PartitionRole::Primary ), + FileSystem::Ext4, + firstFreeSector, + lastSectorForRoot, + luksPassphrase + ); + } PartitionInfo::setFormat( rootPartition, true ); PartitionInfo::setMountPoint( rootPartition, "/" ); core->createPartition( dev, rootPartition ); if ( shouldCreateSwap ) { - Partition* swapPartition = KPMHelpers::createNewPartition( - dev->partitionTable(), - *dev, - PartitionRole( PartitionRole::Primary ), - FileSystem::LinuxSwap, - lastSectorForRoot + 1, - dev->totalSectors() - 1 - ); + Partition* swapPartition = nullptr; + if ( luksPassphrase.isEmpty() ) + { + swapPartition = KPMHelpers::createNewPartition( + dev->partitionTable(), + *dev, + PartitionRole( PartitionRole::Primary ), + FileSystem::LinuxSwap, + lastSectorForRoot + 1, + dev->totalSectors() - 1 + ); + } + else + { + swapPartition = KPMHelpers::createNewEncryptedPartition( + dev->partitionTable(), + *dev, + PartitionRole( PartitionRole::Primary ), + FileSystem::LinuxSwap, + lastSectorForRoot + 1, + dev->totalSectors() - 1, + luksPassphrase + ); + } PartitionInfo::setFormat( swapPartition, true ); core->createPartition( dev, swapPartition ); } diff --git a/src/modules/partition/core/PartitionActions.h b/src/modules/partition/core/PartitionActions.h index f1056edfd..bf0559a49 100644 --- a/src/modules/partition/core/PartitionActions.h +++ b/src/modules/partition/core/PartitionActions.h @@ -19,14 +19,21 @@ #ifndef PARTITIONACTIONS_H #define PARTITIONACTIONS_H +#include + class PartitionCoreModule; class Device; class Partition; namespace PartitionActions { -void doAutopartition( PartitionCoreModule* core, Device* dev ); -void doReplacePartition( PartitionCoreModule* core, Device* dev, Partition* partition ); +void doAutopartition( PartitionCoreModule* core, + Device* dev, + const QString& luksPassphrase = QString() ); + +void doReplacePartition( PartitionCoreModule* core, + Device* dev, + Partition* partition ); } #endif // PARTITIONACTIONS_H