2 Decode a hard disk partitioned with the GPT scheme in the UEFI 2.0
5 Caution: This file requires additional review when modified.
6 This driver will have external input - disk partition.
7 This external input must be validated carefully to avoid security issue like
8 buffer overflow, integer overflow.
10 PartitionInstallGptChildHandles() routine will read disk partition content and
11 do basic validation before PartitionInstallChildHandle().
13 PartitionValidGptTable(), PartitionCheckGptEntry() routine will accept disk
14 partition content and validate the GPT table and GPT entry.
16 Copyright (c) 2018 Qualcomm Datacenter Technologies, Inc.
17 Copyright (c) 2006 - 2019, Intel Corporation. All rights reserved.<BR>
18 SPDX-License-Identifier: BSD-2-Clause-Patent
22 #include "Partition.h"
25 Install child handles if the Handle supports GPT partition structure.
27 Caution: This function may receive untrusted input.
28 The GPT partition table header is external input, so this routine
29 will do basic validation for GPT partition table header before return.
31 @param[in] BlockIo Parent BlockIo interface.
32 @param[in] DiskIo Disk Io protocol.
33 @param[in] Lba The starting Lba of the Partition Table
34 @param[out] PartHeader Stores the partition table that is read
36 @retval TRUE The partition table is valid
37 @retval FALSE The partition table is not valid
41 PartitionValidGptTable (
42 IN EFI_BLOCK_IO_PROTOCOL
*BlockIo
,
43 IN EFI_DISK_IO_PROTOCOL
*DiskIo
,
45 OUT EFI_PARTITION_TABLE_HEADER
*PartHeader
49 Check if the CRC field in the Partition table header is valid
50 for Partition entry array.
52 @param[in] BlockIo Parent BlockIo interface
53 @param[in] DiskIo Disk Io Protocol.
54 @param[in] PartHeader Partition table header structure
56 @retval TRUE the CRC is valid
57 @retval FALSE the CRC is invalid
61 PartitionCheckGptEntryArrayCRC (
62 IN EFI_BLOCK_IO_PROTOCOL
*BlockIo
,
63 IN EFI_DISK_IO_PROTOCOL
*DiskIo
,
64 IN EFI_PARTITION_TABLE_HEADER
*PartHeader
68 Restore Partition Table to its alternate place
69 (Primary -> Backup or Backup -> Primary).
71 @param[in] BlockIo Parent BlockIo interface.
72 @param[in] DiskIo Disk Io Protocol.
73 @param[in] PartHeader Partition table header structure.
75 @retval TRUE Restoring succeeds
76 @retval FALSE Restoring failed
80 PartitionRestoreGptTable (
81 IN EFI_BLOCK_IO_PROTOCOL
*BlockIo
,
82 IN EFI_DISK_IO_PROTOCOL
*DiskIo
,
83 IN EFI_PARTITION_TABLE_HEADER
*PartHeader
87 This routine will check GPT partition entry and return entry status.
89 Caution: This function may receive untrusted input.
90 The GPT partition entry is external input, so this routine
91 will do basic validation for GPT partition entry and report status.
93 @param[in] PartHeader Partition table header structure
94 @param[in] PartEntry The partition entry array
95 @param[out] PEntryStatus the partition entry status array
96 recording the status of each partition
100 PartitionCheckGptEntry (
101 IN EFI_PARTITION_TABLE_HEADER
*PartHeader
,
102 IN EFI_PARTITION_ENTRY
*PartEntry
,
103 OUT EFI_PARTITION_ENTRY_STATUS
*PEntryStatus
107 Checks the CRC32 value in the table header.
109 @param MaxSize Max Size limit
110 @param Size The size of the table
111 @param Hdr Table to check
113 @return TRUE CRC Valid
114 @return FALSE CRC Invalid
118 PartitionCheckCrcAltSize (
121 IN OUT EFI_TABLE_HEADER
*Hdr
125 Checks the CRC32 value in the table header.
127 @param MaxSize Max Size limit
128 @param Hdr Table to check
130 @return TRUE CRC Valid
131 @return FALSE CRC Invalid
137 IN OUT EFI_TABLE_HEADER
*Hdr
141 Updates the CRC32 value in the table header.
143 @param Size The size of the table
144 @param Hdr Table to update
148 PartitionSetCrcAltSize (
150 IN OUT EFI_TABLE_HEADER
*Hdr
154 Updates the CRC32 value in the table header.
156 @param Hdr Table to update
161 IN OUT EFI_TABLE_HEADER
*Hdr
165 Install child handles if the Handle supports GPT partition structure.
167 Caution: This function may receive untrusted input.
168 The GPT partition table is external input, so this routine
169 will do basic validation for GPT partition table before install
170 child handle for each GPT partition.
172 @param[in] This Calling context.
173 @param[in] Handle Parent Handle.
174 @param[in] DiskIo Parent DiskIo interface.
175 @param[in] DiskIo2 Parent DiskIo2 interface.
176 @param[in] BlockIo Parent BlockIo interface.
177 @param[in] BlockIo2 Parent BlockIo2 interface.
178 @param[in] DevicePath Parent Device Path.
180 @retval EFI_SUCCESS Valid GPT disk.
181 @retval EFI_MEDIA_CHANGED Media changed Detected.
182 @retval other Not a valid GPT disk.
186 PartitionInstallGptChildHandles (
187 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
188 IN EFI_HANDLE Handle
,
189 IN EFI_DISK_IO_PROTOCOL
*DiskIo
,
190 IN EFI_DISK_IO2_PROTOCOL
*DiskIo2
,
191 IN EFI_BLOCK_IO_PROTOCOL
*BlockIo
,
192 IN EFI_BLOCK_IO2_PROTOCOL
*BlockIo2
,
193 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePath
199 MASTER_BOOT_RECORD
*ProtectiveMbr
;
200 EFI_PARTITION_TABLE_HEADER
*PrimaryHeader
;
201 EFI_PARTITION_TABLE_HEADER
*BackupHeader
;
202 EFI_PARTITION_ENTRY
*PartEntry
;
203 EFI_PARTITION_ENTRY
*Entry
;
204 EFI_PARTITION_ENTRY_STATUS
*PEntryStatus
;
206 EFI_STATUS GptValidStatus
;
207 HARDDRIVE_DEVICE_PATH HdDev
;
209 EFI_PARTITION_INFO_PROTOCOL PartitionInfo
;
211 ProtectiveMbr
= NULL
;
212 PrimaryHeader
= NULL
;
217 BlockSize
= BlockIo
->Media
->BlockSize
;
218 LastBlock
= BlockIo
->Media
->LastBlock
;
219 MediaId
= BlockIo
->Media
->MediaId
;
221 DEBUG ((DEBUG_INFO
, " BlockSize : %d \n", BlockSize
));
222 DEBUG ((DEBUG_INFO
, " LastBlock : %lx \n", LastBlock
));
224 GptValidStatus
= EFI_NOT_FOUND
;
227 // Ensure the block size can hold the MBR
229 if (BlockSize
< sizeof (MASTER_BOOT_RECORD
)) {
230 return EFI_NOT_FOUND
;
234 // Allocate a buffer for the Protective MBR
236 ProtectiveMbr
= AllocatePool (BlockSize
);
237 if (ProtectiveMbr
== NULL
) {
238 return EFI_NOT_FOUND
;
242 // Read the Protective MBR from LBA #0
244 Status
= DiskIo
->ReadDisk (
251 if (EFI_ERROR (Status
)) {
252 GptValidStatus
= Status
;
257 // Verify that the Protective MBR is valid
259 for (Index
= 0; Index
< MAX_MBR_PARTITIONS
; Index
++) {
260 if ((ProtectiveMbr
->Partition
[Index
].OSIndicator
== PMBR_GPT_PARTITION
) &&
261 (UNPACK_UINT32 (ProtectiveMbr
->Partition
[Index
].StartingLBA
) == 1)
268 if (Index
== MAX_MBR_PARTITIONS
) {
273 // Allocate the GPT structures
275 PrimaryHeader
= AllocateZeroPool (sizeof (EFI_PARTITION_TABLE_HEADER
));
276 if (PrimaryHeader
== NULL
) {
280 BackupHeader
= AllocateZeroPool (sizeof (EFI_PARTITION_TABLE_HEADER
));
281 if (BackupHeader
== NULL
) {
286 // Check primary and backup partition tables
288 if (!PartitionValidGptTable (BlockIo
, DiskIo
, PRIMARY_PART_HEADER_LBA
, PrimaryHeader
)) {
289 DEBUG ((DEBUG_INFO
, " Not Valid primary partition table\n"));
291 if (!PartitionValidGptTable (BlockIo
, DiskIo
, LastBlock
, BackupHeader
)) {
292 DEBUG ((DEBUG_INFO
, " Not Valid backup partition table\n"));
295 DEBUG ((DEBUG_INFO
, " Valid backup partition table\n"));
296 DEBUG ((DEBUG_INFO
, " Restore primary partition table by the backup\n"));
297 if (!PartitionRestoreGptTable (BlockIo
, DiskIo
, BackupHeader
)) {
298 DEBUG ((DEBUG_INFO
, " Restore primary partition table error\n"));
301 if (PartitionValidGptTable (BlockIo
, DiskIo
, BackupHeader
->AlternateLBA
, PrimaryHeader
)) {
302 DEBUG ((DEBUG_INFO
, " Restore backup partition table success\n"));
305 } else if (!PartitionValidGptTable (BlockIo
, DiskIo
, PrimaryHeader
->AlternateLBA
, BackupHeader
)) {
306 DEBUG ((DEBUG_INFO
, " Valid primary and !Valid backup partition table\n"));
307 DEBUG ((DEBUG_INFO
, " Restore backup partition table by the primary\n"));
308 if (!PartitionRestoreGptTable (BlockIo
, DiskIo
, PrimaryHeader
)) {
309 DEBUG ((DEBUG_INFO
, " Restore backup partition table error\n"));
312 if (PartitionValidGptTable (BlockIo
, DiskIo
, PrimaryHeader
->AlternateLBA
, BackupHeader
)) {
313 DEBUG ((DEBUG_INFO
, " Restore backup partition table success\n"));
317 DEBUG ((DEBUG_INFO
, " Valid primary and Valid backup partition table\n"));
320 // Read the EFI Partition Entries
322 PartEntry
= AllocatePool (PrimaryHeader
->NumberOfPartitionEntries
* PrimaryHeader
->SizeOfPartitionEntry
);
323 if (PartEntry
== NULL
) {
324 DEBUG ((DEBUG_ERROR
, "Allocate pool error\n"));
328 Status
= DiskIo
->ReadDisk (
331 MultU64x32 (PrimaryHeader
->PartitionEntryLBA
, BlockSize
),
332 PrimaryHeader
->NumberOfPartitionEntries
* (PrimaryHeader
->SizeOfPartitionEntry
),
335 if (EFI_ERROR (Status
)) {
336 GptValidStatus
= Status
;
337 DEBUG ((DEBUG_ERROR
, " Partition Entry ReadDisk error\n"));
341 DEBUG ((DEBUG_INFO
, " Partition entries read block success\n"));
343 DEBUG ((DEBUG_INFO
, " Number of partition entries: %d\n", PrimaryHeader
->NumberOfPartitionEntries
));
345 PEntryStatus
= AllocateZeroPool (PrimaryHeader
->NumberOfPartitionEntries
* sizeof (EFI_PARTITION_ENTRY_STATUS
));
346 if (PEntryStatus
== NULL
) {
347 DEBUG ((DEBUG_ERROR
, "Allocate pool error\n"));
352 // Check the integrity of partition entries
354 PartitionCheckGptEntry (PrimaryHeader
, PartEntry
, PEntryStatus
);
357 // If we got this far the GPT layout of the disk is valid and we should return true
359 GptValidStatus
= EFI_SUCCESS
;
362 // Create child device handles
364 for (Index
= 0; Index
< PrimaryHeader
->NumberOfPartitionEntries
; Index
++) {
365 Entry
= (EFI_PARTITION_ENTRY
*)((UINT8
*)PartEntry
+ Index
* PrimaryHeader
->SizeOfPartitionEntry
);
366 if (CompareGuid (&Entry
->PartitionTypeGUID
, &gEfiPartTypeUnusedGuid
) ||
367 PEntryStatus
[Index
].OutOfRange
||
368 PEntryStatus
[Index
].Overlap
||
369 PEntryStatus
[Index
].OsSpecific
373 // Don't use null EFI Partition Entries, Invalid Partition Entries or OS specific
379 ZeroMem (&HdDev
, sizeof (HdDev
));
380 HdDev
.Header
.Type
= MEDIA_DEVICE_PATH
;
381 HdDev
.Header
.SubType
= MEDIA_HARDDRIVE_DP
;
382 SetDevicePathNodeLength (&HdDev
.Header
, sizeof (HdDev
));
384 HdDev
.PartitionNumber
= (UINT32
)Index
+ 1;
385 HdDev
.MBRType
= MBR_TYPE_EFI_PARTITION_TABLE_HEADER
;
386 HdDev
.SignatureType
= SIGNATURE_TYPE_GUID
;
387 HdDev
.PartitionStart
= Entry
->StartingLBA
;
388 HdDev
.PartitionSize
= Entry
->EndingLBA
- Entry
->StartingLBA
+ 1;
389 CopyMem (HdDev
.Signature
, &Entry
->UniquePartitionGUID
, sizeof (EFI_GUID
));
391 ZeroMem (&PartitionInfo
, sizeof (EFI_PARTITION_INFO_PROTOCOL
));
392 PartitionInfo
.Revision
= EFI_PARTITION_INFO_PROTOCOL_REVISION
;
393 PartitionInfo
.Type
= PARTITION_TYPE_GPT
;
394 if (CompareGuid (&Entry
->PartitionTypeGUID
, &gEfiPartTypeSystemPartGuid
)) {
395 PartitionInfo
.System
= 1;
398 CopyMem (&PartitionInfo
.Info
.Gpt
, Entry
, sizeof (EFI_PARTITION_ENTRY
));
400 DEBUG ((DEBUG_INFO
, " Index : %d\n", (UINT32
)Index
));
401 DEBUG ((DEBUG_INFO
, " Start LBA : %lx\n", (UINT64
)HdDev
.PartitionStart
));
402 DEBUG ((DEBUG_INFO
, " End LBA : %lx\n", (UINT64
)Entry
->EndingLBA
));
403 DEBUG ((DEBUG_INFO
, " Partition size: %lx\n", (UINT64
)HdDev
.PartitionSize
));
404 DEBUG ((DEBUG_INFO
, " Start : %lx", MultU64x32 (Entry
->StartingLBA
, BlockSize
)));
405 DEBUG ((DEBUG_INFO
, " End : %lx\n", MultU64x32 (Entry
->EndingLBA
, BlockSize
)));
407 Status
= PartitionInstallChildHandle (
415 (EFI_DEVICE_PATH_PROTOCOL
*)&HdDev
,
420 &Entry
->PartitionTypeGUID
424 DEBUG ((DEBUG_INFO
, "Prepare to Free Pool\n"));
427 if (ProtectiveMbr
!= NULL
) {
428 FreePool (ProtectiveMbr
);
431 if (PrimaryHeader
!= NULL
) {
432 FreePool (PrimaryHeader
);
435 if (BackupHeader
!= NULL
) {
436 FreePool (BackupHeader
);
439 if (PartEntry
!= NULL
) {
440 FreePool (PartEntry
);
443 if (PEntryStatus
!= NULL
) {
444 FreePool (PEntryStatus
);
447 return GptValidStatus
;
451 This routine will read GPT partition table header and return it.
453 Caution: This function may receive untrusted input.
454 The GPT partition table header is external input, so this routine
455 will do basic validation for GPT partition table header before return.
457 @param[in] BlockIo Parent BlockIo interface.
458 @param[in] DiskIo Disk Io protocol.
459 @param[in] Lba The starting Lba of the Partition Table
460 @param[out] PartHeader Stores the partition table that is read
462 @retval TRUE The partition table is valid
463 @retval FALSE The partition table is not valid
467 PartitionValidGptTable (
468 IN EFI_BLOCK_IO_PROTOCOL
*BlockIo
,
469 IN EFI_DISK_IO_PROTOCOL
*DiskIo
,
471 OUT EFI_PARTITION_TABLE_HEADER
*PartHeader
476 EFI_PARTITION_TABLE_HEADER
*PartHdr
;
479 BlockSize
= BlockIo
->Media
->BlockSize
;
480 MediaId
= BlockIo
->Media
->MediaId
;
481 PartHdr
= AllocateZeroPool (BlockSize
);
483 if (PartHdr
== NULL
) {
484 DEBUG ((DEBUG_ERROR
, "Allocate pool error\n"));
489 // Read the EFI Partition Table Header
491 Status
= DiskIo
->ReadDisk (
494 MultU64x32 (Lba
, BlockSize
),
498 if (EFI_ERROR (Status
)) {
503 if ((PartHdr
->Header
.Signature
!= EFI_PTAB_HEADER_ID
) ||
504 !PartitionCheckCrc (BlockSize
, &PartHdr
->Header
) ||
505 (PartHdr
->MyLBA
!= Lba
) ||
506 (PartHdr
->SizeOfPartitionEntry
< sizeof (EFI_PARTITION_ENTRY
))
509 DEBUG ((DEBUG_INFO
, "Invalid efi partition table header\n"));
515 // Ensure the NumberOfPartitionEntries * SizeOfPartitionEntry doesn't overflow.
517 if (PartHdr
->NumberOfPartitionEntries
> DivU64x32 (MAX_UINTN
, PartHdr
->SizeOfPartitionEntry
)) {
522 CopyMem (PartHeader
, PartHdr
, sizeof (EFI_PARTITION_TABLE_HEADER
));
523 if (!PartitionCheckGptEntryArrayCRC (BlockIo
, DiskIo
, PartHeader
)) {
528 DEBUG ((DEBUG_INFO
, " Valid efi partition table header\n"));
534 Check if the CRC field in the Partition table header is valid
535 for Partition entry array.
537 @param[in] BlockIo Parent BlockIo interface
538 @param[in] DiskIo Disk Io Protocol.
539 @param[in] PartHeader Partition table header structure
541 @retval TRUE the CRC is valid
542 @retval FALSE the CRC is invalid
546 PartitionCheckGptEntryArrayCRC (
547 IN EFI_BLOCK_IO_PROTOCOL
*BlockIo
,
548 IN EFI_DISK_IO_PROTOCOL
*DiskIo
,
549 IN EFI_PARTITION_TABLE_HEADER
*PartHeader
558 // Read the EFI Partition Entries
560 Ptr
= AllocatePool (PartHeader
->NumberOfPartitionEntries
* PartHeader
->SizeOfPartitionEntry
);
562 DEBUG ((DEBUG_ERROR
, " Allocate pool error\n"));
566 Status
= DiskIo
->ReadDisk (
568 BlockIo
->Media
->MediaId
,
569 MultU64x32 (PartHeader
->PartitionEntryLBA
, BlockIo
->Media
->BlockSize
),
570 PartHeader
->NumberOfPartitionEntries
* PartHeader
->SizeOfPartitionEntry
,
573 if (EFI_ERROR (Status
)) {
578 Size
= PartHeader
->NumberOfPartitionEntries
* PartHeader
->SizeOfPartitionEntry
;
580 Status
= gBS
->CalculateCrc32 (Ptr
, Size
, &Crc
);
581 if (EFI_ERROR (Status
)) {
582 DEBUG ((DEBUG_ERROR
, "CheckPEntryArrayCRC: Crc calculation failed\n"));
589 return (BOOLEAN
)(PartHeader
->PartitionEntryArrayCRC32
== Crc
);
593 Restore Partition Table to its alternate place
594 (Primary -> Backup or Backup -> Primary).
596 @param[in] BlockIo Parent BlockIo interface.
597 @param[in] DiskIo Disk Io Protocol.
598 @param[in] PartHeader Partition table header structure.
600 @retval TRUE Restoring succeeds
601 @retval FALSE Restoring failed
605 PartitionRestoreGptTable (
606 IN EFI_BLOCK_IO_PROTOCOL
*BlockIo
,
607 IN EFI_DISK_IO_PROTOCOL
*DiskIo
,
608 IN EFI_PARTITION_TABLE_HEADER
*PartHeader
613 EFI_PARTITION_TABLE_HEADER
*PartHdr
;
621 BlockSize
= BlockIo
->Media
->BlockSize
;
622 MediaId
= BlockIo
->Media
->MediaId
;
624 PartHdr
= AllocateZeroPool (BlockSize
);
626 if (PartHdr
== NULL
) {
627 DEBUG ((DEBUG_ERROR
, "Allocate pool error\n"));
631 PEntryLBA
= (PartHeader
->MyLBA
== PRIMARY_PART_HEADER_LBA
) ? \
632 (PartHeader
->LastUsableLBA
+ 1) : \
633 (PRIMARY_PART_HEADER_LBA
+ 1);
635 CopyMem (PartHdr
, PartHeader
, sizeof (EFI_PARTITION_TABLE_HEADER
));
637 PartHdr
->MyLBA
= PartHeader
->AlternateLBA
;
638 PartHdr
->AlternateLBA
= PartHeader
->MyLBA
;
639 PartHdr
->PartitionEntryLBA
= PEntryLBA
;
640 PartitionSetCrc ((EFI_TABLE_HEADER
*)PartHdr
);
642 Status
= DiskIo
->WriteDisk (
645 MultU64x32 (PartHdr
->MyLBA
, (UINT32
)BlockSize
),
649 if (EFI_ERROR (Status
)) {
653 Ptr
= AllocatePool (PartHeader
->NumberOfPartitionEntries
* PartHeader
->SizeOfPartitionEntry
);
655 DEBUG ((DEBUG_ERROR
, " Allocate pool error\n"));
656 Status
= EFI_OUT_OF_RESOURCES
;
660 Status
= DiskIo
->ReadDisk (
663 MultU64x32 (PartHeader
->PartitionEntryLBA
, (UINT32
)BlockSize
),
664 PartHeader
->NumberOfPartitionEntries
* PartHeader
->SizeOfPartitionEntry
,
667 if (EFI_ERROR (Status
)) {
671 Status
= DiskIo
->WriteDisk (
674 MultU64x32 (PEntryLBA
, (UINT32
)BlockSize
),
675 PartHeader
->NumberOfPartitionEntries
* PartHeader
->SizeOfPartitionEntry
,
686 if (EFI_ERROR (Status
)) {
694 This routine will check GPT partition entry and return entry status.
696 Caution: This function may receive untrusted input.
697 The GPT partition entry is external input, so this routine
698 will do basic validation for GPT partition entry and report status.
700 @param[in] PartHeader Partition table header structure
701 @param[in] PartEntry The partition entry array
702 @param[out] PEntryStatus the partition entry status array
703 recording the status of each partition
707 PartitionCheckGptEntry (
708 IN EFI_PARTITION_TABLE_HEADER
*PartHeader
,
709 IN EFI_PARTITION_ENTRY
*PartEntry
,
710 OUT EFI_PARTITION_ENTRY_STATUS
*PEntryStatus
715 EFI_PARTITION_ENTRY
*Entry
;
719 DEBUG ((DEBUG_INFO
, " start check partition entries\n"));
720 for (Index1
= 0; Index1
< PartHeader
->NumberOfPartitionEntries
; Index1
++) {
721 Entry
= (EFI_PARTITION_ENTRY
*)((UINT8
*)PartEntry
+ Index1
* PartHeader
->SizeOfPartitionEntry
);
722 if (CompareGuid (&Entry
->PartitionTypeGUID
, &gEfiPartTypeUnusedGuid
)) {
726 StartingLBA
= Entry
->StartingLBA
;
727 EndingLBA
= Entry
->EndingLBA
;
728 if ((StartingLBA
> EndingLBA
) ||
729 (StartingLBA
< PartHeader
->FirstUsableLBA
) ||
730 (StartingLBA
> PartHeader
->LastUsableLBA
) ||
731 (EndingLBA
< PartHeader
->FirstUsableLBA
) ||
732 (EndingLBA
> PartHeader
->LastUsableLBA
)
735 PEntryStatus
[Index1
].OutOfRange
= TRUE
;
739 if ((Entry
->Attributes
& BIT1
) != 0) {
741 // If Bit 1 is set, this indicate that this is an OS specific GUID partition.
743 PEntryStatus
[Index1
].OsSpecific
= TRUE
;
746 for (Index2
= Index1
+ 1; Index2
< PartHeader
->NumberOfPartitionEntries
; Index2
++) {
747 Entry
= (EFI_PARTITION_ENTRY
*)((UINT8
*)PartEntry
+ Index2
* PartHeader
->SizeOfPartitionEntry
);
748 if (CompareGuid (&Entry
->PartitionTypeGUID
, &gEfiPartTypeUnusedGuid
)) {
752 if ((Entry
->EndingLBA
>= StartingLBA
) && (Entry
->StartingLBA
<= EndingLBA
)) {
754 // This region overlaps with the Index1'th region
756 PEntryStatus
[Index1
].Overlap
= TRUE
;
757 PEntryStatus
[Index2
].Overlap
= TRUE
;
763 DEBUG ((DEBUG_INFO
, " End check partition entries\n"));
767 Updates the CRC32 value in the table header.
769 @param Hdr Table to update
774 IN OUT EFI_TABLE_HEADER
*Hdr
777 PartitionSetCrcAltSize (Hdr
->HeaderSize
, Hdr
);
781 Updates the CRC32 value in the table header.
783 @param Size The size of the table
784 @param Hdr Table to update
788 PartitionSetCrcAltSize (
790 IN OUT EFI_TABLE_HEADER
*Hdr
796 gBS
->CalculateCrc32 ((UINT8
*)Hdr
, Size
, &Crc
);
801 Checks the CRC32 value in the table header.
803 @param MaxSize Max Size limit
804 @param Hdr Table to check
806 @return TRUE CRC Valid
807 @return FALSE CRC Invalid
813 IN OUT EFI_TABLE_HEADER
*Hdr
816 return PartitionCheckCrcAltSize (MaxSize
, Hdr
->HeaderSize
, Hdr
);
820 Checks the CRC32 value in the table header.
822 @param MaxSize Max Size limit
823 @param Size The size of the table
824 @param Hdr Table to check
826 @return TRUE CRC Valid
827 @return FALSE CRC Invalid
831 PartitionCheckCrcAltSize (
834 IN OUT EFI_TABLE_HEADER
*Hdr
845 // If header size is 0 CRC will pass so return FALSE here
850 if ((MaxSize
!= 0) && (Size
> MaxSize
)) {
851 DEBUG ((DEBUG_ERROR
, "CheckCrc32: Size > MaxSize\n"));
856 // clear old crc from header
861 Status
= gBS
->CalculateCrc32 ((UINT8
*)Hdr
, Size
, &Crc
);
862 if (EFI_ERROR (Status
)) {
863 DEBUG ((DEBUG_ERROR
, "CheckCrc32: Crc calculation failed\n"));
877 DEBUG ((DEBUG_ERROR
, "CheckCrc32: Crc check failed\n"));
882 return (BOOLEAN
)(OrgCrc
== Crc
);