From 026d1cb5e457dbb7ea5436fac28df99b5eba22ef Mon Sep 17 00:00:00 2001
From: Adriaan de Groot <groot@kde.org>
Date: Mon, 30 Oct 2023 21:24:24 +0100
Subject: [PATCH] partition: add checks for absolute minimum size of EFI

---
 src/modules/partition/PartitionViewStep.cpp |  1 +
 src/modules/partition/core/PartUtils.cpp    | 24 ++++++++++++++++++++-
 src/modules/partition/core/PartUtils.h      |  6 ++++++
 3 files changed, 30 insertions(+), 1 deletion(-)

diff --git a/src/modules/partition/PartitionViewStep.cpp b/src/modules/partition/PartitionViewStep.cpp
index 01dd7098bf..f1ed1f41fc 100644
--- a/src/modules/partition/PartitionViewStep.cpp
+++ b/src/modules/partition/PartitionViewStep.cpp
@@ -528,6 +528,7 @@ PartitionViewStep::onLeave()
 
             const bool okType = esp && PartUtils::isEfiFilesystemSuitableType( esp );
             const bool okSize = esp && PartUtils::isEfiFilesystemSuitableSize( esp );
+            const bool okMinimumSize = esp && PartUtils::isEfiFilesystemSuitableMinimumSize( esp );
             const bool okFlag = esp && PartUtils::isEfiBootable( esp );
 
             if ( !esp )
diff --git a/src/modules/partition/core/PartUtils.cpp b/src/modules/partition/core/PartUtils.cpp
index 8c646e3122..ad39bba375 100644
--- a/src/modules/partition/core/PartUtils.cpp
+++ b/src/modules/partition/core/PartUtils.cpp
@@ -485,7 +485,29 @@ isEfiFilesystemSuitableSize( const Partition* candidate )
     }
     else
     {
-        cWarning() << "Filesystem for EFI is too small (" << size << "bytes)";
+        cWarning() << "Filesystem for EFI is smaller than recommended (" << size << "bytes)";
+        return false;
+    }
+}
+
+bool
+isEfiFilesystemSuitableMinimumSize( const Partition* candidate )
+{
+    using Calamares::Units::operator""_MiB;
+
+    auto size = candidate->capacity();  // bytes
+    if ( size <= 0 )
+    {
+        return false;
+    }
+
+    if ( size >= 32_MiB )
+    {
+        return true;
+    }
+    else
+    {
+        cWarning() << "Filesystem for EFI is below minimum (" << size << "bytes)";
         return false;
     }
 }
diff --git a/src/modules/partition/core/PartUtils.h b/src/modules/partition/core/PartUtils.h
index a6f036710b..98a1c1ab37 100644
--- a/src/modules/partition/core/PartUtils.h
+++ b/src/modules/partition/core/PartUtils.h
@@ -99,6 +99,12 @@ bool isEfiFilesystemSuitableType( const Partition* candidate );
  */
 bool isEfiFilesystemSuitableSize( const Partition* candidate );
 
+/**
+ * @brief Is the @p candidate suitable as an EFI boot partition?
+ * This checks the bonkers-small minimum of 32MiB.
+ */
+bool isEfiFilesystemSuitableMinimumSize( const Partition* candidate );
+
 /** @brief Returns the minimum size of an EFI boot partition in bytes.
  *
  * This is determined as 300MiB, based on the FAT32 standard
-- 
GitLab