]> git.proxmox.com Git - mirror_edk2.git/blame_incremental - MdePkg/Library/UefiDevicePathLib/UefiDevicePathLib.c
MdePkg: Replace BSD License with BSD+Patent License
[mirror_edk2.git] / MdePkg / Library / UefiDevicePathLib / UefiDevicePathLib.c
... / ...
CommitLineData
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
11 Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>\r
12 SPDX-License-Identifier: BSD-2-Clause-Patent\r
13\r
14**/\r
15\r
16\r
17#include "UefiDevicePathLib.h"\r
18\r
19/**\r
20 Returns the size of a device path in bytes.\r
21\r
22 This function returns the size, in bytes, of the device path data structure\r
23 specified by DevicePath including the end of device path node.\r
24 If DevicePath is NULL or invalid, then 0 is returned.\r
25\r
26 @param DevicePath A pointer to a device path data structure.\r
27\r
28 @retval 0 If DevicePath is NULL or invalid.\r
29 @retval Others The size of a device path in bytes.\r
30\r
31**/\r
32UINTN\r
33EFIAPI\r
34GetDevicePathSize (\r
35 IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath\r
36 )\r
37{\r
38 return UefiDevicePathLibGetDevicePathSize (DevicePath);\r
39}\r
40\r
41/**\r
42 Creates a new copy of an existing device path.\r
43\r
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
51 @param DevicePath A pointer to a device path data structure.\r
52\r
53 @retval NULL DevicePath is NULL or invalid.\r
54 @retval Others A pointer to the duplicated device path.\r
55\r
56**/\r
57EFI_DEVICE_PATH_PROTOCOL *\r
58EFIAPI\r
59DuplicateDevicePath (\r
60 IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath\r
61 )\r
62{\r
63 return UefiDevicePathLibDuplicateDevicePath (DevicePath);\r
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
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
77 If there is not enough memory for the newly allocated buffer, then NULL is returned.\r
78 The memory for the new device path is allocated from EFI boot services memory.\r
79 It is the responsibility of the caller to free the memory allocated.\r
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
83\r
84 @retval NULL If there is not enough memory for the newly allocated buffer.\r
85 @retval NULL If FirstDevicePath or SecondDevicePath is invalid.\r
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
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
97 return UefiDevicePathLibAppendDevicePath (FirstDevicePath, SecondDevicePath);\r
98}\r
99\r
100/**\r
101 Creates a new path by appending the device node to the device path.\r
102\r
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
106 end of the appended device node.\r
107 If DevicePathNode is NULL then a copy of DevicePath is returned.\r
108 If DevicePath is NULL then a copy of DevicePathNode, followed by an end-of-device\r
109 path device node is returned.\r
110 If both DevicePathNode and DevicePath are NULL then a copy of an end-of-device-path\r
111 device node is returned.\r
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
115 of the caller to free the memory allocated.\r
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
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
122 A copy of DevicePathNode followed by an end-of-device-path node\r
123 if both FirstDevicePath and SecondDevicePath are NULL.\r
124 A copy of an end-of-device-path node if both FirstDevicePath\r
125 and SecondDevicePath are NULL.\r
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
135 return UefiDevicePathLibAppendDevicePathNode (DevicePath, DevicePathNode);\r
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
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
144 by DevicePath in a allocated buffer.\r
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
147 If DevicePath is NULL, then a copy if DevicePathInstance is returned.\r
148 If DevicePathInstance is NULL, then NULL is returned.\r
149 If DevicePath or DevicePathInstance is invalid, then NULL is returned.\r
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
153 of the caller to free the memory allocated.\r
154\r
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
168 return UefiDevicePathLibAppendDevicePathInstance (DevicePath, DevicePathInstance);\r
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
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
177 if no more) and updates Size to hold the size of the device path instance copy.\r
178 If DevicePath is NULL, then NULL is returned.\r
179 If DevicePath points to a invalid device path, then NULL is returned.\r
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
183 of the caller to free the memory allocated.\r
184 If Size is NULL, then ASSERT().\r
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
189 or NULL if there are no more device path\r
190 instances in the device path pointer to a\r
191 device path data structure.\r
192 @param Size On output, this holds the size of the device\r
193 path instance, in bytes or zero, if DevicePath\r
194 is NULL.\r
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
206 return UefiDevicePathLibGetNextDevicePathInstance (DevicePath, Size);\r
207}\r
208\r
209/**\r
210 Creates a device node.\r
211\r
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
214 The new device path node is returned.\r
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
219 of the caller to free the memory allocated.\r
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
225 @return The new device path.\r
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
236 return UefiDevicePathLibCreateDeviceNode (NodeType, NodeSubType, NodeLength);\r
237}\r
238\r
239/**\r
240 Determines if a device path is single or multi-instance.\r
241\r
242 This function returns TRUE if the device path specified by DevicePath is\r
243 multi-instance.\r
244 Otherwise, FALSE is returned.\r
245 If DevicePath is NULL or invalid, then FALSE is returned.\r
246\r
247 @param DevicePath A pointer to a device path data structure.\r
248\r
249 @retval TRUE DevicePath is multi-instance.\r
250 @retval FALSE DevicePath is not multi-instance, or DevicePath\r
251 is NULL or invalid.\r
252\r
253**/\r
254BOOLEAN\r
255EFIAPI\r
256IsDevicePathMultiInstance (\r
257 IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath\r
258 )\r
259{\r
260 return UefiDevicePathLibIsDevicePathMultiInstance (DevicePath);\r
261}\r
262\r
263/**\r
264 Converts a device node to its string representation.\r
265\r
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
273\r
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
276\r
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
287}\r
288\r
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
314\r
315/**\r
316 Convert text to the binary representation of a device node.\r
317\r
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
321\r
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
324\r
325**/\r
326EFI_DEVICE_PATH_PROTOCOL *\r
327EFIAPI\r
328ConvertTextToDeviceNode (\r
329 IN CONST CHAR16 *TextDeviceNode\r
330 )\r
331{\r
332 return UefiDevicePathLibConvertTextToDeviceNode (TextDeviceNode);\r
333}\r
334\r
335/**\r
336 Convert text to the binary representation of a device path.\r
337\r
338\r
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
345\r
346**/\r
347EFI_DEVICE_PATH_PROTOCOL *\r
348EFIAPI\r
349ConvertTextToDevicePath (\r
350 IN CONST CHAR16 *TextDevicePath\r
351 )\r
352{\r
353 return UefiDevicePathLibConvertTextToDevicePath (TextDevicePath);\r
354}\r