VirtualBox

Ignore:
Timestamp:
Apr 14, 2023 3:17:44 PM (22 months ago)
Author:
vboxsync
Message:

Devices/EFI/FirmwareNew: Update to edk2-stable202302 and make it build, bugref:4643

Location:
trunk/src/VBox/Devices/EFI/FirmwareNew
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Devices/EFI/FirmwareNew

  • trunk/src/VBox/Devices/EFI/FirmwareNew/ShellPkg/Library/UefiShellLevel2CommandsLib/Cp.c

    r80721 r99404  
    3030**/
    3131SHELL_STATUS
    32 ValidateAndCopyFiles(
     32ValidateAndCopyFiles (
    3333  IN CONST EFI_SHELL_FILE_INFO  *FileList,
    3434  IN CONST CHAR16               *DestDir,
     
    5252**/
    5353SHELL_STATUS
    54 CopySingleFile(
    55   IN CONST CHAR16 *Source,
    56   IN CONST CHAR16 *Dest,
    57   OUT VOID        **Resp,
    58   IN BOOLEAN      SilentMode,
    59   IN CONST CHAR16 *CmdName
     54CopySingleFile (
     55  IN CONST CHAR16  *Source,
     56  IN CONST CHAR16  *Dest,
     57  OUT VOID         **Resp,
     58  IN BOOLEAN       SilentMode,
     59  IN CONST CHAR16  *CmdName
    6060  )
    6161{
     
    7676  UINTN                 DestVolumeInfoSize;
    7777
    78   ASSERT(Resp != NULL);
    79 
    80   SourceHandle    = NULL;
    81   DestHandle      = NULL;
    82   Response        = *Resp;
    83   List            = NULL;
    84   DestVolumeInfo  = NULL;
    85   ShellStatus     = SHELL_SUCCESS;
    86 
    87   ReadSize = PcdGet32(PcdShellFileOperationSize);
     78  ASSERT (Resp != NULL);
     79
     80  SourceHandle   = NULL;
     81  DestHandle     = NULL;
     82  Response       = *Resp;
     83  List           = NULL;
     84  DestVolumeInfo = NULL;
     85  ShellStatus    = SHELL_SUCCESS;
     86
     87  ReadSize = PcdGet32 (PcdShellFileOperationSize);
    8888  // Why bother copying a file to itself
    89   if (StrCmp(Source, Dest) == 0) {
     89  if (StrCmp (Source, Dest) == 0) {
    9090    return (SHELL_SUCCESS);
    9191  }
     
    9494  // if the destination file existed check response and possibly prompt user
    9595  //
    96   if (ShellFileExists(Dest) == EFI_SUCCESS) {
    97     if (Response == NULL && !SilentMode) {
    98       Status = ShellPromptForResponseHii(ShellPromptResponseTypeYesNoAllCancel, STRING_TOKEN (STR_GEN_DEST_EXIST_OVR), gShellLevel2HiiHandle, &Response);
    99     }
     96  if (ShellFileExists (Dest) == EFI_SUCCESS) {
     97    if ((Response == NULL) && !SilentMode) {
     98      Status = ShellPromptForResponseHii (ShellPromptResponseTypeYesNoAllCancel, STRING_TOKEN (STR_GEN_DEST_EXIST_OVR), gShellLevel2HiiHandle, &Response);
     99    }
     100
    100101    //
    101102    // possibly return based on response
     
    105106        return SHELL_ABORTED;
    106107      }
    107       switch (*(SHELL_PROMPT_RESPONSE*)Response) {
     108
     109      switch (*(SHELL_PROMPT_RESPONSE *)Response) {
    108110        case ShellPromptResponseNo:
    109111          //
     
    127129  }
    128130
    129   if (ShellIsDirectory(Source) == EFI_SUCCESS) {
    130     Status = ShellCreateDirectory(Dest, &DestHandle);
    131     if (EFI_ERROR(Status)) {
    132       ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_CP_DEST_DIR_FAIL), gShellLevel2HiiHandle, CmdName, Dest);
     131  if (ShellIsDirectory (Source) == EFI_SUCCESS) {
     132    Status = ShellCreateDirectory (Dest, &DestHandle);
     133    if (EFI_ERROR (Status)) {
     134      ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_CP_DEST_DIR_FAIL), gShellLevel2HiiHandle, CmdName, Dest);
    133135      return (SHELL_ACCESS_DENIED);
    134136    }
     
    137139    // Now copy all the files under the directory...
    138140    //
    139     TempName    = NULL;
    140     Size        = 0;
    141     StrnCatGrow(&TempName, &Size, Source, 0);
    142     StrnCatGrow(&TempName, &Size, L"\\*", 0);
     141    TempName = NULL;
     142    Size     = 0;
     143    StrnCatGrow (&TempName, &Size, Source, 0);
     144    StrnCatGrow (&TempName, &Size, L"\\*", 0);
    143145    if (TempName != NULL) {
    144       ShellOpenFileMetaArg((CHAR16*)TempName, EFI_FILE_MODE_READ, &List);
     146      ShellOpenFileMetaArg ((CHAR16 *)TempName, EFI_FILE_MODE_READ, &List);
    145147      *TempName = CHAR_NULL;
    146       StrnCatGrow(&TempName, &Size, Dest, 0);
    147       StrnCatGrow(&TempName, &Size, L"\\", 0);
    148       ShellStatus = ValidateAndCopyFiles(List, TempName, SilentMode, TRUE, Resp);
    149       ShellCloseFileMetaArg(&List);
    150       SHELL_FREE_NON_NULL(TempName);
     148      StrnCatGrow (&TempName, &Size, Dest, 0);
     149      StrnCatGrow (&TempName, &Size, L"\\", 0);
     150      ShellStatus = ValidateAndCopyFiles (List, TempName, SilentMode, TRUE, Resp);
     151      ShellCloseFileMetaArg (&List);
     152      SHELL_FREE_NON_NULL (TempName);
    151153      Size = 0;
    152154    }
    153155  } else {
    154     Status = ShellDeleteFileByName(Dest);
     156    Status = ShellDeleteFileByName (Dest);
    155157
    156158    //
    157159    // open file with create enabled
    158160    //
    159     Status = ShellOpenFileByName(Dest, &DestHandle, EFI_FILE_MODE_READ|EFI_FILE_MODE_WRITE|EFI_FILE_MODE_CREATE, 0);
    160     if (EFI_ERROR(Status)) {
    161       ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_CP_DEST_OPEN_FAIL), gShellLevel2HiiHandle, CmdName, Dest);
     161    Status = ShellOpenFileByName (Dest, &DestHandle, EFI_FILE_MODE_READ|EFI_FILE_MODE_WRITE|EFI_FILE_MODE_CREATE, 0);
     162    if (EFI_ERROR (Status)) {
     163      ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_CP_DEST_OPEN_FAIL), gShellLevel2HiiHandle, CmdName, Dest);
    162164      return (SHELL_ACCESS_DENIED);
    163165    }
     
    173175
    174176    //
    175     //get file size of source file and freespace available on destination volume
    176     //
    177     ShellGetFileSize(SourceHandle, &SourceFileSize);
    178     ShellGetFileSize(DestHandle, &DestFileSize);
    179 
    180     //
    181     //if the destination file already exists then it will be replaced, meaning the sourcefile effectively needs less storage space
    182     //
    183     if(DestFileSize < SourceFileSize){
     177    // get file size of source file and freespace available on destination volume
     178    //
     179    ShellGetFileSize (SourceHandle, &SourceFileSize);
     180    ShellGetFileSize (DestHandle, &DestFileSize);
     181
     182    //
     183    // if the destination file already exists then it will be replaced, meaning the sourcefile effectively needs less storage space
     184    //
     185    if (DestFileSize < SourceFileSize) {
    184186      SourceFileSize -= DestFileSize;
    185187    } else {
     
    188190
    189191    //
    190     //get the system volume info to check the free space
    191     //
    192     DestVolumeFP = ConvertShellHandleToEfiFileProtocol(DestHandle);
    193     DestVolumeInfo = NULL;
     192    // get the system volume info to check the free space
     193    //
     194    DestVolumeFP       = ConvertShellHandleToEfiFileProtocol (DestHandle);
     195    DestVolumeInfo     = NULL;
    194196    DestVolumeInfoSize = 0;
    195     Status = DestVolumeFP->GetInfo(
    196       DestVolumeFP,
    197       &gEfiFileSystemInfoGuid,
    198       &DestVolumeInfoSize,
    199       DestVolumeInfo
    200       );
     197    Status             = DestVolumeFP->GetInfo (
     198                                         DestVolumeFP,
     199                                         &gEfiFileSystemInfoGuid,
     200                                         &DestVolumeInfoSize,
     201                                         DestVolumeInfo
     202                                         );
    201203
    202204    if (Status == EFI_BUFFER_TOO_SMALL) {
    203       DestVolumeInfo = AllocateZeroPool(DestVolumeInfoSize);
    204       Status = DestVolumeFP->GetInfo(
    205         DestVolumeFP,
    206         &gEfiFileSystemInfoGuid,
    207         &DestVolumeInfoSize,
    208         DestVolumeInfo
    209         );
    210     }
    211 
    212     //
    213     //check if enough space available on destination drive to complete copy
    214     //
    215     if (DestVolumeInfo!= NULL && (DestVolumeInfo->FreeSpace < SourceFileSize)) {
    216       //
    217       //not enough space on destination directory to copy file
    218       //
    219       SHELL_FREE_NON_NULL(DestVolumeInfo);
    220       ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_CPY_FAIL), gShellLevel2HiiHandle, CmdName);
    221       return(SHELL_VOLUME_FULL);
     205      DestVolumeInfo = AllocateZeroPool (DestVolumeInfoSize);
     206      Status         = DestVolumeFP->GetInfo (
     207                                       DestVolumeFP,
     208                                       &gEfiFileSystemInfoGuid,
     209                                       &DestVolumeInfoSize,
     210                                       DestVolumeInfo
     211                                       );
     212    }
     213
     214    //
     215    // check if enough space available on destination drive to complete copy
     216    //
     217    if ((DestVolumeInfo != NULL) && (DestVolumeInfo->FreeSpace < SourceFileSize)) {
     218      //
     219      // not enough space on destination directory to copy file
     220      //
     221      SHELL_FREE_NON_NULL (DestVolumeInfo);
     222      ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_CPY_FAIL), gShellLevel2HiiHandle, CmdName);
     223      return (SHELL_VOLUME_FULL);
    222224    } else {
    223225      //
    224226      // copy data between files
    225227      //
    226       Buffer = AllocateZeroPool(ReadSize);
     228      Buffer = AllocateZeroPool (ReadSize);
    227229      if (Buffer == NULL) {
    228230        ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_OUT_MEM), gShellLevel2HiiHandle, CmdName);
    229231        return SHELL_OUT_OF_RESOURCES;
    230232      }
    231       while (ReadSize == PcdGet32(PcdShellFileOperationSize) && !EFI_ERROR(Status)) {
    232         Status = ShellReadFile(SourceHandle, &ReadSize, Buffer);
    233         if (!EFI_ERROR(Status)) {
    234           Status = ShellWriteFile(DestHandle, &ReadSize, Buffer);
    235           if (EFI_ERROR(Status)) {
    236             ShellStatus = (SHELL_STATUS) (Status & (~MAX_BIT));
    237             ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_CPY_WRITE_ERROR), gShellLevel2HiiHandle, CmdName, Dest);
     233
     234      while (ReadSize == PcdGet32 (PcdShellFileOperationSize) && !EFI_ERROR (Status)) {
     235        Status = ShellReadFile (SourceHandle, &ReadSize, Buffer);
     236        if (!EFI_ERROR (Status)) {
     237          Status = ShellWriteFile (DestHandle, &ReadSize, Buffer);
     238          if (EFI_ERROR (Status)) {
     239            ShellStatus = (SHELL_STATUS)(Status & (~MAX_BIT));
     240            ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_CPY_WRITE_ERROR), gShellLevel2HiiHandle, CmdName, Dest);
    238241            break;
    239242          }
    240243        } else {
    241           ShellStatus = (SHELL_STATUS) (Status & (~MAX_BIT));
    242           ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_CPY_READ_ERROR), gShellLevel2HiiHandle, CmdName, Source);
     244          ShellStatus = (SHELL_STATUS)(Status & (~MAX_BIT));
     245          ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_CPY_READ_ERROR), gShellLevel2HiiHandle, CmdName, Source);
    243246          break;
    244247        }
    245248      }
    246249    }
    247     SHELL_FREE_NON_NULL(DestVolumeInfo);
     250
     251    SHELL_FREE_NON_NULL (DestVolumeInfo);
    248252  }
    249253
     
    252256  //
    253257  if (DestHandle != NULL) {
    254     ShellCloseFile(&DestHandle);
    255     DestHandle   = NULL;
    256   }
     258    ShellCloseFile (&DestHandle);
     259    DestHandle = NULL;
     260  }
     261
    257262  if (SourceHandle != NULL) {
    258     ShellCloseFile(&SourceHandle);
     263    ShellCloseFile (&SourceHandle);
    259264    SourceHandle = NULL;
    260265  }
     
    287292**/
    288293SHELL_STATUS
    289 ValidateAndCopyFiles(
     294ValidateAndCopyFiles (
    290295  IN CONST EFI_SHELL_FILE_INFO  *FileList,
    291296  IN CONST CHAR16               *DestDir,
     
    295300  )
    296301{
    297   CHAR16                    *HiiOutput;
    298   CHAR16                    *HiiResultOk;
    299   CONST EFI_SHELL_FILE_INFO *Node;
    300   SHELL_STATUS              ShellStatus;
    301   EFI_STATUS                Status;
    302   CHAR16                    *DestPath;
    303   VOID                      *Response;
    304   UINTN                     PathSize;
    305   CONST CHAR16              *Cwd;
    306   UINTN                     NewSize;
    307   CHAR16                    *CleanFilePathStr;
     302  CHAR16                     *HiiOutput;
     303  CHAR16                     *HiiResultOk;
     304  CONST EFI_SHELL_FILE_INFO  *Node;
     305  SHELL_STATUS               ShellStatus;
     306  EFI_STATUS                 Status;
     307  CHAR16                     *DestPath;
     308  VOID                       *Response;
     309  UINTN                      PathSize;
     310  CONST CHAR16               *Cwd;
     311  UINTN                      NewSize;
     312  CHAR16                     *CleanFilePathStr;
    308313
    309314  if (Resp == NULL) {
     
    316321  ShellStatus      = SHELL_SUCCESS;
    317322  PathSize         = 0;
    318   Cwd              = ShellGetCurrentDir(NULL);
     323  Cwd              = ShellGetCurrentDir (NULL);
    319324  CleanFilePathStr = NULL;
    320325
    321   ASSERT(FileList != NULL);
    322   ASSERT(DestDir  != NULL);
    323 
     326  ASSERT (FileList != NULL);
     327  ASSERT (DestDir  != NULL);
    324328
    325329  Status = ShellLevel2StripQuotes (DestDir, &CleanFilePathStr);
     
    337341  // If we are trying to copy multiple files... make sure we got a directory for the target...
    338342  //
    339   if (EFI_ERROR(ShellIsDirectory(CleanFilePathStr)) && FileList->Link.ForwardLink != FileList->Link.BackLink) {
     343  if (EFI_ERROR (ShellIsDirectory (CleanFilePathStr)) && (FileList->Link.ForwardLink != FileList->Link.BackLink)) {
    340344    //
    341345    // Error for destination not a directory
    342346    //
    343     ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_NOT_DIR), gShellLevel2HiiHandle, L"cp", CleanFilePathStr);
     347    ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_NOT_DIR), gShellLevel2HiiHandle, L"cp", CleanFilePathStr);
    344348    FreePool (CleanFilePathStr);
    345349    return (SHELL_INVALID_PARAMETER);
    346350  }
    347   for (Node = (EFI_SHELL_FILE_INFO *)GetFirstNode(&FileList->Link)
    348     ;  !IsNull(&FileList->Link, &Node->Link)
    349     ;  Node = (EFI_SHELL_FILE_INFO *)GetNextNode(&FileList->Link, &Node->Link)
    350     ){
     351
     352  for (Node = (EFI_SHELL_FILE_INFO *)GetFirstNode (&FileList->Link)
     353       ; !IsNull (&FileList->Link, &Node->Link)
     354       ; Node = (EFI_SHELL_FILE_INFO *)GetNextNode (&FileList->Link, &Node->Link)
     355       )
     356  {
    351357    //
    352358    // skip the directory traversing stuff...
    353359    //
    354     if (StrCmp(Node->FileName, L".") == 0 || StrCmp(Node->FileName, L"..") == 0) {
     360    if ((StrCmp (Node->FileName, L".") == 0) || (StrCmp (Node->FileName, L"..") == 0)) {
    355361      continue;
    356362    }
    357363
    358     NewSize =  StrSize(CleanFilePathStr);
    359     NewSize += StrSize(Node->FullName);
    360     NewSize += (Cwd == NULL)? 0 : (StrSize(Cwd) + sizeof(CHAR16));
     364    NewSize  =  StrSize (CleanFilePathStr);
     365    NewSize += StrSize (Node->FullName);
     366    NewSize += (Cwd == NULL) ? 0 : (StrSize (Cwd) + sizeof (CHAR16));
    361367    if (NewSize > PathSize) {
    362368      PathSize = NewSize;
     
    366372    // Make sure got -r if required
    367373    //
    368     if (!RecursiveMode && !EFI_ERROR(ShellIsDirectory(Node->FullName))) {
    369       ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_CP_DIR_REQ), gShellLevel2HiiHandle, L"cp");
     374    if (!RecursiveMode && !EFI_ERROR (ShellIsDirectory (Node->FullName))) {
     375      ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_CP_DIR_REQ), gShellLevel2HiiHandle, L"cp");
    370376      FreePool (CleanFilePathStr);
    371377      return (SHELL_INVALID_PARAMETER);
     
    375381    // make sure got dest as dir if needed
    376382    //
    377     if (!EFI_ERROR(ShellIsDirectory(Node->FullName)) && EFI_ERROR(ShellIsDirectory(CleanFilePathStr))) {
     383    if (!EFI_ERROR (ShellIsDirectory (Node->FullName)) && EFI_ERROR (ShellIsDirectory (CleanFilePathStr))) {
    378384      //
    379385      // Error for destination not a directory
    380386      //
    381       ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_NOT_DIR), gShellLevel2HiiHandle, L"cp", CleanFilePathStr);
     387      ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_NOT_DIR), gShellLevel2HiiHandle, L"cp", CleanFilePathStr);
    382388      FreePool (CleanFilePathStr);
    383389      return (SHELL_INVALID_PARAMETER);
     
    387393  HiiOutput   = HiiGetString (gShellLevel2HiiHandle, STRING_TOKEN (STR_CP_OUTPUT), NULL);
    388394  HiiResultOk = HiiGetString (gShellLevel2HiiHandle, STRING_TOKEN (STR_GEN_RES_OK), NULL);
    389   DestPath    = AllocateZeroPool(PathSize);
    390 
    391   if (DestPath == NULL || HiiOutput == NULL || HiiResultOk == NULL) {
    392     SHELL_FREE_NON_NULL(DestPath);
    393     SHELL_FREE_NON_NULL(HiiOutput);
    394     SHELL_FREE_NON_NULL(HiiResultOk);
     395  DestPath    = AllocateZeroPool (PathSize);
     396
     397  if ((DestPath == NULL) || (HiiOutput == NULL) || (HiiResultOk == NULL)) {
     398    SHELL_FREE_NON_NULL (DestPath);
     399    SHELL_FREE_NON_NULL (HiiOutput);
     400    SHELL_FREE_NON_NULL (HiiResultOk);
    395401    FreePool (CleanFilePathStr);
    396402    return (SHELL_OUT_OF_RESOURCES);
     
    400406  // Go through the list of files to copy...
    401407  //
    402   for (Node = (EFI_SHELL_FILE_INFO *)GetFirstNode(&FileList->Link)
    403     ;  !IsNull(&FileList->Link, &Node->Link)
    404     ;  Node = (EFI_SHELL_FILE_INFO *)GetNextNode(&FileList->Link, &Node->Link)
    405     ){
    406     if (ShellGetExecutionBreakFlag()) {
     408  for (Node = (EFI_SHELL_FILE_INFO *)GetFirstNode (&FileList->Link)
     409       ; !IsNull (&FileList->Link, &Node->Link)
     410       ; Node = (EFI_SHELL_FILE_INFO *)GetNextNode (&FileList->Link, &Node->Link)
     411       )
     412  {
     413    if (ShellGetExecutionBreakFlag ()) {
    407414      break;
    408415    }
    409     ASSERT(Node->FileName != NULL);
    410     ASSERT(Node->FullName != NULL);
     416
     417    ASSERT (Node->FileName != NULL);
     418    ASSERT (Node->FullName != NULL);
    411419
    412420    //
    413421    // skip the directory traversing stuff...
    414422    //
    415     if (StrCmp(Node->FileName, L".") == 0 || StrCmp(Node->FileName, L"..") == 0) {
     423    if ((StrCmp (Node->FileName, L".") == 0) || (StrCmp (Node->FileName, L"..") == 0)) {
    416424      continue;
    417425    }
    418426
    419     if (FileList->Link.ForwardLink == FileList->Link.BackLink // 1 item
    420       && EFI_ERROR(ShellIsDirectory(CleanFilePathStr))                 // not an existing directory
    421       ) {
    422       if (StrStr(CleanFilePathStr, L":") == NULL) {
     427    if (  (FileList->Link.ForwardLink == FileList->Link.BackLink) // 1 item
     428       && EFI_ERROR (ShellIsDirectory (CleanFilePathStr))         // not an existing directory
     429          )
     430    {
     431      if (StrStr (CleanFilePathStr, L":") == NULL) {
    423432        //
    424433        // simple copy of a single file
    425434        //
    426435        if (Cwd != NULL) {
    427           StrCpyS(DestPath, PathSize / sizeof(CHAR16), Cwd);
    428           StrCatS(DestPath, PathSize / sizeof(CHAR16), L"\\");
     436          StrCpyS (DestPath, PathSize / sizeof (CHAR16), Cwd);
     437          StrCatS (DestPath, PathSize / sizeof (CHAR16), L"\\");
    429438        } else {
    430           ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_DIR_NF), gShellLevel2HiiHandle, L"cp", CleanFilePathStr);
     439          ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_DIR_NF), gShellLevel2HiiHandle, L"cp", CleanFilePathStr);
    431440          FreePool (CleanFilePathStr);
    432441          return (SHELL_INVALID_PARAMETER);
    433442        }
    434         if (DestPath[StrLen(DestPath)-1] != L'\\' && CleanFilePathStr[0] != L'\\') {
    435           StrCatS(DestPath, PathSize / sizeof(CHAR16), L"\\");
    436         } else if (DestPath[StrLen(DestPath)-1] == L'\\' && CleanFilePathStr[0] == L'\\') {
    437           ((CHAR16*)DestPath)[StrLen(DestPath)-1] = CHAR_NULL;
    438         }
    439         StrCatS(DestPath, PathSize/sizeof(CHAR16), CleanFilePathStr);
     443
     444        if ((DestPath[StrLen (DestPath)-1] != L'\\') && (CleanFilePathStr[0] != L'\\')) {
     445          StrCatS (DestPath, PathSize / sizeof (CHAR16), L"\\");
     446        } else if ((DestPath[StrLen (DestPath)-1] == L'\\') && (CleanFilePathStr[0] == L'\\')) {
     447          ((CHAR16 *)DestPath)[StrLen (DestPath)-1] = CHAR_NULL;
     448        }
     449
     450        StrCatS (DestPath, PathSize/sizeof (CHAR16), CleanFilePathStr);
    440451      } else {
    441         StrCpyS(DestPath, PathSize/sizeof(CHAR16), CleanFilePathStr);
     452        StrCpyS (DestPath, PathSize/sizeof (CHAR16), CleanFilePathStr);
    442453      }
    443454    } else {
     
    450461      //
    451462      if (CleanFilePathStr[0] == L'\\') {
    452          //
    453          // Copy to the root of CWD
    454          //
     463        //
     464        // Copy to the root of CWD
     465        //
    455466        if (Cwd != NULL) {
    456           StrCpyS(DestPath, PathSize/sizeof(CHAR16), Cwd);
    457           StrCatS(DestPath, PathSize/sizeof(CHAR16), L"\\");
     467          StrCpyS (DestPath, PathSize/sizeof (CHAR16), Cwd);
     468          StrCatS (DestPath, PathSize/sizeof (CHAR16), L"\\");
    458469        } else {
    459           ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_DIR_NF), gShellLevel2HiiHandle, L"cp", CleanFilePathStr);
    460           FreePool(CleanFilePathStr);
     470          ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_DIR_NF), gShellLevel2HiiHandle, L"cp", CleanFilePathStr);
     471          FreePool (CleanFilePathStr);
    461472          return (SHELL_INVALID_PARAMETER);
    462473        }
    463         while (PathRemoveLastItem(DestPath));
    464         StrCatS(DestPath, PathSize/sizeof(CHAR16), CleanFilePathStr+1);
    465         StrCatS(DestPath, PathSize/sizeof(CHAR16), Node->FileName);
    466       } else if (StrStr(CleanFilePathStr, L":") == NULL) {
     474
     475        while (PathRemoveLastItem (DestPath)) {
     476        }
     477
     478        StrCatS (DestPath, PathSize/sizeof (CHAR16), CleanFilePathStr+1);
     479        StrCatS (DestPath, PathSize/sizeof (CHAR16), Node->FileName);
     480      } else if (StrStr (CleanFilePathStr, L":") == NULL) {
    467481        if (Cwd != NULL) {
    468           StrCpyS(DestPath, PathSize/sizeof(CHAR16), Cwd);
    469           StrCatS(DestPath, PathSize/sizeof(CHAR16), L"\\");
     482          StrCpyS (DestPath, PathSize/sizeof (CHAR16), Cwd);
     483          StrCatS (DestPath, PathSize/sizeof (CHAR16), L"\\");
    470484        } else {
    471           ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_DIR_NF), gShellLevel2HiiHandle, L"cp", CleanFilePathStr);
    472           FreePool(CleanFilePathStr);
     485          ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_DIR_NF), gShellLevel2HiiHandle, L"cp", CleanFilePathStr);
     486          FreePool (CleanFilePathStr);
    473487          return (SHELL_INVALID_PARAMETER);
    474488        }
    475         if (DestPath[StrLen(DestPath)-1] != L'\\' && CleanFilePathStr[0] != L'\\') {
    476           StrCatS(DestPath, PathSize/sizeof(CHAR16), L"\\");
    477         } else if (DestPath[StrLen(DestPath)-1] == L'\\' && CleanFilePathStr[0] == L'\\') {
    478           ((CHAR16*)DestPath)[StrLen(DestPath)-1] = CHAR_NULL;
    479         }
    480         StrCatS(DestPath, PathSize/sizeof(CHAR16), CleanFilePathStr);
    481         if (CleanFilePathStr[StrLen(CleanFilePathStr)-1] != L'\\' && Node->FileName[0] != L'\\') {
    482           StrCatS(DestPath, PathSize/sizeof(CHAR16), L"\\");
    483         } else if (CleanFilePathStr[StrLen(CleanFilePathStr)-1] == L'\\' && Node->FileName[0] == L'\\') {
    484           ((CHAR16*)DestPath)[StrLen(DestPath)-1] = CHAR_NULL;
    485         }
    486         StrCatS(DestPath, PathSize/sizeof(CHAR16), Node->FileName);
    487 
     489
     490        if ((DestPath[StrLen (DestPath)-1] != L'\\') && (CleanFilePathStr[0] != L'\\')) {
     491          StrCatS (DestPath, PathSize/sizeof (CHAR16), L"\\");
     492        } else if ((DestPath[StrLen (DestPath)-1] == L'\\') && (CleanFilePathStr[0] == L'\\')) {
     493          ((CHAR16 *)DestPath)[StrLen (DestPath)-1] = CHAR_NULL;
     494        }
     495
     496        StrCatS (DestPath, PathSize/sizeof (CHAR16), CleanFilePathStr);
     497        if ((CleanFilePathStr[StrLen (CleanFilePathStr)-1] != L'\\') && (Node->FileName[0] != L'\\')) {
     498          StrCatS (DestPath, PathSize/sizeof (CHAR16), L"\\");
     499        } else if ((CleanFilePathStr[StrLen (CleanFilePathStr)-1] == L'\\') && (Node->FileName[0] == L'\\')) {
     500          ((CHAR16 *)DestPath)[StrLen (DestPath)-1] = CHAR_NULL;
     501        }
     502
     503        StrCatS (DestPath, PathSize/sizeof (CHAR16), Node->FileName);
    488504      } else {
    489         StrCpyS(DestPath, PathSize/sizeof(CHAR16), CleanFilePathStr);
    490         if (CleanFilePathStr[StrLen(CleanFilePathStr)-1] != L'\\' && Node->FileName[0] != L'\\') {
    491           StrCatS(DestPath, PathSize/sizeof(CHAR16), L"\\");
    492         } else if (CleanFilePathStr[StrLen(CleanFilePathStr)-1] == L'\\' && Node->FileName[0] == L'\\') {
    493           ((CHAR16*)CleanFilePathStr)[StrLen(CleanFilePathStr)-1] = CHAR_NULL;
    494         }
    495         StrCatS(DestPath, PathSize/sizeof(CHAR16), Node->FileName);
     505        StrCpyS (DestPath, PathSize/sizeof (CHAR16), CleanFilePathStr);
     506        if ((CleanFilePathStr[StrLen (CleanFilePathStr)-1] != L'\\') && (Node->FileName[0] != L'\\')) {
     507          StrCatS (DestPath, PathSize/sizeof (CHAR16), L"\\");
     508        } else if ((CleanFilePathStr[StrLen (CleanFilePathStr)-1] == L'\\') && (Node->FileName[0] == L'\\')) {
     509          ((CHAR16 *)CleanFilePathStr)[StrLen (CleanFilePathStr)-1] = CHAR_NULL;
     510        }
     511
     512        StrCatS (DestPath, PathSize/sizeof (CHAR16), Node->FileName);
    496513      }
    497514    }
     
    500517    // Make sure the path exists
    501518    //
    502     if (EFI_ERROR(VerifyIntermediateDirectories(DestPath))) {
    503       ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_CP_DIR_WNF), gShellLevel2HiiHandle, L"cp", DestPath);
     519    if (EFI_ERROR (VerifyIntermediateDirectories (DestPath))) {
     520      ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_CP_DIR_WNF), gShellLevel2HiiHandle, L"cp", DestPath);
    504521      ShellStatus = SHELL_DEVICE_ERROR;
    505522      break;
    506523    }
    507524
    508     if ( !EFI_ERROR(ShellIsDirectory(Node->FullName))
    509       && !EFI_ERROR(ShellIsDirectory(DestPath))
    510       && StrniCmp(Node->FullName, DestPath, StrLen(DestPath)) == 0
    511       ){
    512       ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_CP_SD_PARENT), gShellLevel2HiiHandle, L"cp");
     525    if (  !EFI_ERROR (ShellIsDirectory (Node->FullName))
     526       && !EFI_ERROR (ShellIsDirectory (DestPath))
     527       && (StrniCmp (Node->FullName, DestPath, StrLen (DestPath)) == 0)
     528          )
     529    {
     530      ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_CP_SD_PARENT), gShellLevel2HiiHandle, L"cp");
    513531      ShellStatus = SHELL_INVALID_PARAMETER;
    514532      break;
    515533    }
    516     if (StringNoCaseCompare(&Node->FullName, &DestPath) == 0) {
    517       ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_CP_SD_SAME), gShellLevel2HiiHandle, L"cp");
     534
     535    if (StringNoCaseCompare (&Node->FullName, &DestPath) == 0) {
     536      ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_CP_SD_SAME), gShellLevel2HiiHandle, L"cp");
    518537      ShellStatus = SHELL_INVALID_PARAMETER;
    519538      break;
    520539    }
    521540
    522     if ((StrniCmp(Node->FullName, DestPath, StrLen(Node->FullName)) == 0)
    523       && (DestPath[StrLen(Node->FullName)] == CHAR_NULL || DestPath[StrLen(Node->FullName)] == L'\\')
    524       ) {
    525       ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_CP_SD_SAME), gShellLevel2HiiHandle, L"cp");
     541    if (  (StrniCmp (Node->FullName, DestPath, StrLen (Node->FullName)) == 0)
     542       && ((DestPath[StrLen (Node->FullName)] == CHAR_NULL) || (DestPath[StrLen (Node->FullName)] == L'\\'))
     543          )
     544    {
     545      ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_CP_SD_SAME), gShellLevel2HiiHandle, L"cp");
    526546      ShellStatus = SHELL_INVALID_PARAMETER;
    527547      break;
    528548    }
    529549
    530     PathCleanUpDirectories(DestPath);
     550    PathCleanUpDirectories (DestPath);
    531551
    532552    if (!SilentMode) {
    533       ShellPrintEx(-1, -1, HiiOutput, Node->FullName, DestPath);
     553      ShellPrintEx (-1, -1, HiiOutput, Node->FullName, DestPath);
    534554    }
    535555
     
    537557    // copy single file...
    538558    //
    539     ShellStatus = CopySingleFile(Node->FullName, DestPath, &Response, SilentMode, L"cp");
     559    ShellStatus = CopySingleFile (Node->FullName, DestPath, &Response, SilentMode, L"cp");
    540560    if (ShellStatus != SHELL_SUCCESS) {
    541561      break;
    542562    }
    543563  }
    544   if (ShellStatus == SHELL_SUCCESS && Resp == NULL) {
    545     ShellPrintEx(-1, -1, L"%s", HiiResultOk);
    546   }
    547 
    548   SHELL_FREE_NON_NULL(DestPath);
    549   SHELL_FREE_NON_NULL(HiiOutput);
    550   SHELL_FREE_NON_NULL(HiiResultOk);
    551   SHELL_FREE_NON_NULL(CleanFilePathStr);
     564
     565  if ((ShellStatus == SHELL_SUCCESS) && (Resp == NULL)) {
     566    ShellPrintEx (-1, -1, L"%s", HiiResultOk);
     567  }
     568
     569  SHELL_FREE_NON_NULL (DestPath);
     570  SHELL_FREE_NON_NULL (HiiOutput);
     571  SHELL_FREE_NON_NULL (HiiResultOk);
     572  SHELL_FREE_NON_NULL (CleanFilePathStr);
    552573  if (Resp == NULL) {
    553     SHELL_FREE_NON_NULL(Response);
     574    SHELL_FREE_NON_NULL (Response);
    554575  }
    555576
    556577  return (ShellStatus);
    557 
    558578}
    559579
     
    571591**/
    572592SHELL_STATUS
    573 ProcessValidateAndCopyFiles(
     593ProcessValidateAndCopyFiles (
    574594  IN       EFI_SHELL_FILE_INFO  *FileList,
    575595  IN CONST CHAR16               *DestDir,
     
    578598  )
    579599{
    580   SHELL_STATUS        ShellStatus;
    581   EFI_SHELL_FILE_INFO *List;
    582   EFI_FILE_INFO       *FileInfo;
    583   CHAR16              *FullName;
    584 
    585   List      = NULL;
    586   FullName  = NULL;
    587   FileInfo  = NULL;
    588 
    589   ShellOpenFileMetaArg((CHAR16*)DestDir, EFI_FILE_MODE_READ, &List);
    590   if (List != NULL && List->Link.ForwardLink != List->Link.BackLink) {
    591     ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_MARG_ERROR), gShellLevel2HiiHandle, L"cp", DestDir);
     600  SHELL_STATUS         ShellStatus;
     601  EFI_SHELL_FILE_INFO  *List;
     602  EFI_FILE_INFO        *FileInfo;
     603  CHAR16               *FullName;
     604
     605  List     = NULL;
     606  FullName = NULL;
     607  FileInfo = NULL;
     608
     609  ShellOpenFileMetaArg ((CHAR16 *)DestDir, EFI_FILE_MODE_READ, &List);
     610  if ((List != NULL) && (List->Link.ForwardLink != List->Link.BackLink)) {
     611    ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_MARG_ERROR), gShellLevel2HiiHandle, L"cp", DestDir);
    592612    ShellStatus = SHELL_INVALID_PARAMETER;
    593     ShellCloseFileMetaArg(&List);
     613    ShellCloseFileMetaArg (&List);
    594614  } else if (List != NULL) {
    595     ASSERT(((EFI_SHELL_FILE_INFO *)List->Link.ForwardLink) != NULL);
    596     ASSERT(((EFI_SHELL_FILE_INFO *)List->Link.ForwardLink)->FullName != NULL);
    597     FileInfo = gEfiShellProtocol->GetFileInfo(((EFI_SHELL_FILE_INFO *)List->Link.ForwardLink)->Handle);
    598     ASSERT(FileInfo != NULL);
    599     StrnCatGrow(&FullName, NULL, ((EFI_SHELL_FILE_INFO *)List->Link.ForwardLink)->FullName, 0);
    600     ShellCloseFileMetaArg(&List);
     615    ASSERT (((EFI_SHELL_FILE_INFO *)List->Link.ForwardLink) != NULL);
     616    ASSERT (((EFI_SHELL_FILE_INFO *)List->Link.ForwardLink)->FullName != NULL);
     617    FileInfo = gEfiShellProtocol->GetFileInfo (((EFI_SHELL_FILE_INFO *)List->Link.ForwardLink)->Handle);
     618    ASSERT (FileInfo != NULL);
     619    StrnCatGrow (&FullName, NULL, ((EFI_SHELL_FILE_INFO *)List->Link.ForwardLink)->FullName, 0);
     620    ShellCloseFileMetaArg (&List);
    601621    if ((FileInfo->Attribute & EFI_FILE_READ_ONLY) == 0) {
    602       ShellStatus = ValidateAndCopyFiles(FileList, FullName, SilentMode, RecursiveMode, NULL);
     622      ShellStatus = ValidateAndCopyFiles (FileList, FullName, SilentMode, RecursiveMode, NULL);
    603623    } else {
    604       ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_CP_DEST_ERROR), gShellLevel2HiiHandle, L"cp");
     624      ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_CP_DEST_ERROR), gShellLevel2HiiHandle, L"cp");
    605625      ShellStatus = SHELL_ACCESS_DENIED;
    606626    }
    607627  } else {
    608     ShellCloseFileMetaArg(&List);
    609     ShellStatus = ValidateAndCopyFiles(FileList, DestDir, SilentMode, RecursiveMode, NULL);
    610   }
    611 
    612   SHELL_FREE_NON_NULL(FileInfo);
    613   SHELL_FREE_NON_NULL(FullName);
     628    ShellCloseFileMetaArg (&List);
     629    ShellStatus = ValidateAndCopyFiles (FileList, DestDir, SilentMode, RecursiveMode, NULL);
     630  }
     631
     632  SHELL_FREE_NON_NULL (FileInfo);
     633  SHELL_FREE_NON_NULL (FullName);
    614634  return (ShellStatus);
    615635}
    616636
    617 STATIC CONST SHELL_PARAM_ITEM ParamList[] = {
    618   {L"-r", TypeFlag},
    619   {L"-q", TypeFlag},
    620   {NULL, TypeMax}
    621   };
     637STATIC CONST SHELL_PARAM_ITEM  ParamList[] = {
     638  { L"-r", TypeFlag },
     639  { L"-q", TypeFlag },
     640  { NULL,  TypeMax  }
     641};
    622642
    623643/**
     
    634654  )
    635655{
    636   EFI_STATUS          Status;
    637   LIST_ENTRY          *Package;
    638   CHAR16              *ProblemParam;
    639   SHELL_STATUS        ShellStatus;
    640   UINTN               ParamCount;
    641   UINTN               LoopCounter;
    642   EFI_SHELL_FILE_INFO *FileList;
    643   BOOLEAN             SilentMode;
    644   BOOLEAN             RecursiveMode;
    645   CONST CHAR16        *Cwd;
    646   CHAR16              *FullCwd;
    647 
    648   ProblemParam        = NULL;
    649   ShellStatus         = SHELL_SUCCESS;
    650   ParamCount          = 0;
    651   FileList            = NULL;
     656  EFI_STATUS           Status;
     657  LIST_ENTRY           *Package;
     658  CHAR16               *ProblemParam;
     659  SHELL_STATUS         ShellStatus;
     660  UINTN                ParamCount;
     661  UINTN                LoopCounter;
     662  EFI_SHELL_FILE_INFO  *FileList;
     663  BOOLEAN              SilentMode;
     664  BOOLEAN              RecursiveMode;
     665  CONST CHAR16         *Cwd;
     666  CHAR16               *FullCwd;
     667
     668  ProblemParam = NULL;
     669  ShellStatus  = SHELL_SUCCESS;
     670  ParamCount   = 0;
     671  FileList     = NULL;
    652672
    653673  //
    654674  // initialize the shell lib (we must be in non-auto-init...)
    655675  //
    656   Status = ShellInitialize();
    657   ASSERT_EFI_ERROR(Status);
    658 
    659   Status = CommandInit();
    660   ASSERT_EFI_ERROR(Status);
     676  Status = ShellInitialize ();
     677  ASSERT_EFI_ERROR (Status);
     678
     679  Status = CommandInit ();
     680  ASSERT_EFI_ERROR (Status);
    661681
    662682  //
     
    664684  //
    665685  Status = ShellCommandLineParse (ParamList, &Package, &ProblemParam, TRUE);
    666   if (EFI_ERROR(Status)) {
    667     if (Status == EFI_VOLUME_CORRUPTED && ProblemParam != NULL) {
    668       ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellLevel2HiiHandle, L"cp", ProblemParam);
    669       FreePool(ProblemParam);
     686  if (EFI_ERROR (Status)) {
     687    if ((Status == EFI_VOLUME_CORRUPTED) && (ProblemParam != NULL)) {
     688      ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellLevel2HiiHandle, L"cp", ProblemParam);
     689      FreePool (ProblemParam);
    670690      ShellStatus = SHELL_INVALID_PARAMETER;
    671691    } else {
    672       ASSERT(FALSE);
     692      ASSERT (FALSE);
    673693    }
    674694  } else {
     
    676696    // check for "-?"
    677697    //
    678     if (ShellCommandLineGetFlag(Package, L"-?")) {
    679       ASSERT(FALSE);
     698    if (ShellCommandLineGetFlag (Package, L"-?")) {
     699      ASSERT (FALSE);
    680700    }
    681701
     
    683703    // Initialize SilentMode and RecursiveMode
    684704    //
    685     if (gEfiShellProtocol->BatchIsActive()) {
     705    if (gEfiShellProtocol->BatchIsActive ()) {
    686706      SilentMode = TRUE;
    687707    } else {
    688       SilentMode = ShellCommandLineGetFlag(Package, L"-q");
    689     }
    690     RecursiveMode = ShellCommandLineGetFlag(Package, L"-r");
    691 
    692     switch (ParamCount = ShellCommandLineGetCount(Package)) {
     708      SilentMode = ShellCommandLineGetFlag (Package, L"-q");
     709    }
     710
     711    RecursiveMode = ShellCommandLineGetFlag (Package, L"-r");
     712
     713    switch (ParamCount = ShellCommandLineGetCount (Package)) {
    693714      case 0:
    694715      case 1:
     
    696717        // we have insufficient parameters
    697718        //
    698         ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_FEW), gShellLevel2HiiHandle, L"cp");
     719        ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_FEW), gShellLevel2HiiHandle, L"cp");
    699720        ShellStatus = SHELL_INVALID_PARAMETER;
    700721        break;
     
    703724        // must have valid CWD for single parameter...
    704725        //
    705         Cwd = ShellGetCurrentDir(NULL);
    706         if (Cwd == NULL){
    707           ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_NO_CWD), gShellLevel2HiiHandle, L"cp");
     726        Cwd = ShellGetCurrentDir (NULL);
     727        if (Cwd == NULL) {
     728          ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_NO_CWD), gShellLevel2HiiHandle, L"cp");
    708729          ShellStatus = SHELL_INVALID_PARAMETER;
    709730        } else {
    710           Status = ShellOpenFileMetaArg((CHAR16*)ShellCommandLineGetRawValue(Package, 1), EFI_FILE_MODE_WRITE|EFI_FILE_MODE_READ, &FileList);
    711           if (FileList == NULL || IsListEmpty(&FileList->Link) || EFI_ERROR(Status)) {
    712             ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_FILE_NF), gShellLevel2HiiHandle, L"cp", ShellCommandLineGetRawValue(Package, 1));
     731          Status = ShellOpenFileMetaArg ((CHAR16 *)ShellCommandLineGetRawValue (Package, 1), EFI_FILE_MODE_WRITE|EFI_FILE_MODE_READ, &FileList);
     732          if ((FileList == NULL) || IsListEmpty (&FileList->Link) || EFI_ERROR (Status)) {
     733            ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_FILE_NF), gShellLevel2HiiHandle, L"cp", ShellCommandLineGetRawValue (Package, 1));
    713734            ShellStatus = SHELL_NOT_FOUND;
    714           } else  {
    715             FullCwd = AllocateZeroPool(StrSize(Cwd) + sizeof(CHAR16));
     735          } else {
     736            FullCwd = AllocateZeroPool (StrSize (Cwd) + sizeof (CHAR16));
    716737            if (FullCwd == NULL) {
    717738              ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_OUT_MEM), gShellLevel2HiiHandle, L"cp");
     
    730751        // Make a big list of all the files...
    731752        //
    732         for (ParamCount--, LoopCounter = 1 ; LoopCounter < ParamCount && ShellStatus == SHELL_SUCCESS ; LoopCounter++) {
    733           if (ShellGetExecutionBreakFlag()) {
     753        for (ParamCount--, LoopCounter = 1; LoopCounter < ParamCount && ShellStatus == SHELL_SUCCESS; LoopCounter++) {
     754          if (ShellGetExecutionBreakFlag ()) {
    734755            break;
    735756          }
    736           Status = ShellOpenFileMetaArg((CHAR16*)ShellCommandLineGetRawValue(Package, LoopCounter), EFI_FILE_MODE_WRITE|EFI_FILE_MODE_READ, &FileList);
    737           if (EFI_ERROR(Status) || FileList == NULL || IsListEmpty(&FileList->Link)) {
    738             ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_FILE_NF), gShellLevel2HiiHandle, L"cp", ShellCommandLineGetRawValue(Package, LoopCounter));
     757
     758          Status = ShellOpenFileMetaArg ((CHAR16 *)ShellCommandLineGetRawValue (Package, LoopCounter), EFI_FILE_MODE_WRITE|EFI_FILE_MODE_READ, &FileList);
     759          if (EFI_ERROR (Status) || (FileList == NULL) || IsListEmpty (&FileList->Link)) {
     760            ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_FILE_NF), gShellLevel2HiiHandle, L"cp", ShellCommandLineGetRawValue (Package, LoopCounter));
    739761            ShellStatus = SHELL_NOT_FOUND;
    740762          }
    741763        }
     764
    742765        if (ShellStatus != SHELL_SUCCESS) {
    743           Status = ShellCloseFileMetaArg(&FileList);
     766          Status = ShellCloseFileMetaArg (&FileList);
    744767        } else {
    745768          //
    746769          // now copy them all...
    747770          //
    748           if (FileList != NULL && !IsListEmpty(&FileList->Link)) {
    749             ShellStatus = ProcessValidateAndCopyFiles(FileList, PathCleanUpDirectories((CHAR16*)ShellCommandLineGetRawValue(Package, ParamCount)), SilentMode, RecursiveMode);
    750             Status = ShellCloseFileMetaArg(&FileList);
    751             if (EFI_ERROR(Status) && ShellStatus == SHELL_SUCCESS) {
    752               ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_ERR_FILE), gShellLevel2HiiHandle, L"cp", ShellCommandLineGetRawValue(Package, ParamCount), ShellStatus|MAX_BIT);
     771          if ((FileList != NULL) && !IsListEmpty (&FileList->Link)) {
     772            ShellStatus = ProcessValidateAndCopyFiles (FileList, PathCleanUpDirectories ((CHAR16 *)ShellCommandLineGetRawValue (Package, ParamCount)), SilentMode, RecursiveMode);
     773            Status      = ShellCloseFileMetaArg (&FileList);
     774            if (EFI_ERROR (Status) && (ShellStatus == SHELL_SUCCESS)) {
     775              ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_ERR_FILE), gShellLevel2HiiHandle, L"cp", ShellCommandLineGetRawValue (Package, ParamCount), ShellStatus|MAX_BIT);
    753776              ShellStatus = SHELL_ACCESS_DENIED;
    754777            }
    755778          }
    756779        }
     780
    757781        break;
    758782    } // switch on parameter count
    759783
    760784    if (FileList != NULL) {
    761       ShellCloseFileMetaArg(&FileList);
     785      ShellCloseFileMetaArg (&FileList);
    762786    }
    763787
     
    768792  }
    769793
    770   if (ShellGetExecutionBreakFlag()) {
     794  if (ShellGetExecutionBreakFlag ()) {
    771795    return (SHELL_ABORTED);
    772796  }
     
    774798  return (ShellStatus);
    775799}
    776 
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette