]>
Commit | Line | Data |
---|---|---|
a405b86d | 1 | /** @file\r |
2 | Member functions of EFI_SHELL_PROTOCOL and functions for creation,\r | |
3 | manipulation, and initialization of EFI_SHELL_PROTOCOL.\r | |
4 | \r | |
5 | Copyright (c) 2009 - 2010, Intel Corporation. All rights reserved.<BR>\r | |
6 | This program and the accompanying materials\r | |
7 | are licensed and made available under the terms and conditions of the BSD License\r | |
8 | which accompanies this distribution. The full text of the license may be found at\r | |
9 | http://opensource.org/licenses/bsd-license.php\r | |
10 | \r | |
11 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r | |
12 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
13 | \r | |
14 | **/\r | |
15 | \r | |
16 | #include "Shell.h"\r | |
17 | #include <Library/FileHandleLib.h>\r | |
18 | \r | |
19 | /**\r | |
20 | Close an open file handle.\r | |
21 | \r | |
22 | This function closes a specified file handle. All "dirty" cached file data is\r | |
23 | flushed to the device, and the file is closed. In all cases the handle is\r | |
24 | closed.\r | |
25 | \r | |
26 | @param[in] FileHandle The file handle to close.\r | |
27 | \r | |
28 | @retval EFI_SUCCESS The file handle was closed successfully.\r | |
29 | **/\r | |
30 | EFI_STATUS\r | |
31 | EFIAPI\r | |
32 | EfiShellClose (\r | |
33 | IN SHELL_FILE_HANDLE FileHandle\r | |
34 | )\r | |
35 | {\r | |
36 | ShellFileHandleRemove(FileHandle);\r | |
37 | return (FileHandleClose(FileHandle));\r | |
38 | }\r | |
39 | \r | |
40 | /**\r | |
41 | Internal worker to determine whether there is a file system somewhere\r | |
42 | upon the device path specified.\r | |
43 | \r | |
44 | @param[in] DevicePath The device path to test.\r | |
45 | \r | |
46 | @retval TRUE gEfiSimpleFileSystemProtocolGuid was installed on a handle with this device path\r | |
47 | @retval FALSE gEfiSimpleFileSystemProtocolGuid was not found.\r | |
48 | **/\r | |
49 | BOOLEAN\r | |
50 | EFIAPI\r | |
51 | InternalShellProtocolIsSimpleFileSystemPresent(\r | |
52 | IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath\r | |
53 | )\r | |
54 | {\r | |
55 | EFI_DEVICE_PATH_PROTOCOL *DevicePathCopy;\r | |
56 | EFI_STATUS Status;\r | |
57 | EFI_HANDLE Handle;\r | |
58 | \r | |
59 | Handle = NULL;\r | |
60 | \r | |
61 | DevicePathCopy = (EFI_DEVICE_PATH_PROTOCOL*)DevicePath;\r | |
62 | Status = gBS->LocateDevicePath(&gEfiSimpleFileSystemProtocolGuid, &DevicePathCopy, &Handle);\r | |
63 | \r | |
64 | if ((Handle != NULL) && (!EFI_ERROR(Status))) {\r | |
65 | return (TRUE);\r | |
66 | }\r | |
67 | return (FALSE);\r | |
68 | }\r | |
69 | \r | |
70 | /**\r | |
71 | Internal worker debug helper function to print out maps as they are added.\r | |
72 | \r | |
73 | @param[in] Mapping string mapping that has been added\r | |
74 | @param[in] DevicePath pointer to device path that has been mapped.\r | |
75 | \r | |
76 | @retval EFI_SUCCESS the operation was successful.\r | |
77 | @return other an error ocurred\r | |
78 | \r | |
79 | @sa LocateHandle\r | |
80 | @sa OpenProtocol\r | |
81 | **/\r | |
82 | EFI_STATUS\r | |
83 | EFIAPI\r | |
84 | InternalShellProtocolDebugPrintMessage (\r | |
85 | IN CONST CHAR16 *Mapping,\r | |
86 | IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath\r | |
87 | )\r | |
88 | {\r | |
89 | EFI_DEVICE_PATH_TO_TEXT_PROTOCOL *DevicePathToText;\r | |
90 | EFI_STATUS Status;\r | |
91 | CHAR16 *Temp;\r | |
92 | \r | |
93 | Status = EFI_SUCCESS;\r | |
94 | DEBUG_CODE_BEGIN();\r | |
95 | DevicePathToText = NULL;\r | |
96 | \r | |
97 | Status = gBS->LocateProtocol(&gEfiDevicePathToTextProtocolGuid,\r | |
98 | NULL,\r | |
99 | (VOID**)&DevicePathToText);\r | |
100 | if (Mapping != NULL) {\r | |
101 | DEBUG((EFI_D_INFO, "Added new map item:\"%S\"\r\n", Mapping));\r | |
102 | }\r | |
103 | if (!EFI_ERROR(Status)) {\r | |
104 | if (DevicePath != NULL) {\r | |
105 | Temp = DevicePathToText->ConvertDevicePathToText(DevicePath, TRUE, TRUE);\r | |
106 | DEBUG((EFI_D_INFO, "DevicePath: %S\r\n", Temp));\r | |
107 | FreePool(Temp);\r | |
108 | }\r | |
109 | }\r | |
110 | DEBUG_CODE_END();\r | |
111 | return (Status);\r | |
112 | }\r | |
113 | \r | |
114 | /**\r | |
115 | This function creates a mapping for a device path.\r | |
116 | \r | |
117 | If both DeviecPath and Mapping are NULL, this will reset the mapping to default values.\r | |
118 | \r | |
119 | @param DevicePath Points to the device path. If this is NULL and Mapping points to a valid mapping,\r | |
120 | then the mapping will be deleted.\r | |
121 | @param Mapping Points to the NULL-terminated mapping for the device path. Must end with a ':'\r | |
122 | \r | |
123 | @retval EFI_SUCCESS Mapping created or deleted successfully.\r | |
124 | @retval EFI_NO_MAPPING There is no handle that corresponds exactly to DevicePath. See the\r | |
125 | boot service function LocateDevicePath().\r | |
126 | @retval EFI_ACCESS_DENIED The mapping is a built-in alias.\r | |
127 | @retval EFI_INVALID_PARAMETER Mapping was NULL\r | |
128 | @retval EFI_INVALID_PARAMETER Mapping did not end with a ':'\r | |
129 | @retval EFI_INVALID_PARAMETER DevicePath was not pointing at a device that had a SIMPLE_FILE_SYSTEM_PROTOCOL installed.\r | |
130 | @retval EFI_NOT_FOUND There was no mapping found to delete\r | |
131 | @retval EFI_OUT_OF_RESOURCES Memory allocation failed\r | |
132 | **/\r | |
133 | EFI_STATUS\r | |
134 | EFIAPI\r | |
135 | EfiShellSetMap(\r | |
136 | IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath OPTIONAL,\r | |
137 | IN CONST CHAR16 *Mapping\r | |
138 | )\r | |
139 | {\r | |
140 | EFI_STATUS Status;\r | |
141 | SHELL_MAP_LIST *MapListNode;\r | |
142 | \r | |
143 | if (Mapping == NULL){\r | |
144 | return (EFI_INVALID_PARAMETER);\r | |
145 | }\r | |
146 | \r | |
147 | if (Mapping[StrLen(Mapping)-1] != ':') {\r | |
148 | return (EFI_INVALID_PARAMETER);\r | |
149 | }\r | |
150 | \r | |
151 | //\r | |
152 | // Delete the mapping\r | |
153 | //\r | |
154 | if (DevicePath == NULL) {\r | |
155 | if (IsListEmpty(&gShellMapList.Link)) {\r | |
156 | return (EFI_NOT_FOUND);\r | |
157 | }\r | |
158 | for ( MapListNode = (SHELL_MAP_LIST *)GetFirstNode(&gShellMapList.Link)\r | |
159 | ; !IsNull(&gShellMapList.Link, &MapListNode->Link)\r | |
160 | ; MapListNode = (SHELL_MAP_LIST *)GetNextNode(&gShellMapList.Link, &MapListNode->Link)\r | |
161 | ){\r | |
162 | if (StringNoCaseCompare(&MapListNode->MapName, &Mapping) == 0) {\r | |
163 | RemoveEntryList(&MapListNode->Link);\r | |
164 | FreePool(MapListNode);\r | |
165 | return (EFI_SUCCESS);\r | |
166 | }\r | |
167 | } // for loop\r | |
168 | \r | |
169 | //\r | |
170 | // We didnt find one to delete\r | |
171 | //\r | |
172 | return (EFI_NOT_FOUND);\r | |
173 | }\r | |
174 | \r | |
175 | //\r | |
176 | // make sure this is a valid to add device path\r | |
177 | //\r | |
178 | ///@todo add BlockIo to this test...\r | |
179 | if (!InternalShellProtocolIsSimpleFileSystemPresent(DevicePath)) {\r | |
180 | return (EFI_INVALID_PARAMETER);\r | |
181 | }\r | |
182 | \r | |
183 | //\r | |
184 | // First make sure there is no old mapping\r | |
185 | //\r | |
186 | Status = EfiShellSetMap(NULL, Mapping);\r | |
187 | if ((Status != EFI_SUCCESS) && (Status != EFI_NOT_FOUND)) {\r | |
188 | return (Status);\r | |
189 | }\r | |
190 | \r | |
191 | //\r | |
192 | // now add the new one.\r | |
193 | //\r | |
194 | Status = ShellCommandAddMapItemAndUpdatePath(Mapping, DevicePath, 0, FALSE);\r | |
195 | \r | |
196 | return(Status);\r | |
197 | }\r | |
198 | \r | |
199 | /**\r | |
200 | Gets the device path from the mapping.\r | |
201 | \r | |
202 | This function gets the device path associated with a mapping.\r | |
203 | \r | |
204 | @param Mapping A pointer to the mapping\r | |
205 | \r | |
206 | @retval !=NULL Pointer to the device path that corresponds to the\r | |
207 | device mapping. The returned pointer does not need\r | |
208 | to be freed.\r | |
209 | @retval NULL There is no device path associated with the\r | |
210 | specified mapping.\r | |
211 | **/\r | |
212 | CONST EFI_DEVICE_PATH_PROTOCOL *\r | |
213 | EFIAPI\r | |
214 | EfiShellGetDevicePathFromMap(\r | |
215 | IN CONST CHAR16 *Mapping\r | |
216 | )\r | |
217 | {\r | |
218 | SHELL_MAP_LIST *MapListItem;\r | |
219 | CHAR16 *NewName;\r | |
220 | UINTN Size;\r | |
221 | \r | |
222 | NewName = NULL;\r | |
223 | Size = 0;\r | |
224 | \r | |
225 | StrnCatGrow(&NewName, &Size, Mapping, 0);\r | |
226 | if (Mapping[StrLen(Mapping)-1] != L':') {\r | |
227 | StrnCatGrow(&NewName, &Size, L":", 0);\r | |
228 | }\r | |
229 | \r | |
230 | MapListItem = ShellCommandFindMapItem(NewName);\r | |
231 | \r | |
232 | FreePool(NewName);\r | |
233 | \r | |
234 | if (MapListItem != NULL) {\r | |
235 | return (MapListItem->DevicePath);\r | |
236 | }\r | |
237 | return(NULL);\r | |
238 | }\r | |
239 | \r | |
240 | /**\r | |
241 | Gets the mapping(s) that most closely matches the device path.\r | |
242 | \r | |
243 | This function gets the mapping which corresponds to the device path *DevicePath. If\r | |
244 | there is no exact match, then the mapping which most closely matches *DevicePath\r | |
245 | is returned, and *DevicePath is updated to point to the remaining portion of the\r | |
246 | device path. If there is an exact match, the mapping is returned and *DevicePath\r | |
247 | points to the end-of-device-path node.\r | |
248 | \r | |
249 | If there are multiple map names they will be semi-colon seperated in the\r | |
250 | NULL-terminated string.\r | |
251 | \r | |
252 | @param DevicePath On entry, points to a device path pointer. On\r | |
253 | exit, updates the pointer to point to the\r | |
254 | portion of the device path after the mapping.\r | |
255 | \r | |
256 | @retval NULL No mapping was found.\r | |
257 | @return !=NULL Pointer to NULL-terminated mapping. The buffer\r | |
258 | is callee allocated and should be freed by the caller.\r | |
259 | **/\r | |
260 | CONST CHAR16 *\r | |
261 | EFIAPI\r | |
262 | EfiShellGetMapFromDevicePath(\r | |
263 | IN OUT EFI_DEVICE_PATH_PROTOCOL **DevicePath\r | |
264 | )\r | |
265 | {\r | |
266 | SHELL_MAP_LIST *Node;\r | |
267 | CHAR16 *PathForReturn;\r | |
268 | UINTN PathSize;\r | |
269 | // EFI_HANDLE PathHandle;\r | |
270 | // EFI_HANDLE MapHandle;\r | |
271 | // EFI_STATUS Status;\r | |
272 | // EFI_DEVICE_PATH_PROTOCOL *DevicePathCopy;\r | |
273 | // EFI_DEVICE_PATH_PROTOCOL *MapPathCopy;\r | |
274 | \r | |
275 | if (DevicePath == NULL || *DevicePath == NULL) {\r | |
276 | return (NULL);\r | |
277 | }\r | |
278 | \r | |
279 | PathForReturn = NULL;\r | |
280 | PathSize = 0;\r | |
281 | \r | |
282 | for ( Node = (SHELL_MAP_LIST *)GetFirstNode(&gShellMapList.Link)\r | |
283 | ; !IsNull(&gShellMapList.Link, &Node->Link)\r | |
284 | ; Node = (SHELL_MAP_LIST *)GetNextNode(&gShellMapList.Link, &Node->Link)\r | |
285 | ){\r | |
286 | //\r | |
287 | // check for exact match\r | |
288 | //\r | |
289 | if (DevicePathCompare(DevicePath, &Node->DevicePath) == 0) {\r | |
290 | ASSERT((PathForReturn == NULL && PathSize == 0) || (PathForReturn != NULL));\r | |
291 | if (PathSize != 0) {\r | |
292 | PathForReturn = StrnCatGrow(&PathForReturn, &PathSize, L";", 0);\r | |
293 | }\r | |
294 | PathForReturn = StrnCatGrow(&PathForReturn, &PathSize, Node->MapName, 0);\r | |
295 | }\r | |
296 | }\r | |
297 | if (PathForReturn != NULL) {\r | |
298 | while (!IsDevicePathEndType (*DevicePath)) {\r | |
299 | *DevicePath = NextDevicePathNode (*DevicePath);\r | |
300 | }\r | |
301 | SetDevicePathEndNode (*DevicePath);\r | |
302 | }\r | |
303 | /*\r | |
304 | ///@todo finish code for inexact matches.\r | |
305 | if (PathForReturn == NULL) {\r | |
306 | PathSize = 0;\r | |
307 | \r | |
308 | DevicePathCopy = DuplicateDevicePath(*DevicePath);\r | |
309 | ASSERT(DevicePathCopy != NULL);\r | |
310 | Status = gBS->LocateDevicePath(&gEfiSimpleFileSystemProtocolGuid, &DevicePathCopy, &PathHandle);\r | |
311 | ASSERT_EFI_ERROR(Status);\r | |
312 | //\r | |
313 | // check each of the device paths we have to get the root of the path for consist mappings\r | |
314 | //\r | |
315 | for ( Node = (SHELL_MAP_LIST *)GetFirstNode(&gShellMapList.Link)\r | |
316 | ; !IsNull(&gShellMapList.Link, &Node->Link)\r | |
317 | ; Node = (SHELL_MAP_LIST *)GetNextNode(&gShellMapList.Link, &Node->Link)\r | |
318 | ){\r | |
319 | if ((Node->Flags & SHELL_MAP_FLAGS_CONSIST) == 0) {\r | |
320 | continue;\r | |
321 | }\r | |
322 | MapPathCopy = DuplicateDevicePath(Node->DevicePath);\r | |
323 | ASSERT(MapPathCopy != NULL);\r | |
324 | Status = gBS->LocateDevicePath(&gEfiSimpleFileSystemProtocolGuid, &MapPathCopy, &MapHandle);\r | |
325 | if (MapHandle == PathHandle) {\r | |
326 | \r | |
327 | *DevicePath = DevicePathCopy;\r | |
328 | \r | |
329 | MapPathCopy = NULL;\r | |
330 | DevicePathCopy = NULL;\r | |
331 | PathForReturn = StrnCatGrow(&PathForReturn, &PathSize, Node->MapName, 0);\r | |
332 | PathForReturn = StrnCatGrow(&PathForReturn, &PathSize, L";", 0);\r | |
333 | break;\r | |
334 | }\r | |
335 | }\r | |
336 | //\r | |
337 | // now add on the non-consistent mappings\r | |
338 | //\r | |
339 | for ( Node = (SHELL_MAP_LIST *)GetFirstNode(&gShellMapList.Link)\r | |
340 | ; !IsNull(&gShellMapList.Link, &Node->Link)\r | |
341 | ; Node = (SHELL_MAP_LIST *)GetNextNode(&gShellMapList.Link, &Node->Link)\r | |
342 | ){\r | |
343 | if ((Node->Flags & SHELL_MAP_FLAGS_CONSIST) != 0) {\r | |
344 | continue;\r | |
345 | }\r | |
346 | MapPathCopy = Node->DevicePath;\r | |
347 | ASSERT(MapPathCopy != NULL);\r | |
348 | Status = gBS->LocateDevicePath(&gEfiSimpleFileSystemProtocolGuid, &MapPathCopy, &MapHandle);\r | |
349 | if (MapHandle == PathHandle) {\r | |
350 | PathForReturn = StrnCatGrow(&PathForReturn, &PathSize, Node->MapName, 0);\r | |
351 | PathForReturn = StrnCatGrow(&PathForReturn, &PathSize, L";", 0);\r | |
352 | break;\r | |
353 | }\r | |
354 | }\r | |
355 | }\r | |
356 | */\r | |
357 | \r | |
358 | return (AddBufferToFreeList(PathForReturn));\r | |
359 | }\r | |
360 | \r | |
361 | /**\r | |
362 | Converts a device path to a file system-style path.\r | |
363 | \r | |
364 | This function converts a device path to a file system path by replacing part, or all, of\r | |
365 | the device path with the file-system mapping. If there are more than one application\r | |
366 | file system mappings, the one that most closely matches Path will be used.\r | |
367 | \r | |
368 | @param Path The pointer to the device path\r | |
369 | \r | |
370 | @retval NULL the device path could not be found.\r | |
371 | @return all The pointer of the NULL-terminated file path. The path\r | |
372 | is callee-allocated and should be freed by the caller.\r | |
373 | **/\r | |
374 | CHAR16 *\r | |
375 | EFIAPI\r | |
376 | EfiShellGetFilePathFromDevicePath(\r | |
377 | IN CONST EFI_DEVICE_PATH_PROTOCOL *Path\r | |
378 | )\r | |
379 | {\r | |
380 | EFI_DEVICE_PATH_PROTOCOL *DevicePathCopy;\r | |
381 | EFI_DEVICE_PATH_PROTOCOL *MapPathCopy;\r | |
382 | SHELL_MAP_LIST *MapListItem;\r | |
383 | CHAR16 *PathForReturn;\r | |
384 | UINTN PathSize;\r | |
385 | EFI_HANDLE PathHandle;\r | |
386 | EFI_HANDLE MapHandle;\r | |
387 | EFI_STATUS Status;\r | |
388 | FILEPATH_DEVICE_PATH *FilePath;\r | |
389 | \r | |
390 | PathForReturn = NULL;\r | |
391 | PathSize = 0;\r | |
392 | \r | |
393 | DevicePathCopy = (EFI_DEVICE_PATH_PROTOCOL*)Path;\r | |
394 | ASSERT(DevicePathCopy != NULL);\r | |
395 | if (DevicePathCopy == NULL) {\r | |
396 | return (NULL);\r | |
397 | }\r | |
398 | ///@todo BlockIo?\r | |
399 | Status = gBS->LocateDevicePath(&gEfiSimpleFileSystemProtocolGuid, &DevicePathCopy, &PathHandle);\r | |
400 | \r | |
401 | if (EFI_ERROR(Status)) {\r | |
402 | return (NULL);\r | |
403 | }\r | |
404 | //\r | |
405 | // check each of the device paths we have to get the root of the path\r | |
406 | //\r | |
407 | for ( MapListItem = (SHELL_MAP_LIST *)GetFirstNode(&gShellMapList.Link)\r | |
408 | ; !IsNull(&gShellMapList.Link, &MapListItem->Link)\r | |
409 | ; MapListItem = (SHELL_MAP_LIST *)GetNextNode(&gShellMapList.Link, &MapListItem->Link)\r | |
410 | ){\r | |
411 | MapPathCopy = (EFI_DEVICE_PATH_PROTOCOL*)MapListItem->DevicePath;\r | |
412 | ASSERT(MapPathCopy != NULL);\r | |
413 | ///@todo BlockIo?\r | |
414 | Status = gBS->LocateDevicePath(&gEfiSimpleFileSystemProtocolGuid, &MapPathCopy, &MapHandle);\r | |
415 | if (MapHandle == PathHandle) {\r | |
416 | ASSERT((PathForReturn == NULL && PathSize == 0) || (PathForReturn != NULL));\r | |
417 | PathForReturn = StrnCatGrow(&PathForReturn, &PathSize, MapListItem->MapName, 0);\r | |
418 | //\r | |
419 | // go through all the remaining nodes in the device path\r | |
420 | //\r | |
421 | for ( FilePath = (FILEPATH_DEVICE_PATH*)DevicePathCopy\r | |
422 | ; !IsDevicePathEnd (&FilePath->Header)\r | |
423 | ; FilePath = (FILEPATH_DEVICE_PATH*)NextDevicePathNode (&FilePath->Header)\r | |
424 | ){\r | |
425 | //\r | |
426 | // all the rest should be file path nodes\r | |
427 | //\r | |
428 | if ((DevicePathType(&FilePath->Header) != MEDIA_DEVICE_PATH) ||\r | |
429 | (DevicePathSubType(&FilePath->Header) != MEDIA_FILEPATH_DP)) {\r | |
430 | FreePool(PathForReturn);\r | |
431 | PathForReturn = NULL;\r | |
432 | ASSERT(FALSE);\r | |
433 | } else {\r | |
434 | //\r | |
435 | // append the path part onto the filepath.\r | |
436 | //\r | |
437 | ASSERT((PathForReturn == NULL && PathSize == 0) || (PathForReturn != NULL));\r | |
438 | PathForReturn = StrnCatGrow(&PathForReturn, &PathSize, L"\\", 1);\r | |
439 | PathForReturn = StrnCatGrow(&PathForReturn, &PathSize, FilePath->PathName, 0);\r | |
440 | }\r | |
441 | } // for loop of remaining nodes\r | |
442 | }\r | |
443 | if (PathForReturn != NULL) {\r | |
444 | break;\r | |
445 | }\r | |
446 | } // for loop of paths to check\r | |
447 | return(PathForReturn);\r | |
448 | }\r | |
449 | \r | |
450 | /**\r | |
451 | Converts a file system style name to a device path.\r | |
452 | \r | |
453 | This function converts a file system style name to a device path, by replacing any\r | |
454 | mapping references to the associated device path.\r | |
455 | \r | |
456 | @param Path the pointer to the path\r | |
457 | \r | |
458 | @return all The pointer of the file path. The file path is callee\r | |
459 | allocated and should be freed by the caller.\r | |
460 | **/\r | |
461 | EFI_DEVICE_PATH_PROTOCOL *\r | |
462 | EFIAPI\r | |
463 | EfiShellGetDevicePathFromFilePath(\r | |
464 | IN CONST CHAR16 *Path\r | |
465 | )\r | |
466 | {\r | |
467 | CHAR16 *MapName;\r | |
468 | CHAR16 *NewPath;\r | |
469 | CONST CHAR16 *Cwd;\r | |
470 | UINTN Size;\r | |
471 | CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath;\r | |
472 | EFI_DEVICE_PATH_PROTOCOL *DevicePathCopy;\r | |
473 | EFI_DEVICE_PATH_PROTOCOL *DevicePathCopyForFree;\r | |
474 | EFI_DEVICE_PATH_PROTOCOL *DevicePathForReturn;\r | |
475 | EFI_HANDLE Handle;\r | |
476 | EFI_STATUS Status;\r | |
477 | \r | |
478 | MapName = NULL;\r | |
479 | ASSERT(Path != NULL);\r | |
480 | \r | |
481 | if (StrStr(Path, L":") == NULL) {\r | |
482 | Cwd = EfiShellGetCurDir(NULL);\r | |
483 | if (Cwd == NULL) {\r | |
484 | return (NULL);\r | |
485 | }\r | |
486 | Size = StrSize(Cwd);\r | |
487 | Size += StrSize(Path);\r | |
488 | NewPath = AllocateZeroPool(Size);\r | |
489 | ASSERT(NewPath != NULL);\r | |
490 | StrCpy(NewPath, Cwd);\r | |
e9723321 | 491 | if ((NewPath[0] == (CHAR16)L'\\') &&\r |
492 | (NewPath[StrLen(NewPath)-1] == (CHAR16)L'\\')\r | |
493 | ) {\r | |
a405b86d | 494 | ((CHAR16*)NewPath)[StrLen(NewPath)-1] = CHAR_NULL;\r |
495 | }\r | |
496 | StrCat(NewPath, Path);\r | |
497 | DevicePathForReturn = EfiShellGetDevicePathFromFilePath(NewPath);\r | |
498 | FreePool(NewPath);\r | |
499 | return (DevicePathForReturn);\r | |
500 | }\r | |
501 | \r | |
502 | Size = 0;\r | |
503 | //\r | |
504 | // find the part before (but including) the : for the map name\r | |
505 | //\r | |
506 | ASSERT((MapName == NULL && Size == 0) || (MapName != NULL));\r | |
507 | MapName = StrnCatGrow(&MapName, &Size, Path, (StrStr(Path, L":")-Path+1));\r | |
508 | if (MapName[StrLen(MapName)-1] != L':') {\r | |
509 | ASSERT(FALSE);\r | |
510 | return (NULL);\r | |
511 | }\r | |
512 | \r | |
513 | //\r | |
514 | // look up the device path in the map\r | |
515 | //\r | |
516 | DevicePath = EfiShellGetDevicePathFromMap(MapName);\r | |
517 | if (DevicePath == NULL) {\r | |
518 | //\r | |
519 | // Must have been a bad Mapname\r | |
520 | //\r | |
521 | return (NULL);\r | |
522 | }\r | |
523 | \r | |
524 | //\r | |
525 | // make a copy for LocateDevicePath to modify (also save a pointer to call FreePool with)\r | |
526 | //\r | |
527 | DevicePathCopyForFree = DevicePathCopy = DuplicateDevicePath(DevicePath);\r | |
528 | if (DevicePathCopy == NULL) {\r | |
529 | ASSERT(FALSE);\r | |
530 | FreePool(MapName);\r | |
531 | return (NULL);\r | |
532 | }\r | |
533 | \r | |
534 | //\r | |
535 | // get the handle\r | |
536 | //\r | |
537 | ///@todo BlockIo?\r | |
538 | Status = gBS->LocateDevicePath(&gEfiSimpleFileSystemProtocolGuid, &DevicePathCopy, &Handle);\r | |
539 | if (EFI_ERROR(Status)) {\r | |
540 | if (DevicePathCopyForFree != NULL) {\r | |
541 | FreePool(DevicePathCopyForFree);\r | |
542 | }\r | |
543 | FreePool(MapName);\r | |
544 | return (NULL);\r | |
545 | }\r | |
546 | \r | |
547 | //\r | |
548 | // build the full device path\r | |
549 | //\r | |
550 | DevicePathForReturn = FileDevicePath(Handle, Path+StrLen(MapName)+1);\r | |
551 | \r | |
552 | FreePool(MapName);\r | |
553 | if (DevicePathCopyForFree != NULL) {\r | |
554 | FreePool(DevicePathCopyForFree);\r | |
555 | }\r | |
556 | \r | |
557 | return (DevicePathForReturn);\r | |
558 | }\r | |
559 | \r | |
560 | /**\r | |
561 | Gets the name of the device specified by the device handle.\r | |
562 | \r | |
563 | This function gets the user-readable name of the device specified by the device\r | |
564 | handle. If no user-readable name could be generated, then *BestDeviceName will be\r | |
565 | NULL and EFI_NOT_FOUND will be returned.\r | |
566 | \r | |
567 | If EFI_DEVICE_NAME_USE_COMPONENT_NAME is set, then the function will return the\r | |
568 | device's name using the EFI_COMPONENT_NAME2_PROTOCOL, if present on\r | |
569 | DeviceHandle.\r | |
570 | \r | |
571 | If EFI_DEVICE_NAME_USE_DEVICE_PATH is set, then the function will return the\r | |
572 | device's name using the EFI_DEVICE_PATH_PROTOCOL, if present on DeviceHandle.\r | |
573 | If both EFI_DEVICE_NAME_USE_COMPONENT_NAME and\r | |
574 | EFI_DEVICE_NAME_USE_DEVICE_PATH are set, then\r | |
575 | EFI_DEVICE_NAME_USE_COMPONENT_NAME will have higher priority.\r | |
576 | \r | |
577 | @param DeviceHandle The handle of the device.\r | |
578 | @param Flags Determines the possible sources of component names.\r | |
579 | Valid bits are:\r | |
580 | EFI_DEVICE_NAME_USE_COMPONENT_NAME\r | |
581 | EFI_DEVICE_NAME_USE_DEVICE_PATH\r | |
582 | @param Language A pointer to the language specified for the device\r | |
583 | name, in the same format as described in the UEFI\r | |
584 | specification, Appendix M\r | |
585 | @param BestDeviceName On return, points to the callee-allocated NULL-\r | |
586 | terminated name of the device. If no device name\r | |
587 | could be found, points to NULL. The name must be\r | |
588 | freed by the caller...\r | |
589 | \r | |
590 | @retval EFI_SUCCESS Get the name successfully.\r | |
591 | @retval EFI_NOT_FOUND Fail to get the device name.\r | |
592 | @retval EFI_INVALID_PARAMETER Flags did not have a valid bit set.\r | |
593 | @retval EFI_INVALID_PARAMETER BestDeviceName was NULL\r | |
594 | @retval EFI_INVALID_PARAMETER DeviceHandle was NULL\r | |
595 | **/\r | |
596 | EFI_STATUS\r | |
597 | EFIAPI\r | |
598 | EfiShellGetDeviceName(\r | |
599 | IN EFI_HANDLE DeviceHandle,\r | |
600 | IN EFI_SHELL_DEVICE_NAME_FLAGS Flags,\r | |
601 | IN CHAR8 *Language,\r | |
602 | OUT CHAR16 **BestDeviceName\r | |
603 | )\r | |
604 | {\r | |
605 | EFI_STATUS Status;\r | |
606 | EFI_COMPONENT_NAME2_PROTOCOL *CompName2;\r | |
607 | EFI_DEVICE_PATH_TO_TEXT_PROTOCOL *DevicePathToText;\r | |
608 | EFI_DEVICE_PATH_PROTOCOL *DevicePath;\r | |
609 | EFI_HANDLE *HandleList;\r | |
610 | UINTN HandleCount;\r | |
611 | UINTN LoopVar;\r | |
612 | CHAR16 *DeviceNameToReturn;\r | |
613 | CHAR8 *Lang;\r | |
614 | CHAR8 *TempChar;\r | |
615 | \r | |
616 | if (BestDeviceName == NULL ||\r | |
617 | DeviceHandle == NULL\r | |
618 | ){\r | |
619 | return (EFI_INVALID_PARAMETER);\r | |
620 | }\r | |
621 | \r | |
622 | //\r | |
623 | // make sure one of the 2 supported bits is on\r | |
624 | //\r | |
625 | if (((Flags & EFI_DEVICE_NAME_USE_COMPONENT_NAME) == 0) &&\r | |
626 | ((Flags & EFI_DEVICE_NAME_USE_DEVICE_PATH) == 0)) {\r | |
627 | return (EFI_INVALID_PARAMETER);\r | |
628 | }\r | |
629 | \r | |
630 | DeviceNameToReturn = NULL;\r | |
631 | *BestDeviceName = NULL;\r | |
632 | HandleList = NULL;\r | |
633 | HandleCount = 0;\r | |
634 | Lang = NULL;\r | |
635 | \r | |
636 | if ((Flags & EFI_DEVICE_NAME_USE_COMPONENT_NAME) != 0) {\r | |
637 | Status = ParseHandleDatabaseByRelationship(\r | |
638 | NULL,\r | |
639 | DeviceHandle,\r | |
640 | HR_DRIVER_BINDING_HANDLE|HR_DEVICE_DRIVER,\r | |
641 | &HandleCount,\r | |
642 | &HandleList);\r | |
643 | for (LoopVar = 0; LoopVar < HandleCount ; LoopVar++){\r | |
644 | //\r | |
645 | // Go through those handles until we get one that passes for GetComponentName\r | |
646 | //\r | |
647 | Status = gBS->OpenProtocol(\r | |
648 | HandleList[LoopVar],\r | |
649 | &gEfiComponentName2ProtocolGuid,\r | |
650 | (VOID**)&CompName2,\r | |
651 | gImageHandle,\r | |
652 | NULL,\r | |
653 | EFI_OPEN_PROTOCOL_GET_PROTOCOL);\r | |
654 | if (EFI_ERROR(Status)) {\r | |
655 | Status = gBS->OpenProtocol(\r | |
656 | HandleList[LoopVar],\r | |
657 | &gEfiComponentNameProtocolGuid,\r | |
658 | (VOID**)&CompName2,\r | |
659 | gImageHandle,\r | |
660 | NULL,\r | |
661 | EFI_OPEN_PROTOCOL_GET_PROTOCOL);\r | |
662 | }\r | |
663 | \r | |
664 | if (EFI_ERROR(Status)) {\r | |
665 | continue;\r | |
666 | }\r | |
667 | if (Language == NULL) {\r | |
668 | Lang = AllocatePool(AsciiStrSize(CompName2->SupportedLanguages));\r | |
3c865f20 | 669 | if (Lang == NULL) {\r |
670 | return (EFI_OUT_OF_RESOURCES);\r | |
671 | }\r | |
a405b86d | 672 | AsciiStrCpy(Lang, CompName2->SupportedLanguages);\r |
673 | TempChar = AsciiStrStr(Lang, ";");\r | |
674 | if (TempChar != NULL){\r | |
675 | *TempChar = CHAR_NULL;\r | |
676 | }\r | |
677 | } else {\r | |
678 | Lang = AllocatePool(AsciiStrSize(Language));\r | |
3c865f20 | 679 | if (Lang == NULL) {\r |
680 | return (EFI_OUT_OF_RESOURCES);\r | |
681 | }\r | |
a405b86d | 682 | AsciiStrCpy(Lang, Language);\r |
683 | }\r | |
684 | Status = CompName2->GetControllerName(CompName2, DeviceHandle, NULL, Lang, &DeviceNameToReturn);\r | |
685 | FreePool(Lang);\r | |
686 | Lang = NULL;\r | |
687 | if (!EFI_ERROR(Status) && DeviceNameToReturn != NULL) {\r | |
688 | break;\r | |
689 | }\r | |
690 | }\r | |
691 | if (HandleList != NULL) {\r | |
692 | FreePool(HandleList);\r | |
693 | }\r | |
694 | if (DeviceNameToReturn != NULL){\r | |
3c865f20 | 695 | ASSERT(BestDeviceName != NULL);\r |
a405b86d | 696 | StrnCatGrow(BestDeviceName, NULL, DeviceNameToReturn, 0);\r |
697 | return (EFI_SUCCESS);\r | |
698 | }\r | |
699 | //\r | |
700 | // dont return on fail since we will try device path if that bit is on\r | |
701 | //\r | |
702 | }\r | |
703 | if ((Flags & EFI_DEVICE_NAME_USE_DEVICE_PATH) != 0) {\r | |
704 | Status = gBS->LocateProtocol(\r | |
705 | &gEfiDevicePathToTextProtocolGuid,\r | |
706 | NULL,\r | |
707 | (VOID**)&DevicePathToText);\r | |
708 | //\r | |
709 | // we now have the device path to text protocol\r | |
710 | //\r | |
711 | if (!EFI_ERROR(Status)) {\r | |
712 | Status = gBS->OpenProtocol(\r | |
713 | DeviceHandle,\r | |
714 | &gEfiDevicePathProtocolGuid,\r | |
715 | (VOID**)&DevicePath,\r | |
716 | gImageHandle,\r | |
717 | NULL,\r | |
718 | EFI_OPEN_PROTOCOL_GET_PROTOCOL);\r | |
719 | if (!EFI_ERROR(Status)) {\r | |
720 | //\r | |
721 | // use device path to text on the device path\r | |
722 | //\r | |
723 | *BestDeviceName = DevicePathToText->ConvertDevicePathToText(DevicePath, TRUE, TRUE);\r | |
724 | return (EFI_SUCCESS);\r | |
725 | }\r | |
726 | }\r | |
727 | }\r | |
728 | //\r | |
729 | // none of the selected bits worked.\r | |
730 | //\r | |
731 | return (EFI_NOT_FOUND);\r | |
732 | }\r | |
733 | \r | |
734 | /**\r | |
735 | Opens the root directory of a device on a handle\r | |
736 | \r | |
737 | This function opens the root directory of a device and returns a file handle to it.\r | |
738 | \r | |
739 | @param DeviceHandle The handle of the device that contains the volume.\r | |
740 | @param FileHandle On exit, points to the file handle corresponding to the root directory on the\r | |
741 | device.\r | |
742 | \r | |
743 | @retval EFI_SUCCESS Root opened successfully.\r | |
744 | @retval EFI_NOT_FOUND EFI_SIMPLE_FILE_SYSTEM could not be found or the root directory\r | |
745 | could not be opened.\r | |
746 | @retval EFI_VOLUME_CORRUPTED The data structures in the volume were corrupted.\r | |
747 | @retval EFI_DEVICE_ERROR The device had an error\r | |
748 | **/\r | |
749 | EFI_STATUS\r | |
750 | EFIAPI\r | |
751 | EfiShellOpenRootByHandle(\r | |
752 | IN EFI_HANDLE DeviceHandle,\r | |
753 | OUT SHELL_FILE_HANDLE *FileHandle\r | |
754 | )\r | |
755 | {\r | |
756 | EFI_STATUS Status;\r | |
757 | EFI_SIMPLE_FILE_SYSTEM_PROTOCOL *SimpleFileSystem;\r | |
758 | EFI_FILE_PROTOCOL *RealFileHandle;\r | |
759 | EFI_DEVICE_PATH_PROTOCOL *DevPath;\r | |
760 | \r | |
761 | //\r | |
762 | // get the simple file system interface\r | |
763 | //\r | |
764 | Status = gBS->OpenProtocol(DeviceHandle,\r | |
765 | &gEfiSimpleFileSystemProtocolGuid,\r | |
766 | (VOID**)&SimpleFileSystem,\r | |
767 | gImageHandle,\r | |
768 | NULL,\r | |
769 | EFI_OPEN_PROTOCOL_GET_PROTOCOL);\r | |
770 | if (EFI_ERROR(Status)) {\r | |
771 | return (EFI_NOT_FOUND);\r | |
772 | }\r | |
773 | \r | |
774 | Status = gBS->OpenProtocol(DeviceHandle,\r | |
775 | &gEfiDevicePathProtocolGuid,\r | |
776 | (VOID**)&DevPath,\r | |
777 | gImageHandle,\r | |
778 | NULL,\r | |
779 | EFI_OPEN_PROTOCOL_GET_PROTOCOL);\r | |
780 | if (EFI_ERROR(Status)) {\r | |
781 | return (EFI_NOT_FOUND);\r | |
782 | }\r | |
783 | //\r | |
784 | // Open the root volume now...\r | |
785 | //\r | |
786 | Status = SimpleFileSystem->OpenVolume(SimpleFileSystem, &RealFileHandle);\r | |
787 | *FileHandle = ConvertEfiFileProtocolToShellHandle(RealFileHandle, EfiShellGetMapFromDevicePath(&DevPath));\r | |
788 | return (Status);\r | |
789 | }\r | |
790 | \r | |
791 | /**\r | |
792 | Opens the root directory of a device.\r | |
793 | \r | |
794 | This function opens the root directory of a device and returns a file handle to it.\r | |
795 | \r | |
796 | @param DevicePath Points to the device path corresponding to the device where the\r | |
797 | EFI_SIMPLE_FILE_SYSTEM_PROTOCOL is installed.\r | |
798 | @param FileHandle On exit, points to the file handle corresponding to the root directory on the\r | |
799 | device.\r | |
800 | \r | |
801 | @retval EFI_SUCCESS Root opened successfully.\r | |
802 | @retval EFI_NOT_FOUND EFI_SIMPLE_FILE_SYSTEM could not be found or the root directory\r | |
803 | could not be opened.\r | |
804 | @retval EFI_VOLUME_CORRUPTED The data structures in the volume were corrupted.\r | |
805 | @retval EFI_DEVICE_ERROR The device had an error\r | |
806 | **/\r | |
807 | EFI_STATUS\r | |
808 | EFIAPI\r | |
809 | EfiShellOpenRoot(\r | |
810 | IN EFI_DEVICE_PATH_PROTOCOL *DevicePath,\r | |
811 | OUT SHELL_FILE_HANDLE *FileHandle\r | |
812 | )\r | |
813 | {\r | |
814 | EFI_STATUS Status;\r | |
815 | EFI_HANDLE Handle;\r | |
816 | \r | |
817 | //\r | |
818 | // find the handle of the device with that device handle and the file system\r | |
819 | //\r | |
820 | ///@todo BlockIo?\r | |
821 | Status = gBS->LocateDevicePath(&gEfiSimpleFileSystemProtocolGuid,\r | |
822 | &DevicePath,\r | |
823 | &Handle);\r | |
824 | if (EFI_ERROR(Status)) {\r | |
825 | return (EFI_NOT_FOUND);\r | |
826 | }\r | |
827 | \r | |
828 | return (EfiShellOpenRootByHandle(Handle, FileHandle));\r | |
829 | }\r | |
830 | \r | |
831 | /**\r | |
832 | Returns whether any script files are currently being processed.\r | |
833 | \r | |
834 | @retval TRUE There is at least one script file active.\r | |
835 | @retval FALSE No script files are active now.\r | |
836 | \r | |
837 | **/\r | |
838 | BOOLEAN\r | |
839 | EFIAPI\r | |
840 | EfiShellBatchIsActive (\r | |
841 | VOID\r | |
842 | )\r | |
843 | {\r | |
844 | if (ShellCommandGetCurrentScriptFile() == NULL) {\r | |
845 | return (FALSE);\r | |
846 | }\r | |
847 | return (TRUE);\r | |
848 | }\r | |
849 | \r | |
850 | /**\r | |
851 | Worker function to open a file based on a device path. this will open the root\r | |
852 | of the volume and then traverse down to the file itself.\r | |
853 | \r | |
854 | @param DevicePath Device Path of the file.\r | |
855 | @param FileHandle Pointer to the file upon a successful return.\r | |
856 | @param OpenMode mode to open file in.\r | |
857 | @param Attributes the File Attributes to use when creating a new file.\r | |
858 | \r | |
859 | @retval EFI_SUCCESS the file is open and FileHandle is valid\r | |
860 | @retval EFI_UNSUPPORTED the device path cotained non-path elements\r | |
861 | @retval other an error ocurred.\r | |
862 | **/\r | |
863 | EFI_STATUS\r | |
864 | EFIAPI\r | |
865 | InternalOpenFileDevicePath(\r | |
866 | IN OUT EFI_DEVICE_PATH_PROTOCOL *DevicePath,\r | |
867 | OUT SHELL_FILE_HANDLE *FileHandle,\r | |
868 | IN UINT64 OpenMode,\r | |
869 | IN UINT64 Attributes OPTIONAL\r | |
870 | )\r | |
871 | {\r | |
872 | EFI_STATUS Status;\r | |
873 | FILEPATH_DEVICE_PATH *FilePathNode;\r | |
874 | EFI_HANDLE Handle;\r | |
875 | SHELL_FILE_HANDLE ShellHandle;\r | |
876 | EFI_FILE_PROTOCOL *Handle1;\r | |
877 | EFI_FILE_PROTOCOL *Handle2;\r | |
878 | EFI_DEVICE_PATH_PROTOCOL *DpCopy;\r | |
879 | \r | |
880 | ASSERT(FileHandle != NULL);\r | |
881 | *FileHandle = NULL;\r | |
882 | Handle1 = NULL;\r | |
883 | DpCopy = DevicePath;\r | |
884 | \r | |
885 | Status = EfiShellOpenRoot(DevicePath, &ShellHandle);\r | |
886 | \r | |
887 | if (!EFI_ERROR(Status)) {\r | |
888 | Handle1 = ConvertShellHandleToEfiFileProtocol(ShellHandle);\r | |
889 | //\r | |
890 | // chop off the begining part before the file system part...\r | |
891 | //\r | |
892 | ///@todo BlockIo?\r | |
893 | Status = gBS->LocateDevicePath(&gEfiSimpleFileSystemProtocolGuid,\r | |
894 | &DevicePath,\r | |
895 | &Handle);\r | |
896 | if (!EFI_ERROR(Status)) {\r | |
897 | //\r | |
898 | // To access as a file system, the file path should only\r | |
899 | // contain file path components. Follow the file path nodes\r | |
900 | // and find the target file\r | |
901 | //\r | |
902 | for ( FilePathNode = (FILEPATH_DEVICE_PATH *)DevicePath\r | |
903 | ; !IsDevicePathEnd (&FilePathNode->Header)\r | |
904 | ; FilePathNode = (FILEPATH_DEVICE_PATH *) NextDevicePathNode (&FilePathNode->Header)\r | |
905 | ){\r | |
906 | //\r | |
907 | // For file system access each node should be a file path component\r | |
908 | //\r | |
909 | if (DevicePathType (&FilePathNode->Header) != MEDIA_DEVICE_PATH ||\r | |
910 | DevicePathSubType (&FilePathNode->Header) != MEDIA_FILEPATH_DP\r | |
911 | ) {\r | |
912 | Status = EFI_UNSUPPORTED;\r | |
913 | break;\r | |
914 | }\r | |
915 | \r | |
916 | //\r | |
917 | // Open this file path node\r | |
918 | //\r | |
919 | Handle2 = Handle1;\r | |
920 | Handle1 = NULL;\r | |
921 | \r | |
922 | //\r | |
923 | // if this is the last node in the DevicePath always create (if that was requested).\r | |
924 | //\r | |
925 | if (IsDevicePathEnd ((NextDevicePathNode (&FilePathNode->Header)))) {\r | |
926 | Status = Handle2->Open (\r | |
927 | Handle2,\r | |
928 | &Handle1,\r | |
929 | FilePathNode->PathName,\r | |
930 | OpenMode,\r | |
931 | Attributes\r | |
932 | );\r | |
933 | } else {\r | |
934 | \r | |
935 | //\r | |
936 | // This is not the last node and we dont want to 'create' existing\r | |
937 | // directory entries...\r | |
938 | //\r | |
939 | \r | |
940 | //\r | |
941 | // open without letting it create\r | |
942 | // prevents error on existing files/directories\r | |
943 | //\r | |
944 | Status = Handle2->Open (\r | |
945 | Handle2,\r | |
946 | &Handle1,\r | |
947 | FilePathNode->PathName,\r | |
948 | OpenMode &~EFI_FILE_MODE_CREATE,\r | |
949 | Attributes\r | |
950 | );\r | |
951 | //\r | |
952 | // if above failed now open and create the 'item'\r | |
953 | // if OpenMode EFI_FILE_MODE_CREATE bit was on (but disabled above)\r | |
954 | //\r | |
955 | if ((EFI_ERROR (Status)) && ((OpenMode & EFI_FILE_MODE_CREATE) != 0)) {\r | |
956 | Status = Handle2->Open (\r | |
957 | Handle2,\r | |
958 | &Handle1,\r | |
959 | FilePathNode->PathName,\r | |
960 | OpenMode,\r | |
961 | Attributes\r | |
962 | );\r | |
963 | }\r | |
964 | }\r | |
965 | //\r | |
966 | // Close the last node\r | |
967 | //\r | |
968 | Handle2->Close (Handle2);\r | |
969 | \r | |
970 | //\r | |
971 | // If there's been an error, stop\r | |
972 | //\r | |
973 | if (EFI_ERROR (Status)) {\r | |
974 | break;\r | |
975 | }\r | |
976 | } // for loop\r | |
977 | }\r | |
978 | }\r | |
979 | if (EFI_ERROR(Status)) {\r | |
980 | if (Handle1 != NULL) {\r | |
981 | Handle1->Close(Handle1);\r | |
982 | }\r | |
983 | } else {\r | |
984 | *FileHandle = ConvertEfiFileProtocolToShellHandle(Handle1, ShellFileHandleGetPath(ShellHandle));\r | |
985 | }\r | |
986 | return (Status);\r | |
987 | }\r | |
988 | \r | |
989 | /**\r | |
990 | Creates a file or directory by name.\r | |
991 | \r | |
992 | This function creates an empty new file or directory with the specified attributes and\r | |
993 | returns the new file's handle. If the file already exists and is read-only, then\r | |
994 | EFI_INVALID_PARAMETER will be returned.\r | |
995 | \r | |
996 | If the file already existed, it is truncated and its attributes updated. If the file is\r | |
997 | created successfully, the FileHandle is the file's handle, else, the FileHandle is NULL.\r | |
998 | \r | |
999 | If the file name begins with >v, then the file handle which is returned refers to the\r | |
1000 | shell environment variable with the specified name. If the shell environment variable\r | |
1001 | already exists and is non-volatile then EFI_INVALID_PARAMETER is returned.\r | |
1002 | \r | |
1003 | @param FileName Pointer to NULL-terminated file path\r | |
1004 | @param FileAttribs The new file's attrbiutes. the different attributes are\r | |
1005 | described in EFI_FILE_PROTOCOL.Open().\r | |
1006 | @param FileHandle On return, points to the created file handle or directory's handle\r | |
1007 | \r | |
1008 | @retval EFI_SUCCESS The file was opened. FileHandle points to the new file's handle.\r | |
1009 | @retval EFI_INVALID_PARAMETER One of the parameters has an invalid value.\r | |
1010 | @retval EFI_UNSUPPORTED could not open the file path\r | |
1011 | @retval EFI_NOT_FOUND the specified file could not be found on the devide, or could not\r | |
1012 | file the file system on the device.\r | |
1013 | @retval EFI_NO_MEDIA the device has no medium.\r | |
1014 | @retval EFI_MEDIA_CHANGED The device has a different medium in it or the medium is no\r | |
1015 | longer supported.\r | |
1016 | @retval EFI_DEVICE_ERROR The device reported an error or can't get the file path according\r | |
1017 | the DirName.\r | |
1018 | @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.\r | |
1019 | @retval EFI_WRITE_PROTECTED An attempt was made to create a file, or open a file for write\r | |
1020 | when the media is write-protected.\r | |
1021 | @retval EFI_ACCESS_DENIED The service denied access to the file.\r | |
1022 | @retval EFI_OUT_OF_RESOURCES Not enough resources were available to open the file.\r | |
1023 | @retval EFI_VOLUME_FULL The volume is full.\r | |
1024 | **/\r | |
1025 | EFI_STATUS\r | |
1026 | EFIAPI\r | |
1027 | EfiShellCreateFile(\r | |
1028 | IN CONST CHAR16 *FileName,\r | |
1029 | IN UINT64 FileAttribs,\r | |
1030 | OUT SHELL_FILE_HANDLE *FileHandle\r | |
1031 | )\r | |
1032 | {\r | |
1033 | EFI_DEVICE_PATH_PROTOCOL *DevicePath;\r | |
1034 | EFI_STATUS Status;\r | |
1035 | \r | |
1036 | //\r | |
1037 | // Is this for an environment variable\r | |
1038 | // do we start with >v\r | |
1039 | //\r | |
1040 | if (StrStr(FileName, L">v") == FileName) {\r | |
1041 | if (!IsVolatileEnv(FileName+2)) {\r | |
1042 | return (EFI_INVALID_PARAMETER);\r | |
1043 | }\r | |
1044 | *FileHandle = CreateFileInterfaceEnv(FileName+2);\r | |
1045 | return (EFI_SUCCESS);\r | |
1046 | }\r | |
1047 | \r | |
1048 | //\r | |
1049 | // We are opening a regular file.\r | |
1050 | //\r | |
1051 | DevicePath = EfiShellGetDevicePathFromFilePath(FileName);\r | |
1052 | if (DevicePath == NULL) {\r | |
1053 | return (EFI_NOT_FOUND);\r | |
1054 | }\r | |
1055 | \r | |
1056 | Status = InternalOpenFileDevicePath(DevicePath, FileHandle, EFI_FILE_MODE_READ|EFI_FILE_MODE_WRITE|EFI_FILE_MODE_CREATE, FileAttribs); // 0 = no specific file attributes\r | |
1057 | FreePool(DevicePath);\r | |
1058 | \r | |
1059 | return(Status);\r | |
1060 | }\r | |
1061 | \r | |
1062 | /**\r | |
1063 | Opens a file or a directory by file name.\r | |
1064 | \r | |
1065 | This function opens the specified file in the specified OpenMode and returns a file\r | |
1066 | handle.\r | |
1067 | If the file name begins with >v, then the file handle which is returned refers to the\r | |
1068 | shell environment variable with the specified name. If the shell environment variable\r | |
1069 | exists, is non-volatile and the OpenMode indicates EFI_FILE_MODE_WRITE, then\r | |
1070 | EFI_INVALID_PARAMETER is returned.\r | |
1071 | \r | |
1072 | If the file name is >i, then the file handle which is returned refers to the standard\r | |
1073 | input. If the OpenMode indicates EFI_FILE_MODE_WRITE, then EFI_INVALID_PARAMETER\r | |
1074 | is returned.\r | |
1075 | \r | |
1076 | If the file name is >o, then the file handle which is returned refers to the standard\r | |
1077 | output. If the OpenMode indicates EFI_FILE_MODE_READ, then EFI_INVALID_PARAMETER\r | |
1078 | is returned.\r | |
1079 | \r | |
1080 | If the file name is >e, then the file handle which is returned refers to the standard\r | |
1081 | error. If the OpenMode indicates EFI_FILE_MODE_READ, then EFI_INVALID_PARAMETER\r | |
1082 | is returned.\r | |
1083 | \r | |
1084 | If the file name is NUL, then the file handle that is returned refers to the standard NUL\r | |
1085 | file. If the OpenMode indicates EFI_FILE_MODE_READ, then EFI_INVALID_PARAMETER is\r | |
1086 | returned.\r | |
1087 | \r | |
1088 | If return EFI_SUCCESS, the FileHandle is the opened file's handle, else, the\r | |
1089 | FileHandle is NULL.\r | |
1090 | \r | |
1091 | @param FileName Points to the NULL-terminated UCS-2 encoded file name.\r | |
1092 | @param FileHandle On return, points to the file handle.\r | |
1093 | @param OpenMode File open mode. Either EFI_FILE_MODE_READ or\r | |
1094 | EFI_FILE_MODE_WRITE from section 12.4 of the UEFI\r | |
1095 | Specification.\r | |
1096 | @retval EFI_SUCCESS The file was opened. FileHandle has the opened file's handle.\r | |
1097 | @retval EFI_INVALID_PARAMETER One of the parameters has an invalid value. FileHandle is NULL.\r | |
1098 | @retval EFI_UNSUPPORTED Could not open the file path. FileHandle is NULL.\r | |
1099 | @retval EFI_NOT_FOUND The specified file could not be found on the device or the file\r | |
1100 | system could not be found on the device. FileHandle is NULL.\r | |
1101 | @retval EFI_NO_MEDIA The device has no medium. FileHandle is NULL.\r | |
1102 | @retval EFI_MEDIA_CHANGED The device has a different medium in it or the medium is no\r | |
1103 | longer supported. FileHandle is NULL.\r | |
1104 | @retval EFI_DEVICE_ERROR The device reported an error or can't get the file path according\r | |
1105 | the FileName. FileHandle is NULL.\r | |
1106 | @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted. FileHandle is NULL.\r | |
1107 | @retval EFI_WRITE_PROTECTED An attempt was made to create a file, or open a file for write\r | |
1108 | when the media is write-protected. FileHandle is NULL.\r | |
1109 | @retval EFI_ACCESS_DENIED The service denied access to the file. FileHandle is NULL.\r | |
1110 | @retval EFI_OUT_OF_RESOURCES Not enough resources were available to open the file. FileHandle\r | |
1111 | is NULL.\r | |
1112 | @retval EFI_VOLUME_FULL The volume is full. FileHandle is NULL.\r | |
1113 | **/\r | |
1114 | EFI_STATUS\r | |
1115 | EFIAPI\r | |
1116 | EfiShellOpenFileByName(\r | |
1117 | IN CONST CHAR16 *FileName,\r | |
1118 | OUT SHELL_FILE_HANDLE *FileHandle,\r | |
1119 | IN UINT64 OpenMode\r | |
1120 | )\r | |
1121 | {\r | |
1122 | EFI_DEVICE_PATH_PROTOCOL *DevicePath;\r | |
1123 | EFI_STATUS Status;\r | |
1124 | \r | |
1125 | *FileHandle = NULL;\r | |
1126 | \r | |
1127 | //\r | |
1128 | // Is this for StdIn\r | |
1129 | //\r | |
1130 | if (StrCmp(FileName, L">i") == 0) {\r | |
1131 | //\r | |
1132 | // make sure not writing to StdIn\r | |
1133 | //\r | |
1134 | if ((OpenMode & EFI_FILE_MODE_WRITE) != 0) {\r | |
1135 | return (EFI_INVALID_PARAMETER);\r | |
1136 | }\r | |
1137 | *FileHandle = ShellInfoObject.NewShellParametersProtocol->StdIn;\r | |
1138 | ASSERT(*FileHandle != NULL);\r | |
1139 | return (EFI_SUCCESS);\r | |
1140 | }\r | |
1141 | \r | |
1142 | //\r | |
1143 | // Is this for StdOut\r | |
1144 | //\r | |
1145 | if (StrCmp(FileName, L">o") == 0) {\r | |
1146 | //\r | |
1147 | // make sure not writing to StdIn\r | |
1148 | //\r | |
1149 | if ((OpenMode & EFI_FILE_MODE_READ) != 0) {\r | |
1150 | return (EFI_INVALID_PARAMETER);\r | |
1151 | }\r | |
1152 | *FileHandle = &FileInterfaceStdOut;\r | |
1153 | return (EFI_SUCCESS);\r | |
1154 | }\r | |
1155 | \r | |
1156 | //\r | |
1157 | // Is this for NUL file\r | |
1158 | //\r | |
1159 | if (StrCmp(FileName, L"NUL") == 0) {\r | |
1160 | *FileHandle = &FileInterfaceNulFile;\r | |
1161 | return (EFI_SUCCESS);\r | |
1162 | }\r | |
1163 | \r | |
1164 | //\r | |
1165 | // Is this for StdErr\r | |
1166 | //\r | |
1167 | if (StrCmp(FileName, L">e") == 0) {\r | |
1168 | //\r | |
1169 | // make sure not writing to StdIn\r | |
1170 | //\r | |
1171 | if ((OpenMode & EFI_FILE_MODE_READ) != 0) {\r | |
1172 | return (EFI_INVALID_PARAMETER);\r | |
1173 | }\r | |
1174 | *FileHandle = &FileInterfaceStdErr;\r | |
1175 | return (EFI_SUCCESS);\r | |
1176 | }\r | |
1177 | \r | |
1178 | //\r | |
1179 | // Is this for an environment variable\r | |
1180 | // do we start with >v\r | |
1181 | //\r | |
1182 | if (StrStr(FileName, L">v") == FileName) {\r | |
1183 | if (!IsVolatileEnv(FileName+2) &&\r | |
1184 | ((OpenMode & EFI_FILE_MODE_WRITE) != 0)) {\r | |
1185 | return (EFI_INVALID_PARAMETER);\r | |
1186 | }\r | |
1187 | *FileHandle = CreateFileInterfaceEnv(FileName+2);\r | |
1188 | return (EFI_SUCCESS);\r | |
1189 | }\r | |
1190 | \r | |
1191 | //\r | |
1192 | // We are opening a regular file.\r | |
1193 | //\r | |
1194 | DevicePath = EfiShellGetDevicePathFromFilePath(FileName);\r | |
1195 | // DEBUG_CODE(InternalShellProtocolDebugPrintMessage (NULL, DevicePath););\r | |
1196 | if (DevicePath == NULL) {\r | |
1197 | return (EFI_NOT_FOUND);\r | |
1198 | }\r | |
1199 | \r | |
1200 | //\r | |
1201 | // Copy the device path, open the file, then free the memory\r | |
1202 | //\r | |
1203 | Status = InternalOpenFileDevicePath(DevicePath, FileHandle, OpenMode, 0); // 0 = no specific file attributes\r | |
1204 | FreePool(DevicePath);\r | |
1205 | \r | |
1206 | return(Status);\r | |
1207 | }\r | |
1208 | \r | |
1209 | /**\r | |
1210 | Deletes the file specified by the file name.\r | |
1211 | \r | |
1212 | This function deletes a file.\r | |
1213 | \r | |
1214 | @param FileName Points to the NULL-terminated file name.\r | |
1215 | \r | |
1216 | @retval EFI_SUCCESS The file was closed and deleted, and the handle was closed.\r | |
1217 | @retval EFI_WARN_DELETE_FAILURE The handle was closed but the file was not deleted.\r | |
1218 | @sa EfiShellCreateFile\r | |
1219 | **/\r | |
1220 | EFI_STATUS\r | |
1221 | EFIAPI\r | |
1222 | EfiShellDeleteFileByName(\r | |
1223 | IN CONST CHAR16 *FileName\r | |
1224 | )\r | |
1225 | {\r | |
1226 | SHELL_FILE_HANDLE FileHandle;\r | |
1227 | EFI_STATUS Status;\r | |
1228 | \r | |
1229 | //\r | |
1230 | // get a handle to the file\r | |
1231 | //\r | |
1232 | Status = EfiShellCreateFile(FileName,\r | |
1233 | 0,\r | |
1234 | &FileHandle);\r | |
1235 | if (EFI_ERROR(Status)) {\r | |
1236 | return (Status);\r | |
1237 | }\r | |
1238 | //\r | |
1239 | // now delete the file\r | |
1240 | //\r | |
1241 | return (ShellInfoObject.NewEfiShellProtocol->DeleteFile(FileHandle));\r | |
1242 | }\r | |
1243 | \r | |
1244 | /**\r | |
1245 | Disables the page break output mode.\r | |
1246 | **/\r | |
1247 | VOID\r | |
1248 | EFIAPI\r | |
1249 | EfiShellDisablePageBreak (\r | |
1250 | VOID\r | |
1251 | )\r | |
1252 | {\r | |
1253 | ShellInfoObject.PageBreakEnabled = FALSE;\r | |
1254 | }\r | |
1255 | \r | |
1256 | /**\r | |
1257 | Enables the page break output mode.\r | |
1258 | **/\r | |
1259 | VOID\r | |
1260 | EFIAPI\r | |
1261 | EfiShellEnablePageBreak (\r | |
1262 | VOID\r | |
1263 | )\r | |
1264 | {\r | |
1265 | ShellInfoObject.PageBreakEnabled = TRUE;\r | |
1266 | }\r | |
1267 | \r | |
1268 | /**\r | |
1269 | internal worker function to load and run an image via device path.\r | |
1270 | \r | |
1271 | @param ParentImageHandle A handle of the image that is executing the specified\r | |
1272 | command line.\r | |
1273 | @param DevicePath device path of the file to execute\r | |
1274 | @param CommandLine Points to the NULL-terminated UCS-2 encoded string\r | |
1275 | containing the command line. If NULL then the command-\r | |
1276 | line will be empty.\r | |
1277 | @param Environment Points to a NULL-terminated array of environment\r | |
1278 | variables with the format 'x=y', where x is the\r | |
1279 | environment variable name and y is the value. If this\r | |
1280 | is NULL, then the current shell environment is used.\r | |
1281 | @param StatusCode Points to the status code returned by the command.\r | |
1282 | \r | |
1283 | @retval EFI_SUCCESS The command executed successfully. The status code\r | |
1284 | returned by the command is pointed to by StatusCode.\r | |
1285 | @retval EFI_INVALID_PARAMETER The parameters are invalid.\r | |
1286 | @retval EFI_OUT_OF_RESOURCES Out of resources.\r | |
1287 | @retval EFI_UNSUPPORTED Nested shell invocations are not allowed.\r | |
1288 | **/\r | |
1289 | EFI_STATUS\r | |
1290 | EFIAPI\r | |
1291 | InternalShellExecuteDevicePath(\r | |
1292 | IN CONST EFI_HANDLE *ParentImageHandle,\r | |
1293 | IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath,\r | |
1294 | IN CONST CHAR16 *CommandLine OPTIONAL,\r | |
1295 | IN CONST CHAR16 **Environment OPTIONAL,\r | |
1296 | OUT EFI_STATUS *StatusCode OPTIONAL\r | |
1297 | )\r | |
1298 | {\r | |
1299 | EFI_STATUS Status;\r | |
1300 | EFI_HANDLE NewHandle;\r | |
1301 | EFI_LOADED_IMAGE_PROTOCOL *LoadedImage;\r | |
1302 | LIST_ENTRY OrigEnvs;\r | |
1303 | EFI_SHELL_PARAMETERS_PROTOCOL ShellParamsProtocol;\r | |
1304 | \r | |
1305 | if (ParentImageHandle == NULL) {\r | |
1306 | return (EFI_INVALID_PARAMETER);\r | |
1307 | }\r | |
1308 | \r | |
1309 | InitializeListHead(&OrigEnvs);\r | |
1310 | \r | |
1311 | NewHandle = NULL;\r | |
1312 | \r | |
1313 | //\r | |
1314 | // Load the image with:\r | |
1315 | // FALSE - not from boot manager and NULL, 0 being not already in memory\r | |
1316 | //\r | |
1317 | Status = gBS->LoadImage(\r | |
1318 | FALSE,\r | |
1319 | *ParentImageHandle,\r | |
1320 | (EFI_DEVICE_PATH_PROTOCOL*)DevicePath,\r | |
1321 | NULL,\r | |
1322 | 0,\r | |
1323 | &NewHandle);\r | |
1324 | \r | |
1325 | if (EFI_ERROR(Status)) {\r | |
1326 | if (NewHandle != NULL) {\r | |
1327 | gBS->UnloadImage(NewHandle);\r | |
1328 | }\r | |
1329 | return (Status);\r | |
1330 | }\r | |
1331 | Status = gBS->OpenProtocol(\r | |
1332 | NewHandle,\r | |
1333 | &gEfiLoadedImageProtocolGuid,\r | |
1334 | (VOID**)&LoadedImage,\r | |
1335 | gImageHandle,\r | |
1336 | NULL,\r | |
1337 | EFI_OPEN_PROTOCOL_GET_PROTOCOL);\r | |
1338 | \r | |
1339 | if (!EFI_ERROR(Status)) {\r | |
1340 | ASSERT(LoadedImage->LoadOptionsSize == 0);\r | |
1341 | if (CommandLine != NULL) {\r | |
1342 | LoadedImage->LoadOptionsSize = (UINT32)StrSize(CommandLine);\r | |
1343 | LoadedImage->LoadOptions = (VOID*)CommandLine;\r | |
1344 | }\r | |
1345 | \r | |
1346 | //\r | |
1347 | // Save our current environment settings for later restoration if necessary\r | |
1348 | //\r | |
1349 | if (Environment != NULL) {\r | |
1350 | Status = GetEnvironmentVariableList(&OrigEnvs);\r | |
1351 | if (!EFI_ERROR(Status)) {\r | |
1352 | Status = SetEnvironmentVariables(Environment);\r | |
1353 | }\r | |
1354 | }\r | |
1355 | \r | |
1356 | //\r | |
1357 | // Initialize and install a shell parameters protocol on the image.\r | |
1358 | //\r | |
1359 | ShellParamsProtocol.StdIn = ShellInfoObject.NewShellParametersProtocol->StdIn;\r | |
1360 | ShellParamsProtocol.StdOut = ShellInfoObject.NewShellParametersProtocol->StdOut;\r | |
1361 | ShellParamsProtocol.StdErr = ShellInfoObject.NewShellParametersProtocol->StdErr;\r | |
1362 | Status = UpdateArgcArgv(&ShellParamsProtocol, CommandLine, NULL, NULL);\r | |
1363 | ASSERT_EFI_ERROR(Status);\r | |
1364 | Status = gBS->InstallProtocolInterface(&NewHandle, &gEfiShellParametersProtocolGuid, EFI_NATIVE_INTERFACE, &ShellParamsProtocol);\r | |
1365 | ASSERT_EFI_ERROR(Status);\r | |
1366 | \r | |
1367 | ///@todo initialize and install ShellInterface protocol on the new image for compatibility if - PcdGetBool(PcdShellSupportOldProtocols)\r | |
1368 | \r | |
1369 | //\r | |
1370 | // now start the image and if the caller wanted the return code pass it to them...\r | |
1371 | //\r | |
1372 | if (!EFI_ERROR(Status)) {\r | |
1373 | if (StatusCode != NULL) {\r | |
1374 | *StatusCode = gBS->StartImage(NewHandle, NULL, NULL);\r | |
1375 | } else {\r | |
1376 | Status = gBS->StartImage(NewHandle, NULL, NULL);\r | |
1377 | }\r | |
1378 | }\r | |
1379 | \r | |
1380 | //\r | |
1381 | // Cleanup (and dont overwrite errors)\r | |
1382 | //\r | |
1383 | if (EFI_ERROR(Status)) {\r | |
1384 | gBS->UninstallProtocolInterface(NewHandle, &gEfiShellParametersProtocolGuid, &ShellParamsProtocol);\r | |
1385 | } else {\r | |
1386 | Status = gBS->UninstallProtocolInterface(NewHandle, &gEfiShellParametersProtocolGuid, &ShellParamsProtocol);\r | |
1387 | ASSERT_EFI_ERROR(Status);\r | |
1388 | }\r | |
1389 | }\r | |
1390 | \r | |
1391 | if (!IsListEmpty(&OrigEnvs)) {\r | |
1392 | if (EFI_ERROR(Status)) {\r | |
1393 | SetEnvironmentVariableList(&OrigEnvs);\r | |
1394 | } else {\r | |
1395 | Status = SetEnvironmentVariableList(&OrigEnvs);\r | |
1396 | }\r | |
1397 | }\r | |
1398 | \r | |
1399 | return(Status);\r | |
1400 | }\r | |
1401 | /**\r | |
1402 | Execute the command line.\r | |
1403 | \r | |
1404 | This function creates a nested instance of the shell and executes the specified\r | |
1405 | command (CommandLine) with the specified environment (Environment). Upon return,\r | |
1406 | the status code returned by the specified command is placed in StatusCode.\r | |
1407 | \r | |
1408 | If Environment is NULL, then the current environment is used and all changes made\r | |
1409 | by the commands executed will be reflected in the current environment. If the\r | |
1410 | Environment is non-NULL, then the changes made will be discarded.\r | |
1411 | \r | |
1412 | The CommandLine is executed from the current working directory on the current\r | |
1413 | device.\r | |
1414 | \r | |
1415 | @param ParentImageHandle A handle of the image that is executing the specified\r | |
1416 | command line.\r | |
1417 | @param CommandLine Points to the NULL-terminated UCS-2 encoded string\r | |
1418 | containing the command line. If NULL then the command-\r | |
1419 | line will be empty.\r | |
1420 | @param Environment Points to a NULL-terminated array of environment\r | |
1421 | variables with the format 'x=y', where x is the\r | |
1422 | environment variable name and y is the value. If this\r | |
1423 | is NULL, then the current shell environment is used.\r | |
1424 | @param StatusCode Points to the status code returned by the command.\r | |
1425 | \r | |
1426 | @retval EFI_SUCCESS The command executed successfully. The status code\r | |
1427 | returned by the command is pointed to by StatusCode.\r | |
1428 | @retval EFI_INVALID_PARAMETER The parameters are invalid.\r | |
1429 | @retval EFI_OUT_OF_RESOURCES Out of resources.\r | |
1430 | @retval EFI_UNSUPPORTED Nested shell invocations are not allowed.\r | |
1431 | @retval EFI_UNSUPPORTED The support level required for this function is not present.\r | |
1432 | \r | |
1433 | @sa InternalShellExecuteDevicePath\r | |
1434 | **/\r | |
1435 | EFI_STATUS\r | |
1436 | EFIAPI\r | |
1437 | EfiShellExecute(\r | |
1438 | IN EFI_HANDLE *ParentImageHandle,\r | |
1439 | IN CHAR16 *CommandLine OPTIONAL,\r | |
1440 | IN CHAR16 **Environment OPTIONAL,\r | |
1441 | OUT EFI_STATUS *StatusCode OPTIONAL\r | |
1442 | )\r | |
1443 | {\r | |
1444 | EFI_STATUS Status;\r | |
1445 | CHAR16 *Temp;\r | |
1446 | EFI_DEVICE_PATH_PROTOCOL *DevPath;\r | |
1447 | UINTN Size;\r | |
1448 | \r | |
1449 | if ((PcdGet8(PcdShellSupportLevel) < 1)) {\r | |
1450 | return (EFI_UNSUPPORTED);\r | |
1451 | }\r | |
1452 | \r | |
1453 | DevPath = AppendDevicePath (ShellInfoObject.ImageDevPath, ShellInfoObject.FileDevPath);\r | |
1454 | \r | |
1455 | DEBUG_CODE_BEGIN();\r | |
1456 | Temp = gDevPathToText->ConvertDevicePathToText(ShellInfoObject.FileDevPath, TRUE, TRUE);\r | |
1457 | FreePool(Temp);\r | |
1458 | Temp = gDevPathToText->ConvertDevicePathToText(ShellInfoObject.ImageDevPath, TRUE, TRUE);\r | |
1459 | FreePool(Temp);\r | |
1460 | Temp = gDevPathToText->ConvertDevicePathToText(DevPath, TRUE, TRUE);\r | |
1461 | FreePool(Temp);\r | |
1462 | DEBUG_CODE_END();\r | |
1463 | \r | |
1464 | Temp = NULL;\r | |
1465 | Size = 0;\r | |
1466 | ASSERT((Temp == NULL && Size == 0) || (Temp != NULL));\r | |
1467 | StrnCatGrow(&Temp, &Size, L"Shell.efi ", 0);\r | |
1468 | StrnCatGrow(&Temp, &Size, CommandLine, 0);\r | |
1469 | \r | |
1470 | Status = InternalShellExecuteDevicePath(\r | |
1471 | ParentImageHandle,\r | |
1472 | DevPath,\r | |
1473 | Temp,\r | |
1474 | (CONST CHAR16**)Environment,\r | |
1475 | StatusCode);\r | |
1476 | \r | |
1477 | //\r | |
1478 | // de-allocate and return\r | |
1479 | //\r | |
1480 | FreePool(DevPath);\r | |
1481 | FreePool(Temp);\r | |
1482 | return(Status);\r | |
1483 | }\r | |
1484 | \r | |
1485 | /**\r | |
1486 | Utility cleanup function for EFI_SHELL_FILE_INFO objects.\r | |
1487 | \r | |
1488 | 1) frees all pointers (non-NULL)\r | |
1489 | 2) Closes the SHELL_FILE_HANDLE\r | |
1490 | \r | |
1491 | @param FileListNode pointer to the list node to free\r | |
1492 | **/\r | |
1493 | VOID\r | |
1494 | EFIAPI\r | |
1495 | InternalFreeShellFileInfoNode(\r | |
1496 | IN EFI_SHELL_FILE_INFO *FileListNode\r | |
1497 | )\r | |
1498 | {\r | |
1499 | if (FileListNode->Info != NULL) {\r | |
1500 | FreePool((VOID*)FileListNode->Info);\r | |
1501 | }\r | |
1502 | if (FileListNode->FileName != NULL) {\r | |
1503 | FreePool((VOID*)FileListNode->FileName);\r | |
1504 | }\r | |
1505 | if (FileListNode->FullName != NULL) {\r | |
1506 | FreePool((VOID*)FileListNode->FullName);\r | |
1507 | }\r | |
1508 | if (FileListNode->Handle != NULL) {\r | |
1509 | ShellInfoObject.NewEfiShellProtocol->CloseFile(FileListNode->Handle);\r | |
1510 | }\r | |
1511 | FreePool(FileListNode);\r | |
1512 | }\r | |
1513 | /**\r | |
1514 | Frees the file list.\r | |
1515 | \r | |
1516 | This function cleans up the file list and any related data structures. It has no\r | |
1517 | impact on the files themselves.\r | |
1518 | \r | |
1519 | @param FileList The file list to free. Type EFI_SHELL_FILE_INFO is\r | |
1520 | defined in OpenFileList()\r | |
1521 | \r | |
1522 | @retval EFI_SUCCESS Free the file list successfully.\r | |
1523 | @retval EFI_INVALID_PARAMETER FileList was NULL or *FileList was NULL;\r | |
1524 | **/\r | |
1525 | EFI_STATUS\r | |
1526 | EFIAPI\r | |
1527 | EfiShellFreeFileList(\r | |
1528 | IN EFI_SHELL_FILE_INFO **FileList\r | |
1529 | )\r | |
1530 | {\r | |
1531 | EFI_SHELL_FILE_INFO *ShellFileListItem;\r | |
1532 | \r | |
1533 | if (FileList == NULL || *FileList == NULL) {\r | |
1534 | return (EFI_INVALID_PARAMETER);\r | |
1535 | }\r | |
1536 | \r | |
1537 | for ( ShellFileListItem = (EFI_SHELL_FILE_INFO*)GetFirstNode(&(*FileList)->Link)\r | |
1538 | ; !IsListEmpty(&(*FileList)->Link)\r | |
1539 | ; ShellFileListItem = (EFI_SHELL_FILE_INFO*)GetFirstNode(&(*FileList)->Link)\r | |
1540 | ){\r | |
1541 | RemoveEntryList(&ShellFileListItem->Link);\r | |
1542 | InternalFreeShellFileInfoNode(ShellFileListItem);\r | |
1543 | }\r | |
1544 | return(EFI_SUCCESS);\r | |
1545 | }\r | |
1546 | \r | |
1547 | /**\r | |
1548 | Deletes the duplicate file names files in the given file list.\r | |
1549 | \r | |
1550 | This function deletes the reduplicate files in the given file list.\r | |
1551 | \r | |
1552 | @param FileList A pointer to the first entry in the file list.\r | |
1553 | \r | |
1554 | @retval EFI_SUCCESS Always success.\r | |
1555 | @retval EFI_INVALID_PARAMETER FileList was NULL or *FileList was NULL;\r | |
1556 | **/\r | |
1557 | EFI_STATUS\r | |
1558 | EFIAPI\r | |
1559 | EfiShellRemoveDupInFileList(\r | |
1560 | IN EFI_SHELL_FILE_INFO **FileList\r | |
1561 | )\r | |
1562 | {\r | |
1563 | EFI_SHELL_FILE_INFO *ShellFileListItem;\r | |
1564 | EFI_SHELL_FILE_INFO *ShellFileListItem2;\r | |
1565 | \r | |
1566 | if (FileList == NULL || *FileList == NULL) {\r | |
1567 | return (EFI_INVALID_PARAMETER);\r | |
1568 | }\r | |
1569 | for ( ShellFileListItem = (EFI_SHELL_FILE_INFO*)GetFirstNode(&(*FileList)->Link)\r | |
1570 | ; !IsNull(&(*FileList)->Link, &ShellFileListItem->Link)\r | |
1571 | ; ShellFileListItem = (EFI_SHELL_FILE_INFO*)GetNextNode(&(*FileList)->Link, &ShellFileListItem->Link)\r | |
1572 | ){\r | |
1573 | for ( ShellFileListItem2 = (EFI_SHELL_FILE_INFO*)GetNextNode(&(*FileList)->Link, &ShellFileListItem->Link)\r | |
1574 | ; !IsNull(&(*FileList)->Link, &ShellFileListItem2->Link)\r | |
1575 | ; ShellFileListItem2 = (EFI_SHELL_FILE_INFO*)GetNextNode(&(*FileList)->Link, &ShellFileListItem2->Link)\r | |
1576 | ){\r | |
1577 | if (gUnicodeCollation->StriColl(\r | |
1578 | gUnicodeCollation,\r | |
1579 | (CHAR16*)ShellFileListItem->FullName,\r | |
1580 | (CHAR16*)ShellFileListItem2->FullName) == 0\r | |
1581 | ){\r | |
1582 | RemoveEntryList(&ShellFileListItem2->Link);\r | |
1583 | InternalFreeShellFileInfoNode(ShellFileListItem2);\r | |
1584 | }\r | |
1585 | }\r | |
1586 | }\r | |
1587 | return (EFI_SUCCESS);\r | |
1588 | }\r | |
1589 | /**\r | |
1590 | Allocates and duplicates a EFI_SHELL_FILE_INFO node.\r | |
1591 | \r | |
1592 | @param[in] Node The node to copy from.\r | |
1593 | @param[in] Save TRUE to set Node->Handle to NULL, FALSE otherwise.\r | |
1594 | \r | |
1595 | @retval NULL a memory allocation error ocurred\r | |
1596 | @return != NULL a pointer to the new node\r | |
1597 | **/\r | |
1598 | EFI_SHELL_FILE_INFO*\r | |
1599 | EFIAPI\r | |
1600 | InternalDuplicateShellFileInfo(\r | |
1601 | IN EFI_SHELL_FILE_INFO *Node,\r | |
1602 | IN BOOLEAN Save\r | |
1603 | )\r | |
1604 | {\r | |
1605 | EFI_SHELL_FILE_INFO *NewNode;\r | |
1606 | \r | |
1607 | NewNode = AllocatePool(sizeof(EFI_SHELL_FILE_INFO));\r | |
1608 | if (NewNode == NULL) {\r | |
1609 | return (NULL);\r | |
1610 | }\r | |
1611 | NewNode->FullName = AllocateZeroPool(StrSize(Node->FullName));\r | |
1612 | \r | |
1613 | NewNode->FileName = AllocateZeroPool(StrSize(Node->FileName));\r | |
1614 | NewNode->Info = AllocatePool((UINTN)Node->Info->Size);\r | |
1615 | if ( NewNode->FullName == NULL\r | |
1616 | || NewNode->FileName == NULL\r | |
1617 | || NewNode->Info == NULL\r | |
1618 | ){\r | |
1619 | return(NULL);\r | |
1620 | }\r | |
1621 | NewNode->Status = Node->Status;\r | |
1622 | NewNode->Handle = Node->Handle;\r | |
1623 | if (!Save) {\r | |
1624 | Node->Handle = NULL;\r | |
1625 | }\r | |
1626 | StrCpy((CHAR16*)NewNode->FullName, Node->FullName);\r | |
1627 | StrCpy((CHAR16*)NewNode->FileName, Node->FileName);\r | |
1628 | CopyMem(NewNode->Info, Node->Info, (UINTN)Node->Info->Size);\r | |
1629 | \r | |
1630 | return(NewNode);\r | |
1631 | }\r | |
1632 | \r | |
1633 | /**\r | |
1634 | Allocates and populates a EFI_SHELL_FILE_INFO structure. if any memory operation\r | |
1635 | failed it will return NULL.\r | |
1636 | \r | |
1637 | @param[in] BasePath the Path to prepend onto filename for FullPath\r | |
1638 | @param[in] Status Status member initial value.\r | |
1639 | @param[in] FullName FullName member initial value.\r | |
1640 | @param[in] FileName FileName member initial value.\r | |
1641 | @param[in] Handle Handle member initial value.\r | |
1642 | @param[in] Info Info struct to copy.\r | |
1643 | \r | |
1644 | @retval NULL An error ocurred.\r | |
1645 | @return a pointer to the newly allocated structure.\r | |
1646 | **/\r | |
1647 | EFI_SHELL_FILE_INFO *\r | |
1648 | EFIAPI\r | |
1649 | CreateAndPopulateShellFileInfo(\r | |
1650 | IN CONST CHAR16 *BasePath,\r | |
1651 | IN CONST EFI_STATUS Status,\r | |
1652 | IN CONST CHAR16 *FullName,\r | |
1653 | IN CONST CHAR16 *FileName,\r | |
1654 | IN CONST SHELL_FILE_HANDLE Handle,\r | |
1655 | IN CONST EFI_FILE_INFO *Info\r | |
1656 | )\r | |
1657 | {\r | |
1658 | EFI_SHELL_FILE_INFO *ShellFileListItem;\r | |
1659 | CHAR16 *TempString;\r | |
1660 | UINTN Size;\r | |
1661 | \r | |
1662 | TempString = NULL;\r | |
1663 | Size = 0;\r | |
1664 | \r | |
1665 | ShellFileListItem = AllocateZeroPool(sizeof(EFI_SHELL_FILE_INFO));\r | |
1666 | if (ShellFileListItem == NULL) {\r | |
1667 | return (NULL);\r | |
1668 | }\r | |
1669 | if (Info != NULL) {\r | |
1670 | ShellFileListItem->Info = AllocateZeroPool((UINTN)Info->Size);\r | |
1671 | if (ShellFileListItem->Info == NULL) {\r | |
1672 | FreePool(ShellFileListItem);\r | |
1673 | return (NULL);\r | |
1674 | }\r | |
1675 | CopyMem(ShellFileListItem->Info, Info, (UINTN)Info->Size);\r | |
1676 | } else {\r | |
1677 | ShellFileListItem->Info = NULL;\r | |
1678 | }\r | |
1679 | if (FileName != NULL) {\r | |
1680 | ASSERT(TempString == NULL);\r | |
1681 | ShellFileListItem->FileName = StrnCatGrow(&TempString, 0, FileName, 0);\r | |
1682 | if (ShellFileListItem->FileName == NULL) {\r | |
1683 | FreePool(ShellFileListItem->Info);\r | |
1684 | FreePool(ShellFileListItem);\r | |
1685 | return (NULL);\r | |
1686 | }\r | |
1687 | } else {\r | |
1688 | ShellFileListItem->FileName = NULL;\r | |
1689 | }\r | |
1690 | Size = 0;\r | |
1691 | TempString = NULL;\r | |
1692 | if (BasePath != NULL) {\r | |
1693 | ASSERT((TempString == NULL && Size == 0) || (TempString != NULL));\r | |
1694 | TempString = StrnCatGrow(&TempString, &Size, BasePath, 0);\r | |
1695 | if (TempString == NULL) {\r | |
1696 | FreePool((VOID*)ShellFileListItem->FileName);\r | |
1697 | FreePool(ShellFileListItem->Info);\r | |
1698 | FreePool(ShellFileListItem);\r | |
1699 | return (NULL);\r | |
1700 | }\r | |
1701 | }\r | |
1702 | if (ShellFileListItem->FileName != NULL) {\r | |
1703 | ASSERT((TempString == NULL && Size == 0) || (TempString != NULL));\r | |
1704 | TempString = StrnCatGrow(&TempString, &Size, ShellFileListItem->FileName, 0);\r | |
1705 | if (TempString == NULL) {\r | |
1706 | FreePool((VOID*)ShellFileListItem->FileName);\r | |
1707 | FreePool(ShellFileListItem->Info);\r | |
1708 | FreePool(ShellFileListItem);\r | |
1709 | return (NULL);\r | |
1710 | }\r | |
1711 | }\r | |
1712 | \r | |
1713 | ShellFileListItem->FullName = TempString;\r | |
1714 | ShellFileListItem->Status = Status;\r | |
1715 | ShellFileListItem->Handle = Handle;\r | |
1716 | \r | |
1717 | return (ShellFileListItem);\r | |
1718 | }\r | |
1719 | \r | |
1720 | /**\r | |
1721 | Find all files in a specified directory.\r | |
1722 | \r | |
1723 | @param FileDirHandle Handle of the directory to search.\r | |
1724 | @param FileList On return, points to the list of files in the directory\r | |
1725 | or NULL if there are no files in the directory.\r | |
1726 | \r | |
1727 | @retval EFI_SUCCESS File information was returned successfully.\r | |
1728 | @retval EFI_VOLUME_CORRUPTED The file system structures have been corrupted.\r | |
1729 | @retval EFI_DEVICE_ERROR The device reported an error.\r | |
1730 | @retval EFI_NO_MEDIA The device media is not present.\r | |
1731 | @retval EFI_INVALID_PARAMETER The FileDirHandle was not a directory.\r | |
1732 | @return An error from FileHandleGetFileName().\r | |
1733 | **/\r | |
1734 | EFI_STATUS\r | |
1735 | EFIAPI\r | |
1736 | EfiShellFindFilesInDir(\r | |
1737 | IN SHELL_FILE_HANDLE FileDirHandle,\r | |
1738 | OUT EFI_SHELL_FILE_INFO **FileList\r | |
1739 | )\r | |
1740 | {\r | |
1741 | EFI_SHELL_FILE_INFO *ShellFileList;\r | |
1742 | EFI_SHELL_FILE_INFO *ShellFileListItem;\r | |
1743 | EFI_FILE_INFO *FileInfo;\r | |
1744 | EFI_STATUS Status;\r | |
1745 | BOOLEAN NoFile;\r | |
1746 | CHAR16 *TempString;\r | |
1747 | CHAR16 *BasePath;\r | |
1748 | UINTN Size;\r | |
1749 | CHAR16 *TempSpot;\r | |
1750 | \r | |
1751 | Status = FileHandleGetFileName(FileDirHandle, &BasePath);\r | |
1752 | if (EFI_ERROR(Status)) {\r | |
1753 | return (Status);\r | |
1754 | }\r | |
1755 | \r | |
1756 | if (ShellFileHandleGetPath(FileDirHandle) != NULL) {\r | |
1757 | TempString = NULL;\r | |
1758 | Size = 0;\r | |
1759 | TempString = StrnCatGrow(&TempString, &Size, ShellFileHandleGetPath(FileDirHandle), 0);\r | |
1760 | TempSpot = StrStr(TempString, L";");\r | |
1761 | \r | |
1762 | if (TempSpot != NULL) {\r | |
1763 | *TempSpot = CHAR_NULL;\r | |
1764 | }\r | |
1765 | \r | |
1766 | TempString = StrnCatGrow(&TempString, &Size, BasePath, 0);\r | |
1767 | BasePath = TempString;\r | |
1768 | }\r | |
1769 | \r | |
1770 | NoFile = FALSE;\r | |
1771 | ShellFileList = NULL;\r | |
1772 | ShellFileListItem = NULL;\r | |
1773 | FileInfo = NULL;\r | |
1774 | Status = EFI_SUCCESS;\r | |
1775 | \r | |
1776 | \r | |
1777 | for ( Status = FileHandleFindFirstFile(FileDirHandle, &FileInfo)\r | |
1778 | ; !EFI_ERROR(Status) && !NoFile\r | |
1779 | ; Status = FileHandleFindNextFile(FileDirHandle, FileInfo, &NoFile)\r | |
1780 | ){\r | |
1781 | TempString = NULL;\r | |
1782 | Size = 0;\r | |
1783 | //\r | |
1784 | // allocate a new EFI_SHELL_FILE_INFO and populate it...\r | |
1785 | //\r | |
1786 | ASSERT((TempString == NULL && Size == 0) || (TempString != NULL));\r | |
1787 | TempString = StrnCatGrow(&TempString, &Size, BasePath, 0);\r | |
1788 | TempString = StrnCatGrow(&TempString, &Size, FileInfo->FileName, 0);\r | |
1789 | ShellFileListItem = CreateAndPopulateShellFileInfo(\r | |
1790 | BasePath,\r | |
1791 | EFI_SUCCESS, // success since we didnt fail to open it...\r | |
1792 | TempString,\r | |
1793 | FileInfo->FileName,\r | |
1794 | NULL, // no handle since not open\r | |
1795 | FileInfo);\r | |
1796 | \r | |
1797 | if (ShellFileList == NULL) {\r | |
1798 | ShellFileList = (EFI_SHELL_FILE_INFO*)AllocateZeroPool(sizeof(EFI_SHELL_FILE_INFO));\r | |
1799 | ASSERT(ShellFileList != NULL);\r | |
1800 | InitializeListHead(&ShellFileList->Link);\r | |
1801 | }\r | |
1802 | InsertTailList(&ShellFileList->Link, &ShellFileListItem->Link);\r | |
1803 | }\r | |
1804 | if (EFI_ERROR(Status)) {\r | |
1805 | EfiShellFreeFileList(&ShellFileList);\r | |
1806 | *FileList = NULL;\r | |
1807 | } else {\r | |
1808 | *FileList = ShellFileList;\r | |
1809 | }\r | |
1810 | SHELL_FREE_NON_NULL(BasePath);\r | |
1811 | return(Status);\r | |
1812 | }\r | |
1813 | \r | |
1814 | /**\r | |
1815 | Updates a file name to be preceeded by the mapped drive name\r | |
1816 | \r | |
1817 | @param[in] BasePath the Mapped drive name to prepend\r | |
1818 | @param[in,out] Path pointer to pointer to the file name to update.\r | |
1819 | \r | |
1820 | @retval EFI_SUCCESS\r | |
1821 | @retval EFI_OUT_OF_RESOURCES\r | |
1822 | **/\r | |
1823 | EFI_STATUS\r | |
1824 | EFIAPI\r | |
1825 | UpdateFileName(\r | |
1826 | IN CONST CHAR16 *BasePath,\r | |
1827 | IN OUT CHAR16 **Path\r | |
1828 | )\r | |
1829 | {\r | |
1830 | CHAR16 *Path2;\r | |
1831 | UINTN Path2Size;\r | |
1832 | \r | |
1833 | Path2Size = 0;\r | |
1834 | Path2 = NULL;\r | |
1835 | \r | |
1836 | ASSERT(Path != NULL);\r | |
1837 | ASSERT(*Path != NULL);\r | |
1838 | ASSERT(BasePath != NULL);\r | |
1839 | \r | |
1840 | //\r | |
1841 | // convert a local path to an absolute path\r | |
1842 | //\r | |
1843 | if (StrStr(*Path, L":") == NULL) {\r | |
1844 | ASSERT((Path2 == NULL && Path2Size == 0) || (Path2 != NULL));\r | |
1845 | StrnCatGrow(&Path2, &Path2Size, BasePath, 0);\r | |
1846 | if (Path2 == NULL) {\r | |
1847 | return (EFI_OUT_OF_RESOURCES);\r | |
1848 | }\r | |
1849 | ASSERT((Path2 == NULL && Path2Size == 0) || (Path2 != NULL));\r | |
1850 | StrnCatGrow(&Path2, &Path2Size, (*Path)[0] == L'\\'?(*Path) + 1 :*Path, 0);\r | |
1851 | if (Path2 == NULL) {\r | |
1852 | return (EFI_OUT_OF_RESOURCES);\r | |
1853 | }\r | |
1854 | }\r | |
1855 | \r | |
1856 | FreePool(*Path);\r | |
1857 | (*Path) = Path2;\r | |
1858 | \r | |
1859 | return (EFI_SUCCESS);\r | |
1860 | }\r | |
1861 | \r | |
1862 | /**\r | |
1863 | If FileHandle is a directory then the function reads from FileHandle and reads in\r | |
1864 | each of the FileInfo structures. If one of them matches the Pattern's first\r | |
1865 | "level" then it opens that handle and calls itself on that handle.\r | |
1866 | \r | |
1867 | If FileHandle is a file and matches all of the remaining Pattern (which would be\r | |
1868 | on its last node), then add a EFI_SHELL_FILE_INFO object for this file to fileList.\r | |
1869 | \r | |
1870 | if FileList is NULL, then ASSERT\r | |
1871 | if FilePattern is NULL, then ASSERT\r | |
1872 | if UnicodeCollation is NULL, then ASSERT\r | |
1873 | if FileHandle is NULL, then ASSERT\r | |
1874 | \r | |
1875 | Upon a EFI_SUCCESS return fromt he function any the caller is responsible to call\r | |
1876 | FreeFileList with FileList.\r | |
1877 | \r | |
1878 | @param[in] FilePattern The FilePattern to check against.\r | |
1879 | @param[in] UnicodeCollation The pointer to EFI_UNICODE_COLLATION_PROTOCOL structure\r | |
1880 | @param[in] FileHandle The FileHandle to start with\r | |
1881 | @param[in,out] FileList pointer to pointer to list of found files.\r | |
1882 | @param[in] ParentNode The node for the parent. Same file as identified by HANDLE.\r | |
1883 | \r | |
1884 | @retval EFI_SUCCESS all files were found and the FileList contains a list.\r | |
1885 | @retval EFI_NOT_FOUND no files were found\r | |
1886 | @retval EFI_OUT_OF_RESOURCES a memory allocation failed\r | |
1887 | **/\r | |
1888 | EFI_STATUS\r | |
1889 | EFIAPI\r | |
1890 | ShellSearchHandle(\r | |
1891 | IN CONST CHAR16 *FilePattern,\r | |
1892 | IN EFI_UNICODE_COLLATION_PROTOCOL *UnicodeCollation,\r | |
1893 | IN SHELL_FILE_HANDLE FileHandle,\r | |
1894 | IN OUT EFI_SHELL_FILE_INFO **FileList,\r | |
1895 | IN CONST EFI_SHELL_FILE_INFO *ParentNode OPTIONAL\r | |
1896 | )\r | |
1897 | {\r | |
1898 | EFI_STATUS Status;\r | |
1899 | CONST CHAR16 *NextFilePatternStart;\r | |
1900 | CHAR16 *CurrentFilePattern;\r | |
1901 | EFI_SHELL_FILE_INFO *ShellInfo;\r | |
1902 | EFI_SHELL_FILE_INFO *ShellInfoNode;\r | |
1903 | EFI_SHELL_FILE_INFO *NewShellNode;\r | |
1904 | BOOLEAN Directory;\r | |
1905 | \r | |
1906 | if ( FilePattern == NULL\r | |
1907 | || UnicodeCollation == NULL\r | |
1908 | || FileList == NULL\r | |
1909 | ){\r | |
1910 | return (EFI_INVALID_PARAMETER);\r | |
1911 | }\r | |
1912 | ShellInfo = NULL;\r | |
1913 | CurrentFilePattern = NULL;\r | |
1914 | \r | |
1915 | if (*FilePattern == L'\\') {\r | |
1916 | FilePattern++;\r | |
1917 | }\r | |
1918 | \r | |
1919 | for( NextFilePatternStart = FilePattern\r | |
1920 | ; *NextFilePatternStart != CHAR_NULL && *NextFilePatternStart != L'\\'\r | |
1921 | ; NextFilePatternStart++);\r | |
1922 | \r | |
1923 | CurrentFilePattern = AllocateZeroPool((NextFilePatternStart-FilePattern+1)*sizeof(CHAR16));\r | |
1924 | ASSERT(CurrentFilePattern != NULL);\r | |
1925 | StrnCpy(CurrentFilePattern, FilePattern, NextFilePatternStart-FilePattern);\r | |
1926 | \r | |
1927 | if (CurrentFilePattern[0] == CHAR_NULL\r | |
1928 | &&NextFilePatternStart[0] == CHAR_NULL\r | |
1929 | ){\r | |
1930 | //\r | |
1931 | // Add the current parameter FileHandle to the list, then end...\r | |
1932 | //\r | |
1933 | if (ParentNode == NULL) {\r | |
1934 | Status = EFI_INVALID_PARAMETER;\r | |
1935 | } else {\r | |
1936 | NewShellNode = InternalDuplicateShellFileInfo((EFI_SHELL_FILE_INFO*)ParentNode, TRUE);\r | |
1937 | if (NewShellNode == NULL) {\r | |
1938 | Status = EFI_OUT_OF_RESOURCES;\r | |
1939 | } else {\r | |
1940 | NewShellNode->Handle = NULL;\r | |
1941 | if (*FileList == NULL) {\r | |
1942 | *FileList = AllocatePool(sizeof(EFI_SHELL_FILE_INFO));\r | |
1943 | InitializeListHead(&((*FileList)->Link));\r | |
1944 | }\r | |
1945 | \r | |
1946 | //\r | |
1947 | // Add to the returning to use list\r | |
1948 | //\r | |
1949 | InsertTailList(&(*FileList)->Link, &NewShellNode->Link);\r | |
1950 | \r | |
1951 | Status = EFI_SUCCESS;\r | |
1952 | }\r | |
1953 | }\r | |
1954 | } else {\r | |
1955 | Status = EfiShellFindFilesInDir(FileHandle, &ShellInfo);\r | |
1956 | \r | |
1957 | if (!EFI_ERROR(Status)){\r | |
1958 | if (StrStr(NextFilePatternStart, L"\\") != NULL){\r | |
1959 | Directory = TRUE;\r | |
1960 | } else {\r | |
1961 | Directory = FALSE;\r | |
1962 | }\r | |
1963 | for ( ShellInfoNode = (EFI_SHELL_FILE_INFO*)GetFirstNode(&ShellInfo->Link)\r | |
1964 | ; !IsNull (&ShellInfo->Link, &ShellInfoNode->Link)\r | |
1965 | ; ShellInfoNode = (EFI_SHELL_FILE_INFO*)GetNextNode(&ShellInfo->Link, &ShellInfoNode->Link)\r | |
1966 | ){\r | |
1967 | if (UnicodeCollation->MetaiMatch(UnicodeCollation, (CHAR16*)ShellInfoNode->FileName, CurrentFilePattern)){\r | |
1968 | if (Directory){\r | |
1969 | //\r | |
1970 | // should be a directory\r | |
1971 | //\r | |
1972 | \r | |
1973 | //\r | |
1974 | // don't open the . and .. directories\r | |
1975 | //\r | |
1976 | if ( (StrCmp(ShellInfoNode->FileName, L".") != 0)\r | |
1977 | && (StrCmp(ShellInfoNode->FileName, L"..") != 0)\r | |
1978 | ){\r | |
1979 | //\r | |
1980 | //\r | |
1981 | //\r | |
1982 | ASSERT_EFI_ERROR(Status);\r | |
1983 | if (EFI_ERROR(Status)) {\r | |
1984 | break;\r | |
1985 | }\r | |
1986 | //\r | |
1987 | // Open the directory since we need that handle in the next recursion.\r | |
1988 | //\r | |
1989 | ShellInfoNode->Status = EfiShellOpenFileByName (ShellInfoNode->FullName, &ShellInfoNode->Handle, EFI_FILE_MODE_READ);\r | |
1990 | \r | |
1991 | //\r | |
1992 | // recurse with the next part of the pattern\r | |
1993 | //\r | |
1994 | Status = ShellSearchHandle(NextFilePatternStart, UnicodeCollation, ShellInfoNode->Handle, FileList, ShellInfoNode);\r | |
1995 | }\r | |
1996 | } else {\r | |
1997 | //\r | |
1998 | // should be a file\r | |
1999 | //\r | |
2000 | \r | |
2001 | //\r | |
2002 | // copy the information we need into a new Node\r | |
2003 | //\r | |
2004 | NewShellNode = InternalDuplicateShellFileInfo(ShellInfoNode, FALSE);\r | |
2005 | ASSERT(NewShellNode != NULL);\r | |
2006 | if (NewShellNode == NULL) {\r | |
2007 | Status = EFI_OUT_OF_RESOURCES;\r | |
2008 | }\r | |
2009 | if (*FileList == NULL) {\r | |
2010 | *FileList = AllocatePool(sizeof(EFI_SHELL_FILE_INFO));\r | |
2011 | InitializeListHead(&((*FileList)->Link));\r | |
2012 | }\r | |
2013 | \r | |
2014 | //\r | |
2015 | // Add to the returning to use list\r | |
2016 | //\r | |
2017 | InsertTailList(&(*FileList)->Link, &NewShellNode->Link);\r | |
2018 | }\r | |
2019 | }\r | |
2020 | if (EFI_ERROR(Status)) {\r | |
2021 | break;\r | |
2022 | }\r | |
2023 | }\r | |
2024 | if (EFI_ERROR(Status)) {\r | |
2025 | EfiShellFreeFileList(&ShellInfo);\r | |
2026 | } else {\r | |
2027 | Status = EfiShellFreeFileList(&ShellInfo);\r | |
2028 | }\r | |
2029 | }\r | |
2030 | }\r | |
2031 | \r | |
2032 | FreePool(CurrentFilePattern);\r | |
2033 | return (Status);\r | |
2034 | }\r | |
2035 | \r | |
2036 | /**\r | |
2037 | Find files that match a specified pattern.\r | |
2038 | \r | |
2039 | This function searches for all files and directories that match the specified\r | |
2040 | FilePattern. The FilePattern can contain wild-card characters. The resulting file\r | |
2041 | information is placed in the file list FileList.\r | |
2042 | \r | |
2043 | Wildcards are processed\r | |
2044 | according to the rules specified in UEFI Shell 2.0 spec section 3.7.1.\r | |
2045 | \r | |
2046 | The files in the file list are not opened. The OpenMode field is set to 0 and the FileInfo\r | |
2047 | field is set to NULL.\r | |
2048 | \r | |
2049 | if *FileList is not NULL then it must be a pre-existing and properly initialized list.\r | |
2050 | \r | |
2051 | @param FilePattern Points to a NULL-terminated shell file path, including wildcards.\r | |
2052 | @param FileList On return, points to the start of a file list containing the names\r | |
2053 | of all matching files or else points to NULL if no matching files\r | |
2054 | were found. only on a EFI_SUCCESS return will; this be non-NULL.\r | |
2055 | \r | |
2056 | @retval EFI_SUCCESS Files found. FileList is a valid list.\r | |
2057 | @retval EFI_NOT_FOUND No files found.\r | |
2058 | @retval EFI_NO_MEDIA The device has no media\r | |
2059 | @retval EFI_DEVICE_ERROR The device reported an error\r | |
2060 | @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted\r | |
2061 | **/\r | |
2062 | EFI_STATUS\r | |
2063 | EFIAPI\r | |
2064 | EfiShellFindFiles(\r | |
2065 | IN CONST CHAR16 *FilePattern,\r | |
2066 | OUT EFI_SHELL_FILE_INFO **FileList\r | |
2067 | )\r | |
2068 | {\r | |
2069 | EFI_STATUS Status;\r | |
2070 | CHAR16 *PatternCopy;\r | |
2071 | CHAR16 *PatternCurrentLocation;\r | |
2072 | EFI_DEVICE_PATH_PROTOCOL *RootDevicePath;\r | |
2073 | SHELL_FILE_HANDLE RootFileHandle;\r | |
2074 | CHAR16 *MapName;\r | |
2075 | UINTN Count;\r | |
2076 | \r | |
2077 | if ( FilePattern == NULL\r | |
2078 | || FileList == NULL\r | |
2079 | || StrStr(FilePattern, L":") == NULL\r | |
2080 | ){\r | |
2081 | return (EFI_INVALID_PARAMETER);\r | |
2082 | }\r | |
2083 | Status = EFI_SUCCESS;\r | |
2084 | RootDevicePath = NULL;\r | |
2085 | RootFileHandle = NULL;\r | |
2086 | MapName = NULL;\r | |
2087 | PatternCopy = AllocatePool(StrSize(FilePattern));\r | |
2088 | if (PatternCopy == NULL) {\r | |
2089 | return (EFI_OUT_OF_RESOURCES);\r | |
2090 | }\r | |
2091 | StrCpy(PatternCopy, FilePattern);\r | |
2092 | \r | |
2093 | PatternCopy = CleanPath(PatternCopy);\r | |
2094 | \r | |
2095 | Count = StrStr(PatternCopy, L":") - PatternCopy;\r | |
2096 | Count += 2;\r | |
2097 | \r | |
2098 | ASSERT(MapName == NULL);\r | |
2099 | MapName = StrnCatGrow(&MapName, NULL, PatternCopy, Count);\r | |
2100 | \r | |
2101 | if (!EFI_ERROR(Status)) {\r | |
2102 | RootDevicePath = EfiShellGetDevicePathFromFilePath(PatternCopy);\r | |
2103 | if (RootDevicePath == NULL) {\r | |
2104 | Status = EFI_INVALID_PARAMETER;\r | |
2105 | } else {\r | |
2106 | Status = EfiShellOpenRoot(RootDevicePath, &RootFileHandle);\r | |
2107 | if (!EFI_ERROR(Status)) {\r | |
2108 | for ( PatternCurrentLocation = PatternCopy\r | |
2109 | ; *PatternCurrentLocation != ':'\r | |
2110 | ; PatternCurrentLocation++);\r | |
2111 | PatternCurrentLocation++;\r | |
2112 | Status = ShellSearchHandle(PatternCurrentLocation, gUnicodeCollation, RootFileHandle, FileList, NULL);\r | |
2113 | }\r | |
2114 | FreePool(RootDevicePath);\r | |
2115 | }\r | |
2116 | }\r | |
2117 | \r | |
2118 | if (PatternCopy != NULL) {\r | |
2119 | FreePool(PatternCopy);\r | |
2120 | }\r | |
2121 | if (MapName != NULL) {\r | |
2122 | FreePool(MapName);\r | |
2123 | }\r | |
2124 | \r | |
2125 | return(Status);\r | |
2126 | }\r | |
2127 | \r | |
2128 | /**\r | |
2129 | Opens the files that match the path specified.\r | |
2130 | \r | |
2131 | This function opens all of the files specified by Path. Wildcards are processed\r | |
2132 | according to the rules specified in UEFI Shell 2.0 spec section 3.7.1. Each\r | |
2133 | matching file has an EFI_SHELL_FILE_INFO structure created in a linked list.\r | |
2134 | \r | |
2135 | @param Path A pointer to the path string.\r | |
2136 | @param OpenMode Specifies the mode used to open each file, EFI_FILE_MODE_READ or\r | |
2137 | EFI_FILE_MODE_WRITE.\r | |
2138 | @param FileList Points to the start of a list of files opened.\r | |
2139 | \r | |
2140 | @retval EFI_SUCCESS Create the file list successfully.\r | |
2141 | @return Others Can't create the file list.\r | |
2142 | **/\r | |
2143 | EFI_STATUS\r | |
2144 | EFIAPI\r | |
2145 | EfiShellOpenFileList(\r | |
2146 | IN CHAR16 *Path,\r | |
2147 | IN UINT64 OpenMode,\r | |
2148 | IN OUT EFI_SHELL_FILE_INFO **FileList\r | |
2149 | )\r | |
2150 | {\r | |
2151 | EFI_STATUS Status;\r | |
2152 | EFI_SHELL_FILE_INFO *ShellFileListItem;\r | |
2153 | CHAR16 *Path2;\r | |
2154 | UINTN Path2Size;\r | |
2155 | CONST CHAR16 *CurDir;\r | |
2156 | \r | |
2157 | ShellCommandCleanPath(Path);\r | |
2158 | \r | |
2159 | Path2Size = 0;\r | |
2160 | Path2 = NULL;\r | |
2161 | \r | |
2162 | ASSERT(FileList != NULL);\r | |
2163 | ASSERT(*FileList != NULL);\r | |
2164 | \r | |
2165 | if (*Path == L'.' && *(Path+1) == L'\\') {\r | |
2166 | Path++;\r | |
2167 | }\r | |
2168 | \r | |
2169 | //\r | |
2170 | // convert a local path to an absolute path\r | |
2171 | //\r | |
2172 | if (StrStr(Path, L":") == NULL) {\r | |
2173 | CurDir = EfiShellGetCurDir(NULL);\r | |
2174 | ASSERT((Path2 == NULL && Path2Size == 0) || (Path2 != NULL));\r | |
2175 | StrnCatGrow(&Path2, &Path2Size, CurDir, 0);\r | |
2176 | if (*Path == L'\\') {\r | |
2177 | Path++;\r | |
2178 | }\r | |
2179 | ASSERT((Path2 == NULL && Path2Size == 0) || (Path2 != NULL));\r | |
2180 | StrnCatGrow(&Path2, &Path2Size, Path, 0);\r | |
2181 | } else {\r | |
2182 | ASSERT(Path2 == NULL);\r | |
2183 | StrnCatGrow(&Path2, NULL, Path, 0);\r | |
2184 | }\r | |
2185 | \r | |
2186 | CleanPath (Path2);\r | |
2187 | \r | |
2188 | //\r | |
2189 | // do the search\r | |
2190 | //\r | |
2191 | Status = EfiShellFindFiles(Path2, FileList);\r | |
2192 | \r | |
2193 | FreePool(Path2);\r | |
2194 | \r | |
2195 | if (EFI_ERROR(Status)) {\r | |
2196 | return (Status);\r | |
2197 | }\r | |
2198 | \r | |
2199 | //\r | |
2200 | // We had no errors so open all the files (that are not already opened...)\r | |
2201 | //\r | |
2202 | for ( ShellFileListItem = (EFI_SHELL_FILE_INFO*)GetFirstNode(&(*FileList)->Link)\r | |
2203 | ; !IsNull(&(*FileList)->Link, &ShellFileListItem->Link)\r | |
2204 | ; ShellFileListItem = (EFI_SHELL_FILE_INFO*)GetNextNode(&(*FileList)->Link, &ShellFileListItem->Link)\r | |
2205 | ){\r | |
2206 | if (ShellFileListItem->Status == 0 && ShellFileListItem->Handle == NULL) {\r | |
2207 | ShellFileListItem->Status = EfiShellOpenFileByName (ShellFileListItem->FullName, &ShellFileListItem->Handle, OpenMode);\r | |
2208 | }\r | |
2209 | }\r | |
2210 | \r | |
2211 | return(EFI_SUCCESS);\r | |
2212 | }\r | |
2213 | \r | |
2214 | /**\r | |
2215 | This function updated with errata.\r | |
2216 | \r | |
2217 | Gets either a single or list of environment variables.\r | |
2218 | \r | |
2219 | If name is not NULL then this function returns the current value of the specified\r | |
2220 | environment variable.\r | |
2221 | \r | |
2222 | If Name is NULL, then a list of all environment variable names is returned. Each is a\r | |
2223 | NULL terminated string with a double NULL terminating the list.\r | |
2224 | \r | |
2225 | @param Name A pointer to the environment variable name. If\r | |
2226 | Name is NULL, then the function will return all\r | |
2227 | of the defined shell environment variables. In\r | |
2228 | the case where multiple environment variables are\r | |
2229 | being returned, each variable will be terminated by\r | |
2230 | a NULL, and the list will be terminated by a double\r | |
2231 | NULL.\r | |
2232 | \r | |
2233 | @return !=NULL A pointer to the returned string.\r | |
2234 | The returned pointer does not need to be freed by the caller.\r | |
2235 | \r | |
2236 | @retval NULL The environment variable doesn't exist or there are\r | |
2237 | no environment variables.\r | |
2238 | **/\r | |
2239 | CONST CHAR16 *\r | |
2240 | EFIAPI\r | |
2241 | EfiShellGetEnv(\r | |
2242 | IN CONST CHAR16 *Name\r | |
2243 | )\r | |
2244 | {\r | |
2245 | EFI_STATUS Status;\r | |
2246 | VOID *Buffer;\r | |
2247 | UINTN Size;\r | |
2248 | LIST_ENTRY List;\r | |
2249 | ENV_VAR_LIST *Node;\r | |
2250 | CHAR16 *CurrentWriteLocation;\r | |
2251 | \r | |
2252 | Size = 0;\r | |
2253 | Buffer = NULL;\r | |
2254 | \r | |
2255 | if (Name == NULL) {\r | |
2256 | //\r | |
2257 | // Get all our environment variables\r | |
2258 | //\r | |
2259 | InitializeListHead(&List);\r | |
2260 | Status = GetEnvironmentVariableList(&List);\r | |
2261 | if (EFI_ERROR(Status)){\r | |
2262 | return (NULL);\r | |
2263 | }\r | |
2264 | \r | |
2265 | //\r | |
2266 | // Build the semi-colon delimited list. (2 passes)\r | |
2267 | //\r | |
2268 | for ( Node = (ENV_VAR_LIST*)GetFirstNode(&List)\r | |
2269 | ; !IsNull(&List, &Node->Link)\r | |
2270 | ; Node = (ENV_VAR_LIST*)GetNextNode(&List, &Node->Link)\r | |
2271 | ){\r | |
2272 | ASSERT(Node->Key != NULL);\r | |
2273 | Size += StrSize(Node->Key);\r | |
2274 | }\r | |
2275 | \r | |
2276 | Size += 2*sizeof(CHAR16);\r | |
2277 | \r | |
2278 | Buffer = AllocateZeroPool(Size);\r | |
3c865f20 | 2279 | if (Buffer == NULL) {\r |
2280 | if (!IsListEmpty (&List)) {\r | |
2281 | FreeEnvironmentVariableList(&List);\r | |
2282 | }\r | |
2283 | return (NULL);\r | |
2284 | }\r | |
a405b86d | 2285 | CurrentWriteLocation = (CHAR16*)Buffer;\r |
2286 | \r | |
2287 | for ( Node = (ENV_VAR_LIST*)GetFirstNode(&List)\r | |
2288 | ; !IsNull(&List, &Node->Link)\r | |
2289 | ; Node = (ENV_VAR_LIST*)GetNextNode(&List, &Node->Link)\r | |
2290 | ){\r | |
2291 | ASSERT(Node->Key != NULL);\r | |
2292 | StrCpy(CurrentWriteLocation, Node->Key);\r | |
2293 | CurrentWriteLocation += StrLen(CurrentWriteLocation) + 1;\r | |
2294 | }\r | |
2295 | \r | |
2296 | //\r | |
2297 | // Free the list...\r | |
2298 | //\r | |
3c865f20 | 2299 | if (!IsListEmpty (&List)) {\r |
2300 | FreeEnvironmentVariableList(&List);\r | |
2301 | }\r | |
a405b86d | 2302 | } else {\r |
2303 | //\r | |
2304 | // We are doing a specific environment variable\r | |
2305 | //\r | |
2306 | \r | |
2307 | //\r | |
2308 | // get the size we need for this EnvVariable\r | |
2309 | //\r | |
2310 | Status = SHELL_GET_ENVIRONMENT_VARIABLE(Name, &Size, Buffer);\r | |
2311 | if (Status == EFI_BUFFER_TOO_SMALL) {\r | |
2312 | //\r | |
2313 | // Allocate the space and recall the get function\r | |
2314 | //\r | |
2315 | Buffer = AllocateZeroPool(Size);\r | |
2316 | ASSERT(Buffer != NULL);\r | |
2317 | Status = SHELL_GET_ENVIRONMENT_VARIABLE(Name, &Size, Buffer);\r | |
2318 | }\r | |
2319 | //\r | |
2320 | // we didnt get it (might not exist)\r | |
2321 | // free the memory if we allocated any and return NULL\r | |
2322 | //\r | |
2323 | if (EFI_ERROR(Status)) {\r | |
2324 | if (Buffer != NULL) {\r | |
2325 | FreePool(Buffer);\r | |
2326 | }\r | |
2327 | return (NULL);\r | |
2328 | }\r | |
2329 | }\r | |
2330 | \r | |
2331 | //\r | |
2332 | // return the buffer\r | |
2333 | //\r | |
2334 | return (AddBufferToFreeList(Buffer));\r | |
2335 | }\r | |
2336 | \r | |
2337 | /**\r | |
2338 | Internal variable setting function. Allows for setting of the read only variables.\r | |
2339 | \r | |
2340 | @param Name Points to the NULL-terminated environment variable name.\r | |
2341 | @param Value Points to the NULL-terminated environment variable value. If the value is an\r | |
2342 | empty string then the environment variable is deleted.\r | |
2343 | @param Volatile Indicates whether the variable is non-volatile (FALSE) or volatile (TRUE).\r | |
2344 | \r | |
2345 | @retval EFI_SUCCESS The environment variable was successfully updated.\r | |
2346 | **/\r | |
2347 | EFI_STATUS\r | |
2348 | EFIAPI\r | |
2349 | InternalEfiShellSetEnv(\r | |
2350 | IN CONST CHAR16 *Name,\r | |
2351 | IN CONST CHAR16 *Value,\r | |
2352 | IN BOOLEAN Volatile\r | |
2353 | )\r | |
2354 | {\r | |
2355 | if (Value == NULL || StrLen(Value) == 0) {\r | |
2356 | return (SHELL_DELETE_ENVIRONMENT_VARIABLE(Name));\r | |
2357 | } else {\r | |
2358 | SHELL_DELETE_ENVIRONMENT_VARIABLE(Name);\r | |
2359 | if (Volatile) {\r | |
2360 | return (SHELL_SET_ENVIRONMENT_VARIABLE_V(Name, StrSize(Value), Value));\r | |
2361 | } else {\r | |
2362 | return (SHELL_SET_ENVIRONMENT_VARIABLE_NV(Name, StrSize(Value), Value));\r | |
2363 | }\r | |
2364 | }\r | |
2365 | }\r | |
2366 | \r | |
2367 | /**\r | |
2368 | Sets the environment variable.\r | |
2369 | \r | |
2370 | This function changes the current value of the specified environment variable. If the\r | |
2371 | environment variable exists and the Value is an empty string, then the environment\r | |
2372 | variable is deleted. If the environment variable exists and the Value is not an empty\r | |
2373 | string, then the value of the environment variable is changed. If the environment\r | |
2374 | variable does not exist and the Value is an empty string, there is no action. If the\r | |
2375 | environment variable does not exist and the Value is a non-empty string, then the\r | |
2376 | environment variable is created and assigned the specified value.\r | |
2377 | \r | |
2378 | For a description of volatile and non-volatile environment variables, see UEFI Shell\r | |
2379 | 2.0 specification section 3.6.1.\r | |
2380 | \r | |
2381 | @param Name Points to the NULL-terminated environment variable name.\r | |
2382 | @param Value Points to the NULL-terminated environment variable value. If the value is an\r | |
2383 | empty string then the environment variable is deleted.\r | |
2384 | @param Volatile Indicates whether the variable is non-volatile (FALSE) or volatile (TRUE).\r | |
2385 | \r | |
2386 | @retval EFI_SUCCESS The environment variable was successfully updated.\r | |
2387 | **/\r | |
2388 | EFI_STATUS\r | |
2389 | EFIAPI\r | |
2390 | EfiShellSetEnv(\r | |
2391 | IN CONST CHAR16 *Name,\r | |
2392 | IN CONST CHAR16 *Value,\r | |
2393 | IN BOOLEAN Volatile\r | |
2394 | )\r | |
2395 | {\r | |
2396 | if (Name == NULL || *Name == CHAR_NULL) {\r | |
2397 | return (EFI_INVALID_PARAMETER);\r | |
2398 | }\r | |
2399 | //\r | |
2400 | // Make sure we dont 'set' a predefined read only variable\r | |
2401 | //\r | |
2402 | if (gUnicodeCollation->StriColl(\r | |
2403 | gUnicodeCollation,\r | |
2404 | (CHAR16*)Name,\r | |
2405 | L"cwd") == 0\r | |
2406 | ||gUnicodeCollation->StriColl(\r | |
2407 | gUnicodeCollation,\r | |
2408 | (CHAR16*)Name,\r | |
2409 | L"Lasterror") == 0\r | |
2410 | ||gUnicodeCollation->StriColl(\r | |
2411 | gUnicodeCollation,\r | |
2412 | (CHAR16*)Name,\r | |
2413 | L"profiles") == 0\r | |
2414 | ||gUnicodeCollation->StriColl(\r | |
2415 | gUnicodeCollation,\r | |
2416 | (CHAR16*)Name,\r | |
2417 | L"uefishellsupport") == 0\r | |
2418 | ||gUnicodeCollation->StriColl(\r | |
2419 | gUnicodeCollation,\r | |
2420 | (CHAR16*)Name,\r | |
2421 | L"uefishellversion") == 0\r | |
2422 | ||gUnicodeCollation->StriColl(\r | |
2423 | gUnicodeCollation,\r | |
2424 | (CHAR16*)Name,\r | |
2425 | L"uefiversion") == 0\r | |
2426 | ){\r | |
2427 | return (EFI_INVALID_PARAMETER);\r | |
2428 | }\r | |
2429 | return (InternalEfiShellSetEnv(Name, Value, Volatile));\r | |
2430 | }\r | |
2431 | \r | |
2432 | /**\r | |
2433 | Returns the current directory on the specified device.\r | |
2434 | \r | |
2435 | If FileSystemMapping is NULL, it returns the current working directory. If the\r | |
2436 | FileSystemMapping is not NULL, it returns the current directory associated with the\r | |
2437 | FileSystemMapping. In both cases, the returned name includes the file system\r | |
2438 | mapping (i.e. fs0:\current-dir).\r | |
2439 | \r | |
2440 | @param FileSystemMapping A pointer to the file system mapping. If NULL,\r | |
2441 | then the current working directory is returned.\r | |
2442 | \r | |
2443 | @retval !=NULL The current directory.\r | |
2444 | @retval NULL Current directory does not exist.\r | |
2445 | **/\r | |
2446 | CONST CHAR16 *\r | |
2447 | EFIAPI\r | |
2448 | EfiShellGetCurDir(\r | |
2449 | IN CONST CHAR16 *FileSystemMapping OPTIONAL\r | |
2450 | )\r | |
2451 | {\r | |
2452 | CHAR16 *PathToReturn;\r | |
2453 | UINTN Size;\r | |
2454 | SHELL_MAP_LIST *MapListItem;\r | |
2455 | if (!IsListEmpty(&gShellMapList.Link)) {\r | |
2456 | //\r | |
2457 | // if parameter is NULL, use current\r | |
2458 | //\r | |
2459 | if (FileSystemMapping == NULL) {\r | |
2460 | return (EfiShellGetEnv(L"cwd"));\r | |
2461 | } else {\r | |
2462 | Size = 0;\r | |
2463 | PathToReturn = NULL;\r | |
2464 | MapListItem = ShellCommandFindMapItem(FileSystemMapping);\r | |
2465 | if (MapListItem != NULL) {\r | |
2466 | ASSERT((PathToReturn == NULL && Size == 0) || (PathToReturn != NULL));\r | |
2467 | PathToReturn = StrnCatGrow(&PathToReturn, &Size, MapListItem->MapName, 0);\r | |
2468 | PathToReturn = StrnCatGrow(&PathToReturn, &Size, MapListItem->CurrentDirectoryPath, 0);\r | |
2469 | }\r | |
2470 | }\r | |
2471 | return (AddBufferToFreeList(PathToReturn));\r | |
2472 | } else {\r | |
2473 | return (NULL);\r | |
2474 | }\r | |
2475 | }\r | |
2476 | \r | |
2477 | /**\r | |
2478 | Changes the current directory on the specified device.\r | |
2479 | \r | |
2480 | If the FileSystem is NULL, and the directory Dir does not contain a file system's\r | |
2481 | mapped name, this function changes the current working directory.\r | |
2482 | \r | |
2483 | If the FileSystem is NULL and the directory Dir contains a mapped name, then the\r | |
2484 | current file system and the current directory on that file system are changed.\r | |
2485 | \r | |
2486 | If FileSystem is NULL, and Dir is not NULL, then this changes the current working file\r | |
2487 | system.\r | |
2488 | \r | |
2489 | If FileSystem is not NULL and Dir is not NULL, then this function changes the current\r | |
2490 | directory on the specified file system.\r | |
2491 | \r | |
2492 | If the current working directory or the current working file system is changed then the\r | |
2493 | %cwd% environment variable will be updated\r | |
2494 | \r | |
2495 | @param FileSystem A pointer to the file system's mapped name. If NULL, then the current working\r | |
2496 | directory is changed.\r | |
2497 | @param Dir Points to the NULL-terminated directory on the device specified by FileSystem.\r | |
2498 | \r | |
2499 | @retval EFI_SUCCESS The operation was sucessful\r | |
2500 | @retval EFI_NOT_FOUND The file system could not be found\r | |
2501 | **/\r | |
2502 | EFI_STATUS\r | |
2503 | EFIAPI\r | |
2504 | EfiShellSetCurDir(\r | |
2505 | IN CONST CHAR16 *FileSystem OPTIONAL,\r | |
2506 | IN CONST CHAR16 *Dir\r | |
2507 | )\r | |
2508 | {\r | |
2509 | CHAR16 *MapName;\r | |
2510 | SHELL_MAP_LIST *MapListItem;\r | |
2511 | UINTN Size;\r | |
2512 | EFI_STATUS Status;\r | |
2513 | CHAR16 *TempString;\r | |
2514 | CHAR16 *DirectoryName;\r | |
2515 | UINTN TempLen;\r | |
2516 | \r | |
2517 | Size = 0;\r | |
2518 | MapName = NULL;\r | |
2519 | MapListItem = NULL;\r | |
2520 | TempString = NULL;\r | |
2521 | DirectoryName = NULL;\r | |
2522 | \r | |
3c865f20 | 2523 | if ((FileSystem == NULL && Dir == NULL) || Dir == NULL) {\r |
a405b86d | 2524 | return (EFI_INVALID_PARAMETER);\r |
2525 | }\r | |
2526 | \r | |
2527 | if (IsListEmpty(&gShellMapList.Link)){\r | |
2528 | return (EFI_NOT_FOUND);\r | |
2529 | }\r | |
2530 | \r | |
2531 | DirectoryName = StrnCatGrow(&DirectoryName, NULL, Dir, 0);\r | |
2532 | ASSERT(DirectoryName != NULL);\r | |
2533 | \r | |
2534 | CleanPath(DirectoryName);\r | |
2535 | \r | |
2536 | if (FileSystem == NULL) {\r | |
2537 | //\r | |
2538 | // determine the file system mapping to use\r | |
2539 | //\r | |
2540 | if (StrStr(DirectoryName, L":") != NULL) {\r | |
2541 | ASSERT(MapName == NULL);\r | |
2542 | MapName = StrnCatGrow(&MapName, NULL, DirectoryName, (StrStr(DirectoryName, L":")-DirectoryName+1));\r | |
2543 | }\r | |
2544 | //\r | |
2545 | // find the file system mapping's entry in the list\r | |
2546 | // or use current\r | |
2547 | //\r | |
2548 | if (MapName != NULL) {\r | |
2549 | MapListItem = ShellCommandFindMapItem(MapName);\r | |
2550 | \r | |
2551 | //\r | |
2552 | // make that the current file system mapping\r | |
2553 | //\r | |
2554 | if (MapListItem != NULL) {\r | |
2555 | gShellCurDir = MapListItem;\r | |
2556 | }\r | |
2557 | } else {\r | |
2558 | MapListItem = gShellCurDir;\r | |
2559 | }\r | |
2560 | \r | |
2561 | if (MapListItem == NULL) {\r | |
2562 | return (EFI_NOT_FOUND);\r | |
2563 | }\r | |
2564 | \r | |
2565 | //\r | |
2566 | // now update the MapListItem's current directory\r | |
2567 | //\r | |
2568 | if (MapListItem->CurrentDirectoryPath != NULL && DirectoryName[StrLen(DirectoryName) - 1] != L':') {\r | |
2569 | FreePool(MapListItem->CurrentDirectoryPath);\r | |
2570 | MapListItem->CurrentDirectoryPath = NULL;\r | |
2571 | }\r | |
2572 | if (MapName != NULL) {\r | |
2573 | TempLen = StrLen(MapName);\r | |
2574 | if (TempLen != StrLen(DirectoryName)) {\r | |
2575 | ASSERT((MapListItem->CurrentDirectoryPath == NULL && Size == 0) || (MapListItem->CurrentDirectoryPath != NULL));\r | |
2576 | MapListItem->CurrentDirectoryPath = StrnCatGrow(&MapListItem->CurrentDirectoryPath, &Size, DirectoryName+StrLen(MapName), 0);\r | |
2577 | }\r | |
2578 | } else {\r | |
2579 | ASSERT((MapListItem->CurrentDirectoryPath == NULL && Size == 0) || (MapListItem->CurrentDirectoryPath != NULL));\r | |
2580 | MapListItem->CurrentDirectoryPath = StrnCatGrow(&MapListItem->CurrentDirectoryPath, &Size, DirectoryName, 0);\r | |
2581 | }\r | |
2582 | if ((MapListItem->CurrentDirectoryPath != NULL && MapListItem->CurrentDirectoryPath[StrLen(MapListItem->CurrentDirectoryPath)-1] != L'\\') || (MapListItem->CurrentDirectoryPath == NULL)) {\r | |
2583 | ASSERT((MapListItem->CurrentDirectoryPath == NULL && Size == 0) || (MapListItem->CurrentDirectoryPath != NULL));\r | |
2584 | MapListItem->CurrentDirectoryPath = StrnCatGrow(&MapListItem->CurrentDirectoryPath, &Size, L"\\", 0);\r | |
2585 | }\r | |
2586 | } else {\r | |
2587 | //\r | |
2588 | // cant have a mapping in the directory...\r | |
2589 | //\r | |
2590 | if (StrStr(DirectoryName, L":") != NULL) {\r | |
2591 | return (EFI_INVALID_PARAMETER);\r | |
2592 | }\r | |
2593 | //\r | |
2594 | // FileSystem != NULL\r | |
2595 | //\r | |
2596 | MapListItem = ShellCommandFindMapItem(FileSystem);\r | |
2597 | if (MapListItem == NULL) {\r | |
2598 | return (EFI_INVALID_PARAMETER);\r | |
2599 | }\r | |
2600 | // gShellCurDir = MapListItem;\r | |
2601 | if (DirectoryName != NULL) {\r | |
2602 | //\r | |
2603 | // change current dir on that file system\r | |
2604 | //\r | |
2605 | \r | |
2606 | if (MapListItem->CurrentDirectoryPath != NULL) {\r | |
2607 | FreePool(MapListItem->CurrentDirectoryPath);\r | |
2608 | DEBUG_CODE(MapListItem->CurrentDirectoryPath = NULL;);\r | |
2609 | }\r | |
2610 | // ASSERT((MapListItem->CurrentDirectoryPath == NULL && Size == 0) || (MapListItem->CurrentDirectoryPath != NULL));\r | |
2611 | // MapListItem->CurrentDirectoryPath = StrnCatGrow(&MapListItem->CurrentDirectoryPath, &Size, FileSystem, 0);\r | |
2612 | ASSERT((MapListItem->CurrentDirectoryPath == NULL && Size == 0) || (MapListItem->CurrentDirectoryPath != NULL));\r | |
2613 | MapListItem->CurrentDirectoryPath = StrnCatGrow(&MapListItem->CurrentDirectoryPath, &Size, L"\\", 0);\r | |
2614 | ASSERT((MapListItem->CurrentDirectoryPath == NULL && Size == 0) || (MapListItem->CurrentDirectoryPath != NULL));\r | |
2615 | MapListItem->CurrentDirectoryPath = StrnCatGrow(&MapListItem->CurrentDirectoryPath, &Size, DirectoryName, 0);\r | |
2616 | if (MapListItem->CurrentDirectoryPath[StrLen(MapListItem->CurrentDirectoryPath)-1] != L'\\') {\r | |
2617 | ASSERT((MapListItem->CurrentDirectoryPath == NULL && Size == 0) || (MapListItem->CurrentDirectoryPath != NULL));\r | |
2618 | MapListItem->CurrentDirectoryPath = StrnCatGrow(&MapListItem->CurrentDirectoryPath, &Size, L"\\", 0);\r | |
2619 | }\r | |
2620 | }\r | |
2621 | }\r | |
2622 | //\r | |
2623 | // if updated the current directory then update the environment variable\r | |
2624 | //\r | |
2625 | if (MapListItem == gShellCurDir) {\r | |
2626 | Size = 0;\r | |
2627 | ASSERT((TempString == NULL && Size == 0) || (TempString != NULL));\r | |
2628 | StrnCatGrow(&TempString, &Size, MapListItem->MapName, 0);\r | |
2629 | ASSERT((TempString == NULL && Size == 0) || (TempString != NULL));\r | |
2630 | StrnCatGrow(&TempString, &Size, MapListItem->CurrentDirectoryPath, 0);\r | |
2631 | Status = InternalEfiShellSetEnv(L"cwd", TempString, TRUE);\r | |
2632 | FreePool(TempString);\r | |
2633 | return (Status);\r | |
2634 | }\r | |
2635 | return(EFI_SUCCESS);\r | |
2636 | }\r | |
2637 | \r | |
2638 | /**\r | |
2639 | Return help information about a specific command.\r | |
2640 | \r | |
2641 | This function returns the help information for the specified command. The help text\r | |
2642 | can be internal to the shell or can be from a UEFI Shell manual page.\r | |
2643 | \r | |
2644 | If Sections is specified, then each section name listed will be compared in a casesensitive\r | |
2645 | manner, to the section names described in Appendix B. If the section exists,\r | |
2646 | it will be appended to the returned help text. If the section does not exist, no\r | |
2647 | information will be returned. If Sections is NULL, then all help text information\r | |
2648 | available will be returned.\r | |
2649 | \r | |
2650 | @param Command Points to the NULL-terminated UEFI Shell command name.\r | |
2651 | @param Sections Points to the NULL-terminated comma-delimited\r | |
2652 | section names to return. If NULL, then all\r | |
2653 | sections will be returned.\r | |
2654 | @param HelpText On return, points to a callee-allocated buffer\r | |
2655 | containing all specified help text.\r | |
2656 | \r | |
2657 | @retval EFI_SUCCESS The help text was returned.\r | |
2658 | @retval EFI_OUT_OF_RESOURCES The necessary buffer could not be allocated to hold the\r | |
2659 | returned help text.\r | |
2660 | @retval EFI_INVALID_PARAMETER HelpText is NULL\r | |
2661 | @retval EFI_NOT_FOUND There is no help text available for Command.\r | |
2662 | **/\r | |
2663 | EFI_STATUS\r | |
2664 | EFIAPI\r | |
2665 | EfiShellGetHelpText(\r | |
2666 | IN CONST CHAR16 *Command,\r | |
2667 | IN CONST CHAR16 *Sections OPTIONAL,\r | |
2668 | OUT CHAR16 **HelpText\r | |
2669 | )\r | |
2670 | {\r | |
2671 | CONST CHAR16 *ManFileName;\r | |
2672 | \r | |
2673 | ASSERT(HelpText != NULL);\r | |
2674 | \r | |
2675 | ManFileName = ShellCommandGetManFileNameHandler(Command);\r | |
2676 | \r | |
2677 | if (ManFileName != NULL) {\r | |
2678 | return (ProcessManFile(ManFileName, Command, Sections, NULL, HelpText));\r | |
2679 | } else {\r | |
2680 | return (ProcessManFile(Command, Command, Sections, NULL, HelpText));\r | |
2681 | }\r | |
2682 | }\r | |
2683 | \r | |
2684 | /**\r | |
2685 | Gets the enable status of the page break output mode.\r | |
2686 | \r | |
2687 | User can use this function to determine current page break mode.\r | |
2688 | \r | |
2689 | @retval TRUE The page break output mode is enabled.\r | |
2690 | @retval FALSE The page break output mode is disabled.\r | |
2691 | **/\r | |
2692 | BOOLEAN\r | |
2693 | EFIAPI\r | |
2694 | EfiShellGetPageBreak(\r | |
2695 | VOID\r | |
2696 | )\r | |
2697 | {\r | |
2698 | return(ShellInfoObject.PageBreakEnabled);\r | |
2699 | }\r | |
2700 | \r | |
2701 | /**\r | |
2702 | Judges whether the active shell is the root shell.\r | |
2703 | \r | |
2704 | This function makes the user to know that whether the active Shell is the root shell.\r | |
2705 | \r | |
2706 | @retval TRUE The active Shell is the root Shell.\r | |
2707 | @retval FALSE The active Shell is NOT the root Shell.\r | |
2708 | **/\r | |
2709 | BOOLEAN\r | |
2710 | EFIAPI\r | |
2711 | EfiShellIsRootShell(\r | |
2712 | VOID\r | |
2713 | )\r | |
2714 | {\r | |
2715 | return(ShellInfoObject.RootShellInstance);\r | |
2716 | }\r | |
2717 | \r | |
2718 | /**\r | |
2719 | function to return a semi-colon delimeted list of all alias' in the current shell\r | |
2720 | \r | |
2721 | up to caller to free the memory.\r | |
2722 | \r | |
2723 | @retval NULL No alias' were found\r | |
2724 | @retval NULL An error ocurred getting alias'\r | |
2725 | @return !NULL a list of all alias'\r | |
2726 | **/\r | |
2727 | CHAR16 *\r | |
2728 | EFIAPI\r | |
2729 | InternalEfiShellGetListAlias(\r | |
2730 | )\r | |
2731 | {\r | |
2732 | UINT64 MaxStorSize;\r | |
2733 | UINT64 RemStorSize;\r | |
2734 | UINT64 MaxVarSize;\r | |
2735 | EFI_STATUS Status;\r | |
2736 | EFI_GUID Guid;\r | |
2737 | CHAR16 *VariableName;\r | |
2738 | UINTN NameSize;\r | |
2739 | CHAR16 *RetVal;\r | |
2740 | UINTN RetSize;\r | |
2741 | CHAR16 *Alias;\r | |
2742 | \r | |
2743 | Status = gRT->QueryVariableInfo(EFI_VARIABLE_NON_VOLATILE|EFI_VARIABLE_BOOTSERVICE_ACCESS, &MaxStorSize, &RemStorSize, &MaxVarSize);\r | |
2744 | ASSERT_EFI_ERROR(Status);\r | |
2745 | \r | |
2746 | VariableName = AllocateZeroPool((UINTN)MaxVarSize);\r | |
2747 | RetSize = 0;\r | |
2748 | RetVal = NULL;\r | |
2749 | \r | |
3c865f20 | 2750 | if (VariableName == NULL) {\r |
2751 | return (NULL);\r | |
2752 | }\r | |
2753 | \r | |
a405b86d | 2754 | VariableName[0] = CHAR_NULL;\r |
2755 | \r | |
2756 | while (TRUE) {\r | |
2757 | NameSize = (UINTN)MaxVarSize;\r | |
2758 | Status = gRT->GetNextVariableName(&NameSize, VariableName, &Guid);\r | |
2759 | if (Status == EFI_NOT_FOUND){\r | |
2760 | break;\r | |
2761 | }\r | |
2762 | ASSERT_EFI_ERROR(Status);\r | |
2763 | if (EFI_ERROR(Status)) {\r | |
2764 | break;\r | |
2765 | }\r | |
2766 | if (CompareGuid(&Guid, &gShellAliasGuid)){\r | |
2767 | Alias = GetVariable(VariableName, &gShellAliasGuid);\r | |
2768 | ASSERT((RetVal == NULL && RetSize == 0) || (RetVal != NULL));\r | |
2769 | RetVal = StrnCatGrow(&RetVal, &RetSize, VariableName, 0);\r | |
2770 | RetVal = StrnCatGrow(&RetVal, &RetSize, L";", 0);\r | |
2771 | } // compare guid\r | |
2772 | } // while\r | |
2773 | FreePool(VariableName);\r | |
2774 | \r | |
2775 | return (RetVal);\r | |
2776 | }\r | |
2777 | \r | |
2778 | /**\r | |
2779 | This function returns the command associated with a alias or a list of all\r | |
2780 | alias'.\r | |
2781 | \r | |
2782 | @param[in] Alias Points to the NULL-terminated shell alias.\r | |
2783 | If this parameter is NULL, then all\r | |
2784 | aliases will be returned in ReturnedData.\r | |
2785 | @param[out] Volatile upon return of a single command if TRUE indicates\r | |
2786 | this is stored in a volatile fashion. FALSE otherwise.\r | |
2787 | \r | |
2788 | @return If Alias is not NULL, it will return a pointer to\r | |
2789 | the NULL-terminated command for that alias.\r | |
2790 | If Alias is NULL, ReturnedData points to a ';'\r | |
2791 | delimited list of alias (e.g.\r | |
2792 | ReturnedData = "dir;del;copy;mfp") that is NULL-terminated.\r | |
2793 | @retval NULL an error ocurred\r | |
2794 | @retval NULL Alias was not a valid Alias\r | |
2795 | **/\r | |
2796 | CONST CHAR16 *\r | |
2797 | EFIAPI\r | |
2798 | EfiShellGetAlias(\r | |
2799 | IN CONST CHAR16 *Alias,\r | |
2800 | OUT BOOLEAN *Volatile OPTIONAL\r | |
2801 | )\r | |
2802 | {\r | |
2803 | CHAR16 *RetVal;\r | |
2804 | UINTN RetSize;\r | |
2805 | UINT32 Attribs;\r | |
2806 | EFI_STATUS Status;\r | |
2807 | \r | |
2808 | if (Alias != NULL) {\r | |
2809 | if (Volatile == NULL) {\r | |
2810 | return (AddBufferToFreeList(GetVariable((CHAR16*)Alias, &gShellAliasGuid)));\r | |
2811 | }\r | |
2812 | RetSize = 0;\r | |
2813 | RetVal = NULL;\r | |
2814 | Status = gRT->GetVariable((CHAR16*)Alias, &gShellAliasGuid, &Attribs, &RetSize, RetVal);\r | |
2815 | if (Status == EFI_BUFFER_TOO_SMALL) {\r | |
2816 | RetVal = AllocateZeroPool(RetSize);\r | |
2817 | Status = gRT->GetVariable((CHAR16*)Alias, &gShellAliasGuid, &Attribs, &RetSize, RetVal);\r | |
2818 | }\r | |
2819 | if (EFI_ERROR(Status)) {\r | |
2820 | if (RetVal != NULL) {\r | |
2821 | FreePool(RetVal);\r | |
2822 | }\r | |
2823 | return (NULL);\r | |
2824 | }\r | |
2825 | if ((EFI_VARIABLE_NON_VOLATILE & Attribs) == EFI_VARIABLE_NON_VOLATILE) {\r | |
2826 | *Volatile = FALSE;\r | |
2827 | } else {\r | |
2828 | *Volatile = TRUE;\r | |
2829 | }\r | |
2830 | \r | |
2831 | return (AddBufferToFreeList(RetVal));\r | |
2832 | }\r | |
2833 | return (AddBufferToFreeList(InternalEfiShellGetListAlias()));\r | |
2834 | }\r | |
2835 | \r | |
2836 | /**\r | |
2837 | Changes a shell command alias.\r | |
2838 | \r | |
2839 | This function creates an alias for a shell command or if Alias is NULL it will delete an existing alias.\r | |
2840 | \r | |
2841 | this function does not check for built in alias'.\r | |
2842 | \r | |
2843 | @param[in] Command Points to the NULL-terminated shell command or existing alias.\r | |
2844 | @param[in] Alias Points to the NULL-terminated alias for the shell command. If this is NULL, and\r | |
2845 | Command refers to an alias, that alias will be deleted.\r | |
2846 | @param[in] Volatile if TRUE the Alias being set will be stored in a volatile fashion. if FALSE the\r | |
2847 | Alias being set will be stored in a non-volatile fashion.\r | |
2848 | \r | |
2849 | @retval EFI_SUCCESS Alias created or deleted successfully.\r | |
2850 | @retval EFI_NOT_FOUND the Alias intended to be deleted was not found\r | |
2851 | **/\r | |
2852 | EFI_STATUS\r | |
2853 | EFIAPI\r | |
2854 | InternalSetAlias(\r | |
2855 | IN CONST CHAR16 *Command,\r | |
2856 | IN CONST CHAR16 *Alias,\r | |
2857 | IN BOOLEAN Volatile\r | |
2858 | )\r | |
2859 | {\r | |
2860 | //\r | |
2861 | // We must be trying to remove one if Alias is NULL\r | |
2862 | //\r | |
2863 | if (Alias == NULL) {\r | |
2864 | //\r | |
2865 | // remove an alias (but passed in COMMAND parameter)\r | |
2866 | //\r | |
2867 | return (gRT->SetVariable((CHAR16*)Command, &gShellAliasGuid, 0, 0, NULL));\r | |
2868 | } else {\r | |
2869 | //\r | |
2870 | // Add and replace are the same\r | |
2871 | //\r | |
2872 | \r | |
2873 | // We dont check the error return on purpose since the variable may not exist.\r | |
2874 | gRT->SetVariable((CHAR16*)Command, &gShellAliasGuid, 0, 0, NULL);\r | |
2875 | \r | |
2876 | return (gRT->SetVariable((CHAR16*)Alias, &gShellAliasGuid, EFI_VARIABLE_BOOTSERVICE_ACCESS|(Volatile?0:EFI_VARIABLE_NON_VOLATILE), StrSize(Command), (VOID*)Command));\r | |
2877 | }\r | |
2878 | }\r | |
2879 | \r | |
2880 | /**\r | |
2881 | Changes a shell command alias.\r | |
2882 | \r | |
2883 | This function creates an alias for a shell command or if Alias is NULL it will delete an existing alias.\r | |
2884 | \r | |
2885 | \r | |
2886 | @param[in] Command Points to the NULL-terminated shell command or existing alias.\r | |
2887 | @param[in] Alias Points to the NULL-terminated alias for the shell command. If this is NULL, and\r | |
2888 | Command refers to an alias, that alias will be deleted.\r | |
2889 | @param[in] Replace If TRUE and the alias already exists, then the existing alias will be replaced. If\r | |
2890 | FALSE and the alias already exists, then the existing alias is unchanged and\r | |
2891 | EFI_ACCESS_DENIED is returned.\r | |
2892 | @param[in] Volatile if TRUE the Alias being set will be stored in a volatile fashion. if FALSE the\r | |
2893 | Alias being set will be stored in a non-volatile fashion.\r | |
2894 | \r | |
2895 | @retval EFI_SUCCESS Alias created or deleted successfully.\r | |
2896 | @retval EFI_NOT_FOUND the Alias intended to be deleted was not found\r | |
2897 | @retval EFI_ACCESS_DENIED The alias is a built-in alias or already existed and Replace was set to\r | |
2898 | FALSE.\r | |
2899 | **/\r | |
2900 | EFI_STATUS\r | |
2901 | EFIAPI\r | |
2902 | EfiShellSetAlias(\r | |
2903 | IN CONST CHAR16 *Command,\r | |
2904 | IN CONST CHAR16 *Alias,\r | |
2905 | IN BOOLEAN Replace,\r | |
2906 | IN BOOLEAN Volatile\r | |
2907 | )\r | |
2908 | {\r | |
2909 | //\r | |
2910 | // cant set over a built in alias\r | |
2911 | //\r | |
2912 | if (ShellCommandIsOnAliasList(Alias==NULL?Command:Alias)) {\r | |
2913 | return (EFI_ACCESS_DENIED);\r | |
2914 | }\r | |
2915 | if (Command == NULL || *Command == CHAR_NULL || StrLen(Command) == 0) {\r | |
2916 | return (EFI_INVALID_PARAMETER);\r | |
2917 | }\r | |
2918 | \r | |
2919 | if (EfiShellGetAlias(Command, NULL) != NULL && !Replace) {\r | |
2920 | return (EFI_ACCESS_DENIED);\r | |
2921 | }\r | |
2922 | \r | |
2923 | return (InternalSetAlias(Command, Alias, Volatile));\r | |
2924 | }\r | |
2925 | \r | |
2926 | // Pure FILE_HANDLE operations are passed to FileHandleLib\r | |
2927 | // these functions are indicated by the *\r | |
2928 | EFI_SHELL_PROTOCOL mShellProtocol = {\r | |
2929 | EfiShellExecute,\r | |
2930 | EfiShellGetEnv,\r | |
2931 | EfiShellSetEnv,\r | |
2932 | EfiShellGetAlias,\r | |
2933 | EfiShellSetAlias,\r | |
2934 | EfiShellGetHelpText,\r | |
2935 | EfiShellGetDevicePathFromMap,\r | |
2936 | EfiShellGetMapFromDevicePath,\r | |
2937 | EfiShellGetDevicePathFromFilePath,\r | |
2938 | EfiShellGetFilePathFromDevicePath,\r | |
2939 | EfiShellSetMap,\r | |
2940 | EfiShellGetCurDir,\r | |
2941 | EfiShellSetCurDir,\r | |
2942 | EfiShellOpenFileList,\r | |
2943 | EfiShellFreeFileList,\r | |
2944 | EfiShellRemoveDupInFileList,\r | |
2945 | EfiShellBatchIsActive,\r | |
2946 | EfiShellIsRootShell,\r | |
2947 | EfiShellEnablePageBreak,\r | |
2948 | EfiShellDisablePageBreak,\r | |
2949 | EfiShellGetPageBreak,\r | |
2950 | EfiShellGetDeviceName,\r | |
2951 | (EFI_SHELL_GET_FILE_INFO)FileHandleGetInfo, //*\r | |
2952 | (EFI_SHELL_SET_FILE_INFO)FileHandleSetInfo, //*\r | |
2953 | EfiShellOpenFileByName,\r | |
2954 | EfiShellClose,\r | |
2955 | EfiShellCreateFile,\r | |
2956 | (EFI_SHELL_READ_FILE)FileHandleRead, //*\r | |
2957 | (EFI_SHELL_WRITE_FILE)FileHandleWrite, //*\r | |
2958 | (EFI_SHELL_DELETE_FILE)FileHandleDelete, //*\r | |
2959 | EfiShellDeleteFileByName,\r | |
2960 | (EFI_SHELL_GET_FILE_POSITION)FileHandleGetPosition, //*\r | |
2961 | (EFI_SHELL_SET_FILE_POSITION)FileHandleSetPosition, //*\r | |
2962 | (EFI_SHELL_FLUSH_FILE)FileHandleFlush, //*\r | |
2963 | EfiShellFindFiles,\r | |
2964 | EfiShellFindFilesInDir,\r | |
2965 | (EFI_SHELL_GET_FILE_SIZE)FileHandleGetSize, //*\r | |
2966 | EfiShellOpenRoot,\r | |
2967 | EfiShellOpenRootByHandle,\r | |
2968 | NULL,\r | |
2969 | SHELL_MAJOR_VERSION,\r | |
2970 | SHELL_MINOR_VERSION\r | |
2971 | };\r | |
2972 | \r | |
2973 | /**\r | |
2974 | Function to create and install on the current handle.\r | |
2975 | \r | |
2976 | Will overwrite any existing ShellProtocols in the system to be sure that\r | |
2977 | the current shell is in control.\r | |
2978 | \r | |
2979 | This must be removed via calling CleanUpShellProtocol().\r | |
2980 | \r | |
e9723321 | 2981 | @param[in,out] NewShell The pointer to the pointer to the structure\r |
a405b86d | 2982 | to install.\r |
2983 | \r | |
2984 | @retval EFI_SUCCESS The operation was successful.\r | |
2985 | @return An error from LocateHandle, CreateEvent, or other core function.\r | |
2986 | **/\r | |
2987 | EFI_STATUS\r | |
2988 | EFIAPI\r | |
2989 | CreatePopulateInstallShellProtocol (\r | |
2990 | IN OUT EFI_SHELL_PROTOCOL **NewShell\r | |
2991 | )\r | |
2992 | {\r | |
2993 | EFI_STATUS Status;\r | |
2994 | UINTN BufferSize;\r | |
2995 | EFI_HANDLE *Buffer;\r | |
2996 | UINTN HandleCounter;\r | |
2997 | SHELL_PROTOCOL_HANDLE_LIST *OldProtocolNode;\r | |
2998 | \r | |
2999 | BufferSize = 0;\r | |
3000 | Buffer = NULL;\r | |
3001 | OldProtocolNode = NULL;\r | |
3002 | InitializeListHead(&ShellInfoObject.OldShellList.Link);\r | |
3003 | \r | |
3004 | ASSERT(NewShell != NULL);\r | |
3005 | \r | |
3006 | //\r | |
3007 | // Initialize EfiShellProtocol object...\r | |
3008 | //\r | |
3009 | *NewShell = &mShellProtocol;\r | |
3010 | Status = gBS->CreateEvent(0,\r | |
3011 | 0,\r | |
3012 | NULL,\r | |
3013 | NULL,\r | |
3014 | &mShellProtocol.ExecutionBreak);\r | |
3015 | ASSERT_EFI_ERROR(Status);\r | |
3016 | \r | |
3017 | //\r | |
3018 | // Get the size of the buffer we need.\r | |
3019 | //\r | |
3020 | Status = gBS->LocateHandle(ByProtocol,\r | |
3021 | &gEfiShellProtocolGuid,\r | |
3022 | NULL,\r | |
3023 | &BufferSize,\r | |
3024 | Buffer);\r | |
3025 | if (Status == EFI_BUFFER_TOO_SMALL) {\r | |
3026 | //\r | |
3027 | // Allocate and recall with buffer of correct size\r | |
3028 | //\r | |
3029 | Buffer = AllocateZeroPool(BufferSize);\r | |
3030 | ASSERT(Buffer != NULL);\r | |
3031 | Status = gBS->LocateHandle(ByProtocol,\r | |
3032 | &gEfiShellProtocolGuid,\r | |
3033 | NULL,\r | |
3034 | &BufferSize,\r | |
3035 | Buffer);\r | |
3036 | ASSERT_EFI_ERROR(Status);\r | |
3037 | //\r | |
3038 | // now overwrite each of them, but save the info to restore when we end.\r | |
3039 | //\r | |
3040 | for (HandleCounter = 0 ; HandleCounter < (BufferSize/sizeof(EFI_HANDLE)) ; HandleCounter++) {\r | |
3041 | OldProtocolNode = AllocateZeroPool(sizeof(SHELL_PROTOCOL_HANDLE_LIST));\r | |
3042 | ASSERT(OldProtocolNode != NULL);\r | |
3043 | Status = gBS->OpenProtocol(Buffer[HandleCounter],\r | |
3044 | &gEfiShellProtocolGuid,\r | |
3045 | (VOID **) &(OldProtocolNode->Interface),\r | |
3046 | gImageHandle,\r | |
3047 | NULL,\r | |
3048 | EFI_OPEN_PROTOCOL_GET_PROTOCOL\r | |
3049 | );\r | |
3050 | if (!EFI_ERROR(Status)) {\r | |
3051 | //\r | |
3052 | // reinstall over the old one...\r | |
3053 | //\r | |
3054 | OldProtocolNode->Handle = Buffer[HandleCounter];\r | |
3055 | Status = gBS->ReinstallProtocolInterface(\r | |
3056 | OldProtocolNode->Handle,\r | |
3057 | &gEfiShellProtocolGuid,\r | |
3058 | OldProtocolNode->Interface,\r | |
3059 | (VOID*)(*NewShell));\r | |
3060 | if (!EFI_ERROR(Status)) {\r | |
3061 | //\r | |
3062 | // we reinstalled sucessfully. log this so we can reverse it later.\r | |
3063 | //\r | |
3064 | \r | |
3065 | //\r | |
3066 | // add to the list for subsequent...\r | |
3067 | //\r | |
3068 | InsertTailList(&ShellInfoObject.OldShellList.Link, &OldProtocolNode->Link);\r | |
3069 | }\r | |
3070 | }\r | |
3071 | }\r | |
3072 | FreePool(Buffer);\r | |
3073 | } else if (Status == EFI_NOT_FOUND) {\r | |
3074 | ASSERT(IsListEmpty(&ShellInfoObject.OldShellList.Link));\r | |
3075 | //\r | |
3076 | // no one else published yet. just publish it ourselves.\r | |
3077 | //\r | |
3078 | Status = gBS->InstallProtocolInterface (\r | |
3079 | &gImageHandle,\r | |
3080 | &gEfiShellProtocolGuid,\r | |
3081 | EFI_NATIVE_INTERFACE,\r | |
3082 | (VOID*)(*NewShell));\r | |
3083 | }\r | |
3084 | \r | |
3085 | if (PcdGetBool(PcdShellSupportOldProtocols)){\r | |
3086 | ///@todo support ShellEnvironment2\r | |
3087 | ///@todo do we need to support ShellEnvironment (not ShellEnvironment2) also?\r | |
3088 | }\r | |
3089 | \r | |
3090 | return (Status);\r | |
3091 | }\r | |
3092 | \r | |
3093 | /**\r | |
e9723321 | 3094 | Opposite of CreatePopulateInstallShellProtocol.\r |
a405b86d | 3095 | \r |
3096 | Free all memory and restore the system to the state it was in before calling\r | |
3097 | CreatePopulateInstallShellProtocol.\r | |
3098 | \r | |
3099 | @param[in,out] NewShell The pointer to the new shell protocol structure.\r | |
3100 | \r | |
3101 | @retval EFI_SUCCESS The operation was successful.\r | |
3102 | **/\r | |
3103 | EFI_STATUS\r | |
3104 | EFIAPI\r | |
3105 | CleanUpShellProtocol (\r | |
3106 | IN OUT EFI_SHELL_PROTOCOL *NewShell\r | |
3107 | )\r | |
3108 | {\r | |
3109 | EFI_STATUS Status;\r | |
3110 | SHELL_PROTOCOL_HANDLE_LIST *Node2;\r | |
3111 | \r | |
3112 | //\r | |
3113 | // if we need to restore old protocols...\r | |
3114 | //\r | |
3115 | if (!IsListEmpty(&ShellInfoObject.OldShellList.Link)) {\r | |
3116 | for (Node2 = (SHELL_PROTOCOL_HANDLE_LIST *)GetFirstNode(&ShellInfoObject.OldShellList.Link)\r | |
3117 | ; !IsListEmpty (&ShellInfoObject.OldShellList.Link)\r | |
3118 | ; Node2 = (SHELL_PROTOCOL_HANDLE_LIST *)GetFirstNode(&ShellInfoObject.OldShellList.Link)\r | |
3119 | ){\r | |
3120 | RemoveEntryList(&Node2->Link);\r | |
3121 | Status = gBS->ReinstallProtocolInterface(Node2->Handle,\r | |
3122 | &gEfiShellProtocolGuid,\r | |
3123 | NewShell,\r | |
3124 | Node2->Interface);\r | |
3125 | ASSERT_EFI_ERROR(Status);\r | |
3126 | FreePool(Node2);\r | |
3127 | }\r | |
3128 | } else {\r | |
3129 | //\r | |
3130 | // no need to restore\r | |
3131 | //\r | |
3132 | Status = gBS->UninstallProtocolInterface(gImageHandle,\r | |
3133 | &gEfiShellProtocolGuid,\r | |
3134 | NewShell);\r | |
3135 | ASSERT_EFI_ERROR(Status);\r | |
3136 | }\r | |
3137 | Status = gBS->CloseEvent(NewShell->ExecutionBreak);\r | |
3138 | \r | |
3139 | return (Status);\r | |
3140 | }\r | |
3141 | \r | |
3142 | \r |