X-Git-Url: https://git.proxmox.com/?a=blobdiff_plain;f=ShellPkg%2FLibrary%2FUefiShellDebug1CommandsLib%2FHexEdit%2FFileImage.c;h=9f9e54c598f1b96da6f3cf4bdd5d81113be320db;hb=ba0014b9f8ae1a593f03e744f26008214c2b06a8;hp=fd6387a20a9a78e98e8817dc696259c859a6d245;hpb=33c031ee2092282a069ce07d30202082ceaf61fe;p=mirror_edk2.git diff --git a/ShellPkg/Library/UefiShellDebug1CommandsLib/HexEdit/FileImage.c b/ShellPkg/Library/UefiShellDebug1CommandsLib/HexEdit/FileImage.c index fd6387a20a..9f9e54c598 100644 --- a/ShellPkg/Library/UefiShellDebug1CommandsLib/HexEdit/FileImage.c +++ b/ShellPkg/Library/UefiShellDebug1CommandsLib/HexEdit/FileImage.c @@ -1,7 +1,7 @@ /** @file Functions to deal with file buffer. - Copyright (c) 2005 - 2011, Intel Corporation. All rights reserved.
+ Copyright (c) 2005 - 2018, 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 @@ -35,26 +35,15 @@ HEFI_EDITOR_BUFFER_IMAGE HFileImageConst = { FALSE }; +/** + Initialization function for HFileImage + + @retval EFI_SUCCESS The operation was successful. +**/ EFI_STATUS HFileImageInit ( VOID ) -/*++ - -Routine Description: - - Initialization function for HFileImage - -Arguments: - - None - -Returns: - - EFI_SUCCESS - EFI_LOAD_ERROR - ---*/ { // // basically initialize the HFileImage @@ -70,29 +59,17 @@ Returns: return EFI_SUCCESS; } +/** + Backup function for HFileImage. Only a few fields need to be backup. + This is for making the file buffer refresh as few as possible. + + @retval EFI_SUCCESS The operation was successful. + @retval EFI_OUT_OF_RESOURCES A memory allocation failed. +**/ EFI_STATUS HFileImageBackup ( VOID ) -/*++ - -Routine Description: - - Backup function for HFileImage - Only a few fields need to be backup. - This is for making the file buffer refresh - as few as possible. - -Arguments: - - None - -Returns: - - EFI_SUCCESS - EFI_OUT_OF_RESOURCES - ---*/ { SHELL_FREE_NON_NULL (HFileImageBackupVar.FileName); HFileImageBackupVar.FileName = CatSPrint(NULL, L"%s", HFileImage.FileName); @@ -103,25 +80,15 @@ Returns: return EFI_SUCCESS; } +/** + Cleanup function for HFileImage. + + @retval EFI_SUCCESS The operation was successful. +**/ EFI_STATUS HFileImageCleanup ( VOID ) -/*++ - -Routine Description: - - Cleanup function for HFileImage - -Arguments: - - None - -Returns: - - EFI_SUCCESS - ---*/ { SHELL_FREE_NON_NULL (HFileImage.FileName); @@ -130,124 +97,53 @@ Returns: return EFI_SUCCESS; } +/** + Set FileName field in HFileImage + + @param[in] Str File name to set. + + @retval EFI_SUCCESS The operation was successful. + @retval EFI_OUT_OF_RESOURCES A memory allocation failed. +**/ EFI_STATUS HFileImageSetFileName ( IN CONST CHAR16 *Str ) -/*++ - -Routine Description: - - Set FileName field in HFileImage - -Arguments: - - Str -- File name to set - -Returns: - - EFI_SUCCESS - EFI_OUT_OF_RESOURCES - ---*/ { - UINTN Size; - UINTN Index; - + if (Str == HFileImage.FileName) { + // + // This function might be called using HFileImage.FileName as Str. + // Directly return without updating HFileImage.FileName. + // + return EFI_SUCCESS; + } // // free the old file name // SHELL_FREE_NON_NULL (HFileImage.FileName); - - Size = StrLen (Str); - - HFileImage.FileName = AllocateZeroPool (2 * (Size + 1)); + HFileImage.FileName = AllocateCopyPool (StrSize (Str), Str); if (HFileImage.FileName == NULL) { return EFI_OUT_OF_RESOURCES; } - for (Index = 0; Index < Size; Index++) { - HFileImage.FileName[Index] = Str[Index]; - } - - HFileImage.FileName[Size] = L'\0'; - return EFI_SUCCESS; } -EFI_STATUS -HFileImageGetFileInfo ( - IN EFI_FILE_HANDLE Handle, - IN CHAR16 *FileName, - OUT EFI_FILE_INFO **InfoOut - ) -/*++ - -Routine Description: - - Get this file's information - -Arguments: - - Handle - in NT32 mode Directory handle, in other mode File Handle - FileName - The file name - InfoOut - parameter to pass file information out - -Returns: - - EFI_SUCCESS - EFI_OUT_OF_RESOURCES - EFI_LOAD_ERROR - ---*/ -{ - - VOID *Info; - UINTN Size; - EFI_STATUS Status; - - Size = SIZE_OF_EFI_FILE_INFO + 1024; - Info = AllocateZeroPool (Size); - if (!Info) { - return EFI_OUT_OF_RESOURCES; - } - // - // get file information - // - Status = Handle->GetInfo (Handle, &gEfiFileInfoGuid, &Size, Info); - if (EFI_ERROR (Status)) { - return EFI_LOAD_ERROR; - } - - *InfoOut = (EFI_FILE_INFO *) Info; +/** + Read a file from disk into HBufferImage. - return EFI_SUCCESS; - -} + @param[in] FileName filename to read. + @param[in] Recover if is for recover, no information print. + @retval EFI_SUCCESS The operation was successful. + @retval EFI_OUT_OF_RESOURCES A memory allocation failed. + @retval EFI_LOAD_ERROR A load error occured. +**/ EFI_STATUS HFileImageRead ( IN CONST CHAR16 *FileName, IN BOOLEAN Recover ) -/*++ - -Routine Description: - - Read a file from disk into HBufferImage - -Arguments: - - FileName -- filename to read - Recover -- if is for recover, no information print - -Returns: - - EFI_SUCCESS - EFI_LOAD_ERROR - EFI_OUT_OF_RESOURCES - ---*/ { HEFI_EDITOR_LINE *Line; UINT8 *Buffer; @@ -268,8 +164,11 @@ Returns: // you should set the status string // Status = ReadFileIntoBuffer (FileName, (VOID**)&Buffer, &HFileImage.Size, &HFileImage.ReadOnly); - if (EFI_ERROR(Status)) { - UnicodeBuffer = CatSPrint(NULL, L"Read error on file &s: %r", FileName, Status); + // + // NULL pointer is only also a failure for a non-zero file size. + // + if ((EFI_ERROR(Status)) || (Buffer == NULL && HFileImage.Size != 0)) { + UnicodeBuffer = CatSPrint(NULL, L"Read error on file %s: %r", FileName, Status); if (UnicodeBuffer == NULL) { SHELL_FREE_NON_NULL(Buffer); return EFI_OUT_OF_RESOURCES; @@ -277,6 +176,7 @@ Returns: StatusBarSetStatusString (UnicodeBuffer); FreePool (UnicodeBuffer); + return EFI_OUT_OF_RESOURCES; } HFileImageSetFileName (FileName); @@ -343,27 +243,19 @@ Returns: return EFI_SUCCESS; } +/** + Save lines in HBufferImage to disk. + + @param[in] FileName The file name. + + @retval EFI_SUCCESS The operation was successful. + @retval EFI_OUT_OF_RESOURCES A memory allocation failed. + @retval EFI_LOAD_ERROR A load error occured. +**/ EFI_STATUS HFileImageSave ( IN CHAR16 *FileName ) -/*++ - -Routine Description: - - Save lines in HBufferImage to disk - -Arguments: - - FileName - The file name - -Returns: - - EFI_SUCCESS - EFI_LOAD_ERROR - EFI_OUT_OF_RESOURCES - ---*/ { LIST_ENTRY *Link; @@ -489,7 +381,8 @@ Returns: // // now everything is ready , you can set the new file name to filebuffer // - if (BufferTypeBackup != FileTypeFileBuffer || StringNoCaseCompare (&FileName, &HFileImage.FileName) != 0) { + if ((BufferTypeBackup != FileTypeFileBuffer && FileName != NULL) || + (FileName != NULL && HFileImage.FileName != NULL && StringNoCaseCompare (&FileName, &HFileImage.FileName) != 0)){ // // not the same //