VirtualBox

source: vbox/trunk/src/VBox/Devices/EFI/FirmwareNew/ShellPkg/Library/UefiShellDebug1CommandsLib/EfiDecompress.c@ 105670

Last change on this file since 105670 was 101291, checked in by vboxsync, 15 months ago

EFI/FirmwareNew: Make edk2-stable202308 build on all supported platforms (using gcc at least, msvc not tested yet), bugref:4643

  • Property svn:eol-style set to native
File size: 6.9 KB
Line 
1/** @file
2 Main file for EfiDecompress shell Debug1 function.
3
4 (C) Copyright 2015 Hewlett-Packard Development Company, L.P.<BR>
5 Copyright (c) 2005 - 2018, Intel Corporation. All rights reserved.<BR>
6 SPDX-License-Identifier: BSD-2-Clause-Patent
7
8**/
9
10#include "UefiShellDebug1CommandsLib.h"
11#include <Protocol/Decompress.h>
12
13/**
14 Function for 'decompress' command.
15
16 @param[in] ImageHandle Handle to the Image (NULL if Internal).
17 @param[in] SystemTable Pointer to the System Table (NULL if Internal).
18**/
19SHELL_STATUS
20EFIAPI
21ShellCommandRunEfiDecompress (
22 IN EFI_HANDLE ImageHandle,
23 IN EFI_SYSTEM_TABLE *SystemTable
24 )
25{
26 EFI_STATUS Status;
27 LIST_ENTRY *Package;
28 CHAR16 *ProblemParam;
29 SHELL_STATUS ShellStatus;
30 SHELL_FILE_HANDLE InFileHandle;
31 SHELL_FILE_HANDLE OutFileHandle;
32 UINT32 OutSize;
33 UINTN OutSizeTemp;
34 VOID *OutBuffer;
35 UINTN InSize;
36 VOID *InBuffer;
37 CHAR16 *InFileName;
38 CONST CHAR16 *OutFileName;
39 UINT64 Temp64Bit;
40 UINT32 ScratchSize;
41 VOID *ScratchBuffer;
42 EFI_DECOMPRESS_PROTOCOL *Decompress;
43 CONST CHAR16 *TempParam;
44
45 InFileName = NULL;
46 OutFileName = NULL;
47 OutSize = 0;
48 ScratchSize = 0;
49 ShellStatus = SHELL_SUCCESS;
50 Status = EFI_SUCCESS;
51 OutBuffer = NULL;
52 InBuffer = NULL;
53 ScratchBuffer = NULL;
54 InFileHandle = NULL;
55 OutFileHandle = NULL;
56 Decompress = NULL;
57
58 //
59 // initialize the shell lib (we must be in non-auto-init...)
60 //
61 Status = ShellInitialize ();
62 ASSERT_EFI_ERROR (Status);
63
64 Status = CommandInit ();
65 ASSERT_EFI_ERROR (Status);
66
67 //
68 // parse the command line
69 //
70 Status = ShellCommandLineParse (EmptyParamList, &Package, &ProblemParam, TRUE);
71 if (EFI_ERROR (Status)) {
72 if ((Status == EFI_VOLUME_CORRUPTED) && (ProblemParam != NULL)) {
73 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellDebug1HiiHandle, L"efidecompress", ProblemParam);
74 FreePool (ProblemParam);
75 ShellStatus = SHELL_INVALID_PARAMETER;
76 } else {
77 ASSERT (FALSE);
78 }
79 } else {
80 if (ShellCommandLineGetCount (Package) > 3) {
81 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_MANY), gShellDebug1HiiHandle, L"efidecompress");
82 ShellStatus = SHELL_INVALID_PARAMETER;
83 } else if (ShellCommandLineGetCount (Package) < 3) {
84 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_FEW), gShellDebug1HiiHandle, L"efidecompress");
85 ShellStatus = SHELL_INVALID_PARAMETER;
86 } else {
87 TempParam = ShellCommandLineGetRawValue (Package, 1);
88 ASSERT (TempParam != NULL);
89 InFileName = ShellFindFilePath (TempParam);
90 OutFileName = ShellCommandLineGetRawValue (Package, 2);
91 if (InFileName == NULL) {
92 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_FILE_FIND_FAIL), gShellDebug1HiiHandle, L"efidecompress", TempParam);
93 ShellStatus = SHELL_NOT_FOUND;
94 } else {
95 if (ShellIsDirectory (InFileName) == EFI_SUCCESS) {
96 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_FILE_NOT_DIR), gShellDebug1HiiHandle, L"efidecompress", InFileName);
97 ShellStatus = SHELL_INVALID_PARAMETER;
98 }
99
100 if (ShellIsDirectory (OutFileName) == EFI_SUCCESS) {
101 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_FILE_NOT_DIR), gShellDebug1HiiHandle, L"efidecompress", OutFileName);
102 ShellStatus = SHELL_INVALID_PARAMETER;
103 }
104
105 if (ShellStatus == SHELL_SUCCESS) {
106 Status = ShellOpenFileByName (InFileName, &InFileHandle, EFI_FILE_MODE_READ, 0);
107 if (EFI_ERROR (Status)) {
108 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_FILE_OPEN_FAIL), gShellDebug1HiiHandle, L"efidecompress", ShellCommandLineGetRawValue (Package, 1));
109 ShellStatus = SHELL_NOT_FOUND;
110 }
111 }
112
113 if (ShellStatus == SHELL_SUCCESS) {
114 Status = FileHandleGetSize (InFileHandle, &Temp64Bit);
115 ASSERT_EFI_ERROR (Status);
116 if (!EFI_ERROR (Status)) {
117 ASSERT (Temp64Bit <= (UINT32)(-1));
118 InSize = (UINTN)Temp64Bit;
119 InBuffer = AllocateZeroPool (InSize);
120 }
121
122 if (InBuffer == NULL) {
123 Status = EFI_OUT_OF_RESOURCES;
124 } else {
125 Status = gEfiShellProtocol->ReadFile (InFileHandle, &InSize, InBuffer);
126 ASSERT_EFI_ERROR (Status);
127
128 Status = gBS->LocateProtocol (&gEfiDecompressProtocolGuid, NULL, (VOID **)&Decompress);
129 ASSERT_EFI_ERROR (Status);
130
131 Status = Decompress->GetInfo (Decompress, InBuffer, (UINT32)InSize, &OutSize, &ScratchSize);
132 }
133
134 if (EFI_ERROR (Status) || (OutSize == 0)) {
135 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_EFI_DECOMPRESS_NOPE), gShellDebug1HiiHandle, InFileName);
136 ShellStatus = SHELL_NOT_FOUND;
137 } else {
138 Status = ShellOpenFileByName (OutFileName, &OutFileHandle, EFI_FILE_MODE_READ|EFI_FILE_MODE_WRITE|EFI_FILE_MODE_CREATE, 0);
139 if (EFI_ERROR (Status)) {
140 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_FILE_OPEN_FAIL), gShellDebug1HiiHandle, ShellCommandLineGetRawValue (Package, 2), Status);
141 ShellStatus = SHELL_NOT_FOUND;
142 } else {
143 OutBuffer = AllocateZeroPool (OutSize);
144 ScratchBuffer = AllocateZeroPool (ScratchSize);
145 if ((OutBuffer == NULL) || (ScratchBuffer == NULL)) {
146 Status = EFI_OUT_OF_RESOURCES;
147 } else {
148 Status = Decompress->Decompress (Decompress, InBuffer, (UINT32)InSize, OutBuffer, OutSize, ScratchBuffer, ScratchSize);
149 }
150 }
151 }
152
153 if (EFI_ERROR (Status)) {
154 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_EFI_DECOMPRESS_FAIL), gShellDebug1HiiHandle, Status);
155 ShellStatus = ((Status == EFI_OUT_OF_RESOURCES) ? SHELL_OUT_OF_RESOURCES : SHELL_DEVICE_ERROR);
156 } else {
157 OutSizeTemp = OutSize;
158 Status = gEfiShellProtocol->WriteFile (OutFileHandle, &OutSizeTemp, OutBuffer);
159 OutSize = (UINT32)OutSizeTemp;
160 if (EFI_ERROR (Status)) {
161 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_FILE_WRITE_FAIL), gShellDebug1HiiHandle, L"efidecompress", OutFileName, Status);
162 ShellStatus = SHELL_DEVICE_ERROR;
163 }
164 }
165 }
166 }
167 }
168
169 ShellCommandLineFreeVarList (Package);
170 }
171
172 if (InFileHandle != NULL) {
173 gEfiShellProtocol->CloseFile (InFileHandle);
174 }
175
176 if (OutFileHandle != NULL) {
177 gEfiShellProtocol->CloseFile (OutFileHandle);
178 }
179
180 SHELL_FREE_NON_NULL (InFileName);
181 SHELL_FREE_NON_NULL (InBuffer);
182 SHELL_FREE_NON_NULL (OutBuffer);
183 SHELL_FREE_NON_NULL (ScratchBuffer);
184
185 return (ShellStatus);
186}
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette