summaryrefslogtreecommitdiffstats
path: root/MdeModulePkg/Universal/Disk/PartitionDxe/Mbr.c
diff options
context:
space:
mode:
Diffstat (limited to 'MdeModulePkg/Universal/Disk/PartitionDxe/Mbr.c')
-rw-r--r--MdeModulePkg/Universal/Disk/PartitionDxe/Mbr.c111
1 files changed, 60 insertions, 51 deletions
diff --git a/MdeModulePkg/Universal/Disk/PartitionDxe/Mbr.c b/MdeModulePkg/Universal/Disk/PartitionDxe/Mbr.c
index df25a93f85..0f8dc54865 100644
--- a/MdeModulePkg/Universal/Disk/PartitionDxe/Mbr.c
+++ b/MdeModulePkg/Universal/Disk/PartitionDxe/Mbr.c
@@ -32,26 +32,27 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
**/
BOOLEAN
PartitionValidMbr (
- IN MASTER_BOOT_RECORD *Mbr,
- IN EFI_LBA LastLba
+ IN MASTER_BOOT_RECORD *Mbr,
+ IN EFI_LBA LastLba
)
{
- UINT32 StartingLBA;
- UINT32 EndingLBA;
- UINT32 NewEndingLBA;
- INTN Index1;
- INTN Index2;
- BOOLEAN MbrValid;
+ UINT32 StartingLBA;
+ UINT32 EndingLBA;
+ UINT32 NewEndingLBA;
+ INTN Index1;
+ INTN Index2;
+ BOOLEAN MbrValid;
if (Mbr->Signature != MBR_SIGNATURE) {
return FALSE;
}
+
//
// The BPB also has this signature, so it can not be used alone.
//
MbrValid = FALSE;
for (Index1 = 0; Index1 < MAX_MBR_PARTITIONS; Index1++) {
- if (Mbr->Partition[Index1].OSIndicator == 0x00 || UNPACK_UINT32 (Mbr->Partition[Index1].SizeInLBA) == 0) {
+ if ((Mbr->Partition[Index1].OSIndicator == 0x00) || (UNPACK_UINT32 (Mbr->Partition[Index1].SizeInLBA) == 0)) {
continue;
}
@@ -71,18 +72,18 @@ PartitionValidMbr (
// with INT 13h
//
- DEBUG((DEBUG_INFO, "PartitionValidMbr: Bad MBR partition size EndingLBA(%1x) > LastLBA(%1x)\n", EndingLBA, LastLba));
+ DEBUG ((DEBUG_INFO, "PartitionValidMbr: Bad MBR partition size EndingLBA(%1x) > LastLBA(%1x)\n", EndingLBA, LastLba));
return FALSE;
}
for (Index2 = Index1 + 1; Index2 < MAX_MBR_PARTITIONS; Index2++) {
- if (Mbr->Partition[Index2].OSIndicator == 0x00 || UNPACK_UINT32 (Mbr->Partition[Index2].SizeInLBA) == 0) {
+ if ((Mbr->Partition[Index2].OSIndicator == 0x00) || (UNPACK_UINT32 (Mbr->Partition[Index2].SizeInLBA) == 0)) {
continue;
}
NewEndingLBA = UNPACK_UINT32 (Mbr->Partition[Index2].StartingLBA) + UNPACK_UINT32 (Mbr->Partition[Index2].SizeInLBA) - 1;
- if (NewEndingLBA >= StartingLBA && UNPACK_UINT32 (Mbr->Partition[Index2].StartingLBA) <= EndingLBA) {
+ if ((NewEndingLBA >= StartingLBA) && (UNPACK_UINT32 (Mbr->Partition[Index2].StartingLBA) <= EndingLBA)) {
//
// This region overlaps with the Index1'th region
//
@@ -90,13 +91,13 @@ PartitionValidMbr (
}
}
}
+
//
// None of the regions overlapped so MBR is O.K.
//
return MbrValid;
}
-
/**
Install child handles if the Handle supports MBR format.
@@ -138,14 +139,14 @@ PartitionInstallMbrChildHandles (
EFI_LBA LastSector;
EFI_PARTITION_INFO_PROTOCOL PartitionInfo;
- Found = EFI_NOT_FOUND;
+ Found = EFI_NOT_FOUND;
- BlockSize = BlockIo->Media->BlockSize;
- MediaId = BlockIo->Media->MediaId;
- LastSector = DivU64x32 (
- MultU64x32 (BlockIo->Media->LastBlock + 1, BlockSize),
- MBR_SIZE
- ) - 1;
+ BlockSize = BlockIo->Media->BlockSize;
+ MediaId = BlockIo->Media->MediaId;
+ LastSector = DivU64x32 (
+ MultU64x32 (BlockIo->Media->LastBlock + 1, BlockSize),
+ MBR_SIZE
+ ) - 1;
//
// Ensure the block size can hold the MBR
@@ -170,9 +171,11 @@ PartitionInstallMbrChildHandles (
Found = Status;
goto Done;
}
+
if (!PartitionValidMbr (Mbr, LastSector)) {
goto Done;
}
+
//
// We have a valid mbr - add each partition
//
@@ -183,14 +186,15 @@ PartitionInstallMbrChildHandles (
ZeroMem (&ParentHdDev, sizeof (ParentHdDev));
DevicePathNode = DevicePath;
while (!IsDevicePathEnd (DevicePathNode)) {
- LastDevicePathNode = DevicePathNode;
- DevicePathNode = NextDevicePathNode (DevicePathNode);
+ LastDevicePathNode = DevicePathNode;
+ DevicePathNode = NextDevicePathNode (DevicePathNode);
}
if (LastDevicePathNode != NULL) {
- if (DevicePathType (LastDevicePathNode) == MEDIA_DEVICE_PATH &&
- DevicePathSubType (LastDevicePathNode) == MEDIA_HARDDRIVE_DP
- ) {
+ if ((DevicePathType (LastDevicePathNode) == MEDIA_DEVICE_PATH) &&
+ (DevicePathSubType (LastDevicePathNode) == MEDIA_HARDDRIVE_DP)
+ )
+ {
CopyMem (&ParentHdDev, LastDevicePathNode, sizeof (ParentHdDev));
} else {
LastDevicePathNode = NULL;
@@ -198,18 +202,18 @@ PartitionInstallMbrChildHandles (
}
ZeroMem (&HdDev, sizeof (HdDev));
- HdDev.Header.Type = MEDIA_DEVICE_PATH;
- HdDev.Header.SubType = MEDIA_HARDDRIVE_DP;
+ HdDev.Header.Type = MEDIA_DEVICE_PATH;
+ HdDev.Header.SubType = MEDIA_HARDDRIVE_DP;
SetDevicePathNodeLength (&HdDev.Header, sizeof (HdDev));
- HdDev.MBRType = MBR_TYPE_PCAT;
- HdDev.SignatureType = SIGNATURE_TYPE_MBR;
+ HdDev.MBRType = MBR_TYPE_PCAT;
+ HdDev.SignatureType = SIGNATURE_TYPE_MBR;
if (LastDevicePathNode == NULL) {
//
// This is a MBR, add each partition
//
for (Index = 0; Index < MAX_MBR_PARTITIONS; Index++) {
- if (Mbr->Partition[Index].OSIndicator == 0x00 || UNPACK_UINT32 (Mbr->Partition[Index].SizeInLBA) == 0) {
+ if ((Mbr->Partition[Index].OSIndicator == 0x00) || (UNPACK_UINT32 (Mbr->Partition[Index].SizeInLBA) == 0)) {
//
// Don't use null MBR entries
//
@@ -237,23 +241,24 @@ PartitionInstallMbrChildHandles (
if (Mbr->Partition[Index].OSIndicator == EFI_PARTITION) {
PartitionInfo.System = 1;
}
+
CopyMem (&PartitionInfo.Info.Mbr, &Mbr->Partition[Index], sizeof (MBR_PARTITION_RECORD));
Status = PartitionInstallChildHandle (
- This,
- Handle,
- DiskIo,
- DiskIo2,
- BlockIo,
- BlockIo2,
- DevicePath,
- (EFI_DEVICE_PATH_PROTOCOL *) &HdDev,
- &PartitionInfo,
- HdDev.PartitionStart,
- HdDev.PartitionStart + HdDev.PartitionSize - 1,
- MBR_SIZE,
- ((Mbr->Partition[Index].OSIndicator == EFI_PARTITION) ? &gEfiPartTypeSystemPartGuid: NULL)
- );
+ This,
+ Handle,
+ DiskIo,
+ DiskIo2,
+ BlockIo,
+ BlockIo2,
+ DevicePath,
+ (EFI_DEVICE_PATH_PROTOCOL *)&HdDev,
+ &PartitionInfo,
+ HdDev.PartitionStart,
+ HdDev.PartitionStart + HdDev.PartitionSize - 1,
+ MBR_SIZE,
+ ((Mbr->Partition[Index].OSIndicator == EFI_PARTITION) ? &gEfiPartTypeSystemPartGuid : NULL)
+ );
if (!EFI_ERROR (Status)) {
Found = EFI_SUCCESS;
@@ -268,7 +273,6 @@ PartitionInstallMbrChildHandles (
ExtMbrStartingLba = 0;
do {
-
Status = DiskIo->ReadDisk (
DiskIo,
MediaId,
@@ -286,22 +290,25 @@ PartitionInstallMbrChildHandles (
}
if ((Mbr->Partition[0].OSIndicator == EXTENDED_DOS_PARTITION) ||
- (Mbr->Partition[0].OSIndicator == EXTENDED_WINDOWS_PARTITION)) {
+ (Mbr->Partition[0].OSIndicator == EXTENDED_WINDOWS_PARTITION))
+ {
ExtMbrStartingLba = UNPACK_UINT32 (Mbr->Partition[0].StartingLBA);
continue;
}
+
HdDev.PartitionNumber = ++Index;
HdDev.PartitionStart = UNPACK_UINT32 (Mbr->Partition[0].StartingLBA) + ExtMbrStartingLba + ParentHdDev.PartitionStart;
HdDev.PartitionSize = UNPACK_UINT32 (Mbr->Partition[0].SizeInLBA);
if ((HdDev.PartitionStart + HdDev.PartitionSize - 1 >= ParentHdDev.PartitionStart + ParentHdDev.PartitionSize) ||
- (HdDev.PartitionStart <= ParentHdDev.PartitionStart)) {
+ (HdDev.PartitionStart <= ParentHdDev.PartitionStart))
+ {
break;
}
//
// The signature in EBR(Extended Boot Record) should always be 0.
//
- *((UINT32 *) &HdDev.Signature[0]) = 0;
+ *((UINT32 *)&HdDev.Signature[0]) = 0;
ZeroMem (&PartitionInfo, sizeof (EFI_PARTITION_INFO_PROTOCOL));
PartitionInfo.Revision = EFI_PARTITION_INFO_PROTOCOL_REVISION;
@@ -309,6 +316,7 @@ PartitionInstallMbrChildHandles (
if (Mbr->Partition[0].OSIndicator == EFI_PARTITION) {
PartitionInfo.System = 1;
}
+
CopyMem (&PartitionInfo.Info.Mbr, &Mbr->Partition[0], sizeof (MBR_PARTITION_RECORD));
Status = PartitionInstallChildHandle (
@@ -319,12 +327,12 @@ PartitionInstallMbrChildHandles (
BlockIo,
BlockIo2,
DevicePath,
- (EFI_DEVICE_PATH_PROTOCOL *) &HdDev,
+ (EFI_DEVICE_PATH_PROTOCOL *)&HdDev,
&PartitionInfo,
HdDev.PartitionStart - ParentHdDev.PartitionStart,
HdDev.PartitionStart - ParentHdDev.PartitionStart + HdDev.PartitionSize - 1,
MBR_SIZE,
- ((Mbr->Partition[0].OSIndicator == EFI_PARTITION) ? &gEfiPartTypeSystemPartGuid: NULL)
+ ((Mbr->Partition[0].OSIndicator == EFI_PARTITION) ? &gEfiPartTypeSystemPartGuid : NULL)
);
if (!EFI_ERROR (Status)) {
Found = EFI_SUCCESS;
@@ -332,7 +340,8 @@ PartitionInstallMbrChildHandles (
if ((Mbr->Partition[1].OSIndicator != EXTENDED_DOS_PARTITION) &&
(Mbr->Partition[1].OSIndicator != EXTENDED_WINDOWS_PARTITION)
- ) {
+ )
+ {
break;
}