]> git.proxmox.com Git - mirror_edk2.git/blame_incremental - 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
1/** @file\r
2 Provides library functions to construct and parse UEFI Device Paths.\r
3\r
4 This library provides defines, macros, and functions to help create and parse \r
5 EFI_DEVICE_PATH_PROTOCOL structures.\r
6\r
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
12\r
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
15\r
16**/\r
17\r
18#ifndef __DEVICE_PATH_LIB_H__\r
19#define __DEVICE_PATH_LIB_H__\r
20\r
21#define END_DEVICE_PATH_LENGTH (sizeof (EFI_DEVICE_PATH_PROTOCOL))\r
22\r
23/**\r
24 Returns the Type field of a device path node.\r
25\r
26 Returns the Type field of the device path node specified by Node.\r
27\r
28 If Node is NULL, then ASSERT().\r
29\r
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
35UINT8\r
36EFIAPI\r
37DevicePathType (\r
38 IN CONST VOID *Node\r
39 );\r
40\r
41/**\r
42 Returns the SubType field of a device path node.\r
43\r
44 Returns the SubType field of the device path node specified by Node.\r
45\r
46 If Node is NULL, then ASSERT().\r
47\r
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
53UINT8\r
54EFIAPI\r
55DevicePathSubType (\r
56 IN CONST VOID *Node\r
57 );\r
58\r
59/**\r
60 Returns the 16-bit Length field of a device path node.\r
61\r
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
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
74UINTN\r
75EFIAPI\r
76DevicePathNodeLength (\r
77 IN CONST VOID *Node\r
78 );\r
79\r
80/**\r
81 Returns a pointer to the next node in a device path.\r
82\r
83 Returns a pointer to the device path node that follows the device path node specified by Node.\r
84\r
85 If Node is NULL, then ASSERT().\r
86\r
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
92EFI_DEVICE_PATH_PROTOCOL *\r
93EFIAPI\r
94NextDevicePathNode (\r
95 IN CONST VOID *Node\r
96 );\r
97\r
98/**\r
99 Determines if a device path node is an end node of a device path.\r
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
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
108 If Node is NULL, then ASSERT().\r
109\r
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
116BOOLEAN\r
117EFIAPI\r
118IsDevicePathEndType (\r
119 IN CONST VOID *Node\r
120 );\r
121\r
122/**\r
123 Determines if a device path node is an end node of an entire device path.\r
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
128 If Node is NULL, then ASSERT().\r
129\r
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
136BOOLEAN\r
137EFIAPI\r
138IsDevicePathEnd (\r
139 IN CONST VOID *Node\r
140 );\r
141\r
142/**\r
143 Determines if a device path node is an end node of a device path instance.\r
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
148 If Node is NULL, then ASSERT().\r
149\r
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
156BOOLEAN\r
157EFIAPI\r
158IsDevicePathEndInstance (\r
159 IN CONST VOID *Node\r
160 );\r
161\r
162/**\r
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
169\r
170 If Node is NULL, then ASSERT().\r
171 If NodeLength >= 0x10000, then ASSERT().\r
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
179UINT16\r
180EFIAPI\r
181SetDevicePathNodeLength (\r
182 IN OUT VOID *Node,\r
183 IN UINTN Length\r
184 );\r
185\r
186/**\r
187 Fills in all the fields of a device path node that is the end of an entire device path.\r
188\r
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
198\r
199 @param Node A pointer to a device path node data structure.\r
200\r
201**/\r
202VOID\r
203EFIAPI\r
204SetDevicePathEndNode (\r
205 OUT VOID *Node\r
206 );\r
207\r
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
215 \r
216 @retval 0 DevicePath is NULL.\r
217 @retval Others The size of a device path in bytes.\r
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
227 Creates a new copy of an existing device path.\r
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
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
235 \r
236 @param DevicePath A pointer to a device path data structure.\r
237\r
238 @retval NULL DevicePath is NULL.\r
239 @retval Others A pointer to the duplicated device path.\r
240 \r
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
256 If both FirstDevicePath and SecondDevicePath are NULL, then a copy of an end-of-device-path is\r
257 returned. \r
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
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
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
283 If DevicePathNode is NULL then a copy of DevicePath is returned.\r
284 If DevicePath is NULL then a copy of DevicePathNode, followed by an end-of-device path device\r
285 node is returned.\r
286 If both DevicePathNode and DevicePath are NULL then a copy of an end-of-device-path device node\r
287 is returned.\r
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
295 @retval NULL There is not enough memory for the new device path.\r
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
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
368 Creates a device node.\r
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
402 @retval FALSE DevicePath is not multi-instance, or DevicePath is NULL.\r
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
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
439 If FileName is NULL, then ASSERT().\r
440 If FileName is not aligned on a 16-bit boundary, then ASSERT().\r
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