X-Git-Url: https://git.proxmox.com/?a=blobdiff_plain;f=ShellPkg%2FLibrary%2FUefiShellLib%2FUefiShellLib.c;h=2e6301d70a6dce59ebcbef1628d9070a8e547e6c;hb=a8577b3a65e2aad01b1c69338ab1c63273d073f6;hp=508e9e0ec0dc56e709d14977ee507bd31b1edb65;hpb=7a95efda40f616117ffd86e338c8bafc287d8221;p=mirror_edk2.git diff --git a/ShellPkg/Library/UefiShellLib/UefiShellLib.c b/ShellPkg/Library/UefiShellLib/UefiShellLib.c index 508e9e0ec0..2e6301d70a 100644 --- a/ShellPkg/Library/UefiShellLib/UefiShellLib.c +++ b/ShellPkg/Library/UefiShellLib/UefiShellLib.c @@ -1,7 +1,7 @@ /** @file Provides interface to shell functionality for shell commands and applications. - Copyright (c) 2006 - 2011, Intel Corporation. All rights reserved.
+ Copyright (c) 2006 - 2015, Intel Corporation. All rights reserved.
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 @@ -15,6 +15,7 @@ #include "UefiShellLib.h" #include #include +#include #define FIND_XXXXX_FILE_BUFFER_SIZE (SIZE_OF_EFI_FILE_INFO + MAX_FILE_NAME_LEN) @@ -163,7 +164,7 @@ ShellFindSE2 ( } /** - Function to do most of the work of the constructor. Allows for calling + Function to do most of the work of the constructor. Allows for calling multiple times without complete re-initialization. @param[in] ImageHandle A copy of the ImageHandle. @@ -421,20 +422,20 @@ ShellGetFileInfo ( @param[in] FileInfo The information to set. - @retval EFI_SUCCESS The information was set. + @retval EFI_SUCCESS The information was set. @retval EFI_INVALID_PARAMETER A parameter was out of range or invalid. @retval EFI_UNSUPPORTED The FileHandle does not support FileInfo. - @retval EFI_NO_MEDIA The device has no medium. - @retval EFI_DEVICE_ERROR The device reported an error. - @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted. - @retval EFI_WRITE_PROTECTED The file or medium is write protected. + @retval EFI_NO_MEDIA The device has no medium. + @retval EFI_DEVICE_ERROR The device reported an error. + @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted. + @retval EFI_WRITE_PROTECTED The file or medium is write protected. @retval EFI_ACCESS_DENIED The file was opened read only. @retval EFI_VOLUME_FULL The volume is full. **/ EFI_STATUS EFIAPI ShellSetFileInfo ( - IN SHELL_FILE_HANDLE FileHandle, + IN SHELL_FILE_HANDLE FileHandle, IN EFI_FILE_INFO *FileInfo ) { @@ -447,38 +448,38 @@ ShellSetFileInfo ( This function opens a file with the open mode according to the file path. The Attributes is valid only for EFI_FILE_MODE_CREATE. - @param FilePath on input the device path to the file. On output + @param FilePath on input the device path to the file. On output the remaining device path. - @param DeviceHandle pointer to the system device handle. - @param FileHandle pointer to the file handle. - @param OpenMode the mode to open the file with. - @param Attributes the file's file attributes. - - @retval EFI_SUCCESS The information was set. - @retval EFI_INVALID_PARAMETER One of the parameters has an invalid value. - @retval EFI_UNSUPPORTED Could not open the file path. - @retval EFI_NOT_FOUND The specified file could not be found on the + @param DeviceHandle pointer to the system device handle. + @param FileHandle pointer to the file handle. + @param OpenMode the mode to open the file with. + @param Attributes the file's file attributes. + + @retval EFI_SUCCESS The information was set. + @retval EFI_INVALID_PARAMETER One of the parameters has an invalid value. + @retval EFI_UNSUPPORTED Could not open the file path. + @retval EFI_NOT_FOUND The specified file could not be found on the device or the file system could not be found on the device. - @retval EFI_NO_MEDIA The device has no medium. - @retval EFI_MEDIA_CHANGED The device has a different medium in it or the + @retval EFI_NO_MEDIA The device has no medium. + @retval EFI_MEDIA_CHANGED The device has a different medium in it or the medium is no longer supported. - @retval EFI_DEVICE_ERROR The device reported an error. - @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted. - @retval EFI_WRITE_PROTECTED The file or medium is write protected. - @retval EFI_ACCESS_DENIED The file was opened read only. - @retval EFI_OUT_OF_RESOURCES Not enough resources were available to open the + @retval EFI_DEVICE_ERROR The device reported an error. + @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted. + @retval EFI_WRITE_PROTECTED The file or medium is write protected. + @retval EFI_ACCESS_DENIED The file was opened read only. + @retval EFI_OUT_OF_RESOURCES Not enough resources were available to open the file. - @retval EFI_VOLUME_FULL The volume is full. + @retval EFI_VOLUME_FULL The volume is full. **/ EFI_STATUS EFIAPI ShellOpenFileByDevicePath( - IN OUT EFI_DEVICE_PATH_PROTOCOL **FilePath, - OUT EFI_HANDLE *DeviceHandle, + IN OUT EFI_DEVICE_PATH_PROTOCOL **FilePath, + OUT EFI_HANDLE *DeviceHandle, OUT SHELL_FILE_HANDLE *FileHandle, - IN UINT64 OpenMode, - IN UINT64 Attributes + IN UINT64 OpenMode, + IN UINT64 Attributes ) { CHAR16 *FileName; @@ -486,6 +487,8 @@ ShellOpenFileByDevicePath( EFI_SIMPLE_FILE_SYSTEM_PROTOCOL *EfiSimpleFileSystemProtocol; EFI_FILE_PROTOCOL *Handle1; EFI_FILE_PROTOCOL *Handle2; + CHAR16 *FnafPathName; + UINTN PathLen; if (FilePath == NULL || FileHandle == NULL || DeviceHandle == NULL) { return (EFI_INVALID_PARAMETER); @@ -551,13 +554,36 @@ ShellOpenFileByDevicePath( Handle2 = Handle1; Handle1 = NULL; + // + // File Name Alignment Fix (FNAF) + // Handle2->Open may be incapable of handling a unaligned CHAR16 data. + // The structure pointed to by FilePath may be not CHAR16 aligned. + // This code copies the potentially unaligned PathName data from the + // FilePath structure to the aligned FnafPathName for use in the + // calls to Handl2->Open. + // + + // + // Determine length of PathName, in bytes. + // + PathLen = DevicePathNodeLength (*FilePath) - SIZE_OF_FILEPATH_DEVICE_PATH; + + // + // Allocate memory for the aligned copy of the string Extra allocation is to allow for forced alignment + // Copy bytes from possibly unaligned location to aligned location + // + FnafPathName = AllocateCopyPool(PathLen, (UINT8 *)((FILEPATH_DEVICE_PATH*)*FilePath)->PathName); + if (FnafPathName == NULL) { + return EFI_OUT_OF_RESOURCES; + } + // // Try to test opening an existing file // Status = Handle2->Open ( Handle2, &Handle1, - ((FILEPATH_DEVICE_PATH*)*FilePath)->PathName, + FnafPathName, OpenMode &~EFI_FILE_MODE_CREATE, 0 ); @@ -569,11 +595,17 @@ ShellOpenFileByDevicePath( Status = Handle2->Open ( Handle2, &Handle1, - ((FILEPATH_DEVICE_PATH*)*FilePath)->PathName, + FnafPathName, OpenMode, Attributes ); } + + // + // Free the alignment buffer + // + FreePool(FnafPathName); + // // Close the last node // @@ -605,41 +637,42 @@ ShellOpenFileByDevicePath( if FileName is NULL then ASSERT() - @param FileName pointer to file name - @param FileHandle pointer to the file handle. - @param OpenMode the mode to open the file with. - @param Attributes the file's file attributes. + @param FileName pointer to file name + @param FileHandle pointer to the file handle. + @param OpenMode the mode to open the file with. + @param Attributes the file's file attributes. - @retval EFI_SUCCESS The information was set. - @retval EFI_INVALID_PARAMETER One of the parameters has an invalid value. - @retval EFI_UNSUPPORTED Could not open the file path. - @retval EFI_NOT_FOUND The specified file could not be found on the + @retval EFI_SUCCESS The information was set. + @retval EFI_INVALID_PARAMETER One of the parameters has an invalid value. + @retval EFI_UNSUPPORTED Could not open the file path. + @retval EFI_NOT_FOUND The specified file could not be found on the device or the file system could not be found on the device. - @retval EFI_NO_MEDIA The device has no medium. - @retval EFI_MEDIA_CHANGED The device has a different medium in it or the + @retval EFI_NO_MEDIA The device has no medium. + @retval EFI_MEDIA_CHANGED The device has a different medium in it or the medium is no longer supported. - @retval EFI_DEVICE_ERROR The device reported an error. - @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted. - @retval EFI_WRITE_PROTECTED The file or medium is write protected. - @retval EFI_ACCESS_DENIED The file was opened read only. - @retval EFI_OUT_OF_RESOURCES Not enough resources were available to open the + @retval EFI_DEVICE_ERROR The device reported an error. + @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted. + @retval EFI_WRITE_PROTECTED The file or medium is write protected. + @retval EFI_ACCESS_DENIED The file was opened read only. + @retval EFI_OUT_OF_RESOURCES Not enough resources were available to open the file. - @retval EFI_VOLUME_FULL The volume is full. + @retval EFI_VOLUME_FULL The volume is full. **/ EFI_STATUS EFIAPI ShellOpenFileByName( - IN CONST CHAR16 *FileName, + IN CONST CHAR16 *FileName, OUT SHELL_FILE_HANDLE *FileHandle, IN UINT64 OpenMode, - IN UINT64 Attributes + IN UINT64 Attributes ) { EFI_HANDLE DeviceHandle; EFI_DEVICE_PATH_PROTOCOL *FilePath; EFI_STATUS Status; EFI_FILE_INFO *FileInfo; + CHAR16 *FileNameCopy; // // ASSERT if FileName is NULL @@ -651,11 +684,32 @@ ShellOpenFileByName( } if (gEfiShellProtocol != NULL) { - if ((OpenMode & EFI_FILE_MODE_CREATE) == EFI_FILE_MODE_CREATE && (Attributes & EFI_FILE_DIRECTORY) == EFI_FILE_DIRECTORY) { - return ShellCreateDirectory(FileName, FileHandle); + if ((OpenMode & EFI_FILE_MODE_CREATE) == EFI_FILE_MODE_CREATE) { + + // + // Create only a directory + // + if ((Attributes & EFI_FILE_DIRECTORY) == EFI_FILE_DIRECTORY) { + return ShellCreateDirectory(FileName, FileHandle); + } + + // + // Create the directory to create the file in + // + FileNameCopy = AllocateCopyPool (StrSize (FileName), FileName); + if (FileName == NULL) { + return (EFI_OUT_OF_RESOURCES); + } + PathCleanUpDirectories (FileNameCopy); + if (PathRemoveLastItem (FileNameCopy)) { + ShellCreateDirectory (FileNameCopy, FileHandle); + ShellCloseFile (FileHandle); + } + SHELL_FREE_NON_NULL (FileNameCopy); } + // - // Use UEFI Shell 2.0 method + // Use UEFI Shell 2.0 method to create the file // Status = gEfiShellProtocol->OpenFileByName(FileName, FileHandle, @@ -692,25 +746,25 @@ ShellOpenFileByName( otherwise, the Filehandle is NULL. If the directory already existed, this function opens the existing directory. - @param DirectoryName pointer to directory name - @param FileHandle pointer to the file handle. + @param DirectoryName pointer to directory name + @param FileHandle pointer to the file handle. - @retval EFI_SUCCESS The information was set. - @retval EFI_INVALID_PARAMETER One of the parameters has an invalid value. - @retval EFI_UNSUPPORTED Could not open the file path. - @retval EFI_NOT_FOUND The specified file could not be found on the + @retval EFI_SUCCESS The information was set. + @retval EFI_INVALID_PARAMETER One of the parameters has an invalid value. + @retval EFI_UNSUPPORTED Could not open the file path. + @retval EFI_NOT_FOUND The specified file could not be found on the device or the file system could not be found on the device. - @retval EFI_NO_MEDIA The device has no medium. - @retval EFI_MEDIA_CHANGED The device has a different medium in it or the + @retval EFI_NO_MEDIA The device has no medium. + @retval EFI_MEDIA_CHANGED The device has a different medium in it or the medium is no longer supported. - @retval EFI_DEVICE_ERROR The device reported an error. - @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted. - @retval EFI_WRITE_PROTECTED The file or medium is write protected. - @retval EFI_ACCESS_DENIED The file was opened read only. - @retval EFI_OUT_OF_RESOURCES Not enough resources were available to open the + @retval EFI_DEVICE_ERROR The device reported an error. + @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted. + @retval EFI_WRITE_PROTECTED The file or medium is write protected. + @retval EFI_ACCESS_DENIED The file was opened read only. + @retval EFI_OUT_OF_RESOURCES Not enough resources were available to open the file. - @retval EFI_VOLUME_FULL The volume is full. + @retval EFI_VOLUME_FULL The volume is full. @sa ShellOpenFileByName **/ EFI_STATUS @@ -758,11 +812,11 @@ ShellCreateDirectory( the number of bytes written. @param Buffer the buffer to put read data into. - @retval EFI_SUCCESS Data was read. - @retval EFI_NO_MEDIA The device has no media. - @retval EFI_DEVICE_ERROR The device reported an error. - @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted. - @retval EFI_BUFFER_TO_SMALL Buffer is too small. ReadSize contains required + @retval EFI_SUCCESS Data was read. + @retval EFI_NO_MEDIA The device has no media. + @retval EFI_DEVICE_ERROR The device reported an error. + @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted. + @retval EFI_BUFFER_TO_SMALL Buffer is too small. ReadSize contains required size. **/ @@ -793,14 +847,14 @@ ShellReadFile( the number of bytes written. @param Buffer the buffer containing data to write is stored. - @retval EFI_SUCCESS Data was written. - @retval EFI_UNSUPPORTED Writes to an open directory are not supported. - @retval EFI_NO_MEDIA The device has no media. - @retval EFI_DEVICE_ERROR The device reported an error. - @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted. - @retval EFI_WRITE_PROTECTED The device is write-protected. - @retval EFI_ACCESS_DENIED The file was open for read only. - @retval EFI_VOLUME_FULL The volume is full. + @retval EFI_SUCCESS Data was written. + @retval EFI_UNSUPPORTED Writes to an open directory are not supported. + @retval EFI_NO_MEDIA The device has no media. + @retval EFI_DEVICE_ERROR The device reported an error. + @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted. + @retval EFI_WRITE_PROTECTED The device is write-protected. + @retval EFI_ACCESS_DENIED The file was open for read only. + @retval EFI_VOLUME_FULL The volume is full. **/ EFI_STATUS EFIAPI @@ -845,12 +899,12 @@ ShellCloseFile ( @retval EFI_SUCCESS the file was closed sucessfully @retval EFI_WARN_DELETE_FAILURE the handle was closed, but the file was not deleted - @retval INVALID_PARAMETER One of the parameters has an invalid value. + @retval INVALID_PARAMETER One of the parameters has an invalid value. **/ EFI_STATUS EFIAPI ShellDeleteFile ( - IN SHELL_FILE_HANDLE *FileHandle + IN SHELL_FILE_HANDLE *FileHandle ) { return (FileFunctionMap.DeleteFile(*FileHandle)); @@ -878,8 +932,8 @@ ShellDeleteFile ( EFI_STATUS EFIAPI ShellSetFilePosition ( - IN SHELL_FILE_HANDLE FileHandle, - IN UINT64 Position + IN SHELL_FILE_HANDLE FileHandle, + IN UINT64 Position ) { return (FileFunctionMap.SetFilePosition(FileHandle, Position)); @@ -932,15 +986,19 @@ ShellFlushFile ( return (FileFunctionMap.FlushFile(FileHandle)); } -/** - Retrieves the first file from a directory +/** Retrieve first entry from a directory. + + This function takes an open directory handle and gets information from the + first entry in the directory. A buffer is allocated to contain + the information and a pointer to the buffer is returned in *Buffer. The + caller can use ShellFindNextFile() to get subsequent directory entries. - This function opens a directory and gets the first file's info in the - directory. Caller can use ShellFindNextFile() to get other files. When - complete the caller is responsible for calling FreePool() on Buffer. + The buffer will be freed by ShellFindNextFile() when the last directory + entry is read. Otherwise, the caller must free the buffer, using FreePool, + when finished with it. - @param DirHandle The file handle of the directory to search - @param Buffer Pointer to buffer for file's information + @param[in] DirHandle The file handle of the directory to search. + @param[out] Buffer The pointer to the buffer for the file's information. @retval EFI_SUCCESS Found the first file. @retval EFI_NOT_FOUND Cannot find the directory. @@ -962,19 +1020,18 @@ ShellFindFirstFile ( // return (FileHandleFindFirstFile(DirHandle, Buffer)); } -/** - Retrieves the next file in a directory. +/** Retrieve next entries from a directory. - To use this function, caller must call the ShellFindFirstFile() to get the - first file, and then use this function get other files. This function can be - called for several times to get each file's information in the directory. If - the call of ShellFindNextFile() got the last file in the directory, the next - call of this function has no file to get. *NoFile will be set to TRUE and the - Buffer memory will be automatically freed. + To use this function, the caller must first call the ShellFindFirstFile() + function to get the first directory entry. Subsequent directory entries are + retrieved by using the ShellFindNextFile() function. This function can + be called several times to get each entry from the directory. If the call of + ShellFindNextFile() retrieved the last directory entry, the next call of + this function will set *NoFile to TRUE and free the buffer. - @param DirHandle the file handle of the directory - @param Buffer pointer to buffer for file's information - @param NoFile pointer to boolean when last file is found + @param[in] DirHandle The file handle of the directory. + @param[out] Buffer The pointer to buffer for file's information. + @param[out] NoFile The pointer to boolean when last file is found. @retval EFI_SUCCESS Found the next file, or reached last file @retval EFI_NO_MEDIA The device has no media. @@ -1141,7 +1198,7 @@ ShellSetEnvironmentVariable ( The CommandLine is executed from the current working directory on the current device. - The EnvironmentVariables and Status parameters are ignored in a pre-UEFI Shell 2.0 + The EnvironmentVariables pararemeter is ignored in a pre-UEFI Shell 2.0 environment. The values pointed to by the parameters will be unchanged by the ShellExecute() function. The Output parameter has no effect in a UEFI Shell 2.0 environment. @@ -1169,6 +1226,7 @@ ShellExecute ( OUT EFI_STATUS *Status OPTIONAL ) { + EFI_STATUS CmdStatus; // // Check for UEFI Shell 2.0 protocols // @@ -1187,16 +1245,29 @@ ShellExecute ( // if (mEfiShellEnvironment2 != NULL) { // - // Call EFI Shell version (not using EnvironmentVariables or Status parameters) + // Call EFI Shell version. // Due to oddity in the EFI shell we want to dereference the ParentHandle here // - return (mEfiShellEnvironment2->Execute(*ParentHandle, + CmdStatus = (mEfiShellEnvironment2->Execute(*ParentHandle, CommandLine, Output)); + // + // No Status output parameter so just use the returned status + // + if (Status != NULL) { + *Status = CmdStatus; + } + // + // If there was an error, we can't tell if it was from the command or from + // the Execute() function, so we'll just assume the shell ran successfully + // and the error came from the command. + // + return EFI_SUCCESS; } return (EFI_UNSUPPORTED); } + /** Retreives the current directory path @@ -1382,26 +1453,30 @@ InternalShellConvertFileListType ( // // allocate new space to copy strings and structure // - NewInfo->FullName = AllocateZeroPool(StrSize(OldInfo->FullName)); - NewInfo->FileName = AllocateZeroPool(StrSize(OldInfo->FileName)); - NewInfo->Info = AllocateZeroPool((UINTN)OldInfo->Info->Size); + NewInfo->FullName = AllocateCopyPool(StrSize(OldInfo->FullName), OldInfo->FullName); + NewInfo->FileName = AllocateCopyPool(StrSize(OldInfo->FileName), OldInfo->FileName); + NewInfo->Info = AllocateCopyPool((UINTN)OldInfo->Info->Size, OldInfo->Info); // // make sure all the memory allocations were sucessful // if (NULL == NewInfo->FullName || NewInfo->FileName == NULL || NewInfo->Info == NULL) { + // + // Free the partially allocated new node + // + SHELL_FREE_NON_NULL(NewInfo->FullName); + SHELL_FREE_NON_NULL(NewInfo->FileName); + SHELL_FREE_NON_NULL(NewInfo->Info); + SHELL_FREE_NON_NULL(NewInfo); + + // + // Free the previously converted stuff + // ShellCloseFileMetaArg((EFI_SHELL_FILE_INFO**)(&ListHead)); ListHead = NULL; break; } - // - // Copt the strings and structure - // - StrCpy(NewInfo->FullName, OldInfo->FullName); - StrCpy(NewInfo->FileName, OldInfo->FileName); - gBS->CopyMem (NewInfo->Info, OldInfo->Info, (UINTN)OldInfo->Info->Size); - // // add that to the list // @@ -1413,8 +1488,8 @@ InternalShellConvertFileListType ( Opens a group of files based on a path. This function uses the Arg to open all the matching files. Each matched - file has a SHELL_FILE_ARG structure to record the file information. These - structures are placed on the list ListHead. Users can get the SHELL_FILE_ARG + file has a SHELL_FILE_INFO structure to record the file information. These + structures are placed on the list ListHead. Users can get the SHELL_FILE_INFO structures from ListHead to access each file. This function supports wildcards and will process '?' and '*' as such. the list must be freed with a call to ShellCloseFileMetaArg(). @@ -1442,6 +1517,7 @@ ShellOpenFileMetaArg ( { EFI_STATUS Status; LIST_ENTRY mOldStyleFileList; + CHAR16 *CleanFilePathStr; // // ASSERT that Arg and ListHead are not NULL @@ -1449,6 +1525,13 @@ ShellOpenFileMetaArg ( ASSERT(Arg != NULL); ASSERT(ListHead != NULL); + CleanFilePathStr = NULL; + + Status = InternalShellStripQuotes (Arg, &CleanFilePathStr); + if (EFI_ERROR (Status)) { + return Status; + } + // // Check for UEFI Shell 2.0 protocols // @@ -1456,11 +1539,12 @@ ShellOpenFileMetaArg ( if (*ListHead == NULL) { *ListHead = (EFI_SHELL_FILE_INFO*)AllocateZeroPool(sizeof(EFI_SHELL_FILE_INFO)); if (*ListHead == NULL) { + FreePool(CleanFilePathStr); return (EFI_OUT_OF_RESOURCES); } InitializeListHead(&((*ListHead)->Link)); } - Status = gEfiShellProtocol->OpenFileList(Arg, + Status = gEfiShellProtocol->OpenFileList(CleanFilePathStr, OpenMode, ListHead); if (EFI_ERROR(Status)) { @@ -1470,9 +1554,11 @@ ShellOpenFileMetaArg ( } if (*ListHead != NULL && IsListEmpty(&(*ListHead)->Link)) { FreePool(*ListHead); + FreePool(CleanFilePathStr); *ListHead = NULL; return (EFI_NOT_FOUND); } + FreePool(CleanFilePathStr); return (Status); } @@ -1488,15 +1574,17 @@ ShellOpenFileMetaArg ( // // Get the EFI Shell list of files // - Status = mEfiShellEnvironment2->FileMetaArg(Arg, &mOldStyleFileList); + Status = mEfiShellEnvironment2->FileMetaArg(CleanFilePathStr, &mOldStyleFileList); if (EFI_ERROR(Status)) { *ListHead = NULL; + FreePool(CleanFilePathStr); return (Status); } if (*ListHead == NULL) { *ListHead = (EFI_SHELL_FILE_INFO *)AllocateZeroPool(sizeof(EFI_SHELL_FILE_INFO)); if (*ListHead == NULL) { + FreePool(CleanFilePathStr); return (EFI_OUT_OF_RESOURCES); } InitializeListHead(&((*ListHead)->Link)); @@ -1517,9 +1605,11 @@ ShellOpenFileMetaArg ( *ListHead = NULL; Status = EFI_NOT_FOUND; } + FreePool(CleanFilePathStr); return (Status); } + FreePool(CleanFilePathStr); return (EFI_UNSUPPORTED); } /** @@ -1564,6 +1654,7 @@ ShellCloseFileMetaArg ( FreePool(((EFI_SHELL_FILE_INFO_NO_CONST*)Node)->Info); FreePool((EFI_SHELL_FILE_INFO_NO_CONST*)Node); } + SHELL_FREE_NON_NULL(*ListHead); return EFI_SUCCESS; } @@ -1622,8 +1713,8 @@ ShellFindFilePath ( if (TestPath == NULL) { return (NULL); } - StrCpy(TestPath, Path); - StrCat(TestPath, FileName); + StrnCpy(TestPath, Path, Size/sizeof(CHAR16) - 1); + StrnCat(TestPath, FileName, Size/sizeof(CHAR16) - 1 - StrLen(TestPath)); Status = ShellOpenFileByName(TestPath, &Handle, EFI_FILE_MODE_READ, 0); if (!EFI_ERROR(Status)){ if (FileHandleIsDirectory(Handle) != EFI_SUCCESS) { @@ -1655,12 +1746,12 @@ ShellFindFilePath ( *TempChar = CHAR_NULL; } if (TestPath[StrLen(TestPath)-1] != L'\\') { - StrCat(TestPath, L"\\"); + StrnCat(TestPath, L"\\", Size/sizeof(CHAR16) - 1 - StrLen(TestPath)); } if (FileName[0] == L'\\') { FileName++; } - StrCat(TestPath, FileName); + StrnCat(TestPath, FileName, Size/sizeof(CHAR16) - 1 - StrLen(TestPath)); if (StrStr(Walker, L";") != NULL) { Walker = StrStr(Walker, L";") + 1; } else { @@ -1729,9 +1820,9 @@ ShellFindFilePathEx ( return (NULL); } for (ExtensionWalker = FileExtension, TempChar2 = (CHAR16*)FileExtension; TempChar2 != NULL ; ExtensionWalker = TempChar2 + 1){ - StrCpy(TestPath, FileName); + StrnCpy(TestPath, FileName, Size/sizeof(CHAR16) - 1); if (ExtensionWalker != NULL) { - StrCat(TestPath, ExtensionWalker); + StrnCat(TestPath, ExtensionWalker, Size/sizeof(CHAR16) - 1 - StrLen(TestPath)); } TempChar = StrStr(TestPath, L";"); if (TempChar != NULL) { @@ -1807,7 +1898,7 @@ InternalIsOnCheckList ( // If the Type is TypeStart only check the first characters of the passed in param // If it matches set the type and return TRUE // - if (TempListItem->Type == TypeStart) { + if (TempListItem->Type == TypeStart) { if (StrnCmp(Name, TempListItem->Name, StrLen(TempListItem->Name)) == 0) { *Type = TempListItem->Type; return (TRUE); @@ -1835,6 +1926,7 @@ InternalIsOnCheckList ( @param[in] Name pointer to Name of parameter found @param[in] AlwaysAllowNumbers TRUE to allow numbers, FALSE to not. + @param[in] TimeNumbers TRUE to allow numbers with ":", FALSE otherwise. @retval TRUE the Parameter is a flag. @retval FALSE the Parameter not a flag. @@ -1843,7 +1935,8 @@ BOOLEAN EFIAPI InternalIsFlag ( IN CONST CHAR16 *Name, - IN BOOLEAN AlwaysAllowNumbers + IN CONST BOOLEAN AlwaysAllowNumbers, + IN CONST BOOLEAN TimeNumbers ) { // @@ -1854,7 +1947,7 @@ InternalIsFlag ( // // If we accept numbers then dont return TRUE. (they will be values) // - if (((Name[0] == L'-' || Name[0] == L'+') && ShellIsHexaDecimalDigitCharacter(Name[1])) && AlwaysAllowNumbers) { + if (((Name[0] == L'-' || Name[0] == L'+') && InternalShellIsHexOrDecimalNumber(Name+1, FALSE, FALSE, TimeNumbers)) && AlwaysAllowNumbers) { return (FALSE); } @@ -1914,6 +2007,7 @@ InternalCommandLineParse ( UINTN ValueSize; UINTN Count; CONST CHAR16 *TempPointer; + UINTN CurrentValueSize; CurrentItemPackage = NULL; GetItemValue = 0; @@ -1969,13 +2063,12 @@ InternalCommandLineParse ( *CheckPackage = NULL; return (EFI_OUT_OF_RESOURCES); } - CurrentItemPackage->Name = AllocateZeroPool(StrSize(Argv[LoopCounter])); + CurrentItemPackage->Name = AllocateCopyPool(StrSize(Argv[LoopCounter]), Argv[LoopCounter]); if (CurrentItemPackage->Name == NULL) { ShellCommandLineFreeVarList(*CheckPackage); *CheckPackage = NULL; return (EFI_OUT_OF_RESOURCES); } - StrCpy(CurrentItemPackage->Name, Argv[LoopCounter]); CurrentItemPackage->Type = CurrentItemType; CurrentItemPackage->OriginalPosition = (UINTN)(-1); CurrentItemPackage->Value = NULL; @@ -1988,6 +2081,7 @@ InternalCommandLineParse ( // possibly trigger the next loop(s) to populate the value of this item // case TypeValue: + case TypeTimeValue: GetItemValue = 1; ValueSize = 0; break; @@ -2007,31 +2101,51 @@ InternalCommandLineParse ( ASSERT(GetItemValue == 0); break; } - } else if (GetItemValue != 0 && !InternalIsFlag(Argv[LoopCounter], AlwaysAllowNumbers)) { - ASSERT(CurrentItemPackage != NULL); + } else if (GetItemValue != 0 && CurrentItemPackage != NULL && !InternalIsFlag(Argv[LoopCounter], AlwaysAllowNumbers, CurrentItemPackage->Type == TypeTimeValue)) { // // get the item VALUE for a previous flag // - CurrentItemPackage->Value = ReallocatePool(ValueSize, ValueSize + StrSize(Argv[LoopCounter]) + sizeof(CHAR16), CurrentItemPackage->Value); - ASSERT(CurrentItemPackage->Value != NULL); - if (ValueSize == 0) { - StrCpy(CurrentItemPackage->Value, Argv[LoopCounter]); + if (StrStr(Argv[LoopCounter], L" ") == NULL) { + CurrentValueSize = ValueSize + StrSize(Argv[LoopCounter]) + sizeof(CHAR16); + CurrentItemPackage->Value = ReallocatePool(ValueSize, CurrentValueSize, CurrentItemPackage->Value); + ASSERT(CurrentItemPackage->Value != NULL); + if (ValueSize == 0) { + StrnCpy(CurrentItemPackage->Value, Argv[LoopCounter], CurrentValueSize/sizeof(CHAR16) - 1); + } else { + StrnCat(CurrentItemPackage->Value, L" ", CurrentValueSize/sizeof(CHAR16) - 1 - StrLen(CurrentItemPackage->Value)); + StrnCat(CurrentItemPackage->Value, Argv[LoopCounter], CurrentValueSize/sizeof(CHAR16) - 1 - StrLen(CurrentItemPackage->Value)); + } + ValueSize += StrSize(Argv[LoopCounter]) + sizeof(CHAR16); } else { - StrCat(CurrentItemPackage->Value, L" "); - StrCat(CurrentItemPackage->Value, Argv[LoopCounter]); + // + // the parameter has spaces. must be quoted. + // + CurrentValueSize = ValueSize + StrSize(Argv[LoopCounter]) + sizeof(CHAR16) + sizeof(CHAR16) + sizeof(CHAR16); + CurrentItemPackage->Value = ReallocatePool(ValueSize, CurrentValueSize, CurrentItemPackage->Value); + ASSERT(CurrentItemPackage->Value != NULL); + if (ValueSize == 0) { + StrnCpy(CurrentItemPackage->Value, L"\"", CurrentValueSize/sizeof(CHAR16) - 1); + StrnCat(CurrentItemPackage->Value, Argv[LoopCounter], CurrentValueSize/sizeof(CHAR16) - 1 - StrLen(CurrentItemPackage->Value)); + StrnCat(CurrentItemPackage->Value, L"\"", CurrentValueSize/sizeof(CHAR16) - 1 - StrLen(CurrentItemPackage->Value)); + } else { + StrnCat(CurrentItemPackage->Value, L" ", CurrentValueSize/sizeof(CHAR16) - 1 - StrLen(CurrentItemPackage->Value)); + StrnCat(CurrentItemPackage->Value, L"\"", CurrentValueSize/sizeof(CHAR16) - 1 - StrLen(CurrentItemPackage->Value)); + StrnCat(CurrentItemPackage->Value, Argv[LoopCounter], CurrentValueSize/sizeof(CHAR16) - 1 - StrLen(CurrentItemPackage->Value)); + StrnCat(CurrentItemPackage->Value, L"\"", CurrentValueSize/sizeof(CHAR16) - 1 - StrLen(CurrentItemPackage->Value)); + } + ValueSize += StrSize(Argv[LoopCounter]) + sizeof(CHAR16); } - ValueSize += StrSize(Argv[LoopCounter]) + sizeof(CHAR16); GetItemValue--; if (GetItemValue == 0) { InsertHeadList(*CheckPackage, &CurrentItemPackage->Link); } - } else if (!InternalIsFlag(Argv[LoopCounter], AlwaysAllowNumbers) ){ //|| ProblemParam == NULL) { + } else if (!InternalIsFlag(Argv[LoopCounter], AlwaysAllowNumbers, FALSE)){ // // add this one as a non-flag // TempPointer = Argv[LoopCounter]; - if ((*TempPointer == L'^' && *(TempPointer+1) == L'-') + if ((*TempPointer == L'^' && *(TempPointer+1) == L'-') || (*TempPointer == L'^' && *(TempPointer+1) == L'/') || (*TempPointer == L'^' && *(TempPointer+1) == L'+') ){ @@ -2045,13 +2159,12 @@ InternalCommandLineParse ( } CurrentItemPackage->Name = NULL; CurrentItemPackage->Type = TypePosition; - CurrentItemPackage->Value = AllocateZeroPool(StrSize(TempPointer)); + CurrentItemPackage->Value = AllocateCopyPool(StrSize(TempPointer), TempPointer); if (CurrentItemPackage->Value == NULL) { ShellCommandLineFreeVarList(*CheckPackage); *CheckPackage = NULL; return (EFI_OUT_OF_RESOURCES); } - StrCpy(CurrentItemPackage->Value, TempPointer); CurrentItemPackage->OriginalPosition = Count++; InsertHeadList(*CheckPackage, &CurrentItemPackage->Link); } else { @@ -2059,10 +2172,7 @@ InternalCommandLineParse ( // this was a non-recognised flag... error! // if (ProblemParam != NULL) { - *ProblemParam = AllocateZeroPool(StrSize(Argv[LoopCounter])); - if (*ProblemParam != NULL) { - StrCpy(*ProblemParam, Argv[LoopCounter]); - } + *ProblemParam = AllocateCopyPool(StrSize(Argv[LoopCounter]), Argv[LoopCounter]); } ShellCommandLineFreeVarList(*CheckPackage); *CheckPackage = NULL; @@ -2529,7 +2639,7 @@ ShellCopySearchAndReplace( if (Replace == NULL) { return (EFI_OUT_OF_RESOURCES); } - NewString = SetMem16(NewString, NewSize, CHAR_NULL); + NewString = ZeroMem(NewString, NewSize); while (*SourceString != CHAR_NULL) { // // if we find the FindTarget and either Skip == FALSE or Skip and we @@ -2544,7 +2654,7 @@ ShellCopySearchAndReplace( FreePool(Replace); return (EFI_BUFFER_TOO_SMALL); } - StrCat(NewString, Replace); + StrnCat(NewString, Replace, NewSize/sizeof(CHAR16) - 1 - StrLen(NewString)); } else { Size = StrSize(NewString); if (Size + sizeof(CHAR16) > NewSize) { @@ -2584,10 +2694,12 @@ InternalPrintTo ( return (gEfiShellProtocol->WriteFile(gEfiShellParametersProtocol->StdOut, &Size, (VOID*)String)); } if (mEfiShellInterface != NULL) { + if (mEfiShellInterface->RedirArgc == 0) { // // Divide in half for old shell. Must be string length not size. - // - Size /= 2; + // + Size /=2; // Divide in half only when no redirection. + } return (mEfiShellInterface->StdOut->Write(mEfiShellInterface->StdOut, &Size, (VOID*)String)); } ASSERT(FALSE); @@ -2698,6 +2810,11 @@ InternalShellPrintWorker( // if (ResumeLocation != NULL) { if (*(ResumeLocation-1) == L'^') { + // + // Move cursor back 1 position to overwrite the ^ + // + gST->ConOut->SetCursorPosition(gST->ConOut, gST->ConOut->Mode->CursorColumn - 1, gST->ConOut->Mode->CursorRow); + // // Print a simple '%' symbol // @@ -2865,9 +2982,10 @@ ShellPrintHiiEx( @param[in] DirName Path to directory to test. - @retval EFI_SUCCESS The Path represents a directory - @retval EFI_NOT_FOUND The Path does not represent a directory - @return other The path failed to open + @retval EFI_SUCCESS The Path represents a directory + @retval EFI_NOT_FOUND The Path does not represent a directory + @retval EFI_OUT_OF_RESOURCES A memory allocation failed. + @return The path failed to open **/ EFI_STATUS EFIAPI @@ -2892,6 +3010,10 @@ ShellIsDirectory( // if (gEfiShellProtocol != NULL) { TempLocation = StrnCatGrow(&TempLocation, NULL, DirName, 0); + if (TempLocation == NULL) { + ShellCloseFile(&Handle); + return (EFI_OUT_OF_RESOURCES); + } TempLocation2 = StrStr(TempLocation, L":"); if (TempLocation2 != NULL && StrLen(StrStr(TempLocation, L":")) == 2) { *(TempLocation2+1) = CHAR_NULL; @@ -2991,9 +3113,35 @@ ShellIsFileInPath( return (Status); } +/** + Function return the number converted from a hex representation of a number. + + Note: this function cannot be used when (UINTN)(-1), (0xFFFFFFFF) may be a valid + result. Use ShellConvertStringToUint64 instead. + + @param[in] String String representation of a number. + + @return The unsigned integer result of the conversion. + @retval (UINTN)(-1) An error occured. +**/ +UINTN +EFIAPI +ShellHexStrToUintn( + IN CONST CHAR16 *String + ) +{ + UINT64 RetVal; + + if (!EFI_ERROR(ShellConvertStringToUint64(String, &RetVal, TRUE, TRUE))) { + return ((UINTN)RetVal); + } + + return ((UINTN)(-1)); +} + /** Function to determine whether a string is decimal or hex representation of a number - and return the number converted from the string. + and return the number converted from the string. Spaces are always skipped. @param[in] String String representation of a number @@ -3011,7 +3159,7 @@ ShellStrToUintn( Hex = FALSE; - if (!InternalShellIsHexOrDecimalNumber(String, Hex, TRUE)) { + if (!InternalShellIsHexOrDecimalNumber(String, Hex, TRUE, FALSE)) { Hex = TRUE; } @@ -3108,11 +3256,13 @@ StrnCatGrow ( // if (CurrentSize != NULL) { NewSize = *CurrentSize; - while (NewSize < (DestinationStartSize + (Count*sizeof(CHAR16)))) { - NewSize += 2 * Count * sizeof(CHAR16); + if (NewSize < DestinationStartSize + (Count * sizeof(CHAR16))) { + while (NewSize < (DestinationStartSize + (Count*sizeof(CHAR16)))) { + NewSize += 2 * Count * sizeof(CHAR16); + } + *Destination = ReallocatePool(*CurrentSize, NewSize, *Destination); + *CurrentSize = NewSize; } - *Destination = ReallocatePool(*CurrentSize, NewSize, *Destination); - *CurrentSize = NewSize; } else { *Destination = AllocateZeroPool((Count+1)*sizeof(CHAR16)); } @@ -3186,7 +3336,9 @@ ShellPromptForResponse ( // gBS->WaitForEvent (1, &gST->ConIn->WaitForKey, &EventIndex); Status = gST->ConIn->ReadKeyStroke (gST->ConIn, &Key); - ASSERT_EFI_ERROR(Status); + if (EFI_ERROR(Status)) { + break; + } ShellPrintEx(-1, -1, L"%c", Key.UnicodeChar); if (Key.UnicodeChar == L'Q' || Key.UnicodeChar ==L'q') { *Resp = ShellPromptResponseQuit; @@ -3203,9 +3355,15 @@ ShellPromptForResponse ( // *Resp = ShellPromptResponseMax; while (*Resp == ShellPromptResponseMax) { + if (ShellGetExecutionBreakFlag()) { + Status = EFI_ABORTED; + break; + } gBS->WaitForEvent (1, &gST->ConIn->WaitForKey, &EventIndex); Status = gST->ConIn->ReadKeyStroke (gST->ConIn, &Key); - ASSERT_EFI_ERROR(Status); + if (EFI_ERROR(Status)) { + break; + } ShellPrintEx(-1, -1, L"%c", Key.UnicodeChar); switch (Key.UnicodeChar) { case L'Y': @@ -3231,9 +3389,15 @@ ShellPromptForResponse ( // *Resp = ShellPromptResponseMax; while (*Resp == ShellPromptResponseMax) { + if (ShellGetExecutionBreakFlag()) { + Status = EFI_ABORTED; + break; + } gBS->WaitForEvent (1, &gST->ConIn->WaitForKey, &EventIndex); Status = gST->ConIn->ReadKeyStroke (gST->ConIn, &Key); - ASSERT_EFI_ERROR(Status); + if (EFI_ERROR(Status)) { + break; + } ShellPrintEx(-1, -1, L"%c", Key.UnicodeChar); switch (Key.UnicodeChar) { case L'Y': @@ -3265,10 +3429,16 @@ ShellPromptForResponse ( // *Resp = ShellPromptResponseMax; while (*Resp == ShellPromptResponseMax) { + if (ShellGetExecutionBreakFlag()) { + Status = EFI_ABORTED; + break; + } gBS->WaitForEvent (1, &gST->ConIn->WaitForKey, &EventIndex); if (Type == ShellPromptResponseTypeEnterContinue) { Status = gST->ConIn->ReadKeyStroke (gST->ConIn, &Key); - ASSERT_EFI_ERROR(Status); + if (EFI_ERROR(Status)) { + break; + } ShellPrintEx(-1, -1, L"%c", Key.UnicodeChar); if (Key.UnicodeChar == CHAR_CARRIAGE_RETURN) { *Resp = ShellPromptResponseContinue; @@ -3292,9 +3462,15 @@ ShellPromptForResponse ( // *Resp = ShellPromptResponseMax; while (*Resp == ShellPromptResponseMax) { + if (ShellGetExecutionBreakFlag()) { + Status = EFI_ABORTED; + break; + } gBS->WaitForEvent (1, &gST->ConIn->WaitForKey, &EventIndex); Status = gST->ConIn->ReadKeyStroke (gST->ConIn, &Key); - ASSERT_EFI_ERROR(Status); + if (EFI_ERROR(Status)) { + break; + } ShellPrintEx(-1, -1, L"%c", Key.UnicodeChar); switch (Key.UnicodeChar) { case L'Y': @@ -3313,9 +3489,15 @@ ShellPromptForResponse ( ShellPrintEx(-1, -1, L"%s", Prompt); } while(1) { + if (ShellGetExecutionBreakFlag()) { + Status = EFI_ABORTED; + break; + } gBS->WaitForEvent (1, &gST->ConIn->WaitForKey, &EventIndex); Status = gST->ConIn->ReadKeyStroke (gST->ConIn, &Key); - ASSERT_EFI_ERROR(Status); + if (EFI_ERROR(Status)) { + break; + } ShellPrintEx(-1, -1, L"%c", Key.UnicodeChar); if (Key.UnicodeChar == CHAR_CARRIAGE_RETURN) { break; @@ -3326,6 +3508,7 @@ ShellPromptForResponse ( break; // // This is the location to add new prompt types. + // If your new type loops remember to add ExecutionBreak support. // default: ASSERT(FALSE); @@ -3393,6 +3576,7 @@ ShellPromptForResponseHii ( @param[in] String The string to evaluate. @param[in] ForceHex TRUE - always assume hex. @param[in] StopAtSpace TRUE to halt upon finding a space, FALSE to keep going. + @param[in] TimeNumbers TRUE to allow numbers with ":", FALSE otherwise. @retval TRUE It is all numeric (dec/hex) characters. @retval FALSE There is a non-numeric character. @@ -3402,7 +3586,8 @@ EFIAPI InternalShellIsHexOrDecimalNumber ( IN CONST CHAR16 *String, IN CONST BOOLEAN ForceHex, - IN CONST BOOLEAN StopAtSpace + IN CONST BOOLEAN StopAtSpace, + IN CONST BOOLEAN TimeNumbers ) { BOOLEAN Hex; @@ -3413,7 +3598,7 @@ InternalShellIsHexOrDecimalNumber ( if (String != NULL && *String == L'-') { String++; } - + if (String == NULL) { return (FALSE); } @@ -3446,6 +3631,9 @@ InternalShellIsHexOrDecimalNumber ( // loop through the remaining characters and use the lib function // for ( ; String != NULL && *String != CHAR_NULL && !(StopAtSpace && *String == L' ') ; String++){ + if (TimeNumbers && (String[0] == L':')) { + continue; + } if (Hex) { if (!ShellIsHexaDecimalDigitCharacter(*String)) { return (FALSE); @@ -3492,7 +3680,7 @@ ShellFileExists( } /** - Convert a Unicode character to upper case only if + Convert a Unicode character to upper case only if it maps to a valid small-case ASCII character. This internal function only deal with Unicode character @@ -3524,7 +3712,7 @@ InternalShellCharToUpper ( This internal function only deal with Unicode character which maps to a valid hexadecimal ASII character, i.e. - L'0' to L'9', L'a' to L'f' or L'A' to L'F'. For other + L'0' to L'9', L'a' to L'f' or L'A' to L'F'. For other Unicode character, the value returned does not make sense. @param Char The character to convert. @@ -3588,9 +3776,9 @@ InternalShellStrHexToUint64 ( if (String == NULL || StrSize(String) == 0 || Value == NULL) { return (EFI_INVALID_PARAMETER); } - + // - // Ignore the pad spaces (space or tab) + // Ignore the pad spaces (space or tab) // while ((*String == L' ') || (*String == L'\t')) { String++; @@ -3614,17 +3802,17 @@ InternalShellStrHexToUint64 ( } Result = 0; - + // // Skip spaces if requested // while (StopAtSpace && *String == L' ') { String++; } - + while (ShellIsHexaDecimalDigitCharacter (*String)) { // - // If the Hex Number represented by String overflows according + // If the Hex Number represented by String overflows according // to the range defined by UINTN, then ASSERT(). // if (!(Result <= (RShiftU64((((UINT64) ~0) - InternalShellHexCharToUintn (*String)), 4)))) { @@ -3637,10 +3825,10 @@ InternalShellStrHexToUint64 ( String++; // - // Skip spaces if requested + // stop at spaces if requested // - while (StopAtSpace && *String == L' ') { - String++; + if (StopAtSpace && *String == L' ') { + break; } } @@ -3715,10 +3903,10 @@ InternalShellStrDecimalToUint64 ( } while (ShellIsDecimalDigitCharacter (*String)) { // - // If the number represented by String overflows according + // If the number represented by String overflows according // to the range defined by UINT64, then ASSERT(). // - + if (!(Result <= (DivU64x32((((UINT64) ~0) - (*String - L'0')),10)))) { return (EFI_DEVICE_ERROR); } @@ -3735,7 +3923,7 @@ InternalShellStrDecimalToUint64 ( } *Value = Result; - + return (EFI_SUCCESS); } @@ -3748,7 +3936,7 @@ InternalShellStrDecimalToUint64 ( @param[out] Value Upon a successful return the value of the conversion. @param[in] ForceHex TRUE - always assume hex. @param[in] StopAtSpace FALSE to skip spaces. - + @retval EFI_SUCCESS The conversion was successful. @retval EFI_INVALID_PARAMETER String contained an invalid character. @retval EFI_NOT_FOUND String was a number, but Value was NULL. @@ -3769,10 +3957,10 @@ ShellConvertStringToUint64( Hex = ForceHex; - if (!InternalShellIsHexOrDecimalNumber(String, Hex, StopAtSpace)) { + if (!InternalShellIsHexOrDecimalNumber(String, Hex, StopAtSpace, FALSE)) { if (!Hex) { Hex = TRUE; - if (!InternalShellIsHexOrDecimalNumber(String, Hex, StopAtSpace)) { + if (!InternalShellIsHexOrDecimalNumber(String, Hex, StopAtSpace, FALSE)) { return (EFI_INVALID_PARAMETER); } } else { @@ -3788,9 +3976,9 @@ ShellConvertStringToUint64( // // make sure we have something left that is numeric. // - if (Walker == NULL || *Walker == CHAR_NULL || !InternalShellIsHexOrDecimalNumber(Walker, Hex, StopAtSpace)) { + if (Walker == NULL || *Walker == CHAR_NULL || !InternalShellIsHexOrDecimalNumber(Walker, Hex, StopAtSpace, FALSE)) { return (EFI_INVALID_PARAMETER); - } + } // // do the conversion. @@ -3875,7 +4063,7 @@ ShellFileHandleReturnLine( return (NULL); } Status = ShellFileHandleReadLine(Handle, RetVal, &Size, FALSE, Ascii); - + } if (EFI_ERROR(Status) && (RetVal != NULL)) { FreePool(RetVal); @@ -3992,3 +4180,146 @@ ShellFileHandleReadLine( return (Status); } + +/** + Function to print help file / man page content in the spec from the UEFI Shell protocol GetHelpText function. + + @param[in] CommandToGetHelpOn Pointer to a string containing the command name of help file to be printed. + @param[in] SectionToGetHelpOn Pointer to the section specifier(s). + @param[in] PrintCommandText If TRUE, prints the command followed by the help content, otherwise prints + the help content only. + @retval EFI_DEVICE_ERROR The help data format was incorrect. + @retval EFI_NOT_FOUND The help data could not be found. + @retval EFI_SUCCESS The operation was successful. +**/ +EFI_STATUS +EFIAPI +ShellPrintHelp ( + IN CONST CHAR16 *CommandToGetHelpOn, + IN CONST CHAR16 *SectionToGetHelpOn, + IN BOOLEAN PrintCommandText + ) +{ + EFI_STATUS Status; + CHAR16 *OutText; + + OutText = NULL; + + // + // Get the string to print based + // + Status = gEfiShellProtocol->GetHelpText (CommandToGetHelpOn, SectionToGetHelpOn, &OutText); + + // + // make sure we got a valid string + // + if (EFI_ERROR(Status)){ + return Status; + } + if (OutText == NULL || StrLen(OutText) == 0) { + return EFI_NOT_FOUND; + } + + // + // Chop off trailing stuff we dont need + // + while (OutText[StrLen(OutText)-1] == L'\r' || OutText[StrLen(OutText)-1] == L'\n' || OutText[StrLen(OutText)-1] == L' ') { + OutText[StrLen(OutText)-1] = CHAR_NULL; + } + + // + // Print this out to the console + // + if (PrintCommandText) { + ShellPrintEx(-1, -1, L"%H%-14s%N- %s\r\n", CommandToGetHelpOn, OutText); + } else { + ShellPrintEx(-1, -1, L"%N%s\r\n", OutText); + } + + SHELL_FREE_NON_NULL(OutText); + + return EFI_SUCCESS; +} + +/** + Function to delete a file by name + + @param[in] FileName Pointer to file name to delete. + + @retval EFI_SUCCESS the file was deleted sucessfully + @retval EFI_WARN_DELETE_FAILURE the handle was closed, but the file was not + deleted + @retval EFI_INVALID_PARAMETER One of the parameters has an invalid value. + @retval EFI_NOT_FOUND The specified file could not be found on the + device or the file system could not be found + on the device. + @retval EFI_NO_MEDIA The device has no medium. + @retval EFI_MEDIA_CHANGED The device has a different medium in it or the + medium is no longer supported. + @retval EFI_DEVICE_ERROR The device reported an error. + @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted. + @retval EFI_WRITE_PROTECTED The file or medium is write protected. + @retval EFI_ACCESS_DENIED The file was opened read only. + @retval EFI_OUT_OF_RESOURCES Not enough resources were available to open the + file. + @retval other The file failed to open +**/ +EFI_STATUS +EFIAPI +ShellDeleteFileByName( + IN CONST CHAR16 *FileName + ) +{ + EFI_STATUS Status; + SHELL_FILE_HANDLE FileHandle; + + Status = ShellFileExists(FileName); + + if (Status == EFI_SUCCESS){ + Status = ShellOpenFileByName(FileName, &FileHandle, EFI_FILE_MODE_READ | EFI_FILE_MODE_WRITE | EFI_FILE_MODE_CREATE, 0x0); + if (Status == EFI_SUCCESS){ + Status = ShellDeleteFile(&FileHandle); + } + } + + return(Status); + +} + +/** + Cleans off all the quotes in the string. + + @param[in] OriginalString pointer to the string to be cleaned. + @param[out] CleanString The new string with all quotes removed. + Memory allocated in the function and free + by caller. + + @retval EFI_SUCCESS The operation was successful. +**/ +EFI_STATUS +EFIAPI +InternalShellStripQuotes ( + IN CONST CHAR16 *OriginalString, + OUT CHAR16 **CleanString + ) +{ + CHAR16 *Walker; + + if (OriginalString == NULL || CleanString == NULL) { + return EFI_INVALID_PARAMETER; + } + + *CleanString = AllocateCopyPool (StrSize (OriginalString), OriginalString); + if (*CleanString == NULL) { + return EFI_OUT_OF_RESOURCES; + } + + for (Walker = *CleanString; Walker != NULL && *Walker != CHAR_NULL ; Walker++) { + if (*Walker == L'\"') { + CopyMem(Walker, Walker+1, StrSize(Walker) - sizeof(Walker[0])); + } + } + + return EFI_SUCCESS; +} +