Skip to content

Commit 0ca4e6d

Browse files
committed
[SETUPLIB][REACTOS][USETUP] Finish unification of MBR extended and primary/logical partitions
Addendum to commmit 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 89a3b8f commit 0ca4e6d

File tree

4 files changed

+44
-56
lines changed

4 files changed

+44
-56
lines changed

base/setup/lib/utils/partlist.c

Lines changed: 35 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -2818,41 +2818,48 @@ 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+
ASSERT(DiskEntry->DiskStyle == PARTITION_STYLE_MBR);
2831+
ASSERT(!PartEntry->IsPartitioned);
2832+
2833+
if (isContainer)
28282834
{
2829-
DPRINT1("GPT-partitioned disk detected, not currently supported by SETUP!\n");
2830-
return ERROR_WARN_PARTITION;
2831-
}
2835+
/* Cannot create an extended partition within logical partition space */
2836+
if (PartEntry->LogicalPartition)
2837+
return ERROR_ONLY_ONE_EXTENDED;
28322838

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

28372844
/*
2838-
* For primary partitions
2845+
* Primary or Extended partitions
28392846
*/
2840-
if (!PartEntry->LogicalPartition)
2847+
if (!PartEntry->LogicalPartition || isContainer)
28412848
{
28422849
/* Only one primary partition is allowed on super-floppy */
28432850
if (IsSuperFloppy(DiskEntry))
28442851
return ERROR_PARTITION_TABLE_FULL;
28452852

2846-
/* Fail if there are already 4 primary partitions in the list */
2853+
/* Fail if there are too many primary partitions */
28472854
if (GetPrimaryPartitionCount(DiskEntry) >= 4)
28482855
return ERROR_PARTITION_TABLE_FULL;
28492856
}
28502857
/*
2851-
* For logical partitions
2858+
* Logical partitions
28522859
*/
28532860
else
28542861
{
2855-
// TODO: Check that we are inside an extended partition!!
2862+
// TODO: Check that we are inside an extended partition!
28562863
// Then the following check will be useless.
28572864

28582865
/* Only one (primary) partition is allowed on super-floppy */
@@ -2864,38 +2871,24 @@ PartitionCreationChecks(
28642871
}
28652872

28662873
ERROR_NUMBER
2867-
ExtendedPartitionCreationChecks(
2868-
_In_ PPARTENTRY PartEntry)
2874+
PartitionCreateChecks(
2875+
_In_ PPARTENTRY PartEntry,
2876+
_In_opt_ ULONGLONG SizeBytes,
2877+
_In_opt_ ULONG_PTR PartitionInfo)
28692878
{
28702879
PDISKENTRY DiskEntry = PartEntry->DiskEntry;
28712880

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-
}
2877-
28782881
/* Fail if the partition is already in use */
28792882
if (PartEntry->IsPartitioned)
28802883
return ERROR_NEW_PARTITION;
28812884

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;
2885+
if (DiskEntry->DiskStyle == PARTITION_STYLE_MBR)
2886+
return MBRPartitionCreateChecks(PartEntry, SizeBytes, PartitionInfo);
2887+
else // if (DiskEntry->DiskStyle == PARTITION_STYLE_GPT)
2888+
{
2889+
DPRINT1("GPT-partitioned disk detected, not currently supported by SETUP!\n");
2890+
return ERROR_WARN_PARTITION;
2891+
}
28992892
}
29002893

29012894
// TODO: Improve upon the PartitionInfo parameter later
@@ -2926,13 +2919,10 @@ CreatePartition(
29262919
return FALSE;
29272920
}
29282921

2929-
if (isContainer)
2930-
Error = ExtendedPartitionCreationChecks(PartEntry);
2931-
else
2932-
Error = PartitionCreationChecks(PartEntry);
2922+
Error = PartitionCreateChecks(PartEntry, SizeBytes, PartitionInfo);
29332923
if (Error != NOT_AN_ERROR)
29342924
{
2935-
DPRINT1("PartitionCreationChecks(%s) failed with error %lu\n", mainType, Error);
2925+
DPRINT1("PartitionCreateChecks(%s) failed with error %lu\n", mainType, Error);
29362926
return FALSE;
29372927
}
29382928

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)