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