diff --git a/src/modules/fsresizer/ResizeFSJob.cpp b/src/modules/fsresizer/ResizeFSJob.cpp index 0d10c5583..f71f010bd 100644 --- a/src/modules/fsresizer/ResizeFSJob.cpp +++ b/src/modules/fsresizer/ResizeFSJob.cpp @@ -68,31 +68,48 @@ ResizeFSJob::RelativeSize::RelativeSize( const QString& s) { matchUnitSuffix( s, "%", Percent, m_value, m_unit ); matchUnitSuffix( s, "MiB", Absolute, m_value, m_unit ); + + if ( ( unit() == Percent ) && ( value() > 100 ) ) + { + cDebug() << "Percent value" << value() << "is not valid."; + m_value = 0; + m_unit = None; + } if ( !m_value ) m_unit = None; } qint64 -ResizeFSJob::RelativeSize::apply( Device* d ) +ResizeFSJob::RelativeSize::apply( qint64 totalSectors , qint64 sectorSize ) { if ( !isValid() ) return -1; - + if ( sectorSize < 1 ) + return -1; + switch( m_unit ) { case None: return -1; case Absolute: - return CalamaresUtils::MiBtoBytes( value() ) / d->logicalSize(); + return CalamaresUtils::MiBtoBytes( value() ) / sectorSize; case Percent: - return d->logicalSize() * value() / 100; + if ( value() == 100 ) + return totalSectors; // Common-case, avoid futzing around + else + return totalSectors * value() / 100; } // notreached return -1; } +qint64 +ResizeFSJob::RelativeSize::apply( Device* d ) +{ + return apply( d->totalLogical(), d->logicalSize() ); +} ResizeFSJob::ResizeFSJob( QObject* parent ) : Calamares::CppJob( parent ) @@ -150,9 +167,11 @@ qint64 ResizeFSJob::findGrownEnd(ResizeFSJob::PartitionMatch m) { if ( !m.first || !m.second ) - return -1; + return -1; // Missing device data if ( !ResizeOperation::canGrow( m.second ) ) - return -1; + return -1; // Operation is doomed + if ( !m_size.isValid() ) + return -1; // Must have a grow-size cDebug() << "Containing device size" << m.first->totalLogical(); qint64 last_available = m.first->totalLogical() - 1; // Numbered from 0 @@ -198,6 +217,13 @@ ResizeFSJob::findGrownEnd(ResizeFSJob::PartitionMatch m) } } + qint64 wanted = m_size.apply( expand, m.first->logicalSize() ); + if ( wanted < expand ) + { + cDebug() << ".. only growing by" << wanted << "instead of full" << expand; + last_available -= ( expand - wanted ); + } + return last_available; } diff --git a/src/modules/fsresizer/ResizeFSJob.h b/src/modules/fsresizer/ResizeFSJob.h index 36527ab56..063495e7d 100644 --- a/src/modules/fsresizer/ResizeFSJob.h +++ b/src/modules/fsresizer/ResizeFSJob.h @@ -64,15 +64,23 @@ public: return ( unit() != None ) && ( value() > 0 ); } - /** @brief Apply this size to the given device @p d + /** @brief Apply this size to the number of sectors @p totalSectors . * + * Each sector has size @p sectorSize , for converting absolute + * sizes in MiB to sector counts. + * * For invalid sizes, returns -1. * For absolute sizes, returns the number of sectors needed. - * For percent sizes, returns the number of sectors matching - * that percentage of the device size. + * For percent sizes, returns that percent of the number of sectors. + */ + qint64 apply( qint64 totalSectors, qint64 sectorSize ); + + /** @brief Apply this size to the given device. + * + * Equivalent to apply( d->totalLogical(), d->logicalSize() ) */ qint64 apply( Device* d ); - + private: int m_value; Unit m_unit; diff --git a/src/modules/fsresizer/fsresizer.conf b/src/modules/fsresizer/fsresizer.conf index f02983e45..06141fc7d 100644 --- a/src/modules/fsresizer/fsresizer.conf +++ b/src/modules/fsresizer/fsresizer.conf @@ -23,6 +23,8 @@ fs: / # how big the card is), use MiB as suffix in that case. # If missing, then it's assumed to be 0, and no resizing # will happen. +# +# Percentages apply to **available space**. size: 100% # Resizing might not be worth it, though. Set the minimum @@ -30,4 +32,6 @@ size: 100% # resizing is skipped. Can be in percentage or absolute # size, as above. If missing, then it's assumed to be 0, # which means resizing is always worthwhile. +# +# Percentages apply to **total device size**. atleast: 1000MiB