PartitionValidGptTable(), PartitionCheckGptEntry() routine will accept disk\r
partition content and validate the GPT table and GPT entry.\r
\r
-Copyright (c) 2006 - 2013, Intel Corporation. All rights reserved.<BR>\r
-This program and the accompanying materials\r
-are licensed and made available under the terms and conditions of the BSD License\r
-which accompanies this distribution. The full text of the license may be found at\r
-http://opensource.org/licenses/bsd-license.php\r
-\r
-THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
-WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+Copyright (c) 2018 Qualcomm Datacenter Technologies, Inc.\r
+Copyright (c) 2006 - 2019, Intel Corporation. All rights reserved.<BR>\r
+SPDX-License-Identifier: BSD-2-Clause-Patent\r
\r
**/\r
\r
-\r
#include "Partition.h"\r
\r
/**\r
IN EFI_PARTITION_TABLE_HEADER *PartHeader\r
);\r
\r
-\r
/**\r
Restore Partition Table to its alternate place\r
(Primary -> Backup or Backup -> Primary).\r
IN EFI_PARTITION_TABLE_HEADER *PartHeader\r
);\r
\r
-\r
/**\r
This routine will check GPT partition entry and return entry status.\r
\r
\r
@param[in] PartHeader Partition table header structure\r
@param[in] PartEntry The partition entry array\r
- @param[out] PEntryStatus the partition entry status array \r
+ @param[out] PEntryStatus the partition entry status array\r
recording the status of each partition\r
\r
**/\r
OUT EFI_PARTITION_ENTRY_STATUS *PEntryStatus\r
);\r
\r
-\r
/**\r
Checks the CRC32 value in the table header.\r
\r
IN OUT EFI_TABLE_HEADER *Hdr\r
);\r
\r
-\r
/**\r
Checks the CRC32 value in the table header.\r
\r
IN OUT EFI_TABLE_HEADER *Hdr\r
);\r
\r
-\r
/**\r
Updates the CRC32 value in the table header.\r
\r
IN OUT EFI_TABLE_HEADER *Hdr\r
);\r
\r
-\r
/**\r
Updates the CRC32 value in the table header.\r
\r
**/\r
VOID\r
PartitionSetCrc (\r
- IN OUT EFI_TABLE_HEADER *Hdr\r
+ IN OUT EFI_TABLE_HEADER *Hdr\r
);\r
\r
/**\r
@param[in] This Calling context.\r
@param[in] Handle Parent Handle.\r
@param[in] DiskIo Parent DiskIo interface.\r
+ @param[in] DiskIo2 Parent DiskIo2 interface.\r
@param[in] BlockIo Parent BlockIo interface.\r
@param[in] BlockIo2 Parent BlockIo2 interface.\r
@param[in] DevicePath Parent Device Path.\r
IN EFI_DRIVER_BINDING_PROTOCOL *This,\r
IN EFI_HANDLE Handle,\r
IN EFI_DISK_IO_PROTOCOL *DiskIo,\r
+ IN EFI_DISK_IO2_PROTOCOL *DiskIo2,\r
IN EFI_BLOCK_IO_PROTOCOL *BlockIo,\r
IN EFI_BLOCK_IO2_PROTOCOL *BlockIo2,\r
IN EFI_DEVICE_PATH_PROTOCOL *DevicePath\r
)\r
{\r
- EFI_STATUS Status;\r
- UINT32 BlockSize;\r
- EFI_LBA LastBlock;\r
- MASTER_BOOT_RECORD *ProtectiveMbr;\r
- EFI_PARTITION_TABLE_HEADER *PrimaryHeader;\r
- EFI_PARTITION_TABLE_HEADER *BackupHeader;\r
- EFI_PARTITION_ENTRY *PartEntry;\r
- EFI_PARTITION_ENTRY *Entry;\r
- EFI_PARTITION_ENTRY_STATUS *PEntryStatus;\r
- UINTN Index;\r
- EFI_STATUS GptValidStatus;\r
- HARDDRIVE_DEVICE_PATH HdDev;\r
- UINT32 MediaId;\r
+ EFI_STATUS Status;\r
+ UINT32 BlockSize;\r
+ EFI_LBA LastBlock;\r
+ MASTER_BOOT_RECORD *ProtectiveMbr;\r
+ EFI_PARTITION_TABLE_HEADER *PrimaryHeader;\r
+ EFI_PARTITION_TABLE_HEADER *BackupHeader;\r
+ EFI_PARTITION_ENTRY *PartEntry;\r
+ EFI_PARTITION_ENTRY *Entry;\r
+ EFI_PARTITION_ENTRY_STATUS *PEntryStatus;\r
+ UINTN Index;\r
+ EFI_STATUS GptValidStatus;\r
+ HARDDRIVE_DEVICE_PATH HdDev;\r
+ UINT32 MediaId;\r
+ EFI_PARTITION_INFO_PROTOCOL PartitionInfo;\r
\r
ProtectiveMbr = NULL;\r
PrimaryHeader = NULL;\r
PartEntry = NULL;\r
PEntryStatus = NULL;\r
\r
- BlockSize = BlockIo->Media->BlockSize;\r
- LastBlock = BlockIo->Media->LastBlock;\r
- MediaId = BlockIo->Media->MediaId;\r
+ BlockSize = BlockIo->Media->BlockSize;\r
+ LastBlock = BlockIo->Media->LastBlock;\r
+ MediaId = BlockIo->Media->MediaId;\r
\r
- DEBUG ((EFI_D_INFO, " BlockSize : %d \n", BlockSize));\r
- DEBUG ((EFI_D_INFO, " LastBlock : %lx \n", LastBlock));\r
+ DEBUG ((DEBUG_INFO, " BlockSize : %d \n", BlockSize));\r
+ DEBUG ((DEBUG_INFO, " LastBlock : %lx \n", LastBlock));\r
\r
GptValidStatus = EFI_NOT_FOUND;\r
\r
+ //\r
+ // Ensure the block size can hold the MBR\r
+ //\r
+ if (BlockSize < sizeof (MASTER_BOOT_RECORD)) {\r
+ return EFI_NOT_FOUND;\r
+ }\r
+\r
//\r
// Allocate a buffer for the Protective MBR\r
//\r
// Verify that the Protective MBR is valid\r
//\r
for (Index = 0; Index < MAX_MBR_PARTITIONS; Index++) {\r
- if (ProtectiveMbr->Partition[Index].BootIndicator == 0x00 &&\r
- ProtectiveMbr->Partition[Index].OSIndicator == PMBR_GPT_PARTITION &&\r
- UNPACK_UINT32 (ProtectiveMbr->Partition[Index].StartingLBA) == 1\r
- ) {\r
+ if ((ProtectiveMbr->Partition[Index].OSIndicator == PMBR_GPT_PARTITION) &&\r
+ (UNPACK_UINT32 (ProtectiveMbr->Partition[Index].StartingLBA) == 1)\r
+ )\r
+ {\r
break;\r
}\r
}\r
+\r
if (Index == MAX_MBR_PARTITIONS) {\r
goto Done;\r
}\r
// Check primary and backup partition tables\r
//\r
if (!PartitionValidGptTable (BlockIo, DiskIo, PRIMARY_PART_HEADER_LBA, PrimaryHeader)) {\r
- DEBUG ((EFI_D_INFO, " Not Valid primary partition table\n"));\r
+ DEBUG ((DEBUG_INFO, " Not Valid primary partition table\n"));\r
\r
if (!PartitionValidGptTable (BlockIo, DiskIo, LastBlock, BackupHeader)) {\r
- DEBUG ((EFI_D_INFO, " Not Valid backup partition table\n"));\r
+ DEBUG ((DEBUG_INFO, " Not Valid backup partition table\n"));\r
goto Done;\r
} else {\r
- DEBUG ((EFI_D_INFO, " Valid backup partition table\n"));\r
- DEBUG ((EFI_D_INFO, " Restore primary partition table by the backup\n"));\r
+ DEBUG ((DEBUG_INFO, " Valid backup partition table\n"));\r
+ DEBUG ((DEBUG_INFO, " Restore primary partition table by the backup\n"));\r
if (!PartitionRestoreGptTable (BlockIo, DiskIo, BackupHeader)) {\r
- DEBUG ((EFI_D_INFO, " Restore primary partition table error\n"));\r
+ DEBUG ((DEBUG_INFO, " Restore primary partition table error\n"));\r
}\r
\r
if (PartitionValidGptTable (BlockIo, DiskIo, BackupHeader->AlternateLBA, PrimaryHeader)) {\r
- DEBUG ((EFI_D_INFO, " Restore backup partition table success\n"));\r
+ DEBUG ((DEBUG_INFO, " Restore backup partition table success\n"));\r
}\r
}\r
} else if (!PartitionValidGptTable (BlockIo, DiskIo, PrimaryHeader->AlternateLBA, BackupHeader)) {\r
- DEBUG ((EFI_D_INFO, " Valid primary and !Valid backup partition table\n"));\r
- DEBUG ((EFI_D_INFO, " Restore backup partition table by the primary\n"));\r
+ DEBUG ((DEBUG_INFO, " Valid primary and !Valid backup partition table\n"));\r
+ DEBUG ((DEBUG_INFO, " Restore backup partition table by the primary\n"));\r
if (!PartitionRestoreGptTable (BlockIo, DiskIo, PrimaryHeader)) {\r
- DEBUG ((EFI_D_INFO, " Restore backup partition table error\n"));\r
+ DEBUG ((DEBUG_INFO, " Restore backup partition table error\n"));\r
}\r
\r
if (PartitionValidGptTable (BlockIo, DiskIo, PrimaryHeader->AlternateLBA, BackupHeader)) {\r
- DEBUG ((EFI_D_INFO, " Restore backup partition table success\n"));\r
+ DEBUG ((DEBUG_INFO, " Restore backup partition table success\n"));\r
}\r
-\r
}\r
\r
- DEBUG ((EFI_D_INFO, " Valid primary and Valid backup partition table\n"));\r
+ DEBUG ((DEBUG_INFO, " Valid primary and Valid backup partition table\n"));\r
\r
//\r
// Read the EFI Partition Entries\r
//\r
PartEntry = AllocatePool (PrimaryHeader->NumberOfPartitionEntries * PrimaryHeader->SizeOfPartitionEntry);\r
if (PartEntry == NULL) {\r
- DEBUG ((EFI_D_ERROR, "Allocate pool error\n"));\r
+ DEBUG ((DEBUG_ERROR, "Allocate pool error\n"));\r
goto Done;\r
}\r
\r
Status = DiskIo->ReadDisk (\r
DiskIo,\r
MediaId,\r
- MultU64x32(PrimaryHeader->PartitionEntryLBA, BlockSize),\r
+ MultU64x32 (PrimaryHeader->PartitionEntryLBA, BlockSize),\r
PrimaryHeader->NumberOfPartitionEntries * (PrimaryHeader->SizeOfPartitionEntry),\r
PartEntry\r
);\r
if (EFI_ERROR (Status)) {\r
GptValidStatus = Status;\r
- DEBUG ((EFI_D_ERROR, " Partition Entry ReadDisk error\n"));\r
+ DEBUG ((DEBUG_ERROR, " Partition Entry ReadDisk error\n"));\r
goto Done;\r
}\r
\r
- DEBUG ((EFI_D_INFO, " Partition entries read block success\n"));\r
+ DEBUG ((DEBUG_INFO, " Partition entries read block success\n"));\r
\r
- DEBUG ((EFI_D_INFO, " Number of partition entries: %d\n", PrimaryHeader->NumberOfPartitionEntries));\r
+ DEBUG ((DEBUG_INFO, " Number of partition entries: %d\n", PrimaryHeader->NumberOfPartitionEntries));\r
\r
PEntryStatus = AllocateZeroPool (PrimaryHeader->NumberOfPartitionEntries * sizeof (EFI_PARTITION_ENTRY_STATUS));\r
if (PEntryStatus == NULL) {\r
- DEBUG ((EFI_D_ERROR, "Allocate pool error\n"));\r
+ DEBUG ((DEBUG_ERROR, "Allocate pool error\n"));\r
goto Done;\r
}\r
\r
// Create child device handles\r
//\r
for (Index = 0; Index < PrimaryHeader->NumberOfPartitionEntries; Index++) {\r
- Entry = (EFI_PARTITION_ENTRY *) ((UINT8 *) PartEntry + Index * PrimaryHeader->SizeOfPartitionEntry);\r
+ Entry = (EFI_PARTITION_ENTRY *)((UINT8 *)PartEntry + Index * PrimaryHeader->SizeOfPartitionEntry);\r
if (CompareGuid (&Entry->PartitionTypeGUID, &gEfiPartTypeUnusedGuid) ||\r
PEntryStatus[Index].OutOfRange ||\r
PEntryStatus[Index].Overlap ||\r
PEntryStatus[Index].OsSpecific\r
- ) {\r
+ )\r
+ {\r
//\r
// Don't use null EFI Partition Entries, Invalid Partition Entries or OS specific\r
// partition Entries\r
}\r
\r
ZeroMem (&HdDev, sizeof (HdDev));\r
- HdDev.Header.Type = MEDIA_DEVICE_PATH;\r
- HdDev.Header.SubType = MEDIA_HARDDRIVE_DP;\r
+ HdDev.Header.Type = MEDIA_DEVICE_PATH;\r
+ HdDev.Header.SubType = MEDIA_HARDDRIVE_DP;\r
SetDevicePathNodeLength (&HdDev.Header, sizeof (HdDev));\r
\r
- HdDev.PartitionNumber = (UINT32) Index + 1;\r
+ HdDev.PartitionNumber = (UINT32)Index + 1;\r
HdDev.MBRType = MBR_TYPE_EFI_PARTITION_TABLE_HEADER;\r
HdDev.SignatureType = SIGNATURE_TYPE_GUID;\r
HdDev.PartitionStart = Entry->StartingLBA;\r
HdDev.PartitionSize = Entry->EndingLBA - Entry->StartingLBA + 1;\r
CopyMem (HdDev.Signature, &Entry->UniquePartitionGUID, sizeof (EFI_GUID));\r
\r
- DEBUG ((EFI_D_INFO, " Index : %d\n", (UINT32) Index));\r
- DEBUG ((EFI_D_INFO, " Start LBA : %lx\n", (UINT64) HdDev.PartitionStart));\r
- DEBUG ((EFI_D_INFO, " End LBA : %lx\n", (UINT64) Entry->EndingLBA));\r
- DEBUG ((EFI_D_INFO, " Partition size: %lx\n", (UINT64) HdDev.PartitionSize));\r
- DEBUG ((EFI_D_INFO, " Start : %lx", MultU64x32 (Entry->StartingLBA, BlockSize)));\r
- DEBUG ((EFI_D_INFO, " End : %lx\n", MultU64x32 (Entry->EndingLBA, BlockSize)));\r
+ ZeroMem (&PartitionInfo, sizeof (EFI_PARTITION_INFO_PROTOCOL));\r
+ PartitionInfo.Revision = EFI_PARTITION_INFO_PROTOCOL_REVISION;\r
+ PartitionInfo.Type = PARTITION_TYPE_GPT;\r
+ if (CompareGuid (&Entry->PartitionTypeGUID, &gEfiPartTypeSystemPartGuid)) {\r
+ PartitionInfo.System = 1;\r
+ }\r
+\r
+ CopyMem (&PartitionInfo.Info.Gpt, Entry, sizeof (EFI_PARTITION_ENTRY));\r
+\r
+ DEBUG ((DEBUG_INFO, " Index : %d\n", (UINT32)Index));\r
+ DEBUG ((DEBUG_INFO, " Start LBA : %lx\n", (UINT64)HdDev.PartitionStart));\r
+ DEBUG ((DEBUG_INFO, " End LBA : %lx\n", (UINT64)Entry->EndingLBA));\r
+ DEBUG ((DEBUG_INFO, " Partition size: %lx\n", (UINT64)HdDev.PartitionSize));\r
+ DEBUG ((DEBUG_INFO, " Start : %lx", MultU64x32 (Entry->StartingLBA, BlockSize)));\r
+ DEBUG ((DEBUG_INFO, " End : %lx\n", MultU64x32 (Entry->EndingLBA, BlockSize)));\r
\r
Status = PartitionInstallChildHandle (\r
This,\r
Handle,\r
DiskIo,\r
+ DiskIo2,\r
BlockIo,\r
BlockIo2,\r
DevicePath,\r
- (EFI_DEVICE_PATH_PROTOCOL *) &HdDev,\r
+ (EFI_DEVICE_PATH_PROTOCOL *)&HdDev,\r
+ &PartitionInfo,\r
Entry->StartingLBA,\r
Entry->EndingLBA,\r
BlockSize,\r
- CompareGuid(&Entry->PartitionTypeGUID, &gEfiPartTypeSystemPartGuid)\r
+ &Entry->PartitionTypeGUID\r
);\r
}\r
\r
- DEBUG ((EFI_D_INFO, "Prepare to Free Pool\n"));\r
+ DEBUG ((DEBUG_INFO, "Prepare to Free Pool\n"));\r
\r
Done:\r
if (ProtectiveMbr != NULL) {\r
FreePool (ProtectiveMbr);\r
}\r
+\r
if (PrimaryHeader != NULL) {\r
FreePool (PrimaryHeader);\r
}\r
+\r
if (BackupHeader != NULL) {\r
FreePool (BackupHeader);\r
}\r
+\r
if (PartEntry != NULL) {\r
FreePool (PartEntry);\r
}\r
+\r
if (PEntryStatus != NULL) {\r
FreePool (PEntryStatus);\r
}\r
PartHdr = AllocateZeroPool (BlockSize);\r
\r
if (PartHdr == NULL) {\r
- DEBUG ((EFI_D_ERROR, "Allocate pool error\n"));\r
+ DEBUG ((DEBUG_ERROR, "Allocate pool error\n"));\r
return FALSE;\r
}\r
+\r
//\r
// Read the EFI Partition Table Header\r
//\r
\r
if ((PartHdr->Header.Signature != EFI_PTAB_HEADER_ID) ||\r
!PartitionCheckCrc (BlockSize, &PartHdr->Header) ||\r
- PartHdr->MyLBA != Lba ||\r
+ (PartHdr->MyLBA != Lba) ||\r
(PartHdr->SizeOfPartitionEntry < sizeof (EFI_PARTITION_ENTRY))\r
- ) {\r
- DEBUG ((EFI_D_INFO, "Invalid efi partition table header\n"));\r
+ )\r
+ {\r
+ DEBUG ((DEBUG_INFO, "Invalid efi partition table header\n"));\r
FreePool (PartHdr);\r
return FALSE;\r
}\r
return FALSE;\r
}\r
\r
- DEBUG ((EFI_D_INFO, " Valid efi partition table header\n"));\r
+ DEBUG ((DEBUG_INFO, " Valid efi partition table header\n"));\r
FreePool (PartHdr);\r
return TRUE;\r
}\r
//\r
Ptr = AllocatePool (PartHeader->NumberOfPartitionEntries * PartHeader->SizeOfPartitionEntry);\r
if (Ptr == NULL) {\r
- DEBUG ((EFI_D_ERROR, " Allocate pool error\n"));\r
+ DEBUG ((DEBUG_ERROR, " Allocate pool error\n"));\r
return FALSE;\r
}\r
\r
Status = DiskIo->ReadDisk (\r
- DiskIo,\r
- BlockIo->Media->MediaId,\r
- MultU64x32(PartHeader->PartitionEntryLBA, BlockIo->Media->BlockSize),\r
- PartHeader->NumberOfPartitionEntries * PartHeader->SizeOfPartitionEntry,\r
- Ptr\r
- );\r
+ DiskIo,\r
+ BlockIo->Media->MediaId,\r
+ MultU64x32 (PartHeader->PartitionEntryLBA, BlockIo->Media->BlockSize),\r
+ PartHeader->NumberOfPartitionEntries * PartHeader->SizeOfPartitionEntry,\r
+ Ptr\r
+ );\r
if (EFI_ERROR (Status)) {\r
FreePool (Ptr);\r
return FALSE;\r
}\r
\r
- Size = PartHeader->NumberOfPartitionEntries * PartHeader->SizeOfPartitionEntry;\r
+ Size = PartHeader->NumberOfPartitionEntries * PartHeader->SizeOfPartitionEntry;\r
\r
- Status = gBS->CalculateCrc32 (Ptr, Size, &Crc);\r
+ Status = gBS->CalculateCrc32 (Ptr, Size, &Crc);\r
if (EFI_ERROR (Status)) {\r
- DEBUG ((EFI_D_ERROR, "CheckPEntryArrayCRC: Crc calculation failed\n"));\r
+ DEBUG ((DEBUG_ERROR, "CheckPEntryArrayCRC: Crc calculation failed\n"));\r
FreePool (Ptr);\r
return FALSE;\r
}\r
\r
FreePool (Ptr);\r
\r
- return (BOOLEAN) (PartHeader->PartitionEntryArrayCRC32 == Crc);\r
+ return (BOOLEAN)(PartHeader->PartitionEntryArrayCRC32 == Crc);\r
}\r
\r
-\r
/**\r
Restore Partition Table to its alternate place\r
(Primary -> Backup or Backup -> Primary).\r
UINT8 *Ptr;\r
UINT32 MediaId;\r
\r
- PartHdr = NULL;\r
- Ptr = NULL;\r
+ PartHdr = NULL;\r
+ Ptr = NULL;\r
\r
BlockSize = BlockIo->Media->BlockSize;\r
MediaId = BlockIo->Media->MediaId;\r
\r
- PartHdr = AllocateZeroPool (BlockSize);\r
+ PartHdr = AllocateZeroPool (BlockSize);\r
\r
if (PartHdr == NULL) {\r
- DEBUG ((EFI_D_ERROR, "Allocate pool error\n"));\r
+ DEBUG ((DEBUG_ERROR, "Allocate pool error\n"));\r
return FALSE;\r
}\r
\r
PEntryLBA = (PartHeader->MyLBA == PRIMARY_PART_HEADER_LBA) ? \\r
- (PartHeader->LastUsableLBA + 1) : \\r
- (PRIMARY_PART_HEADER_LBA + 1);\r
+ (PartHeader->LastUsableLBA + 1) : \\r
+ (PRIMARY_PART_HEADER_LBA + 1);\r
\r
CopyMem (PartHdr, PartHeader, sizeof (EFI_PARTITION_TABLE_HEADER));\r
\r
- PartHdr->MyLBA = PartHeader->AlternateLBA;\r
- PartHdr->AlternateLBA = PartHeader->MyLBA;\r
- PartHdr->PartitionEntryLBA = PEntryLBA;\r
- PartitionSetCrc ((EFI_TABLE_HEADER *) PartHdr);\r
+ PartHdr->MyLBA = PartHeader->AlternateLBA;\r
+ PartHdr->AlternateLBA = PartHeader->MyLBA;\r
+ PartHdr->PartitionEntryLBA = PEntryLBA;\r
+ PartitionSetCrc ((EFI_TABLE_HEADER *)PartHdr);\r
\r
Status = DiskIo->WriteDisk (\r
DiskIo,\r
MediaId,\r
- MultU64x32 (PartHdr->MyLBA, (UINT32) BlockSize),\r
+ MultU64x32 (PartHdr->MyLBA, (UINT32)BlockSize),\r
BlockSize,\r
PartHdr\r
);\r
\r
Ptr = AllocatePool (PartHeader->NumberOfPartitionEntries * PartHeader->SizeOfPartitionEntry);\r
if (Ptr == NULL) {\r
- DEBUG ((EFI_D_ERROR, " Allocate pool error\n"));\r
+ DEBUG ((DEBUG_ERROR, " Allocate pool error\n"));\r
Status = EFI_OUT_OF_RESOURCES;\r
goto Done;\r
}\r
\r
Status = DiskIo->ReadDisk (\r
- DiskIo,\r
- MediaId,\r
- MultU64x32(PartHeader->PartitionEntryLBA, (UINT32) BlockSize),\r
- PartHeader->NumberOfPartitionEntries * PartHeader->SizeOfPartitionEntry,\r
- Ptr\r
- );\r
+ DiskIo,\r
+ MediaId,\r
+ MultU64x32 (PartHeader->PartitionEntryLBA, (UINT32)BlockSize),\r
+ PartHeader->NumberOfPartitionEntries * PartHeader->SizeOfPartitionEntry,\r
+ Ptr\r
+ );\r
if (EFI_ERROR (Status)) {\r
goto Done;\r
}\r
\r
Status = DiskIo->WriteDisk (\r
- DiskIo,\r
- MediaId,\r
- MultU64x32(PEntryLBA, (UINT32) BlockSize),\r
- PartHeader->NumberOfPartitionEntries * PartHeader->SizeOfPartitionEntry,\r
- Ptr\r
- );\r
+ DiskIo,\r
+ MediaId,\r
+ MultU64x32 (PEntryLBA, (UINT32)BlockSize),\r
+ PartHeader->NumberOfPartitionEntries * PartHeader->SizeOfPartitionEntry,\r
+ Ptr\r
+ );\r
\r
Done:\r
FreePool (PartHdr);\r
\r
@param[in] PartHeader Partition table header structure\r
@param[in] PartEntry The partition entry array\r
- @param[out] PEntryStatus the partition entry status array \r
+ @param[out] PEntryStatus the partition entry status array\r
recording the status of each partition\r
\r
**/\r
UINTN Index1;\r
UINTN Index2;\r
\r
- DEBUG ((EFI_D_INFO, " start check partition entries\n"));\r
+ DEBUG ((DEBUG_INFO, " start check partition entries\n"));\r
for (Index1 = 0; Index1 < PartHeader->NumberOfPartitionEntries; Index1++) {\r
- Entry = (EFI_PARTITION_ENTRY *) ((UINT8 *) PartEntry + Index1 * PartHeader->SizeOfPartitionEntry);\r
+ Entry = (EFI_PARTITION_ENTRY *)((UINT8 *)PartEntry + Index1 * PartHeader->SizeOfPartitionEntry);\r
if (CompareGuid (&Entry->PartitionTypeGUID, &gEfiPartTypeUnusedGuid)) {\r
continue;\r
}\r
\r
StartingLBA = Entry->StartingLBA;\r
EndingLBA = Entry->EndingLBA;\r
- if (StartingLBA > EndingLBA ||\r
- StartingLBA < PartHeader->FirstUsableLBA ||\r
- StartingLBA > PartHeader->LastUsableLBA ||\r
- EndingLBA < PartHeader->FirstUsableLBA ||\r
- EndingLBA > PartHeader->LastUsableLBA\r
- ) {\r
+ if ((StartingLBA > EndingLBA) ||\r
+ (StartingLBA < PartHeader->FirstUsableLBA) ||\r
+ (StartingLBA > PartHeader->LastUsableLBA) ||\r
+ (EndingLBA < PartHeader->FirstUsableLBA) ||\r
+ (EndingLBA > PartHeader->LastUsableLBA)\r
+ )\r
+ {\r
PEntryStatus[Index1].OutOfRange = TRUE;\r
continue;\r
}\r
\r
if ((Entry->Attributes & BIT1) != 0) {\r
//\r
- // If Bit 1 is set, this indicate that this is an OS specific GUID partition. \r
+ // If Bit 1 is set, this indicate that this is an OS specific GUID partition.\r
//\r
PEntryStatus[Index1].OsSpecific = TRUE;\r
}\r
\r
for (Index2 = Index1 + 1; Index2 < PartHeader->NumberOfPartitionEntries; Index2++) {\r
- Entry = (EFI_PARTITION_ENTRY *) ((UINT8 *) PartEntry + Index2 * PartHeader->SizeOfPartitionEntry);\r
+ Entry = (EFI_PARTITION_ENTRY *)((UINT8 *)PartEntry + Index2 * PartHeader->SizeOfPartitionEntry);\r
if (CompareGuid (&Entry->PartitionTypeGUID, &gEfiPartTypeUnusedGuid)) {\r
continue;\r
}\r
\r
- if (Entry->EndingLBA >= StartingLBA && Entry->StartingLBA <= EndingLBA) {\r
+ if ((Entry->EndingLBA >= StartingLBA) && (Entry->StartingLBA <= EndingLBA)) {\r
//\r
// This region overlaps with the Index1'th region\r
//\r
- PEntryStatus[Index1].Overlap = TRUE;\r
- PEntryStatus[Index2].Overlap = TRUE;\r
+ PEntryStatus[Index1].Overlap = TRUE;\r
+ PEntryStatus[Index2].Overlap = TRUE;\r
continue;\r
}\r
}\r
}\r
\r
- DEBUG ((EFI_D_INFO, " End check partition entries\n"));\r
+ DEBUG ((DEBUG_INFO, " End check partition entries\n"));\r
}\r
\r
-\r
/**\r
Updates the CRC32 value in the table header.\r
\r
**/\r
VOID\r
PartitionSetCrc (\r
- IN OUT EFI_TABLE_HEADER *Hdr\r
+ IN OUT EFI_TABLE_HEADER *Hdr\r
)\r
{\r
PartitionSetCrcAltSize (Hdr->HeaderSize, Hdr);\r
}\r
\r
-\r
/**\r
Updates the CRC32 value in the table header.\r
\r
UINT32 Crc;\r
\r
Hdr->CRC32 = 0;\r
- gBS->CalculateCrc32 ((UINT8 *) Hdr, Size, &Crc);\r
+ gBS->CalculateCrc32 ((UINT8 *)Hdr, Size, &Crc);\r
Hdr->CRC32 = Crc;\r
}\r
\r
-\r
/**\r
Checks the CRC32 value in the table header.\r
\r
return PartitionCheckCrcAltSize (MaxSize, Hdr->HeaderSize, Hdr);\r
}\r
\r
-\r
/**\r
Checks the CRC32 value in the table header.\r
\r
}\r
\r
if ((MaxSize != 0) && (Size > MaxSize)) {\r
- DEBUG ((EFI_D_ERROR, "CheckCrc32: Size > MaxSize\n"));\r
+ DEBUG ((DEBUG_ERROR, "CheckCrc32: Size > MaxSize\n"));\r
return FALSE;\r
}\r
+\r
//\r
// clear old crc from header\r
//\r
- OrgCrc = Hdr->CRC32;\r
- Hdr->CRC32 = 0;\r
+ OrgCrc = Hdr->CRC32;\r
+ Hdr->CRC32 = 0;\r
\r
- Status = gBS->CalculateCrc32 ((UINT8 *) Hdr, Size, &Crc);\r
+ Status = gBS->CalculateCrc32 ((UINT8 *)Hdr, Size, &Crc);\r
if (EFI_ERROR (Status)) {\r
- DEBUG ((EFI_D_ERROR, "CheckCrc32: Crc calculation failed\n"));\r
+ DEBUG ((DEBUG_ERROR, "CheckCrc32: Crc calculation failed\n"));\r
return FALSE;\r
}\r
+\r
//\r
// set results\r
//\r
// return status\r
//\r
DEBUG_CODE_BEGIN ();\r
- if (OrgCrc != Crc) {\r
- DEBUG ((EFI_D_ERROR, "CheckCrc32: Crc check failed\n"));\r
- }\r
+ if (OrgCrc != Crc) {\r
+ DEBUG ((DEBUG_ERROR, "CheckCrc32: Crc check failed\n"));\r
+ }\r
+\r
DEBUG_CODE_END ();\r
\r
- return (BOOLEAN) (OrgCrc == Crc);\r
+ return (BOOLEAN)(OrgCrc == Crc);\r
}\r