@ -21,6 +21,8 @@
# include "GlobalStorage.h"
# include "JobQueue.h"
# include "utils/Logger.h"
# include "core/PartitionLayout.h"
# include "core/KPMHelpers.h"
@ -69,37 +71,67 @@ PartitionLayout::~PartitionLayout()
{
}
void
bool
PartitionLayout : : addEntry ( PartitionLayout : : PartitionEntry entry )
{
if ( ! entry . isValid ( ) )
{
cError ( ) < < " Partition size is invalid or has min size > max size " ;
return false ;
}
m_partLayout . append ( entry ) ;
return true ;
}
PartitionLayout : : PartitionEntry : : PartitionEntry ( const QString & size , const QString & min , const QString & max )
{
partSize = PartUtils : : PartSize ( size ) ;
if ( ! min . isEmpty ( ) )
partMinSize = PartUtils : : PartSize ( min ) ;
if ( ! max . isEmpty ( ) )
partMaxSize = PartUtils : : PartSize ( max ) ;
partMinSize = PartUtils : : PartSize ( min ) ;
partMaxSize = PartUtils : : PartSize ( max ) ;
}
void
bool
PartitionLayout : : addEntry ( const QString & mountPoint , const QString & size , const QString & min , const QString & max )
{
PartitionLayout : : PartitionEntry entry ( size , min , max ) ;
if ( ! entry . isValid ( ) )
{
cError ( ) < < " Partition size " < < size < < " is invalid or " < < min < < " > " < < max ;
return false ;
}
if ( mountPoint . isEmpty ( ) | | ! mountPoint . startsWith ( QString ( " / " ) ) )
{
cError ( ) < < " Partition mount point " < < mountPoint < < " is invalid " ;
return false ;
}
entry . partMountPoint = mountPoint ;
entry . partFileSystem = m_defaultFsType ;
m_partLayout . append ( entry ) ;
return true ;
}
void
bool
PartitionLayout : : addEntry ( const QString & label , const QString & mountPoint , const QString & fs , const QString & size , const QString & min , const QString & max )
{
PartitionLayout : : PartitionEntry entry ( size , min , max ) ;
if ( ! entry . isValid ( ) )
{
cError ( ) < < " Partition size " < < size < < " is invalid or " < < min < < " > " < < max ;
return false ;
}
if ( mountPoint . isEmpty ( ) | | ! mountPoint . startsWith ( QString ( " / " ) ) )
{
cError ( ) < < " Partition mount point " < < mountPoint < < " is invalid " ;
return false ;
}
entry . partLabel = label ;
entry . partMountPoint = mountPoint ;
PartUtils : : findFS ( fs , & entry . partFileSystem ) ;
@ -107,6 +139,8 @@ PartitionLayout::addEntry( const QString& label, const QString& mountPoint, cons
entry . partFileSystem = m_defaultFsType ;
m_partLayout . append ( entry ) ;
return true ;
}
QList < Partition * >
@ -128,9 +162,36 @@ PartitionLayout::execute( Device *dev, qint64 firstSector,
Partition * currentPartition = nullptr ;
// Calculate partition size
size = part . partSize . toSectors ( totalSize , dev - > logicalSize ( ) ) ;
minSize = part . partMinSize . toSectors ( totalSize , dev - > logicalSize ( ) ) ;
maxSize = part . partMaxSize . toSectors ( totalSize , dev - > logicalSize ( ) ) ;
if ( part . partSize . isValid ( ) )
{
size = part . partSize . toSectors ( totalSize , dev - > logicalSize ( ) ) ;
}
else
{
cWarning ( ) < < " Partition " < < part . partMountPoint < < " size ( "
< < size < < " sectors) is invalid, skipping... " ;
continue ;
}
if ( part . partMinSize . isValid ( ) )
minSize = part . partMinSize . toSectors ( totalSize , dev - > logicalSize ( ) ) ;
else
minSize = 0 ;
if ( part . partMaxSize . isValid ( ) )
maxSize = part . partMaxSize . toSectors ( totalSize , dev - > logicalSize ( ) ) ;
else
maxSize = availableSize ;
// Make sure we never go under minSize once converted to sectors
if ( maxSize < minSize )
{
cWarning ( ) < < " Partition " < < part . partMountPoint < < " max size ( " < < maxSize
< < " sectors) is < min size ( " < < minSize < < " sectors), using min size " ;
maxSize = minSize ;
}
// Adjust partition size based on user-defined boundaries and available space
if ( size < minSize )
size = minSize ;
if ( size > maxSize )