[SETUPLIB] Detect GPT-partitioned disks but don't use them since we don't support them at the moment.

- Add checks for GPT disks and either fail or ignore the disk,
  depending on the operation being executed.

[USETUP][REACTOS] Display the disk style more accurately.
This commit is contained in:
Hermès Bélusca-Maïto 2018-12-14 00:30:12 +01:00
parent 2be0fe5f8f
commit a3168373eb
No known key found for this signature in database
GPG key ID: 3B2539C65E7B93D0
5 changed files with 196 additions and 21 deletions

View file

@ -1193,6 +1193,12 @@ SetDiskSignature(
PDISKENTRY DiskEntry2;
PUCHAR Buffer;
if (DiskEntry->DiskStyle == PARTITION_STYLE_GPT)
{
DPRINT("GPT-partitioned disk detected, not currently supported by SETUP!\n");
return;
}
Buffer = (PUCHAR)&DiskEntry->LayoutBuffer->Signature;
while (TRUE)
@ -1221,6 +1227,12 @@ SetDiskSignature(
{
DiskEntry2 = CONTAINING_RECORD(Entry2, DISKENTRY, ListEntry);
if (DiskEntry2->DiskStyle == PARTITION_STYLE_GPT)
{
DPRINT("GPT-partitioned disk detected, not currently supported by SETUP!\n");
continue;
}
if (DiskEntry != DiskEntry2 &&
DiskEntry->LayoutBuffer->Signature == DiskEntry2->LayoutBuffer->Signature)
break;
@ -1239,13 +1251,19 @@ UpdateDiskSignatures(
PLIST_ENTRY Entry;
PDISKENTRY DiskEntry;
/* Print partition lines */
/* Update each disk */
for (Entry = List->DiskListHead.Flink;
Entry != &List->DiskListHead;
Entry = Entry->Flink)
{
DiskEntry = CONTAINING_RECORD(Entry, DISKENTRY, ListEntry);
if (DiskEntry->DiskStyle == PARTITION_STYLE_GPT)
{
DPRINT("GPT-partitioned disk detected, not currently supported by SETUP!\n");
continue;
}
if (DiskEntry->LayoutBuffer &&
DiskEntry->LayoutBuffer->Signature == 0)
{
@ -1377,11 +1395,30 @@ AddDiskToList(
* Check if this disk has a valid MBR: verify its signature,
* and whether its two first bytes are a valid instruction
* (related to this, see IsThereAValidBootSector() in partlist.c).
*
* See also ntoskrnl/fstub/fstubex.c!FstubDetectPartitionStyle().
*/
if (Mbr->Magic != 0xaa55 || (*(PUSHORT)Mbr->BootCode) == 0x0000)
DiskEntry->NoMbr = TRUE;
// DiskEntry->NoMbr = (Mbr->Magic != PARTITION_MAGIC || (*(PUSHORT)Mbr->BootCode) == 0x0000);
/* If we have not the 0xAA55 then it's raw partition */
if (Mbr->Magic != PARTITION_MAGIC)
{
DiskEntry->DiskStyle = PARTITION_STYLE_RAW;
}
/* Check partitions types: if first is 0xEE and all the others 0, we have GPT */
else if (Mbr->Partition[0].PartitionType == EFI_PMBR_OSTYPE_EFI &&
Mbr->Partition[1].PartitionType == 0 &&
Mbr->Partition[2].PartitionType == 0 &&
Mbr->Partition[3].PartitionType == 0)
{
DiskEntry->DiskStyle = PARTITION_STYLE_GPT;
}
/* Otherwise, partition table is in MBR */
else
DiskEntry->NoMbr = FALSE;
{
DiskEntry->DiskStyle = PARTITION_STYLE_MBR;
}
/* Free the MBR sector buffer */
RtlFreeHeap(ProcessHeap, 0, Mbr);
@ -1478,6 +1515,16 @@ AddDiskToList(
* We now retrieve the disk partition layout
*/
/*
* Stop there now if the disk is GPT-partitioned,
* since we currently do not support such disks.
*/
if (DiskEntry->DiskStyle == PARTITION_STYLE_GPT)
{
DPRINT1("GPT-partitioned disk detected, not currently supported by SETUP!\n");
return;
}
/* Allocate a layout buffer with 4 partition entries first */
LayoutBufferSize = sizeof(DRIVE_LAYOUT_INFORMATION) +
((4 - ANYSIZE_ARRAY) * sizeof(PARTITION_INFORMATION));
@ -1861,6 +1908,12 @@ GetPartition(
PPARTENTRY PartEntry;
PLIST_ENTRY Entry;
if (DiskEntry->DiskStyle == PARTITION_STYLE_GPT)
{
DPRINT("GPT-partitioned disk detected, not currently supported by SETUP!\n");
return NULL;
}
/* Disk found, loop over the primary partitions first... */
for (Entry = DiskEntry->PrimaryPartListHead.Flink;
Entry != &DiskEntry->PrimaryPartListHead;
@ -1912,6 +1965,12 @@ GetDiskOrPartition(
/* If we have a partition (PartitionNumber != 0), find it */
if (PartitionNumber != 0)
{
if (DiskEntry->DiskStyle == PARTITION_STYLE_GPT)
{
DPRINT("GPT-partitioned disk detected, not currently supported by SETUP!\n");
return FALSE;
}
PartEntry = GetPartition(/*List,*/ DiskEntry, PartitionNumber);
if (!PartEntry)
return FALSE;
@ -2033,6 +2092,12 @@ GetNextPartition(
{
DiskEntry = CONTAINING_RECORD(DiskListEntry, DISKENTRY, ListEntry);
if (DiskEntry->DiskStyle == PARTITION_STYLE_GPT)
{
DPRINT("GPT-partitioned disk detected, not currently supported by SETUP!\n");
continue;
}
PartListEntry = DiskEntry->PrimaryPartListHead.Flink;
if (PartListEntry != &DiskEntry->PrimaryPartListHead)
{
@ -2110,6 +2175,12 @@ GetPrevPartition(
{
DiskEntry = CONTAINING_RECORD(DiskListEntry, DISKENTRY, ListEntry);
if (DiskEntry->DiskStyle == PARTITION_STYLE_GPT)
{
DPRINT("GPT-partitioned disk detected, not currently supported by SETUP!\n");
continue;
}
PartListEntry = DiskEntry->PrimaryPartListHead.Blink;
if (PartListEntry != &DiskEntry->PrimaryPartListHead)
{
@ -2182,6 +2253,12 @@ GetPrimaryPartitionCount(
PPARTENTRY PartEntry;
ULONG Count = 0;
if (DiskEntry->DiskStyle == PARTITION_STYLE_GPT)
{
DPRINT("GPT-partitioned disk detected, not currently supported by SETUP!\n");
return 0;
}
for (Entry = DiskEntry->PrimaryPartListHead.Flink;
Entry != &DiskEntry->PrimaryPartListHead;
Entry = Entry->Flink)
@ -2203,6 +2280,12 @@ GetLogicalPartitionCount(
PPARTENTRY PartEntry;
ULONG Count = 0;
if (DiskEntry->DiskStyle == PARTITION_STYLE_GPT)
{
DPRINT("GPT-partitioned disk detected, not currently supported by SETUP!\n");
return 0;
}
for (ListEntry = DiskEntry->LogicalPartListHead.Flink;
ListEntry != &DiskEntry->LogicalPartListHead;
ListEntry = ListEntry->Flink)
@ -2282,6 +2365,12 @@ UpdateDiskLayout(
DPRINT1("UpdateDiskLayout()\n");
if (DiskEntry->DiskStyle == PARTITION_STYLE_GPT)
{
DPRINT("GPT-partitioned disk detected, not currently supported by SETUP!\n");
return;
}
/* Resize the layout buffer if necessary */
if (ReAllocateLayoutBuffer(DiskEntry) == FALSE)
{
@ -2446,6 +2535,12 @@ GetPrevUnpartitionedEntry(
PPARTENTRY PrevPartEntry;
PLIST_ENTRY ListHead;
if (DiskEntry->DiskStyle == PARTITION_STYLE_GPT)
{
DPRINT("GPT-partitioned disk detected, not currently supported by SETUP!\n");
return NULL;
}
if (PartEntry->LogicalPartition)
ListHead = &DiskEntry->LogicalPartListHead;
else
@ -2472,6 +2567,12 @@ GetNextUnpartitionedEntry(
PPARTENTRY NextPartEntry;
PLIST_ENTRY ListHead;
if (DiskEntry->DiskStyle == PARTITION_STYLE_GPT)
{
DPRINT("GPT-partitioned disk detected, not currently supported by SETUP!\n");
return NULL;
}
if (PartEntry->LogicalPartition)
ListHead = &DiskEntry->LogicalPartListHead;
else
@ -3277,6 +3378,12 @@ WritePartitionsToDisk(
{
DiskEntry = CONTAINING_RECORD(Entry, DISKENTRY, ListEntry);
if (DiskEntry->DiskStyle == PARTITION_STYLE_GPT)
{
DPRINT("GPT-partitioned disk detected, not currently supported by SETUP!\n");
continue;
}
if (DiskEntry->Dirty != FALSE)
{
WritePartitions(List, DiskEntry);
@ -3369,6 +3476,12 @@ SetMountedDeviceValues(
DISKENTRY,
ListEntry);
if (DiskEntry->DiskStyle == PARTITION_STYLE_GPT)
{
DPRINT("GPT-partitioned disk detected, not currently supported by SETUP!\n");
continue;
}
for (Entry2 = DiskEntry->PrimaryPartListHead.Flink;
Entry2 != &DiskEntry->PrimaryPartListHead;
Entry2 = Entry2->Flink)
@ -3440,6 +3553,12 @@ PrimaryPartitionCreationChecks(
DiskEntry = List->CurrentDisk;
PartEntry = List->CurrentPartition;
if (DiskEntry->DiskStyle == PARTITION_STYLE_GPT)
{
DPRINT1("GPT-partitioned disk detected, not currently supported by SETUP!\n");
return ERROR_WARN_PARTITION;
}
/* Fail if the partition is already in use */
if (PartEntry->IsPartitioned)
return ERROR_NEW_PARTITION;
@ -3461,6 +3580,12 @@ ExtendedPartitionCreationChecks(
DiskEntry = List->CurrentDisk;
PartEntry = List->CurrentPartition;
if (DiskEntry->DiskStyle == PARTITION_STYLE_GPT)
{
DPRINT1("GPT-partitioned disk detected, not currently supported by SETUP!\n");
return ERROR_WARN_PARTITION;
}
/* Fail if the partition is already in use */
if (PartEntry->IsPartitioned)
return ERROR_NEW_PARTITION;
@ -3480,12 +3605,18 @@ ERROR_NUMBER
LogicalPartitionCreationChecks(
IN PPARTLIST List)
{
// PDISKENTRY DiskEntry;
PDISKENTRY DiskEntry;
PPARTENTRY PartEntry;
// DiskEntry = List->CurrentDisk;
DiskEntry = List->CurrentDisk;
PartEntry = List->CurrentPartition;
if (DiskEntry->DiskStyle == PARTITION_STYLE_GPT)
{
DPRINT1("GPT-partitioned disk detected, not currently supported by SETUP!\n");
return ERROR_WARN_PARTITION;
}
/* Fail if the partition is already in use */
if (PartEntry->IsPartitioned)
return ERROR_NEW_PARTITION;
@ -3511,6 +3642,12 @@ GetNextUnformattedPartition(
DISKENTRY,
ListEntry);
if (DiskEntry->DiskStyle == PARTITION_STYLE_GPT)
{
DPRINT("GPT-partitioned disk detected, not currently supported by SETUP!\n");
continue;
}
for (Entry2 = DiskEntry->PrimaryPartListHead.Flink;
Entry2 != &DiskEntry->PrimaryPartListHead;
Entry2 = Entry2->Flink)
@ -3564,6 +3701,12 @@ GetNextUncheckedPartition(
DISKENTRY,
ListEntry);
if (DiskEntry->DiskStyle == PARTITION_STYLE_GPT)
{
DPRINT("GPT-partitioned disk detected, not currently supported by SETUP!\n");
continue;
}
for (Entry2 = DiskEntry->PrimaryPartListHead.Flink;
Entry2 != &DiskEntry->PrimaryPartListHead;
Entry2 = Entry2->Flink)

View file

@ -118,7 +118,7 @@ typedef struct _DISKENTRY
BOOLEAN Dirty;
BOOLEAN NewDisk; /* If TRUE, the disk is uninitialized */
BOOLEAN NoMbr; /* If TRUE, the MBR is absent */ // See r40437
PARTITION_STYLE DiskStyle; /* MBR/GPT-partitioned disk, or uninitialized disk (RAW) */
UNICODE_STRING DriverName;
@ -174,6 +174,11 @@ typedef struct _PARTLIST
#define PARTITION_TBL_SIZE 4
#define PARTITION_MAGIC 0xAA55
/* Defines system type for MBR showing that a GPT is following */
#define EFI_PMBR_OSTYPE_EFI 0xEE
#include <pshpack1.h>
typedef struct _PARTITION

View file

@ -500,8 +500,11 @@ PrintDiskData(
0, 0,
(LPARAM)DiskEntry);
/* Disk type (MBR or GPT) */
TreeList_SetItemText(hWndList, htiDisk, 1, DiskEntry->NoMbr ? L"GPT" : L"MBR");
/* Disk type: MBR, GPT or RAW (Uninitialized) */
TreeList_SetItemText(hWndList, htiDisk, 1,
DiskEntry->DiskStyle == PARTITION_STYLE_MBR ? L"MBR" :
DiskEntry->DiskStyle == PARTITION_STYLE_GPT ? L"GPT" :
L"RAW");
/* Format the disk size in KBs, MBs, etc... */
DiskSize.QuadPart = DiskEntry->SectorCount.QuadPart * DiskEntry->BytesPerSector;

View file

@ -313,7 +313,9 @@ PrintDiskData(
DiskEntry->Bus,
DiskEntry->Id,
&DiskEntry->DriverName,
DiskEntry->NoMbr ? "GPT" : "MBR");
DiskEntry->DiskStyle == PARTITION_STYLE_MBR ? L"MBR" :
DiskEntry->DiskStyle == PARTITION_STYLE_GPT ? L"GPT" :
L"RAW");
}
else
{
@ -325,7 +327,9 @@ PrintDiskData(
DiskEntry->Port,
DiskEntry->Bus,
DiskEntry->Id,
DiskEntry->NoMbr ? "GPT" : "MBR");
DiskEntry->DiskStyle == PARTITION_STYLE_MBR ? L"MBR" :
DiskEntry->DiskStyle == PARTITION_STYLE_GPT ? L"GPT" :
L"RAW");
}
if (ListUi->Line >= 0 && ListUi->Line <= Height)

View file

@ -1983,7 +1983,9 @@ CreatePrimaryPartitionPage(PINPUT_RECORD Ir)
DiskEntry->Bus,
DiskEntry->Id,
&DiskEntry->DriverName,
DiskEntry->NoMbr ? "GPT" : "MBR");
DiskEntry->DiskStyle == PARTITION_STYLE_MBR ? L"MBR" :
DiskEntry->DiskStyle == PARTITION_STYLE_GPT ? L"GPT" :
L"RAW");
}
else
{
@ -1995,7 +1997,9 @@ CreatePrimaryPartitionPage(PINPUT_RECORD Ir)
DiskEntry->Port,
DiskEntry->Bus,
DiskEntry->Id,
DiskEntry->NoMbr ? "GPT" : "MBR");
DiskEntry->DiskStyle == PARTITION_STYLE_MBR ? L"MBR" :
DiskEntry->DiskStyle == PARTITION_STYLE_GPT ? L"GPT" :
L"RAW");
}
CONSOLE_SetTextXY(6, 12, MUIGetString(STRING_HDDSIZE));
@ -2142,7 +2146,9 @@ CreateExtendedPartitionPage(PINPUT_RECORD Ir)
DiskEntry->Bus,
DiskEntry->Id,
&DiskEntry->DriverName,
DiskEntry->NoMbr ? "GPT" : "MBR");
DiskEntry->DiskStyle == PARTITION_STYLE_MBR ? L"MBR" :
DiskEntry->DiskStyle == PARTITION_STYLE_GPT ? L"GPT" :
L"RAW");
}
else
{
@ -2154,7 +2160,9 @@ CreateExtendedPartitionPage(PINPUT_RECORD Ir)
DiskEntry->Port,
DiskEntry->Bus,
DiskEntry->Id,
DiskEntry->NoMbr ? "GPT" : "MBR");
DiskEntry->DiskStyle == PARTITION_STYLE_MBR ? L"MBR" :
DiskEntry->DiskStyle == PARTITION_STYLE_GPT ? L"GPT" :
L"RAW");
}
CONSOLE_SetTextXY(6, 12, MUIGetString(STRING_HDDSIZE));
@ -2300,7 +2308,9 @@ CreateLogicalPartitionPage(PINPUT_RECORD Ir)
DiskEntry->Bus,
DiskEntry->Id,
&DiskEntry->DriverName,
DiskEntry->NoMbr ? "GPT" : "MBR");
DiskEntry->DiskStyle == PARTITION_STYLE_MBR ? L"MBR" :
DiskEntry->DiskStyle == PARTITION_STYLE_GPT ? L"GPT" :
L"RAW");
}
else
{
@ -2312,7 +2322,9 @@ CreateLogicalPartitionPage(PINPUT_RECORD Ir)
DiskEntry->Port,
DiskEntry->Bus,
DiskEntry->Id,
DiskEntry->NoMbr ? "GPT" : "MBR");
DiskEntry->DiskStyle == PARTITION_STYLE_MBR ? L"MBR" :
DiskEntry->DiskStyle == PARTITION_STYLE_GPT ? L"GPT" :
L"RAW");
}
CONSOLE_SetTextXY(6, 12, MUIGetString(STRING_HDDSIZE));
@ -2539,7 +2551,9 @@ DeletePartitionPage(PINPUT_RECORD Ir)
DiskEntry->Bus,
DiskEntry->Id,
&DiskEntry->DriverName,
DiskEntry->NoMbr ? "GPT" : "MBR");
DiskEntry->DiskStyle == PARTITION_STYLE_MBR ? L"MBR" :
DiskEntry->DiskStyle == PARTITION_STYLE_GPT ? L"GPT" :
L"RAW");
}
else
{
@ -2551,7 +2565,9 @@ DeletePartitionPage(PINPUT_RECORD Ir)
DiskEntry->Port,
DiskEntry->Bus,
DiskEntry->Id,
DiskEntry->NoMbr ? "GPT" : "MBR");
DiskEntry->DiskStyle == PARTITION_STYLE_MBR ? L"MBR" :
DiskEntry->DiskStyle == PARTITION_STYLE_GPT ? L"GPT" :
L"RAW");
}
while (TRUE)
@ -2773,7 +2789,9 @@ SelectFileSystemPage(PINPUT_RECORD Ir)
DiskEntry->Bus,
DiskEntry->Id,
&DiskEntry->DriverName,
DiskEntry->NoMbr ? "GPT" : "MBR");
DiskEntry->DiskStyle == PARTITION_STYLE_MBR ? L"MBR" :
DiskEntry->DiskStyle == PARTITION_STYLE_GPT ? L"GPT" :
L"RAW");
CONSOLE_SetTextXY(6, 12, MUIGetString(STRING_PARTFORMAT));
@ -2834,7 +2852,9 @@ SelectFileSystemPage(PINPUT_RECORD Ir)
DiskEntry->Bus,
DiskEntry->Id,
&DiskEntry->DriverName,
DiskEntry->NoMbr ? "GPT" : "MBR");
DiskEntry->DiskStyle == PARTITION_STYLE_MBR ? L"MBR" :
DiskEntry->DiskStyle == PARTITION_STYLE_GPT ? L"GPT" :
L"RAW");
}
if (FileSystemList == NULL)