Path: blob/main/sys/contrib/edk2/Include/Library/DevicePathLib.h
48383 views
/** @file1Provides library functions to construct and parse UEFI Device Paths.23This library provides defines, macros, and functions to help create and parse4EFI_DEVICE_PATH_PROTOCOL structures.56Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>7SPDX-License-Identifier: BSD-2-Clause-Patent89**/1011#ifndef __DEVICE_PATH_LIB_H__12#define __DEVICE_PATH_LIB_H__1314#define END_DEVICE_PATH_LENGTH (sizeof (EFI_DEVICE_PATH_PROTOCOL))1516/**17Determine whether a given device path is valid.1819@param DevicePath A pointer to a device path data structure.20@param MaxSize The maximum size of the device path data structure.2122@retval TRUE DevicePath is valid.23@retval FALSE DevicePath is NULL.24@retval FALSE Maxsize is less than sizeof(EFI_DEVICE_PATH_PROTOCOL).25@retval FALSE The length of any node node in the DevicePath is less26than sizeof (EFI_DEVICE_PATH_PROTOCOL).27@retval FALSE If MaxSize is not zero, the size of the DevicePath28exceeds MaxSize.29@retval FALSE If PcdMaximumDevicePathNodeCount is not zero, the node30count of the DevicePath exceeds PcdMaximumDevicePathNodeCount.31**/32BOOLEAN33EFIAPI34IsDevicePathValid (35IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath,36IN UINTN MaxSize37);3839/**40Returns the Type field of a device path node.4142Returns the Type field of the device path node specified by Node.4344If Node is NULL, then ASSERT().4546@param Node A pointer to a device path node data structure.4748@return The Type field of the device path node specified by Node.4950**/51UINT852EFIAPI53DevicePathType (54IN CONST VOID *Node55);5657/**58Returns the SubType field of a device path node.5960Returns the SubType field of the device path node specified by Node.6162If Node is NULL, then ASSERT().6364@param Node A pointer to a device path node data structure.6566@return The SubType field of the device path node specified by Node.6768**/69UINT870EFIAPI71DevicePathSubType (72IN CONST VOID *Node73);7475/**76Returns the 16-bit Length field of a device path node.7778Returns the 16-bit Length field of the device path node specified by Node.79Node is not required to be aligned on a 16-bit boundary, so it is recommended80that a function such as ReadUnaligned16() be used to extract the contents of81the Length field.8283If Node is NULL, then ASSERT().8485@param Node A pointer to a device path node data structure.8687@return The 16-bit Length field of the device path node specified by Node.8889**/90UINTN91EFIAPI92DevicePathNodeLength (93IN CONST VOID *Node94);9596/**97Returns a pointer to the next node in a device path.9899Returns a pointer to the device path node that follows the device path node specified by Node.100101If Node is NULL, then ASSERT().102103@param Node A pointer to a device path node data structure.104105@return a pointer to the device path node that follows the device path node specified by Node.106107**/108EFI_DEVICE_PATH_PROTOCOL *109EFIAPI110NextDevicePathNode (111IN CONST VOID *Node112);113114/**115Determines if a device path node is an end node of a device path.116This includes nodes that are the end of a device path instance and nodes that117are the end of an entire device path.118119Determines if the device path node specified by Node is an end node of a device path.120This includes nodes that are the end of a device path instance and nodes that are the121end of an entire device path. If Node represents an end node of a device path,122then TRUE is returned. Otherwise, FALSE is returned.123124If Node is NULL, then ASSERT().125126@param Node A pointer to a device path node data structure.127128@retval TRUE The device path node specified by Node is an end node of a device path.129@retval FALSE The device path node specified by Node is not an end node of a device path.130131**/132BOOLEAN133EFIAPI134IsDevicePathEndType (135IN CONST VOID *Node136);137138/**139Determines if a device path node is an end node of an entire device path.140141Determines if a device path node specified by Node is an end node of an entire device path.142If Node represents the end of an entire device path, then TRUE is returned.143Otherwise, FALSE is returned.144145If Node is NULL, then ASSERT().146147@param Node A pointer to a device path node data structure.148149@retval TRUE The device path node specified by Node is the end of an entire device path.150@retval FALSE The device path node specified by Node is not the end of an entire device path.151152**/153BOOLEAN154EFIAPI155IsDevicePathEnd (156IN CONST VOID *Node157);158159/**160Determines if a device path node is an end node of a device path instance.161162Determines if a device path node specified by Node is an end node of a device path instance.163If Node represents the end of a device path instance, then TRUE is returned.164Otherwise, FALSE is returned.165166If Node is NULL, then ASSERT().167168@param Node A pointer to a device path node data structure.169170@retval TRUE The device path node specified by Node is the end of a device path instance.171@retval FALSE The device path node specified by Node is not the end of a device path instance.172173**/174BOOLEAN175EFIAPI176IsDevicePathEndInstance (177IN CONST VOID *Node178);179180/**181Sets the length, in bytes, of a device path node.182183Sets the length of the device path node specified by Node to the value specified184by NodeLength. NodeLength is returned. Node is not required to be aligned on185a 16-bit boundary, so it is recommended that a function such as WriteUnaligned16()186be used to set the contents of the Length field.187188If Node is NULL, then ASSERT().189If NodeLength >= 0x10000, then ASSERT().190If NodeLength < sizeof (EFI_DEVICE_PATH_PROTOCOL), then ASSERT().191192@param Node A pointer to a device path node data structure.193@param Length The length, in bytes, of the device path node.194195@return Length196197**/198UINT16199EFIAPI200SetDevicePathNodeLength (201IN OUT VOID *Node,202IN UINTN Length203);204205/**206Fills in all the fields of a device path node that is the end of an entire device path.207208Fills in all the fields of a device path node specified by Node so Node represents209the end of an entire device path. The Type field of Node is set to210END_DEVICE_PATH_TYPE, the SubType field of Node is set to211END_ENTIRE_DEVICE_PATH_SUBTYPE, and the Length field of Node is set to212END_DEVICE_PATH_LENGTH. Node is not required to be aligned on a 16-bit boundary,213so it is recommended that a function such as WriteUnaligned16() be used to set214the contents of the Length field.215216If Node is NULL, then ASSERT().217218@param Node A pointer to a device path node data structure.219220**/221VOID222EFIAPI223SetDevicePathEndNode (224OUT VOID *Node225);226227/**228Returns the size of a device path in bytes.229230This function returns the size, in bytes, of the device path data structure231specified by DevicePath including the end of device path node.232If DevicePath is NULL or invalid, then 0 is returned.233234@param DevicePath A pointer to a device path data structure.235236@retval 0 If DevicePath is NULL or invalid.237@retval Others The size of a device path in bytes.238239**/240UINTN241EFIAPI242GetDevicePathSize (243IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath244);245246/**247Creates a new copy of an existing device path.248249This function allocates space for a new copy of the device path specified by DevicePath. If250DevicePath is NULL, then NULL is returned. If the memory is successfully allocated, then the251contents of DevicePath are copied to the newly allocated buffer, and a pointer to that buffer252is returned. Otherwise, NULL is returned.253The memory for the new device path is allocated from EFI boot services memory.254It is the responsibility of the caller to free the memory allocated.255256@param DevicePath A pointer to a device path data structure.257258@retval NULL DevicePath is NULL or invalid.259@retval Others A pointer to the duplicated device path.260261**/262EFI_DEVICE_PATH_PROTOCOL *263EFIAPI264DuplicateDevicePath (265IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath266);267268/**269Creates a new device path by appending a second device path to a first device path.270271This function creates a new device path by appending a copy of SecondDevicePath to a copy of272FirstDevicePath in a newly allocated buffer. Only the end-of-device-path device node from273SecondDevicePath is retained. The newly created device path is returned.274If FirstDevicePath is NULL, then it is ignored, and a duplicate of SecondDevicePath is returned.275If SecondDevicePath is NULL, then it is ignored, and a duplicate of FirstDevicePath is returned.276If both FirstDevicePath and SecondDevicePath are NULL, then a copy of an end-of-device-path is277returned.278If there is not enough memory for the newly allocated buffer, then NULL is returned.279The memory for the new device path is allocated from EFI boot services memory. It is the280responsibility of the caller to free the memory allocated.281282@param FirstDevicePath A pointer to a device path data structure.283@param SecondDevicePath A pointer to a device path data structure.284285@retval NULL If there is not enough memory for the newly allocated buffer.286@retval NULL If FirstDevicePath or SecondDevicePath is invalid.287@retval Others A pointer to the new device path if success.288Or a copy an end-of-device-path if both FirstDevicePath and SecondDevicePath are NULL.289290**/291EFI_DEVICE_PATH_PROTOCOL *292EFIAPI293AppendDevicePath (294IN CONST EFI_DEVICE_PATH_PROTOCOL *FirstDevicePath OPTIONAL,295IN CONST EFI_DEVICE_PATH_PROTOCOL *SecondDevicePath OPTIONAL296);297298/**299Creates a new path by appending the device node to the device path.300301This function creates a new device path by appending a copy of the device node specified by302DevicePathNode to a copy of the device path specified by DevicePath in an allocated buffer.303The end-of-device-path device node is moved after the end of the appended device node.304If DevicePathNode is NULL then a copy of DevicePath is returned.305If DevicePath is NULL then a copy of DevicePathNode, followed by an end-of-device path device306node is returned.307If both DevicePathNode and DevicePath are NULL then a copy of an end-of-device-path device node308is returned.309If there is not enough memory to allocate space for the new device path, then NULL is returned.310The memory is allocated from EFI boot services memory. It is the responsibility of the caller to311free the memory allocated.312313@param DevicePath A pointer to a device path data structure.314@param DevicePathNode A pointer to a single device path node.315316@retval NULL There is not enough memory for the new device path.317@retval Others A pointer to the new device path if success.318A copy of DevicePathNode followed by an end-of-device-path node319if both FirstDevicePath and SecondDevicePath are NULL.320A copy of an end-of-device-path node if both FirstDevicePath and SecondDevicePath are NULL.321322**/323EFI_DEVICE_PATH_PROTOCOL *324EFIAPI325AppendDevicePathNode (326IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath OPTIONAL,327IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePathNode OPTIONAL328);329330/**331Creates a new device path by appending the specified device path instance to the specified device332path.333334This function creates a new device path by appending a copy of the device path instance specified335by DevicePathInstance to a copy of the device path secified by DevicePath in a allocated buffer.336The end-of-device-path device node is moved after the end of the appended device path instance337and a new end-of-device-path-instance node is inserted between.338If DevicePath is NULL, then a copy if DevicePathInstance is returned.339If DevicePathInstance is NULL, then NULL is returned.340If DevicePath or DevicePathInstance is invalid, then NULL is returned.341If there is not enough memory to allocate space for the new device path, then NULL is returned.342The memory is allocated from EFI boot services memory. It is the responsibility of the caller to343free the memory allocated.344345@param DevicePath A pointer to a device path data structure.346@param DevicePathInstance A pointer to a device path instance.347348@return A pointer to the new device path.349350**/351EFI_DEVICE_PATH_PROTOCOL *352EFIAPI353AppendDevicePathInstance (354IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath OPTIONAL,355IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePathInstance OPTIONAL356);357358/**359Creates a copy of the current device path instance and returns a pointer to the next device path360instance.361362This function creates a copy of the current device path instance. It also updates DevicePath to363point to the next device path instance in the device path (or NULL if no more) and updates Size364to hold the size of the device path instance copy.365If DevicePath is NULL, then NULL is returned.366If DevicePath points to a invalid device path, then NULL is returned.367If there is not enough memory to allocate space for the new device path, then NULL is returned.368The memory is allocated from EFI boot services memory. It is the responsibility of the caller to369free the memory allocated.370If Size is NULL, then ASSERT().371372@param DevicePath On input, this holds the pointer to the current device path373instance. On output, this holds the pointer to the next device374path instance or NULL if there are no more device path375instances in the device path pointer to a device path data376structure.377@param Size On output, this holds the size of the device path instance, in378bytes or zero, if DevicePath is NULL.379380@return A pointer to the current device path instance.381382**/383EFI_DEVICE_PATH_PROTOCOL *384EFIAPI385GetNextDevicePathInstance (386IN OUT EFI_DEVICE_PATH_PROTOCOL **DevicePath,387OUT UINTN *Size388);389390/**391Creates a device node.392393This function creates a new device node in a newly allocated buffer of size NodeLength and394initializes the device path node header with NodeType and NodeSubType. The new device path node395is returned.396If NodeLength is smaller than a device path header, then NULL is returned.397If there is not enough memory to allocate space for the new device path, then NULL is returned.398The memory is allocated from EFI boot services memory. It is the responsibility of the caller to399free the memory allocated.400401@param NodeType The device node type for the new device node.402@param NodeSubType The device node sub-type for the new device node.403@param NodeLength The length of the new device node.404405@return The new device path.406407**/408EFI_DEVICE_PATH_PROTOCOL *409EFIAPI410CreateDeviceNode (411IN UINT8 NodeType,412IN UINT8 NodeSubType,413IN UINT16 NodeLength414);415416/**417Determines if a device path is single or multi-instance.418419This function returns TRUE if the device path specified by DevicePath is multi-instance.420Otherwise, FALSE is returned.421If DevicePath is NULL or invalid, then FALSE is returned.422423@param DevicePath A pointer to a device path data structure.424425@retval TRUE DevicePath is multi-instance.426@retval FALSE DevicePath is not multi-instance, or DevicePath is NULL or invalid.427428**/429BOOLEAN430EFIAPI431IsDevicePathMultiInstance (432IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath433);434435/**436Retrieves the device path protocol from a handle.437438This function returns the device path protocol from the handle specified by Handle. If Handle is439NULL or Handle does not contain a device path protocol, then NULL is returned.440441@param Handle The handle from which to retrieve the device path protocol.442443@return The device path protocol from the handle specified by Handle.444445**/446EFI_DEVICE_PATH_PROTOCOL *447EFIAPI448DevicePathFromHandle (449IN EFI_HANDLE Handle450);451452/**453Allocates a device path for a file and appends it to an existing device path.454455If Device is a valid device handle that contains a device path protocol, then a device path for456the file specified by FileName is allocated and appended to the device path associated with the457handle Device. The allocated device path is returned. If Device is NULL or Device is a handle458that does not support the device path protocol, then a device path containing a single device459path node for the file specified by FileName is allocated and returned.460The memory for the new device path is allocated from EFI boot services memory. It is the responsibility461of the caller to free the memory allocated.462463If FileName is NULL, then ASSERT().464If FileName is not aligned on a 16-bit boundary, then ASSERT().465466@param Device A pointer to a device handle. This parameter is optional and467may be NULL.468@param FileName A pointer to a Null-terminated Unicode string.469470@return The allocated device path.471472**/473EFI_DEVICE_PATH_PROTOCOL *474EFIAPI475FileDevicePath (476IN EFI_HANDLE Device OPTIONAL,477IN CONST CHAR16 *FileName478);479480/**481Converts a device path to its text representation.482483@param DevicePath A Pointer to the device to be converted.484@param DisplayOnly If DisplayOnly is TRUE, then the shorter text representation485of the display node is used, where applicable. If DisplayOnly486is FALSE, then the longer text representation of the display node487is used.488@param AllowShortcuts If AllowShortcuts is TRUE, then the shortcut forms of text489representation for a device node can be used, where applicable.490491@return A pointer to the allocated text representation of the device path or492NULL if DeviceNode is NULL or there was insufficient memory.493494**/495CHAR16 *496EFIAPI497ConvertDevicePathToText (498IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath,499IN BOOLEAN DisplayOnly,500IN BOOLEAN AllowShortcuts501);502503/**504Converts a device node to its string representation.505506@param DeviceNode A Pointer to the device node to be converted.507@param DisplayOnly If DisplayOnly is TRUE, then the shorter text representation508of the display node is used, where applicable. If DisplayOnly509is FALSE, then the longer text representation of the display node510is used.511@param AllowShortcuts If AllowShortcuts is TRUE, then the shortcut forms of text512representation for a device node can be used, where applicable.513514@return A pointer to the allocated text representation of the device node or NULL if DeviceNode515is NULL or there was insufficient memory.516517**/518CHAR16 *519EFIAPI520ConvertDeviceNodeToText (521IN CONST EFI_DEVICE_PATH_PROTOCOL *DeviceNode,522IN BOOLEAN DisplayOnly,523IN BOOLEAN AllowShortcuts524);525526/**527Convert text to the binary representation of a device node.528529@param TextDeviceNode TextDeviceNode points to the text representation of a device530node. Conversion starts with the first character and continues531until the first non-device node character.532533@return A pointer to the EFI device node or NULL if TextDeviceNode is NULL or there was534insufficient memory or text unsupported.535536**/537EFI_DEVICE_PATH_PROTOCOL *538EFIAPI539ConvertTextToDeviceNode (540IN CONST CHAR16 *TextDeviceNode541);542543/**544Convert text to the binary representation of a device path.545546@param TextDevicePath TextDevicePath points to the text representation of a device547path. Conversion starts with the first character and continues548until the first non-device node character.549550@return A pointer to the allocated device path or NULL if TextDeviceNode is NULL or551there was insufficient memory.552553**/554EFI_DEVICE_PATH_PROTOCOL *555EFIAPI556ConvertTextToDevicePath (557IN CONST CHAR16 *TextDevicePath558);559560#endif561562563