[SETUPLIB][REACTOS][USETUP] Finish unification of MBR extended and primary/logical partitions

Fixes previous attempt at commit 0ca4e6dcf, which was reverted by commit
bbdcc14b1 because the partitioning checks mistook unpartitioned disks as
GPT.

Addendum to commit 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.
This commit is contained in:
Hermès Bélusca-Maïto 2024-11-22 22:20:58 +01:00
parent 69bf140506
commit 4aee0280f9
No known key found for this signature in database
GPG key ID: 3B2539C65E7B93D0
4 changed files with 50 additions and 57 deletions

View file

@ -2818,41 +2818,49 @@ GetAdjUnpartitionedEntry(
return NULL; return NULL;
} }
ERROR_NUMBER static ERROR_NUMBER
PartitionCreationChecks( MBRPartitionCreateChecks(
_In_ PPARTENTRY PartEntry) _In_ PPARTENTRY PartEntry,
_In_opt_ ULONGLONG SizeBytes,
_In_opt_ ULONG_PTR PartitionInfo)
{ {
PDISKENTRY DiskEntry = PartEntry->DiskEntry; PDISKENTRY DiskEntry = PartEntry->DiskEntry;
BOOLEAN isContainer = IsContainerPartition((UCHAR)PartitionInfo);
if (DiskEntry->DiskStyle == PARTITION_STYLE_GPT) // TODO: Re-enable once we initialize unpartitioned disks before using them.
// ASSERT(DiskEntry->DiskStyle == PARTITION_STYLE_MBR);
ASSERT(!PartEntry->IsPartitioned);
if (isContainer)
{ {
DPRINT1("GPT-partitioned disk detected, not currently supported by SETUP!\n"); /* Cannot create an extended partition within logical partition space */
return ERROR_WARN_PARTITION; if (PartEntry->LogicalPartition)
return ERROR_ONLY_ONE_EXTENDED;
/* Fail if there is another extended partition in the list */
if (DiskEntry->ExtendedPartition)
return ERROR_ONLY_ONE_EXTENDED;
} }
/* Fail if the partition is already in use */
if (PartEntry->IsPartitioned)
return ERROR_NEW_PARTITION;
/* /*
* For primary partitions * Primary or Extended partitions
*/ */
if (!PartEntry->LogicalPartition) if (!PartEntry->LogicalPartition || isContainer)
{ {
/* Only one primary partition is allowed on super-floppy */ /* Only one primary partition is allowed on super-floppy */
if (IsSuperFloppy(DiskEntry)) if (IsSuperFloppy(DiskEntry))
return ERROR_PARTITION_TABLE_FULL; 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) if (GetPrimaryPartitionCount(DiskEntry) >= 4)
return ERROR_PARTITION_TABLE_FULL; return ERROR_PARTITION_TABLE_FULL;
} }
/* /*
* For logical partitions * Logical partitions
*/ */
else 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. // Then the following check will be useless.
/* Only one (primary) partition is allowed on super-floppy */ /* Only one (primary) partition is allowed on super-floppy */
@ -2864,38 +2872,28 @@ PartitionCreationChecks(
} }
ERROR_NUMBER ERROR_NUMBER
ExtendedPartitionCreationChecks( PartitionCreateChecks(
_In_ PPARTENTRY PartEntry) _In_ PPARTENTRY PartEntry,
_In_opt_ ULONGLONG SizeBytes,
_In_opt_ ULONG_PTR PartitionInfo)
{ {
PDISKENTRY DiskEntry = PartEntry->DiskEntry; // 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 */ /* Fail if the partition is already in use */
if (PartEntry->IsPartitioned) if (PartEntry->IsPartitioned)
return ERROR_NEW_PARTITION; return ERROR_NEW_PARTITION;
/* Cannot create an extended partition within logical partition space */ // TODO: Re-enable once we initialize unpartitioned disks before
if (PartEntry->LogicalPartition) // using them; because such disks would be mistook as GPT otherwise.
return ERROR_ONLY_ONE_EXTENDED; // if (DiskEntry->DiskStyle == PARTITION_STYLE_MBR)
return MBRPartitionCreateChecks(PartEntry, SizeBytes, PartitionInfo);
/* Only one primary partition is allowed on super-floppy */ #if 0
if (IsSuperFloppy(DiskEntry)) else // if (DiskEntry->DiskStyle == PARTITION_STYLE_GPT)
return ERROR_PARTITION_TABLE_FULL; {
DPRINT1("GPT-partitioned disk detected, not currently supported by SETUP!\n");
/* Fail if there are already 4 primary partitions in the list */ return ERROR_WARN_PARTITION;
if (GetPrimaryPartitionCount(DiskEntry) >= 4) }
return ERROR_PARTITION_TABLE_FULL; #endif
/* Fail if there is another extended partition in the list */
if (DiskEntry->ExtendedPartition)
return ERROR_ONLY_ONE_EXTENDED;
return ERROR_SUCCESS;
} }
// TODO: Improve upon the PartitionInfo parameter later // TODO: Improve upon the PartitionInfo parameter later
@ -2926,13 +2924,10 @@ CreatePartition(
return FALSE; return FALSE;
} }
if (isContainer) Error = PartitionCreateChecks(PartEntry, SizeBytes, PartitionInfo);
Error = ExtendedPartitionCreationChecks(PartEntry);
else
Error = PartitionCreationChecks(PartEntry);
if (Error != NOT_AN_ERROR) 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; return FALSE;
} }

View file

@ -338,12 +338,10 @@ GetAdjUnpartitionedEntry(
_In_ BOOLEAN Direction); _In_ BOOLEAN Direction);
ERROR_NUMBER ERROR_NUMBER
PartitionCreationChecks( PartitionCreateChecks(
_In_ PPARTENTRY PartEntry); _In_ PPARTENTRY PartEntry,
_In_opt_ ULONGLONG SizeBytes,
ERROR_NUMBER _In_opt_ ULONG_PTR PartitionInfo);
ExtendedPartitionCreationChecks(
_In_ PPARTENTRY PartEntry);
BOOLEAN BOOLEAN
CreatePartition( CreatePartition(

View file

@ -1975,7 +1975,7 @@ DriveDlgProc(
// TODO: In the future: first test needs to be augmented with: // TODO: In the future: first test needs to be augmented with:
// (... && PartEntry->Volume->IsSimpleVolume) // (... && PartEntry->Volume->IsSimpleVolume)
if ((PartEntry->IsPartitioned && PartEntry->Volume) || 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(PartEntry != PartEntry->DiskEntry->ExtendedPartition);
ASSERT(!IsContainerPartition(PartEntry->PartitionType)); ASSERT(!IsContainerPartition(PartEntry->PartitionType));
@ -2090,7 +2090,7 @@ DisableWizNext:
{ {
ULONG Error; ULONG Error;
Error = PartitionCreationChecks(PartEntry); Error = PartitionCreateChecks(PartEntry, 0ULL, 0);
if (Error != NOT_AN_ERROR) if (Error != NOT_AN_ERROR)
{ {
// MUIDisplayError(Error, Ir, POPUP_WAIT_ANY_KEY); // MUIDisplayError(Error, Ir, POPUP_WAIT_ANY_KEY);

View file

@ -1711,7 +1711,7 @@ SelectPartitionPage(PINPUT_RECORD Ir)
{ {
ASSERT(CurrentPartition); ASSERT(CurrentPartition);
Error = PartitionCreationChecks(CurrentPartition); Error = PartitionCreateChecks(CurrentPartition, 0ULL, 0);
if (Error != NOT_AN_ERROR) if (Error != NOT_AN_ERROR)
{ {
MUIDisplayError(Error, Ir, POPUP_WAIT_ANY_KEY); MUIDisplayError(Error, Ir, POPUP_WAIT_ANY_KEY);
@ -1729,7 +1729,7 @@ SelectPartitionPage(PINPUT_RECORD Ir)
if (CurrentPartition->LogicalPartition) if (CurrentPartition->LogicalPartition)
continue; continue;
Error = ExtendedPartitionCreationChecks(CurrentPartition); Error = PartitionCreateChecks(CurrentPartition, 0ULL, PARTITION_EXTENDED);
if (Error != NOT_AN_ERROR) if (Error != NOT_AN_ERROR)
{ {
MUIDisplayError(Error, Ir, POPUP_WAIT_ANY_KEY); MUIDisplayError(Error, Ir, POPUP_WAIT_ANY_KEY);
@ -1789,7 +1789,7 @@ CreateInstallPartition:
/* Create the partition if the selected region is empty */ /* Create the partition if the selected region is empty */
if (!CurrentPartition->IsPartitioned) if (!CurrentPartition->IsPartitioned)
{ {
Error = PartitionCreationChecks(CurrentPartition); Error = PartitionCreateChecks(CurrentPartition, 0ULL, 0);
if (Error != NOT_AN_ERROR) if (Error != NOT_AN_ERROR)
{ {
MUIDisplayError(Error, Ir, POPUP_WAIT_ANY_KEY); MUIDisplayError(Error, Ir, POPUP_WAIT_ANY_KEY);