[partition] Use unsigned sizes
Reduce warnings by using unsigned consistently; this fights the KPMCore API (which uses signed sizes for, e.g. sectorSize) a little, but states more clearly that a disk cannot have a negative size.
This commit is contained in:
parent
8ce92d450c
commit
9b0ef5fce5
@ -30,8 +30,8 @@
|
|||||||
|
|
||||||
using namespace CalamaresUtils::Units;
|
using namespace CalamaresUtils::Units;
|
||||||
|
|
||||||
static qint64
|
static quint64
|
||||||
swapSuggestion( const qint64 availableSpaceB, Config::SwapChoice swap )
|
swapSuggestion( const quint64 availableSpaceB, Config::SwapChoice swap )
|
||||||
{
|
{
|
||||||
if ( ( swap != Config::SwapChoice::SmallSwap ) && ( swap != Config::SwapChoice::FullSwap ) )
|
if ( ( swap != Config::SwapChoice::SmallSwap ) && ( swap != Config::SwapChoice::FullSwap ) )
|
||||||
{
|
{
|
||||||
@ -39,10 +39,8 @@ swapSuggestion( const qint64 availableSpaceB, Config::SwapChoice swap )
|
|||||||
}
|
}
|
||||||
|
|
||||||
// See partition.conf for explanation
|
// See partition.conf for explanation
|
||||||
qint64 suggestedSwapSizeB = 0;
|
quint64 suggestedSwapSizeB = 0;
|
||||||
auto memory = CalamaresUtils::System::instance()->getTotalMemoryB();
|
auto [ availableRamB, overestimationFactor ] = CalamaresUtils::System::instance()->getTotalMemoryB();
|
||||||
qint64 availableRamB = memory.first;
|
|
||||||
qreal overestimationFactor = memory.second;
|
|
||||||
|
|
||||||
bool ensureSuspendToDisk = swap == Config::SwapChoice::FullSwap;
|
bool ensureSuspendToDisk = swap == Config::SwapChoice::FullSwap;
|
||||||
|
|
||||||
@ -63,12 +61,13 @@ swapSuggestion( const qint64 availableSpaceB, Config::SwapChoice swap )
|
|||||||
// .. top out at 8GiB if we don't care about suspend
|
// .. top out at 8GiB if we don't care about suspend
|
||||||
if ( !ensureSuspendToDisk )
|
if ( !ensureSuspendToDisk )
|
||||||
{
|
{
|
||||||
suggestedSwapSizeB = qMin( 8_GiB, suggestedSwapSizeB );
|
// TODO: make the _GiB operator return unsigned
|
||||||
|
suggestedSwapSizeB = qMin( quint64( 8_GiB ), suggestedSwapSizeB );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Allow for a fudge factor
|
// Allow for a fudge factor
|
||||||
suggestedSwapSizeB = qRound64( qreal( suggestedSwapSizeB ) * overestimationFactor );
|
suggestedSwapSizeB = quint64( qRound64( qreal( suggestedSwapSizeB ) * overestimationFactor ) );
|
||||||
|
|
||||||
// don't use more than 10% of available space
|
// don't use more than 10% of available space
|
||||||
if ( !ensureSuspendToDisk )
|
if ( !ensureSuspendToDisk )
|
||||||
@ -76,6 +75,7 @@ swapSuggestion( const qint64 availableSpaceB, Config::SwapChoice swap )
|
|||||||
suggestedSwapSizeB = qMin( suggestedSwapSizeB, availableSpaceB / 10 /* 10% is 0.1 */ );
|
suggestedSwapSizeB = qMin( suggestedSwapSizeB, availableSpaceB / 10 /* 10% is 0.1 */ );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: make Units functions work on unsigned
|
||||||
cDebug() << "Suggested swap size:" << CalamaresUtils::BytesToGiB( suggestedSwapSizeB ) << "GiB";
|
cDebug() << "Suggested swap size:" << CalamaresUtils::BytesToGiB( suggestedSwapSizeB ) << "GiB";
|
||||||
|
|
||||||
return suggestedSwapSizeB;
|
return suggestedSwapSizeB;
|
||||||
@ -147,16 +147,17 @@ doAutopartition( PartitionCoreModule* core, Device* dev, Choices::AutoPartitionO
|
|||||||
const bool mayCreateSwap
|
const bool mayCreateSwap
|
||||||
= ( o.swap == Config::SwapChoice::SmallSwap ) || ( o.swap == Config::SwapChoice::FullSwap );
|
= ( o.swap == Config::SwapChoice::SmallSwap ) || ( o.swap == Config::SwapChoice::FullSwap );
|
||||||
bool shouldCreateSwap = false;
|
bool shouldCreateSwap = false;
|
||||||
qint64 suggestedSwapSizeB = 0;
|
quint64 suggestedSwapSizeB = 0;
|
||||||
|
|
||||||
|
const quint64 sectorSize = quint64( dev->logicalSize() );
|
||||||
if ( mayCreateSwap )
|
if ( mayCreateSwap )
|
||||||
{
|
{
|
||||||
qint64 availableSpaceB = ( dev->totalLogical() - firstFreeSector ) * dev->logicalSize();
|
quint64 availableSpaceB = quint64( dev->totalLogical() - firstFreeSector ) * sectorSize;
|
||||||
suggestedSwapSizeB = swapSuggestion( availableSpaceB, o.swap );
|
suggestedSwapSizeB = swapSuggestion( availableSpaceB, o.swap );
|
||||||
// Space required by this installation is what the distro claims is needed
|
// Space required by this installation is what the distro claims is needed
|
||||||
// (via global configuration) plus the swap size plus a fudge factor of
|
// (via global configuration) plus the swap size plus a fudge factor of
|
||||||
// 0.6GiB (this was 2.1GiB up to Calamares 3.2.2).
|
// 0.6GiB (this was 2.1GiB up to Calamares 3.2.2).
|
||||||
qint64 requiredSpaceB = o.requiredSpaceB + 600_MiB + suggestedSwapSizeB;
|
quint64 requiredSpaceB = o.requiredSpaceB + 600_MiB + suggestedSwapSizeB;
|
||||||
|
|
||||||
// If there is enough room for ESP + root + swap, create swap, otherwise don't.
|
// If there is enough room for ESP + root + swap, create swap, otherwise don't.
|
||||||
shouldCreateSwap = availableSpaceB > requiredSpaceB;
|
shouldCreateSwap = availableSpaceB > requiredSpaceB;
|
||||||
@ -165,7 +166,7 @@ doAutopartition( PartitionCoreModule* core, Device* dev, Choices::AutoPartitionO
|
|||||||
qint64 lastSectorForRoot = dev->totalLogical() - 1; //last sector of the device
|
qint64 lastSectorForRoot = dev->totalLogical() - 1; //last sector of the device
|
||||||
if ( shouldCreateSwap )
|
if ( shouldCreateSwap )
|
||||||
{
|
{
|
||||||
lastSectorForRoot -= suggestedSwapSizeB / dev->logicalSize() + 1;
|
lastSectorForRoot -= suggestedSwapSizeB / sectorSize + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
core->layoutApply( dev, firstFreeSector, lastSectorForRoot, o.luksPassphrase );
|
core->layoutApply( dev, firstFreeSector, lastSectorForRoot, o.luksPassphrase );
|
||||||
|
@ -44,7 +44,7 @@ struct ReplacePartitionOptions
|
|||||||
struct AutoPartitionOptions : ReplacePartitionOptions
|
struct AutoPartitionOptions : ReplacePartitionOptions
|
||||||
{
|
{
|
||||||
QString efiPartitionMountPoint; // optional, e.g. "/boot"
|
QString efiPartitionMountPoint; // optional, e.g. "/boot"
|
||||||
qint64 requiredSpaceB; // estimated required space for root partition
|
quint64 requiredSpaceB; // estimated required space for root partition
|
||||||
Config::SwapChoice swap;
|
Config::SwapChoice swap;
|
||||||
|
|
||||||
AutoPartitionOptions( const QString& pt,
|
AutoPartitionOptions( const QString& pt,
|
||||||
@ -55,7 +55,7 @@ struct AutoPartitionOptions : ReplacePartitionOptions
|
|||||||
Config::SwapChoice s )
|
Config::SwapChoice s )
|
||||||
: ReplacePartitionOptions( pt, fs, luks )
|
: ReplacePartitionOptions( pt, fs, luks )
|
||||||
, efiPartitionMountPoint( efi )
|
, efiPartitionMountPoint( efi )
|
||||||
, requiredSpaceB( requiredBytes > 0 ? requiredBytes : 0 )
|
, requiredSpaceB( requiredBytes > 0 ? quint64( requiredBytes ) : 0U )
|
||||||
, swap( s )
|
, swap( s )
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user