mirror of
https://github.com/reactos/reactos.git
synced 2025-08-06 13:02:59 +00:00
[USETUP] Blur the boundaries between MBR "Primary" and "Logical" partitions (#5837)
Do not do that yet for extended partitions (containers). This is possible, because when creating partitions, we do that on unpartitioned space that is already "tagged" as either being "logical" or not, and the partition style is inherited from that. The resulting code is simpler, yet working as it should. This will also help in the future for supporting other platforms, where the concept of "primary", "extended" and "logical" partitions do not exist (basically all platforms except BIOS-based PC-AT).
This commit is contained in:
parent
9ed4bf1ed7
commit
ebcf3cf38e
3 changed files with 158 additions and 245 deletions
|
@ -2782,16 +2782,92 @@ 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)
|
||||
|
@ -2799,10 +2875,10 @@ CreatePrimaryPartition(
|
|||
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;
|
||||
}
|
||||
|
||||
|
@ -2810,8 +2886,6 @@ CreatePrimaryPartition(
|
|||
if (!InitializePartitionEntry(PartEntry, SectorCount, AutoCreate))
|
||||
return FALSE;
|
||||
|
||||
ASSERT(PartEntry->LogicalPartition == FALSE);
|
||||
|
||||
UpdateDiskLayout(PartEntry->DiskEntry);
|
||||
AssignDriveLetters(List);
|
||||
|
||||
|
@ -2821,7 +2895,7 @@ CreatePrimaryPartition(
|
|||
static
|
||||
VOID
|
||||
AddLogicalDiskSpace(
|
||||
IN PDISKENTRY DiskEntry)
|
||||
_In_ PDISKENTRY DiskEntry)
|
||||
{
|
||||
ULONGLONG StartSector;
|
||||
ULONGLONG SectorCount;
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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)
|
||||
|
@ -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,
|
||||
|
|
|
@ -294,25 +294,26 @@ GetPrevPartition(
|
|||
IN PPARTLIST List,
|
||||
IN PPARTENTRY CurrentPart OPTIONAL);
|
||||
|
||||
ERROR_NUMBER
|
||||
PartitionCreationChecks(
|
||||
_In_ PPARTENTRY PartEntry);
|
||||
|
||||
ERROR_NUMBER
|
||||
ExtendedPartitionCreationChecks(
|
||||
_In_ PPARTENTRY PartEntry);
|
||||
|
||||
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);
|
||||
|
||||
BOOLEAN
|
||||
CreateExtendedPartition(
|
||||
IN PPARTLIST List,
|
||||
IN OUT PPARTENTRY PartEntry,
|
||||
IN ULONGLONG SectorCount);
|
||||
|
||||
BOOLEAN
|
||||
CreateLogicalPartition(
|
||||
IN PPARTLIST List,
|
||||
IN OUT PPARTENTRY PartEntry,
|
||||
IN ULONGLONG SectorCount,
|
||||
IN BOOLEAN AutoCreate);
|
||||
_In_ PPARTLIST List,
|
||||
_Inout_ PPARTENTRY PartEntry,
|
||||
_In_ ULONGLONG SectorCount);
|
||||
|
||||
NTSTATUS
|
||||
DismountVolume(
|
||||
|
@ -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,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue