Merge pull request #1117 from a-wai/partition-layout-add-maxsize

[partition] Add max size parameter
main
Adriaan de Groot 6 years ago committed by GitHub
commit 547dc7d334
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -788,6 +788,7 @@ PartitionCoreModule::initLayout( const QVariantList& config )
{ {
QString sizeString; QString sizeString;
QString minSizeString; QString minSizeString;
QString maxSizeString;
m_partLayout = new PartitionLayout(); m_partLayout = new PartitionLayout();
@ -805,11 +806,17 @@ PartitionCoreModule::initLayout( const QVariantList& config )
else else
minSizeString = CalamaresUtils::getString( pentry, "minSize" ); minSizeString = CalamaresUtils::getString( pentry, "minSize" );
if ( pentry.contains("maxSize") && CalamaresUtils::getString( pentry, "maxSize" ).isEmpty() )
maxSizeString.setNum( CalamaresUtils::getInteger( pentry, "maxSize", 100 ) );
else
maxSizeString = CalamaresUtils::getString( pentry, "maxSize" );
m_partLayout->addEntry( CalamaresUtils::getString( pentry, "name" ), m_partLayout->addEntry( CalamaresUtils::getString( pentry, "name" ),
CalamaresUtils::getString( pentry, "mountPoint" ), CalamaresUtils::getString( pentry, "mountPoint" ),
CalamaresUtils::getString( pentry, "filesystem" ), CalamaresUtils::getString( pentry, "filesystem" ),
sizeString, sizeString,
minSizeString minSizeString,
maxSizeString
); );
} }
} }

@ -75,17 +75,19 @@ PartitionLayout::addEntry( PartitionLayout::PartitionEntry entry )
m_partLayout.append( entry ); m_partLayout.append( entry );
} }
PartitionLayout::PartitionEntry::PartitionEntry(const QString& size, const QString& min) PartitionLayout::PartitionEntry::PartitionEntry( const QString& size, const QString& min, const QString& max )
{ {
partSize = PartUtils::parseSizeString( size , &partSizeUnit ); partSize = PartUtils::parseSizeString( size , &partSizeUnit );
if ( !min.isEmpty() ) if ( !min.isEmpty() )
partMinSize = PartUtils::parseSizeString( min , &partMinSizeUnit ); partMinSize = PartUtils::parseSizeString( min , &partMinSizeUnit );
if ( !max.isEmpty() )
partMaxSize = PartUtils::parseSizeString( max , &partMaxSizeUnit );
} }
void void
PartitionLayout::addEntry( const QString& mountPoint, const QString& size, const QString& min ) PartitionLayout::addEntry( const QString& mountPoint, const QString& size, const QString& min, const QString& max )
{ {
PartitionLayout::PartitionEntry entry( size, min ); PartitionLayout::PartitionEntry entry( size, min, max );
entry.partMountPoint = mountPoint; entry.partMountPoint = mountPoint;
entry.partFileSystem = m_defaultFsType; entry.partFileSystem = m_defaultFsType;
@ -94,9 +96,9 @@ PartitionLayout::addEntry( const QString& mountPoint, const QString& size, const
} }
void void
PartitionLayout::addEntry( const QString& label, const QString& mountPoint, const QString& fs, const QString& size, const QString& min ) 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 ); PartitionLayout::PartitionEntry entry( size, min, max );
entry.partLabel = label; entry.partLabel = label;
entry.partMountPoint = mountPoint; entry.partMountPoint = mountPoint;
@ -114,7 +116,7 @@ PartitionLayout::execute( Device *dev, qint64 firstSector,
const PartitionRole& role ) const PartitionRole& role )
{ {
QList< Partition* > partList; QList< Partition* > partList;
qint64 size, minSize, end; qint64 size, minSize, maxSize, end;
qint64 totalSize = lastSector - firstSector + 1; qint64 totalSize = lastSector - firstSector + 1;
qint64 availableSize = totalSize; qint64 availableSize = totalSize;
@ -128,8 +130,11 @@ PartitionLayout::execute( Device *dev, qint64 firstSector,
// Calculate partition size // Calculate partition size
size = PartUtils::sizeToSectors( part.partSize, part.partSizeUnit, totalSize, dev->logicalSize() ); size = PartUtils::sizeToSectors( part.partSize, part.partSizeUnit, totalSize, dev->logicalSize() );
minSize = PartUtils::sizeToSectors( part.partMinSize, part.partMinSizeUnit, totalSize, dev->logicalSize() ); minSize = PartUtils::sizeToSectors( part.partMinSize, part.partMinSizeUnit, totalSize, dev->logicalSize() );
maxSize = PartUtils::sizeToSectors( part.partMaxSize, part.partMaxSizeUnit, totalSize, dev->logicalSize() );
if ( size < minSize ) if ( size < minSize )
size = minSize; size = minSize;
if ( size > maxSize )
size = maxSize;
if ( size > availableSize ) if ( size > availableSize )
size = availableSize; size = availableSize;
end = firstSector + size - 1; end = firstSector + size - 1;

@ -47,11 +47,13 @@ public:
PartUtils::SizeUnit partSizeUnit = PartUtils::SizeUnit::Percent; PartUtils::SizeUnit partSizeUnit = PartUtils::SizeUnit::Percent;
double partMinSize = 0.0L; double partMinSize = 0.0L;
PartUtils::SizeUnit partMinSizeUnit = PartUtils::SizeUnit::Percent; PartUtils::SizeUnit partMinSizeUnit = PartUtils::SizeUnit::Percent;
double partMaxSize = 100.0L;
PartUtils::SizeUnit partMaxSizeUnit = PartUtils::SizeUnit::Percent;
/// @brief All-zeroes PartitionEntry /// @brief All-zeroes PartitionEntry
PartitionEntry() {}; PartitionEntry() {};
/// @brief Parse @p size and @p min to their respective member variables /// @brief Parse @p size, @p min and @p max to their respective member variables
PartitionEntry( const QString& size, const QString& min ); PartitionEntry( const QString& size, const QString& min, const QString& max );
}; };
PartitionLayout(); PartitionLayout();
@ -60,8 +62,8 @@ public:
~PartitionLayout(); ~PartitionLayout();
void addEntry( PartitionEntry entry ); void addEntry( PartitionEntry entry );
void addEntry( const QString& mountPoint, const QString& size, const QString& min = QString() ); void addEntry( const QString& mountPoint, const QString& size, const QString& min = QString(), const QString& max = QString() );
void addEntry( const QString& label, const QString& mountPoint, const QString& fs, const QString& size, const QString& min = QString() ); void addEntry( const QString& label, const QString& mountPoint, const QString& fs, const QString& size, const QString& min = QString(), const QString& max = QString() );
/** /**
* @brief Apply the current partition layout to the selected drive space. * @brief Apply the current partition layout to the selected drive space.

@ -100,6 +100,7 @@ defaultFileSystemType: "ext4"
# mountPoint: "/" # mountPoint: "/"
# size: 20% # size: 20%
# minSize: 500M # minSize: 500M
# maxSize: 10G
# - name: "home" # - name: "home"
# filesystem: "ext4" # filesystem: "ext4"
# mountPoint: "/home" # mountPoint: "/home"
@ -118,3 +119,4 @@ defaultFileSystemType: "ext4"
# or # or
# % of the available drive space if a '%' is appended to the value # % of the available drive space if a '%' is appended to the value
# - minSize: minimum partition size (optional parameter) # - minSize: minimum partition size (optional parameter)
# - maxSize: maximum partition size (optional parameter)

Loading…
Cancel
Save