]> git.proxmox.com Git - mirror_edk2.git/blame - MdePkg/Library/UefiDevicePathLib/UefiDevicePathLib.c
MdePkg: Replace BSD License with BSD+Patent License
[mirror_edk2.git] / MdePkg / Library / UefiDevicePathLib / UefiDevicePathLib.c
CommitLineData
e386b444 1/** @file\r
2 Device Path services. The thing to remember is device paths are built out of\r
3 nodes. The device path is terminated by an end node that is length\r
4 sizeof(EFI_DEVICE_PATH_PROTOCOL). That would be why there is sizeof(EFI_DEVICE_PATH_PROTOCOL)\r
5 all over this file.\r
6\r
7 The only place where multi-instance device paths are supported is in\r
8 environment varibles. Multi-instance device paths should never be placed\r
9 on a Handle.\r
10\r
9095d37b 11 Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>\r
9344f092 12 SPDX-License-Identifier: BSD-2-Clause-Patent\r
e386b444 13\r
e386b444 14**/\r
15\r
c892d846 16\r
4d0a30a4 17#include "UefiDevicePathLib.h"\r
3dc728fb 18\r
e386b444 19/**\r
20 Returns the size of a device path in bytes.\r
21\r
9095d37b 22 This function returns the size, in bytes, of the device path data structure\r
771729c7
RN
23 specified by DevicePath including the end of device path node.\r
24 If DevicePath is NULL or invalid, then 0 is returned.\r
e386b444 25\r
58380e9c 26 @param DevicePath A pointer to a device path data structure.\r
771729c7
RN
27\r
28 @retval 0 If DevicePath is NULL or invalid.\r
58380e9c 29 @retval Others The size of a device path in bytes.\r
e386b444 30\r
31**/\r
32UINTN\r
33EFIAPI\r
34GetDevicePathSize (\r
35 IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath\r
36 )\r
37{\r
4d0a30a4 38 return UefiDevicePathLibGetDevicePathSize (DevicePath);\r
e386b444 39}\r
40\r
41/**\r
6a3f4ef9 42 Creates a new copy of an existing device path.\r
e386b444 43\r
9095d37b
LG
44 This function allocates space for a new copy of the device path specified by DevicePath.\r
45 If DevicePath is NULL, then NULL is returned. If the memory is successfully\r
46 allocated, then the contents of DevicePath are copied to the newly allocated\r
47 buffer, and a pointer to that buffer is returned. Otherwise, NULL is returned.\r
48 The memory for the new device path is allocated from EFI boot services memory.\r
49 It is the responsibility of the caller to free the memory allocated.\r
50\r
58380e9c 51 @param DevicePath A pointer to a device path data structure.\r
e386b444 52\r
771729c7 53 @retval NULL DevicePath is NULL or invalid.\r
58380e9c 54 @retval Others A pointer to the duplicated device path.\r
9095d37b 55\r
e386b444 56**/\r
57EFI_DEVICE_PATH_PROTOCOL *\r
58EFIAPI\r
59DuplicateDevicePath (\r
60 IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath\r
61 )\r
62{\r
4d0a30a4 63 return UefiDevicePathLibDuplicateDevicePath (DevicePath);\r
e386b444 64}\r
65\r
66/**\r
67 Creates a new device path by appending a second device path to a first device path.\r
68\r
9095d37b
LG
69 This function creates a new device path by appending a copy of SecondDevicePath\r
70 to a copy of FirstDevicePath in a newly allocated buffer. Only the end-of-device-path\r
71 device node from SecondDevicePath is retained. The newly created device path is\r
72 returned. If FirstDevicePath is NULL, then it is ignored, and a duplicate of\r
73 SecondDevicePath is returned. If SecondDevicePath is NULL, then it is ignored,\r
74 and a duplicate of FirstDevicePath is returned. If both FirstDevicePath and\r
75 SecondDevicePath are NULL, then a copy of an end-of-device-path is returned.\r
76\r
e386b444 77 If there is not enough memory for the newly allocated buffer, then NULL is returned.\r
9095d37b 78 The memory for the new device path is allocated from EFI boot services memory.\r
58380e9c 79 It is the responsibility of the caller to free the memory allocated.\r
e386b444 80\r
81 @param FirstDevicePath A pointer to a device path data structure.\r
82 @param SecondDevicePath A pointer to a device path data structure.\r
9095d37b 83\r
3e5c3238 84 @retval NULL If there is not enough memory for the newly allocated buffer.\r
771729c7 85 @retval NULL If FirstDevicePath or SecondDevicePath is invalid.\r
3e5c3238 86 @retval Others A pointer to the new device path if success.\r
87 Or a copy an end-of-device-path if both FirstDevicePath and SecondDevicePath are NULL.\r
e386b444 88\r
89**/\r
90EFI_DEVICE_PATH_PROTOCOL *\r
91EFIAPI\r
92AppendDevicePath (\r
93 IN CONST EFI_DEVICE_PATH_PROTOCOL *FirstDevicePath, OPTIONAL\r
94 IN CONST EFI_DEVICE_PATH_PROTOCOL *SecondDevicePath OPTIONAL\r
95 )\r
96{\r
4d0a30a4 97 return UefiDevicePathLibAppendDevicePath (FirstDevicePath, SecondDevicePath);\r
e386b444 98}\r
99\r
100/**\r
101 Creates a new path by appending the device node to the device path.\r
102\r
9095d37b
LG
103 This function creates a new device path by appending a copy of the device node\r
104 specified by DevicePathNode to a copy of the device path specified by DevicePath\r
105 in an allocated buffer. The end-of-device-path device node is moved after the\r
58380e9c 106 end of the appended device node.\r
98a14db6 107 If DevicePathNode is NULL then a copy of DevicePath is returned.\r
9095d37b 108 If DevicePath is NULL then a copy of DevicePathNode, followed by an end-of-device\r
58380e9c 109 path device node is returned.\r
9095d37b 110 If both DevicePathNode and DevicePath are NULL then a copy of an end-of-device-path\r
58380e9c 111 device node is returned.\r
9095d37b
LG
112 If there is not enough memory to allocate space for the new device path, then\r
113 NULL is returned.\r
114 The memory is allocated from EFI boot services memory. It is the responsibility\r
58380e9c 115 of the caller to free the memory allocated.\r
e386b444 116\r
117 @param DevicePath A pointer to a device path data structure.\r
118 @param DevicePathNode A pointer to a single device path node.\r
119\r
3e5c3238 120 @retval NULL If there is not enough memory for the new device path.\r
121 @retval Others A pointer to the new device path if success.\r
9095d37b 122 A copy of DevicePathNode followed by an end-of-device-path node\r
3e5c3238 123 if both FirstDevicePath and SecondDevicePath are NULL.\r
9095d37b 124 A copy of an end-of-device-path node if both FirstDevicePath\r
58380e9c 125 and SecondDevicePath are NULL.\r
e386b444 126\r
127**/\r
128EFI_DEVICE_PATH_PROTOCOL *\r
129EFIAPI\r
130AppendDevicePathNode (\r
131 IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath, OPTIONAL\r
132 IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePathNode OPTIONAL\r
133 )\r
134{\r
4d0a30a4 135 return UefiDevicePathLibAppendDevicePathNode (DevicePath, DevicePathNode);\r
e386b444 136}\r
137\r
138/**\r
139 Creates a new device path by appending the specified device path instance to the specified device\r
140 path.\r
9095d37b
LG
141\r
142 This function creates a new device path by appending a copy of the device path\r
143 instance specified by DevicePathInstance to a copy of the device path specified\r
58380e9c 144 by DevicePath in a allocated buffer.\r
9095d37b
LG
145 The end-of-device-path device node is moved after the end of the appended device\r
146 path instance and a new end-of-device-path-instance node is inserted between.\r
e386b444 147 If DevicePath is NULL, then a copy if DevicePathInstance is returned.\r
148 If DevicePathInstance is NULL, then NULL is returned.\r
771729c7 149 If DevicePath or DevicePathInstance is invalid, then NULL is returned.\r
9095d37b
LG
150 If there is not enough memory to allocate space for the new device path, then\r
151 NULL is returned.\r
152 The memory is allocated from EFI boot services memory. It is the responsibility\r
58380e9c 153 of the caller to free the memory allocated.\r
9095d37b 154\r
e386b444 155 @param DevicePath A pointer to a device path data structure.\r
156 @param DevicePathInstance A pointer to a device path instance.\r
157\r
158 @return A pointer to the new device path.\r
159\r
160**/\r
161EFI_DEVICE_PATH_PROTOCOL *\r
162EFIAPI\r
163AppendDevicePathInstance (\r
164 IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath, OPTIONAL\r
165 IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePathInstance OPTIONAL\r
166 )\r
167{\r
4d0a30a4 168 return UefiDevicePathLibAppendDevicePathInstance (DevicePath, DevicePathInstance);\r
e386b444 169}\r
170\r
171/**\r
172 Creates a copy of the current device path instance and returns a pointer to the next device path\r
173 instance.\r
174\r
9095d37b
LG
175 This function creates a copy of the current device path instance. It also updates\r
176 DevicePath to point to the next device path instance in the device path (or NULL\r
58380e9c 177 if no more) and updates Size to hold the size of the device path instance copy.\r
e386b444 178 If DevicePath is NULL, then NULL is returned.\r
771729c7 179 If DevicePath points to a invalid device path, then NULL is returned.\r
9095d37b
LG
180 If there is not enough memory to allocate space for the new device path, then\r
181 NULL is returned.\r
182 The memory is allocated from EFI boot services memory. It is the responsibility\r
58380e9c 183 of the caller to free the memory allocated.\r
e386b444 184 If Size is NULL, then ASSERT().\r
9095d37b
LG
185\r
186 @param DevicePath On input, this holds the pointer to the current\r
187 device path instance. On output, this holds\r
188 the pointer to the next device path instance\r
58380e9c 189 or NULL if there are no more device path\r
9095d37b 190 instances in the device path pointer to a\r
58380e9c 191 device path data structure.\r
9095d37b
LG
192 @param Size On output, this holds the size of the device\r
193 path instance, in bytes or zero, if DevicePath\r
58380e9c 194 is NULL.\r
e386b444 195\r
196 @return A pointer to the current device path instance.\r
197\r
198**/\r
199EFI_DEVICE_PATH_PROTOCOL *\r
200EFIAPI\r
201GetNextDevicePathInstance (\r
202 IN OUT EFI_DEVICE_PATH_PROTOCOL **DevicePath,\r
203 OUT UINTN *Size\r
204 )\r
205{\r
4d0a30a4 206 return UefiDevicePathLibGetNextDevicePathInstance (DevicePath, Size);\r
e386b444 207}\r
208\r
209/**\r
3e5c3238 210 Creates a device node.\r
e386b444 211\r
9095d37b
LG
212 This function creates a new device node in a newly allocated buffer of size\r
213 NodeLength and initializes the device path node header with NodeType and NodeSubType.\r
58380e9c 214 The new device path node is returned.\r
9095d37b
LG
215 If NodeLength is smaller than a device path header, then NULL is returned.\r
216 If there is not enough memory to allocate space for the new device path, then\r
217 NULL is returned.\r
218 The memory is allocated from EFI boot services memory. It is the responsibility\r
58380e9c 219 of the caller to free the memory allocated.\r
e386b444 220\r
221 @param NodeType The device node type for the new device node.\r
222 @param NodeSubType The device node sub-type for the new device node.\r
223 @param NodeLength The length of the new device node.\r
224\r
3e5c3238 225 @return The new device path.\r
e386b444 226\r
227**/\r
228EFI_DEVICE_PATH_PROTOCOL *\r
229EFIAPI\r
230CreateDeviceNode (\r
231 IN UINT8 NodeType,\r
232 IN UINT8 NodeSubType,\r
233 IN UINT16 NodeLength\r
234 )\r
235{\r
4d0a30a4 236 return UefiDevicePathLibCreateDeviceNode (NodeType, NodeSubType, NodeLength);\r
e386b444 237}\r
238\r
239/**\r
240 Determines if a device path is single or multi-instance.\r
241\r
58380e9c 242 This function returns TRUE if the device path specified by DevicePath is\r
243 multi-instance.\r
771729c7
RN
244 Otherwise, FALSE is returned.\r
245 If DevicePath is NULL or invalid, then FALSE is returned.\r
e386b444 246\r
247 @param DevicePath A pointer to a device path data structure.\r
248\r
249 @retval TRUE DevicePath is multi-instance.\r
9095d37b 250 @retval FALSE DevicePath is not multi-instance, or DevicePath\r
771729c7 251 is NULL or invalid.\r
e386b444 252\r
253**/\r
254BOOLEAN\r
255EFIAPI\r
256IsDevicePathMultiInstance (\r
257 IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath\r
258 )\r
259{\r
4d0a30a4
RN
260 return UefiDevicePathLibIsDevicePathMultiInstance (DevicePath);\r
261}\r
e386b444 262\r
4d0a30a4
RN
263/**\r
264 Converts a device node to its string representation.\r
771729c7 265\r
4d0a30a4
RN
266 @param DeviceNode A Pointer to the device node to be converted.\r
267 @param DisplayOnly If DisplayOnly is TRUE, then the shorter text representation\r
268 of the display node is used, where applicable. If DisplayOnly\r
269 is FALSE, then the longer text representation of the display node\r
270 is used.\r
271 @param AllowShortcuts If AllowShortcuts is TRUE, then the shortcut forms of text\r
272 representation for a device node can be used, where applicable.\r
e386b444 273\r
4d0a30a4
RN
274 @return A pointer to the allocated text representation of the device node or NULL if DeviceNode\r
275 is NULL or there was insufficient memory.\r
e386b444 276\r
4d0a30a4
RN
277**/\r
278CHAR16 *\r
279EFIAPI\r
280ConvertDeviceNodeToText (\r
281 IN CONST EFI_DEVICE_PATH_PROTOCOL *DeviceNode,\r
282 IN BOOLEAN DisplayOnly,\r
283 IN BOOLEAN AllowShortcuts\r
284 )\r
285{\r
286 return UefiDevicePathLibConvertDeviceNodeToText (DeviceNode, DisplayOnly, AllowShortcuts);\r
e386b444 287}\r
288\r
4d0a30a4
RN
289/**\r
290 Converts a device path to its text representation.\r
291\r
292 @param DevicePath A Pointer to the device to be converted.\r
293 @param DisplayOnly If DisplayOnly is TRUE, then the shorter text representation\r
294 of the display node is used, where applicable. If DisplayOnly\r
295 is FALSE, then the longer text representation of the display node\r
296 is used.\r
297 @param AllowShortcuts If AllowShortcuts is TRUE, then the shortcut forms of text\r
298 representation for a device node can be used, where applicable.\r
299\r
300 @return A pointer to the allocated text representation of the device path or\r
301 NULL if DeviceNode is NULL or there was insufficient memory.\r
302\r
303**/\r
304CHAR16 *\r
305EFIAPI\r
306ConvertDevicePathToText (\r
307 IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath,\r
308 IN BOOLEAN DisplayOnly,\r
309 IN BOOLEAN AllowShortcuts\r
310 )\r
311{\r
312 return UefiDevicePathLibConvertDevicePathToText (DevicePath, DisplayOnly, AllowShortcuts);\r
313}\r
e386b444 314\r
315/**\r
4d0a30a4 316 Convert text to the binary representation of a device node.\r
e386b444 317\r
4d0a30a4
RN
318 @param TextDeviceNode TextDeviceNode points to the text representation of a device\r
319 node. Conversion starts with the first character and continues\r
320 until the first non-device node character.\r
e386b444 321\r
4d0a30a4
RN
322 @return A pointer to the EFI device node or NULL if TextDeviceNode is NULL or there was\r
323 insufficient memory or text unsupported.\r
e386b444 324\r
325**/\r
326EFI_DEVICE_PATH_PROTOCOL *\r
327EFIAPI\r
4d0a30a4
RN
328ConvertTextToDeviceNode (\r
329 IN CONST CHAR16 *TextDeviceNode\r
e386b444 330 )\r
331{\r
4d0a30a4 332 return UefiDevicePathLibConvertTextToDeviceNode (TextDeviceNode);\r
e386b444 333}\r
334\r
335/**\r
4d0a30a4 336 Convert text to the binary representation of a device path.\r
e386b444 337\r
e386b444 338\r
4d0a30a4
RN
339 @param TextDevicePath TextDevicePath points to the text representation of a device\r
340 path. Conversion starts with the first character and continues\r
341 until the first non-device node character.\r
342\r
343 @return A pointer to the allocated device path or NULL if TextDeviceNode is NULL or\r
344 there was insufficient memory.\r
e386b444 345\r
346**/\r
347EFI_DEVICE_PATH_PROTOCOL *\r
348EFIAPI\r
4d0a30a4
RN
349ConvertTextToDevicePath (\r
350 IN CONST CHAR16 *TextDevicePath\r
e386b444 351 )\r
352{\r
4d0a30a4 353 return UefiDevicePathLibConvertTextToDevicePath (TextDevicePath);\r
e386b444 354}\r