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
23 #include "Partition.h"
26 Install child handles if the Handle supports GPT partition structure.
28 Caution: This function may receive untrusted input.
29 The GPT partition table header is external input, so this routine
30 will do basic validation for GPT partition table header before return.
32 @param[in] BlockIo Parent BlockIo interface.
33 @param[in] DiskIo Disk Io protocol.
34 @param[in] Lba The starting Lba of the Partition Table
35 @param[out] PartHeader Stores the partition table that is read
37 @retval TRUE The partition table is valid
38 @retval FALSE The partition table is not valid
42 PartitionValidGptTable (
43 IN EFI_BLOCK_IO_PROTOCOL
*BlockIo
,
44 IN EFI_DISK_IO_PROTOCOL
*DiskIo
,
46 OUT EFI_PARTITION_TABLE_HEADER
*PartHeader
50 Check if the CRC field in the Partition table header is valid
51 for Partition entry array.
53 @param[in] BlockIo Parent BlockIo interface
54 @param[in] DiskIo Disk Io Protocol.
55 @param[in] PartHeader Partition table header structure
57 @retval TRUE the CRC is valid
58 @retval FALSE the CRC is invalid
62 PartitionCheckGptEntryArrayCRC (
63 IN EFI_BLOCK_IO_PROTOCOL
*BlockIo
,
64 IN EFI_DISK_IO_PROTOCOL
*DiskIo
,
65 IN EFI_PARTITION_TABLE_HEADER
*PartHeader
70 Restore Partition Table to its alternate place
71 (Primary -> Backup or Backup -> Primary).
73 @param[in] BlockIo Parent BlockIo interface.
74 @param[in] DiskIo Disk Io Protocol.
75 @param[in] PartHeader Partition table header structure.
77 @retval TRUE Restoring succeeds
78 @retval FALSE Restoring failed
82 PartitionRestoreGptTable (
83 IN EFI_BLOCK_IO_PROTOCOL
*BlockIo
,
84 IN EFI_DISK_IO_PROTOCOL
*DiskIo
,
85 IN EFI_PARTITION_TABLE_HEADER
*PartHeader
90 This routine will check GPT partition entry and return entry status.
92 Caution: This function may receive untrusted input.
93 The GPT partition entry is external input, so this routine
94 will do basic validation for GPT partition entry and report status.
96 @param[in] PartHeader Partition table header structure
97 @param[in] PartEntry The partition entry array
98 @param[out] PEntryStatus the partition entry status array
99 recording the status of each partition
103 PartitionCheckGptEntry (
104 IN EFI_PARTITION_TABLE_HEADER
*PartHeader
,
105 IN EFI_PARTITION_ENTRY
*PartEntry
,
106 OUT EFI_PARTITION_ENTRY_STATUS
*PEntryStatus
111 Checks the CRC32 value in the table header.
113 @param MaxSize Max Size limit
114 @param Size The size of the table
115 @param Hdr Table to check
117 @return TRUE CRC Valid
118 @return FALSE CRC Invalid
122 PartitionCheckCrcAltSize (
125 IN OUT EFI_TABLE_HEADER
*Hdr
130 Checks the CRC32 value in the table header.
132 @param MaxSize Max Size limit
133 @param Hdr Table to check
135 @return TRUE CRC Valid
136 @return FALSE CRC Invalid
142 IN OUT EFI_TABLE_HEADER
*Hdr
147 Updates the CRC32 value in the table header.
149 @param Size The size of the table
150 @param Hdr Table to update
154 PartitionSetCrcAltSize (
156 IN OUT EFI_TABLE_HEADER
*Hdr
161 Updates the CRC32 value in the table header.
163 @param Hdr Table to update
168 IN OUT EFI_TABLE_HEADER
*Hdr
172 Install child handles if the Handle supports GPT partition structure.
174 Caution: This function may receive untrusted input.
175 The GPT partition table is external input, so this routine
176 will do basic validation for GPT partition table before install
177 child handle for each GPT partition.
179 @param[in] This Calling context.
180 @param[in] Handle Parent Handle.
181 @param[in] DiskIo Parent DiskIo interface.
182 @param[in] DiskIo2 Parent DiskIo2 interface.
183 @param[in] BlockIo Parent BlockIo interface.
184 @param[in] BlockIo2 Parent BlockIo2 interface.
185 @param[in] DevicePath Parent Device Path.
187 @retval EFI_SUCCESS Valid GPT disk.
188 @retval EFI_MEDIA_CHANGED Media changed Detected.
189 @retval other Not a valid GPT disk.
193 PartitionInstallGptChildHandles (
194 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
195 IN EFI_HANDLE Handle
,
196 IN EFI_DISK_IO_PROTOCOL
*DiskIo
,
197 IN EFI_DISK_IO2_PROTOCOL
*DiskIo2
,
198 IN EFI_BLOCK_IO_PROTOCOL
*BlockIo
,
199 IN EFI_BLOCK_IO2_PROTOCOL
*BlockIo2
,
200 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePath
206 MASTER_BOOT_RECORD
*ProtectiveMbr
;
207 EFI_PARTITION_TABLE_HEADER
*PrimaryHeader
;
208 EFI_PARTITION_TABLE_HEADER
*BackupHeader
;
209 EFI_PARTITION_ENTRY
*PartEntry
;
210 EFI_PARTITION_ENTRY
*Entry
;
211 EFI_PARTITION_ENTRY_STATUS
*PEntryStatus
;
213 EFI_STATUS GptValidStatus
;
214 HARDDRIVE_DEVICE_PATH HdDev
;
216 EFI_PARTITION_INFO_PROTOCOL PartitionInfo
;
218 ProtectiveMbr
= NULL
;
219 PrimaryHeader
= NULL
;
224 BlockSize
= BlockIo
->Media
->BlockSize
;
225 LastBlock
= BlockIo
->Media
->LastBlock
;
226 MediaId
= BlockIo
->Media
->MediaId
;
228 DEBUG ((EFI_D_INFO
, " BlockSize : %d \n", BlockSize
));
229 DEBUG ((EFI_D_INFO
, " LastBlock : %lx \n", LastBlock
));
231 GptValidStatus
= EFI_NOT_FOUND
;
234 // Ensure the block size can hold the MBR
236 if (BlockSize
< sizeof (MASTER_BOOT_RECORD
)) {
237 return EFI_NOT_FOUND
;
241 // Allocate a buffer for the Protective MBR
243 ProtectiveMbr
= AllocatePool (BlockSize
);
244 if (ProtectiveMbr
== NULL
) {
245 return EFI_NOT_FOUND
;
249 // Read the Protective MBR from LBA #0
251 Status
= DiskIo
->ReadDisk (
258 if (EFI_ERROR (Status
)) {
259 GptValidStatus
= Status
;
264 // Verify that the Protective MBR is valid
266 for (Index
= 0; Index
< MAX_MBR_PARTITIONS
; Index
++) {
267 if (ProtectiveMbr
->Partition
[Index
].OSIndicator
== PMBR_GPT_PARTITION
&&
268 UNPACK_UINT32 (ProtectiveMbr
->Partition
[Index
].StartingLBA
) == 1
273 if (Index
== MAX_MBR_PARTITIONS
) {
278 // Allocate the GPT structures
280 PrimaryHeader
= AllocateZeroPool (sizeof (EFI_PARTITION_TABLE_HEADER
));
281 if (PrimaryHeader
== NULL
) {
285 BackupHeader
= AllocateZeroPool (sizeof (EFI_PARTITION_TABLE_HEADER
));
286 if (BackupHeader
== NULL
) {
291 // Check primary and backup partition tables
293 if (!PartitionValidGptTable (BlockIo
, DiskIo
, PRIMARY_PART_HEADER_LBA
, PrimaryHeader
)) {
294 DEBUG ((EFI_D_INFO
, " Not Valid primary partition table\n"));
296 if (!PartitionValidGptTable (BlockIo
, DiskIo
, LastBlock
, BackupHeader
)) {
297 DEBUG ((EFI_D_INFO
, " Not Valid backup partition table\n"));
300 DEBUG ((EFI_D_INFO
, " Valid backup partition table\n"));
301 DEBUG ((EFI_D_INFO
, " Restore primary partition table by the backup\n"));
302 if (!PartitionRestoreGptTable (BlockIo
, DiskIo
, BackupHeader
)) {
303 DEBUG ((EFI_D_INFO
, " Restore primary partition table error\n"));
306 if (PartitionValidGptTable (BlockIo
, DiskIo
, BackupHeader
->AlternateLBA
, PrimaryHeader
)) {
307 DEBUG ((EFI_D_INFO
, " Restore backup partition table success\n"));
310 } else if (!PartitionValidGptTable (BlockIo
, DiskIo
, PrimaryHeader
->AlternateLBA
, BackupHeader
)) {
311 DEBUG ((EFI_D_INFO
, " Valid primary and !Valid backup partition table\n"));
312 DEBUG ((EFI_D_INFO
, " Restore backup partition table by the primary\n"));
313 if (!PartitionRestoreGptTable (BlockIo
, DiskIo
, PrimaryHeader
)) {
314 DEBUG ((EFI_D_INFO
, " Restore backup partition table error\n"));
317 if (PartitionValidGptTable (BlockIo
, DiskIo
, PrimaryHeader
->AlternateLBA
, BackupHeader
)) {
318 DEBUG ((EFI_D_INFO
, " Restore backup partition table success\n"));
323 DEBUG ((EFI_D_INFO
, " Valid primary and Valid backup partition table\n"));
326 // Read the EFI Partition Entries
328 PartEntry
= AllocatePool (PrimaryHeader
->NumberOfPartitionEntries
* PrimaryHeader
->SizeOfPartitionEntry
);
329 if (PartEntry
== NULL
) {
330 DEBUG ((EFI_D_ERROR
, "Allocate pool error\n"));
334 Status
= DiskIo
->ReadDisk (
337 MultU64x32(PrimaryHeader
->PartitionEntryLBA
, BlockSize
),
338 PrimaryHeader
->NumberOfPartitionEntries
* (PrimaryHeader
->SizeOfPartitionEntry
),
341 if (EFI_ERROR (Status
)) {
342 GptValidStatus
= Status
;
343 DEBUG ((EFI_D_ERROR
, " Partition Entry ReadDisk error\n"));
347 DEBUG ((EFI_D_INFO
, " Partition entries read block success\n"));
349 DEBUG ((EFI_D_INFO
, " Number of partition entries: %d\n", PrimaryHeader
->NumberOfPartitionEntries
));
351 PEntryStatus
= AllocateZeroPool (PrimaryHeader
->NumberOfPartitionEntries
* sizeof (EFI_PARTITION_ENTRY_STATUS
));
352 if (PEntryStatus
== NULL
) {
353 DEBUG ((EFI_D_ERROR
, "Allocate pool error\n"));
358 // Check the integrity of partition entries
360 PartitionCheckGptEntry (PrimaryHeader
, PartEntry
, PEntryStatus
);
363 // If we got this far the GPT layout of the disk is valid and we should return true
365 GptValidStatus
= EFI_SUCCESS
;
368 // Create child device handles
370 for (Index
= 0; Index
< PrimaryHeader
->NumberOfPartitionEntries
; Index
++) {
371 Entry
= (EFI_PARTITION_ENTRY
*) ((UINT8
*) PartEntry
+ Index
* PrimaryHeader
->SizeOfPartitionEntry
);
372 if (CompareGuid (&Entry
->PartitionTypeGUID
, &gEfiPartTypeUnusedGuid
) ||
373 PEntryStatus
[Index
].OutOfRange
||
374 PEntryStatus
[Index
].Overlap
||
375 PEntryStatus
[Index
].OsSpecific
378 // Don't use null EFI Partition Entries, Invalid Partition Entries or OS specific
384 ZeroMem (&HdDev
, sizeof (HdDev
));
385 HdDev
.Header
.Type
= MEDIA_DEVICE_PATH
;
386 HdDev
.Header
.SubType
= MEDIA_HARDDRIVE_DP
;
387 SetDevicePathNodeLength (&HdDev
.Header
, sizeof (HdDev
));
389 HdDev
.PartitionNumber
= (UINT32
) Index
+ 1;
390 HdDev
.MBRType
= MBR_TYPE_EFI_PARTITION_TABLE_HEADER
;
391 HdDev
.SignatureType
= SIGNATURE_TYPE_GUID
;
392 HdDev
.PartitionStart
= Entry
->StartingLBA
;
393 HdDev
.PartitionSize
= Entry
->EndingLBA
- Entry
->StartingLBA
+ 1;
394 CopyMem (HdDev
.Signature
, &Entry
->UniquePartitionGUID
, sizeof (EFI_GUID
));
396 ZeroMem (&PartitionInfo
, sizeof (EFI_PARTITION_INFO_PROTOCOL
));
397 PartitionInfo
.Revision
= EFI_PARTITION_INFO_PROTOCOL_REVISION
;
398 PartitionInfo
.Type
= PARTITION_TYPE_GPT
;
399 if (CompareGuid (&Entry
->PartitionTypeGUID
, &gEfiPartTypeSystemPartGuid
)) {
400 PartitionInfo
.System
= 1;
402 CopyMem (&PartitionInfo
.Info
.Gpt
, Entry
, sizeof (EFI_PARTITION_ENTRY
));
404 DEBUG ((EFI_D_INFO
, " Index : %d\n", (UINT32
) Index
));
405 DEBUG ((EFI_D_INFO
, " Start LBA : %lx\n", (UINT64
) HdDev
.PartitionStart
));
406 DEBUG ((EFI_D_INFO
, " End LBA : %lx\n", (UINT64
) Entry
->EndingLBA
));
407 DEBUG ((EFI_D_INFO
, " Partition size: %lx\n", (UINT64
) HdDev
.PartitionSize
));
408 DEBUG ((EFI_D_INFO
, " Start : %lx", MultU64x32 (Entry
->StartingLBA
, BlockSize
)));
409 DEBUG ((EFI_D_INFO
, " End : %lx\n", MultU64x32 (Entry
->EndingLBA
, BlockSize
)));
411 Status
= PartitionInstallChildHandle (
419 (EFI_DEVICE_PATH_PROTOCOL
*) &HdDev
,
424 &Entry
->PartitionTypeGUID
428 DEBUG ((EFI_D_INFO
, "Prepare to Free Pool\n"));
431 if (ProtectiveMbr
!= NULL
) {
432 FreePool (ProtectiveMbr
);
434 if (PrimaryHeader
!= NULL
) {
435 FreePool (PrimaryHeader
);
437 if (BackupHeader
!= NULL
) {
438 FreePool (BackupHeader
);
440 if (PartEntry
!= NULL
) {
441 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 ((EFI_D_ERROR
, "Allocate pool error\n"));
488 // Read the EFI Partition Table Header
490 Status
= DiskIo
->ReadDisk (
493 MultU64x32 (Lba
, BlockSize
),
497 if (EFI_ERROR (Status
)) {
502 if ((PartHdr
->Header
.Signature
!= EFI_PTAB_HEADER_ID
) ||
503 !PartitionCheckCrc (BlockSize
, &PartHdr
->Header
) ||
504 PartHdr
->MyLBA
!= Lba
||
505 (PartHdr
->SizeOfPartitionEntry
< sizeof (EFI_PARTITION_ENTRY
))
507 DEBUG ((EFI_D_INFO
, "Invalid efi partition table header\n"));
513 // Ensure the NumberOfPartitionEntries * SizeOfPartitionEntry doesn't overflow.
515 if (PartHdr
->NumberOfPartitionEntries
> DivU64x32 (MAX_UINTN
, PartHdr
->SizeOfPartitionEntry
)) {
520 CopyMem (PartHeader
, PartHdr
, sizeof (EFI_PARTITION_TABLE_HEADER
));
521 if (!PartitionCheckGptEntryArrayCRC (BlockIo
, DiskIo
, PartHeader
)) {
526 DEBUG ((EFI_D_INFO
, " Valid efi partition table header\n"));
532 Check if the CRC field in the Partition table header is valid
533 for Partition entry array.
535 @param[in] BlockIo Parent BlockIo interface
536 @param[in] DiskIo Disk Io Protocol.
537 @param[in] PartHeader Partition table header structure
539 @retval TRUE the CRC is valid
540 @retval FALSE the CRC is invalid
544 PartitionCheckGptEntryArrayCRC (
545 IN EFI_BLOCK_IO_PROTOCOL
*BlockIo
,
546 IN EFI_DISK_IO_PROTOCOL
*DiskIo
,
547 IN EFI_PARTITION_TABLE_HEADER
*PartHeader
556 // Read the EFI Partition Entries
558 Ptr
= AllocatePool (PartHeader
->NumberOfPartitionEntries
* PartHeader
->SizeOfPartitionEntry
);
560 DEBUG ((EFI_D_ERROR
, " Allocate pool error\n"));
564 Status
= DiskIo
->ReadDisk (
566 BlockIo
->Media
->MediaId
,
567 MultU64x32(PartHeader
->PartitionEntryLBA
, BlockIo
->Media
->BlockSize
),
568 PartHeader
->NumberOfPartitionEntries
* PartHeader
->SizeOfPartitionEntry
,
571 if (EFI_ERROR (Status
)) {
576 Size
= PartHeader
->NumberOfPartitionEntries
* PartHeader
->SizeOfPartitionEntry
;
578 Status
= gBS
->CalculateCrc32 (Ptr
, Size
, &Crc
);
579 if (EFI_ERROR (Status
)) {
580 DEBUG ((EFI_D_ERROR
, "CheckPEntryArrayCRC: Crc calculation failed\n"));
587 return (BOOLEAN
) (PartHeader
->PartitionEntryArrayCRC32
== Crc
);
592 Restore Partition Table to its alternate place
593 (Primary -> Backup or Backup -> Primary).
595 @param[in] BlockIo Parent BlockIo interface.
596 @param[in] DiskIo Disk Io Protocol.
597 @param[in] PartHeader Partition table header structure.
599 @retval TRUE Restoring succeeds
600 @retval FALSE Restoring failed
604 PartitionRestoreGptTable (
605 IN EFI_BLOCK_IO_PROTOCOL
*BlockIo
,
606 IN EFI_DISK_IO_PROTOCOL
*DiskIo
,
607 IN EFI_PARTITION_TABLE_HEADER
*PartHeader
612 EFI_PARTITION_TABLE_HEADER
*PartHdr
;
620 BlockSize
= BlockIo
->Media
->BlockSize
;
621 MediaId
= BlockIo
->Media
->MediaId
;
623 PartHdr
= AllocateZeroPool (BlockSize
);
625 if (PartHdr
== NULL
) {
626 DEBUG ((EFI_D_ERROR
, "Allocate pool error\n"));
630 PEntryLBA
= (PartHeader
->MyLBA
== PRIMARY_PART_HEADER_LBA
) ? \
631 (PartHeader
->LastUsableLBA
+ 1) : \
632 (PRIMARY_PART_HEADER_LBA
+ 1);
634 CopyMem (PartHdr
, PartHeader
, sizeof (EFI_PARTITION_TABLE_HEADER
));
636 PartHdr
->MyLBA
= PartHeader
->AlternateLBA
;
637 PartHdr
->AlternateLBA
= PartHeader
->MyLBA
;
638 PartHdr
->PartitionEntryLBA
= PEntryLBA
;
639 PartitionSetCrc ((EFI_TABLE_HEADER
*) PartHdr
);
641 Status
= DiskIo
->WriteDisk (
644 MultU64x32 (PartHdr
->MyLBA
, (UINT32
) BlockSize
),
648 if (EFI_ERROR (Status
)) {
652 Ptr
= AllocatePool (PartHeader
->NumberOfPartitionEntries
* PartHeader
->SizeOfPartitionEntry
);
654 DEBUG ((EFI_D_ERROR
, " Allocate pool error\n"));
655 Status
= EFI_OUT_OF_RESOURCES
;
659 Status
= DiskIo
->ReadDisk (
662 MultU64x32(PartHeader
->PartitionEntryLBA
, (UINT32
) BlockSize
),
663 PartHeader
->NumberOfPartitionEntries
* PartHeader
->SizeOfPartitionEntry
,
666 if (EFI_ERROR (Status
)) {
670 Status
= DiskIo
->WriteDisk (
673 MultU64x32(PEntryLBA
, (UINT32
) BlockSize
),
674 PartHeader
->NumberOfPartitionEntries
* PartHeader
->SizeOfPartitionEntry
,
685 if (EFI_ERROR (Status
)) {
693 This routine will check GPT partition entry and return entry status.
695 Caution: This function may receive untrusted input.
696 The GPT partition entry is external input, so this routine
697 will do basic validation for GPT partition entry and report status.
699 @param[in] PartHeader Partition table header structure
700 @param[in] PartEntry The partition entry array
701 @param[out] PEntryStatus the partition entry status array
702 recording the status of each partition
706 PartitionCheckGptEntry (
707 IN EFI_PARTITION_TABLE_HEADER
*PartHeader
,
708 IN EFI_PARTITION_ENTRY
*PartEntry
,
709 OUT EFI_PARTITION_ENTRY_STATUS
*PEntryStatus
714 EFI_PARTITION_ENTRY
*Entry
;
718 DEBUG ((EFI_D_INFO
, " start check partition entries\n"));
719 for (Index1
= 0; Index1
< PartHeader
->NumberOfPartitionEntries
; Index1
++) {
720 Entry
= (EFI_PARTITION_ENTRY
*) ((UINT8
*) PartEntry
+ Index1
* PartHeader
->SizeOfPartitionEntry
);
721 if (CompareGuid (&Entry
->PartitionTypeGUID
, &gEfiPartTypeUnusedGuid
)) {
725 StartingLBA
= Entry
->StartingLBA
;
726 EndingLBA
= Entry
->EndingLBA
;
727 if (StartingLBA
> EndingLBA
||
728 StartingLBA
< PartHeader
->FirstUsableLBA
||
729 StartingLBA
> PartHeader
->LastUsableLBA
||
730 EndingLBA
< PartHeader
->FirstUsableLBA
||
731 EndingLBA
> PartHeader
->LastUsableLBA
733 PEntryStatus
[Index1
].OutOfRange
= TRUE
;
737 if ((Entry
->Attributes
& BIT1
) != 0) {
739 // If Bit 1 is set, this indicate that this is an OS specific GUID partition.
741 PEntryStatus
[Index1
].OsSpecific
= TRUE
;
744 for (Index2
= Index1
+ 1; Index2
< PartHeader
->NumberOfPartitionEntries
; Index2
++) {
745 Entry
= (EFI_PARTITION_ENTRY
*) ((UINT8
*) PartEntry
+ Index2
* PartHeader
->SizeOfPartitionEntry
);
746 if (CompareGuid (&Entry
->PartitionTypeGUID
, &gEfiPartTypeUnusedGuid
)) {
750 if (Entry
->EndingLBA
>= StartingLBA
&& Entry
->StartingLBA
<= EndingLBA
) {
752 // This region overlaps with the Index1'th region
754 PEntryStatus
[Index1
].Overlap
= TRUE
;
755 PEntryStatus
[Index2
].Overlap
= TRUE
;
761 DEBUG ((EFI_D_INFO
, " End check partition entries\n"));
766 Updates the CRC32 value in the table header.
768 @param Hdr Table to update
773 IN OUT EFI_TABLE_HEADER
*Hdr
776 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
);
802 Checks the CRC32 value in the table header.
804 @param MaxSize Max Size limit
805 @param Hdr Table to check
807 @return TRUE CRC Valid
808 @return FALSE CRC Invalid
814 IN OUT EFI_TABLE_HEADER
*Hdr
817 return PartitionCheckCrcAltSize (MaxSize
, Hdr
->HeaderSize
, Hdr
);
822 Checks the CRC32 value in the table header.
824 @param MaxSize Max Size limit
825 @param Size The size of the table
826 @param Hdr Table to check
828 @return TRUE CRC Valid
829 @return FALSE CRC Invalid
833 PartitionCheckCrcAltSize (
836 IN OUT EFI_TABLE_HEADER
*Hdr
847 // If header size is 0 CRC will pass so return FALSE here
852 if ((MaxSize
!= 0) && (Size
> MaxSize
)) {
853 DEBUG ((EFI_D_ERROR
, "CheckCrc32: Size > MaxSize\n"));
857 // clear old crc from header
862 Status
= gBS
->CalculateCrc32 ((UINT8
*) Hdr
, Size
, &Crc
);
863 if (EFI_ERROR (Status
)) {
864 DEBUG ((EFI_D_ERROR
, "CheckCrc32: Crc calculation failed\n"));
877 DEBUG ((EFI_D_ERROR
, "CheckCrc32: Crc check failed\n"));
881 return (BOOLEAN
) (OrgCrc
== Crc
);