]>
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 | |
52 | This function returns the size, in bytes, \r | |
53 | of the device path data structure specified by DevicePath.\r | |
54 | If DevicePath is NULL, then 0 is returned.\r | |
55 | \r | |
56 | @param DevicePath A pointer to a device path data structure.\r | |
57 | \r | |
58 | @return The size of a device path in bytes.\r | |
59 | \r | |
60 | **/\r | |
61 | UINTN\r | |
62 | EFIAPI\r | |
63 | GetDevicePathSize (\r | |
64 | IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath\r | |
65 | )\r | |
66 | {\r | |
67 | return mDevicePathUtilities->GetDevicePathSize (DevicePath);\r | |
68 | }\r | |
69 | \r | |
70 | /**\r | |
71 | This function allocates space for a new copy of the device path\r | |
72 | specified by DevicePath.\r | |
73 | \r | |
74 | @param DevicePath A pointer to a device path data structure.\r | |
75 | \r | |
76 | @return The duplicated device path.\r | |
77 | \r | |
78 | **/\r | |
79 | EFI_DEVICE_PATH_PROTOCOL *\r | |
80 | EFIAPI\r | |
81 | DuplicateDevicePath (\r | |
82 | IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath\r | |
83 | )\r | |
84 | {\r | |
85 | return mDevicePathUtilities->DuplicateDevicePath (DevicePath);\r | |
86 | }\r | |
87 | \r | |
88 | /**\r | |
89 | This function appends the device path SecondDevicePath\r | |
90 | to every device path instance in FirstDevicePath. \r | |
91 | \r | |
92 | @param FirstDevicePath A pointer to a device path data structure.\r | |
93 | \r | |
94 | @param SecondDevicePath A pointer to a device path data structure.\r | |
95 | \r | |
96 | @return A pointer to the new device path is returned.\r | |
97 | NULL is returned if space for the new device path could not be allocated from pool.\r | |
98 | It is up to the caller to free the memory used by FirstDevicePath and SecondDevicePath\r | |
99 | if they are no longer needed.\r | |
100 | \r | |
101 | **/\r | |
102 | EFI_DEVICE_PATH_PROTOCOL *\r | |
103 | EFIAPI\r | |
104 | AppendDevicePath (\r | |
105 | IN CONST EFI_DEVICE_PATH_PROTOCOL *FirstDevicePath,\r | |
106 | IN CONST EFI_DEVICE_PATH_PROTOCOL *SecondDevicePath\r | |
107 | )\r | |
108 | {\r | |
109 | return mDevicePathUtilities->AppendDevicePath (FirstDevicePath, SecondDevicePath);\r | |
110 | }\r | |
111 | \r | |
112 | /**\r | |
113 | This function appends the device path node SecondDevicePath\r | |
114 | to every device path instance in FirstDevicePath.\r | |
115 | \r | |
116 | @param FirstDevicePath A pointer to a device path data structure.\r | |
117 | \r | |
118 | @param SecondDevicePath A pointer to a single device path node.\r | |
119 | \r | |
120 | @return A pointer to the new device path.\r | |
121 | If there is not enough temporary pool memory available to complete this function,\r | |
122 | then NULL is returned.\r | |
123 | \r | |
124 | **/\r | |
125 | EFI_DEVICE_PATH_PROTOCOL *\r | |
126 | EFIAPI\r | |
127 | AppendDevicePathNode (\r | |
128 | IN CONST EFI_DEVICE_PATH_PROTOCOL *FirstDevicePath,\r | |
129 | IN CONST EFI_DEVICE_PATH_PROTOCOL *SecondDevicePath\r | |
130 | )\r | |
131 | {\r | |
132 | return mDevicePathUtilities->AppendDeviceNode (FirstDevicePath, SecondDevicePath);\r | |
133 | }\r | |
134 | \r | |
135 | /**\r | |
136 | This function appends the device path instance Instance to the device path Source.\r | |
137 | If Source is NULL, then a new device path with one instance is created. \r | |
138 | \r | |
139 | @param Source A pointer to a device path data structure.\r | |
140 | @param Instance A pointer to a device path instance.\r | |
141 | \r | |
142 | @return A pointer to the new device path.\r | |
143 | If there is not enough temporary pool memory available to complete this function,\r | |
144 | then NULL is returned.\r | |
145 | \r | |
146 | **/\r | |
147 | EFI_DEVICE_PATH_PROTOCOL *\r | |
148 | EFIAPI\r | |
149 | AppendDevicePathInstance (\r | |
150 | IN CONST EFI_DEVICE_PATH_PROTOCOL *Source,\r | |
151 | IN CONST EFI_DEVICE_PATH_PROTOCOL *Instance\r | |
152 | )\r | |
153 | {\r | |
154 | return mDevicePathUtilities->AppendDevicePathInstance (Source, Instance);\r | |
155 | }\r | |
156 | \r | |
157 | /**\r | |
158 | Function retrieves the next device path instance from a device path data structure.\r | |
159 | \r | |
160 | @param DevicePath A pointer to a device path data structure.\r | |
161 | \r | |
162 | @param Size A pointer to the size of a device path instance in bytes.\r | |
163 | \r | |
164 | @return This function returns a pointer to the current device path instance.\r | |
165 | In addition, it returns the size in bytes of the current device path instance in Size,\r | |
166 | and a pointer to the next device path instance in DevicePath.\r | |
167 | If there are no more device path instances in DevicePath, then DevicePath will be set to NULL.\r | |
168 | \r | |
169 | **/\r | |
170 | EFI_DEVICE_PATH_PROTOCOL *\r | |
171 | EFIAPI\r | |
172 | GetNextDevicePathInstance (\r | |
173 | IN OUT EFI_DEVICE_PATH_PROTOCOL **DevicePath,\r | |
174 | OUT UINTN *Size\r | |
175 | )\r | |
176 | {\r | |
177 | ASSERT (DevicePath != NULL);\r | |
178 | ASSERT (Size != NULL);\r | |
179 | return mDevicePathUtilities->GetNextDevicePathInstance (DevicePath, Size);\r | |
180 | }\r | |
181 | \r | |
182 | /**\r | |
183 | Return TRUE is this is a multi instance device path.\r | |
184 | \r | |
185 | @param DevicePath A pointer to a device path data structure.\r | |
186 | \r | |
187 | @retval TRUE If DevicePath is multi-instance.\r | |
188 | @retval FALSE If DevicePath is not multi-instance or DevicePath is NULL.\r | |
189 | \r | |
190 | **/\r | |
191 | BOOLEAN\r | |
192 | EFIAPI\r | |
193 | IsDevicePathMultiInstance (\r | |
194 | IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath\r | |
195 | )\r | |
196 | {\r | |
197 | return mDevicePathUtilities->IsDevicePathMultiInstance (DevicePath);\r | |
198 | }\r | |
199 | \r | |
200 | /**\r | |
201 | This function retrieves the device path protocol from a handle.\r | |
202 | \r | |
203 | @param Handle The handle from which to retrieve the device path protocol.\r | |
204 | \r | |
205 | @return This function returns the device path protocol from the handle specified by Handle.\r | |
206 | If Handle is NULL or Handle does not contain a device path protocol, then NULL is returned.\r | |
207 | \r | |
208 | **/\r | |
209 | EFI_DEVICE_PATH_PROTOCOL *\r | |
210 | EFIAPI\r | |
211 | DevicePathFromHandle (\r | |
212 | IN EFI_HANDLE Handle\r | |
213 | )\r | |
214 | {\r | |
215 | EFI_DEVICE_PATH_PROTOCOL *DevicePath;\r | |
216 | EFI_STATUS Status;\r | |
217 | \r | |
218 | Status = gBS->HandleProtocol (\r | |
219 | Handle,\r | |
220 | &gEfiDevicePathProtocolGuid,\r | |
221 | (VOID *) &DevicePath\r | |
222 | );\r | |
223 | if (EFI_ERROR (Status)) {\r | |
224 | DevicePath = NULL;\r | |
225 | }\r | |
226 | return DevicePath;\r | |
227 | }\r | |
228 | \r | |
229 | /**\r | |
230 | This function allocates a device path for a file and appends it to an existing device path.\r | |
231 | \r | |
232 | @param Device A pointer to a device handle. This parameter is optional and may be NULL.\r | |
233 | @param FileName A pointer to a Null-terminated Unicode string.\r | |
234 | \r | |
235 | @return If Device is a valid device handle that contains a device path protocol,\r | |
236 | then a device path for the file specified by FileName is allocated\r | |
237 | and appended to the device path associated with the handle Device. The allocated device path is returned.\r | |
238 | If Device is NULL or Device is a handle that does not support the device path protocol,\r | |
239 | then a device path containing a single device path node for the file specified by FileName\r | |
240 | is allocated and returned.\r | |
241 | \r | |
242 | **/\r | |
243 | EFI_DEVICE_PATH_PROTOCOL *\r | |
244 | EFIAPI\r | |
245 | FileDevicePath (\r | |
246 | IN EFI_HANDLE Device, OPTIONAL\r | |
247 | IN CONST CHAR16 *FileName\r | |
248 | )\r | |
249 | {\r | |
250 | UINTN Size;\r | |
251 | FILEPATH_DEVICE_PATH *FilePath;\r | |
252 | EFI_DEVICE_PATH_PROTOCOL *DevicePath;\r | |
253 | EFI_DEVICE_PATH_PROTOCOL *FileDevicePathNode;\r | |
254 | \r | |
255 | DevicePath = NULL;\r | |
256 | \r | |
257 | Size = StrSize (FileName);\r | |
258 | FileDevicePathNode = mDevicePathUtilities->CreateDeviceNode (\r | |
259 | MEDIA_DEVICE_PATH,\r | |
260 | MEDIA_FILEPATH_DP,\r | |
261 | (UINT16) (Size + SIZE_OF_FILEPATH_DEVICE_PATH)\r | |
262 | );\r | |
263 | if (FileDevicePathNode != NULL) {\r | |
264 | FilePath = (FILEPATH_DEVICE_PATH *) FileDevicePathNode;\r | |
265 | CopyMem (&FilePath->PathName, FileName, Size);\r | |
266 | if (Device != NULL) {\r | |
267 | DevicePath = DevicePathFromHandle (Device);\r | |
268 | }\r | |
269 | DevicePath = AppendDevicePathNode (DevicePath, FileDevicePathNode);\r | |
270 | FreePool (FileDevicePathNode);\r | |
271 | }\r | |
272 | return DevicePath;\r | |
273 | }\r | |
274 | \r |