TianoCore EDK2 master
Loading...
Searching...
No Matches
UefiShellLib.c
Go to the documentation of this file.
1
12#include "UefiShellLib.h"
13#include <Library/SortLib.h>
14#include <Library/BaseLib.h>
15
16//
17// globals...
18//
20 { NULL, TypeMax }
21};
23 { L"-sfo", TypeFlag },
24 { NULL, TypeMax }
25};
26EFI_SHELL_ENVIRONMENT2 *mEfiShellEnvironment2;
27EFI_SHELL_INTERFACE *mEfiShellInterface;
28EFI_SHELL_PROTOCOL *gEfiShellProtocol;
29EFI_SHELL_PARAMETERS_PROTOCOL *gEfiShellParametersProtocol;
30EFI_HANDLE mEfiShellEnvironment2Handle;
31FILE_HANDLE_FUNCTION_MAP FileFunctionMap;
32EFI_UNICODE_COLLATION_PROTOCOL *mUnicodeCollationProtocol;
33
62CHAR16 *
63EFIAPI
65 IN CONST CHAR16 *Path
66 )
67{
68 CONST CHAR16 *WorkingPath;
69 CONST CHAR16 *InputPath;
70 CHAR16 *CharPtr;
71 CHAR16 *InputFileSystem;
72 UINTN FileSystemCharCount;
73 CHAR16 *FullyQualifiedPath;
74 UINTN Size;
75
76 FullyQualifiedPath = NULL;
77
78 ASSERT (Path != NULL);
79 //
80 // Handle erroneous input when asserts are disabled.
81 //
82 if (Path == NULL) {
83 return NULL;
84 }
85
86 //
87 // In paths that contain ":", like fs0:dir/file.ext and fs2:\fqpath\file.ext,
88 // we have to consider the file system part separately from the "path" part.
89 // If there is a file system in the path, we have to get the current working
90 // directory for that file system. Then we need to use the part of the path
91 // following the ":". If a path does not contain ":", we use it as given.
92 //
93 InputPath = StrStr (Path, L":");
94 if (InputPath != NULL) {
95 InputPath++;
96 FileSystemCharCount = ((UINTN)InputPath - (UINTN)Path + sizeof (CHAR16)) / sizeof (CHAR16);
97 InputFileSystem = AllocateCopyPool (FileSystemCharCount * sizeof (CHAR16), Path);
98 if (InputFileSystem != NULL) {
99 InputFileSystem[FileSystemCharCount - 1] = CHAR_NULL;
100 }
101
102 WorkingPath = ShellGetCurrentDir (InputFileSystem);
103 SHELL_FREE_NON_NULL (InputFileSystem);
104 } else {
105 InputPath = Path;
106 WorkingPath = ShellGetEnvironmentVariable (L"cwd");
107 }
108
109 if (WorkingPath == NULL) {
110 //
111 // With no working directory, all we can do is copy and clean the input path.
112 //
113 FullyQualifiedPath = AllocateCopyPool (StrSize (Path), Path);
114 } else {
115 //
116 // Allocate space for both strings plus one more character.
117 //
118 Size = StrSize (WorkingPath) + StrSize (InputPath);
119 FullyQualifiedPath = AllocateZeroPool (Size);
120 if (FullyQualifiedPath == NULL) {
121 //
122 // Try to copy and clean just the input. No harm if not enough memory.
123 //
124 FullyQualifiedPath = AllocateCopyPool (StrSize (Path), Path);
125 } else {
126 if ((*InputPath == L'\\') || (*InputPath == L'/')) {
127 //
128 // Absolute path: start with the current working directory, then
129 // truncate the new path after the file system part.
130 //
131 StrCpyS (FullyQualifiedPath, Size/sizeof (CHAR16), WorkingPath);
132 CharPtr = StrStr (FullyQualifiedPath, L":");
133 if (CharPtr != NULL) {
134 *(CharPtr + 1) = CHAR_NULL;
135 }
136 } else {
137 //
138 // Relative path: start with the working directory and append "\".
139 //
140 StrCpyS (FullyQualifiedPath, Size/sizeof (CHAR16), WorkingPath);
141 StrCatS (FullyQualifiedPath, Size/sizeof (CHAR16), L"\\");
142 }
143
144 //
145 // Now append the absolute or relative path.
146 //
147 StrCatS (FullyQualifiedPath, Size/sizeof (CHAR16), InputPath);
148 }
149 }
150
151 PathCleanUpDirectories (FullyQualifiedPath);
152
153 return FullyQualifiedPath;
154}
155
169BOOLEAN
170EFIAPI
172 IN CHAR16 Char
173 )
174{
175 return (BOOLEAN)((Char >= L'0' && Char <= L'9') || (Char >= L'A' && Char <= L'F') || (Char >= L'a' && Char <= L'f'));
176}
177
192BOOLEAN
193EFIAPI
195 IN CHAR16 Char
196 )
197{
198 return (BOOLEAN)(Char >= L'0' && Char <= L'9');
199}
200
210 IN EFI_HANDLE ImageHandle
211 )
212{
213 EFI_STATUS Status;
214 EFI_HANDLE *Buffer;
215 UINTN BufferSize;
216 UINTN HandleIndex;
217
218 BufferSize = 0;
219 Buffer = NULL;
220 Status = gBS->OpenProtocol (
221 ImageHandle,
222 &gEfiShellEnvironment2Guid,
223 (VOID **)&mEfiShellEnvironment2,
224 ImageHandle,
225 NULL,
226 EFI_OPEN_PROTOCOL_GET_PROTOCOL
227 );
228 //
229 // look for the mEfiShellEnvironment2 protocol at a higher level
230 //
231 if (EFI_ERROR (Status) || !(CompareGuid (&mEfiShellEnvironment2->SESGuid, &gEfiShellEnvironment2ExtGuid))) {
232 //
233 // figure out how big of a buffer we need.
234 //
235 Status = gBS->LocateHandle (
237 &gEfiShellEnvironment2Guid,
238 NULL, // ignored for ByProtocol
239 &BufferSize,
240 Buffer
241 );
242 //
243 // maybe it's not there???
244 //
245 if (Status == EFI_BUFFER_TOO_SMALL) {
246 Buffer = (EFI_HANDLE *)AllocateZeroPool (BufferSize);
247 if (Buffer == NULL) {
248 return (EFI_OUT_OF_RESOURCES);
249 }
250
251 Status = gBS->LocateHandle (
253 &gEfiShellEnvironment2Guid,
254 NULL, // ignored for ByProtocol
255 &BufferSize,
256 Buffer
257 );
258 }
259
260 if (!EFI_ERROR (Status) && (Buffer != NULL)) {
261 //
262 // now parse the list of returned handles
263 //
264 Status = EFI_NOT_FOUND;
265 for (HandleIndex = 0; HandleIndex < (BufferSize/sizeof (Buffer[0])); HandleIndex++) {
266 Status = gBS->OpenProtocol (
267 Buffer[HandleIndex],
268 &gEfiShellEnvironment2Guid,
269 (VOID **)&mEfiShellEnvironment2,
270 ImageHandle,
271 NULL,
272 EFI_OPEN_PROTOCOL_GET_PROTOCOL
273 );
274 if (CompareGuid (&mEfiShellEnvironment2->SESGuid, &gEfiShellEnvironment2ExtGuid)) {
275 mEfiShellEnvironment2Handle = Buffer[HandleIndex];
276 Status = EFI_SUCCESS;
277 break;
278 }
279 }
280 }
281 }
282
283 if (Buffer != NULL) {
284 FreePool (Buffer);
285 }
286
287 return (Status);
288}
289
301 IN EFI_HANDLE ImageHandle,
302 IN EFI_SYSTEM_TABLE *SystemTable
303 )
304{
305 EFI_STATUS Status;
306
307 if (gEfiShellProtocol == NULL) {
308 //
309 // UEFI 2.0 shell interfaces (used preferentially)
310 //
311 Status = gBS->OpenProtocol (
312 ImageHandle,
313 &gEfiShellProtocolGuid,
314 (VOID **)&gEfiShellProtocol,
315 ImageHandle,
316 NULL,
317 EFI_OPEN_PROTOCOL_GET_PROTOCOL
318 );
319 if (EFI_ERROR (Status)) {
320 //
321 // Search for the shell protocol
322 //
323 Status = gBS->LocateProtocol (
324 &gEfiShellProtocolGuid,
325 NULL,
326 (VOID **)&gEfiShellProtocol
327 );
328 if (EFI_ERROR (Status)) {
329 gEfiShellProtocol = NULL;
330 }
331 }
332 }
333
334 if (gEfiShellParametersProtocol == NULL) {
335 Status = gBS->OpenProtocol (
336 ImageHandle,
337 &gEfiShellParametersProtocolGuid,
338 (VOID **)&gEfiShellParametersProtocol,
339 ImageHandle,
340 NULL,
341 EFI_OPEN_PROTOCOL_GET_PROTOCOL
342 );
343 if (EFI_ERROR (Status)) {
344 gEfiShellParametersProtocol = NULL;
345 }
346 }
347
348 if (gEfiShellProtocol == NULL) {
349 //
350 // Moved to seperate function due to complexity
351 //
352 Status = ShellFindSE2 (ImageHandle);
353
354 if (EFI_ERROR (Status)) {
355 DEBUG ((DEBUG_ERROR, "Status: 0x%08x\r\n", Status));
356 mEfiShellEnvironment2 = NULL;
357 }
358
359 Status = gBS->OpenProtocol (
360 ImageHandle,
361 &gEfiShellInterfaceGuid,
362 (VOID **)&mEfiShellInterface,
363 ImageHandle,
364 NULL,
365 EFI_OPEN_PROTOCOL_GET_PROTOCOL
366 );
367 if (EFI_ERROR (Status)) {
368 mEfiShellInterface = NULL;
369 }
370 }
371
372 //
373 // Getting either EDK Shell's ShellEnvironment2 and ShellInterface protocol
374 // or UEFI Shell's Shell protocol.
375 // When ShellLib is linked to a driver producing DynamicCommand protocol,
376 // ShellParameters protocol is set by DynamicCommand.Handler().
377 //
378 if (((mEfiShellEnvironment2 != NULL) && (mEfiShellInterface != NULL)) ||
379 (gEfiShellProtocol != NULL)
380 )
381 {
382 if (gEfiShellProtocol != NULL) {
383 FileFunctionMap.GetFileInfo = gEfiShellProtocol->GetFileInfo;
384 FileFunctionMap.SetFileInfo = gEfiShellProtocol->SetFileInfo;
385 FileFunctionMap.ReadFile = gEfiShellProtocol->ReadFile;
386 FileFunctionMap.WriteFile = gEfiShellProtocol->WriteFile;
387 FileFunctionMap.CloseFile = gEfiShellProtocol->CloseFile;
388 FileFunctionMap.DeleteFile = gEfiShellProtocol->DeleteFile;
389 FileFunctionMap.GetFilePosition = gEfiShellProtocol->GetFilePosition;
390 FileFunctionMap.SetFilePosition = gEfiShellProtocol->SetFilePosition;
391 FileFunctionMap.FlushFile = gEfiShellProtocol->FlushFile;
392 FileFunctionMap.GetFileSize = gEfiShellProtocol->GetFileSize;
393 } else {
394 FileFunctionMap.GetFileInfo = (EFI_SHELL_GET_FILE_INFO)FileHandleGetInfo;
395 FileFunctionMap.SetFileInfo = (EFI_SHELL_SET_FILE_INFO)FileHandleSetInfo;
396 FileFunctionMap.ReadFile = (EFI_SHELL_READ_FILE)FileHandleRead;
397 FileFunctionMap.WriteFile = (EFI_SHELL_WRITE_FILE)FileHandleWrite;
398 FileFunctionMap.CloseFile = (EFI_SHELL_CLOSE_FILE)FileHandleClose;
399 FileFunctionMap.DeleteFile = (EFI_SHELL_DELETE_FILE)FileHandleDelete;
400 FileFunctionMap.GetFilePosition = (EFI_SHELL_GET_FILE_POSITION)FileHandleGetPosition;
401 FileFunctionMap.SetFilePosition = (EFI_SHELL_SET_FILE_POSITION)FileHandleSetPosition;
402 FileFunctionMap.FlushFile = (EFI_SHELL_FLUSH_FILE)FileHandleFlush;
403 FileFunctionMap.GetFileSize = (EFI_SHELL_GET_FILE_SIZE)FileHandleGetSize;
404 }
405
406 return (EFI_SUCCESS);
407 }
408
409 return (EFI_NOT_FOUND);
410}
411
424EFIAPI
426 IN EFI_HANDLE ImageHandle,
427 IN EFI_SYSTEM_TABLE *SystemTable
428 )
429{
430 mEfiShellEnvironment2 = NULL;
431 gEfiShellProtocol = NULL;
432 gEfiShellParametersProtocol = NULL;
433 mEfiShellInterface = NULL;
434 mEfiShellEnvironment2Handle = NULL;
435 mUnicodeCollationProtocol = NULL;
436
437 //
438 // verify that auto initialize is not set false
439 //
440 if (PcdGetBool (PcdShellLibAutoInitialize) == 0) {
441 return (EFI_SUCCESS);
442 }
443
444 return (ShellLibConstructorWorker (ImageHandle, SystemTable));
445}
446
457EFIAPI
459 IN EFI_HANDLE ImageHandle,
460 IN EFI_SYSTEM_TABLE *SystemTable
461 )
462{
463 EFI_STATUS Status;
464
465 if (mEfiShellEnvironment2 != NULL) {
466 Status = gBS->CloseProtocol (
467 mEfiShellEnvironment2Handle == NULL ? ImageHandle : mEfiShellEnvironment2Handle,
468 &gEfiShellEnvironment2Guid,
469 ImageHandle,
470 NULL
471 );
472 if (!EFI_ERROR (Status)) {
473 mEfiShellEnvironment2 = NULL;
474 mEfiShellEnvironment2Handle = NULL;
475 }
476 }
477
478 if (mEfiShellInterface != NULL) {
479 Status = gBS->CloseProtocol (
480 ImageHandle,
481 &gEfiShellInterfaceGuid,
482 ImageHandle,
483 NULL
484 );
485 if (!EFI_ERROR (Status)) {
486 mEfiShellInterface = NULL;
487 }
488 }
489
490 if (gEfiShellProtocol != NULL) {
491 Status = gBS->CloseProtocol (
492 ImageHandle,
493 &gEfiShellProtocolGuid,
494 ImageHandle,
495 NULL
496 );
497 if (!EFI_ERROR (Status)) {
498 gEfiShellProtocol = NULL;
499 }
500 }
501
502 if (gEfiShellParametersProtocol != NULL) {
503 Status = gBS->CloseProtocol (
504 ImageHandle,
505 &gEfiShellParametersProtocolGuid,
506 ImageHandle,
507 NULL
508 );
509 if (!EFI_ERROR (Status)) {
510 gEfiShellParametersProtocol = NULL;
511 }
512 }
513
514 return (EFI_SUCCESS);
515}
516
531EFIAPI
533 VOID
534 )
535{
536 EFI_STATUS Status;
537
538 //
539 // if auto initialize is not false then skip
540 //
541 if (PcdGetBool (PcdShellLibAutoInitialize) != 0) {
542 return (EFI_SUCCESS);
543 }
544
545 //
546 // deinit the current stuff
547 //
549 ASSERT_EFI_ERROR (Status);
550
551 //
552 // init the new stuff
553 //
555}
556
572EFIAPI
574 IN SHELL_FILE_HANDLE FileHandle
575 )
576{
577 return (FileFunctionMap.GetFileInfo (FileHandle));
578}
579
600EFIAPI
602 IN SHELL_FILE_HANDLE FileHandle,
604 )
605{
606 return (FileFunctionMap.SetFileInfo (FileHandle, FileInfo));
607}
608
639EFIAPI
642 OUT SHELL_FILE_HANDLE *FileHandle,
643 IN UINT64 OpenMode,
644 IN UINT64 Attributes
645 )
646{
647 CHAR16 *FileName;
648 EFI_STATUS Status;
649 EFI_FILE_PROTOCOL *File;
650
651 if ((FilePath == NULL) || (FileHandle == NULL)) {
652 return (EFI_INVALID_PARAMETER);
653 }
654
655 //
656 // which shell interface should we use
657 //
658 if (gEfiShellProtocol != NULL) {
659 //
660 // use UEFI Shell 2.0 method.
661 //
662 FileName = gEfiShellProtocol->GetFilePathFromDevicePath (*FilePath);
663 if (FileName == NULL) {
664 return (EFI_INVALID_PARAMETER);
665 }
666
667 Status = ShellOpenFileByName (FileName, FileHandle, OpenMode, Attributes);
668 FreePool (FileName);
669 return (Status);
670 }
671
672 //
673 // use old shell method.
674 //
675 Status = EfiOpenFileByDevicePath (FilePath, &File, OpenMode, Attributes);
676 if (EFI_ERROR (Status)) {
677 return Status;
678 }
679
680 //
681 // This is a weak spot since if the undefined SHELL_FILE_HANDLE format changes this must change also!
682 //
683 *FileHandle = (VOID *)File;
684 return (EFI_SUCCESS);
685}
686
719EFIAPI
721 IN CONST CHAR16 *FileName,
722 OUT SHELL_FILE_HANDLE *FileHandle,
723 IN UINT64 OpenMode,
724 IN UINT64 Attributes
725 )
726{
727 EFI_DEVICE_PATH_PROTOCOL *FilePath;
728 EFI_STATUS Status;
730 CHAR16 *FileNameCopy;
731 EFI_STATUS Status2;
732
733 //
734 // ASSERT if FileName is NULL
735 //
736 ASSERT (FileName != NULL);
737
738 if (FileName == NULL) {
739 return (EFI_INVALID_PARAMETER);
740 }
741
742 if (gEfiShellProtocol != NULL) {
743 if ((OpenMode & EFI_FILE_MODE_CREATE) == EFI_FILE_MODE_CREATE) {
744 //
745 // Create only a directory
746 //
747 if ((Attributes & EFI_FILE_DIRECTORY) == EFI_FILE_DIRECTORY) {
748 return ShellCreateDirectory (FileName, FileHandle);
749 }
750
751 //
752 // Create the directory to create the file in
753 //
754 FileNameCopy = AllocateCopyPool (StrSize (FileName), FileName);
755 if (FileNameCopy == NULL) {
756 return (EFI_OUT_OF_RESOURCES);
757 }
758
759 PathCleanUpDirectories (FileNameCopy);
760 if (PathRemoveLastItem (FileNameCopy)) {
761 if (!EFI_ERROR (ShellCreateDirectory (FileNameCopy, FileHandle))) {
762 ShellCloseFile (FileHandle);
763 }
764 }
765
766 SHELL_FREE_NON_NULL (FileNameCopy);
767 }
768
769 //
770 // Use UEFI Shell 2.0 method to create the file
771 //
772 Status = gEfiShellProtocol->OpenFileByName (
773 FileName,
774 FileHandle,
775 OpenMode
776 );
777 if (EFI_ERROR (Status)) {
778 return Status;
779 }
780
781 if (mUnicodeCollationProtocol == NULL) {
782 Status = gBS->LocateProtocol (&gEfiUnicodeCollation2ProtocolGuid, NULL, (VOID **)&mUnicodeCollationProtocol);
783 if (EFI_ERROR (Status)) {
784 gEfiShellProtocol->CloseFile (*FileHandle);
785 return Status;
786 }
787 }
788
789 if ((mUnicodeCollationProtocol->StriColl (mUnicodeCollationProtocol, (CHAR16 *)FileName, L"NUL") != 0) &&
790 (mUnicodeCollationProtocol->StriColl (mUnicodeCollationProtocol, (CHAR16 *)FileName, L"NULL") != 0) &&
791 !EFI_ERROR (Status) && ((OpenMode & EFI_FILE_MODE_CREATE) != 0))
792 {
793 FileInfo = FileFunctionMap.GetFileInfo (*FileHandle);
794 ASSERT (FileInfo != NULL);
795 FileInfo->Attribute = Attributes;
796 Status2 = FileFunctionMap.SetFileInfo (*FileHandle, FileInfo);
798 if (EFI_ERROR (Status2)) {
799 gEfiShellProtocol->CloseFile (*FileHandle);
800 }
801
802 Status = Status2;
803 }
804
805 return (Status);
806 }
807
808 //
809 // Using EFI Shell version
810 // this means convert name to path and call that function
811 // since this will use EFI method again that will open it.
812 //
813 ASSERT (mEfiShellEnvironment2 != NULL);
814 FilePath = mEfiShellEnvironment2->NameToPath ((CHAR16 *)FileName);
815 if (FilePath != NULL) {
817 &FilePath,
818 FileHandle,
819 OpenMode,
820 Attributes
821 ));
822 }
823
824 return (EFI_DEVICE_ERROR);
825}
826
856EFIAPI
858 IN CONST CHAR16 *DirectoryName,
859 OUT SHELL_FILE_HANDLE *FileHandle
860 )
861{
862 if (gEfiShellProtocol != NULL) {
863 //
864 // Use UEFI Shell 2.0 method
865 //
866 return (gEfiShellProtocol->CreateFile (
867 DirectoryName,
868 EFI_FILE_DIRECTORY,
869 FileHandle
870 ));
871 } else {
872 return (ShellOpenFileByName (
873 DirectoryName,
874 FileHandle,
875 EFI_FILE_MODE_READ | EFI_FILE_MODE_WRITE | EFI_FILE_MODE_CREATE,
876 EFI_FILE_DIRECTORY
877 ));
878 }
879}
880
911EFIAPI
913 IN SHELL_FILE_HANDLE FileHandle,
914 IN OUT UINTN *BufferSize,
915 OUT VOID *Buffer
916 )
917{
918 return (FileFunctionMap.ReadFile (FileHandle, BufferSize, Buffer));
919}
920
946EFIAPI
948 IN SHELL_FILE_HANDLE FileHandle,
949 IN OUT UINTN *BufferSize,
950 IN VOID *Buffer
951 )
952{
953 return (FileFunctionMap.WriteFile (FileHandle, BufferSize, Buffer));
954}
955
968EFIAPI
970 IN SHELL_FILE_HANDLE *FileHandle
971 )
972{
973 return (FileFunctionMap.CloseFile (*FileHandle));
974}
975
991EFIAPI
993 IN SHELL_FILE_HANDLE *FileHandle
994 )
995{
996 return (FileFunctionMap.DeleteFile (*FileHandle));
997}
998
1019EFIAPI
1021 IN SHELL_FILE_HANDLE FileHandle,
1022 IN UINT64 Position
1023 )
1024{
1025 return (FileFunctionMap.SetFilePosition (FileHandle, Position));
1026}
1027
1044EFIAPI
1046 IN SHELL_FILE_HANDLE FileHandle,
1047 OUT UINT64 *Position
1048 )
1049{
1050 return (FileFunctionMap.GetFilePosition (FileHandle, Position));
1051}
1052
1068EFIAPI
1070 IN SHELL_FILE_HANDLE FileHandle
1071 )
1072{
1073 return (FileFunctionMap.FlushFile (FileHandle));
1074}
1075
1099EFIAPI
1101 IN SHELL_FILE_HANDLE DirHandle,
1102 OUT EFI_FILE_INFO **Buffer
1103 )
1104{
1105 //
1106 // pass to file handle lib
1107 //
1108 return (FileHandleFindFirstFile (DirHandle, Buffer));
1109}
1110
1130EFIAPI
1132 IN SHELL_FILE_HANDLE DirHandle,
1133 OUT EFI_FILE_INFO *Buffer,
1134 OUT BOOLEAN *NoFile
1135 )
1136{
1137 //
1138 // pass to file handle lib
1139 //
1140 return (FileHandleFindNextFile (DirHandle, Buffer, NoFile));
1141}
1142
1159EFIAPI
1161 IN SHELL_FILE_HANDLE FileHandle,
1162 OUT UINT64 *Size
1163 )
1164{
1165 return (FileFunctionMap.GetFileSize (FileHandle, Size));
1166}
1167
1176BOOLEAN
1177EFIAPI
1179 VOID
1180 )
1181{
1182 //
1183 // Check for UEFI Shell 2.0 protocols
1184 //
1185 if (gEfiShellProtocol != NULL) {
1186 //
1187 // We are using UEFI Shell 2.0; see if the event has been triggered
1188 //
1189 if (gBS->CheckEvent (gEfiShellProtocol->ExecutionBreak) != EFI_SUCCESS) {
1190 return (FALSE);
1191 }
1192
1193 return (TRUE);
1194 }
1195
1196 //
1197 // using EFI Shell; call the function to check
1198 //
1199 if (mEfiShellEnvironment2 != NULL) {
1200 return (mEfiShellEnvironment2->GetExecutionBreak ());
1201 }
1202
1203 return (FALSE);
1204}
1205
1217CONST CHAR16 *
1218EFIAPI
1220 IN CONST CHAR16 *EnvKey
1221 )
1222{
1223 //
1224 // Check for UEFI Shell 2.0 protocols
1225 //
1226 if (gEfiShellProtocol != NULL) {
1227 return (gEfiShellProtocol->GetEnv (EnvKey));
1228 }
1229
1230 //
1231 // Check for EFI shell
1232 //
1233 if (mEfiShellEnvironment2 != NULL) {
1234 return (mEfiShellEnvironment2->GetEnv ((CHAR16 *)EnvKey));
1235 }
1236
1237 return NULL;
1238}
1239
1261EFIAPI
1263 IN CONST CHAR16 *EnvKey,
1264 IN CONST CHAR16 *EnvVal,
1265 IN BOOLEAN Volatile
1266 )
1267{
1268 //
1269 // Check for UEFI Shell 2.0 protocols
1270 //
1271 if (gEfiShellProtocol != NULL) {
1272 return (gEfiShellProtocol->SetEnv (EnvKey, EnvVal, Volatile));
1273 }
1274
1275 //
1276 // This feature does not exist under EFI shell
1277 //
1278 return (EFI_UNSUPPORTED);
1279}
1280
1312EFIAPI
1314 IN EFI_HANDLE *ParentHandle,
1315 IN CHAR16 *CommandLine OPTIONAL,
1316 IN BOOLEAN Output OPTIONAL,
1317 IN CHAR16 **EnvironmentVariables OPTIONAL,
1318 OUT EFI_STATUS *Status OPTIONAL
1319 )
1320{
1321 EFI_STATUS CmdStatus;
1322
1323 //
1324 // Check for UEFI Shell 2.0 protocols
1325 //
1326 if (gEfiShellProtocol != NULL) {
1327 //
1328 // Call UEFI Shell 2.0 version (not using Output parameter)
1329 //
1330 return (gEfiShellProtocol->Execute (
1331 ParentHandle,
1332 CommandLine,
1333 EnvironmentVariables,
1334 Status
1335 ));
1336 }
1337
1338 //
1339 // Check for EFI shell
1340 //
1341 if (mEfiShellEnvironment2 != NULL) {
1342 //
1343 // Call EFI Shell version.
1344 //
1345 // Due to an unfixable bug in the EdkShell implementation, we must
1346 // dereference "ParentHandle" here:
1347 //
1348 // 1. The EFI shell installs the EFI_SHELL_ENVIRONMENT2 protocol,
1349 // identified by gEfiShellEnvironment2Guid.
1350 // 2. The Execute() member function takes "ParentImageHandle" as first
1351 // parameter, with type (EFI_HANDLE*).
1352 // 3. In the EdkShell implementation, SEnvExecute() implements the
1353 // Execute() member function. It passes "ParentImageHandle" correctly to
1354 // SEnvDoExecute().
1355 // 4. SEnvDoExecute() takes the (EFI_HANDLE*), and passes it directly --
1356 // without de-referencing -- to the HandleProtocol() boot service.
1357 // 5. But HandleProtocol() takes an EFI_HANDLE.
1358 //
1359 // Therefore we must
1360 // - de-reference "ParentHandle" here, to mask the bug in
1361 // SEnvDoExecute(), and
1362 // - pass the resultant EFI_HANDLE as an (EFI_HANDLE*).
1363 //
1364 CmdStatus = (mEfiShellEnvironment2->Execute (
1365 (EFI_HANDLE *)*ParentHandle,
1366 CommandLine,
1367 Output
1368 ));
1369 //
1370 // No Status output parameter so just use the returned status
1371 //
1372 if (Status != NULL) {
1373 *Status = CmdStatus;
1374 }
1375
1376 //
1377 // If there was an error, we can't tell if it was from the command or from
1378 // the Execute() function, so we'll just assume the shell ran successfully
1379 // and the error came from the command.
1380 //
1381 return EFI_SUCCESS;
1382 }
1383
1384 return (EFI_UNSUPPORTED);
1385}
1386
1401CONST CHAR16 *
1402EFIAPI
1404 IN CHAR16 *CONST DeviceName OPTIONAL
1405 )
1406{
1407 //
1408 // Check for UEFI Shell 2.0 protocols
1409 //
1410 if (gEfiShellProtocol != NULL) {
1411 return (gEfiShellProtocol->GetCurDir (DeviceName));
1412 }
1413
1414 //
1415 // Check for EFI shell
1416 //
1417 if (mEfiShellEnvironment2 != NULL) {
1418 return (mEfiShellEnvironment2->CurDir (DeviceName));
1419 }
1420
1421 return (NULL);
1422}
1423
1432VOID
1433EFIAPI
1435 IN BOOLEAN CurrentState
1436 )
1437{
1438 //
1439 // check for enabling
1440 //
1441 if (CurrentState != 0x00) {
1442 //
1443 // check for UEFI Shell 2.0
1444 //
1445 if (gEfiShellProtocol != NULL) {
1446 //
1447 // Enable with UEFI 2.0 Shell
1448 //
1449 gEfiShellProtocol->EnablePageBreak ();
1450 return;
1451 } else {
1452 //
1453 // Check for EFI shell
1454 //
1455 if (mEfiShellEnvironment2 != NULL) {
1456 //
1457 // Enable with EFI Shell
1458 //
1459 mEfiShellEnvironment2->EnablePageBreak (DEFAULT_INIT_ROW, DEFAULT_AUTO_LF);
1460 return;
1461 }
1462 }
1463 } else {
1464 //
1465 // check for UEFI Shell 2.0
1466 //
1467 if (gEfiShellProtocol != NULL) {
1468 //
1469 // Disable with UEFI 2.0 Shell
1470 //
1471 gEfiShellProtocol->DisablePageBreak ();
1472 return;
1473 } else {
1474 //
1475 // Check for EFI shell
1476 //
1477 if (mEfiShellEnvironment2 != NULL) {
1478 //
1479 // Disable with EFI Shell
1480 //
1481 mEfiShellEnvironment2->DisablePageBreak ();
1482 return;
1483 }
1484 }
1485 }
1486}
1487
1492typedef struct {
1493 LIST_ENTRY Link;
1494 EFI_STATUS Status;
1495 CHAR16 *FullName;
1496 CHAR16 *FileName;
1497 SHELL_FILE_HANDLE Handle;
1498 EFI_FILE_INFO *Info;
1500
1515LIST_ENTRY *
1517 IN LIST_ENTRY *FileList,
1518 IN OUT LIST_ENTRY *ListHead
1519 )
1520{
1521 SHELL_FILE_ARG *OldInfo;
1522 LIST_ENTRY *Link;
1524
1525 //
1526 // ASSERTs
1527 //
1528 ASSERT (FileList != NULL);
1529 ASSERT (ListHead != NULL);
1530
1531 //
1532 // enumerate through each member of the old list and copy
1533 //
1534 for (Link = FileList->ForwardLink; Link != FileList; Link = Link->ForwardLink) {
1535 OldInfo = CR (Link, SHELL_FILE_ARG, Link, SHELL_FILE_ARG_SIGNATURE);
1536 ASSERT (OldInfo != NULL);
1537
1538 //
1539 // Skip ones that failed to open...
1540 //
1541 if (OldInfo->Status != EFI_SUCCESS) {
1542 continue;
1543 }
1544
1545 //
1546 // make sure the old list was valid
1547 //
1548 ASSERT (OldInfo->Info != NULL);
1549 ASSERT (OldInfo->FullName != NULL);
1550 ASSERT (OldInfo->FileName != NULL);
1551
1552 //
1553 // allocate a new EFI_SHELL_FILE_INFO object
1554 //
1555 NewInfo = AllocateZeroPool (sizeof (EFI_SHELL_FILE_INFO));
1556 if (NewInfo == NULL) {
1558 ListHead = NULL;
1559 break;
1560 }
1561
1562 //
1563 // copy the simple items
1564 //
1565 NewInfo->Handle = OldInfo->Handle;
1566 NewInfo->Status = OldInfo->Status;
1567
1568 // old shell checks for 0 not NULL
1569 OldInfo->Handle = 0;
1570
1571 //
1572 // allocate new space to copy strings and structure
1573 //
1574 NewInfo->FullName = AllocateCopyPool (StrSize (OldInfo->FullName), OldInfo->FullName);
1575 NewInfo->FileName = AllocateCopyPool (StrSize (OldInfo->FileName), OldInfo->FileName);
1576 NewInfo->Info = AllocateCopyPool ((UINTN)OldInfo->Info->Size, OldInfo->Info);
1577
1578 //
1579 // make sure all the memory allocations were successful
1580 //
1581 if ((NULL == NewInfo->FullName) || (NewInfo->FileName == NULL) || (NewInfo->Info == NULL)) {
1582 //
1583 // Free the partially allocated new node
1584 //
1585 SHELL_FREE_NON_NULL (NewInfo->FullName);
1586 SHELL_FREE_NON_NULL (NewInfo->FileName);
1587 SHELL_FREE_NON_NULL (NewInfo->Info);
1588 SHELL_FREE_NON_NULL (NewInfo);
1589
1590 //
1591 // Free the previously converted stuff
1592 //
1594 ListHead = NULL;
1595 break;
1596 }
1597
1598 //
1599 // add that to the list
1600 //
1601 InsertTailList (ListHead, &NewInfo->Link);
1602 }
1603
1604 return (ListHead);
1605}
1606
1631EFIAPI
1633 IN CHAR16 *Arg,
1634 IN UINT64 OpenMode,
1635 IN OUT EFI_SHELL_FILE_INFO **ListHead
1636 )
1637{
1638 EFI_STATUS Status;
1639 LIST_ENTRY mOldStyleFileList;
1640 CHAR16 *CleanFilePathStr;
1641
1642 //
1643 // ASSERT that Arg and ListHead are not NULL
1644 //
1645 ASSERT (Arg != NULL);
1646 ASSERT (ListHead != NULL);
1647
1648 CleanFilePathStr = NULL;
1649
1650 Status = InternalShellStripQuotes (Arg, &CleanFilePathStr);
1651 if (EFI_ERROR (Status)) {
1652 return Status;
1653 }
1654
1655 //
1656 // Check for UEFI Shell 2.0 protocols
1657 //
1658 if (gEfiShellProtocol != NULL) {
1659 if (*ListHead == NULL) {
1661 if (*ListHead == NULL) {
1662 FreePool (CleanFilePathStr);
1663 return (EFI_OUT_OF_RESOURCES);
1664 }
1665
1666 InitializeListHead (&((*ListHead)->Link));
1667 }
1668
1669 Status = gEfiShellProtocol->OpenFileList (
1670 CleanFilePathStr,
1671 OpenMode,
1672 ListHead
1673 );
1674 if (EFI_ERROR (Status)) {
1675 gEfiShellProtocol->RemoveDupInFileList (ListHead);
1676 } else {
1677 Status = gEfiShellProtocol->RemoveDupInFileList (ListHead);
1678 }
1679
1680 if ((*ListHead != NULL) && IsListEmpty (&(*ListHead)->Link)) {
1681 FreePool (*ListHead);
1682 FreePool (CleanFilePathStr);
1683 *ListHead = NULL;
1684 return (EFI_NOT_FOUND);
1685 }
1686
1687 FreePool (CleanFilePathStr);
1688 return (Status);
1689 }
1690
1691 //
1692 // Check for EFI shell
1693 //
1694 if (mEfiShellEnvironment2 != NULL) {
1695 //
1696 // make sure the list head is initialized
1697 //
1698 InitializeListHead (&mOldStyleFileList);
1699
1700 //
1701 // Get the EFI Shell list of files
1702 //
1703 Status = mEfiShellEnvironment2->FileMetaArg (CleanFilePathStr, &mOldStyleFileList);
1704 if (EFI_ERROR (Status)) {
1705 *ListHead = NULL;
1706 FreePool (CleanFilePathStr);
1707 return (Status);
1708 }
1709
1710 if (*ListHead == NULL) {
1712 if (*ListHead == NULL) {
1713 FreePool (CleanFilePathStr);
1714 return (EFI_OUT_OF_RESOURCES);
1715 }
1716
1717 InitializeListHead (&((*ListHead)->Link));
1718 }
1719
1720 //
1721 // Convert that to equivalent of UEFI Shell 2.0 structure
1722 //
1723 InternalShellConvertFileListType (&mOldStyleFileList, &(*ListHead)->Link);
1724
1725 //
1726 // Free the EFI Shell version that was converted.
1727 //
1728 mEfiShellEnvironment2->FreeFileList (&mOldStyleFileList);
1729
1730 if (((*ListHead)->Link.ForwardLink == (*ListHead)->Link.BackLink) && ((*ListHead)->Link.BackLink == &((*ListHead)->Link))) {
1731 FreePool (*ListHead);
1732 *ListHead = NULL;
1733 Status = EFI_NOT_FOUND;
1734 }
1735
1736 FreePool (CleanFilePathStr);
1737 return (Status);
1738 }
1739
1740 FreePool (CleanFilePathStr);
1741 return (EFI_UNSUPPORTED);
1742}
1743
1754EFIAPI
1756 IN OUT EFI_SHELL_FILE_INFO **ListHead
1757 )
1758{
1759 LIST_ENTRY *Node;
1760
1761 //
1762 // ASSERT that ListHead is not NULL
1763 //
1764 ASSERT (ListHead != NULL);
1765
1766 //
1767 // Check for UEFI Shell 2.0 protocols
1768 //
1769 if (gEfiShellProtocol != NULL) {
1770 return (gEfiShellProtocol->FreeFileList (ListHead));
1771 } else if (mEfiShellEnvironment2 != NULL) {
1772 //
1773 // Since this is EFI Shell version we need to free our internally made copy
1774 // of the list
1775 //
1776 for ( Node = GetFirstNode (&(*ListHead)->Link)
1777 ; *ListHead != NULL && !IsListEmpty (&(*ListHead)->Link)
1778 ; Node = GetFirstNode (&(*ListHead)->Link))
1779 {
1780 RemoveEntryList (Node);
1781 ((EFI_FILE_PROTOCOL *)((EFI_SHELL_FILE_INFO_NO_CONST *)Node)->Handle)->Close (((EFI_SHELL_FILE_INFO_NO_CONST *)Node)->Handle);
1782 FreePool (((EFI_SHELL_FILE_INFO_NO_CONST *)Node)->FullName);
1783 FreePool (((EFI_SHELL_FILE_INFO_NO_CONST *)Node)->FileName);
1784 FreePool (((EFI_SHELL_FILE_INFO_NO_CONST *)Node)->Info);
1786 }
1787
1788 SHELL_FREE_NON_NULL (*ListHead);
1789 return EFI_SUCCESS;
1790 }
1791
1792 return (EFI_UNSUPPORTED);
1793}
1794
1807CHAR16 *
1808EFIAPI
1810 IN CONST CHAR16 *FileName
1811 )
1812{
1813 CONST CHAR16 *Path;
1814 SHELL_FILE_HANDLE Handle;
1815 EFI_STATUS Status;
1816 CHAR16 *RetVal;
1817 CHAR16 *TestPath;
1818 CONST CHAR16 *Walker;
1819 UINTN Size;
1820 CHAR16 *TempChar;
1821
1822 RetVal = NULL;
1823
1824 //
1825 // First make sure its not an absolute path.
1826 //
1827 Status = ShellOpenFileByName (FileName, &Handle, EFI_FILE_MODE_READ, 0);
1828 if (!EFI_ERROR (Status)) {
1829 if (FileHandleIsDirectory (Handle) != EFI_SUCCESS) {
1830 ASSERT (RetVal == NULL);
1831 RetVal = StrnCatGrow (&RetVal, NULL, FileName, 0);
1832 ShellCloseFile (&Handle);
1833 return (RetVal);
1834 } else {
1835 ShellCloseFile (&Handle);
1836 }
1837 }
1838
1839 Path = ShellGetEnvironmentVariable (L"cwd");
1840 if (Path != NULL) {
1841 Size = StrSize (Path) + sizeof (CHAR16);
1842 Size += StrSize (FileName);
1843 TestPath = AllocateZeroPool (Size);
1844 if (TestPath == NULL) {
1845 return (NULL);
1846 }
1847
1848 StrCpyS (TestPath, Size/sizeof (CHAR16), Path);
1849 StrCatS (TestPath, Size/sizeof (CHAR16), L"\\");
1850 StrCatS (TestPath, Size/sizeof (CHAR16), FileName);
1851 Status = ShellOpenFileByName (TestPath, &Handle, EFI_FILE_MODE_READ, 0);
1852 if (!EFI_ERROR (Status)) {
1853 if (FileHandleIsDirectory (Handle) != EFI_SUCCESS) {
1854 ASSERT (RetVal == NULL);
1855 RetVal = StrnCatGrow (&RetVal, NULL, TestPath, 0);
1856 ShellCloseFile (&Handle);
1857 FreePool (TestPath);
1858 return (RetVal);
1859 } else {
1860 ShellCloseFile (&Handle);
1861 }
1862 }
1863
1864 FreePool (TestPath);
1865 }
1866
1867 Path = ShellGetEnvironmentVariable (L"path");
1868 if (Path != NULL) {
1869 Size = StrSize (Path)+sizeof (CHAR16);
1870 Size += StrSize (FileName);
1871 TestPath = AllocateZeroPool (Size);
1872 if (TestPath == NULL) {
1873 return (NULL);
1874 }
1875
1876 Walker = (CHAR16 *)Path;
1877 do {
1878 CopyMem (TestPath, Walker, StrSize (Walker));
1879 if (TestPath != NULL) {
1880 TempChar = StrStr (TestPath, L";");
1881 if (TempChar != NULL) {
1882 *TempChar = CHAR_NULL;
1883 }
1884
1885 if (TestPath[StrLen (TestPath)-1] != L'\\') {
1886 StrCatS (TestPath, Size/sizeof (CHAR16), L"\\");
1887 }
1888
1889 if (FileName[0] == L'\\') {
1890 FileName++;
1891 }
1892
1893 StrCatS (TestPath, Size/sizeof (CHAR16), FileName);
1894 if (StrStr (Walker, L";") != NULL) {
1895 Walker = StrStr (Walker, L";") + 1;
1896 } else {
1897 Walker = NULL;
1898 }
1899
1900 Status = ShellOpenFileByName (TestPath, &Handle, EFI_FILE_MODE_READ, 0);
1901 if (!EFI_ERROR (Status)) {
1902 if (FileHandleIsDirectory (Handle) != EFI_SUCCESS) {
1903 ASSERT (RetVal == NULL);
1904 RetVal = StrnCatGrow (&RetVal, NULL, TestPath, 0);
1905 ShellCloseFile (&Handle);
1906 break;
1907 } else {
1908 ShellCloseFile (&Handle);
1909 }
1910 }
1911 }
1912 } while (Walker != NULL && Walker[0] != CHAR_NULL);
1913
1914 FreePool (TestPath);
1915 }
1916
1917 return (RetVal);
1918}
1919
1936CHAR16 *
1937EFIAPI
1939 IN CONST CHAR16 *FileName,
1940 IN CONST CHAR16 *FileExtension
1941 )
1942{
1943 CHAR16 *TestPath;
1944 CHAR16 *RetVal;
1945 CONST CHAR16 *ExtensionWalker;
1946 UINTN Size;
1947 CHAR16 *TempChar;
1948 CHAR16 *TempChar2;
1949
1950 ASSERT (FileName != NULL);
1951 if (FileExtension == NULL) {
1952 return (ShellFindFilePath (FileName));
1953 }
1954
1955 RetVal = ShellFindFilePath (FileName);
1956 if (RetVal != NULL) {
1957 return (RetVal);
1958 }
1959
1960 Size = StrSize (FileName);
1961 Size += StrSize (FileExtension);
1962 TestPath = AllocateZeroPool (Size);
1963 if (TestPath == NULL) {
1964 return (NULL);
1965 }
1966
1967 for (ExtensionWalker = FileExtension, TempChar2 = (CHAR16 *)FileExtension; TempChar2 != NULL; ExtensionWalker = TempChar2 + 1) {
1968 StrCpyS (TestPath, Size/sizeof (CHAR16), FileName);
1969 if (ExtensionWalker != NULL) {
1970 StrCatS (TestPath, Size/sizeof (CHAR16), ExtensionWalker);
1971 }
1972
1973 TempChar = StrStr (TestPath, L";");
1974 if (TempChar != NULL) {
1975 *TempChar = CHAR_NULL;
1976 }
1977
1978 RetVal = ShellFindFilePath (TestPath);
1979 if (RetVal != NULL) {
1980 break;
1981 }
1982
1983 ASSERT (ExtensionWalker != NULL);
1984 TempChar2 = StrStr (ExtensionWalker, L";");
1985 }
1986
1987 FreePool (TestPath);
1988 return (RetVal);
1989}
1990
1991typedef struct {
1992 LIST_ENTRY Link;
1993 CHAR16 *Name;
1994 SHELL_PARAM_TYPE Type;
1995 CHAR16 *Value;
1996 UINTN OriginalPosition;
1998
2014BOOLEAN
2016 IN CONST CHAR16 *Name,
2017 IN CONST SHELL_PARAM_ITEM *CheckList,
2018 OUT SHELL_PARAM_TYPE *Type
2019 )
2020{
2021 SHELL_PARAM_ITEM *TempListItem;
2022 CHAR16 *TempString;
2023
2024 //
2025 // ASSERT that all 3 pointer parameters aren't NULL
2026 //
2027 ASSERT (CheckList != NULL);
2028 ASSERT (Type != NULL);
2029 ASSERT (Name != NULL);
2030
2031 //
2032 // question mark and page break mode are always supported
2033 //
2034 if ((StrCmp (Name, L"-?") == 0) ||
2035 (StrCmp (Name, L"-b") == 0)
2036 )
2037 {
2038 *Type = TypeFlag;
2039 return (TRUE);
2040 }
2041
2042 //
2043 // Enumerate through the list
2044 //
2045 for (TempListItem = (SHELL_PARAM_ITEM *)CheckList; TempListItem->Name != NULL; TempListItem++) {
2046 //
2047 // If the Type is TypeStart only check the first characters of the passed in param
2048 // If it matches set the type and return TRUE
2049 //
2050 if (TempListItem->Type == TypeStart) {
2051 if (StrnCmp (Name, TempListItem->Name, StrLen (TempListItem->Name)) == 0) {
2052 *Type = TempListItem->Type;
2053 return (TRUE);
2054 }
2055
2056 TempString = NULL;
2057 TempString = StrnCatGrow (&TempString, NULL, Name, StrLen (TempListItem->Name));
2058 if (TempString != NULL) {
2059 if (StringNoCaseCompare (&TempString, &TempListItem->Name) == 0) {
2060 *Type = TempListItem->Type;
2061 FreePool (TempString);
2062 return (TRUE);
2063 }
2064
2065 FreePool (TempString);
2066 }
2067 } else if (StringNoCaseCompare (&Name, &TempListItem->Name) == 0) {
2068 *Type = TempListItem->Type;
2069 return (TRUE);
2070 }
2071 }
2072
2073 return (FALSE);
2074}
2075
2086BOOLEAN
2088 IN CONST CHAR16 *Name,
2089 IN CONST BOOLEAN AlwaysAllowNumbers,
2090 IN CONST BOOLEAN TimeNumbers
2091 )
2092{
2093 //
2094 // ASSERT that Name isn't NULL
2095 //
2096 ASSERT (Name != NULL);
2097
2098 //
2099 // If we accept numbers then dont return TRUE. (they will be values)
2100 //
2101 if ((((Name[0] == L'-') || (Name[0] == L'+')) && InternalShellIsHexOrDecimalNumber (Name+1, FALSE, FALSE, TimeNumbers)) && AlwaysAllowNumbers) {
2102 return (FALSE);
2103 }
2104
2105 //
2106 // If the Name has a /, +, or - as the first character return TRUE
2107 //
2108 if ((Name[0] == L'/') ||
2109 (Name[0] == L'-') ||
2110 (Name[0] == L'+')
2111 )
2112 {
2113 return (TRUE);
2114 }
2115
2116 return (FALSE);
2117}
2118
2146 IN CONST SHELL_PARAM_ITEM *CheckList,
2147 OUT LIST_ENTRY **CheckPackage,
2148 OUT CHAR16 **ProblemParam OPTIONAL,
2149 IN BOOLEAN AutoPageBreak,
2150 IN CONST CHAR16 **Argv,
2151 IN UINTN Argc,
2152 IN BOOLEAN AlwaysAllowNumbers
2153 )
2154{
2155 UINTN LoopCounter;
2156 SHELL_PARAM_TYPE CurrentItemType;
2157 SHELL_PARAM_PACKAGE *CurrentItemPackage;
2158 UINTN GetItemValue;
2159 UINTN ValueSize;
2160 UINTN Count;
2161 CONST CHAR16 *TempPointer;
2162 UINTN CurrentValueSize;
2163 CHAR16 *NewValue;
2164
2165 CurrentItemPackage = NULL;
2166 GetItemValue = 0;
2167 ValueSize = 0;
2168 Count = 0;
2169
2170 //
2171 // If there is only 1 item we dont need to do anything
2172 //
2173 if (Argc < 1) {
2174 *CheckPackage = NULL;
2175 return (EFI_SUCCESS);
2176 }
2177
2178 //
2179 // ASSERTs
2180 //
2181 ASSERT (CheckList != NULL);
2182 ASSERT (Argv != NULL);
2183
2184 //
2185 // initialize the linked list
2186 //
2187 *CheckPackage = (LIST_ENTRY *)AllocateZeroPool (sizeof (LIST_ENTRY));
2188 if (*CheckPackage == NULL) {
2189 return (EFI_OUT_OF_RESOURCES);
2190 }
2191
2192 InitializeListHead (*CheckPackage);
2193
2194 //
2195 // loop through each of the arguments
2196 //
2197 for (LoopCounter = 0; LoopCounter < Argc; ++LoopCounter) {
2198 if (Argv[LoopCounter] == NULL) {
2199 //
2200 // do nothing for NULL argv
2201 //
2202 } else if (InternalIsOnCheckList (Argv[LoopCounter], CheckList, &CurrentItemType)) {
2203 //
2204 // We might have leftover if last parameter didnt have optional value
2205 //
2206 if (GetItemValue != 0) {
2207 GetItemValue = 0;
2208 InsertHeadList (*CheckPackage, &CurrentItemPackage->Link);
2209 }
2210
2211 //
2212 // this is a flag
2213 //
2214 CurrentItemPackage = AllocateZeroPool (sizeof (SHELL_PARAM_PACKAGE));
2215 if (CurrentItemPackage == NULL) {
2216 ShellCommandLineFreeVarList (*CheckPackage);
2217 *CheckPackage = NULL;
2218 return (EFI_OUT_OF_RESOURCES);
2219 }
2220
2221 CurrentItemPackage->Name = AllocateCopyPool (StrSize (Argv[LoopCounter]), Argv[LoopCounter]);
2222 if (CurrentItemPackage->Name == NULL) {
2223 ShellCommandLineFreeVarList (*CheckPackage);
2224 *CheckPackage = NULL;
2225 return (EFI_OUT_OF_RESOURCES);
2226 }
2227
2228 CurrentItemPackage->Type = CurrentItemType;
2229 CurrentItemPackage->OriginalPosition = (UINTN)(-1);
2230 CurrentItemPackage->Value = NULL;
2231
2232 //
2233 // Does this flag require a value
2234 //
2235 switch (CurrentItemPackage->Type) {
2236 //
2237 // possibly trigger the next loop(s) to populate the value of this item
2238 //
2239 case TypeValue:
2240 case TypeTimeValue:
2241 GetItemValue = 1;
2242 ValueSize = 0;
2243 break;
2244 case TypeDoubleValue:
2245 GetItemValue = 2;
2246 ValueSize = 0;
2247 break;
2248 case TypeMaxValue:
2249 GetItemValue = (UINTN)(-1);
2250 ValueSize = 0;
2251 break;
2252 default:
2253 //
2254 // this item has no value expected; we are done
2255 //
2256 InsertHeadList (*CheckPackage, &CurrentItemPackage->Link);
2257 ASSERT (GetItemValue == 0);
2258 break;
2259 }
2260 } else if ((GetItemValue != 0) && (CurrentItemPackage != NULL) && !InternalIsFlag (Argv[LoopCounter], AlwaysAllowNumbers, (BOOLEAN)(CurrentItemPackage->Type == TypeTimeValue))) {
2261 //
2262 // get the item VALUE for a previous flag
2263 //
2264 CurrentValueSize = ValueSize + StrSize (Argv[LoopCounter]) + sizeof (CHAR16);
2265 NewValue = ReallocatePool (ValueSize, CurrentValueSize, CurrentItemPackage->Value);
2266 if (NewValue == NULL) {
2267 SHELL_FREE_NON_NULL (CurrentItemPackage->Value);
2268 SHELL_FREE_NON_NULL (CurrentItemPackage);
2269 ShellCommandLineFreeVarList (*CheckPackage);
2270 *CheckPackage = NULL;
2271 return EFI_OUT_OF_RESOURCES;
2272 }
2273
2274 CurrentItemPackage->Value = NewValue;
2275 if (ValueSize == 0) {
2276 StrCpyS (
2277 CurrentItemPackage->Value,
2278 CurrentValueSize/sizeof (CHAR16),
2279 Argv[LoopCounter]
2280 );
2281 } else {
2282 StrCatS (
2283 CurrentItemPackage->Value,
2284 CurrentValueSize/sizeof (CHAR16),
2285 L" "
2286 );
2287 StrCatS (
2288 CurrentItemPackage->Value,
2289 CurrentValueSize/sizeof (CHAR16),
2290 Argv[LoopCounter]
2291 );
2292 }
2293
2294 ValueSize += StrSize (Argv[LoopCounter]) + sizeof (CHAR16);
2295
2296 GetItemValue--;
2297 if (GetItemValue == 0) {
2298 InsertHeadList (*CheckPackage, &CurrentItemPackage->Link);
2299 }
2300 } else if (!InternalIsFlag (Argv[LoopCounter], AlwaysAllowNumbers, FALSE)) {
2301 //
2302 // add this one as a non-flag
2303 //
2304
2305 TempPointer = Argv[LoopCounter];
2306 if ( ((*TempPointer == L'^') && (*(TempPointer+1) == L'-'))
2307 || ((*TempPointer == L'^') && (*(TempPointer+1) == L'/'))
2308 || ((*TempPointer == L'^') && (*(TempPointer+1) == L'+'))
2309 )
2310 {
2311 TempPointer++;
2312 }
2313
2314 CurrentItemPackage = AllocateZeroPool (sizeof (SHELL_PARAM_PACKAGE));
2315 if (CurrentItemPackage == NULL) {
2316 ShellCommandLineFreeVarList (*CheckPackage);
2317 *CheckPackage = NULL;
2318 return (EFI_OUT_OF_RESOURCES);
2319 }
2320
2321 CurrentItemPackage->Name = NULL;
2322 CurrentItemPackage->Type = TypePosition;
2323 CurrentItemPackage->Value = AllocateCopyPool (StrSize (TempPointer), TempPointer);
2324 if (CurrentItemPackage->Value == NULL) {
2325 ShellCommandLineFreeVarList (*CheckPackage);
2326 *CheckPackage = NULL;
2327 return (EFI_OUT_OF_RESOURCES);
2328 }
2329
2330 CurrentItemPackage->OriginalPosition = Count++;
2331 InsertHeadList (*CheckPackage, &CurrentItemPackage->Link);
2332 } else {
2333 //
2334 // this was a non-recognised flag... error!
2335 //
2336 if (ProblemParam != NULL) {
2337 *ProblemParam = AllocateCopyPool (StrSize (Argv[LoopCounter]), Argv[LoopCounter]);
2338 }
2339
2340 ShellCommandLineFreeVarList (*CheckPackage);
2341 *CheckPackage = NULL;
2342 return (EFI_VOLUME_CORRUPTED);
2343 }
2344 }
2345
2346 if (GetItemValue != 0) {
2347 GetItemValue = 0;
2348 InsertHeadList (*CheckPackage, &CurrentItemPackage->Link);
2349 }
2350
2351 //
2352 // support for AutoPageBreak
2353 //
2354 if (AutoPageBreak && ShellCommandLineGetFlag (*CheckPackage, L"-b")) {
2356 }
2357
2358 return (EFI_SUCCESS);
2359}
2360
2386EFIAPI
2388 IN CONST SHELL_PARAM_ITEM *CheckList,
2389 OUT LIST_ENTRY **CheckPackage,
2390 OUT CHAR16 **ProblemParam OPTIONAL,
2391 IN BOOLEAN AutoPageBreak,
2392 IN BOOLEAN AlwaysAllowNumbers
2393 )
2394{
2395 //
2396 // ASSERT that CheckList and CheckPackage aren't NULL
2397 //
2398 ASSERT (CheckList != NULL);
2399 ASSERT (CheckPackage != NULL);
2400
2401 //
2402 // Check for UEFI Shell 2.0 protocols
2403 //
2404 if (gEfiShellParametersProtocol != NULL) {
2405 return (InternalCommandLineParse (
2406 CheckList,
2407 CheckPackage,
2408 ProblemParam,
2409 AutoPageBreak,
2410 (CONST CHAR16 **)gEfiShellParametersProtocol->Argv,
2411 gEfiShellParametersProtocol->Argc,
2412 AlwaysAllowNumbers
2413 ));
2414 }
2415
2416 //
2417 // ASSERT That EFI Shell is not required
2418 //
2419 ASSERT (mEfiShellInterface != NULL);
2420 return (InternalCommandLineParse (
2421 CheckList,
2422 CheckPackage,
2423 ProblemParam,
2424 AutoPageBreak,
2425 (CONST CHAR16 **)mEfiShellInterface->Argv,
2426 mEfiShellInterface->Argc,
2427 AlwaysAllowNumbers
2428 ));
2429}
2430
2443VOID
2444EFIAPI
2446 IN LIST_ENTRY *CheckPackage
2447 )
2448{
2449 LIST_ENTRY *Node;
2450
2451 //
2452 // check for CheckPackage == NULL
2453 //
2454 if (CheckPackage == NULL) {
2455 return;
2456 }
2457
2458 //
2459 // for each node in the list
2460 //
2461 for ( Node = GetFirstNode (CheckPackage)
2462 ; !IsListEmpty (CheckPackage)
2463 ; Node = GetFirstNode (CheckPackage)
2464 )
2465 {
2466 //
2467 // Remove it from the list
2468 //
2469 RemoveEntryList (Node);
2470
2471 //
2472 // if it has a name free the name
2473 //
2474 if (((SHELL_PARAM_PACKAGE *)Node)->Name != NULL) {
2475 FreePool (((SHELL_PARAM_PACKAGE *)Node)->Name);
2476 }
2477
2478 //
2479 // if it has a value free the value
2480 //
2481 if (((SHELL_PARAM_PACKAGE *)Node)->Value != NULL) {
2482 FreePool (((SHELL_PARAM_PACKAGE *)Node)->Value);
2483 }
2484
2485 //
2486 // free the node structure
2487 //
2488 FreePool ((SHELL_PARAM_PACKAGE *)Node);
2489 }
2490
2491 //
2492 // free the list head node
2493 //
2494 FreePool (CheckPackage);
2495}
2496
2511BOOLEAN
2512EFIAPI
2514 IN CONST LIST_ENTRY *CONST CheckPackage,
2515 IN CONST CHAR16 *CONST KeyString
2516 )
2517{
2518 LIST_ENTRY *Node;
2519 CHAR16 *TempString;
2520
2521 //
2522 // return FALSE for no package or KeyString is NULL
2523 //
2524 if ((CheckPackage == NULL) || (KeyString == NULL)) {
2525 return (FALSE);
2526 }
2527
2528 //
2529 // enumerate through the list of parametrs
2530 //
2531 for ( Node = GetFirstNode (CheckPackage)
2532 ; !IsNull (CheckPackage, Node)
2533 ; Node = GetNextNode (CheckPackage, Node)
2534 )
2535 {
2536 //
2537 // If the Name matches, return TRUE (and there may be NULL name)
2538 //
2539 if (((SHELL_PARAM_PACKAGE *)Node)->Name != NULL) {
2540 //
2541 // If Type is TypeStart then only compare the begining of the strings
2542 //
2543 if (((SHELL_PARAM_PACKAGE *)Node)->Type == TypeStart) {
2544 if (StrnCmp (KeyString, ((SHELL_PARAM_PACKAGE *)Node)->Name, StrLen (KeyString)) == 0) {
2545 return (TRUE);
2546 }
2547
2548 TempString = NULL;
2549 TempString = StrnCatGrow (&TempString, NULL, KeyString, StrLen (((SHELL_PARAM_PACKAGE *)Node)->Name));
2550 if (TempString != NULL) {
2551 if (StringNoCaseCompare (&KeyString, &((SHELL_PARAM_PACKAGE *)Node)->Name) == 0) {
2552 FreePool (TempString);
2553 return (TRUE);
2554 }
2555
2556 FreePool (TempString);
2557 }
2558 } else if (StringNoCaseCompare (&KeyString, &((SHELL_PARAM_PACKAGE *)Node)->Name) == 0) {
2559 return (TRUE);
2560 }
2561 }
2562 }
2563
2564 return (FALSE);
2565}
2566
2580CONST CHAR16 *
2581EFIAPI
2583 IN CONST LIST_ENTRY *CheckPackage,
2584 IN CHAR16 *KeyString
2585 )
2586{
2587 LIST_ENTRY *Node;
2588 CHAR16 *TempString;
2589
2590 //
2591 // return NULL for no package or KeyString is NULL
2592 //
2593 if ((CheckPackage == NULL) || (KeyString == NULL)) {
2594 return (NULL);
2595 }
2596
2597 //
2598 // enumerate through the list of parametrs
2599 //
2600 for ( Node = GetFirstNode (CheckPackage)
2601 ; !IsNull (CheckPackage, Node)
2602 ; Node = GetNextNode (CheckPackage, Node)
2603 )
2604 {
2605 //
2606 // If the Name matches, return TRUE (and there may be NULL name)
2607 //
2608 if (((SHELL_PARAM_PACKAGE *)Node)->Name != NULL) {
2609 //
2610 // If Type is TypeStart then only compare the begining of the strings
2611 //
2612 if (((SHELL_PARAM_PACKAGE *)Node)->Type == TypeStart) {
2613 if (StrnCmp (KeyString, ((SHELL_PARAM_PACKAGE *)Node)->Name, StrLen (KeyString)) == 0) {
2614 return (((SHELL_PARAM_PACKAGE *)Node)->Name + StrLen (KeyString));
2615 }
2616
2617 TempString = NULL;
2618 TempString = StrnCatGrow (&TempString, NULL, KeyString, StrLen (((SHELL_PARAM_PACKAGE *)Node)->Name));
2619 if (TempString != NULL) {
2620 if (StringNoCaseCompare (&KeyString, &((SHELL_PARAM_PACKAGE *)Node)->Name) == 0) {
2621 FreePool (TempString);
2622 return (((SHELL_PARAM_PACKAGE *)Node)->Name + StrLen (KeyString));
2623 }
2624
2625 FreePool (TempString);
2626 }
2627 } else if (StringNoCaseCompare (&KeyString, &((SHELL_PARAM_PACKAGE *)Node)->Name) == 0) {
2628 return (((SHELL_PARAM_PACKAGE *)Node)->Value);
2629 }
2630 }
2631 }
2632
2633 return (NULL);
2634}
2635
2649CONST CHAR16 *
2650EFIAPI
2652 IN CONST LIST_ENTRY *CONST CheckPackage,
2653 IN UINTN Position
2654 )
2655{
2656 LIST_ENTRY *Node;
2657
2658 //
2659 // check for CheckPackage == NULL
2660 //
2661 if (CheckPackage == NULL) {
2662 return (NULL);
2663 }
2664
2665 //
2666 // enumerate through the list of parametrs
2667 //
2668 for ( Node = GetFirstNode (CheckPackage)
2669 ; !IsNull (CheckPackage, Node)
2670 ; Node = GetNextNode (CheckPackage, Node)
2671 )
2672 {
2673 //
2674 // If the position matches, return the value
2675 //
2676 if (((SHELL_PARAM_PACKAGE *)Node)->OriginalPosition == Position) {
2677 return (((SHELL_PARAM_PACKAGE *)Node)->Value);
2678 }
2679 }
2680
2681 return (NULL);
2682}
2683
2694UINTN
2695EFIAPI
2697 IN CONST LIST_ENTRY *CheckPackage
2698 )
2699{
2700 LIST_ENTRY *Node1;
2701 UINTN Count;
2702
2703 if (CheckPackage == NULL) {
2704 return (0);
2705 }
2706
2707 for ( Node1 = GetFirstNode (CheckPackage), Count = 0
2708 ; !IsNull (CheckPackage, Node1)
2709 ; Node1 = GetNextNode (CheckPackage, Node1)
2710 )
2711 {
2712 if (((SHELL_PARAM_PACKAGE *)Node1)->Name == NULL) {
2713 Count++;
2714 }
2715 }
2716
2717 return (Count);
2718}
2719
2735EFIAPI
2737 IN CONST LIST_ENTRY *CheckPackage,
2738 OUT CHAR16 **Param
2739 )
2740{
2741 LIST_ENTRY *Node1;
2742 LIST_ENTRY *Node2;
2743
2744 ASSERT (CheckPackage != NULL);
2745
2746 for ( Node1 = GetFirstNode (CheckPackage)
2747 ; !IsNull (CheckPackage, Node1)
2748 ; Node1 = GetNextNode (CheckPackage, Node1)
2749 )
2750 {
2751 for ( Node2 = GetNextNode (CheckPackage, Node1)
2752 ; !IsNull (CheckPackage, Node2)
2753 ; Node2 = GetNextNode (CheckPackage, Node2)
2754 )
2755 {
2756 if ((((SHELL_PARAM_PACKAGE *)Node1)->Name != NULL) && (((SHELL_PARAM_PACKAGE *)Node2)->Name != NULL) && (StrCmp (((SHELL_PARAM_PACKAGE *)Node1)->Name, ((SHELL_PARAM_PACKAGE *)Node2)->Name) == 0)) {
2757 if (Param != NULL) {
2758 *Param = NULL;
2759 *Param = StrnCatGrow (Param, NULL, ((SHELL_PARAM_PACKAGE *)Node1)->Name, 0);
2760 }
2761
2762 return (EFI_DEVICE_ERROR);
2763 }
2764 }
2765 }
2766
2767 return (EFI_SUCCESS);
2768}
2769
2798EFIAPI
2800 IN CHAR16 CONST *SourceString,
2801 IN OUT CHAR16 *NewString,
2802 IN UINTN NewSize,
2803 IN CONST CHAR16 *FindTarget,
2804 IN CONST CHAR16 *ReplaceWith,
2805 IN CONST BOOLEAN SkipPreCarrot,
2806 IN CONST BOOLEAN ParameterReplacing
2807 )
2808{
2809 UINTN Size;
2810 CHAR16 *Replace;
2811
2812 if ( (SourceString == NULL)
2813 || (NewString == NULL)
2814 || (FindTarget == NULL)
2815 || (ReplaceWith == NULL)
2816 || (StrLen (FindTarget) < 1)
2817 || (StrLen (SourceString) < 1)
2818 )
2819 {
2820 return (EFI_INVALID_PARAMETER);
2821 }
2822
2823 Replace = NULL;
2824 if ((StrStr (ReplaceWith, L" ") == NULL) || !ParameterReplacing) {
2825 Replace = StrnCatGrow (&Replace, NULL, ReplaceWith, 0);
2826 } else {
2827 Replace = AllocateZeroPool (StrSize (ReplaceWith) + 2*sizeof (CHAR16));
2828 if (Replace != NULL) {
2829 UnicodeSPrint (Replace, StrSize (ReplaceWith) + 2*sizeof (CHAR16), L"\"%s\"", ReplaceWith);
2830 }
2831 }
2832
2833 if (Replace == NULL) {
2834 return (EFI_OUT_OF_RESOURCES);
2835 }
2836
2837 NewString = ZeroMem (NewString, NewSize);
2838 while (*SourceString != CHAR_NULL) {
2839 //
2840 // if we find the FindTarget and either Skip == FALSE or Skip and we
2841 // dont have a carrot do a replace...
2842 //
2843 if ( (StrnCmp (SourceString, FindTarget, StrLen (FindTarget)) == 0)
2844 && ((SkipPreCarrot && (*(SourceString-1) != L'^')) || !SkipPreCarrot)
2845 )
2846 {
2847 SourceString += StrLen (FindTarget);
2848 Size = StrSize (NewString);
2849 if ((Size + (StrLen (Replace)*sizeof (CHAR16))) > NewSize) {
2850 FreePool (Replace);
2851 return (EFI_BUFFER_TOO_SMALL);
2852 }
2853
2854 StrCatS (NewString, NewSize/sizeof (CHAR16), Replace);
2855 } else {
2856 Size = StrSize (NewString);
2857 if (Size + sizeof (CHAR16) > NewSize) {
2858 FreePool (Replace);
2859 return (EFI_BUFFER_TOO_SMALL);
2860 }
2861
2862 StrnCatS (NewString, NewSize/sizeof (CHAR16), SourceString, 1);
2863 SourceString++;
2864 }
2865 }
2866
2867 FreePool (Replace);
2868 return (EFI_SUCCESS);
2869}
2870
2883 IN CONST CHAR16 *String
2884 )
2885{
2886 UINTN Size;
2887
2888 Size = StrSize (String) - sizeof (CHAR16);
2889 if (Size == 0) {
2890 return (EFI_SUCCESS);
2891 }
2892
2893 if (gEfiShellParametersProtocol != NULL) {
2894 return (gEfiShellProtocol->WriteFile (gEfiShellParametersProtocol->StdOut, &Size, (VOID *)String));
2895 }
2896
2897 if (mEfiShellInterface != NULL) {
2898 if (mEfiShellInterface->RedirArgc == 0) {
2899 //
2900 // Divide in half for old shell. Must be string length not size.
2901 //
2902 Size /= 2; // Divide in half only when no redirection.
2903 }
2904
2905 return (mEfiShellInterface->StdOut->Write (mEfiShellInterface->StdOut, &Size, (VOID *)String));
2906 }
2907
2908 ASSERT (FALSE);
2909 return (EFI_UNSUPPORTED);
2910}
2911
2943 IN INT32 Col OPTIONAL,
2944 IN INT32 Row OPTIONAL,
2945 IN CONST CHAR16 *Format,
2946 IN VA_LIST Marker
2947 )
2948{
2949 EFI_STATUS Status;
2950 CHAR16 *ResumeLocation;
2951 CHAR16 *FormatWalker;
2952 UINTN OriginalAttribute;
2953 CHAR16 *mPostReplaceFormat;
2954 CHAR16 *mPostReplaceFormat2;
2955
2956 mPostReplaceFormat = AllocateZeroPool (PcdGet32 (PcdShellPrintBufferSize));
2957 mPostReplaceFormat2 = AllocateZeroPool (PcdGet32 (PcdShellPrintBufferSize));
2958
2959 if ((mPostReplaceFormat == NULL) || (mPostReplaceFormat2 == NULL)) {
2960 SHELL_FREE_NON_NULL (mPostReplaceFormat);
2961 SHELL_FREE_NON_NULL (mPostReplaceFormat2);
2962 return (EFI_OUT_OF_RESOURCES);
2963 }
2964
2965 Status = EFI_SUCCESS;
2966 OriginalAttribute = gST->ConOut->Mode->Attribute;
2967
2968 //
2969 // Back and forth each time fixing up 1 of our flags...
2970 //
2971 Status = ShellCopySearchAndReplace (Format, mPostReplaceFormat, PcdGet32 (PcdShellPrintBufferSize), L"%N", L"%%N", FALSE, FALSE);
2972 ASSERT_EFI_ERROR (Status);
2973 Status = ShellCopySearchAndReplace (mPostReplaceFormat, mPostReplaceFormat2, PcdGet32 (PcdShellPrintBufferSize), L"%E", L"%%E", FALSE, FALSE);
2974 ASSERT_EFI_ERROR (Status);
2975 Status = ShellCopySearchAndReplace (mPostReplaceFormat2, mPostReplaceFormat, PcdGet32 (PcdShellPrintBufferSize), L"%H", L"%%H", FALSE, FALSE);
2976 ASSERT_EFI_ERROR (Status);
2977 Status = ShellCopySearchAndReplace (mPostReplaceFormat, mPostReplaceFormat2, PcdGet32 (PcdShellPrintBufferSize), L"%B", L"%%B", FALSE, FALSE);
2978 ASSERT_EFI_ERROR (Status);
2979 Status = ShellCopySearchAndReplace (mPostReplaceFormat2, mPostReplaceFormat, PcdGet32 (PcdShellPrintBufferSize), L"%V", L"%%V", FALSE, FALSE);
2980 ASSERT_EFI_ERROR (Status);
2981
2982 //
2983 // Use the last buffer from replacing to print from...
2984 //
2985 UnicodeVSPrint (mPostReplaceFormat2, PcdGet32 (PcdShellPrintBufferSize), mPostReplaceFormat, Marker);
2986
2987 if ((Col != -1) && (Row != -1)) {
2988 Status = gST->ConOut->SetCursorPosition (gST->ConOut, Col, Row);
2989 }
2990
2991 FormatWalker = mPostReplaceFormat2;
2992 while (*FormatWalker != CHAR_NULL) {
2993 //
2994 // Find the next attribute change request
2995 //
2996 ResumeLocation = StrStr (FormatWalker, L"%");
2997 if (ResumeLocation != NULL) {
2998 *ResumeLocation = CHAR_NULL;
2999 }
3000
3001 //
3002 // print the current FormatWalker string
3003 //
3004 if (StrLen (FormatWalker) > 0) {
3005 Status = InternalPrintTo (FormatWalker);
3006 if (EFI_ERROR (Status)) {
3007 break;
3008 }
3009 }
3010
3011 //
3012 // update the attribute
3013 //
3014 if (ResumeLocation != NULL) {
3015 if ((ResumeLocation != mPostReplaceFormat2) && (*(ResumeLocation-1) == L'^')) {
3016 //
3017 // Move cursor back 1 position to overwrite the ^
3018 //
3019 gST->ConOut->SetCursorPosition (gST->ConOut, gST->ConOut->Mode->CursorColumn - 1, gST->ConOut->Mode->CursorRow);
3020
3021 //
3022 // Print a simple '%' symbol
3023 //
3024 Status = InternalPrintTo (L"%");
3025 ResumeLocation = ResumeLocation - 1;
3026 } else {
3027 switch (*(ResumeLocation+1)) {
3028 case (L'N'):
3029 gST->ConOut->SetAttribute (gST->ConOut, OriginalAttribute);
3030 break;
3031 case (L'E'):
3032 gST->ConOut->SetAttribute (gST->ConOut, EFI_TEXT_ATTR (EFI_YELLOW, ((OriginalAttribute&(BIT4|BIT5|BIT6))>>4)));
3033 break;
3034 case (L'H'):
3035 gST->ConOut->SetAttribute (gST->ConOut, EFI_TEXT_ATTR (EFI_WHITE, ((OriginalAttribute&(BIT4|BIT5|BIT6))>>4)));
3036 break;
3037 case (L'B'):
3038 gST->ConOut->SetAttribute (gST->ConOut, EFI_TEXT_ATTR (EFI_LIGHTBLUE, ((OriginalAttribute&(BIT4|BIT5|BIT6))>>4)));
3039 break;
3040 case (L'V'):
3041 gST->ConOut->SetAttribute (gST->ConOut, EFI_TEXT_ATTR (EFI_LIGHTGREEN, ((OriginalAttribute&(BIT4|BIT5|BIT6))>>4)));
3042 break;
3043 default:
3044 //
3045 // Print a simple '%' symbol
3046 //
3047 Status = InternalPrintTo (L"%");
3048 if (EFI_ERROR (Status)) {
3049 break;
3050 }
3051
3052 ResumeLocation = ResumeLocation - 1;
3053 break;
3054 }
3055 }
3056 } else {
3057 //
3058 // reset to normal now...
3059 //
3060 break;
3061 }
3062
3063 //
3064 // update FormatWalker to Resume + 2 (skip the % and the indicator)
3065 //
3066 FormatWalker = ResumeLocation + 2;
3067 }
3068
3069 gST->ConOut->SetAttribute (gST->ConOut, OriginalAttribute);
3070
3071 SHELL_FREE_NON_NULL (mPostReplaceFormat);
3072 SHELL_FREE_NON_NULL (mPostReplaceFormat2);
3073 return (Status);
3074}
3075
3106EFIAPI
3108 IN INT32 Col OPTIONAL,
3109 IN INT32 Row OPTIONAL,
3110 IN CONST CHAR16 *Format,
3111 ...
3112 )
3113{
3114 VA_LIST Marker;
3115 EFI_STATUS RetVal;
3116
3117 if (Format == NULL) {
3118 return (EFI_INVALID_PARAMETER);
3119 }
3120
3121 VA_START (Marker, Format);
3122 RetVal = InternalShellPrintWorker (Col, Row, Format, Marker);
3123 VA_END (Marker);
3124 return (RetVal);
3125}
3126
3160EFIAPI
3162 IN INT32 Col OPTIONAL,
3163 IN INT32 Row OPTIONAL,
3164 IN CONST CHAR8 *Language OPTIONAL,
3165 IN CONST EFI_STRING_ID HiiFormatStringId,
3166 IN CONST EFI_HII_HANDLE HiiFormatHandle,
3167 ...
3168 )
3169{
3170 VA_LIST Marker;
3171 CHAR16 *HiiFormatString;
3172 EFI_STATUS RetVal;
3173
3174 RetVal = EFI_DEVICE_ERROR;
3175
3176 VA_START (Marker, HiiFormatHandle);
3177 HiiFormatString = HiiGetString (HiiFormatHandle, HiiFormatStringId, Language);
3178 if (HiiFormatString != NULL) {
3179 RetVal = InternalShellPrintWorker (Col, Row, HiiFormatString, Marker);
3180 SHELL_FREE_NON_NULL (HiiFormatString);
3181 }
3182
3183 VA_END (Marker);
3184
3185 return (RetVal);
3186}
3187
3199EFIAPI
3201 IN CONST CHAR16 *DirName
3202 )
3203{
3204 EFI_STATUS Status;
3205 SHELL_FILE_HANDLE Handle;
3206 CHAR16 *TempLocation;
3207 CHAR16 *TempLocation2;
3208
3209 ASSERT (DirName != NULL);
3210
3211 Handle = NULL;
3212 TempLocation = NULL;
3213
3214 Status = ShellOpenFileByName (DirName, &Handle, EFI_FILE_MODE_READ, 0);
3215 if (EFI_ERROR (Status)) {
3216 //
3217 // try good logic first.
3218 //
3219 if (gEfiShellProtocol != NULL) {
3220 TempLocation = StrnCatGrow (&TempLocation, NULL, DirName, 0);
3221 if (TempLocation == NULL) {
3222 ShellCloseFile (&Handle);
3223 return (EFI_OUT_OF_RESOURCES);
3224 }
3225
3226 TempLocation2 = StrStr (TempLocation, L":");
3227 if ((TempLocation2 != NULL) && (StrLen (StrStr (TempLocation, L":")) == 2)) {
3228 *(TempLocation2+1) = CHAR_NULL;
3229 }
3230
3231 if (gEfiShellProtocol->GetDevicePathFromMap (TempLocation) != NULL) {
3232 FreePool (TempLocation);
3233 return (EFI_SUCCESS);
3234 }
3235
3236 FreePool (TempLocation);
3237 } else {
3238 //
3239 // probably a map name?!?!!?
3240 //
3241 TempLocation = StrStr (DirName, L"\\");
3242 if ((TempLocation != NULL) && (*(TempLocation+1) == CHAR_NULL)) {
3243 return (EFI_SUCCESS);
3244 }
3245 }
3246
3247 return (Status);
3248 }
3249
3250 if (FileHandleIsDirectory (Handle) == EFI_SUCCESS) {
3251 ShellCloseFile (&Handle);
3252 return (EFI_SUCCESS);
3253 }
3254
3255 ShellCloseFile (&Handle);
3256 return (EFI_NOT_FOUND);
3257}
3258
3269EFIAPI
3271 IN CONST CHAR16 *Name
3272 )
3273{
3274 EFI_STATUS Status;
3275 SHELL_FILE_HANDLE Handle;
3276
3277 ASSERT (Name != NULL);
3278
3279 Handle = NULL;
3280
3281 Status = ShellOpenFileByName (Name, &Handle, EFI_FILE_MODE_READ, 0);
3282 if (EFI_ERROR (Status)) {
3283 return (Status);
3284 }
3285
3286 if (FileHandleIsDirectory (Handle) != EFI_SUCCESS) {
3287 ShellCloseFile (&Handle);
3288 return (EFI_SUCCESS);
3289 }
3290
3291 ShellCloseFile (&Handle);
3292 return (EFI_NOT_FOUND);
3293}
3294
3309EFIAPI
3311 IN CONST CHAR16 *Name
3312 )
3313{
3314 CHAR16 *NewName;
3315 EFI_STATUS Status;
3316
3317 if (!EFI_ERROR (ShellIsFile (Name))) {
3318 return (EFI_SUCCESS);
3319 }
3320
3321 NewName = ShellFindFilePath (Name);
3322 if (NewName == NULL) {
3323 return (EFI_NOT_FOUND);
3324 }
3325
3326 Status = ShellIsFile (NewName);
3327 FreePool (NewName);
3328 return (Status);
3329}
3330
3342UINTN
3343EFIAPI
3345 IN CONST CHAR16 *String
3346 )
3347{
3348 UINT64 RetVal;
3349
3350 if (!EFI_ERROR (ShellConvertStringToUint64 (String, &RetVal, TRUE, TRUE))) {
3351 return ((UINTN)RetVal);
3352 }
3353
3354 return ((UINTN)(-1));
3355}
3356
3366UINTN
3367EFIAPI
3369 IN CONST CHAR16 *String
3370 )
3371{
3372 UINT64 RetVal;
3373 BOOLEAN Hex;
3374
3375 Hex = FALSE;
3376
3377 if (!InternalShellIsHexOrDecimalNumber (String, Hex, TRUE, FALSE)) {
3378 Hex = TRUE;
3379 }
3380
3381 if (!EFI_ERROR (ShellConvertStringToUint64 (String, &RetVal, Hex, TRUE))) {
3382 return ((UINTN)RetVal);
3383 }
3384
3385 return ((UINTN)(-1));
3386}
3387
3420CHAR16 *
3421EFIAPI
3423 IN OUT CHAR16 **Destination,
3424 IN OUT UINTN *CurrentSize,
3425 IN CONST CHAR16 *Source,
3426 IN UINTN Count
3427 )
3428{
3429 UINTN DestinationStartSize;
3430 UINTN NewSize;
3431
3432 //
3433 // ASSERTs
3434 //
3435 ASSERT (Destination != NULL);
3436
3437 //
3438 // If there's nothing to do then just return Destination
3439 //
3440 if (Source == NULL) {
3441 return (*Destination);
3442 }
3443
3444 //
3445 // allow for un-initialized pointers, based on size being 0
3446 //
3447 if ((CurrentSize != NULL) && (*CurrentSize == 0)) {
3448 *Destination = NULL;
3449 }
3450
3451 //
3452 // allow for NULL pointers address as Destination
3453 //
3454 if (*Destination != NULL) {
3455 ASSERT (CurrentSize != 0);
3456 DestinationStartSize = StrSize (*Destination);
3457 ASSERT (DestinationStartSize <= *CurrentSize);
3458 } else {
3459 DestinationStartSize = 0;
3460 // ASSERT(*CurrentSize == 0);
3461 }
3462
3463 //
3464 // Append all of Source?
3465 //
3466 if (Count == 0) {
3467 Count = StrLen (Source);
3468 }
3469
3470 //
3471 // Test and grow if required
3472 //
3473 if (CurrentSize != NULL) {
3474 NewSize = *CurrentSize;
3475 if (NewSize < DestinationStartSize + (Count * sizeof (CHAR16))) {
3476 while (NewSize < (DestinationStartSize + (Count*sizeof (CHAR16)))) {
3477 NewSize += 2 * Count * sizeof (CHAR16);
3478 }
3479
3480 *Destination = ReallocatePool (*CurrentSize, NewSize, *Destination);
3481 *CurrentSize = NewSize;
3482 }
3483 } else {
3484 NewSize = (Count+1)*sizeof (CHAR16);
3485 *Destination = AllocateZeroPool (NewSize);
3486 }
3487
3488 //
3489 // Now use standard StrnCat on a big enough buffer
3490 //
3491 if (*Destination == NULL) {
3492 return (NULL);
3493 }
3494
3495 StrnCatS (*Destination, NewSize/sizeof (CHAR16), Source, Count);
3496 return *Destination;
3497}
3498
3524EFIAPI
3527 IN CHAR16 *Prompt OPTIONAL,
3528 IN OUT VOID **Response OPTIONAL
3529 )
3530{
3531 EFI_STATUS Status;
3532 EFI_INPUT_KEY Key;
3533 UINTN EventIndex;
3535 UINTN Size;
3536 CHAR16 *Buffer;
3537
3538 Status = EFI_UNSUPPORTED;
3539 Resp = NULL;
3540 Buffer = NULL;
3541 Size = 0;
3542 if (Type != ShellPromptResponseTypeFreeform) {
3544 if (Resp == NULL) {
3545 if (Response != NULL) {
3546 *Response = NULL;
3547 }
3548
3549 return (EFI_OUT_OF_RESOURCES);
3550 }
3551 }
3552
3553 switch (Type) {
3554 case ShellPromptResponseTypeQuitContinue:
3555 if (Prompt != NULL) {
3556 ShellPrintEx (-1, -1, L"%s", Prompt);
3557 }
3558
3559 //
3560 // wait for valid response
3561 //
3562 gBS->WaitForEvent (1, &gST->ConIn->WaitForKey, &EventIndex);
3563 Status = gST->ConIn->ReadKeyStroke (gST->ConIn, &Key);
3564 if (EFI_ERROR (Status)) {
3565 break;
3566 }
3567
3568 ShellPrintEx (-1, -1, L"%c", Key.UnicodeChar);
3569 if ((Key.UnicodeChar == L'Q') || (Key.UnicodeChar == L'q')) {
3570 *Resp = ShellPromptResponseQuit;
3571 } else {
3572 *Resp = ShellPromptResponseContinue;
3573 }
3574
3575 break;
3576 case ShellPromptResponseTypeYesNoCancel:
3577 if (Prompt != NULL) {
3578 ShellPrintEx (-1, -1, L"%s", Prompt);
3579 }
3580
3581 //
3582 // wait for valid response
3583 //
3584 *Resp = ShellPromptResponseMax;
3585 while (*Resp == ShellPromptResponseMax) {
3587 Status = EFI_ABORTED;
3588 break;
3589 }
3590
3591 gBS->WaitForEvent (1, &gST->ConIn->WaitForKey, &EventIndex);
3592 Status = gST->ConIn->ReadKeyStroke (gST->ConIn, &Key);
3593 if (EFI_ERROR (Status)) {
3594 break;
3595 }
3596
3597 ShellPrintEx (-1, -1, L"%c", Key.UnicodeChar);
3598 switch (Key.UnicodeChar) {
3599 case L'Y':
3600 case L'y':
3601 *Resp = ShellPromptResponseYes;
3602 break;
3603 case L'N':
3604 case L'n':
3605 *Resp = ShellPromptResponseNo;
3606 break;
3607 case L'C':
3608 case L'c':
3609 *Resp = ShellPromptResponseCancel;
3610 break;
3611 }
3612 }
3613
3614 break;
3615 case ShellPromptResponseTypeYesNoAllCancel:
3616 if (Prompt != NULL) {
3617 ShellPrintEx (-1, -1, L"%s", Prompt);
3618 }
3619
3620 //
3621 // wait for valid response
3622 //
3623 *Resp = ShellPromptResponseMax;
3624 while (*Resp == ShellPromptResponseMax) {
3626 Status = EFI_ABORTED;
3627 break;
3628 }
3629
3630 gBS->WaitForEvent (1, &gST->ConIn->WaitForKey, &EventIndex);
3631 Status = gST->ConIn->ReadKeyStroke (gST->ConIn, &Key);
3632 if (EFI_ERROR (Status)) {
3633 break;
3634 }
3635
3636 if ((Key.UnicodeChar <= 127) && (Key.UnicodeChar >= 32)) {
3637 ShellPrintEx (-1, -1, L"%c", Key.UnicodeChar);
3638 }
3639
3640 switch (Key.UnicodeChar) {
3641 case L'Y':
3642 case L'y':
3643 *Resp = ShellPromptResponseYes;
3644 break;
3645 case L'N':
3646 case L'n':
3647 *Resp = ShellPromptResponseNo;
3648 break;
3649 case L'A':
3650 case L'a':
3651 *Resp = ShellPromptResponseAll;
3652 break;
3653 case L'C':
3654 case L'c':
3655 *Resp = ShellPromptResponseCancel;
3656 break;
3657 }
3658 }
3659
3660 break;
3661 case ShellPromptResponseTypeEnterContinue:
3662 case ShellPromptResponseTypeAnyKeyContinue:
3663 if (Prompt != NULL) {
3664 ShellPrintEx (-1, -1, L"%s", Prompt);
3665 }
3666
3667 //
3668 // wait for valid response
3669 //
3670 *Resp = ShellPromptResponseMax;
3671 while (*Resp == ShellPromptResponseMax) {
3673 Status = EFI_ABORTED;
3674 break;
3675 }
3676
3677 gBS->WaitForEvent (1, &gST->ConIn->WaitForKey, &EventIndex);
3678 if (Type == ShellPromptResponseTypeEnterContinue) {
3679 Status = gST->ConIn->ReadKeyStroke (gST->ConIn, &Key);
3680 if (EFI_ERROR (Status)) {
3681 break;
3682 }
3683
3684 ShellPrintEx (-1, -1, L"%c", Key.UnicodeChar);
3685 if (Key.UnicodeChar == CHAR_CARRIAGE_RETURN) {
3686 *Resp = ShellPromptResponseContinue;
3687 break;
3688 }
3689 }
3690
3691 if (Type == ShellPromptResponseTypeAnyKeyContinue) {
3692 Status = gST->ConIn->ReadKeyStroke (gST->ConIn, &Key);
3693 ASSERT_EFI_ERROR (Status);
3694 *Resp = ShellPromptResponseContinue;
3695 break;
3696 }
3697 }
3698
3699 break;
3700 case ShellPromptResponseTypeYesNo:
3701 if (Prompt != NULL) {
3702 ShellPrintEx (-1, -1, L"%s", Prompt);
3703 }
3704
3705 //
3706 // wait for valid response
3707 //
3708 *Resp = ShellPromptResponseMax;
3709 while (*Resp == ShellPromptResponseMax) {
3711 Status = EFI_ABORTED;
3712 break;
3713 }
3714
3715 gBS->WaitForEvent (1, &gST->ConIn->WaitForKey, &EventIndex);
3716 Status = gST->ConIn->ReadKeyStroke (gST->ConIn, &Key);
3717 if (EFI_ERROR (Status)) {
3718 break;
3719 }
3720
3721 ShellPrintEx (-1, -1, L"%c", Key.UnicodeChar);
3722 switch (Key.UnicodeChar) {
3723 case L'Y':
3724 case L'y':
3725 *Resp = ShellPromptResponseYes;
3726 break;
3727 case L'N':
3728 case L'n':
3729 *Resp = ShellPromptResponseNo;
3730 break;
3731 }
3732 }
3733
3734 break;
3735 case ShellPromptResponseTypeFreeform:
3736 if (Prompt != NULL) {
3737 ShellPrintEx (-1, -1, L"%s", Prompt);
3738 }
3739
3740 while (1) {
3742 Status = EFI_ABORTED;
3743 break;
3744 }
3745
3746 gBS->WaitForEvent (1, &gST->ConIn->WaitForKey, &EventIndex);
3747 Status = gST->ConIn->ReadKeyStroke (gST->ConIn, &Key);
3748 if (EFI_ERROR (Status)) {
3749 break;
3750 }
3751
3752 ShellPrintEx (-1, -1, L"%c", Key.UnicodeChar);
3753 if (Key.UnicodeChar == CHAR_CARRIAGE_RETURN) {
3754 break;
3755 }
3756
3757 ASSERT ((Buffer == NULL && Size == 0) || (Buffer != NULL));
3758 StrnCatGrow (&Buffer, &Size, &Key.UnicodeChar, 1);
3759 }
3760
3761 break;
3762 //
3763 // This is the location to add new prompt types.
3764 // If your new type loops remember to add ExecutionBreak support.
3765 //
3766 default:
3767 ASSERT (FALSE);
3768 }
3769
3770 if (Response != NULL) {
3771 if (Resp != NULL) {
3772 *Response = Resp;
3773 } else if (Buffer != NULL) {
3774 *Response = Buffer;
3775 } else {
3776 *Response = NULL;
3777 }
3778 } else {
3779 if (Resp != NULL) {
3780 FreePool (Resp);
3781 }
3782
3783 if (Buffer != NULL) {
3784 FreePool (Buffer);
3785 }
3786 }
3787
3788 ShellPrintEx (-1, -1, L"\r\n");
3789 return (Status);
3790}
3791
3810EFIAPI
3813 IN CONST EFI_STRING_ID HiiFormatStringId,
3814 IN CONST EFI_HII_HANDLE HiiFormatHandle,
3815 IN OUT VOID **Response
3816 )
3817{
3818 CHAR16 *Prompt;
3819 EFI_STATUS Status;
3820
3821 Prompt = HiiGetString (HiiFormatHandle, HiiFormatStringId, NULL);
3822 Status = ShellPromptForResponse (Type, Prompt, Response);
3823 if (Prompt != NULL) {
3824 FreePool (Prompt);
3825 }
3826
3827 return (Status);
3828}
3829
3843BOOLEAN
3845 IN CONST CHAR16 *String,
3846 IN CONST BOOLEAN ForceHex,
3847 IN CONST BOOLEAN StopAtSpace,
3848 IN CONST BOOLEAN TimeNumbers
3849 )
3850{
3851 BOOLEAN Hex;
3852 BOOLEAN LeadingZero;
3853
3854 if (String == NULL) {
3855 return FALSE;
3856 }
3857
3858 //
3859 // chop off a single negative sign
3860 //
3861 if (*String == L'-') {
3862 String++;
3863 }
3864
3865 if (*String == CHAR_NULL) {
3866 return FALSE;
3867 }
3868
3869 //
3870 // chop leading zeroes
3871 //
3872 LeadingZero = FALSE;
3873 while (*String == L'0') {
3874 String++;
3875 LeadingZero = TRUE;
3876 }
3877
3878 //
3879 // allow '0x' or '0X', but not 'x' or 'X'
3880 //
3881 if ((*String == L'x') || (*String == L'X')) {
3882 if (!LeadingZero) {
3883 //
3884 // we got an x without a preceeding 0
3885 //
3886 return (FALSE);
3887 }
3888
3889 String++;
3890 Hex = TRUE;
3891 } else if (ForceHex) {
3892 Hex = TRUE;
3893 } else {
3894 Hex = FALSE;
3895 }
3896
3897 //
3898 // loop through the remaining characters and use the lib function
3899 //
3900 for ( ; *String != CHAR_NULL && !(StopAtSpace && *String == L' '); String++) {
3901 if (TimeNumbers && (String[0] == L':')) {
3902 continue;
3903 }
3904
3905 if (Hex) {
3906 if (!ShellIsHexaDecimalDigitCharacter (*String)) {
3907 return (FALSE);
3908 }
3909 } else {
3910 if (!ShellIsDecimalDigitCharacter (*String)) {
3911 return (FALSE);
3912 }
3913 }
3914 }
3915
3916 return (TRUE);
3917}
3918
3929EFIAPI
3931 IN CONST CHAR16 *Name
3932 )
3933{
3934 EFI_STATUS Status;
3935 EFI_SHELL_FILE_INFO *List;
3936
3937 ASSERT (Name != NULL);
3938
3939 List = NULL;
3940 Status = ShellOpenFileMetaArg ((CHAR16 *)Name, EFI_FILE_MODE_READ, &List);
3941 if (EFI_ERROR (Status)) {
3942 return (Status);
3943 }
3944
3945 ShellCloseFileMetaArg (&List);
3946
3947 return (EFI_SUCCESS);
3948}
3949
3963UINTN
3965 IN CHAR16 Char
3966 )
3967{
3968 if (ShellIsDecimalDigitCharacter (Char)) {
3969 return Char - L'0';
3970 }
3971
3972 return (10 + CharToUpper (Char) - L'A');
3973}
3974
4007 IN CONST CHAR16 *String,
4008 OUT UINT64 *Value,
4009 IN CONST BOOLEAN StopAtSpace
4010 )
4011{
4012 UINT64 Result;
4013
4014 if ((String == NULL) || (StrSize (String) == 0) || (Value == NULL)) {
4015 return (EFI_INVALID_PARAMETER);
4016 }
4017
4018 //
4019 // Ignore the pad spaces (space or tab)
4020 //
4021 while ((*String == L' ') || (*String == L'\t')) {
4022 String++;
4023 }
4024
4025 //
4026 // Ignore leading Zeros after the spaces
4027 //
4028 while (*String == L'0') {
4029 String++;
4030 }
4031
4032 if (CharToUpper (*String) == L'X') {
4033 if (*(String - 1) != L'0') {
4034 return 0;
4035 }
4036
4037 //
4038 // Skip the 'X'
4039 //
4040 String++;
4041 }
4042
4043 Result = 0;
4044
4045 //
4046 // there is a space where there should't be
4047 //
4048 if (*String == L' ') {
4049 return (EFI_INVALID_PARAMETER);
4050 }
4051
4052 while (ShellIsHexaDecimalDigitCharacter (*String)) {
4053 //
4054 // If the Hex Number represented by String overflows according
4055 // to the range defined by UINT64, then return EFI_DEVICE_ERROR.
4056 //
4057 if (!(Result <= (RShiftU64 ((((UINT64) ~0) - InternalShellHexCharToUintn (*String)), 4)))) {
4058 // if (!(Result <= ((((UINT64) ~0) - InternalShellHexCharToUintn (*String)) >> 4))) {
4059 return (EFI_DEVICE_ERROR);
4060 }
4061
4062 Result = (LShiftU64 (Result, 4));
4063 Result += InternalShellHexCharToUintn (*String);
4064 String++;
4065
4066 //
4067 // stop at spaces if requested
4068 //
4069 if (StopAtSpace && (*String == L' ')) {
4070 break;
4071 }
4072 }
4073
4074 *Value = Result;
4075 return (EFI_SUCCESS);
4076}
4077
4109 IN CONST CHAR16 *String,
4110 OUT UINT64 *Value,
4111 IN CONST BOOLEAN StopAtSpace
4112 )
4113{
4114 UINT64 Result;
4115
4116 if ((String == NULL) || (StrSize (String) == 0) || (Value == NULL)) {
4117 return (EFI_INVALID_PARAMETER);
4118 }
4119
4120 //
4121 // Ignore the pad spaces (space or tab)
4122 //
4123 while ((*String == L' ') || (*String == L'\t')) {
4124 String++;
4125 }
4126
4127 //
4128 // Ignore leading Zeros after the spaces
4129 //
4130 while (*String == L'0') {
4131 String++;
4132 }
4133
4134 Result = 0;
4135
4136 //
4137 // Stop upon space if requested
4138 // (if the whole value was 0)
4139 //
4140 if (StopAtSpace && (*String == L' ')) {
4141 *Value = Result;
4142 return (EFI_SUCCESS);
4143 }
4144
4145 while (ShellIsDecimalDigitCharacter (*String)) {
4146 //
4147 // If the number represented by String overflows according
4148 // to the range defined by UINT64, then return EFI_DEVICE_ERROR.
4149 //
4150
4151 if (!(Result <= (DivU64x32 ((((UINT64) ~0) - (*String - L'0')), 10)))) {
4152 return (EFI_DEVICE_ERROR);
4153 }
4154
4155 Result = MultU64x32 (Result, 10) + (*String - L'0');
4156 String++;
4157
4158 //
4159 // Stop at spaces if requested
4160 //
4161 if (StopAtSpace && (*String == L' ')) {
4162 break;
4163 }
4164 }
4165
4166 *Value = Result;
4167
4168 return (EFI_SUCCESS);
4169}
4170
4186EFIAPI
4188 IN CONST CHAR16 *String,
4189 OUT UINT64 *Value,
4190 IN CONST BOOLEAN ForceHex,
4191 IN CONST BOOLEAN StopAtSpace
4192 )
4193{
4194 UINT64 RetVal;
4195 CONST CHAR16 *Walker;
4196 EFI_STATUS Status;
4197 BOOLEAN Hex;
4198
4199 Hex = ForceHex;
4200
4201 if (!InternalShellIsHexOrDecimalNumber (String, Hex, StopAtSpace, FALSE)) {
4202 if (!Hex) {
4203 Hex = TRUE;
4204 if (!InternalShellIsHexOrDecimalNumber (String, Hex, StopAtSpace, FALSE)) {
4205 return (EFI_INVALID_PARAMETER);
4206 }
4207 } else {
4208 return (EFI_INVALID_PARAMETER);
4209 }
4210 }
4211
4212 //
4213 // Chop off leading spaces
4214 //
4215 for (Walker = String; Walker != NULL && *Walker != CHAR_NULL && *Walker == L' '; Walker++) {
4216 }
4217
4218 //
4219 // make sure we have something left that is numeric.
4220 //
4221 if ((Walker == NULL) || (*Walker == CHAR_NULL) || !InternalShellIsHexOrDecimalNumber (Walker, Hex, StopAtSpace, FALSE)) {
4222 return (EFI_INVALID_PARAMETER);
4223 }
4224
4225 //
4226 // do the conversion.
4227 //
4228 if (Hex || (StrnCmp (Walker, L"0x", 2) == 0) || (StrnCmp (Walker, L"0X", 2) == 0)) {
4229 Status = InternalShellStrHexToUint64 (Walker, &RetVal, StopAtSpace);
4230 } else {
4231 Status = InternalShellStrDecimalToUint64 (Walker, &RetVal, StopAtSpace);
4232 }
4233
4234 if ((Value == NULL) && !EFI_ERROR (Status)) {
4235 return (EFI_NOT_FOUND);
4236 }
4237
4238 if (Value != NULL) {
4239 *Value = RetVal;
4240 }
4241
4242 return (Status);
4243}
4244
4257BOOLEAN
4258EFIAPI
4260 IN CONST CHAR16 *String,
4261 IN CONST BOOLEAN ForceHex,
4262 IN CONST BOOLEAN StopAtSpace
4263 )
4264{
4265 if (ShellConvertStringToUint64 (String, NULL, ForceHex, StopAtSpace) == EFI_NOT_FOUND) {
4266 return (TRUE);
4267 }
4268
4269 return (FALSE);
4270}
4271
4288CHAR16 *
4289EFIAPI
4291 IN SHELL_FILE_HANDLE Handle,
4292 IN OUT BOOLEAN *Ascii
4293 )
4294{
4295 CHAR16 *RetVal;
4296 UINTN Size;
4297 EFI_STATUS Status;
4298
4299 Size = 0;
4300 RetVal = NULL;
4301
4302 Status = ShellFileHandleReadLine (Handle, RetVal, &Size, FALSE, Ascii);
4303 if (Status == EFI_BUFFER_TOO_SMALL) {
4304 RetVal = AllocateZeroPool (Size);
4305 if (RetVal == NULL) {
4306 return (NULL);
4307 }
4308
4309 Status = ShellFileHandleReadLine (Handle, RetVal, &Size, FALSE, Ascii);
4310 }
4311
4312 if ((Status == EFI_END_OF_FILE) && (RetVal != NULL) && (*RetVal != CHAR_NULL)) {
4313 Status = EFI_SUCCESS;
4314 }
4315
4316 if (EFI_ERROR (Status) && (RetVal != NULL)) {
4317 FreePool (RetVal);
4318 RetVal = NULL;
4319 }
4320
4321 return (RetVal);
4322}
4323
4362EFIAPI
4364 IN SHELL_FILE_HANDLE Handle,
4365 IN OUT CHAR16 *Buffer,
4366 IN OUT UINTN *Size,
4367 IN BOOLEAN Truncate,
4368 IN OUT BOOLEAN *Ascii
4369 )
4370{
4371 EFI_STATUS Status;
4372 CHAR16 CharBuffer;
4373 UINTN CharSize;
4374 UINTN CountSoFar;
4375 UINT64 OriginalFilePosition;
4376
4377 if ( (Handle == NULL)
4378 || (Size == NULL)
4379 )
4380 {
4381 return (EFI_INVALID_PARAMETER);
4382 }
4383
4384 if (Buffer == NULL) {
4385 ASSERT (*Size == 0);
4386 } else {
4387 *Buffer = CHAR_NULL;
4388 }
4389
4390 gEfiShellProtocol->GetFilePosition (Handle, &OriginalFilePosition);
4391 if (OriginalFilePosition == 0) {
4392 CharSize = sizeof (CHAR16);
4393 Status = gEfiShellProtocol->ReadFile (Handle, &CharSize, &CharBuffer);
4394 ASSERT_EFI_ERROR (Status);
4395 if (CharBuffer == gUnicodeFileTag) {
4396 *Ascii = FALSE;
4397 } else {
4398 *Ascii = TRUE;
4399 gEfiShellProtocol->SetFilePosition (Handle, OriginalFilePosition);
4400 }
4401 }
4402
4403 if (*Ascii) {
4404 CharSize = sizeof (CHAR8);
4405 } else {
4406 CharSize = sizeof (CHAR16);
4407 }
4408
4409 for (CountSoFar = 0; ; CountSoFar++) {
4410 CharBuffer = 0;
4411 Status = gEfiShellProtocol->ReadFile (Handle, &CharSize, &CharBuffer);
4412 if ( EFI_ERROR (Status)
4413 || (CharSize == 0)
4414 || ((CharBuffer == L'\n') && !(*Ascii))
4415 || ((CharBuffer == '\n') && *Ascii)
4416 )
4417 {
4418 if (CharSize == 0) {
4419 Status = EFI_END_OF_FILE;
4420 }
4421
4422 break;
4423 }
4424
4425 //
4426 // if we have space save it...
4427 //
4428 if ((CountSoFar+1)*sizeof (CHAR16) < *Size) {
4429 ASSERT (Buffer != NULL);
4430 ((CHAR16 *)Buffer)[CountSoFar] = CharBuffer;
4431 ((CHAR16 *)Buffer)[CountSoFar+1] = CHAR_NULL;
4432 }
4433 }
4434
4435 //
4436 // if we ran out of space tell when...
4437 //
4438 if ((CountSoFar+1)*sizeof (CHAR16) > *Size) {
4439 *Size = (CountSoFar+1)*sizeof (CHAR16);
4440 if (!Truncate) {
4441 gEfiShellProtocol->SetFilePosition (Handle, OriginalFilePosition);
4442 } else {
4443 DEBUG ((DEBUG_WARN, "The line was truncated in ShellFileHandleReadLine"));
4444 }
4445
4446 return (EFI_BUFFER_TOO_SMALL);
4447 }
4448
4449 while (Buffer[StrLen (Buffer)-1] == L'\r') {
4450 Buffer[StrLen (Buffer)-1] = CHAR_NULL;
4451 }
4452
4453 return (Status);
4454}
4455
4468EFIAPI
4470 IN CONST CHAR16 *CommandToGetHelpOn,
4471 IN CONST CHAR16 *SectionToGetHelpOn,
4472 IN BOOLEAN PrintCommandText
4473 )
4474{
4475 EFI_STATUS Status;
4476 CHAR16 *OutText;
4477
4478 OutText = NULL;
4479
4480 //
4481 // Get the string to print based
4482 //
4483 Status = gEfiShellProtocol->GetHelpText (CommandToGetHelpOn, SectionToGetHelpOn, &OutText);
4484
4485 //
4486 // make sure we got a valid string
4487 //
4488 if (EFI_ERROR (Status)) {
4489 return Status;
4490 }
4491
4492 if ((OutText == NULL) || (StrLen (OutText) == 0)) {
4493 return EFI_NOT_FOUND;
4494 }
4495
4496 //
4497 // Chop off trailing stuff we dont need
4498 //
4499 while (OutText[StrLen (OutText)-1] == L'\r' || OutText[StrLen (OutText)-1] == L'\n' || OutText[StrLen (OutText)-1] == L' ') {
4500 OutText[StrLen (OutText)-1] = CHAR_NULL;
4501 }
4502
4503 //
4504 // Print this out to the console
4505 //
4506 if (PrintCommandText) {
4507 ShellPrintEx (-1, -1, L"%H%-14s%N- %s\r\n", CommandToGetHelpOn, OutText);
4508 } else {
4509 ShellPrintEx (-1, -1, L"%N%s\r\n", OutText);
4510 }
4511
4512 SHELL_FREE_NON_NULL (OutText);
4513
4514 return EFI_SUCCESS;
4515}
4516
4541EFIAPI
4543 IN CONST CHAR16 *FileName
4544 )
4545{
4546 EFI_STATUS Status;
4547 SHELL_FILE_HANDLE FileHandle;
4548
4549 Status = ShellFileExists (FileName);
4550
4551 if (Status == EFI_SUCCESS) {
4552 Status = ShellOpenFileByName (FileName, &FileHandle, EFI_FILE_MODE_READ | EFI_FILE_MODE_WRITE | EFI_FILE_MODE_CREATE, 0x0);
4553 if (Status == EFI_SUCCESS) {
4554 Status = ShellDeleteFile (&FileHandle);
4555 }
4556 }
4557
4558 return (Status);
4559}
4560
4573 IN CONST CHAR16 *OriginalString,
4574 OUT CHAR16 **CleanString
4575 )
4576{
4577 CHAR16 *Walker;
4578
4579 if ((OriginalString == NULL) || (CleanString == NULL)) {
4580 return EFI_INVALID_PARAMETER;
4581 }
4582
4583 *CleanString = AllocateCopyPool (StrSize (OriginalString), OriginalString);
4584 if (*CleanString == NULL) {
4585 return EFI_OUT_OF_RESOURCES;
4586 }
4587
4588 for (Walker = *CleanString; Walker != NULL && *Walker != CHAR_NULL; Walker++) {
4589 if (*Walker == L'\"') {
4590 CopyMem (Walker, Walker+1, StrSize (Walker) - sizeof (Walker[0]));
4591 }
4592 }
4593
4594 return EFI_SUCCESS;
4595}
UINT64 UINTN
BOOLEAN EFIAPI IsNull(IN CONST LIST_ENTRY *List, IN CONST LIST_ENTRY *Node)
Definition: LinkedList.c:443
UINTN EFIAPI StrSize(IN CONST CHAR16 *String)
Definition: String.c:72
BOOLEAN EFIAPI IsListEmpty(IN CONST LIST_ENTRY *ListHead)
Definition: LinkedList.c:403
RETURN_STATUS EFIAPI StrCpyS(OUT CHAR16 *Destination, IN UINTN DestMax, IN CONST CHAR16 *Source)
Definition: SafeString.c:226
CHAR16 EFIAPI CharToUpper(IN CHAR16 Char)
Definition: String.c:307
LIST_ENTRY *EFIAPI GetNextNode(IN CONST LIST_ENTRY *List, IN CONST LIST_ENTRY *Node)
Definition: LinkedList.c:333
UINT64 EFIAPI DivU64x32(IN UINT64 Dividend, IN UINT32 Divisor)
Definition: DivU64x32.c:29
INTN EFIAPI StrCmp(IN CONST CHAR16 *FirstString, IN CONST CHAR16 *SecondString)
Definition: String.c:109
LIST_ENTRY *EFIAPI InsertHeadList(IN OUT LIST_ENTRY *ListHead, IN OUT LIST_ENTRY *Entry)
Definition: LinkedList.c:218
LIST_ENTRY *EFIAPI GetFirstNode(IN CONST LIST_ENTRY *List)
Definition: LinkedList.c:298
RETURN_STATUS EFIAPI StrCatS(IN OUT CHAR16 *Destination, IN UINTN DestMax, IN CONST CHAR16 *Source)
Definition: SafeString.c:405
INTN EFIAPI StrnCmp(IN CONST CHAR16 *FirstString, IN CONST CHAR16 *SecondString, IN UINTN Length)
Definition: String.c:162
LIST_ENTRY *EFIAPI RemoveEntryList(IN CONST LIST_ENTRY *Entry)
Definition: LinkedList.c:590
UINT64 EFIAPI RShiftU64(IN UINT64 Operand, IN UINTN Count)
Definition: RShiftU64.c:28
UINT64 EFIAPI MultU64x32(IN UINT64 Multiplicand, IN UINT32 Multiplier)
Definition: MultU64x32.c:27
CHAR16 *EFIAPI PathCleanUpDirectories(IN CHAR16 *Path)
Definition: FilePaths.c:68
BOOLEAN EFIAPI PathRemoveLastItem(IN OUT CHAR16 *Path)
Definition: FilePaths.c:22
LIST_ENTRY *EFIAPI InitializeListHead(IN OUT LIST_ENTRY *ListHead)
Definition: LinkedList.c:182
RETURN_STATUS EFIAPI StrnCatS(IN OUT CHAR16 *Destination, IN UINTN DestMax, IN CONST CHAR16 *Source, IN UINTN Length)
Definition: SafeString.c:507
UINT64 EFIAPI LShiftU64(IN UINT64 Operand, IN UINTN Count)
Definition: LShiftU64.c:28
UINTN EFIAPI StrLen(IN CONST CHAR16 *String)
Definition: String.c:30
CHAR16 *EFIAPI StrStr(IN CONST CHAR16 *String, IN CONST CHAR16 *SearchString)
Definition: String.c:224
LIST_ENTRY *EFIAPI InsertTailList(IN OUT LIST_ENTRY *ListHead, IN OUT LIST_ENTRY *Entry)
Definition: LinkedList.c:259
VOID *EFIAPI CopyMem(OUT VOID *DestinationBuffer, IN CONST VOID *SourceBuffer, IN UINTN Length)
BOOLEAN EFIAPI CompareGuid(IN CONST GUID *Guid1, IN CONST GUID *Guid2)
Definition: MemLibGuid.c:73
VOID *EFIAPI ZeroMem(OUT VOID *Buffer, IN UINTN Length)
#define SHELL_FILE_ARG_SIGNATURE
Signature for SHELL_FILE_ARG.
VOID *EFIAPI ReallocatePool(IN UINTN OldSize, IN UINTN NewSize, IN VOID *OldBuffer OPTIONAL)
VOID *EFIAPI AllocateZeroPool(IN UINTN AllocationSize)
VOID EFIAPI FreePool(IN VOID *Buffer)
VOID *EFIAPI AllocateCopyPool(IN UINTN AllocationSize, IN CONST VOID *Buffer)
EFI_STATUS EFIAPI FileHandleFlush(IN EFI_FILE_HANDLE FileHandle)
EFI_STATUS EFIAPI FileHandleSetInfo(IN EFI_FILE_HANDLE FileHandle, IN CONST EFI_FILE_INFO *FileInfo)
EFI_STATUS EFIAPI FileHandleGetPosition(IN EFI_FILE_HANDLE FileHandle, OUT UINT64 *Position)
EFI_STATUS EFIAPI FileHandleSetPosition(IN EFI_FILE_HANDLE FileHandle, IN UINT64 Position)
EFI_FILE_INFO *EFIAPI FileHandleGetInfo(IN EFI_FILE_HANDLE FileHandle)
EFI_STATUS EFIAPI FileHandleIsDirectory(IN EFI_FILE_HANDLE DirHandle)
EFI_STATUS EFIAPI FileHandleFindNextFile(IN EFI_FILE_HANDLE DirHandle, OUT EFI_FILE_INFO *Buffer, OUT BOOLEAN *NoFile)
EFI_STATUS EFIAPI FileHandleClose(IN EFI_FILE_HANDLE FileHandle)
EFI_STATUS EFIAPI FileHandleGetSize(IN EFI_FILE_HANDLE FileHandle, OUT UINT64 *Size)
EFI_STATUS EFIAPI FileHandleDelete(IN EFI_FILE_HANDLE FileHandle)
EFI_STATUS EFIAPI FileHandleFindFirstFile(IN EFI_FILE_HANDLE DirHandle, OUT EFI_FILE_INFO **Buffer)
EFI_STATUS EFIAPI FileHandleWrite(IN EFI_FILE_HANDLE FileHandle, IN OUT UINTN *BufferSize, IN VOID *Buffer)
EFI_STATUS EFIAPI FileHandleRead(IN EFI_FILE_HANDLE FileHandle, IN OUT UINTN *BufferSize, OUT VOID *Buffer)
CONST UINT16 gUnicodeFileTag
EFI_STRING EFIAPI HiiGetString(IN EFI_HII_HANDLE HiiHandle, IN EFI_STRING_ID StringId, IN CONST CHAR8 *Language OPTIONAL)
Definition: HiiString.c:211
UINTN EFIAPI UnicodeVSPrint(OUT CHAR16 *StartOfBuffer, IN UINTN BufferSize, IN CONST CHAR16 *FormatString, IN VA_LIST Marker)
Definition: PrintLib.c:287
UINTN EFIAPI UnicodeSPrint(OUT CHAR16 *StartOfBuffer, IN UINTN BufferSize, IN CONST CHAR16 *FormatString,...)
Definition: PrintLib.c:408
#define NULL
Definition: Base.h:319
#define CONST
Definition: Base.h:259
#define VA_START(Marker, Parameter)
Definition: Base.h:661
#define TRUE
Definition: Base.h:301
#define FALSE
Definition: Base.h:307
CHAR8 * VA_LIST
Definition: Base.h:643
#define IN
Definition: Base.h:279
#define OUT
Definition: Base.h:284
#define VA_END(Marker)
Definition: Base.h:691
#define ASSERT_EFI_ERROR(StatusParameter)
Definition: DebugLib.h:462
#define DEBUG(Expression)
Definition: DebugLib.h:434
#define CR(Record, TYPE, Field, TestSignature)
Definition: DebugLib.h:659
EFI_FILE_INFO *(EFIAPI * EFI_SHELL_GET_FILE_INFO)(IN SHELL_FILE_HANDLE FileHandle)
Definition: Shell.h:584
EFI_STATUS(EFIAPI * EFI_SHELL_SET_FILE_INFO)(IN SHELL_FILE_HANDLE FileHandle, IN CONST EFI_FILE_INFO *FileInfo)
Definition: Shell.h:1102
EFI_STATUS(EFIAPI * EFI_SHELL_CLOSE_FILE)(IN SHELL_FILE_HANDLE FileHandle)
Definition: Shell.h:187
EFI_STATUS(EFIAPI * EFI_SHELL_WRITE_FILE)(IN SHELL_FILE_HANDLE FileHandle, IN OUT UINTN *BufferSize, IN VOID *Buffer)
Definition: Shell.h:1174
EFI_STATUS(EFIAPI * EFI_SHELL_GET_FILE_POSITION)(IN SHELL_FILE_HANDLE FileHandle, OUT UINT64 *Position)
Definition: Shell.h:621
EFI_STATUS(EFIAPI * EFI_SHELL_DELETE_FILE)(IN SHELL_FILE_HANDLE FileHandle)
Definition: Shell.h:249
EFI_STATUS(EFIAPI * EFI_SHELL_READ_FILE)(IN SHELL_FILE_HANDLE FileHandle, IN OUT UINTN *ReadSize, IN OUT VOID *Buffer)
Definition: Shell.h:928
EFI_STATUS(EFIAPI * EFI_SHELL_SET_FILE_POSITION)(IN SHELL_FILE_HANDLE FileHandle, IN UINT64 Position)
Definition: Shell.h:1124
EFI_STATUS(EFIAPI * EFI_SHELL_GET_FILE_SIZE)(IN SHELL_FILE_HANDLE FileHandle, OUT UINT64 *Size)
Definition: Shell.h:639
EFI_STATUS(EFIAPI * EFI_SHELL_FLUSH_FILE)(IN SHELL_FILE_HANDLE FileHandle)
Definition: Shell.h:391
#define PcdGet32(TokenName)
Definition: PcdLib.h:362
#define PcdGetBool(TokenName)
Definition: PcdLib.h:401
EFI_FILE_INFO * FileInfo(IN EFI_FILE_HANDLE FHand)
EFI_STRING_ID NewString(IN CHAR16 *String, IN EFI_HII_HANDLE HiiHandle)
Definition: Setup.c:981
SHELL_PROMPT_REQUEST_TYPE
Definition: ShellLib.h:1184
SHELL_PARAM_TYPE
Definition: ShellLib.h:698
@ TypeStart
A flag that has variable value appended to the end (IE "-ad", "-afd", "-adf", etc....
Definition: ShellLib.h:702
@ TypeValue
A flag that has some data following it with a space (IE "-a 1").
Definition: ShellLib.h:700
@ TypeTimeValue
A flag that has a time value following it (IE "-a -5:00").
Definition: ShellLib.h:705
@ TypeMaxValue
A flag followed by all the command line data before the next flag.
Definition: ShellLib.h:704
@ TypeDoubleValue
A flag that has 2 space seperated value data following it (IE "-a 1 2").
Definition: ShellLib.h:703
@ TypeFlag
A flag that is present or not present only (IE "-a").
Definition: ShellLib.h:699
@ TypePosition
Some data that did not follow a parameter (IE "filename.txt").
Definition: ShellLib.h:701
SHELL_PROMPT_RESPONSE
Definition: ShellLib.h:1198
INTN EFIAPI StringNoCaseCompare(IN CONST VOID *Buffer1, IN CONST VOID *Buffer2)
Definition: BaseSortLib.c:92
RETURN_STATUS EFI_STATUS
Definition: UefiBaseType.h:29
VOID * EFI_HANDLE
Definition: UefiBaseType.h:33
#define EFI_SUCCESS
Definition: UefiBaseType.h:112
EFI_SYSTEM_TABLE * gST
EFI_HANDLE gImageHandle
EFI_BOOT_SERVICES * gBS
VOID * EFI_HII_HANDLE
EFI_STATUS EFIAPI EfiOpenFileByDevicePath(IN OUT EFI_DEVICE_PATH_PROTOCOL **FilePath, OUT EFI_FILE_PROTOCOL **File, IN UINT64 OpenMode, IN UINT64 Attributes)
Definition: UefiLib.c:1806
EFI_STATUS EFIAPI ShellPrintHelp(IN CONST CHAR16 *CommandToGetHelpOn, IN CONST CHAR16 *SectionToGetHelpOn, IN BOOLEAN PrintCommandText)
EFI_STATUS EFIAPI ShellGetFileSize(IN SHELL_FILE_HANDLE FileHandle, OUT UINT64 *Size)
CONST CHAR16 *EFIAPI ShellGetCurrentDir(IN CHAR16 *CONST DeviceName OPTIONAL)
BOOLEAN EFIAPI ShellIsHexaDecimalDigitCharacter(IN CHAR16 Char)
Definition: UefiShellLib.c:171
CHAR16 *EFIAPI ShellFileHandleReturnLine(IN SHELL_FILE_HANDLE Handle, IN OUT BOOLEAN *Ascii)
BOOLEAN InternalShellIsHexOrDecimalNumber(IN CONST CHAR16 *String, IN CONST BOOLEAN ForceHex, IN CONST BOOLEAN StopAtSpace, IN CONST BOOLEAN TimeNumbers)
CHAR16 *EFIAPI FullyQualifyPath(IN CONST CHAR16 *Path)
Definition: UefiShellLib.c:64
CONST CHAR16 *EFIAPI ShellCommandLineGetValue(IN CONST LIST_ENTRY *CheckPackage, IN CHAR16 *KeyString)
EFI_STATUS EFIAPI ShellOpenFileByDevicePath(IN OUT EFI_DEVICE_PATH_PROTOCOL **FilePath, OUT SHELL_FILE_HANDLE *FileHandle, IN UINT64 OpenMode, IN UINT64 Attributes)
Definition: UefiShellLib.c:640
EFI_FILE_INFO *EFIAPI ShellGetFileInfo(IN SHELL_FILE_HANDLE FileHandle)
Definition: UefiShellLib.c:573
EFI_STATUS EFIAPI ShellSetEnvironmentVariable(IN CONST CHAR16 *EnvKey, IN CONST CHAR16 *EnvVal, IN BOOLEAN Volatile)
EFI_STATUS EFIAPI ShellSetFileInfo(IN SHELL_FILE_HANDLE FileHandle, IN EFI_FILE_INFO *FileInfo)
Definition: UefiShellLib.c:601
EFI_STATUS EFIAPI ShellDeleteFile(IN SHELL_FILE_HANDLE *FileHandle)
Definition: UefiShellLib.c:992
EFI_STATUS ShellLibConstructorWorker(IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable)
Definition: UefiShellLib.c:300
EFI_STATUS EFIAPI ShellCopySearchAndReplace(IN CHAR16 CONST *SourceString, IN OUT CHAR16 *NewString, IN UINTN NewSize, IN CONST CHAR16 *FindTarget, IN CONST CHAR16 *ReplaceWith, IN CONST BOOLEAN SkipPreCarrot, IN CONST BOOLEAN ParameterReplacing)
UINTN EFIAPI ShellStrToUintn(IN CONST CHAR16 *String)
BOOLEAN EFIAPI ShellGetExecutionBreakFlag(VOID)
VOID EFIAPI ShellSetPageBreakMode(IN BOOLEAN CurrentState)
EFI_STATUS EFIAPI ShellDeleteFileByName(IN CONST CHAR16 *FileName)
EFI_STATUS InternalShellPrintWorker(IN INT32 Col OPTIONAL, IN INT32 Row OPTIONAL, IN CONST CHAR16 *Format, IN VA_LIST Marker)
EFI_STATUS EFIAPI ShellPromptForResponseHii(IN SHELL_PROMPT_REQUEST_TYPE Type, IN CONST EFI_STRING_ID HiiFormatStringId, IN CONST EFI_HII_HANDLE HiiFormatHandle, IN OUT VOID **Response)
EFI_STATUS EFIAPI ShellCreateDirectory(IN CONST CHAR16 *DirectoryName, OUT SHELL_FILE_HANDLE *FileHandle)
Definition: UefiShellLib.c:857
EFI_STATUS EFIAPI ShellCloseFileMetaArg(IN OUT EFI_SHELL_FILE_INFO **ListHead)
EFI_STATUS EFIAPI ShellExecute(IN EFI_HANDLE *ParentHandle, IN CHAR16 *CommandLine OPTIONAL, IN BOOLEAN Output OPTIONAL, IN CHAR16 **EnvironmentVariables OPTIONAL, OUT EFI_STATUS *Status OPTIONAL)
EFI_STATUS EFIAPI ShellPrintHiiEx(IN INT32 Col OPTIONAL, IN INT32 Row OPTIONAL, IN CONST CHAR8 *Language OPTIONAL, IN CONST EFI_STRING_ID HiiFormatStringId, IN CONST EFI_HII_HANDLE HiiFormatHandle,...)
BOOLEAN EFIAPI ShellCommandLineGetFlag(IN CONST LIST_ENTRY *CONST CheckPackage, IN CONST CHAR16 *CONST KeyString)
LIST_ENTRY * InternalShellConvertFileListType(IN LIST_ENTRY *FileList, IN OUT LIST_ENTRY *ListHead)
BOOLEAN EFIAPI ShellIsHexOrDecimalNumber(IN CONST CHAR16 *String, IN CONST BOOLEAN ForceHex, IN CONST BOOLEAN StopAtSpace)
EFI_STATUS InternalCommandLineParse(IN CONST SHELL_PARAM_ITEM *CheckList, OUT LIST_ENTRY **CheckPackage, OUT CHAR16 **ProblemParam OPTIONAL, IN BOOLEAN AutoPageBreak, IN CONST CHAR16 **Argv, IN UINTN Argc, IN BOOLEAN AlwaysAllowNumbers)
EFI_STATUS EFIAPI ShellOpenFileByName(IN CONST CHAR16 *FileName, OUT SHELL_FILE_HANDLE *FileHandle, IN UINT64 OpenMode, IN UINT64 Attributes)
Definition: UefiShellLib.c:720
BOOLEAN EFIAPI ShellIsDecimalDigitCharacter(IN CHAR16 Char)
Definition: UefiShellLib.c:194
SHELL_PARAM_ITEM SfoParamList[]
Helper structure for -sfo only (besides -? and -b)
Definition: UefiShellLib.c:22
BOOLEAN InternalIsFlag(IN CONST CHAR16 *Name, IN CONST BOOLEAN AlwaysAllowNumbers, IN CONST BOOLEAN TimeNumbers)
CHAR16 *EFIAPI StrnCatGrow(IN OUT CHAR16 **Destination, IN OUT UINTN *CurrentSize, IN CONST CHAR16 *Source, IN UINTN Count)
EFI_STATUS EFIAPI ShellFindFirstFile(IN SHELL_FILE_HANDLE DirHandle, OUT EFI_FILE_INFO **Buffer)
CHAR16 *EFIAPI ShellFindFilePathEx(IN CONST CHAR16 *FileName, IN CONST CHAR16 *FileExtension)
EFI_STATUS EFIAPI ShellPromptForResponse(IN SHELL_PROMPT_REQUEST_TYPE Type, IN CHAR16 *Prompt OPTIONAL, IN OUT VOID **Response OPTIONAL)
EFI_STATUS EFIAPI ShellCommandLineCheckDuplicate(IN CONST LIST_ENTRY *CheckPackage, OUT CHAR16 **Param)
UINTN InternalShellHexCharToUintn(IN CHAR16 Char)
EFI_STATUS InternalShellStripQuotes(IN CONST CHAR16 *OriginalString, OUT CHAR16 **CleanString)
EFI_STATUS EFIAPI ShellFindNextFile(IN SHELL_FILE_HANDLE DirHandle, OUT EFI_FILE_INFO *Buffer, OUT BOOLEAN *NoFile)
CONST CHAR16 *EFIAPI ShellGetEnvironmentVariable(IN CONST CHAR16 *EnvKey)
EFI_STATUS EFIAPI ShellFileExists(IN CONST CHAR16 *Name)
EFI_STATUS EFIAPI ShellFileHandleReadLine(IN SHELL_FILE_HANDLE Handle, IN OUT CHAR16 *Buffer, IN OUT UINTN *Size, IN BOOLEAN Truncate, IN OUT BOOLEAN *Ascii)
EFI_STATUS EFIAPI ShellOpenFileMetaArg(IN CHAR16 *Arg, IN UINT64 OpenMode, IN OUT EFI_SHELL_FILE_INFO **ListHead)
EFI_STATUS EFIAPI ShellCommandLineParseEx(IN CONST SHELL_PARAM_ITEM *CheckList, OUT LIST_ENTRY **CheckPackage, OUT CHAR16 **ProblemParam OPTIONAL, IN BOOLEAN AutoPageBreak, IN BOOLEAN AlwaysAllowNumbers)
EFI_STATUS InternalShellStrHexToUint64(IN CONST CHAR16 *String, OUT UINT64 *Value, IN CONST BOOLEAN StopAtSpace)
VOID EFIAPI ShellCommandLineFreeVarList(IN LIST_ENTRY *CheckPackage)
EFI_STATUS EFIAPI ShellInitialize(VOID)
Definition: UefiShellLib.c:532
UINTN EFIAPI ShellHexStrToUintn(IN CONST CHAR16 *String)
EFI_STATUS EFIAPI ShellIsFile(IN CONST CHAR16 *Name)
EFI_STATUS EFIAPI ShellIsDirectory(IN CONST CHAR16 *DirName)
EFI_STATUS EFIAPI ShellReadFile(IN SHELL_FILE_HANDLE FileHandle, IN OUT UINTN *BufferSize, OUT VOID *Buffer)
Definition: UefiShellLib.c:912
EFI_STATUS EFIAPI ShellGetFilePosition(IN SHELL_FILE_HANDLE FileHandle, OUT UINT64 *Position)
EFI_STATUS EFIAPI ShellSetFilePosition(IN SHELL_FILE_HANDLE FileHandle, IN UINT64 Position)
EFI_STATUS InternalPrintTo(IN CONST CHAR16 *String)
BOOLEAN InternalIsOnCheckList(IN CONST CHAR16 *Name, IN CONST SHELL_PARAM_ITEM *CheckList, OUT SHELL_PARAM_TYPE *Type)
CHAR16 *EFIAPI ShellFindFilePath(IN CONST CHAR16 *FileName)
EFI_STATUS EFIAPI ShellLibConstructor(IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable)
Definition: UefiShellLib.c:425
EFI_STATUS EFIAPI ShellPrintEx(IN INT32 Col OPTIONAL, IN INT32 Row OPTIONAL, IN CONST CHAR16 *Format,...)
EFI_STATUS EFIAPI ShellIsFileInPath(IN CONST CHAR16 *Name)
EFI_STATUS EFIAPI ShellLibDestructor(IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable)
Definition: UefiShellLib.c:458
CONST CHAR16 *EFIAPI ShellCommandLineGetRawValue(IN CONST LIST_ENTRY *CONST CheckPackage, IN UINTN Position)
UINTN EFIAPI ShellCommandLineGetCount(IN CONST LIST_ENTRY *CheckPackage)
EFI_STATUS EFIAPI ShellConvertStringToUint64(IN CONST CHAR16 *String, OUT UINT64 *Value, IN CONST BOOLEAN ForceHex, IN CONST BOOLEAN StopAtSpace)
SHELL_PARAM_ITEM EmptyParamList[]
Helper structure for no parameters (besides -? and -b)
Definition: UefiShellLib.c:19
EFI_STATUS ShellFindSE2(IN EFI_HANDLE ImageHandle)
Definition: UefiShellLib.c:209
EFI_STATUS EFIAPI ShellFlushFile(IN SHELL_FILE_HANDLE FileHandle)
EFI_STATUS InternalShellStrDecimalToUint64(IN CONST CHAR16 *String, OUT UINT64 *Value, IN CONST BOOLEAN StopAtSpace)
EFI_STATUS EFIAPI ShellWriteFile(IN SHELL_FILE_HANDLE FileHandle, IN OUT UINTN *BufferSize, IN VOID *Buffer)
Definition: UefiShellLib.c:947
EFI_STATUS EFIAPI ShellCloseFile(IN SHELL_FILE_HANDLE *FileHandle)
Definition: UefiShellLib.c:969
@ ByProtocol
Definition: UefiSpec.h:1518
EFI_SIMPLE_TEXT_OUTPUT_MODE * Mode
UINT64 Size
Definition: FileInfo.h:23
UINT64 Attribute
Definition: FileInfo.h:47
EFI_SHELL_ENVIRONMENT2 protocol structure.
EFI_STATUS Status
Status of opening the file. Valid only if Handle != NULL.
CHAR16 * FileName
name of this file.
EFI_FILE_INFO * Info
Pointer to the FileInfo struct for this file or NULL.
SHELL_FILE_HANDLE Handle
Handle for interacting with the opened file or NULL if closed.
CHAR16 * FullName
Fully qualified filename.
LIST_ENTRY Link
Linked list members.
EFI_SIMPLE_TEXT_INPUT_PROTOCOL * ConIn
Definition: UefiSpec.h:2053
EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL * ConOut
Definition: UefiSpec.h:2064
EFI_STATUS Status
File's status.
CHAR16 * FullName
Path and file name for this file.
EFI_FILE_HANDLE Handle
Handle to this file.
EFI_FILE_INFO * Info
Pointer to file info for this file.
CHAR16 * FileName
File name for this file.