[SETUPLIB][USETUP] Additional partition validity checks.
authorHermès Bélusca-Maïto <hermes.belusca-maito@reactos.org>
Sun, 18 Nov 2018 18:07:23 +0000 (19:07 +0100)
committerHermès Bélusca-Maïto <hermes.belusca-maito@reactos.org>
Sun, 18 Nov 2018 20:13:36 +0000 (21:13 +0100)
Always perform the partition validity checks when creating new
primary/extended/logical partitions, and also when a new partition
is automatically created when unpartitioned space is selected for
ReactOS installation.

CORE-12246

base/setup/lib/utils/partlist.c
base/setup/lib/utils/partlist.h
base/setup/usetup/usetup.c

index 0d66b6c..10ec9d6 100644 (file)
@@ -2203,6 +2203,8 @@ UpdateDiskLayout(
         ListEntry = ListEntry->Flink;
     }
 
         ListEntry = ListEntry->Flink;
     }
 
+    ASSERT(Index <= 4);
+
     /* Update the logical partition table */
     Index = 4;
     ListEntry = DiskEntry->LogicalPartListHead.Flink;
     /* Update the logical partition table */
     Index = 4;
     ListEntry = DiskEntry->LogicalPartListHead.Flink;
@@ -2356,12 +2358,13 @@ GetNextUnpartitionedEntry(
     return NULL;
 }
 
     return NULL;
 }
 
-VOID
+BOOLEAN
 CreatePrimaryPartition(
     IN PPARTLIST List,
     IN ULONGLONG SectorCount,
     IN BOOLEAN AutoCreate)
 {
 CreatePrimaryPartition(
     IN PPARTLIST List,
     IN ULONGLONG SectorCount,
     IN BOOLEAN AutoCreate)
 {
+    ERROR_NUMBER Error;
     PDISKENTRY DiskEntry;
     PPARTENTRY PartEntry;
     PPARTENTRY NewPartEntry;
     PDISKENTRY DiskEntry;
     PPARTENTRY PartEntry;
     PPARTENTRY NewPartEntry;
@@ -2371,9 +2374,16 @@ CreatePrimaryPartition(
     if (List == NULL ||
         List->CurrentDisk == NULL ||
         List->CurrentPartition == NULL ||
     if (List == NULL ||
         List->CurrentDisk == NULL ||
         List->CurrentPartition == NULL ||
-        List->CurrentPartition->IsPartitioned != FALSE)
+        List->CurrentPartition->IsPartitioned)
     {
     {
-        return;
+        return FALSE;
+    }
+
+    Error = PrimaryPartitionCreationChecks(List);
+    if (Error != NOT_AN_ERROR)
+    {
+        DPRINT1("PrimaryPartitionCreationChecks() failed with error %lu\n", Error);
+        return FALSE;
     }
 
     DiskEntry = List->CurrentDisk;
     }
 
     DiskEntry = List->CurrentDisk;
@@ -2408,7 +2418,7 @@ CreatePrimaryPartition(
                                        HEAP_ZERO_MEMORY,
                                        sizeof(PARTENTRY));
         if (NewPartEntry == NULL)
                                        HEAP_ZERO_MEMORY,
                                        sizeof(PARTENTRY));
         if (NewPartEntry == NULL)
-            return;
+            return FALSE;
 
         /* Insert the new entry into the list */
         InsertTailList(&PartEntry->ListEntry,
 
         /* Insert the new entry into the list */
         InsertTailList(&PartEntry->ListEntry,
@@ -2440,6 +2450,8 @@ CreatePrimaryPartition(
     DiskEntry->Dirty = TRUE;
 
     AssignDriveLetters(List);
     DiskEntry->Dirty = TRUE;
 
     AssignDriveLetters(List);
+
+    return TRUE;
 }
 
 static
 }
 
 static
@@ -2476,11 +2488,12 @@ AddLogicalDiskSpace(
                    &NewPartEntry->ListEntry);
 }
 
                    &NewPartEntry->ListEntry);
 }
 
-VOID
+BOOLEAN
 CreateExtendedPartition(
     IN PPARTLIST List,
     IN ULONGLONG SectorCount)
 {
 CreateExtendedPartition(
     IN PPARTLIST List,
     IN ULONGLONG SectorCount)
 {
+    ERROR_NUMBER Error;
     PDISKENTRY DiskEntry;
     PPARTENTRY PartEntry;
     PPARTENTRY NewPartEntry;
     PDISKENTRY DiskEntry;
     PPARTENTRY PartEntry;
     PPARTENTRY NewPartEntry;
@@ -2490,9 +2503,16 @@ CreateExtendedPartition(
     if (List == NULL ||
         List->CurrentDisk == NULL ||
         List->CurrentPartition == NULL ||
     if (List == NULL ||
         List->CurrentDisk == NULL ||
         List->CurrentPartition == NULL ||
-        List->CurrentPartition->IsPartitioned != FALSE)
+        List->CurrentPartition->IsPartitioned)
     {
     {
-        return;
+        return FALSE;
+    }
+
+    Error = ExtendedPartitionCreationChecks(List);
+    if (Error != NOT_AN_ERROR)
+    {
+        DPRINT1("ExtendedPartitionCreationChecks() failed with error %lu\n", Error);
+        return FALSE;
     }
 
     DiskEntry = List->CurrentDisk;
     }
 
     DiskEntry = List->CurrentDisk;
@@ -2538,7 +2558,7 @@ CreateExtendedPartition(
                                        HEAP_ZERO_MEMORY,
                                        sizeof(PARTENTRY));
         if (NewPartEntry == NULL)
                                        HEAP_ZERO_MEMORY,
                                        sizeof(PARTENTRY));
         if (NewPartEntry == NULL)
-            return;
+            return FALSE;
 
         /* Insert the new entry into the list */
         InsertTailList(&PartEntry->ListEntry,
 
         /* Insert the new entry into the list */
         InsertTailList(&PartEntry->ListEntry,
@@ -2584,14 +2604,17 @@ CreateExtendedPartition(
     DiskEntry->Dirty = TRUE;
 
     AssignDriveLetters(List);
     DiskEntry->Dirty = TRUE;
 
     AssignDriveLetters(List);
+
+    return TRUE;
 }
 
 }
 
-VOID
+BOOLEAN
 CreateLogicalPartition(
     IN PPARTLIST List,
     IN ULONGLONG SectorCount,
     IN BOOLEAN AutoCreate)
 {
 CreateLogicalPartition(
     IN PPARTLIST List,
     IN ULONGLONG SectorCount,
     IN BOOLEAN AutoCreate)
 {
+    ERROR_NUMBER Error;
     PDISKENTRY DiskEntry;
     PPARTENTRY PartEntry;
     PPARTENTRY NewPartEntry;
     PDISKENTRY DiskEntry;
     PPARTENTRY PartEntry;
     PPARTENTRY NewPartEntry;
@@ -2601,9 +2624,16 @@ CreateLogicalPartition(
     if (List == NULL ||
         List->CurrentDisk == NULL ||
         List->CurrentPartition == NULL ||
     if (List == NULL ||
         List->CurrentDisk == NULL ||
         List->CurrentPartition == NULL ||
-        List->CurrentPartition->IsPartitioned != FALSE)
+        List->CurrentPartition->IsPartitioned)
     {
     {
-        return;
+        return FALSE;
+    }
+
+    Error = LogicalPartitionCreationChecks(List);
+    if (Error != NOT_AN_ERROR)
+    {
+        DPRINT1("LogicalPartitionCreationChecks() failed with error %lu\n", Error);
+        return FALSE;
     }
 
     DiskEntry = List->CurrentDisk;
     }
 
     DiskEntry = List->CurrentDisk;
@@ -2639,7 +2669,7 @@ CreateLogicalPartition(
                                        HEAP_ZERO_MEMORY,
                                        sizeof(PARTENTRY));
         if (NewPartEntry == NULL)
                                        HEAP_ZERO_MEMORY,
                                        sizeof(PARTENTRY));
         if (NewPartEntry == NULL)
-            return;
+            return FALSE;
 
         /* Insert the new entry into the list */
         InsertTailList(&PartEntry->ListEntry,
 
         /* Insert the new entry into the list */
         InsertTailList(&PartEntry->ListEntry,
@@ -2672,6 +2702,8 @@ CreateLogicalPartition(
     DiskEntry->Dirty = TRUE;
 
     AssignDriveLetters(List);
     DiskEntry->Dirty = TRUE;
 
     AssignDriveLetters(List);
+
+    return TRUE;
 }
 
 VOID
 }
 
 VOID
@@ -3286,7 +3318,7 @@ PrimaryPartitionCreationChecks(
     PartEntry = List->CurrentPartition;
 
     /* Fail if the partition is already in use */
     PartEntry = List->CurrentPartition;
 
     /* Fail if the partition is already in use */
-    if (PartEntry->IsPartitioned != FALSE)
+    if (PartEntry->IsPartitioned)
         return ERROR_NEW_PARTITION;
 
     /* Fail if there are already 4 primary partitions in the list */
         return ERROR_NEW_PARTITION;
 
     /* Fail if there are already 4 primary partitions in the list */
@@ -3307,7 +3339,7 @@ ExtendedPartitionCreationChecks(
     PartEntry = List->CurrentPartition;
 
     /* Fail if the partition is already in use */
     PartEntry = List->CurrentPartition;
 
     /* Fail if the partition is already in use */
-    if (PartEntry->IsPartitioned != FALSE)
+    if (PartEntry->IsPartitioned)
         return ERROR_NEW_PARTITION;
 
     /* Fail if there are already 4 primary partitions in the list */
         return ERROR_NEW_PARTITION;
 
     /* Fail if there are already 4 primary partitions in the list */
@@ -3332,7 +3364,7 @@ LogicalPartitionCreationChecks(
     PartEntry = List->CurrentPartition;
 
     /* Fail if the partition is already in use */
     PartEntry = List->CurrentPartition;
 
     /* Fail if the partition is already in use */
-    if (PartEntry->IsPartitioned != FALSE)
+    if (PartEntry->IsPartitioned)
         return ERROR_NEW_PARTITION;
 
     return ERROR_SUCCESS;
         return ERROR_NEW_PARTITION;
 
     return ERROR_SUCCESS;
index 5ffbd8c..f2f856c 100644 (file)
@@ -284,18 +284,18 @@ PPARTENTRY
 GetPrevPartition(
     IN PPARTLIST List);
 
 GetPrevPartition(
     IN PPARTLIST List);
 
-VOID
+BOOLEAN
 CreatePrimaryPartition(
     IN PPARTLIST List,
     IN ULONGLONG SectorCount,
     IN BOOLEAN AutoCreate);
 
 CreatePrimaryPartition(
     IN PPARTLIST List,
     IN ULONGLONG SectorCount,
     IN BOOLEAN AutoCreate);
 
-VOID
+BOOLEAN
 CreateExtendedPartition(
     IN PPARTLIST List,
     IN ULONGLONG SectorCount);
 
 CreateExtendedPartition(
     IN PPARTLIST List,
     IN ULONGLONG SectorCount);
 
-VOID
+BOOLEAN
 CreateLogicalPartition(
     IN PPARTLIST List,
     IN ULONGLONG SectorCount,
 CreateLogicalPartition(
     IN PPARTLIST List,
     IN ULONGLONG SectorCount,
index f16d651..48645ec 100644 (file)
@@ -1607,12 +1607,26 @@ SelectPartitionPage(PINPUT_RECORD Ir)
             {
                 if (PartitionList->CurrentPartition->LogicalPartition)
                 {
             {
                 if (PartitionList->CurrentPartition->LogicalPartition)
                 {
+                    Error = LogicalPartitionCreationChecks(PartitionList);
+                    if (Error != NOT_AN_ERROR)
+                    {
+                        MUIDisplayError(Error, Ir, POPUP_WAIT_ANY_KEY);
+                        return SELECT_PARTITION_PAGE;
+                    }
+
                     CreateLogicalPartition(PartitionList,
                                            0ULL,
                                            TRUE);
                 }
                 else
                 {
                     CreateLogicalPartition(PartitionList,
                                            0ULL,
                                            TRUE);
                 }
                 else
                 {
+                    Error = PrimaryPartitionCreationChecks(PartitionList);
+                    if (Error != NOT_AN_ERROR)
+                    {
+                        MUIDisplayError(Error, Ir, POPUP_WAIT_ANY_KEY);
+                        return SELECT_PARTITION_PAGE;
+                    }
+
                     CreatePrimaryPartition(PartitionList,
                                            0ULL,
                                            TRUE);
                     CreatePrimaryPartition(PartitionList,
                                            0ULL,
                                            TRUE);
@@ -2580,7 +2594,7 @@ DeletePartitionPage(PINPUT_RECORD Ir)
  *  QuitPage
  *
  * SIDEEFFECTS
  *  QuitPage
  *
  * SIDEEFFECTS
- *  Sets PartEntry->DiskEntry->LayoutBuffer->PartitionEntry[PartEntry->PartitionIndex].PartitionType (via UpdatePartitionType)
+ *  Calls UpdatePartitionType()
  *  Calls CheckActiveSystemPartition()
  *
  * RETURNS
  *  Calls CheckActiveSystemPartition()
  *
  * RETURNS