]> git.proxmox.com Git - mirror_edk2.git/blame - ShellPkg/Library/UefiShellLib/UefiShellLib.c
Upgrade ShellLib and fix bug with param parsing
[mirror_edk2.git] / ShellPkg / Library / UefiShellLib / UefiShellLib.c
CommitLineData
94b17fa1 1/** @file\r
2 Provides interface to shell functionality for shell commands and applications.\r
3\r
4Copyright (c) 2006 - 2009, Intel Corporation\r
5All rights reserved. This program and the accompanying materials\r
6are licensed and made available under the terms and conditions of the BSD License\r
7which accompanies this distribution. The full text of the license may be found at\r
8http://opensource.org/licenses/bsd-license.php\r
9\r
10THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
11WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
12\r
13**/\r
14\r
15#include <Uefi.h>\r
16#include <Library/ShellLib.h>\r
17#include <Library/UefiBootServicesTableLib.h>\r
18#include <Library/BaseLib.h>\r
19#include <Library/BaseMemoryLib.h>\r
20#include <Library/DebugLib.h>\r
21#include <Library/MemoryAllocationLib.h>\r
22#include <Library/DevicePathLib.h>\r
d2b4564b 23#include <Library/PcdLib.h>\r
24#include <Library/FileHandleLib.h>\r
b1f95a06 25#include <Library/PrintLib.h>\r
26#include <Library/UefiLib.h>\r
2247dde4 27#include <Library/HiiLib.h>\r
b1f95a06 28\r
94b17fa1 29#include <Protocol/EfiShellEnvironment2.h>\r
30#include <Protocol/EfiShellInterface.h>\r
31#include <Protocol/EfiShell.h>\r
32#include <Protocol/EfiShellParameters.h>\r
33#include <Protocol/SimpleFileSystem.h>\r
34\r
b1f95a06 35#include "UefiShellLib.h"\r
d2b4564b 36\r
94b17fa1 37#define MAX_FILE_NAME_LEN 522 // (20 * (6+5+2))+1) unicode characters from EFI FAT spec (doubled for bytes)\r
38#define FIND_XXXXX_FILE_BUFFER_SIZE (SIZE_OF_EFI_FILE_INFO + MAX_FILE_NAME_LEN)\r
39\r
d2b4564b 40//\r
41// This is not static since it's extern in the .h file\r
42//\r
43SHELL_PARAM_ITEM EmptyParamList[] = {\r
44 {NULL, TypeMax}\r
45 };\r
46\r
47//\r
48// Static file globals for the shell library\r
49//\r
50STATIC EFI_SHELL_ENVIRONMENT2 *mEfiShellEnvironment2;\r
51STATIC EFI_SHELL_INTERFACE *mEfiShellInterface;\r
52STATIC EFI_SHELL_PROTOCOL *mEfiShellProtocol;\r
53STATIC EFI_SHELL_PARAMETERS_PROTOCOL *mEfiShellParametersProtocol;\r
54STATIC EFI_HANDLE mEfiShellEnvironment2Handle;\r
55STATIC FILE_HANDLE_FUNCTION_MAP FileFunctionMap;\r
2247dde4 56STATIC UINTN mTotalParameterCount;\r
57\r
58/**\r
59 Check if a Unicode character is a hexadecimal character.\r
60\r
61 This internal function checks if a Unicode character is a \r
62 decimal character. The valid hexadecimal character is \r
63 L'0' to L'9', L'a' to L'f', or L'A' to L'F'.\r
64\r
65\r
66 @param Char The character to check against.\r
67\r
68 @retval TRUE If the Char is a hexadecmial character.\r
69 @retval FALSE If the Char is not a hexadecmial character.\r
70\r
71**/\r
72BOOLEAN\r
73EFIAPI\r
74ShellInternalIsHexaDecimalDigitCharacter (\r
75 IN CHAR16 Char\r
76 ) {\r
77 return (BOOLEAN) ((Char >= L'0' && Char <= L'9') || (Char >= L'A' && Char <= L'F') || (Char >= L'a' && Char <= L'f'));\r
78}\r
94b17fa1 79\r
80/**\r
81 helper function to find ShellEnvironment2 for constructor\r
82**/\r
83EFI_STATUS\r
84EFIAPI\r
85ShellFindSE2 (\r
86 IN EFI_HANDLE ImageHandle\r
2247dde4 87 ) {\r
94b17fa1 88 EFI_STATUS Status;\r
89 EFI_HANDLE *Buffer;\r
90 UINTN BufferSize;\r
91 UINTN HandleIndex;\r
92\r
93 BufferSize = 0;\r
94 Buffer = NULL;\r
95 Status = gBS->OpenProtocol(ImageHandle, \r
96 &gEfiShellEnvironment2Guid,\r
97 (VOID **)&mEfiShellEnvironment2,\r
98 ImageHandle,\r
99 NULL,\r
100 EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
101 );\r
102 //\r
103 // look for the mEfiShellEnvironment2 protocol at a higher level\r
104 //\r
9eb53ac3 105 if (EFI_ERROR (Status) || !(CompareGuid (&mEfiShellEnvironment2->SESGuid, &gEfiShellEnvironment2ExtGuid) != FALSE)){\r
94b17fa1 106 //\r
107 // figure out how big of a buffer we need.\r
108 //\r
109 Status = gBS->LocateHandle (ByProtocol,\r
110 &gEfiShellEnvironment2Guid,\r
111 NULL, // ignored for ByProtocol\r
112 &BufferSize,\r
113 Buffer\r
114 );\r
2247dde4 115 //\r
116 // maybe it's not there???\r
117 //\r
118 if (Status == EFI_BUFFER_TOO_SMALL) {\r
119 Buffer = (EFI_HANDLE*)AllocatePool(BufferSize);\r
120 ASSERT(Buffer != NULL);\r
121 Status = gBS->LocateHandle (ByProtocol,\r
122 &gEfiShellEnvironment2Guid,\r
123 NULL, // ignored for ByProtocol\r
124 &BufferSize,\r
125 Buffer\r
126 );\r
127 }\r
94b17fa1 128 if (!EFI_ERROR (Status)) {\r
129 //\r
130 // now parse the list of returned handles\r
131 //\r
132 Status = EFI_NOT_FOUND;\r
133 for (HandleIndex = 0; HandleIndex < (BufferSize/sizeof(Buffer[0])); HandleIndex++) {\r
134 Status = gBS->OpenProtocol(Buffer[HandleIndex], \r
135 &gEfiShellEnvironment2Guid,\r
136 (VOID **)&mEfiShellEnvironment2,\r
137 ImageHandle,\r
138 NULL,\r
139 EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
140 );\r
9eb53ac3 141 if (CompareGuid (&mEfiShellEnvironment2->SESGuid, &gEfiShellEnvironment2ExtGuid) != FALSE) {\r
94b17fa1 142 mEfiShellEnvironment2Handle = Buffer[HandleIndex];\r
143 Status = EFI_SUCCESS;\r
144 break;\r
145 }\r
146 }\r
147 }\r
148 }\r
149 if (Buffer != NULL) {\r
150 FreePool (Buffer);\r
151 }\r
152 return (Status);\r
153}\r
154\r
94b17fa1 155EFI_STATUS\r
156EFIAPI\r
d2b4564b 157ShellLibConstructorWorker (\r
94b17fa1 158 IN EFI_HANDLE ImageHandle,\r
159 IN EFI_SYSTEM_TABLE *SystemTable\r
2247dde4 160 ) {\r
94b17fa1 161 EFI_STATUS Status;\r
162\r
2247dde4 163 //\r
164 // Set the parameter count to an invalid number\r
165 //\r
166 mTotalParameterCount = (UINTN)(-1);\r
167\r
94b17fa1 168 //\r
169 // UEFI 2.0 shell interfaces (used preferentially)\r
170 //\r
171 Status = gBS->OpenProtocol(ImageHandle, \r
172 &gEfiShellProtocolGuid,\r
173 (VOID **)&mEfiShellProtocol,\r
174 ImageHandle,\r
175 NULL,\r
176 EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
177 );\r
178 if (EFI_ERROR(Status)) {\r
179 mEfiShellProtocol = NULL;\r
180 }\r
181 Status = gBS->OpenProtocol(ImageHandle, \r
182 &gEfiShellParametersProtocolGuid,\r
183 (VOID **)&mEfiShellParametersProtocol,\r
184 ImageHandle,\r
185 NULL,\r
186 EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
187 );\r
188 if (EFI_ERROR(Status)) {\r
189 mEfiShellParametersProtocol = NULL;\r
190 }\r
191\r
192 if (mEfiShellParametersProtocol == NULL || mEfiShellProtocol == NULL) {\r
193 //\r
194 // Moved to seperate function due to complexity\r
195 //\r
196 Status = ShellFindSE2(ImageHandle);\r
197\r
198 if (EFI_ERROR(Status)) {\r
199 DEBUG((DEBUG_ERROR, "Status: 0x%08x\r\n", Status));\r
200 mEfiShellEnvironment2 = NULL;\r
201 }\r
202 Status = gBS->OpenProtocol(ImageHandle, \r
203 &gEfiShellInterfaceGuid,\r
204 (VOID **)&mEfiShellInterface,\r
205 ImageHandle,\r
206 NULL,\r
207 EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
208 );\r
209 if (EFI_ERROR(Status)) {\r
210 mEfiShellInterface = NULL;\r
211 }\r
212 }\r
213 //\r
214 // only success getting 2 of either the old or new, but no 1/2 and 1/2\r
215 //\r
216 if ((mEfiShellEnvironment2 != NULL && mEfiShellInterface != NULL) || \r
217 (mEfiShellProtocol != NULL && mEfiShellParametersProtocol != NULL) ) {\r
d2b4564b 218 if (mEfiShellProtocol != NULL) {\r
219 FileFunctionMap.GetFileInfo = mEfiShellProtocol->GetFileInfo;\r
220 FileFunctionMap.SetFileInfo = mEfiShellProtocol->SetFileInfo;\r
221 FileFunctionMap.ReadFile = mEfiShellProtocol->ReadFile;\r
222 FileFunctionMap.WriteFile = mEfiShellProtocol->WriteFile;\r
223 FileFunctionMap.CloseFile = mEfiShellProtocol->CloseFile;\r
224 FileFunctionMap.DeleteFile = mEfiShellProtocol->DeleteFile;\r
225 FileFunctionMap.GetFilePosition = mEfiShellProtocol->GetFilePosition;\r
226 FileFunctionMap.SetFilePosition = mEfiShellProtocol->SetFilePosition;\r
227 FileFunctionMap.FlushFile = mEfiShellProtocol->FlushFile;\r
228 FileFunctionMap.GetFileSize = mEfiShellProtocol->GetFileSize;\r
229 } else {\r
230 FileFunctionMap.GetFileInfo = FileHandleGetInfo;\r
231 FileFunctionMap.SetFileInfo = FileHandleSetInfo;\r
232 FileFunctionMap.ReadFile = FileHandleRead;\r
233 FileFunctionMap.WriteFile = FileHandleWrite;\r
234 FileFunctionMap.CloseFile = FileHandleClose;\r
235 FileFunctionMap.DeleteFile = FileHandleDelete;\r
236 FileFunctionMap.GetFilePosition = FileHandleGetPosition;\r
237 FileFunctionMap.SetFilePosition = FileHandleSetPosition;\r
238 FileFunctionMap.FlushFile = FileHandleFlush;\r
239 FileFunctionMap.GetFileSize = FileHandleGetSize;\r
240 }\r
94b17fa1 241 return (EFI_SUCCESS);\r
242 }\r
243 return (EFI_NOT_FOUND);\r
244}\r
d2b4564b 245/**\r
246 Constructor for the Shell library.\r
247\r
248 Initialize the library and determine if the underlying is a UEFI Shell 2.0 or an EFI shell.\r
249\r
250 @param ImageHandle the image handle of the process\r
251 @param SystemTable the EFI System Table pointer\r
252\r
253 @retval EFI_SUCCESS the initialization was complete sucessfully\r
254 @return others an error ocurred during initialization\r
255**/\r
256EFI_STATUS\r
257EFIAPI\r
258ShellLibConstructor (\r
259 IN EFI_HANDLE ImageHandle,\r
260 IN EFI_SYSTEM_TABLE *SystemTable\r
2247dde4 261 ) {\r
d2b4564b 262\r
263\r
264 mEfiShellEnvironment2 = NULL;\r
265 mEfiShellProtocol = NULL;\r
266 mEfiShellParametersProtocol = NULL;\r
267 mEfiShellInterface = NULL;\r
268 mEfiShellEnvironment2Handle = NULL;\r
269\r
d2b4564b 270 //\r
271 // verify that auto initialize is not set false\r
272 // \r
273 if (PcdGetBool(PcdShellLibAutoInitialize) == 0) {\r
274 return (EFI_SUCCESS);\r
275 }\r
276 \r
277 return (ShellLibConstructorWorker(ImageHandle, SystemTable));\r
278}\r
94b17fa1 279\r
280/**\r
281 Destructory for the library. free any resources.\r
282**/\r
283EFI_STATUS\r
284EFIAPI\r
285ShellLibDestructor (\r
286 IN EFI_HANDLE ImageHandle,\r
287 IN EFI_SYSTEM_TABLE *SystemTable\r
2247dde4 288 ) {\r
94b17fa1 289 if (mEfiShellEnvironment2 != NULL) {\r
290 gBS->CloseProtocol(mEfiShellEnvironment2Handle==NULL?ImageHandle:mEfiShellEnvironment2Handle,\r
291 &gEfiShellEnvironment2Guid,\r
292 ImageHandle,\r
293 NULL);\r
d2b4564b 294 mEfiShellEnvironment2 = NULL;\r
94b17fa1 295 }\r
296 if (mEfiShellInterface != NULL) {\r
297 gBS->CloseProtocol(ImageHandle,\r
298 &gEfiShellInterfaceGuid,\r
299 ImageHandle,\r
300 NULL); \r
d2b4564b 301 mEfiShellInterface = NULL;\r
94b17fa1 302 }\r
303 if (mEfiShellProtocol != NULL) {\r
304 gBS->CloseProtocol(ImageHandle,\r
305 &gEfiShellProtocolGuid,\r
306 ImageHandle,\r
d2b4564b 307 NULL); \r
308 mEfiShellProtocol = NULL;\r
94b17fa1 309 }\r
310 if (mEfiShellParametersProtocol != NULL) {\r
311 gBS->CloseProtocol(ImageHandle,\r
312 &gEfiShellParametersProtocolGuid,\r
313 ImageHandle,\r
314 NULL); \r
d2b4564b 315 mEfiShellParametersProtocol = NULL;\r
94b17fa1 316 }\r
d2b4564b 317 mEfiShellEnvironment2Handle = NULL;\r
94b17fa1 318 return (EFI_SUCCESS);\r
319}\r
d2b4564b 320\r
321/**\r
322 This function causes the shell library to initialize itself. If the shell library\r
323 is already initialized it will de-initialize all the current protocol poitners and\r
324 re-populate them again.\r
325\r
326 When the library is used with PcdShellLibAutoInitialize set to true this function\r
327 will return EFI_SUCCESS and perform no actions.\r
328\r
329 This function is intended for internal access for shell commands only.\r
330\r
331 @retval EFI_SUCCESS the initialization was complete sucessfully\r
332\r
333**/\r
334EFI_STATUS\r
335EFIAPI\r
336ShellInitialize (\r
337 ) {\r
338 //\r
339 // if auto initialize is not false then skip\r
340 //\r
341 if (PcdGetBool(PcdShellLibAutoInitialize) != 0) {\r
342 return (EFI_SUCCESS);\r
343 }\r
344\r
345 //\r
346 // deinit the current stuff\r
347 //\r
348 ASSERT_EFI_ERROR(ShellLibDestructor(gImageHandle, gST));\r
349\r
350 //\r
351 // init the new stuff\r
352 //\r
353 return (ShellLibConstructorWorker(gImageHandle, gST));\r
354}\r
355\r
94b17fa1 356/**\r
357 This function will retrieve the information about the file for the handle \r
358 specified and store it in allocated pool memory.\r
359\r
69817bf8 360 This function allocates a buffer to store the file's information. It is the \r
361 caller's responsibility to free the buffer\r
94b17fa1 362\r
363 @param FileHandle The file handle of the file for which information is \r
364 being requested.\r
365\r
366 @retval NULL information could not be retrieved.\r
367\r
368 @return the information about the file\r
369**/\r
370EFI_FILE_INFO*\r
371EFIAPI\r
372ShellGetFileInfo (\r
373 IN EFI_FILE_HANDLE FileHandle\r
2247dde4 374 ) {\r
d2b4564b 375 return (FileFunctionMap.GetFileInfo(FileHandle));\r
94b17fa1 376}\r
377\r
378/**\r
379 This function will set the information about the file for the opened handle \r
380 specified.\r
381\r
382 @param FileHandle The file handle of the file for which information \r
383 is being set\r
384\r
385 @param FileInfo The infotmation to set.\r
386\r
387 @retval EFI_SUCCESS The information was set.\r
388 @retval EFI_UNSUPPORTED The InformationType is not known.\r
389 @retval EFI_NO_MEDIA The device has no medium.\r
390 @retval EFI_DEVICE_ERROR The device reported an error.\r
391 @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.\r
392 @retval EFI_WRITE_PROTECTED The file or medium is write protected.\r
393 @retval EFI_ACCESS_DENIED The file was opened read only.\r
394 @retval EFI_VOLUME_FULL The volume is full.\r
395**/\r
396EFI_STATUS\r
397EFIAPI\r
398ShellSetFileInfo (\r
399 IN EFI_FILE_HANDLE FileHandle,\r
400 IN EFI_FILE_INFO *FileInfo\r
2247dde4 401 ) {\r
d2b4564b 402 return (FileFunctionMap.SetFileInfo(FileHandle, FileInfo));\r
94b17fa1 403} \r
404 \r
405 /**\r
406 This function will open a file or directory referenced by DevicePath.\r
407\r
408 This function opens a file with the open mode according to the file path. The \r
409 Attributes is valid only for EFI_FILE_MODE_CREATE.\r
410\r
411 @param FilePath on input the device path to the file. On output \r
412 the remaining device path.\r
413 @param DeviceHandle pointer to the system device handle.\r
414 @param FileHandle pointer to the file handle.\r
415 @param OpenMode the mode to open the file with.\r
416 @param Attributes the file's file attributes.\r
417\r
418 @retval EFI_SUCCESS The information was set.\r
419 @retval EFI_INVALID_PARAMETER One of the parameters has an invalid value.\r
420 @retval EFI_UNSUPPORTED Could not open the file path. \r
421 @retval EFI_NOT_FOUND The specified file could not be found on the \r
422 device or the file system could not be found on \r
423 the device.\r
424 @retval EFI_NO_MEDIA The device has no medium.\r
425 @retval EFI_MEDIA_CHANGED The device has a different medium in it or the \r
426 medium is no longer supported.\r
427 @retval EFI_DEVICE_ERROR The device reported an error.\r
428 @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.\r
429 @retval EFI_WRITE_PROTECTED The file or medium is write protected.\r
430 @retval EFI_ACCESS_DENIED The file was opened read only.\r
431 @retval EFI_OUT_OF_RESOURCES Not enough resources were available to open the \r
432 file.\r
433 @retval EFI_VOLUME_FULL The volume is full.\r
434**/\r
435EFI_STATUS\r
436EFIAPI\r
437ShellOpenFileByDevicePath(\r
438 IN OUT EFI_DEVICE_PATH_PROTOCOL **FilePath,\r
439 OUT EFI_HANDLE *DeviceHandle,\r
440 OUT EFI_FILE_HANDLE *FileHandle,\r
441 IN UINT64 OpenMode,\r
442 IN UINT64 Attributes\r
2247dde4 443 ) {\r
94b17fa1 444 CHAR16 *FileName;\r
445 EFI_STATUS Status;\r
446 EFI_SIMPLE_FILE_SYSTEM_PROTOCOL *EfiSimpleFileSystemProtocol;\r
447 EFI_FILE_HANDLE LastHandle;\r
448\r
449 //\r
450 // ASERT for FileHandle, FilePath, and DeviceHandle being NULL\r
451 //\r
452 ASSERT(FilePath != NULL);\r
453 ASSERT(FileHandle != NULL);\r
454 ASSERT(DeviceHandle != NULL);\r
455 // \r
456 // which shell interface should we use\r
457 //\r
458 if (mEfiShellProtocol != NULL) {\r
459 //\r
460 // use UEFI Shell 2.0 method.\r
461 //\r
462 FileName = mEfiShellProtocol->GetFilePathFromDevicePath(*FilePath);\r
463 if (FileName == NULL) {\r
464 return (EFI_INVALID_PARAMETER);\r
465 }\r
466 Status = ShellOpenFileByName(FileName, FileHandle, OpenMode, Attributes);\r
467 FreePool(FileName);\r
468 return (Status);\r
d2b4564b 469 } \r
470\r
471\r
472 //\r
473 // use old shell method.\r
474 //\r
475 Status = gBS->LocateDevicePath (&gEfiSimpleFileSystemProtocolGuid, \r
476 FilePath, \r
477 DeviceHandle);\r
478 if (EFI_ERROR (Status)) {\r
479 return Status;\r
480 }\r
481 Status = gBS->OpenProtocol(*DeviceHandle,\r
482 &gEfiSimpleFileSystemProtocolGuid,\r
b1f95a06 483 (VOID**)&EfiSimpleFileSystemProtocol,\r
d2b4564b 484 gImageHandle,\r
485 NULL,\r
486 EFI_OPEN_PROTOCOL_GET_PROTOCOL);\r
487 if (EFI_ERROR (Status)) {\r
488 return Status;\r
489 }\r
490 Status = EfiSimpleFileSystemProtocol->OpenVolume(EfiSimpleFileSystemProtocol, FileHandle);\r
491 if (EFI_ERROR (Status)) {\r
492 FileHandle = NULL;\r
493 return Status;\r
494 }\r
495\r
496 //\r
497 // go down directories one node at a time.\r
498 //\r
499 while (!IsDevicePathEnd (*FilePath)) {\r
94b17fa1 500 //\r
d2b4564b 501 // For file system access each node should be a file path component\r
94b17fa1 502 //\r
d2b4564b 503 if (DevicePathType (*FilePath) != MEDIA_DEVICE_PATH ||\r
504 DevicePathSubType (*FilePath) != MEDIA_FILEPATH_DP\r
505 ) {\r
94b17fa1 506 FileHandle = NULL;\r
d2b4564b 507 return (EFI_INVALID_PARAMETER);\r
94b17fa1 508 }\r
d2b4564b 509 //\r
510 // Open this file path node\r
511 //\r
512 LastHandle = *FileHandle;\r
513 *FileHandle = NULL;\r
94b17fa1 514\r
515 //\r
d2b4564b 516 // Try to test opening an existing file\r
94b17fa1 517 //\r
d2b4564b 518 Status = LastHandle->Open (\r
519 LastHandle,\r
520 FileHandle,\r
521 ((FILEPATH_DEVICE_PATH*)*FilePath)->PathName,\r
522 OpenMode &~EFI_FILE_MODE_CREATE,\r
523 0\r
524 );\r
94b17fa1 525\r
d2b4564b 526 //\r
527 // see if the error was that it needs to be created\r
528 //\r
529 if ((EFI_ERROR (Status)) && (OpenMode != (OpenMode &~EFI_FILE_MODE_CREATE))) {\r
94b17fa1 530 Status = LastHandle->Open (\r
531 LastHandle,\r
532 FileHandle,\r
533 ((FILEPATH_DEVICE_PATH*)*FilePath)->PathName,\r
d2b4564b 534 OpenMode,\r
535 Attributes\r
94b17fa1 536 );\r
d2b4564b 537 }\r
538 //\r
539 // Close the last node\r
540 //\r
541 LastHandle->Close (LastHandle);\r
94b17fa1 542\r
d2b4564b 543 if (EFI_ERROR(Status)) {\r
544 return (Status);\r
94b17fa1 545 }\r
d2b4564b 546\r
547 //\r
548 // Get the next node\r
549 //\r
550 *FilePath = NextDevicePathNode (*FilePath);\r
94b17fa1 551 }\r
d2b4564b 552 return (EFI_SUCCESS);\r
94b17fa1 553}\r
554\r
555/**\r
556 This function will open a file or directory referenced by filename.\r
557\r
69817bf8 558 If return is EFI_SUCCESS, the Filehandle is the opened file's handle; \r
94b17fa1 559 otherwise, the Filehandle is NULL. The Attributes is valid only for \r
560 EFI_FILE_MODE_CREATE.\r
561\r
562 if FileNAme is NULL then ASSERT()\r
563\r
564 @param FileName pointer to file name\r
565 @param FileHandle pointer to the file handle.\r
566 @param OpenMode the mode to open the file with.\r
567 @param Attributes the file's file attributes.\r
568\r
569 @retval EFI_SUCCESS The information was set.\r
570 @retval EFI_INVALID_PARAMETER One of the parameters has an invalid value.\r
571 @retval EFI_UNSUPPORTED Could not open the file path. \r
572 @retval EFI_NOT_FOUND The specified file could not be found on the \r
573 device or the file system could not be found \r
574 on the device.\r
575 @retval EFI_NO_MEDIA The device has no medium.\r
576 @retval EFI_MEDIA_CHANGED The device has a different medium in it or the \r
577 medium is no longer supported.\r
578 @retval EFI_DEVICE_ERROR The device reported an error.\r
579 @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.\r
580 @retval EFI_WRITE_PROTECTED The file or medium is write protected.\r
581 @retval EFI_ACCESS_DENIED The file was opened read only.\r
582 @retval EFI_OUT_OF_RESOURCES Not enough resources were available to open the \r
583 file.\r
584 @retval EFI_VOLUME_FULL The volume is full.\r
585**/\r
586EFI_STATUS\r
587EFIAPI\r
588ShellOpenFileByName(\r
b82bfcc1 589 IN CONST CHAR16 *FileName,\r
94b17fa1 590 OUT EFI_FILE_HANDLE *FileHandle,\r
591 IN UINT64 OpenMode,\r
592 IN UINT64 Attributes\r
2247dde4 593 ) {\r
94b17fa1 594 EFI_HANDLE DeviceHandle;\r
595 EFI_DEVICE_PATH_PROTOCOL *FilePath;\r
b1f95a06 596 EFI_STATUS Status;\r
597 EFI_FILE_INFO *FileInfo;\r
94b17fa1 598\r
599 //\r
600 // ASSERT if FileName is NULL\r
601 //\r
602 ASSERT(FileName != NULL);\r
603\r
604 if (mEfiShellProtocol != NULL) {\r
605 //\r
606 // Use UEFI Shell 2.0 method\r
607 //\r
b1f95a06 608 Status = mEfiShellProtocol->OpenFileByName(FileName,\r
609 FileHandle,\r
610 OpenMode);\r
2247dde4 611 if (!EFI_ERROR(Status) && ((OpenMode & EFI_FILE_MODE_CREATE) != 0)){\r
612 FileInfo = FileFunctionMap.GetFileInfo(*FileHandle);\r
b1f95a06 613 ASSERT(FileInfo != NULL);\r
614 FileInfo->Attribute = Attributes;\r
2247dde4 615 Status = FileFunctionMap.SetFileInfo(*FileHandle, FileInfo);\r
616 FreePool(FileInfo);\r
b1f95a06 617 }\r
618 return (Status);\r
94b17fa1 619 } \r
620 //\r
621 // Using EFI Shell version\r
622 // this means convert name to path and call that function\r
623 // since this will use EFI method again that will open it.\r
624 //\r
625 ASSERT(mEfiShellEnvironment2 != NULL);\r
b82bfcc1 626 FilePath = mEfiShellEnvironment2->NameToPath ((CHAR16*)FileName);\r
94b17fa1 627 if (FileDevicePath != NULL) {\r
628 return (ShellOpenFileByDevicePath(&FilePath,\r
629 &DeviceHandle,\r
630 FileHandle,\r
631 OpenMode,\r
632 Attributes ));\r
633 }\r
634 return (EFI_DEVICE_ERROR);\r
635}\r
636/**\r
637 This function create a directory\r
638\r
639 If return is EFI_SUCCESS, the Filehandle is the opened directory's handle; \r
640 otherwise, the Filehandle is NULL. If the directory already existed, this \r
641 function opens the existing directory.\r
642\r
643 @param DirectoryName pointer to directory name\r
644 @param FileHandle pointer to the file handle.\r
645\r
646 @retval EFI_SUCCESS The information was set.\r
647 @retval EFI_INVALID_PARAMETER One of the parameters has an invalid value.\r
648 @retval EFI_UNSUPPORTED Could not open the file path. \r
649 @retval EFI_NOT_FOUND The specified file could not be found on the \r
650 device or the file system could not be found \r
651 on the device.\r
652 @retval EFI_NO_MEDIA The device has no medium.\r
653 @retval EFI_MEDIA_CHANGED The device has a different medium in it or the \r
654 medium is no longer supported.\r
655 @retval EFI_DEVICE_ERROR The device reported an error.\r
656 @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.\r
657 @retval EFI_WRITE_PROTECTED The file or medium is write protected.\r
658 @retval EFI_ACCESS_DENIED The file was opened read only.\r
659 @retval EFI_OUT_OF_RESOURCES Not enough resources were available to open the \r
660 file.\r
661 @retval EFI_VOLUME_FULL The volume is full.\r
662 @sa ShellOpenFileByName\r
663**/\r
664EFI_STATUS\r
665EFIAPI\r
666ShellCreateDirectory(\r
b82bfcc1 667 IN CONST CHAR16 *DirectoryName,\r
94b17fa1 668 OUT EFI_FILE_HANDLE *FileHandle\r
2247dde4 669 ) {\r
670 if (mEfiShellProtocol != NULL) {\r
671 //\r
672 // Use UEFI Shell 2.0 method\r
673 //\r
674 return (mEfiShellProtocol->CreateFile(DirectoryName,\r
675 EFI_FILE_DIRECTORY,\r
676 FileHandle\r
677 ));\r
678 } else {\r
679 return (ShellOpenFileByName(DirectoryName,\r
680 FileHandle,\r
681 EFI_FILE_MODE_READ | EFI_FILE_MODE_WRITE | EFI_FILE_MODE_CREATE,\r
682 EFI_FILE_DIRECTORY\r
683 ));\r
684 }\r
94b17fa1 685}\r
686\r
687/**\r
688 This function reads information from an opened file.\r
689\r
690 If FileHandle is not a directory, the function reads the requested number of \r
69817bf8 691 bytes from the file at the file's current position and returns them in Buffer. \r
94b17fa1 692 If the read goes beyond the end of the file, the read length is truncated to the\r
69817bf8 693 end of the file. The file's current position is increased by the number of bytes \r
94b17fa1 694 returned. If FileHandle is a directory, the function reads the directory entry \r
69817bf8 695 at the file's current position and returns the entry in Buffer. If the Buffer \r
94b17fa1 696 is not large enough to hold the current directory entry, then \r
697 EFI_BUFFER_TOO_SMALL is returned and the current file position is not updated. \r
698 BufferSize is set to be the size of the buffer needed to read the entry. On \r
699 success, the current position is updated to the next directory entry. If there \r
700 are no more directory entries, the read returns a zero-length buffer. \r
701 EFI_FILE_INFO is the structure returned as the directory entry.\r
702\r
703 @param FileHandle the opened file handle\r
704 @param BufferSize on input the size of buffer in bytes. on return \r
705 the number of bytes written.\r
706 @param Buffer the buffer to put read data into.\r
707\r
708 @retval EFI_SUCCESS Data was read.\r
709 @retval EFI_NO_MEDIA The device has no media.\r
710 @retval EFI_DEVICE_ERROR The device reported an error.\r
711 @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.\r
712 @retval EFI_BUFFER_TO_SMALL Buffer is too small. ReadSize contains required \r
713 size.\r
714\r
715**/\r
716EFI_STATUS\r
717EFIAPI\r
718ShellReadFile(\r
719 IN EFI_FILE_HANDLE FileHandle,\r
720 IN OUT UINTN *BufferSize,\r
721 OUT VOID *Buffer\r
2247dde4 722 ) {\r
d2b4564b 723 return (FileFunctionMap.ReadFile(FileHandle, BufferSize, Buffer));\r
94b17fa1 724}\r
725\r
726\r
727/**\r
728 Write data to a file.\r
729\r
730 This function writes the specified number of bytes to the file at the current \r
731 file position. The current file position is advanced the actual number of bytes \r
732 written, which is returned in BufferSize. Partial writes only occur when there \r
69817bf8 733 has been a data error during the write attempt (such as "volume space full"). \r
94b17fa1 734 The file is automatically grown to hold the data if required. Direct writes to \r
735 opened directories are not supported.\r
736\r
737 @param FileHandle The opened file for writing\r
738 @param BufferSize on input the number of bytes in Buffer. On output\r
739 the number of bytes written.\r
740 @param Buffer the buffer containing data to write is stored.\r
741\r
742 @retval EFI_SUCCESS Data was written.\r
743 @retval EFI_UNSUPPORTED Writes to an open directory are not supported.\r
744 @retval EFI_NO_MEDIA The device has no media.\r
745 @retval EFI_DEVICE_ERROR The device reported an error.\r
746 @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.\r
747 @retval EFI_WRITE_PROTECTED The device is write-protected.\r
748 @retval EFI_ACCESS_DENIED The file was open for read only.\r
749 @retval EFI_VOLUME_FULL The volume is full.\r
750**/\r
751EFI_STATUS\r
752EFIAPI\r
753ShellWriteFile(\r
754 IN EFI_FILE_HANDLE FileHandle,\r
755 IN OUT UINTN *BufferSize,\r
756 IN VOID *Buffer\r
2247dde4 757 ) {\r
d2b4564b 758 return (FileFunctionMap.WriteFile(FileHandle, BufferSize, Buffer));\r
94b17fa1 759}\r
760\r
761/** \r
762 Close an open file handle.\r
763\r
69817bf8 764 This function closes a specified file handle. All "dirty" cached file data is \r
94b17fa1 765 flushed to the device, and the file is closed. In all cases the handle is \r
766 closed.\r
767\r
768@param FileHandle the file handle to close.\r
769\r
770@retval EFI_SUCCESS the file handle was closed sucessfully.\r
771**/\r
772EFI_STATUS\r
773EFIAPI\r
774ShellCloseFile (\r
775 IN EFI_FILE_HANDLE *FileHandle\r
2247dde4 776 ) {\r
d2b4564b 777 return (FileFunctionMap.CloseFile(*FileHandle));\r
94b17fa1 778}\r
779\r
780/**\r
781 Delete a file and close the handle\r
782\r
783 This function closes and deletes a file. In all cases the file handle is closed.\r
784 If the file cannot be deleted, the warning code EFI_WARN_DELETE_FAILURE is \r
785 returned, but the handle is still closed.\r
786\r
787 @param FileHandle the file handle to delete\r
788\r
789 @retval EFI_SUCCESS the file was closed sucessfully\r
790 @retval EFI_WARN_DELETE_FAILURE the handle was closed, but the file was not \r
791 deleted\r
792 @retval INVALID_PARAMETER One of the parameters has an invalid value.\r
793**/\r
794EFI_STATUS\r
795EFIAPI\r
796ShellDeleteFile (\r
797 IN EFI_FILE_HANDLE *FileHandle\r
2247dde4 798 ) {\r
d2b4564b 799 return (FileFunctionMap.DeleteFile(*FileHandle));\r
94b17fa1 800}\r
801\r
802/**\r
803 Set the current position in a file.\r
804\r
805 This function sets the current file position for the handle to the position \r
806 supplied. With the exception of seeking to position 0xFFFFFFFFFFFFFFFF, only\r
807 absolute positioning is supported, and seeking past the end of the file is \r
808 allowed (a subsequent write would grow the file). Seeking to position \r
809 0xFFFFFFFFFFFFFFFF causes the current position to be set to the end of the file.\r
810 If FileHandle is a directory, the only position that may be set is zero. This \r
811 has the effect of starting the read process of the directory entries over.\r
812\r
813 @param FileHandle The file handle on which the position is being set\r
814 @param Position Byte position from begining of file\r
815\r
816 @retval EFI_SUCCESS Operation completed sucessfully.\r
817 @retval EFI_UNSUPPORTED the seek request for non-zero is not valid on \r
818 directories.\r
819 @retval INVALID_PARAMETER One of the parameters has an invalid value.\r
820**/\r
821EFI_STATUS\r
822EFIAPI\r
823ShellSetFilePosition (\r
824 IN EFI_FILE_HANDLE FileHandle,\r
825 IN UINT64 Position\r
2247dde4 826 ) {\r
d2b4564b 827 return (FileFunctionMap.SetFilePosition(FileHandle, Position));\r
94b17fa1 828}\r
829\r
830/** \r
831 Gets a file's current position\r
832\r
833 This function retrieves the current file position for the file handle. For \r
834 directories, the current file position has no meaning outside of the file \r
835 system driver and as such the operation is not supported. An error is returned\r
836 if FileHandle is a directory.\r
837\r
838 @param FileHandle The open file handle on which to get the position.\r
839 @param Position Byte position from begining of file.\r
840\r
841 @retval EFI_SUCCESS the operation completed sucessfully.\r
842 @retval INVALID_PARAMETER One of the parameters has an invalid value.\r
843 @retval EFI_UNSUPPORTED the request is not valid on directories.\r
844**/\r
845EFI_STATUS\r
846EFIAPI\r
847ShellGetFilePosition (\r
848 IN EFI_FILE_HANDLE FileHandle,\r
849 OUT UINT64 *Position\r
2247dde4 850 ) {\r
d2b4564b 851 return (FileFunctionMap.GetFilePosition(FileHandle, Position));\r
94b17fa1 852}\r
853/**\r
854 Flushes data on a file\r
855 \r
856 This function flushes all modified data associated with a file to a device.\r
857\r
858 @param FileHandle The file handle on which to flush data\r
859\r
860 @retval EFI_SUCCESS The data was flushed.\r
861 @retval EFI_NO_MEDIA The device has no media.\r
862 @retval EFI_DEVICE_ERROR The device reported an error.\r
863 @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.\r
864 @retval EFI_WRITE_PROTECTED The file or medium is write protected.\r
865 @retval EFI_ACCESS_DENIED The file was opened for read only.\r
866**/\r
867EFI_STATUS\r
868EFIAPI\r
869ShellFlushFile (\r
870 IN EFI_FILE_HANDLE FileHandle\r
2247dde4 871 ) {\r
d2b4564b 872 return (FileFunctionMap.FlushFile(FileHandle));\r
94b17fa1 873}\r
874\r
875/**\r
876 Retrieves the first file from a directory\r
877\r
69817bf8 878 This function opens a directory and gets the first file's info in the \r
94b17fa1 879 directory. Caller can use ShellFindNextFile() to get other files. When \r
880 complete the caller is responsible for calling FreePool() on Buffer.\r
881\r
882 @param DirHandle The file handle of the directory to search\r
883 @param Buffer Pointer to buffer for file's information\r
884\r
885 @retval EFI_SUCCESS Found the first file.\r
886 @retval EFI_NOT_FOUND Cannot find the directory.\r
887 @retval EFI_NO_MEDIA The device has no media.\r
888 @retval EFI_DEVICE_ERROR The device reported an error.\r
889 @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.\r
890 @return Others status of ShellGetFileInfo, ShellSetFilePosition,\r
891 or ShellReadFile\r
892**/\r
893EFI_STATUS\r
894EFIAPI\r
895ShellFindFirstFile (\r
896 IN EFI_FILE_HANDLE DirHandle,\r
d2b4564b 897 OUT EFI_FILE_INFO **Buffer\r
2247dde4 898 ) {\r
94b17fa1 899 //\r
d2b4564b 900 // pass to file handle lib\r
94b17fa1 901 //\r
d2b4564b 902 return (FileHandleFindFirstFile(DirHandle, Buffer));\r
94b17fa1 903}\r
904/**\r
905 Retrieves the next file in a directory.\r
906\r
907 To use this function, caller must call the LibFindFirstFile() to get the \r
908 first file, and then use this function get other files. This function can be \r
909 called for several times to get each file's information in the directory. If \r
910 the call of ShellFindNextFile() got the last file in the directory, the next \r
911 call of this function has no file to get. *NoFile will be set to TRUE and the \r
912 Buffer memory will be automatically freed. \r
913\r
914 @param DirHandle the file handle of the directory\r
915 @param Buffer pointer to buffer for file's information\r
916 @param NoFile pointer to boolean when last file is found\r
917\r
918 @retval EFI_SUCCESS Found the next file, or reached last file\r
919 @retval EFI_NO_MEDIA The device has no media.\r
920 @retval EFI_DEVICE_ERROR The device reported an error.\r
921 @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.\r
922**/\r
923EFI_STATUS\r
924EFIAPI\r
925ShellFindNextFile(\r
926 IN EFI_FILE_HANDLE DirHandle,\r
927 OUT EFI_FILE_INFO *Buffer,\r
928 OUT BOOLEAN *NoFile\r
2247dde4 929 ) {\r
94b17fa1 930 //\r
d2b4564b 931 // pass to file handle lib\r
94b17fa1 932 //\r
d2b4564b 933 return (FileHandleFindNextFile(DirHandle, Buffer, NoFile));\r
94b17fa1 934}\r
935/**\r
936 Retrieve the size of a file.\r
937\r
938 if FileHandle is NULL then ASSERT()\r
939 if Size is NULL then ASSERT()\r
940\r
69817bf8 941 This function extracts the file size info from the FileHandle's EFI_FILE_INFO \r
94b17fa1 942 data.\r
943\r
944 @param FileHandle file handle from which size is retrieved\r
945 @param Size pointer to size\r
946\r
947 @retval EFI_SUCCESS operation was completed sucessfully\r
948 @retval EFI_DEVICE_ERROR cannot access the file\r
949**/\r
950EFI_STATUS\r
951EFIAPI\r
952ShellGetFileSize (\r
953 IN EFI_FILE_HANDLE FileHandle,\r
954 OUT UINT64 *Size\r
2247dde4 955 ) {\r
d2b4564b 956 return (FileFunctionMap.GetFileSize(FileHandle, Size));\r
94b17fa1 957}\r
958/**\r
959 Retrieves the status of the break execution flag\r
960\r
961 this function is useful to check whether the application is being asked to halt by the shell.\r
962\r
963 @retval TRUE the execution break is enabled\r
964 @retval FALSE the execution break is not enabled\r
965**/\r
966BOOLEAN\r
967EFIAPI\r
968ShellGetExecutionBreakFlag(\r
969 VOID\r
970 )\r
971{\r
972 // \r
973 // Check for UEFI Shell 2.0 protocols\r
974 //\r
975 if (mEfiShellProtocol != NULL) {\r
976\r
977 //\r
978 // We are using UEFI Shell 2.0; see if the event has been triggered\r
979 //\r
980 if (gBS->CheckEvent(mEfiShellProtocol->ExecutionBreak) != EFI_SUCCESS) {\r
981 return (FALSE);\r
982 }\r
983 return (TRUE);\r
984 } \r
985\r
986 //\r
987 // using EFI Shell; call the function to check\r
988 //\r
989 ASSERT(mEfiShellEnvironment2 != NULL);\r
990 return (mEfiShellEnvironment2->GetExecutionBreak());\r
991}\r
992/**\r
993 return the value of an environment variable\r
994\r
995 this function gets the value of the environment variable set by the \r
996 ShellSetEnvironmentVariable function\r
997\r
998 @param EnvKey The key name of the environment variable.\r
999\r
1000 @retval NULL the named environment variable does not exist.\r
1001 @return != NULL pointer to the value of the environment variable\r
1002**/\r
1003CONST CHAR16*\r
1004EFIAPI\r
1005ShellGetEnvironmentVariable (\r
9b3bf083 1006 IN CONST CHAR16 *EnvKey\r
94b17fa1 1007 )\r
1008{\r
1009 // \r
1010 // Check for UEFI Shell 2.0 protocols\r
1011 //\r
1012 if (mEfiShellProtocol != NULL) {\r
1013 return (mEfiShellProtocol->GetEnv(EnvKey));\r
1014 }\r
1015\r
1016 //\r
1017 // ASSERT that we must have EFI shell\r
1018 //\r
1019 ASSERT(mEfiShellEnvironment2 != NULL);\r
1020\r
1021 //\r
1022 // using EFI Shell\r
1023 //\r
9b3bf083 1024 return (mEfiShellEnvironment2->GetEnv((CHAR16*)EnvKey));\r
94b17fa1 1025}\r
1026/**\r
1027 set the value of an environment variable\r
1028\r
1029This function changes the current value of the specified environment variable. If the\r
1030environment variable exists and the Value is an empty string, then the environment\r
1031variable is deleted. If the environment variable exists and the Value is not an empty\r
1032string, then the value of the environment variable is changed. If the environment\r
1033variable does not exist and the Value is an empty string, there is no action. If the\r
1034environment variable does not exist and the Value is a non-empty string, then the\r
1035environment variable is created and assigned the specified value.\r
1036\r
1037 This is not supported pre-UEFI Shell 2.0.\r
1038\r
1039 @param EnvKey The key name of the environment variable.\r
1040 @param EnvVal The Value of the environment variable\r
1041 @param Volatile Indicates whether the variable is non-volatile (FALSE) or volatile (TRUE).\r
1042\r
1043 @retval EFI_SUCCESS the operation was completed sucessfully\r
1044 @retval EFI_UNSUPPORTED This operation is not allowed in pre UEFI 2.0 Shell environments\r
1045**/\r
1046EFI_STATUS\r
1047EFIAPI\r
1048ShellSetEnvironmentVariable (\r
1049 IN CONST CHAR16 *EnvKey,\r
1050 IN CONST CHAR16 *EnvVal,\r
1051 IN BOOLEAN Volatile\r
1052 )\r
1053{\r
1054 // \r
1055 // Check for UEFI Shell 2.0 protocols\r
1056 //\r
1057 if (mEfiShellProtocol != NULL) {\r
1058 return (mEfiShellProtocol->SetEnv(EnvKey, EnvVal, Volatile));\r
1059 } \r
1060\r
1061 //\r
1062 // This feature does not exist under EFI shell\r
1063 //\r
1064 return (EFI_UNSUPPORTED);\r
1065}\r
1066/**\r
1067 cause the shell to parse and execute a command line.\r
1068\r
1069 This function creates a nested instance of the shell and executes the specified\r
1070command (CommandLine) with the specified environment (Environment). Upon return,\r
1071the status code returned by the specified command is placed in StatusCode.\r
1072If Environment is NULL, then the current environment is used and all changes made\r
1073by the commands executed will be reflected in the current environment. If the\r
1074Environment is non-NULL, then the changes made will be discarded.\r
1075The CommandLine is executed from the current working directory on the current\r
1076device.\r
1077\r
1078EnvironmentVariables and Status are only supported for UEFI Shell 2.0.\r
1079Output is only supported for pre-UEFI Shell 2.0\r
1080\r
1081 @param ImageHandle Parent image that is starting the operation\r
1082 @param CommandLine pointer to null terminated command line.\r
1083 @param Output true to display debug output. false to hide it.\r
1084 @param EnvironmentVariables optional pointer to array of environment variables\r
1085 in the form "x=y". if NULL current set is used.\r
1086 @param Status the status of the run command line.\r
1087\r
1088 @retval EFI_SUCCESS the operation completed sucessfully. Status\r
1089 contains the status code returned.\r
1090 @retval EFI_INVALID_PARAMETER a parameter contains an invalid value\r
1091 @retval EFI_OUT_OF_RESOURCES out of resources\r
1092 @retval EFI_UNSUPPORTED the operation is not allowed.\r
1093**/\r
1094EFI_STATUS\r
1095EFIAPI\r
1096ShellExecute (\r
1097 IN EFI_HANDLE *ParentHandle,\r
1098 IN CHAR16 *CommandLine OPTIONAL,\r
1099 IN BOOLEAN Output OPTIONAL,\r
1100 IN CHAR16 **EnvironmentVariables OPTIONAL,\r
1101 OUT EFI_STATUS *Status OPTIONAL\r
1102 )\r
1103{\r
1104 // \r
1105 // Check for UEFI Shell 2.0 protocols\r
1106 //\r
1107 if (mEfiShellProtocol != NULL) {\r
1108 //\r
1109 // Call UEFI Shell 2.0 version (not using Output parameter)\r
1110 //\r
1111 return (mEfiShellProtocol->Execute(ParentHandle,\r
1112 CommandLine,\r
1113 EnvironmentVariables,\r
1114 Status));\r
1115 } \r
1116 //\r
1117 // ASSERT that we must have EFI shell\r
1118 //\r
1119 ASSERT(mEfiShellEnvironment2 != NULL);\r
1120 //\r
1121 // Call EFI Shell version (not using EnvironmentVariables or Status parameters)\r
1122 // Due to oddity in the EFI shell we want to dereference the ParentHandle here\r
1123 //\r
1124 return (mEfiShellEnvironment2->Execute(*ParentHandle, \r
1125 CommandLine, \r
1126 Output));\r
1127}\r
1128/**\r
1129 Retreives the current directory path\r
1130\r
69817bf8 1131 If the DeviceName is NULL, it returns the current device's current directory \r
94b17fa1 1132 name. If the DeviceName is not NULL, it returns the current directory name \r
1133 on specified drive.\r
1134\r
1135 @param DeviceName the name of the drive to get directory on\r
1136\r
1137 @retval NULL the directory does not exist\r
1138 @return != NULL the directory\r
1139**/\r
1140CONST CHAR16*\r
1141EFIAPI\r
1142ShellGetCurrentDir (\r
1143 IN CHAR16 *DeviceName OPTIONAL\r
1144 )\r
1145{\r
1146 // \r
1147 // Check for UEFI Shell 2.0 protocols\r
1148 //\r
1149 if (mEfiShellProtocol != NULL) {\r
1150 return (mEfiShellProtocol->GetCurDir(DeviceName));\r
1151 } \r
1152 //\r
1153 // ASSERT that we must have EFI shell\r
1154 //\r
1155 ASSERT(mEfiShellEnvironment2 != NULL);\r
1156 return (mEfiShellEnvironment2->CurDir(DeviceName));\r
1157}\r
1158/**\r
1159 sets (enabled or disabled) the page break mode\r
1160\r
1161 when page break mode is enabled the screen will stop scrolling \r
1162 and wait for operator input before scrolling a subsequent screen.\r
1163\r
1164 @param CurrentState TRUE to enable and FALSE to disable\r
1165**/\r
1166VOID \r
1167EFIAPI\r
1168ShellSetPageBreakMode (\r
1169 IN BOOLEAN CurrentState\r
1170 )\r
1171{\r
1172 //\r
1173 // check for enabling\r
1174 //\r
1175 if (CurrentState != 0x00) {\r
1176 // \r
1177 // check for UEFI Shell 2.0\r
1178 //\r
1179 if (mEfiShellProtocol != NULL) {\r
1180 //\r
1181 // Enable with UEFI 2.0 Shell\r
1182 //\r
1183 mEfiShellProtocol->EnablePageBreak();\r
1184 return;\r
1185 } else {\r
1186 // \r
1187 // ASSERT that must have EFI Shell\r
1188 //\r
1189 ASSERT(mEfiShellEnvironment2 != NULL);\r
1190 //\r
1191 // Enable with EFI Shell\r
1192 //\r
1193 mEfiShellEnvironment2->EnablePageBreak (DEFAULT_INIT_ROW, DEFAULT_AUTO_LF);\r
1194 return;\r
1195 }\r
1196 } else {\r
1197 // \r
1198 // check for UEFI Shell 2.0\r
1199 //\r
1200 if (mEfiShellProtocol != NULL) {\r
1201 //\r
1202 // Disable with UEFI 2.0 Shell\r
1203 //\r
1204 mEfiShellProtocol->DisablePageBreak();\r
1205 return;\r
1206 } else {\r
1207 // \r
1208 // ASSERT that must have EFI Shell\r
1209 //\r
1210 ASSERT(mEfiShellEnvironment2 != NULL);\r
1211 //\r
1212 // Disable with EFI Shell\r
1213 //\r
1214 mEfiShellEnvironment2->DisablePageBreak ();\r
1215 return;\r
1216 }\r
1217 }\r
1218}\r
1219\r
1220///\r
1221/// version of EFI_SHELL_FILE_INFO struct, except has no CONST pointers.\r
1222/// This allows for the struct to be populated.\r
1223///\r
1224typedef struct {\r
d2b4564b 1225 LIST_ENTRY Link;\r
94b17fa1 1226 EFI_STATUS Status;\r
1227 CHAR16 *FullName;\r
1228 CHAR16 *FileName;\r
1229 EFI_FILE_HANDLE Handle;\r
1230 EFI_FILE_INFO *Info;\r
1231} EFI_SHELL_FILE_INFO_NO_CONST;\r
1232\r
1233/**\r
1234 Converts a EFI shell list of structures to the coresponding UEFI Shell 2.0 type of list.\r
1235\r
1236 if OldStyleFileList is NULL then ASSERT()\r
1237\r
1238 this function will convert a SHELL_FILE_ARG based list into a callee allocated \r
1239 EFI_SHELL_FILE_INFO based list. it is up to the caller to free the memory via\r
1240 the ShellCloseFileMetaArg function.\r
1241\r
9b3bf083 1242 @param[in] FileList the EFI shell list type\r
b82bfcc1 1243 @param[in,out] ListHead the list to add to\r
94b17fa1 1244\r
1245 @retval the resultant head of the double linked new format list;\r
1246**/\r
1247LIST_ENTRY*\r
1248EFIAPI\r
1249InternalShellConvertFileListType (\r
9b3bf083 1250 IN LIST_ENTRY *FileList,\r
1251 IN OUT LIST_ENTRY *ListHead\r
1252 ){\r
94b17fa1 1253 SHELL_FILE_ARG *OldInfo;\r
9b3bf083 1254 LIST_ENTRY *Link;\r
94b17fa1 1255 EFI_SHELL_FILE_INFO_NO_CONST *NewInfo;\r
1256\r
1257 //\r
9b3bf083 1258 // ASSERTs\r
94b17fa1 1259 //\r
9b3bf083 1260 ASSERT(FileList != NULL);\r
1261 ASSERT(ListHead != NULL);\r
94b17fa1 1262\r
1263 //\r
1264 // enumerate through each member of the old list and copy\r
1265 //\r
d2b4564b 1266 for (Link = FileList->ForwardLink; Link != FileList; Link = Link->ForwardLink) {\r
94b17fa1 1267 OldInfo = CR (Link, SHELL_FILE_ARG, Link, SHELL_FILE_ARG_SIGNATURE);\r
1268\r
1269 //\r
1270 // make sure the old list was valid\r
1271 //\r
1272 ASSERT(OldInfo != NULL); \r
1273 ASSERT(OldInfo->Info != NULL);\r
1274 ASSERT(OldInfo->FullName != NULL);\r
1275 ASSERT(OldInfo->FileName != NULL);\r
1276\r
1277 //\r
1278 // allocate a new EFI_SHELL_FILE_INFO object\r
1279 //\r
1280 NewInfo = AllocateZeroPool(sizeof(EFI_SHELL_FILE_INFO));\r
1281 \r
1282 // \r
1283 // copy the simple items\r
1284 //\r
1285 NewInfo->Handle = OldInfo->Handle;\r
1286 NewInfo->Status = OldInfo->Status;\r
1287\r
d2b4564b 1288 // old shell checks for 0 not NULL\r
1289 OldInfo->Handle = 0;\r
1290\r
94b17fa1 1291 //\r
1292 // allocate new space to copy strings and structure\r
1293 //\r
1294 NewInfo->FullName = AllocateZeroPool(StrSize(OldInfo->FullName));\r
1295 NewInfo->FileName = AllocateZeroPool(StrSize(OldInfo->FileName));\r
1296 NewInfo->Info = AllocateZeroPool((UINTN)OldInfo->Info->Size);\r
1297 \r
1298 //\r
1299 // make sure all the memory allocations were sucessful\r
1300 //\r
1301 ASSERT(NewInfo->FullName != NULL);\r
1302 ASSERT(NewInfo->FileName != NULL);\r
1303 ASSERT(NewInfo->Info != NULL);\r
1304\r
1305 //\r
1306 // Copt the strings and structure\r
1307 //\r
1308 StrCpy(NewInfo->FullName, OldInfo->FullName);\r
1309 StrCpy(NewInfo->FileName, OldInfo->FileName);\r
1310 gBS->CopyMem (NewInfo->Info, OldInfo->Info, (UINTN)OldInfo->Info->Size);\r
1311\r
1312 //\r
1313 // add that to the list\r
1314 //\r
9b3bf083 1315 InsertTailList(ListHead, &NewInfo->Link);\r
94b17fa1 1316 }\r
1317 return (ListHead);\r
1318}\r
1319/**\r
1320 Opens a group of files based on a path.\r
1321\r
1322 This function uses the Arg to open all the matching files. Each matched \r
1323 file has a SHELL_FILE_ARG structure to record the file information. These \r
1324 structures are placed on the list ListHead. Users can get the SHELL_FILE_ARG \r
1325 structures from ListHead to access each file. This function supports wildcards\r
1326 and will process '?' and '*' as such. the list must be freed with a call to \r
1327 ShellCloseFileMetaArg().\r
1328\r
5f7431d0 1329 If you are NOT appending to an existing list *ListHead must be NULL. If \r
1330 *ListHead is NULL then it must be callee freed.\r
94b17fa1 1331\r
1332 @param Arg pointer to path string\r
1333 @param OpenMode mode to open files with\r
1334 @param ListHead head of linked list of results\r
1335\r
1336 @retval EFI_SUCCESS the operation was sucessful and the list head \r
1337 contains the list of opened files\r
1338 #retval EFI_UNSUPPORTED a previous ShellOpenFileMetaArg must be closed first.\r
1339 *ListHead is set to NULL.\r
1340 @return != EFI_SUCCESS the operation failed\r
1341\r
1342 @sa InternalShellConvertFileListType\r
1343**/\r
1344EFI_STATUS\r
1345EFIAPI\r
1346ShellOpenFileMetaArg (\r
1347 IN CHAR16 *Arg,\r
1348 IN UINT64 OpenMode,\r
1349 IN OUT EFI_SHELL_FILE_INFO **ListHead\r
1350 )\r
1351{\r
1352 EFI_STATUS Status;\r
9b3bf083 1353 LIST_ENTRY mOldStyleFileList;\r
d2b4564b 1354 \r
94b17fa1 1355 //\r
1356 // ASSERT that Arg and ListHead are not NULL\r
1357 //\r
1358 ASSERT(Arg != NULL);\r
1359 ASSERT(ListHead != NULL);\r
1360\r
1361 // \r
1362 // Check for UEFI Shell 2.0 protocols\r
1363 //\r
1364 if (mEfiShellProtocol != NULL) {\r
5f7431d0 1365 if (*ListHead == NULL) {\r
1366 *ListHead = (EFI_SHELL_FILE_INFO*)AllocateZeroPool(sizeof(EFI_SHELL_FILE_INFO));\r
1367 if (*ListHead == NULL) {\r
1368 return (EFI_OUT_OF_RESOURCES);\r
1369 }\r
1370 InitializeListHead(&((*ListHead)->Link));\r
1371 } \r
2247dde4 1372 Status = mEfiShellProtocol->OpenFileList(Arg, \r
94b17fa1 1373 OpenMode, \r
2247dde4 1374 ListHead);\r
1375 if (EFI_ERROR(Status)) {\r
1376 mEfiShellProtocol->RemoveDupInFileList(ListHead);\r
1377 } else {\r
1378 Status = mEfiShellProtocol->RemoveDupInFileList(ListHead);\r
1379 }\r
1380 return (Status);\r
94b17fa1 1381 } \r
1382\r
1383 //\r
1384 // ASSERT that we must have EFI shell\r
1385 //\r
1386 ASSERT(mEfiShellEnvironment2 != NULL);\r
1387\r
94b17fa1 1388 //\r
1389 // make sure the list head is initialized\r
1390 //\r
9b3bf083 1391 InitializeListHead(&mOldStyleFileList);\r
94b17fa1 1392\r
1393 //\r
1394 // Get the EFI Shell list of files\r
1395 //\r
9b3bf083 1396 Status = mEfiShellEnvironment2->FileMetaArg(Arg, &mOldStyleFileList);\r
94b17fa1 1397 if (EFI_ERROR(Status)) {\r
1398 *ListHead = NULL;\r
1399 return (Status);\r
1400 }\r
1401\r
9b3bf083 1402 if (*ListHead == NULL) {\r
1403 *ListHead = (EFI_SHELL_FILE_INFO *)AllocateZeroPool(sizeof(EFI_SHELL_FILE_INFO));\r
1404 if (*ListHead == NULL) {\r
1405 return (EFI_OUT_OF_RESOURCES);\r
1406 }\r
1407 }\r
1408\r
94b17fa1 1409 //\r
1410 // Convert that to equivalent of UEFI Shell 2.0 structure\r
1411 //\r
9b3bf083 1412 InternalShellConvertFileListType(&mOldStyleFileList, &(*ListHead)->Link);\r
94b17fa1 1413\r
d2b4564b 1414 //\r
1415 // Free the EFI Shell version that was converted.\r
1416 //\r
9b3bf083 1417 mEfiShellEnvironment2->FreeFileList(&mOldStyleFileList);\r
94b17fa1 1418\r
1419 return (Status);\r
1420}\r
1421/**\r
1422 Free the linked list returned from ShellOpenFileMetaArg\r
1423\r
1424 if ListHead is NULL then ASSERT()\r
1425\r
1426 @param ListHead the pointer to free\r
1427\r
1428 @retval EFI_SUCCESS the operation was sucessful\r
1429**/\r
1430EFI_STATUS\r
1431EFIAPI\r
1432ShellCloseFileMetaArg (\r
1433 IN OUT EFI_SHELL_FILE_INFO **ListHead\r
1434 )\r
1435{\r
1436 LIST_ENTRY *Node;\r
1437\r
1438 //\r
1439 // ASSERT that ListHead is not NULL\r
1440 //\r
1441 ASSERT(ListHead != NULL);\r
1442\r
1443 // \r
1444 // Check for UEFI Shell 2.0 protocols\r
1445 //\r
1446 if (mEfiShellProtocol != NULL) {\r
1447 return (mEfiShellProtocol->FreeFileList(ListHead));\r
1448 } else {\r
94b17fa1 1449 //\r
1450 // Since this is EFI Shell version we need to free our internally made copy \r
1451 // of the list\r
1452 //\r
9b3bf083 1453 for ( Node = GetFirstNode(&(*ListHead)->Link) \r
1454 ; IsListEmpty(&(*ListHead)->Link) == FALSE \r
1455 ; Node = GetFirstNode(&(*ListHead)->Link)) {\r
94b17fa1 1456 RemoveEntryList(Node);\r
d2b4564b 1457 ((EFI_SHELL_FILE_INFO_NO_CONST*)Node)->Handle->Close(((EFI_SHELL_FILE_INFO_NO_CONST*)Node)->Handle);\r
94b17fa1 1458 FreePool(((EFI_SHELL_FILE_INFO_NO_CONST*)Node)->FullName);\r
1459 FreePool(((EFI_SHELL_FILE_INFO_NO_CONST*)Node)->FileName);\r
1460 FreePool(((EFI_SHELL_FILE_INFO_NO_CONST*)Node)->Info);\r
1461 FreePool((EFI_SHELL_FILE_INFO_NO_CONST*)Node);\r
1462 }\r
1463 return EFI_SUCCESS;\r
1464 }\r
1465}\r
1466\r
1467typedef struct {\r
9b3bf083 1468 LIST_ENTRY Link;\r
94b17fa1 1469 CHAR16 *Name;\r
1470 ParamType Type;\r
1471 CHAR16 *Value;\r
1472 UINTN OriginalPosition;\r
1473} SHELL_PARAM_PACKAGE;\r
1474\r
1475/**\r
1476 Checks the list of valid arguments and returns TRUE if the item was found. If the \r
1477 return value is TRUE then the type parameter is set also.\r
1478 \r
1479 if CheckList is NULL then ASSERT();\r
1480 if Name is NULL then ASSERT();\r
1481 if Type is NULL then ASSERT();\r
1482\r
1483 @param Type pointer to type of parameter if it was found\r
1484 @param Name pointer to Name of parameter found\r
1485 @param CheckList List to check against\r
1486\r
1487 @retval TRUE the Parameter was found. Type is valid.\r
1488 @retval FALSE the Parameter was not found. Type is not valid.\r
1489**/\r
1490BOOLEAN\r
1491EFIAPI\r
d2b4564b 1492InternalIsOnCheckList (\r
94b17fa1 1493 IN CONST CHAR16 *Name,\r
1494 IN CONST SHELL_PARAM_ITEM *CheckList,\r
1495 OUT ParamType *Type\r
2247dde4 1496 ) {\r
94b17fa1 1497 SHELL_PARAM_ITEM *TempListItem;\r
1498\r
1499 //\r
1500 // ASSERT that all 3 pointer parameters aren't NULL\r
1501 //\r
1502 ASSERT(CheckList != NULL);\r
1503 ASSERT(Type != NULL);\r
1504 ASSERT(Name != NULL);\r
1505\r
d2b4564b 1506 //\r
1507 // question mark and page break mode are always supported\r
1508 //\r
1509 if ((StrCmp(Name, L"-?") == 0) ||\r
1510 (StrCmp(Name, L"-b") == 0)\r
1511 ) {\r
1512 return (TRUE);\r
1513 }\r
1514\r
94b17fa1 1515 //\r
1516 // Enumerate through the list\r
1517 //\r
1518 for (TempListItem = (SHELL_PARAM_ITEM*)CheckList ; TempListItem->Name != NULL ; TempListItem++) {\r
1519 //\r
9eb53ac3 1520 // If the Type is TypeStart only check the first characters of the passed in param\r
1521 // If it matches set the type and return TRUE\r
94b17fa1 1522 //\r
9eb53ac3 1523 if (TempListItem->Type == TypeStart && StrnCmp(Name, TempListItem->Name, StrLen(TempListItem->Name)) == 0) {\r
1524 *Type = TempListItem->Type;\r
1525 return (TRUE);\r
1526 } else if (StrCmp(Name, TempListItem->Name) == 0) {\r
94b17fa1 1527 *Type = TempListItem->Type;\r
1528 return (TRUE);\r
1529 }\r
1530 }\r
2247dde4 1531\r
94b17fa1 1532 return (FALSE);\r
1533}\r
1534/**\r
d2b4564b 1535 Checks the string for indicators of "flag" status. this is a leading '/', '-', or '+'\r
94b17fa1 1536\r
1537 @param Name pointer to Name of parameter found\r
1538\r
1539 @retval TRUE the Parameter is a flag.\r
1540 @retval FALSE the Parameter not a flag\r
1541**/\r
1542BOOLEAN\r
1543EFIAPI\r
d2b4564b 1544InternalIsFlag (\r
2247dde4 1545 IN CONST CHAR16 *Name,\r
1546 IN BOOLEAN AlwaysAllowNumbers\r
94b17fa1 1547 )\r
1548{\r
1549 //\r
1550 // ASSERT that Name isn't NULL\r
1551 //\r
1552 ASSERT(Name != NULL);\r
1553\r
2247dde4 1554 //\r
1555 // If we accept numbers then dont return TRUE. (they will be values)\r
1556 //\r
1557 if (((Name[0] == L'-' || Name[0] == L'+') && ShellInternalIsHexaDecimalDigitCharacter(Name[1])) && AlwaysAllowNumbers == TRUE) {\r
1558 return (FALSE);\r
1559 }\r
1560\r
94b17fa1 1561 //\r
1562 // If the Name has a / or - as the first character return TRUE\r
1563 //\r
d2b4564b 1564 if ((Name[0] == L'/') || \r
1565 (Name[0] == L'-') ||\r
1566 (Name[0] == L'+')\r
1567 ) {\r
94b17fa1 1568 return (TRUE);\r
1569 }\r
1570 return (FALSE);\r
1571}\r
1572\r
1573/**\r
1574 Checks the command line arguments passed against the list of valid ones. \r
1575\r
1576 If no initialization is required, then return RETURN_SUCCESS.\r
1577 \r
1578 @param CheckList pointer to list of parameters to check\r
1579 @param CheckPackage pointer to pointer to list checked values\r
1580 @param ProblemParam optional pointer to pointer to unicode string for \r
d2b4564b 1581 the paramater that caused failure. If used then the\r
1582 caller is responsible for freeing the memory.\r
94b17fa1 1583 @param AutoPageBreak will automatically set PageBreakEnabled for "b" parameter\r
1584 @param Argc Count of parameters in Argv\r
1585 @param Argv pointer to array of parameters\r
1586\r
1587 @retval EFI_SUCCESS The operation completed sucessfully.\r
1588 @retval EFI_OUT_OF_RESOURCES A memory allocation failed\r
1589 @retval EFI_INVALID_PARAMETER A parameter was invalid\r
1590 @retval EFI_VOLUME_CORRUPTED the command line was corrupt. an argument was \r
1591 duplicated. the duplicated command line argument \r
1592 was returned in ProblemParam if provided.\r
1593 @retval EFI_NOT_FOUND a argument required a value that was missing. \r
1594 the invalid command line argument was returned in\r
1595 ProblemParam if provided.\r
1596**/\r
2247dde4 1597STATIC\r
94b17fa1 1598EFI_STATUS\r
1599EFIAPI\r
1600InternalCommandLineParse (\r
1601 IN CONST SHELL_PARAM_ITEM *CheckList,\r
1602 OUT LIST_ENTRY **CheckPackage,\r
1603 OUT CHAR16 **ProblemParam OPTIONAL,\r
1604 IN BOOLEAN AutoPageBreak,\r
1605 IN CONST CHAR16 **Argv,\r
2247dde4 1606 IN UINTN Argc,\r
1607 IN BOOLEAN AlwaysAllowNumbers\r
1608 ) {\r
94b17fa1 1609 UINTN LoopCounter;\r
94b17fa1 1610 ParamType CurrentItemType;\r
1611 SHELL_PARAM_PACKAGE *CurrentItemPackage;\r
1612 BOOLEAN GetItemValue;\r
1613\r
1614 CurrentItemPackage = NULL;\r
2247dde4 1615 mTotalParameterCount = 0;\r
94b17fa1 1616 GetItemValue = FALSE;\r
1617\r
1618 //\r
1619 // If there is only 1 item we dont need to do anything\r
1620 //\r
1621 if (Argc <= 1) {\r
1622 *CheckPackage = NULL;\r
1623 return (EFI_SUCCESS);\r
1624 }\r
1625\r
2247dde4 1626 //\r
1627 // ASSERTs\r
1628 //\r
1629 ASSERT(CheckList != NULL);\r
1630 ASSERT(Argv != NULL);\r
1631\r
94b17fa1 1632 //\r
1633 // initialize the linked list\r
1634 //\r
1635 *CheckPackage = (LIST_ENTRY*)AllocateZeroPool(sizeof(LIST_ENTRY));\r
1636 InitializeListHead(*CheckPackage);\r
1637\r
1638 //\r
1639 // loop through each of the arguments\r
1640 //\r
1641 for (LoopCounter = 0 ; LoopCounter < Argc ; ++LoopCounter) {\r
1642 if (Argv[LoopCounter] == NULL) {\r
1643 //\r
1644 // do nothing for NULL argv\r
1645 //\r
d2b4564b 1646 } else if (InternalIsOnCheckList(Argv[LoopCounter], CheckList, &CurrentItemType) == TRUE) {\r
2247dde4 1647 //\r
1648 // We might have leftover if last parameter didnt have optional value\r
1649 //\r
1650 if (GetItemValue == TRUE) {\r
1651 GetItemValue = FALSE;\r
1652 InsertHeadList(*CheckPackage, &CurrentItemPackage->Link);\r
1653 }\r
94b17fa1 1654 //\r
1655 // this is a flag\r
1656 //\r
1657 CurrentItemPackage = AllocatePool(sizeof(SHELL_PARAM_PACKAGE));\r
1658 ASSERT(CurrentItemPackage != NULL);\r
1659 CurrentItemPackage->Name = AllocatePool(StrSize(Argv[LoopCounter]));\r
1660 ASSERT(CurrentItemPackage->Name != NULL);\r
1661 StrCpy(CurrentItemPackage->Name, Argv[LoopCounter]);\r
1662 CurrentItemPackage->Type = CurrentItemType;\r
1663 CurrentItemPackage->OriginalPosition = (UINTN)(-1);\r
b1f95a06 1664 CurrentItemPackage->Value = NULL;\r
94b17fa1 1665\r
1666 //\r
1667 // Does this flag require a value\r
1668 //\r
1669 if (CurrentItemPackage->Type == TypeValue) {\r
1670 //\r
1671 // trigger the next loop to populate the value of this item\r
1672 //\r
1673 GetItemValue = TRUE; \r
1674 } else {\r
1675 //\r
1676 // this item has no value expected; we are done\r
1677 //\r
9b3bf083 1678 InsertHeadList(*CheckPackage, &CurrentItemPackage->Link);\r
94b17fa1 1679 }\r
2247dde4 1680 } else if (GetItemValue == TRUE && InternalIsFlag(Argv[LoopCounter], AlwaysAllowNumbers) == FALSE) {\r
b1f95a06 1681 ASSERT(CurrentItemPackage != NULL);\r
1682 //\r
1683 // get the item VALUE for the previous flag\r
1684 //\r
1685 GetItemValue = FALSE;\r
1686 CurrentItemPackage->Value = AllocateZeroPool(StrSize(Argv[LoopCounter]));\r
1687 ASSERT(CurrentItemPackage->Value != NULL);\r
1688 StrCpy(CurrentItemPackage->Value, Argv[LoopCounter]);\r
9b3bf083 1689 InsertHeadList(*CheckPackage, &CurrentItemPackage->Link);\r
2247dde4 1690 } else if (InternalIsFlag(Argv[LoopCounter], AlwaysAllowNumbers) == FALSE) {\r
b1f95a06 1691 //\r
1692 // add this one as a non-flag\r
1693 //\r
1694 CurrentItemPackage = AllocatePool(sizeof(SHELL_PARAM_PACKAGE));\r
1695 ASSERT(CurrentItemPackage != NULL);\r
1696 CurrentItemPackage->Name = NULL;\r
1697 CurrentItemPackage->Type = TypePosition;\r
1698 CurrentItemPackage->Value = AllocatePool(StrSize(Argv[LoopCounter]));\r
1699 ASSERT(CurrentItemPackage->Value != NULL);\r
1700 StrCpy(CurrentItemPackage->Value, Argv[LoopCounter]);\r
2247dde4 1701 CurrentItemPackage->OriginalPosition = mTotalParameterCount++;\r
9b3bf083 1702 InsertHeadList(*CheckPackage, &CurrentItemPackage->Link);\r
94b17fa1 1703 } else if (ProblemParam) {\r
1704 //\r
1705 // this was a non-recognised flag... error!\r
1706 //\r
d2b4564b 1707 *ProblemParam = AllocatePool(StrSize(Argv[LoopCounter]));\r
1708 ASSERT(*ProblemParam != NULL);\r
1709 StrCpy(*ProblemParam, Argv[LoopCounter]);\r
94b17fa1 1710 ShellCommandLineFreeVarList(*CheckPackage);\r
1711 *CheckPackage = NULL;\r
1712 return (EFI_VOLUME_CORRUPTED);\r
1713 } else {\r
1714 ShellCommandLineFreeVarList(*CheckPackage);\r
1715 *CheckPackage = NULL;\r
1716 return (EFI_VOLUME_CORRUPTED);\r
1717 }\r
1718 }\r
1719 //\r
1720 // support for AutoPageBreak\r
1721 //\r
1722 if (AutoPageBreak && ShellCommandLineGetFlag(*CheckPackage, L"-b")) {\r
1723 ShellSetPageBreakMode(TRUE);\r
1724 }\r
1725 return (EFI_SUCCESS);\r
1726}\r
1727\r
1728/**\r
1729 Checks the command line arguments passed against the list of valid ones. \r
1730 Optionally removes NULL values first.\r
1731 \r
1732 If no initialization is required, then return RETURN_SUCCESS.\r
1733 \r
1734 @param CheckList pointer to list of parameters to check\r
1735 @param CheckPackage pointer to pointer to list checked values\r
1736 @param ProblemParam optional pointer to pointer to unicode string for \r
1737 the paramater that caused failure.\r
1738 @param AutoPageBreak will automatically set PageBreakEnabled for "b" parameter\r
1739\r
1740 @retval EFI_SUCCESS The operation completed sucessfully.\r
1741 @retval EFI_OUT_OF_RESOURCES A memory allocation failed\r
1742 @retval EFI_INVALID_PARAMETER A parameter was invalid\r
1743 @retval EFI_VOLUME_CORRUPTED the command line was corrupt. an argument was \r
1744 duplicated. the duplicated command line argument \r
1745 was returned in ProblemParam if provided.\r
1746 @retval EFI_DEVICE_ERROR the commands contained 2 opposing arguments. one\r
1747 of the command line arguments was returned in \r
1748 ProblemParam if provided.\r
1749 @retval EFI_NOT_FOUND a argument required a value that was missing. \r
1750 the invalid command line argument was returned in\r
1751 ProblemParam if provided.\r
1752**/\r
1753EFI_STATUS\r
1754EFIAPI\r
2247dde4 1755ShellCommandLineParseEx (\r
94b17fa1 1756 IN CONST SHELL_PARAM_ITEM *CheckList,\r
1757 OUT LIST_ENTRY **CheckPackage,\r
1758 OUT CHAR16 **ProblemParam OPTIONAL,\r
2247dde4 1759 IN BOOLEAN AutoPageBreak,\r
1760 IN BOOLEAN AlwaysAllowNumbers\r
1761 ) {\r
94b17fa1 1762 // \r
1763 // ASSERT that CheckList and CheckPackage aren't NULL\r
1764 //\r
1765 ASSERT(CheckList != NULL);\r
1766 ASSERT(CheckPackage != NULL);\r
1767\r
1768 // \r
1769 // Check for UEFI Shell 2.0 protocols\r
1770 //\r
1771 if (mEfiShellParametersProtocol != NULL) {\r
1772 return (InternalCommandLineParse(CheckList, \r
1773 CheckPackage, \r
1774 ProblemParam, \r
1775 AutoPageBreak, \r
08d7f8e8 1776 (CONST CHAR16**) mEfiShellParametersProtocol->Argv,\r
2247dde4 1777 mEfiShellParametersProtocol->Argc,\r
1778 AlwaysAllowNumbers));\r
94b17fa1 1779 }\r
1780\r
1781 // \r
1782 // ASSERT That EFI Shell is not required\r
1783 //\r
1784 ASSERT (mEfiShellInterface != NULL);\r
1785 return (InternalCommandLineParse(CheckList, \r
1786 CheckPackage, \r
1787 ProblemParam, \r
1788 AutoPageBreak, \r
08d7f8e8 1789 (CONST CHAR16**) mEfiShellInterface->Argv,\r
2247dde4 1790 mEfiShellInterface->Argc,\r
1791 AlwaysAllowNumbers));\r
94b17fa1 1792}\r
1793\r
1794/**\r
1795 Frees shell variable list that was returned from ShellCommandLineParse.\r
1796\r
1797 This function will free all the memory that was used for the CheckPackage\r
1798 list of postprocessed shell arguments.\r
1799\r
1800 this function has no return value.\r
1801\r
1802 if CheckPackage is NULL, then return\r
1803\r
1804 @param CheckPackage the list to de-allocate\r
1805 **/\r
1806VOID\r
1807EFIAPI\r
1808ShellCommandLineFreeVarList (\r
1809 IN LIST_ENTRY *CheckPackage\r
2247dde4 1810 ) {\r
94b17fa1 1811 LIST_ENTRY *Node;\r
1812\r
1813 //\r
1814 // check for CheckPackage == NULL\r
1815 //\r
1816 if (CheckPackage == NULL) {\r
1817 return;\r
1818 }\r
1819\r
1820 //\r
1821 // for each node in the list\r
1822 //\r
9eb53ac3 1823 for ( Node = GetFirstNode(CheckPackage)\r
2247dde4 1824 ; IsListEmpty(CheckPackage) == FALSE\r
9eb53ac3 1825 ; Node = GetFirstNode(CheckPackage)\r
1826 ){\r
94b17fa1 1827 //\r
1828 // Remove it from the list\r
1829 //\r
1830 RemoveEntryList(Node);\r
1831\r
1832 //\r
1833 // if it has a name free the name\r
1834 //\r
1835 if (((SHELL_PARAM_PACKAGE*)Node)->Name != NULL) {\r
1836 FreePool(((SHELL_PARAM_PACKAGE*)Node)->Name);\r
1837 }\r
1838\r
1839 //\r
1840 // if it has a value free the value\r
1841 //\r
1842 if (((SHELL_PARAM_PACKAGE*)Node)->Value != NULL) {\r
1843 FreePool(((SHELL_PARAM_PACKAGE*)Node)->Value);\r
1844 }\r
1845 \r
1846 //\r
1847 // free the node structure\r
1848 //\r
1849 FreePool((SHELL_PARAM_PACKAGE*)Node);\r
1850 }\r
1851 //\r
1852 // free the list head node\r
1853 //\r
1854 FreePool(CheckPackage);\r
1855}\r
1856/**\r
1857 Checks for presence of a flag parameter\r
1858\r
1859 flag arguments are in the form of "-<Key>" or "/<Key>", but do not have a value following the key\r
1860\r
1861 if CheckPackage is NULL then return FALSE.\r
1862 if KeyString is NULL then ASSERT()\r
1863 \r
1864 @param CheckPackage The package of parsed command line arguments\r
1865 @param KeyString the Key of the command line argument to check for\r
1866\r
1867 @retval TRUE the flag is on the command line\r
1868 @retval FALSE the flag is not on the command line\r
1869 **/\r
1870BOOLEAN\r
1871EFIAPI\r
1872ShellCommandLineGetFlag (\r
1873 IN CONST LIST_ENTRY *CheckPackage,\r
1874 IN CHAR16 *KeyString\r
2247dde4 1875 ) {\r
94b17fa1 1876 LIST_ENTRY *Node;\r
1877\r
1878 //\r
1879 // ASSERT that both CheckPackage and KeyString aren't NULL\r
1880 //\r
1881 ASSERT(KeyString != NULL);\r
1882\r
1883 //\r
1884 // return FALSE for no package\r
1885 //\r
1886 if (CheckPackage == NULL) {\r
1887 return (FALSE);\r
1888 }\r
1889\r
1890 //\r
1891 // enumerate through the list of parametrs\r
1892 //\r
9eb53ac3 1893 for ( Node = GetFirstNode(CheckPackage) \r
1894 ; !IsNull (CheckPackage, Node) \r
1895 ; Node = GetNextNode(CheckPackage, Node) \r
1896 ){\r
94b17fa1 1897 //\r
1898 // If the Name matches, return TRUE (and there may be NULL name)\r
1899 //\r
1900 if (((SHELL_PARAM_PACKAGE*)Node)->Name != NULL) {\r
9eb53ac3 1901 //\r
1902 // If Type is TypeStart then only compare the begining of the strings\r
1903 //\r
1904 if ( ((SHELL_PARAM_PACKAGE*)Node)->Type == TypeStart \r
1905 && StrnCmp(KeyString, ((SHELL_PARAM_PACKAGE*)Node)->Name, StrLen(KeyString)) == 0\r
1906 ){\r
1907 return (TRUE);\r
1908 } else if (StrCmp(KeyString, ((SHELL_PARAM_PACKAGE*)Node)->Name) == 0) {\r
94b17fa1 1909 return (TRUE);\r
1910 }\r
1911 }\r
1912 }\r
1913 return (FALSE);\r
1914}\r
1915/**\r
1916 returns value from command line argument\r
1917\r
1918 value parameters are in the form of "-<Key> value" or "/<Key> value"\r
1919 \r
1920 if CheckPackage is NULL, then return NULL;\r
1921\r
1922 @param CheckPackage The package of parsed command line arguments\r
1923 @param KeyString the Key of the command line argument to check for\r
1924\r
1925 @retval NULL the flag is not on the command line\r
1926 @return !=NULL pointer to unicode string of the value\r
1927 **/\r
1928CONST CHAR16*\r
1929EFIAPI\r
1930ShellCommandLineGetValue (\r
1931 IN CONST LIST_ENTRY *CheckPackage,\r
1932 IN CHAR16 *KeyString\r
2247dde4 1933 ) {\r
94b17fa1 1934 LIST_ENTRY *Node;\r
1935\r
1936 //\r
1937 // check for CheckPackage == NULL\r
1938 //\r
1939 if (CheckPackage == NULL) {\r
1940 return (NULL);\r
1941 }\r
1942\r
1943 //\r
1944 // enumerate through the list of parametrs\r
1945 //\r
9eb53ac3 1946 for ( Node = GetFirstNode(CheckPackage) \r
1947 ; !IsNull (CheckPackage, Node) \r
1948 ; Node = GetNextNode(CheckPackage, Node) \r
1949 ){\r
94b17fa1 1950 //\r
1951 // If the Name matches, return the value (name can be NULL)\r
1952 //\r
1953 if (((SHELL_PARAM_PACKAGE*)Node)->Name != NULL) {\r
9eb53ac3 1954 //\r
1955 // If Type is TypeStart then only compare the begining of the strings\r
1956 //\r
1957 if ( ((SHELL_PARAM_PACKAGE*)Node)->Type == TypeStart \r
1958 && StrnCmp(KeyString, ((SHELL_PARAM_PACKAGE*)Node)->Name, StrLen(KeyString)) == 0\r
1959 ){\r
1960 //\r
1961 // return the string part after the flag\r
1962 //\r
1963 return (((SHELL_PARAM_PACKAGE*)Node)->Name + StrLen(KeyString));\r
1964 } else if (StrCmp(KeyString, ((SHELL_PARAM_PACKAGE*)Node)->Name) == 0) {\r
1965 //\r
1966 // return the value\r
1967 //\r
94b17fa1 1968 return (((SHELL_PARAM_PACKAGE*)Node)->Value);\r
1969 }\r
1970 }\r
1971 }\r
1972 return (NULL);\r
1973}\r
1974/**\r
1975 returns raw value from command line argument\r
1976\r
1977 raw value parameters are in the form of "value" in a specific position in the list\r
1978 \r
1979 if CheckPackage is NULL, then return NULL;\r
1980\r
1981 @param CheckPackage The package of parsed command line arguments\r
1982 @param Position the position of the value \r
1983\r
1984 @retval NULL the flag is not on the command line\r
1985 @return !=NULL pointer to unicode string of the value\r
1986 **/\r
1987CONST CHAR16*\r
1988EFIAPI\r
1989ShellCommandLineGetRawValue (\r
1990 IN CONST LIST_ENTRY *CheckPackage,\r
1991 IN UINT32 Position\r
2247dde4 1992 ) {\r
94b17fa1 1993 LIST_ENTRY *Node;\r
1994\r
1995 //\r
1996 // check for CheckPackage == NULL\r
1997 //\r
1998 if (CheckPackage == NULL) {\r
1999 return (NULL);\r
2000 }\r
2001\r
2002 //\r
2003 // enumerate through the list of parametrs\r
2004 //\r
b82bfcc1 2005 for ( Node = GetFirstNode(CheckPackage) \r
2006 ; !IsNull (CheckPackage, Node) \r
2007 ; Node = GetNextNode(CheckPackage, Node) \r
2008 ){\r
94b17fa1 2009 //\r
2010 // If the position matches, return the value\r
2011 //\r
2012 if (((SHELL_PARAM_PACKAGE*)Node)->OriginalPosition == Position) {\r
2013 return (((SHELL_PARAM_PACKAGE*)Node)->Value);\r
2014 }\r
2015 }\r
2016 return (NULL);\r
b1f95a06 2017}\r
2247dde4 2018\r
2019/**\r
2020 returns the number of command line value parameters that were parsed. \r
2021 \r
2022 this will not include flags.\r
2023\r
2024 @retval (UINTN)-1 No parsing has ocurred\r
2025 @return other The number of value parameters found\r
2026**/\r
2027UINTN\r
2028EFIAPI\r
2029ShellCommandLineGetCount(\r
2030 VOID\r
2031 ){\r
2032 return (mTotalParameterCount);\r
2033}\r
2034\r
975136ab 2035/**\r
2036 This is a find and replace function. it will return the NewString as a copy of \r
2037 SourceString with each instance of FindTarget replaced with ReplaceWith.\r
2038\r
2039 If the string would grow bigger than NewSize it will halt and return error.\r
2040\r
2041 @param[in] SourceString String with source buffer\r
b82bfcc1 2042 @param[in,out] NewString String with resultant buffer\r
975136ab 2043 @param[in] NewSize Size in bytes of NewString\r
2044 @param[in] FindTarget String to look for\r
2045 @param[in[ ReplaceWith String to replace FindTarget with\r
2046\r
2047 @retval EFI_INVALID_PARAMETER SourceString was NULL\r
2048 @retval EFI_INVALID_PARAMETER NewString was NULL\r
2049 @retval EFI_INVALID_PARAMETER FindTarget was NULL\r
2050 @retval EFI_INVALID_PARAMETER ReplaceWith was NULL\r
2051 @retval EFI_INVALID_PARAMETER FindTarget had length < 1\r
2052 @retval EFI_INVALID_PARAMETER SourceString had length < 1\r
2053 @retval EFI_BUFFER_TOO_SMALL NewSize was less than the minimum size to hold \r
2054 the new string (truncation occurred)\r
2055 @retval EFI_SUCCESS the string was sucessfully copied with replacement\r
2056**/\r
2057\r
2058EFI_STATUS\r
2059EFIAPI\r
2060CopyReplace(\r
2061 IN CHAR16 CONST *SourceString,\r
2062 IN CHAR16 *NewString,\r
2063 IN UINTN NewSize,\r
2064 IN CONST CHAR16 *FindTarget,\r
2065 IN CONST CHAR16 *ReplaceWith\r
2247dde4 2066 ) \r
2067{\r
0158294b 2068 UINTN Size;\r
975136ab 2069 if ( (SourceString == NULL)\r
2070 || (NewString == NULL)\r
2071 || (FindTarget == NULL)\r
2072 || (ReplaceWith == NULL)\r
2073 || (StrLen(FindTarget) < 1)\r
2074 || (StrLen(SourceString) < 1)\r
2075 ){\r
2076 return (EFI_INVALID_PARAMETER);\r
2077 }\r
2247dde4 2078 NewString = SetMem16(NewString, NewSize, CHAR_NULL);\r
2079 while (*SourceString != CHAR_NULL) {\r
975136ab 2080 if (StrnCmp(SourceString, FindTarget, StrLen(FindTarget)) == 0) {\r
2081 SourceString += StrLen(FindTarget);\r
0158294b 2082 Size = StrSize(NewString);\r
2083 if ((Size + (StrLen(ReplaceWith)*sizeof(CHAR16))) > NewSize) {\r
975136ab 2084 return (EFI_BUFFER_TOO_SMALL);\r
2085 }\r
2086 StrCat(NewString, ReplaceWith);\r
2087 } else {\r
0158294b 2088 Size = StrSize(NewString);\r
2089 if (Size + sizeof(CHAR16) > NewSize) {\r
975136ab 2090 return (EFI_BUFFER_TOO_SMALL);\r
2091 }\r
2092 StrnCat(NewString, SourceString, 1);\r
2093 SourceString++;\r
2094 }\r
2095 }\r
2096 return (EFI_SUCCESS);\r
2097}\r
b1f95a06 2098\r
2099/**\r
2100 Print at a specific location on the screen.\r
2101\r
f1b87e7a 2102 This function will move the cursor to a given screen location and print the specified string\r
b1f95a06 2103 \r
2104 If -1 is specified for either the Row or Col the current screen location for BOTH \r
f1b87e7a 2105 will be used.\r
b1f95a06 2106\r
2107 if either Row or Col is out of range for the current console, then ASSERT\r
2108 if Format is NULL, then ASSERT\r
2109\r
2110 In addition to the standard %-based flags as supported by UefiLib Print() this supports \r
2111 the following additional flags:\r
2112 %N - Set output attribute to normal\r
2113 %H - Set output attribute to highlight\r
2114 %E - Set output attribute to error\r
2115 %B - Set output attribute to blue color\r
2116 %V - Set output attribute to green color\r
2117\r
2118 Note: The background color is controlled by the shell command cls.\r
2119\r
2120 @param[in] Row the row to print at\r
2121 @param[in] Col the column to print at\r
2122 @param[in] Format the format string\r
2247dde4 2123 @param[in] Marker the marker for the variable argument list\r
b1f95a06 2124\r
2125 @return the number of characters printed to the screen\r
2126**/\r
2127\r
2128UINTN\r
2129EFIAPI\r
2247dde4 2130InternalShellPrintWorker(\r
b1f95a06 2131 IN INT32 Col OPTIONAL,\r
2132 IN INT32 Row OPTIONAL,\r
2133 IN CONST CHAR16 *Format,\r
2247dde4 2134 VA_LIST Marker\r
2135 ) \r
2136{\r
b1f95a06 2137 UINTN BufferSize;\r
975136ab 2138 CHAR16 *PostReplaceFormat;\r
2139 CHAR16 *PostReplaceFormat2;\r
b1f95a06 2140 UINTN Return;\r
b1f95a06 2141 EFI_STATUS Status;\r
975136ab 2142 UINTN NormalAttribute;\r
2143 CHAR16 *ResumeLocation;\r
2144 CHAR16 *FormatWalker;\r
b1f95a06 2145 \r
2146 BufferSize = (PcdGet32 (PcdUefiLibMaxPrintBufferSize) + 1) * sizeof (CHAR16);\r
975136ab 2147 PostReplaceFormat = AllocateZeroPool (BufferSize);\r
2148 ASSERT (PostReplaceFormat != NULL);\r
2149 PostReplaceFormat2 = AllocateZeroPool (BufferSize);\r
2150 ASSERT (PostReplaceFormat2 != NULL);\r
b1f95a06 2151\r
975136ab 2152 //\r
2153 // Back and forth each time fixing up 1 of our flags...\r
2154 //\r
2155 Status = CopyReplace(Format, PostReplaceFormat, BufferSize, L"%N", L"%%N");\r
2156 ASSERT_EFI_ERROR(Status);\r
2157 Status = CopyReplace(PostReplaceFormat, PostReplaceFormat2, BufferSize, L"%E", L"%%E");\r
2158 ASSERT_EFI_ERROR(Status);\r
2159 Status = CopyReplace(PostReplaceFormat2, PostReplaceFormat, BufferSize, L"%H", L"%%H");\r
2160 ASSERT_EFI_ERROR(Status);\r
2161 Status = CopyReplace(PostReplaceFormat, PostReplaceFormat2, BufferSize, L"%B", L"%%B");\r
2162 ASSERT_EFI_ERROR(Status);\r
2163 Status = CopyReplace(PostReplaceFormat2, PostReplaceFormat, BufferSize, L"%V", L"%%V");\r
2164 ASSERT_EFI_ERROR(Status);\r
2165\r
2166 //\r
2167 // Use the last buffer from replacing to print from...\r
2168 //\r
2169 Return = UnicodeVSPrint (PostReplaceFormat2, BufferSize, PostReplaceFormat, Marker);\r
2170\r
2171 FreePool(PostReplaceFormat);\r
b1f95a06 2172\r
2173 if (Col != -1 && Row != -1) {\r
b1f95a06 2174 Status = gST->ConOut->SetCursorPosition(gST->ConOut, Col, Row);\r
2175 ASSERT_EFI_ERROR(Status);\r
975136ab 2176 }\r
2177\r
2178 NormalAttribute = gST->ConOut->Mode->Attribute;\r
2179 FormatWalker = PostReplaceFormat2;\r
2247dde4 2180 while (*FormatWalker != CHAR_NULL) {\r
975136ab 2181 //\r
2182 // Find the next attribute change request\r
2183 //\r
2184 ResumeLocation = StrStr(FormatWalker, L"%");\r
2185 if (ResumeLocation != NULL) {\r
2247dde4 2186 *ResumeLocation = CHAR_NULL;\r
975136ab 2187 }\r
2188 //\r
2189 // print the current FormatWalker string\r
2190 //\r
2191 Status = gST->ConOut->OutputString(gST->ConOut, FormatWalker);\r
b1f95a06 2192 ASSERT_EFI_ERROR(Status);\r
975136ab 2193 //\r
2194 // update the attribute\r
2195 //\r
2196 if (ResumeLocation != NULL) {\r
2197 switch (*(ResumeLocation+1)) {\r
2198 case (L'N'):\r
2199 gST->ConOut->SetAttribute(gST->ConOut, NormalAttribute);\r
2200 break;\r
2201 case (L'E'):\r
2202 gST->ConOut->SetAttribute(gST->ConOut, EFI_TEXT_ATTR(EFI_YELLOW, ((NormalAttribute&(BIT4|BIT5|BIT6))>>4)));\r
2203 break;\r
2204 case (L'H'):\r
2205 gST->ConOut->SetAttribute(gST->ConOut, EFI_TEXT_ATTR(EFI_WHITE, ((NormalAttribute&(BIT4|BIT5|BIT6))>>4)));\r
2206 break;\r
2207 case (L'B'):\r
2208 gST->ConOut->SetAttribute(gST->ConOut, EFI_TEXT_ATTR(EFI_BLUE, ((NormalAttribute&(BIT4|BIT5|BIT6))>>4)));\r
2209 break;\r
2210 case (L'V'):\r
2211 gST->ConOut->SetAttribute(gST->ConOut, EFI_TEXT_ATTR(EFI_GREEN, ((NormalAttribute&(BIT4|BIT5|BIT6))>>4)));\r
2212 break;\r
2213 default:\r
2214 ASSERT(FALSE);\r
2215 break;\r
2216 }\r
2217 } else {\r
2218 //\r
2219 // reset to normal now...\r
2220 //\r
2221 gST->ConOut->SetAttribute(gST->ConOut, NormalAttribute);\r
2222 break;\r
2223 }\r
2224\r
2225 //\r
2226 // update FormatWalker to Resume + 2 (skip the % and the indicator)\r
2227 //\r
2228 FormatWalker = ResumeLocation + 2;\r
2229 }\r
b1f95a06 2230\r
975136ab 2231 FreePool(PostReplaceFormat2);\r
2232\r
b1f95a06 2233 return (Return);\r
5f7431d0 2234}\r
2247dde4 2235\r
2236/**\r
2237 Print at a specific location on the screen.\r
2238\r
2239 This function will move the cursor to a given screen location and print the specified string\r
2240 \r
2241 If -1 is specified for either the Row or Col the current screen location for BOTH \r
2242 will be used.\r
2243\r
2244 if either Row or Col is out of range for the current console, then ASSERT\r
2245 if Format is NULL, then ASSERT\r
2246\r
2247 In addition to the standard %-based flags as supported by UefiLib Print() this supports \r
2248 the following additional flags:\r
2249 %N - Set output attribute to normal\r
2250 %H - Set output attribute to highlight\r
2251 %E - Set output attribute to error\r
2252 %B - Set output attribute to blue color\r
2253 %V - Set output attribute to green color\r
2254\r
2255 Note: The background color is controlled by the shell command cls.\r
2256\r
2257 @param[in] Row the row to print at\r
2258 @param[in] Col the column to print at\r
2259 @param[in] Format the format string\r
2260\r
2261 @return the number of characters printed to the screen\r
2262**/\r
2263\r
2264UINTN\r
2265EFIAPI\r
2266ShellPrintEx(\r
2267 IN INT32 Col OPTIONAL,\r
2268 IN INT32 Row OPTIONAL,\r
2269 IN CONST CHAR16 *Format,\r
2270 ...\r
2271 ) \r
2272{\r
2273 VA_LIST Marker;\r
2274 VA_START (Marker, Format);\r
2275 return (InternalShellPrintWorker(Col, Row, Format, Marker));\r
2276}\r
2277\r
2278/**\r
2279 Print at a specific location on the screen.\r
2280\r
2281 This function will move the cursor to a given screen location, print the specified string, \r
2282 and return the cursor to the original locaiton. \r
2283 \r
2284 If -1 is specified for either the Row or Col the current screen location for BOTH \r
2285 will be used and the cursor's position will not be moved back to an original location.\r
2286\r
2287 if either Row or Col is out of range for the current console, then ASSERT\r
2288 if Format is NULL, then ASSERT\r
2289\r
2290 In addition to the standard %-based flags as supported by UefiLib Print() this supports \r
2291 the following additional flags:\r
2292 %N - Set output attribute to normal\r
2293 %H - Set output attribute to highlight\r
2294 %E - Set output attribute to error\r
2295 %B - Set output attribute to blue color\r
2296 %V - Set output attribute to green color\r
2297\r
2298 Note: The background color is controlled by the shell command cls.\r
2299\r
2300 @param[in] Row the row to print at\r
2301 @param[in] Col the column to print at\r
2302 @param[in] HiiFormatStringId the format string Id for getting from Hii\r
2303 @param[in] HiiFormatHandle the format string Handle for getting from Hii\r
2304\r
2305 @return the number of characters printed to the screen\r
2306**/\r
2307UINTN\r
2308EFIAPI\r
2309ShellPrintHiiEx(\r
2310 IN INT32 Col OPTIONAL,\r
2311 IN INT32 Row OPTIONAL,\r
2312 IN CONST EFI_STRING_ID HiiFormatStringId,\r
2313 IN CONST EFI_HANDLE HiiFormatHandle,\r
2314 ...\r
2315 )\r
2316{\r
2317 VA_LIST Marker;\r
2318 CHAR16 *HiiFormatString;\r
2319 UINTN RetVal;\r
2320\r
2321 VA_START (Marker, HiiFormatHandle);\r
2322 HiiFormatString = HiiGetString(HiiFormatHandle, HiiFormatStringId, NULL);\r
2323 ASSERT(HiiFormatString != NULL);\r
2324\r
2325 RetVal = InternalShellPrintWorker(Col, Row, HiiFormatString, Marker);\r
2326\r
2327 FreePool(HiiFormatString);\r
2328\r
2329 return (RetVal);\r
2330}\r
2331\r
2332/**\r
2333 Function to determine if a given filename represents a file or a directory.\r
2334\r
2335 @param[in] DirName Path to directory to test.\r
2336\r
2337 @retval EFI_SUCCESS The Path represents a directory\r
2338 @retval EFI_NOT_FOUND The Path does not represent a directory\r
2339 @return other The path failed to open\r
2340**/\r
2341EFI_STATUS\r
2342EFIAPI\r
2343ShellIsDirectory(\r
2344 IN CONST CHAR16 *DirName\r
2345 )\r
2346{\r
2347 EFI_STATUS Status;\r
2348 EFI_FILE_HANDLE Handle;\r
2349\r
2350 Handle = NULL;\r
2351\r
2352 Status = ShellOpenFileByName(DirName, &Handle, EFI_FILE_MODE_READ, 0);\r
2353 if (EFI_ERROR(Status)) {\r
2354 return (Status);\r
2355 }\r
2356\r
2357 if (FileHandleIsDirectory(Handle) == EFI_SUCCESS) {\r
2358 ShellCloseFile(&Handle);\r
2359 return (EFI_SUCCESS);\r
2360 }\r
2361 ShellCloseFile(&Handle);\r
2362 return (EFI_NOT_FOUND);\r
2363}\r
2364\r