OpenCore  1.0.4
OpenCore Bootloader
Loading...
Searching...
No Matches
DiskMisc.c File Reference
#include <Uefi.h>
#include <Guid/Gpt.h>
#include <IndustryStandard/Mbr.h>
#include <Protocol/BlockIo.h>
#include <Protocol/BlockIo2.h>
#include <Protocol/DiskIo.h>
#include <Protocol/DiskIo2.h>
#include <Library/BaseLib.h>
#include <Library/BaseMemoryLib.h>
#include <Library/BaseOverflowLib.h>
#include <Library/DebugLib.h>
#include <Library/DevicePathLib.h>
#include <Library/MemoryAllocationLib.h>
#include <Library/OcDebugLogLib.h>
#include <Library/OcDevicePathLib.h>
#include <Library/OcFileLib.h>
#include <Library/UefiBootServicesTableLib.h>

Go to the source code of this file.

Macros

#define MBR_PARTITION_ACTIVE   0x80
 

Functions

EFI_STATUS OcDiskInitializeContext (OUT OC_DISK_CONTEXT *Context, IN EFI_HANDLE DiskHandle, IN BOOLEAN UseBlockIo2)
 
EFI_STATUS OcDiskRead (IN OC_DISK_CONTEXT *Context, IN UINT64 Lba, IN UINTN BufferSize, OUT VOID *Buffer)
 
EFI_STATUS OcDiskWrite (IN OC_DISK_CONTEXT *Context, IN UINT64 Lba, IN UINTN BufferSize, IN VOID *Buffer)
 
STATIC VOID InternalDebugPrintPartitionEntry (IN UINTN ErrorLevel, IN CONST CHAR8 *Message, IN CONST EFI_PARTITION_ENTRY *PartitionEntry)
 
STATIC EFI_HANDLE InternalGetDiskHandle (IN EFI_DEVICE_PATH_PROTOCOL *HdDevicePath, IN BOOLEAN IsPartitionPath, OUT BOOLEAN *HasBlockIo2)
 
EFI_DEVICE_PATH_PROTOCOL * OcDiskGetDevicePath (IN EFI_DEVICE_PATH_PROTOCOL *HdDevicePath)
 
EFI_HANDLE OcPartitionGetDiskHandle (IN EFI_DEVICE_PATH_PROTOCOL *HdDevicePath)
 
EFI_HANDLE OcPartitionGetPartitionHandle (IN EFI_DEVICE_PATH_PROTOCOL *HdDevicePath)
 
BOOLEAN OcIsDiskCdRom (IN EFI_DEVICE_PATH_PROTOCOL *DiskDevicePath)
 
EFI_STATUS OcDiskReadElTorito (IN EFI_DEVICE_PATH_PROTOCOL *DiskDevicePath, OUT UINT8 **Buffer, OUT UINTN *BufferSize)
 
EFI_DEVICE_PATH_PROTOCOL * OcDiskFindSystemPartitionPath (IN CONST EFI_DEVICE_PATH_PROTOCOL *DiskDevicePath, OUT UINTN *EspDevicePathSize, OUT EFI_HANDLE *EspDeviceHandle)
 
CONST OC_PARTITION_ENTRIESOcGetDiskPartitions (IN EFI_HANDLE DiskHandle, IN BOOLEAN UseBlockIo2)
 
CONST EFI_PARTITION_ENTRY * OcGetGptPartitionEntry (IN EFI_HANDLE FsHandle)
 
MASTER_BOOT_RECORD * OcGetDiskMbrTable (IN EFI_HANDLE DiskHandle, IN BOOLEAN CheckPartitions)
 
EFI_STATUS OcDiskGetMbrPartitionIndex (IN EFI_HANDLE PartitionHandle, OUT UINT8 *PartitionIndex)
 
EFI_STATUS OcDiskMarkMbrPartitionActive (IN EFI_HANDLE DiskHandle, IN UINT8 PartitionIndex)
 
EFI_DEVICE_PATH_PROTOCOL * OcDiskFindActiveMbrPartitionPath (IN EFI_DEVICE_PATH_PROTOCOL *DiskDevicePath, OUT UINTN *PartitionDevicePathSize, OUT EFI_HANDLE *PartitionDeviceHandle)
 

Variables

STATIC EFI_GUID mInternalDiskPartitionEntriesProtocolGuid
 
STATIC EFI_GUID mInternalPartitionEntryProtocolGuid
 

Detailed Description

Copyright (C) 2019, Download-Fritz. All rights reserved.

This program and the accompanying materials are licensed and made available under the terms and conditions of the BSD License which accompanies this distribution. The full text of the license may be found at http://opensource.org/licenses/bsd-license.php

THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.

Definition in file DiskMisc.c.

Macro Definition Documentation

◆ MBR_PARTITION_ACTIVE

#define MBR_PARTITION_ACTIVE   0x80

Definition at line 43 of file DiskMisc.c.

Function Documentation

◆ InternalDebugPrintPartitionEntry()

STATIC VOID InternalDebugPrintPartitionEntry ( IN UINTN ErrorLevel,
IN CONST CHAR8 * Message,
IN CONST EFI_PARTITION_ENTRY * PartitionEntry )

Definition at line 187 of file DiskMisc.c.

◆ InternalGetDiskHandle()

STATIC EFI_HANDLE InternalGetDiskHandle ( IN EFI_DEVICE_PATH_PROTOCOL * HdDevicePath,
IN BOOLEAN IsPartitionPath,
OUT BOOLEAN * HasBlockIo2 )

Definition at line 216 of file DiskMisc.c.

◆ OcDiskFindActiveMbrPartitionPath()

EFI_DEVICE_PATH_PROTOCOL * OcDiskFindActiveMbrPartitionPath ( IN EFI_DEVICE_PATH_PROTOCOL * DiskDevicePath,
OUT UINTN * PartitionDevicePathSize,
OUT EFI_HANDLE * PartitionDeviceHandle )

Locate the disk's active MBR partition.

Parameters
[in]DiskDevicePathThe Device Path of the disk to scan.
[out]PartitionDevicePathSizeThe size of the returned Device Path.
[out]PartitionDeviceHandleDevice handle of the returned partition.
Returns
The device path protocol from the discovered handle or NULL.

Definition at line 1057 of file DiskMisc.c.

◆ OcDiskFindSystemPartitionPath()

EFI_DEVICE_PATH_PROTOCOL * OcDiskFindSystemPartitionPath ( IN CONST EFI_DEVICE_PATH_PROTOCOL * DiskDevicePath,
OUT UINTN * EspDevicePathSize,
OUT EFI_HANDLE * EspDeviceHandle )

Locate the disk's EFI System Partition.

Parameters
[in]DiskDevicePathThe Device Path of the disk to scan.
[out]EspDevicePathSizeThe size of the returned Device Path.
[out]EspDeviceHandleDevice handle of the returned partition.
Returns
The device path protocol from the discovered handle or NULL.

Definition at line 458 of file DiskMisc.c.

◆ OcDiskGetDevicePath()

EFI_DEVICE_PATH_PROTOCOL * OcDiskGetDevicePath ( IN EFI_DEVICE_PATH_PROTOCOL * HdDevicePath)

Retrieve the disk's Device Path from a partition's Device Path.

Parameters
[in]HdDevicePathThe Device Path of the partition.
Return values
DevicePath or NULL

Definition at line 280 of file DiskMisc.c.

◆ OcDiskGetMbrPartitionIndex()

EFI_STATUS OcDiskGetMbrPartitionIndex ( IN EFI_HANDLE PartitionHandle,
OUT UINT8 * PartitionIndex )

Retrieve the MBR partition index for the specified partition.

Parameters
[in]PartitionHandlePartition device handle to retrieve MBR partition index for.
[out]PartitionIndexPointer to store partition index in.
Return values
EFI_SUCCESSon success.

Definition at line 908 of file DiskMisc.c.

◆ OcDiskInitializeContext()

EFI_STATUS OcDiskInitializeContext ( OUT OC_DISK_CONTEXT * Context,
IN EFI_HANDLE DiskHandle,
IN BOOLEAN UseBlockIo2 )

Initialize disk I/O context.

Parameters
[out]ContextDisk I/O context to intialize.
[in]DiskHandleDisk handle with protocols.
[in]UseBlockIo2Try to use BlockIo2 protocol if available.
Return values
EFI_SUCCESSon success.

Definition at line 46 of file DiskMisc.c.

◆ OcDiskMarkMbrPartitionActive()

EFI_STATUS OcDiskMarkMbrPartitionActive ( IN EFI_HANDLE DiskHandle,
IN UINT8 PartitionIndex )

Mark specified MBR partition as active.

Parameters
[in]DiskHandleDisk device handle containing MBR partition table
[in]PartitionIndexMBR partition index.
Return values
EFI_SUCCESSon success.

Definition at line 978 of file DiskMisc.c.

◆ OcDiskRead()

EFI_STATUS OcDiskRead ( IN OC_DISK_CONTEXT * Context,
IN UINT64 Lba,
IN UINTN BufferSize,
OUT VOID * Buffer )

Read information from disk.

Parameters
[in]ContextDisk I/O context.
[in]LbaLBA number to read from.
[in]BufferSizeBuffer size allocated in Buffer.
[out]BufferBuffer to store data in.
Return values
EFI_SUCCESSon success.

Definition at line 116 of file DiskMisc.c.

◆ OcDiskReadElTorito()

EFI_STATUS OcDiskReadElTorito ( IN EFI_DEVICE_PATH_PROTOCOL * DiskDevicePath,
OUT UINT8 ** Buffer,
OUT UINTN * BufferSize )

Read El-Torito boot sector from CD-ROM device.

Parameters
[in]DiskDevicePathThe Device Path of the disk.
[out]BufferPointer to pool-allocated buffer containing the boot sector data.
[out]BufferSizeSize of Buffer.
Return values
EFI_SUCCESSon success.

Definition at line 392 of file DiskMisc.c.

◆ OcDiskWrite()

EFI_STATUS OcDiskWrite ( IN OC_DISK_CONTEXT * Context,
IN UINT64 Lba,
IN UINTN BufferSize,
IN VOID * Buffer )

Write information to disk.

Parameters
[in]ContextDisk I/O context.
[in]LbaLBA number to write to.
[in]BufferSizeBuffer size allocated in Buffer.
[out]BufferBuffer containing data to write.
Return values
EFI_SUCCESSon success.

Definition at line 151 of file DiskMisc.c.

◆ OcGetDiskMbrTable()

MASTER_BOOT_RECORD * OcGetDiskMbrTable ( IN EFI_HANDLE DiskHandle,
IN BOOLEAN CheckPartitions )

Retrieve the disk MBR table, if applicable.

Parameters
[in]DiskHandleDisk device handle to retrive MBR partition table from.
[in]CheckPartitionsCheck partition layout. This should be FALSE for a PBR.
Return values
MBRpartition table or NULL.

Definition at line 828 of file DiskMisc.c.

◆ OcGetDiskPartitions()

CONST OC_PARTITION_ENTRIES * OcGetDiskPartitions ( IN EFI_HANDLE DiskHandle,
IN BOOLEAN UseBlockIo2 )

Retrieve the disk GPT partitions, if applicable.

Parameters
[in]DiskHandleDisk device handle to retrive partition table from.
[in]UseBlockIo2Use 2nd revision of Block I/O if available.
Return values
partitionentry list or NULL.

Definition at line 573 of file DiskMisc.c.

◆ OcGetGptPartitionEntry()

CONST EFI_PARTITION_ENTRY * OcGetGptPartitionEntry ( IN EFI_HANDLE FsHandle)

Retrieve the partition's GPT information, if applicable

Parameters
[in]FsHandleThe device handle of the partition to retrieve info of.

Definition at line 732 of file DiskMisc.c.

◆ OcIsDiskCdRom()

BOOLEAN OcIsDiskCdRom ( IN EFI_DEVICE_PATH_PROTOCOL * DiskDevicePath)

Check if disk is a CD-ROM device.

Parameters
[in]DiskDevicePathThe Device Path of the disk.
Return values
DevicePath or NULL

Definition at line 369 of file DiskMisc.c.

◆ OcPartitionGetDiskHandle()

EFI_HANDLE OcPartitionGetDiskHandle ( IN EFI_DEVICE_PATH_PROTOCOL * HdDevicePath)

Retrieve the disk's device handle from a partition's Device Path.

Parameters
[in]HdDevicePathThe Device Path of the partition.

Definition at line 331 of file DiskMisc.c.

◆ OcPartitionGetPartitionHandle()

EFI_HANDLE OcPartitionGetPartitionHandle ( IN EFI_DEVICE_PATH_PROTOCOL * HdDevicePath)

Retrieve the partition's device handle from a partition's Device Path.

Parameters
[in]HdDevicePathThe Device Path of the partition.

Definition at line 353 of file DiskMisc.c.

Variable Documentation

◆ mInternalDiskPartitionEntriesProtocolGuid

STATIC EFI_GUID mInternalDiskPartitionEntriesProtocolGuid
Initial value:
= {
0x1A81704, 0x3442, 0x4A7D, { 0x87, 0x40, 0xF4, 0xEC, 0x5B, 0xBE, 0x59, 0x77 }
}

Definition at line 35 of file DiskMisc.c.

◆ mInternalPartitionEntryProtocolGuid

STATIC EFI_GUID mInternalPartitionEntryProtocolGuid
Initial value:
= {
0x9FC6B19, 0xB8A1, 0x4A01, { 0x8D, 0xB1, 0x87, 0x94, 0xE7, 0x63, 0x4C, 0xA5 }
}

Definition at line 39 of file DiskMisc.c.