partition: simplify Arm code

- introduce a helper function for accessing the globalstorage value
- add consts and calculate the initial gap in a single expression
This commit is contained in:
Adriaan de Groot 2023-06-25 22:21:01 +02:00
parent baf580f0ac
commit e7161443d6
3 changed files with 16 additions and 19 deletions

View File

@ -441,17 +441,16 @@ runOsprober( DeviceModel* dm )
} }
bool bool
isEfiSystem() isArmSystem()
{ {
Calamares::GlobalStorage* gs = Calamares::JobQueue::instance()->globalStorage(); Calamares::GlobalStorage* gs = Calamares::JobQueue::instance()->globalStorage();
if ( gs->contains( "armInstall" ) && gs->value( "armInstall" ).toBool() ) return gs->contains( "armInstall" ) && gs->value( "armInstall" ).toBool() );
{ }
return true;
} bool
else isEfiSystem()
{ {
return QDir( "/sys/firmware/efi/efivars" ).exists(); return isArmSystem() || QDir( "/sys/firmware/efi/efivars" ).exists();
}
} }
bool bool

View File

@ -77,6 +77,11 @@ bool canBeResized( DeviceModel* dm, const QString& partitionPath, const Logger::
*/ */
OsproberEntryList runOsprober( DeviceModel* dm ); OsproberEntryList runOsprober( DeviceModel* dm );
/**
* @brief Is this an ARM-based system? Set in the configuration file
*/
bool isArmSystem();
/** /**
* @brief Is this system EFI-enabled? Decides based on /sys/firmware/efi * @brief Is this system EFI-enabled? Decides based on /sys/firmware/efi
*/ */

View File

@ -89,22 +89,15 @@ doAutopartition( PartitionCoreModule* core, Device* dev, Choices::AutoPartitionO
{ {
Calamares::GlobalStorage* gs = Calamares::JobQueue::instance()->globalStorage(); Calamares::GlobalStorage* gs = Calamares::JobQueue::instance()->globalStorage();
bool isEfi = PartUtils::isEfiSystem(); const bool isEfi = PartUtils::isEfiSystem();
// Partition sizes are expressed in MiB, should be multiples of // Partition sizes are expressed in MiB, should be multiples of
// the logical sector size (usually 512B). EFI starts with 2MiB // the logical sector size (usually 512B). EFI starts with 2MiB
// empty and a EFI boot partition, while BIOS starts at // empty and a EFI boot partition, while BIOS starts at
// the 1MiB boundary (usually sector 2048). // the 1MiB boundary (usually sector 2048).
// ARM empty sectors are 16 MiB in size. // ARM empty sectors are 16 MiB in size.
int empty_space_sizeB; const int empty_space_sizeB = PartUtils::isArmSystem() ? 16_MiB : ( isEfi ? 2_MiB : 1_MiB );
if ( gs->contains( "armInstall" ) && gs->value( "armInstall" ).toBool() )
{
empty_space_sizeB = 16_MiB;
}
else
{
empty_space_sizeB = isEfi ? 2_MiB : 1_MiB;
}
// Since sectors count from 0, if the space is 2048 sectors in size, // Since sectors count from 0, if the space is 2048 sectors in size,
// the first free sector has number 2048 (and there are 2048 sectors // the first free sector has number 2048 (and there are 2048 sectors
// before that one, numbered 0..2047). // before that one, numbered 0..2047).