VirtualBox

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

Last change on this file since 101283 was 99404, checked in by vboxsync, 20 months ago

Devices/EFI/FirmwareNew: Update to edk2-stable202302 and make it build, 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 (Temp64Bit <= (UINT32)(-1));
116 InSize = (UINTN)Temp64Bit;
117 ASSERT_EFI_ERROR (Status);
118 InBuffer = AllocateZeroPool (InSize);
119 if (InBuffer == NULL) {
120 Status = EFI_OUT_OF_RESOURCES;
121 } else {
122 Status = gEfiShellProtocol->ReadFile (InFileHandle, &InSize, InBuffer);
123 ASSERT_EFI_ERROR (Status);
124
125 Status = gBS->LocateProtocol (&gEfiDecompressProtocolGuid, NULL, (VOID **)&Decompress);
126 ASSERT_EFI_ERROR (Status);
127
128 Status = Decompress->GetInfo (Decompress, InBuffer, (UINT32)InSize, &OutSize, &ScratchSize);
129 }
130
131 if (EFI_ERROR (Status) || (OutSize == 0)) {
132 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_EFI_DECOMPRESS_NOPE), gShellDebug1HiiHandle, InFileName);
133 ShellStatus = SHELL_NOT_FOUND;
134 } else {
135 Status = ShellOpenFileByName (OutFileName, &OutFileHandle, EFI_FILE_MODE_READ|EFI_FILE_MODE_WRITE|EFI_FILE_MODE_CREATE, 0);
136 if (EFI_ERROR (Status)) {
137 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_FILE_OPEN_FAIL), gShellDebug1HiiHandle, ShellCommandLineGetRawValue (Package, 2), Status);
138 ShellStatus = SHELL_NOT_FOUND;
139 } else {
140 OutBuffer = AllocateZeroPool (OutSize);
141 ScratchBuffer = AllocateZeroPool (ScratchSize);
142 if ((OutBuffer == NULL) || (ScratchBuffer == NULL)) {
143 Status = EFI_OUT_OF_RESOURCES;
144 } else {
145 Status = Decompress->Decompress (Decompress, InBuffer, (UINT32)InSize, OutBuffer, OutSize, ScratchBuffer, ScratchSize);
146 }
147 }
148 }
149
150 if (EFI_ERROR (Status)) {
151 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_EFI_DECOMPRESS_FAIL), gShellDebug1HiiHandle, Status);
152 ShellStatus = ((Status == EFI_OUT_OF_RESOURCES) ? SHELL_OUT_OF_RESOURCES : SHELL_DEVICE_ERROR);
153 } else {
154 OutSizeTemp = OutSize;
155 Status = gEfiShellProtocol->WriteFile (OutFileHandle, &OutSizeTemp, OutBuffer);
156 OutSize = (UINT32)OutSizeTemp;
157 if (EFI_ERROR (Status)) {
158 ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_FILE_WRITE_FAIL), gShellDebug1HiiHandle, L"efidecompress", OutFileName, Status);
159 ShellStatus = SHELL_DEVICE_ERROR;
160 }
161 }
162 }
163 }
164 }
165
166 ShellCommandLineFreeVarList (Package);
167 }
168
169 if (InFileHandle != NULL) {
170 gEfiShellProtocol->CloseFile (InFileHandle);
171 }
172
173 if (OutFileHandle != NULL) {
174 gEfiShellProtocol->CloseFile (OutFileHandle);
175 }
176
177 SHELL_FREE_NON_NULL (InFileName);
178 SHELL_FREE_NON_NULL (InBuffer);
179 SHELL_FREE_NON_NULL (OutBuffer);
180 SHELL_FREE_NON_NULL (ScratchBuffer);
181
182 return (ShellStatus);
183}
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