[partition] Simplify space calculations

- Q_ASSERT doesn't work in constexpr functions because it's not
 - May as well calculate bytes at compile-time, no need to give
   the runaround via number-of-MiB
This commit is contained in:
Adriaan de Groot 2018-09-13 05:33:39 -04:00
parent 959cd7b224
commit 8c79c981b1

View File

@ -83,10 +83,7 @@ swapSuggestion( const qint64 availableSpaceB )
constexpr qint64 constexpr qint64
alignBytesToBlockSize( qint64 bytes, qint64 blocksize ) alignBytesToBlockSize( qint64 bytes, qint64 blocksize )
{ {
Q_ASSERT( bytes >= 0 );
Q_ASSERT( blocksize > 0 );
qint64 blocks = bytes / blocksize; qint64 blocks = bytes / blocksize;
Q_ASSERT( blocks >= 0 );
if ( blocks * blocksize != bytes ) if ( blocks * blocksize != bytes )
++blocks; ++blocks;
@ -114,17 +111,17 @@ doAutopartition( PartitionCoreModule* core, Device* dev, const QString& luksPass
// the logical sector size (usually 512B). EFI starts with 2MiB // the logical sector size (usually 512B). EFI starts with 2MiB
// empty and a 300MiB EFI boot partition, while BIOS starts at // empty and a 300MiB EFI boot partition, while BIOS starts at
// the 1MiB boundary (usually sector 2048). // the 1MiB boundary (usually sector 2048).
int uefisys_part_size = isEfi ? 300 : 0; int uefisys_part_sizeB = isEfi ? 300_MiB : 0_MiB;
int empty_space_size = isEfi ? 2 : 1; int empty_space_sizeB = isEfi ? 2_MiB : 1_MiB;
// Since sectors count from 0, if the space is 2048 sectors in size, // Since sectors count from 0, if the space is 2048 sectors in size,
// the first free sector has number 2048 (and there are 2048 sectors // the first free sector has number 2048 (and there are 2048 sectors
// before that one, numbered 0..2047). // before that one, numbered 0..2047).
qint64 firstFreeSector = bytesToSectors( MiBtoBytes(empty_space_size), dev->logicalSize() ); qint64 firstFreeSector = bytesToSectors( empty_space_sizeB, dev->logicalSize() );
if ( isEfi ) if ( isEfi )
{ {
qint64 efiSectorCount = bytesToSectors( MiBtoBytes(uefisys_part_size), dev->logicalSize() ); qint64 efiSectorCount = bytesToSectors( uefisys_part_sizeB, dev->logicalSize() );
Q_ASSERT( efiSectorCount > 0 ); Q_ASSERT( efiSectorCount > 0 );
// Since sectors count from 0, and this partition is created starting // Since sectors count from 0, and this partition is created starting