diff --git a/src/modules/partition/CreatePartitionDialog.cpp b/src/modules/partition/CreatePartitionDialog.cpp index 17ec65765..eec0e3f0c 100644 --- a/src/modules/partition/CreatePartitionDialog.cpp +++ b/src/modules/partition/CreatePartitionDialog.cpp @@ -142,9 +142,7 @@ CreatePartitionDialog::initSectorRange( Partition* partition ) m_minSector = partition->firstSector() - table->freeSectorsBefore( *partition ); m_maxSector = partition->lastSector() + table->freeSectorsAfter( *partition ); - qint64 maxSize = ( m_maxSector - m_minSector + 1 ) * m_device->logicalSectorSize(); - - m_ui->sizeSpinBox->setMaximum( maxSize / 1024 / 1024 ); + m_ui->sizeSpinBox->setMaximum( mbSizeForSectorRange( m_minSector, m_maxSector ) ); m_ui->sizeSpinBox->setValue( m_ui->sizeSpinBox->maximum() ); } @@ -162,8 +160,13 @@ CreatePartitionDialog::initFromPartitionInfo( PartitionInfo* partitionInfo ) initSectorRange( partition ); - qint64 maxSize = ( partition->lastSector() - partition->firstSector() + 1 ) * m_device->logicalSectorSize(); - m_ui->sizeSpinBox->setValue( maxSize / 1024 / 1024 ); + m_ui->sizeSpinBox->setValue( mbSizeForSectorRange( partition->firstSector(), partition->lastSector() ) ); m_ui->mountPointComboBox->setCurrentText( partitionInfo->mountPoint ); } + +qint64 +CreatePartitionDialog::mbSizeForSectorRange( qint64 first, qint64 last ) const +{ + return ( last - first + 1 ) * m_device->logicalSectorSize() / 1024 / 1024; +} diff --git a/src/modules/partition/CreatePartitionDialog.h b/src/modules/partition/CreatePartitionDialog.h index 1f8e0c88a..dd700f558 100644 --- a/src/modules/partition/CreatePartitionDialog.h +++ b/src/modules/partition/CreatePartitionDialog.h @@ -54,6 +54,8 @@ private: PartitionRole m_role = PartitionRole( PartitionRole::None ); void initSectorRange( Partition* ); + + qint64 mbSizeForSectorRange( qint64 first, qint64 last ) const; }; #endif /* CREATEPARTITIONDIALOG_H */