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 <CreatePartitionDialog.h>
|
||||||
|
|
||||||
#include <PartitionInfo.h>
|
#include <PartitionInfo.h>
|
||||||
|
#include <PMUtils.h>
|
||||||
#include <ui_CreatePartitionDialog.h>
|
#include <ui_CreatePartitionDialog.h>
|
||||||
#include <utils/Logger.h>
|
#include <utils/Logger.h>
|
||||||
|
|
||||||
@ -137,23 +138,14 @@ CreatePartitionDialog::createPartition()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
FileSystem::Type type = m_role.has( PartitionRole::Extended )
|
FileSystem::Type fsType = m_role.has( PartitionRole::Extended )
|
||||||
? FileSystem::Extended
|
? FileSystem::Extended
|
||||||
: FileSystem::typeForName( m_ui->fsComboBox->currentText() );
|
: FileSystem::typeForName( m_ui->fsComboBox->currentText() );
|
||||||
FileSystem* fs = FileSystemFactory::create( type, m_minSector, lastSector );
|
Partition* partition = PMUtils::createNewPartition(
|
||||||
|
|
||||||
auto partition = new Partition(
|
|
||||||
m_parent,
|
m_parent,
|
||||||
*m_device,
|
*m_device,
|
||||||
m_role,
|
m_role,
|
||||||
fs, m_minSector, lastSector,
|
fsType, m_minSector, lastSector );
|
||||||
QString() /* path */,
|
|
||||||
PartitionTable::FlagNone /* availableFlags */,
|
|
||||||
QString() /* mountPoint */,
|
|
||||||
false /* mounted */,
|
|
||||||
PartitionTable::FlagNone /* activeFlags */,
|
|
||||||
Partition::StateNew
|
|
||||||
);
|
|
||||||
|
|
||||||
PartitionInfo::setMountPoint( partition, m_ui->mountPointComboBox->currentText() );
|
PartitionInfo::setMountPoint( partition, m_ui->mountPointComboBox->currentText() );
|
||||||
PartitionInfo::setFormat( partition, true );
|
PartitionInfo::setFormat( partition, true );
|
||||||
|
@ -20,6 +20,7 @@
|
|||||||
|
|
||||||
#include <PartitionCoreModule.h>
|
#include <PartitionCoreModule.h>
|
||||||
#include <PartitionInfo.h>
|
#include <PartitionInfo.h>
|
||||||
|
#include <PMUtils.h>
|
||||||
#include <ui_EditExistingPartitionDialog.h>
|
#include <ui_EditExistingPartitionDialog.h>
|
||||||
#include <utils/Logger.h>
|
#include <utils/Logger.h>
|
||||||
|
|
||||||
@ -62,8 +63,59 @@ void
|
|||||||
EditExistingPartitionDialog::applyChanges( PartitionCoreModule* core )
|
EditExistingPartitionDialog::applyChanges( PartitionCoreModule* core )
|
||||||
{
|
{
|
||||||
PartitionInfo::setMountPoint( m_partition, m_ui->mountPointComboBox->currentText() );
|
PartitionInfo::setMountPoint( m_partition, m_ui->mountPointComboBox->currentText() );
|
||||||
|
|
||||||
|
qint64 oldSize = mbSizeForSectorRange( m_partition->firstSector(), m_partition->lastSector() );
|
||||||
|
qint64 newSize = m_ui->sizeSpinBox->value();
|
||||||
|
if ( oldSize == newSize )
|
||||||
|
{
|
||||||
if ( m_ui->formatRadioButton->isChecked() )
|
if ( m_ui->formatRadioButton->isChecked() )
|
||||||
core->formatPartition( m_device, m_partition );
|
core->formatPartition( m_device, m_partition );
|
||||||
else
|
else
|
||||||
core->refreshPartition( m_device, m_partition );
|
core->refreshPartition( m_device, m_partition );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// 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
|
// CalaPM
|
||||||
#include <core/partition.h>
|
#include <core/partition.h>
|
||||||
#include <fs/filesystem.h>
|
#include <fs/filesystemfactory.h>
|
||||||
|
|
||||||
namespace PMUtils
|
namespace PMUtils
|
||||||
{
|
{
|
||||||
@ -48,4 +48,22 @@ findPartitionByMountPoint( const QList< Device* >& devices, const QString& mount
|
|||||||
return nullptr;
|
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
|
} // namespace
|
||||||
|
@ -18,11 +18,16 @@
|
|||||||
#ifndef PMUTILS_H
|
#ifndef PMUTILS_H
|
||||||
#define PMUTILS_H
|
#define PMUTILS_H
|
||||||
|
|
||||||
|
// CalaPM
|
||||||
|
#include <fs/filesystem.h>
|
||||||
|
|
||||||
// Qt
|
// Qt
|
||||||
#include <QList>
|
#include <QList>
|
||||||
|
|
||||||
class Device;
|
class Device;
|
||||||
class Partition;
|
class Partition;
|
||||||
|
class PartitionNode;
|
||||||
|
class PartitionRole;
|
||||||
|
|
||||||
namespace PMUtils
|
namespace PMUtils
|
||||||
{
|
{
|
||||||
@ -33,6 +38,8 @@ bool isPartitionNew( Partition* );
|
|||||||
|
|
||||||
Partition* findPartitionByMountPoint( const QList< Device* >& devices, const QString& mountPoint );
|
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 */
|
#endif /* PMUTILS_H */
|
||||||
|
Loading…
Reference in New Issue
Block a user