Пример #1
0
/** The getenv function searches an environment list, provided by the host
    environment, for a string that matches the string pointed to by name.  The
    set of environment names and the method for altering the environment list
    are determined by the underlying UEFI Shell implementation.

    @return   The getenv function returns a pointer to a string associated with
              the matched list member.  The string pointed to shall not be
              modified by the program, but may be overwritten by a subsequent
              call to the getenv function.  If the specified name cannot be
              found, a null pointer is returned.
**/
char   *getenv(const char *name)
{
  const CHAR16  *EfiEnv;
  char          *retval = NULL;

  (void)AsciiStrToUnicodeStr( name, gMD->UString);
  EfiEnv = ShellGetEnvironmentVariable(gMD->UString);
  if(EfiEnv != NULL) {
    retval = UnicodeStrToAsciiStr( EfiEnv, gMD->ASgetenv);
  }

  return retval;
}
Пример #2
0
Файл: If.c Проект: jeppeter/vbox
/**
  Determine if String represents a valid profile.

  @param[in] String     The pointer to the string to test.

  @retval TRUE    String is a valid profile.
  @retval FALSE   String is not a valid profile.
**/
BOOLEAN
EFIAPI
IsValidProfile (
    IN CONST CHAR16 *String
)
{
    CONST CHAR16  *ProfilesString;
    CONST CHAR16  *TempLocation;

    ProfilesString = ShellGetEnvironmentVariable(L"profiles");
    ASSERT(ProfilesString != NULL);
    TempLocation = StrStr(ProfilesString, String);
    if ((TempLocation != NULL) && (*(TempLocation-1) == L';') && (*(TempLocation+StrLen(String)) == L';')) {
        return (TRUE);
    }
    return (FALSE);
}
Пример #3
0
/**
  as the real entry point for the application.

  @param[in] ImageHandle    The firmware allocated handle for the EFI image.
  @param[in] SystemTable    A pointer to the EFI System Table.

  @retval EFI_SUCCESS       The entry point is executed successfully.
  @retval other             Some error occurs when executing this entry point.

**/
EFI_STATUS
EFIAPI
UefiMain (
  IN EFI_HANDLE        ImageHandle,
  IN EFI_SYSTEM_TABLE  *SystemTable
  )
{
  EFI_FILE_HANDLE     FileHandle;
  EFI_STATUS          Status;
  CHAR16              FileName[100];
  UINTN               BufferSize;
  UINT64              Position;
  UINT8               Buffer[200];
  EFI_FILE_INFO       *pFileInfo;
  UINT64              Size;
  BOOLEAN             NoFile;
  EFI_SHELL_FILE_INFO *pShellFileInfo;
  LIST_ENTRY          *List;
  // CONST CHAR16              *Tester;

  FileHandle = NULL;
  StrCpy(FileName, L"testfile.txt");
//  Position = 0;
  pFileInfo = NULL;
  Size = 0;
  NoFile = FALSE;
  pShellFileInfo = NULL;
  List = NULL;

  // command line param functions
  Status = ShellCommandLineParse(ParamList, &List, NULL, FALSE);
  // if you put an invalid parameter you SHOULD hit this assert.
  ASSERT_EFI_ERROR(Status);
  if (List) {
    ASSERT(ShellCommandLineGetFlag(List, L"/Param5") == FALSE);
    ASSERT(ShellCommandLineGetFlag(List, L"/Param1") != FALSE);
    ASSERT(StrCmp(ShellCommandLineGetValue(List, L"/Param2"), L"Val1")==0);
    ASSERT(StrCmp(ShellCommandLineGetRawValue(List, 0), L"SimpleApplication.efi")==0);
    // Tester = ShellCommandLineGetValue(List, L"/Param3");
    // Tester = ShellCommandLineGetValue(List, L"/Param4");

    ShellCommandLineFreeVarList(List);
  } else {
    Print(L"param checking skipped.\r\n");
  }

//  return (EFI_SUCCESS);


  ASSERT(ShellGetExecutionBreakFlag() == FALSE);
  ASSERT(StrCmp(ShellGetCurrentDir(NULL), L"f10:\\") == 0);
  Print(L"execution break and get cur dir - pass\r\n");

  ShellSetPageBreakMode(TRUE);

  Status = ShellOpenFileByName(FileName,
                               &FileHandle,
                               EFI_FILE_MODE_CREATE|EFI_FILE_MODE_READ|EFI_FILE_MODE_WRITE,
                               0
                               );
  ASSERT_EFI_ERROR(Status);

  BufferSize = StrSize(FileName);
  Status = ShellWriteFile(FileHandle, &BufferSize, FileName);
  ASSERT_EFI_ERROR(Status);
  Status = ShellGetFilePosition(FileHandle, &Position);
  ASSERT_EFI_ERROR(Status);
  ASSERT(Position == 0x1A);
  Status = ShellSetFilePosition(FileHandle, 0);
  ASSERT_EFI_ERROR(Status);
  BufferSize = sizeof(Buffer) * sizeof(Buffer[0]);
  Status = ShellReadFile(FileHandle, &BufferSize, Buffer);
  ASSERT_EFI_ERROR(Status);
  ASSERT(BufferSize == 0x1A);
  ASSERT(StrCmp((CHAR16*)Buffer, FileName) == 0);
  pFileInfo = ShellGetFileInfo(FileHandle);
  ASSERT(pFileInfo != NULL);
  ASSERT(StrCmp(pFileInfo->FileName, FileName) == 0);
  ASSERT(pFileInfo->FileSize == 0x1A);
  FreePool(pFileInfo);
  pFileInfo = NULL;
  Status = ShellCloseFile(&FileHandle);
  ASSERT_EFI_ERROR(Status);
  Print(L"read, write, create, getinfo - pass\r\n");

  Status = ShellOpenFileByName(FileName,
                               &FileHandle,
                               EFI_FILE_MODE_CREATE|EFI_FILE_MODE_READ|EFI_FILE_MODE_WRITE,
                               0
                               );
  ASSERT_EFI_ERROR(Status);
  pFileInfo = ShellGetFileInfo(FileHandle);
  ASSERT(pFileInfo != NULL);
  pFileInfo->FileSize = 0x20;
  Status = ShellSetFileInfo(FileHandle, pFileInfo);
  FreePool(pFileInfo);
  pFileInfo = NULL;
  ASSERT_EFI_ERROR(Status);
  pFileInfo = ShellGetFileInfo(FileHandle);
  ASSERT(pFileInfo != NULL);
  ASSERT(StrCmp(pFileInfo->FileName, FileName) == 0);
  ASSERT(pFileInfo->PhysicalSize == 0x20);
  ASSERT(pFileInfo->FileSize == 0x20);
  ASSERT((pFileInfo->Attribute&EFI_FILE_DIRECTORY)==0);
  FreePool(pFileInfo);
  Status = ShellGetFileSize(FileHandle, &Size);
  ASSERT(Size == 0x20);
  ASSERT_EFI_ERROR(Status);
  Status = ShellCloseFile(&FileHandle);
  ASSERT_EFI_ERROR(Status);
  Print(L"setinfo and change size, getsize - pass\r\n");

  Status = ShellOpenFileByName(FileName,
                               &FileHandle,
                               EFI_FILE_MODE_CREATE|EFI_FILE_MODE_READ|EFI_FILE_MODE_WRITE,
                               0
                               );
  ASSERT_EFI_ERROR(Status);

  pFileInfo = ShellGetFileInfo(FileHandle);
  ASSERT(pFileInfo != NULL);
  ASSERT(StrCmp(pFileInfo->FileName, FileName) == 0);
  ASSERT(pFileInfo->PhysicalSize == 0x20);
  ASSERT(pFileInfo->FileSize == 0x20);
  ASSERT((pFileInfo->Attribute&EFI_FILE_DIRECTORY)==0);
  FreePool(pFileInfo);
  pFileInfo = NULL;
  Status = ShellDeleteFile(&FileHandle);
  ASSERT_EFI_ERROR(Status);
  Print(L"reopen file - pass\r\n");

  Status = ShellOpenFileByName(FileName,
                               &FileHandle,
                               EFI_FILE_MODE_CREATE|EFI_FILE_MODE_READ|EFI_FILE_MODE_WRITE,
                               0
                               );
  ASSERT_EFI_ERROR(Status);
  pFileInfo = ShellGetFileInfo(FileHandle);
  ASSERT(pFileInfo != NULL);
  ASSERT(StrCmp(pFileInfo->FileName, FileName) == 0);
  ASSERT(pFileInfo->PhysicalSize == 0x0);
  ASSERT(pFileInfo->FileSize == 0x0);
  ASSERT((pFileInfo->Attribute&EFI_FILE_DIRECTORY)==0);
  FreePool(pFileInfo);
  Status = ShellDeleteFile(&FileHandle);
  ASSERT_EFI_ERROR(Status);
  Print(L"size of empty - pass\r\n");

  Status = ShellOpenFileByName(FileName,
                               &FileHandle,
                               EFI_FILE_MODE_READ|EFI_FILE_MODE_WRITE,
                               0
                               );
  ASSERT(Status == EFI_NOT_FOUND);
  ASSERT(FileHandle == NULL);

  Status = ShellCreateDirectory(FileName, &FileHandle);
  ASSERT_EFI_ERROR(Status);
  ASSERT(FileHandle != NULL);
  pFileInfo = ShellGetFileInfo(FileHandle);
  ASSERT(pFileInfo != NULL);
  ASSERT(StrCmp(pFileInfo->FileName, FileName) == 0);
  ASSERT(pFileInfo->Attribute&EFI_FILE_DIRECTORY);
  Status = ShellDeleteFile(&FileHandle);
  ASSERT_EFI_ERROR(Status);
  Print(L"Directory create - pass\r\n");

  // FindFirst and FindNext
  StrCpy(FileName, L"testDir");
  Status = ShellCreateDirectory(FileName, &FileHandle);
  Status = ShellCloseFile(&FileHandle);
  StrCat(FileName, L"\\File.txt");
  Status = ShellOpenFileByName(FileName,
                               &FileHandle,
                               EFI_FILE_MODE_CREATE|EFI_FILE_MODE_READ|EFI_FILE_MODE_WRITE,
                               0
                               );
  ASSERT_EFI_ERROR(Status);
  Status = ShellCloseFile(&FileHandle);
  StrCpy(FileName, L"testDir");
  Status = ShellOpenFileByName(FileName,
                               &FileHandle,
                               EFI_FILE_MODE_CREATE|EFI_FILE_MODE_READ|EFI_FILE_MODE_WRITE,
                               0
                               );
  ASSERT_EFI_ERROR(Status);
  Status = ShellFindFirstFile(FileHandle, &pFileInfo);
  ASSERT_EFI_ERROR(Status);
  Status = ShellFindNextFile(FileHandle, pFileInfo, &NoFile);
  ASSERT_EFI_ERROR(Status);
  ASSERT(NoFile == FALSE);
  Status = ShellFindNextFile(FileHandle, pFileInfo, &NoFile);
  ASSERT_EFI_ERROR(Status);
  ASSERT(NoFile == FALSE);
  Status = ShellFindNextFile(FileHandle, pFileInfo, &NoFile);
  ASSERT_EFI_ERROR(Status);
  ///@todo - why is NoFile never set? limitation of NT32 file system?
  Status = ShellDeleteFile(&FileHandle);
  ASSERT(Status == RETURN_WARN_DELETE_FAILURE);
  Print(L"FindFirst - pass\r\n");
  Print(L"FindNext - Verify with real EFI system.  Cant verify NoFile under NT32\r\n");

  // open and close meta arg
  Status = ShellOpenFileMetaArg(L"testDir\\*.*", EFI_FILE_MODE_READ, &pShellFileInfo);
  ASSERT_EFI_ERROR(Status);
  ASSERT(pShellFileInfo->Status == 0);
  ASSERT(StrCmp(pShellFileInfo->FileName, L"File.txt") == 0);
  ASSERT(pShellFileInfo->Handle);
  ASSERT(pShellFileInfo->Info);
  ASSERT(pShellFileInfo->Info->FileSize == 0);
  ASSERT(StrCmp(pShellFileInfo->Info->FileName, L"File.txt") == 0);
  ASSERT(pShellFileInfo->Info->Attribute == 0);

  Status = ShellCloseFileMetaArg(&pShellFileInfo);
  ASSERT_EFI_ERROR(Status);
  Print(L"Open/Close Meta Arg - pass\r\n");

  // now delete that file and that directory
  StrCat(FileName, L"\\File.txt");
  Status = ShellOpenFileByName(FileName,
                               &FileHandle,
                               EFI_FILE_MODE_CREATE|EFI_FILE_MODE_READ|EFI_FILE_MODE_WRITE,
                               0
                               );
  ASSERT_EFI_ERROR(Status);
  Status = ShellDeleteFile(&FileHandle);
  StrCpy(FileName, L"testDir");
  ASSERT_EFI_ERROR(Status);
  Status = ShellOpenFileByName(FileName,
                               &FileHandle,
                               EFI_FILE_MODE_CREATE|EFI_FILE_MODE_READ|EFI_FILE_MODE_WRITE,
                               0
                               );
  Status = ShellDeleteFile(&FileHandle);
  ASSERT_EFI_ERROR(Status);

  // get environment variable
  // made for testing under nt32
  ASSERT(StrCmp(ShellGetEnvironmentVariable(L"path"), L".;f10:\\efi\\tools;f10:\\efi\\boot;f10:\\;f9:\\efi\\tools;f9:\\efi\\boot;f9:\\") == 0);
  Print(L"ShellGetEnvironmentVariable - pass\r\n");

  // set environment variable
  Status = ShellSetEnvironmentVariable(L"", L"", FALSE);
  ASSERT(Status == EFI_UNSUPPORTED);
  Print(L"ShellSetEnvironmentVariable - pass\r\n");

  // ShellExecute
  Status = ShellExecute(&ImageHandle, L"EmptyApplication.efi", TRUE, NULL, NULL);
  ASSERT_EFI_ERROR(Status);
  // the pass printout for this is performed by EmptyApplication
  Print(L"\r\n");

  // page break mode (done last so we can see the results)
  // we set this true at the begining of the program
  // this is enough lines to trigger the page...
  Print(L"1\r\n2\r\n3\r\n4\r\n5\r\n6\r\n7\r\n8\r\n9\r\n10\r\n11\r\n12\r\n13\r\n14\r\n15\r\n16\r\n17\r\n18\r\n19\r\n20\r\n21\r\n22\r\n23\r\n24\r\n25\r\n26\r\n27\r\n28\r\n29\r\n30\r\n31\r\n");
  ShellSetPageBreakMode(FALSE);
  Print(L"1\r\n2\r\n3\r\n4\r\n5\r\n6\r\n7\r\n8\r\n9\r\n10\r\n11\r\n12\r\n13\r\n14\r\n15\r\n16\r\n17\r\n18\r\n19\r\n20\r\n21\r\n22\r\n23\r\n24\r\n25\r\n26\r\n27\r\n28\r\n29\r\n30\r\n31\r\n32\r\n33\r\n34\r\n35\r\n36\r\n37\r\n38\r\n39\r\n40\r\n41\r\n42\r\n43\r\n44\r\n45\r\n46\r\n47\r\n48\r\n49\r\n50\r\n51\r\n52\r\n53\r\n54\r\n55\r\n56\r\n57\r\n58\r\n59\r\n60\r\n");

  return EFI_SUCCESS;
}
Пример #4
0
Файл: Set.c Проект: etiago/vbox
/**
  Function for 'set' command.

  @param[in] ImageHandle  Handle to the Image (NULL if Internal).
  @param[in] SystemTable  Pointer to the System Table (NULL if Internal).
**/
SHELL_STATUS
EFIAPI
ShellCommandRunSet (
  IN EFI_HANDLE        ImageHandle,
  IN EFI_SYSTEM_TABLE  *SystemTable
  )
{
  EFI_STATUS    Status;
  LIST_ENTRY    *Package;
  CONST CHAR16  *KeyName;
  CONST CHAR16  *Value;
  CHAR16        *ProblemParam;
  SHELL_STATUS  ShellStatus;

  ProblemParam = NULL;
  ShellStatus  = SHELL_SUCCESS;

  //
  // initialize the shell lib (we must be in non-auto-init...)
  //
  Status = ShellInitialize();
  ASSERT_EFI_ERROR(Status);

  //
  // Make sure globals are good...
  //
  Status = CommandInit();
  ASSERT_EFI_ERROR(Status);

  //
  // parse the command line
  //
  Status = ShellCommandLineParse (SetParamList, &Package, &ProblemParam, TRUE);
  if (EFI_ERROR(Status)) {
    if (Status == EFI_VOLUME_CORRUPTED && ProblemParam != NULL) {
      ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellLevel2HiiHandle, ProblemParam);
      FreePool(ProblemParam);
      return (SHELL_INVALID_PARAMETER);
    } else {
      ASSERT(FALSE);
    }
  } else {
    //
    // check for "-?"
    //
    if (ShellCommandLineGetFlag(Package, L"-?")) {
      ASSERT(FALSE);
    } else if (ShellCommandLineGetRawValue(Package, 3) != NULL) {
      ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_MANY), gShellLevel2HiiHandle);
      ShellStatus = SHELL_INVALID_PARAMETER;
    } else if (ShellCommandLineGetRawValue(Package, 1) != NULL && ShellCommandLineGetFlag(Package, L"-d")) {
      ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_MANY), gShellLevel2HiiHandle);
      ShellStatus = SHELL_INVALID_PARAMETER;
    } else if (ShellCommandLineGetFlag(Package, L"-d")) {
      //
      // delete a environment variable
      //
      KeyName = ShellCommandLineGetValue(Package, L"-d");
      if (KeyName == NULL) {
        ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_NO_VALUE), gShellLevel2HiiHandle, L"-d");
        ShellStatus = SHELL_INVALID_PARAMETER;
      } else {
        Status = ShellSetEnvironmentVariable(KeyName, L"", ShellCommandLineGetFlag(Package, L"-v"));
        if (EFI_ERROR(Status)) {
          ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SET_ND), gShellLevel2HiiHandle, KeyName, Status);
          ShellStatus = SHELL_DEVICE_ERROR;
        }
      }
    } else if (ShellCommandLineGetRawValue(Package, 1) == NULL) {
      //
      // print out all current environment variables
      //
      return(PrintAllShellEnvVars());
    } else {
      //
      // we are either printing one or assigning one
      //
      KeyName = ShellCommandLineGetRawValue(Package, 1);
      Value   = ShellCommandLineGetRawValue(Package, 2);
      if (KeyName != NULL && Value != NULL) {
        //
        // assigning one
        //
        Status = ShellSetEnvironmentVariable(KeyName, Value, ShellCommandLineGetFlag(Package, L"-v"));
      } else {
        if (KeyName != NULL) {
          //
          // print out value for this one only.
          //
          Value = ShellGetEnvironmentVariable(KeyName);
          if (Value == NULL) {
            ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SET_NF), gShellLevel2HiiHandle, KeyName);
            ShellStatus = SHELL_SUCCESS;
          } else {
            ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SET_DISP), gShellLevel2HiiHandle, KeyName, Value);
            ShellStatus = SHELL_SUCCESS;
          }
        } else {
          ASSERT(FALSE);
        }
      }
    }
  }

  //
  // free the command line package
  //
  ShellCommandLineFreeVarList (Package);

  return (ShellStatus);
}
Пример #5
0
/**
  Add or update a variable in the environment list

  @param name     Address of a zero terminated name string
  @param value    Address of a zero terminated value string
  @param rewrite  TRUE allows overwriting existing values

  @retval Returns 0 upon success
  @retval Returns -1 upon failure, sets errno with more information

  Errors

  EINVAL - name is NULL or points to a zero length string
  EALREADY - name already set and rewrite set to FALSE
  ENODEV - Unable to set non-volatile version of environment variable
  ENOMEM - Unable to set volatile version of environment variable
  ENOTSUP - Variable storage not supported

**/
int
setenv (
  register const char * name,
  register const char * value,
  int rewrite
  )
{
  CONST CHAR16 * HostName;
  int retval;
  EFI_STATUS Status;
  CHAR16 * UName;
  CHAR16 * UValue;

  //
  //  Assume failure
  //
  retval = -1;

  //
  //  Validate the inputs
  //
  errno = EINVAL;
  if (( NULL != name ) && ( 0 != *name )) {
    //
    //  Get the storage locations for the unicode strings
    //
    UName = &gMD->UString[0];
    UValue = &gMD->UString2[0];

    //
    //  Convert the strings
    //
    AsciiStrToUnicodeStr ( name, UName );
    AsciiStrToUnicodeStr ( value, UValue );

    //
    //  Determine if the string is already present
    //
    errno = EALREADY;
    HostName = ShellGetEnvironmentVariable ( UName );
    if ( rewrite || ( NULL == HostName )) {
      //
      //  Support systems that don't have non-volatile memory
      //
      errno = ENOMEM;
      Status = ShellSetEnvironmentVariable ( UName, UValue, TRUE );
      if ( EFI_ERROR ( Status )) {
        if ( EFI_UNSUPPORTED == Status ) {
          errno = ENOTSUP;
        }
      }
      else {
        //
        //  Permanently set the environment variable
        //
        errno = ENODEV;
        Status = ShellSetEnvironmentVariable ( UName, UValue, FALSE );
        if ( !EFI_ERROR ( Status )) {
          //
          //  Success
          //
          errno = 0;
          retval = 0;
        }
      }
    }
  }

  //
  //  Return the operation status
  //
  return retval;
}
Пример #6
0
/**
  Function for 'edit' command.

  @param[in] ImageHandle  Handle to the Image (NULL if Internal).
  @param[in] SystemTable  Pointer to the System Table (NULL if Internal).
**/
SHELL_STATUS
EFIAPI
ShellCommandRunEdit (
  IN EFI_HANDLE        ImageHandle,
  IN EFI_SYSTEM_TABLE  *SystemTable
  )
{
  EFI_STATUS          Status;
  CHAR16              *Buffer;
  CHAR16              *ProblemParam;
  SHELL_STATUS        ShellStatus;
  LIST_ENTRY          *Package;
  CONST CHAR16        *Cwd;
  CHAR16              *Nfs;
  CHAR16              *Spot;
  CONST CHAR16        *TempParam;
//  SHELL_FILE_HANDLE   TempHandle;

  Buffer      = NULL;
  ShellStatus = SHELL_SUCCESS;
  Nfs         = NULL;

  //
  // initialize the shell lib (we must be in non-auto-init...)
  //
  Status = ShellInitialize();
  ASSERT_EFI_ERROR(Status);

  Status = CommandInit();
  ASSERT_EFI_ERROR(Status);

  //
  // parse the command line
  //
  Status = ShellCommandLineParse (EmptyParamList, &Package, &ProblemParam, TRUE);
  if (EFI_ERROR(Status)) {
    if (Status == EFI_VOLUME_CORRUPTED && ProblemParam != NULL) {
      ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellDebug1HiiHandle, L"edit", ProblemParam);  
      FreePool(ProblemParam);
      ShellStatus = SHELL_INVALID_PARAMETER;
    } else {
      ASSERT(FALSE);
    }
  } else {
    if (ShellCommandLineGetCount(Package) > 2) {
      ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_MANY), gShellDebug1HiiHandle, L"edit");  
      ShellStatus = SHELL_INVALID_PARAMETER;
    } else {
      Cwd = gEfiShellProtocol->GetCurDir(NULL);
      if (Cwd == NULL) {
        Cwd = ShellGetEnvironmentVariable(L"path");
        if (Cwd != NULL) {
          Nfs = StrnCatGrow(&Nfs, NULL, Cwd+3, 0);
          if (Nfs != NULL) {
            Spot = StrStr(Nfs, L";");
            if (Spot != NULL) {
              *Spot = CHAR_NULL;
            }
            Spot = StrStr(Nfs, L"\\");
            if (Spot != NULL) {
              Spot[1] = CHAR_NULL;
            }
            gEfiShellProtocol->SetCurDir(NULL, Nfs);
            FreePool(Nfs);
          } 
        }
      }

      Status = MainEditorInit ();

      if (EFI_ERROR (Status)) {
        gST->ConOut->ClearScreen (gST->ConOut);
        gST->ConOut->EnableCursor (gST->ConOut, TRUE);
        ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN(STR_EDIT_MAIN_INIT_FAILED), gShellDebug1HiiHandle);
      } else {
        MainEditorBackup ();

        //
        // if editor launched with file named
        //
        if (ShellCommandLineGetCount(Package) == 2) {
          TempParam = ShellCommandLineGetRawValue(Package, 1);
          ASSERT(TempParam != NULL);
          FileBufferSetFileName (TempParam);
//          if (EFI_ERROR(ShellFileExists(MainEditor.FileBuffer->FileName))) {
//            Status = ShellOpenFileByName(MainEditor.FileBuffer->FileName, &TempHandle, EFI_FILE_MODE_CREATE|EFI_FILE_MODE_READ|EFI_FILE_MODE_WRITE, 0);
//            if (!EFI_ERROR(Status)) {
//              ShellCloseFile(&TempHandle);
//            }
//          }
        }

        Status = FileBufferRead (MainEditor.FileBuffer->FileName, FALSE);
        if (!EFI_ERROR (Status)) {
          MainEditorRefresh ();

          Status = MainEditorKeyInput ();
        }

        if (Status != EFI_OUT_OF_RESOURCES) {
          //
          // back up the status string
          //
          Buffer = CatSPrint (NULL, L"%s", StatusBarGetString());
        }

        MainEditorCleanup ();

        //
        // print editor exit code on screen
        //
        if (Status == EFI_SUCCESS) {
        } else if (Status == EFI_OUT_OF_RESOURCES) {
          ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN(STR_GEN_OUT_MEM), gShellDebug1HiiHandle, L"edit");  
        } else {
          if (Buffer != NULL) {
            if (StrCmp (Buffer, L"") != 0) {
              //
              // print out the status string
              //
              ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN(STR_EDIT_MAIN_BUFFER), gShellDebug1HiiHandle, Buffer);
            } else {
              ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN(STR_EDIT_MAIN_UNKNOWN_EDITOR_ERR), gShellDebug1HiiHandle);
            }
          } else {
            ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN(STR_EDIT_MAIN_UNKNOWN_EDITOR_ERR), gShellDebug1HiiHandle);
          }
        }

        if (Status != EFI_OUT_OF_RESOURCES) {
          SHELL_FREE_NON_NULL (Buffer);
        }
      }
    }
    ShellCommandLineFreeVarList (Package);
  }
  return ShellStatus;
}