/** @file
Main file for cp 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 take a list of files to copy and a destination location and do
the verification and copying of those files to that location. This function
will report any errors to the user and halt.
@param[in] FileList A LIST_ENTRY* based list of files to move.
@param[in] DestDir The destination location.
@param[in] SilentMode TRUE to eliminate screen output.
@param[in] RecursiveMode TRUE to copy directories.
@param[in] Resp The response to the overwrite query (if always).
@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
**/
);
/**
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
**/
)
{
SourceHandle = NULL;
DestHandle = NULL;
// Why bother copying a file to itself
return (SHELL_SUCCESS);
}
//
// Open destination file without create
//
//
// close file
//
if (DestHandle != NULL) {
DestHandle = NULL;
}
//
// if the destination file existed check response and possibly prompt user
//
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);
//
// indicate to stop everything
//
return (SHELL_ABORTED);
case ShellPromptResponseAll:
case ShellPromptResponseYes:
break;
default:
return SHELL_ABORTED;
}
}
}
return (SHELL_ACCESS_DENIED);
}
//
// Now copy all the files under the directory...
//
Size = 0;
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);
return (SHELL_ACCESS_DENIED);
}
//
// open source file
//
//
// copy data between files
//
}
}
//
// close files
//
if (DestHandle != NULL) {
DestHandle = NULL;
}
if (SourceHandle != NULL) {
SourceHandle = NULL;
}
//
// return
//
return (SHELL_SUCCESS);
}
/**
function to take a list of files to copy and a destination location and do
the verification and copying of those files to that location. This function
will report any errors to the user and halt.
The key is to have this function called ONLY once. this allows for the parameter
verification to happen correctly.
@param[in] FileList A LIST_ENTRY* based list of files to move.
@param[in] DestDir The destination location.
@param[in] SilentMode TRUE to eliminate screen output.
@param[in] RecursiveMode TRUE to copy directories.
@param[in] Resp The response to the overwrite query (if always).
@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
**/
)
{
} else {
}
PathLen = 0;
//
// We already verified that this was present.
//
//
// If we are trying to copy multiple files... make sure we got a directory for the target...
//
if (EFI_ERROR(ShellIsDirectory(DestDir)) && FileList->Link.ForwardLink != FileList->Link.BackLink) {
//
// Error for destination not a directory
//
return (SHELL_INVALID_PARAMETER);
}
){
//
// skip the directory traversing stuff...
//
continue;
}
}
//
// Make sure got -r if required
//
return (SHELL_INVALID_PARAMETER);
}
//
// make sure got dest as dir if needed
//
//
// Error for destination not a directory
//
return (SHELL_INVALID_PARAMETER);
}
}
return (SHELL_OUT_OF_RESOURCES);
}
//
// Go through the list of files to copy...
//
){
if (ShellGetExecutionBreakFlag()) {
break;
}
//
// skip the directory traversing stuff...
//
continue;
}
) {
//
// simple copy of a single file
//
}
} else {
}
} else {
//
// we have multiple files or a directory in the DestDir
//
//
// Check for leading slash
//
if (DestDir[0] == L'\\') {
//
// Copy to the root of CWD
//
while (PathRemoveLastItem(DestPath));
}
}
} else {
}
}
}
//
// Make sure the path exists
//
break;
}
){
break;
}
break;
}
) {
break;
}
//
// copy single file...
//
if (ShellStatus != SHELL_SUCCESS) {
break;
}
}
}
}
return (ShellStatus);
}
/**
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.
**/
)
{
ShellStatus = ValidateAndCopyFiles(FileList, ((EFI_SHELL_FILE_INFO *)List->Link.ForwardLink)->FullName, SilentMode, RecursiveMode, NULL);
} else {
}
} else {
}
return (ShellStatus);
}
{L"-r", TypeFlag},
{L"-q", TypeFlag},
};
/**
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).
**/
)
{
ProblemParam = NULL;
ParamCount = 0;
//
// initialize the shell lib (we must be in non-auto-init...)
//
Status = ShellInitialize();
Status = CommandInit();
//
// parse the command line
//
} else {
}
} else {
//
// check for "-?"
//
}
//
// Initialize SilentMode and RecursiveMode
//
if (gEfiShellProtocol->BatchIsActive()) {
SilentMode = TRUE;
} else {
}
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 {
}
}
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);
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_FILE_NF), gShellLevel2HiiHandle, ShellCommandLineGetRawValue(Package, LoopCounter));
}
}
if (ShellStatus != SHELL_SUCCESS) {
} else {
//
// now copy them all...
//
ShellStatus = ProcessValidateAndCopyFiles(FileList, PathCleanUpDirectories((CHAR16*)ShellCommandLineGetRawValue(Package, ParamCount)), SilentMode, RecursiveMode);
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_ERR_FILE), gShellLevel2HiiHandle, ShellCommandLineGetRawValue(Package, ParamCount), ShellStatus|MAX_BIT);
}
}
}
break;
} // switch on parameter count
}
//
// free the command line package
//
}
if (ShellGetExecutionBreakFlag()) {
return (SHELL_ABORTED);
}
return (ShellStatus);
}