X-Git-Url: https://git.proxmox.com/?a=blobdiff_plain;f=ShellPkg%2FLibrary%2FUefiShellCommandLib%2FUefiShellCommandLib.c;h=a2ebc8f8206118852b7d17540504de8d79321139;hb=17c3dc19395121486c6f1614dbc564f39763720a;hp=2c1dcd3c1308f59a43a69ff576611e4dcdc90daf;hpb=4ff7e37b4f7e336a8ecb7080b8f48eef4b52d396;p=mirror_edk2.git diff --git a/ShellPkg/Library/UefiShellCommandLib/UefiShellCommandLib.c b/ShellPkg/Library/UefiShellCommandLib/UefiShellCommandLib.c index 2c1dcd3c13..a2ebc8f820 100644 --- a/ShellPkg/Library/UefiShellCommandLib/UefiShellCommandLib.c +++ b/ShellPkg/Library/UefiShellCommandLib/UefiShellCommandLib.c @@ -1,7 +1,10 @@ /** @file Provides interface to shell internal functions for shell commands. - Copyright (c) 2009 - 2011, Intel Corporation. All rights reserved.
+ Copyright (c) 2009 - 2016, Intel Corporation. All rights reserved.
+ (C) Copyright 2013-2015 Hewlett-Packard Development Company, L.P.
+ (C) Copyright 2016 Hewlett Packard Enterprise Development LP
+ 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 @@ -14,18 +17,13 @@ #include "UefiShellCommandLib.h" -/// The tag for use in identifying UNICODE files. -/// If the file is UNICODE, the first 16 bits of the file will equal this value. -enum { - gUnicodeFileTag = 0xFEFF -}; - // STATIC local variables STATIC SHELL_COMMAND_INTERNAL_LIST_ENTRY mCommandList; STATIC SCRIPT_FILE_LIST mScriptList; STATIC ALIAS_LIST mAliasList; STATIC BOOLEAN mEchoState; STATIC BOOLEAN mExitRequested; +STATIC UINT64 mExitCode; STATIC BOOLEAN mExitScript; STATIC CHAR16 *mProfileList; STATIC UINTN mProfileListSize; @@ -33,9 +31,27 @@ STATIC UINTN mFsMaxCount = 0; STATIC UINTN mBlkMaxCount = 0; STATIC BUFFER_LIST mFileHandleList; +STATIC CONST CHAR8 Hex[] = { + '0', + '1', + '2', + '3', + '4', + '5', + '6', + '7', + '8', + '9', + 'A', + 'B', + 'C', + 'D', + 'E', + 'F' +}; + // global variables required by library class. EFI_UNICODE_COLLATION_PROTOCOL *gUnicodeCollation = NULL; -EFI_DEVICE_PATH_TO_TEXT_PROTOCOL *gDevPathToText = NULL; SHELL_MAP_LIST gShellMapList; SHELL_MAP_LIST *gShellCurDir = NULL; @@ -63,12 +79,6 @@ CommandInit( return (EFI_DEVICE_ERROR); } } - if (gDevPathToText == NULL) { - Status = gBS->LocateProtocol(&gEfiDevicePathToTextProtocolGuid, NULL, (VOID**)&gDevPathToText); - if (EFI_ERROR(Status)) { - return (EFI_DEVICE_ERROR); - } - } return (EFI_SUCCESS); } @@ -112,6 +122,36 @@ ShellCommandLibConstructor ( return (RETURN_SUCCESS); } +/** + Frees list of file handles. + + @param[in] List The list to free. +**/ +VOID +FreeFileHandleList ( + IN BUFFER_LIST *List + ) +{ + BUFFER_LIST *BufferListEntry; + + if (List == NULL){ + return; + } + // + // enumerate through the buffer list and free all memory + // + for ( BufferListEntry = ( BUFFER_LIST *)GetFirstNode(&List->Link) + ; !IsListEmpty (&List->Link) + ; BufferListEntry = (BUFFER_LIST *)GetFirstNode(&List->Link) + ){ + RemoveEntryList(&BufferListEntry->Link); + ASSERT(BufferListEntry->Buffer != NULL); + SHELL_FREE_NON_NULL(((SHELL_COMMAND_FILE_HANDLE*)(BufferListEntry->Buffer))->Path); + SHELL_FREE_NON_NULL(BufferListEntry->Buffer); + SHELL_FREE_NON_NULL(BufferListEntry); + } +} + /** Destructor for the library. free any resources. @@ -128,7 +168,7 @@ ShellCommandLibDestructor ( ) { SHELL_COMMAND_INTERNAL_LIST_ENTRY *Node; - COMMAND_LIST *Node2; + ALIAS_LIST *Node2; SCRIPT_FILE_LIST *Node3; SHELL_MAP_LIST *MapNode; // @@ -143,13 +183,14 @@ ShellCommandLibDestructor ( } // - // enumerate through the init command list and free all memory + // enumerate through the alias list and free all memory // while (!IsListEmpty (&mAliasList.Link)) { - Node2 = (COMMAND_LIST *)GetFirstNode(&mAliasList.Link); + Node2 = (ALIAS_LIST *)GetFirstNode(&mAliasList.Link); RemoveEntryList(&Node2->Link); SHELL_FREE_NON_NULL(Node2->CommandString); - FreePool(Node2); + SHELL_FREE_NON_NULL(Node2->Alias); + SHELL_FREE_NON_NULL(Node2); DEBUG_CODE(Node2 = NULL;); } @@ -180,7 +221,7 @@ ShellCommandLibDestructor ( } } if (!IsListEmpty(&mFileHandleList.Link)){ - FreeBufferList(&mFileHandleList); + FreeFileHandleList(&mFileHandleList); } if (mProfileList != NULL) { @@ -188,21 +229,83 @@ ShellCommandLibDestructor ( } gUnicodeCollation = NULL; - gDevPathToText = NULL; gShellCurDir = NULL; return (RETURN_SUCCESS); } /** - Checks if a command is already on the list. + Find a dynamic command protocol instance given a command name string. + + @param CommandString the command name string + + @return instance the command protocol instance, if dynamic command instance found + @retval NULL no dynamic command protocol instance found for name +**/ +CONST EFI_SHELL_DYNAMIC_COMMAND_PROTOCOL * +ShellCommandFindDynamicCommand ( + IN CONST CHAR16 *CommandString + ) +{ + EFI_STATUS Status; + EFI_HANDLE *CommandHandleList; + EFI_HANDLE *NextCommand; + EFI_SHELL_DYNAMIC_COMMAND_PROTOCOL *DynamicCommand; + + CommandHandleList = GetHandleListByProtocol(&gEfiShellDynamicCommandProtocolGuid); + if (CommandHandleList == NULL) { + // + // not found or out of resources + // + return NULL; + } + + for (NextCommand = CommandHandleList; *NextCommand != NULL; NextCommand++) { + Status = gBS->HandleProtocol( + *NextCommand, + &gEfiShellDynamicCommandProtocolGuid, + (VOID **)&DynamicCommand + ); + + if (EFI_ERROR(Status)) { + continue; + } + + if (gUnicodeCollation->StriColl( + gUnicodeCollation, + (CHAR16*)CommandString, + (CHAR16*)DynamicCommand->CommandName) == 0 + ){ + FreePool(CommandHandleList); + return (DynamicCommand); + } + } + + FreePool(CommandHandleList); + return (NULL); +} + +/** + Checks if a command exists as a dynamic command protocol instance @param[in] CommandString The command string to check for on the list. **/ BOOLEAN -EFIAPI -ShellCommandIsCommandOnList ( - IN CONST CHAR16 *CommandString +ShellCommandDynamicCommandExists ( + IN CONST CHAR16 *CommandString + ) +{ + return (BOOLEAN) ((ShellCommandFindDynamicCommand(CommandString) != NULL)); +} + +/** + Checks if a command is already on the internal command list. + + @param[in] CommandString The command string to check for on the list. +**/ +BOOLEAN +ShellCommandIsCommandOnInternalList( + IN CONST CHAR16 *CommandString ) { SHELL_COMMAND_INTERNAL_LIST_ENTRY *Node; @@ -232,7 +335,51 @@ ShellCommandIsCommandOnList ( } /** - Get the help text for a command. + Checks if a command exists, either internally or through the dynamic command protocol. + + @param[in] CommandString The command string to check for on the list. +**/ +BOOLEAN +EFIAPI +ShellCommandIsCommandOnList( + IN CONST CHAR16 *CommandString + ) +{ + if (ShellCommandIsCommandOnInternalList(CommandString)) { + return TRUE; + } + + return ShellCommandDynamicCommandExists(CommandString); +} + +/** + Get the help text for a dynamic command. + + @param[in] CommandString The command name. + + @retval NULL No help text was found. + @return String of help text. Caller required to free. +**/ +CHAR16* +ShellCommandGetDynamicCommandHelp( + IN CONST CHAR16 *CommandString + ) +{ + EFI_SHELL_DYNAMIC_COMMAND_PROTOCOL *DynamicCommand; + + DynamicCommand = (EFI_SHELL_DYNAMIC_COMMAND_PROTOCOL *)ShellCommandFindDynamicCommand(CommandString); + if (DynamicCommand == NULL) { + return (NULL); + } + + // + // TODO: how to get proper language? + // + return DynamicCommand->GetHelp(DynamicCommand, "en"); +} + +/** + Get the help text for an internal command. @param[in] CommandString The command name. @@ -240,8 +387,7 @@ ShellCommandIsCommandOnList ( @return String of help text. Caller reuiqred to free. **/ CHAR16* -EFIAPI -ShellCommandGetCommandHelp ( +ShellCommandGetInternalCommandHelp( IN CONST CHAR16 *CommandString ) { @@ -271,6 +417,31 @@ ShellCommandGetCommandHelp ( return (NULL); } +/** + Get the help text for a command. + + @param[in] CommandString The command name. + + @retval NULL No help text was found. + @return String of help text.Caller reuiqred to free. +**/ +CHAR16* +EFIAPI +ShellCommandGetCommandHelp ( + IN CONST CHAR16 *CommandString + ) +{ + CHAR16 *HelpStr; + HelpStr = ShellCommandGetInternalCommandHelp(CommandString); + + if (HelpStr == NULL) { + HelpStr = ShellCommandGetDynamicCommandHelp(CommandString); + } + + return HelpStr; +} + + /** Registers handlers of type SHELL_RUN_COMMAND and SHELL_GET_MAN_FILENAME for each shell command. @@ -332,6 +503,16 @@ ShellCommandRegisterCommandName ( ) { SHELL_COMMAND_INTERNAL_LIST_ENTRY *Node; + SHELL_COMMAND_INTERNAL_LIST_ENTRY *Command; + SHELL_COMMAND_INTERNAL_LIST_ENTRY *PrevCommand; + INTN LexicalMatchValue; + + // + // Initialize local variables. + // + Command = NULL; + PrevCommand = NULL; + LexicalMatchValue = 0; // // ASSERTs for NULL parameters @@ -359,14 +540,14 @@ ShellCommandRegisterCommandName ( // allocate memory for new struct // Node = AllocateZeroPool(sizeof(SHELL_COMMAND_INTERNAL_LIST_ENTRY)); - ASSERT(Node != NULL); - Node->CommandString = AllocateZeroPool(StrSize(CommandString)); - ASSERT(Node->CommandString != NULL); - - // - // populate the new struct - // - StrCpy(Node->CommandString, CommandString); + if (Node == NULL) { + return RETURN_OUT_OF_RESOURCES; + } + Node->CommandString = AllocateCopyPool(StrSize(CommandString), CommandString); + if (Node->CommandString == NULL) { + FreePool (Node); + return RETURN_OUT_OF_RESOURCES; + } Node->GetManFileName = GetManFileName; Node->CommandHandler = CommandHandler; @@ -390,9 +571,40 @@ ShellCommandRegisterCommandName ( } // - // add the new struct to the list + // Insert a new entry on top of the list + // + InsertHeadList (&mCommandList.Link, &Node->Link); + + // + // Move a new registered command to its sorted ordered location in the list // - InsertTailList (&mCommandList.Link, &Node->Link); + for (Command = (SHELL_COMMAND_INTERNAL_LIST_ENTRY *)GetFirstNode (&mCommandList.Link), + PrevCommand = (SHELL_COMMAND_INTERNAL_LIST_ENTRY *)GetFirstNode (&mCommandList.Link) + ; !IsNull (&mCommandList.Link, &Command->Link) + ; Command = (SHELL_COMMAND_INTERNAL_LIST_ENTRY *)GetNextNode (&mCommandList.Link, &Command->Link)) { + + // + // Get Lexical Comparison Value between PrevCommand and Command list entry + // + LexicalMatchValue = gUnicodeCollation->StriColl ( + gUnicodeCollation, + PrevCommand->CommandString, + Command->CommandString + ); + + // + // Swap PrevCommand and Command list entry if PrevCommand list entry + // is alphabetically greater than Command list entry + // + if (LexicalMatchValue > 0){ + Command = (SHELL_COMMAND_INTERNAL_LIST_ENTRY *) SwapListEntries (&PrevCommand->Link, &Command->Link); + } else if (LexicalMatchValue < 0) { + // + // PrevCommand entry is lexically lower than Command entry + // + break; + } + } return (RETURN_SUCCESS); } @@ -444,7 +656,8 @@ ShellCommandRunCommandHandler ( IN OUT BOOLEAN *CanAffectLE OPTIONAL ) { - SHELL_COMMAND_INTERNAL_LIST_ENTRY *Node; + SHELL_COMMAND_INTERNAL_LIST_ENTRY *Node; + EFI_SHELL_DYNAMIC_COMMAND_PROTOCOL *DynamicCommand; // // assert for NULL parameters @@ -463,7 +676,7 @@ ShellCommandRunCommandHandler ( gUnicodeCollation, (CHAR16*)CommandString, Node->CommandString) == 0 - ){ + ){ if (CanAffectLE != NULL) { *CanAffectLE = Node->LastError; } @@ -475,6 +688,20 @@ ShellCommandRunCommandHandler ( return (RETURN_SUCCESS); } } + + // + // An internal command was not found, try to find a dynamic command + // + DynamicCommand = (EFI_SHELL_DYNAMIC_COMMAND_PROTOCOL *)ShellCommandFindDynamicCommand(CommandString); + if (DynamicCommand != NULL) { + if (RetVal != NULL) { + *RetVal = DynamicCommand->Handler(DynamicCommand, gST, gEfiShellParametersProtocol, gEfiShellProtocol); + } else { + DynamicCommand->Handler(DynamicCommand, gST, gEfiShellParametersProtocol, gEfiShellProtocol); + } + return (RETURN_SUCCESS); + } + return (RETURN_NOT_FOUND); } @@ -565,6 +792,9 @@ ShellCommandRegisterAlias ( ) { ALIAS_LIST *Node; + ALIAS_LIST *CommandAlias; + ALIAS_LIST *PrevCommandAlias; + INTN LexicalMatchValue; // // Asserts for NULL @@ -576,22 +806,52 @@ ShellCommandRegisterAlias ( // allocate memory for new struct // Node = AllocateZeroPool(sizeof(ALIAS_LIST)); - ASSERT(Node != NULL); - Node->CommandString = AllocateZeroPool(StrSize(Command)); - Node->Alias = AllocateZeroPool(StrSize(Alias)); - ASSERT(Node->CommandString != NULL); - ASSERT(Node->Alias != NULL); + if (Node == NULL) { + return RETURN_OUT_OF_RESOURCES; + } + Node->CommandString = AllocateCopyPool(StrSize(Command), Command); + if (Node->CommandString == NULL) { + FreePool (Node); + return RETURN_OUT_OF_RESOURCES; + } + Node->Alias = AllocateCopyPool(StrSize(Alias), Alias); + if (Node->Alias == NULL) { + FreePool (Node->CommandString); + FreePool (Node); + return RETURN_OUT_OF_RESOURCES; + } - // - // populate the new struct - // - StrCpy(Node->CommandString, Command); - StrCpy(Node->Alias , Alias ); + InsertHeadList (&mAliasList.Link, &Node->Link); // - // add the new struct to the list + // Move a new pre-defined registered alias to its sorted ordered location in the list // - InsertTailList (&mAliasList.Link, &Node->Link); + for ( CommandAlias = (ALIAS_LIST *)GetFirstNode (&mAliasList.Link), + PrevCommandAlias = (ALIAS_LIST *)GetFirstNode (&mAliasList.Link) + ; !IsNull (&mAliasList.Link, &CommandAlias->Link) + ; CommandAlias = (ALIAS_LIST *) GetNextNode (&mAliasList.Link, &CommandAlias->Link) ) { + // + // Get Lexical comparison value between PrevCommandAlias and CommandAlias List Entry + // + LexicalMatchValue = gUnicodeCollation->StriColl ( + gUnicodeCollation, + PrevCommandAlias->Alias, + CommandAlias->Alias + ); + + // + // Swap PrevCommandAlias and CommandAlias list entry if PrevCommandAlias list entry + // is alphabetically greater than CommandAlias list entry + // + if (LexicalMatchValue > 0) { + CommandAlias = (ALIAS_LIST *) SwapListEntries (&PrevCommandAlias->Link, &CommandAlias->Link); + } else if (LexicalMatchValue < 0) { + // + // PrevCommandAlias entry is lexically lower than CommandAlias entry + // + break; + } + } return (RETURN_SUCCESS); } @@ -661,7 +921,7 @@ ShellCommandIsOnAliasList( } /** - Function to determine current state of ECHO. Echo determins if lines from scripts + Function to determine current state of ECHO. Echo determines if lines from scripts and ECHO commands are enabled. @retval TRUE Echo is currently enabled @@ -677,7 +937,7 @@ ShellCommandGetEchoState( } /** - Function to set current state of ECHO. Echo determins if lines from scripts + Function to set current state of ECHO. Echo determines if lines from scripts and ECHO commands are enabled. If State is TRUE, Echo will be enabled. @@ -697,12 +957,14 @@ ShellCommandSetEchoState( /** Indicate that the current shell or script should exit. - @param[in] ScriptOnly TRUE if only exiting a script, FALSE othrwise. + @param[in] ScriptOnly TRUE if exiting a script; FALSE otherwise. + @param[in] ErrorCode The 64 bit error code to return. **/ VOID EFIAPI ShellCommandRegisterExit ( - IN BOOLEAN ScriptOnly + IN BOOLEAN ScriptOnly, + IN CONST UINT64 ErrorCode ) { mExitRequested = (BOOLEAN)(!mExitRequested); @@ -711,6 +973,7 @@ ShellCommandRegisterExit ( } else { mExitScript = FALSE; } + mExitCode = ErrorCode; } /** @@ -728,6 +991,21 @@ ShellCommandGetExit ( return (mExitRequested); } +/** + Retrieve the Exit code. + + If ShellCommandGetExit returns FALSE than the return from this is undefined. + + @return the value passed into RegisterExit. +**/ +UINT64 +EFIAPI +ShellCommandGetExitCode ( + VOID + ) +{ + return (mExitCode); +} /** Retrieve the Exit script indicator. @@ -916,12 +1194,11 @@ ShellCommandAddMapItemAndUpdatePath( Status = EFI_OUT_OF_RESOURCES; } else { MapListNode->Flags = Flags; - MapListNode->MapName = AllocateZeroPool(StrSize(Name)); + MapListNode->MapName = AllocateCopyPool(StrSize(Name), Name); MapListNode->DevicePath = DuplicateDevicePath(DevicePath); if ((MapListNode->MapName == NULL) || (MapListNode->DevicePath == NULL)){ Status = EFI_OUT_OF_RESOURCES; } else { - StrCpy(MapListNode->MapName, Name); InsertTailList(&gShellMapList.Link, &MapListNode->Link); } } @@ -944,10 +1221,8 @@ ShellCommandAddMapItemAndUpdatePath( ASSERT((NewPath == NULL && NewPathSize == 0) || (NewPath != NULL)); if (OriginalPath != NULL) { StrnCatGrow(&NewPath, &NewPathSize, OriginalPath, 0); - } else { - StrnCatGrow(&NewPath, &NewPathSize, L".\\", 0); + StrnCatGrow(&NewPath, &NewPathSize, L";", 0); } - StrnCatGrow(&NewPath, &NewPathSize, L";", 0); StrnCatGrow(&NewPath, &NewPathSize, Name, 0); StrnCatGrow(&NewPath, &NewPathSize, L"\\efi\\tools\\;", 0); StrnCatGrow(&NewPath, &NewPathSize, Name, 0); @@ -1013,6 +1288,9 @@ ShellCommandCreateInitialMappingsAndPaths( ; MapListNode = (SHELL_MAP_LIST *)GetFirstNode(&gShellMapList.Link) ){ RemoveEntryList(&MapListNode->Link); + SHELL_FREE_NON_NULL(MapListNode->DevicePath); + SHELL_FREE_NON_NULL(MapListNode->MapName); + SHELL_FREE_NON_NULL(MapListNode->CurrentDirectoryPath); FreePool(MapListNode); } // for loop } @@ -1031,7 +1309,10 @@ ShellCommandCreateInitialMappingsAndPaths( // Get all Device Paths // DevicePathList = AllocateZeroPool(sizeof(EFI_DEVICE_PATH_PROTOCOL*) * Count); - ASSERT(DevicePathList != NULL); + if (DevicePathList == NULL) { + SHELL_FREE_NON_NULL (HandleList); + return EFI_OUT_OF_RESOURCES; + } for (Count = 0 ; HandleList[Count] != NULL ; Count++) { DevicePathList[Count] = DevicePathFromHandle(HandleList[Count]); @@ -1088,7 +1369,10 @@ ShellCommandCreateInitialMappingsAndPaths( // Get all Device Paths // DevicePathList = AllocateZeroPool(sizeof(EFI_DEVICE_PATH_PROTOCOL*) * Count); - ASSERT(DevicePathList != NULL); + if (DevicePathList == NULL) { + SHELL_FREE_NON_NULL (HandleList); + return EFI_OUT_OF_RESOURCES; + } for (Count = 0 ; HandleList[Count] != NULL ; Count++) { DevicePathList[Count] = DevicePathFromHandle(HandleList[Count]); @@ -1122,6 +1406,113 @@ ShellCommandCreateInitialMappingsAndPaths( return (EFI_SUCCESS); } +/** + Add mappings for any devices without one. Do not change any existing maps. + + @retval EFI_SUCCESS The operation was successful. +**/ +EFI_STATUS +EFIAPI +ShellCommandUpdateMapping ( + VOID + ) +{ + EFI_STATUS Status; + EFI_HANDLE *HandleList; + UINTN Count; + EFI_DEVICE_PATH_PROTOCOL **DevicePathList; + CHAR16 *NewDefaultName; + CHAR16 *NewConsistName; + EFI_DEVICE_PATH_PROTOCOL **ConsistMappingTable; + + HandleList = NULL; + Status = EFI_SUCCESS; + + // + // remove mappings that represent removed devices. + // + + // + // Find each handle with Simple File System + // + HandleList = GetHandleListByProtocol(&gEfiSimpleFileSystemProtocolGuid); + if (HandleList != NULL) { + // + // Do a count of the handles + // + for (Count = 0 ; HandleList[Count] != NULL ; Count++); + + // + // Get all Device Paths + // + DevicePathList = AllocateZeroPool(sizeof(EFI_DEVICE_PATH_PROTOCOL*) * Count); + if (DevicePathList == NULL) { + return (EFI_OUT_OF_RESOURCES); + } + + for (Count = 0 ; HandleList[Count] != NULL ; Count++) { + DevicePathList[Count] = DevicePathFromHandle(HandleList[Count]); + } + + // + // Sort all DevicePaths + // + PerformQuickSort(DevicePathList, Count, sizeof(EFI_DEVICE_PATH_PROTOCOL*), DevicePathCompare); + + ShellCommandConsistMappingInitialize(&ConsistMappingTable); + + // + // Assign new Mappings to remainders + // + for (Count = 0 ; !EFI_ERROR(Status) && HandleList[Count] != NULL && !EFI_ERROR(Status); Count++) { + // + // Skip ones that already have + // + if (gEfiShellProtocol->GetMapFromDevicePath(&DevicePathList[Count]) != NULL) { + continue; + } + // + // Get default name + // + NewDefaultName = ShellCommandCreateNewMappingName(MappingTypeFileSystem); + if (NewDefaultName == NULL) { + Status = EFI_OUT_OF_RESOURCES; + break; + } + + // + // Call shell protocol SetMap function now... + // + Status = gEfiShellProtocol->SetMap(DevicePathList[Count], NewDefaultName); + + if (!EFI_ERROR(Status)) { + // + // Now do consistent name + // + NewConsistName = ShellCommandConsistMappingGenMappingName(DevicePathList[Count], ConsistMappingTable); + if (NewConsistName != NULL) { + Status = gEfiShellProtocol->SetMap(DevicePathList[Count], NewConsistName); + FreePool(NewConsistName); + } + } + + FreePool(NewDefaultName); + } + ShellCommandConsistMappingUnInitialize(ConsistMappingTable); + SHELL_FREE_NON_NULL(HandleList); + SHELL_FREE_NON_NULL(DevicePathList); + + HandleList = NULL; + } else { + Count = (UINTN)-1; + } + // + // Do it all over again for gEfiBlockIoProtocolGuid + // + + return (Status); +} + /** Converts a SHELL_FILE_HANDLE to an EFI_FILE_PROTOCOL*. @@ -1164,11 +1555,14 @@ ConvertEfiFileProtocolToShellHandle( } NewNode = AllocateZeroPool(sizeof(BUFFER_LIST)); if (NewNode == NULL) { + SHELL_FREE_NON_NULL(Buffer); return (NULL); } Buffer->FileHandle = (EFI_FILE_PROTOCOL*)Handle; Buffer->Path = StrnCatGrow(&Buffer->Path, NULL, Path, 0); if (Buffer->Path == NULL) { + SHELL_FREE_NON_NULL(NewNode); + SHELL_FREE_NON_NULL(Buffer); return (NULL); } NewNode->Buffer = Buffer; @@ -1264,7 +1658,6 @@ ShellFileHandleEof( gEfiShellProtocol->GetFilePosition(Handle, &Pos); Info = gEfiShellProtocol->GetFileInfo (Handle); - ASSERT(Info != NULL); gEfiShellProtocol->SetFilePosition(Handle, Pos); if (Info == NULL) { @@ -1306,7 +1699,6 @@ FreeBufferList ( ; BufferListEntry = (BUFFER_LIST *)GetFirstNode(&List->Link) ){ RemoveEntryList(&BufferListEntry->Link); - ASSERT(BufferListEntry->Buffer != NULL); if (BufferListEntry->Buffer != NULL) { FreePool(BufferListEntry->Buffer); } @@ -1314,3 +1706,112 @@ FreeBufferList ( } } +/** + Dump some hexadecimal data to the screen. + + @param[in] Indent How many spaces to indent the output. + @param[in] Offset The offset of the printing. + @param[in] DataSize The size in bytes of UserData. + @param[in] UserData The data to print out. +**/ +VOID +EFIAPI +DumpHex ( + IN UINTN Indent, + IN UINTN Offset, + IN UINTN DataSize, + IN VOID *UserData + ) +{ + UINT8 *Data; + + CHAR8 Val[50]; + + CHAR8 Str[20]; + + UINT8 TempByte; + UINTN Size; + UINTN Index; + + Data = UserData; + while (DataSize != 0) { + Size = 16; + if (Size > DataSize) { + Size = DataSize; + } + + for (Index = 0; Index < Size; Index += 1) { + TempByte = Data[Index]; + Val[Index * 3 + 0] = Hex[TempByte >> 4]; + Val[Index * 3 + 1] = Hex[TempByte & 0xF]; + Val[Index * 3 + 2] = (CHAR8) ((Index == 7) ? '-' : ' '); + Str[Index] = (CHAR8) ((TempByte < ' ' || TempByte > 'z') ? '.' : TempByte); + } + + Val[Index * 3] = 0; + Str[Index] = 0; + ShellPrintEx(-1, -1, L"%*a%08X: %-48a *%a*\r\n", Indent, "", Offset, Val, Str); + + Data += Size; + Offset += Size; + DataSize -= Size; + } +} + +/** + Dump HEX data into buffer. + + @param[in] Buffer HEX data to be dumped in Buffer. + @param[in] Indent How many spaces to indent the output. + @param[in] Offset The offset of the printing. + @param[in] DataSize The size in bytes of UserData. + @param[in] UserData The data to print out. +**/ +CHAR16* +EFIAPI +CatSDumpHex ( + IN CHAR16 *Buffer, + IN UINTN Indent, + IN UINTN Offset, + IN UINTN DataSize, + IN VOID *UserData + ) +{ + UINT8 *Data; + UINT8 TempByte; + UINTN Size; + UINTN Index; + CHAR8 Val[50]; + CHAR8 Str[20]; + CHAR16 *RetVal; + CHAR16 *TempRetVal; + + Data = UserData; + RetVal = Buffer; + while (DataSize != 0) { + Size = 16; + if (Size > DataSize) { + Size = DataSize; + } + + for (Index = 0; Index < Size; Index += 1) { + TempByte = Data[Index]; + Val[Index * 3 + 0] = Hex[TempByte >> 4]; + Val[Index * 3 + 1] = Hex[TempByte & 0xF]; + Val[Index * 3 + 2] = (CHAR8) ((Index == 7) ? '-' : ' '); + Str[Index] = (CHAR8) ((TempByte < ' ' || TempByte > 'z') ? '.' : TempByte); + } + + Val[Index * 3] = 0; + Str[Index] = 0; + TempRetVal = CatSPrint (RetVal, L"%*a%08X: %-48a *%a*\r\n", Indent, "", Offset, Val, Str); + SHELL_FREE_NON_NULL (RetVal); + RetVal = TempRetVal; + + Data += Size; + Offset += Size; + DataSize -= Size; + } + + return RetVal; +}