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
].BootIndicator
== 0x00 &&
268 ProtectiveMbr
->Partition
[Index
].OSIndicator
== PMBR_GPT_PARTITION
&&
269 UNPACK_UINT32 (ProtectiveMbr
->Partition
[Index
].StartingLBA
) == 1
274 if (Index
== MAX_MBR_PARTITIONS
) {
279 // Allocate the GPT structures
281 PrimaryHeader
= AllocateZeroPool (sizeof (EFI_PARTITION_TABLE_HEADER
));
282 if (PrimaryHeader
== NULL
) {
286 BackupHeader
= AllocateZeroPool (sizeof (EFI_PARTITION_TABLE_HEADER
));
287 if (BackupHeader
== NULL
) {
292 // Check primary and backup partition tables
294 if (!PartitionValidGptTable (BlockIo
, DiskIo
, PRIMARY_PART_HEADER_LBA
, PrimaryHeader
)) {
295 DEBUG ((EFI_D_INFO
, " Not Valid primary partition table\n"));
297 if (!PartitionValidGptTable (BlockIo
, DiskIo
, LastBlock
, BackupHeader
)) {
298 DEBUG ((EFI_D_INFO
, " Not Valid backup partition table\n"));
301 DEBUG ((EFI_D_INFO
, " Valid backup partition table\n"));
302 DEBUG ((EFI_D_INFO
, " Restore primary partition table by the backup\n"));
303 if (!PartitionRestoreGptTable (BlockIo
, DiskIo
, BackupHeader
)) {
304 DEBUG ((EFI_D_INFO
, " Restore primary partition table error\n"));
307 if (PartitionValidGptTable (BlockIo
, DiskIo
, BackupHeader
->AlternateLBA
, PrimaryHeader
)) {
308 DEBUG ((EFI_D_INFO
, " Restore backup partition table success\n"));
311 } else if (!PartitionValidGptTable (BlockIo
, DiskIo
, PrimaryHeader
->AlternateLBA
, BackupHeader
)) {
312 DEBUG ((EFI_D_INFO
, " Valid primary and !Valid backup partition table\n"));
313 DEBUG ((EFI_D_INFO
, " Restore backup partition table by the primary\n"));
314 if (!PartitionRestoreGptTable (BlockIo
, DiskIo
, PrimaryHeader
)) {
315 DEBUG ((EFI_D_INFO
, " Restore backup partition table error\n"));
318 if (PartitionValidGptTable (BlockIo
, DiskIo
, PrimaryHeader
->AlternateLBA
, BackupHeader
)) {
319 DEBUG ((EFI_D_INFO
, " Restore backup partition table success\n"));
324 DEBUG ((EFI_D_INFO
, " Valid primary and Valid backup partition table\n"));
327 // Read the EFI Partition Entries
329 PartEntry
= AllocatePool (PrimaryHeader
->NumberOfPartitionEntries
* PrimaryHeader
->SizeOfPartitionEntry
);
330 if (PartEntry
== NULL
) {
331 DEBUG ((EFI_D_ERROR
, "Allocate pool error\n"));
335 Status
= DiskIo
->ReadDisk (
338 MultU64x32(PrimaryHeader
->PartitionEntryLBA
, BlockSize
),
339 PrimaryHeader
->NumberOfPartitionEntries
* (PrimaryHeader
->SizeOfPartitionEntry
),
342 if (EFI_ERROR (Status
)) {
343 GptValidStatus
= Status
;
344 DEBUG ((EFI_D_ERROR
, " Partition Entry ReadDisk error\n"));
348 DEBUG ((EFI_D_INFO
, " Partition entries read block success\n"));
350 DEBUG ((EFI_D_INFO
, " Number of partition entries: %d\n", PrimaryHeader
->NumberOfPartitionEntries
));
352 PEntryStatus
= AllocateZeroPool (PrimaryHeader
->NumberOfPartitionEntries
* sizeof (EFI_PARTITION_ENTRY_STATUS
));
353 if (PEntryStatus
== NULL
) {
354 DEBUG ((EFI_D_ERROR
, "Allocate pool error\n"));
359 // Check the integrity of partition entries
361 PartitionCheckGptEntry (PrimaryHeader
, PartEntry
, PEntryStatus
);
364 // If we got this far the GPT layout of the disk is valid and we should return true
366 GptValidStatus
= EFI_SUCCESS
;
369 // Create child device handles
371 for (Index
= 0; Index
< PrimaryHeader
->NumberOfPartitionEntries
; Index
++) {
372 Entry
= (EFI_PARTITION_ENTRY
*) ((UINT8
*) PartEntry
+ Index
* PrimaryHeader
->SizeOfPartitionEntry
);
373 if (CompareGuid (&Entry
->PartitionTypeGUID
, &gEfiPartTypeUnusedGuid
) ||
374 PEntryStatus
[Index
].OutOfRange
||
375 PEntryStatus
[Index
].Overlap
||
376 PEntryStatus
[Index
].OsSpecific
379 // Don't use null EFI Partition Entries, Invalid Partition Entries or OS specific
385 ZeroMem (&HdDev
, sizeof (HdDev
));
386 HdDev
.Header
.Type
= MEDIA_DEVICE_PATH
;
387 HdDev
.Header
.SubType
= MEDIA_HARDDRIVE_DP
;
388 SetDevicePathNodeLength (&HdDev
.Header
, sizeof (HdDev
));
390 HdDev
.PartitionNumber
= (UINT32
) Index
+ 1;
391 HdDev
.MBRType
= MBR_TYPE_EFI_PARTITION_TABLE_HEADER
;
392 HdDev
.SignatureType
= SIGNATURE_TYPE_GUID
;
393 HdDev
.PartitionStart
= Entry
->StartingLBA
;
394 HdDev
.PartitionSize
= Entry
->EndingLBA
- Entry
->StartingLBA
+ 1;
395 CopyMem (HdDev
.Signature
, &Entry
->UniquePartitionGUID
, sizeof (EFI_GUID
));
397 ZeroMem (&PartitionInfo
, sizeof (EFI_PARTITION_INFO_PROTOCOL
));
398 PartitionInfo
.Revision
= EFI_PARTITION_INFO_PROTOCOL_REVISION
;
399 PartitionInfo
.Type
= PARTITION_TYPE_GPT
;
400 if (CompareGuid (&Entry
->PartitionTypeGUID
, &gEfiPartTypeSystemPartGuid
)) {
401 PartitionInfo
.System
= 1;
403 CopyMem (&PartitionInfo
.Info
.Gpt
, Entry
, sizeof (EFI_PARTITION_ENTRY
));
405 DEBUG ((EFI_D_INFO
, " Index : %d\n", (UINT32
) Index
));
406 DEBUG ((EFI_D_INFO
, " Start LBA : %lx\n", (UINT64
) HdDev
.PartitionStart
));
407 DEBUG ((EFI_D_INFO
, " End LBA : %lx\n", (UINT64
) Entry
->EndingLBA
));
408 DEBUG ((EFI_D_INFO
, " Partition size: %lx\n", (UINT64
) HdDev
.PartitionSize
));
409 DEBUG ((EFI_D_INFO
, " Start : %lx", MultU64x32 (Entry
->StartingLBA
, BlockSize
)));
410 DEBUG ((EFI_D_INFO
, " End : %lx\n", MultU64x32 (Entry
->EndingLBA
, BlockSize
)));
412 Status
= PartitionInstallChildHandle (
420 (EFI_DEVICE_PATH_PROTOCOL
*) &HdDev
,
425 &Entry
->PartitionTypeGUID
429 DEBUG ((EFI_D_INFO
, "Prepare to Free Pool\n"));
432 if (ProtectiveMbr
!= NULL
) {
433 FreePool (ProtectiveMbr
);
435 if (PrimaryHeader
!= NULL
) {
436 FreePool (PrimaryHeader
);
438 if (BackupHeader
!= NULL
) {
439 FreePool (BackupHeader
);
441 if (PartEntry
!= NULL
) {
442 FreePool (PartEntry
);
444 if (PEntryStatus
!= NULL
) {
445 FreePool (PEntryStatus
);
448 return GptValidStatus
;
452 This routine will read GPT partition table header and return it.
454 Caution: This function may receive untrusted input.
455 The GPT partition table header is external input, so this routine
456 will do basic validation for GPT partition table header before return.
458 @param[in] BlockIo Parent BlockIo interface.
459 @param[in] DiskIo Disk Io protocol.
460 @param[in] Lba The starting Lba of the Partition Table
461 @param[out] PartHeader Stores the partition table that is read
463 @retval TRUE The partition table is valid
464 @retval FALSE The partition table is not valid
468 PartitionValidGptTable (
469 IN EFI_BLOCK_IO_PROTOCOL
*BlockIo
,
470 IN EFI_DISK_IO_PROTOCOL
*DiskIo
,
472 OUT EFI_PARTITION_TABLE_HEADER
*PartHeader
477 EFI_PARTITION_TABLE_HEADER
*PartHdr
;
480 BlockSize
= BlockIo
->Media
->BlockSize
;
481 MediaId
= BlockIo
->Media
->MediaId
;
482 PartHdr
= AllocateZeroPool (BlockSize
);
484 if (PartHdr
== NULL
) {
485 DEBUG ((EFI_D_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
))
508 DEBUG ((EFI_D_INFO
, "Invalid efi partition table header\n"));
514 // Ensure the NumberOfPartitionEntries * SizeOfPartitionEntry doesn't overflow.
516 if (PartHdr
->NumberOfPartitionEntries
> DivU64x32 (MAX_UINTN
, PartHdr
->SizeOfPartitionEntry
)) {
521 CopyMem (PartHeader
, PartHdr
, sizeof (EFI_PARTITION_TABLE_HEADER
));
522 if (!PartitionCheckGptEntryArrayCRC (BlockIo
, DiskIo
, PartHeader
)) {
527 DEBUG ((EFI_D_INFO
, " Valid efi partition table header\n"));
533 Check if the CRC field in the Partition table header is valid
534 for Partition entry array.
536 @param[in] BlockIo Parent BlockIo interface
537 @param[in] DiskIo Disk Io Protocol.
538 @param[in] PartHeader Partition table header structure
540 @retval TRUE the CRC is valid
541 @retval FALSE the CRC is invalid
545 PartitionCheckGptEntryArrayCRC (
546 IN EFI_BLOCK_IO_PROTOCOL
*BlockIo
,
547 IN EFI_DISK_IO_PROTOCOL
*DiskIo
,
548 IN EFI_PARTITION_TABLE_HEADER
*PartHeader
557 // Read the EFI Partition Entries
559 Ptr
= AllocatePool (PartHeader
->NumberOfPartitionEntries
* PartHeader
->SizeOfPartitionEntry
);
561 DEBUG ((EFI_D_ERROR
, " Allocate pool error\n"));
565 Status
= DiskIo
->ReadDisk (
567 BlockIo
->Media
->MediaId
,
568 MultU64x32(PartHeader
->PartitionEntryLBA
, BlockIo
->Media
->BlockSize
),
569 PartHeader
->NumberOfPartitionEntries
* PartHeader
->SizeOfPartitionEntry
,
572 if (EFI_ERROR (Status
)) {
577 Size
= PartHeader
->NumberOfPartitionEntries
* PartHeader
->SizeOfPartitionEntry
;
579 Status
= gBS
->CalculateCrc32 (Ptr
, Size
, &Crc
);
580 if (EFI_ERROR (Status
)) {
581 DEBUG ((EFI_D_ERROR
, "CheckPEntryArrayCRC: Crc calculation failed\n"));
588 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 ((EFI_D_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 ((EFI_D_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 ((EFI_D_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
734 PEntryStatus
[Index1
].OutOfRange
= TRUE
;
738 if ((Entry
->Attributes
& BIT1
) != 0) {
740 // If Bit 1 is set, this indicate that this is an OS specific GUID partition.
742 PEntryStatus
[Index1
].OsSpecific
= TRUE
;
745 for (Index2
= Index1
+ 1; Index2
< PartHeader
->NumberOfPartitionEntries
; Index2
++) {
746 Entry
= (EFI_PARTITION_ENTRY
*) ((UINT8
*) PartEntry
+ Index2
* PartHeader
->SizeOfPartitionEntry
);
747 if (CompareGuid (&Entry
->PartitionTypeGUID
, &gEfiPartTypeUnusedGuid
)) {
751 if (Entry
->EndingLBA
>= StartingLBA
&& Entry
->StartingLBA
<= EndingLBA
) {
753 // This region overlaps with the Index1'th region
755 PEntryStatus
[Index1
].Overlap
= TRUE
;
756 PEntryStatus
[Index2
].Overlap
= TRUE
;
762 DEBUG ((EFI_D_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
);
782 Updates the CRC32 value in the table header.
784 @param Size The size of the table
785 @param Hdr Table to update
789 PartitionSetCrcAltSize (
791 IN OUT EFI_TABLE_HEADER
*Hdr
797 gBS
->CalculateCrc32 ((UINT8
*) Hdr
, Size
, &Crc
);
803 Checks the CRC32 value in the table header.
805 @param MaxSize Max Size limit
806 @param Hdr Table to check
808 @return TRUE CRC Valid
809 @return FALSE CRC Invalid
815 IN OUT EFI_TABLE_HEADER
*Hdr
818 return PartitionCheckCrcAltSize (MaxSize
, Hdr
->HeaderSize
, Hdr
);
823 Checks the CRC32 value in the table header.
825 @param MaxSize Max Size limit
826 @param Size The size of the table
827 @param Hdr Table to check
829 @return TRUE CRC Valid
830 @return FALSE CRC Invalid
834 PartitionCheckCrcAltSize (
837 IN OUT EFI_TABLE_HEADER
*Hdr
848 // If header size is 0 CRC will pass so return FALSE here
853 if ((MaxSize
!= 0) && (Size
> MaxSize
)) {
854 DEBUG ((EFI_D_ERROR
, "CheckCrc32: Size > MaxSize\n"));
858 // clear old crc from header
863 Status
= gBS
->CalculateCrc32 ((UINT8
*) Hdr
, Size
, &Crc
);
864 if (EFI_ERROR (Status
)) {
865 DEBUG ((EFI_D_ERROR
, "CheckCrc32: Crc calculation failed\n"));
878 DEBUG ((EFI_D_ERROR
, "CheckCrc32: Crc check failed\n"));
882 return (BOOLEAN
) (OrgCrc
== Crc
);