[fsresizer] Apply sizes properly
- Distinguish size and atleast; in percentages they mean different things (atleast is a bit weird as a percentage, but hey). - Fix bug in percentage calculation. - Avoid percentage above 100. - Add documentation in config-file.
This commit is contained in:
parent
c725f6b552
commit
aaf27ac2ab
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user