Avoid potential rounding errors

This commit is contained in:
Aurélien Gâteau 2014-07-16 10:35:09 +02:00
parent 45dda6fa17
commit 27b28a5bd1

View File

@ -20,6 +20,7 @@
#include <PartitionInfo.h>
#include <ui_CreatePartitionDialog.h>
#include <utils/Logger.h>
// CalaPM
#include <core/device.h>
@ -93,19 +94,33 @@ CreatePartitionDialog::createPartitionInfo()
);
}
// FIXME: Check rounding errors here
qint64 last = m_minSector + qint64( m_ui->sizeSpinBox->value() ) * 1024 * 1024 / m_device->logicalSectorSize();
qint64 lastSector;
int mbSize = m_ui->sizeSpinBox->value();
if ( mbSize == m_ui->sizeSpinBox->maximum() ) {
// If we are at the maximum value, select the last sector to avoid
// potential rounding errors which could leave a few sectors at the end
// unused
lastSector = m_maxSector;
} else {
lastSector = m_minSector + qint64( mbSize ) * 1024 * 1024 / m_device->logicalSectorSize();
Q_ASSERT( lastSector <= m_maxSector );
if ( lastSector > m_maxSector )
{
cDebug() << "lastSector (" << lastSector << ") > m_maxSector (" << m_maxSector << "). This should not happen!";
lastSector = m_maxSector;
}
}
FileSystem::Type type = m_role.has( PartitionRole::Extended )
? FileSystem::Extended
: FileSystem::typeForName( m_ui->fsComboBox->currentText() );
FileSystem* fs = FileSystemFactory::create( type, m_minSector, last );
FileSystem* fs = FileSystemFactory::create( type, m_minSector, lastSector );
auto partition = new Partition(
m_parent,
*m_device,
m_role,
fs, m_minSector, last,
fs, m_minSector, lastSector,
QString() /* path */,
PartitionTable::FlagNone /* availableFlags */,
QString() /* mountPoint */,