Make it possible to "resize" (aka delete + create for now) existing partitions
This commit is contained in:
parent
df790986ae
commit
3d40527d29
@ -19,6 +19,7 @@
|
||||
#include <CreatePartitionDialog.h>
|
||||
|
||||
#include <PartitionInfo.h>
|
||||
#include <PMUtils.h>
|
||||
#include <ui_CreatePartitionDialog.h>
|
||||
#include <utils/Logger.h>
|
||||
|
||||
@ -137,23 +138,14 @@ CreatePartitionDialog::createPartition()
|
||||
}
|
||||
}
|
||||
|
||||
FileSystem::Type type = m_role.has( PartitionRole::Extended )
|
||||
? FileSystem::Extended
|
||||
: FileSystem::typeForName( m_ui->fsComboBox->currentText() );
|
||||
FileSystem* fs = FileSystemFactory::create( type, m_minSector, lastSector );
|
||||
|
||||
auto partition = new Partition(
|
||||
FileSystem::Type fsType = m_role.has( PartitionRole::Extended )
|
||||
? FileSystem::Extended
|
||||
: FileSystem::typeForName( m_ui->fsComboBox->currentText() );
|
||||
Partition* partition = PMUtils::createNewPartition(
|
||||
m_parent,
|
||||
*m_device,
|
||||
m_role,
|
||||
fs, m_minSector, lastSector,
|
||||
QString() /* path */,
|
||||
PartitionTable::FlagNone /* availableFlags */,
|
||||
QString() /* mountPoint */,
|
||||
false /* mounted */,
|
||||
PartitionTable::FlagNone /* activeFlags */,
|
||||
Partition::StateNew
|
||||
);
|
||||
fsType, m_minSector, lastSector );
|
||||
|
||||
PartitionInfo::setMountPoint( partition, m_ui->mountPointComboBox->currentText() );
|
||||
PartitionInfo::setFormat( partition, true );
|
||||
|
@ -20,6 +20,7 @@
|
||||
|
||||
#include <PartitionCoreModule.h>
|
||||
#include <PartitionInfo.h>
|
||||
#include <PMUtils.h>
|
||||
#include <ui_EditExistingPartitionDialog.h>
|
||||
#include <utils/Logger.h>
|
||||
|
||||
@ -62,8 +63,59 @@ void
|
||||
EditExistingPartitionDialog::applyChanges( PartitionCoreModule* core )
|
||||
{
|
||||
PartitionInfo::setMountPoint( m_partition, m_ui->mountPointComboBox->currentText() );
|
||||
if ( m_ui->formatRadioButton->isChecked() )
|
||||
core->formatPartition( m_device, m_partition );
|
||||
|
||||
qint64 oldSize = mbSizeForSectorRange( m_partition->firstSector(), m_partition->lastSector() );
|
||||
qint64 newSize = m_ui->sizeSpinBox->value();
|
||||
if ( oldSize == newSize )
|
||||
{
|
||||
if ( m_ui->formatRadioButton->isChecked() )
|
||||
core->formatPartition( m_device, m_partition );
|
||||
else
|
||||
core->refreshPartition( m_device, m_partition );
|
||||
}
|
||||
else
|
||||
core->refreshPartition( m_device, m_partition );
|
||||
{
|
||||
// FIXME: Duplicated from CreatePartitionDialog
|
||||
qint64 maxSector = m_partition->lastSector() + m_device->partitionTable()->freeSectorsAfter( *m_partition );
|
||||
|
||||
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 = maxSector;
|
||||
}
|
||||
else
|
||||
{
|
||||
lastSector = m_partition->firstSector() + qint64( mbSize ) * 1024 * 1024 / m_device->logicalSectorSize();
|
||||
Q_ASSERT( lastSector <= maxSector );
|
||||
if ( lastSector > maxSector )
|
||||
{
|
||||
cDebug() << "lastSector (" << lastSector << ") > maxSector (" << maxSector << "). This should not happen!";
|
||||
lastSector = maxSector;
|
||||
}
|
||||
}
|
||||
|
||||
if ( m_ui->formatRadioButton->isChecked() )
|
||||
{
|
||||
Partition* newPartition = PMUtils::createNewPartition(
|
||||
m_partition->parent(),
|
||||
*m_device,
|
||||
m_partition->roles(),
|
||||
m_partition->fileSystem().type(),
|
||||
m_partition->firstSector(),
|
||||
lastSector);
|
||||
PartitionInfo::setMountPoint( newPartition, PartitionInfo::mountPoint( m_partition ) );
|
||||
PartitionInfo::setFormat( newPartition, true );
|
||||
|
||||
core->deletePartition( m_device, m_partition );
|
||||
core->createPartition( m_device, newPartition );
|
||||
}
|
||||
else
|
||||
{
|
||||
//core->resizePartition( m_device, m_partition );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -23,7 +23,7 @@
|
||||
|
||||
// CalaPM
|
||||
#include <core/partition.h>
|
||||
#include <fs/filesystem.h>
|
||||
#include <fs/filesystemfactory.h>
|
||||
|
||||
namespace PMUtils
|
||||
{
|
||||
@ -48,4 +48,22 @@ findPartitionByMountPoint( const QList< Device* >& devices, const QString& mount
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
Partition*
|
||||
createNewPartition( PartitionNode* parent, const Device& device, const PartitionRole& role, FileSystem::Type fsType, qint64 firstSector, qint64 lastSector )
|
||||
{
|
||||
FileSystem* fs = FileSystemFactory::create( fsType, firstSector, lastSector );
|
||||
return new Partition(
|
||||
parent,
|
||||
device,
|
||||
role,
|
||||
fs, fs->firstSector(), fs->lastSector(),
|
||||
QString() /* path */,
|
||||
PartitionTable::FlagNone /* availableFlags */,
|
||||
QString() /* mountPoint */,
|
||||
false /* mounted */,
|
||||
PartitionTable::FlagNone /* activeFlags */,
|
||||
Partition::StateNew
|
||||
);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
@ -18,11 +18,16 @@
|
||||
#ifndef PMUTILS_H
|
||||
#define PMUTILS_H
|
||||
|
||||
// CalaPM
|
||||
#include <fs/filesystem.h>
|
||||
|
||||
// Qt
|
||||
#include <QList>
|
||||
|
||||
class Device;
|
||||
class Partition;
|
||||
class PartitionNode;
|
||||
class PartitionRole;
|
||||
|
||||
namespace PMUtils
|
||||
{
|
||||
@ -33,6 +38,8 @@ bool isPartitionNew( Partition* );
|
||||
|
||||
Partition* findPartitionByMountPoint( const QList< Device* >& devices, const QString& mountPoint );
|
||||
|
||||
Partition* createNewPartition( PartitionNode* parent, const Device& device, const PartitionRole& role, FileSystem::Type fsType, qint64 firstSector, qint64 lastSector );
|
||||
|
||||
}
|
||||
|
||||
#endif /* PMUTILS_H */
|
||||
|
Loading…
Reference in New Issue
Block a user