https://git.reactos.org/?p=reactos.git;a=commitdiff;h=0ca4e6dcfaf93165300cc1866eeae50d221ab403

commit 0ca4e6dcfaf93165300cc1866eeae50d221ab403
Author:     Hermès Bélusca-Maïto <hermes.belusca-ma...@reactos.org>
AuthorDate: Fri Nov 22 22:20:58 2024 +0100
Commit:     Hermès Bélusca-Maïto <hermes.belusca-ma...@reactos.org>
CommitDate: Sat Nov 23 21:41:32 2024 +0100

    [SETUPLIB][REACTOS][USETUP] Finish unification of MBR extended and 
primary/logical partitions
    
    Addendum to commmit 99f0937fd.
    
    The partition-creation checks are unified for these partitions into one
    single function. To prepare for GPT support, the specifics are put into
    a separate MBRPartitionCreateChecks() helper, called for MBR disks by the
    upper-level function. GPT disks will have a similar helper in the future.
---
 base/setup/lib/utils/partlist.c | 80 ++++++++++++++++++-----------------------
 base/setup/lib/utils/partlist.h | 10 +++---
 base/setup/reactos/drivepage.c  |  4 +--
 base/setup/usetup/usetup.c      |  6 ++--
 4 files changed, 44 insertions(+), 56 deletions(-)

diff --git a/base/setup/lib/utils/partlist.c b/base/setup/lib/utils/partlist.c
index c045518cbfe..6793ec855a9 100644
--- a/base/setup/lib/utils/partlist.c
+++ b/base/setup/lib/utils/partlist.c
@@ -2818,41 +2818,48 @@ GetAdjUnpartitionedEntry(
     return NULL;
 }
 
-ERROR_NUMBER
-PartitionCreationChecks(
-    _In_ PPARTENTRY PartEntry)
+static ERROR_NUMBER
+MBRPartitionCreateChecks(
+    _In_ PPARTENTRY PartEntry,
+    _In_opt_ ULONGLONG SizeBytes,
+    _In_opt_ ULONG_PTR PartitionInfo)
 {
     PDISKENTRY DiskEntry = PartEntry->DiskEntry;
+    BOOLEAN isContainer = IsContainerPartition((UCHAR)PartitionInfo);
 
-    if (DiskEntry->DiskStyle == PARTITION_STYLE_GPT)
+    ASSERT(DiskEntry->DiskStyle == PARTITION_STYLE_MBR);
+    ASSERT(!PartEntry->IsPartitioned);
+
+    if (isContainer)
     {
-        DPRINT1("GPT-partitioned disk detected, not currently supported by 
SETUP!\n");
-        return ERROR_WARN_PARTITION;
-    }
+        /* Cannot create an extended partition within logical partition space 
*/
+        if (PartEntry->LogicalPartition)
+            return ERROR_ONLY_ONE_EXTENDED;
 
-    /* Fail if the partition is already in use */
-    if (PartEntry->IsPartitioned)
-        return ERROR_NEW_PARTITION;
+        /* Fail if there is another extended partition in the list */
+        if (DiskEntry->ExtendedPartition)
+            return ERROR_ONLY_ONE_EXTENDED;
+    }
 
     /*
-     * For primary partitions
+     * Primary or Extended partitions
      */
-    if (!PartEntry->LogicalPartition)
+    if (!PartEntry->LogicalPartition || isContainer)
     {
         /* Only one primary partition is allowed on super-floppy */
         if (IsSuperFloppy(DiskEntry))
             return ERROR_PARTITION_TABLE_FULL;
 
-        /* Fail if there are already 4 primary partitions in the list */
+        /* Fail if there are too many primary partitions */
         if (GetPrimaryPartitionCount(DiskEntry) >= 4)
             return ERROR_PARTITION_TABLE_FULL;
     }
     /*
-     * For logical partitions
+     * Logical partitions
      */
     else
     {
-        // TODO: Check that we are inside an extended partition!!
+        // TODO: Check that we are inside an extended partition!
         // Then the following check will be useless.
 
         /* Only one (primary) partition is allowed on super-floppy */
@@ -2864,38 +2871,24 @@ PartitionCreationChecks(
 }
 
 ERROR_NUMBER
-ExtendedPartitionCreationChecks(
-    _In_ PPARTENTRY PartEntry)
+PartitionCreateChecks(
+    _In_ PPARTENTRY PartEntry,
+    _In_opt_ ULONGLONG SizeBytes,
+    _In_opt_ ULONG_PTR PartitionInfo)
 {
     PDISKENTRY DiskEntry = PartEntry->DiskEntry;
 
-    if (DiskEntry->DiskStyle == PARTITION_STYLE_GPT)
-    {
-        DPRINT1("GPT-partitioned disk detected, not currently supported by 
SETUP!\n");
-        return ERROR_WARN_PARTITION;
-    }
-
     /* Fail if the partition is already in use */
     if (PartEntry->IsPartitioned)
         return ERROR_NEW_PARTITION;
 
-    /* Cannot create an extended partition within logical partition space */
-    if (PartEntry->LogicalPartition)
-        return ERROR_ONLY_ONE_EXTENDED;
-
-    /* Only one primary partition is allowed on super-floppy */
-    if (IsSuperFloppy(DiskEntry))
-        return ERROR_PARTITION_TABLE_FULL;
-
-    /* Fail if there are already 4 primary partitions in the list */
-    if (GetPrimaryPartitionCount(DiskEntry) >= 4)
-        return ERROR_PARTITION_TABLE_FULL;
-
-    /* Fail if there is another extended partition in the list */
-    if (DiskEntry->ExtendedPartition)
-        return ERROR_ONLY_ONE_EXTENDED;
-
-    return ERROR_SUCCESS;
+    if (DiskEntry->DiskStyle == PARTITION_STYLE_MBR)
+        return MBRPartitionCreateChecks(PartEntry, SizeBytes, PartitionInfo);
+    else // if (DiskEntry->DiskStyle == PARTITION_STYLE_GPT)
+    {
+        DPRINT1("GPT-partitioned disk detected, not currently supported by 
SETUP!\n");
+        return ERROR_WARN_PARTITION;
+    }
 }
 
 // TODO: Improve upon the PartitionInfo parameter later
@@ -2926,13 +2919,10 @@ CreatePartition(
         return FALSE;
     }
 
-    if (isContainer)
-        Error = ExtendedPartitionCreationChecks(PartEntry);
-    else
-        Error = PartitionCreationChecks(PartEntry);
+    Error = PartitionCreateChecks(PartEntry, SizeBytes, PartitionInfo);
     if (Error != NOT_AN_ERROR)
     {
-        DPRINT1("PartitionCreationChecks(%s) failed with error %lu\n", 
mainType, Error);
+        DPRINT1("PartitionCreateChecks(%s) failed with error %lu\n", mainType, 
Error);
         return FALSE;
     }
 
diff --git a/base/setup/lib/utils/partlist.h b/base/setup/lib/utils/partlist.h
index fb20f1500c0..71b9eb99181 100644
--- a/base/setup/lib/utils/partlist.h
+++ b/base/setup/lib/utils/partlist.h
@@ -338,12 +338,10 @@ GetAdjUnpartitionedEntry(
     _In_ BOOLEAN Direction);
 
 ERROR_NUMBER
-PartitionCreationChecks(
-    _In_ PPARTENTRY PartEntry);
-
-ERROR_NUMBER
-ExtendedPartitionCreationChecks(
-    _In_ PPARTENTRY PartEntry);
+PartitionCreateChecks(
+    _In_ PPARTENTRY PartEntry,
+    _In_opt_ ULONGLONG SizeBytes,
+    _In_opt_ ULONG_PTR PartitionInfo);
 
 BOOLEAN
 CreatePartition(
diff --git a/base/setup/reactos/drivepage.c b/base/setup/reactos/drivepage.c
index 5afdb57b084..dc4fc64cfb5 100644
--- a/base/setup/reactos/drivepage.c
+++ b/base/setup/reactos/drivepage.c
@@ -1975,7 +1975,7 @@ DriveDlgProc(
                         // TODO: In the future: first test needs to be 
augmented with:
                         // (... && PartEntry->Volume->IsSimpleVolume)
                         if ((PartEntry->IsPartitioned && PartEntry->Volume) ||
-                            (!PartEntry->IsPartitioned && 
(PartitionCreationChecks(PartEntry) == NOT_AN_ERROR)))
+                            (!PartEntry->IsPartitioned && 
(PartitionCreateChecks(PartEntry, 0ULL, 0) == NOT_AN_ERROR)))
                         {
                             // ASSERT(PartEntry != 
PartEntry->DiskEntry->ExtendedPartition);
                             
ASSERT(!IsContainerPartition(PartEntry->PartitionType));
@@ -2090,7 +2090,7 @@ DisableWizNext:
                     {
                         ULONG Error;
 
-                        Error = PartitionCreationChecks(PartEntry);
+                        Error = PartitionCreateChecks(PartEntry, 0ULL, 0);
                         if (Error != NOT_AN_ERROR)
                         {
                             // MUIDisplayError(Error, Ir, POPUP_WAIT_ANY_KEY);
diff --git a/base/setup/usetup/usetup.c b/base/setup/usetup/usetup.c
index d5d569ede42..10d133eb560 100644
--- a/base/setup/usetup/usetup.c
+++ b/base/setup/usetup/usetup.c
@@ -1711,7 +1711,7 @@ SelectPartitionPage(PINPUT_RECORD Ir)
         {
             ASSERT(CurrentPartition);
 
-            Error = PartitionCreationChecks(CurrentPartition);
+            Error = PartitionCreateChecks(CurrentPartition, 0ULL, 0);
             if (Error != NOT_AN_ERROR)
             {
                 MUIDisplayError(Error, Ir, POPUP_WAIT_ANY_KEY);
@@ -1729,7 +1729,7 @@ SelectPartitionPage(PINPUT_RECORD Ir)
             if (CurrentPartition->LogicalPartition)
                 continue;
 
-            Error = ExtendedPartitionCreationChecks(CurrentPartition);
+            Error = PartitionCreateChecks(CurrentPartition, 0ULL, 
PARTITION_EXTENDED);
             if (Error != NOT_AN_ERROR)
             {
                 MUIDisplayError(Error, Ir, POPUP_WAIT_ANY_KEY);
@@ -1789,7 +1789,7 @@ CreateInstallPartition:
     /* Create the partition if the selected region is empty */
     if (!CurrentPartition->IsPartitioned)
     {
-        Error = PartitionCreationChecks(CurrentPartition);
+        Error = PartitionCreateChecks(CurrentPartition, 0ULL, 0);
         if (Error != NOT_AN_ERROR)
         {
             MUIDisplayError(Error, Ir, POPUP_WAIT_ANY_KEY);

Reply via email to