]>
Commit | Line | Data |
---|---|---|
878ddf1f | 1 | /** @file\r |
2 | UEFI Device Path Library.\r | |
3 | \r | |
4 | Copyright (c) 2006, Intel Corporation<BR>\r | |
5 | All rights reserved. This program and the accompanying materials\r | |
6 | are licensed and made available under the terms and conditions of the BSD License\r | |
7 | which accompanies this distribution. The full text of the license may be found at\r | |
8 | http://opensource.org/licenses/bsd-license.php\r | |
9 | \r | |
10 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r | |
11 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
12 | \r | |
13 | Module Name: UefiDevicePathLib.c\r | |
14 | \r | |
15 | **/\r | |
16 | \r | |
17 | STATIC EFI_DEVICE_PATH_UTILITIES_PROTOCOL *mDevicePathUtilities = NULL;\r | |
18 | \r | |
19 | /**\r | |
20 | The constructor function caches the pointer to DevicePathUtilites protocol.\r | |
21 | \r | |
22 | The constructor function locates DevicePathUtilities protocol from protocol database.\r | |
23 | It will ASSERT() if that operation fails and it will always return EFI_SUCCESS. \r | |
24 | \r | |
25 | @param ImageHandle The firmware allocated handle for the EFI image.\r | |
26 | @param SystemTable A pointer to the EFI System Table.\r | |
27 | \r | |
28 | @retval EFI_SUCCESS The constructor always returns EFI_SUCCESS.\r | |
29 | \r | |
30 | **/\r | |
31 | EFI_STATUS\r | |
32 | EFIAPI\r | |
33 | DevicePathLibConstructor (\r | |
34 | IN EFI_HANDLE ImageHandle,\r | |
35 | IN EFI_SYSTEM_TABLE *SystemTable\r | |
36 | )\r | |
37 | {\r | |
38 | EFI_STATUS Status;\r | |
39 | \r | |
40 | Status = gBS->LocateProtocol (\r | |
41 | &gEfiDevicePathUtilitiesProtocolGuid,\r | |
42 | NULL,\r | |
43 | (VOID**) &mDevicePathUtilities\r | |
44 | );\r | |
45 | ASSERT_EFI_ERROR (Status);\r | |
46 | ASSERT (mDevicePathUtilities != NULL);\r | |
47 | \r | |
48 | return Status;\r | |
49 | }\r | |
50 | \r | |
51 | /**\r | |
add13dc2 | 52 | Returns the size of a device path in bytes.\r |
878ddf1f | 53 | \r |
add13dc2 | 54 | This function returns the size, in bytes, of the device path data structure specified by\r |
55 | DevicePath including the end of device path node. If DevicePath is NULL, then 0 is returned.\r | |
56 | \r | |
57 | @param DevicePath A pointer to a device path data structure.\r | |
878ddf1f | 58 | \r |
59 | @return The size of a device path in bytes.\r | |
60 | \r | |
61 | **/\r | |
62 | UINTN\r | |
63 | EFIAPI\r | |
64 | GetDevicePathSize (\r | |
65 | IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath\r | |
66 | )\r | |
67 | {\r | |
68 | return mDevicePathUtilities->GetDevicePathSize (DevicePath);\r | |
69 | }\r | |
70 | \r | |
71 | /**\r | |
add13dc2 | 72 | Creates a new device path by appending a second device path to a first device path.\r |
878ddf1f | 73 | \r |
add13dc2 | 74 | This function allocates space for a new copy of the device path specified by DevicePath. If\r |
75 | DevicePath is NULL, then NULL is returned. If the memory is successfully allocated, then the\r | |
76 | contents of DevicePath are copied to the newly allocated buffer, and a pointer to that buffer\r | |
77 | is returned. Otherwise, NULL is returned. \r | |
78 | \r | |
79 | @param DevicePath A pointer to a device path data structure.\r | |
878ddf1f | 80 | \r |
add13dc2 | 81 | @return A pointer to the duplicated device path.\r |
878ddf1f | 82 | \r |
83 | **/\r | |
84 | EFI_DEVICE_PATH_PROTOCOL *\r | |
85 | EFIAPI\r | |
86 | DuplicateDevicePath (\r | |
add13dc2 | 87 | IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath\r |
878ddf1f | 88 | )\r |
89 | {\r | |
90 | return mDevicePathUtilities->DuplicateDevicePath (DevicePath);\r | |
91 | }\r | |
92 | \r | |
93 | /**\r | |
add13dc2 | 94 | Creates a new device path by appending a second device path to a first device path.\r |
878ddf1f | 95 | \r |
add13dc2 | 96 | This function creates a new device path by appending a copy of SecondDevicePath to a copy of\r |
97 | FirstDevicePath in a newly allocated buffer. Only the end-of-device-path device node from\r | |
98 | SecondDevicePath is retained. The newly created device path is returned. \r | |
99 | If FirstDevicePath is NULL, then it is ignored, and a duplicate of SecondDevicePath is returned. \r | |
100 | If SecondDevicePath is NULL, then it is ignored, and a duplicate of FirstDevicePath is returned. \r | |
101 | If both FirstDevicePath and SecondDevicePath are NULL, then NULL is returned. \r | |
102 | If there is not enough memory for the newly allocated buffer, then NULL is returned.\r | |
103 | The memory for the new device path is allocated from EFI boot services memory. It is the\r | |
104 | responsibility of the caller to free the memory allocated.\r | |
878ddf1f | 105 | \r |
add13dc2 | 106 | @param FirstDevicePath A pointer to a device path data structure.\r |
107 | @param SecondDevicePath A pointer to a device path data structure.\r | |
108 | \r | |
109 | @return A pointer to the new device path.\r | |
878ddf1f | 110 | \r |
111 | **/\r | |
112 | EFI_DEVICE_PATH_PROTOCOL *\r | |
113 | EFIAPI\r | |
114 | AppendDevicePath (\r | |
add13dc2 | 115 | IN CONST EFI_DEVICE_PATH_PROTOCOL *FirstDevicePath, OPTIONAL\r |
116 | IN CONST EFI_DEVICE_PATH_PROTOCOL *SecondDevicePath OPTIONAL\r | |
878ddf1f | 117 | )\r |
118 | {\r | |
119 | return mDevicePathUtilities->AppendDevicePath (FirstDevicePath, SecondDevicePath);\r | |
120 | }\r | |
121 | \r | |
122 | /**\r | |
add13dc2 | 123 | Creates a new path by appending the device node to the device path.\r |
878ddf1f | 124 | \r |
add13dc2 | 125 | This function creates a new device path by appending a copy of the device node specified by\r |
126 | DevicePathNode to a copy of the device path specified by DevicePath in an allocated buffer.\r | |
127 | The end-of-device-path device node is moved after the end of the appended device node.\r | |
128 | If DevicePath is NULL, then NULL is returned.\r | |
129 | If DevicePathNode is NULL, then NULL is returned.\r | |
130 | If there is not enough memory to allocate space for the new device path, then NULL is returned. \r | |
131 | The memory is allocated from EFI boot services memory. It is the responsibility of the caller to\r | |
132 | free the memory allocated.\r | |
133 | \r | |
134 | @param DevicePath A pointer to a device path data structure.\r | |
135 | @param DevicePathNode A pointer to a single device path node.\r | |
878ddf1f | 136 | \r |
137 | @return A pointer to the new device path.\r | |
878ddf1f | 138 | \r |
139 | **/\r | |
140 | EFI_DEVICE_PATH_PROTOCOL *\r | |
141 | EFIAPI\r | |
142 | AppendDevicePathNode (\r | |
add13dc2 | 143 | IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath, OPTIONAL\r |
144 | IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePathNode OPTIONAL\r | |
878ddf1f | 145 | )\r |
146 | {\r | |
add13dc2 | 147 | return mDevicePathUtilities->AppendDeviceNode (DevicePath, DevicePathNode);\r |
878ddf1f | 148 | }\r |
149 | \r | |
150 | /**\r | |
add13dc2 | 151 | Creates a new device path by appending the specified device path instance to the specified device\r |
152 | path.\r | |
153 | \r | |
154 | This function creates a new device path by appending a copy of the device path instance specified\r | |
155 | by DevicePathInstance to a copy of the device path secified by DevicePath in a allocated buffer.\r | |
156 | The end-of-device-path device node is moved after the end of the appended device path instance\r | |
157 | and a new end-of-device-path-instance node is inserted between. \r | |
158 | If DevicePath is NULL, then a copy if DevicePathInstance is returned.\r | |
159 | If DevicePathInstance is NULL, then NULL is returned.\r | |
160 | If there is not enough memory to allocate space for the new device path, then NULL is returned. \r | |
161 | The memory is allocated from EFI boot services memory. It is the responsibility of the caller to\r | |
162 | free the memory allocated.\r | |
163 | \r | |
164 | @param DevicePath A pointer to a device path data structure.\r | |
165 | @param DevicePathInstance A pointer to a device path instance.\r | |
878ddf1f | 166 | \r |
167 | @return A pointer to the new device path.\r | |
878ddf1f | 168 | \r |
169 | **/\r | |
170 | EFI_DEVICE_PATH_PROTOCOL *\r | |
171 | EFIAPI\r | |
172 | AppendDevicePathInstance (\r | |
add13dc2 | 173 | IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath, OPTIONAL\r |
174 | IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePathInstance OPTIONAL\r | |
878ddf1f | 175 | )\r |
176 | {\r | |
add13dc2 | 177 | return mDevicePathUtilities->AppendDevicePathInstance (DevicePath, DevicePathInstance);\r |
878ddf1f | 178 | }\r |
179 | \r | |
180 | /**\r | |
add13dc2 | 181 | Creates a copy of the current device path instance and returns a pointer to the next device path\r |
182 | instance.\r | |
183 | \r | |
184 | This function creates a copy of the current device path instance. It also updates DevicePath to\r | |
185 | point to the next device path instance in the device path (or NULL if no more) and updates Size\r | |
186 | to hold the size of the device path instance copy.\r | |
187 | If DevicePath is NULL, then NULL is returned.\r | |
188 | If there is not enough memory to allocate space for the new device path, then NULL is returned. \r | |
189 | The memory is allocated from EFI boot services memory. It is the responsibility of the caller to\r | |
190 | free the memory allocated.\r | |
191 | If Size is NULL, then ASSERT().\r | |
192 | \r | |
193 | @param DevicePath On input, this holds the pointer to the current device path\r | |
194 | instance. On output, this holds the pointer to the next device\r | |
195 | path instance or NULL if there are no more device path\r | |
196 | instances in the device path pointer to a device path data\r | |
197 | structure.\r | |
198 | @param Size On output, this holds the size of the device path instance, in\r | |
199 | bytes or zero, if DevicePath is NULL.\r | |
200 | \r | |
201 | @return A pointer to the current device path instance.\r | |
878ddf1f | 202 | \r |
203 | **/\r | |
204 | EFI_DEVICE_PATH_PROTOCOL *\r | |
205 | EFIAPI\r | |
206 | GetNextDevicePathInstance (\r | |
add13dc2 | 207 | IN OUT EFI_DEVICE_PATH_PROTOCOL **DevicePath,\r |
208 | OUT UINTN *Size\r | |
878ddf1f | 209 | )\r |
210 | {\r | |
878ddf1f | 211 | ASSERT (Size != NULL);\r |
212 | return mDevicePathUtilities->GetNextDevicePathInstance (DevicePath, Size);\r | |
213 | }\r | |
214 | \r | |
215 | /**\r | |
add13dc2 | 216 | Creates a copy of the current device path instance and returns a pointer to the next device path\r |
217 | instance.\r | |
218 | \r | |
219 | This function creates a new device node in a newly allocated buffer of size NodeLength and\r | |
220 | initializes the device path node header with NodeType and NodeSubType. The new device path node\r | |
221 | is returned.\r | |
222 | If NodeLength is smaller than a device path header, then NULL is returned. \r | |
223 | If there is not enough memory to allocate space for the new device path, then NULL is returned. \r | |
224 | The memory is allocated from EFI boot services memory. It is the responsibility of the caller to\r | |
225 | 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 mDevicePathUtilities->CreateDeviceNode (NodeType, NodeSubType, NodeLength);\r | |
243 | }\r | |
244 | \r | |
245 | /**\r | |
246 | Determines if a device path is single or multi-instance.\r | |
878ddf1f | 247 | \r |
add13dc2 | 248 | This function returns TRUE if the device path specified by DevicePath is multi-instance.\r |
249 | Otherwise, FALSE is returned. If DevicePath is NULL, then FALSE is returned.\r | |
878ddf1f | 250 | \r |
add13dc2 | 251 | @param DevicePath A pointer to a device path data structure.\r |
252 | \r | |
253 | @retval TRUE DevicePath is multi-instance.\r | |
254 | @retval FALSE DevicePath is not multi-instance or DevicePath is NULL.\r | |
878ddf1f | 255 | \r |
256 | **/\r | |
257 | BOOLEAN\r | |
258 | EFIAPI\r | |
259 | IsDevicePathMultiInstance (\r | |
260 | IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath\r | |
261 | )\r | |
262 | {\r | |
263 | return mDevicePathUtilities->IsDevicePathMultiInstance (DevicePath);\r | |
264 | }\r | |
265 | \r | |
266 | /**\r | |
add13dc2 | 267 | Retrieves the device path protocol from a handle.\r |
878ddf1f | 268 | \r |
add13dc2 | 269 | This function returns the device path protocol from the handle specified by Handle. If Handle is\r |
270 | NULL or Handle does not contain a device path protocol, then NULL is returned.\r | |
271 | \r | |
272 | @param Handle The handle from which to retrieve the device path protocol.\r | |
878ddf1f | 273 | \r |
add13dc2 | 274 | @return The device path protocol from the handle specified by Handle.\r |
878ddf1f | 275 | \r |
276 | **/\r | |
277 | EFI_DEVICE_PATH_PROTOCOL *\r | |
278 | EFIAPI\r | |
279 | DevicePathFromHandle (\r | |
add13dc2 | 280 | IN EFI_HANDLE Handle\r |
878ddf1f | 281 | )\r |
282 | {\r | |
283 | EFI_DEVICE_PATH_PROTOCOL *DevicePath;\r | |
284 | EFI_STATUS Status;\r | |
285 | \r | |
286 | Status = gBS->HandleProtocol (\r | |
287 | Handle,\r | |
288 | &gEfiDevicePathProtocolGuid,\r | |
289 | (VOID *) &DevicePath\r | |
290 | );\r | |
291 | if (EFI_ERROR (Status)) {\r | |
292 | DevicePath = NULL;\r | |
293 | }\r | |
294 | return DevicePath;\r | |
295 | }\r | |
296 | \r | |
297 | /**\r | |
add13dc2 | 298 | Allocates a device path for a file and appends it to an existing device path.\r |
299 | \r | |
300 | If Device is a valid device handle that contains a device path protocol, then a device path for\r | |
301 | the file specified by FileName is allocated and appended to the device path associated with the\r | |
302 | handle Device. The allocated device path is returned. If Device is NULL or Device is a handle\r | |
303 | that does not support the device path protocol, then a device path containing a single device\r | |
304 | path node for the file specified by FileName is allocated and returned.\r | |
305 | If FileName is NULL, then ASSERT().\r | |
878ddf1f | 306 | \r |
add13dc2 | 307 | @param Device A pointer to a device handle. This parameter is optional and\r |
308 | may be NULL.\r | |
309 | @param FileName A pointer to a Null-terminated Unicode string.\r | |
878ddf1f | 310 | \r |
add13dc2 | 311 | @return The allocated device path.\r |
878ddf1f | 312 | \r |
313 | **/\r | |
314 | EFI_DEVICE_PATH_PROTOCOL *\r | |
315 | EFIAPI\r | |
316 | FileDevicePath (\r | |
add13dc2 | 317 | IN EFI_HANDLE Device, OPTIONAL\r |
318 | IN CONST CHAR16 *FileName\r | |
878ddf1f | 319 | )\r |
320 | {\r | |
321 | UINTN Size;\r | |
322 | FILEPATH_DEVICE_PATH *FilePath;\r | |
323 | EFI_DEVICE_PATH_PROTOCOL *DevicePath;\r | |
28c73f6e | 324 | EFI_DEVICE_PATH_PROTOCOL *FileDevicePath;\r |
878ddf1f | 325 | \r |
326 | DevicePath = NULL;\r | |
327 | \r | |
328 | Size = StrSize (FileName);\r | |
28c73f6e | 329 | FileDevicePath = AllocatePool (Size + SIZE_OF_FILEPATH_DEVICE_PATH + EFI_END_DEVICE_PATH_LENGTH);\r |
330 | if (FileDevicePath != NULL) {\r | |
331 | FilePath = (FILEPATH_DEVICE_PATH *) FileDevicePath;\r | |
332 | FilePath->Header.Type = MEDIA_DEVICE_PATH;\r | |
333 | FilePath->Header.SubType = MEDIA_FILEPATH_DP;\r | |
878ddf1f | 334 | CopyMem (&FilePath->PathName, FileName, Size);\r |
28c73f6e | 335 | SetDevicePathNodeLength (&FilePath->Header, Size + SIZE_OF_FILEPATH_DEVICE_PATH);\r |
336 | SetDevicePathEndNode (NextDevicePathNode (&FilePath->Header));\r | |
337 | \r | |
878ddf1f | 338 | if (Device != NULL) {\r |
339 | DevicePath = DevicePathFromHandle (Device);\r | |
340 | }\r | |
28c73f6e | 341 | \r |
342 | DevicePath = AppendDevicePath (DevicePath, FileDevicePath);\r | |
343 | FreePool (FileDevicePath);\r | |
878ddf1f | 344 | }\r |
add13dc2 | 345 | \r |
878ddf1f | 346 | return DevicePath;\r |
347 | }\r | |
348 | \r |