diff options
Diffstat (limited to 'ShellPkg/Library')
12 files changed, 174 insertions, 119 deletions
diff --git a/ShellPkg/Library/BasePathLib/BasePathLib.c b/ShellPkg/Library/BasePathLib/BasePathLib.c new file mode 100644 index 0000000000..53a2a095b5 --- /dev/null +++ b/ShellPkg/Library/BasePathLib/BasePathLib.c @@ -0,0 +1,122 @@ +/** @file
+ Provides interface to path manipulation functions.
+
+ Copyright (c) 2011, Intel Corporation. All rights reserved.<BR>
+ This program and the accompanying materials
+ are licensed and made available under the terms and conditions of the BSD License
+ which accompanies this distribution. The full text of the license may be found at
+ http://opensource.org/licenses/bsd-license.php.
+
+ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+**/
+
+#include <Base.h>
+#include <Library/BaseMemoryLib.h>
+#include <Library/PathLib.h>
+#include <Library/BaseLib.h>
+
+/**
+ Removes the last directory or file entry in a path by changing the last
+ L'\' to a CHAR_NULL.
+
+ @param[in,out] Path The pointer to the path to modify.
+
+ @retval FALSE Nothing was found to remove.
+ @retval TRUE A directory or file was removed.
+**/
+BOOLEAN
+EFIAPI
+PathRemoveLastItem(
+ IN OUT CHAR16 *Path
+ )
+{
+ CHAR16 *Walker;
+ CHAR16 *LastSlash;
+ //
+ // get directory name from path... ('chop' off extra)
+ //
+ for ( Walker = Path, LastSlash = NULL
+ ; Walker != NULL && *Walker != CHAR_NULL
+ ; Walker++
+ ){
+ if (*Walker == L'\\' && *(Walker + 1) != CHAR_NULL) {
+ LastSlash = Walker+1;
+ }
+ }
+ if (LastSlash != NULL) {
+ *LastSlash = CHAR_NULL;
+ return (TRUE);
+ }
+ return (FALSE);
+}
+
+/**
+ Function to clean up paths.
+
+ - Single periods in the path are removed.
+ - Double periods in the path are removed along with a single parent directory.
+ - Forward slashes L'/' are converted to backward slashes L'\'.
+
+ This will be done inline and the existing buffer may be larger than required
+ upon completion.
+
+ @param[in] Path The pointer to the string containing the path.
+
+ @retval NULL An error occured.
+ @return Path in all other instances.
+**/
+CHAR16*
+EFIAPI
+PathCleanUpDirectories(
+ IN CHAR16 *Path
+ )
+{
+ CHAR16 *TempString;
+ UINTN TempSize;
+ if (Path==NULL) {
+ return(NULL);
+ }
+
+ //
+ // Fix up the / vs \
+ //
+ for (TempString = Path ; TempString != NULL && *TempString != CHAR_NULL ; TempString++) {
+ if (*TempString == L'/') {
+ *TempString = L'\\';
+ }
+ }
+
+ //
+ // Fix up the ..
+ //
+ while ((TempString = StrStr(Path, L"\\..\\")) != NULL) {
+ *TempString = CHAR_NULL;
+ TempString += 4;
+ PathRemoveLastItem(Path);
+ TempSize = StrSize(TempString);
+ CopyMem(Path+StrLen(Path), TempString, TempSize);
+ }
+ if ((TempString = StrStr(Path, L"\\..")) != NULL && *(TempString + 3) == CHAR_NULL) {
+ *TempString = CHAR_NULL;
+ PathRemoveLastItem(Path);
+ }
+
+ //
+ // Fix up the .
+ //
+ while ((TempString = StrStr(Path, L"\\.\\")) != NULL) {
+ *TempString = CHAR_NULL;
+ TempString += 2;
+ TempSize = StrSize(TempString);
+ CopyMem(Path+StrLen(Path), TempString, TempSize);
+ }
+ if ((TempString = StrStr(Path, L"\\.")) != NULL && *(TempString + 2) == CHAR_NULL) {
+ *TempString = CHAR_NULL;
+ }
+
+
+
+ return (Path);
+}
+
diff --git a/ShellPkg/Library/BasePathLib/BasePathLib.inf b/ShellPkg/Library/BasePathLib/BasePathLib.inf new file mode 100644 index 0000000000..a9bd6a8e45 --- /dev/null +++ b/ShellPkg/Library/BasePathLib/BasePathLib.inf @@ -0,0 +1,38 @@ +## @file
+# Provides interface to path manipulation functions.
+#
+# Copyright (c) 2011, Intel Corporation. All rights reserved. <BR>
+#
+# This program and the accompanying materials
+# are licensed and made available under the terms and conditions of the BSD License
+# which accompanies this distribution. The full text of the license may be found at
+# http://opensource.org/licenses/bsd-license.php
+# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+#
+#
+##
+
+[Defines]
+ INF_VERSION = 0x00010006
+ BASE_NAME = BasePathLib
+ FILE_GUID = ED244F93-B97A-4a17-83E0-A03CF2A7F7B4
+ MODULE_TYPE = UEFI_DRIVER
+ VERSION_STRING = 1.0
+ LIBRARY_CLASS = PathLib|UEFI_APPLICATION UEFI_DRIVER
+
+#
+# VALID_ARCHITECTURES = IA32 X64 IPF EBC
+#
+
+[Sources.common]
+ BasePathLib.c
+
+[Packages]
+ MdePkg/MdePkg.dec
+ ShellPkg/ShellPkg.dec
+
+
+[LibraryClasses]
+ BaseMemoryLib
+ BaseLib
\ No newline at end of file diff --git a/ShellPkg/Library/UefiShellCommandLib/UefiShellCommandLib.c b/ShellPkg/Library/UefiShellCommandLib/UefiShellCommandLib.c index 82a9e78ed5..28b7dda51e 100644 --- a/ShellPkg/Library/UefiShellCommandLib/UefiShellCommandLib.c +++ b/ShellPkg/Library/UefiShellCommandLib/UefiShellCommandLib.c @@ -1123,30 +1123,6 @@ ShellCommandCreateInitialMappingsAndPaths( }
/**
- Function to make sure all directory delimeters are backslashes.
-
- @param[in,out] Path The path to modify.
-
- @return Path.
-**/
-CHAR16*
-EFIAPI
-ShellCommandCleanPath (
- IN OUT CHAR16 *Path
- )
-{
- CHAR16 *Path2;
-
- for (Path2 = Path ; Path2 != NULL && *Path2 != CHAR_NULL ; Path2++) {
- if (*Path2 == L'/') {
- *Path2 = L'\\';
- }
- }
-
- return (Path);
-}
-
-/**
Converts a SHELL_FILE_HANDLE to an EFI_FILE_PROTOCOL*.
@param[in] Handle The SHELL_FILE_HANDLE to convert.
@@ -1489,85 +1465,3 @@ FreeBufferList ( }
}
-/**
- Chops off last directory or file entry in a path leaving the trailing slash
-
- @param[in,out] PathToReturn The path to modify.
-
- @retval FALSE No directory was found to chop off.
- @retval TRUE A directory was chopped off.
-**/
-BOOLEAN
-EFIAPI
-ChopLastSlash(
- IN OUT CHAR16 *PathToReturn
- )
-{
- CHAR16 *Walker;
- CHAR16 *LastSlash;
- //
- // get directory name from path... ('chop' off extra)
- //
- for ( Walker = PathToReturn, LastSlash = NULL
- ; Walker != NULL && *Walker != CHAR_NULL
- ; Walker++
- ){
- if (*Walker == L'\\' && *(Walker + 1) != CHAR_NULL) {
- LastSlash = Walker+1;
- }
- }
- if (LastSlash != NULL) {
- *LastSlash = CHAR_NULL;
- return (TRUE);
- }
- return (FALSE);
-}
-
-/**
- Function to clean up paths. Removes the following items:
- single periods in the path (no need for the current directory tag)
- double periods in the path and removes a single parent directory.
-
- This will be done inline and the resultant string may be be 'too big'.
-
- @param[in] PathToReturn The pointer to the string containing the path.
-
- @return PathToReturn is always returned.
-**/
-CHAR16*
-EFIAPI
-CleanPath(
- IN CHAR16 *PathToReturn
- )
-{
- CHAR16 *TempString;
- UINTN TempSize;
- if (PathToReturn==NULL) {
- return(NULL);
- }
- //
- // Fix up the directory name
- //
- while ((TempString = StrStr(PathToReturn, L"\\..\\")) != NULL) {
- *TempString = CHAR_NULL;
- TempString += 4;
- ChopLastSlash(PathToReturn);
- TempSize = StrSize(TempString);
- CopyMem(PathToReturn+StrLen(PathToReturn), TempString, TempSize);
- }
- if ((TempString = StrStr(PathToReturn, L"\\..")) != NULL && *(TempString + 3) == CHAR_NULL) {
- *TempString = CHAR_NULL;
- ChopLastSlash(PathToReturn);
- }
- while ((TempString = StrStr(PathToReturn, L"\\.\\")) != NULL) {
- *TempString = CHAR_NULL;
- TempString += 2;
- TempSize = StrSize(TempString);
- CopyMem(PathToReturn+StrLen(PathToReturn), TempString, TempSize);
- }
- if ((TempString = StrStr(PathToReturn, L"\\.")) != NULL && *(TempString + 2) == CHAR_NULL) {
- *TempString = CHAR_NULL;
- }
- return (PathToReturn);
-}
-
diff --git a/ShellPkg/Library/UefiShellLevel1CommandsLib/If.c b/ShellPkg/Library/UefiShellLevel1CommandsLib/If.c index 62c713e589..b7f423ff4d 100644 --- a/ShellPkg/Library/UefiShellLevel1CommandsLib/If.c +++ b/ShellPkg/Library/UefiShellLevel1CommandsLib/If.c @@ -14,6 +14,7 @@ #include "UefiShellLevel1CommandsLib.h"
#include <Library/PrintLib.h>
+#include <Library/PathLib.h>
typedef enum {
EndTagOr,
@@ -95,10 +96,7 @@ IsValidProfile ( CONST CHAR16 *TempLocation;
ProfilesString = ShellGetEnvironmentVariable(L"profiles");
- //
- // According to the Shell spec this is a required environment variable.
- //
- ASSERT(ProfileString != NULL);
+ ASSERT(ProfilesString != NULL);
TempLocation = StrStr(ProfilesString, String);
if ((TempLocation != NULL) && (*(TempLocation-1) == L';') && (*(TempLocation+StrLen(String)) == L';')) {
return (TRUE);
diff --git a/ShellPkg/Library/UefiShellLevel1CommandsLib/UefiShellLevel1CommandsLib.inf b/ShellPkg/Library/UefiShellLevel1CommandsLib/UefiShellLevel1CommandsLib.inf index 8b04b7d369..3a62cc3c8e 100644 --- a/ShellPkg/Library/UefiShellLevel1CommandsLib/UefiShellLevel1CommandsLib.inf +++ b/ShellPkg/Library/UefiShellLevel1CommandsLib/UefiShellLevel1CommandsLib.inf @@ -50,6 +50,7 @@ UefiBootServicesTableLib
SortLib
PrintLib
+ PathLib
[Pcd.common]
gEfiShellPkgTokenSpaceGuid.PcdShellSupportLevel # ALWAYS_CONSUMED
diff --git a/ShellPkg/Library/UefiShellLevel2CommandsLib/Cd.c b/ShellPkg/Library/UefiShellLevel2CommandsLib/Cd.c index bee4b0ae43..82d1c39df0 100644 --- a/ShellPkg/Library/UefiShellLevel2CommandsLib/Cd.c +++ b/ShellPkg/Library/UefiShellLevel2CommandsLib/Cd.c @@ -108,7 +108,7 @@ ShellCommandRunCd ( ShellStatus = SHELL_NOT_FOUND;
} else {
Drive = GetFullyQualifiedPath(Directory);
- ChopLastSlash(Drive);
+ PathRemoveLastItem(Drive);
}
if (ShellStatus == SHELL_SUCCESS && Drive != NULL) {
//
@@ -130,7 +130,7 @@ ShellCommandRunCd ( ShellStatus = SHELL_NOT_FOUND;
} else {
Drive = GetFullyQualifiedPath(Directory);
- while (ChopLastSlash(Drive)) ;
+ while (PathRemoveLastItem(Drive)) ;
}
if (ShellStatus == SHELL_SUCCESS && Drive != NULL) {
//
@@ -150,7 +150,7 @@ ShellCommandRunCd ( ASSERT((Drive == NULL && DriveSize == 0) || (Drive != NULL));
Drive = StrnCatGrow(&Drive, &DriveSize, ShellGetCurrentDir(NULL), 0);
if (*Param1 == L'\\') {
- while (ChopLastSlash(Drive)) ;
+ while (PathRemoveLastItem(Drive)) ;
Drive = StrnCatGrow(&Drive, &DriveSize, Param1+1, 0);
} else {
Drive = StrnCatGrow(&Drive, &DriveSize, Param1, 0);
diff --git a/ShellPkg/Library/UefiShellLevel2CommandsLib/Cp.c b/ShellPkg/Library/UefiShellLevel2CommandsLib/Cp.c index 8b30ac3122..08f5514cf5 100644 --- a/ShellPkg/Library/UefiShellLevel2CommandsLib/Cp.c +++ b/ShellPkg/Library/UefiShellLevel2CommandsLib/Cp.c @@ -416,7 +416,7 @@ ValidateAndCopyFiles( break;
}
- CleanPath(DestPath);
+ PathCleanUpDirectories(DestPath);
ShellPrintEx(-1, -1, HiiOutput, Node->FullName, DestPath);
@@ -619,7 +619,7 @@ ShellCommandRunCp ( // now copy them all...
//
if (FileList != NULL && !IsListEmpty(&FileList->Link)) {
- ShellStatus = ProcessValidateAndCopyFiles(FileList, ShellCommandCleanPath((CHAR16*)ShellCommandLineGetRawValue(Package, ParamCount)), SilentMode, RecursiveMode);
+ 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, ShellCommandLineGetRawValue(Package, ParamCount), ShellStatus|MAX_BIT);
diff --git a/ShellPkg/Library/UefiShellLevel2CommandsLib/Ls.c b/ShellPkg/Library/UefiShellLevel2CommandsLib/Ls.c index ac71350ef4..a93b54c429 100644 --- a/ShellPkg/Library/UefiShellLevel2CommandsLib/Ls.c +++ b/ShellPkg/Library/UefiShellLevel2CommandsLib/Ls.c @@ -67,7 +67,7 @@ PrintLsOutput( CorrectedPath = StrnCatGrow(&CorrectedPath, NULL, Path, 0);
ASSERT(CorrectedPath != NULL);
- ShellCommandCleanPath(CorrectedPath);
+ PathCleanUpDirectories(CorrectedPath);
Status = ShellOpenFileMetaArg((CHAR16*)CorrectedPath, EFI_FILE_MODE_READ, &ListHead);
if (EFI_ERROR(Status)) {
diff --git a/ShellPkg/Library/UefiShellLevel2CommandsLib/Mv.c b/ShellPkg/Library/UefiShellLevel2CommandsLib/Mv.c index dc9ef64d7f..5afcea2310 100644 --- a/ShellPkg/Library/UefiShellLevel2CommandsLib/Mv.c +++ b/ShellPkg/Library/UefiShellLevel2CommandsLib/Mv.c @@ -148,7 +148,7 @@ GetDestinationLocation( return (SHELL_OUT_OF_RESOURCES);
}
StrCpy(DestPath, Cwd);
- while (ChopLastSlash(DestPath)) ;
+ while (PathRemoveLastItem(DestPath)) ;
*DestPathPointer = DestPath;
return (SHELL_SUCCESS);
}
@@ -268,7 +268,7 @@ ValidateAndMoveFiles( if (ShellStatus != SHELL_SUCCESS) {
return (ShellStatus);
}
- DestPath = CleanPath(DestPath);
+ DestPath = PathCleanUpDirectories(DestPath);
HiiOutput = HiiGetString (gShellLevel2HiiHandle, STRING_TOKEN (STR_MV_OUTPUT), NULL);
HiiResultOk = HiiGetString (gShellLevel2HiiHandle, STRING_TOKEN (STR_GEN_RES_OK), NULL);
diff --git a/ShellPkg/Library/UefiShellLevel2CommandsLib/UefiShellLevel2CommandsLib.c b/ShellPkg/Library/UefiShellLevel2CommandsLib/UefiShellLevel2CommandsLib.c index fed233c33a..ce3d87ba50 100644 --- a/ShellPkg/Library/UefiShellLevel2CommandsLib/UefiShellLevel2CommandsLib.c +++ b/ShellPkg/Library/UefiShellLevel2CommandsLib/UefiShellLevel2CommandsLib.c @@ -196,7 +196,7 @@ GetFullyQualifiedPath( }
StrnCatGrow(&PathToReturn, &Size, Path, 0);
- CleanPath(PathToReturn);
+ PathCleanUpDirectories(PathToReturn);
while (PathToReturn[StrLen(PathToReturn)-1] == L'*') {
PathToReturn[StrLen(PathToReturn)-1] = CHAR_NULL;
diff --git a/ShellPkg/Library/UefiShellLevel2CommandsLib/UefiShellLevel2CommandsLib.h b/ShellPkg/Library/UefiShellLevel2CommandsLib/UefiShellLevel2CommandsLib.h index 49e187fc7a..80f6d59ee9 100644 --- a/ShellPkg/Library/UefiShellLevel2CommandsLib/UefiShellLevel2CommandsLib.h +++ b/ShellPkg/Library/UefiShellLevel2CommandsLib/UefiShellLevel2CommandsLib.h @@ -46,6 +46,7 @@ #include <Library/HiiLib.h>
#include <Library/SortLib.h>
#include <Library/FileHandleLib.h>
+#include <Library/PathLib.h>
extern CONST CHAR16 mFileName[];
extern EFI_HANDLE gShellLevel2HiiHandle;
diff --git a/ShellPkg/Library/UefiShellLevel2CommandsLib/UefiShellLevel2CommandsLib.inf b/ShellPkg/Library/UefiShellLevel2CommandsLib/UefiShellLevel2CommandsLib.inf index 8b618b1f5f..52dc28feb2 100644 --- a/ShellPkg/Library/UefiShellLevel2CommandsLib/UefiShellLevel2CommandsLib.inf +++ b/ShellPkg/Library/UefiShellLevel2CommandsLib/UefiShellLevel2CommandsLib.inf @@ -64,6 +64,7 @@ PcdLib
HiiLib
HandleParsingLib
+ PathLib
[Protocols]
gEfiUnicodeCollation2ProtocolGuid # ALWAYS_CONSUMED
|