https://git.reactos.org/?p=reactos.git;a=commitdiff;h=70fa2e2eb4c8adf4458f0…
commit 70fa2e2eb4c8adf4458f0824237dae10328c415a
Author: Hermès Bélusca-Maïto <hermes.belusca-maito(a)reactos.org>
AuthorDate: Sun Nov 18 19:07:23 2018 +0100
Commit: Hermès Bélusca-Maïto <hermes.belusca-maito(a)reactos.org>
CommitDate: Sun Nov 18 21:13:36 2018 +0100
[SETUPLIB][USETUP] Additional partition validity checks.
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 | 62 +++++++++++++++++++++++++++++++----------
base/setup/lib/utils/partlist.h | 6 ++--
base/setup/usetup/usetup.c | 16 ++++++++++-
3 files changed, 65 insertions(+), 19 deletions(-)
diff --git a/base/setup/lib/utils/partlist.c b/base/setup/lib/utils/partlist.c
index 0d66b6c87e..10ec9d6db6 100644
--- a/base/setup/lib/utils/partlist.c
+++ b/base/setup/lib/utils/partlist.c
@@ -2203,6 +2203,8 @@ UpdateDiskLayout(
ListEntry = ListEntry->Flink;
}
+ ASSERT(Index <= 4);
+
/* Update the logical partition table */
Index = 4;
ListEntry = DiskEntry->LogicalPartListHead.Flink;
@@ -2356,12 +2358,13 @@ GetNextUnpartitionedEntry(
return NULL;
}
-VOID
+BOOLEAN
CreatePrimaryPartition(
IN PPARTLIST List,
IN ULONGLONG SectorCount,
IN BOOLEAN AutoCreate)
{
+ ERROR_NUMBER Error;
PDISKENTRY DiskEntry;
PPARTENTRY PartEntry;
PPARTENTRY NewPartEntry;
@@ -2371,9 +2374,16 @@ CreatePrimaryPartition(
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;
@@ -2408,7 +2418,7 @@ CreatePrimaryPartition(
HEAP_ZERO_MEMORY,
sizeof(PARTENTRY));
if (NewPartEntry == NULL)
- return;
+ return FALSE;
/* Insert the new entry into the list */
InsertTailList(&PartEntry->ListEntry,
@@ -2440,6 +2450,8 @@ CreatePrimaryPartition(
DiskEntry->Dirty = TRUE;
AssignDriveLetters(List);
+
+ return TRUE;
}
static
@@ -2476,11 +2488,12 @@ AddLogicalDiskSpace(
&NewPartEntry->ListEntry);
}
-VOID
+BOOLEAN
CreateExtendedPartition(
IN PPARTLIST List,
IN ULONGLONG SectorCount)
{
+ ERROR_NUMBER Error;
PDISKENTRY DiskEntry;
PPARTENTRY PartEntry;
PPARTENTRY NewPartEntry;
@@ -2490,9 +2503,16 @@ CreateExtendedPartition(
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;
@@ -2538,7 +2558,7 @@ CreateExtendedPartition(
HEAP_ZERO_MEMORY,
sizeof(PARTENTRY));
if (NewPartEntry == NULL)
- return;
+ return FALSE;
/* Insert the new entry into the list */
InsertTailList(&PartEntry->ListEntry,
@@ -2584,14 +2604,17 @@ CreateExtendedPartition(
DiskEntry->Dirty = TRUE;
AssignDriveLetters(List);
+
+ return TRUE;
}
-VOID
+BOOLEAN
CreateLogicalPartition(
IN PPARTLIST List,
IN ULONGLONG SectorCount,
IN BOOLEAN AutoCreate)
{
+ ERROR_NUMBER Error;
PDISKENTRY DiskEntry;
PPARTENTRY PartEntry;
PPARTENTRY NewPartEntry;
@@ -2601,9 +2624,16 @@ CreateLogicalPartition(
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;
@@ -2639,7 +2669,7 @@ CreateLogicalPartition(
HEAP_ZERO_MEMORY,
sizeof(PARTENTRY));
if (NewPartEntry == NULL)
- return;
+ return FALSE;
/* Insert the new entry into the list */
InsertTailList(&PartEntry->ListEntry,
@@ -2672,6 +2702,8 @@ CreateLogicalPartition(
DiskEntry->Dirty = TRUE;
AssignDriveLetters(List);
+
+ return TRUE;
}
VOID
@@ -3286,7 +3318,7 @@ PrimaryPartitionCreationChecks(
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 */
@@ -3307,7 +3339,7 @@ ExtendedPartitionCreationChecks(
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 */
@@ -3332,7 +3364,7 @@ LogicalPartitionCreationChecks(
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;
diff --git a/base/setup/lib/utils/partlist.h b/base/setup/lib/utils/partlist.h
index 5ffbd8cca4..f2f856cda2 100644
--- a/base/setup/lib/utils/partlist.h
+++ b/base/setup/lib/utils/partlist.h
@@ -284,18 +284,18 @@ PPARTENTRY
GetPrevPartition(
IN PPARTLIST List);
-VOID
+BOOLEAN
CreatePrimaryPartition(
IN PPARTLIST List,
IN ULONGLONG SectorCount,
IN BOOLEAN AutoCreate);
-VOID
+BOOLEAN
CreateExtendedPartition(
IN PPARTLIST List,
IN ULONGLONG SectorCount);
-VOID
+BOOLEAN
CreateLogicalPartition(
IN PPARTLIST List,
IN ULONGLONG SectorCount,
diff --git a/base/setup/usetup/usetup.c b/base/setup/usetup/usetup.c
index f16d6512b7..48645eca32 100644
--- a/base/setup/usetup/usetup.c
+++ b/base/setup/usetup/usetup.c
@@ -1607,12 +1607,26 @@ SelectPartitionPage(PINPUT_RECORD Ir)
{
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
{
+ Error = PrimaryPartitionCreationChecks(PartitionList);
+ if (Error != NOT_AN_ERROR)
+ {
+ MUIDisplayError(Error, Ir, POPUP_WAIT_ANY_KEY);
+ return SELECT_PARTITION_PAGE;
+ }
+
CreatePrimaryPartition(PartitionList,
0ULL,
TRUE);
@@ -2580,7 +2594,7 @@ DeletePartitionPage(PINPUT_RECORD Ir)
* QuitPage
*
* SIDEEFFECTS
- * Sets
PartEntry->DiskEntry->LayoutBuffer->PartitionEntry[PartEntry->PartitionIndex].PartitionType
(via UpdatePartitionType)
+ * Calls UpdatePartitionType()
* Calls CheckActiveSystemPartition()
*
* RETURNS