From 0293015b099bf200597091e805d892ccf6645d8d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Corentin=20No=C3=ABl?= Date: Thu, 1 Oct 2020 15:38:18 +0200 Subject: [PATCH] [partition] Fix regression in partition size assignment In some cases, the partition size was set to zero as the maxSize isn't always defined. --- .../partition/core/PartitionLayout.cpp | 33 +++++++++---------- 1 file changed, 16 insertions(+), 17 deletions(-) diff --git a/src/modules/partition/core/PartitionLayout.cpp b/src/modules/partition/core/PartitionLayout.cpp index eaed27af6..f8f279ce8 100644 --- a/src/modules/partition/core/PartitionLayout.cpp +++ b/src/modules/partition/core/PartitionLayout.cpp @@ -166,14 +166,13 @@ PartitionLayout::execute( Device* dev, QList< Partition* > partList; // Map each partition entry to its requested size (0 when calculated later) QMap< const PartitionLayout::PartitionEntry *, qint64 > partSizeMap; - qint64 minSize, maxSize, end; qint64 totalSize = lastSector - firstSector + 1; qint64 availableSize = totalSize; // Let's check if we have enough space for each partSize - for( const PartitionLayout::PartitionEntry& part : m_partLayout ) + for( const auto& part : qAsConst(m_partLayout) ) { - qint64 size = -1; + qint64 size; // Calculate partition size if ( part.partSize.isValid() ) @@ -201,7 +200,7 @@ PartitionLayout::execute( Device* dev, continue; } - partSizeMap.insert (&part, size); + partSizeMap.insert(&part, size); availableSize -= size; } @@ -209,7 +208,7 @@ PartitionLayout::execute( Device* dev, if (availableSize < 0) { availableSize = totalSize; - for( const PartitionLayout::PartitionEntry& part : m_partLayout ) + for( const auto& part : qAsConst(m_partLayout) ) { qint64 size; @@ -233,19 +232,18 @@ PartitionLayout::execute( Device* dev, size = 0; } - partSizeMap.insert (&part, size); + partSizeMap.insert(&part, size); availableSize -= size; } } // Assign size for percentage-defined partitions - for( const PartitionLayout::PartitionEntry& part : m_partLayout ) + for( const auto& part : qAsConst(m_partLayout) ) { if ( part.partSize.unit() == CalamaresUtils::Partition::SizeUnit::Percent) { - qint64 size = partSizeMap.value (&part); + qint64 size = partSizeMap.value(&part); size = part.partSize.toSectors( availableSize + size, dev->logicalSize() ); - partSizeMap.insert (&part, size); if ( part.partMinSize.isValid() ) { qint64 minSize = part.partMinSize.toSectors( totalSize, dev->logicalSize() ); @@ -262,6 +260,8 @@ PartitionLayout::execute( Device* dev, size = maxSize; } } + + partSizeMap.insert(&part, size); } } @@ -270,21 +270,20 @@ PartitionLayout::execute( Device* dev, // TODO: Refine partition sizes to make sure there is room for every partition // Use a default (200-500M ?) minimum size for partition without minSize - for( const PartitionLayout::PartitionEntry& part : m_partLayout ) + for( const auto& part : qAsConst(m_partLayout) ) { - qint64 size = partSizeMap.value (&part); + qint64 size, end; Partition* currentPartition = nullptr; - // Adjust partition size based on user-defined boundaries and available space - if ( size > maxSize ) - { - size = maxSize; - } + size = partSizeMap.value(&part); + + // Adjust partition size based on available space if ( size > availableSize ) { size = availableSize; } - end = firstSector + size - 1; + + end = firstSector + std::max(size - 1, Q_INT64_C(0)); if ( luksPassphrase.isEmpty() ) {