summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJaben Carsey <jaben.carsey@intel.com>2014-10-02 16:40:49 +0000
committerjcarsey <jcarsey@6f19259b-4bc3-4df7-8a09-765794883524>2014-10-02 16:40:49 +0000
commit7fe3fbad05cd6ef23e83ab5da8c5a82ff9bb456e (patch)
treeabec70839fd1a5a0d7b8772ca9156c14bc61e4f6
parent57446bb979d7466055977d1b816e6958b8ae997c (diff)
ShellPkg: Update MV. now supports across file system moves.
Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Jaben Carsey <jaben.carsey@intel.com> Reviewed-by: Erik Bjorge <erik.c.bjorge@intel.com> Reviewed-by: Tapan Shah <tapandshah@hp.com> git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@16193 6f19259b-4bc3-4df7-8a09-765794883524
-rw-r--r--ShellPkg/Library/UefiShellLevel2CommandsLib/Mv.c525
-rw-r--r--ShellPkg/Library/UefiShellLevel2CommandsLib/UefiShellLevel2CommandsLib.h41
-rw-r--r--ShellPkg/Library/UefiShellLevel2CommandsLib/UefiShellLevel2CommandsLib.unibin110208 -> 109962 bytes
3 files changed, 370 insertions, 196 deletions
diff --git a/ShellPkg/Library/UefiShellLevel2CommandsLib/Mv.c b/ShellPkg/Library/UefiShellLevel2CommandsLib/Mv.c
index 666cedb49..4dbc6d591 100644
--- a/ShellPkg/Library/UefiShellLevel2CommandsLib/Mv.c
+++ b/ShellPkg/Library/UefiShellLevel2CommandsLib/Mv.c
@@ -16,6 +16,50 @@
#include "UefiShellLevel2CommandsLib.h"
/**
+ function to determine if a move is between file systems.
+
+ @param FullName [in] The name of the file to move.
+ @param Cwd [in] The current working directory
+ @param DestPath [in] The target location to move to
+
+ @retval TRUE The move is across file system.
+ @retval FALSE The move is within a file system.
+**/
+STATIC
+BOOLEAN
+EFIAPI
+IsBetweenFileSystem(
+ IN CONST CHAR16 *FullName,
+ IN CONST CHAR16 *Cwd,
+ IN CONST CHAR16 *DestPath
+ )
+{
+ CHAR16 *Test;
+ CHAR16 *Test1;
+ UINTN Result;
+
+ Test = StrStr(FullName, L":");
+ if (Test == NULL && Cwd != NULL) {
+ Test = StrStr(Cwd, L":");
+ }
+ Test1 = StrStr(DestPath, L":");
+ if (Test1 == NULL && Cwd != NULL) {
+ Test1 = StrStr(Cwd, L":");
+ }
+ if (Test1 != NULL && Test != NULL) {
+ *Test = CHAR_NULL;
+ *Test1 = CHAR_NULL;
+ Result = StringNoCaseCompare(&FullName, &DestPath);
+ *Test = L':';
+ *Test1 = L':';
+ if (Result != 0) {
+ return (TRUE);
+ }
+ }
+ return (FALSE);
+}
+
+/**
Function to validate that moving a specific file (FileName) to a specific
location (DestPath) is valid.
@@ -29,86 +73,72 @@
@param Cwd [in] The current working directory
@param DestPath [in] The target location to move to
@param Attribute[in] The Attribute of the file
+ @param DestAttr [in] The Attribute of the destination
@param FileStatus[in] The Status of the file when opened
@retval TRUE The move is valid
@retval FALSE The move is not
**/
+STATIC
BOOLEAN
EFIAPI
IsValidMove(
- IN CONST CHAR16 *FullName,
+ IN CONST CHAR16 *SourcePath,
IN CONST CHAR16 *Cwd,
IN CONST CHAR16 *DestPath,
IN CONST UINT64 Attribute,
+ IN CONST UINT64 DestAttr,
IN CONST EFI_STATUS FileStatus
)
{
- CHAR16 *Test;
- CHAR16 *Test1;
- CHAR16 *TestWalker;
- INTN Result;
- UINTN TempLen;
- if (Cwd != NULL && StrCmp(FullName, Cwd) == 0) {
+ CHAR16 *DestPathCopy;
+ CHAR16 *DestPathWalker;
+
+ if (Cwd != NULL && StrCmp(SourcePath, Cwd) == 0) {
//
// Invalid move
//
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_MV_INV_CWD), gShellLevel2HiiHandle);
return (FALSE);
}
- Test = NULL;
- Test = StrnCatGrow(&Test, NULL, DestPath, 0);
- TestWalker = Test;
- ASSERT(TestWalker != NULL);
- while(*TestWalker == L'\\') {
- TestWalker++;
- }
- while(TestWalker != NULL && TestWalker[StrLen(TestWalker)-1] == L'\\') {
- TestWalker[StrLen(TestWalker)-1] = CHAR_NULL;
+
+ //
+ // invalid to move read only or move to a read only destination
+ //
+ if (((Attribute & EFI_FILE_READ_ONLY) != 0)
+ || (FileStatus == EFI_WRITE_PROTECTED)
+ || ((DestAttr & EFI_FILE_READ_ONLY) != 0)
+ ) {
+ ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_MV_INV_RO), gShellLevel2HiiHandle, SourcePath);
+ return (FALSE);
+ }
+
+ DestPathCopy = AllocateCopyPool(StrSize(DestPath), DestPath);
+ if (DestPathCopy == NULL) {
+ return (FALSE);
}
- ASSERT(TestWalker != NULL);
- ASSERT(FullName != NULL);
- if (StrStr(FullName, TestWalker) != 0) {
- TempLen = StrLen(FullName);
- if (StrStr(FullName, TestWalker) != FullName // not the first items... (could below it)
- && TempLen <= (StrLen(TestWalker) + 1)
- && StrStr(FullName+StrLen(TestWalker) + 1, L"\\") == NULL) {
- //
- // Invalid move
- //
- ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_MV_INV_SUB), gShellLevel2HiiHandle);
- FreePool(Test);
- return (FALSE);
- }
+
+ for (DestPathWalker = DestPathCopy; *DestPathWalker == L'\\'; DestPathWalker++) ;
+
+ while(DestPathWalker != NULL && DestPathWalker[StrLen(DestPathWalker)-1] == L'\\') {
+ DestPathWalker[StrLen(DestPathWalker)-1] = CHAR_NULL;
}
- FreePool(Test);
- if (StrStr(DestPath, FullName) != 0 && StrStr(DestPath, FullName) != DestPath) {
- //
- // Invalid move
- //
+
+ ASSERT(DestPathWalker != NULL);
+ ASSERT(SourcePath != NULL);
+
+ //
+ // If they're the same, or if source is "above" dest on file path tree
+ //
+ if ( StrCmp(DestPathWalker, SourcePath) == 0
+ || StrStr(DestPathWalker, SourcePath) == DestPathWalker
+ ) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_MV_INV_SUB), gShellLevel2HiiHandle);
+ FreePool(DestPathCopy);
return (FALSE);
}
- if (((Attribute & EFI_FILE_READ_ONLY) != 0) || (FileStatus == EFI_WRITE_PROTECTED)) {
- //
- // invalid to move read only
- //
- ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_MV_INV_RO), gShellLevel2HiiHandle, FullName);
- return (FALSE);
- }
- Test = StrStr(FullName, L":");
- Test1 = StrStr(DestPath, L":");
- if (Test1 != NULL && Test != NULL) {
- *Test = CHAR_NULL;
- *Test1 = CHAR_NULL;
- Result = StringNoCaseCompare(&FullName, &DestPath);
- *Test = L':';
- *Test1 = L':';
- if (Result != 0) {
- ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_MV_INV_FS), gShellLevel2HiiHandle);
- return (FALSE);
- }
- }
+ FreePool(DestPathCopy);
+
return (TRUE);
}
@@ -119,21 +149,24 @@ IsValidMove(
if the result is sucessful the caller must free *DestPathPointer.
- @param[in] DestDir The original path to the destination.
+ @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.
- @retval SHELL_INVALID_PARAMETER The DestDir could not be resolved to a location.
- @retval SHELL_INVALID_PARAMETER The DestDir could be resolved to more than 1 location.
+ @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.
**/
+STATIC
SHELL_STATUS
EFIAPI
GetDestinationLocation(
- IN CONST CHAR16 *DestDir,
+ IN CONST CHAR16 *DestParameter,
IN OUT CHAR16 **DestPathPointer,
- IN CONST CHAR16 *Cwd
+ IN CONST CHAR16 *Cwd,
+ IN CONST BOOLEAN SingleSource,
+ IN OUT UINT64 *DestAttr
)
{
EFI_SHELL_FILE_INFO *DestList;
@@ -145,7 +178,9 @@ GetDestinationLocation(
DestList = NULL;
DestPath = NULL;
- if (StrStr(DestDir, L"\\") == DestDir) {
+ ASSERT(DestAttr != NULL);
+
+ if (StrStr(DestParameter, L"\\") == DestParameter) {
if (Cwd == NULL) {
return SHELL_INVALID_PARAMETER;
}
@@ -157,10 +192,10 @@ GetDestinationLocation(
while (PathRemoveLastItem(DestPath)) ;
//
- // Append DestDir beyond '\' which may be present
+ // Append DestParameter beyond '\' which may be present
//
CurrentSize = StrSize(DestPath);
- StrnCatGrow(&DestPath, &CurrentSize, &DestDir[1], 0);
+ StrnCatGrow(&DestPath, &CurrentSize, &DestParameter[1], 0);
*DestPathPointer = DestPath;
return (SHELL_SUCCESS);
@@ -168,33 +203,34 @@ GetDestinationLocation(
//
// get the destination path
//
- ShellOpenFileMetaArg((CHAR16*)DestDir, EFI_FILE_MODE_WRITE|EFI_FILE_MODE_READ|EFI_FILE_MODE_CREATE, &DestList);
+ 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(DestDir, L":") == NULL) {
+ 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(DestDir);
+ NewSize += StrSize(DestParameter);
DestPath = AllocateZeroPool(NewSize);
if (DestPath == NULL) {
ShellCloseFileMetaArg(&DestList);
return (SHELL_OUT_OF_RESOURCES);
}
StrCpy(DestPath, Cwd);
- if (DestPath[StrLen(DestPath)-1] != L'\\' && DestDir[0] != L'\\') {
+ if (DestPath[StrLen(DestPath)-1] != L'\\' && DestParameter[0] != L'\\') {
StrCat(DestPath, L"\\");
- } else if (DestPath[StrLen(DestPath)-1] == L'\\' && DestDir[0] == L'\\') {
+ } else if (DestPath[StrLen(DestPath)-1] == L'\\' && DestParameter[0] == L'\\') {
((CHAR16*)DestPath)[StrLen(DestPath)-1] = CHAR_NULL;
}
- StrCat(DestPath, DestDir);
+ StrCat(DestPath, DestParameter);
} else {
ASSERT(DestPath == NULL);
- DestPath = StrnCatGrow(&DestPath, NULL, DestDir, 0);
+ DestPath = StrnCatGrow(&DestPath, NULL, DestParameter, 0);
if (DestPath == NULL) {
ShellCloseFileMetaArg(&DestList);
return (SHELL_OUT_OF_RESOURCES);
@@ -202,15 +238,20 @@ GetDestinationLocation(
}
} 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, DestDir);
+ ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_MARG_ERROR), gShellLevel2HiiHandle, DestParameter);
return (SHELL_INVALID_PARAMETER);
}
- if (ShellIsDirectory(Node->FullName)==EFI_SUCCESS) {
+
+ //
+ // 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);
@@ -220,10 +261,10 @@ GetDestinationLocation(
StrCat(DestPath, L"\\");
} else {
//
- // cant move onto another file.
+ // cant move multiple files onto a single file.
//
ShellCloseFileMetaArg(&DestList);
- ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_FILE_ERROR), gShellLevel2HiiHandle, DestDir);
+ ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_FILE_ERROR), gShellLevel2HiiHandle, DestParameter);
return (SHELL_INVALID_PARAMETER);
}
}
@@ -234,6 +275,130 @@ GetDestinationLocation(
return (SHELL_SUCCESS);
}
+EFI_STATUS
+EFIAPI
+MoveBetweenFileSystems(
+ IN EFI_SHELL_FILE_INFO *Node,
+ IN CONST CHAR16 *DestPath,
+ OUT VOID **Resp
+ )
+{
+ EFI_STATUS Status;
+
+ //
+ // First we copy the file
+ //
+ Status = CopySingleFile(Node->FullName, DestPath, Resp, TRUE);
+
+ //
+ // Check our result
+ //
+ if (!EFI_ERROR(Status)) {
+ //
+ // The copy was successful. delete the source file.
+ //
+ CascadeDelete(Node, TRUE);
+ Node->Handle = NULL;
+ }
+
+ return (Status);
+}
+
+EFI_STATUS
+EFIAPI
+CreateFullDestPath(
+ IN CONST CHAR16 **DestPath,
+ OUT CHAR16 **FullDestPath,
+ IN CONST CHAR16 *FileName
+ )
+{
+ UINTN Size;
+ if (FullDestPath == NULL || FileName == NULL || DestPath == NULL || *DestPath == NULL){
+ return (EFI_INVALID_PARAMETER);
+ }
+
+ Size = StrSize(*DestPath) + StrSize(FileName);
+
+ *FullDestPath = AllocateZeroPool(Size);
+ if (*FullDestPath == NULL){
+ return (EFI_OUT_OF_RESOURCES);
+ }
+
+ StrnCpy(*FullDestPath, *DestPath, Size / sizeof(CHAR16) - 1);
+ if ((*FullDestPath)[StrLen(*FullDestPath)-1] != L'\\' && FileName[0] != L'\\') {
+ StrnCat(*FullDestPath, L"\\",Size / sizeof(CHAR16) - 1 - StrLen(*FullDestPath));
+ }
+ StrnCat(*FullDestPath, FileName, Size / sizeof(CHAR16) - 1 - StrLen(*FullDestPath));
+
+ return (EFI_SUCCESS);
+}
+
+EFI_STATUS
+EFIAPI
+MoveWithinFileSystems(
+ IN EFI_SHELL_FILE_INFO *Node,
+ IN CHAR16 *DestPath,
+ OUT VOID **Resp
+ )
+{
+ EFI_FILE_INFO *NewFileInfo;
+ CHAR16 *TempLocation;
+ UINTN NewSize;
+ UINTN Length;
+ EFI_STATUS Status;
+
+ //
+ // Chop off map info from DestPath
+ //
+ if ((TempLocation = StrStr(DestPath, L":")) != NULL) {
+ CopyMem(DestPath, TempLocation+1, StrSize(TempLocation+1));
+ }
+
+ //
+ // construct the new file info block
+ //
+ NewSize = StrSize(DestPath);
+ NewSize += StrSize(Node->FileName) + SIZE_OF_EFI_FILE_INFO + sizeof(CHAR16);
+ NewFileInfo = AllocateZeroPool(NewSize);
+ if (NewFileInfo == NULL) {
+ ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_NO_MEM), gShellLevel2HiiHandle);
+ Status = EFI_OUT_OF_RESOURCES;
+ } else {
+ CopyMem(NewFileInfo, Node->Info, SIZE_OF_EFI_FILE_INFO);
+ if (DestPath[0] != L'\\') {
+ StrCpy(NewFileInfo->FileName, L"\\");
+ StrCat(NewFileInfo->FileName, DestPath);
+ } else {
+ StrCpy(NewFileInfo->FileName, DestPath);
+ }
+ Length = StrLen(NewFileInfo->FileName);
+ if (Length > 0) {
+ Length--;
+ }
+ if (NewFileInfo->FileName[Length] == L'\\') {
+ if (Node->FileName[0] == L'\\') {
+ //
+ // Don't allow for double slashes. Eliminate one of them.
+ //
+ NewFileInfo->FileName[Length] = CHAR_NULL;
+ }
+ StrCat(NewFileInfo->FileName, Node->FileName);
+ }
+ NewFileInfo->Size = SIZE_OF_EFI_FILE_INFO + StrSize(NewFileInfo->FileName);
+
+ //
+ // Perform the move operation
+ //
+ Status = ShellSetFileInfo(Node->Handle, NewFileInfo);
+
+ //
+ // Free the info object we used...
+ //
+ FreePool(NewFileInfo);
+ }
+
+ return (Status);
+}
/**
function to take a list of files to move and a destination location and do
the verification and moving of those files to that location. This function
@@ -241,7 +406,7 @@ GetDestinationLocation(
@param[in] FileList A LIST_ENTRY* based list of files to move
@param[out] Resp pointer to response from question. Pass back on looped calling
- @param[in] DestDir the destination location
+ @param[in] DestParameter the originally specified destination location
@retval SHELL_SUCCESS the files were all moved.
@retval SHELL_INVALID_PARAMETER a parameter was invalid
@@ -249,63 +414,70 @@ GetDestinationLocation(
@retval SHELL_WRITE_PROTECTED the destination was write protected
@retval SHELL_OUT_OF_RESOURCES a memory allocation failed
**/
+STATIC
SHELL_STATUS
EFIAPI
ValidateAndMoveFiles(
- IN CONST EFI_SHELL_FILE_INFO *FileList,
+ IN EFI_SHELL_FILE_INFO *FileList,
OUT VOID **Resp,
- IN CONST CHAR16 *DestDir
+ IN CONST CHAR16 *DestParameter
)
{
EFI_STATUS Status;
CHAR16 *HiiOutput;
CHAR16 *HiiResultOk;
CHAR16 *DestPath;
+ CHAR16 *FullDestPath;
CONST CHAR16 *Cwd;
SHELL_STATUS ShellStatus;
- CONST EFI_SHELL_FILE_INFO *Node;
- EFI_FILE_INFO *NewFileInfo;
- CHAR16 *TempLocation;
- UINTN NewSize;
- UINTN Length;
+ EFI_SHELL_FILE_INFO *Node;
VOID *Response;
- SHELL_FILE_HANDLE DestHandle;
+ UINT64 Attr;
CHAR16 *CleanFilePathStr;
ASSERT(FileList != NULL);
- ASSERT(DestDir != NULL);
+ ASSERT(DestParameter != NULL);
- DestPath = NULL;
- Cwd = ShellGetCurrentDir(NULL);
- Response = *Resp;
- CleanFilePathStr = NULL;
+ DestPath = NULL;
+ FullDestPath = NULL;
+ Cwd = ShellGetCurrentDir(NULL);
+ Response = *Resp;
+ Attr = 0;
+ CleanFilePathStr = NULL;
- Status = ShellLevel2StripQuotes (DestDir, &CleanFilePathStr);
+ Status = ShellLevel2StripQuotes (DestParameter, &CleanFilePathStr);
if (EFI_ERROR (Status)) {
if (Status == EFI_OUT_OF_RESOURCES) {
return SHELL_OUT_OF_RESOURCES;
} else {
return SHELL_INVALID_PARAMETER;
}
- }
+ }
ASSERT (CleanFilePathStr != NULL);
//
// Get and validate the destination location
//
- ShellStatus = GetDestinationLocation(CleanFilePathStr, &DestPath, Cwd);
+ ShellStatus = GetDestinationLocation(CleanFilePathStr, &DestPath, Cwd, FileList->Link.ForwardLink == FileList->Link.BackLink, &Attr);
FreePool (CleanFilePathStr);
+
if (ShellStatus != SHELL_SUCCESS) {
return (ShellStatus);
}
DestPath = PathCleanUpDirectories(DestPath);
+ if (DestPath == NULL) {
+ return (SHELL_OUT_OF_RESOURCES);
+ }
HiiOutput = HiiGetString (gShellLevel2HiiHandle, STRING_TOKEN (STR_MV_OUTPUT), NULL);
HiiResultOk = HiiGetString (gShellLevel2HiiHandle, STRING_TOKEN (STR_GEN_RES_OK), NULL);
- ASSERT (DestPath != NULL);
- ASSERT (HiiResultOk != NULL);
- ASSERT (HiiOutput != NULL);
+ if (HiiOutput == NULL || HiiResultOk == NULL) {
+ SHELL_FREE_NON_NULL(DestPath);
+ SHELL_FREE_NON_NULL(HiiOutput);
+ SHELL_FREE_NON_NULL(HiiResultOk);
+ return (SHELL_OUT_OF_RESOURCES);
+ }
//
// Go through the list of files and directories to move...
@@ -332,127 +504,90 @@ ValidateAndMoveFiles(
continue;
}
+ SHELL_FREE_NON_NULL(FullDestPath);
+ FullDestPath = NULL;
+ if (ShellIsDirectory(DestPath)==EFI_SUCCESS) {
+ CreateFullDestPath(&DestPath, &FullDestPath, Node->FileName);
+ }
+
//
// Validate that the move is valid
//
- if (!IsValidMove(Node->FullName, Cwd, DestPath, Node->Info->Attribute, Node->Status)) {
+ if (!IsValidMove(Node->FullName, Cwd, FullDestPath?FullDestPath:DestPath, Node->Info->Attribute, Attr, Node->Status)) {
ShellStatus = SHELL_INVALID_PARAMETER;
continue;
}
- //
- // Chop off map info from "DestPath"
- //
- if ((TempLocation = StrStr(DestPath, L":")) != NULL) {
- CopyMem(DestPath, TempLocation+1, StrSize(TempLocation+1));
- }
+ ShellPrintEx(-1, -1, HiiOutput, Node->FullName, FullDestPath?FullDestPath:DestPath);
//
- // construct the new file info block
+ // See if destination exists
//
- NewSize = StrSize(DestPath);
- NewSize += StrSize(Node->FileName) + SIZE_OF_EFI_FILE_INFO + sizeof(CHAR16);
- NewFileInfo = AllocateZeroPool(NewSize);
- if (NewFileInfo == NULL) {
- ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_NO_MEM), gShellLevel2HiiHandle);
- ShellStatus = SHELL_OUT_OF_RESOURCES;
- } else {
- CopyMem(NewFileInfo, Node->Info, SIZE_OF_EFI_FILE_INFO);
- if (DestPath[0] != L'\\') {
- StrCpy(NewFileInfo->FileName, L"\\");
- StrCat(NewFileInfo->FileName, DestPath);
- } else {
- StrCpy(NewFileInfo->FileName, DestPath);
+ if (!EFI_ERROR(ShellFileExists(FullDestPath?FullDestPath:DestPath))) {
+ if (Response == NULL) {
+ ShellPromptForResponseHii(ShellPromptResponseTypeYesNoAllCancel, STRING_TOKEN (STR_GEN_DEST_EXIST_OVR), gShellLevel2HiiHandle, &Response);
}
- Length = StrLen(NewFileInfo->FileName);
- if (Length > 0) {
- Length--;
- }
- if (NewFileInfo->FileName[Length] == L'\\') {
- if (Node->FileName[0] == L'\\') {
+ switch (*(SHELL_PROMPT_RESPONSE*)Response) {
+ case ShellPromptResponseNo:
+ FreePool(Response);
+ Response = NULL;
+ continue;
+ case ShellPromptResponseCancel:
+ *Resp = Response;
//
- // Don't allow for double slashes. Eliminate one of them.
+ // indicate to stop everything
//
- NewFileInfo->FileName[Length] = CHAR_NULL;
- }
- StrCat(NewFileInfo->FileName, Node->FileName);
+ return (SHELL_ABORTED);
+ case ShellPromptResponseAll:
+ *Resp = Response;
+ break;
+ case ShellPromptResponseYes:
+ FreePool(Response);
+ Response = NULL;
+ break;
+ default:
+ FreePool(Response);
+ return SHELL_ABORTED;
}
- NewFileInfo->Size = SIZE_OF_EFI_FILE_INFO + StrSize(NewFileInfo->FileName);
- ShellPrintEx(-1, -1, HiiOutput, Node->FullName, NewFileInfo->FileName);
+ Status = ShellDeleteFileByName(FullDestPath?FullDestPath:DestPath);
+ }
- if (!EFI_ERROR(ShellFileExists(NewFileInfo->FileName))) {
- if (Response == NULL) {
- ShellPromptForResponseHii(ShellPromptResponseTypeYesNoAllCancel, STRING_TOKEN (STR_GEN_DEST_EXIST_OVR), gShellLevel2HiiHandle, &Response);
- }
- switch (*(SHELL_PROMPT_RESPONSE*)Response) {
- case ShellPromptResponseNo:
- FreePool(NewFileInfo);
- continue;
- case ShellPromptResponseCancel:
- *Resp = Response;
- //
- // indicate to stop everything
- //
- FreePool(NewFileInfo);
- FreePool(DestPath);
- FreePool(HiiOutput);
- FreePool(HiiResultOk);
- return (SHELL_ABORTED);
- case ShellPromptResponseAll:
- *Resp = Response;
- break;
- case ShellPromptResponseYes:
- FreePool(Response);
- break;
- default:
- FreePool(Response);
- FreePool(NewFileInfo);
- FreePool(DestPath);
- FreePool(HiiOutput);
- FreePool(HiiResultOk);
- return SHELL_ABORTED;
- }
- Status = ShellOpenFileByName(NewFileInfo->FileName, &DestHandle, EFI_FILE_MODE_READ|EFI_FILE_MODE_WRITE, 0);
- ShellDeleteFile(&DestHandle);
+ if (IsBetweenFileSystem(Node->FullName, Cwd, DestPath)) {
+ while (FullDestPath == NULL && DestPath != NULL && DestPath[0] != CHAR_NULL && DestPath[StrLen(DestPath) - 1] == L'\\') {
+ DestPath[StrLen(DestPath) - 1] = CHAR_NULL;
}
+ Status = MoveBetweenFileSystems(Node, FullDestPath?FullDestPath:DestPath, &Response);
+ } else {
+ Status = MoveWithinFileSystems(Node, DestPath, &Response);
+ }
-
- //
- // Perform the move operation
- //
- Status = ShellSetFileInfo(Node->Handle, NewFileInfo);
-
- //
- // Free the info object we used...
- //
- FreePool(NewFileInfo);
-
- //
- // Check our result
- //
- if (EFI_ERROR(Status)) {
- ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_ERR_UK), gShellLevel2HiiHandle, Status);
- ShellStatus = SHELL_INVALID_PARAMETER;
- if (Status == EFI_SECURITY_VIOLATION) {
- ShellStatus = SHELL_SECURITY_VIOLATION;
- } else if (Status == EFI_WRITE_PROTECTED) {
- ShellStatus = SHELL_WRITE_PROTECTED;
- } else if (Status == EFI_OUT_OF_RESOURCES) {
- ShellStatus = SHELL_OUT_OF_RESOURCES;
- } else if (Status == EFI_DEVICE_ERROR) {
- ShellStatus = SHELL_DEVICE_ERROR;
- } else if (Status == EFI_ACCESS_DENIED) {
- ShellStatus = SHELL_ACCESS_DENIED;
- }
- } else {
- ShellPrintEx(-1, -1, L"%s", HiiResultOk);
+ //
+ // Check our result
+ //
+ if (EFI_ERROR(Status)) {
+ ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_ERR_UK), gShellLevel2HiiHandle, Status);
+ ShellStatus = SHELL_INVALID_PARAMETER;
+ if (Status == EFI_SECURITY_VIOLATION) {
+ ShellStatus = SHELL_SECURITY_VIOLATION;
+ } else if (Status == EFI_WRITE_PROTECTED) {
+ ShellStatus = SHELL_WRITE_PROTECTED;
+ } else if (Status == EFI_OUT_OF_RESOURCES) {
+ ShellStatus = SHELL_OUT_OF_RESOURCES;
+ } else if (Status == EFI_DEVICE_ERROR) {
+ ShellStatus = SHELL_DEVICE_ERROR;
+ } else if (Status == EFI_ACCESS_DENIED) {
+ ShellStatus = SHELL_ACCESS_DENIED;
}
+ } else {
+ ShellPrintEx(-1, -1, L"%s", HiiResultOk);
}
- } // for loop
- FreePool(DestPath);
- FreePool(HiiOutput);
- FreePool(HiiResultOk);
+ } // main for loop
+
+ SHELL_FREE_NON_NULL(FullDestPath);
+ SHELL_FREE_NON_NULL(DestPath);
+ SHELL_FREE_NON_NULL(HiiOutput);
+ SHELL_FREE_NON_NULL(HiiResultOk);
return (ShellStatus);
}
diff --git a/ShellPkg/Library/UefiShellLevel2CommandsLib/UefiShellLevel2CommandsLib.h b/ShellPkg/Library/UefiShellLevel2CommandsLib/UefiShellLevel2CommandsLib.h
index d6f23187b..f1549b916 100644
--- a/ShellPkg/Library/UefiShellLevel2CommandsLib/UefiShellLevel2CommandsLib.h
+++ b/ShellPkg/Library/UefiShellLevel2CommandsLib/UefiShellLevel2CommandsLib.h
@@ -9,7 +9,7 @@
* functions are non-interactive only
- Copyright (c) 2009 - 2013, Intel Corporation. All rights reserved.<BR>
+ Copyright (c) 2009 - 2014, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
@@ -330,5 +330,44 @@ ShellCommandRunVol (
IN EFI_SYSTEM_TABLE *SystemTable
);
+/**
+ 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
+ );
+
+/**
+ Delete a node and all nodes under it (including sub directories).
+
+ @param[in] Node The node to start deleting with.
+ @param[in] Quiet TRUE to print no messages.
+
+ @retval SHELL_SUCCESS The operation was successful.
+ @retval SHELL_ACCESS_DENIED A file was read only.
+ @retval SHELL_ABORTED The abort message was received.
+ @retval SHELL_DEVICE_ERROR A device error occured reading this Node.
+**/
+SHELL_STATUS
+EFIAPI
+CascadeDelete(
+ IN EFI_SHELL_FILE_INFO *Node,
+ IN CONST BOOLEAN Quiet
+ );
+
#endif
diff --git a/ShellPkg/Library/UefiShellLevel2CommandsLib/UefiShellLevel2CommandsLib.uni b/ShellPkg/Library/UefiShellLevel2CommandsLib/UefiShellLevel2CommandsLib.uni
index b3243e75a..8328456b3 100644
--- a/ShellPkg/Library/UefiShellLevel2CommandsLib/UefiShellLevel2CommandsLib.uni
+++ b/ShellPkg/Library/UefiShellLevel2CommandsLib/UefiShellLevel2CommandsLib.uni
Binary files differ