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