]> git.proxmox.com Git - mirror_edk2.git/blame - MdePkg/Include/Library/DevicePathLib.h
Grammatical and disclaimer changes (does not follow internal C coding stds.)
[mirror_edk2.git] / MdePkg / Include / Library / DevicePathLib.h
CommitLineData
fb3df220 1/** @file\r
50a64e5b 2 Provides library functions to construct and parse UEFI Device Paths.\r
fb3df220 3\r
d80b2f71 4 This library provides defines, macros, and functions to help create and parse \r
bcdff90d 5 EFI_DEVICE_PATH_PROTOCOL structures.\r
d80b2f71 6\r
af2dc6a7 7Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved<BR>\r
8This program and the accompanying materials are licensed and made available under \r
9the terms and conditions of the BSD License that accompanies this distribution. \r
10The full text of the license may be found at\r
11http://opensource.org/licenses/bsd-license.php.\r
fb3df220 12\r
50a64e5b 13THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
14WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
fb3df220 15\r
fb3df220 16**/\r
17\r
18#ifndef __DEVICE_PATH_LIB_H__\r
19#define __DEVICE_PATH_LIB_H__\r
20\r
e5dab016 21#define END_DEVICE_PATH_LENGTH (sizeof (EFI_DEVICE_PATH_PROTOCOL))\r
d80b2f71 22\r
23/**\r
3dc728fb 24 Returns the Type field of a device path node.\r
d80b2f71 25\r
26 Returns the Type field of the device path node specified by Node.\r
27\r
3dc728fb 28 If Node is NULL, then ASSERT().\r
29\r
d80b2f71 30 @param Node A pointer to a device path node data structure.\r
31\r
32 @return The Type field of the device path node specified by Node.\r
33\r
34**/\r
3dc728fb 35UINT8\r
5cba121d 36EFIAPI\r
3dc728fb 37DevicePathType (\r
38 IN CONST VOID *Node\r
39 );\r
d80b2f71 40\r
41/**\r
3dc728fb 42 Returns the SubType field of a device path node.\r
d80b2f71 43\r
44 Returns the SubType field of the device path node specified by Node.\r
45\r
3dc728fb 46 If Node is NULL, then ASSERT().\r
47\r
d80b2f71 48 @param Node A pointer to a device path node data structure.\r
49\r
50 @return The SubType field of the device path node specified by Node.\r
51\r
52**/\r
3dc728fb 53UINT8\r
5cba121d 54EFIAPI\r
3dc728fb 55DevicePathSubType (\r
56 IN CONST VOID *Node\r
57 );\r
d80b2f71 58\r
59/**\r
3dc728fb 60 Returns the 16-bit Length field of a device path node.\r
d80b2f71 61\r
3dc728fb 62 Returns the 16-bit Length field of the device path node specified by Node. \r
63 Node is not required to be aligned on a 16-bit boundary, so it is recommended\r
64 that a function such as ReadUnaligned16() be used to extract the contents of \r
65 the Length field.\r
66\r
67 If Node is NULL, then ASSERT().\r
d80b2f71 68\r
69 @param Node A pointer to a device path node data structure.\r
70\r
71 @return The 16-bit Length field of the device path node specified by Node.\r
72\r
73**/\r
3dc728fb 74UINTN\r
5cba121d 75EFIAPI\r
3dc728fb 76DevicePathNodeLength (\r
77 IN CONST VOID *Node\r
78 );\r
d80b2f71 79\r
80/**\r
3dc728fb 81 Returns a pointer to the next node in a device path.\r
d80b2f71 82\r
83 Returns a pointer to the device path node that follows the device path node specified by Node.\r
84\r
3dc728fb 85 If Node is NULL, then ASSERT().\r
86\r
d80b2f71 87 @param Node A pointer to a device path node data structure.\r
88\r
89 @return a pointer to the device path node that follows the device path node specified by Node.\r
90\r
91**/\r
3dc728fb 92EFI_DEVICE_PATH_PROTOCOL *\r
5cba121d 93EFIAPI\r
3dc728fb 94NextDevicePathNode (\r
95 IN CONST VOID *Node\r
96 );\r
d80b2f71 97\r
98/**\r
3dc728fb 99 Determines if a device path node is an end node of a device path.\r
af2dc6a7 100 This includes nodes that are the end of a device path instance and nodes that \r
101 are the end of an entire device path.\r
d80b2f71 102\r
103 Determines if the device path node specified by Node is an end node of a device path. \r
104 This includes nodes that are the end of a device path instance and nodes that are the \r
105 end of an entire device path. If Node represents an end node of a device path, \r
106 then TRUE is returned. Otherwise, FALSE is returned.\r
107\r
3dc728fb 108 If Node is NULL, then ASSERT().\r
109\r
d80b2f71 110 @param Node A pointer to a device path node data structure.\r
111\r
112 @retval TRUE The device path node specified by Node is an end node of a device path.\r
113 @retval FALSE The device path node specified by Node is not an end node of a device path.\r
114 \r
115**/\r
3dc728fb 116BOOLEAN\r
5cba121d 117EFIAPI\r
3dc728fb 118IsDevicePathEndType (\r
119 IN CONST VOID *Node\r
120 );\r
d80b2f71 121\r
122/**\r
3dc728fb 123 Determines if a device path node is an end node of an entire device path.\r
d80b2f71 124\r
125 Determines if a device path node specified by Node is an end node of an entire device path.\r
126 If Node represents the end of an entire device path, then TRUE is returned. Otherwise, FALSE is returned.\r
127\r
3dc728fb 128 If Node is NULL, then ASSERT().\r
129\r
d80b2f71 130 @param Node A pointer to a device path node data structure.\r
131\r
132 @retval TRUE The device path node specified by Node is the end of an entire device path.\r
133 @retval FALSE The device path node specified by Node is not the end of an entire device path.\r
134\r
135**/\r
3dc728fb 136BOOLEAN\r
5cba121d 137EFIAPI\r
3dc728fb 138IsDevicePathEnd (\r
139 IN CONST VOID *Node\r
140 );\r
d80b2f71 141\r
142/**\r
3dc728fb 143 Determines if a device path node is an end node of a device path instance.\r
d80b2f71 144\r
145 Determines if a device path node specified by Node is an end node of a device path instance.\r
146 If Node represents the end of a device path instance, then TRUE is returned. Otherwise, FALSE is returned.\r
147\r
3dc728fb 148 If Node is NULL, then ASSERT().\r
149\r
d80b2f71 150 @param Node A pointer to a device path node data structure.\r
151\r
152 @retval TRUE The device path node specified by Node is the end of a device path instance.\r
153 @retval FALSE The device path node specified by Node is not the end of a device path instance.\r
154\r
155**/\r
3dc728fb 156BOOLEAN\r
5cba121d 157EFIAPI\r
3dc728fb 158IsDevicePathEndInstance (\r
159 IN CONST VOID *Node\r
160 );\r
e5dab016 161\r
d80b2f71 162/**\r
3dc728fb 163 Sets the length, in bytes, of a device path node.\r
164\r
165 Sets the length of the device path node specified by Node to the value specified \r
166 by NodeLength. NodeLength is returned. Node is not required to be aligned on \r
167 a 16-bit boundary, so it is recommended that a function such as WriteUnaligned16()\r
168 be used to set the contents of the Length field.\r
d80b2f71 169\r
3dc728fb 170 If Node is NULL, then ASSERT().\r
171 If NodeLength >= 0x10000, then ASSERT().\r
d80b2f71 172\r
173 @param Node A pointer to a device path node data structure.\r
174 @param Length The length, in bytes, of the device path node.\r
175\r
176 @return Length\r
177\r
178**/\r
3dc728fb 179UINT16\r
5cba121d 180EFIAPI\r
3dc728fb 181SetDevicePathNodeLength (\r
9bb407c6 182 IN OUT VOID *Node,\r
183 IN UINTN Length\r
3dc728fb 184 );\r
d80b2f71 185\r
186/**\r
3dc728fb 187 Fills in all the fields of a device path node that is the end of an entire device path.\r
d80b2f71 188\r
3dc728fb 189 Fills in all the fields of a device path node specified by Node so Node represents \r
190 the end of an entire device path. The Type field of Node is set to \r
191 END_DEVICE_PATH_TYPE, the SubType field of Node is set to \r
192 END_ENTIRE_DEVICE_PATH_SUBTYPE, and the Length field of Node is set to \r
193 END_DEVICE_PATH_LENGTH. Node is not required to be aligned on a 16-bit boundary, \r
194 so it is recommended that a function such as WriteUnaligned16() be used to set \r
195 the contents of the Length field. \r
196\r
197 If Node is NULL, then ASSERT(). \r
d80b2f71 198\r
199 @param Node A pointer to a device path node data structure.\r
200\r
201**/\r
3dc728fb 202VOID\r
5cba121d 203EFIAPI\r
3dc728fb 204SetDevicePathEndNode (\r
9bb407c6 205 OUT VOID *Node\r
3dc728fb 206 );\r
e5dab016 207\r
fb3df220 208/**\r
209 Returns the size of a device path in bytes.\r
210\r
211 This function returns the size, in bytes, of the device path data structure specified by\r
212 DevicePath including the end of device path node. If DevicePath is NULL, then 0 is returned.\r
213\r
214 @param DevicePath A pointer to a device path data structure.\r
d80b2f71 215 \r
af2dc6a7 216 @retval 0 DevicePath is NULL.\r
d80b2f71 217 @retval Others The size of a device path in bytes.\r
fb3df220 218\r
219**/\r
220UINTN\r
221EFIAPI\r
222GetDevicePathSize (\r
223 IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath\r
224 );\r
225\r
226/**\r
bc7e6003 227 Creates a new copy of an existing device path.\r
fb3df220 228\r
229 This function allocates space for a new copy of the device path specified by DevicePath. If\r
230 DevicePath is NULL, then NULL is returned. If the memory is successfully allocated, then the\r
231 contents of DevicePath are copied to the newly allocated buffer, and a pointer to that buffer\r
232 is returned. Otherwise, NULL is returned. \r
d80b2f71 233 The memory for the new device path is allocated from EFI boot services memory. \r
234 It is the responsibility of the caller to free the memory allocated. \r
fb3df220 235 \r
236 @param DevicePath A pointer to a device path data structure.\r
237\r
af2dc6a7 238 @retval NULL DevicePath is NULL.\r
d80b2f71 239 @retval Others A pointer to the duplicated device path.\r
240 \r
fb3df220 241**/\r
242EFI_DEVICE_PATH_PROTOCOL *\r
243EFIAPI\r
244DuplicateDevicePath (\r
245 IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath\r
246 );\r
247\r
248/**\r
249 Creates a new device path by appending a second device path to a first device path.\r
250\r
251 This function creates a new device path by appending a copy of SecondDevicePath to a copy of\r
252 FirstDevicePath in a newly allocated buffer. Only the end-of-device-path device node from\r
253 SecondDevicePath is retained. The newly created device path is returned. \r
254 If FirstDevicePath is NULL, then it is ignored, and a duplicate of SecondDevicePath is returned. \r
255 If SecondDevicePath is NULL, then it is ignored, and a duplicate of FirstDevicePath is returned. \r
98a14db6 256 If both FirstDevicePath and SecondDevicePath are NULL, then a copy of an end-of-device-path is\r
257 returned. \r
fb3df220 258 If there is not enough memory for the newly allocated buffer, then NULL is returned.\r
259 The memory for the new device path is allocated from EFI boot services memory. It is the\r
260 responsibility of the caller to free the memory allocated.\r
261\r
262 @param FirstDevicePath A pointer to a device path data structure.\r
263 @param SecondDevicePath A pointer to a device path data structure.\r
d80b2f71 264 \r
265 @retval NULL If there is not enough memory for the newly allocated buffer.\r
266 @retval Others A pointer to the new device path if success.\r
267 Or a copy an end-of-device-path if both FirstDevicePath and SecondDevicePath are NULL.\r
fb3df220 268\r
269**/\r
270EFI_DEVICE_PATH_PROTOCOL *\r
271EFIAPI\r
272AppendDevicePath (\r
273 IN CONST EFI_DEVICE_PATH_PROTOCOL *FirstDevicePath, OPTIONAL\r
274 IN CONST EFI_DEVICE_PATH_PROTOCOL *SecondDevicePath OPTIONAL\r
275 );\r
276\r
277/**\r
278 Creates a new path by appending the device node to the device path.\r
279\r
280 This function creates a new device path by appending a copy of the device node specified by\r
281 DevicePathNode to a copy of the device path specified by DevicePath in an allocated buffer.\r
282 The end-of-device-path device node is moved after the end of the appended device node.\r
98a14db6 283 If DevicePathNode is NULL then a copy of DevicePath is returned.\r
6336a895 284 If DevicePath is NULL then a copy of DevicePathNode, followed by an end-of-device path device\r
285 node is returned.\r
98a14db6 286 If both DevicePathNode and DevicePath are NULL then a copy of an end-of-device-path device node\r
287 is returned.\r
fb3df220 288 If there is not enough memory to allocate space for the new device path, then NULL is returned. \r
289 The memory is allocated from EFI boot services memory. It is the responsibility of the caller to\r
290 free the memory allocated.\r
291\r
292 @param DevicePath A pointer to a device path data structure.\r
293 @param DevicePathNode A pointer to a single device path node.\r
294\r
af2dc6a7 295 @retval NULL There is not enough memory for the new device path.\r
d80b2f71 296 @retval Others A pointer to the new device path if success.\r
297 A copy of DevicePathNode followed by an end-of-device-path node \r
298 if both FirstDevicePath and SecondDevicePath are NULL.\r
299 A copy of an end-of-device-path node if both FirstDevicePath and SecondDevicePath are NULL.\r
fb3df220 300\r
301**/\r
302EFI_DEVICE_PATH_PROTOCOL *\r
303EFIAPI\r
304AppendDevicePathNode (\r
305 IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath, OPTIONAL\r
306 IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePathNode OPTIONAL\r
307 );\r
308\r
309/**\r
310 Creates a new device path by appending the specified device path instance to the specified device\r
311 path.\r
312 \r
313 This function creates a new device path by appending a copy of the device path instance specified\r
314 by DevicePathInstance to a copy of the device path secified by DevicePath in a allocated buffer.\r
315 The end-of-device-path device node is moved after the end of the appended device path instance\r
316 and a new end-of-device-path-instance node is inserted between. \r
317 If DevicePath is NULL, then a copy if DevicePathInstance is returned.\r
318 If DevicePathInstance is NULL, then NULL is returned.\r
319 If there is not enough memory to allocate space for the new device path, then NULL is returned. \r
320 The memory is allocated from EFI boot services memory. It is the responsibility of the caller to\r
321 free the memory allocated.\r
322 \r
323 @param DevicePath A pointer to a device path data structure.\r
324 @param DevicePathInstance A pointer to a device path instance.\r
325\r
326 @return A pointer to the new device path.\r
327\r
328**/\r
329EFI_DEVICE_PATH_PROTOCOL *\r
330EFIAPI\r
331AppendDevicePathInstance (\r
332 IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath, OPTIONAL\r
333 IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePathInstance OPTIONAL\r
334 );\r
335\r
336/**\r
337 Creates a copy of the current device path instance and returns a pointer to the next device path\r
338 instance.\r
339\r
340 This function creates a copy of the current device path instance. It also updates DevicePath to\r
341 point to the next device path instance in the device path (or NULL if no more) and updates Size\r
342 to hold the size of the device path instance copy.\r
343 If DevicePath is NULL, then NULL is returned.\r
344 If there is not enough memory to allocate space for the new device path, then NULL is returned. \r
345 The memory is allocated from EFI boot services memory. It is the responsibility of the caller to\r
346 free the memory allocated.\r
347 If Size is NULL, then ASSERT().\r
348 \r
349 @param DevicePath On input, this holds the pointer to the current device path\r
350 instance. On output, this holds the pointer to the next device\r
351 path instance or NULL if there are no more device path\r
352 instances in the device path pointer to a device path data\r
353 structure.\r
354 @param Size On output, this holds the size of the device path instance, in\r
355 bytes or zero, if DevicePath is NULL.\r
356\r
357 @return A pointer to the current device path instance.\r
358\r
359**/\r
360EFI_DEVICE_PATH_PROTOCOL *\r
361EFIAPI\r
362GetNextDevicePathInstance (\r
363 IN OUT EFI_DEVICE_PATH_PROTOCOL **DevicePath,\r
364 OUT UINTN *Size\r
365 );\r
366\r
367/**\r
d80b2f71 368 Creates a device node.\r
fb3df220 369\r
370 This function creates a new device node in a newly allocated buffer of size NodeLength and\r
371 initializes the device path node header with NodeType and NodeSubType. The new device path node\r
372 is returned.\r
373 If NodeLength is smaller than a device path header, then NULL is returned. \r
374 If there is not enough memory to allocate space for the new device path, then NULL is returned. \r
375 The memory is allocated from EFI boot services memory. It is the responsibility of the caller to\r
376 free the memory allocated.\r
377\r
378 @param NodeType The device node type for the new device node.\r
379 @param NodeSubType The device node sub-type for the new device node.\r
380 @param NodeLength The length of the new device node.\r
381\r
382 @return The new device path.\r
383\r
384**/\r
385EFI_DEVICE_PATH_PROTOCOL *\r
386EFIAPI\r
387CreateDeviceNode (\r
388 IN UINT8 NodeType,\r
389 IN UINT8 NodeSubType,\r
390 IN UINT16 NodeLength\r
391 );\r
392\r
393/**\r
394 Determines if a device path is single or multi-instance.\r
395\r
396 This function returns TRUE if the device path specified by DevicePath is multi-instance.\r
397 Otherwise, FALSE is returned. If DevicePath is NULL, then FALSE is returned.\r
398\r
399 @param DevicePath A pointer to a device path data structure.\r
400\r
401 @retval TRUE DevicePath is multi-instance.\r
af2dc6a7 402 @retval FALSE DevicePath is not multi-instance, or DevicePath is NULL.\r
fb3df220 403\r
404**/\r
405BOOLEAN\r
406EFIAPI\r
407IsDevicePathMultiInstance (\r
408 IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath\r
409 );\r
410\r
411/**\r
412 Retrieves the device path protocol from a handle.\r
413\r
414 This function returns the device path protocol from the handle specified by Handle. If Handle is\r
415 NULL or Handle does not contain a device path protocol, then NULL is returned.\r
416 \r
417 @param Handle The handle from which to retrieve the device path protocol.\r
418\r
419 @return The device path protocol from the handle specified by Handle.\r
420\r
421**/\r
422EFI_DEVICE_PATH_PROTOCOL *\r
423EFIAPI\r
424DevicePathFromHandle (\r
425 IN EFI_HANDLE Handle\r
426 );\r
427\r
428/**\r
429 Allocates a device path for a file and appends it to an existing device path.\r
430\r
431 If Device is a valid device handle that contains a device path protocol, then a device path for\r
432 the file specified by FileName is allocated and appended to the device path associated with the\r
433 handle Device. The allocated device path is returned. If Device is NULL or Device is a handle\r
434 that does not support the device path protocol, then a device path containing a single device\r
435 path node for the file specified by FileName is allocated and returned.\r
d80b2f71 436 The memory for the new device path is allocated from EFI boot services memory. It is the responsibility\r
437 of the caller to free the memory allocated.\r
438 \r
fb3df220 439 If FileName is NULL, then ASSERT().\r
d80b2f71 440 If FileName is not aligned on a 16-bit boundary, then ASSERT().\r
fb3df220 441\r
442 @param Device A pointer to a device handle. This parameter is optional and\r
443 may be NULL.\r
444 @param FileName A pointer to a Null-terminated Unicode string.\r
445\r
446 @return The allocated device path.\r
447\r
448**/\r
449EFI_DEVICE_PATH_PROTOCOL *\r
450EFIAPI\r
451FileDevicePath (\r
452 IN EFI_HANDLE Device, OPTIONAL\r
453 IN CONST CHAR16 *FileName\r
454 );\r
455\r
456#endif\r