From e7161443d6cccf3795b93e5cb41bca895645a113 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Sun, 25 Jun 2023 22:21:01 +0200 Subject: [PATCH] partition: simplify Arm code - introduce a helper function for accessing the globalstorage value - add consts and calculate the initial gap in a single expression --- src/modules/partition/core/PartUtils.cpp | 17 ++++++++--------- src/modules/partition/core/PartUtils.h | 5 +++++ src/modules/partition/core/PartitionActions.cpp | 13 +++---------- 3 files changed, 16 insertions(+), 19 deletions(-) diff --git a/src/modules/partition/core/PartUtils.cpp b/src/modules/partition/core/PartUtils.cpp index 60f966f27..16d6b1d49 100644 --- a/src/modules/partition/core/PartUtils.cpp +++ b/src/modules/partition/core/PartUtils.cpp @@ -441,17 +441,16 @@ runOsprober( DeviceModel* dm ) } bool -isEfiSystem() +isArmSystem() { Calamares::GlobalStorage* gs = Calamares::JobQueue::instance()->globalStorage(); - if ( gs->contains( "armInstall" ) && gs->value( "armInstall" ).toBool() ) - { - return true; - } - else - { - return QDir( "/sys/firmware/efi/efivars" ).exists(); - } + return gs->contains( "armInstall" ) && gs->value( "armInstall" ).toBool() ); +} + +bool +isEfiSystem() +{ + return isArmSystem() || QDir( "/sys/firmware/efi/efivars" ).exists(); } bool diff --git a/src/modules/partition/core/PartUtils.h b/src/modules/partition/core/PartUtils.h index 0ed388ff5..a6f036710 100644 --- a/src/modules/partition/core/PartUtils.h +++ b/src/modules/partition/core/PartUtils.h @@ -77,6 +77,11 @@ bool canBeResized( DeviceModel* dm, const QString& partitionPath, const Logger:: */ 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 */ diff --git a/src/modules/partition/core/PartitionActions.cpp b/src/modules/partition/core/PartitionActions.cpp index 631d4ca64..801cb1e75 100644 --- a/src/modules/partition/core/PartitionActions.cpp +++ b/src/modules/partition/core/PartitionActions.cpp @@ -89,22 +89,15 @@ doAutopartition( PartitionCoreModule* core, Device* dev, Choices::AutoPartitionO { 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 // the logical sector size (usually 512B). EFI starts with 2MiB // empty and a EFI boot partition, while BIOS starts at // the 1MiB boundary (usually sector 2048). // ARM empty sectors are 16 MiB in size. - int empty_space_sizeB; - if ( gs->contains( "armInstall" ) && gs->value( "armInstall" ).toBool() ) - { - empty_space_sizeB = 16_MiB; - } - else - { - empty_space_sizeB = isEfi ? 2_MiB : 1_MiB; - } + const int empty_space_sizeB = PartUtils::isArmSystem() ? 16_MiB : ( isEfi ? 2_MiB : 1_MiB ); + // 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 // before that one, numbered 0..2047).