https://git.reactos.org/?p=reactos.git;a=commitdiff;h=2521d3c4787c60fc1b19c…
commit 2521d3c4787c60fc1b19c22ab82fd7a64a5600a9
Author: Hermès Bélusca-Maïto <hermes.belusca-maito(a)reactos.org>
AuthorDate: Sat May 13 16:40:30 2017 +0000
Commit: Hermès Bélusca-Maïto <hermes.belusca-maito(a)reactos.org>
CommitDate: Sat May 26 22:45:39 2018 +0200
[USETUP] Additions for the PartList code.
- Document more some of the fields in the PARTENTRY, DISKETNRY and PARTLIST
structures;
- Remove the redundant members "SystemDisk", "OriginalSystemDisk"
and "TempDisk" in PARTLIST as these can be consistently deduced from the
corresponding (Original)(System)(Temp)Partition members
(note that we however keep "CurrentDisk" alongside
"CurrentPartition", see the comment in the code why we do it so).
- Adjust the rest of the code to take the removal of the redundant members into
account. The 2nd parameter of GetNextUnformattedPartition() and
GetNextUncheckedPartition() is now really optional.
- Introduce a SetPartitionType() helper to simplify the code that sets the partition
type, which also automatically adjusts other internal variables of said partition in
accordance.
- "Mounted" logical drives can have assigned letters too, registered in
\DosDevices\.
svn path=/branches/setup_improvements/; revision=74532
---
base/setup/usetup/partlist.c | 176 ++++++++++++++++++++++++++++++-------------
base/setup/usetup/partlist.h | 50 +++++++++---
base/setup/usetup/usetup.c | 48 ++++--------
3 files changed, 176 insertions(+), 98 deletions(-)
diff --git a/base/setup/usetup/partlist.c b/base/setup/usetup/partlist.c
index 22867b73a4..7d52208bad 100644
--- a/base/setup/usetup/partlist.c
+++ b/base/setup/usetup/partlist.c
@@ -700,10 +700,28 @@ AddPartitionToDisk(
if (IsContainerPartition(PartEntry->PartitionType))
{
PartEntry->FormatState = Unformatted;
+ PartEntry->FileSystem = NULL;
if (LogicalPartition == FALSE && DiskEntry->ExtendedPartition ==
NULL)
DiskEntry->ExtendedPartition = PartEntry;
}
+#if 0
+ else if (IsRecognizedPartition(PartEntry->PartitionType))
+ {
+ // FIXME FIXME! We should completely rework how we get this
'FileSystemList' available...
+ PartEntry->FileSystem = GetFileSystem(FileSystemList, PartEntry);
+ if (!PartEntry->FileSystem)
+ PartEntry->FormatState = Preformatted;
+ else
+ PartEntry->FormatState = Unformatted;
+ // PartEntry->FormatState = UnknownFormat;
+ }
+ else
+ {
+ /* Unknown partition, so unknown partition format (may or may not be actually
formatted) */
+ PartEntry->FormatState = UnknownFormat;
+ }
+#endif
else if ((PartEntry->PartitionType == PARTITION_FAT_12) ||
(PartEntry->PartitionType == PARTITION_FAT_16) ||
(PartEntry->PartitionType == PARTITION_HUGE) ||
@@ -806,6 +824,7 @@ ScanForUnpartitionedDiskSpace(
DPRINT1("Total Sectors: %I64u\n",
NewPartEntry->SectorCount.QuadPart);
NewPartEntry->FormatState = Unformatted;
+ NewPartEntry->FileSystem = NULL;
InsertTailList(&DiskEntry->PrimaryPartListHead,
&NewPartEntry->ListEntry);
@@ -852,6 +871,7 @@ ScanForUnpartitionedDiskSpace(
DPRINT1("Total Sectors: %I64u\n",
NewPartEntry->SectorCount.QuadPart);
NewPartEntry->FormatState = Unformatted;
+ NewPartEntry->FileSystem = NULL;
/* Insert the table into the list */
InsertTailList(&PartEntry->ListEntry,
@@ -892,6 +912,7 @@ ScanForUnpartitionedDiskSpace(
DPRINT("Total Sectors: %I64u\n",
NewPartEntry->SectorCount.QuadPart);
NewPartEntry->FormatState = Unformatted;
+ NewPartEntry->FileSystem = NULL;
/* Append the table to the list */
InsertTailList(&DiskEntry->PrimaryPartListHead,
@@ -924,6 +945,7 @@ ScanForUnpartitionedDiskSpace(
DPRINT1("Total Sectors: %I64u\n",
NewPartEntry->SectorCount.QuadPart);
NewPartEntry->FormatState = Unformatted;
+ NewPartEntry->FileSystem = NULL;
InsertTailList(&DiskEntry->LogicalPartListHead,
&NewPartEntry->ListEntry);
@@ -971,6 +993,7 @@ ScanForUnpartitionedDiskSpace(
DPRINT("Total Sectors: %I64u\n",
NewPartEntry->SectorCount.QuadPart);
NewPartEntry->FormatState = Unformatted;
+ NewPartEntry->FileSystem = NULL;
/* Insert the table into the list */
InsertTailList(&PartEntry->ListEntry,
@@ -1012,6 +1035,7 @@ ScanForUnpartitionedDiskSpace(
DPRINT("Total Sectors: %I64u\n",
NewPartEntry->SectorCount.QuadPart);
NewPartEntry->FormatState = Unformatted;
+ NewPartEntry->FileSystem = NULL;
/* Append the table to the list */
InsertTailList(&DiskEntry->LogicalPartListHead,
@@ -1158,6 +1182,11 @@ AddDiskToList(
if (!NT_SUCCESS(Status))
return;
+ /*
+ * Check whether the disk is initialized, by looking at its MBR.
+ * NOTE that this must be generalized to GPT disks as well!
+ */
+
Mbr = (PARTITION_SECTOR*)RtlAllocateHeap(ProcessHeap,
0,
DiskGeometry.BytesPerSector);
@@ -1207,6 +1236,7 @@ AddDiskToList(
DiskEntry->BiosFound = FALSE;
/* Check if this disk has a valid MBR */
+ // FIXME: Check for the MBR signature as well, etc...
if (Mbr->BootCode[0] == 0 && Mbr->BootCode[1] == 0)
DiskEntry->NoMbr = TRUE;
else
@@ -1215,6 +1245,7 @@ AddDiskToList(
/* Free the MBR sector buffer */
RtlFreeHeap(ProcessHeap, 0, Mbr);
+
ListEntry = List->BiosDiskListHead.Flink;
while (ListEntry != &List->BiosDiskListHead)
{
@@ -1422,12 +1453,9 @@ CreatePartitionList(
List->CurrentDisk = NULL;
List->CurrentPartition = NULL;
- List->SystemDisk = NULL;
List->SystemPartition = NULL;
- List->OriginalSystemDisk = NULL;
List->OriginalSystemPartition = NULL;
- List->TempDisk = NULL;
List->TempPartition = NULL;
List->FormatState = Start;
@@ -2739,6 +2767,7 @@ CreatePrimaryPartition(
PartEntry->IsPartitioned = TRUE;
PartEntry->PartitionType = PARTITION_ENTRY_UNUSED;
PartEntry->FormatState = Unformatted;
+ PartEntry->FileSystem = NULL;
PartEntry->AutoCreate = AutoCreate;
PartEntry->New = TRUE;
PartEntry->BootIndicator = FALSE;
@@ -2776,6 +2805,7 @@ CreatePrimaryPartition(
NewPartEntry->New = TRUE;
NewPartEntry->FormatState = Unformatted;
+ NewPartEntry->FileSystem = NULL;
NewPartEntry->BootIndicator = FALSE;
PartEntry->StartSector.QuadPart = NewPartEntry->StartSector.QuadPart +
NewPartEntry->SectorCount.QuadPart;
@@ -2818,6 +2848,7 @@ AddLogicalDiskSpace(
DPRINT1("Total Sectors: %I64u\n", NewPartEntry->SectorCount.QuadPart);
NewPartEntry->FormatState = Unformatted;
+ NewPartEntry->FileSystem = NULL;
InsertTailList(&DiskEntry->LogicalPartListHead,
&NewPartEntry->ListEntry);
@@ -2854,7 +2885,8 @@ CreateExtendedPartition(
/* Convert current entry to 'new (unformatted)' */
PartEntry->IsPartitioned = TRUE;
- PartEntry->FormatState = Formatted;
+ PartEntry->FormatState = Formatted; // FIXME? Possibly to make
GetNextUnformattedPartition work (i.e. skip the extended partition container)
+ PartEntry->FileSystem = NULL;
PartEntry->AutoCreate = FALSE;
PartEntry->New = FALSE;
PartEntry->BootIndicator = FALSE;
@@ -2899,7 +2931,8 @@ CreateExtendedPartition(
NewPartEntry->StartSector.QuadPart;
NewPartEntry->New = FALSE;
- NewPartEntry->FormatState = Formatted;
+ NewPartEntry->FormatState = Formatted; // FIXME? Possibly to make
GetNextUnformattedPartition work (i.e. skip the extended partition container)
+ NewPartEntry->FileSystem = NULL;
NewPartEntry->BootIndicator = FALSE;
if (NewPartEntry->StartSector.QuadPart < 1450560)
@@ -2967,6 +3000,7 @@ CreateLogicalPartition(
PartEntry->IsPartitioned = TRUE;
PartEntry->PartitionType = PARTITION_ENTRY_UNUSED;
PartEntry->FormatState = Unformatted;
+ PartEntry->FileSystem = NULL;
PartEntry->AutoCreate = FALSE;
PartEntry->New = TRUE;
PartEntry->BootIndicator = FALSE;
@@ -3005,6 +3039,7 @@ CreateLogicalPartition(
NewPartEntry->New = TRUE;
NewPartEntry->FormatState = Unformatted;
+ NewPartEntry->FileSystem = NULL;
NewPartEntry->BootIndicator = FALSE;
NewPartEntry->LogicalPartition = TRUE;
@@ -3042,7 +3077,6 @@ DeleteCurrentPartition(
/* Clear the system disk and partition pointers if the system partition is being
deleted */
if (List->SystemPartition == List->CurrentPartition)
{
- List->SystemDisk = NULL;
List->SystemPartition = NULL;
}
@@ -3122,6 +3156,7 @@ DeleteCurrentPartition(
PartEntry->IsPartitioned = FALSE;
PartEntry->PartitionType = PARTITION_ENTRY_UNUSED;
PartEntry->FormatState = Unformatted;
+ PartEntry->FileSystem = NULL;
PartEntry->DriveLetter = 0;
}
@@ -3148,9 +3183,7 @@ CheckActiveSystemPartition(
/* Check for empty disk list */
if (IsListEmpty(&List->DiskListHead))
{
- List->SystemDisk = NULL;
List->SystemPartition = NULL;
- List->OriginalSystemDisk = NULL;
List->OriginalSystemPartition = NULL;
return;
}
@@ -3161,35 +3194,31 @@ CheckActiveSystemPartition(
/* Check for empty partition list */
if (IsListEmpty(&DiskEntry->PrimaryPartListHead))
{
- List->SystemDisk = NULL;
List->SystemPartition = NULL;
- List->OriginalSystemDisk = NULL;
List->OriginalSystemPartition = NULL;
return;
}
- if (List->SystemDisk != NULL && List->SystemPartition != NULL)
+ if (List->SystemPartition != NULL)
{
/* We already have an active system partition */
DPRINT1("Use the current system partition %lu in disk %lu, drive letter
%c\n",
List->SystemPartition->PartitionNumber,
- List->SystemDisk->DiskNumber,
+ List->SystemPartition->DiskEntry->DiskNumber,
(List->SystemPartition->DriveLetter == 0) ? '-' :
List->SystemPartition->DriveLetter);
return;
}
DPRINT1("We are here (1)!\n");
- List->SystemDisk = NULL;
List->SystemPartition = NULL;
- List->OriginalSystemDisk = NULL;
List->OriginalSystemPartition = NULL;
/* Retrieve the first partition of the disk */
PartEntry = CONTAINING_RECORD(DiskEntry->PrimaryPartListHead.Flink,
PARTENTRY,
ListEntry);
- List->SystemDisk = DiskEntry;
+ ASSERT(DiskEntry == PartEntry->DiskEntry);
List->SystemPartition = PartEntry;
//
@@ -3201,16 +3230,14 @@ CheckActiveSystemPartition(
{
if (PartEntry->PartitionType == PARTITION_ENTRY_UNUSED ||
PartEntry->BootIndicator == FALSE)
{
- /* FIXME: Might be incorrect if partitions were created by Linux FDISK */
- List->SystemDisk = DiskEntry;
+ ASSERT(DiskEntry == PartEntry->DiskEntry);
List->SystemPartition = PartEntry;
- List->OriginalSystemDisk = List->SystemDisk;
List->OriginalSystemPartition = List->SystemPartition;
DPRINT1("Use new first active system partition %lu in disk %lu, drive
letter %c\n",
List->SystemPartition->PartitionNumber,
- List->SystemDisk->DiskNumber,
+ List->SystemPartition->DiskEntry->DiskNumber,
(List->SystemPartition->DriveLetter == 0) ? '-' :
List->SystemPartition->DriveLetter);
goto SetSystemPartition;
@@ -3249,22 +3276,18 @@ CheckActiveSystemPartition(
* OK we haven't encountered any used and active partition,
* so use the first one as the system partition.
*/
-
- /* FIXME: Might be incorrect if partitions were created by Linux FDISK */
- List->OriginalSystemDisk = List->SystemDisk; // DiskEntry
+ ASSERT(DiskEntry == List->SystemPartition->DiskEntry);
List->OriginalSystemPartition = List->SystemPartition; // First PartEntry
DPRINT1("Use first active system partition %lu in disk %lu, drive letter
%c\n",
List->SystemPartition->PartitionNumber,
- List->SystemDisk->DiskNumber,
+ List->SystemPartition->DiskEntry->DiskNumber,
(List->SystemPartition->DriveLetter == 0) ? '-' :
List->SystemPartition->DriveLetter);
goto SetSystemPartition;
}
- List->SystemDisk = NULL;
List->SystemPartition = NULL;
- List->OriginalSystemDisk = NULL;
List->OriginalSystemPartition = NULL;
DPRINT1("We are here (3)!\n");
@@ -3287,7 +3310,7 @@ CheckActiveSystemPartition(
if (PartEntry->BootIndicator)
{
/* Yes, we found it */
- List->SystemDisk = DiskEntry;
+ ASSERT(DiskEntry == PartEntry->DiskEntry);
List->SystemPartition = PartEntry;
DPRINT1("Found active system partition %lu in disk %lu, drive letter
%c\n",
@@ -3300,15 +3323,14 @@ CheckActiveSystemPartition(
}
/* Check if we have found the system partition */
- if (List->SystemDisk == NULL || List->SystemPartition == NULL)
+ if (List->SystemPartition == NULL)
{
/* Nothing, use the alternative system partition */
DPRINT1("No system partition found, use the alternative
partition!\n");
goto UseAlternativeSystemPartition;
}
- /* Save them */
- List->OriginalSystemDisk = List->SystemDisk;
+ /* Save it */
List->OriginalSystemPartition = List->SystemPartition;
/*
@@ -3332,7 +3354,7 @@ CheckActiveSystemPartition(
{
DPRINT1("System partition %lu in disk %lu with no FS?!\n",
List->OriginalSystemPartition->PartitionNumber,
- List->OriginalSystemDisk->DiskNumber);
+ List->OriginalSystemPartition->DiskEntry->DiskNumber);
goto FindAndUseAlternativeSystemPartition;
}
// HACK: WARNING: We cannot write on this FS yet!
@@ -3347,7 +3369,7 @@ CheckActiveSystemPartition(
DPRINT1("Use existing active system partition %lu in disk %lu, drive letter
%c\n",
List->SystemPartition->PartitionNumber,
- List->SystemDisk->DiskNumber,
+ List->SystemPartition->DiskEntry->DiskNumber,
(List->SystemPartition->DriveLetter == 0) ? '-' :
List->SystemPartition->DriveLetter);
return;
@@ -3364,25 +3386,24 @@ FindAndUseAlternativeSystemPartition:
/* Unset the old system partition */
List->SystemPartition->BootIndicator = FALSE;
-
List->SystemDisk->LayoutBuffer->PartitionEntry[List->SystemPartition->PartitionIndex].BootIndicator
= FALSE;
-
List->SystemDisk->LayoutBuffer->PartitionEntry[List->SystemPartition->PartitionIndex].RewritePartition
= TRUE;
- List->SystemDisk->Dirty = TRUE;
+
List->SystemPartition->DiskEntry->LayoutBuffer->PartitionEntry[List->SystemPartition->PartitionIndex].BootIndicator
= FALSE;
+
List->SystemPartition->DiskEntry->LayoutBuffer->PartitionEntry[List->SystemPartition->PartitionIndex].RewritePartition
= TRUE;
+ List->SystemPartition->DiskEntry->Dirty = TRUE;
UseAlternativeSystemPartition:
- List->SystemDisk = List->CurrentDisk;
List->SystemPartition = List->CurrentPartition;
DPRINT1("Use alternative active system partition %lu in disk %lu, drive letter
%c\n",
List->SystemPartition->PartitionNumber,
- List->SystemDisk->DiskNumber,
+ List->SystemPartition->DiskEntry->DiskNumber,
(List->SystemPartition->DriveLetter == 0) ? '-' :
List->SystemPartition->DriveLetter);
SetSystemPartition:
/* Set the new active system partition */
List->SystemPartition->BootIndicator = TRUE;
-
List->SystemDisk->LayoutBuffer->PartitionEntry[List->SystemPartition->PartitionIndex].BootIndicator
= TRUE;
-
List->SystemDisk->LayoutBuffer->PartitionEntry[List->SystemPartition->PartitionIndex].RewritePartition
= TRUE;
- List->SystemDisk->Dirty = TRUE;
+
List->SystemPartition->DiskEntry->LayoutBuffer->PartitionEntry[List->SystemPartition->PartitionIndex].BootIndicator
= TRUE;
+
List->SystemPartition->DiskEntry->LayoutBuffer->PartitionEntry[List->SystemPartition->PartitionIndex].RewritePartition
= TRUE;
+ List->SystemPartition->DiskEntry->Dirty = TRUE;
}
@@ -3449,6 +3470,16 @@ WritePartitions(
if (FileHandle != NULL)
NtClose(FileHandle);
+ //
+ // NOTE: Originally (see r40437), we used to install here also a new MBR
+ // for this disk (by calling InstallMbrBootCodeToDisk), only if:
+ // DiskEntry->NewDisk == TRUE and DiskEntry->BiosDiskNumber == 0.
+ // Then after that, both DiskEntry->NewDisk and DiskEntry->NoMbr were set
+ // to FALSE. In the other place (in usetup.c) where InstallMbrBootCodeToDisk
+ // was called too, the installation test was modified by checking whether
+ // DiskEntry->NoMbr was TRUE (instead of NewDisk).
+ //
+
return Status;
}
@@ -3522,12 +3553,47 @@ SetMountedDeviceValues(
Entry2 = Entry2->Flink;
}
+ Entry2 = DiskEntry->LogicalPartListHead.Flink;
+ while (Entry2 != &DiskEntry->LogicalPartListHead)
+ {
+ PartEntry = CONTAINING_RECORD(Entry2, PARTENTRY, ListEntry);
+ if (PartEntry->IsPartitioned)
+ {
+ /* Assign a "\DosDevices\#:" mount point to this partition */
+ if (PartEntry->DriveLetter)
+ {
+ StartingOffset.QuadPart = PartEntry->StartSector.QuadPart *
DiskEntry->BytesPerSector;
+ if (!SetMountedDeviceValue(PartEntry->DriveLetter,
+ DiskEntry->LayoutBuffer->Signature,
+ StartingOffset))
+ {
+ return FALSE;
+ }
+ }
+ }
+
+ Entry2 = Entry2->Flink;
+ }
+
Entry1 = Entry1->Flink;
}
return TRUE;
}
+VOID
+SetPartitionType(
+ IN PPARTENTRY PartEntry,
+ IN UCHAR PartitionType)
+{
+ PDISKENTRY DiskEntry = PartEntry->DiskEntry;
+
+ PartEntry->PartitionType = PartitionType;
+
+ DiskEntry->Dirty = TRUE;
+
DiskEntry->LayoutBuffer->PartitionEntry[PartEntry->PartitionIndex].PartitionType
= PartitionType;
+
DiskEntry->LayoutBuffer->PartitionEntry[PartEntry->PartitionIndex].RewritePartition
= TRUE;
+}
ULONG
PrimaryPartitionCreationChecks(
@@ -3618,9 +3684,10 @@ GetNextUnformattedPartition(
PartEntry = CONTAINING_RECORD(Entry2, PARTENTRY, ListEntry);
if (PartEntry->IsPartitioned && PartEntry->New)
{
- *pDiskEntry = DiskEntry;
- *pPartEntry = PartEntry;
- return TRUE;
+ ASSERT(DiskEntry == PartEntry->DiskEntry);
+ if (pDiskEntry) *pDiskEntry = DiskEntry;
+ *pPartEntry = PartEntry;
+ return TRUE;
}
Entry2 = Entry2->Flink;
@@ -3632,9 +3699,10 @@ GetNextUnformattedPartition(
PartEntry = CONTAINING_RECORD(Entry2, PARTENTRY, ListEntry);
if (PartEntry->IsPartitioned && PartEntry->New)
{
- *pDiskEntry = DiskEntry;
- *pPartEntry = PartEntry;
- return TRUE;
+ ASSERT(DiskEntry == PartEntry->DiskEntry);
+ if (pDiskEntry) *pDiskEntry = DiskEntry;
+ *pPartEntry = PartEntry;
+ return TRUE;
}
Entry2 = Entry2->Flink;
@@ -3643,7 +3711,7 @@ GetNextUnformattedPartition(
Entry1 = Entry1->Flink;
}
- *pDiskEntry = NULL;
+ if (pDiskEntry) *pDiskEntry = NULL;
*pPartEntry = NULL;
return FALSE;
@@ -3672,9 +3740,10 @@ GetNextUncheckedPartition(
PartEntry = CONTAINING_RECORD(Entry2, PARTENTRY, ListEntry);
if (PartEntry->NeedsCheck == TRUE)
{
- *pDiskEntry = DiskEntry;
- *pPartEntry = PartEntry;
- return TRUE;
+ ASSERT(DiskEntry == PartEntry->DiskEntry);
+ if (pDiskEntry) *pDiskEntry = DiskEntry;
+ *pPartEntry = PartEntry;
+ return TRUE;
}
Entry2 = Entry2->Flink;
@@ -3686,9 +3755,10 @@ GetNextUncheckedPartition(
PartEntry = CONTAINING_RECORD(Entry2, PARTENTRY, ListEntry);
if (PartEntry->NeedsCheck == TRUE)
{
- *pDiskEntry = DiskEntry;
- *pPartEntry = PartEntry;
- return TRUE;
+ ASSERT(DiskEntry == PartEntry->DiskEntry);
+ if (pDiskEntry) *pDiskEntry = DiskEntry;
+ *pPartEntry = PartEntry;
+ return TRUE;
}
Entry2 = Entry2->Flink;
@@ -3697,7 +3767,7 @@ GetNextUncheckedPartition(
Entry1 = Entry1->Flink;
}
- *pDiskEntry = NULL;
+ if (pDiskEntry) *pDiskEntry = NULL;
*pPartEntry = NULL;
return FALSE;
diff --git a/base/setup/usetup/partlist.h b/base/setup/usetup/partlist.h
index 9787f94ae3..35c83b3f17 100644
--- a/base/setup/usetup/partlist.h
+++ b/base/setup/usetup/partlist.h
@@ -51,16 +51,18 @@ typedef struct _PARTENTRY
{
LIST_ENTRY ListEntry;
+ /* The disk this partition belongs to */
struct _DISKENTRY *DiskEntry;
+ /* Partition geometry */
ULARGE_INTEGER StartSector;
ULARGE_INTEGER SectorCount;
BOOLEAN BootIndicator;
UCHAR PartitionType;
ULONG HiddenSectors;
- ULONG PartitionNumber;
- ULONG PartitionIndex;
+ ULONG PartitionNumber; /* Enumerated partition number (primary partitions first --
excluding the extended partition container --, then the logical partitions) */
+ ULONG PartitionIndex; /* Index in the LayoutBuffer->PartitionEntry[] cached
array of the corresponding DiskEntry */
CHAR DriveLetter;
@@ -75,12 +77,12 @@ typedef struct _PARTENTRY
/* Partition was created automatically */
BOOLEAN AutoCreate;
- FORMATSTATE FormatState;
-
/* Partition must be checked */
BOOLEAN NeedsCheck;
+ FORMATSTATE FormatState;
struct _FILE_SYSTEM_ITEM *FileSystem;
+
} PARTENTRY, *PPARTENTRY;
@@ -100,6 +102,8 @@ typedef struct _DISKENTRY
{
LIST_ENTRY ListEntry;
+ /* Disk geometry */
+
ULONGLONG Cylinders;
ULONG TracksPerCylinder;
ULONG SectorsPerTrack;
@@ -109,11 +113,13 @@ typedef struct _DISKENTRY
ULONG SectorAlignment;
ULONG CylinderAlignment;
+ /* BIOS parameters */
BOOLEAN BiosFound;
ULONG BiosDiskNumber;
// ULONG Signature;
// ULONG Checksum;
+ /* SCSI parameters */
ULONG DiskNumber;
USHORT Port;
USHORT Bus;
@@ -123,12 +129,17 @@ typedef struct _DISKENTRY
BOOLEAN Dirty;
BOOLEAN NewDisk;
- BOOLEAN NoMbr; /* MBR is absent */
+ BOOLEAN NoMbr; /* MBR is absent */ // See r40437
UNICODE_STRING DriverName;
PDRIVE_LAYOUT_INFORMATION LayoutBuffer;
+ // TODO: When adding support for GPT disks:
+ // Use PDRIVE_LAYOUT_INFORMATION_EX which indicates whether
+ // the disk is MBR, GPT, or unknown (uninitialized).
+ // Depending on the style, either use the MBR or GPT partition info.
+ /* Pointer to the unique extended partition on this disk */
PPARTENTRY ExtendedPartition;
LIST_ENTRY PrimaryPartListHead;
@@ -139,6 +150,7 @@ typedef struct _DISKENTRY
typedef struct _PARTLIST
{
+ /* UI stuff */
SHORT Left;
SHORT Top;
SHORT Right;
@@ -147,23 +159,32 @@ typedef struct _PARTLIST
SHORT Line;
SHORT Offset;
+ /*
+ * 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 disk and partition where the boot manager resides */
- PDISKENTRY SystemDisk;
+ /*
+ * The system partition where the boot manager resides.
+ * The corresponding system disk is obtained via:
+ * SystemPartition->DiskEntry.
+ */
PPARTENTRY SystemPartition;
/*
- * The original system disk and partition in case we are redefining them
- * because we do not have write support on them.
- * Please not that this is partly a HACK and MUST NEVER happen on
+ * The original system partition in case we are redefining it because
+ * we do not have write support on it.
+ * Please note that this is partly a HACK and MUST NEVER happen on
* architectures where real system partitions are mandatory (because then
* they are formatted in FAT FS and we support write operation on them).
+ * The corresponding original system disk is obtained via:
+ * OriginalSystemPartition->DiskEntry.
*/
- PDISKENTRY OriginalSystemDisk;
PPARTENTRY OriginalSystemPartition;
- PDISKENTRY TempDisk;
PPARTENTRY TempPartition;
FORMATMACHINESTATE FormatState;
@@ -278,6 +299,11 @@ BOOLEAN
SetMountedDeviceValues(
IN PPARTLIST List);
+VOID
+SetPartitionType(
+ IN PPARTENTRY PartEntry,
+ IN UCHAR PartitionType);
+
ULONG
PrimaryPartitionCreationChecks(
IN PPARTLIST List);
diff --git a/base/setup/usetup/usetup.c b/base/setup/usetup/usetup.c
index 234bfa45be..0fe4f16a57 100644
--- a/base/setup/usetup/usetup.c
+++ b/base/setup/usetup/usetup.c
@@ -2657,9 +2657,7 @@ SelectFileSystemPage(PINPUT_RECORD Ir)
/* Find or set the active system partition */
CheckActiveSystemPartition(PartitionList, FileSystemList);
-
- if (PartitionList->SystemDisk == NULL ||
- PartitionList->SystemPartition == NULL)
+ if (PartitionList->SystemPartition == NULL)
{
/* FIXME: show an error dialog */
return QUIT_PAGE;
@@ -2671,7 +2669,6 @@ SelectFileSystemPage(PINPUT_RECORD Ir)
case Start:
if (PartitionList->CurrentPartition != PartitionList->SystemPartition)
{
- PartitionList->TempDisk = PartitionList->SystemDisk;
PartitionList->TempPartition = PartitionList->SystemPartition;
PartitionList->TempPartition->NeedsCheck = TRUE;
@@ -2680,7 +2677,6 @@ SelectFileSystemPage(PINPUT_RECORD Ir)
}
else
{
- PartitionList->TempDisk = PartitionList->CurrentDisk;
PartitionList->TempPartition = PartitionList->CurrentPartition;
PartitionList->TempPartition->NeedsCheck = TRUE;
@@ -2690,7 +2686,6 @@ SelectFileSystemPage(PINPUT_RECORD Ir)
break;
case FormatSystemPartition:
- PartitionList->TempDisk = PartitionList->CurrentDisk;
PartitionList->TempPartition = PartitionList->CurrentPartition;
PartitionList->TempPartition->NeedsCheck = TRUE;
@@ -2700,7 +2695,7 @@ SelectFileSystemPage(PINPUT_RECORD Ir)
case FormatInstallPartition:
if (GetNextUnformattedPartition(PartitionList,
- &PartitionList->TempDisk,
+ NULL,
&PartitionList->TempPartition))
{
PartitionList->FormatState = FormatOtherPartition;
@@ -2717,7 +2712,7 @@ SelectFileSystemPage(PINPUT_RECORD Ir)
case FormatOtherPartition:
if (GetNextUnformattedPartition(PartitionList,
- &PartitionList->TempDisk,
+ NULL,
&PartitionList->TempPartition))
{
PartitionList->FormatState = FormatOtherPartition;
@@ -2738,8 +2733,8 @@ SelectFileSystemPage(PINPUT_RECORD Ir)
return QUIT_PAGE;
}
- DiskEntry = PartitionList->TempDisk;
PartEntry = PartitionList->TempPartition;
+ DiskEntry = PartEntry->DiskEntry;
/* Adjust disk size */
DiskSize = DiskEntry->SectorCount.QuadPart * DiskEntry->BytesPerSector;
@@ -2970,15 +2965,14 @@ FormatPartitionPage(PINPUT_RECORD Ir)
MUIDisplayPage(FORMAT_PARTITION_PAGE);
if (PartitionList == NULL ||
- PartitionList->TempDisk == NULL ||
PartitionList->TempPartition == NULL)
{
/* FIXME: show an error dialog */
return QUIT_PAGE;
}
- DiskEntry = PartitionList->TempDisk;
PartEntry = PartitionList->TempPartition;
+ DiskEntry = PartEntry->DiskEntry;
while (TRUE)
{
@@ -3004,7 +2998,7 @@ FormatPartitionPage(PINPUT_RECORD Ir)
if (PartEntry->SectorCount.QuadPart < 8192)
{
/* FAT12 CHS partition (disk is smaller than 4.1MB) */
- PartEntry->PartitionType = PARTITION_FAT_12;
+ SetPartitionType(PartEntry, PARTITION_FAT_12);
}
else if (PartEntry->StartSector.QuadPart < 1450560)
{
@@ -3013,17 +3007,17 @@ FormatPartitionPage(PINPUT_RECORD Ir)
if (PartEntry->SectorCount.QuadPart < 65536)
{
/* FAT16 CHS partition (partition size < 32MB) */
- PartEntry->PartitionType = PARTITION_FAT_16;
+ SetPartitionType(PartEntry, PARTITION_FAT_16);
}
else if (PartEntry->SectorCount.QuadPart < 1048576)
{
/* FAT16 CHS partition (partition size < 512MB) */
- PartEntry->PartitionType = PARTITION_HUGE;
+ SetPartitionType(PartEntry, PARTITION_HUGE);
}
else
{
/* FAT32 CHS partition (partition size >= 512MB) */
- PartEntry->PartitionType = PARTITION_FAT32;
+ SetPartitionType(PartEntry, PARTITION_FAT32);
}
}
else
@@ -3033,35 +3027,23 @@ FormatPartitionPage(PINPUT_RECORD Ir)
if (PartEntry->SectorCount.QuadPart < 1048576)
{
/* FAT16 LBA partition (partition size < 512MB) */
- PartEntry->PartitionType = PARTITION_XINT13;
+ SetPartitionType(PartEntry, PARTITION_XINT13);
}
else
{
/* FAT32 LBA partition (partition size >= 512MB) */
- PartEntry->PartitionType = PARTITION_FAT32_XINT13;
+ SetPartitionType(PartEntry, PARTITION_FAT32_XINT13);
}
}
-
- DiskEntry->Dirty = TRUE;
-
DiskEntry->LayoutBuffer->PartitionEntry[PartEntry->PartitionIndex].PartitionType
= PartEntry->PartitionType;
-
DiskEntry->LayoutBuffer->PartitionEntry[PartEntry->PartitionIndex].RewritePartition
= TRUE;
}
#if 0
else if (wcscmp(PartEntry->FileSystem->FileSystemName,
L"EXT2") == 0)
{
- PartEntry->PartitionType = PARTITION_EXT2;
-
- DiskEntry->Dirty = TRUE;
-
DiskEntry->LayoutBuffer->PartitionEntry[PartEntry->PartitionIndex].PartitionType
= PartEntry->PartitionType;
-
DiskEntry->LayoutBuffer->PartitionEntry[PartEntry->PartitionIndex].RewritePartition
= TRUE;
+ SetPartitionType(PartEntry, PARTITION_EXT2);
}
else if (wcscmp(PartEntry->FileSystem->FileSystemName,
L"NTFS") == 0)
{
- PartEntry->PartitionType = PARTITION_IFS;
-
- DiskEntry->Dirty = TRUE;
-
DiskEntry->LayoutBuffer->PartitionEntry[PartEntry->PartitionIndex].PartitionType
= PartEntry->PartitionType;
-
DiskEntry->LayoutBuffer->PartitionEntry[PartEntry->PartitionIndex].RewritePartition
= TRUE;
+ SetPartitionType(PartEntry, PARTITION_IFS);
}
#endif
else if (!PartEntry->FileSystem->FormatFunc)
@@ -4284,7 +4266,7 @@ BootLoaderPage(PINPUT_RECORD Ir)
RtlFreeUnicodeString(&SystemRootPath);
swprintf(PathBuffer,
L"\\Device\\Harddisk%lu\\Partition%lu",
- PartitionList->SystemDisk->DiskNumber,
+ PartitionList->SystemPartition->DiskEntry->DiskNumber,
PartitionList->SystemPartition->PartitionNumber);
RtlCreateUnicodeString(&SystemRootPath, PathBuffer);
DPRINT1("SystemRootPath: %wZ\n", &SystemRootPath);
@@ -4557,7 +4539,7 @@ BootLoaderHarddiskMbrPage(PINPUT_RECORD Ir)
/* Step 2: Write the MBR */
swprintf(DestinationDevicePathBuffer,
L"\\Device\\Harddisk%d\\Partition0",
- PartitionList->SystemDisk->DiskNumber);
+ PartitionList->SystemPartition->DiskEntry->DiskNumber);
wcscpy(SourceMbrPathBuffer, SourceRootPath.Buffer);
wcscat(SourceMbrPathBuffer, L"\\loader\\dosmbr.bin");