Skip to content

Commit 4aee028

Browse files
committed
[SETUPLIB][REACTOS][USETUP] Finish unification of MBR extended and primary/logical partitions
Fixes previous attempt at commit 0ca4e6d, which was reverted by commit bbdcc14 because the partitioning checks mistook unpartitioned disks as GPT. Addendum to commit 99f0937. 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.
1 parent 69bf140 commit 4aee028

File tree

4 files changed

+50
-57
lines changed

4 files changed

+50
-57
lines changed

base/setup/lib/utils/partlist.c

Lines changed: 41 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -2818,41 +2818,49 @@ GetAdjUnpartitionedEntry(
28182818
return NULL;
28192819
}
28202820

2821-
ERROR_NUMBER
2822-
PartitionCreationChecks(
2823-
_In_ PPARTENTRY PartEntry)
2821+
static ERROR_NUMBER
2822+
MBRPartitionCreateChecks(
2823+
_In_ PPARTENTRY PartEntry,
2824+
_In_opt_ ULONGLONG SizeBytes,
2825+
_In_opt_ ULONG_PTR PartitionInfo)
28242826
{
28252827
PDISKENTRY DiskEntry = PartEntry->DiskEntry;
2828+
BOOLEAN isContainer = IsContainerPartition((UCHAR)PartitionInfo);
28262829

2827-
if (DiskEntry->DiskStyle == PARTITION_STYLE_GPT)
2830+
// TODO: Re-enable once we initialize unpartitioned disks before using them.
2831+
// ASSERT(DiskEntry->DiskStyle == PARTITION_STYLE_MBR);
2832+
ASSERT(!PartEntry->IsPartitioned);
2833+
2834+
if (isContainer)
28282835
{
2829-
DPRINT1("GPT-partitioned disk detected, not currently supported by SETUP!\n");
2830-
return ERROR_WARN_PARTITION;
2831-
}
2836+
/* Cannot create an extended partition within logical partition space */
2837+
if (PartEntry->LogicalPartition)
2838+
return ERROR_ONLY_ONE_EXTENDED;
28322839

2833-
/* Fail if the partition is already in use */
2834-
if (PartEntry->IsPartitioned)
2835-
return ERROR_NEW_PARTITION;
2840+
/* Fail if there is another extended partition in the list */
2841+
if (DiskEntry->ExtendedPartition)
2842+
return ERROR_ONLY_ONE_EXTENDED;
2843+
}
28362844

28372845
/*
2838-
* For primary partitions
2846+
* Primary or Extended partitions
28392847
*/
2840-
if (!PartEntry->LogicalPartition)
2848+
if (!PartEntry->LogicalPartition || isContainer)
28412849
{
28422850
/* Only one primary partition is allowed on super-floppy */
28432851
if (IsSuperFloppy(DiskEntry))
28442852
return ERROR_PARTITION_TABLE_FULL;
28452853

2846-
/* Fail if there are already 4 primary partitions in the list */
2854+
/* Fail if there are too many primary partitions */
28472855
if (GetPrimaryPartitionCount(DiskEntry) >= 4)
28482856
return ERROR_PARTITION_TABLE_FULL;
28492857
}
28502858
/*
2851-
* For logical partitions
2859+
* Logical partitions
28522860
*/
28532861
else
28542862
{
2855-
// TODO: Check that we are inside an extended partition!!
2863+
// TODO: Check that we are inside an extended partition!
28562864
// Then the following check will be useless.
28572865

28582866
/* Only one (primary) partition is allowed on super-floppy */
@@ -2864,38 +2872,28 @@ PartitionCreationChecks(
28642872
}
28652873

28662874
ERROR_NUMBER
2867-
ExtendedPartitionCreationChecks(
2868-
_In_ PPARTENTRY PartEntry)
2875+
PartitionCreateChecks(
2876+
_In_ PPARTENTRY PartEntry,
2877+
_In_opt_ ULONGLONG SizeBytes,
2878+
_In_opt_ ULONG_PTR PartitionInfo)
28692879
{
2870-
PDISKENTRY DiskEntry = PartEntry->DiskEntry;
2871-
2872-
if (DiskEntry->DiskStyle == PARTITION_STYLE_GPT)
2873-
{
2874-
DPRINT1("GPT-partitioned disk detected, not currently supported by SETUP!\n");
2875-
return ERROR_WARN_PARTITION;
2876-
}
2880+
// PDISKENTRY DiskEntry = PartEntry->DiskEntry;
28772881

28782882
/* Fail if the partition is already in use */
28792883
if (PartEntry->IsPartitioned)
28802884
return ERROR_NEW_PARTITION;
28812885

2882-
/* Cannot create an extended partition within logical partition space */
2883-
if (PartEntry->LogicalPartition)
2884-
return ERROR_ONLY_ONE_EXTENDED;
2885-
2886-
/* Only one primary partition is allowed on super-floppy */
2887-
if (IsSuperFloppy(DiskEntry))
2888-
return ERROR_PARTITION_TABLE_FULL;
2889-
2890-
/* Fail if there are already 4 primary partitions in the list */
2891-
if (GetPrimaryPartitionCount(DiskEntry) >= 4)
2892-
return ERROR_PARTITION_TABLE_FULL;
2893-
2894-
/* Fail if there is another extended partition in the list */
2895-
if (DiskEntry->ExtendedPartition)
2896-
return ERROR_ONLY_ONE_EXTENDED;
2897-
2898-
return ERROR_SUCCESS;
2886+
// TODO: Re-enable once we initialize unpartitioned disks before
2887+
// using them; because such disks would be mistook as GPT otherwise.
2888+
// if (DiskEntry->DiskStyle == PARTITION_STYLE_MBR)
2889+
return MBRPartitionCreateChecks(PartEntry, SizeBytes, PartitionInfo);
2890+
#if 0
2891+
else // if (DiskEntry->DiskStyle == PARTITION_STYLE_GPT)
2892+
{
2893+
DPRINT1("GPT-partitioned disk detected, not currently supported by SETUP!\n");
2894+
return ERROR_WARN_PARTITION;
2895+
}
2896+
#endif
28992897
}
29002898

29012899
// TODO: Improve upon the PartitionInfo parameter later
@@ -2926,13 +2924,10 @@ CreatePartition(
29262924
return FALSE;
29272925
}
29282926

2929-
if (isContainer)
2930-
Error = ExtendedPartitionCreationChecks(PartEntry);
2931-
else
2932-
Error = PartitionCreationChecks(PartEntry);
2927+
Error = PartitionCreateChecks(PartEntry, SizeBytes, PartitionInfo);
29332928
if (Error != NOT_AN_ERROR)
29342929
{
2935-
DPRINT1("PartitionCreationChecks(%s) failed with error %lu\n", mainType, Error);
2930+
DPRINT1("PartitionCreateChecks(%s) failed with error %lu\n", mainType, Error);
29362931
return FALSE;
29372932
}
29382933

base/setup/lib/utils/partlist.h

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -338,12 +338,10 @@ GetAdjUnpartitionedEntry(
338338
_In_ BOOLEAN Direction);
339339

340340
ERROR_NUMBER
341-
PartitionCreationChecks(
342-
_In_ PPARTENTRY PartEntry);
343-
344-
ERROR_NUMBER
345-
ExtendedPartitionCreationChecks(
346-
_In_ PPARTENTRY PartEntry);
341+
PartitionCreateChecks(
342+
_In_ PPARTENTRY PartEntry,
343+
_In_opt_ ULONGLONG SizeBytes,
344+
_In_opt_ ULONG_PTR PartitionInfo);
347345

348346
BOOLEAN
349347
CreatePartition(

base/setup/reactos/drivepage.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1975,7 +1975,7 @@ DriveDlgProc(
19751975
// TODO: In the future: first test needs to be augmented with:
19761976
// (... && PartEntry->Volume->IsSimpleVolume)
19771977
if ((PartEntry->IsPartitioned && PartEntry->Volume) ||
1978-
(!PartEntry->IsPartitioned && (PartitionCreationChecks(PartEntry) == NOT_AN_ERROR)))
1978+
(!PartEntry->IsPartitioned && (PartitionCreateChecks(PartEntry, 0ULL, 0) == NOT_AN_ERROR)))
19791979
{
19801980
// ASSERT(PartEntry != PartEntry->DiskEntry->ExtendedPartition);
19811981
ASSERT(!IsContainerPartition(PartEntry->PartitionType));
@@ -2090,7 +2090,7 @@ DriveDlgProc(
20902090
{
20912091
ULONG Error;
20922092

2093-
Error = PartitionCreationChecks(PartEntry);
2093+
Error = PartitionCreateChecks(PartEntry, 0ULL, 0);
20942094
if (Error != NOT_AN_ERROR)
20952095
{
20962096
// MUIDisplayError(Error, Ir, POPUP_WAIT_ANY_KEY);

base/setup/usetup/usetup.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1711,7 +1711,7 @@ SelectPartitionPage(PINPUT_RECORD Ir)
17111711
{
17121712
ASSERT(CurrentPartition);
17131713

1714-
Error = PartitionCreationChecks(CurrentPartition);
1714+
Error = PartitionCreateChecks(CurrentPartition, 0ULL, 0);
17151715
if (Error != NOT_AN_ERROR)
17161716
{
17171717
MUIDisplayError(Error, Ir, POPUP_WAIT_ANY_KEY);
@@ -1729,7 +1729,7 @@ SelectPartitionPage(PINPUT_RECORD Ir)
17291729
if (CurrentPartition->LogicalPartition)
17301730
continue;
17311731

1732-
Error = ExtendedPartitionCreationChecks(CurrentPartition);
1732+
Error = PartitionCreateChecks(CurrentPartition, 0ULL, PARTITION_EXTENDED);
17331733
if (Error != NOT_AN_ERROR)
17341734
{
17351735
MUIDisplayError(Error, Ir, POPUP_WAIT_ANY_KEY);
@@ -1789,7 +1789,7 @@ SelectPartitionPage(PINPUT_RECORD Ir)
17891789
/* Create the partition if the selected region is empty */
17901790
if (!CurrentPartition->IsPartitioned)
17911791
{
1792-
Error = PartitionCreationChecks(CurrentPartition);
1792+
Error = PartitionCreateChecks(CurrentPartition, 0ULL, 0);
17931793
if (Error != NOT_AN_ERROR)
17941794
{
17951795
MUIDisplayError(Error, Ir, POPUP_WAIT_ANY_KEY);

0 commit comments

Comments
 (0)