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