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) 2006 - 2017, Intel Corporation. All rights reserved.<BR>
17 This program and the accompanying materials
18 are licensed and made available under the terms and conditions of the BSD License
19 which accompanies this distribution. The full text of the license may be found at
20 http://opensource.org/licenses/bsd-license.php
22 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
23 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
28 #include "Partition.h"
31 Install child handles if the Handle supports GPT partition structure.
33 Caution: This function may receive untrusted input.
34 The GPT partition table header is external input, so this routine
35 will do basic validation for GPT partition table header before return.
37 @param[in] BlockIo Parent BlockIo interface.
38 @param[in] DiskIo Disk Io protocol.
39 @param[in] Lba The starting Lba of the Partition Table
40 @param[out] PartHeader Stores the partition table that is read
42 @retval TRUE The partition table is valid
43 @retval FALSE The partition table is not valid
47 PartitionValidGptTable (
48 IN EFI_BLOCK_IO_PROTOCOL
*BlockIo
,
49 IN EFI_DISK_IO_PROTOCOL
*DiskIo
,
51 OUT EFI_PARTITION_TABLE_HEADER
*PartHeader
55 Check if the CRC field in the Partition table header is valid
56 for Partition entry array.
58 @param[in] BlockIo Parent BlockIo interface
59 @param[in] DiskIo Disk Io Protocol.
60 @param[in] PartHeader Partition table header structure
62 @retval TRUE the CRC is valid
63 @retval FALSE the CRC is invalid
67 PartitionCheckGptEntryArrayCRC (
68 IN EFI_BLOCK_IO_PROTOCOL
*BlockIo
,
69 IN EFI_DISK_IO_PROTOCOL
*DiskIo
,
70 IN EFI_PARTITION_TABLE_HEADER
*PartHeader
75 Restore Partition Table to its alternate place
76 (Primary -> Backup or Backup -> Primary).
78 @param[in] BlockIo Parent BlockIo interface.
79 @param[in] DiskIo Disk Io Protocol.
80 @param[in] PartHeader Partition table header structure.
82 @retval TRUE Restoring succeeds
83 @retval FALSE Restoring failed
87 PartitionRestoreGptTable (
88 IN EFI_BLOCK_IO_PROTOCOL
*BlockIo
,
89 IN EFI_DISK_IO_PROTOCOL
*DiskIo
,
90 IN EFI_PARTITION_TABLE_HEADER
*PartHeader
95 This routine will check GPT partition entry and return entry status.
97 Caution: This function may receive untrusted input.
98 The GPT partition entry is external input, so this routine
99 will do basic validation for GPT partition entry and report status.
101 @param[in] PartHeader Partition table header structure
102 @param[in] PartEntry The partition entry array
103 @param[out] PEntryStatus the partition entry status array
104 recording the status of each partition
108 PartitionCheckGptEntry (
109 IN EFI_PARTITION_TABLE_HEADER
*PartHeader
,
110 IN EFI_PARTITION_ENTRY
*PartEntry
,
111 OUT EFI_PARTITION_ENTRY_STATUS
*PEntryStatus
116 Checks the CRC32 value in the table header.
118 @param MaxSize Max Size limit
119 @param Size The size of the table
120 @param Hdr Table to check
122 @return TRUE CRC Valid
123 @return FALSE CRC Invalid
127 PartitionCheckCrcAltSize (
130 IN OUT EFI_TABLE_HEADER
*Hdr
135 Checks the CRC32 value in the table header.
137 @param MaxSize Max Size limit
138 @param Hdr Table to check
140 @return TRUE CRC Valid
141 @return FALSE CRC Invalid
147 IN OUT EFI_TABLE_HEADER
*Hdr
152 Updates the CRC32 value in the table header.
154 @param Size The size of the table
155 @param Hdr Table to update
159 PartitionSetCrcAltSize (
161 IN OUT EFI_TABLE_HEADER
*Hdr
166 Updates the CRC32 value in the table header.
168 @param Hdr Table to update
173 IN OUT EFI_TABLE_HEADER
*Hdr
177 Install child handles if the Handle supports GPT partition structure.
179 Caution: This function may receive untrusted input.
180 The GPT partition table is external input, so this routine
181 will do basic validation for GPT partition table before install
182 child handle for each GPT partition.
184 @param[in] This Calling context.
185 @param[in] Handle Parent Handle.
186 @param[in] DiskIo Parent DiskIo interface.
187 @param[in] DiskIo2 Parent DiskIo2 interface.
188 @param[in] BlockIo Parent BlockIo interface.
189 @param[in] BlockIo2 Parent BlockIo2 interface.
190 @param[in] DevicePath Parent Device Path.
192 @retval EFI_SUCCESS Valid GPT disk.
193 @retval EFI_MEDIA_CHANGED Media changed Detected.
194 @retval other Not a valid GPT disk.
198 PartitionInstallGptChildHandles (
199 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
200 IN EFI_HANDLE Handle
,
201 IN EFI_DISK_IO_PROTOCOL
*DiskIo
,
202 IN EFI_DISK_IO2_PROTOCOL
*DiskIo2
,
203 IN EFI_BLOCK_IO_PROTOCOL
*BlockIo
,
204 IN EFI_BLOCK_IO2_PROTOCOL
*BlockIo2
,
205 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePath
211 MASTER_BOOT_RECORD
*ProtectiveMbr
;
212 EFI_PARTITION_TABLE_HEADER
*PrimaryHeader
;
213 EFI_PARTITION_TABLE_HEADER
*BackupHeader
;
214 EFI_PARTITION_ENTRY
*PartEntry
;
215 EFI_PARTITION_ENTRY
*Entry
;
216 EFI_PARTITION_ENTRY_STATUS
*PEntryStatus
;
218 EFI_STATUS GptValidStatus
;
219 HARDDRIVE_DEVICE_PATH HdDev
;
221 EFI_PARTITION_INFO_PROTOCOL PartitionInfo
;
223 ProtectiveMbr
= NULL
;
224 PrimaryHeader
= NULL
;
229 BlockSize
= BlockIo
->Media
->BlockSize
;
230 LastBlock
= BlockIo
->Media
->LastBlock
;
231 MediaId
= BlockIo
->Media
->MediaId
;
233 DEBUG ((EFI_D_INFO
, " BlockSize : %d \n", BlockSize
));
234 DEBUG ((EFI_D_INFO
, " LastBlock : %lx \n", LastBlock
));
236 GptValidStatus
= EFI_NOT_FOUND
;
239 // Allocate a buffer for the Protective MBR
241 ProtectiveMbr
= AllocatePool (BlockSize
);
242 if (ProtectiveMbr
== NULL
) {
243 return EFI_NOT_FOUND
;
247 // Read the Protective MBR from LBA #0
249 Status
= DiskIo
->ReadDisk (
256 if (EFI_ERROR (Status
)) {
257 GptValidStatus
= Status
;
262 // Verify that the Protective MBR is valid
264 for (Index
= 0; Index
< MAX_MBR_PARTITIONS
; Index
++) {
265 if (ProtectiveMbr
->Partition
[Index
].BootIndicator
== 0x00 &&
266 ProtectiveMbr
->Partition
[Index
].OSIndicator
== PMBR_GPT_PARTITION
&&
267 UNPACK_UINT32 (ProtectiveMbr
->Partition
[Index
].StartingLBA
) == 1
272 if (Index
== MAX_MBR_PARTITIONS
) {
277 // Allocate the GPT structures
279 PrimaryHeader
= AllocateZeroPool (sizeof (EFI_PARTITION_TABLE_HEADER
));
280 if (PrimaryHeader
== NULL
) {
284 BackupHeader
= AllocateZeroPool (sizeof (EFI_PARTITION_TABLE_HEADER
));
285 if (BackupHeader
== NULL
) {
290 // Check primary and backup partition tables
292 if (!PartitionValidGptTable (BlockIo
, DiskIo
, PRIMARY_PART_HEADER_LBA
, PrimaryHeader
)) {
293 DEBUG ((EFI_D_INFO
, " Not Valid primary partition table\n"));
295 if (!PartitionValidGptTable (BlockIo
, DiskIo
, LastBlock
, BackupHeader
)) {
296 DEBUG ((EFI_D_INFO
, " Not Valid backup partition table\n"));
299 DEBUG ((EFI_D_INFO
, " Valid backup partition table\n"));
300 DEBUG ((EFI_D_INFO
, " Restore primary partition table by the backup\n"));
301 if (!PartitionRestoreGptTable (BlockIo
, DiskIo
, BackupHeader
)) {
302 DEBUG ((EFI_D_INFO
, " Restore primary partition table error\n"));
305 if (PartitionValidGptTable (BlockIo
, DiskIo
, BackupHeader
->AlternateLBA
, PrimaryHeader
)) {
306 DEBUG ((EFI_D_INFO
, " Restore backup partition table success\n"));
309 } else if (!PartitionValidGptTable (BlockIo
, DiskIo
, PrimaryHeader
->AlternateLBA
, BackupHeader
)) {
310 DEBUG ((EFI_D_INFO
, " Valid primary and !Valid backup partition table\n"));
311 DEBUG ((EFI_D_INFO
, " Restore backup partition table by the primary\n"));
312 if (!PartitionRestoreGptTable (BlockIo
, DiskIo
, PrimaryHeader
)) {
313 DEBUG ((EFI_D_INFO
, " Restore backup partition table error\n"));
316 if (PartitionValidGptTable (BlockIo
, DiskIo
, PrimaryHeader
->AlternateLBA
, BackupHeader
)) {
317 DEBUG ((EFI_D_INFO
, " Restore backup partition table success\n"));
322 DEBUG ((EFI_D_INFO
, " Valid primary and Valid backup partition table\n"));
325 // Read the EFI Partition Entries
327 PartEntry
= AllocatePool (PrimaryHeader
->NumberOfPartitionEntries
* PrimaryHeader
->SizeOfPartitionEntry
);
328 if (PartEntry
== NULL
) {
329 DEBUG ((EFI_D_ERROR
, "Allocate pool error\n"));
333 Status
= DiskIo
->ReadDisk (
336 MultU64x32(PrimaryHeader
->PartitionEntryLBA
, BlockSize
),
337 PrimaryHeader
->NumberOfPartitionEntries
* (PrimaryHeader
->SizeOfPartitionEntry
),
340 if (EFI_ERROR (Status
)) {
341 GptValidStatus
= Status
;
342 DEBUG ((EFI_D_ERROR
, " Partition Entry ReadDisk error\n"));
346 DEBUG ((EFI_D_INFO
, " Partition entries read block success\n"));
348 DEBUG ((EFI_D_INFO
, " Number of partition entries: %d\n", PrimaryHeader
->NumberOfPartitionEntries
));
350 PEntryStatus
= AllocateZeroPool (PrimaryHeader
->NumberOfPartitionEntries
* sizeof (EFI_PARTITION_ENTRY_STATUS
));
351 if (PEntryStatus
== NULL
) {
352 DEBUG ((EFI_D_ERROR
, "Allocate pool error\n"));
357 // Check the integrity of partition entries
359 PartitionCheckGptEntry (PrimaryHeader
, PartEntry
, PEntryStatus
);
362 // If we got this far the GPT layout of the disk is valid and we should return true
364 GptValidStatus
= EFI_SUCCESS
;
367 // Create child device handles
369 for (Index
= 0; Index
< PrimaryHeader
->NumberOfPartitionEntries
; Index
++) {
370 Entry
= (EFI_PARTITION_ENTRY
*) ((UINT8
*) PartEntry
+ Index
* PrimaryHeader
->SizeOfPartitionEntry
);
371 if (CompareGuid (&Entry
->PartitionTypeGUID
, &gEfiPartTypeUnusedGuid
) ||
372 PEntryStatus
[Index
].OutOfRange
||
373 PEntryStatus
[Index
].Overlap
||
374 PEntryStatus
[Index
].OsSpecific
377 // Don't use null EFI Partition Entries, Invalid Partition Entries or OS specific
383 ZeroMem (&HdDev
, sizeof (HdDev
));
384 HdDev
.Header
.Type
= MEDIA_DEVICE_PATH
;
385 HdDev
.Header
.SubType
= MEDIA_HARDDRIVE_DP
;
386 SetDevicePathNodeLength (&HdDev
.Header
, sizeof (HdDev
));
388 HdDev
.PartitionNumber
= (UINT32
) Index
+ 1;
389 HdDev
.MBRType
= MBR_TYPE_EFI_PARTITION_TABLE_HEADER
;
390 HdDev
.SignatureType
= SIGNATURE_TYPE_GUID
;
391 HdDev
.PartitionStart
= Entry
->StartingLBA
;
392 HdDev
.PartitionSize
= Entry
->EndingLBA
- Entry
->StartingLBA
+ 1;
393 CopyMem (HdDev
.Signature
, &Entry
->UniquePartitionGUID
, sizeof (EFI_GUID
));
395 ZeroMem (&PartitionInfo
, sizeof (EFI_PARTITION_INFO_PROTOCOL
));
396 PartitionInfo
.Revision
= EFI_PARTITION_INFO_PROTOCOL_REVISION
;
397 PartitionInfo
.Type
= PARTITION_TYPE_GPT
;
398 if (CompareGuid (&Entry
->PartitionTypeGUID
, &gEfiPartTypeSystemPartGuid
)) {
399 PartitionInfo
.System
= 1;
401 CopyMem (&PartitionInfo
.Info
.Gpt
, Entry
, sizeof (EFI_PARTITION_ENTRY
));
403 DEBUG ((EFI_D_INFO
, " Index : %d\n", (UINT32
) Index
));
404 DEBUG ((EFI_D_INFO
, " Start LBA : %lx\n", (UINT64
) HdDev
.PartitionStart
));
405 DEBUG ((EFI_D_INFO
, " End LBA : %lx\n", (UINT64
) Entry
->EndingLBA
));
406 DEBUG ((EFI_D_INFO
, " Partition size: %lx\n", (UINT64
) HdDev
.PartitionSize
));
407 DEBUG ((EFI_D_INFO
, " Start : %lx", MultU64x32 (Entry
->StartingLBA
, BlockSize
)));
408 DEBUG ((EFI_D_INFO
, " End : %lx\n", MultU64x32 (Entry
->EndingLBA
, BlockSize
)));
410 Status
= PartitionInstallChildHandle (
418 (EFI_DEVICE_PATH_PROTOCOL
*) &HdDev
,
426 DEBUG ((EFI_D_INFO
, "Prepare to Free Pool\n"));
429 if (ProtectiveMbr
!= NULL
) {
430 FreePool (ProtectiveMbr
);
432 if (PrimaryHeader
!= NULL
) {
433 FreePool (PrimaryHeader
);
435 if (BackupHeader
!= NULL
) {
436 FreePool (BackupHeader
);
438 if (PartEntry
!= NULL
) {
439 FreePool (PartEntry
);
441 if (PEntryStatus
!= NULL
) {
442 FreePool (PEntryStatus
);
445 return GptValidStatus
;
449 This routine will read GPT partition table header and return it.
451 Caution: This function may receive untrusted input.
452 The GPT partition table header is external input, so this routine
453 will do basic validation for GPT partition table header before return.
455 @param[in] BlockIo Parent BlockIo interface.
456 @param[in] DiskIo Disk Io protocol.
457 @param[in] Lba The starting Lba of the Partition Table
458 @param[out] PartHeader Stores the partition table that is read
460 @retval TRUE The partition table is valid
461 @retval FALSE The partition table is not valid
465 PartitionValidGptTable (
466 IN EFI_BLOCK_IO_PROTOCOL
*BlockIo
,
467 IN EFI_DISK_IO_PROTOCOL
*DiskIo
,
469 OUT EFI_PARTITION_TABLE_HEADER
*PartHeader
474 EFI_PARTITION_TABLE_HEADER
*PartHdr
;
477 BlockSize
= BlockIo
->Media
->BlockSize
;
478 MediaId
= BlockIo
->Media
->MediaId
;
479 PartHdr
= AllocateZeroPool (BlockSize
);
481 if (PartHdr
== NULL
) {
482 DEBUG ((EFI_D_ERROR
, "Allocate pool error\n"));
486 // Read the EFI Partition Table Header
488 Status
= DiskIo
->ReadDisk (
491 MultU64x32 (Lba
, BlockSize
),
495 if (EFI_ERROR (Status
)) {
500 if ((PartHdr
->Header
.Signature
!= EFI_PTAB_HEADER_ID
) ||
501 !PartitionCheckCrc (BlockSize
, &PartHdr
->Header
) ||
502 PartHdr
->MyLBA
!= Lba
||
503 (PartHdr
->SizeOfPartitionEntry
< sizeof (EFI_PARTITION_ENTRY
))
505 DEBUG ((EFI_D_INFO
, "Invalid efi partition table header\n"));
511 // Ensure the NumberOfPartitionEntries * SizeOfPartitionEntry doesn't overflow.
513 if (PartHdr
->NumberOfPartitionEntries
> DivU64x32 (MAX_UINTN
, PartHdr
->SizeOfPartitionEntry
)) {
518 CopyMem (PartHeader
, PartHdr
, sizeof (EFI_PARTITION_TABLE_HEADER
));
519 if (!PartitionCheckGptEntryArrayCRC (BlockIo
, DiskIo
, PartHeader
)) {
524 DEBUG ((EFI_D_INFO
, " Valid efi partition table header\n"));
530 Check if the CRC field in the Partition table header is valid
531 for Partition entry array.
533 @param[in] BlockIo Parent BlockIo interface
534 @param[in] DiskIo Disk Io Protocol.
535 @param[in] PartHeader Partition table header structure
537 @retval TRUE the CRC is valid
538 @retval FALSE the CRC is invalid
542 PartitionCheckGptEntryArrayCRC (
543 IN EFI_BLOCK_IO_PROTOCOL
*BlockIo
,
544 IN EFI_DISK_IO_PROTOCOL
*DiskIo
,
545 IN EFI_PARTITION_TABLE_HEADER
*PartHeader
554 // Read the EFI Partition Entries
556 Ptr
= AllocatePool (PartHeader
->NumberOfPartitionEntries
* PartHeader
->SizeOfPartitionEntry
);
558 DEBUG ((EFI_D_ERROR
, " Allocate pool error\n"));
562 Status
= DiskIo
->ReadDisk (
564 BlockIo
->Media
->MediaId
,
565 MultU64x32(PartHeader
->PartitionEntryLBA
, BlockIo
->Media
->BlockSize
),
566 PartHeader
->NumberOfPartitionEntries
* PartHeader
->SizeOfPartitionEntry
,
569 if (EFI_ERROR (Status
)) {
574 Size
= PartHeader
->NumberOfPartitionEntries
* PartHeader
->SizeOfPartitionEntry
;
576 Status
= gBS
->CalculateCrc32 (Ptr
, Size
, &Crc
);
577 if (EFI_ERROR (Status
)) {
578 DEBUG ((EFI_D_ERROR
, "CheckPEntryArrayCRC: Crc calculation failed\n"));
585 return (BOOLEAN
) (PartHeader
->PartitionEntryArrayCRC32
== Crc
);
590 Restore Partition Table to its alternate place
591 (Primary -> Backup or Backup -> Primary).
593 @param[in] BlockIo Parent BlockIo interface.
594 @param[in] DiskIo Disk Io Protocol.
595 @param[in] PartHeader Partition table header structure.
597 @retval TRUE Restoring succeeds
598 @retval FALSE Restoring failed
602 PartitionRestoreGptTable (
603 IN EFI_BLOCK_IO_PROTOCOL
*BlockIo
,
604 IN EFI_DISK_IO_PROTOCOL
*DiskIo
,
605 IN EFI_PARTITION_TABLE_HEADER
*PartHeader
610 EFI_PARTITION_TABLE_HEADER
*PartHdr
;
618 BlockSize
= BlockIo
->Media
->BlockSize
;
619 MediaId
= BlockIo
->Media
->MediaId
;
621 PartHdr
= AllocateZeroPool (BlockSize
);
623 if (PartHdr
== NULL
) {
624 DEBUG ((EFI_D_ERROR
, "Allocate pool error\n"));
628 PEntryLBA
= (PartHeader
->MyLBA
== PRIMARY_PART_HEADER_LBA
) ? \
629 (PartHeader
->LastUsableLBA
+ 1) : \
630 (PRIMARY_PART_HEADER_LBA
+ 1);
632 CopyMem (PartHdr
, PartHeader
, sizeof (EFI_PARTITION_TABLE_HEADER
));
634 PartHdr
->MyLBA
= PartHeader
->AlternateLBA
;
635 PartHdr
->AlternateLBA
= PartHeader
->MyLBA
;
636 PartHdr
->PartitionEntryLBA
= PEntryLBA
;
637 PartitionSetCrc ((EFI_TABLE_HEADER
*) PartHdr
);
639 Status
= DiskIo
->WriteDisk (
642 MultU64x32 (PartHdr
->MyLBA
, (UINT32
) BlockSize
),
646 if (EFI_ERROR (Status
)) {
650 Ptr
= AllocatePool (PartHeader
->NumberOfPartitionEntries
* PartHeader
->SizeOfPartitionEntry
);
652 DEBUG ((EFI_D_ERROR
, " Allocate pool error\n"));
653 Status
= EFI_OUT_OF_RESOURCES
;
657 Status
= DiskIo
->ReadDisk (
660 MultU64x32(PartHeader
->PartitionEntryLBA
, (UINT32
) BlockSize
),
661 PartHeader
->NumberOfPartitionEntries
* PartHeader
->SizeOfPartitionEntry
,
664 if (EFI_ERROR (Status
)) {
668 Status
= DiskIo
->WriteDisk (
671 MultU64x32(PEntryLBA
, (UINT32
) BlockSize
),
672 PartHeader
->NumberOfPartitionEntries
* PartHeader
->SizeOfPartitionEntry
,
683 if (EFI_ERROR (Status
)) {
691 This routine will check GPT partition entry and return entry status.
693 Caution: This function may receive untrusted input.
694 The GPT partition entry is external input, so this routine
695 will do basic validation for GPT partition entry and report status.
697 @param[in] PartHeader Partition table header structure
698 @param[in] PartEntry The partition entry array
699 @param[out] PEntryStatus the partition entry status array
700 recording the status of each partition
704 PartitionCheckGptEntry (
705 IN EFI_PARTITION_TABLE_HEADER
*PartHeader
,
706 IN EFI_PARTITION_ENTRY
*PartEntry
,
707 OUT EFI_PARTITION_ENTRY_STATUS
*PEntryStatus
712 EFI_PARTITION_ENTRY
*Entry
;
716 DEBUG ((EFI_D_INFO
, " start check partition entries\n"));
717 for (Index1
= 0; Index1
< PartHeader
->NumberOfPartitionEntries
; Index1
++) {
718 Entry
= (EFI_PARTITION_ENTRY
*) ((UINT8
*) PartEntry
+ Index1
* PartHeader
->SizeOfPartitionEntry
);
719 if (CompareGuid (&Entry
->PartitionTypeGUID
, &gEfiPartTypeUnusedGuid
)) {
723 StartingLBA
= Entry
->StartingLBA
;
724 EndingLBA
= Entry
->EndingLBA
;
725 if (StartingLBA
> EndingLBA
||
726 StartingLBA
< PartHeader
->FirstUsableLBA
||
727 StartingLBA
> PartHeader
->LastUsableLBA
||
728 EndingLBA
< PartHeader
->FirstUsableLBA
||
729 EndingLBA
> PartHeader
->LastUsableLBA
731 PEntryStatus
[Index1
].OutOfRange
= TRUE
;
735 if ((Entry
->Attributes
& BIT1
) != 0) {
737 // If Bit 1 is set, this indicate that this is an OS specific GUID partition.
739 PEntryStatus
[Index1
].OsSpecific
= TRUE
;
742 for (Index2
= Index1
+ 1; Index2
< PartHeader
->NumberOfPartitionEntries
; Index2
++) {
743 Entry
= (EFI_PARTITION_ENTRY
*) ((UINT8
*) PartEntry
+ Index2
* PartHeader
->SizeOfPartitionEntry
);
744 if (CompareGuid (&Entry
->PartitionTypeGUID
, &gEfiPartTypeUnusedGuid
)) {
748 if (Entry
->EndingLBA
>= StartingLBA
&& Entry
->StartingLBA
<= EndingLBA
) {
750 // This region overlaps with the Index1'th region
752 PEntryStatus
[Index1
].Overlap
= TRUE
;
753 PEntryStatus
[Index2
].Overlap
= TRUE
;
759 DEBUG ((EFI_D_INFO
, " End check partition entries\n"));
764 Updates the CRC32 value in the table header.
766 @param Hdr Table to update
771 IN OUT EFI_TABLE_HEADER
*Hdr
774 PartitionSetCrcAltSize (Hdr
->HeaderSize
, Hdr
);
779 Updates the CRC32 value in the table header.
781 @param Size The size of the table
782 @param Hdr Table to update
786 PartitionSetCrcAltSize (
788 IN OUT EFI_TABLE_HEADER
*Hdr
794 gBS
->CalculateCrc32 ((UINT8
*) Hdr
, Size
, &Crc
);
800 Checks the CRC32 value in the table header.
802 @param MaxSize Max Size limit
803 @param Hdr Table to check
805 @return TRUE CRC Valid
806 @return FALSE CRC Invalid
812 IN OUT EFI_TABLE_HEADER
*Hdr
815 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 ((EFI_D_ERROR
, "CheckCrc32: Size > MaxSize\n"));
855 // clear old crc from header
860 Status
= gBS
->CalculateCrc32 ((UINT8
*) Hdr
, Size
, &Crc
);
861 if (EFI_ERROR (Status
)) {
862 DEBUG ((EFI_D_ERROR
, "CheckCrc32: Crc calculation failed\n"));
875 DEBUG ((EFI_D_ERROR
, "CheckCrc32: Crc check failed\n"));
879 return (BOOLEAN
) (OrgCrc
== Crc
);