/** @file
Main file for mv shell level 2 function.
Copyright (c) 2009 - 2011, 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
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
**/
#include "UefiShellLevel2CommandsLib.h"
/**
Function to validate that moving a specific file (FileName) to a specific
location (DestPath) is valid.
This function will verify that the destination is not a subdirectory of
FullName, that the Current working Directory is not being moved, and that
the directory is not read only.
if the move is invalid this function will report the error to StdOut.
@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
@param Attribute[in] The Attribute of the file
@retval TRUE The move is valid
@retval FALSE The move is not
**/
)
{
//
// Invalid move
//
return (FALSE);
}
TestWalker = Test;
while(*TestWalker == L'\\') {
TestWalker++;
}
}
//
// Invalid move
//
return (FALSE);
}
}
//
// Invalid move
//
return (FALSE);
}
if ((Attribute & EFI_FILE_READ_ONLY) != 0) {
//
// invalid to move read only
//
return (FALSE);
}
*Test = L':';
*Test1 = L':';
if (Result != 0) {
return (FALSE);
}
}
return (TRUE);
}
/**
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] DestDir 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 Cwd is required and is NULL.
@retval SHELL_SUCCESS The operation was sucessful.
**/
)
{
return SHELL_INVALID_PARAMETER;
}
return (SHELL_OUT_OF_RESOURCES);
}
while (PathRemoveLastItem(DestPath)) ;
return (SHELL_SUCCESS);
}
//
// get the destination path
//
Status = ShellOpenFileMetaArg((CHAR16*)DestDir, EFI_FILE_MODE_WRITE|EFI_FILE_MODE_READ|EFI_FILE_MODE_CREATE, &DestList);
//
// Not existing... must be renaming
//
return (SHELL_INVALID_PARAMETER);
}
return (SHELL_OUT_OF_RESOURCES);
}
}
} else {
return (SHELL_OUT_OF_RESOURCES);
}
}
} else {
//
// Make sure there is only 1 node in the list.
//
return (SHELL_INVALID_PARAMETER);
}
return (SHELL_OUT_OF_RESOURCES);
}
} else {
//
// cant move onto another file.
//
return (SHELL_INVALID_PARAMETER);
}
}
return (SHELL_SUCCESS);
}
/**
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
will report any errors to the user and continue to move the rest of the files.
@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
@retval SHELL_SUCCESS the files were all moved.
@retval SHELL_INVALID_PARAMETER a parameter was invalid
@retval SHELL_SECURITY_VIOLATION a security violation ocurred
@retval SHELL_WRITE_PROTECTED the destination was write protected
@retval SHELL_OUT_OF_RESOURCES a memory allocation failed
**/
)
{
//
// Get and validate the destination location
//
if (ShellStatus != SHELL_SUCCESS) {
return (ShellStatus);
}
// ASSERT (Cwd != NULL);
//
// Go through the list of files and directories to move...
//
){
if (ShellGetExecutionBreakFlag()) {
break;
}
//
// skip the directory traversing stuff...
//
continue;
}
//
// Validate that the move is valid
//
continue;
}
//
// Chop off map info from "DestPath"
//
}
//
// construct the new file info block
//
if (NewFileInfo == NULL) {
} else {
if (DestPath[0] != L'\\') {
} else {
}
if (Length > 0) {
Length--;
}
//
// Don't allow for double slashes. Eliminate one of them.
//
}
}
ShellPromptForResponseHii(ShellPromptResponseTypeYesNoAllCancel, STRING_TOKEN (STR_GEN_DEST_EXIST_OVR), gShellLevel2HiiHandle, &Response);
}
switch (*(SHELL_PROMPT_RESPONSE*)Response) {
case ShellPromptResponseNo:
continue;
//
// indicate to stop everything
//
return (SHELL_ABORTED);
case ShellPromptResponseAll:
break;
case ShellPromptResponseYes:
break;
default:
return SHELL_ABORTED;
}
Status = ShellOpenFileByName(NewFileInfo->FileName, &DestHandle, EFI_FILE_MODE_READ|EFI_FILE_MODE_WRITE, 0);
}
//
// Perform the move operation
//
//
// Free the info object we used...
//
//
// Check our result
//
//
// move failed
//
switch(Status){
default:
case EFI_SECURITY_VIOLATION:
case EFI_WRITE_PROTECTED:
case EFI_OUT_OF_RESOURCES:
case EFI_DEVICE_ERROR:
case EFI_ACCESS_DENIED:
} // switch
} else {
}
}
} // for loop
return (ShellStatus);
}
/**
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).
**/
)
{
ProblemParam = NULL;
ParamCount = 0;
//
// initialize the shell lib (we must be in non-auto-init...)
//
Status = ShellInitialize();
//
// parse the command line
//
} else {
}
} else {
//
// check for "-?"
//
}
case 0:
case 1:
//
// we have insufficient parameters
//
break;
case 2:
//
// must have valid CWD for single parameter...
//
} else {
Status = ShellOpenFileMetaArg((CHAR16*)ShellCommandLineGetRawValue(Package, 1), EFI_FILE_MODE_WRITE|EFI_FILE_MODE_READ, &FileList);
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_FILE_NF), gShellLevel2HiiHandle, ShellCommandLineGetRawValue(Package, 1));
} else {
//
// ValidateAndMoveFiles will report errors to the screen itself
//
}
}
break;
default:
///@todo make sure this works with error half way through and continues...
if (ShellGetExecutionBreakFlag()) {
break;
}
Status = ShellOpenFileMetaArg((CHAR16*)ShellCommandLineGetRawValue(Package, LoopCounter), EFI_FILE_MODE_WRITE|EFI_FILE_MODE_READ, &FileList);
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_FILE_NF), gShellLevel2HiiHandle, ShellCommandLineGetRawValue(Package, LoopCounter));
} 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 {
}
}
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_ERR_FILE), gShellLevel2HiiHandle, ShellCommandLineGetRawValue(Package, 1), ShellStatus|MAX_BIT);
}
}
}
break;
} // switch on parameter count
}
//
// free the command line package
//
}
if (ShellGetExecutionBreakFlag()) {
return (SHELL_ABORTED);
}
return (ShellStatus);
}