diff --git a/base/setup/lib/utils/partlist.c b/base/setup/lib/utils/partlist.c index c917aada568..5f1044335ed 100644 --- a/base/setup/lib/utils/partlist.c +++ b/base/setup/lib/utils/partlist.c @@ -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, diff --git a/base/setup/lib/utils/partlist.h b/base/setup/lib/utils/partlist.h index cce21d2eede..c59b5e1f4b7 100644 --- a/base/setup/lib/utils/partlist.h +++ b/base/setup/lib/utils/partlist.h @@ -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, diff --git a/base/setup/usetup/usetup.c b/base/setup/usetup/usetup.c index 10bf53553dd..6cb6cfa720d 100644 --- a/base/setup/usetup/usetup.c +++ b/base/setup/usetup/usetup.c @@ -75,10 +75,9 @@ static PPARTLIST PartitionList = NULL; /* Currently selected partition entry in the list */ static PPARTENTRY CurrentPartition = NULL; static enum { - PartTypePrimary, - PartTypeExtended, - PartTypeLogical -} PartCreateType = PartTypePrimary; + PartTypeData, // On MBR-disks, primary or logical partition + PartTypeExtended // MBR-disk container +} PartCreateType = PartTypeData; /* List of supported file systems for the partition to be formatted */ static PFILE_SYSTEM_LIST FileSystemList = NULL; @@ -1607,20 +1606,10 @@ SelectPartitionPage(PINPUT_RECORD Ir) ASSERT(CurrentPartition != NULL); ASSERT(!IsContainerPartition(CurrentPartition->PartitionType)); - if (CurrentPartition->LogicalPartition) - { - CreateLogicalPartition(PartitionList, - CurrentPartition, - CurrentPartition->SectorCount.QuadPart, - TRUE); - } - else - { - CreatePrimaryPartition(PartitionList, - CurrentPartition, - CurrentPartition->SectorCount.QuadPart, - TRUE); - } + CreatePartition(PartitionList, + CurrentPartition, + CurrentPartition->SectorCount.QuadPart, + TRUE); // FIXME?? Aren't we going to enter an infinite loop, if this test fails?? if (!IsDiskSizeValid(CurrentPartition)) @@ -1654,42 +1643,40 @@ SelectPartitionPage(PINPUT_RECORD Ir) while (TRUE) { + ULONG uID; + CurrentPartition = ListUi.CurrentPartition; /* Update status text */ if (CurrentPartition == NULL) { - CONSOLE_SetStatusText(MUIGetString(STRING_INSTALLCREATEPARTITION)); - } - else if (CurrentPartition->LogicalPartition) - { - if (CurrentPartition->IsPartitioned) - { - CONSOLE_SetStatusText(MUIGetString(STRING_DELETEPARTITION)); - } - else - { - CONSOLE_SetStatusText(MUIGetString(STRING_INSTALLCREATELOGICAL)); - } + // FIXME: If we get a NULL current partition, this means that + // the current disk is of unrecognized type. So we should display + // instead a status string to initialize the disk with one of + // the recognized partitioning schemes (MBR, later: GPT, etc.) + // For the time being we don't have that, so use instead another + // known string. + uID = STRING_INSTALLCREATEPARTITION; } else { if (CurrentPartition->IsPartitioned) { - if (IsContainerPartition(CurrentPartition->PartitionType)) + uID = STRING_INSTALLDELETEPARTITION; + if (!CurrentPartition->LogicalPartition && + IsContainerPartition(CurrentPartition->PartitionType)) { - CONSOLE_SetStatusText(MUIGetString(STRING_DELETEPARTITION)); - } - else - { - CONSOLE_SetStatusText(MUIGetString(STRING_INSTALLDELETEPARTITION)); + uID = STRING_DELETEPARTITION; } } else { - CONSOLE_SetStatusText(MUIGetString(STRING_INSTALLCREATEPARTITION)); + uID = STRING_INSTALLCREATEPARTITION; + if (CurrentPartition->LogicalPartition) + uID = STRING_INSTALLCREATELOGICAL; } } + CONSOLE_SetStatusText(MUIGetString(uID)); CONSOLE_ConInKey(Ir); @@ -1741,34 +1728,17 @@ SelectPartitionPage(PINPUT_RECORD Ir) if (CurrentPartition->IsPartitioned == FALSE) { - if (CurrentPartition->LogicalPartition) + Error = PartitionCreationChecks(CurrentPartition); + if (Error != NOT_AN_ERROR) { - Error = LogicalPartitionCreationChecks(CurrentPartition); - if (Error != NOT_AN_ERROR) - { - MUIDisplayError(Error, Ir, POPUP_WAIT_ANY_KEY); - return SELECT_PARTITION_PAGE; - } - - CreateLogicalPartition(PartitionList, - CurrentPartition, - 0ULL, - TRUE); + MUIDisplayError(Error, Ir, POPUP_WAIT_ANY_KEY); + return SELECT_PARTITION_PAGE; } - else - { - Error = PrimaryPartitionCreationChecks(CurrentPartition); - if (Error != NOT_AN_ERROR) - { - MUIDisplayError(Error, Ir, POPUP_WAIT_ANY_KEY); - return SELECT_PARTITION_PAGE; - } - CreatePrimaryPartition(PartitionList, - CurrentPartition, - 0ULL, - TRUE); - } + CreatePartition(PartitionList, + CurrentPartition, + 0ULL, + TRUE); } if (!IsDiskSizeValid(CurrentPartition)) @@ -1787,14 +1757,14 @@ SelectPartitionPage(PINPUT_RECORD Ir) if (CurrentPartition->LogicalPartition == FALSE) { - Error = PrimaryPartitionCreationChecks(CurrentPartition); + Error = PartitionCreationChecks(CurrentPartition); if (Error != NOT_AN_ERROR) { MUIDisplayError(Error, Ir, POPUP_WAIT_ANY_KEY); return SELECT_PARTITION_PAGE; } - PartCreateType = PartTypePrimary; + PartCreateType = PartTypeData; return CREATE_PARTITION_PAGE; } } @@ -1821,14 +1791,14 @@ SelectPartitionPage(PINPUT_RECORD Ir) if (CurrentPartition->LogicalPartition) { - Error = LogicalPartitionCreationChecks(CurrentPartition); + Error = PartitionCreationChecks(CurrentPartition); if (Error != NOT_AN_ERROR) { MUIDisplayError(Error, Ir, POPUP_WAIT_ANY_KEY); return SELECT_PARTITION_PAGE; } - PartCreateType = PartTypeLogical; + PartCreateType = PartTypeData; return CREATE_PARTITION_PAGE; } } @@ -2102,12 +2072,16 @@ CreatePartitionPage(PINPUT_RECORD Ir) return QUIT_PAGE; } - if (PartCreateType == PartTypePrimary) + if (PartCreateType == PartTypeData) + { uID = STRING_CHOOSE_NEW_PARTITION; - else if (PartCreateType == PartTypeExtended) + if (CurrentPartition->LogicalPartition) + uID = STRING_CHOOSE_NEW_LOGICAL_PARTITION; + } + else // if (PartCreateType == PartTypeExtended) + { uID = STRING_CHOOSE_NEW_EXTENDED_PARTITION; - else // if (PartCreateType == PartTypeLogical) - uID = STRING_CHOOSE_NEW_LOGICAL_PARTITION; + } CONSOLE_SetTextXY(6, 8, MUIGetString(uID)); @@ -2169,26 +2143,19 @@ CreatePartitionPage(PINPUT_RECORD Ir) DPRINT("Partition size: %I64u bytes\n", PartSize); - if (PartCreateType == PartTypePrimary) + if (PartCreateType == PartTypeData) { - CreatePrimaryPartition(PartitionList, - CurrentPartition, - SectorCount, - FALSE); + CreatePartition(PartitionList, + CurrentPartition, + SectorCount, + FALSE); } - else if (PartCreateType == PartTypeExtended) + else // if (PartCreateType == PartTypeExtended) { CreateExtendedPartition(PartitionList, CurrentPartition, SectorCount); } - else // if (PartCreateType == PartTypeLogical) - { - CreateLogicalPartition(PartitionList, - CurrentPartition, - SectorCount, - FALSE); - } return SELECT_PARTITION_PAGE; } @@ -2443,10 +2410,10 @@ SelectFileSystemPage(PINPUT_RECORD Ir) */ if (!SystemPartition->IsPartitioned) { - CreatePrimaryPartition(PartitionList, - SystemPartition, - 0LL, // SystemPartition->SectorCount.QuadPart, - TRUE); + CreatePartition(PartitionList, + SystemPartition, + 0LL, // SystemPartition->SectorCount.QuadPart, + TRUE); ASSERT(SystemPartition->IsPartitioned); }