Changeset 99404 in vbox for trunk/src/VBox/Devices/EFI/FirmwareNew/ShellPkg/Application/Shell/ShellParametersProtocol.c
- Timestamp:
- Apr 14, 2023 3:17:44 PM (22 months ago)
- svn:sync-xref-src-repo-rev:
- 156854
- Location:
- trunk/src/VBox/Devices/EFI/FirmwareNew
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Devices/EFI/FirmwareNew
-
Property svn:mergeinfo
changed from (toggle deleted branches)
to (toggle deleted branches)/vendor/edk2/current 103735-103757,103769-103776,129194-145445 /vendor/edk2/current 103735-103757,103769-103776,129194-156846
-
Property svn:mergeinfo
changed from (toggle deleted branches)
-
trunk/src/VBox/Devices/EFI/FirmwareNew/ShellPkg/Application/Shell/ShellParametersProtocol.c
r85718 r99404 13 13 #include "Shell.h" 14 14 15 BOOLEAN AsciiRedirection = FALSE;15 BOOLEAN AsciiRedirection = FALSE; 16 16 17 17 /** … … 20 20 @param[in] String the string to parse 21 21 **/ 22 CONST CHAR16 *23 FindEndOfParameter (24 IN CONST CHAR16 *String22 CONST CHAR16 * 23 FindEndOfParameter ( 24 IN CONST CHAR16 *String 25 25 ) 26 26 { 27 CONST CHAR16 *First;28 CONST CHAR16 *CloseQuote;29 30 First = FindFirstCharacter (String, L" \"", L'^');27 CONST CHAR16 *First; 28 CONST CHAR16 *CloseQuote; 29 30 First = FindFirstCharacter (String, L" \"", L'^'); 31 31 32 32 // … … 80 80 **/ 81 81 EFI_STATUS 82 GetNextParameter (82 GetNextParameter ( 83 83 IN OUT CHAR16 **Walker, 84 84 IN OUT CHAR16 **TempParameter, … … 87 87 ) 88 88 { 89 CONST CHAR16 *NextDelim; 90 91 if (Walker == NULL 92 ||*Walker == NULL 93 ||TempParameter == NULL 94 ||*TempParameter == NULL 95 ){ 89 CONST CHAR16 *NextDelim; 90 91 if ( (Walker == NULL) 92 || (*Walker == NULL) 93 || (TempParameter == NULL) 94 || (*TempParameter == NULL) 95 ) 96 { 96 97 return (EFI_INVALID_PARAMETER); 97 98 } 98 99 99 100 100 // 101 101 // make sure we dont have any leading spaces 102 102 // 103 103 while ((*Walker)[0] == L' ') { 104 104 (*Walker)++; 105 105 } 106 106 … … 108 108 // make sure we still have some params now... 109 109 // 110 if (StrLen (*Walker) == 0) {111 DEBUG_CODE_BEGIN();112 *Walker 113 DEBUG_CODE_END();110 if (StrLen (*Walker) == 0) { 111 DEBUG_CODE_BEGIN (); 112 *Walker = NULL; 113 DEBUG_CODE_END (); 114 114 return (EFI_INVALID_PARAMETER); 115 115 } 116 116 117 NextDelim = FindEndOfParameter (*Walker);118 119 if (NextDelim == NULL) {120 DEBUG_CODE_BEGIN();121 *Walker 122 DEBUG_CODE_END();117 NextDelim = FindEndOfParameter (*Walker); 118 119 if (NextDelim == NULL) { 120 DEBUG_CODE_BEGIN (); 121 *Walker = NULL; 122 DEBUG_CODE_END (); 123 123 return (EFI_NOT_FOUND); 124 124 } 125 125 126 StrnCpyS (*TempParameter, Length / sizeof(CHAR16), (*Walker), NextDelim - *Walker);126 StrnCpyS (*TempParameter, Length / sizeof (CHAR16), (*Walker), NextDelim - *Walker); 127 127 128 128 // … … 136 136 // Update Walker for the next iteration through the function 137 137 // 138 *Walker = (CHAR16 *)NextDelim;138 *Walker = (CHAR16 *)NextDelim; 139 139 140 140 // … … 142 142 // Remove any remaining escape characters in the string 143 143 // 144 for (NextDelim = FindFirstCharacter(*TempParameter, L"\"^", CHAR_NULL) 145 ; *NextDelim != CHAR_NULL 146 ; NextDelim = FindFirstCharacter(NextDelim, L"\"^", CHAR_NULL) 147 ) { 144 for (NextDelim = FindFirstCharacter (*TempParameter, L"\"^", CHAR_NULL) 145 ; *NextDelim != CHAR_NULL 146 ; NextDelim = FindFirstCharacter (NextDelim, L"\"^", CHAR_NULL) 147 ) 148 { 148 149 if (*NextDelim == L'^') { 149 150 150 // 151 151 // eliminate the escape ^ 152 152 // 153 CopyMem ((CHAR16 *)NextDelim, NextDelim + 1, StrSize (NextDelim + 1));153 CopyMem ((CHAR16 *)NextDelim, NextDelim + 1, StrSize (NextDelim + 1)); 154 154 NextDelim++; 155 155 } else if (*NextDelim == L'\"') { 156 157 156 // 158 157 // eliminate the unescaped quote 159 158 // 160 159 if (StripQuotation) { 161 CopyMem ((CHAR16 *)NextDelim, NextDelim + 1, StrSize (NextDelim + 1));162 } else{160 CopyMem ((CHAR16 *)NextDelim, NextDelim + 1, StrSize (NextDelim + 1)); 161 } else { 163 162 NextDelim++; 164 }163 } 165 164 } 166 165 } … … 190 189 **/ 191 190 EFI_STATUS 192 ParseCommandLineToArgs (193 IN CONST CHAR16 *CommandLine,194 IN BOOLEAN StripQuotation,195 IN OUT CHAR16 ***Argv,196 IN OUT UINTN *Argc191 ParseCommandLineToArgs ( 192 IN CONST CHAR16 *CommandLine, 193 IN BOOLEAN StripQuotation, 194 IN OUT CHAR16 ***Argv, 195 IN OUT UINTN *Argc 197 196 ) 198 197 { … … 205 204 EFI_STATUS Status; 206 205 207 ASSERT (Argc != NULL);208 ASSERT (Argv != NULL);209 210 if ( CommandLine == NULL || StrLen(CommandLine)==0) {206 ASSERT (Argc != NULL); 207 ASSERT (Argv != NULL); 208 209 if ((CommandLine == NULL) || (StrLen (CommandLine) == 0)) { 211 210 (*Argc) = 0; 212 211 (*Argv) = NULL; … … 214 213 } 215 214 216 NewCommandLine = AllocateCopyPool (StrSize(CommandLine), CommandLine);217 if (NewCommandLine == NULL) {215 NewCommandLine = AllocateCopyPool (StrSize (CommandLine), CommandLine); 216 if (NewCommandLine == NULL) { 218 217 return (EFI_OUT_OF_RESOURCES); 219 218 } 220 219 221 TrimSpaces (&NewCommandLine);222 Size = StrSize(NewCommandLine);223 TempParameter = AllocateZeroPool (Size);220 TrimSpaces (&NewCommandLine); 221 Size = StrSize (NewCommandLine); 222 TempParameter = AllocateZeroPool (Size); 224 223 if (TempParameter == NULL) { 225 SHELL_FREE_NON_NULL (NewCommandLine);224 SHELL_FREE_NON_NULL (NewCommandLine); 226 225 return (EFI_OUT_OF_RESOURCES); 227 226 } 228 227 229 for ( Count = 0 230 , Walker = (CHAR16*)NewCommandLine 231 ; Walker != NULL && *Walker != CHAR_NULL 232 ; Count++ 233 ) { 234 if (EFI_ERROR(GetNextParameter(&Walker, &TempParameter, Size, TRUE))) { 228 for ( Count = 0, 229 Walker = (CHAR16 *)NewCommandLine 230 ; Walker != NULL && *Walker != CHAR_NULL 231 ; Count++ 232 ) 233 { 234 if (EFI_ERROR (GetNextParameter (&Walker, &TempParameter, Size, TRUE))) { 235 235 break; 236 236 } … … 240 240 // lets allocate the pointer array 241 241 // 242 (*Argv) = AllocateZeroPool ((Count)*sizeof(CHAR16*));242 (*Argv) = AllocateZeroPool ((Count)*sizeof (CHAR16 *)); 243 243 if (*Argv == NULL) { 244 244 Status = EFI_OUT_OF_RESOURCES; … … 246 246 } 247 247 248 *Argc = 0;249 Walker = (CHAR16 *)NewCommandLine;250 while (Walker != NULL && *Walker != CHAR_NULL) {251 SetMem16 (TempParameter, Size, CHAR_NULL);252 if (EFI_ERROR (GetNextParameter(&Walker, &TempParameter, Size, StripQuotation))) {248 *Argc = 0; 249 Walker = (CHAR16 *)NewCommandLine; 250 while (Walker != NULL && *Walker != CHAR_NULL) { 251 SetMem16 (TempParameter, Size, CHAR_NULL); 252 if (EFI_ERROR (GetNextParameter (&Walker, &TempParameter, Size, StripQuotation))) { 253 253 Status = EFI_INVALID_PARAMETER; 254 254 goto Done; 255 255 } 256 256 257 NewParam = AllocateCopyPool (StrSize(TempParameter), TempParameter);258 if (NewParam == NULL) {257 NewParam = AllocateCopyPool (StrSize (TempParameter), TempParameter); 258 if (NewParam == NULL) { 259 259 Status = EFI_OUT_OF_RESOURCES; 260 260 goto Done; 261 261 } 262 ((CHAR16**)(*Argv))[(*Argc)] = NewParam; 262 263 ((CHAR16 **)(*Argv))[(*Argc)] = NewParam; 263 264 (*Argc)++; 264 265 } 265 ASSERT(Count >= (*Argc)); 266 267 ASSERT (Count >= (*Argc)); 266 268 Status = EFI_SUCCESS; 267 269 268 270 Done: 269 SHELL_FREE_NON_NULL (TempParameter);270 SHELL_FREE_NON_NULL (NewCommandLine);271 SHELL_FREE_NON_NULL (TempParameter); 272 SHELL_FREE_NON_NULL (NewCommandLine); 271 273 return (Status); 272 274 } … … 294 296 ) 295 297 { 296 EFI_STATUS Status;297 EFI_LOADED_IMAGE_PROTOCOL *LoadedImage;298 CHAR16 *FullCommandLine;299 UINTN Size;300 301 Size = 0;298 EFI_STATUS Status; 299 EFI_LOADED_IMAGE_PROTOCOL *LoadedImage; 300 CHAR16 *FullCommandLine; 301 UINTN Size; 302 303 Size = 0; 302 304 FullCommandLine = NULL; 303 LoadedImage = NULL;305 LoadedImage = NULL; 304 306 305 307 // 306 308 // Assert for valid parameters 307 309 // 308 ASSERT (NewShellParameters != NULL);309 ASSERT (RootShellInstance != NULL);310 ASSERT (NewShellParameters != NULL); 311 ASSERT (RootShellInstance != NULL); 310 312 311 313 // … … 313 315 // 314 316 Status = gBS->OpenProtocol ( 315 gImageHandle,316 &gEfiShellParametersProtocolGuid,317 (VOID **)&ShellInfoObject.OldShellParameters,318 gImageHandle,319 NULL,320 EFI_OPEN_PROTOCOL_GET_PROTOCOL321 );317 gImageHandle, 318 &gEfiShellParametersProtocolGuid, 319 (VOID **)&ShellInfoObject.OldShellParameters, 320 gImageHandle, 321 NULL, 322 EFI_OPEN_PROTOCOL_GET_PROTOCOL 323 ); 322 324 // 323 325 // if we don't then we must be the root shell (error is expected) … … 330 332 // Allocate the new structure 331 333 // 332 *NewShellParameters = AllocateZeroPool (sizeof(EFI_SHELL_PARAMETERS_PROTOCOL));334 *NewShellParameters = AllocateZeroPool (sizeof (EFI_SHELL_PARAMETERS_PROTOCOL)); 333 335 if ((*NewShellParameters) == NULL) { 334 336 return (EFI_OUT_OF_RESOURCES); … … 339 341 // 340 342 Status = gBS->OpenProtocol ( 341 gImageHandle,342 &gEfiLoadedImageProtocolGuid,343 (VOID **)&LoadedImage,344 gImageHandle,345 NULL,346 EFI_OPEN_PROTOCOL_GET_PROTOCOL347 );348 ASSERT_EFI_ERROR (Status);343 gImageHandle, 344 &gEfiLoadedImageProtocolGuid, 345 (VOID **)&LoadedImage, 346 gImageHandle, 347 NULL, 348 EFI_OPEN_PROTOCOL_GET_PROTOCOL 349 ); 350 ASSERT_EFI_ERROR (Status); 349 351 // 350 352 // Build the full command line 351 353 // 352 Status = SHELL_GET_ENVIRONMENT_VARIABLE (L"ShellOpt", &Size, FullCommandLine);354 Status = SHELL_GET_ENVIRONMENT_VARIABLE (L"ShellOpt", &Size, FullCommandLine); 353 355 if (Status == EFI_BUFFER_TOO_SMALL) { 354 FullCommandLine = AllocateZeroPool(Size + LoadedImage->LoadOptionsSize); 355 Status = SHELL_GET_ENVIRONMENT_VARIABLE(L"ShellOpt", &Size, FullCommandLine); 356 } 356 FullCommandLine = AllocateZeroPool (Size + LoadedImage->LoadOptionsSize); 357 Status = SHELL_GET_ENVIRONMENT_VARIABLE (L"ShellOpt", &Size, FullCommandLine); 358 } 359 357 360 if (Status == EFI_NOT_FOUND) { 358 361 // … … 360 363 // 361 364 } else { 362 if (EFI_ERROR (Status)) {365 if (EFI_ERROR (Status)) { 363 366 return (Status); 364 367 } 365 368 } 366 if (Size == 0 && LoadedImage->LoadOptionsSize != 0) { 367 ASSERT(FullCommandLine == NULL); 369 370 if ((Size == 0) && (LoadedImage->LoadOptionsSize != 0)) { 371 ASSERT (FullCommandLine == NULL); 368 372 // 369 373 // Now we need to include a NULL terminator in the size. 370 374 // 371 Size = LoadedImage->LoadOptionsSize + sizeof(FullCommandLine[0]); 372 FullCommandLine = AllocateZeroPool(Size); 373 } 375 Size = LoadedImage->LoadOptionsSize + sizeof (FullCommandLine[0]); 376 FullCommandLine = AllocateZeroPool (Size); 377 } 378 374 379 if (FullCommandLine != NULL) { 375 380 CopyMem (FullCommandLine, LoadedImage->LoadOptions, LoadedImage->LoadOptionsSize); … … 377 382 // Populate Argc and Argv 378 383 // 379 Status = ParseCommandLineToArgs(FullCommandLine, 380 TRUE, 381 &(*NewShellParameters)->Argv, 382 &(*NewShellParameters)->Argc); 383 384 FreePool(FullCommandLine); 385 386 ASSERT_EFI_ERROR(Status); 384 Status = ParseCommandLineToArgs ( 385 FullCommandLine, 386 TRUE, 387 &(*NewShellParameters)->Argv, 388 &(*NewShellParameters)->Argc 389 ); 390 391 FreePool (FullCommandLine); 392 393 ASSERT_EFI_ERROR (Status); 387 394 } else { 388 395 (*NewShellParameters)->Argv = NULL; … … 397 404 (*NewShellParameters)->StdOut = &FileInterfaceStdOut; 398 405 (*NewShellParameters)->StdErr = &FileInterfaceStdErr; 399 Status = gBS->InstallProtocolInterface(&gImageHandle, 406 Status = gBS->InstallProtocolInterface ( 407 &gImageHandle, 400 408 &gEfiShellParametersProtocolGuid, 401 409 EFI_NATIVE_INTERFACE, 402 (VOID*)(*NewShellParameters)); 410 (VOID *)(*NewShellParameters) 411 ); 403 412 } else { 404 413 // … … 408 417 (*NewShellParameters)->StdOut = ShellInfoObject.OldShellParameters->StdOut; 409 418 (*NewShellParameters)->StdErr = ShellInfoObject.OldShellParameters->StdErr; 410 Status = gBS->ReinstallProtocolInterface(gImageHandle, 411 &gEfiShellParametersProtocolGuid, 412 (VOID*)ShellInfoObject.OldShellParameters, 413 (VOID*)(*NewShellParameters)); 419 Status = gBS->ReinstallProtocolInterface ( 420 gImageHandle, 421 &gEfiShellParametersProtocolGuid, 422 (VOID *)ShellInfoObject.OldShellParameters, 423 (VOID *)(*NewShellParameters) 424 ); 414 425 } 415 426 … … 434 445 ) 435 446 { 436 EFI_STATUS Status;437 UINTN LoopCounter;447 EFI_STATUS Status; 448 UINTN LoopCounter; 438 449 439 450 // … … 441 452 // 442 453 if (ShellInfoObject.OldShellParameters != NULL) { 443 Status = gBS->ReinstallProtocolInterface(gImageHandle, 444 &gEfiShellParametersProtocolGuid, 445 (VOID*)NewShellParameters, 446 (VOID*)ShellInfoObject.OldShellParameters); 447 DEBUG_CODE(ShellInfoObject.OldShellParameters = NULL;); 454 Status = gBS->ReinstallProtocolInterface ( 455 gImageHandle, 456 &gEfiShellParametersProtocolGuid, 457 (VOID *)NewShellParameters, 458 (VOID *)ShellInfoObject.OldShellParameters 459 ); 460 DEBUG_CODE ( 461 ShellInfoObject.OldShellParameters = NULL; 462 ); 448 463 } else { 449 464 // 450 465 // No old one, just uninstall us... 451 466 // 452 Status = gBS->UninstallProtocolInterface(gImageHandle, 453 &gEfiShellParametersProtocolGuid, 454 (VOID*)NewShellParameters); 455 } 467 Status = gBS->UninstallProtocolInterface ( 468 gImageHandle, 469 &gEfiShellParametersProtocolGuid, 470 (VOID *)NewShellParameters 471 ); 472 } 473 456 474 if (NewShellParameters->Argv != NULL) { 457 475 for ( LoopCounter = 0 458 ; LoopCounter < NewShellParameters->Argc 459 ; LoopCounter++ 460 ){ 461 FreePool(NewShellParameters->Argv[LoopCounter]); 462 } 463 FreePool(NewShellParameters->Argv); 464 } 465 FreePool(NewShellParameters); 476 ; LoopCounter < NewShellParameters->Argc 477 ; LoopCounter++ 478 ) 479 { 480 FreePool (NewShellParameters->Argv[LoopCounter]); 481 } 482 483 FreePool (NewShellParameters->Argv); 484 } 485 486 FreePool (NewShellParameters); 466 487 return (Status); 467 488 } … … 476 497 **/ 477 498 EFI_STATUS 478 IsUnicodeFile (479 IN CONST CHAR16 *FileName499 IsUnicodeFile ( 500 IN CONST CHAR16 *FileName 480 501 ) 481 502 { 482 SHELL_FILE_HANDLE Handle;483 EFI_STATUS Status;484 UINT64 OriginalFilePosition;485 UINTN CharSize;486 CHAR16 CharBuffer;487 488 Status = gEfiShellProtocol->OpenFileByName (FileName, &Handle, EFI_FILE_MODE_READ);489 if (EFI_ERROR (Status)) {503 SHELL_FILE_HANDLE Handle; 504 EFI_STATUS Status; 505 UINT64 OriginalFilePosition; 506 UINTN CharSize; 507 CHAR16 CharBuffer; 508 509 Status = gEfiShellProtocol->OpenFileByName (FileName, &Handle, EFI_FILE_MODE_READ); 510 if (EFI_ERROR (Status)) { 490 511 return (Status); 491 512 } 492 gEfiShellProtocol->GetFilePosition(Handle, &OriginalFilePosition); 493 gEfiShellProtocol->SetFilePosition(Handle, 0); 494 CharSize = sizeof(CHAR16); 495 Status = gEfiShellProtocol->ReadFile(Handle, &CharSize, &CharBuffer); 496 if (EFI_ERROR(Status) || CharBuffer != gUnicodeFileTag) { 513 514 gEfiShellProtocol->GetFilePosition (Handle, &OriginalFilePosition); 515 gEfiShellProtocol->SetFilePosition (Handle, 0); 516 CharSize = sizeof (CHAR16); 517 Status = gEfiShellProtocol->ReadFile (Handle, &CharSize, &CharBuffer); 518 if (EFI_ERROR (Status) || (CharBuffer != gUnicodeFileTag)) { 497 519 Status = EFI_BUFFER_TOO_SMALL; 498 520 } 499 gEfiShellProtocol->SetFilePosition(Handle, OriginalFilePosition); 500 gEfiShellProtocol->CloseFile(Handle); 521 522 gEfiShellProtocol->SetFilePosition (Handle, OriginalFilePosition); 523 gEfiShellProtocol->CloseFile (Handle); 501 524 return (Status); 502 525 } … … 511 534 VOID 512 535 StripQuotes ( 513 IN OUT CHAR16 *TheString536 IN OUT CHAR16 *TheString 514 537 ) 515 538 { 516 BOOLEAN RemoveNow;517 518 for (RemoveNow = FALSE ; TheString != NULL && *TheString != CHAR_NULL; TheString++) {519 if ( *TheString == L'^' && *(TheString + 1) == L'\"') {539 BOOLEAN RemoveNow; 540 541 for (RemoveNow = FALSE; TheString != NULL && *TheString != CHAR_NULL; TheString++) { 542 if ((*TheString == L'^') && (*(TheString + 1) == L'\"')) { 520 543 TheString++; 521 544 } else if (*TheString == L'\"') { 522 RemoveNow = (BOOLEAN) !RemoveNow;545 RemoveNow = (BOOLEAN) !RemoveNow; 523 546 } else if (RemoveNow) { 524 547 *TheString = L' '; … … 536 559 VOID 537 560 CalculateEfiHdrCrc ( 538 IN OUT EFI_TABLE_HEADER 561 IN OUT EFI_TABLE_HEADER *Hdr 539 562 ) 540 563 { 541 UINT32 Crc;564 UINT32 Crc; 542 565 543 566 Hdr->CRC32 = 0; … … 560 583 @return The modified FileName. 561 584 **/ 562 CHAR16 *585 CHAR16 * 563 586 FixFileName ( 564 IN CHAR16 *FileName587 IN CHAR16 *FileName 565 588 ) 566 589 { … … 574 597 if (FileName[0] == L'\"') { 575 598 Copy = FileName+1; 576 if ((TempLocation = StrStr (Copy, L"\"")) != NULL) {599 if ((TempLocation = StrStr (Copy, L"\"")) != NULL) { 577 600 TempLocation[0] = CHAR_NULL; 578 601 } 579 602 } else { 580 603 Copy = FileName; 581 while (Copy[0] == L' ') {604 while (Copy[0] == L' ') { 582 605 Copy++; 583 606 } 584 if ((TempLocation = StrStr(Copy , L" ")) != NULL) { 607 608 if ((TempLocation = StrStr (Copy, L" ")) != NULL) { 585 609 TempLocation[0] = CHAR_NULL; 586 610 } … … 602 626 @return The modified FileName. 603 627 **/ 604 CHAR16 *628 CHAR16 * 605 629 FixVarName ( 606 IN CHAR16 *FileName630 IN CHAR16 *FileName 607 631 ) 608 632 { … … 614 638 if (FileName[0] == L'%') { 615 639 Copy = FileName+1; 616 if ((TempLocation = StrStr (Copy, L"%")) != NULL) {640 if ((TempLocation = StrStr (Copy, L"%")) != NULL) { 617 641 TempLocation[0] = CHAR_NULL; 618 642 } 619 643 } 620 644 621 return (FixFileName (Copy));645 return (FixFileName (Copy)); 622 646 } 623 624 647 625 648 /** … … 636 659 EFI_STATUS 637 660 WriteFileTag ( 638 IN SHELL_FILE_HANDLE FileHandle661 IN SHELL_FILE_HANDLE FileHandle 639 662 ) 640 663 { 641 CHAR16 FileTag;642 UINTN Size;643 EFI_STATUS Status;664 CHAR16 FileTag; 665 UINTN Size; 666 EFI_STATUS Status; 644 667 645 668 FileTag = gUnicodeFileTag; 646 Size = sizeof FileTag; 647 Status = ShellInfoObject.NewEfiShellProtocol->WriteFile (FileHandle, &Size, 648 &FileTag); 669 Size = sizeof FileTag; 670 Status = ShellInfoObject.NewEfiShellProtocol->WriteFile ( 671 FileHandle, 672 &Size, 673 &FileTag 674 ); 649 675 ASSERT (EFI_ERROR (Status) || Size == sizeof FileTag); 650 676 return Status; 651 677 } 652 653 678 654 679 /** … … 670 695 **/ 671 696 EFI_STATUS 672 UpdateStdInStdOutStdErr (697 UpdateStdInStdOutStdErr ( 673 698 IN OUT EFI_SHELL_PARAMETERS_PROTOCOL *ShellParameters, 674 699 IN CHAR16 *NewCommandLine, … … 679 704 ) 680 705 { 681 CHAR16 *CommandLineCopy;682 CHAR16 *CommandLineWalker;683 CHAR16 *StdErrFileName;684 CHAR16 *StdOutFileName;685 CHAR16 *StdInFileName;686 CHAR16 *StdInVarName;687 CHAR16 *StdOutVarName;688 CHAR16 *StdErrVarName;689 EFI_STATUS Status;690 SHELL_FILE_HANDLE TempHandle;691 UINT64 FileSize;692 BOOLEAN OutUnicode;693 BOOLEAN InUnicode;694 BOOLEAN ErrUnicode;695 BOOLEAN OutAppend;696 BOOLEAN ErrAppend;697 UINTN Size;698 SPLIT_LIST *Split;699 CHAR16 *FirstLocation;700 BOOLEAN Volatile;701 702 OutUnicode = TRUE;703 InUnicode = TRUE;706 CHAR16 *CommandLineCopy; 707 CHAR16 *CommandLineWalker; 708 CHAR16 *StdErrFileName; 709 CHAR16 *StdOutFileName; 710 CHAR16 *StdInFileName; 711 CHAR16 *StdInVarName; 712 CHAR16 *StdOutVarName; 713 CHAR16 *StdErrVarName; 714 EFI_STATUS Status; 715 SHELL_FILE_HANDLE TempHandle; 716 UINT64 FileSize; 717 BOOLEAN OutUnicode; 718 BOOLEAN InUnicode; 719 BOOLEAN ErrUnicode; 720 BOOLEAN OutAppend; 721 BOOLEAN ErrAppend; 722 UINTN Size; 723 SPLIT_LIST *Split; 724 CHAR16 *FirstLocation; 725 BOOLEAN Volatile; 726 727 OutUnicode = TRUE; 728 InUnicode = TRUE; 704 729 AsciiRedirection = FALSE; 705 ErrUnicode = TRUE;706 StdInVarName = NULL;707 StdOutVarName = NULL;708 StdErrVarName = NULL;709 StdErrFileName = NULL;710 StdInFileName = NULL;711 StdOutFileName = NULL;712 ErrAppend = FALSE;713 OutAppend = FALSE;714 CommandLineCopy = NULL;715 FirstLocation = NULL;716 717 if ( ShellParameters == NULL || SystemTableInfo == NULL || OldStdIn == NULL || OldStdOut == NULL || OldStdErr == NULL) {730 ErrUnicode = TRUE; 731 StdInVarName = NULL; 732 StdOutVarName = NULL; 733 StdErrVarName = NULL; 734 StdErrFileName = NULL; 735 StdInFileName = NULL; 736 StdOutFileName = NULL; 737 ErrAppend = FALSE; 738 OutAppend = FALSE; 739 CommandLineCopy = NULL; 740 FirstLocation = NULL; 741 742 if ((ShellParameters == NULL) || (SystemTableInfo == NULL) || (OldStdIn == NULL) || (OldStdOut == NULL) || (OldStdErr == NULL)) { 718 743 return (EFI_INVALID_PARAMETER); 719 744 } 720 745 721 SystemTableInfo->ConIn 722 SystemTableInfo->ConInHandle 723 SystemTableInfo->ConOut 724 SystemTableInfo->ConOutHandle 725 SystemTableInfo->ErrOut 726 SystemTableInfo->ErrOutHandle 727 *OldStdIn 728 *OldStdOut 729 *OldStdErr 746 SystemTableInfo->ConIn = gST->ConIn; 747 SystemTableInfo->ConInHandle = gST->ConsoleInHandle; 748 SystemTableInfo->ConOut = gST->ConOut; 749 SystemTableInfo->ConOutHandle = gST->ConsoleOutHandle; 750 SystemTableInfo->ErrOut = gST->StdErr; 751 SystemTableInfo->ErrOutHandle = gST->StandardErrorHandle; 752 *OldStdIn = ShellParameters->StdIn; 753 *OldStdOut = ShellParameters->StdOut; 754 *OldStdErr = ShellParameters->StdErr; 730 755 731 756 if (NewCommandLine == NULL) { … … 733 758 } 734 759 735 CommandLineCopy = StrnCatGrow (&CommandLineCopy, NULL, NewCommandLine, 0);760 CommandLineCopy = StrnCatGrow (&CommandLineCopy, NULL, NewCommandLine, 0); 736 761 if (CommandLineCopy == NULL) { 737 762 return (EFI_OUT_OF_RESOURCES); 738 763 } 739 Status = EFI_SUCCESS; 740 Split = NULL; 741 FirstLocation = CommandLineCopy + StrLen(CommandLineCopy); 742 743 StripQuotes(CommandLineCopy); 744 745 if (!IsListEmpty(&ShellInfoObject.SplitList.Link)) { 746 Split = (SPLIT_LIST*)GetFirstNode(&ShellInfoObject.SplitList.Link); 747 if (Split != NULL && Split->SplitStdIn != NULL) { 748 ShellParameters->StdIn = Split->SplitStdIn; 749 } 750 if (Split != NULL && Split->SplitStdOut != NULL) { 764 765 Status = EFI_SUCCESS; 766 Split = NULL; 767 FirstLocation = CommandLineCopy + StrLen (CommandLineCopy); 768 769 StripQuotes (CommandLineCopy); 770 771 if (!IsListEmpty (&ShellInfoObject.SplitList.Link)) { 772 Split = (SPLIT_LIST *)GetFirstNode (&ShellInfoObject.SplitList.Link); 773 if ((Split != NULL) && (Split->SplitStdIn != NULL)) { 774 ShellParameters->StdIn = Split->SplitStdIn; 775 } 776 777 if ((Split != NULL) && (Split->SplitStdOut != NULL)) { 751 778 ShellParameters->StdOut = Split->SplitStdOut; 752 779 } 753 780 } 754 781 755 if (!EFI_ERROR(Status) && (CommandLineWalker = StrStr(CommandLineCopy, L" 2>>v ")) != NULL) { 756 FirstLocation = MIN(CommandLineWalker, FirstLocation); 757 SetMem16(CommandLineWalker, 12, L' '); 758 StdErrVarName = CommandLineWalker += 6; 759 ErrAppend = TRUE; 760 if (StrStr(CommandLineWalker, L" 2>>v ") != NULL) { 761 Status = EFI_NOT_FOUND; 762 } 763 } 764 if (!EFI_ERROR(Status) && (CommandLineWalker = StrStr(CommandLineCopy, L" 1>>v ")) != NULL) { 765 FirstLocation = MIN(CommandLineWalker, FirstLocation); 766 SetMem16(CommandLineWalker, 12, L' '); 767 StdOutVarName = CommandLineWalker += 6; 768 OutAppend = TRUE; 769 if (StrStr(CommandLineWalker, L" 1>>v ") != NULL) { 770 Status = EFI_NOT_FOUND; 771 } 772 } else if (!EFI_ERROR(Status) && (CommandLineWalker = StrStr(CommandLineCopy, L" >>v ")) != NULL) { 773 FirstLocation = MIN(CommandLineWalker, FirstLocation); 774 SetMem16(CommandLineWalker, 10, L' '); 775 StdOutVarName = CommandLineWalker += 5; 776 OutAppend = TRUE; 777 if (StrStr(CommandLineWalker, L" >>v ") != NULL) { 778 Status = EFI_NOT_FOUND; 779 } 780 } else if (!EFI_ERROR(Status) && (CommandLineWalker = StrStr(CommandLineCopy, L" >v ")) != NULL) { 781 FirstLocation = MIN(CommandLineWalker, FirstLocation); 782 SetMem16(CommandLineWalker, 8, L' '); 783 StdOutVarName = CommandLineWalker += 4; 784 OutAppend = FALSE; 785 if (StrStr(CommandLineWalker, L" >v ") != NULL) { 786 Status = EFI_NOT_FOUND; 787 } 788 } 789 if (!EFI_ERROR(Status) && (CommandLineWalker = StrStr(CommandLineCopy, L" 1>>a ")) != NULL) { 790 FirstLocation = MIN(CommandLineWalker, FirstLocation); 791 SetMem16(CommandLineWalker, 12, L' '); 792 StdOutFileName = CommandLineWalker += 6; 793 OutAppend = TRUE; 794 OutUnicode = FALSE; 795 if (StrStr(CommandLineWalker, L" 1>>a ") != NULL) { 796 Status = EFI_NOT_FOUND; 797 } 798 } 799 if (!EFI_ERROR(Status) && (CommandLineWalker = StrStr(CommandLineCopy, L" 1>> ")) != NULL) { 800 FirstLocation = MIN(CommandLineWalker, FirstLocation); 801 SetMem16(CommandLineWalker, 10, L' '); 782 if (!EFI_ERROR (Status) && ((CommandLineWalker = StrStr (CommandLineCopy, L" 2>>v ")) != NULL)) { 783 FirstLocation = MIN (CommandLineWalker, FirstLocation); 784 SetMem16 (CommandLineWalker, 12, L' '); 785 StdErrVarName = CommandLineWalker += 6; 786 ErrAppend = TRUE; 787 if (StrStr (CommandLineWalker, L" 2>>v ") != NULL) { 788 Status = EFI_NOT_FOUND; 789 } 790 } 791 792 if (!EFI_ERROR (Status) && ((CommandLineWalker = StrStr (CommandLineCopy, L" 1>>v ")) != NULL)) { 793 FirstLocation = MIN (CommandLineWalker, FirstLocation); 794 SetMem16 (CommandLineWalker, 12, L' '); 795 StdOutVarName = CommandLineWalker += 6; 796 OutAppend = TRUE; 797 if (StrStr (CommandLineWalker, L" 1>>v ") != NULL) { 798 Status = EFI_NOT_FOUND; 799 } 800 } else if (!EFI_ERROR (Status) && ((CommandLineWalker = StrStr (CommandLineCopy, L" >>v ")) != NULL)) { 801 FirstLocation = MIN (CommandLineWalker, FirstLocation); 802 SetMem16 (CommandLineWalker, 10, L' '); 803 StdOutVarName = CommandLineWalker += 5; 804 OutAppend = TRUE; 805 if (StrStr (CommandLineWalker, L" >>v ") != NULL) { 806 Status = EFI_NOT_FOUND; 807 } 808 } else if (!EFI_ERROR (Status) && ((CommandLineWalker = StrStr (CommandLineCopy, L" >v ")) != NULL)) { 809 FirstLocation = MIN (CommandLineWalker, FirstLocation); 810 SetMem16 (CommandLineWalker, 8, L' '); 811 StdOutVarName = CommandLineWalker += 4; 812 OutAppend = FALSE; 813 if (StrStr (CommandLineWalker, L" >v ") != NULL) { 814 Status = EFI_NOT_FOUND; 815 } 816 } 817 818 if (!EFI_ERROR (Status) && ((CommandLineWalker = StrStr (CommandLineCopy, L" 1>>a ")) != NULL)) { 819 FirstLocation = MIN (CommandLineWalker, FirstLocation); 820 SetMem16 (CommandLineWalker, 12, L' '); 821 StdOutFileName = CommandLineWalker += 6; 822 OutAppend = TRUE; 823 OutUnicode = FALSE; 824 if (StrStr (CommandLineWalker, L" 1>>a ") != NULL) { 825 Status = EFI_NOT_FOUND; 826 } 827 } 828 829 if (!EFI_ERROR (Status) && ((CommandLineWalker = StrStr (CommandLineCopy, L" 1>> ")) != NULL)) { 830 FirstLocation = MIN (CommandLineWalker, FirstLocation); 831 SetMem16 (CommandLineWalker, 10, L' '); 802 832 if (StdOutFileName != NULL) { 803 833 Status = EFI_INVALID_PARAMETER; 804 834 } else { 805 StdOutFileName = CommandLineWalker += 5; 806 OutAppend = TRUE; 807 } 808 if (StrStr(CommandLineWalker, L" 1>> ") != NULL) { 809 Status = EFI_NOT_FOUND; 810 } 811 } 812 if (!EFI_ERROR(Status) && (CommandLineWalker = StrStr(CommandLineCopy, L" >> ")) != NULL) { 813 FirstLocation = MIN(CommandLineWalker, FirstLocation); 814 SetMem16(CommandLineWalker, 8, L' '); 835 StdOutFileName = CommandLineWalker += 5; 836 OutAppend = TRUE; 837 } 838 839 if (StrStr (CommandLineWalker, L" 1>> ") != NULL) { 840 Status = EFI_NOT_FOUND; 841 } 842 } 843 844 if (!EFI_ERROR (Status) && ((CommandLineWalker = StrStr (CommandLineCopy, L" >> ")) != NULL)) { 845 FirstLocation = MIN (CommandLineWalker, FirstLocation); 846 SetMem16 (CommandLineWalker, 8, L' '); 815 847 if (StdOutFileName != NULL) { 816 848 Status = EFI_INVALID_PARAMETER; 817 849 } else { 818 StdOutFileName = CommandLineWalker += 4; 819 OutAppend = TRUE; 820 } 821 if (StrStr(CommandLineWalker, L" >> ") != NULL) { 822 Status = EFI_NOT_FOUND; 823 } 824 } 825 if (!EFI_ERROR(Status) && (CommandLineWalker = StrStr(CommandLineCopy, L" >>a ")) != NULL) { 826 FirstLocation = MIN(CommandLineWalker, FirstLocation); 827 SetMem16(CommandLineWalker, 10, L' '); 850 StdOutFileName = CommandLineWalker += 4; 851 OutAppend = TRUE; 852 } 853 854 if (StrStr (CommandLineWalker, L" >> ") != NULL) { 855 Status = EFI_NOT_FOUND; 856 } 857 } 858 859 if (!EFI_ERROR (Status) && ((CommandLineWalker = StrStr (CommandLineCopy, L" >>a ")) != NULL)) { 860 FirstLocation = MIN (CommandLineWalker, FirstLocation); 861 SetMem16 (CommandLineWalker, 10, L' '); 828 862 if (StdOutFileName != NULL) { 829 863 Status = EFI_INVALID_PARAMETER; 830 864 } else { 831 StdOutFileName = CommandLineWalker += 5; 832 OutAppend = TRUE; 833 OutUnicode = FALSE; 834 } 835 if (StrStr(CommandLineWalker, L" >>a ") != NULL) { 836 Status = EFI_NOT_FOUND; 837 } 838 } 839 if (!EFI_ERROR(Status) && (CommandLineWalker = StrStr(CommandLineCopy, L" 1>a ")) != NULL) { 840 FirstLocation = MIN(CommandLineWalker, FirstLocation); 841 SetMem16(CommandLineWalker, 10, L' '); 865 StdOutFileName = CommandLineWalker += 5; 866 OutAppend = TRUE; 867 OutUnicode = FALSE; 868 } 869 870 if (StrStr (CommandLineWalker, L" >>a ") != NULL) { 871 Status = EFI_NOT_FOUND; 872 } 873 } 874 875 if (!EFI_ERROR (Status) && ((CommandLineWalker = StrStr (CommandLineCopy, L" 1>a ")) != NULL)) { 876 FirstLocation = MIN (CommandLineWalker, FirstLocation); 877 SetMem16 (CommandLineWalker, 10, L' '); 842 878 if (StdOutFileName != NULL) { 843 879 Status = EFI_INVALID_PARAMETER; 844 880 } else { 845 StdOutFileName = CommandLineWalker += 5; 846 OutAppend = FALSE; 847 OutUnicode = FALSE; 848 } 849 if (StrStr(CommandLineWalker, L" 1>a ") != NULL) { 850 Status = EFI_NOT_FOUND; 851 } 852 } 853 if (!EFI_ERROR(Status) && (CommandLineWalker = StrStr(CommandLineCopy, L" >a ")) != NULL) { 854 FirstLocation = MIN(CommandLineWalker, FirstLocation); 855 SetMem16(CommandLineWalker, 8, L' '); 881 StdOutFileName = CommandLineWalker += 5; 882 OutAppend = FALSE; 883 OutUnicode = FALSE; 884 } 885 886 if (StrStr (CommandLineWalker, L" 1>a ") != NULL) { 887 Status = EFI_NOT_FOUND; 888 } 889 } 890 891 if (!EFI_ERROR (Status) && ((CommandLineWalker = StrStr (CommandLineCopy, L" >a ")) != NULL)) { 892 FirstLocation = MIN (CommandLineWalker, FirstLocation); 893 SetMem16 (CommandLineWalker, 8, L' '); 856 894 if (StdOutFileName != NULL) { 857 895 Status = EFI_INVALID_PARAMETER; 858 896 } else { 859 StdOutFileName = CommandLineWalker += 4; 860 OutAppend = FALSE; 861 OutUnicode = FALSE; 862 } 863 if (StrStr(CommandLineWalker, L" >a ") != NULL) { 864 Status = EFI_NOT_FOUND; 865 } 866 } 867 if (!EFI_ERROR(Status) && (CommandLineWalker = StrStr(CommandLineCopy, L" 2>> ")) != NULL) { 868 FirstLocation = MIN(CommandLineWalker, FirstLocation); 869 SetMem16(CommandLineWalker, 10, L' '); 897 StdOutFileName = CommandLineWalker += 4; 898 OutAppend = FALSE; 899 OutUnicode = FALSE; 900 } 901 902 if (StrStr (CommandLineWalker, L" >a ") != NULL) { 903 Status = EFI_NOT_FOUND; 904 } 905 } 906 907 if (!EFI_ERROR (Status) && ((CommandLineWalker = StrStr (CommandLineCopy, L" 2>> ")) != NULL)) { 908 FirstLocation = MIN (CommandLineWalker, FirstLocation); 909 SetMem16 (CommandLineWalker, 10, L' '); 870 910 if (StdErrFileName != NULL) { 871 911 Status = EFI_INVALID_PARAMETER; 872 912 } else { 873 StdErrFileName = CommandLineWalker += 5; 874 ErrAppend = TRUE; 875 } 876 if (StrStr(CommandLineWalker, L" 2>> ") != NULL) { 877 Status = EFI_NOT_FOUND; 878 } 879 } 880 881 if (!EFI_ERROR(Status) && (CommandLineWalker = StrStr(CommandLineCopy, L" 2>v ")) != NULL) { 882 FirstLocation = MIN(CommandLineWalker, FirstLocation); 883 SetMem16(CommandLineWalker, 10, L' '); 913 StdErrFileName = CommandLineWalker += 5; 914 ErrAppend = TRUE; 915 } 916 917 if (StrStr (CommandLineWalker, L" 2>> ") != NULL) { 918 Status = EFI_NOT_FOUND; 919 } 920 } 921 922 if (!EFI_ERROR (Status) && ((CommandLineWalker = StrStr (CommandLineCopy, L" 2>v ")) != NULL)) { 923 FirstLocation = MIN (CommandLineWalker, FirstLocation); 924 SetMem16 (CommandLineWalker, 10, L' '); 884 925 if (StdErrVarName != NULL) { 885 926 Status = EFI_INVALID_PARAMETER; 886 927 } else { 887 StdErrVarName = CommandLineWalker += 5; 888 ErrAppend = FALSE; 889 } 890 if (StrStr(CommandLineWalker, L" 2>v ") != NULL) { 891 Status = EFI_NOT_FOUND; 892 } 893 } 894 if (!EFI_ERROR(Status) && (CommandLineWalker = StrStr(CommandLineCopy, L" 1>v ")) != NULL) { 895 FirstLocation = MIN(CommandLineWalker, FirstLocation); 896 SetMem16(CommandLineWalker, 10, L' '); 928 StdErrVarName = CommandLineWalker += 5; 929 ErrAppend = FALSE; 930 } 931 932 if (StrStr (CommandLineWalker, L" 2>v ") != NULL) { 933 Status = EFI_NOT_FOUND; 934 } 935 } 936 937 if (!EFI_ERROR (Status) && ((CommandLineWalker = StrStr (CommandLineCopy, L" 1>v ")) != NULL)) { 938 FirstLocation = MIN (CommandLineWalker, FirstLocation); 939 SetMem16 (CommandLineWalker, 10, L' '); 897 940 if (StdOutVarName != NULL) { 898 941 Status = EFI_INVALID_PARAMETER; 899 942 } else { 900 StdOutVarName = CommandLineWalker += 5; 901 OutAppend = FALSE; 902 } 903 if (StrStr(CommandLineWalker, L" 1>v ") != NULL) { 904 Status = EFI_NOT_FOUND; 905 } 906 } 907 if (!EFI_ERROR(Status) && (CommandLineWalker = StrStr(CommandLineCopy, L" 2>a ")) != NULL) { 908 FirstLocation = MIN(CommandLineWalker, FirstLocation); 909 SetMem16(CommandLineWalker, 10, L' '); 943 StdOutVarName = CommandLineWalker += 5; 944 OutAppend = FALSE; 945 } 946 947 if (StrStr (CommandLineWalker, L" 1>v ") != NULL) { 948 Status = EFI_NOT_FOUND; 949 } 950 } 951 952 if (!EFI_ERROR (Status) && ((CommandLineWalker = StrStr (CommandLineCopy, L" 2>a ")) != NULL)) { 953 FirstLocation = MIN (CommandLineWalker, FirstLocation); 954 SetMem16 (CommandLineWalker, 10, L' '); 910 955 if (StdErrFileName != NULL) { 911 956 Status = EFI_INVALID_PARAMETER; 912 957 } else { 913 StdErrFileName = CommandLineWalker += 5; 914 ErrAppend = FALSE; 915 ErrUnicode = FALSE; 916 } 917 if (StrStr(CommandLineWalker, L" 2>a ") != NULL) { 918 Status = EFI_NOT_FOUND; 919 } 920 } 921 if (!EFI_ERROR(Status) && (CommandLineWalker = StrStr(CommandLineCopy, L" 2> ")) != NULL) { 922 FirstLocation = MIN(CommandLineWalker, FirstLocation); 923 SetMem16(CommandLineWalker, 8, L' '); 958 StdErrFileName = CommandLineWalker += 5; 959 ErrAppend = FALSE; 960 ErrUnicode = FALSE; 961 } 962 963 if (StrStr (CommandLineWalker, L" 2>a ") != NULL) { 964 Status = EFI_NOT_FOUND; 965 } 966 } 967 968 if (!EFI_ERROR (Status) && ((CommandLineWalker = StrStr (CommandLineCopy, L" 2> ")) != NULL)) { 969 FirstLocation = MIN (CommandLineWalker, FirstLocation); 970 SetMem16 (CommandLineWalker, 8, L' '); 924 971 if (StdErrFileName != NULL) { 925 972 Status = EFI_INVALID_PARAMETER; 926 973 } else { 927 StdErrFileName = CommandLineWalker += 4; 928 ErrAppend = FALSE; 929 } 930 if (StrStr(CommandLineWalker, L" 2> ") != NULL) { 931 Status = EFI_NOT_FOUND; 932 } 933 } 934 935 if (!EFI_ERROR(Status) && (CommandLineWalker = StrStr(CommandLineCopy, L" 1> ")) != NULL) { 936 FirstLocation = MIN(CommandLineWalker, FirstLocation); 937 SetMem16(CommandLineWalker, 8, L' '); 974 StdErrFileName = CommandLineWalker += 4; 975 ErrAppend = FALSE; 976 } 977 978 if (StrStr (CommandLineWalker, L" 2> ") != NULL) { 979 Status = EFI_NOT_FOUND; 980 } 981 } 982 983 if (!EFI_ERROR (Status) && ((CommandLineWalker = StrStr (CommandLineCopy, L" 1> ")) != NULL)) { 984 FirstLocation = MIN (CommandLineWalker, FirstLocation); 985 SetMem16 (CommandLineWalker, 8, L' '); 938 986 if (StdOutFileName != NULL) { 939 987 Status = EFI_INVALID_PARAMETER; 940 988 } else { 941 StdOutFileName = CommandLineWalker += 4; 942 OutAppend = FALSE; 943 } 944 if (StrStr(CommandLineWalker, L" 1> ") != NULL) { 945 Status = EFI_NOT_FOUND; 946 } 947 } 948 949 if (!EFI_ERROR(Status) && (CommandLineWalker = StrStr(CommandLineCopy, L" > ")) != NULL) { 950 FirstLocation = MIN(CommandLineWalker, FirstLocation); 951 SetMem16(CommandLineWalker, 6, L' '); 989 StdOutFileName = CommandLineWalker += 4; 990 OutAppend = FALSE; 991 } 992 993 if (StrStr (CommandLineWalker, L" 1> ") != NULL) { 994 Status = EFI_NOT_FOUND; 995 } 996 } 997 998 if (!EFI_ERROR (Status) && ((CommandLineWalker = StrStr (CommandLineCopy, L" > ")) != NULL)) { 999 FirstLocation = MIN (CommandLineWalker, FirstLocation); 1000 SetMem16 (CommandLineWalker, 6, L' '); 952 1001 if (StdOutFileName != NULL) { 953 1002 Status = EFI_INVALID_PARAMETER; 954 1003 } else { 955 StdOutFileName = CommandLineWalker += 3; 956 OutAppend = FALSE; 957 } 958 if (StrStr(CommandLineWalker, L" > ") != NULL) { 959 Status = EFI_NOT_FOUND; 960 } 961 } 962 963 if (!EFI_ERROR(Status) && (CommandLineWalker = StrStr(CommandLineCopy, L" < ")) != NULL) { 964 FirstLocation = MIN(CommandLineWalker, FirstLocation); 965 SetMem16(CommandLineWalker, 6, L' '); 1004 StdOutFileName = CommandLineWalker += 3; 1005 OutAppend = FALSE; 1006 } 1007 1008 if (StrStr (CommandLineWalker, L" > ") != NULL) { 1009 Status = EFI_NOT_FOUND; 1010 } 1011 } 1012 1013 if (!EFI_ERROR (Status) && ((CommandLineWalker = StrStr (CommandLineCopy, L" < ")) != NULL)) { 1014 FirstLocation = MIN (CommandLineWalker, FirstLocation); 1015 SetMem16 (CommandLineWalker, 6, L' '); 966 1016 if (StdInFileName != NULL) { 967 1017 Status = EFI_INVALID_PARAMETER; 968 1018 } else { 969 StdInFileName = CommandLineWalker += 3; 970 } 971 if (StrStr(CommandLineWalker, L" < ") != NULL) { 972 Status = EFI_NOT_FOUND; 973 } 974 } 975 if (!EFI_ERROR(Status) && (CommandLineWalker = StrStr(CommandLineCopy, L" <a ")) != NULL) { 976 FirstLocation = MIN(CommandLineWalker, FirstLocation); 977 SetMem16(CommandLineWalker, 8, L' '); 1019 StdInFileName = CommandLineWalker += 3; 1020 } 1021 1022 if (StrStr (CommandLineWalker, L" < ") != NULL) { 1023 Status = EFI_NOT_FOUND; 1024 } 1025 } 1026 1027 if (!EFI_ERROR (Status) && ((CommandLineWalker = StrStr (CommandLineCopy, L" <a ")) != NULL)) { 1028 FirstLocation = MIN (CommandLineWalker, FirstLocation); 1029 SetMem16 (CommandLineWalker, 8, L' '); 978 1030 if (StdInFileName != NULL) { 979 1031 Status = EFI_INVALID_PARAMETER; 980 1032 } else { 981 StdInFileName = CommandLineWalker += 4;982 InUnicode = FALSE;1033 StdInFileName = CommandLineWalker += 4; 1034 InUnicode = FALSE; 983 1035 AsciiRedirection = TRUE; 984 1036 } 985 if (StrStr(CommandLineWalker, L" <a ") != NULL) { 986 Status = EFI_NOT_FOUND; 987 } 988 } 989 if (!EFI_ERROR(Status) && (CommandLineWalker = StrStr(CommandLineCopy, L" <v ")) != NULL) { 990 FirstLocation = MIN(CommandLineWalker, FirstLocation); 991 SetMem16(CommandLineWalker, 8, L' '); 1037 1038 if (StrStr (CommandLineWalker, L" <a ") != NULL) { 1039 Status = EFI_NOT_FOUND; 1040 } 1041 } 1042 1043 if (!EFI_ERROR (Status) && ((CommandLineWalker = StrStr (CommandLineCopy, L" <v ")) != NULL)) { 1044 FirstLocation = MIN (CommandLineWalker, FirstLocation); 1045 SetMem16 (CommandLineWalker, 8, L' '); 992 1046 if (StdInVarName != NULL) { 993 1047 Status = EFI_INVALID_PARAMETER; 994 1048 } else { 995 StdInVarName = CommandLineWalker += 4; 996 } 997 if (StrStr(CommandLineWalker, L" <v ") != NULL) { 1049 StdInVarName = CommandLineWalker += 4; 1050 } 1051 1052 if (StrStr (CommandLineWalker, L" <v ") != NULL) { 998 1053 Status = EFI_NOT_FOUND; 999 1054 } … … 1003 1058 // re-populate the string to support any filenames that were in quotes. 1004 1059 // 1005 StrnCpyS (CommandLineCopy, StrSize(CommandLineCopy)/sizeof(CHAR16), NewCommandLine, StrLen(NewCommandLine));1006 1007 if ( FirstLocation != CommandLineCopy + StrLen(CommandLineCopy)1008 && (((UINTN)FirstLocation - (UINTN)CommandLineCopy)/sizeof(CHAR16) < StrLen(NewCommandLine))1009 ){1010 *(NewCommandLine + ((UINTN)FirstLocation - (UINTN)CommandLineCopy)/sizeof(CHAR16)) = CHAR_NULL;1011 }1012 1013 if (!EFI_ERROR(Status)) { 1014 1060 StrnCpyS (CommandLineCopy, StrSize (CommandLineCopy)/sizeof (CHAR16), NewCommandLine, StrLen (NewCommandLine)); 1061 1062 if ( (FirstLocation != CommandLineCopy + StrLen (CommandLineCopy)) 1063 && (((UINTN)FirstLocation - (UINTN)CommandLineCopy)/sizeof (CHAR16) < StrLen (NewCommandLine)) 1064 ) 1065 { 1066 *(NewCommandLine + ((UINTN)FirstLocation - (UINTN)CommandLineCopy)/sizeof (CHAR16)) = CHAR_NULL; 1067 } 1068 1069 if (!EFI_ERROR (Status)) { 1015 1070 if (StdErrFileName != NULL) { 1016 if ((StdErrFileName = FixFileName (StdErrFileName)) == NULL) {1071 if ((StdErrFileName = FixFileName (StdErrFileName)) == NULL) { 1017 1072 Status = EFI_INVALID_PARAMETER; 1018 1073 } 1019 1074 } 1075 1020 1076 if (StdOutFileName != NULL) { 1021 if ((StdOutFileName = FixFileName (StdOutFileName)) == NULL) {1077 if ((StdOutFileName = FixFileName (StdOutFileName)) == NULL) { 1022 1078 Status = EFI_INVALID_PARAMETER; 1023 1079 } 1024 1080 } 1081 1025 1082 if (StdInFileName != NULL) { 1026 if ((StdInFileName = FixFileName (StdInFileName)) == NULL) {1083 if ((StdInFileName = FixFileName (StdInFileName)) == NULL) { 1027 1084 Status = EFI_INVALID_PARAMETER; 1028 1085 } 1029 1086 } 1087 1030 1088 if (StdErrVarName != NULL) { 1031 if ((StdErrVarName = FixVarName (StdErrVarName)) == NULL) {1089 if ((StdErrVarName = FixVarName (StdErrVarName)) == NULL) { 1032 1090 Status = EFI_INVALID_PARAMETER; 1033 1091 } 1034 1092 } 1093 1035 1094 if (StdOutVarName != NULL) { 1036 if ((StdOutVarName = FixVarName (StdOutVarName)) == NULL) {1095 if ((StdOutVarName = FixVarName (StdOutVarName)) == NULL) { 1037 1096 Status = EFI_INVALID_PARAMETER; 1038 1097 } 1039 1098 } 1099 1040 1100 if (StdInVarName != NULL) { 1041 if ((StdInVarName = FixVarName (StdInVarName)) == NULL) {1101 if ((StdInVarName = FixVarName (StdInVarName)) == NULL) { 1042 1102 Status = EFI_INVALID_PARAMETER; 1043 1103 } … … 1048 1108 // 1049 1109 if ( 1050 // 1051 // Check that no 2 filenames are the same 1052 // 1053 (StdErrFileName != NULL && StdOutFileName!= NULL && StringNoCaseCompare(&StdErrFileName, &StdOutFileName) == 0) 1054 ||(StdErrFileName != NULL && StdInFileName != NULL && StringNoCaseCompare(&StdErrFileName, &StdInFileName ) == 0) 1055 ||(StdOutFileName != NULL && StdInFileName != NULL && StringNoCaseCompare(&StdOutFileName, &StdInFileName ) == 0) 1056 // 1057 // Check that no 2 variable names are the same 1058 // 1059 ||(StdErrVarName != NULL && StdInVarName != NULL && StringNoCaseCompare(&StdErrVarName , &StdInVarName ) == 0) 1060 ||(StdOutVarName != NULL && StdInVarName != NULL && StringNoCaseCompare(&StdOutVarName , &StdInVarName ) == 0) 1061 ||(StdErrVarName != NULL && StdOutVarName != NULL && StringNoCaseCompare(&StdErrVarName , &StdOutVarName ) == 0) 1062 // 1063 // When a split (using | operator) is in place some are not allowed 1064 // 1065 ||(Split != NULL && Split->SplitStdIn != NULL && (StdInVarName != NULL || StdInFileName != NULL)) 1066 ||(Split != NULL && Split->SplitStdOut != NULL && (StdOutVarName != NULL || StdOutFileName != NULL)) 1067 // 1068 // Check that nothing is trying to be output to 2 locations. 1069 // 1070 ||(StdErrFileName != NULL && StdErrVarName != NULL) 1071 ||(StdOutFileName != NULL && StdOutVarName != NULL) 1072 ||(StdInFileName != NULL && StdInVarName != NULL) 1073 // 1074 // Check for no volatile environment variables 1075 // 1076 ||(StdErrVarName != NULL && !EFI_ERROR (IsVolatileEnv (StdErrVarName, &Volatile)) && !Volatile) 1077 ||(StdOutVarName != NULL && !EFI_ERROR (IsVolatileEnv (StdOutVarName, &Volatile)) && !Volatile) 1078 // 1079 // Cant redirect during a reconnect operation. 1080 // 1081 ||(StrStr(NewCommandLine, L"connect -r") != NULL 1082 && (StdOutVarName != NULL || StdOutFileName != NULL || StdErrFileName != NULL || StdErrVarName != NULL)) 1083 // 1084 // Check that filetypes (Unicode/Ascii) do not change during an append 1085 // 1086 ||(StdOutFileName != NULL && OutUnicode && OutAppend && (!EFI_ERROR(ShellFileExists(StdOutFileName)) && EFI_ERROR(IsUnicodeFile(StdOutFileName)))) 1087 ||(StdErrFileName != NULL && ErrUnicode && ErrAppend && (!EFI_ERROR(ShellFileExists(StdErrFileName)) && EFI_ERROR(IsUnicodeFile(StdErrFileName)))) 1088 ||(StdOutFileName != NULL && !OutUnicode && OutAppend && (!EFI_ERROR(ShellFileExists(StdOutFileName)) && !EFI_ERROR(IsUnicodeFile(StdOutFileName)))) 1089 ||(StdErrFileName != NULL && !ErrUnicode && ErrAppend && (!EFI_ERROR(ShellFileExists(StdErrFileName)) && !EFI_ERROR(IsUnicodeFile(StdErrFileName)))) 1090 ){ 1091 Status = EFI_INVALID_PARAMETER; 1110 // 1111 // Check that no 2 filenames are the same 1112 // 1113 ((StdErrFileName != NULL) && (StdOutFileName != NULL) && (StringNoCaseCompare (&StdErrFileName, &StdOutFileName) == 0)) 1114 || ((StdErrFileName != NULL) && (StdInFileName != NULL) && (StringNoCaseCompare (&StdErrFileName, &StdInFileName) == 0)) 1115 || ((StdOutFileName != NULL) && (StdInFileName != NULL) && (StringNoCaseCompare (&StdOutFileName, &StdInFileName) == 0)) 1116 // 1117 // Check that no 2 variable names are the same 1118 // 1119 || ((StdErrVarName != NULL) && (StdInVarName != NULL) && (StringNoCaseCompare (&StdErrVarName, &StdInVarName) == 0)) 1120 || ((StdOutVarName != NULL) && (StdInVarName != NULL) && (StringNoCaseCompare (&StdOutVarName, &StdInVarName) == 0)) 1121 || ((StdErrVarName != NULL) && (StdOutVarName != NULL) && (StringNoCaseCompare (&StdErrVarName, &StdOutVarName) == 0)) 1122 // 1123 // When a split (using | operator) is in place some are not allowed 1124 // 1125 || ((Split != NULL) && (Split->SplitStdIn != NULL) && ((StdInVarName != NULL) || (StdInFileName != NULL))) 1126 || ((Split != NULL) && (Split->SplitStdOut != NULL) && ((StdOutVarName != NULL) || (StdOutFileName != NULL))) 1127 // 1128 // Check that nothing is trying to be output to 2 locations. 1129 // 1130 || ((StdErrFileName != NULL) && (StdErrVarName != NULL)) 1131 || ((StdOutFileName != NULL) && (StdOutVarName != NULL)) 1132 || ((StdInFileName != NULL) && (StdInVarName != NULL)) 1133 // 1134 // Check for no volatile environment variables 1135 // 1136 || ((StdErrVarName != NULL) && !EFI_ERROR (IsVolatileEnv (StdErrVarName, &Volatile)) && !Volatile) 1137 || ((StdOutVarName != NULL) && !EFI_ERROR (IsVolatileEnv (StdOutVarName, &Volatile)) && !Volatile) 1138 // 1139 // Cant redirect during a reconnect operation. 1140 // 1141 || ( (StrStr (NewCommandLine, L"connect -r") != NULL) 1142 && ((StdOutVarName != NULL) || (StdOutFileName != NULL) || (StdErrFileName != NULL) || (StdErrVarName != NULL))) 1143 // 1144 // Check that filetypes (Unicode/Ascii) do not change during an append 1145 // 1146 || ((StdOutFileName != NULL) && OutUnicode && OutAppend && (!EFI_ERROR (ShellFileExists (StdOutFileName)) && EFI_ERROR (IsUnicodeFile (StdOutFileName)))) 1147 || ((StdErrFileName != NULL) && ErrUnicode && ErrAppend && (!EFI_ERROR (ShellFileExists (StdErrFileName)) && EFI_ERROR (IsUnicodeFile (StdErrFileName)))) 1148 || ((StdOutFileName != NULL) && !OutUnicode && OutAppend && (!EFI_ERROR (ShellFileExists (StdOutFileName)) && !EFI_ERROR (IsUnicodeFile (StdOutFileName)))) 1149 || ((StdErrFileName != NULL) && !ErrUnicode && ErrAppend && (!EFI_ERROR (ShellFileExists (StdErrFileName)) && !EFI_ERROR (IsUnicodeFile (StdErrFileName)))) 1150 ) 1151 { 1152 Status = EFI_INVALID_PARAMETER; 1092 1153 ShellParameters->StdIn = *OldStdIn; 1093 1154 ShellParameters->StdOut = *OldStdOut; 1094 1155 ShellParameters->StdErr = *OldStdErr; 1095 } else if (!EFI_ERROR (Status)){1156 } else if (!EFI_ERROR (Status)) { 1096 1157 // 1097 1158 // Open the Std<Whatever> and we should not have conflicts here... … … 1106 1167 // delete existing file. 1107 1168 // 1108 ShellInfoObject.NewEfiShellProtocol->DeleteFileByName (StdErrFileName);1169 ShellInfoObject.NewEfiShellProtocol->DeleteFileByName (StdErrFileName); 1109 1170 } 1110 Status = ShellOpenFileByName(StdErrFileName, &TempHandle, EFI_FILE_MODE_WRITE|EFI_FILE_MODE_READ|EFI_FILE_MODE_CREATE,0); 1111 if (!ErrAppend && ErrUnicode && !EFI_ERROR(Status)) { 1171 1172 Status = ShellOpenFileByName (StdErrFileName, &TempHandle, EFI_FILE_MODE_WRITE|EFI_FILE_MODE_READ|EFI_FILE_MODE_CREATE, 0); 1173 if (!ErrAppend && ErrUnicode && !EFI_ERROR (Status)) { 1112 1174 Status = WriteFileTag (TempHandle); 1113 1175 } 1114 if (!ErrUnicode && !EFI_ERROR(Status)) { 1115 TempHandle = CreateFileInterfaceFile(TempHandle, FALSE); 1116 ASSERT(TempHandle != NULL); 1176 1177 if (!ErrUnicode && !EFI_ERROR (Status)) { 1178 TempHandle = CreateFileInterfaceFile (TempHandle, FALSE); 1179 ASSERT (TempHandle != NULL); 1117 1180 } 1118 if (!EFI_ERROR(Status)) { 1181 1182 if (!EFI_ERROR (Status)) { 1119 1183 ShellParameters->StdErr = TempHandle; 1120 gST->StdErr = CreateSimpleTextOutOnFile(TempHandle, &gST->StandardErrorHandle, gST->StdErr);1184 gST->StdErr = CreateSimpleTextOutOnFile (TempHandle, &gST->StandardErrorHandle, gST->StdErr); 1121 1185 } 1122 1186 } … … 1125 1189 // StdOut to a file 1126 1190 // 1127 if (!EFI_ERROR (Status) && StdOutFileName != NULL) {1191 if (!EFI_ERROR (Status) && (StdOutFileName != NULL)) { 1128 1192 if (!OutAppend) { 1129 1193 // 1130 1194 // delete existing file. 1131 1195 // 1132 ShellInfoObject.NewEfiShellProtocol->DeleteFileByName (StdOutFileName);1196 ShellInfoObject.NewEfiShellProtocol->DeleteFileByName (StdOutFileName); 1133 1197 } 1134 Status = ShellOpenFileByName(StdOutFileName, &TempHandle, EFI_FILE_MODE_WRITE|EFI_FILE_MODE_READ|EFI_FILE_MODE_CREATE,0); 1198 1199 Status = ShellOpenFileByName (StdOutFileName, &TempHandle, EFI_FILE_MODE_WRITE|EFI_FILE_MODE_READ|EFI_FILE_MODE_CREATE, 0); 1135 1200 if (TempHandle == NULL) { 1136 1201 Status = EFI_INVALID_PARAMETER; 1137 1202 } else { 1138 1203 if (gUnicodeCollation->MetaiMatch (gUnicodeCollation, StdOutFileName, L"NUL")) { 1139 // no-op1140 } else if (!OutAppend && OutUnicode && !EFI_ERROR (Status)) {1204 // no-op 1205 } else if (!OutAppend && OutUnicode && !EFI_ERROR (Status)) { 1141 1206 Status = WriteFileTag (TempHandle); 1142 1207 } else if (OutAppend) { 1143 Status = ShellInfoObject.NewEfiShellProtocol->GetFileSize (TempHandle, &FileSize);1144 if (!EFI_ERROR (Status)) {1208 Status = ShellInfoObject.NewEfiShellProtocol->GetFileSize (TempHandle, &FileSize); 1209 if (!EFI_ERROR (Status)) { 1145 1210 // 1146 1211 // When appending to a new unicode file, write the file tag. … … 1149 1214 // 1150 1215 Status = (FileSize == 0 && OutUnicode) ? 1151 WriteFileTag (TempHandle) : 1152 ShellInfoObject.NewEfiShellProtocol->SetFilePosition ( 1153 TempHandle, 1154 FileSize); 1216 WriteFileTag (TempHandle) : 1217 ShellInfoObject.NewEfiShellProtocol->SetFilePosition ( 1218 TempHandle, 1219 FileSize 1220 ); 1155 1221 } 1156 1222 } 1157 if (!OutUnicode && !EFI_ERROR(Status)) { 1158 TempHandle = CreateFileInterfaceFile(TempHandle, FALSE); 1159 ASSERT(TempHandle != NULL); 1223 1224 if (!OutUnicode && !EFI_ERROR (Status)) { 1225 TempHandle = CreateFileInterfaceFile (TempHandle, FALSE); 1226 ASSERT (TempHandle != NULL); 1160 1227 } 1161 if (!EFI_ERROR(Status)) { 1228 1229 if (!EFI_ERROR (Status)) { 1162 1230 ShellParameters->StdOut = TempHandle; 1163 gST->ConOut = CreateSimpleTextOutOnFile(TempHandle, &gST->ConsoleOutHandle, gST->ConOut);1231 gST->ConOut = CreateSimpleTextOutOnFile (TempHandle, &gST->ConsoleOutHandle, gST->ConOut); 1164 1232 } 1165 1233 } … … 1169 1237 // StdOut to a var 1170 1238 // 1171 if (!EFI_ERROR (Status) && StdOutVarName != NULL) {1239 if (!EFI_ERROR (Status) && (StdOutVarName != NULL)) { 1172 1240 if (!OutAppend) { 1173 1241 // 1174 1242 // delete existing variable. 1175 1243 // 1176 SHELL_SET_ENVIRONMENT_VARIABLE_V (StdOutVarName, 0, L"");1244 SHELL_SET_ENVIRONMENT_VARIABLE_V (StdOutVarName, 0, L""); 1177 1245 } 1178 TempHandle = CreateFileInterfaceEnv(StdOutVarName); 1179 ASSERT(TempHandle != NULL); 1246 1247 TempHandle = CreateFileInterfaceEnv (StdOutVarName); 1248 ASSERT (TempHandle != NULL); 1180 1249 ShellParameters->StdOut = TempHandle; 1181 gST->ConOut = CreateSimpleTextOutOnFile(TempHandle, &gST->ConsoleOutHandle, gST->ConOut);1250 gST->ConOut = CreateSimpleTextOutOnFile (TempHandle, &gST->ConsoleOutHandle, gST->ConOut); 1182 1251 } 1183 1252 … … 1185 1254 // StdErr to a var 1186 1255 // 1187 if (!EFI_ERROR (Status) && StdErrVarName != NULL) {1256 if (!EFI_ERROR (Status) && (StdErrVarName != NULL)) { 1188 1257 if (!ErrAppend) { 1189 1258 // 1190 1259 // delete existing variable. 1191 1260 // 1192 SHELL_SET_ENVIRONMENT_VARIABLE_V (StdErrVarName, 0, L"");1261 SHELL_SET_ENVIRONMENT_VARIABLE_V (StdErrVarName, 0, L""); 1193 1262 } 1194 TempHandle = CreateFileInterfaceEnv(StdErrVarName); 1195 ASSERT(TempHandle != NULL); 1263 1264 TempHandle = CreateFileInterfaceEnv (StdErrVarName); 1265 ASSERT (TempHandle != NULL); 1196 1266 ShellParameters->StdErr = TempHandle; 1197 gST->StdErr = CreateSimpleTextOutOnFile(TempHandle, &gST->StandardErrorHandle, gST->StdErr);1267 gST->StdErr = CreateSimpleTextOutOnFile (TempHandle, &gST->StandardErrorHandle, gST->StdErr); 1198 1268 } 1199 1269 … … 1201 1271 // StdIn from a var 1202 1272 // 1203 if (!EFI_ERROR (Status) && StdInVarName != NULL) {1204 TempHandle = CreateFileInterfaceEnv (StdInVarName);1273 if (!EFI_ERROR (Status) && (StdInVarName != NULL)) { 1274 TempHandle = CreateFileInterfaceEnv (StdInVarName); 1205 1275 if (TempHandle == NULL) { 1206 1276 Status = EFI_OUT_OF_RESOURCES; 1207 1277 } else { 1208 1278 if (!InUnicode) { 1209 TempHandle = CreateFileInterfaceFile (TempHandle, FALSE);1279 TempHandle = CreateFileInterfaceFile (TempHandle, FALSE); 1210 1280 } 1281 1211 1282 Size = 0; 1212 if ( TempHandle == NULL || ((EFI_FILE_PROTOCOL*)TempHandle)->Read(TempHandle, &Size, NULL) != EFI_BUFFER_TOO_SMALL) {1283 if ((TempHandle == NULL) || (((EFI_FILE_PROTOCOL *)TempHandle)->Read (TempHandle, &Size, NULL) != EFI_BUFFER_TOO_SMALL)) { 1213 1284 Status = EFI_INVALID_PARAMETER; 1214 1285 } else { 1215 1286 ShellParameters->StdIn = TempHandle; 1216 gST->ConIn = CreateSimpleTextInOnFile(TempHandle, &gST->ConsoleInHandle);1287 gST->ConIn = CreateSimpleTextInOnFile (TempHandle, &gST->ConsoleInHandle); 1217 1288 } 1218 1289 } … … 1222 1293 // StdIn from a file 1223 1294 // 1224 if (!EFI_ERROR(Status) && StdInFileName != NULL) { 1225 Status = ShellOpenFileByName( 1226 StdInFileName, 1227 &TempHandle, 1228 EFI_FILE_MODE_READ, 1229 0); 1230 if (!EFI_ERROR(Status)) { 1295 if (!EFI_ERROR (Status) && (StdInFileName != NULL)) { 1296 Status = ShellOpenFileByName ( 1297 StdInFileName, 1298 &TempHandle, 1299 EFI_FILE_MODE_READ, 1300 0 1301 ); 1302 if (!EFI_ERROR (Status)) { 1231 1303 if (!InUnicode) { 1232 1304 // 1233 1305 // Create the ASCII->Unicode conversion layer 1234 1306 // 1235 TempHandle = CreateFileInterfaceFile (TempHandle, FALSE);1307 TempHandle = CreateFileInterfaceFile (TempHandle, FALSE); 1236 1308 } 1309 1237 1310 ShellParameters->StdIn = TempHandle; 1238 gST->ConIn = CreateSimpleTextInOnFile(TempHandle, &gST->ConsoleInHandle);1311 gST->ConIn = CreateSimpleTextInOnFile (TempHandle, &gST->ConsoleInHandle); 1239 1312 } 1240 1313 } 1241 1314 } 1242 1315 } 1243 FreePool(CommandLineCopy); 1244 1245 CalculateEfiHdrCrc(&gST->Hdr); 1246 1247 if (gST->ConIn == NULL ||gST->ConOut == NULL) { 1316 1317 FreePool (CommandLineCopy); 1318 1319 CalculateEfiHdrCrc (&gST->Hdr); 1320 1321 if ((gST->ConIn == NULL) || (gST->ConOut == NULL)) { 1248 1322 Status = EFI_OUT_OF_RESOURCES; 1249 1323 } 1250 1324 1251 1325 if (Status == EFI_NOT_FOUND) { 1252 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_SHELL_REDUNDA_REDIR), ShellInfoObject.HiiHandle);1253 } else if (EFI_ERROR (Status)) {1254 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_SHELL_INVALID_REDIR), ShellInfoObject.HiiHandle);1326 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_SHELL_REDUNDA_REDIR), ShellInfoObject.HiiHandle); 1327 } else if (EFI_ERROR (Status)) { 1328 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_SHELL_INVALID_REDIR), ShellInfoObject.HiiHandle); 1255 1329 } 1256 1330 … … 1277 1351 ) 1278 1352 { 1279 SPLIT_LIST *Split; 1280 1281 if (ShellParameters == NULL 1282 ||OldStdIn == NULL 1283 ||OldStdOut == NULL 1284 ||OldStdErr == NULL 1285 ||SystemTableInfo == NULL) { 1353 SPLIT_LIST *Split; 1354 1355 if ( (ShellParameters == NULL) 1356 || (OldStdIn == NULL) 1357 || (OldStdOut == NULL) 1358 || (OldStdErr == NULL) 1359 || (SystemTableInfo == NULL)) 1360 { 1286 1361 return (EFI_INVALID_PARAMETER); 1287 1362 } 1288 if (!IsListEmpty(&ShellInfoObject.SplitList.Link)) { 1289 Split = (SPLIT_LIST*)GetFirstNode(&ShellInfoObject.SplitList.Link); 1363 1364 if (!IsListEmpty (&ShellInfoObject.SplitList.Link)) { 1365 Split = (SPLIT_LIST *)GetFirstNode (&ShellInfoObject.SplitList.Link); 1290 1366 } else { 1291 1367 Split = NULL; 1292 1368 } 1369 1293 1370 if (ShellParameters->StdIn != *OldStdIn) { 1294 if ((Split != NULL && Split->SplitStdIn != ShellParameters->StdIn) || Split == NULL) { 1295 gEfiShellProtocol->CloseFile(ShellParameters->StdIn); 1296 } 1371 if (((Split != NULL) && (Split->SplitStdIn != ShellParameters->StdIn)) || (Split == NULL)) { 1372 gEfiShellProtocol->CloseFile (ShellParameters->StdIn); 1373 } 1374 1297 1375 ShellParameters->StdIn = *OldStdIn; 1298 1376 } 1377 1299 1378 if (ShellParameters->StdOut != *OldStdOut) { 1300 if ((Split != NULL && Split->SplitStdOut != ShellParameters->StdOut) || Split == NULL) { 1301 gEfiShellProtocol->CloseFile(ShellParameters->StdOut); 1302 } 1379 if (((Split != NULL) && (Split->SplitStdOut != ShellParameters->StdOut)) || (Split == NULL)) { 1380 gEfiShellProtocol->CloseFile (ShellParameters->StdOut); 1381 } 1382 1303 1383 ShellParameters->StdOut = *OldStdOut; 1304 1384 } 1385 1305 1386 if (ShellParameters->StdErr != *OldStdErr) { 1306 gEfiShellProtocol->CloseFile (ShellParameters->StdErr);1387 gEfiShellProtocol->CloseFile (ShellParameters->StdErr); 1307 1388 ShellParameters->StdErr = *OldStdErr; 1308 1389 } 1309 1390 1310 1391 if (gST->ConIn != SystemTableInfo->ConIn) { 1311 CloseSimpleTextInOnFile(gST->ConIn); 1312 gST->ConIn = SystemTableInfo->ConIn; 1313 gST->ConsoleInHandle = SystemTableInfo->ConInHandle; 1314 } 1392 CloseSimpleTextInOnFile (gST->ConIn); 1393 gST->ConIn = SystemTableInfo->ConIn; 1394 gST->ConsoleInHandle = SystemTableInfo->ConInHandle; 1395 } 1396 1315 1397 if (gST->ConOut != SystemTableInfo->ConOut) { 1316 CloseSimpleTextOutOnFile(gST->ConOut); 1317 gST->ConOut = SystemTableInfo->ConOut; 1318 gST->ConsoleOutHandle = SystemTableInfo->ConOutHandle; 1319 } 1398 CloseSimpleTextOutOnFile (gST->ConOut); 1399 gST->ConOut = SystemTableInfo->ConOut; 1400 gST->ConsoleOutHandle = SystemTableInfo->ConOutHandle; 1401 } 1402 1320 1403 if (gST->StdErr != SystemTableInfo->ErrOut) { 1321 CloseSimpleTextOutOnFile (gST->StdErr);1322 gST->StdErr 1323 gST->StandardErrorHandle 1324 } 1325 1326 CalculateEfiHdrCrc (&gST->Hdr);1404 CloseSimpleTextOutOnFile (gST->StdErr); 1405 gST->StdErr = SystemTableInfo->ErrOut; 1406 gST->StandardErrorHandle = SystemTableInfo->ErrOutHandle; 1407 } 1408 1409 CalculateEfiHdrCrc (&gST->Hdr); 1327 1410 1328 1411 return (EFI_SUCCESS); 1329 1412 } 1413 1330 1414 /** 1331 1415 Function will replace the current Argc and Argv in the ShellParameters protocol … … 1347 1431 **/ 1348 1432 EFI_STATUS 1349 UpdateArgcArgv (1433 UpdateArgcArgv ( 1350 1434 IN OUT EFI_SHELL_PARAMETERS_PROTOCOL *ShellParameters, 1351 1435 IN CONST CHAR16 *NewCommandLine, … … 1355 1439 ) 1356 1440 { 1357 BOOLEAN 1358 1359 ASSERT (ShellParameters != NULL);1441 BOOLEAN StripParamQuotation; 1442 1443 ASSERT (ShellParameters != NULL); 1360 1444 StripParamQuotation = TRUE; 1361 1445 … … 1363 1447 *OldArgc = ShellParameters->Argc; 1364 1448 } 1449 1365 1450 if (OldArgc != NULL) { 1366 1451 *OldArgv = ShellParameters->Argv; … … 1371 1456 } 1372 1457 1373 return ParseCommandLineToArgs( NewCommandLine, 1374 StripParamQuotation, 1375 &(ShellParameters->Argv), 1376 &(ShellParameters->Argc) 1377 ); 1458 return ParseCommandLineToArgs ( 1459 NewCommandLine, 1460 StripParamQuotation, 1461 &(ShellParameters->Argv), 1462 &(ShellParameters->Argc) 1463 ); 1378 1464 } 1379 1465 … … 1388 1474 **/ 1389 1475 VOID 1390 RestoreArgcArgv (1476 RestoreArgcArgv ( 1391 1477 IN OUT EFI_SHELL_PARAMETERS_PROTOCOL *ShellParameters, 1392 1478 IN CHAR16 ***OldArgv, … … 1394 1480 ) 1395 1481 { 1396 UINTN LoopCounter; 1397 ASSERT(ShellParameters != NULL); 1398 ASSERT(OldArgv != NULL); 1399 ASSERT(OldArgc != NULL); 1482 UINTN LoopCounter; 1483 1484 ASSERT (ShellParameters != NULL); 1485 ASSERT (OldArgv != NULL); 1486 ASSERT (OldArgc != NULL); 1400 1487 1401 1488 if (ShellParameters->Argv != NULL) { 1402 1489 for ( LoopCounter = 0 1403 ; LoopCounter < ShellParameters->Argc 1404 ; LoopCounter++ 1405 ){ 1406 FreePool(ShellParameters->Argv[LoopCounter]); 1407 } 1408 FreePool(ShellParameters->Argv); 1409 } 1490 ; LoopCounter < ShellParameters->Argc 1491 ; LoopCounter++ 1492 ) 1493 { 1494 FreePool (ShellParameters->Argv[LoopCounter]); 1495 } 1496 1497 FreePool (ShellParameters->Argv); 1498 } 1499 1410 1500 ShellParameters->Argv = *OldArgv; 1411 *OldArgv = NULL;1501 *OldArgv = NULL; 1412 1502 ShellParameters->Argc = *OldArgc; 1413 *OldArgc = 0;1503 *OldArgc = 0; 1414 1504 }
Note:
See TracChangeset
for help on using the changeset viewer.