Skip to content

Commit

Permalink
Merge pull request #84 from reactos/hbelusca/setup_simplify_partition_UI
Browse files Browse the repository at this point in the history
Hbelusca/setup simplify partition UI
  • Loading branch information
errortek authored Oct 27, 2023
2 parents f3b0752 + 3ce8d90 commit 47ceff8
Show file tree
Hide file tree
Showing 37 changed files with 631 additions and 946 deletions.
219 changes: 88 additions & 131 deletions base/setup/lib/utils/partlist.c
Original file line number Diff line number Diff line change
Expand Up @@ -2782,36 +2782,110 @@ GetNextUnpartitionedEntry(
return NULL;
}

ERROR_NUMBER
PartitionCreationChecks(
_In_ PPARTENTRY PartEntry)
{
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 */
if (PartEntry->IsPartitioned)
return ERROR_NEW_PARTITION;

/*
* For primary partitions
*/
if (!PartEntry->LogicalPartition)
{
/* Only one primary partition is allowed on super-floppy */
if (IsSuperFloppy(DiskEntry))
return ERROR_PARTITION_TABLE_FULL;

/* Fail if there are already 4 primary partitions in the list */
if (GetPrimaryPartitionCount(DiskEntry) >= 4)
return ERROR_PARTITION_TABLE_FULL;
}
/*
* For logical partitions
*/
else
{
// TODO: Check that we are inside an extended partition!!
// Then the following check will be useless.

/* Only one (primary) partition is allowed on super-floppy */
if (IsSuperFloppy(DiskEntry))
return ERROR_PARTITION_TABLE_FULL;
}

return ERROR_SUCCESS;
}

ERROR_NUMBER
ExtendedPartitionCreationChecks(
_In_ PPARTENTRY PartEntry)
{
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 */
if (PartEntry->IsPartitioned)
return ERROR_NEW_PARTITION;

/* Only one primary partition is allowed on super-floppy */
if (IsSuperFloppy(DiskEntry))
return ERROR_PARTITION_TABLE_FULL;

/* Fail if there are already 4 primary partitions in the list */
if (GetPrimaryPartitionCount(DiskEntry) >= 4)
return ERROR_PARTITION_TABLE_FULL;

/* Fail if there is another extended partition in the list */
if (DiskEntry->ExtendedPartition != NULL)
return ERROR_ONLY_ONE_EXTENDED;

return ERROR_SUCCESS;
}

BOOLEAN
CreatePrimaryPartition(
IN PPARTLIST List,
IN OUT PPARTENTRY PartEntry,
IN ULONGLONG SectorCount,
IN BOOLEAN AutoCreate)
CreatePartition(
_In_ PPARTLIST List,
_Inout_ PPARTENTRY PartEntry,
_In_ ULONGLONG SectorCount,
_In_ BOOLEAN AutoCreate)
{
ERROR_NUMBER Error;

DPRINT1("CreatePrimaryPartition(%I64u)\n", SectorCount);
DPRINT1("CreatePartition(%I64u)\n", SectorCount);

if (List == NULL || PartEntry == NULL ||
PartEntry->DiskEntry == NULL || PartEntry->IsPartitioned)
{
return FALSE;
}

Error = PrimaryPartitionCreationChecks(PartEntry);
Error = PartitionCreationChecks(PartEntry);
if (Error != NOT_AN_ERROR)
{
DPRINT1("PrimaryPartitionCreationChecks() failed with error %lu\n", Error);
DPRINT1("PartitionCreationChecks() failed with error %lu\n", Error);
return FALSE;
}

/* Initialize the partition entry, inserting a new blank region if needed */
if (!InitializePartitionEntry(PartEntry, SectorCount, AutoCreate))
return FALSE;

ASSERT(PartEntry->LogicalPartition == FALSE);

UpdateDiskLayout(PartEntry->DiskEntry);
AssignDriveLetters(List);

Expand All @@ -2821,7 +2895,7 @@ CreatePrimaryPartition(
static
VOID
AddLogicalDiskSpace(
IN PDISKENTRY DiskEntry)
_In_ PDISKENTRY DiskEntry)
{
ULONGLONG StartSector;
ULONGLONG SectorCount;
Expand All @@ -2848,9 +2922,9 @@ AddLogicalDiskSpace(

BOOLEAN
CreateExtendedPartition(
IN PPARTLIST List,
IN OUT PPARTENTRY PartEntry,
IN ULONGLONG SectorCount)
_In_ PPARTLIST List,
_Inout_ PPARTENTRY PartEntry,
_In_ ULONGLONG SectorCount)
{
ERROR_NUMBER Error;

Expand Down Expand Up @@ -2900,42 +2974,6 @@ CreateExtendedPartition(
return TRUE;
}

BOOLEAN
CreateLogicalPartition(
IN PPARTLIST List,
IN OUT PPARTENTRY PartEntry,
IN ULONGLONG SectorCount,
IN BOOLEAN AutoCreate)
{
ERROR_NUMBER Error;

DPRINT1("CreateLogicalPartition(%I64u)\n", SectorCount);

if (List == NULL || PartEntry == NULL ||
PartEntry->DiskEntry == NULL || PartEntry->IsPartitioned)
{
return FALSE;
}

Error = LogicalPartitionCreationChecks(PartEntry);
if (Error != NOT_AN_ERROR)
{
DPRINT1("LogicalPartitionCreationChecks() failed with error %lu\n", Error);
return FALSE;
}

/* Initialize the partition entry, inserting a new blank region if needed */
if (!InitializePartitionEntry(PartEntry, SectorCount, AutoCreate))
return FALSE;

ASSERT(PartEntry->LogicalPartition == TRUE);

UpdateDiskLayout(PartEntry->DiskEntry);
AssignDriveLetters(List);

return TRUE;
}

NTSTATUS
DismountVolume(
IN PPARTENTRY PartEntry)
Expand Down Expand Up @@ -3950,87 +3988,6 @@ SetMBRPartitionType(
DiskEntry->LayoutBuffer->PartitionEntry[PartEntry->PartitionIndex].RewritePartition = TRUE;
}

ERROR_NUMBER
PrimaryPartitionCreationChecks(
IN PPARTENTRY PartEntry)
{
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 */
if (PartEntry->IsPartitioned)
return ERROR_NEW_PARTITION;

/* Only one primary partition is allowed on super-floppy */
if (IsSuperFloppy(DiskEntry))
return ERROR_PARTITION_TABLE_FULL;

/* Fail if there are already 4 primary partitions in the list */
if (GetPrimaryPartitionCount(DiskEntry) >= 4)
return ERROR_PARTITION_TABLE_FULL;

return ERROR_SUCCESS;
}

ERROR_NUMBER
ExtendedPartitionCreationChecks(
IN PPARTENTRY PartEntry)
{
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 */
if (PartEntry->IsPartitioned)
return ERROR_NEW_PARTITION;

/* Only one primary partition is allowed on super-floppy */
if (IsSuperFloppy(DiskEntry))
return ERROR_PARTITION_TABLE_FULL;

/* Fail if there are already 4 primary partitions in the list */
if (GetPrimaryPartitionCount(DiskEntry) >= 4)
return ERROR_PARTITION_TABLE_FULL;

/* Fail if there is another extended partition in the list */
if (DiskEntry->ExtendedPartition != NULL)
return ERROR_ONLY_ONE_EXTENDED;

return ERROR_SUCCESS;
}

ERROR_NUMBER
LogicalPartitionCreationChecks(
IN PPARTENTRY PartEntry)
{
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 */
if (PartEntry->IsPartitioned)
return ERROR_NEW_PARTITION;

/* Only one primary partition is allowed on super-floppy */
if (IsSuperFloppy(DiskEntry))
return ERROR_PARTITION_TABLE_FULL;

return ERROR_SUCCESS;
}

BOOLEAN
GetNextUnformattedPartition(
IN PPARTLIST List,
Expand Down
43 changes: 16 additions & 27 deletions base/setup/lib/utils/partlist.h
Original file line number Diff line number Diff line change
Expand Up @@ -294,25 +294,26 @@ GetPrevPartition(
IN PPARTLIST List,
IN PPARTENTRY CurrentPart OPTIONAL);

BOOLEAN
CreatePrimaryPartition(
IN PPARTLIST List,
IN OUT PPARTENTRY PartEntry,
IN ULONGLONG SectorCount,
IN BOOLEAN AutoCreate);
ERROR_NUMBER
PartitionCreationChecks(
_In_ PPARTENTRY PartEntry);

ERROR_NUMBER
ExtendedPartitionCreationChecks(
_In_ PPARTENTRY PartEntry);

BOOLEAN
CreateExtendedPartition(
IN PPARTLIST List,
IN OUT PPARTENTRY PartEntry,
IN ULONGLONG SectorCount);
CreatePartition(
_In_ PPARTLIST List,
_Inout_ PPARTENTRY PartEntry,
_In_ ULONGLONG SectorCount,
_In_ BOOLEAN AutoCreate);

BOOLEAN
CreateLogicalPartition(
IN PPARTLIST List,
IN OUT PPARTENTRY PartEntry,
IN ULONGLONG SectorCount,
IN BOOLEAN AutoCreate);
CreateExtendedPartition(
_In_ PPARTLIST List,
_Inout_ PPARTENTRY PartEntry,
_In_ ULONGLONG SectorCount);

NTSTATUS
DismountVolume(
Expand Down Expand Up @@ -360,18 +361,6 @@ SetMBRPartitionType(
IN PPARTENTRY PartEntry,
IN UCHAR PartitionType);

ERROR_NUMBER
PrimaryPartitionCreationChecks(
IN PPARTENTRY PartEntry);

ERROR_NUMBER
ExtendedPartitionCreationChecks(
IN PPARTENTRY PartEntry);

ERROR_NUMBER
LogicalPartitionCreationChecks(
IN PPARTENTRY PartEntry);

BOOLEAN
GetNextUnformattedPartition(
IN PPARTLIST List,
Expand Down
2 changes: 1 addition & 1 deletion base/setup/usetup/format.c
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ DoFormat(
10,
24,
TRUE,
MUIGetString(STRING_FORMATTINGDISK));
MUIGetString(STRING_FORMATTINGPART));

ProgressSetStepCount(FormatProgressBar, 100);

Expand Down
Loading

0 comments on commit 47ceff8

Please sign in to comment.