ShellPkg: Apply uncrustify changes

REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3737

Apply uncrustify changes to .c/.h files in the ShellPkg package

Cc: Andrew Fish <afish@apple.com>
Cc: Leif Lindholm <leif@nuviainc.com>
Cc: Michael D Kinney <michael.d.kinney@intel.com>
Signed-off-by: Michael Kubacki <michael.kubacki@microsoft.com>
Reviewed-by: Ray Ni <ray.ni@intel.com>
This commit is contained in:
Michael Kubacki
2021-12-05 14:54:13 -08:00
committed by mergify[bot]
parent c411b485b6
commit 47d20b54f9
211 changed files with 30269 additions and 27004 deletions

View File

@ -9,19 +9,19 @@
#include "UefiShellLevel2CommandsLib.h"
STATIC CONST CHAR16 AllFiles[] = L"*";
STATIC CONST CHAR16 AllFiles[] = L"*";
STATIC CONST SHELL_PARAM_ITEM AttribParamList[] = {
{L"-a", TypeFlag},
{L"+a", TypeFlag},
{L"-s", TypeFlag},
{L"+s", TypeFlag},
{L"-h", TypeFlag},
{L"+h", TypeFlag},
{L"-r", TypeFlag},
{L"+r", TypeFlag},
{NULL, TypeMax}
};
STATIC CONST SHELL_PARAM_ITEM AttribParamList[] = {
{ L"-a", TypeFlag },
{ L"+a", TypeFlag },
{ L"-s", TypeFlag },
{ L"+s", TypeFlag },
{ L"-h", TypeFlag },
{ L"+h", TypeFlag },
{ L"-r", TypeFlag },
{ L"+r", TypeFlag },
{ NULL, TypeMax }
};
/**
Function for 'attrib' command.
@ -36,127 +36,137 @@ ShellCommandRunAttrib (
IN EFI_SYSTEM_TABLE *SystemTable
)
{
UINT64 FileAttributesToAdd;
UINT64 FileAttributesToRemove;
EFI_STATUS Status;
LIST_ENTRY *Package;
CHAR16 *ProblemParam;
SHELL_STATUS ShellStatus;
UINTN ParamNumberCount;
CONST CHAR16 *FileName;
EFI_SHELL_FILE_INFO *ListOfFiles;
EFI_SHELL_FILE_INFO *FileNode;
EFI_FILE_INFO *FileInfo;
UINT64 FileAttributesToAdd;
UINT64 FileAttributesToRemove;
EFI_STATUS Status;
LIST_ENTRY *Package;
CHAR16 *ProblemParam;
SHELL_STATUS ShellStatus;
UINTN ParamNumberCount;
CONST CHAR16 *FileName;
EFI_SHELL_FILE_INFO *ListOfFiles;
EFI_SHELL_FILE_INFO *FileNode;
EFI_FILE_INFO *FileInfo;
ListOfFiles = NULL;
ShellStatus = SHELL_SUCCESS;
ProblemParam = NULL;
ListOfFiles = NULL;
ShellStatus = SHELL_SUCCESS;
ProblemParam = NULL;
//
// initialize the shell lib (we must be in non-auto-init...)
//
Status = ShellInitialize();
ASSERT_EFI_ERROR(Status);
Status = ShellInitialize ();
ASSERT_EFI_ERROR (Status);
//
// parse the command line
//
Status = ShellCommandLineParse (AttribParamList, &Package, &ProblemParam, TRUE);
if (EFI_ERROR(Status)) {
if (Status == EFI_VOLUME_CORRUPTED && ProblemParam != NULL) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellLevel2HiiHandle, L"attrib", ProblemParam);
FreePool(ProblemParam);
if (EFI_ERROR (Status)) {
if ((Status == EFI_VOLUME_CORRUPTED) && (ProblemParam != NULL)) {
ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellLevel2HiiHandle, L"attrib", ProblemParam);
FreePool (ProblemParam);
ShellStatus = SHELL_INVALID_PARAMETER;
} else {
ASSERT(FALSE);
ASSERT (FALSE);
}
} else {
//
// check for "-?"
//
if (ShellCommandLineGetFlag(Package, L"-?")) {
ASSERT(FALSE);
if (ShellCommandLineGetFlag (Package, L"-?")) {
ASSERT (FALSE);
} else {
FileAttributesToAdd = 0;
FileAttributesToAdd = 0;
FileAttributesToRemove = 0;
//
// apply or remove each flag
//
if (ShellCommandLineGetFlag(Package, L"+a")) {
if (ShellCommandLineGetFlag (Package, L"+a")) {
FileAttributesToAdd |= EFI_FILE_ARCHIVE;
}
if (ShellCommandLineGetFlag(Package, L"-a")) {
if (ShellCommandLineGetFlag (Package, L"-a")) {
FileAttributesToRemove |= EFI_FILE_ARCHIVE;
}
if (ShellCommandLineGetFlag(Package, L"+s")) {
if (ShellCommandLineGetFlag (Package, L"+s")) {
FileAttributesToAdd |= EFI_FILE_SYSTEM;
}
if (ShellCommandLineGetFlag(Package, L"-s")) {
if (ShellCommandLineGetFlag (Package, L"-s")) {
FileAttributesToRemove |= EFI_FILE_SYSTEM;
}
if (ShellCommandLineGetFlag(Package, L"+h")) {
if (ShellCommandLineGetFlag (Package, L"+h")) {
FileAttributesToAdd |= EFI_FILE_HIDDEN;
}
if (ShellCommandLineGetFlag(Package, L"-h")) {
if (ShellCommandLineGetFlag (Package, L"-h")) {
FileAttributesToRemove |= EFI_FILE_HIDDEN;
}
if (ShellCommandLineGetFlag(Package, L"+r")) {
if (ShellCommandLineGetFlag (Package, L"+r")) {
FileAttributesToAdd |= EFI_FILE_READ_ONLY;
}
if (ShellCommandLineGetFlag(Package, L"-r")) {
if (ShellCommandLineGetFlag (Package, L"-r")) {
FileAttributesToRemove |= EFI_FILE_READ_ONLY;
}
if (FileAttributesToRemove == 0 && FileAttributesToAdd == 0) {
if ((FileAttributesToRemove == 0) && (FileAttributesToAdd == 0)) {
//
// Do display as we have no attributes to change
//
for ( ParamNumberCount = 1
;
; ParamNumberCount++
){
FileName = ShellCommandLineGetRawValue(Package, ParamNumberCount);
;
; ParamNumberCount++
)
{
FileName = ShellCommandLineGetRawValue (Package, ParamNumberCount);
// if we dont have anything left, move on...
if (FileName == NULL && ParamNumberCount == 1) {
FileName = (CHAR16*)AllFiles;
if ((FileName == NULL) && (ParamNumberCount == 1)) {
FileName = (CHAR16 *)AllFiles;
} else if (FileName == NULL) {
break;
}
ASSERT(ListOfFiles == NULL);
Status = ShellOpenFileMetaArg((CHAR16*)FileName, EFI_FILE_MODE_READ, &ListOfFiles);
if (EFI_ERROR(Status)) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_FILE_OPEN_FAIL), gShellLevel2HiiHandle, L"attrib", ShellCommandLineGetRawValue(Package, ParamNumberCount));
ASSERT (ListOfFiles == NULL);
Status = ShellOpenFileMetaArg ((CHAR16 *)FileName, EFI_FILE_MODE_READ, &ListOfFiles);
if (EFI_ERROR (Status)) {
ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_FILE_OPEN_FAIL), gShellLevel2HiiHandle, L"attrib", ShellCommandLineGetRawValue (Package, ParamNumberCount));
ShellStatus = SHELL_NOT_FOUND;
} else {
for (FileNode = (EFI_SHELL_FILE_INFO*)GetFirstNode(&ListOfFiles->Link)
; !IsNull(&ListOfFiles->Link, &FileNode->Link)
; FileNode = (EFI_SHELL_FILE_INFO*)GetNextNode(&ListOfFiles->Link, &FileNode->Link)
){
ShellPrintHiiEx(
for (FileNode = (EFI_SHELL_FILE_INFO *)GetFirstNode (&ListOfFiles->Link)
; !IsNull (&ListOfFiles->Link, &FileNode->Link)
; FileNode = (EFI_SHELL_FILE_INFO *)GetNextNode (&ListOfFiles->Link, &FileNode->Link)
)
{
ShellPrintHiiEx (
-1,
-1,
NULL,
STRING_TOKEN (STR_ATTRIB_OUTPUT_LINE),
gShellLevel2HiiHandle,
FileNode->Info->Attribute&EFI_FILE_DIRECTORY? L'D':L' ',
FileNode->Info->Attribute&EFI_FILE_ARCHIVE? L'A':L' ',
FileNode->Info->Attribute&EFI_FILE_SYSTEM? L'S':L' ',
FileNode->Info->Attribute&EFI_FILE_HIDDEN? L'H':L' ',
FileNode->Info->Attribute&EFI_FILE_READ_ONLY? L'R':L' ',
FileNode->Info->Attribute&EFI_FILE_DIRECTORY ? L'D' : L' ',
FileNode->Info->Attribute&EFI_FILE_ARCHIVE ? L'A' : L' ',
FileNode->Info->Attribute&EFI_FILE_SYSTEM ? L'S' : L' ',
FileNode->Info->Attribute&EFI_FILE_HIDDEN ? L'H' : L' ',
FileNode->Info->Attribute&EFI_FILE_READ_ONLY ? L'R' : L' ',
FileNode->FileName
);
);
if (ShellGetExecutionBreakFlag()) {
ShellStatus = SHELL_ABORTED;
break;
if (ShellGetExecutionBreakFlag ()) {
ShellStatus = SHELL_ABORTED;
break;
}
}
Status = ShellCloseFileMetaArg(&ListOfFiles);
Status = ShellCloseFileMetaArg (&ListOfFiles);
ListOfFiles = NULL;
if (EFI_ERROR(Status)) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_FILE_CLOSE_FAIL), gShellLevel2HiiHandle, L"attrib", ShellCommandLineGetRawValue(Package, ParamNumberCount));
if (EFI_ERROR (Status)) {
ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_FILE_CLOSE_FAIL), gShellLevel2HiiHandle, L"attrib", ShellCommandLineGetRawValue (Package, ParamNumberCount));
ShellStatus = SHELL_NOT_FOUND;
}
} // for loop for handling wildcard filenames
@ -165,26 +175,28 @@ ShellCommandRunAttrib (
//
// fail as we have conflcting params.
//
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PARAM_CON), gShellLevel2HiiHandle, L"attrib");
ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_PARAM_CON), gShellLevel2HiiHandle, L"attrib");
ShellStatus = SHELL_INVALID_PARAMETER;
} else {
//
// enumerate through all the files/directories and apply the attributes
//
for ( ParamNumberCount = 1
;
; ParamNumberCount++
){
FileName = ShellCommandLineGetRawValue(Package, ParamNumberCount);
;
; ParamNumberCount++
)
{
FileName = ShellCommandLineGetRawValue (Package, ParamNumberCount);
// if we dont have anything left, move on...
if (FileName == NULL) {
//
// make sure we are not failing on the first one we do... if yes that's an error...
//
if (ParamNumberCount == 1) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_FEW), gShellLevel2HiiHandle, L"attrib");
ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_FEW), gShellLevel2HiiHandle, L"attrib");
ShellStatus = SHELL_INVALID_PARAMETER;
}
break;
}
@ -196,24 +208,25 @@ ShellCommandRunAttrib (
//
// Open the file(s)
//
ASSERT(ListOfFiles == NULL);
Status = ShellOpenFileMetaArg((CHAR16*)FileName, EFI_FILE_MODE_READ, &ListOfFiles);
if (EFI_ERROR(Status)) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_FILE_OPEN_FAIL), gShellLevel2HiiHandle, L"attrib", ShellCommandLineGetRawValue(Package, ParamNumberCount));
ASSERT (ListOfFiles == NULL);
Status = ShellOpenFileMetaArg ((CHAR16 *)FileName, EFI_FILE_MODE_READ, &ListOfFiles);
if (EFI_ERROR (Status)) {
ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_FILE_OPEN_FAIL), gShellLevel2HiiHandle, L"attrib", ShellCommandLineGetRawValue (Package, ParamNumberCount));
ShellStatus = SHELL_NOT_FOUND;
} else {
for (FileNode = (EFI_SHELL_FILE_INFO*)GetFirstNode(&ListOfFiles->Link)
; !IsNull(&ListOfFiles->Link, &FileNode->Link)
; FileNode = (EFI_SHELL_FILE_INFO*)GetNextNode(&ListOfFiles->Link, &FileNode->Link)
){
for (FileNode = (EFI_SHELL_FILE_INFO *)GetFirstNode (&ListOfFiles->Link)
; !IsNull (&ListOfFiles->Link, &FileNode->Link)
; FileNode = (EFI_SHELL_FILE_INFO *)GetNextNode (&ListOfFiles->Link, &FileNode->Link)
)
{
//
// skip the directory traversing stuff...
//
if (StrCmp(FileNode->FileName, L".") == 0 || StrCmp(FileNode->FileName, L"..") == 0) {
if ((StrCmp (FileNode->FileName, L".") == 0) || (StrCmp (FileNode->FileName, L"..") == 0)) {
continue;
}
FileInfo = gEfiShellProtocol->GetFileInfo(FileNode->Handle);
FileInfo = gEfiShellProtocol->GetFileInfo (FileNode->Handle);
//
// if we are removing Read-Only we need to do that alone
@ -223,9 +236,9 @@ ShellCommandRunAttrib (
//
// SetFileInfo
//
Status = ShellSetFileInfo(FileNode->Handle, FileInfo);
if (EFI_ERROR(Status)) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_FILE_AD), gShellLevel2HiiHandle, L"attrib", ShellCommandLineGetRawValue(Package, ParamNumberCount));
Status = ShellSetFileInfo (FileNode->Handle, FileInfo);
if (EFI_ERROR (Status)) {
ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_FILE_AD), gShellLevel2HiiHandle, L"attrib", ShellCommandLineGetRawValue (Package, ParamNumberCount));
ShellStatus = SHELL_ACCESS_DENIED;
}
}
@ -239,18 +252,19 @@ ShellCommandRunAttrib (
//
// SetFileInfo
//
Status = ShellSetFileInfo(FileNode->Handle, FileInfo);
if (EFI_ERROR(Status)) {;
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_FILE_AD), gShellLevel2HiiHandle, L"attrib", ShellCommandLineGetRawValue(Package, ParamNumberCount));
Status = ShellSetFileInfo (FileNode->Handle, FileInfo);
if (EFI_ERROR (Status)) {
ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_FILE_AD), gShellLevel2HiiHandle, L"attrib", ShellCommandLineGetRawValue (Package, ParamNumberCount));
ShellStatus = SHELL_ACCESS_DENIED;
}
SHELL_FREE_NON_NULL(FileInfo);
SHELL_FREE_NON_NULL (FileInfo);
}
Status = ShellCloseFileMetaArg(&ListOfFiles);
Status = ShellCloseFileMetaArg (&ListOfFiles);
ListOfFiles = NULL;
if (EFI_ERROR(Status)) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_FILE_CLOSE_FAIL), gShellLevel2HiiHandle, L"attrib", ShellCommandLineGetRawValue(Package, ParamNumberCount));
if (EFI_ERROR (Status)) {
ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_FILE_CLOSE_FAIL), gShellLevel2HiiHandle, L"attrib", ShellCommandLineGetRawValue (Package, ParamNumberCount));
ShellStatus = SHELL_NOT_FOUND;
}
} // for loop for handling wildcard filenames

View File

@ -31,33 +31,33 @@ ReplaceDriveWithCwd (
IN CONST CHAR16 *Cwd
)
{
CHAR16 *Splitter;
CHAR16 *TempBuffer;
UINTN TotalSize;
CHAR16 *Splitter;
CHAR16 *TempBuffer;
UINTN TotalSize;
Splitter = NULL;
TempBuffer = NULL;
TotalSize = 0;
if (FullPath == NULL || *FullPath == NULL) {
if ((FullPath == NULL) || (*FullPath == NULL)) {
return EFI_SUCCESS;
}
Splitter = StrStr (*FullPath, L":");
ASSERT(Splitter != *FullPath);
ASSERT (Splitter != *FullPath);
if (Splitter != NULL && *(Splitter + 1) != L'\\' && *(Splitter + 1) != L'/') {
TotalSize = StrSize (Cwd) + StrSize (Splitter + 1);
if ((Splitter != NULL) && (*(Splitter + 1) != L'\\') && (*(Splitter + 1) != L'/')) {
TotalSize = StrSize (Cwd) + StrSize (Splitter + 1);
TempBuffer = AllocateZeroPool (TotalSize);
if (TempBuffer == NULL) {
return EFI_OUT_OF_RESOURCES;
}
StrCpyS (TempBuffer, TotalSize / sizeof(CHAR16), Cwd);
StrCatS (TempBuffer, TotalSize / sizeof(CHAR16), L"\\");
StrCatS (TempBuffer, TotalSize / sizeof(CHAR16), Splitter + 1);
StrCpyS (TempBuffer, TotalSize / sizeof (CHAR16), Cwd);
StrCatS (TempBuffer, TotalSize / sizeof (CHAR16), L"\\");
StrCatS (TempBuffer, TotalSize / sizeof (CHAR16), Splitter + 1);
FreePool(*FullPath);
FreePool (*FullPath);
*FullPath = TempBuffer;
}
@ -75,17 +75,17 @@ ReplaceDriveWithCwd (
**/
BOOLEAN
IsCurrentFileSystem (
IN CONST CHAR16 *FullPath,
IN CONST CHAR16 *Cwd
IN CONST CHAR16 *FullPath,
IN CONST CHAR16 *Cwd
)
{
CHAR16 *Splitter1;
CHAR16 *Splitter2;
CHAR16 *Splitter1;
CHAR16 *Splitter2;
Splitter1 = NULL;
Splitter2 = NULL;
ASSERT(FullPath != NULL);
ASSERT (FullPath != NULL);
Splitter1 = StrStr (FullPath, L":");
if (Splitter1 == NULL) {
@ -94,10 +94,10 @@ IsCurrentFileSystem (
Splitter2 = StrStr (Cwd, L":");
if (((UINTN) Splitter1 - (UINTN) FullPath) != ((UINTN) Splitter2 - (UINTN) Cwd)) {
if (((UINTN)Splitter1 - (UINTN)FullPath) != ((UINTN)Splitter2 - (UINTN)Cwd)) {
return FALSE;
} else {
if (StrniCmp (FullPath, Cwd, ((UINTN) Splitter1 - (UINTN) FullPath) / sizeof (CHAR16)) == 0) {
if (StrniCmp (FullPath, Cwd, ((UINTN)Splitter1 - (UINTN)FullPath) / sizeof (CHAR16)) == 0) {
return TRUE;
} else {
return FALSE;
@ -119,12 +119,12 @@ IsCurrentFileSystem (
**/
EFI_STATUS
ExtractDriveAndPath (
IN CONST CHAR16 *FullPath,
OUT CHAR16 **Drive,
OUT CHAR16 **Path
IN CONST CHAR16 *FullPath,
OUT CHAR16 **Drive,
OUT CHAR16 **Path
)
{
CHAR16 *Splitter;
CHAR16 *Splitter;
ASSERT (FullPath != NULL);
@ -132,22 +132,23 @@ ExtractDriveAndPath (
if (Splitter == NULL) {
*Drive = NULL;
*Path = AllocateCopyPool (StrSize (FullPath), FullPath);
*Path = AllocateCopyPool (StrSize (FullPath), FullPath);
if (*Path == NULL) {
return EFI_OUT_OF_RESOURCES;
}
} else {
if (*(Splitter + 1) == CHAR_NULL) {
*Drive = AllocateCopyPool (StrSize (FullPath), FullPath);
*Path = NULL;
*Path = NULL;
if (*Drive == NULL) {
return EFI_OUT_OF_RESOURCES;
}
} else {
*Drive = AllocateCopyPool ((Splitter - FullPath + 2) * sizeof(CHAR16), FullPath);
*Drive = AllocateCopyPool ((Splitter - FullPath + 2) * sizeof (CHAR16), FullPath);
if (*Drive == NULL) {
return EFI_OUT_OF_RESOURCES;
}
(*Drive)[Splitter - FullPath + 1] = CHAR_NULL;
*Path = AllocateCopyPool (StrSize (Splitter + 1), Splitter + 1);
@ -174,59 +175,59 @@ ShellCommandRunCd (
IN EFI_SYSTEM_TABLE *SystemTable
)
{
EFI_STATUS Status;
LIST_ENTRY *Package;
CONST CHAR16 *Cwd;
CHAR16 *Path;
CHAR16 *Drive;
CHAR16 *ProblemParam;
SHELL_STATUS ShellStatus;
CONST CHAR16 *Param1;
CHAR16 *Param1Copy;
CHAR16 *Walker;
CHAR16 *Splitter;
CHAR16 *TempBuffer;
UINTN TotalSize;
EFI_STATUS Status;
LIST_ENTRY *Package;
CONST CHAR16 *Cwd;
CHAR16 *Path;
CHAR16 *Drive;
CHAR16 *ProblemParam;
SHELL_STATUS ShellStatus;
CONST CHAR16 *Param1;
CHAR16 *Param1Copy;
CHAR16 *Walker;
CHAR16 *Splitter;
CHAR16 *TempBuffer;
UINTN TotalSize;
ProblemParam = NULL;
ShellStatus = SHELL_SUCCESS;
Cwd = NULL;
Path = NULL;
Drive = NULL;
Splitter = NULL;
TempBuffer = NULL;
TotalSize = 0;
ProblemParam = NULL;
ShellStatus = SHELL_SUCCESS;
Cwd = NULL;
Path = NULL;
Drive = NULL;
Splitter = NULL;
TempBuffer = NULL;
TotalSize = 0;
Status = CommandInit();
ASSERT_EFI_ERROR(Status);
Status = CommandInit ();
ASSERT_EFI_ERROR (Status);
//
// initialize the shell lib (we must be in non-auto-init...)
//
Status = ShellInitialize();
ASSERT_EFI_ERROR(Status);
Status = ShellInitialize ();
ASSERT_EFI_ERROR (Status);
//
// parse the command line
//
Status = ShellCommandLineParse (EmptyParamList, &Package, &ProblemParam, TRUE);
if (EFI_ERROR(Status)) {
if (Status == EFI_VOLUME_CORRUPTED && ProblemParam != NULL) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellLevel2HiiHandle, L"cd", ProblemParam);
FreePool(ProblemParam);
if (EFI_ERROR (Status)) {
if ((Status == EFI_VOLUME_CORRUPTED) && (ProblemParam != NULL)) {
ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellLevel2HiiHandle, L"cd", ProblemParam);
FreePool (ProblemParam);
ShellStatus = SHELL_INVALID_PARAMETER;
} else {
ASSERT(FALSE);
ASSERT (FALSE);
}
}
//
// check for "-?"
//
if (ShellCommandLineGetFlag(Package, L"-?")) {
ASSERT(FALSE);
} else if (ShellCommandLineGetRawValue(Package, 2) != NULL) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_MANY), gShellLevel2HiiHandle, L"cd");
if (ShellCommandLineGetFlag (Package, L"-?")) {
ASSERT (FALSE);
} else if (ShellCommandLineGetRawValue (Package, 2) != NULL) {
ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_MANY), gShellLevel2HiiHandle, L"cd");
ShellStatus = SHELL_INVALID_PARAMETER;
} else {
//
@ -237,7 +238,7 @@ ShellCommandRunCd (
//
Cwd = ShellGetCurrentDir (NULL);
if (Cwd == NULL) {
ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN(STR_GEN_NO_CWD), gShellLevel2HiiHandle, L"cd");
ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_NO_CWD), gShellLevel2HiiHandle, L"cd");
ShellStatus = SHELL_NOT_FOUND;
} else {
Param1 = ShellCommandLineGetRawValue (Package, 1);
@ -245,17 +246,17 @@ ShellCommandRunCd (
//
// display the current directory
//
ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN(STR_CD_PRINT), gShellLevel2HiiHandle, Cwd);
ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_CD_PRINT), gShellLevel2HiiHandle, Cwd);
} else {
Param1Copy = CatSPrint (NULL, L"%s", Param1, NULL);
for (Walker = Param1Copy; Walker != NULL && *Walker != CHAR_NULL; Walker++) {
if (*Walker == L'\"') {
CopyMem (Walker, Walker + 1, StrSize(Walker) - sizeof(Walker[0]));
CopyMem (Walker, Walker + 1, StrSize (Walker) - sizeof (Walker[0]));
}
}
if (Param1Copy != NULL && IsCurrentFileSystem (Param1Copy, Cwd)) {
Status = ReplaceDriveWithCwd (&Param1Copy,Cwd);
if ((Param1Copy != NULL) && IsCurrentFileSystem (Param1Copy, Cwd)) {
Status = ReplaceDriveWithCwd (&Param1Copy, Cwd);
} else {
//
// Can't use cd command to change filesystem.
@ -264,27 +265,27 @@ ShellCommandRunCd (
Status = EFI_NOT_FOUND;
}
if (!EFI_ERROR(Status) && Param1Copy != NULL) {
if (!EFI_ERROR (Status) && (Param1Copy != NULL)) {
Splitter = StrStr (Cwd, L":");
if (Param1Copy[0] == L'\\') {
//
// Absolute Path on current drive letter.
//
TotalSize = ((Splitter - Cwd + 1) * sizeof(CHAR16)) + StrSize(Param1Copy);
TotalSize = ((Splitter - Cwd + 1) * sizeof (CHAR16)) + StrSize (Param1Copy);
TempBuffer = AllocateZeroPool (TotalSize);
if (TempBuffer == NULL) {
Status = EFI_OUT_OF_RESOURCES;
} else {
StrnCpyS (TempBuffer, TotalSize / sizeof(CHAR16), Cwd, (Splitter - Cwd + 1));
StrCatS (TempBuffer, TotalSize / sizeof(CHAR16), Param1Copy);
StrnCpyS (TempBuffer, TotalSize / sizeof (CHAR16), Cwd, (Splitter - Cwd + 1));
StrCatS (TempBuffer, TotalSize / sizeof (CHAR16), Param1Copy);
FreePool (Param1Copy);
Param1Copy = TempBuffer;
TempBuffer = NULL;
}
} else {
if (StrStr (Param1Copy,L":") == NULL) {
TotalSize = StrSize (Cwd) + StrSize (Param1Copy);
if (StrStr (Param1Copy, L":") == NULL) {
TotalSize = StrSize (Cwd) + StrSize (Param1Copy);
TempBuffer = AllocateZeroPool (TotalSize);
if (TempBuffer == NULL) {
Status = EFI_OUT_OF_RESOURCES;
@ -301,19 +302,19 @@ ShellCommandRunCd (
}
}
if (!EFI_ERROR(Status)) {
if (!EFI_ERROR (Status)) {
Param1Copy = PathCleanUpDirectories (Param1Copy);
Status = ExtractDriveAndPath (Param1Copy, &Drive, &Path);
Status = ExtractDriveAndPath (Param1Copy, &Drive, &Path);
}
if (!EFI_ERROR (Status) && Drive != NULL && Path != NULL) {
if (EFI_ERROR(ShellIsDirectory (Param1Copy))) {
ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN(STR_GEN_NOT_DIR), gShellLevel2HiiHandle, L"cd", Param1Copy);
if (!EFI_ERROR (Status) && (Drive != NULL) && (Path != NULL)) {
if (EFI_ERROR (ShellIsDirectory (Param1Copy))) {
ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_NOT_DIR), gShellLevel2HiiHandle, L"cd", Param1Copy);
ShellStatus = SHELL_NOT_FOUND;
} else {
Status = gEfiShellProtocol->SetCurDir (Drive, Path + 1);
if (EFI_ERROR (Status)) {
ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN(STR_GEN_DIR_NF), gShellLevel2HiiHandle, L"cd", Param1Copy);
ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_DIR_NF), gShellLevel2HiiHandle, L"cd", Param1Copy);
ShellStatus = SHELL_NOT_FOUND;
}
}
@ -342,4 +343,3 @@ ShellCommandRunCd (
//
return (ShellStatus);
}

View File

@ -29,7 +29,7 @@
@retval SHELL_OUT_OF_RESOURCES a memory allocation failed
**/
SHELL_STATUS
ValidateAndCopyFiles(
ValidateAndCopyFiles (
IN CONST EFI_SHELL_FILE_INFO *FileList,
IN CONST CHAR16 *DestDir,
IN BOOLEAN SilentMode,
@ -51,12 +51,12 @@ ValidateAndCopyFiles(
@retval SHELL_SUCCESS The source file was copied to the destination
**/
SHELL_STATUS
CopySingleFile(
IN CONST CHAR16 *Source,
IN CONST CHAR16 *Dest,
OUT VOID **Resp,
IN BOOLEAN SilentMode,
IN CONST CHAR16 *CmdName
CopySingleFile (
IN CONST CHAR16 *Source,
IN CONST CHAR16 *Dest,
OUT VOID **Resp,
IN BOOLEAN SilentMode,
IN CONST CHAR16 *CmdName
)
{
VOID *Response;
@ -75,28 +75,29 @@ CopySingleFile(
EFI_FILE_SYSTEM_INFO *DestVolumeInfo;
UINTN DestVolumeInfoSize;
ASSERT(Resp != NULL);
ASSERT (Resp != NULL);
SourceHandle = NULL;
DestHandle = NULL;
Response = *Resp;
List = NULL;
DestVolumeInfo = NULL;
ShellStatus = SHELL_SUCCESS;
SourceHandle = NULL;
DestHandle = NULL;
Response = *Resp;
List = NULL;
DestVolumeInfo = NULL;
ShellStatus = SHELL_SUCCESS;
ReadSize = PcdGet32(PcdShellFileOperationSize);
ReadSize = PcdGet32 (PcdShellFileOperationSize);
// Why bother copying a file to itself
if (StrCmp(Source, Dest) == 0) {
if (StrCmp (Source, Dest) == 0) {
return (SHELL_SUCCESS);
}
//
// if the destination file existed check response and possibly prompt user
//
if (ShellFileExists(Dest) == EFI_SUCCESS) {
if (Response == NULL && !SilentMode) {
Status = ShellPromptForResponseHii(ShellPromptResponseTypeYesNoAllCancel, STRING_TOKEN (STR_GEN_DEST_EXIST_OVR), gShellLevel2HiiHandle, &Response);
if (ShellFileExists (Dest) == EFI_SUCCESS) {
if ((Response == NULL) && !SilentMode) {
Status = ShellPromptForResponseHii (ShellPromptResponseTypeYesNoAllCancel, STRING_TOKEN (STR_GEN_DEST_EXIST_OVR), gShellLevel2HiiHandle, &Response);
}
//
// possibly return based on response
//
@ -104,7 +105,8 @@ CopySingleFile(
if (Response == NULL) {
return SHELL_ABORTED;
}
switch (*(SHELL_PROMPT_RESPONSE*)Response) {
switch (*(SHELL_PROMPT_RESPONSE *)Response) {
case ShellPromptResponseNo:
//
// return success here so we dont stop the process
@ -126,39 +128,39 @@ CopySingleFile(
}
}
if (ShellIsDirectory(Source) == EFI_SUCCESS) {
Status = ShellCreateDirectory(Dest, &DestHandle);
if (EFI_ERROR(Status)) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_CP_DEST_DIR_FAIL), gShellLevel2HiiHandle, CmdName, Dest);
if (ShellIsDirectory (Source) == EFI_SUCCESS) {
Status = ShellCreateDirectory (Dest, &DestHandle);
if (EFI_ERROR (Status)) {
ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_CP_DEST_DIR_FAIL), gShellLevel2HiiHandle, CmdName, Dest);
return (SHELL_ACCESS_DENIED);
}
//
// Now copy all the files under the directory...
//
TempName = NULL;
Size = 0;
StrnCatGrow(&TempName, &Size, Source, 0);
StrnCatGrow(&TempName, &Size, L"\\*", 0);
TempName = NULL;
Size = 0;
StrnCatGrow (&TempName, &Size, Source, 0);
StrnCatGrow (&TempName, &Size, L"\\*", 0);
if (TempName != NULL) {
ShellOpenFileMetaArg((CHAR16*)TempName, EFI_FILE_MODE_READ, &List);
ShellOpenFileMetaArg ((CHAR16 *)TempName, EFI_FILE_MODE_READ, &List);
*TempName = CHAR_NULL;
StrnCatGrow(&TempName, &Size, Dest, 0);
StrnCatGrow(&TempName, &Size, L"\\", 0);
ShellStatus = ValidateAndCopyFiles(List, TempName, SilentMode, TRUE, Resp);
ShellCloseFileMetaArg(&List);
SHELL_FREE_NON_NULL(TempName);
StrnCatGrow (&TempName, &Size, Dest, 0);
StrnCatGrow (&TempName, &Size, L"\\", 0);
ShellStatus = ValidateAndCopyFiles (List, TempName, SilentMode, TRUE, Resp);
ShellCloseFileMetaArg (&List);
SHELL_FREE_NON_NULL (TempName);
Size = 0;
}
} else {
Status = ShellDeleteFileByName(Dest);
Status = ShellDeleteFileByName (Dest);
//
// open file with create enabled
//
Status = ShellOpenFileByName(Dest, &DestHandle, EFI_FILE_MODE_READ|EFI_FILE_MODE_WRITE|EFI_FILE_MODE_CREATE, 0);
if (EFI_ERROR(Status)) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_CP_DEST_OPEN_FAIL), gShellLevel2HiiHandle, CmdName, Dest);
Status = ShellOpenFileByName (Dest, &DestHandle, EFI_FILE_MODE_READ|EFI_FILE_MODE_WRITE|EFI_FILE_MODE_CREATE, 0);
if (EFI_ERROR (Status)) {
ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_CP_DEST_OPEN_FAIL), gShellLevel2HiiHandle, CmdName, Dest);
return (SHELL_ACCESS_DENIED);
}
@ -172,90 +174,93 @@ CopySingleFile(
}
//
//get file size of source file and freespace available on destination volume
// get file size of source file and freespace available on destination volume
//
ShellGetFileSize(SourceHandle, &SourceFileSize);
ShellGetFileSize(DestHandle, &DestFileSize);
ShellGetFileSize (SourceHandle, &SourceFileSize);
ShellGetFileSize (DestHandle, &DestFileSize);
//
//if the destination file already exists then it will be replaced, meaning the sourcefile effectively needs less storage space
// if the destination file already exists then it will be replaced, meaning the sourcefile effectively needs less storage space
//
if(DestFileSize < SourceFileSize){
if (DestFileSize < SourceFileSize) {
SourceFileSize -= DestFileSize;
} else {
SourceFileSize = 0;
}
//
//get the system volume info to check the free space
// get the system volume info to check the free space
//
DestVolumeFP = ConvertShellHandleToEfiFileProtocol(DestHandle);
DestVolumeInfo = NULL;
DestVolumeFP = ConvertShellHandleToEfiFileProtocol (DestHandle);
DestVolumeInfo = NULL;
DestVolumeInfoSize = 0;
Status = DestVolumeFP->GetInfo(
DestVolumeFP,
&gEfiFileSystemInfoGuid,
&DestVolumeInfoSize,
DestVolumeInfo
);
Status = DestVolumeFP->GetInfo (
DestVolumeFP,
&gEfiFileSystemInfoGuid,
&DestVolumeInfoSize,
DestVolumeInfo
);
if (Status == EFI_BUFFER_TOO_SMALL) {
DestVolumeInfo = AllocateZeroPool(DestVolumeInfoSize);
Status = DestVolumeFP->GetInfo(
DestVolumeFP,
&gEfiFileSystemInfoGuid,
&DestVolumeInfoSize,
DestVolumeInfo
);
DestVolumeInfo = AllocateZeroPool (DestVolumeInfoSize);
Status = DestVolumeFP->GetInfo (
DestVolumeFP,
&gEfiFileSystemInfoGuid,
&DestVolumeInfoSize,
DestVolumeInfo
);
}
//
//check if enough space available on destination drive to complete copy
// check if enough space available on destination drive to complete copy
//
if (DestVolumeInfo!= NULL && (DestVolumeInfo->FreeSpace < SourceFileSize)) {
if ((DestVolumeInfo != NULL) && (DestVolumeInfo->FreeSpace < SourceFileSize)) {
//
//not enough space on destination directory to copy file
// not enough space on destination directory to copy file
//
SHELL_FREE_NON_NULL(DestVolumeInfo);
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_CPY_FAIL), gShellLevel2HiiHandle, CmdName);
return(SHELL_VOLUME_FULL);
SHELL_FREE_NON_NULL (DestVolumeInfo);
ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_CPY_FAIL), gShellLevel2HiiHandle, CmdName);
return (SHELL_VOLUME_FULL);
} else {
//
// copy data between files
//
Buffer = AllocateZeroPool(ReadSize);
Buffer = AllocateZeroPool (ReadSize);
if (Buffer == NULL) {
ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_OUT_MEM), gShellLevel2HiiHandle, CmdName);
return SHELL_OUT_OF_RESOURCES;
}
while (ReadSize == PcdGet32(PcdShellFileOperationSize) && !EFI_ERROR(Status)) {
Status = ShellReadFile(SourceHandle, &ReadSize, Buffer);
if (!EFI_ERROR(Status)) {
Status = ShellWriteFile(DestHandle, &ReadSize, Buffer);
if (EFI_ERROR(Status)) {
ShellStatus = (SHELL_STATUS) (Status & (~MAX_BIT));
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_CPY_WRITE_ERROR), gShellLevel2HiiHandle, CmdName, Dest);
while (ReadSize == PcdGet32 (PcdShellFileOperationSize) && !EFI_ERROR (Status)) {
Status = ShellReadFile (SourceHandle, &ReadSize, Buffer);
if (!EFI_ERROR (Status)) {
Status = ShellWriteFile (DestHandle, &ReadSize, Buffer);
if (EFI_ERROR (Status)) {
ShellStatus = (SHELL_STATUS)(Status & (~MAX_BIT));
ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_CPY_WRITE_ERROR), gShellLevel2HiiHandle, CmdName, Dest);
break;
}
} else {
ShellStatus = (SHELL_STATUS) (Status & (~MAX_BIT));
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_CPY_READ_ERROR), gShellLevel2HiiHandle, CmdName, Source);
ShellStatus = (SHELL_STATUS)(Status & (~MAX_BIT));
ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_CPY_READ_ERROR), gShellLevel2HiiHandle, CmdName, Source);
break;
}
}
}
SHELL_FREE_NON_NULL(DestVolumeInfo);
SHELL_FREE_NON_NULL (DestVolumeInfo);
}
//
// close files
//
if (DestHandle != NULL) {
ShellCloseFile(&DestHandle);
DestHandle = NULL;
ShellCloseFile (&DestHandle);
DestHandle = NULL;
}
if (SourceHandle != NULL) {
ShellCloseFile(&SourceHandle);
ShellCloseFile (&SourceHandle);
SourceHandle = NULL;
}
@ -286,7 +291,7 @@ CopySingleFile(
@retval SHELL_OUT_OF_RESOURCES a memory allocation failed
**/
SHELL_STATUS
ValidateAndCopyFiles(
ValidateAndCopyFiles (
IN CONST EFI_SHELL_FILE_INFO *FileList,
IN CONST CHAR16 *DestDir,
IN BOOLEAN SilentMode,
@ -294,17 +299,17 @@ ValidateAndCopyFiles(
IN VOID **Resp
)
{
CHAR16 *HiiOutput;
CHAR16 *HiiResultOk;
CONST EFI_SHELL_FILE_INFO *Node;
SHELL_STATUS ShellStatus;
EFI_STATUS Status;
CHAR16 *DestPath;
VOID *Response;
UINTN PathSize;
CONST CHAR16 *Cwd;
UINTN NewSize;
CHAR16 *CleanFilePathStr;
CHAR16 *HiiOutput;
CHAR16 *HiiResultOk;
CONST EFI_SHELL_FILE_INFO *Node;
SHELL_STATUS ShellStatus;
EFI_STATUS Status;
CHAR16 *DestPath;
VOID *Response;
UINTN PathSize;
CONST CHAR16 *Cwd;
UINTN NewSize;
CHAR16 *CleanFilePathStr;
if (Resp == NULL) {
Response = NULL;
@ -315,12 +320,11 @@ ValidateAndCopyFiles(
DestPath = NULL;
ShellStatus = SHELL_SUCCESS;
PathSize = 0;
Cwd = ShellGetCurrentDir(NULL);
Cwd = ShellGetCurrentDir (NULL);
CleanFilePathStr = NULL;
ASSERT(FileList != NULL);
ASSERT(DestDir != NULL);
ASSERT (FileList != NULL);
ASSERT (DestDir != NULL);
Status = ShellLevel2StripQuotes (DestDir, &CleanFilePathStr);
if (EFI_ERROR (Status)) {
@ -336,28 +340,30 @@ ValidateAndCopyFiles(
//
// If we are trying to copy multiple files... make sure we got a directory for the target...
//
if (EFI_ERROR(ShellIsDirectory(CleanFilePathStr)) && FileList->Link.ForwardLink != FileList->Link.BackLink) {
if (EFI_ERROR (ShellIsDirectory (CleanFilePathStr)) && (FileList->Link.ForwardLink != FileList->Link.BackLink)) {
//
// Error for destination not a directory
//
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_NOT_DIR), gShellLevel2HiiHandle, L"cp", CleanFilePathStr);
ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_NOT_DIR), gShellLevel2HiiHandle, L"cp", CleanFilePathStr);
FreePool (CleanFilePathStr);
return (SHELL_INVALID_PARAMETER);
}
for (Node = (EFI_SHELL_FILE_INFO *)GetFirstNode(&FileList->Link)
; !IsNull(&FileList->Link, &Node->Link)
; Node = (EFI_SHELL_FILE_INFO *)GetNextNode(&FileList->Link, &Node->Link)
){
for (Node = (EFI_SHELL_FILE_INFO *)GetFirstNode (&FileList->Link)
; !IsNull (&FileList->Link, &Node->Link)
; Node = (EFI_SHELL_FILE_INFO *)GetNextNode (&FileList->Link, &Node->Link)
)
{
//
// skip the directory traversing stuff...
//
if (StrCmp(Node->FileName, L".") == 0 || StrCmp(Node->FileName, L"..") == 0) {
if ((StrCmp (Node->FileName, L".") == 0) || (StrCmp (Node->FileName, L"..") == 0)) {
continue;
}
NewSize = StrSize(CleanFilePathStr);
NewSize += StrSize(Node->FullName);
NewSize += (Cwd == NULL)? 0 : (StrSize(Cwd) + sizeof(CHAR16));
NewSize = StrSize (CleanFilePathStr);
NewSize += StrSize (Node->FullName);
NewSize += (Cwd == NULL) ? 0 : (StrSize (Cwd) + sizeof (CHAR16));
if (NewSize > PathSize) {
PathSize = NewSize;
}
@ -365,8 +371,8 @@ ValidateAndCopyFiles(
//
// Make sure got -r if required
//
if (!RecursiveMode && !EFI_ERROR(ShellIsDirectory(Node->FullName))) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_CP_DIR_REQ), gShellLevel2HiiHandle, L"cp");
if (!RecursiveMode && !EFI_ERROR (ShellIsDirectory (Node->FullName))) {
ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_CP_DIR_REQ), gShellLevel2HiiHandle, L"cp");
FreePool (CleanFilePathStr);
return (SHELL_INVALID_PARAMETER);
}
@ -374,11 +380,11 @@ ValidateAndCopyFiles(
//
// make sure got dest as dir if needed
//
if (!EFI_ERROR(ShellIsDirectory(Node->FullName)) && EFI_ERROR(ShellIsDirectory(CleanFilePathStr))) {
if (!EFI_ERROR (ShellIsDirectory (Node->FullName)) && EFI_ERROR (ShellIsDirectory (CleanFilePathStr))) {
//
// Error for destination not a directory
//
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_NOT_DIR), gShellLevel2HiiHandle, L"cp", CleanFilePathStr);
ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_NOT_DIR), gShellLevel2HiiHandle, L"cp", CleanFilePathStr);
FreePool (CleanFilePathStr);
return (SHELL_INVALID_PARAMETER);
}
@ -386,12 +392,12 @@ ValidateAndCopyFiles(
HiiOutput = HiiGetString (gShellLevel2HiiHandle, STRING_TOKEN (STR_CP_OUTPUT), NULL);
HiiResultOk = HiiGetString (gShellLevel2HiiHandle, STRING_TOKEN (STR_GEN_RES_OK), NULL);
DestPath = AllocateZeroPool(PathSize);
DestPath = AllocateZeroPool (PathSize);
if (DestPath == NULL || HiiOutput == NULL || HiiResultOk == NULL) {
SHELL_FREE_NON_NULL(DestPath);
SHELL_FREE_NON_NULL(HiiOutput);
SHELL_FREE_NON_NULL(HiiResultOk);
if ((DestPath == NULL) || (HiiOutput == NULL) || (HiiResultOk == NULL)) {
SHELL_FREE_NON_NULL (DestPath);
SHELL_FREE_NON_NULL (HiiOutput);
SHELL_FREE_NON_NULL (HiiResultOk);
FreePool (CleanFilePathStr);
return (SHELL_OUT_OF_RESOURCES);
}
@ -399,46 +405,51 @@ ValidateAndCopyFiles(
//
// Go through the list of files to copy...
//
for (Node = (EFI_SHELL_FILE_INFO *)GetFirstNode(&FileList->Link)
; !IsNull(&FileList->Link, &Node->Link)
; Node = (EFI_SHELL_FILE_INFO *)GetNextNode(&FileList->Link, &Node->Link)
){
if (ShellGetExecutionBreakFlag()) {
for (Node = (EFI_SHELL_FILE_INFO *)GetFirstNode (&FileList->Link)
; !IsNull (&FileList->Link, &Node->Link)
; Node = (EFI_SHELL_FILE_INFO *)GetNextNode (&FileList->Link, &Node->Link)
)
{
if (ShellGetExecutionBreakFlag ()) {
break;
}
ASSERT(Node->FileName != NULL);
ASSERT(Node->FullName != NULL);
ASSERT (Node->FileName != NULL);
ASSERT (Node->FullName != NULL);
//
// skip the directory traversing stuff...
//
if (StrCmp(Node->FileName, L".") == 0 || StrCmp(Node->FileName, L"..") == 0) {
if ((StrCmp (Node->FileName, L".") == 0) || (StrCmp (Node->FileName, L"..") == 0)) {
continue;
}
if (FileList->Link.ForwardLink == FileList->Link.BackLink // 1 item
&& EFI_ERROR(ShellIsDirectory(CleanFilePathStr)) // not an existing directory
) {
if (StrStr(CleanFilePathStr, L":") == NULL) {
if ( (FileList->Link.ForwardLink == FileList->Link.BackLink) // 1 item
&& EFI_ERROR (ShellIsDirectory (CleanFilePathStr)) // not an existing directory
)
{
if (StrStr (CleanFilePathStr, L":") == NULL) {
//
// simple copy of a single file
//
if (Cwd != NULL) {
StrCpyS(DestPath, PathSize / sizeof(CHAR16), Cwd);
StrCatS(DestPath, PathSize / sizeof(CHAR16), L"\\");
StrCpyS (DestPath, PathSize / sizeof (CHAR16), Cwd);
StrCatS (DestPath, PathSize / sizeof (CHAR16), L"\\");
} else {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_DIR_NF), gShellLevel2HiiHandle, L"cp", CleanFilePathStr);
ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_DIR_NF), gShellLevel2HiiHandle, L"cp", CleanFilePathStr);
FreePool (CleanFilePathStr);
return (SHELL_INVALID_PARAMETER);
}
if (DestPath[StrLen(DestPath)-1] != L'\\' && CleanFilePathStr[0] != L'\\') {
StrCatS(DestPath, PathSize / sizeof(CHAR16), L"\\");
} else if (DestPath[StrLen(DestPath)-1] == L'\\' && CleanFilePathStr[0] == L'\\') {
((CHAR16*)DestPath)[StrLen(DestPath)-1] = CHAR_NULL;
if ((DestPath[StrLen (DestPath)-1] != L'\\') && (CleanFilePathStr[0] != L'\\')) {
StrCatS (DestPath, PathSize / sizeof (CHAR16), L"\\");
} else if ((DestPath[StrLen (DestPath)-1] == L'\\') && (CleanFilePathStr[0] == L'\\')) {
((CHAR16 *)DestPath)[StrLen (DestPath)-1] = CHAR_NULL;
}
StrCatS(DestPath, PathSize/sizeof(CHAR16), CleanFilePathStr);
StrCatS (DestPath, PathSize/sizeof (CHAR16), CleanFilePathStr);
} else {
StrCpyS(DestPath, PathSize/sizeof(CHAR16), CleanFilePathStr);
StrCpyS (DestPath, PathSize/sizeof (CHAR16), CleanFilePathStr);
}
} else {
//
@ -449,112 +460,121 @@ ValidateAndCopyFiles(
// Check for leading slash
//
if (CleanFilePathStr[0] == L'\\') {
//
// Copy to the root of CWD
//
//
// Copy to the root of CWD
//
if (Cwd != NULL) {
StrCpyS(DestPath, PathSize/sizeof(CHAR16), Cwd);
StrCatS(DestPath, PathSize/sizeof(CHAR16), L"\\");
StrCpyS (DestPath, PathSize/sizeof (CHAR16), Cwd);
StrCatS (DestPath, PathSize/sizeof (CHAR16), L"\\");
} else {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_DIR_NF), gShellLevel2HiiHandle, L"cp", CleanFilePathStr);
FreePool(CleanFilePathStr);
ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_DIR_NF), gShellLevel2HiiHandle, L"cp", CleanFilePathStr);
FreePool (CleanFilePathStr);
return (SHELL_INVALID_PARAMETER);
}
while (PathRemoveLastItem(DestPath));
StrCatS(DestPath, PathSize/sizeof(CHAR16), CleanFilePathStr+1);
StrCatS(DestPath, PathSize/sizeof(CHAR16), Node->FileName);
} else if (StrStr(CleanFilePathStr, L":") == NULL) {
if (Cwd != NULL) {
StrCpyS(DestPath, PathSize/sizeof(CHAR16), Cwd);
StrCatS(DestPath, PathSize/sizeof(CHAR16), L"\\");
} else {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_DIR_NF), gShellLevel2HiiHandle, L"cp", CleanFilePathStr);
FreePool(CleanFilePathStr);
return (SHELL_INVALID_PARAMETER);
}
if (DestPath[StrLen(DestPath)-1] != L'\\' && CleanFilePathStr[0] != L'\\') {
StrCatS(DestPath, PathSize/sizeof(CHAR16), L"\\");
} else if (DestPath[StrLen(DestPath)-1] == L'\\' && CleanFilePathStr[0] == L'\\') {
((CHAR16*)DestPath)[StrLen(DestPath)-1] = CHAR_NULL;
}
StrCatS(DestPath, PathSize/sizeof(CHAR16), CleanFilePathStr);
if (CleanFilePathStr[StrLen(CleanFilePathStr)-1] != L'\\' && Node->FileName[0] != L'\\') {
StrCatS(DestPath, PathSize/sizeof(CHAR16), L"\\");
} else if (CleanFilePathStr[StrLen(CleanFilePathStr)-1] == L'\\' && Node->FileName[0] == L'\\') {
((CHAR16*)DestPath)[StrLen(DestPath)-1] = CHAR_NULL;
}
StrCatS(DestPath, PathSize/sizeof(CHAR16), Node->FileName);
} else {
StrCpyS(DestPath, PathSize/sizeof(CHAR16), CleanFilePathStr);
if (CleanFilePathStr[StrLen(CleanFilePathStr)-1] != L'\\' && Node->FileName[0] != L'\\') {
StrCatS(DestPath, PathSize/sizeof(CHAR16), L"\\");
} else if (CleanFilePathStr[StrLen(CleanFilePathStr)-1] == L'\\' && Node->FileName[0] == L'\\') {
((CHAR16*)CleanFilePathStr)[StrLen(CleanFilePathStr)-1] = CHAR_NULL;
while (PathRemoveLastItem (DestPath)) {
}
StrCatS(DestPath, PathSize/sizeof(CHAR16), Node->FileName);
StrCatS (DestPath, PathSize/sizeof (CHAR16), CleanFilePathStr+1);
StrCatS (DestPath, PathSize/sizeof (CHAR16), Node->FileName);
} else if (StrStr (CleanFilePathStr, L":") == NULL) {
if (Cwd != NULL) {
StrCpyS (DestPath, PathSize/sizeof (CHAR16), Cwd);
StrCatS (DestPath, PathSize/sizeof (CHAR16), L"\\");
} else {
ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_DIR_NF), gShellLevel2HiiHandle, L"cp", CleanFilePathStr);
FreePool (CleanFilePathStr);
return (SHELL_INVALID_PARAMETER);
}
if ((DestPath[StrLen (DestPath)-1] != L'\\') && (CleanFilePathStr[0] != L'\\')) {
StrCatS (DestPath, PathSize/sizeof (CHAR16), L"\\");
} else if ((DestPath[StrLen (DestPath)-1] == L'\\') && (CleanFilePathStr[0] == L'\\')) {
((CHAR16 *)DestPath)[StrLen (DestPath)-1] = CHAR_NULL;
}
StrCatS (DestPath, PathSize/sizeof (CHAR16), CleanFilePathStr);
if ((CleanFilePathStr[StrLen (CleanFilePathStr)-1] != L'\\') && (Node->FileName[0] != L'\\')) {
StrCatS (DestPath, PathSize/sizeof (CHAR16), L"\\");
} else if ((CleanFilePathStr[StrLen (CleanFilePathStr)-1] == L'\\') && (Node->FileName[0] == L'\\')) {
((CHAR16 *)DestPath)[StrLen (DestPath)-1] = CHAR_NULL;
}
StrCatS (DestPath, PathSize/sizeof (CHAR16), Node->FileName);
} else {
StrCpyS (DestPath, PathSize/sizeof (CHAR16), CleanFilePathStr);
if ((CleanFilePathStr[StrLen (CleanFilePathStr)-1] != L'\\') && (Node->FileName[0] != L'\\')) {
StrCatS (DestPath, PathSize/sizeof (CHAR16), L"\\");
} else if ((CleanFilePathStr[StrLen (CleanFilePathStr)-1] == L'\\') && (Node->FileName[0] == L'\\')) {
((CHAR16 *)CleanFilePathStr)[StrLen (CleanFilePathStr)-1] = CHAR_NULL;
}
StrCatS (DestPath, PathSize/sizeof (CHAR16), Node->FileName);
}
}
//
// Make sure the path exists
//
if (EFI_ERROR(VerifyIntermediateDirectories(DestPath))) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_CP_DIR_WNF), gShellLevel2HiiHandle, L"cp", DestPath);
if (EFI_ERROR (VerifyIntermediateDirectories (DestPath))) {
ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_CP_DIR_WNF), gShellLevel2HiiHandle, L"cp", DestPath);
ShellStatus = SHELL_DEVICE_ERROR;
break;
}
if ( !EFI_ERROR(ShellIsDirectory(Node->FullName))
&& !EFI_ERROR(ShellIsDirectory(DestPath))
&& StrniCmp(Node->FullName, DestPath, StrLen(DestPath)) == 0
){
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_CP_SD_PARENT), gShellLevel2HiiHandle, L"cp");
ShellStatus = SHELL_INVALID_PARAMETER;
break;
}
if (StringNoCaseCompare(&Node->FullName, &DestPath) == 0) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_CP_SD_SAME), gShellLevel2HiiHandle, L"cp");
if ( !EFI_ERROR (ShellIsDirectory (Node->FullName))
&& !EFI_ERROR (ShellIsDirectory (DestPath))
&& (StrniCmp (Node->FullName, DestPath, StrLen (DestPath)) == 0)
)
{
ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_CP_SD_PARENT), gShellLevel2HiiHandle, L"cp");
ShellStatus = SHELL_INVALID_PARAMETER;
break;
}
if ((StrniCmp(Node->FullName, DestPath, StrLen(Node->FullName)) == 0)
&& (DestPath[StrLen(Node->FullName)] == CHAR_NULL || DestPath[StrLen(Node->FullName)] == L'\\')
) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_CP_SD_SAME), gShellLevel2HiiHandle, L"cp");
if (StringNoCaseCompare (&Node->FullName, &DestPath) == 0) {
ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_CP_SD_SAME), gShellLevel2HiiHandle, L"cp");
ShellStatus = SHELL_INVALID_PARAMETER;
break;
}
PathCleanUpDirectories(DestPath);
if ( (StrniCmp (Node->FullName, DestPath, StrLen (Node->FullName)) == 0)
&& ((DestPath[StrLen (Node->FullName)] == CHAR_NULL) || (DestPath[StrLen (Node->FullName)] == L'\\'))
)
{
ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_CP_SD_SAME), gShellLevel2HiiHandle, L"cp");
ShellStatus = SHELL_INVALID_PARAMETER;
break;
}
PathCleanUpDirectories (DestPath);
if (!SilentMode) {
ShellPrintEx(-1, -1, HiiOutput, Node->FullName, DestPath);
ShellPrintEx (-1, -1, HiiOutput, Node->FullName, DestPath);
}
//
// copy single file...
//
ShellStatus = CopySingleFile(Node->FullName, DestPath, &Response, SilentMode, L"cp");
ShellStatus = CopySingleFile (Node->FullName, DestPath, &Response, SilentMode, L"cp");
if (ShellStatus != SHELL_SUCCESS) {
break;
}
}
if (ShellStatus == SHELL_SUCCESS && Resp == NULL) {
ShellPrintEx(-1, -1, L"%s", HiiResultOk);
if ((ShellStatus == SHELL_SUCCESS) && (Resp == NULL)) {
ShellPrintEx (-1, -1, L"%s", HiiResultOk);
}
SHELL_FREE_NON_NULL(DestPath);
SHELL_FREE_NON_NULL(HiiOutput);
SHELL_FREE_NON_NULL(HiiResultOk);
SHELL_FREE_NON_NULL(CleanFilePathStr);
SHELL_FREE_NON_NULL (DestPath);
SHELL_FREE_NON_NULL (HiiOutput);
SHELL_FREE_NON_NULL (HiiResultOk);
SHELL_FREE_NON_NULL (CleanFilePathStr);
if (Resp == NULL) {
SHELL_FREE_NON_NULL(Response);
SHELL_FREE_NON_NULL (Response);
}
return (ShellStatus);
}
/**
@ -570,55 +590,55 @@ ValidateAndCopyFiles(
@retval SHELL_SUCCESS The operation was successful.
**/
SHELL_STATUS
ProcessValidateAndCopyFiles(
ProcessValidateAndCopyFiles (
IN EFI_SHELL_FILE_INFO *FileList,
IN CONST CHAR16 *DestDir,
IN BOOLEAN SilentMode,
IN BOOLEAN RecursiveMode
)
{
SHELL_STATUS ShellStatus;
EFI_SHELL_FILE_INFO *List;
EFI_FILE_INFO *FileInfo;
CHAR16 *FullName;
SHELL_STATUS ShellStatus;
EFI_SHELL_FILE_INFO *List;
EFI_FILE_INFO *FileInfo;
CHAR16 *FullName;
List = NULL;
FullName = NULL;
FileInfo = NULL;
List = NULL;
FullName = NULL;
FileInfo = NULL;
ShellOpenFileMetaArg((CHAR16*)DestDir, EFI_FILE_MODE_READ, &List);
if (List != NULL && List->Link.ForwardLink != List->Link.BackLink) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_MARG_ERROR), gShellLevel2HiiHandle, L"cp", DestDir);
ShellOpenFileMetaArg ((CHAR16 *)DestDir, EFI_FILE_MODE_READ, &List);
if ((List != NULL) && (List->Link.ForwardLink != List->Link.BackLink)) {
ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_MARG_ERROR), gShellLevel2HiiHandle, L"cp", DestDir);
ShellStatus = SHELL_INVALID_PARAMETER;
ShellCloseFileMetaArg(&List);
ShellCloseFileMetaArg (&List);
} else if (List != NULL) {
ASSERT(((EFI_SHELL_FILE_INFO *)List->Link.ForwardLink) != NULL);
ASSERT(((EFI_SHELL_FILE_INFO *)List->Link.ForwardLink)->FullName != NULL);
FileInfo = gEfiShellProtocol->GetFileInfo(((EFI_SHELL_FILE_INFO *)List->Link.ForwardLink)->Handle);
ASSERT(FileInfo != NULL);
StrnCatGrow(&FullName, NULL, ((EFI_SHELL_FILE_INFO *)List->Link.ForwardLink)->FullName, 0);
ShellCloseFileMetaArg(&List);
ASSERT (((EFI_SHELL_FILE_INFO *)List->Link.ForwardLink) != NULL);
ASSERT (((EFI_SHELL_FILE_INFO *)List->Link.ForwardLink)->FullName != NULL);
FileInfo = gEfiShellProtocol->GetFileInfo (((EFI_SHELL_FILE_INFO *)List->Link.ForwardLink)->Handle);
ASSERT (FileInfo != NULL);
StrnCatGrow (&FullName, NULL, ((EFI_SHELL_FILE_INFO *)List->Link.ForwardLink)->FullName, 0);
ShellCloseFileMetaArg (&List);
if ((FileInfo->Attribute & EFI_FILE_READ_ONLY) == 0) {
ShellStatus = ValidateAndCopyFiles(FileList, FullName, SilentMode, RecursiveMode, NULL);
ShellStatus = ValidateAndCopyFiles (FileList, FullName, SilentMode, RecursiveMode, NULL);
} else {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_CP_DEST_ERROR), gShellLevel2HiiHandle, L"cp");
ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_CP_DEST_ERROR), gShellLevel2HiiHandle, L"cp");
ShellStatus = SHELL_ACCESS_DENIED;
}
} else {
ShellCloseFileMetaArg(&List);
ShellStatus = ValidateAndCopyFiles(FileList, DestDir, SilentMode, RecursiveMode, NULL);
ShellCloseFileMetaArg (&List);
ShellStatus = ValidateAndCopyFiles (FileList, DestDir, SilentMode, RecursiveMode, NULL);
}
SHELL_FREE_NON_NULL(FileInfo);
SHELL_FREE_NON_NULL(FullName);
SHELL_FREE_NON_NULL (FileInfo);
SHELL_FREE_NON_NULL (FullName);
return (ShellStatus);
}
STATIC CONST SHELL_PARAM_ITEM ParamList[] = {
{L"-r", TypeFlag},
{L"-q", TypeFlag},
{NULL, TypeMax}
};
STATIC CONST SHELL_PARAM_ITEM ParamList[] = {
{ L"-r", TypeFlag },
{ L"-q", TypeFlag },
{ NULL, TypeMax }
};
/**
Function for 'cp' command.
@ -633,86 +653,87 @@ ShellCommandRunCp (
IN EFI_SYSTEM_TABLE *SystemTable
)
{
EFI_STATUS Status;
LIST_ENTRY *Package;
CHAR16 *ProblemParam;
SHELL_STATUS ShellStatus;
UINTN ParamCount;
UINTN LoopCounter;
EFI_SHELL_FILE_INFO *FileList;
BOOLEAN SilentMode;
BOOLEAN RecursiveMode;
CONST CHAR16 *Cwd;
CHAR16 *FullCwd;
EFI_STATUS Status;
LIST_ENTRY *Package;
CHAR16 *ProblemParam;
SHELL_STATUS ShellStatus;
UINTN ParamCount;
UINTN LoopCounter;
EFI_SHELL_FILE_INFO *FileList;
BOOLEAN SilentMode;
BOOLEAN RecursiveMode;
CONST CHAR16 *Cwd;
CHAR16 *FullCwd;
ProblemParam = NULL;
ShellStatus = SHELL_SUCCESS;
ParamCount = 0;
FileList = NULL;
ProblemParam = NULL;
ShellStatus = SHELL_SUCCESS;
ParamCount = 0;
FileList = NULL;
//
// initialize the shell lib (we must be in non-auto-init...)
//
Status = ShellInitialize();
ASSERT_EFI_ERROR(Status);
Status = ShellInitialize ();
ASSERT_EFI_ERROR (Status);
Status = CommandInit();
ASSERT_EFI_ERROR(Status);
Status = CommandInit ();
ASSERT_EFI_ERROR (Status);
//
// parse the command line
//
Status = ShellCommandLineParse (ParamList, &Package, &ProblemParam, TRUE);
if (EFI_ERROR(Status)) {
if (Status == EFI_VOLUME_CORRUPTED && ProblemParam != NULL) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellLevel2HiiHandle, L"cp", ProblemParam);
FreePool(ProblemParam);
if (EFI_ERROR (Status)) {
if ((Status == EFI_VOLUME_CORRUPTED) && (ProblemParam != NULL)) {
ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellLevel2HiiHandle, L"cp", ProblemParam);
FreePool (ProblemParam);
ShellStatus = SHELL_INVALID_PARAMETER;
} else {
ASSERT(FALSE);
ASSERT (FALSE);
}
} else {
//
// check for "-?"
//
if (ShellCommandLineGetFlag(Package, L"-?")) {
ASSERT(FALSE);
if (ShellCommandLineGetFlag (Package, L"-?")) {
ASSERT (FALSE);
}
//
// Initialize SilentMode and RecursiveMode
//
if (gEfiShellProtocol->BatchIsActive()) {
if (gEfiShellProtocol->BatchIsActive ()) {
SilentMode = TRUE;
} else {
SilentMode = ShellCommandLineGetFlag(Package, L"-q");
SilentMode = ShellCommandLineGetFlag (Package, L"-q");
}
RecursiveMode = ShellCommandLineGetFlag(Package, L"-r");
switch (ParamCount = ShellCommandLineGetCount(Package)) {
RecursiveMode = ShellCommandLineGetFlag (Package, L"-r");
switch (ParamCount = ShellCommandLineGetCount (Package)) {
case 0:
case 1:
//
// we have insufficient parameters
//
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_FEW), gShellLevel2HiiHandle, L"cp");
ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_FEW), gShellLevel2HiiHandle, L"cp");
ShellStatus = SHELL_INVALID_PARAMETER;
break;
case 2:
//
// must have valid CWD for single parameter...
//
Cwd = ShellGetCurrentDir(NULL);
if (Cwd == NULL){
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_NO_CWD), gShellLevel2HiiHandle, L"cp");
Cwd = ShellGetCurrentDir (NULL);
if (Cwd == NULL) {
ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_NO_CWD), gShellLevel2HiiHandle, L"cp");
ShellStatus = SHELL_INVALID_PARAMETER;
} else {
Status = ShellOpenFileMetaArg((CHAR16*)ShellCommandLineGetRawValue(Package, 1), EFI_FILE_MODE_WRITE|EFI_FILE_MODE_READ, &FileList);
if (FileList == NULL || IsListEmpty(&FileList->Link) || EFI_ERROR(Status)) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_FILE_NF), gShellLevel2HiiHandle, L"cp", ShellCommandLineGetRawValue(Package, 1));
Status = ShellOpenFileMetaArg ((CHAR16 *)ShellCommandLineGetRawValue (Package, 1), EFI_FILE_MODE_WRITE|EFI_FILE_MODE_READ, &FileList);
if ((FileList == NULL) || IsListEmpty (&FileList->Link) || EFI_ERROR (Status)) {
ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_FILE_NF), gShellLevel2HiiHandle, L"cp", ShellCommandLineGetRawValue (Package, 1));
ShellStatus = SHELL_NOT_FOUND;
} else {
FullCwd = AllocateZeroPool(StrSize(Cwd) + sizeof(CHAR16));
} else {
FullCwd = AllocateZeroPool (StrSize (Cwd) + sizeof (CHAR16));
if (FullCwd == NULL) {
ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_OUT_MEM), gShellLevel2HiiHandle, L"cp");
ShellStatus = SHELL_OUT_OF_RESOURCES;
@ -729,36 +750,39 @@ ShellCommandRunCp (
//
// Make a big list of all the files...
//
for (ParamCount--, LoopCounter = 1 ; LoopCounter < ParamCount && ShellStatus == SHELL_SUCCESS ; LoopCounter++) {
if (ShellGetExecutionBreakFlag()) {
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);
if (EFI_ERROR(Status) || FileList == NULL || IsListEmpty(&FileList->Link)) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_FILE_NF), gShellLevel2HiiHandle, L"cp", ShellCommandLineGetRawValue(Package, LoopCounter));
Status = ShellOpenFileMetaArg ((CHAR16 *)ShellCommandLineGetRawValue (Package, LoopCounter), EFI_FILE_MODE_WRITE|EFI_FILE_MODE_READ, &FileList);
if (EFI_ERROR (Status) || (FileList == NULL) || IsListEmpty (&FileList->Link)) {
ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_FILE_NF), gShellLevel2HiiHandle, L"cp", ShellCommandLineGetRawValue (Package, LoopCounter));
ShellStatus = SHELL_NOT_FOUND;
}
}
if (ShellStatus != SHELL_SUCCESS) {
Status = ShellCloseFileMetaArg(&FileList);
Status = ShellCloseFileMetaArg (&FileList);
} else {
//
// now copy them all...
//
if (FileList != NULL && !IsListEmpty(&FileList->Link)) {
ShellStatus = ProcessValidateAndCopyFiles(FileList, PathCleanUpDirectories((CHAR16*)ShellCommandLineGetRawValue(Package, ParamCount)), SilentMode, RecursiveMode);
Status = ShellCloseFileMetaArg(&FileList);
if (EFI_ERROR(Status) && ShellStatus == SHELL_SUCCESS) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_ERR_FILE), gShellLevel2HiiHandle, L"cp", ShellCommandLineGetRawValue(Package, ParamCount), ShellStatus|MAX_BIT);
if ((FileList != NULL) && !IsListEmpty (&FileList->Link)) {
ShellStatus = ProcessValidateAndCopyFiles (FileList, PathCleanUpDirectories ((CHAR16 *)ShellCommandLineGetRawValue (Package, ParamCount)), SilentMode, RecursiveMode);
Status = ShellCloseFileMetaArg (&FileList);
if (EFI_ERROR (Status) && (ShellStatus == SHELL_SUCCESS)) {
ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_ERR_FILE), gShellLevel2HiiHandle, L"cp", ShellCommandLineGetRawValue (Package, ParamCount), ShellStatus|MAX_BIT);
ShellStatus = SHELL_ACCESS_DENIED;
}
}
}
break;
} // switch on parameter count
if (FileList != NULL) {
ShellCloseFileMetaArg(&FileList);
ShellCloseFileMetaArg (&FileList);
}
//
@ -767,10 +791,9 @@ ShellCommandRunCp (
ShellCommandLineFreeVarList (Package);
}
if (ShellGetExecutionBreakFlag()) {
if (ShellGetExecutionBreakFlag ()) {
return (SHELL_ABORTED);
}
return (ShellStatus);
}

View File

@ -12,6 +12,7 @@
// This function was from from the BdsLib implementation in
// IntelFrameworkModulePkg\Library\GenericBdsLib\BdsConnect.c
// function name: BdsLibConnectAllEfi
/**
This function will connect all current system handles recursively. The
connection will finish until every handle's child handle created if it have.
@ -37,7 +38,7 @@ ConnectAllEfi (
NULL,
&HandleCount,
&HandleBuffer
);
);
if (EFI_ERROR (Status)) {
return Status;
}
@ -67,51 +68,52 @@ ConnectAllEfi (
@retval EFI_OUT_OF_RESOURCES there was insufficient memory
**/
EFI_STATUS
LoadDriver(
LoadDriver (
IN CONST CHAR16 *FileName,
IN CONST BOOLEAN Connect
)
{
EFI_HANDLE LoadedDriverHandle;
EFI_STATUS Status;
EFI_DEVICE_PATH_PROTOCOL *FilePath;
EFI_LOADED_IMAGE_PROTOCOL *LoadedDriverImage;
EFI_HANDLE LoadedDriverHandle;
EFI_STATUS Status;
EFI_DEVICE_PATH_PROTOCOL *FilePath;
EFI_LOADED_IMAGE_PROTOCOL *LoadedDriverImage;
LoadedDriverImage = NULL;
FilePath = NULL;
LoadedDriverHandle = NULL;
Status = EFI_SUCCESS;
LoadedDriverImage = NULL;
FilePath = NULL;
LoadedDriverHandle = NULL;
Status = EFI_SUCCESS;
ASSERT (FileName != NULL);
//
// Fix local copies of the protocol pointers
//
Status = CommandInit();
ASSERT_EFI_ERROR(Status);
Status = CommandInit ();
ASSERT_EFI_ERROR (Status);
//
// Convert to DEVICE_PATH
//
FilePath = gEfiShellProtocol->GetDevicePathFromFilePath(FileName);
FilePath = gEfiShellProtocol->GetDevicePathFromFilePath (FileName);
if (FilePath == NULL) {
ASSERT(FALSE);
ASSERT (FALSE);
return (EFI_INVALID_PARAMETER);
}
//
// Use LoadImage to get it into memory
//
Status = gBS->LoadImage(
FALSE,
gImageHandle,
FilePath,
NULL,
0,
&LoadedDriverHandle);
Status = gBS->LoadImage (
FALSE,
gImageHandle,
FilePath,
NULL,
0,
&LoadedDriverHandle
);
if (EFI_ERROR(Status)) {
if (EFI_ERROR (Status)) {
//
// With EFI_SECURITY_VIOLATION retval, the Image was loaded and an ImageHandle was created
// with a valid EFI_LOADED_IMAGE_PROTOCOL, but the image can not be started right now.
@ -121,62 +123,64 @@ LoadDriver(
if (Status == EFI_SECURITY_VIOLATION) {
gBS->UnloadImage (LoadedDriverHandle);
}
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_LOAD_NOT_IMAGE), gShellLevel2HiiHandle, FileName, Status);
ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_LOAD_NOT_IMAGE), gShellLevel2HiiHandle, FileName, Status);
} else {
//
// Make sure it is a driver image
//
Status = gBS->HandleProtocol (LoadedDriverHandle, &gEfiLoadedImageProtocolGuid, (VOID *) &LoadedDriverImage);
Status = gBS->HandleProtocol (LoadedDriverHandle, &gEfiLoadedImageProtocolGuid, (VOID *)&LoadedDriverImage);
ASSERT (LoadedDriverImage != NULL);
if ( EFI_ERROR(Status)
|| ( LoadedDriverImage->ImageCodeType != EfiBootServicesCode
&& LoadedDriverImage->ImageCodeType != EfiRuntimeServicesCode)
){
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_LOAD_NOT_DRIVER), gShellLevel2HiiHandle, FileName);
if ( EFI_ERROR (Status)
|| ( (LoadedDriverImage->ImageCodeType != EfiBootServicesCode)
&& (LoadedDriverImage->ImageCodeType != EfiRuntimeServicesCode))
)
{
ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_LOAD_NOT_DRIVER), gShellLevel2HiiHandle, FileName);
//
// Exit and unload the non-driver image
//
gBS->Exit(LoadedDriverHandle, EFI_INVALID_PARAMETER, 0, NULL);
gBS->Exit (LoadedDriverHandle, EFI_INVALID_PARAMETER, 0, NULL);
Status = EFI_INVALID_PARAMETER;
}
}
if (!EFI_ERROR(Status)) {
if (!EFI_ERROR (Status)) {
//
// Start the image
//
Status = gBS->StartImage(LoadedDriverHandle, NULL, NULL);
if (EFI_ERROR(Status)) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_LOAD_ERROR), gShellLevel2HiiHandle, FileName, Status);
Status = gBS->StartImage (LoadedDriverHandle, NULL, NULL);
if (EFI_ERROR (Status)) {
ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_LOAD_ERROR), gShellLevel2HiiHandle, FileName, Status);
} else {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_LOAD_LOADED), gShellLevel2HiiHandle, FileName, LoadedDriverImage->ImageBase, Status);
ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_LOAD_LOADED), gShellLevel2HiiHandle, FileName, LoadedDriverImage->ImageBase, Status);
}
}
if (!EFI_ERROR(Status) && Connect) {
if (!EFI_ERROR (Status) && Connect) {
//
// Connect it...
//
Status = ConnectAllEfi();
Status = ConnectAllEfi ();
}
//
// clean up memory...
//
if (FilePath != NULL) {
FreePool(FilePath);
FreePool (FilePath);
}
return (Status);
}
STATIC CONST SHELL_PARAM_ITEM LoadParamList[] = {
{L"-nc", TypeFlag},
{NULL, TypeMax}
};
STATIC CONST SHELL_PARAM_ITEM LoadParamList[] = {
{ L"-nc", TypeFlag },
{ NULL, TypeMax }
};
/**
Function for 'load' command.
@ -191,78 +195,81 @@ ShellCommandRunLoad (
IN EFI_SYSTEM_TABLE *SystemTable
)
{
EFI_STATUS Status;
LIST_ENTRY *Package;
CHAR16 *ProblemParam;
SHELL_STATUS ShellStatus;
UINTN ParamCount;
EFI_SHELL_FILE_INFO *ListHead;
EFI_SHELL_FILE_INFO *Node;
EFI_STATUS Status;
LIST_ENTRY *Package;
CHAR16 *ProblemParam;
SHELL_STATUS ShellStatus;
UINTN ParamCount;
EFI_SHELL_FILE_INFO *ListHead;
EFI_SHELL_FILE_INFO *Node;
ListHead = NULL;
ProblemParam = NULL;
ShellStatus = SHELL_SUCCESS;
ListHead = NULL;
ProblemParam = NULL;
ShellStatus = SHELL_SUCCESS;
//
// initialize the shell lib (we must be in non-auto-init...)
//
Status = ShellInitialize();
ASSERT_EFI_ERROR(Status);
Status = ShellInitialize ();
ASSERT_EFI_ERROR (Status);
//
// parse the command line
//
Status = ShellCommandLineParse (LoadParamList, &Package, &ProblemParam, TRUE);
if (EFI_ERROR(Status)) {
if (Status == EFI_VOLUME_CORRUPTED && ProblemParam != NULL) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellLevel2HiiHandle, L"load", ProblemParam);
FreePool(ProblemParam);
if (EFI_ERROR (Status)) {
if ((Status == EFI_VOLUME_CORRUPTED) && (ProblemParam != NULL)) {
ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellLevel2HiiHandle, L"load", ProblemParam);
FreePool (ProblemParam);
ShellStatus = SHELL_INVALID_PARAMETER;
} else {
ASSERT(FALSE);
ASSERT (FALSE);
}
} else {
//
// check for "-?"
//
if (ShellCommandLineGetFlag(Package, L"-?")) {
ASSERT(FALSE);
} else if (ShellCommandLineGetRawValue(Package, 1) == NULL) {
if (ShellCommandLineGetFlag (Package, L"-?")) {
ASSERT (FALSE);
} else if (ShellCommandLineGetRawValue (Package, 1) == NULL) {
//
// we didnt get a single file to load parameter
//
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_FEW), gShellLevel2HiiHandle, L"load");
ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_FEW), gShellLevel2HiiHandle, L"load");
ShellStatus = SHELL_INVALID_PARAMETER;
} else {
for ( ParamCount = 1
; ShellCommandLineGetRawValue(Package, ParamCount) != NULL
; ParamCount++
){
Status = ShellOpenFileMetaArg((CHAR16*)ShellCommandLineGetRawValue(Package, ParamCount), EFI_FILE_MODE_READ, &ListHead);
if (!EFI_ERROR(Status)) {
for ( Node = (EFI_SHELL_FILE_INFO *)GetFirstNode(&ListHead->Link)
; !IsNull(&ListHead->Link, &Node->Link)
; Node = (EFI_SHELL_FILE_INFO *)GetNextNode(&ListHead->Link, &Node->Link)
){
; ShellCommandLineGetRawValue (Package, ParamCount) != NULL
; ParamCount++
)
{
Status = ShellOpenFileMetaArg ((CHAR16 *)ShellCommandLineGetRawValue (Package, ParamCount), EFI_FILE_MODE_READ, &ListHead);
if (!EFI_ERROR (Status)) {
for ( Node = (EFI_SHELL_FILE_INFO *)GetFirstNode (&ListHead->Link)
; !IsNull (&ListHead->Link, &Node->Link)
; Node = (EFI_SHELL_FILE_INFO *)GetNextNode (&ListHead->Link, &Node->Link)
)
{
//
// once we have an error preserve that value, but finish the loop.
//
if (EFI_ERROR(Status)) {
LoadDriver(Node->FullName, (BOOLEAN)(ShellCommandLineGetFlag(Package, L"-nc")==FALSE));
if (EFI_ERROR (Status)) {
LoadDriver (Node->FullName, (BOOLEAN)(ShellCommandLineGetFlag (Package, L"-nc") == FALSE));
} else {
Status = LoadDriver(Node->FullName, (BOOLEAN)(ShellCommandLineGetFlag(Package, L"-nc")==FALSE));
Status = LoadDriver (Node->FullName, (BOOLEAN)(ShellCommandLineGetFlag (Package, L"-nc") == FALSE));
}
} // for loop for multi-open
if (EFI_ERROR(Status)) {
ShellCloseFileMetaArg(&ListHead);
if (EFI_ERROR (Status)) {
ShellCloseFileMetaArg (&ListHead);
} else {
Status = ShellCloseFileMetaArg(&ListHead);;
Status = ShellCloseFileMetaArg (&ListHead);
}
} else {
//
// no files found.
//
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_FILE_NF), gShellLevel2HiiHandle, L"load", (CHAR16*)ShellCommandLineGetRawValue(Package, ParamCount));
ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_FILE_NF), gShellLevel2HiiHandle, L"load", (CHAR16 *)ShellCommandLineGetRawValue (Package, ParamCount));
ShellStatus = SHELL_NOT_FOUND;
}
} // for loop for params
@ -274,7 +281,7 @@ ShellCommandRunLoad (
ShellCommandLineFreeVarList (Package);
}
if (EFI_ERROR(Status) && ShellStatus == SHELL_SUCCESS) {
if (EFI_ERROR (Status) && (ShellStatus == SHELL_SUCCESS)) {
ShellStatus = SHELL_DEVICE_ERROR;
}

View File

@ -10,7 +10,7 @@
#include "UefiShellLevel2CommandsLib.h"
#include <Guid/FileSystemInfo.h>
UINTN mDayOfMonth[] = {31, 28, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30};
UINTN mDayOfMonth[] = { 31, 28, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30 };
/**
print out the standard format output volume entry.
@ -18,8 +18,8 @@ UINTN mDayOfMonth[] = {31, 28, 31, 30, 31, 30, 31, 30, 31, 30, 31, 30};
@param[in] TheList a list of files from the volume.
**/
EFI_STATUS
PrintSfoVolumeInfoTableEntry(
IN CONST EFI_SHELL_FILE_INFO *TheList
PrintSfoVolumeInfoTableEntry (
IN CONST EFI_SHELL_FILE_INFO *TheList
)
{
EFI_STATUS Status;
@ -33,77 +33,79 @@ PrintSfoVolumeInfoTableEntry(
//
// Get the first valid handle (directories)
//
for ( Node = (EFI_SHELL_FILE_INFO *)GetFirstNode(&TheList->Link)
; !IsNull(&TheList->Link, &Node->Link) && Node->Handle == NULL
; Node = (EFI_SHELL_FILE_INFO *)GetNextNode(&TheList->Link, &Node->Link)
);
for ( Node = (EFI_SHELL_FILE_INFO *)GetFirstNode (&TheList->Link)
; !IsNull (&TheList->Link, &Node->Link) && Node->Handle == NULL
; Node = (EFI_SHELL_FILE_INFO *)GetNextNode (&TheList->Link, &Node->Link)
)
{
}
if (Node->Handle == NULL) {
DirectoryName = GetFullyQualifiedPath(((EFI_SHELL_FILE_INFO *)GetFirstNode(&TheList->Link))->FullName);
DirectoryName = GetFullyQualifiedPath (((EFI_SHELL_FILE_INFO *)GetFirstNode (&TheList->Link))->FullName);
//
// We need to open something up to get system information
//
Status = gEfiShellProtocol->OpenFileByName(
DirectoryName,
&ShellFileHandle,
EFI_FILE_MODE_READ
);
Status = gEfiShellProtocol->OpenFileByName (
DirectoryName,
&ShellFileHandle,
EFI_FILE_MODE_READ
);
ASSERT_EFI_ERROR(Status);
FreePool(DirectoryName);
ASSERT_EFI_ERROR (Status);
FreePool (DirectoryName);
//
// Get the Volume Info from ShellFileHandle
//
SysInfo = NULL;
SysInfoSize = 0;
EfiFpHandle = ConvertShellHandleToEfiFileProtocol(ShellFileHandle);
Status = EfiFpHandle->GetInfo(
EfiFpHandle,
&gEfiFileSystemInfoGuid,
&SysInfoSize,
SysInfo
);
EfiFpHandle = ConvertShellHandleToEfiFileProtocol (ShellFileHandle);
Status = EfiFpHandle->GetInfo (
EfiFpHandle,
&gEfiFileSystemInfoGuid,
&SysInfoSize,
SysInfo
);
if (Status == EFI_BUFFER_TOO_SMALL) {
SysInfo = AllocateZeroPool(SysInfoSize);
Status = EfiFpHandle->GetInfo(
EfiFpHandle,
&gEfiFileSystemInfoGuid,
&SysInfoSize,
SysInfo
);
SysInfo = AllocateZeroPool (SysInfoSize);
Status = EfiFpHandle->GetInfo (
EfiFpHandle,
&gEfiFileSystemInfoGuid,
&SysInfoSize,
SysInfo
);
}
ASSERT_EFI_ERROR(Status);
ASSERT_EFI_ERROR (Status);
gEfiShellProtocol->CloseFile(ShellFileHandle);
gEfiShellProtocol->CloseFile (ShellFileHandle);
} else {
//
// Get the Volume Info from Node->Handle
//
SysInfo = NULL;
SysInfo = NULL;
SysInfoSize = 0;
EfiFpHandle = ConvertShellHandleToEfiFileProtocol(Node->Handle);
Status = EfiFpHandle->GetInfo(
EfiFpHandle,
&gEfiFileSystemInfoGuid,
&SysInfoSize,
SysInfo
);
EfiFpHandle = ConvertShellHandleToEfiFileProtocol (Node->Handle);
Status = EfiFpHandle->GetInfo (
EfiFpHandle,
&gEfiFileSystemInfoGuid,
&SysInfoSize,
SysInfo
);
if (Status == EFI_BUFFER_TOO_SMALL) {
SysInfo = AllocateZeroPool(SysInfoSize);
Status = EfiFpHandle->GetInfo(
EfiFpHandle,
&gEfiFileSystemInfoGuid,
&SysInfoSize,
SysInfo
);
SysInfo = AllocateZeroPool (SysInfoSize);
Status = EfiFpHandle->GetInfo (
EfiFpHandle,
&gEfiFileSystemInfoGuid,
&SysInfoSize,
SysInfo
);
}
ASSERT_EFI_ERROR(Status);
ASSERT_EFI_ERROR (Status);
}
ShellPrintHiiEx (
@ -117,7 +119,7 @@ PrintSfoVolumeInfoTableEntry(
//
// print VolumeInfo table
//
ASSERT(SysInfo != NULL);
ASSERT (SysInfo != NULL);
ShellPrintHiiEx (
0,
gST->ConOut->Mode->CursorRow,
@ -126,12 +128,12 @@ PrintSfoVolumeInfoTableEntry(
gShellLevel2HiiHandle,
SysInfo->VolumeLabel,
SysInfo->VolumeSize,
SysInfo->ReadOnly?L"TRUE":L"FALSE",
SysInfo->ReadOnly ? L"TRUE" : L"FALSE",
SysInfo->FreeSpace,
SysInfo->BlockSize
);
SHELL_FREE_NON_NULL(SysInfo);
SHELL_FREE_NON_NULL (SysInfo);
return (Status);
}
@ -147,7 +149,7 @@ PrintSfoVolumeInfoTableEntry(
**/
VOID
PrintFileInformation(
PrintFileInformation (
IN CONST BOOLEAN Sfo,
IN CONST EFI_SHELL_FILE_INFO *TheNode,
IN UINT64 *Files,
@ -155,10 +157,10 @@ PrintFileInformation(
IN UINT64 *Dirs
)
{
ASSERT(Files != NULL);
ASSERT(Size != NULL);
ASSERT(Dirs != NULL);
ASSERT(TheNode != NULL);
ASSERT (Files != NULL);
ASSERT (Size != NULL);
ASSERT (Dirs != NULL);
ASSERT (TheNode != NULL);
if (Sfo) {
//
@ -173,11 +175,11 @@ PrintFileInformation(
TheNode->FullName,
TheNode->Info->FileSize,
TheNode->Info->PhysicalSize,
(TheNode->Info->Attribute & EFI_FILE_ARCHIVE) != 0?L"a":L"",
(TheNode->Info->Attribute & EFI_FILE_DIRECTORY) != 0?L"d":L"",
(TheNode->Info->Attribute & EFI_FILE_HIDDEN) != 0?L"h":L"",
(TheNode->Info->Attribute & EFI_FILE_READ_ONLY) != 0?L"r":L"",
(TheNode->Info->Attribute & EFI_FILE_SYSTEM) != 0?L"s":L"",
(TheNode->Info->Attribute & EFI_FILE_ARCHIVE) != 0 ? L"a" : L"",
(TheNode->Info->Attribute & EFI_FILE_DIRECTORY) != 0 ? L"d" : L"",
(TheNode->Info->Attribute & EFI_FILE_HIDDEN) != 0 ? L"h" : L"",
(TheNode->Info->Attribute & EFI_FILE_READ_ONLY) != 0 ? L"r" : L"",
(TheNode->Info->Attribute & EFI_FILE_SYSTEM) != 0 ? L"s" : L"",
TheNode->Info->CreateTime.Hour,
TheNode->Info->CreateTime.Minute,
TheNode->Info->CreateTime.Second,
@ -209,8 +211,8 @@ PrintFileInformation(
STRING_TOKEN (STR_LS_LINE_START_ALL),
gShellLevel2HiiHandle,
&TheNode->Info->ModificationTime,
(TheNode->Info->Attribute & EFI_FILE_DIRECTORY) != 0?L"<DIR>":L"",
(TheNode->Info->Attribute & EFI_FILE_READ_ONLY) != 0?L'r':L' ',
(TheNode->Info->Attribute & EFI_FILE_DIRECTORY) != 0 ? L"<DIR>" : L"",
(TheNode->Info->Attribute & EFI_FILE_READ_ONLY) != 0 ? L'r' : L' ',
TheNode->Info->FileSize
);
if (TheNode->Info->Attribute & EFI_FILE_DIRECTORY) {
@ -226,9 +228,10 @@ PrintFileInformation(
} else {
(*Files)++;
(*Size) += TheNode->Info->FileSize;
if ( (gUnicodeCollation->StriColl(gUnicodeCollation, (CHAR16*)L".nsh", (CHAR16*)&(TheNode->FileName[StrLen (TheNode->FileName) - 4])) == 0)
|| (gUnicodeCollation->StriColl(gUnicodeCollation, (CHAR16*)L".efi", (CHAR16*)&(TheNode->FileName[StrLen (TheNode->FileName) - 4])) == 0)
){
if ( (gUnicodeCollation->StriColl (gUnicodeCollation, (CHAR16 *)L".nsh", (CHAR16 *)&(TheNode->FileName[StrLen (TheNode->FileName) - 4])) == 0)
|| (gUnicodeCollation->StriColl (gUnicodeCollation, (CHAR16 *)L".efi", (CHAR16 *)&(TheNode->FileName[StrLen (TheNode->FileName) - 4])) == 0)
)
{
ShellPrintHiiEx (
-1,
-1,
@ -257,16 +260,16 @@ PrintFileInformation(
@param[in] Path String with starting path.
**/
VOID
PrintNonSfoHeader(
IN CONST CHAR16 *Path
PrintNonSfoHeader (
IN CONST CHAR16 *Path
)
{
CHAR16 *DirectoryName;
CHAR16 *DirectoryName;
//
// get directory name from path...
//
DirectoryName = GetFullyQualifiedPath(Path);
DirectoryName = GetFullyQualifiedPath (Path);
if (DirectoryName != NULL) {
//
@ -281,7 +284,7 @@ PrintNonSfoHeader(
DirectoryName
);
SHELL_FREE_NON_NULL(DirectoryName);
SHELL_FREE_NON_NULL (DirectoryName);
}
}
@ -293,10 +296,10 @@ PrintNonSfoHeader(
@param[in] Dirs The number of directories.
**/
VOID
PrintNonSfoFooter(
IN UINT64 Files,
IN UINT64 Size,
IN UINT64 Dirs
PrintNonSfoFooter (
IN UINT64 Files,
IN UINT64 Size,
IN UINT64 Dirs
)
{
//
@ -311,7 +314,7 @@ PrintNonSfoFooter(
Files,
Size,
Dirs
);
);
}
/**
@ -322,33 +325,33 @@ PrintNonSfoFooter(
**/
VOID
FileTimeToLocalTime (
IN EFI_TIME *Time,
IN INT16 LocalTimeZone
IN EFI_TIME *Time,
IN INT16 LocalTimeZone
)
{
INTN MinuteDiff;
INTN TempMinute;
INTN HourNumberOfTempMinute;
INTN TempHour;
INTN DayNumberOfTempHour;
INTN TempDay;
INTN MonthNumberOfTempDay;
INTN TempMonth;
INTN YearNumberOfTempMonth;
INTN MonthRecord;
INTN MinuteDiff;
INTN TempMinute;
INTN HourNumberOfTempMinute;
INTN TempHour;
INTN DayNumberOfTempHour;
INTN TempDay;
INTN MonthNumberOfTempDay;
INTN TempMonth;
INTN YearNumberOfTempMonth;
INTN MonthRecord;
ASSERT ((Time->TimeZone >= -1440) && (Time->TimeZone <=1440));
ASSERT ((LocalTimeZone >= -1440) && (LocalTimeZone <=1440));
ASSERT ((Time->TimeZone >= -1440) && (Time->TimeZone <= 1440));
ASSERT ((LocalTimeZone >= -1440) && (LocalTimeZone <= 1440));
ASSERT ((Time->Month >= 1) && (Time->Month <= 12));
if(Time->TimeZone == LocalTimeZone) {
if (Time->TimeZone == LocalTimeZone) {
//
//if the file timezone is equal to the local timezone, there is no need to adjust the file time.
// if the file timezone is equal to the local timezone, there is no need to adjust the file time.
//
return;
}
if((Time->Year % 4 == 0 && Time->Year / 100 != 0)||(Time->Year % 400 == 0)) {
if (((Time->Year % 4 == 0) && (Time->Year / 100 != 0)) || (Time->Year % 400 == 0)) {
//
// Day in February of leap year is 29.
//
@ -363,21 +366,23 @@ FileTimeToLocalTime (
// TempHour will be used to calculate Time->Hour
//
HourNumberOfTempMinute = TempMinute / 60;
if(TempMinute < 0) {
HourNumberOfTempMinute --;
if (TempMinute < 0) {
HourNumberOfTempMinute--;
}
TempHour = Time->Hour + HourNumberOfTempMinute;
TempHour = Time->Hour + HourNumberOfTempMinute;
Time->Minute = (UINT8)(TempMinute - 60 * HourNumberOfTempMinute);
//
// Calculate Time->Hour
// TempDay will be used to calculate Time->Day
//
DayNumberOfTempHour = TempHour / 24 ;
if(TempHour < 0){
DayNumberOfTempHour = TempHour / 24;
if (TempHour < 0) {
DayNumberOfTempHour--;
}
TempDay = Time->Day + DayNumberOfTempHour;
TempDay = Time->Day + DayNumberOfTempHour;
Time->Hour = (UINT8)(TempHour - 24 * DayNumberOfTempHour);
//
@ -385,11 +390,12 @@ FileTimeToLocalTime (
// TempMonth will be used to calculate Time->Month
//
MonthNumberOfTempDay = (TempDay - 1) / (INTN)mDayOfMonth[Time->Month - 1];
MonthRecord = (INTN)(Time->Month) ;
if(TempDay - 1 < 0){
MonthNumberOfTempDay -- ;
MonthRecord -- ;
MonthRecord = (INTN)(Time->Month);
if (TempDay - 1 < 0) {
MonthNumberOfTempDay--;
MonthRecord--;
}
TempMonth = Time->Month + MonthNumberOfTempDay;
Time->Day = (UINT8)(TempDay - (INTN)mDayOfMonth[(MonthRecord - 1 + 12) % 12] * MonthNumberOfTempDay);
@ -397,11 +403,12 @@ FileTimeToLocalTime (
// Calculate Time->Month, Time->Year
//
YearNumberOfTempMonth = (TempMonth - 1) / 12;
if(TempMonth - 1 < 0){
YearNumberOfTempMonth --;
if (TempMonth - 1 < 0) {
YearNumberOfTempMonth--;
}
Time->Month = (UINT8)(TempMonth - 12 * (YearNumberOfTempMonth));
Time->Year = (UINT16)(Time->Year + YearNumberOfTempMonth);
Time->Year = (UINT16)(Time->Year + YearNumberOfTempMonth);
}
/**
@ -423,30 +430,30 @@ FileTimeToLocalTime (
@retval SHELL_SUCCESS the printing was sucessful.
**/
SHELL_STATUS
PrintLsOutput(
IN CONST BOOLEAN Rec,
IN CONST UINT64 Attribs,
IN CONST BOOLEAN Sfo,
IN CONST CHAR16 *RootPath,
IN CONST CHAR16 *SearchString,
IN BOOLEAN *Found,
IN CONST UINTN Count,
IN CONST INT16 TimeZone,
IN CONST BOOLEAN ListUnfiltered
PrintLsOutput (
IN CONST BOOLEAN Rec,
IN CONST UINT64 Attribs,
IN CONST BOOLEAN Sfo,
IN CONST CHAR16 *RootPath,
IN CONST CHAR16 *SearchString,
IN BOOLEAN *Found,
IN CONST UINTN Count,
IN CONST INT16 TimeZone,
IN CONST BOOLEAN ListUnfiltered
)
{
EFI_STATUS Status;
EFI_SHELL_FILE_INFO *ListHead;
EFI_SHELL_FILE_INFO *Node;
SHELL_STATUS ShellStatus;
UINT64 FileCount;
UINT64 DirCount;
UINT64 FileSize;
UINTN LongestPath;
CHAR16 *CorrectedPath;
BOOLEAN FoundOne;
BOOLEAN HeaderPrinted;
EFI_TIME LocalTime;
EFI_STATUS Status;
EFI_SHELL_FILE_INFO *ListHead;
EFI_SHELL_FILE_INFO *Node;
SHELL_STATUS ShellStatus;
UINT64 FileCount;
UINT64 DirCount;
UINT64 FileSize;
UINTN LongestPath;
CHAR16 *CorrectedPath;
BOOLEAN FoundOne;
BOOLEAN HeaderPrinted;
EFI_TIME LocalTime;
HeaderPrinted = FALSE;
FileCount = 0;
@ -463,30 +470,33 @@ PrintLsOutput(
FoundOne = FALSE;
}
CorrectedPath = StrnCatGrow(&CorrectedPath, &LongestPath, RootPath, 0);
CorrectedPath = StrnCatGrow (&CorrectedPath, &LongestPath, RootPath, 0);
if (CorrectedPath == NULL) {
return SHELL_OUT_OF_RESOURCES;
}
if (CorrectedPath[StrLen(CorrectedPath)-1] != L'\\'
&&CorrectedPath[StrLen(CorrectedPath)-1] != L'/') {
CorrectedPath = StrnCatGrow(&CorrectedPath, &LongestPath, L"\\", 0);
if ( (CorrectedPath[StrLen (CorrectedPath)-1] != L'\\')
&& (CorrectedPath[StrLen (CorrectedPath)-1] != L'/'))
{
CorrectedPath = StrnCatGrow (&CorrectedPath, &LongestPath, L"\\", 0);
}
CorrectedPath = StrnCatGrow(&CorrectedPath, &LongestPath, SearchString, 0);
CorrectedPath = StrnCatGrow (&CorrectedPath, &LongestPath, SearchString, 0);
if (CorrectedPath == NULL) {
return (SHELL_OUT_OF_RESOURCES);
}
PathCleanUpDirectories(CorrectedPath);
PathCleanUpDirectories (CorrectedPath);
Status = ShellOpenFileMetaArg((CHAR16*)CorrectedPath, EFI_FILE_MODE_READ, &ListHead);
if (!EFI_ERROR(Status)) {
if (ListHead == NULL || IsListEmpty(&ListHead->Link)) {
SHELL_FREE_NON_NULL(CorrectedPath);
Status = ShellOpenFileMetaArg ((CHAR16 *)CorrectedPath, EFI_FILE_MODE_READ, &ListHead);
if (!EFI_ERROR (Status)) {
if ((ListHead == NULL) || IsListEmpty (&ListHead->Link)) {
SHELL_FREE_NON_NULL (CorrectedPath);
return (SHELL_SUCCESS);
}
if (Sfo && Found == NULL) {
PrintSfoVolumeInfoTableEntry(ListHead);
if (Sfo && (Found == NULL)) {
PrintSfoVolumeInfoTableEntry (ListHead);
}
if (!Sfo) {
@ -503,54 +513,64 @@ PrintLsOutput(
);
}
for ( Node = (EFI_SHELL_FILE_INFO *)GetFirstNode(&ListHead->Link), LongestPath = 0
; !IsNull(&ListHead->Link, &Node->Link)
; Node = (EFI_SHELL_FILE_INFO *)GetNextNode(&ListHead->Link, &Node->Link)
){
for ( Node = (EFI_SHELL_FILE_INFO *)GetFirstNode (&ListHead->Link), LongestPath = 0
; !IsNull (&ListHead->Link, &Node->Link)
; Node = (EFI_SHELL_FILE_INFO *)GetNextNode (&ListHead->Link, &Node->Link)
)
{
if (ShellGetExecutionBreakFlag ()) {
ShellStatus = SHELL_ABORTED;
break;
}
ASSERT(Node != NULL);
ASSERT (Node != NULL);
//
// Change the file time to local time.
//
Status = gRT->GetTime(&LocalTime, NULL);
Status = gRT->GetTime (&LocalTime, NULL);
if (!EFI_ERROR (Status) && (LocalTime.TimeZone != EFI_UNSPECIFIED_TIMEZONE)) {
if ((Node->Info->CreateTime.TimeZone != EFI_UNSPECIFIED_TIMEZONE) &&
(Node->Info->CreateTime.Month >= 1 && Node->Info->CreateTime.Month <= 12)) {
((Node->Info->CreateTime.Month >= 1) && (Node->Info->CreateTime.Month <= 12)))
{
//
// FileTimeToLocalTime () requires Month is in a valid range, other buffer out-of-band access happens.
//
FileTimeToLocalTime (&Node->Info->CreateTime, LocalTime.TimeZone);
}
if ((Node->Info->LastAccessTime.TimeZone != EFI_UNSPECIFIED_TIMEZONE) &&
(Node->Info->LastAccessTime.Month >= 1 && Node->Info->LastAccessTime.Month <= 12)) {
((Node->Info->LastAccessTime.Month >= 1) && (Node->Info->LastAccessTime.Month <= 12)))
{
FileTimeToLocalTime (&Node->Info->LastAccessTime, LocalTime.TimeZone);
}
if ((Node->Info->ModificationTime.TimeZone != EFI_UNSPECIFIED_TIMEZONE) &&
(Node->Info->ModificationTime.Month >= 1 && Node->Info->ModificationTime.Month <= 12)) {
((Node->Info->ModificationTime.Month >= 1) && (Node->Info->ModificationTime.Month <= 12)))
{
FileTimeToLocalTime (&Node->Info->ModificationTime, LocalTime.TimeZone);
}
}
if (LongestPath < StrSize(Node->FullName)) {
LongestPath = StrSize(Node->FullName);
if (LongestPath < StrSize (Node->FullName)) {
LongestPath = StrSize (Node->FullName);
}
ASSERT(Node->Info != NULL);
ASSERT((Node->Info->Attribute & EFI_FILE_VALID_ATTR) == Node->Info->Attribute);
ASSERT (Node->Info != NULL);
ASSERT ((Node->Info->Attribute & EFI_FILE_VALID_ATTR) == Node->Info->Attribute);
if (Attribs == 0) {
//
// NOT system & NOT hidden
//
if ( (Node->Info->Attribute & EFI_FILE_SYSTEM)
|| (Node->Info->Attribute & EFI_FILE_HIDDEN)
){
if ( (Node->Info->Attribute & EFI_FILE_SYSTEM)
|| (Node->Info->Attribute & EFI_FILE_HIDDEN)
)
{
continue;
}
} else if ((Attribs != EFI_FILE_VALID_ATTR) ||
(Count == 5)) {
(Count == 5))
{
//
// Only matches the bits which "Attribs" contains, not
// all files/directories with any of the bits.
@ -558,47 +578,52 @@ PrintLsOutput(
// specifying all bits (EX: -arhsda) and just specifying
// -a (means display all files with any attribute).
//
if ( (Node->Info->Attribute & Attribs) != Attribs) {
if ((Node->Info->Attribute & Attribs) != Attribs) {
continue;
}
}
if (!Sfo && !HeaderPrinted) {
PathRemoveLastItem (CorrectedPath);
PrintNonSfoHeader(CorrectedPath);
PrintNonSfoHeader (CorrectedPath);
}
PrintFileInformation(Sfo, Node, &FileCount, &FileSize, &DirCount);
FoundOne = TRUE;
PrintFileInformation (Sfo, Node, &FileCount, &FileSize, &DirCount);
FoundOne = TRUE;
HeaderPrinted = TRUE;
}
if (!Sfo && ShellStatus != SHELL_ABORTED && HeaderPrinted) {
PrintNonSfoFooter(FileCount, FileSize, DirCount);
if (!Sfo && (ShellStatus != SHELL_ABORTED) && HeaderPrinted) {
PrintNonSfoFooter (FileCount, FileSize, DirCount);
}
}
if (Rec && ShellStatus != SHELL_ABORTED) {
if (Rec && (ShellStatus != SHELL_ABORTED)) {
//
// Re-Open all the files under the starting path for directories that didnt necessarily match our file filter
//
ShellCloseFileMetaArg(&ListHead);
ShellCloseFileMetaArg (&ListHead);
CorrectedPath[0] = CHAR_NULL;
CorrectedPath = StrnCatGrow(&CorrectedPath, &LongestPath, RootPath, 0);
CorrectedPath = StrnCatGrow (&CorrectedPath, &LongestPath, RootPath, 0);
if (CorrectedPath == NULL) {
return SHELL_OUT_OF_RESOURCES;
}
if (CorrectedPath[StrLen(CorrectedPath)-1] != L'\\'
&&CorrectedPath[StrLen(CorrectedPath)-1] != L'/') {
CorrectedPath = StrnCatGrow(&CorrectedPath, &LongestPath, L"\\", 0);
}
CorrectedPath = StrnCatGrow(&CorrectedPath, &LongestPath, L"*", 0);
Status = ShellOpenFileMetaArg((CHAR16*)CorrectedPath, EFI_FILE_MODE_READ, &ListHead);
if (!EFI_ERROR(Status)) {
for ( Node = (EFI_SHELL_FILE_INFO *)GetFirstNode(&ListHead->Link)
; !IsNull(&ListHead->Link, &Node->Link) && ShellStatus == SHELL_SUCCESS
; Node = (EFI_SHELL_FILE_INFO *)GetNextNode(&ListHead->Link, &Node->Link)
){
if ( (CorrectedPath[StrLen (CorrectedPath)-1] != L'\\')
&& (CorrectedPath[StrLen (CorrectedPath)-1] != L'/'))
{
CorrectedPath = StrnCatGrow (&CorrectedPath, &LongestPath, L"\\", 0);
}
CorrectedPath = StrnCatGrow (&CorrectedPath, &LongestPath, L"*", 0);
Status = ShellOpenFileMetaArg ((CHAR16 *)CorrectedPath, EFI_FILE_MODE_READ, &ListHead);
if (!EFI_ERROR (Status)) {
for ( Node = (EFI_SHELL_FILE_INFO *)GetFirstNode (&ListHead->Link)
; !IsNull (&ListHead->Link, &Node->Link) && ShellStatus == SHELL_SUCCESS
; Node = (EFI_SHELL_FILE_INFO *)GetNextNode (&ListHead->Link, &Node->Link)
)
{
if (ShellGetExecutionBreakFlag ()) {
ShellStatus = SHELL_ABORTED;
break;
@ -607,20 +632,22 @@ PrintLsOutput(
//
// recurse on any directory except the traversing ones...
//
if (((Node->Info->Attribute & EFI_FILE_DIRECTORY) == EFI_FILE_DIRECTORY)
&& StrCmp(Node->FileName, L".") != 0
&& StrCmp(Node->FileName, L"..") != 0
){
ShellStatus = PrintLsOutput(
Rec,
Attribs,
Sfo,
Node->FullName,
SearchString,
&FoundOne,
Count,
TimeZone,
FALSE);
if ( ((Node->Info->Attribute & EFI_FILE_DIRECTORY) == EFI_FILE_DIRECTORY)
&& (StrCmp (Node->FileName, L".") != 0)
&& (StrCmp (Node->FileName, L"..") != 0)
)
{
ShellStatus = PrintLsOutput (
Rec,
Attribs,
Sfo,
Node->FullName,
SearchString,
&FoundOne,
Count,
TimeZone,
FALSE
);
//
// Since it's running recursively, we have to break immediately when returned SHELL_ABORTED
@ -633,10 +660,10 @@ PrintLsOutput(
}
}
SHELL_FREE_NON_NULL(CorrectedPath);
ShellCloseFileMetaArg(&ListHead);
SHELL_FREE_NON_NULL (CorrectedPath);
ShellCloseFileMetaArg (&ListHead);
if (Found == NULL && !FoundOne) {
if ((Found == NULL) && !FoundOne) {
if (ListUnfiltered) {
//
// When running "ls" without any filtering request, avoid outputing
@ -661,12 +688,12 @@ PrintLsOutput(
return (ShellStatus);
}
STATIC CONST SHELL_PARAM_ITEM LsParamList[] = {
{L"-r", TypeFlag},
{L"-a", TypeStart},
{L"-sfo", TypeFlag},
{NULL, TypeMax}
};
STATIC CONST SHELL_PARAM_ITEM LsParamList[] = {
{ L"-r", TypeFlag },
{ L"-a", TypeStart },
{ L"-sfo", TypeFlag },
{ NULL, TypeMax }
};
/**
Function for 'ls' command.
@ -696,62 +723,63 @@ ShellCommandRunLs (
CHAR16 *SearchString;
BOOLEAN ListUnfiltered;
Size = 0;
FullPath = NULL;
ProblemParam = NULL;
Attribs = NULL;
ShellStatus = SHELL_SUCCESS;
RequiredAttributes = 0;
PathName = NULL;
SearchString = NULL;
CurDir = NULL;
Count = 0;
ListUnfiltered = FALSE;
Size = 0;
FullPath = NULL;
ProblemParam = NULL;
Attribs = NULL;
ShellStatus = SHELL_SUCCESS;
RequiredAttributes = 0;
PathName = NULL;
SearchString = NULL;
CurDir = NULL;
Count = 0;
ListUnfiltered = FALSE;
//
// initialize the shell lib (we must be in non-auto-init...)
//
Status = ShellInitialize();
ASSERT_EFI_ERROR(Status);
Status = ShellInitialize ();
ASSERT_EFI_ERROR (Status);
//
// Fix local copies of the protocol pointers
//
Status = CommandInit();
ASSERT_EFI_ERROR(Status);
Status = CommandInit ();
ASSERT_EFI_ERROR (Status);
//
// parse the command line
//
Status = ShellCommandLineParse (LsParamList, &Package, &ProblemParam, TRUE);
if (EFI_ERROR(Status)) {
if (Status == EFI_VOLUME_CORRUPTED && ProblemParam != NULL) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellLevel2HiiHandle, L"ls", ProblemParam);
FreePool(ProblemParam);
if (EFI_ERROR (Status)) {
if ((Status == EFI_VOLUME_CORRUPTED) && (ProblemParam != NULL)) {
ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellLevel2HiiHandle, L"ls", ProblemParam);
FreePool (ProblemParam);
ShellStatus = SHELL_INVALID_PARAMETER;
} else {
ASSERT(FALSE);
ASSERT (FALSE);
}
} else {
//
// check for "-?"
//
if (ShellCommandLineGetFlag(Package, L"-?")) {
ASSERT(FALSE);
if (ShellCommandLineGetFlag (Package, L"-?")) {
ASSERT (FALSE);
}
if (ShellCommandLineGetCount(Package) > 2) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_MANY), gShellLevel2HiiHandle, L"ls");
if (ShellCommandLineGetCount (Package) > 2) {
ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_MANY), gShellLevel2HiiHandle, L"ls");
ShellStatus = SHELL_INVALID_PARAMETER;
} else {
//
// check for -a
//
if (ShellCommandLineGetFlag(Package, L"-a")) {
for ( Attribs = ShellCommandLineGetValue(Package, L"-a")
; Attribs != NULL && *Attribs != CHAR_NULL && ShellStatus == SHELL_SUCCESS
; Attribs++
){
if (ShellCommandLineGetFlag (Package, L"-a")) {
for ( Attribs = ShellCommandLineGetValue (Package, L"-a")
; Attribs != NULL && *Attribs != CHAR_NULL && ShellStatus == SHELL_SUCCESS
; Attribs++
)
{
switch (*Attribs) {
case L'a':
case L'A':
@ -779,11 +807,12 @@ ShellCommandRunLs (
Count++;
continue;
default:
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_ATTRIBUTE), gShellLevel2HiiHandle, L"ls", ShellCommandLineGetValue(Package, L"-a"));
ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_ATTRIBUTE), gShellLevel2HiiHandle, L"ls", ShellCommandLineGetValue (Package, L"-a"));
ShellStatus = SHELL_INVALID_PARAMETER;
break;
} // switch
} // for loop
//
// if nothing is specified all are specified
//
@ -791,103 +820,109 @@ ShellCommandRunLs (
RequiredAttributes = EFI_FILE_VALID_ATTR;
}
} // if -a present
if (ShellStatus == SHELL_SUCCESS) {
PathName = ShellCommandLineGetRawValue(Package, 1);
PathName = ShellCommandLineGetRawValue (Package, 1);
if (PathName == NULL) {
//
// Nothing specified... must start from current directory
//
CurDir = gEfiShellProtocol->GetCurDir(NULL);
CurDir = gEfiShellProtocol->GetCurDir (NULL);
if (CurDir == NULL) {
ShellStatus = SHELL_NOT_FOUND;
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_NO_CWD), gShellLevel2HiiHandle, L"ls");
ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_NO_CWD), gShellLevel2HiiHandle, L"ls");
}
ListUnfiltered = TRUE;
//
// Copy to the 2 strings for starting path and file search string
//
ASSERT(SearchString == NULL);
ASSERT(FullPath == NULL);
StrnCatGrow(&SearchString, NULL, L"*", 0);
StrnCatGrow(&FullPath, NULL, CurDir, 0);
Size = FullPath != NULL? StrSize(FullPath) : 0;
StrnCatGrow(&FullPath, &Size, L"\\", 0);
ASSERT (SearchString == NULL);
ASSERT (FullPath == NULL);
StrnCatGrow (&SearchString, NULL, L"*", 0);
StrnCatGrow (&FullPath, NULL, CurDir, 0);
Size = FullPath != NULL ? StrSize (FullPath) : 0;
StrnCatGrow (&FullPath, &Size, L"\\", 0);
} else {
if (StrStr(PathName, L":") == NULL && gEfiShellProtocol->GetCurDir(NULL) == NULL) {
if ((StrStr (PathName, L":") == NULL) && (gEfiShellProtocol->GetCurDir (NULL) == NULL)) {
//
// If we got something and it doesnt have a fully qualified path, then we needed to have a CWD.
//
ShellStatus = SHELL_NOT_FOUND;
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_NO_CWD), gShellLevel2HiiHandle, L"ls");
ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_NO_CWD), gShellLevel2HiiHandle, L"ls");
} else {
//
// We got a valid fully qualified path or we have a CWD
//
ASSERT((FullPath == NULL && Size == 0) || (FullPath != NULL));
if (StrStr(PathName, L":") == NULL) {
StrnCatGrow(&FullPath, &Size, gEfiShellProtocol->GetCurDir(NULL), 0);
ASSERT ((FullPath == NULL && Size == 0) || (FullPath != NULL));
if (StrStr (PathName, L":") == NULL) {
StrnCatGrow (&FullPath, &Size, gEfiShellProtocol->GetCurDir (NULL), 0);
if (FullPath == NULL) {
ShellCommandLineFreeVarList (Package);
return SHELL_OUT_OF_RESOURCES;
}
Size = FullPath != NULL? StrSize(FullPath) : 0;
StrnCatGrow(&FullPath, &Size, L"\\", 0);
}
StrnCatGrow(&FullPath, &Size, PathName, 0);
if (FullPath == NULL) {
ShellCommandLineFreeVarList (Package);
return SHELL_OUT_OF_RESOURCES;
Size = FullPath != NULL ? StrSize (FullPath) : 0;
StrnCatGrow (&FullPath, &Size, L"\\", 0);
}
if (ShellIsDirectory(PathName) == EFI_SUCCESS) {
StrnCatGrow (&FullPath, &Size, PathName, 0);
if (FullPath == NULL) {
ShellCommandLineFreeVarList (Package);
return SHELL_OUT_OF_RESOURCES;
}
if (ShellIsDirectory (PathName) == EFI_SUCCESS) {
//
// is listing ends with a directory, then we list all files in that directory
//
ListUnfiltered = TRUE;
StrnCatGrow(&SearchString, NULL, L"*", 0);
StrnCatGrow (&SearchString, NULL, L"*", 0);
} else {
//
// must split off the search part that applies to files from the end of the directory part
//
StrnCatGrow(&SearchString, NULL, FullPath, 0);
StrnCatGrow (&SearchString, NULL, FullPath, 0);
if (SearchString == NULL) {
FreePool (FullPath);
ShellCommandLineFreeVarList (Package);
return SHELL_OUT_OF_RESOURCES;
}
PathRemoveLastItem (FullPath);
CopyMem (SearchString, SearchString + StrLen (FullPath), StrSize (SearchString + StrLen (FullPath)));
}
}
}
Status = gRT->GetTime(&TheTime, NULL);
if (EFI_ERROR(Status)) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_UEFI_FUNC_WARN), gShellLevel2HiiHandle, L"ls", L"gRT->GetTime", Status);
Status = gRT->GetTime (&TheTime, NULL);
if (EFI_ERROR (Status)) {
ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_UEFI_FUNC_WARN), gShellLevel2HiiHandle, L"ls", L"gRT->GetTime", Status);
TheTime.TimeZone = EFI_UNSPECIFIED_TIMEZONE;
}
if (ShellStatus == SHELL_SUCCESS) {
ShellStatus = PrintLsOutput(
ShellCommandLineGetFlag(Package, L"-r"),
RequiredAttributes,
ShellCommandLineGetFlag(Package, L"-sfo"),
FullPath,
SearchString,
NULL,
Count,
TheTime.TimeZone,
ListUnfiltered
);
ShellStatus = PrintLsOutput (
ShellCommandLineGetFlag (Package, L"-r"),
RequiredAttributes,
ShellCommandLineGetFlag (Package, L"-sfo"),
FullPath,
SearchString,
NULL,
Count,
TheTime.TimeZone,
ListUnfiltered
);
if (ShellStatus == SHELL_NOT_FOUND) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_LS_FILE_NOT_FOUND), gShellLevel2HiiHandle, L"ls", FullPath);
ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_LS_FILE_NOT_FOUND), gShellLevel2HiiHandle, L"ls", FullPath);
} else if (ShellStatus == SHELL_INVALID_PARAMETER) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PARAM_INV), gShellLevel2HiiHandle, L"ls", FullPath);
ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_PARAM_INV), gShellLevel2HiiHandle, L"ls", FullPath);
} else if (ShellStatus == SHELL_ABORTED) {
//
// Ignore aborting.
//
} else if (ShellStatus != SHELL_SUCCESS) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PARAM_INV), gShellLevel2HiiHandle, L"ls", FullPath);
ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_PARAM_INV), gShellLevel2HiiHandle, L"ls", FullPath);
}
}
}
@ -897,8 +932,8 @@ ShellCommandRunLs (
//
// Free memory allocated
//
SHELL_FREE_NON_NULL(SearchString);
SHELL_FREE_NON_NULL(FullPath);
SHELL_FREE_NON_NULL (SearchString);
SHELL_FREE_NON_NULL (FullPath);
ShellCommandLineFreeVarList (Package);
return (ShellStatus);

File diff suppressed because it is too large Load Diff

View File

@ -22,129 +22,139 @@ ShellCommandRunMkDir (
IN EFI_SYSTEM_TABLE *SystemTable
)
{
EFI_STATUS Status;
CONST CHAR16 *NewDirName;
CHAR16 *NewDirNameCopy;
CHAR16 *SplitName;
CHAR16 SaveSplitChar;
UINTN DirCreateCount;
LIST_ENTRY *Package;
CHAR16 *ProblemParam;
SHELL_FILE_HANDLE FileHandle;
SHELL_STATUS ShellStatus;
EFI_STATUS Status;
CONST CHAR16 *NewDirName;
CHAR16 *NewDirNameCopy;
CHAR16 *SplitName;
CHAR16 SaveSplitChar;
UINTN DirCreateCount;
LIST_ENTRY *Package;
CHAR16 *ProblemParam;
SHELL_FILE_HANDLE FileHandle;
SHELL_STATUS ShellStatus;
ShellStatus = SHELL_SUCCESS;
NewDirNameCopy = NULL;
SplitName = NULL;
SaveSplitChar = CHAR_NULL;
ShellStatus = SHELL_SUCCESS;
NewDirNameCopy = NULL;
SplitName = NULL;
SaveSplitChar = CHAR_NULL;
//
// initialize the shell lib (we must be in non-auto-init...)
//
Status = ShellInitialize();
ASSERT_EFI_ERROR(Status);
Status = ShellInitialize ();
ASSERT_EFI_ERROR (Status);
//
// parse the command line
//
Status = ShellCommandLineParse (EmptyParamList, &Package, &ProblemParam, TRUE);
if (EFI_ERROR(Status)) {
if (Status == EFI_VOLUME_CORRUPTED && ProblemParam != NULL) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellLevel2HiiHandle, L"mkdir", ProblemParam);
FreePool(ProblemParam);
if (EFI_ERROR (Status)) {
if ((Status == EFI_VOLUME_CORRUPTED) && (ProblemParam != NULL)) {
ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellLevel2HiiHandle, L"mkdir", ProblemParam);
FreePool (ProblemParam);
ShellStatus = SHELL_INVALID_PARAMETER;
} else {
ASSERT(FALSE);
ASSERT (FALSE);
}
} else {
//
// check for "-?"
//
if (ShellCommandLineGetFlag(Package, L"-?")) {
ASSERT(FALSE);
if (ShellCommandLineGetFlag (Package, L"-?")) {
ASSERT (FALSE);
}
//
// create a set of directories
//
if (ShellCommandLineGetRawValue(Package, 1) == NULL) {
if (ShellCommandLineGetRawValue (Package, 1) == NULL) {
//
// we didnt get a single parameter
//
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_FEW), gShellLevel2HiiHandle, L"mkdir");
ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_FEW), gShellLevel2HiiHandle, L"mkdir");
ShellStatus = SHELL_INVALID_PARAMETER;
} else {
for ( DirCreateCount = 1
;
; DirCreateCount++
){
;
; DirCreateCount++
)
{
//
// loop through each directory specified
//
NewDirName = ShellCommandLineGetRawValue(Package, DirCreateCount);
NewDirName = ShellCommandLineGetRawValue (Package, DirCreateCount);
if (NewDirName == NULL) {
break;
}
//
// check if that already exists... if yes fail
//
FileHandle = NULL;
Status = ShellOpenFileByName(NewDirName,
&FileHandle,
EFI_FILE_MODE_READ | EFI_FILE_MODE_WRITE,
EFI_FILE_DIRECTORY
);
if (!EFI_ERROR(Status)) {
ShellCloseFile(&FileHandle);
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_MKDIR_ALREADY), gShellLevel2HiiHandle, NewDirName);
Status = ShellOpenFileByName (
NewDirName,
&FileHandle,
EFI_FILE_MODE_READ | EFI_FILE_MODE_WRITE,
EFI_FILE_DIRECTORY
);
if (!EFI_ERROR (Status)) {
ShellCloseFile (&FileHandle);
ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_MKDIR_ALREADY), gShellLevel2HiiHandle, NewDirName);
ShellStatus = SHELL_INVALID_PARAMETER;
} else {
ASSERT(FileHandle == NULL);
ASSERT (FileHandle == NULL);
//
// create the nested directory from parent to child.
// if NewDirName = test1\test2\test3, first create "test1\" directory, then "test1\test2\", finally "test1\test2\test3".
//
NewDirNameCopy = AllocateCopyPool (StrSize(NewDirName), NewDirName);
NewDirNameCopy = AllocateCopyPool (StrSize (NewDirName), NewDirName);
NewDirNameCopy = PathCleanUpDirectories (NewDirNameCopy);
if(NewDirNameCopy == NULL) {
if (NewDirNameCopy == NULL) {
ShellStatus = SHELL_OUT_OF_RESOURCES;
break;
}
SplitName = NewDirNameCopy;
while (SplitName != NULL) {
SplitName = StrStr (SplitName + 1, L"\\");
if (SplitName != NULL) {
SaveSplitChar = *(SplitName + 1);
SaveSplitChar = *(SplitName + 1);
*(SplitName + 1) = '\0';
}
//
// check if current nested directory already exists... continue to create the child directory.
//
Status = ShellOpenFileByName (NewDirNameCopy,
&FileHandle,
EFI_FILE_MODE_READ,
EFI_FILE_DIRECTORY
);
if (!EFI_ERROR(Status)) {
Status = ShellOpenFileByName (
NewDirNameCopy,
&FileHandle,
EFI_FILE_MODE_READ,
EFI_FILE_DIRECTORY
);
if (!EFI_ERROR (Status)) {
ShellCloseFile (&FileHandle);
} else {
Status = ShellCreateDirectory (NewDirNameCopy, &FileHandle);
if (EFI_ERROR(Status)) {
if (EFI_ERROR (Status)) {
break;
}
if (FileHandle != NULL) {
gEfiShellProtocol->CloseFile (FileHandle);
}
}
if (SplitName != NULL) {
*(SplitName + 1) = SaveSplitChar;
}
}
if (EFI_ERROR(Status)) {
if (EFI_ERROR (Status)) {
ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_MKDIR_CREATEFAIL), gShellLevel2HiiHandle, NewDirName);
ShellStatus = SHELL_ACCESS_DENIED;
break;
}
SHELL_FREE_NON_NULL (NewDirNameCopy);
}
}
@ -158,4 +168,3 @@ ShellCommandRunMkDir (
return (ShellStatus);
}

View File

@ -20,34 +20,37 @@
@retval FALSE The move is within a file system.
**/
BOOLEAN
IsBetweenFileSystem(
IN CONST CHAR16 *FullName,
IN CONST CHAR16 *Cwd,
IN CONST CHAR16 *DestPath
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":");
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":");
Test1 = StrStr (DestPath, L":");
if ((Test1 == NULL) && (Cwd != NULL)) {
Test1 = StrStr (Cwd, L":");
}
if (Test1 != NULL && Test != NULL) {
*Test = CHAR_NULL;
if ((Test1 != NULL) && (Test != NULL)) {
*Test = CHAR_NULL;
*Test1 = CHAR_NULL;
Result = StringNoCaseCompare(&FullName, &DestPath);
*Test = L':';
Result = StringNoCaseCompare (&FullName, &DestPath);
*Test = L':';
*Test1 = L':';
if (Result != 0) {
return (TRUE);
}
}
return (FALSE);
}
@ -67,14 +70,14 @@ IsBetweenFileSystem(
@retval FALSE The source path is invalid.
**/
BOOLEAN
IsSoucePathValid(
IN CONST CHAR16* SrcPath,
IN CONST CHAR16* CwdPath
IsSoucePathValid (
IN CONST CHAR16 *SrcPath,
IN CONST CHAR16 *CwdPath
)
{
CHAR16* SrcPathBuffer;
CHAR16* CwdPathBuffer;
BOOLEAN Ret;
CHAR16 *SrcPathBuffer;
CHAR16 *CwdPathBuffer;
BOOLEAN Ret;
ASSERT (CwdPath != NULL);
if (SrcPath == NULL) {
@ -90,14 +93,14 @@ IsSoucePathValid(
CwdPathBuffer = AllocateCopyPool (StrSize (CwdPath), CwdPath);
if (CwdPathBuffer == NULL) {
FreePool(SrcPathBuffer);
FreePool (SrcPathBuffer);
return FALSE;
}
gUnicodeCollation->StrUpr (gUnicodeCollation, SrcPathBuffer);
gUnicodeCollation->StrUpr (gUnicodeCollation, CwdPathBuffer);
if (SrcPathBuffer[StrLen (SrcPathBuffer) -1 ] == L'\\') {
if (SrcPathBuffer[StrLen (SrcPathBuffer) -1] == L'\\') {
SrcPathBuffer[StrLen (SrcPathBuffer) - 1] = CHAR_NULL;
}
@ -105,10 +108,11 @@ IsSoucePathValid(
CwdPathBuffer[StrLen (CwdPathBuffer) - 1] = CHAR_NULL;
}
if (StrCmp (CwdPathBuffer, SrcPathBuffer) == 0 ||
if ((StrCmp (CwdPathBuffer, SrcPathBuffer) == 0) ||
((StrStr (CwdPathBuffer, SrcPathBuffer) == CwdPathBuffer) &&
(CwdPathBuffer[StrLen (SrcPathBuffer)] == L'\\'))
) {
)
{
Ret = FALSE;
}
@ -139,13 +143,13 @@ IsSoucePathValid(
@retval FALSE The move is not
**/
BOOLEAN
IsValidMove(
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
IsValidMove (
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 *DestPathCopy;
@ -156,7 +160,7 @@ IsValidMove(
//
// Invalid move
//
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN(STR_MV_INV_CWD), gShellLevel2HiiHandle);
ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_MV_INV_CWD), gShellLevel2HiiHandle);
return FALSE;
}
}
@ -164,41 +168,45 @@ IsValidMove(
//
// 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);
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);
DestPathCopy = AllocateCopyPool (StrSize (DestPath), DestPath);
if (DestPathCopy == NULL) {
return (FALSE);
}
for (DestPathWalker = DestPathCopy; *DestPathWalker == L'\\'; DestPathWalker++) ;
while(DestPathWalker != NULL && DestPathWalker[StrLen(DestPathWalker)-1] == L'\\') {
DestPathWalker[StrLen(DestPathWalker)-1] = CHAR_NULL;
for (DestPathWalker = DestPathCopy; *DestPathWalker == L'\\'; DestPathWalker++) {
}
ASSERT(DestPathWalker != NULL);
ASSERT(SourcePath != NULL);
while (DestPathWalker != NULL && DestPathWalker[StrLen (DestPathWalker)-1] == L'\\') {
DestPathWalker[StrLen (DestPathWalker)-1] = CHAR_NULL;
}
ASSERT (DestPathWalker != NULL);
ASSERT (SourcePath != NULL);
//
// If they're the same, or if source is "above" dest on file path tree
//
if ( StringNoCaseCompare (&DestPathWalker, &SourcePath) == 0 ||
((StrStr(DestPathWalker, SourcePath) == DestPathWalker) &&
(DestPathWalker[StrLen(SourcePath)] == '\\')
)
) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_MV_INV_SUB), gShellLevel2HiiHandle);
FreePool(DestPathCopy);
if ((StringNoCaseCompare (&DestPathWalker, &SourcePath) == 0) ||
((StrStr (DestPathWalker, SourcePath) == DestPathWalker) &&
(DestPathWalker[StrLen (SourcePath)] == '\\')
)
)
{
ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_MV_INV_SUB), gShellLevel2HiiHandle);
FreePool (DestPathCopy);
return (FALSE);
}
FreePool(DestPathCopy);
FreePool (DestPathCopy);
return (TRUE);
}
@ -222,116 +230,124 @@ IsValidMove(
@retval SHELL_SUCCESS The operation was sucessful.
**/
SHELL_STATUS
GetDestinationLocation(
IN CONST CHAR16 *DestParameter,
IN OUT CHAR16 **DestPathPointer,
IN CONST CHAR16 *Cwd,
IN CONST BOOLEAN SingleSource,
IN OUT UINT64 *DestAttr
GetDestinationLocation (
IN CONST CHAR16 *DestParameter,
IN OUT CHAR16 **DestPathPointer,
IN CONST CHAR16 *Cwd,
IN CONST BOOLEAN SingleSource,
IN OUT UINT64 *DestAttr
)
{
EFI_SHELL_FILE_INFO *DestList;
EFI_SHELL_FILE_INFO *Node;
CHAR16 *DestPath;
UINTN NewSize;
UINTN CurrentSize;
EFI_SHELL_FILE_INFO *DestList;
EFI_SHELL_FILE_INFO *Node;
CHAR16 *DestPath;
UINTN NewSize;
UINTN CurrentSize;
DestList = NULL;
DestPath = NULL;
ASSERT(DestAttr != NULL);
ASSERT (DestAttr != NULL);
if (StrStr(DestParameter, L"\\") == DestParameter) {
if (StrStr (DestParameter, L"\\") == DestParameter) {
if (Cwd == NULL) {
return SHELL_INVALID_PARAMETER;
}
DestPath = AllocateZeroPool(StrSize(Cwd));
DestPath = AllocateZeroPool (StrSize (Cwd));
if (DestPath == NULL) {
return (SHELL_OUT_OF_RESOURCES);
}
StrCpyS(DestPath, StrSize(Cwd) / sizeof(CHAR16), Cwd);
while (PathRemoveLastItem(DestPath)) ;
StrCpyS (DestPath, StrSize (Cwd) / sizeof (CHAR16), Cwd);
while (PathRemoveLastItem (DestPath)) {
}
//
// Append DestParameter beyond '\' which may be present
//
CurrentSize = StrSize(DestPath);
StrnCatGrow(&DestPath, &CurrentSize, &DestParameter[1], 0);
CurrentSize = StrSize (DestPath);
StrnCatGrow (&DestPath, &CurrentSize, &DestParameter[1], 0);
*DestPathPointer = DestPath;
return (SHELL_SUCCESS);
}
//
// get the destination path
//
ShellOpenFileMetaArg((CHAR16*)DestParameter, EFI_FILE_MODE_WRITE|EFI_FILE_MODE_READ|EFI_FILE_MODE_CREATE, &DestList);
if (DestList == NULL || IsListEmpty(&DestList->Link)) {
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(DestParameter, L":") == NULL) {
if (StrStr (DestParameter, L":") == NULL) {
if (Cwd == NULL) {
ShellCloseFileMetaArg(&DestList);
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_NO_CWD), gShellLevel2HiiHandle);
ShellCloseFileMetaArg (&DestList);
ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_NO_CWD), gShellLevel2HiiHandle);
return (SHELL_INVALID_PARAMETER);
}
NewSize = StrSize(Cwd);
NewSize += StrSize(DestParameter);
DestPath = AllocateZeroPool(NewSize);
NewSize = StrSize (Cwd);
NewSize += StrSize (DestParameter);
DestPath = AllocateZeroPool (NewSize);
if (DestPath == NULL) {
ShellCloseFileMetaArg(&DestList);
ShellCloseFileMetaArg (&DestList);
return (SHELL_OUT_OF_RESOURCES);
}
StrCpyS(DestPath, NewSize / sizeof(CHAR16), Cwd);
if (DestPath[StrLen(DestPath)-1] != L'\\' && DestParameter[0] != L'\\') {
StrCatS(DestPath, NewSize / sizeof(CHAR16), L"\\");
} else if (DestPath[StrLen(DestPath)-1] == L'\\' && DestParameter[0] == L'\\') {
((CHAR16*)DestPath)[StrLen(DestPath)-1] = CHAR_NULL;
StrCpyS (DestPath, NewSize / sizeof (CHAR16), Cwd);
if ((DestPath[StrLen (DestPath)-1] != L'\\') && (DestParameter[0] != L'\\')) {
StrCatS (DestPath, NewSize / sizeof (CHAR16), L"\\");
} else if ((DestPath[StrLen (DestPath)-1] == L'\\') && (DestParameter[0] == L'\\')) {
((CHAR16 *)DestPath)[StrLen (DestPath)-1] = CHAR_NULL;
}
StrCatS(DestPath, NewSize / sizeof(CHAR16), DestParameter);
StrCatS (DestPath, NewSize / sizeof (CHAR16), DestParameter);
} else {
ASSERT(DestPath == NULL);
DestPath = StrnCatGrow(&DestPath, NULL, DestParameter, 0);
ASSERT (DestPath == NULL);
DestPath = StrnCatGrow (&DestPath, NULL, DestParameter, 0);
if (DestPath == NULL) {
ShellCloseFileMetaArg(&DestList);
ShellCloseFileMetaArg (&DestList);
return (SHELL_OUT_OF_RESOURCES);
}
}
} else {
Node = (EFI_SHELL_FILE_INFO*)GetFirstNode(&DestList->Link);
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, L"mv", DestParameter);
if (!IsNodeAtEnd (&DestList->Link, &Node->Link)) {
ShellCloseFileMetaArg (&DestList);
ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_MARG_ERROR), gShellLevel2HiiHandle, L"mv", DestParameter);
return (SHELL_INVALID_PARAMETER);
}
//
// 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 ((ShellIsDirectory (Node->FullName) == EFI_SUCCESS) || SingleSource) {
DestPath = AllocateZeroPool (StrSize (Node->FullName)+sizeof (CHAR16));
if (DestPath == NULL) {
ShellCloseFileMetaArg(&DestList);
ShellCloseFileMetaArg (&DestList);
return (SHELL_OUT_OF_RESOURCES);
}
StrCpyS(DestPath, (StrSize(Node->FullName)+sizeof(CHAR16)) / sizeof(CHAR16), Node->FullName);
StrCatS(DestPath, (StrSize(Node->FullName)+sizeof(CHAR16)) / sizeof(CHAR16), L"\\");
StrCpyS (DestPath, (StrSize (Node->FullName)+sizeof (CHAR16)) / sizeof (CHAR16), Node->FullName);
StrCatS (DestPath, (StrSize (Node->FullName)+sizeof (CHAR16)) / sizeof (CHAR16), L"\\");
} else {
//
// cant move multiple files onto a single file.
//
ShellCloseFileMetaArg(&DestList);
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_FILE_ERROR), gShellLevel2HiiHandle, L"mv", DestParameter);
ShellCloseFileMetaArg (&DestList);
ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_FILE_ERROR), gShellLevel2HiiHandle, L"mv", DestParameter);
return (SHELL_INVALID_PARAMETER);
}
}
*DestPathPointer = DestPath;
ShellCloseFileMetaArg(&DestList);
ShellCloseFileMetaArg (&DestList);
return (SHELL_SUCCESS);
}
@ -346,13 +362,13 @@ GetDestinationLocation(
@retval SHELL_SUCCESS The source file was moved to the destination.
**/
EFI_STATUS
MoveBetweenFileSystems(
MoveBetweenFileSystems (
IN EFI_SHELL_FILE_INFO *Node,
IN CONST CHAR16 *DestPath,
OUT VOID **Resp
)
{
SHELL_STATUS ShellStatus;
SHELL_STATUS ShellStatus;
//
// First we copy the file
@ -366,7 +382,7 @@ MoveBetweenFileSystems(
//
// The copy was successful. delete the source file.
//
CascadeDelete(Node, TRUE);
CascadeDelete (Node, TRUE);
Node->Handle = NULL;
} else if (ShellStatus == SHELL_ABORTED) {
return EFI_ABORTED;
@ -393,29 +409,31 @@ MoveBetweenFileSystems(
@retval SHELL_OUT_OF_RESOURCES a memory allocation failed
**/
EFI_STATUS
CreateFullDestPath(
IN CONST CHAR16 **DestPath,
OUT CHAR16 **FullDestPath,
IN CONST CHAR16 *FileName
CreateFullDestPath (
IN CONST CHAR16 **DestPath,
OUT CHAR16 **FullDestPath,
IN CONST CHAR16 *FileName
)
{
UINTN Size;
if (FullDestPath == NULL || FileName == NULL || DestPath == NULL || *DestPath == NULL){
UINTN Size;
if ((FullDestPath == NULL) || (FileName == NULL) || (DestPath == NULL) || (*DestPath == NULL)) {
return (EFI_INVALID_PARAMETER);
}
Size = StrSize(*DestPath) + StrSize(FileName);
Size = StrSize (*DestPath) + StrSize (FileName);
*FullDestPath = AllocateZeroPool(Size);
if (*FullDestPath == NULL){
*FullDestPath = AllocateZeroPool (Size);
if (*FullDestPath == NULL) {
return (EFI_OUT_OF_RESOURCES);
}
StrCpyS(*FullDestPath, Size / sizeof(CHAR16), *DestPath);
if ((*FullDestPath)[StrLen(*FullDestPath)-1] != L'\\' && FileName[0] != L'\\') {
StrCatS(*FullDestPath, Size / sizeof(CHAR16), L"\\");
StrCpyS (*FullDestPath, Size / sizeof (CHAR16), *DestPath);
if (((*FullDestPath)[StrLen (*FullDestPath)-1] != L'\\') && (FileName[0] != L'\\')) {
StrCatS (*FullDestPath, Size / sizeof (CHAR16), L"\\");
}
StrCatS(*FullDestPath, Size / sizeof(CHAR16), FileName);
StrCatS (*FullDestPath, Size / sizeof (CHAR16), FileName);
return (EFI_SUCCESS);
}
@ -431,46 +449,48 @@ CreateFullDestPath(
@retval SHELL_OUT_OF_RESOURCES A memory allocation failed.
**/
EFI_STATUS
MoveWithinFileSystems(
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;
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));
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);
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);
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);
CopyMem (NewFileInfo, Node->Info, SIZE_OF_EFI_FILE_INFO);
if (DestPath[0] != L'\\') {
StrCpyS(NewFileInfo->FileName, (NewSize - SIZE_OF_EFI_FILE_INFO) / sizeof(CHAR16), L"\\");
StrCatS(NewFileInfo->FileName, (NewSize - SIZE_OF_EFI_FILE_INFO) / sizeof(CHAR16), DestPath);
StrCpyS (NewFileInfo->FileName, (NewSize - SIZE_OF_EFI_FILE_INFO) / sizeof (CHAR16), L"\\");
StrCatS (NewFileInfo->FileName, (NewSize - SIZE_OF_EFI_FILE_INFO) / sizeof (CHAR16), DestPath);
} else {
StrCpyS(NewFileInfo->FileName, (NewSize - SIZE_OF_EFI_FILE_INFO) / sizeof(CHAR16), DestPath);
StrCpyS (NewFileInfo->FileName, (NewSize - SIZE_OF_EFI_FILE_INFO) / sizeof (CHAR16), DestPath);
}
Length = StrLen(NewFileInfo->FileName);
Length = StrLen (NewFileInfo->FileName);
if (Length > 0) {
Length--;
}
if (NewFileInfo->FileName[Length] == L'\\') {
if (Node->FileName[0] == L'\\') {
//
@ -478,23 +498,26 @@ MoveWithinFileSystems(
//
NewFileInfo->FileName[Length] = CHAR_NULL;
}
StrCatS(NewFileInfo->FileName, (NewSize - SIZE_OF_EFI_FILE_INFO) / sizeof(CHAR16), Node->FileName);
StrCatS (NewFileInfo->FileName, (NewSize - SIZE_OF_EFI_FILE_INFO) / sizeof (CHAR16), Node->FileName);
}
NewFileInfo->Size = SIZE_OF_EFI_FILE_INFO + StrSize(NewFileInfo->FileName);
NewFileInfo->Size = SIZE_OF_EFI_FILE_INFO + StrSize (NewFileInfo->FileName);
//
// Perform the move operation
//
Status = ShellSetFileInfo(Node->Handle, NewFileInfo);
Status = ShellSetFileInfo (Node->Handle, NewFileInfo);
//
// Free the info object we used...
//
FreePool(NewFileInfo);
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
@ -511,49 +534,49 @@ MoveWithinFileSystems(
@retval SHELL_OUT_OF_RESOURCES a memory allocation failed
**/
SHELL_STATUS
ValidateAndMoveFiles(
IN EFI_SHELL_FILE_INFO *FileList,
OUT VOID **Resp,
IN CONST CHAR16 *DestParameter
ValidateAndMoveFiles (
IN EFI_SHELL_FILE_INFO *FileList,
OUT VOID **Resp,
IN CONST CHAR16 *DestParameter
)
{
EFI_STATUS Status;
CHAR16 *HiiOutput;
CHAR16 *HiiResultOk;
CHAR16 *DestPath;
CHAR16 *FullDestPath;
CONST CHAR16 *Cwd;
CHAR16 *FullCwd;
SHELL_STATUS ShellStatus;
EFI_SHELL_FILE_INFO *Node;
VOID *Response;
UINT64 Attr;
CHAR16 *CleanFilePathStr;
EFI_STATUS Status;
CHAR16 *HiiOutput;
CHAR16 *HiiResultOk;
CHAR16 *DestPath;
CHAR16 *FullDestPath;
CONST CHAR16 *Cwd;
CHAR16 *FullCwd;
SHELL_STATUS ShellStatus;
EFI_SHELL_FILE_INFO *Node;
VOID *Response;
UINT64 Attr;
CHAR16 *CleanFilePathStr;
ASSERT(FileList != NULL);
ASSERT(DestParameter != NULL);
ASSERT (FileList != NULL);
ASSERT (DestParameter != NULL);
DestPath = NULL;
FullDestPath = NULL;
Cwd = ShellGetCurrentDir(NULL);
Response = *Resp;
Attr = 0;
CleanFilePathStr = NULL;
FullCwd = NULL;
DestPath = NULL;
FullDestPath = NULL;
Cwd = ShellGetCurrentDir (NULL);
Response = *Resp;
Attr = 0;
CleanFilePathStr = NULL;
FullCwd = NULL;
if (Cwd != NULL) {
FullCwd = AllocateZeroPool(StrSize(Cwd) + sizeof(CHAR16));
FullCwd = AllocateZeroPool (StrSize (Cwd) + sizeof (CHAR16));
if (FullCwd == NULL) {
return SHELL_OUT_OF_RESOURCES;
} else {
StrCpyS(FullCwd, StrSize(Cwd)/sizeof(CHAR16)+1, Cwd);
StrCatS(FullCwd, StrSize(Cwd)/sizeof(CHAR16)+1, L"\\");
StrCpyS (FullCwd, StrSize (Cwd)/sizeof (CHAR16)+1, Cwd);
StrCatS (FullCwd, StrSize (Cwd)/sizeof (CHAR16)+1, L"\\");
}
}
Status = ShellLevel2StripQuotes (DestParameter, &CleanFilePathStr);
if (EFI_ERROR (Status)) {
SHELL_FREE_NON_NULL(FullCwd);
SHELL_FREE_NON_NULL (FullCwd);
if (Status == EFI_OUT_OF_RESOURCES) {
return SHELL_OUT_OF_RESOURCES;
} else {
@ -566,14 +589,15 @@ ValidateAndMoveFiles(
//
// Get and validate the destination location
//
ShellStatus = GetDestinationLocation(CleanFilePathStr, &DestPath, FullCwd, (BOOLEAN)(FileList->Link.ForwardLink == FileList->Link.BackLink), &Attr);
ShellStatus = GetDestinationLocation (CleanFilePathStr, &DestPath, FullCwd, (BOOLEAN)(FileList->Link.ForwardLink == FileList->Link.BackLink), &Attr);
FreePool (CleanFilePathStr);
if (ShellStatus != SHELL_SUCCESS) {
SHELL_FREE_NON_NULL (FullCwd);
return (ShellStatus);
}
DestPath = PathCleanUpDirectories(DestPath);
DestPath = PathCleanUpDirectories (DestPath);
if (DestPath == NULL) {
FreePool (FullCwd);
return (SHELL_OUT_OF_RESOURCES);
@ -581,68 +605,71 @@ ValidateAndMoveFiles(
HiiOutput = HiiGetString (gShellLevel2HiiHandle, STRING_TOKEN (STR_MV_OUTPUT), NULL);
HiiResultOk = HiiGetString (gShellLevel2HiiHandle, STRING_TOKEN (STR_GEN_RES_OK), NULL);
if (HiiOutput == NULL || HiiResultOk == NULL) {
SHELL_FREE_NON_NULL(DestPath);
SHELL_FREE_NON_NULL(HiiOutput);
SHELL_FREE_NON_NULL(HiiResultOk);
SHELL_FREE_NON_NULL(FullCwd);
if ((HiiOutput == NULL) || (HiiResultOk == NULL)) {
SHELL_FREE_NON_NULL (DestPath);
SHELL_FREE_NON_NULL (HiiOutput);
SHELL_FREE_NON_NULL (HiiResultOk);
SHELL_FREE_NON_NULL (FullCwd);
return (SHELL_OUT_OF_RESOURCES);
}
//
// Go through the list of files and directories to move...
//
for (Node = (EFI_SHELL_FILE_INFO *)GetFirstNode(&FileList->Link)
; !IsNull(&FileList->Link, &Node->Link)
; Node = (EFI_SHELL_FILE_INFO *)GetNextNode(&FileList->Link, &Node->Link)
){
if (ShellGetExecutionBreakFlag()) {
for (Node = (EFI_SHELL_FILE_INFO *)GetFirstNode (&FileList->Link)
; !IsNull (&FileList->Link, &Node->Link)
; Node = (EFI_SHELL_FILE_INFO *)GetNextNode (&FileList->Link, &Node->Link)
)
{
if (ShellGetExecutionBreakFlag ()) {
break;
}
//
// These should never be NULL
//
ASSERT(Node->FileName != NULL);
ASSERT(Node->FullName != NULL);
ASSERT(Node->Info != NULL);
ASSERT (Node->FileName != NULL);
ASSERT (Node->FullName != NULL);
ASSERT (Node->Info != NULL);
//
// skip the directory traversing stuff...
//
if (StrCmp(Node->FileName, L".") == 0 || StrCmp(Node->FileName, L"..") == 0) {
if ((StrCmp (Node->FileName, L".") == 0) || (StrCmp (Node->FileName, L"..") == 0)) {
continue;
}
SHELL_FREE_NON_NULL(FullDestPath);
SHELL_FREE_NON_NULL (FullDestPath);
FullDestPath = NULL;
if (ShellIsDirectory(DestPath)==EFI_SUCCESS) {
CreateFullDestPath((CONST CHAR16 **)&DestPath, &FullDestPath, Node->FileName);
if (ShellIsDirectory (DestPath) == EFI_SUCCESS) {
CreateFullDestPath ((CONST CHAR16 **)&DestPath, &FullDestPath, Node->FileName);
}
//
// Validate that the move is valid
//
if (!IsValidMove(Node->FullName, FullCwd, FullDestPath!=NULL? FullDestPath:DestPath, Node->Info->Attribute, Attr, Node->Status)) {
if (!IsValidMove (Node->FullName, FullCwd, (FullDestPath != NULL) ? FullDestPath : DestPath, Node->Info->Attribute, Attr, Node->Status)) {
ShellStatus = SHELL_INVALID_PARAMETER;
continue;
}
ShellPrintEx(-1, -1, HiiOutput, Node->FullName, FullDestPath!=NULL? FullDestPath:DestPath);
ShellPrintEx (-1, -1, HiiOutput, Node->FullName, FullDestPath != NULL ? FullDestPath : DestPath);
//
// See if destination exists
//
if (!EFI_ERROR(ShellFileExists(FullDestPath!=NULL? FullDestPath:DestPath))) {
if (!EFI_ERROR (ShellFileExists ((FullDestPath != NULL) ? FullDestPath : DestPath))) {
if (Response == NULL) {
ShellPromptForResponseHii(ShellPromptResponseTypeYesNoAllCancel, STRING_TOKEN (STR_GEN_DEST_EXIST_OVR), gShellLevel2HiiHandle, &Response);
ShellPromptForResponseHii (ShellPromptResponseTypeYesNoAllCancel, STRING_TOKEN (STR_GEN_DEST_EXIST_OVR), gShellLevel2HiiHandle, &Response);
}
if (Response == NULL) {
return SHELL_ABORTED;
}
switch (*(SHELL_PROMPT_RESPONSE*)Response) {
switch (*(SHELL_PROMPT_RESPONSE *)Response) {
case ShellPromptResponseNo:
FreePool(Response);
FreePool (Response);
Response = NULL;
continue;
case ShellPromptResponseCancel:
@ -650,42 +677,44 @@ ValidateAndMoveFiles(
//
// indicate to stop everything
//
SHELL_FREE_NON_NULL(FullCwd);
SHELL_FREE_NON_NULL (FullCwd);
return (SHELL_ABORTED);
case ShellPromptResponseAll:
*Resp = Response;
break;
case ShellPromptResponseYes:
FreePool(Response);
FreePool (Response);
Response = NULL;
break;
default:
FreePool(Response);
SHELL_FREE_NON_NULL(FullCwd);
FreePool (Response);
SHELL_FREE_NON_NULL (FullCwd);
return SHELL_ABORTED;
}
Status = ShellDeleteFileByName(FullDestPath!=NULL? FullDestPath:DestPath);
Status = ShellDeleteFileByName (FullDestPath != NULL ? FullDestPath : DestPath);
}
if (IsBetweenFileSystem(Node->FullName, FullCwd, DestPath)) {
while (FullDestPath == NULL && DestPath != NULL && DestPath[0] != CHAR_NULL && DestPath[StrLen(DestPath) - 1] == L'\\') {
DestPath[StrLen(DestPath) - 1] = CHAR_NULL;
if (IsBetweenFileSystem (Node->FullName, FullCwd, 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!=NULL? FullDestPath:DestPath, &Response);
Status = MoveBetweenFileSystems (Node, FullDestPath != NULL ? FullDestPath : DestPath, &Response);
} else {
Status = MoveWithinFileSystems(Node, DestPath, &Response);
Status = MoveWithinFileSystems (Node, DestPath, &Response);
//
// Display error status
//
if (EFI_ERROR(Status)) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_ERR_UK), gShellLevel2HiiHandle, L"mv", Status);
if (EFI_ERROR (Status)) {
ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_ERR_UK), gShellLevel2HiiHandle, L"mv", Status);
}
}
//
// Check our result
//
if (EFI_ERROR(Status)) {
if (EFI_ERROR (Status)) {
ShellStatus = SHELL_INVALID_PARAMETER;
if (Status == EFI_SECURITY_VIOLATION) {
ShellStatus = SHELL_SECURITY_VIOLATION;
@ -699,16 +728,15 @@ ValidateAndMoveFiles(
ShellStatus = SHELL_ACCESS_DENIED;
}
} else {
ShellPrintEx(-1, -1, L"%s", HiiResultOk);
ShellPrintEx (-1, -1, L"%s", HiiResultOk);
}
} // main for loop
SHELL_FREE_NON_NULL(FullDestPath);
SHELL_FREE_NON_NULL(DestPath);
SHELL_FREE_NON_NULL(HiiOutput);
SHELL_FREE_NON_NULL(HiiResultOk);
SHELL_FREE_NON_NULL(FullCwd);
SHELL_FREE_NON_NULL (FullDestPath);
SHELL_FREE_NON_NULL (DestPath);
SHELL_FREE_NON_NULL (HiiOutput);
SHELL_FREE_NON_NULL (HiiResultOk);
SHELL_FREE_NON_NULL (FullCwd);
return (ShellStatus);
}
@ -725,76 +753,76 @@ ShellCommandRunMv (
IN EFI_SYSTEM_TABLE *SystemTable
)
{
EFI_STATUS Status;
LIST_ENTRY *Package;
CHAR16 *ProblemParam;
CHAR16 *Cwd;
UINTN CwdSize;
SHELL_STATUS ShellStatus;
UINTN ParamCount;
UINTN LoopCounter;
EFI_SHELL_FILE_INFO *FileList;
VOID *Response;
EFI_STATUS Status;
LIST_ENTRY *Package;
CHAR16 *ProblemParam;
CHAR16 *Cwd;
UINTN CwdSize;
SHELL_STATUS ShellStatus;
UINTN ParamCount;
UINTN LoopCounter;
EFI_SHELL_FILE_INFO *FileList;
VOID *Response;
ProblemParam = NULL;
ShellStatus = SHELL_SUCCESS;
ParamCount = 0;
FileList = NULL;
Response = NULL;
ProblemParam = NULL;
ShellStatus = SHELL_SUCCESS;
ParamCount = 0;
FileList = NULL;
Response = NULL;
//
// initialize the shell lib (we must be in non-auto-init...)
//
Status = ShellInitialize();
ASSERT_EFI_ERROR(Status);
Status = ShellInitialize ();
ASSERT_EFI_ERROR (Status);
//
// parse the command line
//
Status = ShellCommandLineParse (EmptyParamList, &Package, &ProblemParam, TRUE);
if (EFI_ERROR(Status)) {
if (Status == EFI_VOLUME_CORRUPTED && ProblemParam != NULL) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellLevel2HiiHandle, L"mv", ProblemParam);
FreePool(ProblemParam);
if (EFI_ERROR (Status)) {
if ((Status == EFI_VOLUME_CORRUPTED) && (ProblemParam != NULL)) {
ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellLevel2HiiHandle, L"mv", ProblemParam);
FreePool (ProblemParam);
ShellStatus = SHELL_INVALID_PARAMETER;
} else {
ASSERT(FALSE);
ASSERT (FALSE);
}
} else {
//
// check for "-?"
//
if (ShellCommandLineGetFlag(Package, L"-?")) {
ASSERT(FALSE);
if (ShellCommandLineGetFlag (Package, L"-?")) {
ASSERT (FALSE);
}
switch (ParamCount = ShellCommandLineGetCount(Package)) {
switch (ParamCount = ShellCommandLineGetCount (Package)) {
case 0:
case 1:
//
// we have insufficient parameters
//
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_FEW), gShellLevel2HiiHandle, L"mv");
ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_FEW), gShellLevel2HiiHandle, L"mv");
ShellStatus = SHELL_INVALID_PARAMETER;
break;
case 2:
//
// must have valid CWD for single parameter...
//
if (ShellGetCurrentDir(NULL) == NULL){
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_NO_CWD), gShellLevel2HiiHandle, L"mv");
if (ShellGetCurrentDir (NULL) == NULL) {
ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_NO_CWD), gShellLevel2HiiHandle, L"mv");
ShellStatus = SHELL_INVALID_PARAMETER;
} else {
Status = ShellOpenFileMetaArg((CHAR16*)ShellCommandLineGetRawValue(Package, 1), EFI_FILE_MODE_WRITE|EFI_FILE_MODE_READ, &FileList);
if (FileList == NULL || IsListEmpty(&FileList->Link) || EFI_ERROR(Status)) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_FILE_NF), gShellLevel2HiiHandle, L"mv", ShellCommandLineGetRawValue(Package, 1));
Status = ShellOpenFileMetaArg ((CHAR16 *)ShellCommandLineGetRawValue (Package, 1), EFI_FILE_MODE_WRITE|EFI_FILE_MODE_READ, &FileList);
if ((FileList == NULL) || IsListEmpty (&FileList->Link) || EFI_ERROR (Status)) {
ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_FILE_NF), gShellLevel2HiiHandle, L"mv", ShellCommandLineGetRawValue (Package, 1));
ShellStatus = SHELL_NOT_FOUND;
} else {
} else {
//
// ValidateAndMoveFiles will report errors to the screen itself
//
CwdSize = StrSize(ShellGetCurrentDir(NULL)) + sizeof(CHAR16);
Cwd = AllocateZeroPool(CwdSize);
CwdSize = StrSize (ShellGetCurrentDir (NULL)) + sizeof (CHAR16);
Cwd = AllocateZeroPool (CwdSize);
if (Cwd == NULL) {
ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_OUT_MEM), gShellLevel2HiiHandle, L"mv");
ShellStatus = SHELL_OUT_OF_RESOURCES;
@ -809,39 +837,42 @@ ShellCommandRunMv (
break;
default:
///@todo make sure this works with error half way through and continues...
for (ParamCount--, LoopCounter = 1 ; LoopCounter < ParamCount ; LoopCounter++) {
if (ShellGetExecutionBreakFlag()) {
/// @todo make sure this works with error half way through and continues...
for (ParamCount--, LoopCounter = 1; LoopCounter < ParamCount; LoopCounter++) {
if (ShellGetExecutionBreakFlag ()) {
break;
}
Status = ShellOpenFileMetaArg((CHAR16*)ShellCommandLineGetRawValue(Package, LoopCounter), EFI_FILE_MODE_WRITE|EFI_FILE_MODE_READ, &FileList);
if (FileList == NULL || IsListEmpty(&FileList->Link) || EFI_ERROR(Status)) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_FILE_NF), gShellLevel2HiiHandle, L"mv", ShellCommandLineGetRawValue(Package, LoopCounter));
Status = ShellOpenFileMetaArg ((CHAR16 *)ShellCommandLineGetRawValue (Package, LoopCounter), EFI_FILE_MODE_WRITE|EFI_FILE_MODE_READ, &FileList);
if ((FileList == NULL) || IsListEmpty (&FileList->Link) || EFI_ERROR (Status)) {
ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_FILE_NF), gShellLevel2HiiHandle, L"mv", ShellCommandLineGetRawValue (Package, LoopCounter));
ShellStatus = SHELL_NOT_FOUND;
} else {
} 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));
ShellStatus = ValidateAndMoveFiles (FileList, &Response, ShellCommandLineGetRawValue (Package, ParamCount));
} else {
ValidateAndMoveFiles(FileList, &Response, ShellCommandLineGetRawValue(Package, ParamCount));
ValidateAndMoveFiles (FileList, &Response, ShellCommandLineGetRawValue (Package, ParamCount));
}
}
if (FileList != NULL && !IsListEmpty(&FileList->Link)) {
Status = ShellCloseFileMetaArg(&FileList);
if (EFI_ERROR(Status) && ShellStatus == SHELL_SUCCESS) {
if ((FileList != NULL) && !IsListEmpty (&FileList->Link)) {
Status = ShellCloseFileMetaArg (&FileList);
if (EFI_ERROR (Status) && (ShellStatus == SHELL_SUCCESS)) {
ShellStatus = SHELL_ACCESS_DENIED;
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_ERR_FILE), gShellLevel2HiiHandle, L"mv", ShellCommandLineGetRawValue(Package, 1), ShellStatus|MAX_BIT);
ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_ERR_FILE), gShellLevel2HiiHandle, L"mv", ShellCommandLineGetRawValue (Package, 1), ShellStatus|MAX_BIT);
}
}
}
break;
} // switch on parameter count
if (FileList != NULL) {
ShellCloseFileMetaArg(&FileList);
ShellCloseFileMetaArg (&FileList);
}
//
@ -850,9 +881,9 @@ ShellCommandRunMv (
ShellCommandLineFreeVarList (Package);
}
SHELL_FREE_NON_NULL(Response);
SHELL_FREE_NON_NULL (Response);
if (ShellGetExecutionBreakFlag()) {
if (ShellGetExecutionBreakFlag ()) {
return (SHELL_ABORTED);
}

View File

@ -22,24 +22,25 @@ IsStdInDataAvailable (
VOID
)
{
SHELL_FILE_HANDLE FileHandle;
EFI_STATUS Status;
CHAR16 CharBuffer;
UINTN CharSize;
UINT64 OriginalFilePosition;
SHELL_FILE_HANDLE FileHandle;
EFI_STATUS Status;
CHAR16 CharBuffer;
UINTN CharSize;
UINT64 OriginalFilePosition;
Status = EFI_SUCCESS;
FileHandle = NULL;
OriginalFilePosition = 0;
if (ShellOpenFileByName (L">i", &FileHandle, EFI_FILE_MODE_READ, 0) == EFI_SUCCESS) {
CharSize = sizeof(CHAR16);
CharSize = sizeof (CHAR16);
gEfiShellProtocol->GetFilePosition (FileHandle, &OriginalFilePosition);
Status = gEfiShellProtocol->ReadFile (FileHandle, &CharSize, &CharBuffer);
if (EFI_ERROR (Status) || (CharSize != sizeof(CHAR16))) {
if (EFI_ERROR (Status) || (CharSize != sizeof (CHAR16))) {
return FALSE;
}
gEfiShellProtocol->SetFilePosition(FileHandle, OriginalFilePosition);
gEfiShellProtocol->SetFilePosition (FileHandle, OriginalFilePosition);
}
if (FileHandle == NULL) {
@ -78,15 +79,17 @@ HandleStringWithEscapeCharForParse (
if (NewStr == NULL) {
return NULL;
}
ReturnStr = NewStr;
StrWalker = String;
while (*StrWalker != CHAR_NULL) {
if (*StrWalker == L'^' && (*(StrWalker + 1) == L'^' || *(StrWalker + 1) == L'"')) {
if ((*StrWalker == L'^') && ((*(StrWalker + 1) == L'^') || (*(StrWalker + 1) == L'"'))) {
*NewStr = *(StrWalker + 1);
StrWalker++;
} else {
*NewStr = *StrWalker;
}
StrWalker++;
NewStr++;
}
@ -94,7 +97,6 @@ HandleStringWithEscapeCharForParse (
return ReturnStr;
}
/**
Do the actual parsing of the file. the file should be SFO output from a
shell command or a similar format.
@ -110,44 +112,44 @@ HandleStringWithEscapeCharForParse (
@retval SHELL_SUCCESS The operation was successful.
**/
SHELL_STATUS
PerformParsing(
IN CONST CHAR16 *FileName,
IN CONST CHAR16 *TableName,
IN CONST UINTN ColumnIndex,
IN CONST UINTN TableNameInstance,
IN CONST UINTN ShellCommandInstance,
IN BOOLEAN StreamingUnicode
PerformParsing (
IN CONST CHAR16 *FileName,
IN CONST CHAR16 *TableName,
IN CONST UINTN ColumnIndex,
IN CONST UINTN TableNameInstance,
IN CONST UINTN ShellCommandInstance,
IN BOOLEAN StreamingUnicode
)
{
SHELL_FILE_HANDLE FileHandle;
EFI_STATUS Status;
BOOLEAN Ascii;
UINTN LoopVariable;
UINTN ColumnLoop;
CHAR16 *TempLine;
CHAR16 *ColumnPointer;
SHELL_STATUS ShellStatus;
CHAR16 *TempSpot;
CHAR16 *SfoString;
SHELL_FILE_HANDLE FileHandle;
EFI_STATUS Status;
BOOLEAN Ascii;
UINTN LoopVariable;
UINTN ColumnLoop;
CHAR16 *TempLine;
CHAR16 *ColumnPointer;
SHELL_STATUS ShellStatus;
CHAR16 *TempSpot;
CHAR16 *SfoString;
ASSERT(FileName != NULL);
ASSERT(TableName != NULL);
ASSERT (FileName != NULL);
ASSERT (TableName != NULL);
ShellStatus = SHELL_SUCCESS;
ShellStatus = SHELL_SUCCESS;
Status = ShellOpenFileByName(FileName, &FileHandle, EFI_FILE_MODE_READ, 0);
if (EFI_ERROR(Status)) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_FILE_OPEN_FAIL), gShellLevel2HiiHandle, L"parse", FileName);
Status = ShellOpenFileByName (FileName, &FileHandle, EFI_FILE_MODE_READ, 0);
if (EFI_ERROR (Status)) {
ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_FILE_OPEN_FAIL), gShellLevel2HiiHandle, L"parse", FileName);
ShellStatus = SHELL_NOT_FOUND;
} else if (!EFI_ERROR (FileHandleIsDirectory (FileHandle))) {
ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_NOT_FILE), gShellLevel2HiiHandle, L"parse", FileName);
ShellStatus = SHELL_NOT_FOUND;
} else {
for (LoopVariable = 0 ; LoopVariable < ShellCommandInstance && !ShellFileHandleEof(FileHandle);) {
TempLine = ShellFileHandleReturnLine (FileHandle, &Ascii);
for (LoopVariable = 0; LoopVariable < ShellCommandInstance && !ShellFileHandleEof (FileHandle);) {
TempLine = ShellFileHandleReturnLine (FileHandle, &Ascii);
if ((TempLine == NULL) || (*TempLine == CHAR_NULL && StreamingUnicode)) {
break;
if ((TempLine == NULL) || ((*TempLine == CHAR_NULL) && StreamingUnicode)) {
break;
}
//
@ -158,46 +160,56 @@ PerformParsing(
if (StrStr (TempLine, L"ShellCommand,") == TempLine) {
LoopVariable++;
}
SHELL_FREE_NON_NULL(TempLine);
SHELL_FREE_NON_NULL (TempLine);
}
if (LoopVariable == ShellCommandInstance) {
LoopVariable = 0;
while(1) {
while (1) {
TempLine = ShellFileHandleReturnLine (FileHandle, &Ascii);
if (TempLine == NULL
|| *TempLine == CHAR_NULL
|| StrStr (TempLine, L"ShellCommand,") == TempLine) {
SHELL_FREE_NON_NULL(TempLine);
if ( (TempLine == NULL)
|| (*TempLine == CHAR_NULL)
|| (StrStr (TempLine, L"ShellCommand,") == TempLine))
{
SHELL_FREE_NON_NULL (TempLine);
break;
}
if (StrStr (TempLine, TableName) == TempLine) {
LoopVariable++;
if (LoopVariable == TableNameInstance
|| (TableNameInstance == (UINTN)-1)) {
if ( (LoopVariable == TableNameInstance)
|| (TableNameInstance == (UINTN)-1))
{
for (ColumnLoop = 1, ColumnPointer = TempLine; ColumnLoop < ColumnIndex && ColumnPointer != NULL && *ColumnPointer != CHAR_NULL; ColumnLoop++) {
ColumnPointer = StrStr (ColumnPointer, L",\"");
if (ColumnPointer != NULL && *ColumnPointer != CHAR_NULL){
if ((ColumnPointer != NULL) && (*ColumnPointer != CHAR_NULL)) {
ColumnPointer++;
}
}
if (ColumnLoop == ColumnIndex) {
if (ColumnPointer == NULL) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_NO_VALUE), gShellLevel2HiiHandle, L"parse", L"Column Index");
ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_NO_VALUE), gShellLevel2HiiHandle, L"parse", L"Column Index");
ShellStatus = SHELL_INVALID_PARAMETER;
} else {
TempSpot = StrStr (ColumnPointer, L",\"");
if (TempSpot != NULL) {
*TempSpot = CHAR_NULL;
}
while (ColumnPointer != NULL && *ColumnPointer != CHAR_NULL && ColumnPointer[0] == L' '){
while (ColumnPointer != NULL && *ColumnPointer != CHAR_NULL && ColumnPointer[0] == L' ') {
ColumnPointer++;
}
if (ColumnPointer != NULL && *ColumnPointer != CHAR_NULL && ColumnPointer[0] == L'\"'){
if ((ColumnPointer != NULL) && (*ColumnPointer != CHAR_NULL) && (ColumnPointer[0] == L'\"')) {
ColumnPointer++;
}
if (ColumnPointer != NULL && *ColumnPointer != CHAR_NULL && ColumnPointer[StrLen (ColumnPointer) - 1] == L'\"'){
if ((ColumnPointer != NULL) && (*ColumnPointer != CHAR_NULL) && (ColumnPointer[StrLen (ColumnPointer) - 1] == L'\"')) {
ColumnPointer[StrLen (ColumnPointer) - 1] = CHAR_NULL;
}
SfoString = HandleStringWithEscapeCharForParse (ColumnPointer);
if (SfoString != NULL) {
ShellPrintEx (-1, -1, L"%s\r\n", SfoString);
@ -207,18 +219,20 @@ PerformParsing(
}
}
}
SHELL_FREE_NON_NULL(TempLine);
SHELL_FREE_NON_NULL (TempLine);
}
}
}
return (ShellStatus);
}
STATIC CONST SHELL_PARAM_ITEM ParamList[] = {
{L"-i", TypeValue},
{L"-s", TypeValue},
{NULL, TypeMax}
};
STATIC CONST SHELL_PARAM_ITEM ParamList[] = {
{ L"-i", TypeValue },
{ L"-s", TypeValue },
{ NULL, TypeMax }
};
/**
Function for 'parse' command.
@ -233,16 +247,16 @@ ShellCommandRunParse (
IN EFI_SYSTEM_TABLE *SystemTable
)
{
EFI_STATUS Status;
LIST_ENTRY *Package;
CHAR16 *ProblemParam;
CONST CHAR16 *FileName;
CONST CHAR16 *TableName;
CONST CHAR16 *ColumnString;
SHELL_STATUS ShellStatus;
UINTN ShellCommandInstance;
UINTN TableNameInstance;
BOOLEAN StreamingUnicode;
EFI_STATUS Status;
LIST_ENTRY *Package;
CHAR16 *ProblemParam;
CONST CHAR16 *FileName;
CONST CHAR16 *TableName;
CONST CHAR16 *ColumnString;
SHELL_STATUS ShellStatus;
UINTN ShellCommandInstance;
UINTN TableNameInstance;
BOOLEAN StreamingUnicode;
ShellStatus = SHELL_SUCCESS;
ProblemParam = NULL;
@ -251,53 +265,57 @@ ShellCommandRunParse (
//
// initialize the shell lib (we must be in non-auto-init...)
//
Status = ShellInitialize();
ASSERT_EFI_ERROR(Status);
Status = ShellInitialize ();
ASSERT_EFI_ERROR (Status);
//
// parse the command line
//
Status = ShellCommandLineParseEx (ParamList, &Package, &ProblemParam, TRUE, FALSE);
if (EFI_ERROR(Status)) {
if (Status == EFI_VOLUME_CORRUPTED && ProblemParam != NULL) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellLevel2HiiHandle, L"parse", ProblemParam);
FreePool(ProblemParam);
if (EFI_ERROR (Status)) {
if ((Status == EFI_VOLUME_CORRUPTED) && (ProblemParam != NULL)) {
ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellLevel2HiiHandle, L"parse", ProblemParam);
FreePool (ProblemParam);
ShellStatus = SHELL_INVALID_PARAMETER;
} else {
ASSERT(FALSE);
ASSERT (FALSE);
}
} else {
StreamingUnicode = IsStdInDataAvailable ();
if ((!StreamingUnicode && (ShellCommandLineGetCount(Package) < 4)) ||
(ShellCommandLineGetCount(Package) < 3)) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_FEW), gShellLevel2HiiHandle, L"parse");
if ((!StreamingUnicode && (ShellCommandLineGetCount (Package) < 4)) ||
(ShellCommandLineGetCount (Package) < 3))
{
ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_FEW), gShellLevel2HiiHandle, L"parse");
ShellStatus = SHELL_INVALID_PARAMETER;
} else if ((StreamingUnicode && (ShellCommandLineGetCount(Package) > 3)) ||
(ShellCommandLineGetCount(Package) > 4)) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_MANY), gShellLevel2HiiHandle, L"parse");
} else if ((StreamingUnicode && (ShellCommandLineGetCount (Package) > 3)) ||
(ShellCommandLineGetCount (Package) > 4))
{
ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_MANY), gShellLevel2HiiHandle, L"parse");
ShellStatus = SHELL_INVALID_PARAMETER;
} else {
if (StreamingUnicode) {
FileName = L">i";
TableName = ShellCommandLineGetRawValue(Package, 1);
ColumnString = ShellCommandLineGetRawValue(Package, 2);
FileName = L">i";
TableName = ShellCommandLineGetRawValue (Package, 1);
ColumnString = ShellCommandLineGetRawValue (Package, 2);
} else {
FileName = ShellCommandLineGetRawValue(Package, 1);
TableName = ShellCommandLineGetRawValue(Package, 2);
ColumnString = ShellCommandLineGetRawValue(Package, 3);
}
if (ShellCommandLineGetValue(Package, L"-i") == NULL) {
TableNameInstance = (UINTN)-1;
} else {
TableNameInstance = ShellStrToUintn(ShellCommandLineGetValue(Package, L"-i"));
}
if (ShellCommandLineGetValue(Package, L"-s") == NULL) {
ShellCommandInstance = 1;
} else {
ShellCommandInstance = ShellStrToUintn(ShellCommandLineGetValue(Package, L"-s"));
FileName = ShellCommandLineGetRawValue (Package, 1);
TableName = ShellCommandLineGetRawValue (Package, 2);
ColumnString = ShellCommandLineGetRawValue (Package, 3);
}
ShellStatus = PerformParsing(FileName, TableName, ShellStrToUintn(ColumnString), TableNameInstance, ShellCommandInstance, StreamingUnicode);
if (ShellCommandLineGetValue (Package, L"-i") == NULL) {
TableNameInstance = (UINTN)-1;
} else {
TableNameInstance = ShellStrToUintn (ShellCommandLineGetValue (Package, L"-i"));
}
if (ShellCommandLineGetValue (Package, L"-s") == NULL) {
ShellCommandInstance = 1;
} else {
ShellCommandInstance = ShellStrToUintn (ShellCommandLineGetValue (Package, L"-s"));
}
ShellStatus = PerformParsing (FileName, TableName, ShellStrToUintn (ColumnString), TableNameInstance, ShellCommandInstance, StreamingUnicode);
}
}
@ -308,4 +326,3 @@ ShellCommandRunParse (
return (ShellStatus);
}

View File

@ -9,13 +9,13 @@
#include "UefiShellLevel2CommandsLib.h"
STATIC CONST SHELL_PARAM_ITEM ResetParamList[] = {
{L"-w", TypeValue},
{L"-s", TypeValue},
{L"-c", TypeValue},
{L"-fwui", TypeFlag },
{NULL, TypeMax }
};
STATIC CONST SHELL_PARAM_ITEM ResetParamList[] = {
{ L"-w", TypeValue },
{ L"-s", TypeValue },
{ L"-c", TypeValue },
{ L"-fwui", TypeFlag },
{ NULL, TypeMax }
};
/**
Function for 'reset' command.
@ -39,64 +39,72 @@ ShellCommandRunReset (
UINT32 Attr;
UINTN DataSize;
ShellStatus = SHELL_SUCCESS;
ShellStatus = SHELL_SUCCESS;
ProblemParam = NULL;
//
// initialize the shell lib (we must be in non-auto-init...)
//
Status = ShellInitialize();
ASSERT_EFI_ERROR(Status);
Status = ShellInitialize ();
ASSERT_EFI_ERROR (Status);
//
// parse the command line
//
Status = ShellCommandLineParse (ResetParamList, &Package, &ProblemParam, TRUE);
if (EFI_ERROR(Status)) {
if (Status == EFI_VOLUME_CORRUPTED && ProblemParam != NULL) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellLevel2HiiHandle, L"reset", ProblemParam);
FreePool(ProblemParam);
if (EFI_ERROR (Status)) {
if ((Status == EFI_VOLUME_CORRUPTED) && (ProblemParam != NULL)) {
ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellLevel2HiiHandle, L"reset", ProblemParam);
FreePool (ProblemParam);
return (SHELL_INVALID_PARAMETER);
} else {
ASSERT(FALSE);
ASSERT (FALSE);
}
} else {
//
// check for "-?"
//
if (ShellCommandLineGetFlag(Package, L"-?")) {
ASSERT(FALSE);
} else if (ShellCommandLineGetRawValue(Package, 1) != NULL) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_MANY), gShellLevel2HiiHandle, L"reset");
if (ShellCommandLineGetFlag (Package, L"-?")) {
ASSERT (FALSE);
} else if (ShellCommandLineGetRawValue (Package, 1) != NULL) {
ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_MANY), gShellLevel2HiiHandle, L"reset");
ShellStatus = SHELL_INVALID_PARAMETER;
} else {
if (ShellCommandLineGetFlag (Package, L"-fwui")) {
DataSize = sizeof (OsIndications);
Status = gRT->GetVariable (
EFI_OS_INDICATIONS_SUPPORT_VARIABLE_NAME, &gEfiGlobalVariableGuid,
&Attr, &DataSize, &OsIndications
);
DataSize = sizeof (OsIndications);
Status = gRT->GetVariable (
EFI_OS_INDICATIONS_SUPPORT_VARIABLE_NAME,
&gEfiGlobalVariableGuid,
&Attr,
&DataSize,
&OsIndications
);
if (!EFI_ERROR (Status)) {
if ((OsIndications & EFI_OS_INDICATIONS_BOOT_TO_FW_UI) != 0) {
DataSize = sizeof (OsIndications);
Status = gRT->GetVariable (
EFI_OS_INDICATIONS_VARIABLE_NAME, &gEfiGlobalVariableGuid,
&Attr, &DataSize, &OsIndications
);
Status = gRT->GetVariable (
EFI_OS_INDICATIONS_VARIABLE_NAME,
&gEfiGlobalVariableGuid,
&Attr,
&DataSize,
&OsIndications
);
if (!EFI_ERROR (Status)) {
OsIndications |= EFI_OS_INDICATIONS_BOOT_TO_FW_UI;
} else {
OsIndications = EFI_OS_INDICATIONS_BOOT_TO_FW_UI;
}
Status = gRT->SetVariable (
EFI_OS_INDICATIONS_VARIABLE_NAME, &gEfiGlobalVariableGuid,
EFI_OS_INDICATIONS_VARIABLE_NAME,
&gEfiGlobalVariableGuid,
EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,
sizeof (OsIndications), &OsIndications
sizeof (OsIndications),
&OsIndications
);
}
}
if (EFI_ERROR (Status)) {
ShellStatus = SHELL_UNSUPPORTED;
goto Error;
@ -106,40 +114,42 @@ ShellCommandRunReset (
//
// check for warm reset flag, then shutdown reset flag, then cold (default) reset flag
//
if (ShellCommandLineGetFlag(Package, L"-w")) {
if (ShellCommandLineGetFlag(Package, L"-s") || ShellCommandLineGetFlag(Package, L"-c")) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_MANY), gShellLevel2HiiHandle, L"reset");
if (ShellCommandLineGetFlag (Package, L"-w")) {
if (ShellCommandLineGetFlag (Package, L"-s") || ShellCommandLineGetFlag (Package, L"-c")) {
ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_MANY), gShellLevel2HiiHandle, L"reset");
ShellStatus = SHELL_INVALID_PARAMETER;
} else {
String = ShellCommandLineGetValue(Package, L"-w");
String = ShellCommandLineGetValue (Package, L"-w");
if (String != NULL) {
gRT->ResetSystem(EfiResetWarm, EFI_SUCCESS, StrSize(String), (VOID*)String);
gRT->ResetSystem (EfiResetWarm, EFI_SUCCESS, StrSize (String), (VOID *)String);
} else {
gRT->ResetSystem(EfiResetWarm, EFI_SUCCESS, 0, NULL);
gRT->ResetSystem (EfiResetWarm, EFI_SUCCESS, 0, NULL);
}
}
} else if (ShellCommandLineGetFlag(Package, L"-s")) {
if (ShellCommandLineGetFlag(Package, L"-c")) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_MANY), gShellLevel2HiiHandle, L"reset");
} else if (ShellCommandLineGetFlag (Package, L"-s")) {
if (ShellCommandLineGetFlag (Package, L"-c")) {
ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_MANY), gShellLevel2HiiHandle, L"reset");
ShellStatus = SHELL_INVALID_PARAMETER;
} else {
String = ShellCommandLineGetValue(Package, L"-s");
DEBUG_CODE(ShellPrintEx(-1,-1,L"Reset with %s (%d bytes)", String, String!=NULL?StrSize(String):0););
String = ShellCommandLineGetValue (Package, L"-s");
DEBUG_CODE (
ShellPrintEx (-1, -1, L"Reset with %s (%d bytes)", String, String != NULL ? StrSize (String) : 0);
);
if (String != NULL) {
gRT->ResetSystem(EfiResetShutdown, EFI_SUCCESS, StrSize(String), (VOID*)String);
gRT->ResetSystem (EfiResetShutdown, EFI_SUCCESS, StrSize (String), (VOID *)String);
} else {
gRT->ResetSystem(EfiResetShutdown, EFI_SUCCESS, 0, NULL);
gRT->ResetSystem (EfiResetShutdown, EFI_SUCCESS, 0, NULL);
}
}
} else {
//
// this is default so dont worry about flag...
//
String = ShellCommandLineGetValue(Package, L"-c");
String = ShellCommandLineGetValue (Package, L"-c");
if (String != NULL) {
gRT->ResetSystem(EfiResetCold, EFI_SUCCESS, StrSize(String), (VOID*)String);
gRT->ResetSystem (EfiResetCold, EFI_SUCCESS, StrSize (String), (VOID *)String);
} else {
gRT->ResetSystem(EfiResetCold, EFI_SUCCESS, 0, NULL);
gRT->ResetSystem (EfiResetCold, EFI_SUCCESS, 0, NULL);
}
}
}
@ -161,4 +171,3 @@ Error:
//
return (ShellStatus);
}

View File

@ -9,10 +9,10 @@
#include "UefiShellLevel2CommandsLib.h"
STATIC CONST SHELL_PARAM_ITEM ParamList[] = {
{L"-q", TypeFlag},
{NULL, TypeMax}
};
STATIC CONST SHELL_PARAM_ITEM ParamList[] = {
{ L"-q", TypeFlag },
{ NULL, TypeMax }
};
/**
Determine if a directory has no files in it.
@ -24,27 +24,30 @@ STATIC CONST SHELL_PARAM_ITEM ParamList[] = {
**/
BOOLEAN
IsDirectoryEmpty (
IN SHELL_FILE_HANDLE FileHandle
IN SHELL_FILE_HANDLE FileHandle
)
{
EFI_STATUS Status;
EFI_FILE_INFO *FileInfo;
BOOLEAN NoFile;
BOOLEAN RetVal;
EFI_STATUS Status;
EFI_FILE_INFO *FileInfo;
BOOLEAN NoFile;
BOOLEAN RetVal;
RetVal = TRUE;
NoFile = FALSE;
RetVal = TRUE;
NoFile = FALSE;
FileInfo = NULL;
for (Status = FileHandleFindFirstFile(FileHandle, &FileInfo)
; !NoFile && !EFI_ERROR (Status)
; FileHandleFindNextFile(FileHandle, FileInfo, &NoFile)
){
if (StrStr(FileInfo->FileName, L".") != FileInfo->FileName
&&StrStr(FileInfo->FileName, L"..") != FileInfo->FileName) {
for (Status = FileHandleFindFirstFile (FileHandle, &FileInfo)
; !NoFile && !EFI_ERROR (Status)
; FileHandleFindNextFile (FileHandle, FileInfo, &NoFile)
)
{
if ( (StrStr (FileInfo->FileName, L".") != FileInfo->FileName)
&& (StrStr (FileInfo->FileName, L"..") != FileInfo->FileName))
{
RetVal = FALSE;
}
}
return (RetVal);
}
@ -60,75 +63,81 @@ IsDirectoryEmpty (
@retval SHELL_DEVICE_ERROR A device error occurred reading this Node.
**/
SHELL_STATUS
CascadeDelete(
CascadeDelete (
IN EFI_SHELL_FILE_INFO *Node,
IN CONST BOOLEAN Quiet
)
{
SHELL_STATUS ShellStatus;
EFI_SHELL_FILE_INFO *List;
EFI_SHELL_FILE_INFO *Node2;
EFI_STATUS Status;
SHELL_PROMPT_RESPONSE *Resp;
CHAR16 *TempName;
UINTN NewSize;
SHELL_STATUS ShellStatus;
EFI_SHELL_FILE_INFO *List;
EFI_SHELL_FILE_INFO *Node2;
EFI_STATUS Status;
SHELL_PROMPT_RESPONSE *Resp;
CHAR16 *TempName;
UINTN NewSize;
Resp = NULL;
ShellStatus = SHELL_SUCCESS;
List = NULL;
Status = EFI_SUCCESS;
Resp = NULL;
ShellStatus = SHELL_SUCCESS;
List = NULL;
Status = EFI_SUCCESS;
if ((Node->Info->Attribute & EFI_FILE_READ_ONLY) == EFI_FILE_READ_ONLY) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_RM_LOG_DETELE_RO), gShellLevel2HiiHandle, L"rm", Node->FullName);
ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_RM_LOG_DETELE_RO), gShellLevel2HiiHandle, L"rm", Node->FullName);
return (SHELL_ACCESS_DENIED);
}
if ((Node->Info->Attribute & EFI_FILE_DIRECTORY) == EFI_FILE_DIRECTORY) {
if (!IsDirectoryEmpty(Node->Handle)) {
if (!IsDirectoryEmpty (Node->Handle)) {
if (!Quiet) {
Status = ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN(STR_RM_LOG_DELETE_CONF), gShellLevel2HiiHandle, Node->FullName);
Status = ShellPromptForResponse(ShellPromptResponseTypeYesNo, NULL, (VOID**)&Resp);
ASSERT(Resp != NULL);
if (EFI_ERROR(Status) || *Resp != ShellPromptResponseYes) {
SHELL_FREE_NON_NULL(Resp);
Status = ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_RM_LOG_DELETE_CONF), gShellLevel2HiiHandle, Node->FullName);
Status = ShellPromptForResponse (ShellPromptResponseTypeYesNo, NULL, (VOID **)&Resp);
ASSERT (Resp != NULL);
if (EFI_ERROR (Status) || (*Resp != ShellPromptResponseYes)) {
SHELL_FREE_NON_NULL (Resp);
return (SHELL_ABORTED);
}
SHELL_FREE_NON_NULL(Resp);
SHELL_FREE_NON_NULL (Resp);
}
//
// empty out the directory
//
Status = gEfiShellProtocol->FindFilesInDir(Node->Handle, &List);
if (EFI_ERROR(Status)) {
if (List!=NULL) {
gEfiShellProtocol->FreeFileList(&List);
Status = gEfiShellProtocol->FindFilesInDir (Node->Handle, &List);
if (EFI_ERROR (Status)) {
if (List != NULL) {
gEfiShellProtocol->FreeFileList (&List);
}
return (SHELL_DEVICE_ERROR);
}
for (Node2 = (EFI_SHELL_FILE_INFO *)GetFirstNode(&List->Link)
; !IsNull(&List->Link, &Node2->Link)
; Node2 = (EFI_SHELL_FILE_INFO *)GetNextNode(&List->Link, &Node2->Link)
){
for (Node2 = (EFI_SHELL_FILE_INFO *)GetFirstNode (&List->Link)
; !IsNull (&List->Link, &Node2->Link)
; Node2 = (EFI_SHELL_FILE_INFO *)GetNextNode (&List->Link, &Node2->Link)
)
{
//
// skip the directory traversing stuff...
//
if (StrCmp(Node2->FileName, L".") == 0 || StrCmp(Node2->FileName, L"..") == 0) {
if ((StrCmp (Node2->FileName, L".") == 0) || (StrCmp (Node2->FileName, L"..") == 0)) {
continue;
}
Node2->Status = gEfiShellProtocol->OpenFileByName (Node2->FullName, &Node2->Handle, EFI_FILE_MODE_READ|EFI_FILE_MODE_WRITE);
if (EFI_ERROR(Node2->Status) && StrStr(Node2->FileName, L":") == NULL) {
if (EFI_ERROR (Node2->Status) && (StrStr (Node2->FileName, L":") == NULL)) {
//
// Update the node filename to have full path with file system identifier
//
NewSize = StrSize(Node->FullName) + StrSize(Node2->FullName);
TempName = AllocateZeroPool(NewSize);
NewSize = StrSize (Node->FullName) + StrSize (Node2->FullName);
TempName = AllocateZeroPool (NewSize);
if (TempName == NULL) {
ShellStatus = SHELL_OUT_OF_RESOURCES;
} else {
StrCpyS(TempName, NewSize/sizeof(CHAR16), Node->FullName);
TempName[StrStr(TempName, L":")+1-TempName] = CHAR_NULL;
StrCatS(TempName, NewSize/sizeof(CHAR16), Node2->FullName);
FreePool((VOID*)Node2->FullName);
StrCpyS (TempName, NewSize/sizeof (CHAR16), Node->FullName);
TempName[StrStr (TempName, L":")+1-TempName] = CHAR_NULL;
StrCatS (TempName, NewSize/sizeof (CHAR16), Node2->FullName);
FreePool ((VOID *)Node2->FullName);
Node2->FullName = TempName;
//
@ -137,45 +146,51 @@ CascadeDelete(
Node2->Status = gEfiShellProtocol->OpenFileByName (Node2->FullName, &Node2->Handle, EFI_FILE_MODE_READ|EFI_FILE_MODE_WRITE);
}
}
if (!EFI_ERROR(Node2->Status)) {
ShellStatus = CascadeDelete(Node2, Quiet);
if (!EFI_ERROR (Node2->Status)) {
ShellStatus = CascadeDelete (Node2, Quiet);
} else if (ShellStatus == SHELL_SUCCESS) {
ShellStatus = (SHELL_STATUS)(Node2->Status&(~0x80000000));
}
if (ShellStatus != SHELL_SUCCESS) {
if (List!=NULL) {
gEfiShellProtocol->FreeFileList(&List);
if (List != NULL) {
gEfiShellProtocol->FreeFileList (&List);
}
return (ShellStatus);
}
}
if (List!=NULL) {
gEfiShellProtocol->FreeFileList(&List);
if (List != NULL) {
gEfiShellProtocol->FreeFileList (&List);
}
}
}
if (!(StrCmp(Node->FileName, L".") == 0 || StrCmp(Node->FileName, L"..") == 0)) {
if (!((StrCmp (Node->FileName, L".") == 0) || (StrCmp (Node->FileName, L"..") == 0))) {
//
// now delete the current node...
//
if (!Quiet) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_RM_LOG_DELETE), gShellLevel2HiiHandle, Node->FullName);
ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_RM_LOG_DELETE), gShellLevel2HiiHandle, Node->FullName);
}
Status = gEfiShellProtocol->DeleteFile(Node->Handle);
Status = gEfiShellProtocol->DeleteFile (Node->Handle);
Node->Handle = NULL;
}
//
// We cant allow for the warning here! (Dont use EFI_ERROR Macro).
//
if (Status != EFI_SUCCESS){
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_RM_LOG_DELETE_ERR), gShellLevel2HiiHandle, Status);
if (Status != EFI_SUCCESS) {
ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_RM_LOG_DELETE_ERR), gShellLevel2HiiHandle, Status);
return (SHELL_ACCESS_DENIED);
} else {
if (!Quiet) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_RM_LOG_DELETE_COMP), gShellLevel2HiiHandle);
ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_RM_LOG_DELETE_COMP), gShellLevel2HiiHandle);
}
return (SHELL_SUCCESS);
}
}
@ -188,31 +203,31 @@ CascadeDelete(
@param[in] Package RESERVED. Not used.
**/
BOOLEAN
IsValidDeleteTarget(
IsValidDeleteTarget (
IN CONST EFI_SHELL_FILE_INFO *List,
IN CONST EFI_SHELL_FILE_INFO *Node,
IN CONST LIST_ENTRY *Package
)
{
CONST CHAR16 *TempLocation;
BOOLEAN RetVal;
CHAR16 *SearchString;
CHAR16 *Pattern;
UINTN Size;
CONST CHAR16 *TempLocation;
BOOLEAN RetVal;
CHAR16 *SearchString;
CHAR16 *Pattern;
UINTN Size;
if (Node == NULL || Node->FullName == NULL) {
if ((Node == NULL) || (Node->FullName == NULL)) {
return (FALSE);
}
TempLocation = StrStr(Node->FullName, L":");
if (StrLen(TempLocation) <= 2) {
TempLocation = StrStr (Node->FullName, L":");
if (StrLen (TempLocation) <= 2) {
//
// Deleting the root directory is invalid.
//
return (FALSE);
}
TempLocation = ShellGetCurrentDir(NULL);
TempLocation = ShellGetCurrentDir (NULL);
if (TempLocation == NULL) {
//
// No working directory is specified so whatever is left is ok.
@ -220,29 +235,29 @@ IsValidDeleteTarget(
return (TRUE);
}
Pattern = NULL;
SearchString = NULL;
Size = 0;
Pattern = StrnCatGrow(&Pattern, &Size, TempLocation , 0);
Pattern = StrnCatGrow(&Pattern, &Size, L"\\" , 0);
Size = 0;
SearchString = StrnCatGrow(&SearchString, &Size, Node->FullName, 0);
if (!EFI_ERROR(ShellIsDirectory(SearchString))) {
SearchString = StrnCatGrow(&SearchString, &Size, L"\\", 0);
SearchString = StrnCatGrow(&SearchString, &Size, L"*", 0);
Pattern = NULL;
SearchString = NULL;
Size = 0;
Pattern = StrnCatGrow (&Pattern, &Size, TempLocation, 0);
Pattern = StrnCatGrow (&Pattern, &Size, L"\\", 0);
Size = 0;
SearchString = StrnCatGrow (&SearchString, &Size, Node->FullName, 0);
if (!EFI_ERROR (ShellIsDirectory (SearchString))) {
SearchString = StrnCatGrow (&SearchString, &Size, L"\\", 0);
SearchString = StrnCatGrow (&SearchString, &Size, L"*", 0);
}
if (Pattern == NULL || SearchString == NULL) {
if ((Pattern == NULL) || (SearchString == NULL)) {
RetVal = FALSE;
} else {
RetVal = TRUE;
if (gUnicodeCollation->MetaiMatch(gUnicodeCollation, Pattern, SearchString)) {
if (gUnicodeCollation->MetaiMatch (gUnicodeCollation, Pattern, SearchString)) {
RetVal = FALSE;
}
}
SHELL_FREE_NON_NULL(Pattern );
SHELL_FREE_NON_NULL(SearchString);
SHELL_FREE_NON_NULL (Pattern);
SHELL_FREE_NON_NULL (SearchString);
return (RetVal);
}
@ -260,106 +275,112 @@ ShellCommandRunRm (
IN EFI_SYSTEM_TABLE *SystemTable
)
{
EFI_STATUS Status;
LIST_ENTRY *Package;
CHAR16 *ProblemParam;
CONST CHAR16 *Param;
SHELL_STATUS ShellStatus;
UINTN ParamCount;
EFI_SHELL_FILE_INFO *FileList;
EFI_SHELL_FILE_INFO *Node;
EFI_STATUS Status;
LIST_ENTRY *Package;
CHAR16 *ProblemParam;
CONST CHAR16 *Param;
SHELL_STATUS ShellStatus;
UINTN ParamCount;
EFI_SHELL_FILE_INFO *FileList;
EFI_SHELL_FILE_INFO *Node;
ProblemParam = NULL;
ShellStatus = SHELL_SUCCESS;
ParamCount = 0;
FileList = NULL;
ProblemParam = NULL;
ShellStatus = SHELL_SUCCESS;
ParamCount = 0;
FileList = NULL;
//
// initialize the shell lib (we must be in non-auto-init...)
//
Status = ShellInitialize();
ASSERT_EFI_ERROR(Status);
Status = ShellInitialize ();
ASSERT_EFI_ERROR (Status);
//
// parse the command line
//
Status = ShellCommandLineParse (ParamList, &Package, &ProblemParam, TRUE);
if (EFI_ERROR(Status)) {
if (Status == EFI_VOLUME_CORRUPTED && ProblemParam != NULL) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellLevel2HiiHandle, L"rm", ProblemParam);
FreePool(ProblemParam);
if (EFI_ERROR (Status)) {
if ((Status == EFI_VOLUME_CORRUPTED) && (ProblemParam != NULL)) {
ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellLevel2HiiHandle, L"rm", ProblemParam);
FreePool (ProblemParam);
ShellStatus = SHELL_INVALID_PARAMETER;
} else {
ASSERT(FALSE);
ASSERT (FALSE);
}
} else {
//
// check for "-?"
//
if (ShellCommandLineGetFlag(Package, L"-?")) {
ASSERT(FALSE);
if (ShellCommandLineGetFlag (Package, L"-?")) {
ASSERT (FALSE);
}
if (ShellCommandLineGetRawValue(Package, 1) == NULL) {
if (ShellCommandLineGetRawValue (Package, 1) == NULL) {
//
// we insufficient parameters
//
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_FEW), gShellLevel2HiiHandle, L"rm");
ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_FEW), gShellLevel2HiiHandle, L"rm");
ShellStatus = SHELL_INVALID_PARAMETER;
} else {
//
// get a list with each file specified by parameters
// if parameter is a directory then add all the files below it to the list
//
for ( ParamCount = 1, Param = ShellCommandLineGetRawValue(Package, ParamCount)
; Param != NULL
; ParamCount++, Param = ShellCommandLineGetRawValue(Package, ParamCount)
){
Status = ShellOpenFileMetaArg((CHAR16*)Param, EFI_FILE_MODE_WRITE|EFI_FILE_MODE_READ, &FileList);
if (EFI_ERROR(Status) || FileList == NULL || IsListEmpty(&FileList->Link)) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_FILE_NF), gShellLevel2HiiHandle, L"rm", (CHAR16*)Param);
for ( ParamCount = 1, Param = ShellCommandLineGetRawValue (Package, ParamCount)
; Param != NULL
; ParamCount++, Param = ShellCommandLineGetRawValue (Package, ParamCount)
)
{
Status = ShellOpenFileMetaArg ((CHAR16 *)Param, EFI_FILE_MODE_WRITE|EFI_FILE_MODE_READ, &FileList);
if (EFI_ERROR (Status) || (FileList == NULL) || IsListEmpty (&FileList->Link)) {
ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_FILE_NF), gShellLevel2HiiHandle, L"rm", (CHAR16 *)Param);
ShellStatus = SHELL_NOT_FOUND;
break;
}
}
if (ShellStatus == SHELL_SUCCESS){
if (ShellStatus == SHELL_SUCCESS) {
//
// loop through the list and make sure we are not aborting...
//
for ( Node = (EFI_SHELL_FILE_INFO*)GetFirstNode(&FileList->Link)
; !IsNull(&FileList->Link, &Node->Link) && !ShellGetExecutionBreakFlag()
; Node = (EFI_SHELL_FILE_INFO*)GetNextNode(&FileList->Link, &Node->Link)
){
for ( Node = (EFI_SHELL_FILE_INFO *)GetFirstNode (&FileList->Link)
; !IsNull (&FileList->Link, &Node->Link) && !ShellGetExecutionBreakFlag ()
; Node = (EFI_SHELL_FILE_INFO *)GetNextNode (&FileList->Link, &Node->Link)
)
{
//
// skip the directory traversing stuff...
//
if (StrCmp(Node->FileName, L".") == 0 || StrCmp(Node->FileName, L"..") == 0) {
if ((StrCmp (Node->FileName, L".") == 0) || (StrCmp (Node->FileName, L"..") == 0)) {
continue;
}
//
// do the deleting of nodes
//
if (EFI_ERROR(Node->Status)){
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_RM_LOG_DELETE_ERR2), gShellLevel2HiiHandle, Node->Status);
if (EFI_ERROR (Node->Status)) {
ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_RM_LOG_DELETE_ERR2), gShellLevel2HiiHandle, Node->Status);
ShellStatus = SHELL_ACCESS_DENIED;
break;
}
if (!IsValidDeleteTarget(FileList, Node, Package)) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_RM_LOG_DELETE_ERR3), gShellLevel2HiiHandle, Node->FullName);
if (!IsValidDeleteTarget (FileList, Node, Package)) {
ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_RM_LOG_DELETE_ERR3), gShellLevel2HiiHandle, Node->FullName);
ShellStatus = SHELL_INVALID_PARAMETER;
break;
}
ShellStatus = CascadeDelete(Node, ShellCommandLineGetFlag(Package, L"-q"));
ShellStatus = CascadeDelete (Node, ShellCommandLineGetFlag (Package, L"-q"));
}
}
//
// Free the fileList
//
if (FileList != NULL) {
Status = ShellCloseFileMetaArg(&FileList);
Status = ShellCloseFileMetaArg (&FileList);
}
FileList = NULL;
}
@ -371,4 +392,3 @@ ShellCommandRunRm (
return (ShellStatus);
}

View File

@ -18,31 +18,32 @@
@return any return code from GetNextVariableName except EFI_NOT_FOUND
**/
SHELL_STATUS
PrintAllShellEnvVars(
PrintAllShellEnvVars (
VOID
)
{
CONST CHAR16 *Value;
CONST CHAR16 *ConstEnvNameList;
CONST CHAR16 *Value;
CONST CHAR16 *ConstEnvNameList;
ConstEnvNameList = gEfiShellProtocol->GetEnv(NULL);
ConstEnvNameList = gEfiShellProtocol->GetEnv (NULL);
if (ConstEnvNameList == NULL) {
return (SHELL_SUCCESS);
}
while (*ConstEnvNameList != CHAR_NULL){
Value = gEfiShellProtocol->GetEnv(ConstEnvNameList);
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SET_DISP), gShellLevel2HiiHandle, ConstEnvNameList, Value);
ConstEnvNameList += StrLen(ConstEnvNameList)+1;
while (*ConstEnvNameList != CHAR_NULL) {
Value = gEfiShellProtocol->GetEnv (ConstEnvNameList);
ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_SET_DISP), gShellLevel2HiiHandle, ConstEnvNameList, Value);
ConstEnvNameList += StrLen (ConstEnvNameList)+1;
}
return (SHELL_SUCCESS);
}
STATIC CONST SHELL_PARAM_ITEM SetParamList[] = {
{L"-d", TypeValue},
{L"-v", TypeFlag},
{NULL, TypeMax}
};
STATIC CONST SHELL_PARAM_ITEM SetParamList[] = {
{ L"-d", TypeValue },
{ L"-v", TypeFlag },
{ NULL, TypeMax }
};
/**
Function for 'set' command.
@ -70,90 +71,89 @@ ShellCommandRunSet (
//
// initialize the shell lib (we must be in non-auto-init...)
//
Status = ShellInitialize();
ASSERT_EFI_ERROR(Status);
Status = ShellInitialize ();
ASSERT_EFI_ERROR (Status);
//
// Make sure globals are good...
//
Status = CommandInit();
ASSERT_EFI_ERROR(Status);
Status = CommandInit ();
ASSERT_EFI_ERROR (Status);
//
// parse the command line
//
Status = ShellCommandLineParse (SetParamList, &Package, &ProblemParam, TRUE);
if (EFI_ERROR(Status)) {
if (Status == EFI_VOLUME_CORRUPTED && ProblemParam != NULL) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellLevel2HiiHandle, L"set", ProblemParam);
FreePool(ProblemParam);
if (EFI_ERROR (Status)) {
if ((Status == EFI_VOLUME_CORRUPTED) && (ProblemParam != NULL)) {
ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellLevel2HiiHandle, L"set", ProblemParam);
FreePool (ProblemParam);
return (SHELL_INVALID_PARAMETER);
} else {
ASSERT(FALSE);
ASSERT (FALSE);
}
} else {
//
// check for "-?"
//
if (ShellCommandLineGetFlag(Package, L"-?")) {
ASSERT(FALSE);
} else if (ShellCommandLineGetRawValue(Package, 3) != NULL) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_MANY), gShellLevel2HiiHandle, L"set");
if (ShellCommandLineGetFlag (Package, L"-?")) {
ASSERT (FALSE);
} else if (ShellCommandLineGetRawValue (Package, 3) != NULL) {
ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_MANY), gShellLevel2HiiHandle, L"set");
ShellStatus = SHELL_INVALID_PARAMETER;
} else if (ShellCommandLineGetRawValue(Package, 1) != NULL && ShellCommandLineGetFlag(Package, L"-d")) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_MANY), gShellLevel2HiiHandle, L"set");
} else if ((ShellCommandLineGetRawValue (Package, 1) != NULL) && ShellCommandLineGetFlag (Package, L"-d")) {
ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_MANY), gShellLevel2HiiHandle, L"set");
ShellStatus = SHELL_INVALID_PARAMETER;
} else if (ShellCommandLineGetFlag(Package, L"-d")) {
} else if (ShellCommandLineGetFlag (Package, L"-d")) {
//
// delete a environment variable
//
KeyName = ShellCommandLineGetValue(Package, L"-d");
KeyName = ShellCommandLineGetValue (Package, L"-d");
if (KeyName == NULL) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_NO_VALUE), gShellLevel2HiiHandle, L"set", L"-d");
ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_NO_VALUE), gShellLevel2HiiHandle, L"set", L"-d");
ShellStatus = SHELL_INVALID_PARAMETER;
} else {
Status = ShellSetEnvironmentVariable(KeyName, L"", ShellCommandLineGetFlag(Package, L"-v"));
if (EFI_ERROR(Status)) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SET_ND), gShellLevel2HiiHandle, L"set", KeyName);
Status = ShellSetEnvironmentVariable (KeyName, L"", ShellCommandLineGetFlag (Package, L"-v"));
if (EFI_ERROR (Status)) {
ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_SET_ND), gShellLevel2HiiHandle, L"set", KeyName);
ShellStatus = SHELL_DEVICE_ERROR;
}
}
} else if (ShellCommandLineGetRawValue(Package, 1) == NULL) {
} else if (ShellCommandLineGetRawValue (Package, 1) == NULL) {
//
// print out all current environment variables
//
return(PrintAllShellEnvVars());
return (PrintAllShellEnvVars ());
} else {
//
// we are either printing one or assigning one
//
KeyName = ShellCommandLineGetRawValue(Package, 1);
Value = ShellCommandLineGetRawValue(Package, 2);
if (KeyName != NULL && Value != NULL) {
KeyName = ShellCommandLineGetRawValue (Package, 1);
Value = ShellCommandLineGetRawValue (Package, 2);
if ((KeyName != NULL) && (Value != NULL)) {
//
// assigning one
//
Status = ShellSetEnvironmentVariable(KeyName, Value, ShellCommandLineGetFlag(Package, L"-v"));
if (EFI_ERROR(Status)) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SET_ERROR_SET), gShellLevel2HiiHandle, L"set", KeyName);
ShellStatus = (SHELL_STATUS) (Status & (~MAX_BIT));
Status = ShellSetEnvironmentVariable (KeyName, Value, ShellCommandLineGetFlag (Package, L"-v"));
if (EFI_ERROR (Status)) {
ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_SET_ERROR_SET), gShellLevel2HiiHandle, L"set", KeyName);
ShellStatus = (SHELL_STATUS)(Status & (~MAX_BIT));
}
} else {
if (KeyName != NULL) {
//
// print out value for this one only.
//
Value = ShellGetEnvironmentVariable(KeyName);
Value = ShellGetEnvironmentVariable (KeyName);
if (Value == NULL) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SET_NF), gShellLevel2HiiHandle, L"set", KeyName);
ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_SET_NF), gShellLevel2HiiHandle, L"set", KeyName);
ShellStatus = SHELL_SUCCESS;
} else {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SET_DISP), gShellLevel2HiiHandle, KeyName, Value);
ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_SET_DISP), gShellLevel2HiiHandle, KeyName, Value);
ShellStatus = SHELL_SUCCESS;
}
} else {
ASSERT(FALSE);
ASSERT (FALSE);
}
}
}

File diff suppressed because it is too large Load Diff

View File

@ -28,15 +28,15 @@
**/
#include "UefiShellLevel2CommandsLib.h"
CONST CHAR16 mFileName[] = L"ShellCommands";
EFI_HII_HANDLE gShellLevel2HiiHandle = NULL;
CONST CHAR16 mFileName[] = L"ShellCommands";
EFI_HII_HANDLE gShellLevel2HiiHandle = NULL;
/**
Get the filename to get help text from if not using HII.
@retval The filename.
**/
CONST CHAR16*
CONST CHAR16 *
EFIAPI
ShellCommandGetManFileNameLevel2 (
VOID
@ -66,7 +66,7 @@ ShellLevel2CommandsLibConstructor (
//
// if shell level is less than 2 do nothing
//
if (PcdGet8(PcdShellSupportLevel) < 2) {
if (PcdGet8 (PcdShellSupportLevel) < 2) {
return (EFI_SUCCESS);
}
@ -78,48 +78,48 @@ ShellLevel2CommandsLibConstructor (
//
// install our shell command handlers that are always installed
//
ShellCommandRegisterCommandName(L"attrib", ShellCommandRunAttrib , ShellCommandGetManFileNameLevel2, 2, L"", TRUE, gShellLevel2HiiHandle, STRING_TOKEN(STR_GET_HELP_ATTRIB) );
ShellCommandRegisterCommandName(L"cd", ShellCommandRunCd , ShellCommandGetManFileNameLevel2, 2, L"", TRUE, gShellLevel2HiiHandle, STRING_TOKEN(STR_GET_HELP_CD) );
ShellCommandRegisterCommandName(L"cp", ShellCommandRunCp , ShellCommandGetManFileNameLevel2, 2, L"", TRUE, gShellLevel2HiiHandle, STRING_TOKEN(STR_GET_HELP_CP) );
ShellCommandRegisterCommandName(L"load", ShellCommandRunLoad , ShellCommandGetManFileNameLevel2, 2, L"", TRUE, gShellLevel2HiiHandle, STRING_TOKEN(STR_GET_HELP_LOAD) );
ShellCommandRegisterCommandName(L"map", ShellCommandRunMap , ShellCommandGetManFileNameLevel2, 2, L"", TRUE, gShellLevel2HiiHandle, STRING_TOKEN(STR_GET_HELP_MAP) );
ShellCommandRegisterCommandName(L"mkdir", ShellCommandRunMkDir , ShellCommandGetManFileNameLevel2, 2, L"", TRUE, gShellLevel2HiiHandle, STRING_TOKEN(STR_GET_HELP_MKDIR) );
ShellCommandRegisterCommandName(L"mv", ShellCommandRunMv , ShellCommandGetManFileNameLevel2, 2, L"", TRUE, gShellLevel2HiiHandle, STRING_TOKEN(STR_GET_HELP_MV) );
ShellCommandRegisterCommandName(L"parse", ShellCommandRunParse , ShellCommandGetManFileNameLevel2, 2, L"", TRUE, gShellLevel2HiiHandle, STRING_TOKEN(STR_GET_HELP_PARSE) );
ShellCommandRegisterCommandName(L"reset", ShellCommandRunReset , ShellCommandGetManFileNameLevel2, 2, L"", TRUE, gShellLevel2HiiHandle, STRING_TOKEN(STR_GET_HELP_RESET) );
ShellCommandRegisterCommandName(L"set", ShellCommandRunSet , ShellCommandGetManFileNameLevel2, 2, L"",FALSE, gShellLevel2HiiHandle, STRING_TOKEN(STR_GET_HELP_SET) );
ShellCommandRegisterCommandName(L"ls", ShellCommandRunLs , ShellCommandGetManFileNameLevel2, 2, L"", TRUE, gShellLevel2HiiHandle, STRING_TOKEN(STR_GET_HELP_LS) );
ShellCommandRegisterCommandName(L"rm", ShellCommandRunRm , ShellCommandGetManFileNameLevel2, 2, L"", TRUE, gShellLevel2HiiHandle, STRING_TOKEN(STR_GET_HELP_RM) );
ShellCommandRegisterCommandName(L"vol", ShellCommandRunVol , ShellCommandGetManFileNameLevel2, 2, L"", TRUE, gShellLevel2HiiHandle, STRING_TOKEN(STR_GET_HELP_VOL) );
ShellCommandRegisterCommandName (L"attrib", ShellCommandRunAttrib, ShellCommandGetManFileNameLevel2, 2, L"", TRUE, gShellLevel2HiiHandle, STRING_TOKEN (STR_GET_HELP_ATTRIB));
ShellCommandRegisterCommandName (L"cd", ShellCommandRunCd, ShellCommandGetManFileNameLevel2, 2, L"", TRUE, gShellLevel2HiiHandle, STRING_TOKEN (STR_GET_HELP_CD));
ShellCommandRegisterCommandName (L"cp", ShellCommandRunCp, ShellCommandGetManFileNameLevel2, 2, L"", TRUE, gShellLevel2HiiHandle, STRING_TOKEN (STR_GET_HELP_CP));
ShellCommandRegisterCommandName (L"load", ShellCommandRunLoad, ShellCommandGetManFileNameLevel2, 2, L"", TRUE, gShellLevel2HiiHandle, STRING_TOKEN (STR_GET_HELP_LOAD));
ShellCommandRegisterCommandName (L"map", ShellCommandRunMap, ShellCommandGetManFileNameLevel2, 2, L"", TRUE, gShellLevel2HiiHandle, STRING_TOKEN (STR_GET_HELP_MAP));
ShellCommandRegisterCommandName (L"mkdir", ShellCommandRunMkDir, ShellCommandGetManFileNameLevel2, 2, L"", TRUE, gShellLevel2HiiHandle, STRING_TOKEN (STR_GET_HELP_MKDIR));
ShellCommandRegisterCommandName (L"mv", ShellCommandRunMv, ShellCommandGetManFileNameLevel2, 2, L"", TRUE, gShellLevel2HiiHandle, STRING_TOKEN (STR_GET_HELP_MV));
ShellCommandRegisterCommandName (L"parse", ShellCommandRunParse, ShellCommandGetManFileNameLevel2, 2, L"", TRUE, gShellLevel2HiiHandle, STRING_TOKEN (STR_GET_HELP_PARSE));
ShellCommandRegisterCommandName (L"reset", ShellCommandRunReset, ShellCommandGetManFileNameLevel2, 2, L"", TRUE, gShellLevel2HiiHandle, STRING_TOKEN (STR_GET_HELP_RESET));
ShellCommandRegisterCommandName (L"set", ShellCommandRunSet, ShellCommandGetManFileNameLevel2, 2, L"", FALSE, gShellLevel2HiiHandle, STRING_TOKEN (STR_GET_HELP_SET));
ShellCommandRegisterCommandName (L"ls", ShellCommandRunLs, ShellCommandGetManFileNameLevel2, 2, L"", TRUE, gShellLevel2HiiHandle, STRING_TOKEN (STR_GET_HELP_LS));
ShellCommandRegisterCommandName (L"rm", ShellCommandRunRm, ShellCommandGetManFileNameLevel2, 2, L"", TRUE, gShellLevel2HiiHandle, STRING_TOKEN (STR_GET_HELP_RM));
ShellCommandRegisterCommandName (L"vol", ShellCommandRunVol, ShellCommandGetManFileNameLevel2, 2, L"", TRUE, gShellLevel2HiiHandle, STRING_TOKEN (STR_GET_HELP_VOL));
//
// support for permanent (built in) aliases
//
ShellCommandRegisterAlias(L"rm", L"del");
ShellCommandRegisterAlias(L"ls", L"dir");
ShellCommandRegisterAlias(L"cp", L"copy");
ShellCommandRegisterAlias(L"mkdir", L"md");
ShellCommandRegisterAlias(L"cd ..", L"cd..");
ShellCommandRegisterAlias(L"cd \\", L"cd\\");
ShellCommandRegisterAlias(L"mv", L"ren");
ShellCommandRegisterAlias(L"mv", L"move");
ShellCommandRegisterAlias(L"map", L"mount");
ShellCommandRegisterAlias (L"rm", L"del");
ShellCommandRegisterAlias (L"ls", L"dir");
ShellCommandRegisterAlias (L"cp", L"copy");
ShellCommandRegisterAlias (L"mkdir", L"md");
ShellCommandRegisterAlias (L"cd ..", L"cd..");
ShellCommandRegisterAlias (L"cd \\", L"cd\\");
ShellCommandRegisterAlias (L"mv", L"ren");
ShellCommandRegisterAlias (L"mv", L"move");
ShellCommandRegisterAlias (L"map", L"mount");
//
// These are installed in level 2 or 3...
//
if (PcdGet8(PcdShellSupportLevel) == 2 || PcdGet8(PcdShellSupportLevel) == 3) {
ShellCommandRegisterCommandName(L"date", ShellCommandRunDate , ShellCommandGetManFileNameLevel2, PcdGet8(PcdShellSupportLevel), L"", TRUE, gShellLevel2HiiHandle, STRING_TOKEN(STR_GET_HELP_DATE) );
ShellCommandRegisterCommandName(L"time", ShellCommandRunTime , ShellCommandGetManFileNameLevel2, PcdGet8(PcdShellSupportLevel), L"", TRUE, gShellLevel2HiiHandle, STRING_TOKEN(STR_GET_HELP_TIME) );
ShellCommandRegisterCommandName(L"timezone", ShellCommandRunTimeZone, ShellCommandGetManFileNameLevel2, PcdGet8(PcdShellSupportLevel), L"", TRUE, gShellLevel2HiiHandle, STRING_TOKEN(STR_GET_HELP_TIMEZONE));
if ((PcdGet8 (PcdShellSupportLevel) == 2) || (PcdGet8 (PcdShellSupportLevel) == 3)) {
ShellCommandRegisterCommandName (L"date", ShellCommandRunDate, ShellCommandGetManFileNameLevel2, PcdGet8 (PcdShellSupportLevel), L"", TRUE, gShellLevel2HiiHandle, STRING_TOKEN (STR_GET_HELP_DATE));
ShellCommandRegisterCommandName (L"time", ShellCommandRunTime, ShellCommandGetManFileNameLevel2, PcdGet8 (PcdShellSupportLevel), L"", TRUE, gShellLevel2HiiHandle, STRING_TOKEN (STR_GET_HELP_TIME));
ShellCommandRegisterCommandName (L"timezone", ShellCommandRunTimeZone, ShellCommandGetManFileNameLevel2, PcdGet8 (PcdShellSupportLevel), L"", TRUE, gShellLevel2HiiHandle, STRING_TOKEN (STR_GET_HELP_TIMEZONE));
} else {
DEBUG_CODE_BEGIN();
DEBUG_CODE_BEGIN ();
//
// we want to be able to test these so install them under a different name in debug mode...
//
ShellCommandRegisterCommandName(L"l2date", ShellCommandRunDate , ShellCommandGetManFileNameLevel2, 2, L"", TRUE, gShellLevel2HiiHandle, STRING_TOKEN(STR_GET_HELP_DATE) );
ShellCommandRegisterCommandName(L"l2time", ShellCommandRunTime , ShellCommandGetManFileNameLevel2, 2, L"", TRUE, gShellLevel2HiiHandle, STRING_TOKEN(STR_GET_HELP_TIME) );
ShellCommandRegisterCommandName(L"l2timezone", ShellCommandRunTimeZone, ShellCommandGetManFileNameLevel2, 2, L"", TRUE, gShellLevel2HiiHandle, STRING_TOKEN(STR_GET_HELP_TIMEZONE));
DEBUG_CODE_END();
ShellCommandRegisterCommandName (L"l2date", ShellCommandRunDate, ShellCommandGetManFileNameLevel2, 2, L"", TRUE, gShellLevel2HiiHandle, STRING_TOKEN (STR_GET_HELP_DATE));
ShellCommandRegisterCommandName (L"l2time", ShellCommandRunTime, ShellCommandGetManFileNameLevel2, 2, L"", TRUE, gShellLevel2HiiHandle, STRING_TOKEN (STR_GET_HELP_TIME));
ShellCommandRegisterCommandName (L"l2timezone", ShellCommandRunTimeZone, ShellCommandGetManFileNameLevel2, 2, L"", TRUE, gShellLevel2HiiHandle, STRING_TOKEN (STR_GET_HELP_TIMEZONE));
DEBUG_CODE_END ();
}
return (EFI_SUCCESS);
@ -141,8 +141,9 @@ ShellLevel2CommandsLibDestructor (
)
{
if (gShellLevel2HiiHandle != NULL) {
HiiRemovePackages(gShellLevel2HiiHandle);
HiiRemovePackages (gShellLevel2HiiHandle);
}
return (EFI_SUCCESS);
}
@ -162,40 +163,41 @@ ShellLevel2CommandsLibDestructor (
@retval NULL A fully qualified path could not be discovered.
@retval other An allocated pointer to a fuly qualified path.
**/
CHAR16*
GetFullyQualifiedPath(
IN CONST CHAR16* Path
CHAR16 *
GetFullyQualifiedPath (
IN CONST CHAR16 *Path
)
{
CHAR16 *PathToReturn;
UINTN Size;
CONST CHAR16 *CurDir;
PathToReturn = NULL;
Size = 0;
PathToReturn = NULL;
Size = 0;
ASSERT((PathToReturn == NULL && Size == 0) || (PathToReturn != NULL));
ASSERT ((PathToReturn == NULL && Size == 0) || (PathToReturn != NULL));
//
// convert a local path to an absolute path
//
if (StrStr(Path, L":") == NULL) {
CurDir = gEfiShellProtocol->GetCurDir(NULL);
StrnCatGrow(&PathToReturn, &Size, CurDir, 0);
StrnCatGrow(&PathToReturn, &Size, L"\\", 0);
if (StrStr (Path, L":") == NULL) {
CurDir = gEfiShellProtocol->GetCurDir (NULL);
StrnCatGrow (&PathToReturn, &Size, CurDir, 0);
StrnCatGrow (&PathToReturn, &Size, L"\\", 0);
if (*Path == L'\\') {
Path++;
}
}
StrnCatGrow(&PathToReturn, &Size, Path, 0);
PathCleanUpDirectories(PathToReturn);
StrnCatGrow (&PathToReturn, &Size, Path, 0);
PathCleanUpDirectories (PathToReturn);
if (PathToReturn == NULL) {
return NULL;
}
while (PathToReturn[StrLen(PathToReturn)-1] == L'*') {
PathToReturn[StrLen(PathToReturn)-1] = CHAR_NULL;
while (PathToReturn[StrLen (PathToReturn)-1] == L'*') {
PathToReturn[StrLen (PathToReturn)-1] = CHAR_NULL;
}
return (PathToReturn);
@ -210,46 +212,47 @@ GetFullyQualifiedPath(
**/
EFI_STATUS
VerifyIntermediateDirectories (
IN CONST CHAR16 *Path
IN CONST CHAR16 *Path
)
{
EFI_STATUS Status;
CHAR16 *PathCopy;
CHAR16 *TempSpot;
SHELL_FILE_HANDLE FileHandle;
EFI_STATUS Status;
CHAR16 *PathCopy;
CHAR16 *TempSpot;
SHELL_FILE_HANDLE FileHandle;
ASSERT(Path != NULL);
ASSERT (Path != NULL);
Status = EFI_SUCCESS;
PathCopy = NULL;
PathCopy = StrnCatGrow(&PathCopy, NULL, Path, 0);
FileHandle = NULL;
Status = EFI_SUCCESS;
PathCopy = NULL;
PathCopy = StrnCatGrow (&PathCopy, NULL, Path, 0);
FileHandle = NULL;
if (PathCopy == NULL) {
return (EFI_OUT_OF_RESOURCES);
}
for (TempSpot = &PathCopy[StrLen(PathCopy)-1] ; *TempSpot != CHAR_NULL && *TempSpot != L'\\' ; TempSpot = &PathCopy[StrLen(PathCopy)-1]){
for (TempSpot = &PathCopy[StrLen (PathCopy)-1]; *TempSpot != CHAR_NULL && *TempSpot != L'\\'; TempSpot = &PathCopy[StrLen (PathCopy)-1]) {
*TempSpot = CHAR_NULL;
}
if (*TempSpot == L'\\') {
*TempSpot = CHAR_NULL;
}
if (PathCopy != NULL && *PathCopy != CHAR_NULL) {
Status = VerifyIntermediateDirectories(PathCopy);
if ((PathCopy != NULL) && (*PathCopy != CHAR_NULL)) {
Status = VerifyIntermediateDirectories (PathCopy);
if (PathCopy[StrLen(PathCopy)-1] != L':') {
if (!EFI_ERROR(Status)) {
Status = ShellOpenFileByName(PathCopy, &FileHandle, EFI_FILE_MODE_READ, 0);
if (PathCopy[StrLen (PathCopy)-1] != L':') {
if (!EFI_ERROR (Status)) {
Status = ShellOpenFileByName (PathCopy, &FileHandle, EFI_FILE_MODE_READ, 0);
if (FileHandle != NULL) {
ShellCloseFile(&FileHandle);
ShellCloseFile (&FileHandle);
}
}
}
}
SHELL_FREE_NON_NULL(PathCopy);
SHELL_FREE_NON_NULL (PathCopy);
return (Status);
}
@ -266,17 +269,17 @@ VerifyIntermediateDirectories (
**/
INTN
StrniCmp(
IN CONST CHAR16 *Source,
IN CONST CHAR16 *Target,
IN CONST UINTN Count
StrniCmp (
IN CONST CHAR16 *Source,
IN CONST CHAR16 *Target,
IN CONST UINTN Count
)
{
CHAR16 *SourceCopy;
CHAR16 *TargetCopy;
UINTN SourceLength;
UINTN TargetLength;
INTN Result;
CHAR16 *SourceCopy;
CHAR16 *TargetCopy;
UINTN SourceLength;
UINTN TargetLength;
INTN Result;
if (Count == 0) {
return 0;
@ -286,10 +289,11 @@ StrniCmp(
TargetLength = StrLen (Target);
SourceLength = MIN (SourceLength, Count);
TargetLength = MIN (TargetLength, Count);
SourceCopy = AllocateCopyPool ((SourceLength + 1) * sizeof (CHAR16), Source);
SourceCopy = AllocateCopyPool ((SourceLength + 1) * sizeof (CHAR16), Source);
if (SourceCopy == NULL) {
return -1;
}
TargetCopy = AllocateCopyPool ((TargetLength + 1) * sizeof (CHAR16), Target);
if (TargetCopy == NULL) {
FreePool (SourceCopy);
@ -298,13 +302,12 @@ StrniCmp(
SourceCopy[SourceLength] = L'\0';
TargetCopy[TargetLength] = L'\0';
Result = gUnicodeCollation->StriColl (gUnicodeCollation, SourceCopy, TargetCopy);
Result = gUnicodeCollation->StriColl (gUnicodeCollation, SourceCopy, TargetCopy);
FreePool (SourceCopy);
FreePool (TargetCopy);
return Result;
}
/**
Cleans off all the quotes in the string.
@ -317,13 +320,13 @@ StrniCmp(
**/
EFI_STATUS
ShellLevel2StripQuotes (
IN CONST CHAR16 *OriginalString,
OUT CHAR16 **CleanString
IN CONST CHAR16 *OriginalString,
OUT CHAR16 **CleanString
)
{
CHAR16 *Walker;
CHAR16 *Walker;
if (OriginalString == NULL || CleanString == NULL) {
if ((OriginalString == NULL) || (CleanString == NULL)) {
return EFI_INVALID_PARAMETER;
}
@ -332,13 +335,11 @@ ShellLevel2StripQuotes (
return EFI_OUT_OF_RESOURCES;
}
for (Walker = *CleanString; Walker != NULL && *Walker != CHAR_NULL ; Walker++) {
for (Walker = *CleanString; Walker != NULL && *Walker != CHAR_NULL; Walker++) {
if (*Walker == L'\"') {
CopyMem(Walker, Walker+1, StrSize(Walker) - sizeof(Walker[0]));
CopyMem (Walker, Walker+1, StrSize (Walker) - sizeof (Walker[0]));
}
}
return EFI_SUCCESS;
}

View File

@ -42,8 +42,8 @@
#include <Library/SortLib.h>
#include <Library/FileHandleLib.h>
extern CONST CHAR16 mFileName[];
extern EFI_HII_HANDLE gShellLevel2HiiHandle;
extern CONST CHAR16 mFileName[];
extern EFI_HII_HANDLE gShellLevel2HiiHandle;
/**
Function for 'attrib' command.
@ -256,9 +256,9 @@ ShellCommandRunMv (
@retval NULL a fully qualified path could not be discovered.
@retval other pointer to a fuly qualified path.
**/
CHAR16*
GetFullyQualifiedPath(
IN CONST CHAR16* Path
CHAR16 *
GetFullyQualifiedPath (
IN CONST CHAR16 *Path
);
/**
@ -270,7 +270,7 @@ GetFullyQualifiedPath(
**/
EFI_STATUS
VerifyIntermediateDirectories (
IN CONST CHAR16 *Path
IN CONST CHAR16 *Path
);
/**
@ -285,10 +285,10 @@ VerifyIntermediateDirectories (
**/
INTN
StrniCmp(
IN CONST CHAR16 *Source,
IN CONST CHAR16 *Target,
IN CONST UINTN Count
StrniCmp (
IN CONST CHAR16 *Source,
IN CONST CHAR16 *Target,
IN CONST UINTN Count
);
/**
@ -303,8 +303,8 @@ StrniCmp(
**/
EFI_STATUS
ShellLevel2StripQuotes (
IN CONST CHAR16 *OriginalString,
OUT CHAR16 **CleanString
IN CONST CHAR16 *OriginalString,
OUT CHAR16 **CleanString
);
/**
@ -334,12 +334,12 @@ ShellCommandRunVol (
@retval SHELL_SUCCESS The source file was copied to the destination
**/
SHELL_STATUS
CopySingleFile(
IN CONST CHAR16 *Source,
IN CONST CHAR16 *Dest,
OUT VOID **Resp,
IN BOOLEAN SilentMode,
IN CONST CHAR16 *CmdName
CopySingleFile (
IN CONST CHAR16 *Source,
IN CONST CHAR16 *Dest,
OUT VOID **Resp,
IN BOOLEAN SilentMode,
IN CONST CHAR16 *CmdName
);
/**
@ -354,10 +354,9 @@ CopySingleFile(
@retval SHELL_DEVICE_ERROR A device error occurred reading this Node.
**/
SHELL_STATUS
CascadeDelete(
CascadeDelete (
IN EFI_SHELL_FILE_INFO *Node,
IN CONST BOOLEAN Quiet
);
#endif

View File

@ -21,10 +21,10 @@
@retval SHELL_SUCCESS The operation was sucessful.
**/
SHELL_STATUS
HandleVol(
IN CONST CHAR16 *Path,
IN CONST BOOLEAN Delete,
IN CONST CHAR16 *Name OPTIONAL
HandleVol (
IN CONST CHAR16 *Path,
IN CONST BOOLEAN Delete,
IN CONST CHAR16 *Name OPTIONAL
)
{
EFI_STATUS Status;
@ -36,38 +36,40 @@ HandleVol(
UINTN Size1;
UINTN Size2;
ShellStatus = SHELL_SUCCESS;
ShellStatus = SHELL_SUCCESS;
if (
Name != NULL && (
StrStr(Name, L"%") != NULL ||
StrStr(Name, L"^") != NULL ||
StrStr(Name, L"*") != NULL ||
StrStr(Name, L"+") != NULL ||
StrStr(Name, L"=") != NULL ||
StrStr(Name, L"[") != NULL ||
StrStr(Name, L"]") != NULL ||
StrStr(Name, L"|") != NULL ||
StrStr(Name, L":") != NULL ||
StrStr(Name, L";") != NULL ||
StrStr(Name, L"\"") != NULL ||
StrStr(Name, L"<") != NULL ||
StrStr(Name, L">") != NULL ||
StrStr(Name, L"?") != NULL ||
StrStr(Name, L"/") != NULL ||
StrStr(Name, L" ") != NULL )
){
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PARAM_INV), gShellLevel2HiiHandle, L"vol", Name);
(Name != NULL) && (
(StrStr (Name, L"%") != NULL) ||
(StrStr (Name, L"^") != NULL) ||
(StrStr (Name, L"*") != NULL) ||
(StrStr (Name, L"+") != NULL) ||
(StrStr (Name, L"=") != NULL) ||
(StrStr (Name, L"[") != NULL) ||
(StrStr (Name, L"]") != NULL) ||
(StrStr (Name, L"|") != NULL) ||
(StrStr (Name, L":") != NULL) ||
(StrStr (Name, L";") != NULL) ||
(StrStr (Name, L"\"") != NULL) ||
(StrStr (Name, L"<") != NULL) ||
(StrStr (Name, L">") != NULL) ||
(StrStr (Name, L"?") != NULL) ||
(StrStr (Name, L"/") != NULL) ||
(StrStr (Name, L" ") != NULL))
)
{
ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_PARAM_INV), gShellLevel2HiiHandle, L"vol", Name);
return (SHELL_INVALID_PARAMETER);
}
Status = gEfiShellProtocol->OpenFileByName(
Path,
&ShellFileHandle,
Name != NULL?EFI_FILE_MODE_READ|EFI_FILE_MODE_WRITE:EFI_FILE_MODE_READ);
Status = gEfiShellProtocol->OpenFileByName (
Path,
&ShellFileHandle,
Name != NULL ? EFI_FILE_MODE_READ|EFI_FILE_MODE_WRITE : EFI_FILE_MODE_READ
);
if (EFI_ERROR(Status) || ShellFileHandle == NULL) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_FILE_OPEN_FAIL), gShellLevel2HiiHandle, L"vol", Path);
if (EFI_ERROR (Status) || (ShellFileHandle == NULL)) {
ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_FILE_OPEN_FAIL), gShellLevel2HiiHandle, L"vol", Path);
return (SHELL_ACCESS_DENIED);
}
@ -76,86 +78,94 @@ HandleVol(
//
SysInfo = NULL;
SysInfoSize = 0;
EfiFpHandle = ConvertShellHandleToEfiFileProtocol(ShellFileHandle);
Status = EfiFpHandle->GetInfo(
EfiFpHandle,
&gEfiFileSystemInfoGuid,
&SysInfoSize,
SysInfo);
EfiFpHandle = ConvertShellHandleToEfiFileProtocol (ShellFileHandle);
Status = EfiFpHandle->GetInfo (
EfiFpHandle,
&gEfiFileSystemInfoGuid,
&SysInfoSize,
SysInfo
);
if (Status == EFI_BUFFER_TOO_SMALL) {
SysInfo = AllocateZeroPool(SysInfoSize);
Status = EfiFpHandle->GetInfo(
EfiFpHandle,
&gEfiFileSystemInfoGuid,
&SysInfoSize,
SysInfo);
SysInfo = AllocateZeroPool (SysInfoSize);
Status = EfiFpHandle->GetInfo (
EfiFpHandle,
&gEfiFileSystemInfoGuid,
&SysInfoSize,
SysInfo
);
}
ASSERT(SysInfo != NULL);
ASSERT (SysInfo != NULL);
if (Delete) {
*((CHAR16 *) SysInfo->VolumeLabel) = CHAR_NULL;
SysInfo->Size = SIZE_OF_EFI_FILE_SYSTEM_INFO + StrSize(SysInfo->VolumeLabel);
Status = EfiFpHandle->SetInfo(
EfiFpHandle,
&gEfiFileSystemInfoGuid,
(UINTN)SysInfo->Size,
SysInfo);
*((CHAR16 *)SysInfo->VolumeLabel) = CHAR_NULL;
SysInfo->Size = SIZE_OF_EFI_FILE_SYSTEM_INFO + StrSize (SysInfo->VolumeLabel);
Status = EfiFpHandle->SetInfo (
EfiFpHandle,
&gEfiFileSystemInfoGuid,
(UINTN)SysInfo->Size,
SysInfo
);
} else if (Name != NULL) {
Size1 = StrSize(Name);
Size2 = StrSize(SysInfo->VolumeLabel);
Size1 = StrSize (Name);
Size2 = StrSize (SysInfo->VolumeLabel);
if (Size1 > Size2) {
SysInfo = ReallocatePool((UINTN)SysInfo->Size, (UINTN)SysInfo->Size + Size1 - Size2, SysInfo);
SysInfo = ReallocatePool ((UINTN)SysInfo->Size, (UINTN)SysInfo->Size + Size1 - Size2, SysInfo);
if (SysInfo == NULL) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_OUT_MEM), gShellLevel2HiiHandle, L"vol");
ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_OUT_MEM), gShellLevel2HiiHandle, L"vol");
ShellStatus = SHELL_OUT_OF_RESOURCES;
}
}
if (SysInfo != NULL) {
StrCpyS ( (CHAR16 *) SysInfo->VolumeLabel,
(Size1>Size2? Size1/sizeof(CHAR16) : Size2/sizeof(CHAR16)),
Name
);
StrCpyS (
(CHAR16 *)SysInfo->VolumeLabel,
(Size1 > Size2 ? Size1/sizeof (CHAR16) : Size2/sizeof (CHAR16)),
Name
);
SysInfo->Size = SIZE_OF_EFI_FILE_SYSTEM_INFO + Size1;
Status = EfiFpHandle->SetInfo(
EfiFpHandle,
&gEfiFileSystemInfoGuid,
(UINTN)SysInfo->Size,
SysInfo);
Status = EfiFpHandle->SetInfo (
EfiFpHandle,
&gEfiFileSystemInfoGuid,
(UINTN)SysInfo->Size,
SysInfo
);
}
}
FreePool(SysInfo);
FreePool (SysInfo);
if (Delete || Name != NULL) {
if (EFI_ERROR(Status)) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_FILE_AD), gShellLevel2HiiHandle, L"vol", Path);
if (Delete || (Name != NULL)) {
if (EFI_ERROR (Status)) {
ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_FILE_AD), gShellLevel2HiiHandle, L"vol", Path);
ShellStatus = SHELL_ACCESS_DENIED;
}
}
SysInfoSize = 0;
SysInfo = NULL;
SysInfo = NULL;
Status = EfiFpHandle->GetInfo(
EfiFpHandle,
&gEfiFileSystemInfoGuid,
&SysInfoSize,
SysInfo);
Status = EfiFpHandle->GetInfo (
EfiFpHandle,
&gEfiFileSystemInfoGuid,
&SysInfoSize,
SysInfo
);
if (Status == EFI_BUFFER_TOO_SMALL) {
SysInfo = AllocateZeroPool(SysInfoSize);
Status = EfiFpHandle->GetInfo(
EfiFpHandle,
&gEfiFileSystemInfoGuid,
&SysInfoSize,
SysInfo);
SysInfo = AllocateZeroPool (SysInfoSize);
Status = EfiFpHandle->GetInfo (
EfiFpHandle,
&gEfiFileSystemInfoGuid,
&SysInfoSize,
SysInfo
);
}
gEfiShellProtocol->CloseFile(ShellFileHandle);
gEfiShellProtocol->CloseFile (ShellFileHandle);
ASSERT(SysInfo != NULL);
ASSERT (SysInfo != NULL);
if (SysInfo != NULL) {
//
@ -168,22 +178,22 @@ HandleVol(
STRING_TOKEN (STR_VOL_VOLINFO),
gShellLevel2HiiHandle,
SysInfo->VolumeLabel,
SysInfo->ReadOnly?L"r":L"rw",
SysInfo->ReadOnly ? L"r" : L"rw",
SysInfo->VolumeSize,
SysInfo->FreeSpace,
SysInfo->BlockSize
);
SHELL_FREE_NON_NULL(SysInfo);
);
SHELL_FREE_NON_NULL (SysInfo);
}
return (ShellStatus);
}
STATIC CONST SHELL_PARAM_ITEM ParamList[] = {
{L"-d", TypeFlag},
{L"-n", TypeValue},
{NULL, TypeMax}
};
STATIC CONST SHELL_PARAM_ITEM ParamList[] = {
{ L"-d", TypeFlag },
{ L"-n", TypeValue },
{ NULL, TypeMax }
};
/**
Function for 'Vol' command.
@ -210,93 +220,96 @@ ShellCommandRunVol (
UINTN Length;
CONST CHAR16 *NewName;
Length = 0;
ProblemParam = NULL;
ShellStatus = SHELL_SUCCESS;
PathName = NULL;
CurDir = NULL;
FullPath = NULL;
Length = 0;
ProblemParam = NULL;
ShellStatus = SHELL_SUCCESS;
PathName = NULL;
CurDir = NULL;
FullPath = NULL;
//
// initialize the shell lib (we must be in non-auto-init...)
//
Status = ShellInitialize();
ASSERT_EFI_ERROR(Status);
Status = ShellInitialize ();
ASSERT_EFI_ERROR (Status);
//
// Fix local copies of the protocol pointers
//
Status = CommandInit();
ASSERT_EFI_ERROR(Status);
Status = CommandInit ();
ASSERT_EFI_ERROR (Status);
//
// parse the command line
//
Status = ShellCommandLineParse (ParamList, &Package, &ProblemParam, TRUE);
if (EFI_ERROR(Status)) {
if (Status == EFI_VOLUME_CORRUPTED && ProblemParam != NULL) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellLevel2HiiHandle, L"vol", ProblemParam);
FreePool(ProblemParam);
if (EFI_ERROR (Status)) {
if ((Status == EFI_VOLUME_CORRUPTED) && (ProblemParam != NULL)) {
ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellLevel2HiiHandle, L"vol", ProblemParam);
FreePool (ProblemParam);
ShellStatus = SHELL_INVALID_PARAMETER;
} else {
ASSERT(FALSE);
ASSERT (FALSE);
}
} else {
//
// check for "-?"
//
if (ShellCommandLineGetFlag(Package, L"-?")) {
ASSERT(FALSE);
if (ShellCommandLineGetFlag (Package, L"-?")) {
ASSERT (FALSE);
}
if (ShellCommandLineGetCount(Package) > 2) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_MANY), gShellLevel2HiiHandle, L"vol");
if (ShellCommandLineGetCount (Package) > 2) {
ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_MANY), gShellLevel2HiiHandle, L"vol");
ShellStatus = SHELL_INVALID_PARAMETER;
} else {
PathName = ShellCommandLineGetRawValue(Package, 1);
PathName = ShellCommandLineGetRawValue (Package, 1);
if (PathName == NULL) {
CurDir = gEfiShellProtocol->GetCurDir(NULL);
CurDir = gEfiShellProtocol->GetCurDir (NULL);
if (CurDir == NULL) {
ShellStatus = SHELL_NOT_FOUND;
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_NO_CWD), gShellLevel2HiiHandle, L"vol");
ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_NO_CWD), gShellLevel2HiiHandle, L"vol");
} else {
PathName = CurDir;
}
}
if (PathName != NULL) {
TempSpot = StrStr(PathName, L":");
TempSpot = StrStr (PathName, L":");
if (TempSpot != NULL) {
*TempSpot = CHAR_NULL;
}
TempSpot = StrStr(PathName, L"\\");
TempSpot = StrStr (PathName, L"\\");
if (TempSpot != NULL) {
*TempSpot = CHAR_NULL;
}
StrnCatGrow(&FullPath, &Length, PathName, 0);
StrnCatGrow(&FullPath, &Length, L":\\", 0);
DeleteMode = ShellCommandLineGetFlag(Package, L"-d");
NewName = ShellCommandLineGetValue(Package, L"-n");
if (DeleteMode && ShellCommandLineGetFlag(Package, L"-n")) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PARAM_CONFLICT), gShellLevel2HiiHandle, L"vol", L"-d", L"-n");
StrnCatGrow (&FullPath, &Length, PathName, 0);
StrnCatGrow (&FullPath, &Length, L":\\", 0);
DeleteMode = ShellCommandLineGetFlag (Package, L"-d");
NewName = ShellCommandLineGetValue (Package, L"-n");
if (DeleteMode && ShellCommandLineGetFlag (Package, L"-n")) {
ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_PARAM_CONFLICT), gShellLevel2HiiHandle, L"vol", L"-d", L"-n");
ShellStatus = SHELL_INVALID_PARAMETER;
} else if (ShellCommandLineGetFlag(Package, L"-n") && NewName == NULL) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_NO_VALUE), gShellLevel2HiiHandle, L"vol", L"-n");
} else if (ShellCommandLineGetFlag (Package, L"-n") && (NewName == NULL)) {
ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_NO_VALUE), gShellLevel2HiiHandle, L"vol", L"-n");
ShellStatus = SHELL_INVALID_PARAMETER;
} else if (NewName != NULL && StrLen(NewName) > 11) {
ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM_VAL), gShellLevel2HiiHandle, L"vol", NewName, L"-n");
} else if ((NewName != NULL) && (StrLen (NewName) > 11)) {
ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM_VAL), gShellLevel2HiiHandle, L"vol", NewName, L"-n");
ShellStatus = SHELL_INVALID_PARAMETER;
} else if (ShellStatus == SHELL_SUCCESS) {
ShellStatus = HandleVol(
FullPath,
DeleteMode,
NewName
);
ShellStatus = HandleVol (
FullPath,
DeleteMode,
NewName
);
}
}
}
}
SHELL_FREE_NON_NULL(FullPath);
SHELL_FREE_NON_NULL (FullPath);
//
// free the command line package