OpenCore  1.0.4
OpenCore Bootloader
Loading...
Searching...
No Matches
Gpt.c File Reference
#include "Partition.h"

Go to the source code of this file.

Functions

BOOLEAN PartitionValidGptTable (IN EFI_BLOCK_IO_PROTOCOL *BlockIo, IN EFI_DISK_IO_PROTOCOL *DiskIo, IN EFI_LBA Lba, OUT EFI_PARTITION_TABLE_HEADER *PartHeader)
 
BOOLEAN PartitionCheckGptEntryArrayCRC (IN EFI_BLOCK_IO_PROTOCOL *BlockIo, IN EFI_DISK_IO_PROTOCOL *DiskIo, IN EFI_PARTITION_TABLE_HEADER *PartHeader)
 
BOOLEAN PartitionRestoreGptTable (IN EFI_BLOCK_IO_PROTOCOL *BlockIo, IN EFI_DISK_IO_PROTOCOL *DiskIo, IN EFI_PARTITION_TABLE_HEADER *PartHeader)
 
VOID PartitionCheckGptEntry (IN EFI_PARTITION_TABLE_HEADER *PartHeader, IN EFI_PARTITION_ENTRY *PartEntry, OUT EFI_PARTITION_ENTRY_STATUS *PEntryStatus)
 
BOOLEAN PartitionCheckCrcAltSize (IN UINTN MaxSize, IN UINTN Size, IN OUT EFI_TABLE_HEADER *Hdr)
 
BOOLEAN PartitionCheckCrc (IN UINTN MaxSize, IN OUT EFI_TABLE_HEADER *Hdr)
 
VOID PartitionSetCrcAltSize (IN UINTN Size, IN OUT EFI_TABLE_HEADER *Hdr)
 
VOID PartitionSetCrc (IN OUT EFI_TABLE_HEADER *Hdr)
 
EFI_STATUS PartitionInstallGptChildHandles (IN EFI_DRIVER_BINDING_PROTOCOL *This, IN EFI_HANDLE Handle, IN EFI_DISK_IO_PROTOCOL *DiskIo, IN EFI_DISK_IO2_PROTOCOL *DiskIo2, IN EFI_BLOCK_IO_PROTOCOL *BlockIo, IN EFI_BLOCK_IO2_PROTOCOL *BlockIo2, IN EFI_DEVICE_PATH_PROTOCOL *DevicePath)
 

Detailed Description

Decode a hard disk partitioned with the GPT scheme in the UEFI 2.0 specification.

Caution: This file requires additional review when modified. This driver will have external input - disk partition. This external input must be validated carefully to avoid security issue like buffer overflow, integer overflow.

PartitionInstallGptChildHandles() routine will read disk partition content and do basic validation before PartitionInstallChildHandle().

PartitionValidGptTable(), PartitionCheckGptEntry() routine will accept disk partition content and validate the GPT table and GPT entry.

Copyright (c) 2018 Qualcomm Datacenter Technologies, Inc. Copyright (c) 2006 - 2019, Intel Corporation. All rights reserved.
SPDX-License-Identifier: BSD-2-Clause-Patent

Definition in file Gpt.c.

Function Documentation

◆ PartitionCheckCrc()

BOOLEAN PartitionCheckCrc ( IN UINTN MaxSize,
IN OUT EFI_TABLE_HEADER * Hdr )

Checks the CRC32 value in the table header.

Parameters
MaxSizeMax Size limit
HdrTable to check
Returns
TRUE CRC Valid
FALSE CRC Invalid

Definition at line 826 of file Gpt.c.

◆ PartitionCheckCrcAltSize()

BOOLEAN PartitionCheckCrcAltSize ( IN UINTN MaxSize,
IN UINTN Size,
IN OUT EFI_TABLE_HEADER * Hdr )

Checks the CRC32 value in the table header.

Parameters
MaxSizeMax Size limit
SizeThe size of the table
HdrTable to check
Returns
TRUE CRC Valid
FALSE CRC Invalid

Definition at line 846 of file Gpt.c.

◆ PartitionCheckGptEntry()

VOID PartitionCheckGptEntry ( IN EFI_PARTITION_TABLE_HEADER * PartHeader,
IN EFI_PARTITION_ENTRY * PartEntry,
OUT EFI_PARTITION_ENTRY_STATUS * PEntryStatus )

This routine will check GPT partition entry and return entry status.

Caution: This function may receive untrusted input. The GPT partition entry is external input, so this routine will do basic validation for GPT partition entry and report status.

Parameters
[in]PartHeaderPartition table header structure
[in]PartEntryThe partition entry array
[out]PEntryStatusthe partition entry status array recording the status of each partition

Definition at line 722 of file Gpt.c.

◆ PartitionCheckGptEntryArrayCRC()

BOOLEAN PartitionCheckGptEntryArrayCRC ( IN EFI_BLOCK_IO_PROTOCOL * BlockIo,
IN EFI_DISK_IO_PROTOCOL * DiskIo,
IN EFI_PARTITION_TABLE_HEADER * PartHeader )

Check if the CRC field in the Partition table header is valid for Partition entry array.

Parameters
[in]BlockIoParent BlockIo interface
[in]DiskIoDisk Io Protocol.
[in]PartHeaderPartition table header structure
Return values
TRUEthe CRC is valid
FALSEthe CRC is invalid

Definition at line 561 of file Gpt.c.

◆ PartitionInstallGptChildHandles()

EFI_STATUS PartitionInstallGptChildHandles ( IN EFI_DRIVER_BINDING_PROTOCOL * This,
IN EFI_HANDLE Handle,
IN EFI_DISK_IO_PROTOCOL * DiskIo,
IN EFI_DISK_IO2_PROTOCOL * DiskIo2,
IN EFI_BLOCK_IO_PROTOCOL * BlockIo,
IN EFI_BLOCK_IO2_PROTOCOL * BlockIo2,
IN EFI_DEVICE_PATH_PROTOCOL * DevicePath )

Install child handles if the Handle supports GPT partition structure.

Caution: This function may receive untrusted input. The GPT partition table is external input, so this routine will do basic validation for GPT partition table before install child handle for each GPT partition.

Parameters
[in]ThisCalling context.
[in]HandleParent Handle.
[in]DiskIoParent DiskIo interface.
[in]DiskIo2Parent DiskIo2 interface.
[in]BlockIoParent BlockIo interface.
[in]BlockIo2Parent BlockIo2 interface.
[in]DevicePathParent Device Path.
Return values
EFI_SUCCESSValid GPT disk.
EFI_MEDIA_CHANGEDMedia changed Detected.
otherNot a valid GPT disk.

Definition at line 186 of file Gpt.c.

◆ PartitionRestoreGptTable()

BOOLEAN PartitionRestoreGptTable ( IN EFI_BLOCK_IO_PROTOCOL * BlockIo,
IN EFI_DISK_IO_PROTOCOL * DiskIo,
IN EFI_PARTITION_TABLE_HEADER * PartHeader )

Restore Partition Table to its alternate place (Primary -> Backup or Backup -> Primary).

Parameters
[in]BlockIoParent BlockIo interface.
[in]DiskIoDisk Io Protocol.
[in]PartHeaderPartition table header structure.
Return values
TRUERestoring succeeds
FALSERestoring failed

Definition at line 620 of file Gpt.c.

◆ PartitionSetCrc()

VOID PartitionSetCrc ( IN OUT EFI_TABLE_HEADER * Hdr)

Updates the CRC32 value in the table header.

Parameters
HdrTable to update

Definition at line 788 of file Gpt.c.

◆ PartitionSetCrcAltSize()

VOID PartitionSetCrcAltSize ( IN UINTN Size,
IN OUT EFI_TABLE_HEADER * Hdr )

Updates the CRC32 value in the table header.

Parameters
SizeThe size of the table
HdrTable to update

Definition at line 803 of file Gpt.c.

◆ PartitionValidGptTable()

BOOLEAN PartitionValidGptTable ( IN EFI_BLOCK_IO_PROTOCOL * BlockIo,
IN EFI_DISK_IO_PROTOCOL * DiskIo,
IN EFI_LBA Lba,
OUT EFI_PARTITION_TABLE_HEADER * PartHeader )

Install child handles if the Handle supports GPT partition structure.

Caution: This function may receive untrusted input. The GPT partition table header is external input, so this routine will do basic validation for GPT partition table header before return.

Parameters
[in]BlockIoParent BlockIo interface.
[in]DiskIoDisk Io protocol.
[in]LbaThe starting Lba of the Partition Table
[out]PartHeaderStores the partition table that is read
Return values
TRUEThe partition table is valid
FALSEThe partition table is not valid

This routine will read GPT partition table header and return it.

Caution: This function may receive untrusted input. The GPT partition table header is external input, so this routine will do basic validation for GPT partition table header before return.

Parameters
[in]BlockIoParent BlockIo interface.
[in]DiskIoDisk Io protocol.
[in]LbaThe starting Lba of the Partition Table
[out]PartHeaderStores the partition table that is read
Return values
TRUEThe partition table is valid
FALSEThe partition table is not valid

Definition at line 482 of file Gpt.c.