From 3737ac2bc3c2e6589d88be97345d641ea2006933 Mon Sep 17 00:00:00 2001 From: jcarsey Date: Fri, 25 Mar 2011 21:22:20 +0000 Subject: comp - add comments and add input verification bcfg - updated for bugs. compress - rename for coding standards. add comments. dblk - add comments, input verification, and a header line dmem - add comments, add input verification, add system table info dmpstore - add comments eficompress - add comments and add input verification efidecompress - add comments and add input verification loadpcirom - add comments and more output messages memmap - add more output to exceed the spec. mm - move functions, add comments, add input verification. mode - add comment pci - add input verification. SerMode - add comments and add input verification setsize - add comments and add input verification setvar - add comments and add input verification smbiosview - add input verification. clarify error messages. git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@11438 6f19259b-4bc3-4df7-8a09-765794883524 --- .../UefiShellDebug1CommandsLib/EfiCompress.c | 101 +++++++++++---------- 1 file changed, 55 insertions(+), 46 deletions(-) (limited to 'ShellPkg/Library/UefiShellDebug1CommandsLib/EfiCompress.c') diff --git a/ShellPkg/Library/UefiShellDebug1CommandsLib/EfiCompress.c b/ShellPkg/Library/UefiShellDebug1CommandsLib/EfiCompress.c index 8d5aabdafc..3f27d1ae0d 100644 --- a/ShellPkg/Library/UefiShellDebug1CommandsLib/EfiCompress.c +++ b/ShellPkg/Library/UefiShellDebug1CommandsLib/EfiCompress.c @@ -1,7 +1,7 @@ /** @file Main file for EfiCompress shell Debug1 function. - Copyright (c) 2005 - 2010, Intel Corporation. All rights reserved.
+ Copyright (c) 2005 - 2011, 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,12 @@ #include "UefiShellDebug1CommandsLib.h" #include "Compress.h" +/** + Function for 'compress' command. + + @param[in] ImageHandle Handle to the Image (NULL if Internal). + @param[in] SystemTable Pointer to the System Table (NULL if Internal). +**/ SHELL_STATUS EFIAPI ShellCommandRunEfiCompress ( @@ -76,65 +82,68 @@ ShellCommandRunEfiCompress ( } else { InFileName = ShellFindFilePath(ShellCommandLineGetRawValue(Package, 1)); OutFileName = ShellCommandLineGetRawValue(Package, 2); - Status = ShellOpenFileByName(InFileName, &InShellFileHandle, EFI_FILE_MODE_READ, 0); - if (EFI_ERROR(Status)) { - ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_FILE_OPEN_FAIL), gShellDebug1HiiHandle, ShellCommandLineGetRawValue(Package, 1), Status); - ShellStatus = SHELL_NOT_FOUND; - } - Status = ShellOpenFileByName(OutFileName, &OutShellFileHandle, EFI_FILE_MODE_READ|EFI_FILE_MODE_WRITE|EFI_FILE_MODE_CREATE, 0); - if (EFI_ERROR(Status)) { - ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_FILE_OPEN_FAIL), gShellDebug1HiiHandle, ShellCommandLineGetRawValue(Package, 2), Status); + if (InFileName == NULL) { + ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_FILE_FIND_FAIL), gShellDebug1HiiHandle, ShellCommandLineGetRawValue(Package, 1)); ShellStatus = SHELL_NOT_FOUND; - } - if (FileHandleIsDirectory(InShellFileHandle) == EFI_SUCCESS){ - ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_FILE_NOT_DIR), gShellDebug1HiiHandle, InFileName); - ShellStatus = SHELL_INVALID_PARAMETER; - } - if (FileHandleIsDirectory(OutShellFileHandle) == EFI_SUCCESS){ - ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_FILE_NOT_DIR), gShellDebug1HiiHandle, OutFileName); - ShellStatus = SHELL_INVALID_PARAMETER; - } - Status = gEfiShellProtocol->GetFileSize(InShellFileHandle, &InSize); - ASSERT_EFI_ERROR(Status); - InBuffer = AllocateZeroPool((UINTN)InSize); - ASSERT(InBuffer != NULL); - Status = gEfiShellProtocol->ReadFile(InShellFileHandle, &((UINTN)InSize), InBuffer); - ASSERT_EFI_ERROR(Status); - Status = Compress(InBuffer, InSize, OutBuffer, &OutSize); - if (Status == EFI_BUFFER_TOO_SMALL) { - OutBuffer = AllocateZeroPool((UINTN)OutSize); - ASSERT(OutBuffer != NULL); - Status = Compress(InBuffer, InSize, OutBuffer, &OutSize); - } - if (EFI_ERROR(Status)) { - ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_EFI_COMPRESS_FAIL), gShellDebug1HiiHandle, Status); - ShellStatus = SHELL_DEVICE_ERROR; } else { - Status = gEfiShellProtocol->WriteFile(OutShellFileHandle, &((UINTN)OutSize), OutBuffer); - if (EFI_ERROR(Status)) { - ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_FILE_WRITE_FAIL), gShellDebug1HiiHandle, OutFileName, Status); - ShellStatus = SHELL_DEVICE_ERROR; + if (ShellIsDirectory(InFileName) == EFI_SUCCESS){ + ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_FILE_NOT_DIR), gShellDebug1HiiHandle, InFileName); + ShellStatus = SHELL_INVALID_PARAMETER; + } + if (ShellIsDirectory(OutFileName) == EFI_SUCCESS){ + ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_FILE_NOT_DIR), gShellDebug1HiiHandle, OutFileName); + ShellStatus = SHELL_INVALID_PARAMETER; + } + if (ShellStatus == SHELL_SUCCESS) { + Status = ShellOpenFileByName(InFileName, &InShellFileHandle, EFI_FILE_MODE_READ, 0); + if (EFI_ERROR(Status)) { + ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_FILE_OPEN_FAIL), gShellDebug1HiiHandle, ShellCommandLineGetRawValue(Package, 1), Status); + ShellStatus = SHELL_NOT_FOUND; + } + Status = ShellOpenFileByName(OutFileName, &OutShellFileHandle, EFI_FILE_MODE_READ|EFI_FILE_MODE_WRITE|EFI_FILE_MODE_CREATE, 0); + if (EFI_ERROR(Status)) { + ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_FILE_OPEN_FAIL), gShellDebug1HiiHandle, ShellCommandLineGetRawValue(Package, 2), Status); + ShellStatus = SHELL_NOT_FOUND; + } + } + if (ShellStatus == SHELL_SUCCESS) { + Status = gEfiShellProtocol->GetFileSize(InShellFileHandle, &InSize); + ASSERT_EFI_ERROR(Status); + InBuffer = AllocateZeroPool((UINTN)InSize); + ASSERT(InBuffer != NULL); + Status = gEfiShellProtocol->ReadFile(InShellFileHandle, &((UINTN)InSize), InBuffer); + ASSERT_EFI_ERROR(Status); + Status = Compress(InBuffer, InSize, OutBuffer, &OutSize); + if (Status == EFI_BUFFER_TOO_SMALL) { + OutBuffer = AllocateZeroPool((UINTN)OutSize); + ASSERT(OutBuffer != NULL); + Status = Compress(InBuffer, InSize, OutBuffer, &OutSize); + } + if (EFI_ERROR(Status)) { + ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_EFI_COMPRESS_FAIL), gShellDebug1HiiHandle, Status); + ShellStatus = SHELL_DEVICE_ERROR; + } else { + Status = gEfiShellProtocol->WriteFile(OutShellFileHandle, &((UINTN)OutSize), OutBuffer); + if (EFI_ERROR(Status)) { + ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_FILE_WRITE_FAIL), gShellDebug1HiiHandle, OutFileName, Status); + ShellStatus = SHELL_DEVICE_ERROR; + } + } } } } ShellCommandLineFreeVarList (Package); } - if (InFileName != NULL) { - FreePool(InFileName); - } if (InShellFileHandle != NULL) { gEfiShellProtocol->CloseFile(InShellFileHandle); } if (OutShellFileHandle != NULL) { gEfiShellProtocol->CloseFile(OutShellFileHandle); } - if (InBuffer != NULL) { - FreePool(InBuffer); - } - if (OutBuffer != NULL) { - FreePool(OutBuffer); - } + SHELL_FREE_NON_NULL(InFileName); + SHELL_FREE_NON_NULL(InBuffer); + SHELL_FREE_NON_NULL(OutBuffer); return (ShellStatus); } -- cgit v1.2.3