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 - 2013, 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
;
222 ProtectiveMbr
= NULL
;
223 PrimaryHeader
= NULL
;
228 BlockSize
= BlockIo
->Media
->BlockSize
;
229 LastBlock
= BlockIo
->Media
->LastBlock
;
230 MediaId
= BlockIo
->Media
->MediaId
;
232 DEBUG ((EFI_D_INFO
, " BlockSize : %d \n", BlockSize
));
233 DEBUG ((EFI_D_INFO
, " LastBlock : %lx \n", LastBlock
));
235 GptValidStatus
= EFI_NOT_FOUND
;
238 // Allocate a buffer for the Protective MBR
240 ProtectiveMbr
= AllocatePool (BlockSize
);
241 if (ProtectiveMbr
== NULL
) {
242 return EFI_NOT_FOUND
;
246 // Read the Protective MBR from LBA #0
248 Status
= DiskIo
->ReadDisk (
255 if (EFI_ERROR (Status
)) {
256 GptValidStatus
= Status
;
261 // Verify that the Protective MBR is valid
263 for (Index
= 0; Index
< MAX_MBR_PARTITIONS
; Index
++) {
264 if (ProtectiveMbr
->Partition
[Index
].BootIndicator
== 0x00 &&
265 ProtectiveMbr
->Partition
[Index
].OSIndicator
== PMBR_GPT_PARTITION
&&
266 UNPACK_UINT32 (ProtectiveMbr
->Partition
[Index
].StartingLBA
) == 1
271 if (Index
== MAX_MBR_PARTITIONS
) {
276 // Allocate the GPT structures
278 PrimaryHeader
= AllocateZeroPool (sizeof (EFI_PARTITION_TABLE_HEADER
));
279 if (PrimaryHeader
== NULL
) {
283 BackupHeader
= AllocateZeroPool (sizeof (EFI_PARTITION_TABLE_HEADER
));
284 if (BackupHeader
== NULL
) {
289 // Check primary and backup partition tables
291 if (!PartitionValidGptTable (BlockIo
, DiskIo
, PRIMARY_PART_HEADER_LBA
, PrimaryHeader
)) {
292 DEBUG ((EFI_D_INFO
, " Not Valid primary partition table\n"));
294 if (!PartitionValidGptTable (BlockIo
, DiskIo
, LastBlock
, BackupHeader
)) {
295 DEBUG ((EFI_D_INFO
, " Not Valid backup partition table\n"));
298 DEBUG ((EFI_D_INFO
, " Valid backup partition table\n"));
299 DEBUG ((EFI_D_INFO
, " Restore primary partition table by the backup\n"));
300 if (!PartitionRestoreGptTable (BlockIo
, DiskIo
, BackupHeader
)) {
301 DEBUG ((EFI_D_INFO
, " Restore primary partition table error\n"));
304 if (PartitionValidGptTable (BlockIo
, DiskIo
, BackupHeader
->AlternateLBA
, PrimaryHeader
)) {
305 DEBUG ((EFI_D_INFO
, " Restore backup partition table success\n"));
308 } else if (!PartitionValidGptTable (BlockIo
, DiskIo
, PrimaryHeader
->AlternateLBA
, BackupHeader
)) {
309 DEBUG ((EFI_D_INFO
, " Valid primary and !Valid backup partition table\n"));
310 DEBUG ((EFI_D_INFO
, " Restore backup partition table by the primary\n"));
311 if (!PartitionRestoreGptTable (BlockIo
, DiskIo
, PrimaryHeader
)) {
312 DEBUG ((EFI_D_INFO
, " Restore backup partition table error\n"));
315 if (PartitionValidGptTable (BlockIo
, DiskIo
, PrimaryHeader
->AlternateLBA
, BackupHeader
)) {
316 DEBUG ((EFI_D_INFO
, " Restore backup partition table success\n"));
321 DEBUG ((EFI_D_INFO
, " Valid primary and Valid backup partition table\n"));
324 // Read the EFI Partition Entries
326 PartEntry
= AllocatePool (PrimaryHeader
->NumberOfPartitionEntries
* PrimaryHeader
->SizeOfPartitionEntry
);
327 if (PartEntry
== NULL
) {
328 DEBUG ((EFI_D_ERROR
, "Allocate pool error\n"));
332 Status
= DiskIo
->ReadDisk (
335 MultU64x32(PrimaryHeader
->PartitionEntryLBA
, BlockSize
),
336 PrimaryHeader
->NumberOfPartitionEntries
* (PrimaryHeader
->SizeOfPartitionEntry
),
339 if (EFI_ERROR (Status
)) {
340 GptValidStatus
= Status
;
341 DEBUG ((EFI_D_ERROR
, " Partition Entry ReadDisk error\n"));
345 DEBUG ((EFI_D_INFO
, " Partition entries read block success\n"));
347 DEBUG ((EFI_D_INFO
, " Number of partition entries: %d\n", PrimaryHeader
->NumberOfPartitionEntries
));
349 PEntryStatus
= AllocateZeroPool (PrimaryHeader
->NumberOfPartitionEntries
* sizeof (EFI_PARTITION_ENTRY_STATUS
));
350 if (PEntryStatus
== NULL
) {
351 DEBUG ((EFI_D_ERROR
, "Allocate pool error\n"));
356 // Check the integrity of partition entries
358 PartitionCheckGptEntry (PrimaryHeader
, PartEntry
, PEntryStatus
);
361 // If we got this far the GPT layout of the disk is valid and we should return true
363 GptValidStatus
= EFI_SUCCESS
;
366 // Create child device handles
368 for (Index
= 0; Index
< PrimaryHeader
->NumberOfPartitionEntries
; Index
++) {
369 Entry
= (EFI_PARTITION_ENTRY
*) ((UINT8
*) PartEntry
+ Index
* PrimaryHeader
->SizeOfPartitionEntry
);
370 if (CompareGuid (&Entry
->PartitionTypeGUID
, &gEfiPartTypeUnusedGuid
) ||
371 PEntryStatus
[Index
].OutOfRange
||
372 PEntryStatus
[Index
].Overlap
||
373 PEntryStatus
[Index
].OsSpecific
376 // Don't use null EFI Partition Entries, Invalid Partition Entries or OS specific
382 ZeroMem (&HdDev
, sizeof (HdDev
));
383 HdDev
.Header
.Type
= MEDIA_DEVICE_PATH
;
384 HdDev
.Header
.SubType
= MEDIA_HARDDRIVE_DP
;
385 SetDevicePathNodeLength (&HdDev
.Header
, sizeof (HdDev
));
387 HdDev
.PartitionNumber
= (UINT32
) Index
+ 1;
388 HdDev
.MBRType
= MBR_TYPE_EFI_PARTITION_TABLE_HEADER
;
389 HdDev
.SignatureType
= SIGNATURE_TYPE_GUID
;
390 HdDev
.PartitionStart
= Entry
->StartingLBA
;
391 HdDev
.PartitionSize
= Entry
->EndingLBA
- Entry
->StartingLBA
+ 1;
392 CopyMem (HdDev
.Signature
, &Entry
->UniquePartitionGUID
, sizeof (EFI_GUID
));
394 DEBUG ((EFI_D_INFO
, " Index : %d\n", (UINT32
) Index
));
395 DEBUG ((EFI_D_INFO
, " Start LBA : %lx\n", (UINT64
) HdDev
.PartitionStart
));
396 DEBUG ((EFI_D_INFO
, " End LBA : %lx\n", (UINT64
) Entry
->EndingLBA
));
397 DEBUG ((EFI_D_INFO
, " Partition size: %lx\n", (UINT64
) HdDev
.PartitionSize
));
398 DEBUG ((EFI_D_INFO
, " Start : %lx", MultU64x32 (Entry
->StartingLBA
, BlockSize
)));
399 DEBUG ((EFI_D_INFO
, " End : %lx\n", MultU64x32 (Entry
->EndingLBA
, BlockSize
)));
401 Status
= PartitionInstallChildHandle (
409 (EFI_DEVICE_PATH_PROTOCOL
*) &HdDev
,
413 CompareGuid(&Entry
->PartitionTypeGUID
, &gEfiPartTypeSystemPartGuid
)
417 DEBUG ((EFI_D_INFO
, "Prepare to Free Pool\n"));
420 if (ProtectiveMbr
!= NULL
) {
421 FreePool (ProtectiveMbr
);
423 if (PrimaryHeader
!= NULL
) {
424 FreePool (PrimaryHeader
);
426 if (BackupHeader
!= NULL
) {
427 FreePool (BackupHeader
);
429 if (PartEntry
!= NULL
) {
430 FreePool (PartEntry
);
432 if (PEntryStatus
!= NULL
) {
433 FreePool (PEntryStatus
);
436 return GptValidStatus
;
440 This routine will read GPT partition table header and return it.
442 Caution: This function may receive untrusted input.
443 The GPT partition table header is external input, so this routine
444 will do basic validation for GPT partition table header before return.
446 @param[in] BlockIo Parent BlockIo interface.
447 @param[in] DiskIo Disk Io protocol.
448 @param[in] Lba The starting Lba of the Partition Table
449 @param[out] PartHeader Stores the partition table that is read
451 @retval TRUE The partition table is valid
452 @retval FALSE The partition table is not valid
456 PartitionValidGptTable (
457 IN EFI_BLOCK_IO_PROTOCOL
*BlockIo
,
458 IN EFI_DISK_IO_PROTOCOL
*DiskIo
,
460 OUT EFI_PARTITION_TABLE_HEADER
*PartHeader
465 EFI_PARTITION_TABLE_HEADER
*PartHdr
;
468 BlockSize
= BlockIo
->Media
->BlockSize
;
469 MediaId
= BlockIo
->Media
->MediaId
;
470 PartHdr
= AllocateZeroPool (BlockSize
);
472 if (PartHdr
== NULL
) {
473 DEBUG ((EFI_D_ERROR
, "Allocate pool error\n"));
477 // Read the EFI Partition Table Header
479 Status
= DiskIo
->ReadDisk (
482 MultU64x32 (Lba
, BlockSize
),
486 if (EFI_ERROR (Status
)) {
491 if ((PartHdr
->Header
.Signature
!= EFI_PTAB_HEADER_ID
) ||
492 !PartitionCheckCrc (BlockSize
, &PartHdr
->Header
) ||
493 PartHdr
->MyLBA
!= Lba
||
494 (PartHdr
->SizeOfPartitionEntry
< sizeof (EFI_PARTITION_ENTRY
))
496 DEBUG ((EFI_D_INFO
, "Invalid efi partition table header\n"));
502 // Ensure the NumberOfPartitionEntries * SizeOfPartitionEntry doesn't overflow.
504 if (PartHdr
->NumberOfPartitionEntries
> DivU64x32 (MAX_UINTN
, PartHdr
->SizeOfPartitionEntry
)) {
509 CopyMem (PartHeader
, PartHdr
, sizeof (EFI_PARTITION_TABLE_HEADER
));
510 if (!PartitionCheckGptEntryArrayCRC (BlockIo
, DiskIo
, PartHeader
)) {
515 DEBUG ((EFI_D_INFO
, " Valid efi partition table header\n"));
521 Check if the CRC field in the Partition table header is valid
522 for Partition entry array.
524 @param[in] BlockIo Parent BlockIo interface
525 @param[in] DiskIo Disk Io Protocol.
526 @param[in] PartHeader Partition table header structure
528 @retval TRUE the CRC is valid
529 @retval FALSE the CRC is invalid
533 PartitionCheckGptEntryArrayCRC (
534 IN EFI_BLOCK_IO_PROTOCOL
*BlockIo
,
535 IN EFI_DISK_IO_PROTOCOL
*DiskIo
,
536 IN EFI_PARTITION_TABLE_HEADER
*PartHeader
545 // Read the EFI Partition Entries
547 Ptr
= AllocatePool (PartHeader
->NumberOfPartitionEntries
* PartHeader
->SizeOfPartitionEntry
);
549 DEBUG ((EFI_D_ERROR
, " Allocate pool error\n"));
553 Status
= DiskIo
->ReadDisk (
555 BlockIo
->Media
->MediaId
,
556 MultU64x32(PartHeader
->PartitionEntryLBA
, BlockIo
->Media
->BlockSize
),
557 PartHeader
->NumberOfPartitionEntries
* PartHeader
->SizeOfPartitionEntry
,
560 if (EFI_ERROR (Status
)) {
565 Size
= PartHeader
->NumberOfPartitionEntries
* PartHeader
->SizeOfPartitionEntry
;
567 Status
= gBS
->CalculateCrc32 (Ptr
, Size
, &Crc
);
568 if (EFI_ERROR (Status
)) {
569 DEBUG ((EFI_D_ERROR
, "CheckPEntryArrayCRC: Crc calculation failed\n"));
576 return (BOOLEAN
) (PartHeader
->PartitionEntryArrayCRC32
== Crc
);
581 Restore Partition Table to its alternate place
582 (Primary -> Backup or Backup -> Primary).
584 @param[in] BlockIo Parent BlockIo interface.
585 @param[in] DiskIo Disk Io Protocol.
586 @param[in] PartHeader Partition table header structure.
588 @retval TRUE Restoring succeeds
589 @retval FALSE Restoring failed
593 PartitionRestoreGptTable (
594 IN EFI_BLOCK_IO_PROTOCOL
*BlockIo
,
595 IN EFI_DISK_IO_PROTOCOL
*DiskIo
,
596 IN EFI_PARTITION_TABLE_HEADER
*PartHeader
601 EFI_PARTITION_TABLE_HEADER
*PartHdr
;
609 BlockSize
= BlockIo
->Media
->BlockSize
;
610 MediaId
= BlockIo
->Media
->MediaId
;
612 PartHdr
= AllocateZeroPool (BlockSize
);
614 if (PartHdr
== NULL
) {
615 DEBUG ((EFI_D_ERROR
, "Allocate pool error\n"));
619 PEntryLBA
= (PartHeader
->MyLBA
== PRIMARY_PART_HEADER_LBA
) ? \
620 (PartHeader
->LastUsableLBA
+ 1) : \
621 (PRIMARY_PART_HEADER_LBA
+ 1);
623 CopyMem (PartHdr
, PartHeader
, sizeof (EFI_PARTITION_TABLE_HEADER
));
625 PartHdr
->MyLBA
= PartHeader
->AlternateLBA
;
626 PartHdr
->AlternateLBA
= PartHeader
->MyLBA
;
627 PartHdr
->PartitionEntryLBA
= PEntryLBA
;
628 PartitionSetCrc ((EFI_TABLE_HEADER
*) PartHdr
);
630 Status
= DiskIo
->WriteDisk (
633 MultU64x32 (PartHdr
->MyLBA
, (UINT32
) BlockSize
),
637 if (EFI_ERROR (Status
)) {
641 Ptr
= AllocatePool (PartHeader
->NumberOfPartitionEntries
* PartHeader
->SizeOfPartitionEntry
);
643 DEBUG ((EFI_D_ERROR
, " Allocate pool error\n"));
644 Status
= EFI_OUT_OF_RESOURCES
;
648 Status
= DiskIo
->ReadDisk (
651 MultU64x32(PartHeader
->PartitionEntryLBA
, (UINT32
) BlockSize
),
652 PartHeader
->NumberOfPartitionEntries
* PartHeader
->SizeOfPartitionEntry
,
655 if (EFI_ERROR (Status
)) {
659 Status
= DiskIo
->WriteDisk (
662 MultU64x32(PEntryLBA
, (UINT32
) BlockSize
),
663 PartHeader
->NumberOfPartitionEntries
* PartHeader
->SizeOfPartitionEntry
,
674 if (EFI_ERROR (Status
)) {
682 This routine will check GPT partition entry and return entry status.
684 Caution: This function may receive untrusted input.
685 The GPT partition entry is external input, so this routine
686 will do basic validation for GPT partition entry and report status.
688 @param[in] PartHeader Partition table header structure
689 @param[in] PartEntry The partition entry array
690 @param[out] PEntryStatus the partition entry status array
691 recording the status of each partition
695 PartitionCheckGptEntry (
696 IN EFI_PARTITION_TABLE_HEADER
*PartHeader
,
697 IN EFI_PARTITION_ENTRY
*PartEntry
,
698 OUT EFI_PARTITION_ENTRY_STATUS
*PEntryStatus
703 EFI_PARTITION_ENTRY
*Entry
;
707 DEBUG ((EFI_D_INFO
, " start check partition entries\n"));
708 for (Index1
= 0; Index1
< PartHeader
->NumberOfPartitionEntries
; Index1
++) {
709 Entry
= (EFI_PARTITION_ENTRY
*) ((UINT8
*) PartEntry
+ Index1
* PartHeader
->SizeOfPartitionEntry
);
710 if (CompareGuid (&Entry
->PartitionTypeGUID
, &gEfiPartTypeUnusedGuid
)) {
714 StartingLBA
= Entry
->StartingLBA
;
715 EndingLBA
= Entry
->EndingLBA
;
716 if (StartingLBA
> EndingLBA
||
717 StartingLBA
< PartHeader
->FirstUsableLBA
||
718 StartingLBA
> PartHeader
->LastUsableLBA
||
719 EndingLBA
< PartHeader
->FirstUsableLBA
||
720 EndingLBA
> PartHeader
->LastUsableLBA
722 PEntryStatus
[Index1
].OutOfRange
= TRUE
;
726 if ((Entry
->Attributes
& BIT1
) != 0) {
728 // If Bit 1 is set, this indicate that this is an OS specific GUID partition.
730 PEntryStatus
[Index1
].OsSpecific
= TRUE
;
733 for (Index2
= Index1
+ 1; Index2
< PartHeader
->NumberOfPartitionEntries
; Index2
++) {
734 Entry
= (EFI_PARTITION_ENTRY
*) ((UINT8
*) PartEntry
+ Index2
* PartHeader
->SizeOfPartitionEntry
);
735 if (CompareGuid (&Entry
->PartitionTypeGUID
, &gEfiPartTypeUnusedGuid
)) {
739 if (Entry
->EndingLBA
>= StartingLBA
&& Entry
->StartingLBA
<= EndingLBA
) {
741 // This region overlaps with the Index1'th region
743 PEntryStatus
[Index1
].Overlap
= TRUE
;
744 PEntryStatus
[Index2
].Overlap
= TRUE
;
750 DEBUG ((EFI_D_INFO
, " End check partition entries\n"));
755 Updates the CRC32 value in the table header.
757 @param Hdr Table to update
762 IN OUT EFI_TABLE_HEADER
*Hdr
765 PartitionSetCrcAltSize (Hdr
->HeaderSize
, Hdr
);
770 Updates the CRC32 value in the table header.
772 @param Size The size of the table
773 @param Hdr Table to update
777 PartitionSetCrcAltSize (
779 IN OUT EFI_TABLE_HEADER
*Hdr
785 gBS
->CalculateCrc32 ((UINT8
*) Hdr
, Size
, &Crc
);
791 Checks the CRC32 value in the table header.
793 @param MaxSize Max Size limit
794 @param Hdr Table to check
796 @return TRUE CRC Valid
797 @return FALSE CRC Invalid
803 IN OUT EFI_TABLE_HEADER
*Hdr
806 return PartitionCheckCrcAltSize (MaxSize
, Hdr
->HeaderSize
, Hdr
);
811 Checks the CRC32 value in the table header.
813 @param MaxSize Max Size limit
814 @param Size The size of the table
815 @param Hdr Table to check
817 @return TRUE CRC Valid
818 @return FALSE CRC Invalid
822 PartitionCheckCrcAltSize (
825 IN OUT EFI_TABLE_HEADER
*Hdr
836 // If header size is 0 CRC will pass so return FALSE here
841 if ((MaxSize
!= 0) && (Size
> MaxSize
)) {
842 DEBUG ((EFI_D_ERROR
, "CheckCrc32: Size > MaxSize\n"));
846 // clear old crc from header
851 Status
= gBS
->CalculateCrc32 ((UINT8
*) Hdr
, Size
, &Crc
);
852 if (EFI_ERROR (Status
)) {
853 DEBUG ((EFI_D_ERROR
, "CheckCrc32: Crc calculation failed\n"));
866 DEBUG ((EFI_D_ERROR
, "CheckCrc32: Crc check failed\n"));
870 return (BOOLEAN
) (OrgCrc
== Crc
);