[SETUPLIB][USETUP] Remove CurrentDisk/Partition from the partlist lib code, and move these into the UI code.

- Add also some validation ASSERTs and simplify the code here and there.

- The installation partition is called "InstallPartition", while the
  global "CurrentPartition" is the disk region currently selected in
  the partition UI list, on which prtitioning operations are effectued.

- Extend CheckActiveSystemPartition() to use an optional alternative
  disk or partition in case the actual system partition (present in the
  first disk) cannot be used, e.g. because we don't support writes on it.
This commit is contained in:
Hermès Bélusca-Maïto 2019-03-05 01:42:33 +01:00
parent 0d9ebb67ce
commit 84f3e2df5d
No known key found for this signature in database
GPG key ID: 3B2539C65E7B93D0
8 changed files with 383 additions and 356 deletions

View file

@ -624,11 +624,11 @@ NTSTATUS
InitDestinationPaths( InitDestinationPaths(
IN OUT PUSETUP_DATA pSetupData, IN OUT PUSETUP_DATA pSetupData,
IN PCWSTR InstallationDir, IN PCWSTR InstallationDir,
IN PDISKENTRY DiskEntry, // FIXME: HACK!
IN PPARTENTRY PartEntry) // FIXME: HACK! IN PPARTENTRY PartEntry) // FIXME: HACK!
{ {
WCHAR PathBuffer[MAX_PATH];
NTSTATUS Status; NTSTATUS Status;
PDISKENTRY DiskEntry = PartEntry->DiskEntry;
WCHAR PathBuffer[MAX_PATH];
ASSERT(PartEntry->IsPartitioned && PartEntry->PartitionNumber != 0); ASSERT(PartEntry->IsPartitioned && PartEntry->PartitionNumber != 0);

View file

@ -159,7 +159,6 @@ NTSTATUS
InitDestinationPaths( InitDestinationPaths(
IN OUT PUSETUP_DATA pSetupData, IN OUT PUSETUP_DATA pSetupData,
IN PCWSTR InstallationDir, IN PCWSTR InstallationDir,
IN PDISKENTRY DiskEntry, // FIXME: HACK!
IN PPARTENTRY PartEntry); // FIXME: HACK! IN PPARTENTRY PartEntry); // FIXME: HACK!
// NTSTATUS // NTSTATUS

View file

@ -1407,6 +1407,8 @@ AddDiskToList(
return; return;
} }
DiskEntry->PartList = List;
// DiskEntry->Checksum = Checksum; // DiskEntry->Checksum = Checksum;
// DiskEntry->Signature = Signature; // DiskEntry->Signature = Signature;
DiskEntry->BiosFound = FALSE; DiskEntry->BiosFound = FALSE;
@ -1670,9 +1672,6 @@ CreatePartitionList(VOID)
if (List == NULL) if (List == NULL)
return NULL; return NULL;
List->CurrentDisk = NULL;
List->CurrentPartition = NULL;
List->SystemPartition = NULL; List->SystemPartition = NULL;
List->OriginalSystemPartition = NULL; List->OriginalSystemPartition = NULL;
@ -1727,30 +1726,6 @@ CreatePartitionList(VOID)
AssignDriveLetters(List); AssignDriveLetters(List);
/* Search for first usable disk and partition */
if (IsListEmpty(&List->DiskListHead))
{
List->CurrentDisk = NULL;
List->CurrentPartition = NULL;
}
else
{
List->CurrentDisk = CONTAINING_RECORD(List->DiskListHead.Flink,
DISKENTRY,
ListEntry);
if (IsListEmpty(&List->CurrentDisk->PrimaryPartListHead))
{
List->CurrentPartition = NULL;
}
else
{
List->CurrentPartition = CONTAINING_RECORD(List->CurrentDisk->PrimaryPartListHead.Flink,
PARTENTRY,
ListEntry);
}
}
return List; return List;
} }
@ -2006,7 +1981,7 @@ GetDiskOrPartition(
// //
// NOTE: Was introduced broken in r6258 by Casper // NOTE: Was introduced broken in r6258 by Casper
// //
BOOLEAN PPARTENTRY
SelectPartition( SelectPartition(
IN PPARTLIST List, IN PPARTLIST List,
IN ULONG DiskNumber, IN ULONG DiskNumber,
@ -2017,59 +1992,55 @@ SelectPartition(
DiskEntry = GetDiskByNumber(List, DiskNumber); DiskEntry = GetDiskByNumber(List, DiskNumber);
if (!DiskEntry) if (!DiskEntry)
return FALSE; return NULL;
PartEntry = GetPartition(/*List,*/ DiskEntry, PartitionNumber); PartEntry = GetPartition(/*List,*/ DiskEntry, PartitionNumber);
if (!PartEntry) if (!PartEntry)
return FALSE; return NULL;
ASSERT(PartEntry->DiskEntry == DiskEntry); ASSERT(PartEntry->DiskEntry == DiskEntry);
ASSERT(DiskEntry->DiskNumber == DiskNumber); ASSERT(DiskEntry->DiskNumber == DiskNumber);
ASSERT(PartEntry->PartitionNumber == PartitionNumber); ASSERT(PartEntry->PartitionNumber == PartitionNumber);
List->CurrentDisk = DiskEntry; return PartEntry;
List->CurrentPartition = PartEntry;
return TRUE;
} }
PPARTENTRY PPARTENTRY
GetNextPartition( GetNextPartition(
IN PPARTLIST List) IN PPARTLIST List,
IN PPARTENTRY CurrentPart OPTIONAL)
{ {
PLIST_ENTRY DiskListEntry; PLIST_ENTRY DiskListEntry;
PLIST_ENTRY PartListEntry; PLIST_ENTRY PartListEntry;
PDISKENTRY DiskEntry; PDISKENTRY CurrentDisk;
PPARTENTRY PartEntry;
/* Fail if no disks are available */ /* Fail if no disks are available */
if (IsListEmpty(&List->DiskListHead)) if (IsListEmpty(&List->DiskListHead))
return NULL; return NULL;
/* Check for next usable entry on current disk */ /* Check for the next usable entry on the current partition's disk */
if (List->CurrentPartition != NULL) if (CurrentPart != NULL)
{ {
if (List->CurrentPartition->LogicalPartition) CurrentDisk = CurrentPart->DiskEntry;
if (CurrentPart->LogicalPartition)
{ {
/* Logical partition */ /* Logical partition */
PartListEntry = List->CurrentPartition->ListEntry.Flink; PartListEntry = CurrentPart->ListEntry.Flink;
if (PartListEntry != &List->CurrentDisk->LogicalPartListHead) if (PartListEntry != &CurrentDisk->LogicalPartListHead)
{ {
/* Next logical partition */ /* Next logical partition */
PartEntry = CONTAINING_RECORD(PartListEntry, PARTENTRY, ListEntry); CurrentPart = CONTAINING_RECORD(PartListEntry, PARTENTRY, ListEntry);
return CurrentPart;
List->CurrentPartition = PartEntry;
return List->CurrentPartition;
} }
else else
{ {
PartListEntry = List->CurrentDisk->ExtendedPartition->ListEntry.Flink; PartListEntry = CurrentDisk->ExtendedPartition->ListEntry.Flink;
if (PartListEntry != &List->CurrentDisk->PrimaryPartListHead) if (PartListEntry != &CurrentDisk->PrimaryPartListHead)
{ {
PartEntry = CONTAINING_RECORD(PartListEntry, PARTENTRY, ListEntry); CurrentPart = CONTAINING_RECORD(PartListEntry, PARTENTRY, ListEntry);
return CurrentPart;
List->CurrentPartition = PartEntry;
return List->CurrentPartition;
} }
} }
} }
@ -2077,55 +2048,49 @@ GetNextPartition(
{ {
/* Primary or extended partition */ /* Primary or extended partition */
if (List->CurrentPartition->IsPartitioned && if (CurrentPart->IsPartitioned &&
IsContainerPartition(List->CurrentPartition->PartitionType)) IsContainerPartition(CurrentPart->PartitionType))
{ {
/* First logical partition */ /* First logical partition */
PartListEntry = List->CurrentDisk->LogicalPartListHead.Flink; PartListEntry = CurrentDisk->LogicalPartListHead.Flink;
if (PartListEntry != &List->CurrentDisk->LogicalPartListHead) if (PartListEntry != &CurrentDisk->LogicalPartListHead)
{ {
PartEntry = CONTAINING_RECORD(PartListEntry, PARTENTRY, ListEntry); CurrentPart = CONTAINING_RECORD(PartListEntry, PARTENTRY, ListEntry);
return CurrentPart;
List->CurrentPartition = PartEntry;
return List->CurrentPartition;
} }
} }
else else
{ {
/* Next primary partition */ /* Next primary partition */
PartListEntry = List->CurrentPartition->ListEntry.Flink; PartListEntry = CurrentPart->ListEntry.Flink;
if (PartListEntry != &List->CurrentDisk->PrimaryPartListHead) if (PartListEntry != &CurrentDisk->PrimaryPartListHead)
{ {
PartEntry = CONTAINING_RECORD(PartListEntry, PARTENTRY, ListEntry); CurrentPart = CONTAINING_RECORD(PartListEntry, PARTENTRY, ListEntry);
return CurrentPart;
List->CurrentPartition = PartEntry;
return List->CurrentPartition;
} }
} }
} }
} }
/* Search for the first partition entry on the next disk */ /* Search for the first partition entry on the next disk */
for (DiskListEntry = List->CurrentDisk->ListEntry.Flink; for (DiskListEntry = (CurrentPart ? CurrentDisk->ListEntry.Flink
: List->DiskListHead.Flink);
DiskListEntry != &List->DiskListHead; DiskListEntry != &List->DiskListHead;
DiskListEntry = DiskListEntry->Flink) DiskListEntry = DiskListEntry->Flink)
{ {
DiskEntry = CONTAINING_RECORD(DiskListEntry, DISKENTRY, ListEntry); CurrentDisk = CONTAINING_RECORD(DiskListEntry, DISKENTRY, ListEntry);
if (DiskEntry->DiskStyle == PARTITION_STYLE_GPT) if (CurrentDisk->DiskStyle == PARTITION_STYLE_GPT)
{ {
DPRINT("GPT-partitioned disk detected, not currently supported by SETUP!\n"); DPRINT("GPT-partitioned disk detected, not currently supported by SETUP!\n");
continue; continue;
} }
PartListEntry = DiskEntry->PrimaryPartListHead.Flink; PartListEntry = CurrentDisk->PrimaryPartListHead.Flink;
if (PartListEntry != &DiskEntry->PrimaryPartListHead) if (PartListEntry != &CurrentDisk->PrimaryPartListHead)
{ {
PartEntry = CONTAINING_RECORD(PartListEntry, PARTENTRY, ListEntry); CurrentPart = CONTAINING_RECORD(PartListEntry, PARTENTRY, ListEntry);
return CurrentPart;
List->CurrentDisk = DiskEntry;
List->CurrentPartition = PartEntry;
return List->CurrentPartition;
} }
} }
@ -2134,96 +2099,92 @@ GetNextPartition(
PPARTENTRY PPARTENTRY
GetPrevPartition( GetPrevPartition(
IN PPARTLIST List) IN PPARTLIST List,
IN PPARTENTRY CurrentPart OPTIONAL)
{ {
PLIST_ENTRY DiskListEntry; PLIST_ENTRY DiskListEntry;
PLIST_ENTRY PartListEntry; PLIST_ENTRY PartListEntry;
PDISKENTRY DiskEntry; PDISKENTRY CurrentDisk;
PPARTENTRY PartEntry;
/* Fail if no disks are available */ /* Fail if no disks are available */
if (IsListEmpty(&List->DiskListHead)) if (IsListEmpty(&List->DiskListHead))
return NULL; return NULL;
/* Check for previous usable entry on current disk */ /* Check for the previous usable entry on the current partition's disk */
if (List->CurrentPartition != NULL) if (CurrentPart != NULL)
{ {
if (List->CurrentPartition->LogicalPartition) CurrentDisk = CurrentPart->DiskEntry;
if (CurrentPart->LogicalPartition)
{ {
/* Logical partition */ /* Logical partition */
PartListEntry = List->CurrentPartition->ListEntry.Blink;
if (PartListEntry != &List->CurrentDisk->LogicalPartListHead) PartListEntry = CurrentPart->ListEntry.Blink;
if (PartListEntry != &CurrentDisk->LogicalPartListHead)
{ {
/* Previous logical partition */ /* Previous logical partition */
PartEntry = CONTAINING_RECORD(PartListEntry, PARTENTRY, ListEntry); CurrentPart = CONTAINING_RECORD(PartListEntry, PARTENTRY, ListEntry);
} }
else else
{ {
/* Extended partition */ /* Extended partition */
PartEntry = List->CurrentDisk->ExtendedPartition; CurrentPart = CurrentDisk->ExtendedPartition;
} }
return CurrentPart;
List->CurrentPartition = PartEntry;
return List->CurrentPartition;
} }
else else
{ {
/* Primary or extended partition */ /* Primary or extended partition */
PartListEntry = List->CurrentPartition->ListEntry.Blink; PartListEntry = CurrentPart->ListEntry.Blink;
if (PartListEntry != &List->CurrentDisk->PrimaryPartListHead) if (PartListEntry != &CurrentDisk->PrimaryPartListHead)
{ {
PartEntry = CONTAINING_RECORD(PartListEntry, PARTENTRY, ListEntry); CurrentPart = CONTAINING_RECORD(PartListEntry, PARTENTRY, ListEntry);
if (PartEntry->IsPartitioned && if (CurrentPart->IsPartitioned &&
IsContainerPartition(PartEntry->PartitionType)) IsContainerPartition(CurrentPart->PartitionType))
{ {
PartListEntry = List->CurrentDisk->LogicalPartListHead.Blink; PartListEntry = CurrentDisk->LogicalPartListHead.Blink;
PartEntry = CONTAINING_RECORD(PartListEntry, PARTENTRY, ListEntry); CurrentPart = CONTAINING_RECORD(PartListEntry, PARTENTRY, ListEntry);
} }
List->CurrentPartition = PartEntry; return CurrentPart;
return List->CurrentPartition;
} }
} }
} }
/* Search for the last partition entry on the previous disk */ /* Search for the last partition entry on the previous disk */
for (DiskListEntry = List->CurrentDisk->ListEntry.Blink; for (DiskListEntry = (CurrentPart ? CurrentDisk->ListEntry.Blink
: List->DiskListHead.Blink);
DiskListEntry != &List->DiskListHead; DiskListEntry != &List->DiskListHead;
DiskListEntry = DiskListEntry->Blink) DiskListEntry = DiskListEntry->Blink)
{ {
DiskEntry = CONTAINING_RECORD(DiskListEntry, DISKENTRY, ListEntry); CurrentDisk = CONTAINING_RECORD(DiskListEntry, DISKENTRY, ListEntry);
if (DiskEntry->DiskStyle == PARTITION_STYLE_GPT) if (CurrentDisk->DiskStyle == PARTITION_STYLE_GPT)
{ {
DPRINT("GPT-partitioned disk detected, not currently supported by SETUP!\n"); DPRINT("GPT-partitioned disk detected, not currently supported by SETUP!\n");
continue; continue;
} }
PartListEntry = DiskEntry->PrimaryPartListHead.Blink; PartListEntry = CurrentDisk->PrimaryPartListHead.Blink;
if (PartListEntry != &DiskEntry->PrimaryPartListHead) if (PartListEntry != &CurrentDisk->PrimaryPartListHead)
{ {
PartEntry = CONTAINING_RECORD(PartListEntry, PARTENTRY, ListEntry); CurrentPart = CONTAINING_RECORD(PartListEntry, PARTENTRY, ListEntry);
if (PartEntry->IsPartitioned && if (CurrentPart->IsPartitioned &&
IsContainerPartition(PartEntry->PartitionType)) IsContainerPartition(CurrentPart->PartitionType))
{ {
PartListEntry = DiskEntry->LogicalPartListHead.Blink; PartListEntry = CurrentDisk->LogicalPartListHead.Blink;
if (PartListEntry != &DiskEntry->LogicalPartListHead) if (PartListEntry != &CurrentDisk->LogicalPartListHead)
{ {
PartEntry = CONTAINING_RECORD(PartListEntry, PARTENTRY, ListEntry); CurrentPart = CONTAINING_RECORD(PartListEntry, PARTENTRY, ListEntry);
return CurrentPart;
List->CurrentDisk = DiskEntry;
List->CurrentPartition = PartEntry;
return List->CurrentPartition;
} }
} }
else else
{ {
List->CurrentDisk = DiskEntry; return CurrentPart;
List->CurrentPartition = PartEntry;
return List->CurrentPartition;
} }
} }
} }
@ -2553,9 +2514,9 @@ UpdateDiskLayout(
static static
PPARTENTRY PPARTENTRY
GetPrevUnpartitionedEntry( GetPrevUnpartitionedEntry(
IN PDISKENTRY DiskEntry,
IN PPARTENTRY PartEntry) IN PPARTENTRY PartEntry)
{ {
PDISKENTRY DiskEntry = PartEntry->DiskEntry;
PPARTENTRY PrevPartEntry; PPARTENTRY PrevPartEntry;
PLIST_ENTRY ListHead; PLIST_ENTRY ListHead;
@ -2575,7 +2536,7 @@ GetPrevUnpartitionedEntry(
PrevPartEntry = CONTAINING_RECORD(PartEntry->ListEntry.Blink, PrevPartEntry = CONTAINING_RECORD(PartEntry->ListEntry.Blink,
PARTENTRY, PARTENTRY,
ListEntry); ListEntry);
if (PrevPartEntry->IsPartitioned == FALSE) if (!PrevPartEntry->IsPartitioned)
{ {
ASSERT(PrevPartEntry->PartitionType == PARTITION_ENTRY_UNUSED); ASSERT(PrevPartEntry->PartitionType == PARTITION_ENTRY_UNUSED);
return PrevPartEntry; return PrevPartEntry;
@ -2588,9 +2549,9 @@ GetPrevUnpartitionedEntry(
static static
PPARTENTRY PPARTENTRY
GetNextUnpartitionedEntry( GetNextUnpartitionedEntry(
IN PDISKENTRY DiskEntry,
IN PPARTENTRY PartEntry) IN PPARTENTRY PartEntry)
{ {
PDISKENTRY DiskEntry = PartEntry->DiskEntry;
PPARTENTRY NextPartEntry; PPARTENTRY NextPartEntry;
PLIST_ENTRY ListHead; PLIST_ENTRY ListHead;
@ -2610,7 +2571,7 @@ GetNextUnpartitionedEntry(
NextPartEntry = CONTAINING_RECORD(PartEntry->ListEntry.Flink, NextPartEntry = CONTAINING_RECORD(PartEntry->ListEntry.Flink,
PARTENTRY, PARTENTRY,
ListEntry); ListEntry);
if (NextPartEntry->IsPartitioned == FALSE) if (!NextPartEntry->IsPartitioned)
{ {
ASSERT(NextPartEntry->PartitionType == PARTITION_ENTRY_UNUSED); ASSERT(NextPartEntry->PartitionType == PARTITION_ENTRY_UNUSED);
return NextPartEntry; return NextPartEntry;
@ -2892,10 +2853,11 @@ DismountVolume(
return Status; return Status;
} }
VOID BOOLEAN
DeletePartition( DeletePartition(
IN PPARTLIST List, IN PPARTLIST List,
IN PPARTENTRY PartEntry) IN PPARTENTRY PartEntry,
OUT PPARTENTRY* FreeRegion OPTIONAL)
{ {
PDISKENTRY DiskEntry; PDISKENTRY DiskEntry;
PPARTENTRY PrevPartEntry; PPARTENTRY PrevPartEntry;
@ -2908,7 +2870,7 @@ DeletePartition(
PartEntry->DiskEntry == NULL || PartEntry->DiskEntry == NULL ||
PartEntry->IsPartitioned == FALSE) PartEntry->IsPartitioned == FALSE)
{ {
return; return FALSE;
} }
ASSERT(PartEntry->PartitionType != PARTITION_ENTRY_UNUSED); ASSERT(PartEntry->PartitionType != PARTITION_ENTRY_UNUSED);
@ -2949,56 +2911,49 @@ DeletePartition(
DismountVolume(PartEntry); DismountVolume(PartEntry);
} }
/* Adjust unpartitioned disk space entries */ /* Adjust the unpartitioned disk space entries */
/* Get pointer to previous and next unpartitioned entries */ /* Get pointer to previous and next unpartitioned entries */
PrevPartEntry = GetPrevUnpartitionedEntry(DiskEntry, PartEntry); PrevPartEntry = GetPrevUnpartitionedEntry(PartEntry);
NextPartEntry = GetNextUnpartitionedEntry(DiskEntry, PartEntry); NextPartEntry = GetNextUnpartitionedEntry(PartEntry);
if (PrevPartEntry != NULL && NextPartEntry != NULL) if (PrevPartEntry != NULL && NextPartEntry != NULL)
{ {
/* Merge previous, current and next unpartitioned entry */ /* Merge the previous, current and next unpartitioned entries */
/* Adjust the previous entries length */ /* Adjust the previous entry length */
PrevPartEntry->SectorCount.QuadPart += (PartEntry->SectorCount.QuadPart + NextPartEntry->SectorCount.QuadPart); PrevPartEntry->SectorCount.QuadPart += (PartEntry->SectorCount.QuadPart + NextPartEntry->SectorCount.QuadPart);
/* Remove the current entry */ /* Remove the current and next entries */
RemoveEntryList(&PartEntry->ListEntry); RemoveEntryList(&PartEntry->ListEntry);
RtlFreeHeap(ProcessHeap, 0, PartEntry); RtlFreeHeap(ProcessHeap, 0, PartEntry);
/* Remove the next entry */
RemoveEntryList(&NextPartEntry->ListEntry); RemoveEntryList(&NextPartEntry->ListEntry);
RtlFreeHeap(ProcessHeap, 0, NextPartEntry); RtlFreeHeap(ProcessHeap, 0, NextPartEntry);
/* Update current partition */ /* Optionally return the freed region */
if (List->CurrentPartition == PartEntry || if (FreeRegion)
List->CurrentPartition == NextPartEntry) *FreeRegion = PrevPartEntry;
{
List->CurrentPartition = PrevPartEntry;
}
} }
else if (PrevPartEntry != NULL && NextPartEntry == NULL) else if (PrevPartEntry != NULL && NextPartEntry == NULL)
{ {
/* Merge current and previous unpartitioned entry */ /* Merge the current and the previous unpartitioned entries */
/* Adjust the previous entries length */ /* Adjust the previous entry length */
PrevPartEntry->SectorCount.QuadPart += PartEntry->SectorCount.QuadPart; PrevPartEntry->SectorCount.QuadPart += PartEntry->SectorCount.QuadPart;
/* Remove the current entry */ /* Remove the current entry */
RemoveEntryList(&PartEntry->ListEntry); RemoveEntryList(&PartEntry->ListEntry);
RtlFreeHeap(ProcessHeap, 0, PartEntry); RtlFreeHeap(ProcessHeap, 0, PartEntry);
/* Update current partition */ /* Optionally return the freed region */
if (List->CurrentPartition == PartEntry) if (FreeRegion)
{ *FreeRegion = PrevPartEntry;
List->CurrentPartition = PrevPartEntry;
}
} }
else if (PrevPartEntry == NULL && NextPartEntry != NULL) else if (PrevPartEntry == NULL && NextPartEntry != NULL)
{ {
/* Merge current and next unpartitioned entry */ /* Merge the current and the next unpartitioned entries */
/* Adjust the next entries offset and length */ /* Adjust the next entry offset and length */
NextPartEntry->StartSector.QuadPart = PartEntry->StartSector.QuadPart; NextPartEntry->StartSector.QuadPart = PartEntry->StartSector.QuadPart;
NextPartEntry->SectorCount.QuadPart += PartEntry->SectorCount.QuadPart; NextPartEntry->SectorCount.QuadPart += PartEntry->SectorCount.QuadPart;
@ -3006,15 +2961,13 @@ DeletePartition(
RemoveEntryList(&PartEntry->ListEntry); RemoveEntryList(&PartEntry->ListEntry);
RtlFreeHeap(ProcessHeap, 0, PartEntry); RtlFreeHeap(ProcessHeap, 0, PartEntry);
/* Update current partition */ /* Optionally return the freed region */
if (List->CurrentPartition == PartEntry) if (FreeRegion)
{ *FreeRegion = NextPartEntry;
List->CurrentPartition = NextPartEntry;
}
} }
else else
{ {
/* Nothing to merge but change current entry */ /* Nothing to merge but change the current entry */
PartEntry->IsPartitioned = FALSE; PartEntry->IsPartitioned = FALSE;
PartEntry->PartitionType = PARTITION_ENTRY_UNUSED; PartEntry->PartitionType = PARTITION_ENTRY_UNUSED;
PartEntry->FormatState = Unformatted; PartEntry->FormatState = Unformatted;
@ -3023,18 +2976,17 @@ DeletePartition(
PartEntry->OnDiskPartitionNumber = 0; PartEntry->OnDiskPartitionNumber = 0;
PartEntry->PartitionNumber = 0; PartEntry->PartitionNumber = 0;
// PartEntry->PartitionIndex = 0; // PartEntry->PartitionIndex = 0;
/* Optionally return the freed region */
if (FreeRegion)
*FreeRegion = PartEntry;
} }
UpdateDiskLayout(DiskEntry); UpdateDiskLayout(DiskEntry);
AssignDriveLetters(List); AssignDriveLetters(List);
}
VOID return TRUE;
DeleteCurrentPartition(
IN PPARTLIST List)
{
DeletePartition(List, List->CurrentPartition);
} }
/* /*
@ -3185,7 +3137,10 @@ IsSupportedActivePartition(
VOID VOID
CheckActiveSystemPartition( CheckActiveSystemPartition(
IN PPARTLIST List) IN PPARTLIST List,
IN BOOLEAN ForceSelect,
IN PDISKENTRY AlternateDisk OPTIONAL,
IN PPARTENTRY AlternatePart OPTIONAL)
{ {
PLIST_ENTRY ListEntry; PLIST_ENTRY ListEntry;
PDISKENTRY DiskEntry; PDISKENTRY DiskEntry;
@ -3199,7 +3154,7 @@ CheckActiveSystemPartition(
/* No system partition! */ /* No system partition! */
List->SystemPartition = NULL; List->SystemPartition = NULL;
List->OriginalSystemPartition = NULL; List->OriginalSystemPartition = NULL;
return; goto NoSystemPartition;
} }
if (List->SystemPartition != NULL) if (List->SystemPartition != NULL)
@ -3216,11 +3171,21 @@ CheckActiveSystemPartition(
List->SystemPartition = NULL; List->SystemPartition = NULL;
List->OriginalSystemPartition = NULL; List->OriginalSystemPartition = NULL;
/* Adjust the optional alternate disk if needed */
if (!AlternateDisk && AlternatePart)
AlternateDisk = AlternatePart->DiskEntry;
/* Ensure that the alternate partition is on the alternate disk */
if (AlternatePart)
ASSERT(AlternateDisk && (AlternatePart->DiskEntry == AlternateDisk));
/* Ensure that the alternate disk is in the list */
if (AlternateDisk)
ASSERT(AlternateDisk->PartList == List);
// //
// Pass == 1 : Checking the first disk. // Pass == 1 : Check the first (system) disk.
// //
DPRINT("We are here (1)!\n");
/* /*
* First, check whether the first disk (the one that will be booted * First, check whether the first disk (the one that will be booted
@ -3230,13 +3195,11 @@ CheckActiveSystemPartition(
DiskEntry = CONTAINING_RECORD(List->DiskListHead.Flink, DiskEntry = CONTAINING_RECORD(List->DiskListHead.Flink,
DISKENTRY, ListEntry); DISKENTRY, ListEntry);
// if (DiskEntry->DiskStyle == PARTITION_STYLE_GPT) if (DiskEntry->DiskStyle == PARTITION_STYLE_GPT)
// { {
// DPRINT1("GPT-partitioned disk detected, not currently supported by SETUP!\n"); DPRINT1("First (system) disk -- GPT-partitioned disk detected, not currently supported by SETUP!\n");
// continue; goto UseAlternateDisk;
// } }
DPRINT("We are here (1a)!\n");
ActivePartition = GetActiveDiskPartition(DiskEntry); ActivePartition = GetActiveDiskPartition(DiskEntry);
if (ActivePartition) if (ActivePartition)
@ -3252,14 +3215,13 @@ CheckActiveSystemPartition(
} }
} }
DPRINT("We are here (1b)!\n"); /* If this first disk is not the optional alternate disk, perform the minimal checks */
if (DiskEntry != AlternateDisk)
/* If this first disk is not the current installation disk, do the minimal checks */
if (DiskEntry != List->CurrentDisk)
{ {
/* /*
* We don't. Enumerate all the (primary) partitions in the first disk, * No active partition has been recognized. Enumerate all the (primary)
* excluding the current active partition, to find a candidate new one. * partitions in the first disk, excluding the possible current active
* partition, to find a new candidate.
*/ */
for (ListEntry = DiskEntry->PrimaryPartListHead.Flink; for (ListEntry = DiskEntry->PrimaryPartListHead.Flink;
ListEntry != &DiskEntry->PrimaryPartListHead; ListEntry != &DiskEntry->PrimaryPartListHead;
@ -3336,26 +3298,24 @@ CheckActiveSystemPartition(
} }
/**** Case where we don't have an active partition on the first disk ****/
// //
// Pass == 2 : Checking the CurrentDisk on which we install. // Pass == 2 : No active partition found: Check the alternate disk if specified.
// //
DPRINT("We are here (2)!\n");
if (DiskEntry != List->CurrentDisk) UseAlternateDisk:
{ if (!AlternateDisk || (!ForceSelect && (DiskEntry != AlternateDisk)))
/* Choose the currently selected disk */ goto NoSystemPartition;
DiskEntry = List->CurrentDisk;
if (DiskEntry->DiskStyle == PARTITION_STYLE_GPT) if (AlternateDisk->DiskStyle == PARTITION_STYLE_GPT)
{ {
DPRINT1("Current disk?! -- GPT-partitioned disk detected, not currently supported by SETUP!\n"); DPRINT1("Alternate disk -- GPT-partitioned disk detected, not currently supported by SETUP!\n");
DPRINT1("No supported active partition found on this system!\n"); goto NoSystemPartition;
return;
} }
DPRINT("We are here (2x)!\n"); if (DiskEntry != AlternateDisk)
{
/* Choose the alternate disk */
DiskEntry = AlternateDisk;
ActivePartition = GetActiveDiskPartition(DiskEntry); ActivePartition = GetActiveDiskPartition(DiskEntry);
if (ActivePartition) if (ActivePartition)
@ -3369,19 +3329,16 @@ CheckActiveSystemPartition(
} }
} }
/* We now may have an unsupported active partition, or none */
/**** Here, we either don't have an active partition, or we have one BUT it is not supported ****/
/*** /***
*** TODO: Improve the selection: *** TODO: Improve the selection:
*** - If we want a really separate system partition from the partition where *** - If we want a really separate system partition from the partition where
*** we install, do something similar to what's done below in the code. *** we install, do something similar to what's done below in the code.
*** - Otherwise if we allow for the system partition to be also the partition *** - Otherwise if we allow for the system partition to be also the partition
*** where we install, just directly fall down to List->CurrentPartition. *** where we install, just directly fall down to using AlternatePart.
***/ ***/
DPRINT("We are here (2a)!\n");
/* Retrieve the first partition of the disk */ /* Retrieve the first partition of the disk */
PartEntry = CONTAINING_RECORD(DiskEntry->PrimaryPartListHead.Flink, PartEntry = CONTAINING_RECORD(DiskEntry->PrimaryPartListHead.Flink,
PARTENTRY, ListEntry); PARTENTRY, ListEntry);
@ -3416,8 +3373,6 @@ CheckActiveSystemPartition(
DPRINT1("NewDisk TRUE but first partition is used?\n"); DPRINT1("NewDisk TRUE but first partition is used?\n");
} }
DPRINT("We are here (3)!\n");
/* /*
* The disk is not new, check if any partition is initialized; * The disk is not new, check if any partition is initialized;
* if not, the first one becomes the system partition. * if not, the first one becomes the system partition.
@ -3455,20 +3410,27 @@ CheckActiveSystemPartition(
goto SetSystemPartition; goto SetSystemPartition;
} }
DPRINT("We are here (4)!\n");
/* /*
* The disk is not new, we did not find any actual active partition, * The disk is not new, we did not find any actual active partition,
* or the one we found was not supported, or any possible other canditate * or the one we found was not supported, or any possible other canditate
* is not supported. We then use the current (installation) partition. * is not supported. We then use the alternate partition if specified.
*/ */
/* Nothing, use the alternative system partition */ if (AlternatePart)
{
DPRINT1("No system partition found, use the alternative partition!\n"); DPRINT1("No system partition found, use the alternative partition!\n");
CandidatePartition = List->CurrentPartition; CandidatePartition = AlternatePart;
goto UseAlternativeSystemPartition; goto UseAlternativeSystemPartition;
}
else
{
NoSystemPartition:
DPRINT1("No valid or supported system partition has been found on this system!\n");
return;
}
SystemPartitionFound: SystemPartitionFound:
ASSERT(CandidatePartition);
List->SystemPartition = CandidatePartition; List->SystemPartition = CandidatePartition;
DPRINT1("Use existing active system partition %lu in disk %lu, drive letter %C\n", DPRINT1("Use existing active system partition %lu in disk %lu, drive letter %C\n",
@ -3498,6 +3460,7 @@ FindAndUseAlternativeSystemPartition:
} }
UseAlternativeSystemPartition: UseAlternativeSystemPartition:
ASSERT(CandidatePartition);
List->SystemPartition = CandidatePartition; List->SystemPartition = CandidatePartition;
DPRINT1("Use alternative active system partition %lu in disk %lu, drive letter %C\n", DPRINT1("Use alternative active system partition %lu in disk %lu, drive letter %C\n",

View file

@ -89,6 +89,9 @@ typedef struct _DISKENTRY
{ {
LIST_ENTRY ListEntry; LIST_ENTRY ListEntry;
/* The list of disks/partitions this disk belongs to */
struct _PARTLIST *PartList;
/* Disk geometry */ /* Disk geometry */
ULONGLONG Cylinders; ULONGLONG Cylinders;
@ -138,17 +141,6 @@ typedef struct _DISKENTRY
typedef struct _PARTLIST typedef struct _PARTLIST
{ {
/*
* Disk & Partition iterators.
*
* NOTE that when CurrentPartition != NULL, then CurrentPartition->DiskEntry
* must be the same as CurrentDisk. We should however keep the two members
* separated as we can have a current (selected) disk without any current
* partition, if the former does not contain any.
*/
PDISKENTRY CurrentDisk;
PPARTENTRY CurrentPartition;
/* /*
* The system partition where the boot manager resides. * The system partition where the boot manager resides.
* The corresponding system disk is obtained via: * The corresponding system disk is obtained via:
@ -275,7 +267,7 @@ GetDiskOrPartition(
OUT PDISKENTRY* pDiskEntry, OUT PDISKENTRY* pDiskEntry,
OUT PPARTENTRY* pPartEntry OPTIONAL); OUT PPARTENTRY* pPartEntry OPTIONAL);
BOOLEAN PPARTENTRY
SelectPartition( SelectPartition(
IN PPARTLIST List, IN PPARTLIST List,
IN ULONG DiskNumber, IN ULONG DiskNumber,
@ -283,11 +275,13 @@ SelectPartition(
PPARTENTRY PPARTENTRY
GetNextPartition( GetNextPartition(
IN PPARTLIST List); IN PPARTLIST List,
IN PPARTENTRY CurrentPart OPTIONAL);
PPARTENTRY PPARTENTRY
GetPrevPartition( GetPrevPartition(
IN PPARTLIST List); IN PPARTLIST List,
IN PPARTENTRY CurrentPart OPTIONAL);
BOOLEAN BOOLEAN
CreatePrimaryPartition( CreatePrimaryPartition(
@ -309,18 +303,18 @@ CreateLogicalPartition(
IN ULONGLONG SectorCount, IN ULONGLONG SectorCount,
IN BOOLEAN AutoCreate); IN BOOLEAN AutoCreate);
VOID BOOLEAN
DeletePartition( DeletePartition(
IN PPARTLIST List, IN PPARTLIST List,
IN PPARTENTRY PartEntry); IN PPARTENTRY PartEntry,
OUT PPARTENTRY* FreeRegion OPTIONAL);
VOID
DeleteCurrentPartition(
IN PPARTLIST List);
VOID VOID
CheckActiveSystemPartition( CheckActiveSystemPartition(
IN PPARTLIST List); IN PPARTLIST List,
IN BOOLEAN ForceSelect,
IN PDISKENTRY AlternateDisk OPTIONAL,
IN PPARTENTRY AlternatePart OPTIONAL);
NTSTATUS NTSTATUS
WritePartitions( WritePartitions(

View file

@ -792,12 +792,13 @@ DisableWizNext:
PARTENTRY PartEntry; PARTENTRY PartEntry;
DiskEntry.DiskNumber = 0; DiskEntry.DiskNumber = 0;
DiskEntry.BiosDiskNumber = 0; DiskEntry.BiosDiskNumber = 0;
PartEntry.DiskEntry = &DiskEntry;
PartEntry.PartitionNumber = 1; // 4; PartEntry.PartitionNumber = 1; // 4;
/****/ /****/
Status = InitDestinationPaths(&pSetupData->USetupData, Status = InitDestinationPaths(&pSetupData->USetupData,
NULL, // pSetupData->USetupData.InstallationDirectory, NULL, // pSetupData->USetupData.InstallationDirectory,
&DiskEntry, &PartEntry); &PartEntry);
if (!NT_SUCCESS(Status)) if (!NT_SUCCESS(Status))
{ {

View file

@ -73,6 +73,7 @@ VOID
InitPartitionListUi( InitPartitionListUi(
IN OUT PPARTLIST_UI ListUi, IN OUT PPARTLIST_UI ListUi,
IN PPARTLIST List, IN PPARTLIST List,
IN PPARTENTRY CurrentEntry OPTIONAL,
IN SHORT Left, IN SHORT Left,
IN SHORT Top, IN SHORT Top,
IN SHORT Right, IN SHORT Right,
@ -91,6 +92,37 @@ InitPartitionListUi(
ListUi->Offset = 0; ListUi->Offset = 0;
// ListUi->Redraw = TRUE; // ListUi->Redraw = TRUE;
/* Search for first usable disk and partition */
if (!CurrentEntry)
{
ListUi->CurrentDisk = NULL;
ListUi->CurrentPartition = NULL;
if (!IsListEmpty(&List->DiskListHead))
{
ListUi->CurrentDisk = CONTAINING_RECORD(List->DiskListHead.Flink,
DISKENTRY, ListEntry);
if (!IsListEmpty(&ListUi->CurrentDisk->PrimaryPartListHead))
{
ListUi->CurrentPartition = CONTAINING_RECORD(ListUi->CurrentDisk->PrimaryPartListHead.Flink,
PARTENTRY, ListEntry);
}
}
}
else
{
/*
* The CurrentEntry must belong to the associated partition list,
* and the latter must therefore not be empty.
*/
ASSERT(!IsListEmpty(&List->DiskListHead));
ASSERT(CurrentEntry->DiskEntry->PartList == List);
ListUi->CurrentPartition = CurrentEntry;
ListUi->CurrentDisk = CurrentEntry->DiskEntry;
}
} }
static static
@ -134,7 +166,6 @@ PrintPartitionData(
IN PDISKENTRY DiskEntry, IN PDISKENTRY DiskEntry,
IN PPARTENTRY PartEntry) IN PPARTENTRY PartEntry)
{ {
PPARTLIST List = ListUi->List;
CHAR LineBuffer[128]; CHAR LineBuffer[128];
COORD coPos; COORD coPos;
ULONG Written; ULONG Written;
@ -226,8 +257,8 @@ PrintPartitionData(
} }
} }
Attribute = (List->CurrentDisk == DiskEntry && Attribute = (ListUi->CurrentDisk == DiskEntry &&
List->CurrentPartition == PartEntry) ? ListUi->CurrentPartition == PartEntry) ?
FOREGROUND_BLUE | BACKGROUND_WHITE : FOREGROUND_BLUE | BACKGROUND_WHITE :
FOREGROUND_WHITE | BACKGROUND_BLUE; FOREGROUND_WHITE | BACKGROUND_BLUE;
@ -269,7 +300,6 @@ PrintDiskData(
IN PPARTLIST_UI ListUi, IN PPARTLIST_UI ListUi,
IN PDISKENTRY DiskEntry) IN PDISKENTRY DiskEntry)
{ {
// PPARTLIST List = ListUi->List;
PPARTENTRY PrimaryPartEntry, LogicalPartEntry; PPARTENTRY PrimaryPartEntry, LogicalPartEntry;
PLIST_ENTRY PrimaryEntry, LogicalEntry; PLIST_ENTRY PrimaryEntry, LogicalEntry;
CHAR LineBuffer[128]; CHAR LineBuffer[128];
@ -432,7 +462,7 @@ DrawPartitionList(
while (Entry2 != &DiskEntry->PrimaryPartListHead) while (Entry2 != &DiskEntry->PrimaryPartListHead)
{ {
PartEntry = CONTAINING_RECORD(Entry2, PARTENTRY, ListEntry); PartEntry = CONTAINING_RECORD(Entry2, PARTENTRY, ListEntry);
if (PartEntry == List->CurrentPartition) if (PartEntry == ListUi->CurrentPartition)
{ {
CurrentPartLineFound = TRUE; CurrentPartLineFound = TRUE;
} }
@ -452,7 +482,7 @@ DrawPartitionList(
while (Entry2 != &DiskEntry->LogicalPartListHead) while (Entry2 != &DiskEntry->LogicalPartListHead)
{ {
PartEntry = CONTAINING_RECORD(Entry2, PARTENTRY, ListEntry); PartEntry = CONTAINING_RECORD(Entry2, PARTENTRY, ListEntry);
if (PartEntry == List->CurrentPartition) if (PartEntry == ListUi->CurrentPartition)
{ {
CurrentPartLineFound = TRUE; CurrentPartLineFound = TRUE;
} }
@ -467,7 +497,7 @@ DrawPartitionList(
} }
} }
if (DiskEntry == List->CurrentDisk) if (DiskEntry == ListUi->CurrentDisk)
{ {
CurrentDiskLineFound = TRUE; CurrentDiskLineFound = TRUE;
} }
@ -642,16 +672,26 @@ VOID
ScrollDownPartitionList( ScrollDownPartitionList(
IN PPARTLIST_UI ListUi) IN PPARTLIST_UI ListUi)
{ {
if (GetNextPartition(ListUi->List)) PPARTENTRY NextPart = GetNextPartition(ListUi->List, ListUi->CurrentPartition);
if (NextPart)
{
ListUi->CurrentPartition = NextPart;
ListUi->CurrentDisk = NextPart->DiskEntry;
DrawPartitionList(ListUi); DrawPartitionList(ListUi);
}
} }
VOID VOID
ScrollUpPartitionList( ScrollUpPartitionList(
IN PPARTLIST_UI ListUi) IN PPARTLIST_UI ListUi)
{ {
if (GetPrevPartition(ListUi->List)) PPARTENTRY PrevPart = GetPrevPartition(ListUi->List, ListUi->CurrentPartition);
if (PrevPart)
{
ListUi->CurrentPartition = PrevPart;
ListUi->CurrentDisk = PrevPart->DiskEntry;
DrawPartitionList(ListUi); DrawPartitionList(ListUi);
}
} }
/* EOF */ /* EOF */

View file

@ -45,6 +45,16 @@ typedef struct _PARTLIST_UI
{ {
PPARTLIST List; PPARTLIST List;
/*
* Selected partition.
*
* NOTE that when CurrentPartition != NULL, then CurrentPartition->DiskEntry
* must be the same as CurrentDisk. We should however keep the two members
* separated as we can have a selected disk without any partition.
*/
PDISKENTRY CurrentDisk;
PPARTENTRY CurrentPartition;
// PLIST_ENTRY FirstShown; // PLIST_ENTRY FirstShown;
// PLIST_ENTRY LastShown; // PLIST_ENTRY LastShown;
@ -70,6 +80,7 @@ VOID
InitPartitionListUi( InitPartitionListUi(
IN OUT PPARTLIST_UI ListUi, IN OUT PPARTLIST_UI ListUi,
IN PPARTLIST List, IN PPARTLIST List,
IN PPARTENTRY CurrentEntry OPTIONAL,
IN SHORT Left, IN SHORT Left,
IN SHORT Top, IN SHORT Top,
IN SHORT Right, IN SHORT Right,

View file

@ -45,6 +45,10 @@ BOOLEAN IsUnattendedSetup = FALSE;
static USETUP_DATA USetupData; static USETUP_DATA USetupData;
/* Partition where to perform the installation */
static PPARTENTRY InstallPartition = NULL;
// static PPARTENTRY SystemPartition = NULL; // The system partition we will actually use (can be different from PartitionList->SystemPartition in case we install on removable disk)
// FIXME: Is it really useful?? Just used for SetDefaultPagefile... // FIXME: Is it really useful?? Just used for SetDefaultPagefile...
static WCHAR DestinationDriveLetter; static WCHAR DestinationDriveLetter;
@ -60,7 +64,10 @@ static BOOLEAN RepairUpdateFlag = FALSE;
/* Global partition list on the system */ /* Global partition list on the system */
static PPARTLIST PartitionList = NULL; static PPARTLIST PartitionList = NULL;
/* List of currently supported file systems for the partition to be formatted */ /* Currently selected partition entry in the list */
static PPARTENTRY CurrentPartition = NULL;
/* List of supported file systems for the partition to be formatted */
static PFILE_SYSTEM_LIST FileSystemList = NULL; static PFILE_SYSTEM_LIST FileSystemList = NULL;
/* Machine state for the formatter */ /* Machine state for the formatter */
@ -1474,14 +1481,18 @@ SelectPartitionPage(PINPUT_RECORD Ir)
if (RepairUpdateFlag) if (RepairUpdateFlag)
{ {
ASSERT(CurrentInstallation);
/* Determine the selected installation disk & partition */ /* Determine the selected installation disk & partition */
if (!SelectPartition(PartitionList, InstallPartition = SelectPartition(PartitionList,
CurrentInstallation->DiskNumber, CurrentInstallation->DiskNumber,
CurrentInstallation->PartitionNumber)) CurrentInstallation->PartitionNumber);
if (!InstallPartition)
{ {
DPRINT1("RepairUpdateFlag == TRUE, SelectPartition() returned FALSE, assert!\n"); DPRINT1("RepairUpdateFlag == TRUE, SelectPartition() returned FALSE, assert!\n");
ASSERT(FALSE); ASSERT(FALSE);
} }
ASSERT(!IsContainerPartition(InstallPartition->PartitionType));
return SELECT_FILE_SYSTEM_PAGE; return SELECT_FILE_SYSTEM_PAGE;
} }
@ -1489,52 +1500,62 @@ SelectPartitionPage(PINPUT_RECORD Ir)
MUIDisplayPage(SELECT_PARTITION_PAGE); MUIDisplayPage(SELECT_PARTITION_PAGE);
InitPartitionListUi(&ListUi, PartitionList, InitPartitionListUi(&ListUi, PartitionList,
2, CurrentPartition,
23, 2, 23,
xScreen - 3, xScreen - 3,
yScreen - 3); yScreen - 3);
DrawPartitionList(&ListUi); DrawPartitionList(&ListUi);
if (IsUnattendedSetup) if (IsUnattendedSetup)
{ {
if (!SelectPartition(PartitionList, /* Determine the selected installation disk & partition */
InstallPartition = SelectPartition(PartitionList,
USetupData.DestinationDiskNumber, USetupData.DestinationDiskNumber,
USetupData.DestinationPartitionNumber)) USetupData.DestinationPartitionNumber);
if (!InstallPartition)
{ {
CurrentPartition = ListUi.CurrentPartition;
if (USetupData.AutoPartition) if (USetupData.AutoPartition)
{ {
if (PartitionList->CurrentPartition->LogicalPartition) ASSERT(CurrentPartition != NULL);
ASSERT(!IsContainerPartition(CurrentPartition->PartitionType));
if (CurrentPartition->LogicalPartition)
{ {
CreateLogicalPartition(PartitionList, CreateLogicalPartition(PartitionList,
PartitionList->CurrentPartition, CurrentPartition,
PartitionList->CurrentPartition->SectorCount.QuadPart, CurrentPartition->SectorCount.QuadPart,
TRUE); TRUE);
} }
else else
{ {
CreatePrimaryPartition(PartitionList, CreatePrimaryPartition(PartitionList,
PartitionList->CurrentPartition, CurrentPartition,
PartitionList->CurrentPartition->SectorCount.QuadPart, CurrentPartition->SectorCount.QuadPart,
TRUE); TRUE);
} }
// FIXME?? Aren't we going to enter an infinite loop, if this test fails?? // FIXME?? Aren't we going to enter an infinite loop, if this test fails??
if (!IsDiskSizeValid(PartitionList->CurrentPartition)) if (!IsDiskSizeValid(CurrentPartition))
{ {
MUIDisplayError(ERROR_INSUFFICIENT_PARTITION_SIZE, Ir, POPUP_WAIT_ANY_KEY, MUIDisplayError(ERROR_INSUFFICIENT_PARTITION_SIZE, Ir, POPUP_WAIT_ANY_KEY,
USetupData.RequiredPartitionDiskSpace); USetupData.RequiredPartitionDiskSpace);
return SELECT_PARTITION_PAGE; /* let the user select another partition */ return SELECT_PARTITION_PAGE; /* let the user select another partition */
} }
InstallPartition = CurrentPartition;
return SELECT_FILE_SYSTEM_PAGE; return SELECT_FILE_SYSTEM_PAGE;
} }
} }
else else
{ {
DrawPartitionList(&ListUi); ASSERT(!IsContainerPartition(InstallPartition->PartitionType));
DrawPartitionList(&ListUi); // FIXME: Doesn't make much sense...
// FIXME?? Aren't we going to enter an infinite loop, if this test fails?? // FIXME?? Aren't we going to enter an infinite loop, if this test fails??
if (!IsDiskSizeValid(PartitionList->CurrentPartition)) if (!IsDiskSizeValid(InstallPartition))
{ {
MUIDisplayError(ERROR_INSUFFICIENT_PARTITION_SIZE, Ir, POPUP_WAIT_ANY_KEY, MUIDisplayError(ERROR_INSUFFICIENT_PARTITION_SIZE, Ir, POPUP_WAIT_ANY_KEY,
USetupData.RequiredPartitionDiskSpace); USetupData.RequiredPartitionDiskSpace);
@ -1547,14 +1568,16 @@ SelectPartitionPage(PINPUT_RECORD Ir)
while (TRUE) while (TRUE)
{ {
CurrentPartition = ListUi.CurrentPartition;
/* Update status text */ /* Update status text */
if (PartitionList->CurrentPartition == NULL) if (CurrentPartition == NULL)
{ {
CONSOLE_SetStatusText(MUIGetString(STRING_INSTALLCREATEPARTITION)); CONSOLE_SetStatusText(MUIGetString(STRING_INSTALLCREATEPARTITION));
} }
else if (PartitionList->CurrentPartition->LogicalPartition) else if (CurrentPartition->LogicalPartition)
{ {
if (PartitionList->CurrentPartition->IsPartitioned) if (CurrentPartition->IsPartitioned)
{ {
CONSOLE_SetStatusText(MUIGetString(STRING_DELETEPARTITION)); CONSOLE_SetStatusText(MUIGetString(STRING_DELETEPARTITION));
} }
@ -1565,9 +1588,9 @@ SelectPartitionPage(PINPUT_RECORD Ir)
} }
else else
{ {
if (PartitionList->CurrentPartition->IsPartitioned) if (CurrentPartition->IsPartitioned)
{ {
if (IsContainerPartition(PartitionList->CurrentPartition->PartitionType)) if (IsContainerPartition(CurrentPartition->PartitionType))
{ {
CONSOLE_SetStatusText(MUIGetString(STRING_DELETEPARTITION)); CONSOLE_SetStatusText(MUIGetString(STRING_DELETEPARTITION));
} }
@ -1608,15 +1631,16 @@ SelectPartitionPage(PINPUT_RECORD Ir)
} }
else if (Ir->Event.KeyEvent.wVirtualKeyCode == VK_RETURN) /* ENTER */ else if (Ir->Event.KeyEvent.wVirtualKeyCode == VK_RETURN) /* ENTER */
{ {
if (IsContainerPartition(PartitionList->CurrentPartition->PartitionType)) ASSERT(CurrentPartition != NULL);
if (IsContainerPartition(CurrentPartition->PartitionType))
continue; // return SELECT_PARTITION_PAGE; continue; // return SELECT_PARTITION_PAGE;
if (PartitionList->CurrentPartition == NULL || if (CurrentPartition->IsPartitioned == FALSE)
PartitionList->CurrentPartition->IsPartitioned == FALSE)
{ {
if (PartitionList->CurrentPartition->LogicalPartition) if (CurrentPartition->LogicalPartition)
{ {
Error = LogicalPartitionCreationChecks(PartitionList->CurrentPartition); Error = LogicalPartitionCreationChecks(CurrentPartition);
if (Error != NOT_AN_ERROR) if (Error != NOT_AN_ERROR)
{ {
MUIDisplayError(Error, Ir, POPUP_WAIT_ANY_KEY); MUIDisplayError(Error, Ir, POPUP_WAIT_ANY_KEY);
@ -1624,13 +1648,13 @@ SelectPartitionPage(PINPUT_RECORD Ir)
} }
CreateLogicalPartition(PartitionList, CreateLogicalPartition(PartitionList,
PartitionList->CurrentPartition, CurrentPartition,
0ULL, 0ULL,
TRUE); TRUE);
} }
else else
{ {
Error = PrimaryPartitionCreationChecks(PartitionList->CurrentPartition); Error = PrimaryPartitionCreationChecks(CurrentPartition);
if (Error != NOT_AN_ERROR) if (Error != NOT_AN_ERROR)
{ {
MUIDisplayError(Error, Ir, POPUP_WAIT_ANY_KEY); MUIDisplayError(Error, Ir, POPUP_WAIT_ANY_KEY);
@ -1638,26 +1662,29 @@ SelectPartitionPage(PINPUT_RECORD Ir)
} }
CreatePrimaryPartition(PartitionList, CreatePrimaryPartition(PartitionList,
PartitionList->CurrentPartition, CurrentPartition,
0ULL, 0ULL,
TRUE); TRUE);
} }
} }
if (!IsDiskSizeValid(PartitionList->CurrentPartition)) if (!IsDiskSizeValid(CurrentPartition))
{ {
MUIDisplayError(ERROR_INSUFFICIENT_PARTITION_SIZE, Ir, POPUP_WAIT_ANY_KEY, MUIDisplayError(ERROR_INSUFFICIENT_PARTITION_SIZE, Ir, POPUP_WAIT_ANY_KEY,
USetupData.RequiredPartitionDiskSpace); USetupData.RequiredPartitionDiskSpace);
return SELECT_PARTITION_PAGE; /* let the user select another partition */ return SELECT_PARTITION_PAGE; /* let the user select another partition */
} }
InstallPartition = CurrentPartition;
return SELECT_FILE_SYSTEM_PAGE; return SELECT_FILE_SYSTEM_PAGE;
} }
else if (Ir->Event.KeyEvent.wVirtualKeyCode == 'P') /* P */ else if (Ir->Event.KeyEvent.wVirtualKeyCode == 'P') /* P */
{ {
if (PartitionList->CurrentPartition->LogicalPartition == FALSE) ASSERT(CurrentPartition != NULL);
if (CurrentPartition->LogicalPartition == FALSE)
{ {
Error = PrimaryPartitionCreationChecks(PartitionList->CurrentPartition); Error = PrimaryPartitionCreationChecks(CurrentPartition);
if (Error != NOT_AN_ERROR) if (Error != NOT_AN_ERROR)
{ {
MUIDisplayError(Error, Ir, POPUP_WAIT_ANY_KEY); MUIDisplayError(Error, Ir, POPUP_WAIT_ANY_KEY);
@ -1669,9 +1696,11 @@ SelectPartitionPage(PINPUT_RECORD Ir)
} }
else if (Ir->Event.KeyEvent.wVirtualKeyCode == 'E') /* E */ else if (Ir->Event.KeyEvent.wVirtualKeyCode == 'E') /* E */
{ {
if (PartitionList->CurrentPartition->LogicalPartition == FALSE) ASSERT(CurrentPartition != NULL);
if (CurrentPartition->LogicalPartition == FALSE)
{ {
Error = ExtendedPartitionCreationChecks(PartitionList->CurrentPartition); Error = ExtendedPartitionCreationChecks(CurrentPartition);
if (Error != NOT_AN_ERROR) if (Error != NOT_AN_ERROR)
{ {
MUIDisplayError(Error, Ir, POPUP_WAIT_ANY_KEY); MUIDisplayError(Error, Ir, POPUP_WAIT_ANY_KEY);
@ -1683,9 +1712,11 @@ SelectPartitionPage(PINPUT_RECORD Ir)
} }
else if (Ir->Event.KeyEvent.wVirtualKeyCode == 'L') /* L */ else if (Ir->Event.KeyEvent.wVirtualKeyCode == 'L') /* L */
{ {
if (PartitionList->CurrentPartition->LogicalPartition) ASSERT(CurrentPartition != NULL);
if (CurrentPartition->LogicalPartition)
{ {
Error = LogicalPartitionCreationChecks(PartitionList->CurrentPartition); Error = LogicalPartitionCreationChecks(CurrentPartition);
if (Error != NOT_AN_ERROR) if (Error != NOT_AN_ERROR)
{ {
MUIDisplayError(Error, Ir, POPUP_WAIT_ANY_KEY); MUIDisplayError(Error, Ir, POPUP_WAIT_ANY_KEY);
@ -1697,33 +1728,36 @@ SelectPartitionPage(PINPUT_RECORD Ir)
} }
else if (Ir->Event.KeyEvent.wVirtualKeyCode == 'D') /* D */ else if (Ir->Event.KeyEvent.wVirtualKeyCode == 'D') /* D */
{ {
UNICODE_STRING CurrentPartition; UNICODE_STRING CurrentPartitionU;
WCHAR PathBuffer[MAX_PATH]; WCHAR PathBuffer[MAX_PATH];
if (PartitionList->CurrentPartition->IsPartitioned == FALSE) ASSERT(CurrentPartition != NULL);
if (CurrentPartition->IsPartitioned == FALSE)
{ {
MUIDisplayError(ERROR_DELETE_SPACE, Ir, POPUP_WAIT_ANY_KEY); MUIDisplayError(ERROR_DELETE_SPACE, Ir, POPUP_WAIT_ANY_KEY);
return SELECT_PARTITION_PAGE; return SELECT_PARTITION_PAGE;
} }
// TODO: Do something similar before trying to format the partition? // TODO: Do something similar before trying to format the partition?
if (!PartitionList->CurrentPartition->New && if (!CurrentPartition->New &&
PartitionList->CurrentPartition->FormatState != Unformatted) !IsContainerPartition(CurrentPartition->PartitionType) &&
CurrentPartition->FormatState != Unformatted)
{ {
ASSERT(PartitionList->CurrentPartition->PartitionNumber != 0); ASSERT(CurrentPartition->PartitionNumber != 0);
RtlStringCchPrintfW(PathBuffer, ARRAYSIZE(PathBuffer), RtlStringCchPrintfW(PathBuffer, ARRAYSIZE(PathBuffer),
L"\\Device\\Harddisk%lu\\Partition%lu\\", L"\\Device\\Harddisk%lu\\Partition%lu\\",
PartitionList->CurrentDisk->DiskNumber, CurrentPartition->DiskEntry->DiskNumber,
PartitionList->CurrentPartition->PartitionNumber); CurrentPartition->PartitionNumber);
RtlInitUnicodeString(&CurrentPartition, PathBuffer); RtlInitUnicodeString(&CurrentPartitionU, PathBuffer);
/* /*
* Check whether the user attempts to delete the partition on which * Check whether the user attempts to delete the partition on which
* the installation source is present. If so, fail with an error. * the installation source is present. If so, fail with an error.
*/ */
// &USetupData.SourceRootPath // &USetupData.SourceRootPath
if (RtlPrefixUnicodeString(&CurrentPartition, &USetupData.SourcePath, TRUE)) if (RtlPrefixUnicodeString(&CurrentPartitionU, &USetupData.SourcePath, TRUE))
{ {
PopupError("You cannot delete the partition containing the installation source!", PopupError("You cannot delete the partition containing the installation source!",
MUIGetString(STRING_CONTINUE), MUIGetString(STRING_CONTINUE),
@ -1732,8 +1766,9 @@ SelectPartitionPage(PINPUT_RECORD Ir)
} }
} }
if (PartitionList->CurrentPartition == PartitionList->SystemPartition || // FIXME TODO: PartitionList->SystemPartition is not yet initialized!!!!
PartitionList->CurrentPartition->BootIndicator) if (CurrentPartition == PartitionList->SystemPartition ||
CurrentPartition->BootIndicator)
{ {
return CONFIRM_DELETE_SYSTEM_PARTITION_PAGE; return CONFIRM_DELETE_SYSTEM_PARTITION_PAGE;
} }
@ -1947,8 +1982,8 @@ ShowPartitionSizeInputBox(SHORT Left,
static PAGE_NUMBER static PAGE_NUMBER
CreatePrimaryPartitionPage(PINPUT_RECORD Ir) CreatePrimaryPartitionPage(PINPUT_RECORD Ir)
{ {
PDISKENTRY DiskEntry;
PPARTENTRY PartEntry; PPARTENTRY PartEntry;
PDISKENTRY DiskEntry;
BOOLEAN Quit; BOOLEAN Quit;
BOOLEAN Cancel; BOOLEAN Cancel;
WCHAR InputBuffer[50]; WCHAR InputBuffer[50];
@ -1958,16 +1993,14 @@ CreatePrimaryPartitionPage(PINPUT_RECORD Ir)
ULONGLONG SectorCount; ULONGLONG SectorCount;
PCHAR Unit; PCHAR Unit;
if (PartitionList == NULL || if (PartitionList == NULL || CurrentPartition == NULL)
PartitionList->CurrentDisk == NULL ||
PartitionList->CurrentPartition == NULL)
{ {
/* FIXME: show an error dialog */ /* FIXME: show an error dialog */
return QUIT_PAGE; return QUIT_PAGE;
} }
DiskEntry = PartitionList->CurrentDisk; PartEntry = CurrentPartition;
PartEntry = PartitionList->CurrentPartition; DiskEntry = CurrentPartition->DiskEntry;
CONSOLE_SetStatusText(MUIGetString(STRING_PLEASEWAIT)); CONSOLE_SetStatusText(MUIGetString(STRING_PLEASEWAIT));
@ -2024,12 +2057,12 @@ CreatePrimaryPartitionPage(PINPUT_RECORD Ir)
#if 0 #if 0
CONSOLE_PrintTextXY(8, 10, "Maximum size of the new partition is %I64u MB", CONSOLE_PrintTextXY(8, 10, "Maximum size of the new partition is %I64u MB",
PartitionList->CurrentPartition->SectorCount * DiskEntry->BytesPerSector / MB); CurrentPartition->SectorCount * DiskEntry->BytesPerSector / MB);
#endif #endif
CONSOLE_SetStatusText(MUIGetString(STRING_CREATEPARTITION)); CONSOLE_SetStatusText(MUIGetString(STRING_CREATEPARTITION));
PartEntry = PartitionList->CurrentPartition; PartEntry = CurrentPartition;
while (TRUE) while (TRUE)
{ {
MaxSize = (PartEntry->SectorCount.QuadPart * DiskEntry->BytesPerSector) / MB; /* in MBytes (rounded) */ MaxSize = (PartEntry->SectorCount.QuadPart * DiskEntry->BytesPerSector) / MB; /* in MBytes (rounded) */
@ -2086,7 +2119,7 @@ CreatePrimaryPartitionPage(PINPUT_RECORD Ir)
DPRINT ("Partition size: %I64u bytes\n", PartSize); DPRINT ("Partition size: %I64u bytes\n", PartSize);
CreatePrimaryPartition(PartitionList, CreatePrimaryPartition(PartitionList,
PartitionList->CurrentPartition, CurrentPartition,
SectorCount, SectorCount,
FALSE); FALSE);
@ -2111,8 +2144,8 @@ CreatePrimaryPartitionPage(PINPUT_RECORD Ir)
static PAGE_NUMBER static PAGE_NUMBER
CreateExtendedPartitionPage(PINPUT_RECORD Ir) CreateExtendedPartitionPage(PINPUT_RECORD Ir)
{ {
PDISKENTRY DiskEntry;
PPARTENTRY PartEntry; PPARTENTRY PartEntry;
PDISKENTRY DiskEntry;
BOOLEAN Quit; BOOLEAN Quit;
BOOLEAN Cancel; BOOLEAN Cancel;
WCHAR InputBuffer[50]; WCHAR InputBuffer[50];
@ -2122,16 +2155,14 @@ CreateExtendedPartitionPage(PINPUT_RECORD Ir)
ULONGLONG SectorCount; ULONGLONG SectorCount;
PCHAR Unit; PCHAR Unit;
if (PartitionList == NULL || if (PartitionList == NULL || CurrentPartition == NULL)
PartitionList->CurrentDisk == NULL ||
PartitionList->CurrentPartition == NULL)
{ {
/* FIXME: show an error dialog */ /* FIXME: show an error dialog */
return QUIT_PAGE; return QUIT_PAGE;
} }
DiskEntry = PartitionList->CurrentDisk; PartEntry = CurrentPartition;
PartEntry = PartitionList->CurrentPartition; DiskEntry = CurrentPartition->DiskEntry;
CONSOLE_SetStatusText(MUIGetString(STRING_PLEASEWAIT)); CONSOLE_SetStatusText(MUIGetString(STRING_PLEASEWAIT));
@ -2188,12 +2219,12 @@ CreateExtendedPartitionPage(PINPUT_RECORD Ir)
#if 0 #if 0
CONSOLE_PrintTextXY(8, 10, "Maximum size of the new partition is %I64u MB", CONSOLE_PrintTextXY(8, 10, "Maximum size of the new partition is %I64u MB",
PartitionList->CurrentPartition->SectorCount * DiskEntry->BytesPerSector / MB); CurrentPartition->SectorCount * DiskEntry->BytesPerSector / MB);
#endif #endif
CONSOLE_SetStatusText(MUIGetString(STRING_CREATEPARTITION)); CONSOLE_SetStatusText(MUIGetString(STRING_CREATEPARTITION));
PartEntry = PartitionList->CurrentPartition; PartEntry = CurrentPartition;
while (TRUE) while (TRUE)
{ {
MaxSize = (PartEntry->SectorCount.QuadPart * DiskEntry->BytesPerSector) / MB; /* in MBytes (rounded) */ MaxSize = (PartEntry->SectorCount.QuadPart * DiskEntry->BytesPerSector) / MB; /* in MBytes (rounded) */
@ -2250,7 +2281,7 @@ CreateExtendedPartitionPage(PINPUT_RECORD Ir)
DPRINT ("Partition size: %I64u bytes\n", PartSize); DPRINT ("Partition size: %I64u bytes\n", PartSize);
CreateExtendedPartition(PartitionList, CreateExtendedPartition(PartitionList,
PartitionList->CurrentPartition, CurrentPartition,
SectorCount); SectorCount);
return SELECT_PARTITION_PAGE; return SELECT_PARTITION_PAGE;
@ -2274,8 +2305,8 @@ CreateExtendedPartitionPage(PINPUT_RECORD Ir)
static PAGE_NUMBER static PAGE_NUMBER
CreateLogicalPartitionPage(PINPUT_RECORD Ir) CreateLogicalPartitionPage(PINPUT_RECORD Ir)
{ {
PDISKENTRY DiskEntry;
PPARTENTRY PartEntry; PPARTENTRY PartEntry;
PDISKENTRY DiskEntry;
BOOLEAN Quit; BOOLEAN Quit;
BOOLEAN Cancel; BOOLEAN Cancel;
WCHAR InputBuffer[50]; WCHAR InputBuffer[50];
@ -2285,16 +2316,14 @@ CreateLogicalPartitionPage(PINPUT_RECORD Ir)
ULONGLONG SectorCount; ULONGLONG SectorCount;
PCHAR Unit; PCHAR Unit;
if (PartitionList == NULL || if (PartitionList == NULL || CurrentPartition == NULL)
PartitionList->CurrentDisk == NULL ||
PartitionList->CurrentPartition == NULL)
{ {
/* FIXME: show an error dialog */ /* FIXME: show an error dialog */
return QUIT_PAGE; return QUIT_PAGE;
} }
DiskEntry = PartitionList->CurrentDisk; PartEntry = CurrentPartition;
PartEntry = PartitionList->CurrentPartition; DiskEntry = CurrentPartition->DiskEntry;
CONSOLE_SetStatusText(MUIGetString(STRING_PLEASEWAIT)); CONSOLE_SetStatusText(MUIGetString(STRING_PLEASEWAIT));
@ -2351,12 +2380,12 @@ CreateLogicalPartitionPage(PINPUT_RECORD Ir)
#if 0 #if 0
CONSOLE_PrintTextXY(8, 10, "Maximum size of the new partition is %I64u MB", CONSOLE_PrintTextXY(8, 10, "Maximum size of the new partition is %I64u MB",
PartitionList->CurrentPartition->SectorCount * DiskEntry->BytesPerSector / MB); CurrentPartition->SectorCount * DiskEntry->BytesPerSector / MB);
#endif #endif
CONSOLE_SetStatusText(MUIGetString(STRING_CREATEPARTITION)); CONSOLE_SetStatusText(MUIGetString(STRING_CREATEPARTITION));
PartEntry = PartitionList->CurrentPartition; PartEntry = CurrentPartition;
while (TRUE) while (TRUE)
{ {
MaxSize = (PartEntry->SectorCount.QuadPart * DiskEntry->BytesPerSector) / MB; /* in MBytes (rounded) */ MaxSize = (PartEntry->SectorCount.QuadPart * DiskEntry->BytesPerSector) / MB; /* in MBytes (rounded) */
@ -2413,7 +2442,7 @@ CreateLogicalPartitionPage(PINPUT_RECORD Ir)
DPRINT("Partition size: %I64u bytes\n", PartSize); DPRINT("Partition size: %I64u bytes\n", PartSize);
CreateLogicalPartition(PartitionList, CreateLogicalPartition(PartitionList,
PartitionList->CurrentPartition, CurrentPartition,
SectorCount, SectorCount,
FALSE); FALSE);
@ -2479,23 +2508,21 @@ ConfirmDeleteSystemPartitionPage(PINPUT_RECORD Ir)
static PAGE_NUMBER static PAGE_NUMBER
DeletePartitionPage(PINPUT_RECORD Ir) DeletePartitionPage(PINPUT_RECORD Ir)
{ {
PDISKENTRY DiskEntry;
PPARTENTRY PartEntry; PPARTENTRY PartEntry;
PDISKENTRY DiskEntry;
ULONGLONG DiskSize; ULONGLONG DiskSize;
ULONGLONG PartSize; ULONGLONG PartSize;
PCHAR Unit; PCHAR Unit;
CHAR PartTypeString[32]; CHAR PartTypeString[32];
if (PartitionList == NULL || if (PartitionList == NULL || CurrentPartition == NULL)
PartitionList->CurrentDisk == NULL ||
PartitionList->CurrentPartition == NULL)
{ {
/* FIXME: show an error dialog */ /* FIXME: show an error dialog */
return QUIT_PAGE; return QUIT_PAGE;
} }
DiskEntry = PartitionList->CurrentDisk; PartEntry = CurrentPartition;
PartEntry = PartitionList->CurrentPartition; DiskEntry = CurrentPartition->DiskEntry;
MUIDisplayPage(DELETE_PARTITION_PAGE); MUIDisplayPage(DELETE_PARTITION_PAGE);
@ -2610,7 +2637,9 @@ DeletePartitionPage(PINPUT_RECORD Ir)
} }
else if (Ir->Event.KeyEvent.wVirtualKeyCode == 'D') /* D */ else if (Ir->Event.KeyEvent.wVirtualKeyCode == 'D') /* D */
{ {
DeleteCurrentPartition(PartitionList); DeletePartition(PartitionList,
CurrentPartition,
&CurrentPartition);
return SELECT_PARTITION_PAGE; return SELECT_PARTITION_PAGE;
} }
} }
@ -2650,8 +2679,8 @@ ResetFileSystemList(VOID)
static PAGE_NUMBER static PAGE_NUMBER
SelectFileSystemPage(PINPUT_RECORD Ir) SelectFileSystemPage(PINPUT_RECORD Ir)
{ {
PDISKENTRY DiskEntry;
PPARTENTRY PartEntry; PPARTENTRY PartEntry;
PDISKENTRY DiskEntry;
ULONGLONG DiskSize; ULONGLONG DiskSize;
ULONGLONG PartSize; ULONGLONG PartSize;
PCHAR DiskUnit; PCHAR DiskUnit;
@ -2662,9 +2691,7 @@ SelectFileSystemPage(PINPUT_RECORD Ir)
DPRINT("SelectFileSystemPage()\n"); DPRINT("SelectFileSystemPage()\n");
if (PartitionList == NULL || if (PartitionList == NULL || InstallPartition == NULL)
PartitionList->CurrentDisk == NULL ||
PartitionList->CurrentPartition == NULL)
{ {
/* FIXME: show an error dialog */ /* FIXME: show an error dialog */
return QUIT_PAGE; return QUIT_PAGE;
@ -2674,7 +2701,10 @@ SelectFileSystemPage(PINPUT_RECORD Ir)
if (FormatState == Start) if (FormatState == Start)
{ {
/* Find or set the active system partition */ /* Find or set the active system partition */
CheckActiveSystemPartition(PartitionList); CheckActiveSystemPartition(PartitionList,
FALSE,
InstallPartition->DiskEntry,
InstallPartition);
if (PartitionList->SystemPartition == NULL) if (PartitionList->SystemPartition == NULL)
{ {
/* FIXME: show an error dialog */ /* FIXME: show an error dialog */
@ -2720,8 +2750,8 @@ SelectFileSystemPage(PINPUT_RECORD Ir)
* we must perform a filesystem check of both the system and the * we must perform a filesystem check of both the system and the
* installation partitions. * installation partitions.
*/ */
PartitionList->CurrentPartition->NeedsCheck = TRUE; InstallPartition->NeedsCheck = TRUE;
if (PartitionList->SystemPartition != PartitionList->CurrentPartition) if (PartitionList->SystemPartition != InstallPartition)
PartitionList->SystemPartition->NeedsCheck = TRUE; PartitionList->SystemPartition->NeedsCheck = TRUE;
/* /*
@ -2755,7 +2785,7 @@ SelectFileSystemPage(PINPUT_RECORD Ir)
ASSERT(PartitionList->SystemPartition->IsPartitioned); ASSERT(PartitionList->SystemPartition->IsPartitioned);
if ((PartitionList->SystemPartition != PartitionList->CurrentPartition) && if ((PartitionList->SystemPartition != InstallPartition) &&
(PartitionList->SystemPartition->FormatState == Unformatted)) (PartitionList->SystemPartition->FormatState == Unformatted))
{ {
TempPartition = PartitionList->SystemPartition; TempPartition = PartitionList->SystemPartition;
@ -2770,10 +2800,10 @@ SelectFileSystemPage(PINPUT_RECORD Ir)
} }
else else
{ {
TempPartition = PartitionList->CurrentPartition; TempPartition = InstallPartition;
TempPartition->NeedsCheck = TRUE; TempPartition->NeedsCheck = TRUE;
if (PartitionList->SystemPartition != PartitionList->CurrentPartition) if (PartitionList->SystemPartition != InstallPartition)
{ {
/* The system partition is separate, so it had better be formatted! */ /* The system partition is separate, so it had better be formatted! */
ASSERT((PartitionList->SystemPartition->FormatState == Preformatted) || ASSERT((PartitionList->SystemPartition->FormatState == Preformatted) ||
@ -2791,7 +2821,7 @@ SelectFileSystemPage(PINPUT_RECORD Ir)
case FormatSystemPartition: case FormatSystemPartition:
{ {
TempPartition = PartitionList->CurrentPartition; TempPartition = InstallPartition;
TempPartition->NeedsCheck = TRUE; TempPartition->NeedsCheck = TRUE;
FormatState = FormatInstallPartition; FormatState = FormatInstallPartition;
@ -2843,7 +2873,7 @@ SelectFileSystemPage(PINPUT_RECORD Ir)
} }
PartEntry = TempPartition; PartEntry = TempPartition;
DiskEntry = PartEntry->DiskEntry; DiskEntry = TempPartition->DiskEntry;
ASSERT(PartEntry->IsPartitioned && PartEntry->PartitionNumber != 0); ASSERT(PartEntry->IsPartitioned && PartEntry->PartitionNumber != 0);
@ -3063,7 +3093,7 @@ SelectFileSystemPage(PINPUT_RECORD Ir)
* or the installation partition. * or the installation partition.
*/ */
if (TempPartition != PartitionList->SystemPartition && if (TempPartition != PartitionList->SystemPartition &&
TempPartition != PartitionList->CurrentPartition) TempPartition != InstallPartition)
{ {
PartEntry->NeedsCheck = FALSE; PartEntry->NeedsCheck = FALSE;
} }
@ -3093,7 +3123,7 @@ SelectFileSystemPage(PINPUT_RECORD Ir)
* QuitPage * QuitPage
* *
* SIDEEFFECTS * SIDEEFFECTS
* Sets PartitionList->CurrentPartition->FormatState * Sets InstallPartition->FormatState
* Sets USetupData.DestinationRootPath * Sets USetupData.DestinationRootPath
* *
* RETURNS * RETURNS
@ -3103,8 +3133,8 @@ static PAGE_NUMBER
FormatPartitionPage(PINPUT_RECORD Ir) FormatPartitionPage(PINPUT_RECORD Ir)
{ {
NTSTATUS Status; NTSTATUS Status;
PDISKENTRY DiskEntry;
PPARTENTRY PartEntry; PPARTENTRY PartEntry;
PDISKENTRY DiskEntry;
PFILE_SYSTEM_ITEM SelectedFileSystem; PFILE_SYSTEM_ITEM SelectedFileSystem;
UNICODE_STRING PartitionRootPath; UNICODE_STRING PartitionRootPath;
WCHAR PathBuffer[MAX_PATH]; WCHAR PathBuffer[MAX_PATH];
@ -3127,7 +3157,7 @@ FormatPartitionPage(PINPUT_RECORD Ir)
} }
PartEntry = TempPartition; PartEntry = TempPartition;
DiskEntry = PartEntry->DiskEntry; DiskEntry = TempPartition->DiskEntry;
ASSERT(PartEntry->IsPartitioned && PartEntry->PartitionNumber != 0); ASSERT(PartEntry->IsPartitioned && PartEntry->PartitionNumber != 0);
@ -3405,13 +3435,13 @@ CheckFileSystemPage(PINPUT_RECORD Ir)
static NTSTATUS static NTSTATUS
BuildInstallPaths(PWSTR InstallDir, BuildInstallPaths(
PDISKENTRY DiskEntry, IN PCWSTR InstallDir,
PPARTENTRY PartEntry) IN PPARTENTRY PartEntry)
{ {
NTSTATUS Status; NTSTATUS Status;
Status = InitDestinationPaths(&USetupData, InstallDir, DiskEntry, PartEntry); Status = InitDestinationPaths(&USetupData, InstallDir, PartEntry);
if (!NT_SUCCESS(Status)) if (!NT_SUCCESS(Status))
{ {
@ -3485,27 +3515,20 @@ IsValidPath(
static PAGE_NUMBER static PAGE_NUMBER
InstallDirectoryPage(PINPUT_RECORD Ir) InstallDirectoryPage(PINPUT_RECORD Ir)
{ {
PDISKENTRY DiskEntry;
PPARTENTRY PartEntry;
WCHAR InstallDir[MAX_PATH];
WCHAR c;
ULONG Length, Pos;
NTSTATUS Status; NTSTATUS Status;
ULONG Length, Pos;
WCHAR c;
WCHAR InstallDir[MAX_PATH];
/* We do not need the filesystem list anymore */ /* We do not need the filesystem list anymore */
ResetFileSystemList(); ResetFileSystemList();
if (PartitionList == NULL || if (PartitionList == NULL || InstallPartition == NULL)
PartitionList->CurrentDisk == NULL ||
PartitionList->CurrentPartition == NULL)
{ {
/* FIXME: show an error dialog */ /* FIXME: show an error dialog */
return QUIT_PAGE; return QUIT_PAGE;
} }
DiskEntry = PartitionList->CurrentDisk;
PartEntry = PartitionList->CurrentPartition;
// if (IsUnattendedSetup) // if (IsUnattendedSetup)
if (RepairUpdateFlag) if (RepairUpdateFlag)
wcscpy(InstallDir, CurrentInstallation->PathComponent); // SystemNtPath wcscpy(InstallDir, CurrentInstallation->PathComponent); // SystemNtPath
@ -3523,9 +3546,7 @@ InstallDirectoryPage(PINPUT_RECORD Ir)
*/ */
if ((RepairUpdateFlag || IsUnattendedSetup) && IsValidPath(InstallDir)) if ((RepairUpdateFlag || IsUnattendedSetup) && IsValidPath(InstallDir))
{ {
Status = BuildInstallPaths(InstallDir, Status = BuildInstallPaths(InstallDir, InstallPartition);
DiskEntry,
PartEntry);
if (!NT_SUCCESS(Status)) if (!NT_SUCCESS(Status))
{ {
DPRINT1("BuildInstallPaths() failed. Status code: 0x%lx", Status); DPRINT1("BuildInstallPaths() failed. Status code: 0x%lx", Status);
@ -3633,9 +3654,7 @@ InstallDirectoryPage(PINPUT_RECORD Ir)
return INSTALL_DIRECTORY_PAGE; return INSTALL_DIRECTORY_PAGE;
} }
Status = BuildInstallPaths(InstallDir, Status = BuildInstallPaths(InstallDir, InstallPartition);
DiskEntry,
PartEntry);
if (!NT_SUCCESS(Status)) if (!NT_SUCCESS(Status))
{ {
DPRINT1("BuildInstallPaths() failed. Status code: 0x%lx", Status); DPRINT1("BuildInstallPaths() failed. Status code: 0x%lx", Status);