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 - 2018, Intel Corporation. All rights reserved.<BR>
18 This program and the accompanying materials
19 are licensed and made available under the terms and conditions of the BSD License
20 which accompanies this distribution. The full text of the license may be found at
21 http://opensource.org/licenses/bsd-license.php
23 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
24 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
29 #include "Partition.h"
32 Install child handles if the Handle supports GPT partition structure.
34 Caution: This function may receive untrusted input.
35 The GPT partition table header is external input, so this routine
36 will do basic validation for GPT partition table header before return.
38 @param[in] BlockIo Parent BlockIo interface.
39 @param[in] DiskIo Disk Io protocol.
40 @param[in] Lba The starting Lba of the Partition Table
41 @param[out] PartHeader Stores the partition table that is read
43 @retval TRUE The partition table is valid
44 @retval FALSE The partition table is not valid
48 PartitionValidGptTable (
49 IN EFI_BLOCK_IO_PROTOCOL
*BlockIo
,
50 IN EFI_DISK_IO_PROTOCOL
*DiskIo
,
52 OUT EFI_PARTITION_TABLE_HEADER
*PartHeader
56 Check if the CRC field in the Partition table header is valid
57 for Partition entry array.
59 @param[in] BlockIo Parent BlockIo interface
60 @param[in] DiskIo Disk Io Protocol.
61 @param[in] PartHeader Partition table header structure
63 @retval TRUE the CRC is valid
64 @retval FALSE the CRC is invalid
68 PartitionCheckGptEntryArrayCRC (
69 IN EFI_BLOCK_IO_PROTOCOL
*BlockIo
,
70 IN EFI_DISK_IO_PROTOCOL
*DiskIo
,
71 IN EFI_PARTITION_TABLE_HEADER
*PartHeader
76 Restore Partition Table to its alternate place
77 (Primary -> Backup or Backup -> Primary).
79 @param[in] BlockIo Parent BlockIo interface.
80 @param[in] DiskIo Disk Io Protocol.
81 @param[in] PartHeader Partition table header structure.
83 @retval TRUE Restoring succeeds
84 @retval FALSE Restoring failed
88 PartitionRestoreGptTable (
89 IN EFI_BLOCK_IO_PROTOCOL
*BlockIo
,
90 IN EFI_DISK_IO_PROTOCOL
*DiskIo
,
91 IN EFI_PARTITION_TABLE_HEADER
*PartHeader
96 This routine will check GPT partition entry and return entry status.
98 Caution: This function may receive untrusted input.
99 The GPT partition entry is external input, so this routine
100 will do basic validation for GPT partition entry and report status.
102 @param[in] PartHeader Partition table header structure
103 @param[in] PartEntry The partition entry array
104 @param[out] PEntryStatus the partition entry status array
105 recording the status of each partition
109 PartitionCheckGptEntry (
110 IN EFI_PARTITION_TABLE_HEADER
*PartHeader
,
111 IN EFI_PARTITION_ENTRY
*PartEntry
,
112 OUT EFI_PARTITION_ENTRY_STATUS
*PEntryStatus
117 Checks the CRC32 value in the table header.
119 @param MaxSize Max Size limit
120 @param Size The size of the table
121 @param Hdr Table to check
123 @return TRUE CRC Valid
124 @return FALSE CRC Invalid
128 PartitionCheckCrcAltSize (
131 IN OUT EFI_TABLE_HEADER
*Hdr
136 Checks the CRC32 value in the table header.
138 @param MaxSize Max Size limit
139 @param Hdr Table to check
141 @return TRUE CRC Valid
142 @return FALSE CRC Invalid
148 IN OUT EFI_TABLE_HEADER
*Hdr
153 Updates the CRC32 value in the table header.
155 @param Size The size of the table
156 @param Hdr Table to update
160 PartitionSetCrcAltSize (
162 IN OUT EFI_TABLE_HEADER
*Hdr
167 Updates the CRC32 value in the table header.
169 @param Hdr Table to update
174 IN OUT EFI_TABLE_HEADER
*Hdr
178 Install child handles if the Handle supports GPT partition structure.
180 Caution: This function may receive untrusted input.
181 The GPT partition table is external input, so this routine
182 will do basic validation for GPT partition table before install
183 child handle for each GPT partition.
185 @param[in] This Calling context.
186 @param[in] Handle Parent Handle.
187 @param[in] DiskIo Parent DiskIo interface.
188 @param[in] DiskIo2 Parent DiskIo2 interface.
189 @param[in] BlockIo Parent BlockIo interface.
190 @param[in] BlockIo2 Parent BlockIo2 interface.
191 @param[in] DevicePath Parent Device Path.
193 @retval EFI_SUCCESS Valid GPT disk.
194 @retval EFI_MEDIA_CHANGED Media changed Detected.
195 @retval other Not a valid GPT disk.
199 PartitionInstallGptChildHandles (
200 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
201 IN EFI_HANDLE Handle
,
202 IN EFI_DISK_IO_PROTOCOL
*DiskIo
,
203 IN EFI_DISK_IO2_PROTOCOL
*DiskIo2
,
204 IN EFI_BLOCK_IO_PROTOCOL
*BlockIo
,
205 IN EFI_BLOCK_IO2_PROTOCOL
*BlockIo2
,
206 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePath
212 MASTER_BOOT_RECORD
*ProtectiveMbr
;
213 EFI_PARTITION_TABLE_HEADER
*PrimaryHeader
;
214 EFI_PARTITION_TABLE_HEADER
*BackupHeader
;
215 EFI_PARTITION_ENTRY
*PartEntry
;
216 EFI_PARTITION_ENTRY
*Entry
;
217 EFI_PARTITION_ENTRY_STATUS
*PEntryStatus
;
219 EFI_STATUS GptValidStatus
;
220 HARDDRIVE_DEVICE_PATH HdDev
;
222 EFI_PARTITION_INFO_PROTOCOL PartitionInfo
;
224 ProtectiveMbr
= NULL
;
225 PrimaryHeader
= NULL
;
230 BlockSize
= BlockIo
->Media
->BlockSize
;
231 LastBlock
= BlockIo
->Media
->LastBlock
;
232 MediaId
= BlockIo
->Media
->MediaId
;
234 DEBUG ((EFI_D_INFO
, " BlockSize : %d \n", BlockSize
));
235 DEBUG ((EFI_D_INFO
, " LastBlock : %lx \n", LastBlock
));
237 GptValidStatus
= EFI_NOT_FOUND
;
240 // Allocate a buffer for the Protective MBR
242 ProtectiveMbr
= AllocatePool (BlockSize
);
243 if (ProtectiveMbr
== NULL
) {
244 return EFI_NOT_FOUND
;
248 // Read the Protective MBR from LBA #0
250 Status
= DiskIo
->ReadDisk (
257 if (EFI_ERROR (Status
)) {
258 GptValidStatus
= Status
;
263 // Verify that the Protective MBR is valid
265 for (Index
= 0; Index
< MAX_MBR_PARTITIONS
; Index
++) {
266 if (ProtectiveMbr
->Partition
[Index
].BootIndicator
== 0x00 &&
267 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
);