OpenCore  1.0.4
OpenCore Bootloader
Loading...
Searching...
No Matches
OcDevicePathLib.c File Reference
#include <Uefi.h>
#include <Protocol/DevicePathToText.h>
#include <Protocol/SimpleFileSystem.h>
#include <Library/DebugLib.h>
#include <Library/BaseLib.h>
#include <Library/BaseMemoryLib.h>
#include <Library/BaseOverflowLib.h>
#include <Library/DevicePathLib.h>
#include <Library/MemoryAllocationLib.h>
#include <Library/OcStringLib.h>
#include <Library/OcDevicePathLib.h>
#include <Library/UefiBootServicesTableLib.h>
#include <Library/OcDebugLogLib.h>

Go to the source code of this file.

Functions

EFI_DEVICE_PATH_PROTOCOL * AppendFileNameDevicePath (IN EFI_DEVICE_PATH_PROTOCOL *DevicePath, IN CHAR16 *FileName)
 
EFI_DEVICE_PATH_PROTOCOL * FindDevicePathEndNode (IN EFI_DEVICE_PATH_PROTOCOL *DevicePath)
 
EFI_DEVICE_PATH_PROTOCOL * FindDevicePathNodeWithType (IN EFI_DEVICE_PATH_PROTOCOL *DevicePath, IN UINT8 Type, IN UINT8 SubType OPTIONAL)
 
EFI_DEVICE_PATH_PROTOCOL * AbsoluteDevicePath (IN EFI_HANDLE Handle, IN EFI_DEVICE_PATH_PROTOCOL *RelativePath OPTIONAL)
 
EFI_DEVICE_PATH_PROTOCOL * TrailedBooterDevicePath (IN EFI_DEVICE_PATH_PROTOCOL *DevicePath)
 
VOID OcFixAppleBootDevicePathNodeRestore (IN OUT EFI_DEVICE_PATH_PROTOCOL **DevicePath, IN OUT EFI_DEVICE_PATH_PROTOCOL **DevicePathNode, IN CONST APPLE_BOOT_DP_PATCH_CONTEXT *RestoreContext)
 
VOID OcFixAppleBootDevicePathNodeRestoreFree (IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePathNode, IN OUT APPLE_BOOT_DP_PATCH_CONTEXT *RestoreContext)
 
STATIC INTN InternalExpandNewPath (IN OUT EFI_DEVICE_PATH_PROTOCOL **DevicePath, IN OUT EFI_DEVICE_PATH_PROTOCOL **DevicePathNode)
 
STATIC INTN InternalFixAppleBootDevicePathVirtioNode (IN OUT EFI_DEVICE_PATH_PROTOCOL **DevicePath, IN OUT EFI_DEVICE_PATH_PROTOCOL **DevicePathNode, OUT APPLE_BOOT_DP_PATCH_CONTEXT *RestoreContext OPTIONAL)
 
INTN OcFixAppleBootDevicePathNode (IN OUT EFI_DEVICE_PATH_PROTOCOL **DevicePath, IN OUT EFI_DEVICE_PATH_PROTOCOL **DevicePathNode, OUT APPLE_BOOT_DP_PATCH_CONTEXT *RestoreContext OPTIONAL, IN EFI_HANDLE ValidDevice OPTIONAL)
 
INTN OcFixAppleBootDevicePath (IN OUT EFI_DEVICE_PATH_PROTOCOL **DevicePath, OUT EFI_DEVICE_PATH_PROTOCOL **RemainingDevicePath)
 
STATIC BOOLEAN InternalFileDevicePathsEqualClipBottom (IN CONST FILEPATH_DEVICE_PATH *FilePath, IN OUT UINTN *FilePathLength, IN OUT UINTN *ClipIndex)
 
STATIC UINTN InternalFileDevicePathsEqualClipNode (IN FILEPATH_DEVICE_PATH **FilePath, OUT UINTN *ClipIndex)
 
STATIC UINTN InternalFileDevicePathsEqualClipNextNode (IN FILEPATH_DEVICE_PATH **FilePath, OUT UINTN *ClipIndex)
 
BOOLEAN InternalFileDevicePathsEqualWorker (IN FILEPATH_DEVICE_PATH **FilePath1, IN FILEPATH_DEVICE_PATH **FilePath2)
 
BOOLEAN FileDevicePathsEqual (IN FILEPATH_DEVICE_PATH *FilePath1, IN FILEPATH_DEVICE_PATH *FilePath2)
 
STATIC BOOLEAN InternalDevicePathCmpWorker (IN EFI_DEVICE_PATH_PROTOCOL *ParentPath, IN EFI_DEVICE_PATH_PROTOCOL *ChildPath, IN BOOLEAN CheckChild)
 
BOOLEAN EFIAPI IsDevicePathEqual (IN EFI_DEVICE_PATH_PROTOCOL *DevicePath1, IN EFI_DEVICE_PATH_PROTOCOL *DevicePath2)
 
BOOLEAN EFIAPI IsDevicePathChild (IN EFI_DEVICE_PATH_PROTOCOL *ParentPath, IN EFI_DEVICE_PATH_PROTOCOL *ChildPath)
 
UINTN OcFileDevicePathNameSize (IN CONST FILEPATH_DEVICE_PATH *FilePath)
 
UINTN OcFileDevicePathNameLen (IN CONST FILEPATH_DEVICE_PATH *FilePath)
 
UINTN OcFileDevicePathFullNameLen (IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath)
 
UINTN OcFileDevicePathFullNameSize (IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath)
 
VOID OcFileDevicePathFullName (OUT CHAR16 *PathName, IN CONST FILEPATH_DEVICE_PATH *FilePath, IN UINTN PathNameSize)
 
CHAR16 * OcCopyDevicePathFullName (IN EFI_DEVICE_PATH_PROTOCOL *DevicePath, OUT EFI_DEVICE_PATH_PROTOCOL **FileDevicePath OPTIONAL)
 
EFI_DEVICE_PATH_PROTOCOL * OcAppendDevicePathInstanceDedupe (IN EFI_DEVICE_PATH_PROTOCOL *DevicePath OPTIONAL, IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePathInstance)
 
UINTN OcGetNumDevicePathInstances (IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath)
 
BOOLEAN OcDevicePathHasFilePathSuffix (IN EFI_DEVICE_PATH_PROTOCOL *DevicePath, IN CONST CHAR16 *Suffix, IN UINTN SuffixLen)
 

Detailed Description

Copyright (C) 2016 - 2018, The HermitCrabs Lab. All rights reserved.

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 OcDevicePathLib.c.

Function Documentation

◆ AbsoluteDevicePath()

EFI_DEVICE_PATH_PROTOCOL * AbsoluteDevicePath ( IN EFI_HANDLE Handle,
IN EFI_DEVICE_PATH_PROTOCOL *RelativePath OPTIONAL )

Get absolute device path.

Parameters
[in]HandleDevice handle.
[in]RelativePathRelative device path to handle, optional.
Return values
Newdevice path or NULL.

Definition at line 112 of file OcDevicePathLib.c.

◆ AppendFileNameDevicePath()

EFI_DEVICE_PATH_PROTOCOL * AppendFileNameDevicePath ( IN EFI_DEVICE_PATH_PROTOCOL * DevicePath,
IN CHAR16 * FileName )

Append file name to device path.

Parameters
[in]DevicePathThe device path which to append the file path.
[in]FileNameThe file name to append to the device path.
Return values
EFI_SUCCESSThe defaults were initialized successfully.
EFI_INVALID_PARAMETERThe parameters passed were invalid.
EFI_OUT_OF_RESOURCESThe system ran out of memory.

Definition at line 33 of file OcDevicePathLib.c.

◆ FileDevicePathsEqual()

BOOLEAN FileDevicePathsEqual ( IN FILEPATH_DEVICE_PATH * FilePath1,
IN FILEPATH_DEVICE_PATH * FilePath2 )

Check whether File Device Paths are equal.

Parameters
[in]FilePath1The first device path protocol to compare.
[in]FilePath2The second device path protocol to compare.
Return values
TRUEThe device paths matched
FALSEThe device paths were different

Definition at line 1107 of file OcDevicePathLib.c.

◆ FindDevicePathEndNode()

EFI_DEVICE_PATH_PROTOCOL * FindDevicePathEndNode ( IN EFI_DEVICE_PATH_PROTOCOL * DevicePath)

Locate the terminating node inside the device path.

Parameters
[in]DevicePathThe device path used in the search.
Returns
Returned is the last Device Path Node.

Definition at line 74 of file OcDevicePathLib.c.

◆ FindDevicePathNodeWithType()

EFI_DEVICE_PATH_PROTOCOL * FindDevicePathNodeWithType ( IN EFI_DEVICE_PATH_PROTOCOL * DevicePath,
IN UINT8 Type,
IN UINT8 SubType OPTIONAL )

Locate the node inside the device path specified by Type an SubType values.

Parameters
[in]DevicePathThe device path used in the search.
[in]TypeThe Type field of the device path node specified by Node.
[in]SubTypeThe SubType field of the device path node specified by Node.
Returns
Returned is the first Device Path Node with the given type.

Definition at line 86 of file OcDevicePathLib.c.

◆ InternalDevicePathCmpWorker()

STATIC BOOLEAN InternalDevicePathCmpWorker ( IN EFI_DEVICE_PATH_PROTOCOL * ParentPath,
IN EFI_DEVICE_PATH_PROTOCOL * ChildPath,
IN BOOLEAN CheckChild )

Definition at line 1120 of file OcDevicePathLib.c.

◆ InternalExpandNewPath()

STATIC INTN InternalExpandNewPath ( IN OUT EFI_DEVICE_PATH_PROTOCOL ** DevicePath,
IN OUT EFI_DEVICE_PATH_PROTOCOL ** DevicePathNode )

Definition at line 324 of file OcDevicePathLib.c.

◆ InternalFileDevicePathsEqualClipBottom()

STATIC BOOLEAN InternalFileDevicePathsEqualClipBottom ( IN CONST FILEPATH_DEVICE_PATH * FilePath,
IN OUT UINTN * FilePathLength,
IN OUT UINTN * ClipIndex )

Definition at line 921 of file OcDevicePathLib.c.

◆ InternalFileDevicePathsEqualClipNextNode()

STATIC UINTN InternalFileDevicePathsEqualClipNextNode ( IN FILEPATH_DEVICE_PATH ** FilePath,
OUT UINTN * ClipIndex )

Definition at line 997 of file OcDevicePathLib.c.

◆ InternalFileDevicePathsEqualClipNode()

STATIC UINTN InternalFileDevicePathsEqualClipNode ( IN FILEPATH_DEVICE_PATH ** FilePath,
OUT UINTN * ClipIndex )

Definition at line 946 of file OcDevicePathLib.c.

◆ InternalFileDevicePathsEqualWorker()

BOOLEAN InternalFileDevicePathsEqualWorker ( IN FILEPATH_DEVICE_PATH ** FilePath1,
IN FILEPATH_DEVICE_PATH ** FilePath2 )

Definition at line 1010 of file OcDevicePathLib.c.

◆ InternalFixAppleBootDevicePathVirtioNode()

STATIC INTN InternalFixAppleBootDevicePathVirtioNode ( IN OUT EFI_DEVICE_PATH_PROTOCOL ** DevicePath,
IN OUT EFI_DEVICE_PATH_PROTOCOL ** DevicePathNode,
OUT APPLE_BOOT_DP_PATCH_CONTEXT *RestoreContext OPTIONAL )

Fix Apple Boot Device Path VirtIO node to be compatible with conventional UEFI implementations. Currently only APFS file system is supported as VirtIO support landed in macOS in 10.14, which was APFS-only.

Parameters
[in,out]DevicePathA pointer to the device path to fix a node of. It must be a pool memory buffer. On success, may be updated with a reallocated pool memory buffer.
[in,out]DevicePathNodeA pointer to the device path node to fix. It must be a node of *DevicePath. On success, may be updated with the corresponding node of *DevicePath.
[out]RestoreContextA pointer to a context that can be used to restore DevicePathNode's original content in the case of failure. On success, data may need to be freed.
Return values
0DevicePathNode was not modified and may be valid.
1DevicePathNode was fixed and may be valid.

Definition at line 435 of file OcDevicePathLib.c.

◆ IsDevicePathChild()

BOOLEAN EFIAPI IsDevicePathChild ( IN EFI_DEVICE_PATH_PROTOCOL * ParentPath,
IN EFI_DEVICE_PATH_PROTOCOL * ChildPath )

Check whether one device path exists in the other.

Parameters
[in]ParentPathThe parent device path protocol to check against.
[in]ChildPathThe device path protocol of the child device to compare.
Return values
TRUEThe child device path contains the parent device path.
FALSEThe device paths were different

Definition at line 1219 of file OcDevicePathLib.c.

◆ IsDevicePathEqual()

BOOLEAN EFIAPI IsDevicePathEqual ( IN EFI_DEVICE_PATH_PROTOCOL * DevicePath1,
IN EFI_DEVICE_PATH_PROTOCOL * DevicePath2 )

Check whether device paths are equal.

Parameters
[in]DevicePath1The first device path protocol to compare.
[in]DevicePath2The second device path protocol to compare.
Return values
TRUEThe device paths matched
FALSEThe device paths were different

Definition at line 1209 of file OcDevicePathLib.c.

◆ OcAppendDevicePathInstanceDedupe()

EFI_DEVICE_PATH_PROTOCOL * OcAppendDevicePathInstanceDedupe ( IN EFI_DEVICE_PATH_PROTOCOL *DevicePath OPTIONAL,
IN CONST EFI_DEVICE_PATH_PROTOCOL * DevicePathInstance )

Duplicate device path with DevicePathInstance appended if it is not present.

Parameters
[in]DevicePathDevice Path to append new instance to, optional.
[in]DevicePathInstanceDevice Path instance to append.
Return values
NewDevice Path or NULL.

Definition at line 1424 of file OcDevicePathLib.c.

◆ OcCopyDevicePathFullName()

CHAR16 * OcCopyDevicePathFullName ( IN EFI_DEVICE_PATH_PROTOCOL * DevicePath,
OUT EFI_DEVICE_PATH_PROTOCOL **FileDevicePath OPTIONAL )

Retrieves full file path from device path allocating it on pool.

Parameters
[in]DevicePathDevice path to extract file path from.
[out]FileDevicePathPointer to file path part of the device path, optional.
Returns
Path allocated from pool.
Return values
NULLwhen missing.

Definition at line 1379 of file OcDevicePathLib.c.

◆ OcDevicePathHasFilePathSuffix()

BOOLEAN OcDevicePathHasFilePathSuffix ( IN EFI_DEVICE_PATH_PROTOCOL * DevicePath,
IN CONST CHAR16 * Suffix,
IN UINTN SuffixLen )

Definition at line 1495 of file OcDevicePathLib.c.

◆ OcFileDevicePathFullName()

VOID OcFileDevicePathFullName ( OUT CHAR16 * PathName,
IN CONST FILEPATH_DEVICE_PATH * FilePath,
IN UINTN PathNameSize )

Retrieve the full file path described by FilePath. The caller is expected to call OcFileDevicePathFullNameSize() or ensure its guarantees are met.

Parameters
[out]PathNameOn output, the full file path of FilePath.
[in]FilePathThe File Device Path to inspect.
[in]PathNameSizeThe size, in bytes, of PathName. Must equal the actual full file path size.

Definition at line 1343 of file OcDevicePathLib.c.

◆ OcFileDevicePathFullNameLen()

UINTN OcFileDevicePathFullNameLen ( IN CONST EFI_DEVICE_PATH_PROTOCOL * DevicePath)

Retrieve the length of the full file path described by DevicePath.

Parameters
[in]DevicePathThe Device Path to inspect.
Returns
The length of the full file path.
Return values
0DevicePath does not start with a File Path node or contains non-terminating nodes that are not File Path nodes.

Definition at line 1271 of file OcDevicePathLib.c.

◆ OcFileDevicePathFullNameSize()

UINTN OcFileDevicePathFullNameSize ( IN CONST EFI_DEVICE_PATH_PROTOCOL * DevicePath)

Retrieve the size of the full file path described by DevicePath.

Parameters
[in]DevicePathThe Device Path to inspect.
Returns
The size of the full file path.
Return values
0DevicePath does not start with a File Path node or contains non-terminating nodes that are not File Path nodes.

Definition at line 1316 of file OcDevicePathLib.c.

◆ OcFileDevicePathNameLen()

UINTN OcFileDevicePathNameLen ( IN CONST FILEPATH_DEVICE_PATH * FilePath)

Returns the length of PathName.

Parameters
[in]FilePathThe file Device Path node to inspect.
Return values
Namelength in characters (without trailing zero).

Definition at line 1238 of file OcDevicePathLib.c.

◆ OcFileDevicePathNameSize()

UINTN OcFileDevicePathNameSize ( IN CONST FILEPATH_DEVICE_PATH * FilePath)

Returns the size of PathName.

Parameters
[in]FilePathThe file Device Path node to inspect.
Return values
Namesize in bytes.

Definition at line 1228 of file OcDevicePathLib.c.

◆ OcFixAppleBootDevicePath()

INTN OcFixAppleBootDevicePath ( IN OUT EFI_DEVICE_PATH_PROTOCOL ** DevicePath,
OUT EFI_DEVICE_PATH_PROTOCOL ** RemainingDevicePath )

Fix Apple Boot Device Path to be compatible with conventional UEFI implementations. In case -1 is returned and the first node could not be located or fixed, DevicePath's original state will be preserved. In all other cases, it may be destroyed.

Parameters
[in,out]DevicePathA pointer to the device path to fix. It must be a pool memory buffer. On success, may be updated with a reallocated pool memory buffer.
[in,out]RemainingDevicePathA pointer the remaining part of the device path is returned into.

Note, RemainingDevicePath will always point into DevicePath after this function completes. RemainingDevicePath being equal to DevicePath means that we failed to advance, and this device path is likely a short form device path or something completely not valid.

Return values
-1*DevicePath could not be fixed.
0*DevicePath was not modified and may be valid.
1*DevicePath was fixed and may be valid.

Definition at line 822 of file OcDevicePathLib.c.

◆ OcFixAppleBootDevicePathNode()

INTN OcFixAppleBootDevicePathNode ( IN OUT EFI_DEVICE_PATH_PROTOCOL ** DevicePath,
IN OUT EFI_DEVICE_PATH_PROTOCOL ** DevicePathNode,
OUT APPLE_BOOT_DP_PATCH_CONTEXT *RestoreContext OPTIONAL,
IN EFI_HANDLE ValidDevice OPTIONAL )

Fix Apple Boot Device Path node to be compatible with conventional UEFI implementations.

Parameters
[in,out]DevicePathA pointer to the device path to fix a node of. It must be a pool memory buffer. On success, may be updated with a reallocated pool memory buffer.
[in,out]DevicePathNodeA pointer to the device path node to fix. It must be a node of *DevicePath. On success, may be updated with the corresponding node of *DevicePath.
[out]RestoreContextA pointer to a context that can be used to restore DevicePathNode's original content in the case of failure. On success, data may need to be freed.
[in]ValidDeviceA device handle pointing to previous valid device path if any.
Return values
-1DevicePathNode could not be fixed.
0DevicePathNode was not modified and may be valid.
1DevicePathNode was fixed and may be valid.

Definition at line 590 of file OcDevicePathLib.c.

◆ OcFixAppleBootDevicePathNodeRestore()

VOID OcFixAppleBootDevicePathNodeRestore ( IN OUT EFI_DEVICE_PATH_PROTOCOL ** DevicePath,
IN OUT EFI_DEVICE_PATH_PROTOCOL ** DevicePathNode,
IN CONST APPLE_BOOT_DP_PATCH_CONTEXT * RestoreContext )

Restore the original content of DevicePathNode before calling OcFixAppleBootDevicePathNode() with RestoreContext. Modifying a device path and then restoring a node may lead to lost updates.

Parameters
[in,out]DevicePathA pointer to the device path to restore a node of. May be updated with the previous pool memory buffer.
[in,out]DevicePathNodeA pointer to the device path node to restore. It must be a node of *DevicePath. May be updated with the corresponding node of *DevicePath.
[out]RestoreContextA pointer to a context that was used to call OcFixAppleBootDevicePathNode(). All resources are freed.

Definition at line 211 of file OcDevicePathLib.c.

◆ OcFixAppleBootDevicePathNodeRestoreFree()

VOID OcFixAppleBootDevicePathNodeRestoreFree ( IN CONST EFI_DEVICE_PATH_PROTOCOL * DevicePathNode,
IN OUT APPLE_BOOT_DP_PATCH_CONTEXT * RestoreContext )

Definition at line 283 of file OcDevicePathLib.c.

◆ OcGetNumDevicePathInstances()

UINTN OcGetNumDevicePathInstances ( IN CONST EFI_DEVICE_PATH_PROTOCOL * DevicePath)

Calculate number of device path instances.

Parameters
[in]DevicePathDevice Path to calculate instances in.
Return values
Numberof instances in device path.

Definition at line 1475 of file OcDevicePathLib.c.

◆ TrailedBooterDevicePath()

EFI_DEVICE_PATH_PROTOCOL * TrailedBooterDevicePath ( IN EFI_DEVICE_PATH_PROTOCOL * DevicePath)

Get trailed (slash-appended) device path for booter paths. This way \smth.efi gets NULL and \smth gives \smth\.

Parameters
[in]DevicePathDevice path.
Return values
Newdevice path or NULL.

Definition at line 139 of file OcDevicePathLib.c.