/** @file\r
Main file for cp shell level 2 function.\r
\r
- Copyright (c) 2015, Hewlett-Packard Development Company, L.P.<BR>\r
- Copyright (c) 2009 - 2014, Intel Corporation. All rights reserved.<BR>\r
+ (C) Copyright 2015 Hewlett-Packard Development Company, L.P.<BR>\r
+ Copyright (c) 2009 - 2015, Intel Corporation. All rights reserved.<BR>\r
This program and the accompanying materials\r
are licensed and made available under the terms and conditions of the BSD License\r
which accompanies this distribution. The full text of the license may be found at\r
@param[in] Dest pointer to destination file name\r
@param[out] Resp pointer to response from question. Pass back on looped calling\r
@param[in] SilentMode whether to run in quiet mode or not\r
+ @param[in] CmdName Source command name requesting single file copy\r
\r
@retval SHELL_SUCCESS The source file was copied to the destination\r
**/\r
IN CONST CHAR16 *Source,\r
IN CONST CHAR16 *Dest,\r
OUT VOID **Resp,\r
- IN BOOLEAN SilentMode\r
+ IN BOOLEAN SilentMode,\r
+ IN CONST CHAR16 *CmdName\r
)\r
{\r
VOID *Response;\r
if (ShellIsDirectory(Source) == EFI_SUCCESS) {\r
Status = ShellCreateDirectory(Dest, &DestHandle);\r
if (EFI_ERROR(Status)) {\r
- ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_CP_DEST_DIR_FAIL), gShellLevel2HiiHandle, L"cp", Dest); \r
+ ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_CP_DEST_DIR_FAIL), gShellLevel2HiiHandle, CmdName, Dest); \r
return (SHELL_ACCESS_DENIED);\r
}\r
\r
//\r
Status = ShellOpenFileByName(Dest, &DestHandle, EFI_FILE_MODE_READ|EFI_FILE_MODE_WRITE|EFI_FILE_MODE_CREATE, 0);\r
if (EFI_ERROR(Status)) {\r
- ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_CP_DEST_OPEN_FAIL), gShellLevel2HiiHandle, L"cp", Dest); \r
+ ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_CP_DEST_OPEN_FAIL), gShellLevel2HiiHandle, CmdName, Dest); \r
return (SHELL_ACCESS_DENIED);\r
}\r
\r
//\r
// open source file\r
//\r
- Status = ShellOpenFileByName(Source, &SourceHandle, EFI_FILE_MODE_READ, 0);\r
- ASSERT_EFI_ERROR(Status);\r
+ Status = ShellOpenFileByName (Source, &SourceHandle, EFI_FILE_MODE_READ, 0);\r
+ if (EFI_ERROR (Status)) {\r
+ ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_CP_SRC_OPEN_FAIL), gShellLevel2HiiHandle, CmdName, Source);\r
+ return (SHELL_ACCESS_DENIED);\r
+ }\r
\r
//\r
//get file size of source file and freespace available on destination volume\r
//not enough space on destination directory to copy file\r
//\r
SHELL_FREE_NON_NULL(DestVolumeInfo);\r
- ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_CPY_FAIL), gShellLevel2HiiHandle, L"cp"); \r
+ ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_CPY_FAIL), gShellLevel2HiiHandle, CmdName); \r
return(SHELL_VOLUME_FULL);\r
} else {\r
//\r
Status = ShellWriteFile(DestHandle, &ReadSize, Buffer);\r
if (EFI_ERROR(Status)) {\r
ShellStatus = (SHELL_STATUS) (Status & (~MAX_BIT));\r
- ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_CPY_WRITE_ERROR), gShellLevel2HiiHandle, L"cp", Dest); \r
+ ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_CPY_WRITE_ERROR), gShellLevel2HiiHandle, CmdName, Dest); \r
break;\r
}\r
} else {\r
ShellStatus = (SHELL_STATUS) (Status & (~MAX_BIT));\r
- ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_CPY_READ_ERROR), gShellLevel2HiiHandle, L"cp", Source); \r
+ ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_CPY_READ_ERROR), gShellLevel2HiiHandle, CmdName, Source); \r
break;\r
}\r
}\r
// simple copy of a single file\r
//\r
if (Cwd != NULL) {\r
- StrnCpy(DestPath, Cwd, PathSize/sizeof(CHAR16)-1);\r
+ StrCpyS(DestPath, PathSize / sizeof(CHAR16), Cwd);\r
} else {\r
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_DIR_NF), gShellLevel2HiiHandle, L"cp", CleanFilePathStr); \r
FreePool (CleanFilePathStr);\r
return (SHELL_INVALID_PARAMETER);\r
}\r
if (DestPath[StrLen(DestPath)-1] != L'\\' && CleanFilePathStr[0] != L'\\') {\r
- StrnCat(DestPath, L"\\", PathSize/sizeof(CHAR16) - StrLen(DestPath) -1);\r
+ StrCatS(DestPath, PathSize / sizeof(CHAR16), L"\\");\r
} else if (DestPath[StrLen(DestPath)-1] == L'\\' && CleanFilePathStr[0] == L'\\') {\r
((CHAR16*)DestPath)[StrLen(DestPath)-1] = CHAR_NULL;\r
}\r
- StrnCat(DestPath, CleanFilePathStr, PathSize/sizeof(CHAR16) - StrLen(DestPath) -1);\r
+ StrCatS(DestPath, PathSize/sizeof(CHAR16), CleanFilePathStr);\r
} else {\r
- StrnCpy(DestPath, CleanFilePathStr, PathSize/sizeof(CHAR16) -1);\r
+ StrCpyS(DestPath, PathSize/sizeof(CHAR16), CleanFilePathStr);\r
}\r
} else {\r
//\r
// Copy to the root of CWD\r
//\r
if (Cwd != NULL) {\r
- StrnCpy(DestPath, Cwd, PathSize/sizeof(CHAR16) -1);\r
+ StrCpyS(DestPath, PathSize/sizeof(CHAR16), Cwd);\r
} else {\r
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_DIR_NF), gShellLevel2HiiHandle, L"cp", CleanFilePathStr); \r
FreePool(CleanFilePathStr);\r
return (SHELL_INVALID_PARAMETER);\r
}\r
while (PathRemoveLastItem(DestPath));\r
- StrnCat(DestPath, CleanFilePathStr+1, PathSize/sizeof(CHAR16) - StrLen(DestPath) -1);\r
- StrnCat(DestPath, Node->FileName, PathSize/sizeof(CHAR16) - StrLen(DestPath) -1);\r
+ StrCatS(DestPath, PathSize/sizeof(CHAR16), CleanFilePathStr+1);\r
+ StrCatS(DestPath, PathSize/sizeof(CHAR16), Node->FileName);\r
} else if (StrStr(CleanFilePathStr, L":") == NULL) {\r
if (Cwd != NULL) {\r
- StrnCpy(DestPath, Cwd, PathSize/sizeof(CHAR16) -1);\r
+ StrCpyS(DestPath, PathSize/sizeof(CHAR16), Cwd);\r
} else {\r
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_DIR_NF), gShellLevel2HiiHandle, L"cp", CleanFilePathStr); \r
FreePool(CleanFilePathStr);\r
return (SHELL_INVALID_PARAMETER);\r
}\r
if (DestPath[StrLen(DestPath)-1] != L'\\' && CleanFilePathStr[0] != L'\\') {\r
- StrnCat(DestPath, L"\\", PathSize/sizeof(CHAR16) - StrLen(DestPath) -1);\r
+ StrCatS(DestPath, PathSize/sizeof(CHAR16), L"\\");\r
} else if (DestPath[StrLen(DestPath)-1] == L'\\' && CleanFilePathStr[0] == L'\\') {\r
((CHAR16*)DestPath)[StrLen(DestPath)-1] = CHAR_NULL;\r
}\r
- StrnCat(DestPath, CleanFilePathStr, PathSize/sizeof(CHAR16) - StrLen(DestPath) -1);\r
+ StrCatS(DestPath, PathSize/sizeof(CHAR16), CleanFilePathStr);\r
if (CleanFilePathStr[StrLen(CleanFilePathStr)-1] != L'\\' && Node->FileName[0] != L'\\') {\r
- StrnCat(DestPath, L"\\", PathSize/sizeof(CHAR16) - StrLen(DestPath) -1);\r
+ StrCatS(DestPath, PathSize/sizeof(CHAR16), L"\\");\r
} else if (CleanFilePathStr[StrLen(CleanFilePathStr)-1] == L'\\' && Node->FileName[0] == L'\\') {\r
((CHAR16*)DestPath)[StrLen(DestPath)-1] = CHAR_NULL;\r
}\r
- StrnCat(DestPath, Node->FileName, PathSize/sizeof(CHAR16) - StrLen(DestPath) -1);\r
+ StrCatS(DestPath, PathSize/sizeof(CHAR16), Node->FileName);\r
\r
} else {\r
- StrnCpy(DestPath, CleanFilePathStr, PathSize/sizeof(CHAR16) -1);\r
+ StrCpyS(DestPath, PathSize/sizeof(CHAR16), CleanFilePathStr);\r
if (CleanFilePathStr[StrLen(CleanFilePathStr)-1] != L'\\' && Node->FileName[0] != L'\\') {\r
- StrnCat(DestPath, L"\\", PathSize/sizeof(CHAR16) - StrLen(DestPath) -1);\r
+ StrCatS(DestPath, PathSize/sizeof(CHAR16), L"\\");\r
} else if (CleanFilePathStr[StrLen(CleanFilePathStr)-1] == L'\\' && Node->FileName[0] == L'\\') {\r
((CHAR16*)CleanFilePathStr)[StrLen(CleanFilePathStr)-1] = CHAR_NULL;\r
}\r
- StrnCat(DestPath, Node->FileName, PathSize/sizeof(CHAR16) - StrLen(DestPath) -1);\r
+ StrCatS(DestPath, PathSize/sizeof(CHAR16), Node->FileName);\r
}\r
}\r
\r
//\r
// copy single file...\r
//\r
- ShellStatus = CopySingleFile(Node->FullName, DestPath, &Response, SilentMode);\r
+ ShellStatus = CopySingleFile(Node->FullName, DestPath, &Response, SilentMode, L"cp");\r
if (ShellStatus != SHELL_SUCCESS) {\r
break;\r
}\r