Exemplo n.º 1
0
Arquivo: Cp.c Projeto: jian-tian/UEFI
/**
  Validate and if successful copy all the files from the list into
  destination directory.

  @param[in] FileList       The list of files to copy.
  @param[in] DestDir        The directory to copy files to.
  @param[in] SilentMode     TRUE to eliminate screen output.
  @param[in] RecursiveMode  TRUE to copy directories.

  @retval SHELL_INVALID_PARAMETER   A parameter was invalid.
  @retval SHELL_SUCCESS             The operation was successful.
**/
SHELL_STATUS
EFIAPI
ProcessValidateAndCopyFiles(
    IN       EFI_SHELL_FILE_INFO  *FileList,
    IN CONST CHAR16               *DestDir,
    IN BOOLEAN                    SilentMode,
    IN BOOLEAN                    RecursiveMode
)
{
    SHELL_STATUS        ShellStatus;
    EFI_SHELL_FILE_INFO *List;
    EFI_FILE_INFO       *FileInfo;
    CHAR16              *FullName;

    List      = NULL;
    FullName  = NULL;
    FileInfo  = NULL;

    ShellOpenFileMetaArg((CHAR16*)DestDir, EFI_FILE_MODE_READ, &List);
    if (List != NULL && List->Link.ForwardLink != List->Link.BackLink) {
        ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_MARG_ERROR), gShellLevel2HiiHandle, DestDir);
        ShellStatus = SHELL_INVALID_PARAMETER;
        ShellCloseFileMetaArg(&List);
    } else if (List != NULL) {
        ASSERT(((EFI_SHELL_FILE_INFO *)List->Link.ForwardLink) != NULL);
        ASSERT(((EFI_SHELL_FILE_INFO *)List->Link.ForwardLink)->FullName != NULL);
        FileInfo = gEfiShellProtocol->GetFileInfo(((EFI_SHELL_FILE_INFO *)List->Link.ForwardLink)->Handle);
        ASSERT(FileInfo != NULL);
        StrnCatGrow(&FullName, NULL, ((EFI_SHELL_FILE_INFO *)List->Link.ForwardLink)->FullName, 0);
        ShellCloseFileMetaArg(&List);
        if ((FileInfo->Attribute & EFI_FILE_READ_ONLY) == 0) {
            ShellStatus = ValidateAndCopyFiles(FileList, FullName, SilentMode, RecursiveMode, NULL);
        } else {
            ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_CP_DEST_ERROR), gShellLevel2HiiHandle);
            ShellStatus = SHELL_ACCESS_DENIED;
        }
    } else {
        ShellCloseFileMetaArg(&List);
        ShellStatus = ValidateAndCopyFiles(FileList, DestDir, SilentMode, RecursiveMode, NULL);
    }

    SHELL_FREE_NON_NULL(FileInfo);
    SHELL_FREE_NON_NULL(FullName);
    return (ShellStatus);
}
Exemplo n.º 2
0
/**
  Function for 'touch' 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
ShellCommandRunTouch (
  IN EFI_HANDLE        ImageHandle,
  IN EFI_SYSTEM_TABLE  *SystemTable
  )
{
  EFI_STATUS          Status;
  LIST_ENTRY          *Package;
  CHAR16              *ProblemParam;
  CONST CHAR16        *Param;
  SHELL_STATUS        ShellStatus;
  UINTN               ParamCount;
  EFI_SHELL_FILE_INFO *FileList;
  EFI_SHELL_FILE_INFO *Node;

  ProblemParam        = NULL;
  ShellStatus         = SHELL_SUCCESS;
  ParamCount          = 0;
  FileList            = 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 (ParamList, &Package, &ProblemParam, TRUE);
  if (EFI_ERROR(Status)) {
    if (Status == EFI_VOLUME_CORRUPTED && ProblemParam != NULL) {
      ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellLevel3HiiHandle, L"touch", ProblemParam);  
      FreePool(ProblemParam);
      ShellStatus = SHELL_INVALID_PARAMETER;
    } else {
      ASSERT(FALSE);
    }
  } else {
    //
    // check for "-?"
    //
    if (ShellCommandLineGetFlag(Package, L"-?")) {
      ASSERT(FALSE);
    }
    if (ShellCommandLineGetRawValue(Package, 1) == NULL) {
      //
      // we insufficient parameters
      //
      ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_FEW), gShellLevel3HiiHandle, L"touch");  
      ShellStatus = SHELL_INVALID_PARAMETER;
    } else {
      //
      // get a list with each file specified by parameters
      // if parameter is a directory then add all the files below it to the list
      //
      for ( ParamCount = 1, Param = ShellCommandLineGetRawValue(Package, ParamCount)
          ; Param != NULL
          ; ParamCount++, Param = ShellCommandLineGetRawValue(Package, ParamCount)
         ){
        Status = ShellOpenFileMetaArg((CHAR16*)Param, EFI_FILE_MODE_READ|EFI_FILE_MODE_WRITE, &FileList);
        if (EFI_ERROR(Status)) {
          ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PARAM_INV), gShellLevel3HiiHandle, L"touch", (CHAR16*)Param);  
          ShellStatus = SHELL_NOT_FOUND;
          break;
        }
        //
        // make sure we completed the param parsing sucessfully...
        // Also make sure that any previous action was sucessful
        //
        if (ShellStatus == SHELL_SUCCESS) {
          //
          // check that we have at least 1 file
          //
          if (FileList == NULL || IsListEmpty(&FileList->Link)) {
            ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_FILE_NF), gShellLevel3HiiHandle, L"touch", Param);  
            continue;
          } else {
            //
            // loop through the list and make sure we are not aborting...
            //
            for ( Node = (EFI_SHELL_FILE_INFO*)GetFirstNode(&FileList->Link)
                ; !IsNull(&FileList->Link, &Node->Link) && !ShellGetExecutionBreakFlag()
                ; Node = (EFI_SHELL_FILE_INFO*)GetNextNode(&FileList->Link, &Node->Link)
               ){
              //
              // make sure the file opened ok
              //
              if (EFI_ERROR(Node->Status)){
                ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_FILE_OPEN_FAIL), gShellLevel3HiiHandle, L"touch", Node->FileName);  
                ShellStatus = SHELL_NOT_FOUND;
                continue;
              }

              Status = DoTouchByHandle(Node->FullName, NULL, Node->Handle, ShellCommandLineGetFlag(Package, L"-r"));
              if (EFI_ERROR(Status) && Status != EFI_ACCESS_DENIED) {
                ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_FILE_OPEN_FAIL), gShellLevel3HiiHandle, L"touch", Node->FileName);  
                ShellStatus = SHELL_NOT_FOUND;
              }
            }
          }
        }
        //
        // Free the fileList
        //
        if (FileList != NULL && !IsListEmpty(&FileList->Link)) {
          Status = ShellCloseFileMetaArg(&FileList);
          ASSERT_EFI_ERROR(Status);
        }
        FileList = NULL;
      }
    }

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

  if (ShellGetExecutionBreakFlag()) {
    return (SHELL_ABORTED);
  }

  return (ShellStatus);
}
Exemplo n.º 3
0
Arquivo: Mv.c Projeto: alt0174/edk2
/**
  Function for 'mv' 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
ShellCommandRunMv (
  IN EFI_HANDLE        ImageHandle,
  IN EFI_SYSTEM_TABLE  *SystemTable
  )
{
  EFI_STATUS          Status;
  LIST_ENTRY          *Package;
  CHAR16              *ProblemParam;
  CHAR16              *Cwd;
  UINTN               CwdSize;
  SHELL_STATUS        ShellStatus;
  UINTN               ParamCount;
  UINTN               LoopCounter;
  EFI_SHELL_FILE_INFO *FileList;
  VOID                *Response;

  ProblemParam        = NULL;
  ShellStatus         = SHELL_SUCCESS;
  ParamCount          = 0;
  FileList            = NULL;
  Response            = NULL;

  //
  // initialize the shell lib (we must be in non-auto-init...)
  //
  Status = ShellInitialize();
  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), gShellLevel2HiiHandle, L"mv", ProblemParam);  
      FreePool(ProblemParam);
      ShellStatus = SHELL_INVALID_PARAMETER;
    } else {
      ASSERT(FALSE);
    }
  } else {
    //
    // check for "-?"
    //
    if (ShellCommandLineGetFlag(Package, L"-?")) {
      ASSERT(FALSE);
    }

    switch (ParamCount = ShellCommandLineGetCount(Package)) {
      case 0:
      case 1:
        //
        // we have insufficient parameters
        //
        ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_FEW), gShellLevel2HiiHandle, L"mv");  
        ShellStatus = SHELL_INVALID_PARAMETER;
        break;
      case 2:
        //
        // must have valid CWD for single parameter...
        //
        if (ShellGetCurrentDir(NULL) == NULL){
          ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_NO_CWD), gShellLevel2HiiHandle, L"mv");  
          ShellStatus = SHELL_INVALID_PARAMETER;
        } else {
          Status = ShellOpenFileMetaArg((CHAR16*)ShellCommandLineGetRawValue(Package, 1), EFI_FILE_MODE_WRITE|EFI_FILE_MODE_READ, &FileList);
          if (FileList == NULL || IsListEmpty(&FileList->Link) || EFI_ERROR(Status)) {
            ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_FILE_NF), gShellLevel2HiiHandle, L"mv", ShellCommandLineGetRawValue(Package, 1));  
            ShellStatus = SHELL_NOT_FOUND;
          } else  {
            //
            // ValidateAndMoveFiles will report errors to the screen itself
            //
            CwdSize = StrSize(ShellGetCurrentDir(NULL)) + sizeof(CHAR16);
            Cwd = AllocateZeroPool(CwdSize);
            ASSERT (Cwd != NULL);
            StrCpyS(Cwd, CwdSize/sizeof(CHAR16), ShellGetCurrentDir(NULL));
            StrCatS(Cwd, CwdSize/sizeof(CHAR16), L"\\");
            ShellStatus = ValidateAndMoveFiles(FileList, &Response, Cwd);
            FreePool(Cwd);
          }
        }

        break;
      default:
        ///@todo make sure this works with error half way through and continues...
        for (ParamCount--, LoopCounter = 1 ; LoopCounter < ParamCount ; LoopCounter++) {
          if (ShellGetExecutionBreakFlag()) {
            break;
          }
          Status = ShellOpenFileMetaArg((CHAR16*)ShellCommandLineGetRawValue(Package, LoopCounter), EFI_FILE_MODE_WRITE|EFI_FILE_MODE_READ, &FileList);
          if (FileList == NULL || IsListEmpty(&FileList->Link) || EFI_ERROR(Status)) {
            ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_FILE_NF), gShellLevel2HiiHandle, L"mv", ShellCommandLineGetRawValue(Package, LoopCounter));  
            ShellStatus = SHELL_NOT_FOUND;
          } else  {
            //
            // ValidateAndMoveFiles will report errors to the screen itself
            // Only change ShellStatus if it's sucessful
            //
            if (ShellStatus == SHELL_SUCCESS) {
              ShellStatus = ValidateAndMoveFiles(FileList, &Response, ShellCommandLineGetRawValue(Package, ParamCount));
            } else {
              ValidateAndMoveFiles(FileList, &Response, ShellCommandLineGetRawValue(Package, ParamCount));
            }
          }
          if (FileList != NULL && !IsListEmpty(&FileList->Link)) {
            Status = ShellCloseFileMetaArg(&FileList);
            if (EFI_ERROR(Status) && ShellStatus == SHELL_SUCCESS) {
              ShellStatus = SHELL_ACCESS_DENIED;
              ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_ERR_FILE), gShellLevel2HiiHandle, L"mv", ShellCommandLineGetRawValue(Package, 1), ShellStatus|MAX_BIT);  
            }
          }
        }
        break;
    } // switch on parameter count

    if (FileList != NULL) {
      ShellCloseFileMetaArg(&FileList);
    }

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

  SHELL_FREE_NON_NULL(Response);

  if (ShellGetExecutionBreakFlag()) {
    return (SHELL_ABORTED);
  }

  return (ShellStatus);
}
Exemplo n.º 4
0
Arquivo: Mv.c Projeto: alt0174/edk2
/**
  Function to take a destination path that might contain wildcards and verify
  that there is only a single possible target (IE we cant have wildcards that
  have 2 possible destination).

  if the result is sucessful the caller must free *DestPathPointer.

  @param[in] DestParameter               The original path to the destination.
  @param[in, out] DestPathPointer  A pointer to the callee allocated final path.
  @param[in] Cwd                   A pointer to the current working directory.
  @param[in] SingleSource          TRUE to have only one source file.
  @param[in, out] DestAttr         A pointer to the destination information attribute.

  @retval SHELL_INVALID_PARAMETER  The DestParameter could not be resolved to a location.
  @retval SHELL_INVALID_PARAMETER  The DestParameter could be resolved to more than 1 location.
  @retval SHELL_INVALID_PARAMETER  Cwd is required and is NULL.
  @retval SHELL_SUCCESS            The operation was sucessful.
**/
SHELL_STATUS
EFIAPI
GetDestinationLocation(
  IN CONST CHAR16               *DestParameter,
  IN OUT CHAR16                 **DestPathPointer,
  IN CONST CHAR16               *Cwd,
  IN CONST BOOLEAN              SingleSource,
  IN OUT UINT64                 *DestAttr
  )
{
  EFI_SHELL_FILE_INFO       *DestList;
  EFI_SHELL_FILE_INFO       *Node;
  CHAR16                    *DestPath;
  UINTN                     NewSize;
  UINTN                     CurrentSize;

  DestList = NULL;
  DestPath = NULL;

  ASSERT(DestAttr != NULL);

  if (StrStr(DestParameter, L"\\") == DestParameter) {
    if (Cwd == NULL) {
      return SHELL_INVALID_PARAMETER;
    }
    DestPath = AllocateZeroPool(StrSize(Cwd));
    if (DestPath == NULL) {
      return (SHELL_OUT_OF_RESOURCES);
    }
    StrCpyS(DestPath, StrSize(Cwd) / sizeof(CHAR16), Cwd);
    while (PathRemoveLastItem(DestPath)) ;

    //
    // Append DestParameter beyond '\' which may be present
    //
    CurrentSize = StrSize(DestPath);
    StrnCatGrow(&DestPath, &CurrentSize, &DestParameter[1], 0);

    *DestPathPointer =  DestPath;
    return (SHELL_SUCCESS);
  }
  //
  // get the destination path
  //
  ShellOpenFileMetaArg((CHAR16*)DestParameter, EFI_FILE_MODE_WRITE|EFI_FILE_MODE_READ|EFI_FILE_MODE_CREATE, &DestList);
  if (DestList == NULL || IsListEmpty(&DestList->Link)) {
    //
    // Not existing... must be renaming
    //
    if (StrStr(DestParameter, L":") == NULL) {
      if (Cwd == NULL) {
        ShellCloseFileMetaArg(&DestList);
        ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_NO_CWD), gShellLevel2HiiHandle);
        return (SHELL_INVALID_PARAMETER);
      }
      NewSize = StrSize(Cwd);
      NewSize += StrSize(DestParameter);
      DestPath = AllocateZeroPool(NewSize);
      if (DestPath == NULL) {
        ShellCloseFileMetaArg(&DestList);
        return (SHELL_OUT_OF_RESOURCES);
      }
      StrCpyS(DestPath, NewSize / sizeof(CHAR16), Cwd);
      if (DestPath[StrLen(DestPath)-1] != L'\\' && DestParameter[0] != L'\\') {
        StrCatS(DestPath, NewSize / sizeof(CHAR16), L"\\");
      } else if (DestPath[StrLen(DestPath)-1] == L'\\' && DestParameter[0] == L'\\') {
        ((CHAR16*)DestPath)[StrLen(DestPath)-1] = CHAR_NULL;
      }
      StrCatS(DestPath, NewSize / sizeof(CHAR16), DestParameter);
    } else {
      ASSERT(DestPath == NULL);
      DestPath = StrnCatGrow(&DestPath, NULL, DestParameter, 0);
      if (DestPath == NULL) {
        ShellCloseFileMetaArg(&DestList);
        return (SHELL_OUT_OF_RESOURCES);
      }
    }
  } else {
    Node = (EFI_SHELL_FILE_INFO*)GetFirstNode(&DestList->Link);
    *DestAttr = Node->Info->Attribute;
    //
    // Make sure there is only 1 node in the list.
    //
    if (!IsNodeAtEnd(&DestList->Link, &Node->Link)) {
      ShellCloseFileMetaArg(&DestList);
      ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_MARG_ERROR), gShellLevel2HiiHandle, L"mv", DestParameter);  
      return (SHELL_INVALID_PARAMETER);
    }

    //
    // If we are a directory or a single file, then one node is fine.
    //
    if (ShellIsDirectory(Node->FullName)==EFI_SUCCESS || SingleSource) {
      DestPath = AllocateZeroPool(StrSize(Node->FullName)+sizeof(CHAR16));
      if (DestPath == NULL) {
        ShellCloseFileMetaArg(&DestList);
        return (SHELL_OUT_OF_RESOURCES);
      }
      StrCpyS(DestPath, (StrSize(Node->FullName)+sizeof(CHAR16)) / sizeof(CHAR16), Node->FullName);
      StrCatS(DestPath, (StrSize(Node->FullName)+sizeof(CHAR16)) / sizeof(CHAR16), L"\\");
    } else {
      //
      // cant move multiple files onto a single file.
      //
      ShellCloseFileMetaArg(&DestList);
      ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_FILE_ERROR), gShellLevel2HiiHandle, L"mv", DestParameter);  
      return (SHELL_INVALID_PARAMETER);
    }
  }

  *DestPathPointer =  DestPath;
  ShellCloseFileMetaArg(&DestList);

  return (SHELL_SUCCESS);
}
Exemplo n.º 5
0
/**
  Function for 'for' 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
ShellCommandRunFor (
  IN EFI_HANDLE        ImageHandle,
  IN EFI_SYSTEM_TABLE  *SystemTable
  )
{
  EFI_STATUS          Status;
  SHELL_STATUS        ShellStatus;
  SCRIPT_FILE         *CurrentScriptFile;
  CHAR16              *ArgSet;
  CHAR16              *ArgSetWalker;
  UINTN               ArgSize;
  UINTN               LoopVar;
  SHELL_FOR_INFO      *Info;
  CHAR16              *TempString;
  CHAR16              *TempSpot;
  BOOLEAN             FirstPass;
  EFI_SHELL_FILE_INFO *Node;
  EFI_SHELL_FILE_INFO *FileList;
  UINTN               NewSize;

  ArgSet              = NULL;
  ArgSize             = 0;
  ShellStatus         = SHELL_SUCCESS;
  ArgSetWalker        = NULL;
  TempString          = NULL;
  FirstPass           = FALSE;

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

  Status = CommandInit();
  ASSERT_EFI_ERROR(Status);

  if (!gEfiShellProtocol->BatchIsActive()) {
    ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_NO_SCRIPT), gShellLevel1HiiHandle, L"For");
    return (SHELL_UNSUPPORTED);
  }

  if (gEfiShellParametersProtocol->Argc < 4) {
    ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_FEW), gShellLevel1HiiHandle);
    return (SHELL_INVALID_PARAMETER);
  }

  CurrentScriptFile = ShellCommandGetCurrentScriptFile();
  ASSERT(CurrentScriptFile != NULL);

  if (CurrentScriptFile->CurrentCommand->Data == NULL) {
    FirstPass = TRUE;

    //
    // Make sure that an End exists.
    //
    if (!MoveToTag(GetNextNode, L"endfor", L"for", NULL, CurrentScriptFile, TRUE, TRUE, FALSE)) {
      ShellPrintHiiEx(
        -1, 
        -1, 
        NULL, 
        STRING_TOKEN (STR_SYNTAX_NO_MATCHING), 
        gShellLevel1HiiHandle, 
        L"EndFor", 
        L"For", 
        CurrentScriptFile->CurrentCommand!=NULL
          ?CurrentScriptFile->CurrentCommand->Line:0);
      return (SHELL_DEVICE_ERROR);
    }

    //
    // Process the line.
    //
    if (gEfiShellParametersProtocol->Argv[1][0] != L'%' || gEfiShellParametersProtocol->Argv[1][2] != CHAR_NULL
      ||!((gEfiShellParametersProtocol->Argv[1][1] >= L'a' && gEfiShellParametersProtocol->Argv[1][1] <= L'z')
       ||(gEfiShellParametersProtocol->Argv[1][1] >= L'A' && gEfiShellParametersProtocol->Argv[1][1] <= L'Z'))
     ) {
      ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_INV_VAR), gShellLevel1HiiHandle, gEfiShellParametersProtocol->Argv[1]);
      return (SHELL_INVALID_PARAMETER);
    }

    if (gUnicodeCollation->StriColl(
        gUnicodeCollation,
        L"in",
        gEfiShellParametersProtocol->Argv[2]) == 0) {
      for (LoopVar = 0x3 ; LoopVar < gEfiShellParametersProtocol->Argc ; LoopVar++) {
        ASSERT((ArgSet == NULL && ArgSize == 0) || (ArgSet != NULL));
        if (StrStr(gEfiShellParametersProtocol->Argv[LoopVar], L"*") != NULL
          ||StrStr(gEfiShellParametersProtocol->Argv[LoopVar], L"?") != NULL
          ||StrStr(gEfiShellParametersProtocol->Argv[LoopVar], L"[") != NULL
          ||StrStr(gEfiShellParametersProtocol->Argv[LoopVar], L"]") != NULL) {
          FileList = NULL;
          Status = ShellOpenFileMetaArg ((CHAR16*)gEfiShellParametersProtocol->Argv[LoopVar], EFI_FILE_MODE_READ, &FileList);
          if (EFI_ERROR(Status) || FileList == NULL || IsListEmpty(&FileList->Link)) {
            ArgSet = StrnCatGrow(&ArgSet, &ArgSize, L" \"", 0);
            ArgSet = StrnCatGrow(&ArgSet, &ArgSize, gEfiShellParametersProtocol->Argv[LoopVar], 0);
            ArgSet = StrnCatGrow(&ArgSet, &ArgSize, L"\"", 0);
          } else {
            for (Node = (EFI_SHELL_FILE_INFO *)GetFirstNode(&FileList->Link)
              ;  !IsNull(&FileList->Link, &Node->Link)
              ;  Node = (EFI_SHELL_FILE_INFO *)GetNextNode(&FileList->Link, &Node->Link)
             ){
              ArgSet = StrnCatGrow(&ArgSet, &ArgSize, L" \"", 0);
              ArgSet = StrnCatGrow(&ArgSet, &ArgSize, Node->FullName, 0);
              ArgSet = StrnCatGrow(&ArgSet, &ArgSize, L"\"", 0);
            }
            ShellCloseFileMetaArg(&FileList);
          }
        } else {
          ArgSet = StrnCatGrow(&ArgSet, &ArgSize, L" \"", 0);
          ArgSet = StrnCatGrow(&ArgSet, &ArgSize, gEfiShellParametersProtocol->Argv[LoopVar], 0);
          ArgSet = StrnCatGrow(&ArgSet, &ArgSize, L"\"", 0);
        }
      }
      if (ArgSet == NULL) {
        ShellStatus = SHELL_OUT_OF_RESOURCES;
      } else {
        //
        // set up for an 'in' for loop
        //
        NewSize = StrSize(ArgSet);
        NewSize += sizeof(SHELL_FOR_INFO)+StrSize(gEfiShellParametersProtocol->Argv[1]);
        Info = AllocateZeroPool(NewSize);
        ASSERT(Info != NULL);
        Info->Signature = SHELL_FOR_INFO_SIGNATURE;
        CopyMem(Info->Set, ArgSet, StrSize(ArgSet));
        NewSize = StrSize(gEfiShellParametersProtocol->Argv[1]);
        CopyMem(Info->Set+(StrSize(ArgSet)/sizeof(Info->Set[0])), gEfiShellParametersProtocol->Argv[1], NewSize);
        Info->ReplacementName = Info->Set+StrSize(ArgSet)/sizeof(Info->Set[0]);
        Info->CurrentValue  = (CHAR16*)Info->Set;
        Info->Step          = 0;
        Info->Current       = 0;
        Info->End           = 0;

        if (InternalIsAliasOnList(Info->ReplacementName, &CurrentScriptFile->SubstList)) {
          Info->RemoveSubstAlias  = FALSE;
        } else {
          Info->RemoveSubstAlias  = TRUE;
        }
        CurrentScriptFile->CurrentCommand->Data = Info;
      }
    } else if (gUnicodeCollation->StriColl(
        gUnicodeCollation,
        L"run",
        gEfiShellParametersProtocol->Argv[2]) == 0) {
      for (LoopVar = 0x3 ; LoopVar < gEfiShellParametersProtocol->Argc ; LoopVar++) {
        ASSERT((ArgSet == NULL && ArgSize == 0) || (ArgSet != NULL));
        if (ArgSet == NULL) {
//        ArgSet = StrnCatGrow(&ArgSet, &ArgSize, L"\"", 0);
        } else {
          ArgSet = StrnCatGrow(&ArgSet, &ArgSize, L" ", 0);
        }
        ArgSet = StrnCatGrow(&ArgSet, &ArgSize, gEfiShellParametersProtocol->Argv[LoopVar], 0);
//        ArgSet = StrnCatGrow(&ArgSet, &ArgSize, L" ", 0);
      }
      if (ArgSet == NULL) {
        ShellStatus = SHELL_OUT_OF_RESOURCES;
      } else {
        //
        // set up for a 'run' for loop
        //
        Info = AllocateZeroPool(sizeof(SHELL_FOR_INFO)+StrSize(gEfiShellParametersProtocol->Argv[1]));
        ASSERT(Info != NULL);
        Info->Signature = SHELL_FOR_INFO_SIGNATURE;
        CopyMem(Info->Set, gEfiShellParametersProtocol->Argv[1], StrSize(gEfiShellParametersProtocol->Argv[1]));
        Info->ReplacementName = Info->Set;
        Info->CurrentValue    = NULL;
        ArgSetWalker            = ArgSet;
        if (ArgSetWalker[0] != L'(') {
          ShellPrintHiiEx(
            -1, 
            -1, 
            NULL, 
            STRING_TOKEN (STR_GEN_PROBLEM_SCRIPT), 
            gShellLevel1HiiHandle, 
            ArgSet, 
            CurrentScriptFile!=NULL 
              && CurrentScriptFile->CurrentCommand!=NULL
              ? CurrentScriptFile->CurrentCommand->Line:0);
          ShellStatus = SHELL_INVALID_PARAMETER;
        } else {
          TempSpot = StrStr(ArgSetWalker, L")");
          if (TempSpot != NULL) {
            TempString = TempSpot+1;
            if (*(TempString) != CHAR_NULL) {
              while(TempString != NULL && *TempString == L' ') {
                TempString++;
              }
              if (StrLen(TempString) > 0) {
                TempSpot = NULL;
              }
            }
          }
          if (TempSpot == NULL) {
            ShellPrintHiiEx(
              -1, 
              -1, 
              NULL, 
              STRING_TOKEN (STR_GEN_PROBLEM_SCRIPT), 
              gShellLevel1HiiHandle, 
              CurrentScriptFile!=NULL 
                && CurrentScriptFile->CurrentCommand!=NULL
                ? CurrentScriptFile->CurrentCommand->Line:0);
            ShellStatus = SHELL_INVALID_PARAMETER;
          } else {
            *TempSpot = CHAR_NULL;
            ArgSetWalker++;
            while (ArgSetWalker != NULL && ArgSetWalker[0] == L' ') {
              ArgSetWalker++;
            }
            if (!ShellIsValidForNumber(ArgSetWalker)) {
              ShellPrintHiiEx(
                -1, 
                -1, 
                NULL, 
                STRING_TOKEN (STR_GEN_PROBLEM_SCRIPT), 
                gShellLevel1HiiHandle, 
                ArgSet, 
                CurrentScriptFile!=NULL 
                  && CurrentScriptFile->CurrentCommand!=NULL
                  ? CurrentScriptFile->CurrentCommand->Line:0);
              ShellStatus = SHELL_INVALID_PARAMETER;
            } else {
              if (ArgSetWalker[0] == L'-') {
                Info->Current = 0 - (INTN)ReturnUintn(ArgSetWalker+1);
              } else {
                Info->Current = (INTN)ReturnUintn(ArgSetWalker);
              }
              ArgSetWalker  = StrStr(ArgSetWalker, L" ");
              while (ArgSetWalker != NULL && ArgSetWalker[0] == L' ') {
                ArgSetWalker++;
              }
              if (ArgSetWalker == NULL || *ArgSetWalker == CHAR_NULL || !ShellIsValidForNumber(ArgSetWalker)){
                ShellPrintHiiEx(
                  -1, 
                  -1, 
                  NULL, 
                  STRING_TOKEN (STR_GEN_PROBLEM_SCRIPT), 
                  gShellLevel1HiiHandle, 
                  ArgSet, 
                  CurrentScriptFile!=NULL 
                    && CurrentScriptFile->CurrentCommand!=NULL
                    ? CurrentScriptFile->CurrentCommand->Line:0);
                ShellStatus = SHELL_INVALID_PARAMETER;
              } else {
                if (ArgSetWalker[0] == L'-') {
                  Info->End = 0 - (INTN)ReturnUintn(ArgSetWalker+1);
                } else {
                  Info->End = (INTN)ReturnUintn(ArgSetWalker);
                }
                if (Info->Current < Info->End) {
                  Info->Step            = 1;
                } else {
                  Info->Step            = -1;
                }

                ArgSetWalker  = StrStr(ArgSetWalker, L" ");
                while (ArgSetWalker != NULL && ArgSetWalker[0] == L' ') {
                  ArgSetWalker++;
                }
                if (ArgSetWalker != NULL && *ArgSetWalker != CHAR_NULL) {
                  if (ArgSetWalker == NULL || *ArgSetWalker == CHAR_NULL || !ShellIsValidForNumber(ArgSetWalker)){
                    ShellPrintHiiEx(
                      -1, 
                      -1, 
                      NULL, 
                      STRING_TOKEN (STR_GEN_PROBLEM_SCRIPT), 
                      gShellLevel1HiiHandle, 
                      ArgSet, 
                      CurrentScriptFile!=NULL 
                        && CurrentScriptFile->CurrentCommand!=NULL
                        ? CurrentScriptFile->CurrentCommand->Line:0);
                    ShellStatus = SHELL_INVALID_PARAMETER;
                  } else {
                    if (*ArgSetWalker == L')') {
                      ASSERT(Info->Step == 1 || Info->Step == -1);
                    } else {
                      if (ArgSetWalker[0] == L'-') {
                        Info->Step = 0 - (INTN)ReturnUintn(ArgSetWalker+1);
                      } else {
                        Info->Step = (INTN)ReturnUintn(ArgSetWalker);
                      }

                      if (StrStr(ArgSetWalker, L" ") != NULL) {
                        ShellPrintHiiEx(
                          -1, 
                          -1, 
                          NULL, 
                          STRING_TOKEN (STR_GEN_PROBLEM_SCRIPT), 
                          gShellLevel1HiiHandle, 
                          ArgSet, 
                          CurrentScriptFile!=NULL 
                            && CurrentScriptFile->CurrentCommand!=NULL
                            ? CurrentScriptFile->CurrentCommand->Line:0);
                        ShellStatus = SHELL_INVALID_PARAMETER;
                      }
                    }
                  }
                  
                }
              }
            }
          }
        }
        if (ShellStatus == SHELL_SUCCESS) {
          if (InternalIsAliasOnList(Info->ReplacementName, &CurrentScriptFile->SubstList)) {
            Info->RemoveSubstAlias  = FALSE;
          } else {
            Info->RemoveSubstAlias  = TRUE;
          }
        }
        if (CurrentScriptFile->CurrentCommand != NULL) {
          CurrentScriptFile->CurrentCommand->Data = Info;
        }
      }
    } else {
      ShellPrintHiiEx(
        -1, 
        -1, 
        NULL, 
        STRING_TOKEN (STR_GEN_PROBLEM_SCRIPT), 
        gShellLevel1HiiHandle, 
        ArgSet, 
        CurrentScriptFile!=NULL 
          && CurrentScriptFile->CurrentCommand!=NULL
          ? CurrentScriptFile->CurrentCommand->Line:0);
      ShellStatus = SHELL_INVALID_PARAMETER;
    }
  } else {
    //
    // These need to be NULL since they are used to determine if this is the first pass later on...
    //
    ASSERT(ArgSetWalker == NULL);
    ASSERT(ArgSet       == NULL);
  }

  if (CurrentScriptFile != NULL && CurrentScriptFile->CurrentCommand != NULL) {
    Info = (SHELL_FOR_INFO*)CurrentScriptFile->CurrentCommand->Data;
    if (CurrentScriptFile->CurrentCommand->Reset) {
      Info->CurrentValue  = (CHAR16*)Info->Set;
      FirstPass = TRUE;
      CurrentScriptFile->CurrentCommand->Reset = FALSE;
    }
  } else {
    ShellStatus = SHELL_UNSUPPORTED;
    Info = NULL;
  }
  if (ShellStatus == SHELL_SUCCESS) {
    ASSERT(Info != NULL);
    if (Info->Step != 0) {
      //
      // only advance if not the first pass
      //
      if (!FirstPass) {
        //
        // sequence version of for loop...
        //
        Info->Current += Info->Step;
      }

      TempString = AllocateZeroPool(50*sizeof(CHAR16));
      UnicodeSPrint(TempString, 50*sizeof(CHAR16), L"%d", Info->Current);
      InternalUpdateAliasOnList(Info->ReplacementName, TempString, &CurrentScriptFile->SubstList);
      FreePool(TempString);

      if ((Info->Step > 0 && Info->Current > Info->End) || (Info->Step < 0 && Info->Current < Info->End)) {
        CurrentScriptFile->CurrentCommand->Data = NULL;
        //
        // find the matching endfor (we're done with the loop)
        //
        if (!MoveToTag(GetNextNode, L"endfor", L"for", NULL, CurrentScriptFile, TRUE, FALSE, FALSE)) {
          ShellPrintHiiEx(
            -1, 
            -1, 
            NULL, 
            STRING_TOKEN (STR_SYNTAX_NO_MATCHING), 
            gShellLevel1HiiHandle, 
            L"EndFor", 
            L"For", 
            CurrentScriptFile!=NULL 
              && CurrentScriptFile->CurrentCommand!=NULL
              ? CurrentScriptFile->CurrentCommand->Line:0);
          ShellStatus = SHELL_DEVICE_ERROR;
        }
        if (Info->RemoveSubstAlias) {
          //
          // remove item from list
          //
          InternalRemoveAliasFromList(Info->ReplacementName, &CurrentScriptFile->SubstList);
        }
        FreePool(Info);
      }
    } else {
      //
      // Must be in 'in' version of for loop...
      //
      ASSERT(Info->Set != NULL);
      if (Info->CurrentValue != NULL && *Info->CurrentValue != CHAR_NULL) {
        if (Info->CurrentValue[0] == L' ') {
          Info->CurrentValue++;
        }
        if (Info->CurrentValue[0] == L'\"') {
          Info->CurrentValue++;
        }
        //
        // do the next one of the set
        //
        ASSERT(TempString == NULL);
        TempString = StrnCatGrow(&TempString, NULL, Info->CurrentValue, 0);
        if (TempString == NULL) {
          ShellStatus = SHELL_OUT_OF_RESOURCES;
        } else {
          TempSpot   = StrStr(TempString, L"\" \"");
          if (TempSpot != NULL) {
            *TempSpot = CHAR_NULL;
          }
          while (TempString[StrLen(TempString)-1] == L'\"') {
            TempString[StrLen(TempString)-1] = CHAR_NULL;
          }
          InternalUpdateAliasOnList(Info->ReplacementName, TempString, &CurrentScriptFile->SubstList);
          Info->CurrentValue += StrLen(TempString);

          if (Info->CurrentValue[0] == L'\"') {
            Info->CurrentValue++;
          }
          while (Info->CurrentValue[0] == L' ') {
            Info->CurrentValue++;
          }
          if (Info->CurrentValue[0] == L'\"') {
            Info->CurrentValue++;
          }
          FreePool(TempString);
        }
      } else {
        CurrentScriptFile->CurrentCommand->Data = NULL;
        //
        // find the matching endfor (we're done with the loop)
        //
        if (!MoveToTag(GetNextNode, L"endfor", L"for", NULL, CurrentScriptFile, TRUE, FALSE, FALSE)) {
          ShellPrintHiiEx(
            -1, 
            -1, 
            NULL, 
            STRING_TOKEN (STR_SYNTAX_NO_MATCHING), 
            gShellLevel1HiiHandle, 
            L"EndFor", 
            L"For", 
            CurrentScriptFile!=NULL 
              && CurrentScriptFile->CurrentCommand!=NULL
              ? CurrentScriptFile->CurrentCommand->Line:0);
          ShellStatus = SHELL_DEVICE_ERROR;
        }
        if (Info->RemoveSubstAlias) {
          //
          // remove item from list
          //
          InternalRemoveAliasFromList(Info->ReplacementName, &CurrentScriptFile->SubstList);
        }
        FreePool(Info);
      }
    }
  }
  if (ArgSet != NULL) {
    FreePool(ArgSet);
  }
  return (ShellStatus);
}
Exemplo n.º 6
0
/**
  Function for 'loadpcirom' 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
ShellCommandRunLoadPciRom (
  IN EFI_HANDLE        ImageHandle,
  IN EFI_SYSTEM_TABLE  *SystemTable
  )
{
  EFI_SHELL_FILE_INFO     *FileList;
  UINTN                   SourceSize;
  UINT8                   *File1Buffer;
  EFI_STATUS              Status;
  LIST_ENTRY              *Package;
  CHAR16                  *ProblemParam;
  SHELL_STATUS            ShellStatus;
  BOOLEAN                 Connect;
  CONST CHAR16            *Param;
  UINTN                   ParamCount;
  EFI_SHELL_FILE_INFO     *Node;
  //
  // Local variable initializations
  //
  File1Buffer = NULL;
  ShellStatus = SHELL_SUCCESS;
  FileList    = NULL;


  //
  // verify number of arguments
  //
  Status = ShellCommandLineParse (ParamList, &Package, &ProblemParam, TRUE);
  if (EFI_ERROR(Status)) {
    if (Status == EFI_VOLUME_CORRUPTED && ProblemParam != NULL) {
      ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellDebug1HiiHandle, ProblemParam);
      FreePool(ProblemParam);
      ShellStatus = SHELL_INVALID_PARAMETER;
    } else {
      ASSERT(FALSE);
    }
  } else {
    if (ShellCommandLineGetCount(Package) < 2) {
      ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_FEW), gShellDebug1HiiHandle);
      ShellStatus = SHELL_INVALID_PARAMETER;
    } else {
      if (ShellCommandLineGetFlag(Package, L"-nc")) {
        Connect = FALSE;
      } else {
        Connect = TRUE;
      }

      //
      // get a list with each file specified by parameters
      // if parameter is a directory then add all the files below it to the list
      //
      for ( ParamCount = 1, Param = ShellCommandLineGetRawValue(Package, ParamCount)
          ; Param != NULL
          ; ParamCount++, Param = ShellCommandLineGetRawValue(Package, ParamCount)
         ){
        Status = ShellOpenFileMetaArg((CHAR16*)Param, EFI_FILE_MODE_WRITE|EFI_FILE_MODE_READ, &FileList);
        if (EFI_ERROR(Status)) {
          ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_FILE_OPEN_FAIL), gShellDebug1HiiHandle, Param, Status);
          ShellStatus = SHELL_ACCESS_DENIED;
          break;
        }
      }
      if (ShellStatus == SHELL_SUCCESS  && FileList != NULL) {
        //
        // loop through the list and make sure we are not aborting...
        //
        for ( Node = (EFI_SHELL_FILE_INFO*)GetFirstNode(&FileList->Link)
            ; !IsNull(&FileList->Link, &Node->Link) && !ShellGetExecutionBreakFlag()
            ; Node = (EFI_SHELL_FILE_INFO*)GetNextNode(&FileList->Link, &Node->Link)
           ){
          if (EFI_ERROR(Node->Status)){
            ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_FILE_OPEN_FAIL), gShellDebug1HiiHandle, Node->FullName);
            ShellStatus = SHELL_INVALID_PARAMETER;
            continue;
          }
          if (FileHandleIsDirectory(Node->Handle) == EFI_SUCCESS) {
            ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_FILE_NOT_DIR), gShellDebug1HiiHandle, Node->FullName);
            ShellStatus = SHELL_INVALID_PARAMETER;
            continue;
          }
          SourceSize  = (UINTN) Node->Info->FileSize;
          File1Buffer = AllocateZeroPool (SourceSize);
          ASSERT(File1Buffer != NULL);
          Status = gEfiShellProtocol->ReadFile(Node->Handle, &SourceSize, File1Buffer);
          if (EFI_ERROR(Status)) {
            ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_READ_FAIL), gShellDebug1HiiHandle, Node->FullName);
            ShellStatus = SHELL_INVALID_PARAMETER;
          } else {
            Status = LoadEfiDriversFromRomImage (
                      File1Buffer,
                      SourceSize,
                      Node->FullName
                     );

            ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_LOAD_PCI_ROM_RES), gShellDebug1HiiHandle, Node->FullName, Status);
          }
          FreePool(File1Buffer);
        }
      } else if (ShellStatus == SHELL_SUCCESS) {
        ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_FILE_NOT_SPEC), gShellDebug1HiiHandle);
        ShellStatus = SHELL_NOT_FOUND;
      }
      if (FileList != NULL && !IsListEmpty(&FileList->Link)) {
        Status = ShellCloseFileMetaArg(&FileList);
      }
      FileList = NULL;

      if (Connect) {
        Status = LoadPciRomConnectAllDriversToAllControllers ();
      }
    }
  }

  return (ShellStatus);
}
Exemplo n.º 7
0
Arquivo: Ls.c Projeto: shijunjing/edk2
/**
  print out the list of files and directories from the LS command

  @param[in] Rec            TRUE to automatically recurse into each found directory
                            FALSE to only list the specified directory.
  @param[in] Attribs        List of required Attribute for display.
                            If 0 then all non-system and non-hidden files will be printed.
  @param[in] Sfo            TRUE to use Standard Format Output, FALSE otherwise
  @param[in] RootPath       String with starting path to search in.
  @param[in] SearchString   String with search string.
  @param[in] Found          Set to TRUE, if anyone were found.
  @param[in] Count          The count of bits enabled in Attribs.
  @param[in] TimeZone       The current time zone offset.

  @retval SHELL_SUCCESS     the printing was sucessful.
**/
SHELL_STATUS
PrintLsOutput(
  IN CONST BOOLEAN Rec,
  IN CONST UINT64  Attribs,
  IN CONST BOOLEAN Sfo,
  IN CONST CHAR16  *RootPath,
  IN CONST CHAR16  *SearchString,
  IN       BOOLEAN *Found,
  IN CONST UINTN   Count,
  IN CONST INT16   TimeZone
  )
{
  EFI_STATUS            Status;
  EFI_SHELL_FILE_INFO   *ListHead;
  EFI_SHELL_FILE_INFO   *Node;
  SHELL_STATUS          ShellStatus;
  UINT64                FileCount;
  UINT64                DirCount;
  UINT64                FileSize;
  UINTN                 LongestPath;
  CHAR16                *CorrectedPath;
  BOOLEAN               FoundOne;
  BOOLEAN               HeaderPrinted;
  EFI_TIME              LocalTime;

  HeaderPrinted = FALSE;
  FileCount     = 0;
  DirCount      = 0;
  FileSize      = 0;
  ListHead      = NULL;
  ShellStatus   = SHELL_SUCCESS;
  LongestPath   = 0;
  CorrectedPath = NULL;

  if (Found != NULL) {
    FoundOne = *Found;
  } else {
    FoundOne = FALSE;
  }

  CorrectedPath = StrnCatGrow(&CorrectedPath, &LongestPath, RootPath,     0);
  if (CorrectedPath == NULL) {
    return SHELL_OUT_OF_RESOURCES;
  }
  if (CorrectedPath[StrLen(CorrectedPath)-1] != L'\\'
    &&CorrectedPath[StrLen(CorrectedPath)-1] != L'/') {
    CorrectedPath = StrnCatGrow(&CorrectedPath, &LongestPath, L"\\",     0);
  }
  CorrectedPath = StrnCatGrow(&CorrectedPath, &LongestPath, SearchString, 0);
  if (CorrectedPath == NULL) {
    return (SHELL_OUT_OF_RESOURCES);
  }

  PathCleanUpDirectories(CorrectedPath);

  Status = ShellOpenFileMetaArg((CHAR16*)CorrectedPath, EFI_FILE_MODE_READ, &ListHead);
  if (!EFI_ERROR(Status)) {
    if (ListHead == NULL || IsListEmpty(&ListHead->Link)) {
      SHELL_FREE_NON_NULL(CorrectedPath);
      return (SHELL_SUCCESS);
    }

    if (Sfo && Found == NULL) {
      PrintSfoVolumeInfoTableEntry(ListHead);
    }

    for ( Node = (EFI_SHELL_FILE_INFO *)GetFirstNode(&ListHead->Link), LongestPath = 0
        ; !IsNull(&ListHead->Link, &Node->Link)
        ; Node = (EFI_SHELL_FILE_INFO *)GetNextNode(&ListHead->Link, &Node->Link)
        ){
      if (ShellGetExecutionBreakFlag ()) {
        ShellStatus = SHELL_ABORTED;
        break;
      }
      ASSERT(Node != NULL);

      //
      // Change the file time to local time.
      //
      Status = gRT->GetTime(&LocalTime, NULL);
      if (!EFI_ERROR (Status)) {
        if ((Node->Info->CreateTime.TimeZone != EFI_UNSPECIFIED_TIMEZONE) &&
            (Node->Info->CreateTime.Month >= 1 && Node->Info->CreateTime.Month <= 12)) {
          //
          // FileTimeToLocalTime () requires Month is in a valid range, other buffer out-of-band access happens.
          //
          FileTimeToLocalTime (&Node->Info->CreateTime, LocalTime.TimeZone);
        }
        if ((Node->Info->LastAccessTime.TimeZone != EFI_UNSPECIFIED_TIMEZONE) &&
            (Node->Info->LastAccessTime.Month >= 1 && Node->Info->LastAccessTime.Month <= 12)) {
          FileTimeToLocalTime (&Node->Info->LastAccessTime, LocalTime.TimeZone);
        }
        if ((Node->Info->ModificationTime.TimeZone != EFI_UNSPECIFIED_TIMEZONE) &&
            (Node->Info->ModificationTime.Month >= 1 && Node->Info->ModificationTime.Month <= 12)) {
          FileTimeToLocalTime (&Node->Info->ModificationTime, LocalTime.TimeZone);
        }
      }

      if (LongestPath < StrSize(Node->FullName)) {
        LongestPath = StrSize(Node->FullName);
      }
      ASSERT(Node->Info != NULL);
      ASSERT((Node->Info->Attribute & EFI_FILE_VALID_ATTR) == Node->Info->Attribute);
      if (Attribs == 0) {
        //
        // NOT system & NOT hidden
        //
        if ( (Node->Info->Attribute & EFI_FILE_SYSTEM)
          || (Node->Info->Attribute & EFI_FILE_HIDDEN)
         ){
          continue;
        }
      } else if ((Attribs != EFI_FILE_VALID_ATTR) ||
                 (Count == 5)) {
        //
        // Only matches the bits which "Attribs" contains, not
        // all files/directories with any of the bits.
        // Count == 5 is used to tell the difference between a user
        // specifying all bits (EX: -arhsda) and just specifying
        // -a (means display all files with any attribute).
        //
        if ( (Node->Info->Attribute & Attribs) != Attribs) {
          continue;
        }
      }

      if (!Sfo && !HeaderPrinted) {
        PathRemoveLastItem (CorrectedPath);
        PrintNonSfoHeader(CorrectedPath);
      }
      PrintFileInformation(Sfo, Node, &FileCount, &FileSize, &DirCount);
      FoundOne = TRUE;
      HeaderPrinted = TRUE;
    }

    if (!Sfo && ShellStatus != SHELL_ABORTED) {
      PrintNonSfoFooter(FileCount, FileSize, DirCount);
    }
  }

  if (Rec && ShellStatus != SHELL_ABORTED) {
    //
    // Re-Open all the files under the starting path for directories that didnt necessarily match our file filter
    //
    ShellCloseFileMetaArg(&ListHead);
    CorrectedPath[0] = CHAR_NULL;
    CorrectedPath = StrnCatGrow(&CorrectedPath, &LongestPath, RootPath, 0);
    if (CorrectedPath == NULL) {
      return SHELL_OUT_OF_RESOURCES;
    }
    if (CorrectedPath[StrLen(CorrectedPath)-1] != L'\\'
      &&CorrectedPath[StrLen(CorrectedPath)-1] != L'/') {
      CorrectedPath = StrnCatGrow(&CorrectedPath, &LongestPath, L"\\",     0);
    }
    CorrectedPath = StrnCatGrow(&CorrectedPath, &LongestPath, L"*",     0);
    Status = ShellOpenFileMetaArg((CHAR16*)CorrectedPath, EFI_FILE_MODE_READ, &ListHead);

    if (!EFI_ERROR(Status)) {
      for ( Node = (EFI_SHELL_FILE_INFO *)GetFirstNode(&ListHead->Link)
          ; !IsNull(&ListHead->Link, &Node->Link) && ShellStatus == SHELL_SUCCESS
          ; Node = (EFI_SHELL_FILE_INFO *)GetNextNode(&ListHead->Link, &Node->Link)
         ){
        if (ShellGetExecutionBreakFlag ()) {
          ShellStatus = SHELL_ABORTED;
          break;
        }

        //
        // recurse on any directory except the traversing ones...
        //
        if (((Node->Info->Attribute & EFI_FILE_DIRECTORY) == EFI_FILE_DIRECTORY)
          && StrCmp(Node->FileName, L".") != 0
          && StrCmp(Node->FileName, L"..") != 0
         ){
          ShellStatus = PrintLsOutput(
            Rec,
            Attribs,
            Sfo,
            Node->FullName,
            SearchString,
            &FoundOne,
            Count,
            TimeZone);

          //
          // Since it's running recursively, we have to break immediately when returned SHELL_ABORTED
          //
          if (ShellStatus == SHELL_ABORTED) {
            break;
          }
        }
      }
    }
  }

  SHELL_FREE_NON_NULL(CorrectedPath);
  ShellCloseFileMetaArg(&ListHead);

  if (Found == NULL && !FoundOne) {
    return (SHELL_NOT_FOUND);
  }

  if (Found != NULL) {
    *Found = FoundOne;
  }

  return (ShellStatus);
}
Exemplo n.º 8
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;
}
Exemplo n.º 9
0
Arquivo: Cp.c Projeto: Cutty/edk2
/**
  Function for 'cp' 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
ShellCommandRunCp (
  IN EFI_HANDLE        ImageHandle,
  IN EFI_SYSTEM_TABLE  *SystemTable
  )
{
  EFI_STATUS          Status;
  LIST_ENTRY          *Package;
  CHAR16              *ProblemParam;
  SHELL_STATUS        ShellStatus;
  UINTN               ParamCount;
  UINTN               LoopCounter;
  EFI_SHELL_FILE_INFO *FileList;
  BOOLEAN             SilentMode;
  BOOLEAN             RecursiveMode;
  CONST CHAR16        *Cwd;

  ProblemParam        = NULL;
  ShellStatus         = SHELL_SUCCESS;
  ParamCount          = 0;
  FileList            = 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 (ParamList, &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);
      ShellStatus = SHELL_INVALID_PARAMETER;
    } else {
      ASSERT(FALSE);
    }
  } else {
    //
    // check for "-?"
    //
    if (ShellCommandLineGetFlag(Package, L"-?")) {
      ASSERT(FALSE);
    }

    //
    // Initialize SilentMode and RecursiveMode
    //
    if (gEfiShellProtocol->BatchIsActive()) {
      SilentMode = TRUE;
    } else {
      SilentMode = ShellCommandLineGetFlag(Package, L"-q");
    }
    RecursiveMode = ShellCommandLineGetFlag(Package, L"-r");

    switch (ParamCount = ShellCommandLineGetCount(Package)) {
      case 0:
      case 1:
        //
        // we have insufficient parameters
        //
        ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_FEW), gShellLevel2HiiHandle);
        ShellStatus = SHELL_INVALID_PARAMETER;
        break;
      case 2:
        //
        // must have valid CWD for single parameter...
        //
        Cwd = ShellGetCurrentDir(NULL);
        if (Cwd == NULL){
          ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_NO_CWD), gShellLevel2HiiHandle);
          ShellStatus = SHELL_INVALID_PARAMETER;
        } else {
          Status = ShellOpenFileMetaArg((CHAR16*)ShellCommandLineGetRawValue(Package, 1), EFI_FILE_MODE_WRITE|EFI_FILE_MODE_READ, &FileList);
          if (FileList == NULL || IsListEmpty(&FileList->Link) || EFI_ERROR(Status)) {
            ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_FILE_NF), gShellLevel2HiiHandle, ShellCommandLineGetRawValue(Package, 1));
            ShellStatus = SHELL_NOT_FOUND;
          } else  {
            ShellStatus = ProcessValidateAndCopyFiles(FileList, Cwd, SilentMode, RecursiveMode);
          }
        }

        break;
      default:
        //
        // Make a big list of all the files...
        //
        for (ParamCount--, LoopCounter = 1 ; LoopCounter < ParamCount && ShellStatus == SHELL_SUCCESS ; LoopCounter++) {
          if (ShellGetExecutionBreakFlag()) {
            break;
          }
          Status = ShellOpenFileMetaArg((CHAR16*)ShellCommandLineGetRawValue(Package, LoopCounter), EFI_FILE_MODE_WRITE|EFI_FILE_MODE_READ, &FileList);
          if (EFI_ERROR(Status) || FileList == NULL || IsListEmpty(&FileList->Link)) {
            ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_FILE_NF), gShellLevel2HiiHandle, ShellCommandLineGetRawValue(Package, LoopCounter));
            ShellStatus = SHELL_NOT_FOUND;
          }
        }
        if (ShellStatus != SHELL_SUCCESS) {
          Status = ShellCloseFileMetaArg(&FileList);
        } else {
          //
          // now copy them all...
          //
          if (FileList != NULL && !IsListEmpty(&FileList->Link)) {
            ShellStatus = ProcessValidateAndCopyFiles(FileList, PathCleanUpDirectories((CHAR16*)ShellCommandLineGetRawValue(Package, ParamCount)), SilentMode, RecursiveMode);
            Status = ShellCloseFileMetaArg(&FileList);
            if (EFI_ERROR(Status) && ShellStatus == SHELL_SUCCESS) {
              ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_ERR_FILE), gShellLevel2HiiHandle, ShellCommandLineGetRawValue(Package, ParamCount), ShellStatus|MAX_BIT);
              ShellStatus = SHELL_ACCESS_DENIED;
            }
          }
        }
        break;
    } // switch on parameter count

    if (FileList != NULL) {
      ShellCloseFileMetaArg(&FileList);
    }

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

  if (ShellGetExecutionBreakFlag()) {
    return (SHELL_ABORTED);
  }

  return (ShellStatus);
}
Exemplo n.º 10
0
Arquivo: Cp.c Projeto: Cutty/edk2
/**
  Function to Copy one file to another location

  If the destination exists the user will be prompted and the result put into *resp

  @param[in] Source     pointer to source file name
  @param[in] Dest       pointer to destination file name
  @param[out] Resp      pointer to response from question.  Pass back on looped calling
  @param[in] SilentMode whether to run in quiet mode or not

  @retval SHELL_SUCCESS   The source file was copied to the destination
**/
SHELL_STATUS
EFIAPI
CopySingleFile(
  IN CONST CHAR16 *Source,
  IN CONST CHAR16 *Dest,
  OUT VOID        **Resp,
  IN BOOLEAN      SilentMode
  )
{
  VOID                  *Response;
  UINTN                 ReadSize;
  SHELL_FILE_HANDLE     SourceHandle;
  SHELL_FILE_HANDLE     DestHandle;
  EFI_STATUS            Status;
  VOID                  *Buffer;
  CHAR16                *TempName;
  UINTN                 Size;
  EFI_SHELL_FILE_INFO   *List;
  SHELL_STATUS          ShellStatus;
  UINT64                SourceFileSize;
  UINT64                DestFileSize;
  EFI_FILE_PROTOCOL     *DestVolumeFP;
  EFI_FILE_SYSTEM_INFO  *DestVolumeInfo;
  UINTN                 DestVolumeInfoSize;

  ASSERT(Resp != NULL);

  SourceHandle    = NULL;
  DestHandle      = NULL;
  Response        = *Resp;
  List            = NULL;
  DestVolumeInfo  = NULL;

  ReadSize = PcdGet16(PcdShellFileOperationSize);
  // Why bother copying a file to itself
  if (StrCmp(Source, Dest) == 0) {
    return (SHELL_SUCCESS);
  }

  //
  // Open destination file without create
  //
  Status = ShellOpenFileByName(Dest, &DestHandle, EFI_FILE_MODE_READ|EFI_FILE_MODE_WRITE, 0);

  //
  // close file
  //
  if (DestHandle != NULL) {
    ShellCloseFile(&DestHandle);
    DestHandle   = NULL;
  }

  //
  // if the destination file existed check response and possibly prompt user
  //
  if (!EFI_ERROR(Status)) {
    if (Response == NULL && !SilentMode) {
      Status = ShellPromptForResponseHii(ShellPromptResponseTypeYesNoAllCancel, STRING_TOKEN (STR_GEN_DEST_EXIST_OVR), gShellLevel2HiiHandle, &Response);
    }
    //
    // possibly return based on response
    //
    if (!SilentMode) {
      switch (*(SHELL_PROMPT_RESPONSE*)Response) {
        case ShellPromptResponseNo:
          //
          // return success here so we dont stop the process
          //
          return (SHELL_SUCCESS);
        case ShellPromptResponseCancel:
          *Resp = Response;
          //
          // indicate to stop everything
          //
          return (SHELL_ABORTED);
        case ShellPromptResponseAll:
          *Resp = Response;
        case ShellPromptResponseYes:
          break;
        default:
          return SHELL_ABORTED;
      }
    }
  }

  if (ShellIsDirectory(Source) == EFI_SUCCESS) {
    Status = ShellCreateDirectory(Dest, &DestHandle);
    if (EFI_ERROR(Status)) {
      return (SHELL_ACCESS_DENIED);
    }

    //
    // Now copy all the files under the directory...
    //
    TempName    = NULL;
    Size        = 0;
    StrnCatGrow(&TempName, &Size, Source, 0);
    StrnCatGrow(&TempName, &Size, L"\\*", 0);
    if (TempName != NULL) {
      ShellOpenFileMetaArg((CHAR16*)TempName, EFI_FILE_MODE_READ, &List);
      *TempName = CHAR_NULL;
      StrnCatGrow(&TempName, &Size, Dest, 0);
      StrnCatGrow(&TempName, &Size, L"\\", 0);
      ShellStatus = ValidateAndCopyFiles(List, TempName, SilentMode, TRUE, Resp);
      ShellCloseFileMetaArg(&List);
      SHELL_FREE_NON_NULL(TempName);
      Size = 0;
    }
  } else {
      //
      // open file with create enabled
      //
      Status = ShellOpenFileByName(Dest, &DestHandle, EFI_FILE_MODE_READ|EFI_FILE_MODE_WRITE|EFI_FILE_MODE_CREATE, 0);
      if (EFI_ERROR(Status)) {
        return (SHELL_ACCESS_DENIED);
      }

      //
      // open source file
      //
      Status = ShellOpenFileByName(Source, &SourceHandle, EFI_FILE_MODE_READ, 0);
      ASSERT_EFI_ERROR(Status);

      //
      //get file size of source file and freespace available on destination volume
      //
      ShellGetFileSize(SourceHandle, &SourceFileSize);
      ShellGetFileSize(DestHandle, &DestFileSize);

      //
      //if the destination file already exists then it will be replaced, meaning the sourcefile effectively needs less storage space
      //
      if(DestFileSize < SourceFileSize){
        SourceFileSize -= DestFileSize;
      } else {
        SourceFileSize = 0;
      }

      //
      //get the system volume info to check the free space
      //
      DestVolumeFP = ConvertShellHandleToEfiFileProtocol(DestHandle);
      DestVolumeInfo = NULL;
      DestVolumeInfoSize = 0;
      Status = DestVolumeFP->GetInfo(
        DestVolumeFP,
        &gEfiFileSystemInfoGuid,
        &DestVolumeInfoSize,
        DestVolumeInfo
        );

      if (Status == EFI_BUFFER_TOO_SMALL) {
        DestVolumeInfo = AllocateZeroPool(DestVolumeInfoSize);
        Status = DestVolumeFP->GetInfo(
          DestVolumeFP,
          &gEfiFileSystemInfoGuid,
          &DestVolumeInfoSize,
          DestVolumeInfo
          );
      }

      //
      //check if enough space available on destination drive to complete copy
      //
      if (DestVolumeInfo->FreeSpace < SourceFileSize) {
        //
        //not enough space on destination directory to copy file
        //
        SHELL_FREE_NON_NULL(DestVolumeInfo);
        ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_CPY_FAIL), gShellLevel2HiiHandle);
        return(SHELL_VOLUME_FULL);
      } else {
        //
        // copy data between files
        //
        Buffer = AllocateZeroPool(ReadSize);
        ASSERT(Buffer != NULL);
        while (ReadSize == PcdGet16(PcdShellFileOperationSize) && !EFI_ERROR(Status)) {
          Status = ShellReadFile(SourceHandle, &ReadSize, Buffer);
          Status = ShellWriteFile(DestHandle, &ReadSize, Buffer);
        }
      }
      SHELL_FREE_NON_NULL(DestVolumeInfo);
    }

  //
  // close files
  //
  if (DestHandle != NULL) {
    ShellCloseFile(&DestHandle);
    DestHandle   = NULL;
  }
  if (SourceHandle != NULL) {
    ShellCloseFile(&SourceHandle);
    SourceHandle = NULL;
  }

  //
  // return
  //
  return (SHELL_SUCCESS);
}
Exemplo n.º 11
0
Arquivo: Rm.c Projeto: shijunjing/edk2
/**
  Function for 'rm' 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
ShellCommandRunRm (
  IN EFI_HANDLE        ImageHandle,
  IN EFI_SYSTEM_TABLE  *SystemTable
  )
{
  EFI_STATUS            Status;
  LIST_ENTRY            *Package;
  CHAR16                *ProblemParam;
  CONST CHAR16          *Param;
  SHELL_STATUS          ShellStatus;
  UINTN                 ParamCount;
  EFI_SHELL_FILE_INFO   *FileList;
  EFI_SHELL_FILE_INFO   *Node;

  ProblemParam        = NULL;
  ShellStatus         = SHELL_SUCCESS;
  ParamCount          = 0;
  FileList            = NULL;

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

  //
  // parse the command line
  //
  Status = ShellCommandLineParse (ParamList, &Package, &ProblemParam, TRUE);
  if (EFI_ERROR(Status)) {
    if (Status == EFI_VOLUME_CORRUPTED && ProblemParam != NULL) {
      ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellLevel2HiiHandle, L"rm", ProblemParam);
      FreePool(ProblemParam);
      ShellStatus = SHELL_INVALID_PARAMETER;
    } else {
      ASSERT(FALSE);
    }
  } else {
    //
    // check for "-?"
    //
    if (ShellCommandLineGetFlag(Package, L"-?")) {
      ASSERT(FALSE);
    }
    if (ShellCommandLineGetRawValue(Package, 1) == NULL) {
      //
      // we insufficient parameters
      //
      ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_FEW), gShellLevel2HiiHandle, L"rm");
      ShellStatus = SHELL_INVALID_PARAMETER;
    } else {
      //
      // get a list with each file specified by parameters
      // if parameter is a directory then add all the files below it to the list
      //
      for ( ParamCount = 1, Param = ShellCommandLineGetRawValue(Package, ParamCount)
          ; Param != NULL
          ; ParamCount++, Param = ShellCommandLineGetRawValue(Package, ParamCount)
         ){
        Status = ShellOpenFileMetaArg((CHAR16*)Param, EFI_FILE_MODE_WRITE|EFI_FILE_MODE_READ, &FileList);
        if (EFI_ERROR(Status) || FileList == NULL || IsListEmpty(&FileList->Link)) {
          ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_FILE_NF), gShellLevel2HiiHandle, L"rm", (CHAR16*)Param);
          ShellStatus = SHELL_NOT_FOUND;
          break;
        }
      }

      if (ShellStatus == SHELL_SUCCESS){
        //
        // loop through the list and make sure we are not aborting...
        //
        for ( Node = (EFI_SHELL_FILE_INFO*)GetFirstNode(&FileList->Link)
            ; !IsNull(&FileList->Link, &Node->Link) && !ShellGetExecutionBreakFlag()
            ; Node = (EFI_SHELL_FILE_INFO*)GetNextNode(&FileList->Link, &Node->Link)
           ){
          //
          // skip the directory traversing stuff...
          //
          if (StrCmp(Node->FileName, L".") == 0 || StrCmp(Node->FileName, L"..") == 0) {
            continue;
          }

          //
          // do the deleting of nodes
          //
          if (EFI_ERROR(Node->Status)){
            ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_RM_LOG_DELETE_ERR2), gShellLevel2HiiHandle, Node->Status);
            ShellStatus = SHELL_ACCESS_DENIED;
            break;
          }
          if (!IsValidDeleteTarget(FileList, Node, Package)) {
            ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_RM_LOG_DELETE_ERR3), gShellLevel2HiiHandle, Node->FullName);
            ShellStatus = SHELL_INVALID_PARAMETER;
            break;
          }

          ShellStatus = CascadeDelete(Node, ShellCommandLineGetFlag(Package, L"-q"));
        }
      }
      //
      // Free the fileList
      //
      if (FileList != NULL) {
        Status = ShellCloseFileMetaArg(&FileList);
      }
      FileList = NULL;
    }

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

  return (ShellStatus);
}
Exemplo n.º 12
0
/**
  Function for 'load' 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
ShellCommandRunLoad (
  IN EFI_HANDLE        ImageHandle,
  IN EFI_SYSTEM_TABLE  *SystemTable
  )
{
  EFI_STATUS          Status;
  LIST_ENTRY          *Package;
  CHAR16              *ProblemParam;
  SHELL_STATUS        ShellStatus;
  UINTN               ParamCount;
  EFI_SHELL_FILE_INFO *ListHead;
  EFI_SHELL_FILE_INFO *Node;

  ListHead            = NULL;
  ProblemParam        = NULL;
  ShellStatus         = SHELL_SUCCESS;

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

  //
  // parse the command line
  //
  Status = ShellCommandLineParse (LoadParamList, &Package, &ProblemParam, TRUE);
  if (EFI_ERROR(Status)) {
    if (Status == EFI_VOLUME_CORRUPTED && ProblemParam != NULL) {
      ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellLevel2HiiHandle, L"load", ProblemParam);
      FreePool(ProblemParam);
      ShellStatus = SHELL_INVALID_PARAMETER;
    } else {
      ASSERT(FALSE);
    }
  } else {
    //
    // check for "-?"
    //
    if (ShellCommandLineGetFlag(Package, L"-?")) {
      ASSERT(FALSE);
    } else if (ShellCommandLineGetRawValue(Package, 1) == NULL) {
      //
      // we didnt get a single file to load parameter
      //
      ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_FEW), gShellLevel2HiiHandle, L"load");
      ShellStatus = SHELL_INVALID_PARAMETER;
    } else {
      for ( ParamCount = 1
          ; ShellCommandLineGetRawValue(Package, ParamCount) != NULL
          ; ParamCount++
         ){
        Status = ShellOpenFileMetaArg((CHAR16*)ShellCommandLineGetRawValue(Package, ParamCount), EFI_FILE_MODE_READ, &ListHead);
        if (!EFI_ERROR(Status)) {
          for ( Node = (EFI_SHELL_FILE_INFO *)GetFirstNode(&ListHead->Link)
              ; !IsNull(&ListHead->Link, &Node->Link)
              ; Node = (EFI_SHELL_FILE_INFO *)GetNextNode(&ListHead->Link, &Node->Link)
             ){
            //
            // once we have an error preserve that value, but finish the loop.
            //
            if (EFI_ERROR(Status)) {
              LoadDriver(Node->FullName, (BOOLEAN)(ShellCommandLineGetFlag(Package, L"-nc")==FALSE));
            } else {
              Status = LoadDriver(Node->FullName, (BOOLEAN)(ShellCommandLineGetFlag(Package, L"-nc")==FALSE));
            }
          } // for loop for multi-open
          if (EFI_ERROR(Status)) {
            ShellCloseFileMetaArg(&ListHead);
          } else {
            Status = ShellCloseFileMetaArg(&ListHead);;
          }
        } else {
          //
          // no files found.
          //
          ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_FILE_NF), gShellLevel2HiiHandle, L"load", (CHAR16*)ShellCommandLineGetRawValue(Package, ParamCount));
          ShellStatus = SHELL_NOT_FOUND;
        }
      } // for loop for params
    }

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

  if (EFI_ERROR(Status) && ShellStatus == SHELL_SUCCESS) {
    ShellStatus = SHELL_DEVICE_ERROR;
  }

  return (ShellStatus);
}
Exemplo n.º 13
0
Arquivo: Attrib.c Projeto: etiago/vbox
/**
  Function for 'attrib' 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
ShellCommandRunAttrib (
  IN EFI_HANDLE        ImageHandle,
  IN EFI_SYSTEM_TABLE  *SystemTable
  )
{
  UINT64              FileAttributesToAdd;
  UINT64              FileAttributesToRemove;
  EFI_STATUS          Status;
  LIST_ENTRY          *Package;
  CHAR16              *ProblemParam;
  SHELL_STATUS        ShellStatus;
  UINTN               ParamNumberCount;
  CONST CHAR16        *FileName;
  EFI_SHELL_FILE_INFO *ListOfFiles;
  EFI_SHELL_FILE_INFO *FileNode;
  EFI_FILE_INFO       *FileInfo;

  ListOfFiles   = NULL;
  ShellStatus   = SHELL_SUCCESS;
  ProblemParam  = NULL;

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

  //
  // parse the command line
  //
  Status = ShellCommandLineParse (AttribParamList, &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);
      ShellStatus = SHELL_INVALID_PARAMETER;
    } else {
      ASSERT(FALSE);
    }
  } else {

    //
    // check for "-?"
    //
    if (ShellCommandLineGetFlag(Package, L"-?")) {
      ASSERT(FALSE);
    } else {
      FileAttributesToAdd = 0;
      FileAttributesToRemove = 0;

      //
      // apply or remove each flag
      //
      if (ShellCommandLineGetFlag(Package, L"+a")) {
        FileAttributesToAdd |= EFI_FILE_ARCHIVE;
      }
      if (ShellCommandLineGetFlag(Package, L"-a")) {
        FileAttributesToRemove |= EFI_FILE_ARCHIVE;
      }
      if (ShellCommandLineGetFlag(Package, L"+s")) {
        FileAttributesToAdd |= EFI_FILE_SYSTEM;
      }
      if (ShellCommandLineGetFlag(Package, L"-s")) {
        FileAttributesToRemove |= EFI_FILE_SYSTEM;
      }
      if (ShellCommandLineGetFlag(Package, L"+h")) {
        FileAttributesToAdd |= EFI_FILE_HIDDEN;
      }
      if (ShellCommandLineGetFlag(Package, L"-h")) {
        FileAttributesToRemove |= EFI_FILE_HIDDEN;
      }
      if (ShellCommandLineGetFlag(Package, L"+r")) {
        FileAttributesToAdd |= EFI_FILE_READ_ONLY;
      }
      if (ShellCommandLineGetFlag(Package, L"-r")) {
        FileAttributesToRemove |= EFI_FILE_READ_ONLY;
      }

      if (FileAttributesToRemove == 0 && FileAttributesToAdd == 0) {
        //
        // Do display as we have no attributes to change
        //
        for ( ParamNumberCount = 1
            ;
            ; ParamNumberCount++
           ){
          FileName = ShellCommandLineGetRawValue(Package, ParamNumberCount);
          // if we dont have anything left, move on...
          if (FileName == NULL && ParamNumberCount == 1) {
            FileName = (CHAR16*)AllFiles;
          } else if (FileName == NULL) {
            break;
          }
          ASSERT(ListOfFiles == NULL);
          Status = ShellOpenFileMetaArg((CHAR16*)FileName, EFI_FILE_MODE_READ, &ListOfFiles);
          if (EFI_ERROR(Status)) {
            ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_FILE_OPEN_FAIL), gShellLevel2HiiHandle, ShellCommandLineGetRawValue(Package, ParamNumberCount));
            ShellStatus = SHELL_NOT_FOUND;
          } else {
            for (FileNode = (EFI_SHELL_FILE_INFO*)GetFirstNode(&ListOfFiles->Link)
              ;  !IsNull(&ListOfFiles->Link, &FileNode->Link)
              ;  FileNode = (EFI_SHELL_FILE_INFO*)GetNextNode(&ListOfFiles->Link, &FileNode->Link)
             ){
              ShellPrintHiiEx(
                -1,
                -1,
                NULL,
                STRING_TOKEN (STR_ATTRIB_OUTPUT_LINE),
                gShellLevel2HiiHandle,
                FileNode->Info->Attribute&EFI_FILE_DIRECTORY? L'D':L' ',
                FileNode->Info->Attribute&EFI_FILE_ARCHIVE?   L'A':L' ',
                FileNode->Info->Attribute&EFI_FILE_SYSTEM?    L'S':L' ',
                FileNode->Info->Attribute&EFI_FILE_HIDDEN?    L'H':L' ',
                FileNode->Info->Attribute&EFI_FILE_READ_ONLY? L'R':L' ',
                FileNode->FileName
               );
            }
            Status = ShellCloseFileMetaArg(&ListOfFiles);
            ListOfFiles = NULL;
            if (EFI_ERROR(Status)) {
              ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_FILE_CLOSE_FAIL), gShellLevel2HiiHandle, ShellCommandLineGetRawValue(Package, ParamNumberCount));
              ShellStatus = SHELL_NOT_FOUND;
            }
          } // for loop for handling wildcard filenames
        } // for loop for printing out the info
      } else if ((FileAttributesToRemove & FileAttributesToAdd) != 0) {
        //
        // fail as we have conflcting params.
        //
        ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PARAM_CON), gShellLevel2HiiHandle);
        ShellStatus = SHELL_INVALID_PARAMETER;
      } else {
        //
        // enumerate through all the files/directories and apply the attributes
        //
        for ( ParamNumberCount = 1
            ;
            ; ParamNumberCount++
           ){
          FileName = ShellCommandLineGetRawValue(Package, ParamNumberCount);
          // if we dont have anything left, move on...
          if (FileName == NULL) {
            //
            // make sure we are not failing on the first one we do... if yes that's an error...
            //
            if (ParamNumberCount == 1) {
              ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_FEW), gShellLevel2HiiHandle);
              ShellStatus = SHELL_INVALID_PARAMETER;
            }
            break;
          }

          //
          // OpenFileByName / GetFileInfo / Change attributes / SetFileInfo / CloseFile / free memory
          // for each file or directory on the line.
          //

          //
          // Open the file(s)
          //
          ASSERT(ListOfFiles == NULL);
          Status = ShellOpenFileMetaArg((CHAR16*)FileName, EFI_FILE_MODE_READ, &ListOfFiles);
          if (EFI_ERROR(Status)) {
            ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_FILE_OPEN_FAIL), gShellLevel2HiiHandle, ShellCommandLineGetRawValue(Package, ParamNumberCount));
            ShellStatus = SHELL_NOT_FOUND;
          } else {
            for (FileNode = (EFI_SHELL_FILE_INFO*)GetFirstNode(&ListOfFiles->Link)
              ;  !IsNull(&ListOfFiles->Link, &FileNode->Link)
              ;  FileNode = (EFI_SHELL_FILE_INFO*)GetNextNode(&ListOfFiles->Link, &FileNode->Link)
             ){
              //
              // skip the directory traversing stuff...
              //
              if (StrCmp(FileNode->FileName, L".") == 0 || StrCmp(FileNode->FileName, L"..") == 0) {
                continue;
              }

              FileInfo = gEfiShellProtocol->GetFileInfo(FileNode->Handle);

              //
              // if we are removing Read-Only we need to do that alone
              //
              if ((FileAttributesToRemove & EFI_FILE_READ_ONLY) == EFI_FILE_READ_ONLY) {
                FileInfo->Attribute &= ~EFI_FILE_READ_ONLY;
                //
                // SetFileInfo
                //
                Status = ShellSetFileInfo(FileNode->Handle, FileInfo);
                if (EFI_ERROR(Status)) {;
                  ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_FILE_AD), gShellLevel2HiiHandle, ShellCommandLineGetRawValue(Package, ParamNumberCount));
                  ShellStatus = SHELL_ACCESS_DENIED;
                }
              }

              //
              // change the attribute
              //
              FileInfo->Attribute &= ~FileAttributesToRemove;
              FileInfo->Attribute |= FileAttributesToAdd;

              //
              // SetFileInfo
              //
              Status = ShellSetFileInfo(FileNode->Handle, FileInfo);
              if (EFI_ERROR(Status)) {;
                ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_FILE_AD), gShellLevel2HiiHandle, ShellCommandLineGetRawValue(Package, ParamNumberCount));
                ShellStatus = SHELL_ACCESS_DENIED;
              }

              SHELL_FREE_NON_NULL(FileInfo);
            }
            Status = ShellCloseFileMetaArg(&ListOfFiles);
            ListOfFiles = NULL;
            if (EFI_ERROR(Status)) {
              ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_FILE_CLOSE_FAIL), gShellLevel2HiiHandle, ShellCommandLineGetRawValue(Package, ParamNumberCount));
              ShellStatus = SHELL_NOT_FOUND;
            }
          } // for loop for handling wildcard filenames
        }
      }
    }
  }

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

  //
  // return the status
  //
  return (ShellStatus);
}