jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 1 | /** @file
|
| 2 | Provides interface to shell functionality for shell commands and applications.
|
| 3 |
|
jaben carsey | 9ed2194 | 2016-02-08 15:59:04 -0800 | [diff] [blame] | 4 | Copyright 2016 Dell Inc.
|
Qiu Shumin | f79d7b6 | 2016-02-18 13:12:58 +0800 | [diff] [blame] | 5 | Copyright (c) 2006 - 2016, Intel Corporation. All rights reserved.<BR>
|
jcarsey | 1e6e84c | 2010-01-25 20:05:08 +0000 | [diff] [blame] | 6 | This program and the accompanying materials
|
jcarsey | b3011f4 | 2010-01-11 21:49:04 +0000 | [diff] [blame] | 7 | are licensed and made available under the terms and conditions of the BSD License
|
| 8 | which accompanies this distribution. The full text of the license may be found at
|
| 9 | http://opensource.org/licenses/bsd-license.php
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 10 |
|
jcarsey | b3011f4 | 2010-01-11 21:49:04 +0000 | [diff] [blame] | 11 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
| 12 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 13 |
|
| 14 | **/
|
| 15 |
|
jcarsey | b1f95a0 | 2009-06-16 00:23:19 +0000 | [diff] [blame] | 16 | #include "UefiShellLib.h"
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 17 | #include <ShellBase.h>
|
jcarsey | 252d945 | 2011-03-25 20:49:53 +0000 | [diff] [blame] | 18 | #include <Library/SortLib.h>
|
Laszlo Ersek | 3fe23dc | 2015-01-14 16:25:48 +0000 | [diff] [blame] | 19 | #include <Library/BaseLib.h>
|
jcarsey | d2b4564 | 2009-05-11 18:02:16 +0000 | [diff] [blame] | 20 |
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 21 | #define FIND_XXXXX_FILE_BUFFER_SIZE (SIZE_OF_EFI_FILE_INFO + MAX_FILE_NAME_LEN)
|
| 22 |
|
jcarsey | d2b4564 | 2009-05-11 18:02:16 +0000 | [diff] [blame] | 23 | //
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 24 | // globals...
|
jcarsey | d2b4564 | 2009-05-11 18:02:16 +0000 | [diff] [blame] | 25 | //
|
| 26 | SHELL_PARAM_ITEM EmptyParamList[] = {
|
| 27 | {NULL, TypeMax}
|
| 28 | };
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 29 | SHELL_PARAM_ITEM SfoParamList[] = {
|
| 30 | {L"-sfo", TypeFlag},
|
| 31 | {NULL, TypeMax}
|
| 32 | };
|
| 33 | EFI_SHELL_ENVIRONMENT2 *mEfiShellEnvironment2;
|
| 34 | EFI_SHELL_INTERFACE *mEfiShellInterface;
|
jcarsey | 366f81a | 2011-06-27 21:04:22 +0000 | [diff] [blame] | 35 | EFI_SHELL_PROTOCOL *gEfiShellProtocol;
|
| 36 | EFI_SHELL_PARAMETERS_PROTOCOL *gEfiShellParametersProtocol;
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 37 | EFI_HANDLE mEfiShellEnvironment2Handle;
|
| 38 | FILE_HANDLE_FUNCTION_MAP FileFunctionMap;
|
jcarsey | b3011f4 | 2010-01-11 21:49:04 +0000 | [diff] [blame] | 39 |
|
jcarsey | 2247dde | 2009-11-09 18:08:58 +0000 | [diff] [blame] | 40 | /**
|
| 41 | Check if a Unicode character is a hexadecimal character.
|
| 42 |
|
jcarsey | 1e6e84c | 2010-01-25 20:05:08 +0000 | [diff] [blame] | 43 | This internal function checks if a Unicode character is a
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 44 | numeric character. The valid hexadecimal characters are
|
jcarsey | 2247dde | 2009-11-09 18:08:58 +0000 | [diff] [blame] | 45 | L'0' to L'9', L'a' to L'f', or L'A' to L'F'.
|
| 46 |
|
jcarsey | 2247dde | 2009-11-09 18:08:58 +0000 | [diff] [blame] | 47 | @param Char The character to check against.
|
| 48 |
|
| 49 | @retval TRUE If the Char is a hexadecmial character.
|
| 50 | @retval FALSE If the Char is not a hexadecmial character.
|
| 51 |
|
| 52 | **/
|
| 53 | BOOLEAN
|
| 54 | EFIAPI
|
jcarsey | 969c783 | 2010-01-13 16:46:33 +0000 | [diff] [blame] | 55 | ShellIsHexaDecimalDigitCharacter (
|
jcarsey | 2247dde | 2009-11-09 18:08:58 +0000 | [diff] [blame] | 56 | IN CHAR16 Char
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 57 | )
|
| 58 | {
|
jcarsey | 2247dde | 2009-11-09 18:08:58 +0000 | [diff] [blame] | 59 | return (BOOLEAN) ((Char >= L'0' && Char <= L'9') || (Char >= L'A' && Char <= L'F') || (Char >= L'a' && Char <= L'f'));
|
| 60 | }
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 61 |
|
| 62 | /**
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 63 | Check if a Unicode character is a decimal character.
|
| 64 |
|
| 65 | This internal function checks if a Unicode character is a
|
| 66 | decimal character. The valid characters are
|
| 67 | L'0' to L'9'.
|
| 68 |
|
| 69 |
|
| 70 | @param Char The character to check against.
|
| 71 |
|
| 72 | @retval TRUE If the Char is a hexadecmial character.
|
| 73 | @retval FALSE If the Char is not a hexadecmial character.
|
| 74 |
|
| 75 | **/
|
| 76 | BOOLEAN
|
| 77 | EFIAPI
|
| 78 | ShellIsDecimalDigitCharacter (
|
| 79 | IN CHAR16 Char
|
| 80 | )
|
| 81 | {
|
| 82 | return (BOOLEAN) (Char >= L'0' && Char <= L'9');
|
| 83 | }
|
| 84 |
|
| 85 | /**
|
| 86 | Helper function to find ShellEnvironment2 for constructor.
|
| 87 |
|
| 88 | @param[in] ImageHandle A copy of the calling image's handle.
|
jcarsey | beab0fc | 2011-10-10 17:26:25 +0000 | [diff] [blame] | 89 |
|
| 90 | @retval EFI_OUT_OF_RESOURCES Memory allocation failed.
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 91 | **/
|
| 92 | EFI_STATUS
|
| 93 | EFIAPI
|
| 94 | ShellFindSE2 (
|
| 95 | IN EFI_HANDLE ImageHandle
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 96 | )
|
| 97 | {
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 98 | EFI_STATUS Status;
|
| 99 | EFI_HANDLE *Buffer;
|
| 100 | UINTN BufferSize;
|
| 101 | UINTN HandleIndex;
|
| 102 |
|
| 103 | BufferSize = 0;
|
| 104 | Buffer = NULL;
|
jcarsey | 1e6e84c | 2010-01-25 20:05:08 +0000 | [diff] [blame] | 105 | Status = gBS->OpenProtocol(ImageHandle,
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 106 | &gEfiShellEnvironment2Guid,
|
| 107 | (VOID **)&mEfiShellEnvironment2,
|
| 108 | ImageHandle,
|
| 109 | NULL,
|
| 110 | EFI_OPEN_PROTOCOL_GET_PROTOCOL
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 111 | );
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 112 | //
|
| 113 | // look for the mEfiShellEnvironment2 protocol at a higher level
|
| 114 | //
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 115 | if (EFI_ERROR (Status) || !(CompareGuid (&mEfiShellEnvironment2->SESGuid, &gEfiShellEnvironment2ExtGuid))){
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 116 | //
|
| 117 | // figure out how big of a buffer we need.
|
| 118 | //
|
| 119 | Status = gBS->LocateHandle (ByProtocol,
|
| 120 | &gEfiShellEnvironment2Guid,
|
| 121 | NULL, // ignored for ByProtocol
|
| 122 | &BufferSize,
|
| 123 | Buffer
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 124 | );
|
jcarsey | 2247dde | 2009-11-09 18:08:58 +0000 | [diff] [blame] | 125 | //
|
| 126 | // maybe it's not there???
|
| 127 | //
|
| 128 | if (Status == EFI_BUFFER_TOO_SMALL) {
|
jcarsey | 252d945 | 2011-03-25 20:49:53 +0000 | [diff] [blame] | 129 | Buffer = (EFI_HANDLE*)AllocateZeroPool(BufferSize);
|
jcarsey | beab0fc | 2011-10-10 17:26:25 +0000 | [diff] [blame] | 130 | if (Buffer == NULL) {
|
| 131 | return (EFI_OUT_OF_RESOURCES);
|
| 132 | }
|
jcarsey | 2247dde | 2009-11-09 18:08:58 +0000 | [diff] [blame] | 133 | Status = gBS->LocateHandle (ByProtocol,
|
| 134 | &gEfiShellEnvironment2Guid,
|
| 135 | NULL, // ignored for ByProtocol
|
| 136 | &BufferSize,
|
| 137 | Buffer
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 138 | );
|
jcarsey | 2247dde | 2009-11-09 18:08:58 +0000 | [diff] [blame] | 139 | }
|
jcarsey | 1cd45e7 | 2010-01-29 15:07:44 +0000 | [diff] [blame] | 140 | if (!EFI_ERROR (Status) && Buffer != NULL) {
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 141 | //
|
| 142 | // now parse the list of returned handles
|
| 143 | //
|
| 144 | Status = EFI_NOT_FOUND;
|
| 145 | for (HandleIndex = 0; HandleIndex < (BufferSize/sizeof(Buffer[0])); HandleIndex++) {
|
jcarsey | 1e6e84c | 2010-01-25 20:05:08 +0000 | [diff] [blame] | 146 | Status = gBS->OpenProtocol(Buffer[HandleIndex],
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 147 | &gEfiShellEnvironment2Guid,
|
| 148 | (VOID **)&mEfiShellEnvironment2,
|
| 149 | ImageHandle,
|
| 150 | NULL,
|
| 151 | EFI_OPEN_PROTOCOL_GET_PROTOCOL
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 152 | );
|
| 153 | if (CompareGuid (&mEfiShellEnvironment2->SESGuid, &gEfiShellEnvironment2ExtGuid)) {
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 154 | mEfiShellEnvironment2Handle = Buffer[HandleIndex];
|
| 155 | Status = EFI_SUCCESS;
|
| 156 | break;
|
| 157 | }
|
| 158 | }
|
| 159 | }
|
| 160 | }
|
| 161 | if (Buffer != NULL) {
|
| 162 | FreePool (Buffer);
|
| 163 | }
|
| 164 | return (Status);
|
| 165 | }
|
| 166 |
|
jcarsey | 252d945 | 2011-03-25 20:49:53 +0000 | [diff] [blame] | 167 | /**
|
darylm503 | b0934ac | 2011-11-12 00:35:11 +0000 | [diff] [blame] | 168 | Function to do most of the work of the constructor. Allows for calling
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 169 | multiple times without complete re-initialization.
|
| 170 |
|
| 171 | @param[in] ImageHandle A copy of the ImageHandle.
|
| 172 | @param[in] SystemTable A pointer to the SystemTable for the application.
|
jcarsey | 252d945 | 2011-03-25 20:49:53 +0000 | [diff] [blame] | 173 |
|
| 174 | @retval EFI_SUCCESS The operationw as successful.
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 175 | **/
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 176 | EFI_STATUS
|
| 177 | EFIAPI
|
jcarsey | d2b4564 | 2009-05-11 18:02:16 +0000 | [diff] [blame] | 178 | ShellLibConstructorWorker (
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 179 | IN EFI_HANDLE ImageHandle,
|
| 180 | IN EFI_SYSTEM_TABLE *SystemTable
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 181 | )
|
| 182 | {
|
| 183 | EFI_STATUS Status;
|
jcarsey | ecd3d59 | 2009-12-07 18:05:00 +0000 | [diff] [blame] | 184 |
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 185 | //
|
| 186 | // UEFI 2.0 shell interfaces (used preferentially)
|
| 187 | //
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 188 | Status = gBS->OpenProtocol(
|
| 189 | ImageHandle,
|
| 190 | &gEfiShellProtocolGuid,
|
jcarsey | 366f81a | 2011-06-27 21:04:22 +0000 | [diff] [blame] | 191 | (VOID **)&gEfiShellProtocol,
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 192 | ImageHandle,
|
| 193 | NULL,
|
| 194 | EFI_OPEN_PROTOCOL_GET_PROTOCOL
|
| 195 | );
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 196 | if (EFI_ERROR(Status)) {
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 197 | //
|
| 198 | // Search for the shell protocol
|
| 199 | //
|
| 200 | Status = gBS->LocateProtocol(
|
| 201 | &gEfiShellProtocolGuid,
|
| 202 | NULL,
|
jcarsey | 366f81a | 2011-06-27 21:04:22 +0000 | [diff] [blame] | 203 | (VOID **)&gEfiShellProtocol
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 204 | );
|
| 205 | if (EFI_ERROR(Status)) {
|
jcarsey | 366f81a | 2011-06-27 21:04:22 +0000 | [diff] [blame] | 206 | gEfiShellProtocol = NULL;
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 207 | }
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 208 | }
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 209 | Status = gBS->OpenProtocol(
|
| 210 | ImageHandle,
|
| 211 | &gEfiShellParametersProtocolGuid,
|
jcarsey | 366f81a | 2011-06-27 21:04:22 +0000 | [diff] [blame] | 212 | (VOID **)&gEfiShellParametersProtocol,
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 213 | ImageHandle,
|
| 214 | NULL,
|
| 215 | EFI_OPEN_PROTOCOL_GET_PROTOCOL
|
| 216 | );
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 217 | if (EFI_ERROR(Status)) {
|
jcarsey | 366f81a | 2011-06-27 21:04:22 +0000 | [diff] [blame] | 218 | gEfiShellParametersProtocol = NULL;
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 219 | }
|
| 220 |
|
jcarsey | 366f81a | 2011-06-27 21:04:22 +0000 | [diff] [blame] | 221 | if (gEfiShellParametersProtocol == NULL || gEfiShellProtocol == NULL) {
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 222 | //
|
| 223 | // Moved to seperate function due to complexity
|
| 224 | //
|
| 225 | Status = ShellFindSE2(ImageHandle);
|
| 226 |
|
| 227 | if (EFI_ERROR(Status)) {
|
| 228 | DEBUG((DEBUG_ERROR, "Status: 0x%08x\r\n", Status));
|
| 229 | mEfiShellEnvironment2 = NULL;
|
| 230 | }
|
jcarsey | 1e6e84c | 2010-01-25 20:05:08 +0000 | [diff] [blame] | 231 | Status = gBS->OpenProtocol(ImageHandle,
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 232 | &gEfiShellInterfaceGuid,
|
| 233 | (VOID **)&mEfiShellInterface,
|
| 234 | ImageHandle,
|
| 235 | NULL,
|
| 236 | EFI_OPEN_PROTOCOL_GET_PROTOCOL
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 237 | );
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 238 | if (EFI_ERROR(Status)) {
|
| 239 | mEfiShellInterface = NULL;
|
| 240 | }
|
| 241 | }
|
jcarsey | c9d92df | 2010-02-03 15:37:54 +0000 | [diff] [blame] | 242 |
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 243 | //
|
| 244 | // only success getting 2 of either the old or new, but no 1/2 and 1/2
|
| 245 | //
|
jcarsey | 1e6e84c | 2010-01-25 20:05:08 +0000 | [diff] [blame] | 246 | if ((mEfiShellEnvironment2 != NULL && mEfiShellInterface != NULL) ||
|
jcarsey | 366f81a | 2011-06-27 21:04:22 +0000 | [diff] [blame] | 247 | (gEfiShellProtocol != NULL && gEfiShellParametersProtocol != NULL) ) {
|
| 248 | if (gEfiShellProtocol != NULL) {
|
| 249 | FileFunctionMap.GetFileInfo = gEfiShellProtocol->GetFileInfo;
|
| 250 | FileFunctionMap.SetFileInfo = gEfiShellProtocol->SetFileInfo;
|
| 251 | FileFunctionMap.ReadFile = gEfiShellProtocol->ReadFile;
|
| 252 | FileFunctionMap.WriteFile = gEfiShellProtocol->WriteFile;
|
| 253 | FileFunctionMap.CloseFile = gEfiShellProtocol->CloseFile;
|
| 254 | FileFunctionMap.DeleteFile = gEfiShellProtocol->DeleteFile;
|
| 255 | FileFunctionMap.GetFilePosition = gEfiShellProtocol->GetFilePosition;
|
| 256 | FileFunctionMap.SetFilePosition = gEfiShellProtocol->SetFilePosition;
|
| 257 | FileFunctionMap.FlushFile = gEfiShellProtocol->FlushFile;
|
| 258 | FileFunctionMap.GetFileSize = gEfiShellProtocol->GetFileSize;
|
jcarsey | d2b4564 | 2009-05-11 18:02:16 +0000 | [diff] [blame] | 259 | } else {
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 260 | FileFunctionMap.GetFileInfo = (EFI_SHELL_GET_FILE_INFO)FileHandleGetInfo;
|
| 261 | FileFunctionMap.SetFileInfo = (EFI_SHELL_SET_FILE_INFO)FileHandleSetInfo;
|
| 262 | FileFunctionMap.ReadFile = (EFI_SHELL_READ_FILE)FileHandleRead;
|
| 263 | FileFunctionMap.WriteFile = (EFI_SHELL_WRITE_FILE)FileHandleWrite;
|
| 264 | FileFunctionMap.CloseFile = (EFI_SHELL_CLOSE_FILE)FileHandleClose;
|
| 265 | FileFunctionMap.DeleteFile = (EFI_SHELL_DELETE_FILE)FileHandleDelete;
|
| 266 | FileFunctionMap.GetFilePosition = (EFI_SHELL_GET_FILE_POSITION)FileHandleGetPosition;
|
| 267 | FileFunctionMap.SetFilePosition = (EFI_SHELL_SET_FILE_POSITION)FileHandleSetPosition;
|
| 268 | FileFunctionMap.FlushFile = (EFI_SHELL_FLUSH_FILE)FileHandleFlush;
|
| 269 | FileFunctionMap.GetFileSize = (EFI_SHELL_GET_FILE_SIZE)FileHandleGetSize;
|
jcarsey | d2b4564 | 2009-05-11 18:02:16 +0000 | [diff] [blame] | 270 | }
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 271 | return (EFI_SUCCESS);
|
| 272 | }
|
| 273 | return (EFI_NOT_FOUND);
|
| 274 | }
|
jcarsey | d2b4564 | 2009-05-11 18:02:16 +0000 | [diff] [blame] | 275 | /**
|
| 276 | Constructor for the Shell library.
|
| 277 |
|
| 278 | Initialize the library and determine if the underlying is a UEFI Shell 2.0 or an EFI shell.
|
| 279 |
|
| 280 | @param ImageHandle the image handle of the process
|
| 281 | @param SystemTable the EFI System Table pointer
|
| 282 |
|
| 283 | @retval EFI_SUCCESS the initialization was complete sucessfully
|
| 284 | @return others an error ocurred during initialization
|
| 285 | **/
|
| 286 | EFI_STATUS
|
| 287 | EFIAPI
|
| 288 | ShellLibConstructor (
|
| 289 | IN EFI_HANDLE ImageHandle,
|
| 290 | IN EFI_SYSTEM_TABLE *SystemTable
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 291 | )
|
| 292 | {
|
jcarsey | d2b4564 | 2009-05-11 18:02:16 +0000 | [diff] [blame] | 293 | mEfiShellEnvironment2 = NULL;
|
jcarsey | 366f81a | 2011-06-27 21:04:22 +0000 | [diff] [blame] | 294 | gEfiShellProtocol = NULL;
|
| 295 | gEfiShellParametersProtocol = NULL;
|
jcarsey | d2b4564 | 2009-05-11 18:02:16 +0000 | [diff] [blame] | 296 | mEfiShellInterface = NULL;
|
| 297 | mEfiShellEnvironment2Handle = NULL;
|
| 298 |
|
jcarsey | d2b4564 | 2009-05-11 18:02:16 +0000 | [diff] [blame] | 299 | //
|
| 300 | // verify that auto initialize is not set false
|
jcarsey | 1e6e84c | 2010-01-25 20:05:08 +0000 | [diff] [blame] | 301 | //
|
jcarsey | d2b4564 | 2009-05-11 18:02:16 +0000 | [diff] [blame] | 302 | if (PcdGetBool(PcdShellLibAutoInitialize) == 0) {
|
| 303 | return (EFI_SUCCESS);
|
| 304 | }
|
jcarsey | 1e6e84c | 2010-01-25 20:05:08 +0000 | [diff] [blame] | 305 |
|
jcarsey | d2b4564 | 2009-05-11 18:02:16 +0000 | [diff] [blame] | 306 | return (ShellLibConstructorWorker(ImageHandle, SystemTable));
|
| 307 | }
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 308 |
|
| 309 | /**
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 310 | Destructor for the library. free any resources.
|
| 311 |
|
| 312 | @param[in] ImageHandle A copy of the ImageHandle.
|
| 313 | @param[in] SystemTable A pointer to the SystemTable for the application.
|
| 314 |
|
| 315 | @retval EFI_SUCCESS The operation was successful.
|
| 316 | @return An error from the CloseProtocol function.
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 317 | **/
|
| 318 | EFI_STATUS
|
| 319 | EFIAPI
|
| 320 | ShellLibDestructor (
|
| 321 | IN EFI_HANDLE ImageHandle,
|
| 322 | IN EFI_SYSTEM_TABLE *SystemTable
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 323 | )
|
| 324 | {
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 325 | if (mEfiShellEnvironment2 != NULL) {
|
| 326 | gBS->CloseProtocol(mEfiShellEnvironment2Handle==NULL?ImageHandle:mEfiShellEnvironment2Handle,
|
| 327 | &gEfiShellEnvironment2Guid,
|
| 328 | ImageHandle,
|
| 329 | NULL);
|
jcarsey | d2b4564 | 2009-05-11 18:02:16 +0000 | [diff] [blame] | 330 | mEfiShellEnvironment2 = NULL;
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 331 | }
|
| 332 | if (mEfiShellInterface != NULL) {
|
| 333 | gBS->CloseProtocol(ImageHandle,
|
| 334 | &gEfiShellInterfaceGuid,
|
| 335 | ImageHandle,
|
jcarsey | 1e6e84c | 2010-01-25 20:05:08 +0000 | [diff] [blame] | 336 | NULL);
|
jcarsey | d2b4564 | 2009-05-11 18:02:16 +0000 | [diff] [blame] | 337 | mEfiShellInterface = NULL;
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 338 | }
|
jcarsey | 366f81a | 2011-06-27 21:04:22 +0000 | [diff] [blame] | 339 | if (gEfiShellProtocol != NULL) {
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 340 | gBS->CloseProtocol(ImageHandle,
|
| 341 | &gEfiShellProtocolGuid,
|
| 342 | ImageHandle,
|
jcarsey | 1e6e84c | 2010-01-25 20:05:08 +0000 | [diff] [blame] | 343 | NULL);
|
jcarsey | 366f81a | 2011-06-27 21:04:22 +0000 | [diff] [blame] | 344 | gEfiShellProtocol = NULL;
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 345 | }
|
jcarsey | 366f81a | 2011-06-27 21:04:22 +0000 | [diff] [blame] | 346 | if (gEfiShellParametersProtocol != NULL) {
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 347 | gBS->CloseProtocol(ImageHandle,
|
| 348 | &gEfiShellParametersProtocolGuid,
|
| 349 | ImageHandle,
|
jcarsey | 1e6e84c | 2010-01-25 20:05:08 +0000 | [diff] [blame] | 350 | NULL);
|
jcarsey | 366f81a | 2011-06-27 21:04:22 +0000 | [diff] [blame] | 351 | gEfiShellParametersProtocol = NULL;
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 352 | }
|
jcarsey | d2b4564 | 2009-05-11 18:02:16 +0000 | [diff] [blame] | 353 | mEfiShellEnvironment2Handle = NULL;
|
jcarsey | ecd3d59 | 2009-12-07 18:05:00 +0000 | [diff] [blame] | 354 |
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 355 | return (EFI_SUCCESS);
|
| 356 | }
|
jcarsey | d2b4564 | 2009-05-11 18:02:16 +0000 | [diff] [blame] | 357 |
|
| 358 | /**
|
| 359 | This function causes the shell library to initialize itself. If the shell library
|
| 360 | is already initialized it will de-initialize all the current protocol poitners and
|
| 361 | re-populate them again.
|
| 362 |
|
| 363 | When the library is used with PcdShellLibAutoInitialize set to true this function
|
| 364 | will return EFI_SUCCESS and perform no actions.
|
| 365 |
|
| 366 | This function is intended for internal access for shell commands only.
|
| 367 |
|
| 368 | @retval EFI_SUCCESS the initialization was complete sucessfully
|
| 369 |
|
| 370 | **/
|
| 371 | EFI_STATUS
|
| 372 | EFIAPI
|
| 373 | ShellInitialize (
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 374 | )
|
| 375 | {
|
Laszlo Ersek | 4a7518d | 2016-06-28 13:52:11 +0200 | [diff] [blame] | 376 | EFI_STATUS Status;
|
| 377 |
|
jcarsey | d2b4564 | 2009-05-11 18:02:16 +0000 | [diff] [blame] | 378 | //
|
| 379 | // if auto initialize is not false then skip
|
| 380 | //
|
| 381 | if (PcdGetBool(PcdShellLibAutoInitialize) != 0) {
|
| 382 | return (EFI_SUCCESS);
|
| 383 | }
|
| 384 |
|
| 385 | //
|
| 386 | // deinit the current stuff
|
| 387 | //
|
Laszlo Ersek | 4a7518d | 2016-06-28 13:52:11 +0200 | [diff] [blame] | 388 | Status = ShellLibDestructor (gImageHandle, gST);
|
| 389 | ASSERT_EFI_ERROR (Status);
|
jcarsey | d2b4564 | 2009-05-11 18:02:16 +0000 | [diff] [blame] | 390 |
|
| 391 | //
|
| 392 | // init the new stuff
|
| 393 | //
|
| 394 | return (ShellLibConstructorWorker(gImageHandle, gST));
|
| 395 | }
|
| 396 |
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 397 | /**
|
jcarsey | 1e6e84c | 2010-01-25 20:05:08 +0000 | [diff] [blame] | 398 | This function will retrieve the information about the file for the handle
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 399 | specified and store it in allocated pool memory.
|
| 400 |
|
jcarsey | 1e6e84c | 2010-01-25 20:05:08 +0000 | [diff] [blame] | 401 | This function allocates a buffer to store the file's information. It is the
|
qhuang8 | 69817bf | 2009-05-20 14:42:48 +0000 | [diff] [blame] | 402 | caller's responsibility to free the buffer
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 403 |
|
jcarsey | 1e6e84c | 2010-01-25 20:05:08 +0000 | [diff] [blame] | 404 | @param FileHandle The file handle of the file for which information is
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 405 | being requested.
|
| 406 |
|
| 407 | @retval NULL information could not be retrieved.
|
| 408 |
|
| 409 | @return the information about the file
|
| 410 | **/
|
| 411 | EFI_FILE_INFO*
|
| 412 | EFIAPI
|
| 413 | ShellGetFileInfo (
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 414 | IN SHELL_FILE_HANDLE FileHandle
|
| 415 | )
|
| 416 | {
|
jcarsey | d2b4564 | 2009-05-11 18:02:16 +0000 | [diff] [blame] | 417 | return (FileFunctionMap.GetFileInfo(FileHandle));
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 418 | }
|
| 419 |
|
| 420 | /**
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 421 | This function sets the information about the file for the opened handle
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 422 | specified.
|
| 423 |
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 424 | @param[in] FileHandle The file handle of the file for which information
|
| 425 | is being set.
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 426 |
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 427 | @param[in] FileInfo The information to set.
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 428 |
|
darylm503 | b0934ac | 2011-11-12 00:35:11 +0000 | [diff] [blame] | 429 | @retval EFI_SUCCESS The information was set.
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 430 | @retval EFI_INVALID_PARAMETER A parameter was out of range or invalid.
|
| 431 | @retval EFI_UNSUPPORTED The FileHandle does not support FileInfo.
|
darylm503 | b0934ac | 2011-11-12 00:35:11 +0000 | [diff] [blame] | 432 | @retval EFI_NO_MEDIA The device has no medium.
|
| 433 | @retval EFI_DEVICE_ERROR The device reported an error.
|
| 434 | @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.
|
| 435 | @retval EFI_WRITE_PROTECTED The file or medium is write protected.
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 436 | @retval EFI_ACCESS_DENIED The file was opened read only.
|
| 437 | @retval EFI_VOLUME_FULL The volume is full.
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 438 | **/
|
| 439 | EFI_STATUS
|
| 440 | EFIAPI
|
| 441 | ShellSetFileInfo (
|
darylm503 | b0934ac | 2011-11-12 00:35:11 +0000 | [diff] [blame] | 442 | IN SHELL_FILE_HANDLE FileHandle,
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 443 | IN EFI_FILE_INFO *FileInfo
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 444 | )
|
| 445 | {
|
jcarsey | d2b4564 | 2009-05-11 18:02:16 +0000 | [diff] [blame] | 446 | return (FileFunctionMap.SetFileInfo(FileHandle, FileInfo));
|
jcarsey | 1e6e84c | 2010-01-25 20:05:08 +0000 | [diff] [blame] | 447 | }
|
| 448 |
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 449 | /**
|
| 450 | This function will open a file or directory referenced by DevicePath.
|
| 451 |
|
jcarsey | 1e6e84c | 2010-01-25 20:05:08 +0000 | [diff] [blame] | 452 | This function opens a file with the open mode according to the file path. The
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 453 | Attributes is valid only for EFI_FILE_MODE_CREATE.
|
| 454 |
|
darylm503 | b0934ac | 2011-11-12 00:35:11 +0000 | [diff] [blame] | 455 | @param FilePath on input the device path to the file. On output
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 456 | the remaining device path.
|
darylm503 | b0934ac | 2011-11-12 00:35:11 +0000 | [diff] [blame] | 457 | @param DeviceHandle pointer to the system device handle.
|
| 458 | @param FileHandle pointer to the file handle.
|
| 459 | @param OpenMode the mode to open the file with.
|
| 460 | @param Attributes the file's file attributes.
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 461 |
|
darylm503 | b0934ac | 2011-11-12 00:35:11 +0000 | [diff] [blame] | 462 | @retval EFI_SUCCESS The information was set.
|
| 463 | @retval EFI_INVALID_PARAMETER One of the parameters has an invalid value.
|
| 464 | @retval EFI_UNSUPPORTED Could not open the file path.
|
| 465 | @retval EFI_NOT_FOUND The specified file could not be found on the
|
jcarsey | 1e6e84c | 2010-01-25 20:05:08 +0000 | [diff] [blame] | 466 | device or the file system could not be found on
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 467 | the device.
|
darylm503 | b0934ac | 2011-11-12 00:35:11 +0000 | [diff] [blame] | 468 | @retval EFI_NO_MEDIA The device has no medium.
|
| 469 | @retval EFI_MEDIA_CHANGED The device has a different medium in it or the
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 470 | medium is no longer supported.
|
darylm503 | b0934ac | 2011-11-12 00:35:11 +0000 | [diff] [blame] | 471 | @retval EFI_DEVICE_ERROR The device reported an error.
|
| 472 | @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.
|
| 473 | @retval EFI_WRITE_PROTECTED The file or medium is write protected.
|
| 474 | @retval EFI_ACCESS_DENIED The file was opened read only.
|
| 475 | @retval EFI_OUT_OF_RESOURCES Not enough resources were available to open the
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 476 | file.
|
darylm503 | b0934ac | 2011-11-12 00:35:11 +0000 | [diff] [blame] | 477 | @retval EFI_VOLUME_FULL The volume is full.
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 478 | **/
|
| 479 | EFI_STATUS
|
| 480 | EFIAPI
|
| 481 | ShellOpenFileByDevicePath(
|
darylm503 | b0934ac | 2011-11-12 00:35:11 +0000 | [diff] [blame] | 482 | IN OUT EFI_DEVICE_PATH_PROTOCOL **FilePath,
|
| 483 | OUT EFI_HANDLE *DeviceHandle,
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 484 | OUT SHELL_FILE_HANDLE *FileHandle,
|
darylm503 | b0934ac | 2011-11-12 00:35:11 +0000 | [diff] [blame] | 485 | IN UINT64 OpenMode,
|
| 486 | IN UINT64 Attributes
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 487 | )
|
| 488 | {
|
| 489 | CHAR16 *FileName;
|
| 490 | EFI_STATUS Status;
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 491 | EFI_SIMPLE_FILE_SYSTEM_PROTOCOL *EfiSimpleFileSystemProtocol;
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 492 | EFI_FILE_PROTOCOL *Handle1;
|
| 493 | EFI_FILE_PROTOCOL *Handle2;
|
ydong10 | 0b6cb33 | 2013-01-25 02:00:22 +0000 | [diff] [blame] | 494 | CHAR16 *FnafPathName;
|
| 495 | UINTN PathLen;
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 496 |
|
jcarsey | 92a5447 | 2011-06-27 20:33:13 +0000 | [diff] [blame] | 497 | if (FilePath == NULL || FileHandle == NULL || DeviceHandle == NULL) {
|
| 498 | return (EFI_INVALID_PARAMETER);
|
| 499 | }
|
| 500 |
|
jcarsey | 1e6e84c | 2010-01-25 20:05:08 +0000 | [diff] [blame] | 501 | //
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 502 | // which shell interface should we use
|
| 503 | //
|
jcarsey | 366f81a | 2011-06-27 21:04:22 +0000 | [diff] [blame] | 504 | if (gEfiShellProtocol != NULL) {
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 505 | //
|
| 506 | // use UEFI Shell 2.0 method.
|
| 507 | //
|
jcarsey | 366f81a | 2011-06-27 21:04:22 +0000 | [diff] [blame] | 508 | FileName = gEfiShellProtocol->GetFilePathFromDevicePath(*FilePath);
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 509 | if (FileName == NULL) {
|
| 510 | return (EFI_INVALID_PARAMETER);
|
| 511 | }
|
| 512 | Status = ShellOpenFileByName(FileName, FileHandle, OpenMode, Attributes);
|
| 513 | FreePool(FileName);
|
| 514 | return (Status);
|
jcarsey | 1e6e84c | 2010-01-25 20:05:08 +0000 | [diff] [blame] | 515 | }
|
jcarsey | d2b4564 | 2009-05-11 18:02:16 +0000 | [diff] [blame] | 516 |
|
| 517 |
|
| 518 | //
|
| 519 | // use old shell method.
|
| 520 | //
|
jcarsey | 1e6e84c | 2010-01-25 20:05:08 +0000 | [diff] [blame] | 521 | Status = gBS->LocateDevicePath (&gEfiSimpleFileSystemProtocolGuid,
|
| 522 | FilePath,
|
jcarsey | d2b4564 | 2009-05-11 18:02:16 +0000 | [diff] [blame] | 523 | DeviceHandle);
|
| 524 | if (EFI_ERROR (Status)) {
|
| 525 | return Status;
|
| 526 | }
|
| 527 | Status = gBS->OpenProtocol(*DeviceHandle,
|
| 528 | &gEfiSimpleFileSystemProtocolGuid,
|
jcarsey | b1f95a0 | 2009-06-16 00:23:19 +0000 | [diff] [blame] | 529 | (VOID**)&EfiSimpleFileSystemProtocol,
|
jcarsey | d2b4564 | 2009-05-11 18:02:16 +0000 | [diff] [blame] | 530 | gImageHandle,
|
| 531 | NULL,
|
| 532 | EFI_OPEN_PROTOCOL_GET_PROTOCOL);
|
| 533 | if (EFI_ERROR (Status)) {
|
| 534 | return Status;
|
| 535 | }
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 536 | Status = EfiSimpleFileSystemProtocol->OpenVolume(EfiSimpleFileSystemProtocol, &Handle1);
|
jcarsey | d2b4564 | 2009-05-11 18:02:16 +0000 | [diff] [blame] | 537 | if (EFI_ERROR (Status)) {
|
| 538 | FileHandle = NULL;
|
| 539 | return Status;
|
| 540 | }
|
| 541 |
|
| 542 | //
|
| 543 | // go down directories one node at a time.
|
| 544 | //
|
| 545 | while (!IsDevicePathEnd (*FilePath)) {
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 546 | //
|
jcarsey | d2b4564 | 2009-05-11 18:02:16 +0000 | [diff] [blame] | 547 | // For file system access each node should be a file path component
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 548 | //
|
jcarsey | d2b4564 | 2009-05-11 18:02:16 +0000 | [diff] [blame] | 549 | if (DevicePathType (*FilePath) != MEDIA_DEVICE_PATH ||
|
| 550 | DevicePathSubType (*FilePath) != MEDIA_FILEPATH_DP
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 551 | ) {
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 552 | FileHandle = NULL;
|
jcarsey | d2b4564 | 2009-05-11 18:02:16 +0000 | [diff] [blame] | 553 | return (EFI_INVALID_PARAMETER);
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 554 | }
|
jcarsey | d2b4564 | 2009-05-11 18:02:16 +0000 | [diff] [blame] | 555 | //
|
| 556 | // Open this file path node
|
| 557 | //
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 558 | Handle2 = Handle1;
|
| 559 | Handle1 = NULL;
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 560 |
|
| 561 | //
|
ydong10 | 0b6cb33 | 2013-01-25 02:00:22 +0000 | [diff] [blame] | 562 | // File Name Alignment Fix (FNAF)
|
| 563 | // Handle2->Open may be incapable of handling a unaligned CHAR16 data.
|
| 564 | // The structure pointed to by FilePath may be not CHAR16 aligned.
|
| 565 | // This code copies the potentially unaligned PathName data from the
|
| 566 | // FilePath structure to the aligned FnafPathName for use in the
|
| 567 | // calls to Handl2->Open.
|
| 568 | //
|
| 569 |
|
| 570 | //
|
| 571 | // Determine length of PathName, in bytes.
|
| 572 | //
|
| 573 | PathLen = DevicePathNodeLength (*FilePath) - SIZE_OF_FILEPATH_DEVICE_PATH;
|
| 574 |
|
| 575 | //
|
| 576 | // Allocate memory for the aligned copy of the string Extra allocation is to allow for forced alignment
|
| 577 | // Copy bytes from possibly unaligned location to aligned location
|
| 578 | //
|
| 579 | FnafPathName = AllocateCopyPool(PathLen, (UINT8 *)((FILEPATH_DEVICE_PATH*)*FilePath)->PathName);
|
| 580 | if (FnafPathName == NULL) {
|
| 581 | return EFI_OUT_OF_RESOURCES;
|
| 582 | }
|
| 583 |
|
| 584 | //
|
jcarsey | d2b4564 | 2009-05-11 18:02:16 +0000 | [diff] [blame] | 585 | // Try to test opening an existing file
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 586 | //
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 587 | Status = Handle2->Open (
|
| 588 | Handle2,
|
| 589 | &Handle1,
|
ydong10 | 0b6cb33 | 2013-01-25 02:00:22 +0000 | [diff] [blame] | 590 | FnafPathName,
|
jcarsey | d2b4564 | 2009-05-11 18:02:16 +0000 | [diff] [blame] | 591 | OpenMode &~EFI_FILE_MODE_CREATE,
|
| 592 | 0
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 593 | );
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 594 |
|
jcarsey | d2b4564 | 2009-05-11 18:02:16 +0000 | [diff] [blame] | 595 | //
|
| 596 | // see if the error was that it needs to be created
|
| 597 | //
|
| 598 | if ((EFI_ERROR (Status)) && (OpenMode != (OpenMode &~EFI_FILE_MODE_CREATE))) {
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 599 | Status = Handle2->Open (
|
| 600 | Handle2,
|
| 601 | &Handle1,
|
ydong10 | 0b6cb33 | 2013-01-25 02:00:22 +0000 | [diff] [blame] | 602 | FnafPathName,
|
jcarsey | d2b4564 | 2009-05-11 18:02:16 +0000 | [diff] [blame] | 603 | OpenMode,
|
| 604 | Attributes
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 605 | );
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 606 | }
|
ydong10 | 0b6cb33 | 2013-01-25 02:00:22 +0000 | [diff] [blame] | 607 |
|
| 608 | //
|
| 609 | // Free the alignment buffer
|
| 610 | //
|
| 611 | FreePool(FnafPathName);
|
| 612 |
|
jcarsey | d2b4564 | 2009-05-11 18:02:16 +0000 | [diff] [blame] | 613 | //
|
| 614 | // Close the last node
|
| 615 | //
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 616 | Handle2->Close (Handle2);
|
jcarsey | d2b4564 | 2009-05-11 18:02:16 +0000 | [diff] [blame] | 617 |
|
| 618 | if (EFI_ERROR(Status)) {
|
| 619 | return (Status);
|
| 620 | }
|
| 621 |
|
| 622 | //
|
| 623 | // Get the next node
|
| 624 | //
|
| 625 | *FilePath = NextDevicePathNode (*FilePath);
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 626 | }
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 627 |
|
| 628 | //
|
| 629 | // This is a weak spot since if the undefined SHELL_FILE_HANDLE format changes this must change also!
|
| 630 | //
|
| 631 | *FileHandle = (VOID*)Handle1;
|
jcarsey | d2b4564 | 2009-05-11 18:02:16 +0000 | [diff] [blame] | 632 | return (EFI_SUCCESS);
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 633 | }
|
| 634 |
|
| 635 | /**
|
| 636 | This function will open a file or directory referenced by filename.
|
| 637 |
|
jcarsey | 1e6e84c | 2010-01-25 20:05:08 +0000 | [diff] [blame] | 638 | If return is EFI_SUCCESS, the Filehandle is the opened file's handle;
|
| 639 | otherwise, the Filehandle is NULL. The Attributes is valid only for
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 640 | EFI_FILE_MODE_CREATE.
|
| 641 |
|
jcarsey | 92a5447 | 2011-06-27 20:33:13 +0000 | [diff] [blame] | 642 | if FileName is NULL then ASSERT()
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 643 |
|
darylm503 | b0934ac | 2011-11-12 00:35:11 +0000 | [diff] [blame] | 644 | @param FileName pointer to file name
|
| 645 | @param FileHandle pointer to the file handle.
|
| 646 | @param OpenMode the mode to open the file with.
|
| 647 | @param Attributes the file's file attributes.
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 648 |
|
darylm503 | b0934ac | 2011-11-12 00:35:11 +0000 | [diff] [blame] | 649 | @retval EFI_SUCCESS The information was set.
|
| 650 | @retval EFI_INVALID_PARAMETER One of the parameters has an invalid value.
|
| 651 | @retval EFI_UNSUPPORTED Could not open the file path.
|
| 652 | @retval EFI_NOT_FOUND The specified file could not be found on the
|
jcarsey | 1e6e84c | 2010-01-25 20:05:08 +0000 | [diff] [blame] | 653 | device or the file system could not be found
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 654 | on the device.
|
darylm503 | b0934ac | 2011-11-12 00:35:11 +0000 | [diff] [blame] | 655 | @retval EFI_NO_MEDIA The device has no medium.
|
| 656 | @retval EFI_MEDIA_CHANGED The device has a different medium in it or the
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 657 | medium is no longer supported.
|
darylm503 | b0934ac | 2011-11-12 00:35:11 +0000 | [diff] [blame] | 658 | @retval EFI_DEVICE_ERROR The device reported an error.
|
| 659 | @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.
|
| 660 | @retval EFI_WRITE_PROTECTED The file or medium is write protected.
|
| 661 | @retval EFI_ACCESS_DENIED The file was opened read only.
|
| 662 | @retval EFI_OUT_OF_RESOURCES Not enough resources were available to open the
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 663 | file.
|
darylm503 | b0934ac | 2011-11-12 00:35:11 +0000 | [diff] [blame] | 664 | @retval EFI_VOLUME_FULL The volume is full.
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 665 | **/
|
| 666 | EFI_STATUS
|
| 667 | EFIAPI
|
| 668 | ShellOpenFileByName(
|
darylm503 | b0934ac | 2011-11-12 00:35:11 +0000 | [diff] [blame] | 669 | IN CONST CHAR16 *FileName,
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 670 | OUT SHELL_FILE_HANDLE *FileHandle,
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 671 | IN UINT64 OpenMode,
|
darylm503 | b0934ac | 2011-11-12 00:35:11 +0000 | [diff] [blame] | 672 | IN UINT64 Attributes
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 673 | )
|
| 674 | {
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 675 | EFI_HANDLE DeviceHandle;
|
| 676 | EFI_DEVICE_PATH_PROTOCOL *FilePath;
|
jcarsey | b1f95a0 | 2009-06-16 00:23:19 +0000 | [diff] [blame] | 677 | EFI_STATUS Status;
|
| 678 | EFI_FILE_INFO *FileInfo;
|
jaben carsey | 21a86a7 | 2015-01-13 22:16:41 +0000 | [diff] [blame] | 679 | CHAR16 *FileNameCopy;
|
Yao Jiewen | dd17e3f | 2015-12-25 01:24:16 +0000 | [diff] [blame] | 680 | EFI_STATUS Status2;
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 681 |
|
| 682 | //
|
| 683 | // ASSERT if FileName is NULL
|
| 684 | //
|
| 685 | ASSERT(FileName != NULL);
|
| 686 |
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 687 | if (FileName == NULL) {
|
| 688 | return (EFI_INVALID_PARAMETER);
|
| 689 | }
|
| 690 |
|
jcarsey | 366f81a | 2011-06-27 21:04:22 +0000 | [diff] [blame] | 691 | if (gEfiShellProtocol != NULL) {
|
jaben carsey | 21a86a7 | 2015-01-13 22:16:41 +0000 | [diff] [blame] | 692 | if ((OpenMode & EFI_FILE_MODE_CREATE) == EFI_FILE_MODE_CREATE) {
|
| 693 |
|
| 694 | //
|
| 695 | // Create only a directory
|
| 696 | //
|
| 697 | if ((Attributes & EFI_FILE_DIRECTORY) == EFI_FILE_DIRECTORY) {
|
| 698 | return ShellCreateDirectory(FileName, FileHandle);
|
| 699 | }
|
| 700 |
|
| 701 | //
|
| 702 | // Create the directory to create the file in
|
| 703 | //
|
| 704 | FileNameCopy = AllocateCopyPool (StrSize (FileName), FileName);
|
| 705 | if (FileName == NULL) {
|
| 706 | return (EFI_OUT_OF_RESOURCES);
|
| 707 | }
|
| 708 | PathCleanUpDirectories (FileNameCopy);
|
| 709 | if (PathRemoveLastItem (FileNameCopy)) {
|
Jaben Carsey | 983fffd | 2015-07-28 20:22:26 +0000 | [diff] [blame] | 710 | if (!EFI_ERROR(ShellCreateDirectory (FileNameCopy, FileHandle))) {
|
| 711 | ShellCloseFile (FileHandle);
|
| 712 | }
|
jaben carsey | 21a86a7 | 2015-01-13 22:16:41 +0000 | [diff] [blame] | 713 | }
|
| 714 | SHELL_FREE_NON_NULL (FileNameCopy);
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 715 | }
|
jaben carsey | 21a86a7 | 2015-01-13 22:16:41 +0000 | [diff] [blame] | 716 |
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 717 | //
|
jaben carsey | 21a86a7 | 2015-01-13 22:16:41 +0000 | [diff] [blame] | 718 | // Use UEFI Shell 2.0 method to create the file
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 719 | //
|
jcarsey | 366f81a | 2011-06-27 21:04:22 +0000 | [diff] [blame] | 720 | Status = gEfiShellProtocol->OpenFileByName(FileName,
|
jcarsey | b1f95a0 | 2009-06-16 00:23:19 +0000 | [diff] [blame] | 721 | FileHandle,
|
| 722 | OpenMode);
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 723 | if (StrCmp(FileName, L"NUL") != 0 && !EFI_ERROR(Status) && ((OpenMode & EFI_FILE_MODE_CREATE) != 0)){
|
jcarsey | 2247dde | 2009-11-09 18:08:58 +0000 | [diff] [blame] | 724 | FileInfo = FileFunctionMap.GetFileInfo(*FileHandle);
|
jcarsey | b1f95a0 | 2009-06-16 00:23:19 +0000 | [diff] [blame] | 725 | ASSERT(FileInfo != NULL);
|
| 726 | FileInfo->Attribute = Attributes;
|
Yao Jiewen | dd17e3f | 2015-12-25 01:24:16 +0000 | [diff] [blame] | 727 | Status2 = FileFunctionMap.SetFileInfo(*FileHandle, FileInfo);
|
jcarsey | 2247dde | 2009-11-09 18:08:58 +0000 | [diff] [blame] | 728 | FreePool(FileInfo);
|
Yao Jiewen | dd17e3f | 2015-12-25 01:24:16 +0000 | [diff] [blame] | 729 | if (EFI_ERROR (Status2)) {
|
| 730 | gEfiShellProtocol->CloseFile(*FileHandle);
|
| 731 | }
|
| 732 | Status = Status2;
|
jcarsey | b1f95a0 | 2009-06-16 00:23:19 +0000 | [diff] [blame] | 733 | }
|
| 734 | return (Status);
|
jcarsey | 1e6e84c | 2010-01-25 20:05:08 +0000 | [diff] [blame] | 735 | }
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 736 | //
|
| 737 | // Using EFI Shell version
|
| 738 | // this means convert name to path and call that function
|
| 739 | // since this will use EFI method again that will open it.
|
| 740 | //
|
| 741 | ASSERT(mEfiShellEnvironment2 != NULL);
|
jcarsey | b82bfcc | 2009-06-29 16:28:23 +0000 | [diff] [blame] | 742 | FilePath = mEfiShellEnvironment2->NameToPath ((CHAR16*)FileName);
|
xdu2 | 90bfa22 | 2010-07-19 05:21:27 +0000 | [diff] [blame] | 743 | if (FilePath != NULL) {
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 744 | return (ShellOpenFileByDevicePath(&FilePath,
|
| 745 | &DeviceHandle,
|
| 746 | FileHandle,
|
| 747 | OpenMode,
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 748 | Attributes));
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 749 | }
|
| 750 | return (EFI_DEVICE_ERROR);
|
| 751 | }
|
| 752 | /**
|
| 753 | This function create a directory
|
| 754 |
|
jcarsey | 1e6e84c | 2010-01-25 20:05:08 +0000 | [diff] [blame] | 755 | If return is EFI_SUCCESS, the Filehandle is the opened directory's handle;
|
| 756 | otherwise, the Filehandle is NULL. If the directory already existed, this
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 757 | function opens the existing directory.
|
| 758 |
|
darylm503 | b0934ac | 2011-11-12 00:35:11 +0000 | [diff] [blame] | 759 | @param DirectoryName pointer to directory name
|
| 760 | @param FileHandle pointer to the file handle.
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 761 |
|
darylm503 | b0934ac | 2011-11-12 00:35:11 +0000 | [diff] [blame] | 762 | @retval EFI_SUCCESS The information was set.
|
| 763 | @retval EFI_INVALID_PARAMETER One of the parameters has an invalid value.
|
| 764 | @retval EFI_UNSUPPORTED Could not open the file path.
|
| 765 | @retval EFI_NOT_FOUND The specified file could not be found on the
|
jcarsey | 1e6e84c | 2010-01-25 20:05:08 +0000 | [diff] [blame] | 766 | device or the file system could not be found
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 767 | on the device.
|
darylm503 | b0934ac | 2011-11-12 00:35:11 +0000 | [diff] [blame] | 768 | @retval EFI_NO_MEDIA The device has no medium.
|
| 769 | @retval EFI_MEDIA_CHANGED The device has a different medium in it or the
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 770 | medium is no longer supported.
|
darylm503 | b0934ac | 2011-11-12 00:35:11 +0000 | [diff] [blame] | 771 | @retval EFI_DEVICE_ERROR The device reported an error.
|
| 772 | @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.
|
| 773 | @retval EFI_WRITE_PROTECTED The file or medium is write protected.
|
| 774 | @retval EFI_ACCESS_DENIED The file was opened read only.
|
| 775 | @retval EFI_OUT_OF_RESOURCES Not enough resources were available to open the
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 776 | file.
|
darylm503 | b0934ac | 2011-11-12 00:35:11 +0000 | [diff] [blame] | 777 | @retval EFI_VOLUME_FULL The volume is full.
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 778 | @sa ShellOpenFileByName
|
| 779 | **/
|
| 780 | EFI_STATUS
|
| 781 | EFIAPI
|
| 782 | ShellCreateDirectory(
|
jcarsey | b82bfcc | 2009-06-29 16:28:23 +0000 | [diff] [blame] | 783 | IN CONST CHAR16 *DirectoryName,
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 784 | OUT SHELL_FILE_HANDLE *FileHandle
|
| 785 | )
|
| 786 | {
|
jcarsey | 366f81a | 2011-06-27 21:04:22 +0000 | [diff] [blame] | 787 | if (gEfiShellProtocol != NULL) {
|
jcarsey | 2247dde | 2009-11-09 18:08:58 +0000 | [diff] [blame] | 788 | //
|
| 789 | // Use UEFI Shell 2.0 method
|
| 790 | //
|
jcarsey | 366f81a | 2011-06-27 21:04:22 +0000 | [diff] [blame] | 791 | return (gEfiShellProtocol->CreateFile(DirectoryName,
|
jcarsey | 2247dde | 2009-11-09 18:08:58 +0000 | [diff] [blame] | 792 | EFI_FILE_DIRECTORY,
|
| 793 | FileHandle
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 794 | ));
|
jcarsey | 2247dde | 2009-11-09 18:08:58 +0000 | [diff] [blame] | 795 | } else {
|
| 796 | return (ShellOpenFileByName(DirectoryName,
|
| 797 | FileHandle,
|
| 798 | EFI_FILE_MODE_READ | EFI_FILE_MODE_WRITE | EFI_FILE_MODE_CREATE,
|
| 799 | EFI_FILE_DIRECTORY
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 800 | ));
|
jcarsey | 2247dde | 2009-11-09 18:08:58 +0000 | [diff] [blame] | 801 | }
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 802 | }
|
| 803 |
|
| 804 | /**
|
| 805 | This function reads information from an opened file.
|
| 806 |
|
jcarsey | 1e6e84c | 2010-01-25 20:05:08 +0000 | [diff] [blame] | 807 | If FileHandle is not a directory, the function reads the requested number of
|
| 808 | bytes from the file at the file's current position and returns them in Buffer.
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 809 | If the read goes beyond the end of the file, the read length is truncated to the
|
jcarsey | 1e6e84c | 2010-01-25 20:05:08 +0000 | [diff] [blame] | 810 | end of the file. The file's current position is increased by the number of bytes
|
| 811 | returned. If FileHandle is a directory, the function reads the directory entry
|
| 812 | at the file's current position and returns the entry in Buffer. If the Buffer
|
| 813 | is not large enough to hold the current directory entry, then
|
| 814 | EFI_BUFFER_TOO_SMALL is returned and the current file position is not updated.
|
| 815 | BufferSize is set to be the size of the buffer needed to read the entry. On
|
| 816 | success, the current position is updated to the next directory entry. If there
|
| 817 | are no more directory entries, the read returns a zero-length buffer.
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 818 | EFI_FILE_INFO is the structure returned as the directory entry.
|
| 819 |
|
| 820 | @param FileHandle the opened file handle
|
jcarsey | 1e6e84c | 2010-01-25 20:05:08 +0000 | [diff] [blame] | 821 | @param BufferSize on input the size of buffer in bytes. on return
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 822 | the number of bytes written.
|
| 823 | @param Buffer the buffer to put read data into.
|
| 824 |
|
darylm503 | b0934ac | 2011-11-12 00:35:11 +0000 | [diff] [blame] | 825 | @retval EFI_SUCCESS Data was read.
|
| 826 | @retval EFI_NO_MEDIA The device has no media.
|
| 827 | @retval EFI_DEVICE_ERROR The device reported an error.
|
| 828 | @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.
|
| 829 | @retval EFI_BUFFER_TO_SMALL Buffer is too small. ReadSize contains required
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 830 | size.
|
| 831 |
|
| 832 | **/
|
| 833 | EFI_STATUS
|
| 834 | EFIAPI
|
| 835 | ShellReadFile(
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 836 | IN SHELL_FILE_HANDLE FileHandle,
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 837 | IN OUT UINTN *BufferSize,
|
| 838 | OUT VOID *Buffer
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 839 | )
|
| 840 | {
|
jcarsey | d2b4564 | 2009-05-11 18:02:16 +0000 | [diff] [blame] | 841 | return (FileFunctionMap.ReadFile(FileHandle, BufferSize, Buffer));
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 842 | }
|
| 843 |
|
| 844 |
|
| 845 | /**
|
| 846 | Write data to a file.
|
| 847 |
|
jcarsey | 1e6e84c | 2010-01-25 20:05:08 +0000 | [diff] [blame] | 848 | This function writes the specified number of bytes to the file at the current
|
| 849 | file position. The current file position is advanced the actual number of bytes
|
| 850 | written, which is returned in BufferSize. Partial writes only occur when there
|
| 851 | has been a data error during the write attempt (such as "volume space full").
|
| 852 | The file is automatically grown to hold the data if required. Direct writes to
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 853 | opened directories are not supported.
|
| 854 |
|
| 855 | @param FileHandle The opened file for writing
|
| 856 | @param BufferSize on input the number of bytes in Buffer. On output
|
| 857 | the number of bytes written.
|
| 858 | @param Buffer the buffer containing data to write is stored.
|
| 859 |
|
darylm503 | b0934ac | 2011-11-12 00:35:11 +0000 | [diff] [blame] | 860 | @retval EFI_SUCCESS Data was written.
|
| 861 | @retval EFI_UNSUPPORTED Writes to an open directory are not supported.
|
| 862 | @retval EFI_NO_MEDIA The device has no media.
|
| 863 | @retval EFI_DEVICE_ERROR The device reported an error.
|
| 864 | @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.
|
| 865 | @retval EFI_WRITE_PROTECTED The device is write-protected.
|
| 866 | @retval EFI_ACCESS_DENIED The file was open for read only.
|
| 867 | @retval EFI_VOLUME_FULL The volume is full.
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 868 | **/
|
| 869 | EFI_STATUS
|
| 870 | EFIAPI
|
| 871 | ShellWriteFile(
|
jcarsey | 252d945 | 2011-03-25 20:49:53 +0000 | [diff] [blame] | 872 | IN SHELL_FILE_HANDLE FileHandle,
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 873 | IN OUT UINTN *BufferSize,
|
| 874 | IN VOID *Buffer
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 875 | )
|
| 876 | {
|
jcarsey | d2b4564 | 2009-05-11 18:02:16 +0000 | [diff] [blame] | 877 | return (FileFunctionMap.WriteFile(FileHandle, BufferSize, Buffer));
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 878 | }
|
| 879 |
|
jcarsey | 1e6e84c | 2010-01-25 20:05:08 +0000 | [diff] [blame] | 880 | /**
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 881 | Close an open file handle.
|
| 882 |
|
jcarsey | 1e6e84c | 2010-01-25 20:05:08 +0000 | [diff] [blame] | 883 | This function closes a specified file handle. All "dirty" cached file data is
|
| 884 | flushed to the device, and the file is closed. In all cases the handle is
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 885 | closed.
|
| 886 |
|
| 887 | @param FileHandle the file handle to close.
|
| 888 |
|
| 889 | @retval EFI_SUCCESS the file handle was closed sucessfully.
|
| 890 | **/
|
| 891 | EFI_STATUS
|
| 892 | EFIAPI
|
| 893 | ShellCloseFile (
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 894 | IN SHELL_FILE_HANDLE *FileHandle
|
| 895 | )
|
| 896 | {
|
jcarsey | d2b4564 | 2009-05-11 18:02:16 +0000 | [diff] [blame] | 897 | return (FileFunctionMap.CloseFile(*FileHandle));
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 898 | }
|
| 899 |
|
| 900 | /**
|
| 901 | Delete a file and close the handle
|
| 902 |
|
| 903 | This function closes and deletes a file. In all cases the file handle is closed.
|
jcarsey | 1e6e84c | 2010-01-25 20:05:08 +0000 | [diff] [blame] | 904 | If the file cannot be deleted, the warning code EFI_WARN_DELETE_FAILURE is
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 905 | returned, but the handle is still closed.
|
| 906 |
|
| 907 | @param FileHandle the file handle to delete
|
| 908 |
|
| 909 | @retval EFI_SUCCESS the file was closed sucessfully
|
jcarsey | 1e6e84c | 2010-01-25 20:05:08 +0000 | [diff] [blame] | 910 | @retval EFI_WARN_DELETE_FAILURE the handle was closed, but the file was not
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 911 | deleted
|
darylm503 | b0934ac | 2011-11-12 00:35:11 +0000 | [diff] [blame] | 912 | @retval INVALID_PARAMETER One of the parameters has an invalid value.
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 913 | **/
|
| 914 | EFI_STATUS
|
| 915 | EFIAPI
|
| 916 | ShellDeleteFile (
|
darylm503 | b0934ac | 2011-11-12 00:35:11 +0000 | [diff] [blame] | 917 | IN SHELL_FILE_HANDLE *FileHandle
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 918 | )
|
| 919 | {
|
jcarsey | d2b4564 | 2009-05-11 18:02:16 +0000 | [diff] [blame] | 920 | return (FileFunctionMap.DeleteFile(*FileHandle));
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 921 | }
|
| 922 |
|
| 923 | /**
|
| 924 | Set the current position in a file.
|
| 925 |
|
jcarsey | 1e6e84c | 2010-01-25 20:05:08 +0000 | [diff] [blame] | 926 | This function sets the current file position for the handle to the position
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 927 | supplied. With the exception of seeking to position 0xFFFFFFFFFFFFFFFF, only
|
jcarsey | 1e6e84c | 2010-01-25 20:05:08 +0000 | [diff] [blame] | 928 | absolute positioning is supported, and seeking past the end of the file is
|
| 929 | allowed (a subsequent write would grow the file). Seeking to position
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 930 | 0xFFFFFFFFFFFFFFFF causes the current position to be set to the end of the file.
|
jcarsey | 1e6e84c | 2010-01-25 20:05:08 +0000 | [diff] [blame] | 931 | If FileHandle is a directory, the only position that may be set is zero. This
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 932 | has the effect of starting the read process of the directory entries over.
|
| 933 |
|
| 934 | @param FileHandle The file handle on which the position is being set
|
| 935 | @param Position Byte position from begining of file
|
| 936 |
|
| 937 | @retval EFI_SUCCESS Operation completed sucessfully.
|
jcarsey | 1e6e84c | 2010-01-25 20:05:08 +0000 | [diff] [blame] | 938 | @retval EFI_UNSUPPORTED the seek request for non-zero is not valid on
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 939 | directories.
|
| 940 | @retval INVALID_PARAMETER One of the parameters has an invalid value.
|
| 941 | **/
|
| 942 | EFI_STATUS
|
| 943 | EFIAPI
|
| 944 | ShellSetFilePosition (
|
darylm503 | b0934ac | 2011-11-12 00:35:11 +0000 | [diff] [blame] | 945 | IN SHELL_FILE_HANDLE FileHandle,
|
| 946 | IN UINT64 Position
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 947 | )
|
| 948 | {
|
jcarsey | d2b4564 | 2009-05-11 18:02:16 +0000 | [diff] [blame] | 949 | return (FileFunctionMap.SetFilePosition(FileHandle, Position));
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 950 | }
|
| 951 |
|
jcarsey | 1e6e84c | 2010-01-25 20:05:08 +0000 | [diff] [blame] | 952 | /**
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 953 | Gets a file's current position
|
| 954 |
|
jcarsey | 1e6e84c | 2010-01-25 20:05:08 +0000 | [diff] [blame] | 955 | This function retrieves the current file position for the file handle. For
|
| 956 | directories, the current file position has no meaning outside of the file
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 957 | system driver and as such the operation is not supported. An error is returned
|
| 958 | if FileHandle is a directory.
|
| 959 |
|
| 960 | @param FileHandle The open file handle on which to get the position.
|
| 961 | @param Position Byte position from begining of file.
|
| 962 |
|
| 963 | @retval EFI_SUCCESS the operation completed sucessfully.
|
| 964 | @retval INVALID_PARAMETER One of the parameters has an invalid value.
|
| 965 | @retval EFI_UNSUPPORTED the request is not valid on directories.
|
| 966 | **/
|
| 967 | EFI_STATUS
|
| 968 | EFIAPI
|
| 969 | ShellGetFilePosition (
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 970 | IN SHELL_FILE_HANDLE FileHandle,
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 971 | OUT UINT64 *Position
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 972 | )
|
| 973 | {
|
jcarsey | d2b4564 | 2009-05-11 18:02:16 +0000 | [diff] [blame] | 974 | return (FileFunctionMap.GetFilePosition(FileHandle, Position));
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 975 | }
|
| 976 | /**
|
| 977 | Flushes data on a file
|
jcarsey | 1e6e84c | 2010-01-25 20:05:08 +0000 | [diff] [blame] | 978 |
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 979 | This function flushes all modified data associated with a file to a device.
|
| 980 |
|
| 981 | @param FileHandle The file handle on which to flush data
|
| 982 |
|
| 983 | @retval EFI_SUCCESS The data was flushed.
|
| 984 | @retval EFI_NO_MEDIA The device has no media.
|
| 985 | @retval EFI_DEVICE_ERROR The device reported an error.
|
| 986 | @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.
|
| 987 | @retval EFI_WRITE_PROTECTED The file or medium is write protected.
|
| 988 | @retval EFI_ACCESS_DENIED The file was opened for read only.
|
| 989 | **/
|
| 990 | EFI_STATUS
|
| 991 | EFIAPI
|
| 992 | ShellFlushFile (
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 993 | IN SHELL_FILE_HANDLE FileHandle
|
| 994 | )
|
| 995 | {
|
jcarsey | d2b4564 | 2009-05-11 18:02:16 +0000 | [diff] [blame] | 996 | return (FileFunctionMap.FlushFile(FileHandle));
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 997 | }
|
| 998 |
|
darylm503 | b0934ac | 2011-11-12 00:35:11 +0000 | [diff] [blame] | 999 | /** Retrieve first entry from a directory.
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 1000 |
|
darylm503 | b0934ac | 2011-11-12 00:35:11 +0000 | [diff] [blame] | 1001 | This function takes an open directory handle and gets information from the
|
| 1002 | first entry in the directory. A buffer is allocated to contain
|
| 1003 | the information and a pointer to the buffer is returned in *Buffer. The
|
| 1004 | caller can use ShellFindNextFile() to get subsequent directory entries.
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 1005 |
|
darylm503 | b0934ac | 2011-11-12 00:35:11 +0000 | [diff] [blame] | 1006 | The buffer will be freed by ShellFindNextFile() when the last directory
|
| 1007 | entry is read. Otherwise, the caller must free the buffer, using FreePool,
|
| 1008 | when finished with it.
|
| 1009 |
|
| 1010 | @param[in] DirHandle The file handle of the directory to search.
|
| 1011 | @param[out] Buffer The pointer to the buffer for the file's information.
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 1012 |
|
| 1013 | @retval EFI_SUCCESS Found the first file.
|
| 1014 | @retval EFI_NOT_FOUND Cannot find the directory.
|
| 1015 | @retval EFI_NO_MEDIA The device has no media.
|
| 1016 | @retval EFI_DEVICE_ERROR The device reported an error.
|
| 1017 | @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.
|
| 1018 | @return Others status of ShellGetFileInfo, ShellSetFilePosition,
|
| 1019 | or ShellReadFile
|
| 1020 | **/
|
| 1021 | EFI_STATUS
|
| 1022 | EFIAPI
|
| 1023 | ShellFindFirstFile (
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 1024 | IN SHELL_FILE_HANDLE DirHandle,
|
jcarsey | d2b4564 | 2009-05-11 18:02:16 +0000 | [diff] [blame] | 1025 | OUT EFI_FILE_INFO **Buffer
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 1026 | )
|
| 1027 | {
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 1028 | //
|
jcarsey | d2b4564 | 2009-05-11 18:02:16 +0000 | [diff] [blame] | 1029 | // pass to file handle lib
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 1030 | //
|
jcarsey | d2b4564 | 2009-05-11 18:02:16 +0000 | [diff] [blame] | 1031 | return (FileHandleFindFirstFile(DirHandle, Buffer));
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 1032 | }
|
darylm503 | b0934ac | 2011-11-12 00:35:11 +0000 | [diff] [blame] | 1033 | /** Retrieve next entries from a directory.
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 1034 |
|
darylm503 | b0934ac | 2011-11-12 00:35:11 +0000 | [diff] [blame] | 1035 | To use this function, the caller must first call the ShellFindFirstFile()
|
| 1036 | function to get the first directory entry. Subsequent directory entries are
|
| 1037 | retrieved by using the ShellFindNextFile() function. This function can
|
| 1038 | be called several times to get each entry from the directory. If the call of
|
| 1039 | ShellFindNextFile() retrieved the last directory entry, the next call of
|
| 1040 | this function will set *NoFile to TRUE and free the buffer.
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 1041 |
|
darylm503 | b0934ac | 2011-11-12 00:35:11 +0000 | [diff] [blame] | 1042 | @param[in] DirHandle The file handle of the directory.
|
| 1043 | @param[out] Buffer The pointer to buffer for file's information.
|
| 1044 | @param[out] NoFile The pointer to boolean when last file is found.
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 1045 |
|
| 1046 | @retval EFI_SUCCESS Found the next file, or reached last file
|
| 1047 | @retval EFI_NO_MEDIA The device has no media.
|
| 1048 | @retval EFI_DEVICE_ERROR The device reported an error.
|
| 1049 | @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.
|
| 1050 | **/
|
| 1051 | EFI_STATUS
|
| 1052 | EFIAPI
|
| 1053 | ShellFindNextFile(
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 1054 | IN SHELL_FILE_HANDLE DirHandle,
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 1055 | OUT EFI_FILE_INFO *Buffer,
|
| 1056 | OUT BOOLEAN *NoFile
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 1057 | )
|
| 1058 | {
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 1059 | //
|
jcarsey | d2b4564 | 2009-05-11 18:02:16 +0000 | [diff] [blame] | 1060 | // pass to file handle lib
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 1061 | //
|
jcarsey | d2b4564 | 2009-05-11 18:02:16 +0000 | [diff] [blame] | 1062 | return (FileHandleFindNextFile(DirHandle, Buffer, NoFile));
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 1063 | }
|
| 1064 | /**
|
| 1065 | Retrieve the size of a file.
|
| 1066 |
|
| 1067 | if FileHandle is NULL then ASSERT()
|
| 1068 | if Size is NULL then ASSERT()
|
| 1069 |
|
jcarsey | 1e6e84c | 2010-01-25 20:05:08 +0000 | [diff] [blame] | 1070 | This function extracts the file size info from the FileHandle's EFI_FILE_INFO
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 1071 | data.
|
| 1072 |
|
| 1073 | @param FileHandle file handle from which size is retrieved
|
| 1074 | @param Size pointer to size
|
| 1075 |
|
| 1076 | @retval EFI_SUCCESS operation was completed sucessfully
|
| 1077 | @retval EFI_DEVICE_ERROR cannot access the file
|
| 1078 | **/
|
| 1079 | EFI_STATUS
|
| 1080 | EFIAPI
|
| 1081 | ShellGetFileSize (
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 1082 | IN SHELL_FILE_HANDLE FileHandle,
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 1083 | OUT UINT64 *Size
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 1084 | )
|
| 1085 | {
|
jcarsey | d2b4564 | 2009-05-11 18:02:16 +0000 | [diff] [blame] | 1086 | return (FileFunctionMap.GetFileSize(FileHandle, Size));
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 1087 | }
|
| 1088 | /**
|
| 1089 | Retrieves the status of the break execution flag
|
| 1090 |
|
| 1091 | this function is useful to check whether the application is being asked to halt by the shell.
|
| 1092 |
|
| 1093 | @retval TRUE the execution break is enabled
|
| 1094 | @retval FALSE the execution break is not enabled
|
| 1095 | **/
|
| 1096 | BOOLEAN
|
| 1097 | EFIAPI
|
| 1098 | ShellGetExecutionBreakFlag(
|
| 1099 | VOID
|
| 1100 | )
|
| 1101 | {
|
jcarsey | 1e6e84c | 2010-01-25 20:05:08 +0000 | [diff] [blame] | 1102 | //
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 1103 | // Check for UEFI Shell 2.0 protocols
|
| 1104 | //
|
jcarsey | 366f81a | 2011-06-27 21:04:22 +0000 | [diff] [blame] | 1105 | if (gEfiShellProtocol != NULL) {
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 1106 |
|
| 1107 | //
|
| 1108 | // We are using UEFI Shell 2.0; see if the event has been triggered
|
| 1109 | //
|
jcarsey | 366f81a | 2011-06-27 21:04:22 +0000 | [diff] [blame] | 1110 | if (gBS->CheckEvent(gEfiShellProtocol->ExecutionBreak) != EFI_SUCCESS) {
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 1111 | return (FALSE);
|
| 1112 | }
|
| 1113 | return (TRUE);
|
jcarsey | 1e6e84c | 2010-01-25 20:05:08 +0000 | [diff] [blame] | 1114 | }
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 1115 |
|
| 1116 | //
|
| 1117 | // using EFI Shell; call the function to check
|
| 1118 | //
|
jcarsey | 92a5447 | 2011-06-27 20:33:13 +0000 | [diff] [blame] | 1119 | if (mEfiShellEnvironment2 != NULL) {
|
| 1120 | return (mEfiShellEnvironment2->GetExecutionBreak());
|
| 1121 | }
|
| 1122 |
|
| 1123 | return (FALSE);
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 1124 | }
|
| 1125 | /**
|
| 1126 | return the value of an environment variable
|
| 1127 |
|
jcarsey | 1e6e84c | 2010-01-25 20:05:08 +0000 | [diff] [blame] | 1128 | this function gets the value of the environment variable set by the
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 1129 | ShellSetEnvironmentVariable function
|
| 1130 |
|
| 1131 | @param EnvKey The key name of the environment variable.
|
| 1132 |
|
| 1133 | @retval NULL the named environment variable does not exist.
|
| 1134 | @return != NULL pointer to the value of the environment variable
|
| 1135 | **/
|
| 1136 | CONST CHAR16*
|
| 1137 | EFIAPI
|
| 1138 | ShellGetEnvironmentVariable (
|
jcarsey | 9b3bf08 | 2009-06-23 21:15:07 +0000 | [diff] [blame] | 1139 | IN CONST CHAR16 *EnvKey
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 1140 | )
|
| 1141 | {
|
jcarsey | 1e6e84c | 2010-01-25 20:05:08 +0000 | [diff] [blame] | 1142 | //
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 1143 | // Check for UEFI Shell 2.0 protocols
|
| 1144 | //
|
jcarsey | 366f81a | 2011-06-27 21:04:22 +0000 | [diff] [blame] | 1145 | if (gEfiShellProtocol != NULL) {
|
| 1146 | return (gEfiShellProtocol->GetEnv(EnvKey));
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 1147 | }
|
| 1148 |
|
| 1149 | //
|
jcarsey | 92a5447 | 2011-06-27 20:33:13 +0000 | [diff] [blame] | 1150 | // Check for EFI shell
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 1151 | //
|
jcarsey | 92a5447 | 2011-06-27 20:33:13 +0000 | [diff] [blame] | 1152 | if (mEfiShellEnvironment2 != NULL) {
|
| 1153 | return (mEfiShellEnvironment2->GetEnv((CHAR16*)EnvKey));
|
| 1154 | }
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 1155 |
|
jcarsey | 92a5447 | 2011-06-27 20:33:13 +0000 | [diff] [blame] | 1156 | return NULL;
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 1157 | }
|
| 1158 | /**
|
| 1159 | set the value of an environment variable
|
| 1160 |
|
| 1161 | This function changes the current value of the specified environment variable. If the
|
| 1162 | environment variable exists and the Value is an empty string, then the environment
|
| 1163 | variable is deleted. If the environment variable exists and the Value is not an empty
|
| 1164 | string, then the value of the environment variable is changed. If the environment
|
| 1165 | variable does not exist and the Value is an empty string, there is no action. If the
|
| 1166 | environment variable does not exist and the Value is a non-empty string, then the
|
| 1167 | environment variable is created and assigned the specified value.
|
| 1168 |
|
| 1169 | This is not supported pre-UEFI Shell 2.0.
|
| 1170 |
|
| 1171 | @param EnvKey The key name of the environment variable.
|
| 1172 | @param EnvVal The Value of the environment variable
|
| 1173 | @param Volatile Indicates whether the variable is non-volatile (FALSE) or volatile (TRUE).
|
| 1174 |
|
| 1175 | @retval EFI_SUCCESS the operation was completed sucessfully
|
| 1176 | @retval EFI_UNSUPPORTED This operation is not allowed in pre UEFI 2.0 Shell environments
|
| 1177 | **/
|
| 1178 | EFI_STATUS
|
| 1179 | EFIAPI
|
| 1180 | ShellSetEnvironmentVariable (
|
| 1181 | IN CONST CHAR16 *EnvKey,
|
| 1182 | IN CONST CHAR16 *EnvVal,
|
| 1183 | IN BOOLEAN Volatile
|
| 1184 | )
|
| 1185 | {
|
jcarsey | 1e6e84c | 2010-01-25 20:05:08 +0000 | [diff] [blame] | 1186 | //
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 1187 | // Check for UEFI Shell 2.0 protocols
|
| 1188 | //
|
jcarsey | 366f81a | 2011-06-27 21:04:22 +0000 | [diff] [blame] | 1189 | if (gEfiShellProtocol != NULL) {
|
| 1190 | return (gEfiShellProtocol->SetEnv(EnvKey, EnvVal, Volatile));
|
jcarsey | 1e6e84c | 2010-01-25 20:05:08 +0000 | [diff] [blame] | 1191 | }
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 1192 |
|
| 1193 | //
|
| 1194 | // This feature does not exist under EFI shell
|
| 1195 | //
|
| 1196 | return (EFI_UNSUPPORTED);
|
| 1197 | }
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 1198 |
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 1199 | /**
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 1200 | Cause the shell to parse and execute a command line.
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 1201 |
|
| 1202 | This function creates a nested instance of the shell and executes the specified
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 1203 | command (CommandLine) with the specified environment (Environment). Upon return,
|
| 1204 | the status code returned by the specified command is placed in StatusCode.
|
| 1205 | If Environment is NULL, then the current environment is used and all changes made
|
| 1206 | by the commands executed will be reflected in the current environment. If the
|
| 1207 | Environment is non-NULL, then the changes made will be discarded.
|
| 1208 | The CommandLine is executed from the current working directory on the current
|
| 1209 | device.
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 1210 |
|
Brendan Jackman | 3877d0f | 2014-01-24 22:31:07 +0000 | [diff] [blame] | 1211 | The EnvironmentVariables pararemeter is ignored in a pre-UEFI Shell 2.0
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 1212 | environment. The values pointed to by the parameters will be unchanged by the
|
| 1213 | ShellExecute() function. The Output parameter has no effect in a
|
| 1214 | UEFI Shell 2.0 environment.
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 1215 |
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 1216 | @param[in] ParentHandle The parent image starting the operation.
|
| 1217 | @param[in] CommandLine The pointer to a NULL terminated command line.
|
| 1218 | @param[in] Output True to display debug output. False to hide it.
|
| 1219 | @param[in] EnvironmentVariables Optional pointer to array of environment variables
|
| 1220 | in the form "x=y". If NULL, the current set is used.
|
| 1221 | @param[out] Status The status of the run command line.
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 1222 |
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 1223 | @retval EFI_SUCCESS The operation completed sucessfully. Status
|
| 1224 | contains the status code returned.
|
| 1225 | @retval EFI_INVALID_PARAMETER A parameter contains an invalid value.
|
| 1226 | @retval EFI_OUT_OF_RESOURCES Out of resources.
|
| 1227 | @retval EFI_UNSUPPORTED The operation is not allowed.
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 1228 | **/
|
| 1229 | EFI_STATUS
|
| 1230 | EFIAPI
|
| 1231 | ShellExecute (
|
| 1232 | IN EFI_HANDLE *ParentHandle,
|
| 1233 | IN CHAR16 *CommandLine OPTIONAL,
|
| 1234 | IN BOOLEAN Output OPTIONAL,
|
| 1235 | IN CHAR16 **EnvironmentVariables OPTIONAL,
|
| 1236 | OUT EFI_STATUS *Status OPTIONAL
|
| 1237 | )
|
| 1238 | {
|
Brendan Jackman | 3877d0f | 2014-01-24 22:31:07 +0000 | [diff] [blame] | 1239 | EFI_STATUS CmdStatus;
|
jcarsey | 1e6e84c | 2010-01-25 20:05:08 +0000 | [diff] [blame] | 1240 | //
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 1241 | // Check for UEFI Shell 2.0 protocols
|
| 1242 | //
|
jcarsey | 366f81a | 2011-06-27 21:04:22 +0000 | [diff] [blame] | 1243 | if (gEfiShellProtocol != NULL) {
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 1244 | //
|
| 1245 | // Call UEFI Shell 2.0 version (not using Output parameter)
|
| 1246 | //
|
jcarsey | 366f81a | 2011-06-27 21:04:22 +0000 | [diff] [blame] | 1247 | return (gEfiShellProtocol->Execute(ParentHandle,
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 1248 | CommandLine,
|
| 1249 | EnvironmentVariables,
|
| 1250 | Status));
|
jcarsey | 1e6e84c | 2010-01-25 20:05:08 +0000 | [diff] [blame] | 1251 | }
|
jcarsey | 92a5447 | 2011-06-27 20:33:13 +0000 | [diff] [blame] | 1252 |
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 1253 | //
|
jcarsey | 92a5447 | 2011-06-27 20:33:13 +0000 | [diff] [blame] | 1254 | // Check for EFI shell
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 1255 | //
|
jcarsey | 92a5447 | 2011-06-27 20:33:13 +0000 | [diff] [blame] | 1256 | if (mEfiShellEnvironment2 != NULL) {
|
| 1257 | //
|
Brendan Jackman | 3877d0f | 2014-01-24 22:31:07 +0000 | [diff] [blame] | 1258 | // Call EFI Shell version.
|
jcarsey | 92a5447 | 2011-06-27 20:33:13 +0000 | [diff] [blame] | 1259 | // Due to oddity in the EFI shell we want to dereference the ParentHandle here
|
| 1260 | //
|
Brendan Jackman | 3877d0f | 2014-01-24 22:31:07 +0000 | [diff] [blame] | 1261 | CmdStatus = (mEfiShellEnvironment2->Execute(*ParentHandle,
|
jcarsey | 92a5447 | 2011-06-27 20:33:13 +0000 | [diff] [blame] | 1262 | CommandLine,
|
| 1263 | Output));
|
Brendan Jackman | 3877d0f | 2014-01-24 22:31:07 +0000 | [diff] [blame] | 1264 | //
|
| 1265 | // No Status output parameter so just use the returned status
|
| 1266 | //
|
| 1267 | if (Status != NULL) {
|
| 1268 | *Status = CmdStatus;
|
| 1269 | }
|
| 1270 | //
|
| 1271 | // If there was an error, we can't tell if it was from the command or from
|
| 1272 | // the Execute() function, so we'll just assume the shell ran successfully
|
| 1273 | // and the error came from the command.
|
| 1274 | //
|
| 1275 | return EFI_SUCCESS;
|
jcarsey | 92a5447 | 2011-06-27 20:33:13 +0000 | [diff] [blame] | 1276 | }
|
| 1277 |
|
| 1278 | return (EFI_UNSUPPORTED);
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 1279 | }
|
Brendan Jackman | 3877d0f | 2014-01-24 22:31:07 +0000 | [diff] [blame] | 1280 |
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 1281 | /**
|
| 1282 | Retreives the current directory path
|
| 1283 |
|
jcarsey | 1e6e84c | 2010-01-25 20:05:08 +0000 | [diff] [blame] | 1284 | If the DeviceName is NULL, it returns the current device's current directory
|
| 1285 | name. If the DeviceName is not NULL, it returns the current directory name
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 1286 | on specified drive.
|
| 1287 |
|
Qiu Shumin | fbd2dfa | 2015-10-23 02:03:20 +0000 | [diff] [blame] | 1288 | Note that the current directory string should exclude the tailing backslash character.
|
| 1289 |
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 1290 | @param DeviceName the name of the drive to get directory on
|
| 1291 |
|
| 1292 | @retval NULL the directory does not exist
|
| 1293 | @return != NULL the directory
|
| 1294 | **/
|
| 1295 | CONST CHAR16*
|
| 1296 | EFIAPI
|
| 1297 | ShellGetCurrentDir (
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 1298 | IN CHAR16 * CONST DeviceName OPTIONAL
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 1299 | )
|
| 1300 | {
|
jcarsey | 1e6e84c | 2010-01-25 20:05:08 +0000 | [diff] [blame] | 1301 | //
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 1302 | // Check for UEFI Shell 2.0 protocols
|
| 1303 | //
|
jcarsey | 366f81a | 2011-06-27 21:04:22 +0000 | [diff] [blame] | 1304 | if (gEfiShellProtocol != NULL) {
|
| 1305 | return (gEfiShellProtocol->GetCurDir(DeviceName));
|
jcarsey | 1e6e84c | 2010-01-25 20:05:08 +0000 | [diff] [blame] | 1306 | }
|
jcarsey | 92a5447 | 2011-06-27 20:33:13 +0000 | [diff] [blame] | 1307 |
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 1308 | //
|
jcarsey | 8bd282b | 2011-06-27 16:45:41 +0000 | [diff] [blame] | 1309 | // Check for EFI shell
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 1310 | //
|
jcarsey | 8bd282b | 2011-06-27 16:45:41 +0000 | [diff] [blame] | 1311 | if (mEfiShellEnvironment2 != NULL) {
|
| 1312 | return (mEfiShellEnvironment2->CurDir(DeviceName));
|
| 1313 | }
|
| 1314 |
|
| 1315 | return (NULL);
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 1316 | }
|
| 1317 | /**
|
| 1318 | sets (enabled or disabled) the page break mode
|
| 1319 |
|
jcarsey | 1e6e84c | 2010-01-25 20:05:08 +0000 | [diff] [blame] | 1320 | when page break mode is enabled the screen will stop scrolling
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 1321 | and wait for operator input before scrolling a subsequent screen.
|
| 1322 |
|
| 1323 | @param CurrentState TRUE to enable and FALSE to disable
|
| 1324 | **/
|
jcarsey | 1e6e84c | 2010-01-25 20:05:08 +0000 | [diff] [blame] | 1325 | VOID
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 1326 | EFIAPI
|
| 1327 | ShellSetPageBreakMode (
|
| 1328 | IN BOOLEAN CurrentState
|
| 1329 | )
|
| 1330 | {
|
| 1331 | //
|
| 1332 | // check for enabling
|
| 1333 | //
|
| 1334 | if (CurrentState != 0x00) {
|
jcarsey | 1e6e84c | 2010-01-25 20:05:08 +0000 | [diff] [blame] | 1335 | //
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 1336 | // check for UEFI Shell 2.0
|
| 1337 | //
|
jcarsey | 366f81a | 2011-06-27 21:04:22 +0000 | [diff] [blame] | 1338 | if (gEfiShellProtocol != NULL) {
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 1339 | //
|
| 1340 | // Enable with UEFI 2.0 Shell
|
| 1341 | //
|
jcarsey | 366f81a | 2011-06-27 21:04:22 +0000 | [diff] [blame] | 1342 | gEfiShellProtocol->EnablePageBreak();
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 1343 | return;
|
| 1344 | } else {
|
jcarsey | 1e6e84c | 2010-01-25 20:05:08 +0000 | [diff] [blame] | 1345 | //
|
jcarsey | 92a5447 | 2011-06-27 20:33:13 +0000 | [diff] [blame] | 1346 | // Check for EFI shell
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 1347 | //
|
jcarsey | 92a5447 | 2011-06-27 20:33:13 +0000 | [diff] [blame] | 1348 | if (mEfiShellEnvironment2 != NULL) {
|
| 1349 | //
|
| 1350 | // Enable with EFI Shell
|
| 1351 | //
|
| 1352 | mEfiShellEnvironment2->EnablePageBreak (DEFAULT_INIT_ROW, DEFAULT_AUTO_LF);
|
| 1353 | return;
|
| 1354 | }
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 1355 | }
|
| 1356 | } else {
|
jcarsey | 1e6e84c | 2010-01-25 20:05:08 +0000 | [diff] [blame] | 1357 | //
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 1358 | // check for UEFI Shell 2.0
|
| 1359 | //
|
jcarsey | 366f81a | 2011-06-27 21:04:22 +0000 | [diff] [blame] | 1360 | if (gEfiShellProtocol != NULL) {
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 1361 | //
|
| 1362 | // Disable with UEFI 2.0 Shell
|
| 1363 | //
|
jcarsey | 366f81a | 2011-06-27 21:04:22 +0000 | [diff] [blame] | 1364 | gEfiShellProtocol->DisablePageBreak();
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 1365 | return;
|
| 1366 | } else {
|
jcarsey | 1e6e84c | 2010-01-25 20:05:08 +0000 | [diff] [blame] | 1367 | //
|
jcarsey | 92a5447 | 2011-06-27 20:33:13 +0000 | [diff] [blame] | 1368 | // Check for EFI shell
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 1369 | //
|
jcarsey | 92a5447 | 2011-06-27 20:33:13 +0000 | [diff] [blame] | 1370 | if (mEfiShellEnvironment2 != NULL) {
|
| 1371 | //
|
| 1372 | // Disable with EFI Shell
|
| 1373 | //
|
| 1374 | mEfiShellEnvironment2->DisablePageBreak ();
|
| 1375 | return;
|
| 1376 | }
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 1377 | }
|
| 1378 | }
|
| 1379 | }
|
| 1380 |
|
| 1381 | ///
|
| 1382 | /// version of EFI_SHELL_FILE_INFO struct, except has no CONST pointers.
|
| 1383 | /// This allows for the struct to be populated.
|
| 1384 | ///
|
| 1385 | typedef struct {
|
jcarsey | d2b4564 | 2009-05-11 18:02:16 +0000 | [diff] [blame] | 1386 | LIST_ENTRY Link;
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 1387 | EFI_STATUS Status;
|
| 1388 | CHAR16 *FullName;
|
| 1389 | CHAR16 *FileName;
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 1390 | SHELL_FILE_HANDLE Handle;
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 1391 | EFI_FILE_INFO *Info;
|
| 1392 | } EFI_SHELL_FILE_INFO_NO_CONST;
|
| 1393 |
|
| 1394 | /**
|
| 1395 | Converts a EFI shell list of structures to the coresponding UEFI Shell 2.0 type of list.
|
| 1396 |
|
| 1397 | if OldStyleFileList is NULL then ASSERT()
|
| 1398 |
|
jcarsey | 1e6e84c | 2010-01-25 20:05:08 +0000 | [diff] [blame] | 1399 | this function will convert a SHELL_FILE_ARG based list into a callee allocated
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 1400 | EFI_SHELL_FILE_INFO based list. it is up to the caller to free the memory via
|
| 1401 | the ShellCloseFileMetaArg function.
|
| 1402 |
|
ydong10 | 4ff7e37 | 2011-09-02 08:05:34 +0000 | [diff] [blame] | 1403 | @param[in] FileList the EFI shell list type
|
| 1404 | @param[in, out] ListHead the list to add to
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 1405 |
|
| 1406 | @retval the resultant head of the double linked new format list;
|
| 1407 | **/
|
| 1408 | LIST_ENTRY*
|
| 1409 | EFIAPI
|
| 1410 | InternalShellConvertFileListType (
|
jcarsey | 9b3bf08 | 2009-06-23 21:15:07 +0000 | [diff] [blame] | 1411 | IN LIST_ENTRY *FileList,
|
| 1412 | IN OUT LIST_ENTRY *ListHead
|
jcarsey | 125c2cf | 2009-11-18 21:36:50 +0000 | [diff] [blame] | 1413 | )
|
| 1414 | {
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 1415 | SHELL_FILE_ARG *OldInfo;
|
jcarsey | 9b3bf08 | 2009-06-23 21:15:07 +0000 | [diff] [blame] | 1416 | LIST_ENTRY *Link;
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 1417 | EFI_SHELL_FILE_INFO_NO_CONST *NewInfo;
|
| 1418 |
|
| 1419 | //
|
jcarsey | 9b3bf08 | 2009-06-23 21:15:07 +0000 | [diff] [blame] | 1420 | // ASSERTs
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 1421 | //
|
jcarsey | 9b3bf08 | 2009-06-23 21:15:07 +0000 | [diff] [blame] | 1422 | ASSERT(FileList != NULL);
|
| 1423 | ASSERT(ListHead != NULL);
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 1424 |
|
| 1425 | //
|
| 1426 | // enumerate through each member of the old list and copy
|
| 1427 | //
|
jcarsey | d2b4564 | 2009-05-11 18:02:16 +0000 | [diff] [blame] | 1428 | for (Link = FileList->ForwardLink; Link != FileList; Link = Link->ForwardLink) {
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 1429 | OldInfo = CR (Link, SHELL_FILE_ARG, Link, SHELL_FILE_ARG_SIGNATURE);
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 1430 | ASSERT(OldInfo != NULL);
|
| 1431 |
|
| 1432 | //
|
| 1433 | // Skip ones that failed to open...
|
| 1434 | //
|
| 1435 | if (OldInfo->Status != EFI_SUCCESS) {
|
| 1436 | continue;
|
| 1437 | }
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 1438 |
|
| 1439 | //
|
| 1440 | // make sure the old list was valid
|
| 1441 | //
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 1442 | ASSERT(OldInfo->Info != NULL);
|
| 1443 | ASSERT(OldInfo->FullName != NULL);
|
| 1444 | ASSERT(OldInfo->FileName != NULL);
|
| 1445 |
|
| 1446 | //
|
| 1447 | // allocate a new EFI_SHELL_FILE_INFO object
|
| 1448 | //
|
| 1449 | NewInfo = AllocateZeroPool(sizeof(EFI_SHELL_FILE_INFO));
|
jcarsey | c9d92df | 2010-02-03 15:37:54 +0000 | [diff] [blame] | 1450 | if (NewInfo == NULL) {
|
jcarsey | 7a95efd | 2011-10-13 16:08:18 +0000 | [diff] [blame] | 1451 | ShellCloseFileMetaArg((EFI_SHELL_FILE_INFO**)(&ListHead));
|
jcarsey | beab0fc | 2011-10-10 17:26:25 +0000 | [diff] [blame] | 1452 | ListHead = NULL;
|
jcarsey | c9d92df | 2010-02-03 15:37:54 +0000 | [diff] [blame] | 1453 | break;
|
| 1454 | }
|
jcarsey | 1e6e84c | 2010-01-25 20:05:08 +0000 | [diff] [blame] | 1455 |
|
| 1456 | //
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 1457 | // copy the simple items
|
| 1458 | //
|
| 1459 | NewInfo->Handle = OldInfo->Handle;
|
| 1460 | NewInfo->Status = OldInfo->Status;
|
| 1461 |
|
jcarsey | d2b4564 | 2009-05-11 18:02:16 +0000 | [diff] [blame] | 1462 | // old shell checks for 0 not NULL
|
| 1463 | OldInfo->Handle = 0;
|
| 1464 |
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 1465 | //
|
| 1466 | // allocate new space to copy strings and structure
|
| 1467 | //
|
Jaben Carsey | 98c16be | 2014-08-19 21:00:34 +0000 | [diff] [blame] | 1468 | NewInfo->FullName = AllocateCopyPool(StrSize(OldInfo->FullName), OldInfo->FullName);
|
| 1469 | NewInfo->FileName = AllocateCopyPool(StrSize(OldInfo->FileName), OldInfo->FileName);
|
| 1470 | NewInfo->Info = AllocateCopyPool((UINTN)OldInfo->Info->Size, OldInfo->Info);
|
jcarsey | 1e6e84c | 2010-01-25 20:05:08 +0000 | [diff] [blame] | 1471 |
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 1472 | //
|
| 1473 | // make sure all the memory allocations were sucessful
|
| 1474 | //
|
jcarsey | beab0fc | 2011-10-10 17:26:25 +0000 | [diff] [blame] | 1475 | if (NULL == NewInfo->FullName || NewInfo->FileName == NULL || NewInfo->Info == NULL) {
|
Jaben Carsey | 98c16be | 2014-08-19 21:00:34 +0000 | [diff] [blame] | 1476 | //
|
| 1477 | // Free the partially allocated new node
|
| 1478 | //
|
| 1479 | SHELL_FREE_NON_NULL(NewInfo->FullName);
|
| 1480 | SHELL_FREE_NON_NULL(NewInfo->FileName);
|
| 1481 | SHELL_FREE_NON_NULL(NewInfo->Info);
|
| 1482 | SHELL_FREE_NON_NULL(NewInfo);
|
| 1483 |
|
| 1484 | //
|
| 1485 | // Free the previously converted stuff
|
| 1486 | //
|
jcarsey | 7a95efd | 2011-10-13 16:08:18 +0000 | [diff] [blame] | 1487 | ShellCloseFileMetaArg((EFI_SHELL_FILE_INFO**)(&ListHead));
|
jcarsey | beab0fc | 2011-10-10 17:26:25 +0000 | [diff] [blame] | 1488 | ListHead = NULL;
|
| 1489 | break;
|
| 1490 | }
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 1491 |
|
| 1492 | //
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 1493 | // add that to the list
|
| 1494 | //
|
jcarsey | 9b3bf08 | 2009-06-23 21:15:07 +0000 | [diff] [blame] | 1495 | InsertTailList(ListHead, &NewInfo->Link);
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 1496 | }
|
| 1497 | return (ListHead);
|
| 1498 | }
|
| 1499 | /**
|
| 1500 | Opens a group of files based on a path.
|
| 1501 |
|
jcarsey | 1e6e84c | 2010-01-25 20:05:08 +0000 | [diff] [blame] | 1502 | This function uses the Arg to open all the matching files. Each matched
|
Brendan Jackman | 7087931 | 2014-01-24 22:29:53 +0000 | [diff] [blame] | 1503 | file has a SHELL_FILE_INFO structure to record the file information. These
|
| 1504 | structures are placed on the list ListHead. Users can get the SHELL_FILE_INFO
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 1505 | structures from ListHead to access each file. This function supports wildcards
|
jcarsey | 1e6e84c | 2010-01-25 20:05:08 +0000 | [diff] [blame] | 1506 | and will process '?' and '*' as such. the list must be freed with a call to
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 1507 | ShellCloseFileMetaArg().
|
| 1508 |
|
jcarsey | 1e6e84c | 2010-01-25 20:05:08 +0000 | [diff] [blame] | 1509 | If you are NOT appending to an existing list *ListHead must be NULL. If
|
jcarsey | 5f7431d | 2009-07-10 18:06:01 +0000 | [diff] [blame] | 1510 | *ListHead is NULL then it must be callee freed.
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 1511 |
|
| 1512 | @param Arg pointer to path string
|
| 1513 | @param OpenMode mode to open files with
|
| 1514 | @param ListHead head of linked list of results
|
| 1515 |
|
jcarsey | 1e6e84c | 2010-01-25 20:05:08 +0000 | [diff] [blame] | 1516 | @retval EFI_SUCCESS the operation was sucessful and the list head
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 1517 | contains the list of opened files
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 1518 | @return != EFI_SUCCESS the operation failed
|
| 1519 |
|
| 1520 | @sa InternalShellConvertFileListType
|
| 1521 | **/
|
| 1522 | EFI_STATUS
|
| 1523 | EFIAPI
|
| 1524 | ShellOpenFileMetaArg (
|
| 1525 | IN CHAR16 *Arg,
|
| 1526 | IN UINT64 OpenMode,
|
| 1527 | IN OUT EFI_SHELL_FILE_INFO **ListHead
|
| 1528 | )
|
| 1529 | {
|
| 1530 | EFI_STATUS Status;
|
jcarsey | 9b3bf08 | 2009-06-23 21:15:07 +0000 | [diff] [blame] | 1531 | LIST_ENTRY mOldStyleFileList;
|
Qiu Shumin | 0960ba1 | 2014-09-17 07:58:31 +0000 | [diff] [blame] | 1532 | CHAR16 *CleanFilePathStr;
|
jcarsey | 1e6e84c | 2010-01-25 20:05:08 +0000 | [diff] [blame] | 1533 |
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 1534 | //
|
| 1535 | // ASSERT that Arg and ListHead are not NULL
|
| 1536 | //
|
| 1537 | ASSERT(Arg != NULL);
|
| 1538 | ASSERT(ListHead != NULL);
|
| 1539 |
|
Qiu Shumin | 715096c | 2014-09-19 01:32:05 +0000 | [diff] [blame] | 1540 | CleanFilePathStr = NULL;
|
| 1541 |
|
Qiu Shumin | 0960ba1 | 2014-09-17 07:58:31 +0000 | [diff] [blame] | 1542 | Status = InternalShellStripQuotes (Arg, &CleanFilePathStr);
|
| 1543 | if (EFI_ERROR (Status)) {
|
| 1544 | return Status;
|
| 1545 | }
|
| 1546 |
|
jcarsey | 1e6e84c | 2010-01-25 20:05:08 +0000 | [diff] [blame] | 1547 | //
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 1548 | // Check for UEFI Shell 2.0 protocols
|
| 1549 | //
|
jcarsey | 366f81a | 2011-06-27 21:04:22 +0000 | [diff] [blame] | 1550 | if (gEfiShellProtocol != NULL) {
|
jcarsey | 5f7431d | 2009-07-10 18:06:01 +0000 | [diff] [blame] | 1551 | if (*ListHead == NULL) {
|
| 1552 | *ListHead = (EFI_SHELL_FILE_INFO*)AllocateZeroPool(sizeof(EFI_SHELL_FILE_INFO));
|
| 1553 | if (*ListHead == NULL) {
|
Qiu Shumin | 0960ba1 | 2014-09-17 07:58:31 +0000 | [diff] [blame] | 1554 | FreePool(CleanFilePathStr);
|
jcarsey | 5f7431d | 2009-07-10 18:06:01 +0000 | [diff] [blame] | 1555 | return (EFI_OUT_OF_RESOURCES);
|
| 1556 | }
|
| 1557 | InitializeListHead(&((*ListHead)->Link));
|
jcarsey | 1e6e84c | 2010-01-25 20:05:08 +0000 | [diff] [blame] | 1558 | }
|
Qiu Shumin | 0960ba1 | 2014-09-17 07:58:31 +0000 | [diff] [blame] | 1559 | Status = gEfiShellProtocol->OpenFileList(CleanFilePathStr,
|
jcarsey | 1e6e84c | 2010-01-25 20:05:08 +0000 | [diff] [blame] | 1560 | OpenMode,
|
jcarsey | 2247dde | 2009-11-09 18:08:58 +0000 | [diff] [blame] | 1561 | ListHead);
|
| 1562 | if (EFI_ERROR(Status)) {
|
jcarsey | 366f81a | 2011-06-27 21:04:22 +0000 | [diff] [blame] | 1563 | gEfiShellProtocol->RemoveDupInFileList(ListHead);
|
jcarsey | 2247dde | 2009-11-09 18:08:58 +0000 | [diff] [blame] | 1564 | } else {
|
jcarsey | 366f81a | 2011-06-27 21:04:22 +0000 | [diff] [blame] | 1565 | Status = gEfiShellProtocol->RemoveDupInFileList(ListHead);
|
jcarsey | 2247dde | 2009-11-09 18:08:58 +0000 | [diff] [blame] | 1566 | }
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 1567 | if (*ListHead != NULL && IsListEmpty(&(*ListHead)->Link)) {
|
| 1568 | FreePool(*ListHead);
|
Qiu Shumin | 0960ba1 | 2014-09-17 07:58:31 +0000 | [diff] [blame] | 1569 | FreePool(CleanFilePathStr);
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 1570 | *ListHead = NULL;
|
| 1571 | return (EFI_NOT_FOUND);
|
| 1572 | }
|
Qiu Shumin | 0960ba1 | 2014-09-17 07:58:31 +0000 | [diff] [blame] | 1573 | FreePool(CleanFilePathStr);
|
jcarsey | 2247dde | 2009-11-09 18:08:58 +0000 | [diff] [blame] | 1574 | return (Status);
|
jcarsey | 1e6e84c | 2010-01-25 20:05:08 +0000 | [diff] [blame] | 1575 | }
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 1576 |
|
| 1577 | //
|
jcarsey | 92a5447 | 2011-06-27 20:33:13 +0000 | [diff] [blame] | 1578 | // Check for EFI shell
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 1579 | //
|
jcarsey | 92a5447 | 2011-06-27 20:33:13 +0000 | [diff] [blame] | 1580 | if (mEfiShellEnvironment2 != NULL) {
|
| 1581 | //
|
| 1582 | // make sure the list head is initialized
|
| 1583 | //
|
| 1584 | InitializeListHead(&mOldStyleFileList);
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 1585 |
|
jcarsey | 92a5447 | 2011-06-27 20:33:13 +0000 | [diff] [blame] | 1586 | //
|
| 1587 | // Get the EFI Shell list of files
|
| 1588 | //
|
Qiu Shumin | 0960ba1 | 2014-09-17 07:58:31 +0000 | [diff] [blame] | 1589 | Status = mEfiShellEnvironment2->FileMetaArg(CleanFilePathStr, &mOldStyleFileList);
|
jcarsey | 92a5447 | 2011-06-27 20:33:13 +0000 | [diff] [blame] | 1590 | if (EFI_ERROR(Status)) {
|
| 1591 | *ListHead = NULL;
|
Qiu Shumin | 0960ba1 | 2014-09-17 07:58:31 +0000 | [diff] [blame] | 1592 | FreePool(CleanFilePathStr);
|
jcarsey | 92a5447 | 2011-06-27 20:33:13 +0000 | [diff] [blame] | 1593 | return (Status);
|
| 1594 | }
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 1595 |
|
jcarsey | 92a5447 | 2011-06-27 20:33:13 +0000 | [diff] [blame] | 1596 | if (*ListHead == NULL) {
|
| 1597 | *ListHead = (EFI_SHELL_FILE_INFO *)AllocateZeroPool(sizeof(EFI_SHELL_FILE_INFO));
|
| 1598 | if (*ListHead == NULL) {
|
Qiu Shumin | 0960ba1 | 2014-09-17 07:58:31 +0000 | [diff] [blame] | 1599 | FreePool(CleanFilePathStr);
|
jcarsey | 92a5447 | 2011-06-27 20:33:13 +0000 | [diff] [blame] | 1600 | return (EFI_OUT_OF_RESOURCES);
|
| 1601 | }
|
| 1602 | InitializeListHead(&((*ListHead)->Link));
|
| 1603 | }
|
| 1604 |
|
| 1605 | //
|
| 1606 | // Convert that to equivalent of UEFI Shell 2.0 structure
|
| 1607 | //
|
| 1608 | InternalShellConvertFileListType(&mOldStyleFileList, &(*ListHead)->Link);
|
| 1609 |
|
| 1610 | //
|
| 1611 | // Free the EFI Shell version that was converted.
|
| 1612 | //
|
| 1613 | mEfiShellEnvironment2->FreeFileList(&mOldStyleFileList);
|
| 1614 |
|
| 1615 | if ((*ListHead)->Link.ForwardLink == (*ListHead)->Link.BackLink && (*ListHead)->Link.BackLink == &((*ListHead)->Link)) {
|
| 1616 | FreePool(*ListHead);
|
| 1617 | *ListHead = NULL;
|
| 1618 | Status = EFI_NOT_FOUND;
|
| 1619 | }
|
Qiu Shumin | 0960ba1 | 2014-09-17 07:58:31 +0000 | [diff] [blame] | 1620 | FreePool(CleanFilePathStr);
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 1621 | return (Status);
|
| 1622 | }
|
| 1623 |
|
Qiu Shumin | 0960ba1 | 2014-09-17 07:58:31 +0000 | [diff] [blame] | 1624 | FreePool(CleanFilePathStr);
|
jcarsey | 92a5447 | 2011-06-27 20:33:13 +0000 | [diff] [blame] | 1625 | return (EFI_UNSUPPORTED);
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 1626 | }
|
| 1627 | /**
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 1628 | Free the linked list returned from ShellOpenFileMetaArg.
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 1629 |
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 1630 | if ListHead is NULL then ASSERT().
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 1631 |
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 1632 | @param ListHead the pointer to free.
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 1633 |
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 1634 | @retval EFI_SUCCESS the operation was sucessful.
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 1635 | **/
|
| 1636 | EFI_STATUS
|
| 1637 | EFIAPI
|
| 1638 | ShellCloseFileMetaArg (
|
| 1639 | IN OUT EFI_SHELL_FILE_INFO **ListHead
|
| 1640 | )
|
| 1641 | {
|
| 1642 | LIST_ENTRY *Node;
|
| 1643 |
|
| 1644 | //
|
| 1645 | // ASSERT that ListHead is not NULL
|
| 1646 | //
|
| 1647 | ASSERT(ListHead != NULL);
|
| 1648 |
|
jcarsey | 1e6e84c | 2010-01-25 20:05:08 +0000 | [diff] [blame] | 1649 | //
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 1650 | // Check for UEFI Shell 2.0 protocols
|
| 1651 | //
|
jcarsey | 366f81a | 2011-06-27 21:04:22 +0000 | [diff] [blame] | 1652 | if (gEfiShellProtocol != NULL) {
|
| 1653 | return (gEfiShellProtocol->FreeFileList(ListHead));
|
jcarsey | 92a5447 | 2011-06-27 20:33:13 +0000 | [diff] [blame] | 1654 | } else if (mEfiShellEnvironment2 != NULL) {
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 1655 | //
|
jcarsey | 1e6e84c | 2010-01-25 20:05:08 +0000 | [diff] [blame] | 1656 | // Since this is EFI Shell version we need to free our internally made copy
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 1657 | // of the list
|
| 1658 | //
|
jcarsey | 1e6e84c | 2010-01-25 20:05:08 +0000 | [diff] [blame] | 1659 | for ( Node = GetFirstNode(&(*ListHead)->Link)
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 1660 | ; *ListHead != NULL && !IsListEmpty(&(*ListHead)->Link)
|
jcarsey | 9b3bf08 | 2009-06-23 21:15:07 +0000 | [diff] [blame] | 1661 | ; Node = GetFirstNode(&(*ListHead)->Link)) {
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 1662 | RemoveEntryList(Node);
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 1663 | ((EFI_FILE_PROTOCOL*)((EFI_SHELL_FILE_INFO_NO_CONST*)Node)->Handle)->Close(((EFI_SHELL_FILE_INFO_NO_CONST*)Node)->Handle);
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 1664 | FreePool(((EFI_SHELL_FILE_INFO_NO_CONST*)Node)->FullName);
|
| 1665 | FreePool(((EFI_SHELL_FILE_INFO_NO_CONST*)Node)->FileName);
|
| 1666 | FreePool(((EFI_SHELL_FILE_INFO_NO_CONST*)Node)->Info);
|
| 1667 | FreePool((EFI_SHELL_FILE_INFO_NO_CONST*)Node);
|
| 1668 | }
|
Jaben Carsey | 75a5e2e | 2014-01-10 16:42:45 +0000 | [diff] [blame] | 1669 | SHELL_FREE_NON_NULL(*ListHead);
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 1670 | return EFI_SUCCESS;
|
| 1671 | }
|
jcarsey | 92a5447 | 2011-06-27 20:33:13 +0000 | [diff] [blame] | 1672 |
|
| 1673 | return (EFI_UNSUPPORTED);
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 1674 | }
|
| 1675 |
|
jcarsey | 125c2cf | 2009-11-18 21:36:50 +0000 | [diff] [blame] | 1676 | /**
|
| 1677 | Find a file by searching the CWD and then the path.
|
| 1678 |
|
jcarsey | b3011f4 | 2010-01-11 21:49:04 +0000 | [diff] [blame] | 1679 | If FileName is NULL then ASSERT.
|
jcarsey | 125c2cf | 2009-11-18 21:36:50 +0000 | [diff] [blame] | 1680 |
|
jcarsey | b3011f4 | 2010-01-11 21:49:04 +0000 | [diff] [blame] | 1681 | If the return value is not NULL then the memory must be caller freed.
|
jcarsey | 125c2cf | 2009-11-18 21:36:50 +0000 | [diff] [blame] | 1682 |
|
| 1683 | @param FileName Filename string.
|
| 1684 |
|
| 1685 | @retval NULL the file was not found
|
| 1686 | @return !NULL the full path to the file.
|
| 1687 | **/
|
| 1688 | CHAR16 *
|
| 1689 | EFIAPI
|
| 1690 | ShellFindFilePath (
|
| 1691 | IN CONST CHAR16 *FileName
|
| 1692 | )
|
| 1693 | {
|
| 1694 | CONST CHAR16 *Path;
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 1695 | SHELL_FILE_HANDLE Handle;
|
jcarsey | 125c2cf | 2009-11-18 21:36:50 +0000 | [diff] [blame] | 1696 | EFI_STATUS Status;
|
| 1697 | CHAR16 *RetVal;
|
| 1698 | CHAR16 *TestPath;
|
| 1699 | CONST CHAR16 *Walker;
|
jcarsey | 36a9d67 | 2009-11-20 21:13:41 +0000 | [diff] [blame] | 1700 | UINTN Size;
|
jcarsey | 1cd45e7 | 2010-01-29 15:07:44 +0000 | [diff] [blame] | 1701 | CHAR16 *TempChar;
|
jcarsey | 125c2cf | 2009-11-18 21:36:50 +0000 | [diff] [blame] | 1702 |
|
| 1703 | RetVal = NULL;
|
| 1704 |
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 1705 | //
|
| 1706 | // First make sure its not an absolute path.
|
| 1707 | //
|
| 1708 | Status = ShellOpenFileByName(FileName, &Handle, EFI_FILE_MODE_READ, 0);
|
| 1709 | if (!EFI_ERROR(Status)){
|
| 1710 | if (FileHandleIsDirectory(Handle) != EFI_SUCCESS) {
|
| 1711 | ASSERT(RetVal == NULL);
|
| 1712 | RetVal = StrnCatGrow(&RetVal, NULL, FileName, 0);
|
| 1713 | ShellCloseFile(&Handle);
|
| 1714 | return (RetVal);
|
| 1715 | } else {
|
| 1716 | ShellCloseFile(&Handle);
|
| 1717 | }
|
| 1718 | }
|
| 1719 |
|
jcarsey | 125c2cf | 2009-11-18 21:36:50 +0000 | [diff] [blame] | 1720 | Path = ShellGetEnvironmentVariable(L"cwd");
|
| 1721 | if (Path != NULL) {
|
Qiu Shumin | fbd2dfa | 2015-10-23 02:03:20 +0000 | [diff] [blame] | 1722 | Size = StrSize(Path) + sizeof(CHAR16);
|
jcarsey | 36a9d67 | 2009-11-20 21:13:41 +0000 | [diff] [blame] | 1723 | Size += StrSize(FileName);
|
| 1724 | TestPath = AllocateZeroPool(Size);
|
jcarsey | c9d92df | 2010-02-03 15:37:54 +0000 | [diff] [blame] | 1725 | if (TestPath == NULL) {
|
| 1726 | return (NULL);
|
| 1727 | }
|
Qiu Shumin | e75390f | 2015-06-30 03:18:31 +0000 | [diff] [blame] | 1728 | StrCpyS(TestPath, Size/sizeof(CHAR16), Path);
|
Qiu Shumin | fbd2dfa | 2015-10-23 02:03:20 +0000 | [diff] [blame] | 1729 | StrCatS(TestPath, Size/sizeof(CHAR16), L"\\");
|
Qiu Shumin | e75390f | 2015-06-30 03:18:31 +0000 | [diff] [blame] | 1730 | StrCatS(TestPath, Size/sizeof(CHAR16), FileName);
|
jcarsey | 125c2cf | 2009-11-18 21:36:50 +0000 | [diff] [blame] | 1731 | Status = ShellOpenFileByName(TestPath, &Handle, EFI_FILE_MODE_READ, 0);
|
| 1732 | if (!EFI_ERROR(Status)){
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 1733 | if (FileHandleIsDirectory(Handle) != EFI_SUCCESS) {
|
| 1734 | ASSERT(RetVal == NULL);
|
| 1735 | RetVal = StrnCatGrow(&RetVal, NULL, TestPath, 0);
|
| 1736 | ShellCloseFile(&Handle);
|
| 1737 | FreePool(TestPath);
|
| 1738 | return (RetVal);
|
| 1739 | } else {
|
| 1740 | ShellCloseFile(&Handle);
|
| 1741 | }
|
jcarsey | 125c2cf | 2009-11-18 21:36:50 +0000 | [diff] [blame] | 1742 | }
|
| 1743 | FreePool(TestPath);
|
| 1744 | }
|
| 1745 | Path = ShellGetEnvironmentVariable(L"path");
|
| 1746 | if (Path != NULL) {
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 1747 | Size = StrSize(Path)+sizeof(CHAR16);
|
jcarsey | 36a9d67 | 2009-11-20 21:13:41 +0000 | [diff] [blame] | 1748 | Size += StrSize(FileName);
|
| 1749 | TestPath = AllocateZeroPool(Size);
|
jcarsey | 3e082d5 | 2010-10-04 16:44:57 +0000 | [diff] [blame] | 1750 | if (TestPath == NULL) {
|
| 1751 | return (NULL);
|
| 1752 | }
|
jcarsey | 1e6e84c | 2010-01-25 20:05:08 +0000 | [diff] [blame] | 1753 | Walker = (CHAR16*)Path;
|
jcarsey | 125c2cf | 2009-11-18 21:36:50 +0000 | [diff] [blame] | 1754 | do {
|
| 1755 | CopyMem(TestPath, Walker, StrSize(Walker));
|
jcarsey | 3e082d5 | 2010-10-04 16:44:57 +0000 | [diff] [blame] | 1756 | if (TestPath != NULL) {
|
| 1757 | TempChar = StrStr(TestPath, L";");
|
| 1758 | if (TempChar != NULL) {
|
| 1759 | *TempChar = CHAR_NULL;
|
| 1760 | }
|
| 1761 | if (TestPath[StrLen(TestPath)-1] != L'\\') {
|
Qiu Shumin | e75390f | 2015-06-30 03:18:31 +0000 | [diff] [blame] | 1762 | StrCatS(TestPath, Size/sizeof(CHAR16), L"\\");
|
jcarsey | 3e082d5 | 2010-10-04 16:44:57 +0000 | [diff] [blame] | 1763 | }
|
jcarsey | 89e8537 | 2011-04-13 23:37:50 +0000 | [diff] [blame] | 1764 | if (FileName[0] == L'\\') {
|
| 1765 | FileName++;
|
| 1766 | }
|
Qiu Shumin | e75390f | 2015-06-30 03:18:31 +0000 | [diff] [blame] | 1767 | StrCatS(TestPath, Size/sizeof(CHAR16), FileName);
|
jcarsey | 3e082d5 | 2010-10-04 16:44:57 +0000 | [diff] [blame] | 1768 | if (StrStr(Walker, L";") != NULL) {
|
| 1769 | Walker = StrStr(Walker, L";") + 1;
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 1770 | } else {
|
jcarsey | 3e082d5 | 2010-10-04 16:44:57 +0000 | [diff] [blame] | 1771 | Walker = NULL;
|
| 1772 | }
|
| 1773 | Status = ShellOpenFileByName(TestPath, &Handle, EFI_FILE_MODE_READ, 0);
|
| 1774 | if (!EFI_ERROR(Status)){
|
| 1775 | if (FileHandleIsDirectory(Handle) != EFI_SUCCESS) {
|
| 1776 | ASSERT(RetVal == NULL);
|
| 1777 | RetVal = StrnCatGrow(&RetVal, NULL, TestPath, 0);
|
| 1778 | ShellCloseFile(&Handle);
|
| 1779 | break;
|
| 1780 | } else {
|
| 1781 | ShellCloseFile(&Handle);
|
| 1782 | }
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 1783 | }
|
jcarsey | 125c2cf | 2009-11-18 21:36:50 +0000 | [diff] [blame] | 1784 | }
|
| 1785 | } while (Walker != NULL && Walker[0] != CHAR_NULL);
|
| 1786 | FreePool(TestPath);
|
| 1787 | }
|
| 1788 | return (RetVal);
|
| 1789 | }
|
| 1790 |
|
jcarsey | b3011f4 | 2010-01-11 21:49:04 +0000 | [diff] [blame] | 1791 | /**
|
jcarsey | 1e6e84c | 2010-01-25 20:05:08 +0000 | [diff] [blame] | 1792 | Find a file by searching the CWD and then the path with a variable set of file
|
| 1793 | extensions. If the file is not found it will append each extension in the list
|
jcarsey | b3011f4 | 2010-01-11 21:49:04 +0000 | [diff] [blame] | 1794 | in the order provided and return the first one that is successful.
|
| 1795 |
|
| 1796 | If FileName is NULL, then ASSERT.
|
| 1797 | If FileExtension is NULL, then behavior is identical to ShellFindFilePath.
|
| 1798 |
|
| 1799 | If the return value is not NULL then the memory must be caller freed.
|
| 1800 |
|
| 1801 | @param[in] FileName Filename string.
|
| 1802 | @param[in] FileExtension Semi-colon delimeted list of possible extensions.
|
| 1803 |
|
| 1804 | @retval NULL The file was not found.
|
| 1805 | @retval !NULL The path to the file.
|
| 1806 | **/
|
| 1807 | CHAR16 *
|
| 1808 | EFIAPI
|
| 1809 | ShellFindFilePathEx (
|
| 1810 | IN CONST CHAR16 *FileName,
|
| 1811 | IN CONST CHAR16 *FileExtension
|
| 1812 | )
|
| 1813 | {
|
| 1814 | CHAR16 *TestPath;
|
| 1815 | CHAR16 *RetVal;
|
| 1816 | CONST CHAR16 *ExtensionWalker;
|
jcarsey | 9e926b6 | 2010-01-14 20:26:39 +0000 | [diff] [blame] | 1817 | UINTN Size;
|
jcarsey | 1cd45e7 | 2010-01-29 15:07:44 +0000 | [diff] [blame] | 1818 | CHAR16 *TempChar;
|
jcarsey | c9d92df | 2010-02-03 15:37:54 +0000 | [diff] [blame] | 1819 | CHAR16 *TempChar2;
|
jcarsey | 1cd45e7 | 2010-01-29 15:07:44 +0000 | [diff] [blame] | 1820 |
|
jcarsey | b3011f4 | 2010-01-11 21:49:04 +0000 | [diff] [blame] | 1821 | ASSERT(FileName != NULL);
|
| 1822 | if (FileExtension == NULL) {
|
| 1823 | return (ShellFindFilePath(FileName));
|
| 1824 | }
|
| 1825 | RetVal = ShellFindFilePath(FileName);
|
| 1826 | if (RetVal != NULL) {
|
| 1827 | return (RetVal);
|
| 1828 | }
|
jcarsey | 9e926b6 | 2010-01-14 20:26:39 +0000 | [diff] [blame] | 1829 | Size = StrSize(FileName);
|
| 1830 | Size += StrSize(FileExtension);
|
| 1831 | TestPath = AllocateZeroPool(Size);
|
jcarsey | c9d92df | 2010-02-03 15:37:54 +0000 | [diff] [blame] | 1832 | if (TestPath == NULL) {
|
| 1833 | return (NULL);
|
| 1834 | }
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 1835 | for (ExtensionWalker = FileExtension, TempChar2 = (CHAR16*)FileExtension; TempChar2 != NULL ; ExtensionWalker = TempChar2 + 1){
|
Qiu Shumin | e75390f | 2015-06-30 03:18:31 +0000 | [diff] [blame] | 1836 | StrCpyS(TestPath, Size/sizeof(CHAR16), FileName);
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 1837 | if (ExtensionWalker != NULL) {
|
Qiu Shumin | e75390f | 2015-06-30 03:18:31 +0000 | [diff] [blame] | 1838 | StrCatS(TestPath, Size/sizeof(CHAR16), ExtensionWalker);
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 1839 | }
|
jcarsey | 1cd45e7 | 2010-01-29 15:07:44 +0000 | [diff] [blame] | 1840 | TempChar = StrStr(TestPath, L";");
|
| 1841 | if (TempChar != NULL) {
|
| 1842 | *TempChar = CHAR_NULL;
|
jcarsey | b3011f4 | 2010-01-11 21:49:04 +0000 | [diff] [blame] | 1843 | }
|
| 1844 | RetVal = ShellFindFilePath(TestPath);
|
| 1845 | if (RetVal != NULL) {
|
| 1846 | break;
|
| 1847 | }
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 1848 | ASSERT(ExtensionWalker != NULL);
|
jcarsey | c9d92df | 2010-02-03 15:37:54 +0000 | [diff] [blame] | 1849 | TempChar2 = StrStr(ExtensionWalker, L";");
|
jcarsey | b3011f4 | 2010-01-11 21:49:04 +0000 | [diff] [blame] | 1850 | }
|
| 1851 | FreePool(TestPath);
|
| 1852 | return (RetVal);
|
| 1853 | }
|
| 1854 |
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 1855 | typedef struct {
|
jcarsey | 9b3bf08 | 2009-06-23 21:15:07 +0000 | [diff] [blame] | 1856 | LIST_ENTRY Link;
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 1857 | CHAR16 *Name;
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 1858 | SHELL_PARAM_TYPE Type;
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 1859 | CHAR16 *Value;
|
| 1860 | UINTN OriginalPosition;
|
| 1861 | } SHELL_PARAM_PACKAGE;
|
| 1862 |
|
| 1863 | /**
|
jcarsey | 1e6e84c | 2010-01-25 20:05:08 +0000 | [diff] [blame] | 1864 | Checks the list of valid arguments and returns TRUE if the item was found. If the
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 1865 | return value is TRUE then the type parameter is set also.
|
jcarsey | 1e6e84c | 2010-01-25 20:05:08 +0000 | [diff] [blame] | 1866 |
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 1867 | if CheckList is NULL then ASSERT();
|
| 1868 | if Name is NULL then ASSERT();
|
| 1869 | if Type is NULL then ASSERT();
|
| 1870 |
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 1871 | @param Name pointer to Name of parameter found
|
| 1872 | @param CheckList List to check against
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 1873 | @param Type pointer to type of parameter if it was found
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 1874 |
|
| 1875 | @retval TRUE the Parameter was found. Type is valid.
|
| 1876 | @retval FALSE the Parameter was not found. Type is not valid.
|
| 1877 | **/
|
| 1878 | BOOLEAN
|
| 1879 | EFIAPI
|
jcarsey | d2b4564 | 2009-05-11 18:02:16 +0000 | [diff] [blame] | 1880 | InternalIsOnCheckList (
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 1881 | IN CONST CHAR16 *Name,
|
| 1882 | IN CONST SHELL_PARAM_ITEM *CheckList,
|
jcarsey | 252d945 | 2011-03-25 20:49:53 +0000 | [diff] [blame] | 1883 | OUT SHELL_PARAM_TYPE *Type
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 1884 | )
|
| 1885 | {
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 1886 | SHELL_PARAM_ITEM *TempListItem;
|
jcarsey | 252d945 | 2011-03-25 20:49:53 +0000 | [diff] [blame] | 1887 | CHAR16 *TempString;
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 1888 |
|
| 1889 | //
|
| 1890 | // ASSERT that all 3 pointer parameters aren't NULL
|
| 1891 | //
|
| 1892 | ASSERT(CheckList != NULL);
|
| 1893 | ASSERT(Type != NULL);
|
| 1894 | ASSERT(Name != NULL);
|
| 1895 |
|
| 1896 | //
|
jcarsey | d2b4564 | 2009-05-11 18:02:16 +0000 | [diff] [blame] | 1897 | // question mark and page break mode are always supported
|
| 1898 | //
|
| 1899 | if ((StrCmp(Name, L"-?") == 0) ||
|
| 1900 | (StrCmp(Name, L"-b") == 0)
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 1901 | ) {
|
jcarsey | 252d945 | 2011-03-25 20:49:53 +0000 | [diff] [blame] | 1902 | *Type = TypeFlag;
|
jcarsey | d2b4564 | 2009-05-11 18:02:16 +0000 | [diff] [blame] | 1903 | return (TRUE);
|
| 1904 | }
|
| 1905 |
|
| 1906 | //
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 1907 | // Enumerate through the list
|
| 1908 | //
|
| 1909 | for (TempListItem = (SHELL_PARAM_ITEM*)CheckList ; TempListItem->Name != NULL ; TempListItem++) {
|
| 1910 | //
|
jcarsey | 9eb53ac | 2009-07-08 17:26:58 +0000 | [diff] [blame] | 1911 | // If the Type is TypeStart only check the first characters of the passed in param
|
| 1912 | // If it matches set the type and return TRUE
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 1913 | //
|
darylm503 | b0934ac | 2011-11-12 00:35:11 +0000 | [diff] [blame] | 1914 | if (TempListItem->Type == TypeStart) {
|
jcarsey | 252d945 | 2011-03-25 20:49:53 +0000 | [diff] [blame] | 1915 | if (StrnCmp(Name, TempListItem->Name, StrLen(TempListItem->Name)) == 0) {
|
| 1916 | *Type = TempListItem->Type;
|
| 1917 | return (TRUE);
|
| 1918 | }
|
| 1919 | TempString = NULL;
|
| 1920 | TempString = StrnCatGrow(&TempString, NULL, Name, StrLen(TempListItem->Name));
|
| 1921 | if (TempString != NULL) {
|
| 1922 | if (StringNoCaseCompare(&TempString, &TempListItem->Name) == 0) {
|
| 1923 | *Type = TempListItem->Type;
|
| 1924 | FreePool(TempString);
|
| 1925 | return (TRUE);
|
| 1926 | }
|
| 1927 | FreePool(TempString);
|
| 1928 | }
|
| 1929 | } else if (StringNoCaseCompare(&Name, &TempListItem->Name) == 0) {
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 1930 | *Type = TempListItem->Type;
|
| 1931 | return (TRUE);
|
| 1932 | }
|
| 1933 | }
|
jcarsey | 2247dde | 2009-11-09 18:08:58 +0000 | [diff] [blame] | 1934 |
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 1935 | return (FALSE);
|
| 1936 | }
|
| 1937 | /**
|
jcarsey | d2b4564 | 2009-05-11 18:02:16 +0000 | [diff] [blame] | 1938 | Checks the string for indicators of "flag" status. this is a leading '/', '-', or '+'
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 1939 |
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 1940 | @param[in] Name pointer to Name of parameter found
|
| 1941 | @param[in] AlwaysAllowNumbers TRUE to allow numbers, FALSE to not.
|
jcarsey | 658bf43 | 2014-11-04 22:33:16 +0000 | [diff] [blame] | 1942 | @param[in] TimeNumbers TRUE to allow numbers with ":", FALSE otherwise.
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 1943 |
|
| 1944 | @retval TRUE the Parameter is a flag.
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 1945 | @retval FALSE the Parameter not a flag.
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 1946 | **/
|
| 1947 | BOOLEAN
|
| 1948 | EFIAPI
|
jcarsey | d2b4564 | 2009-05-11 18:02:16 +0000 | [diff] [blame] | 1949 | InternalIsFlag (
|
jcarsey | 2247dde | 2009-11-09 18:08:58 +0000 | [diff] [blame] | 1950 | IN CONST CHAR16 *Name,
|
jcarsey | 658bf43 | 2014-11-04 22:33:16 +0000 | [diff] [blame] | 1951 | IN CONST BOOLEAN AlwaysAllowNumbers,
|
| 1952 | IN CONST BOOLEAN TimeNumbers
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 1953 | )
|
| 1954 | {
|
| 1955 | //
|
| 1956 | // ASSERT that Name isn't NULL
|
| 1957 | //
|
| 1958 | ASSERT(Name != NULL);
|
| 1959 |
|
| 1960 | //
|
jcarsey | 2247dde | 2009-11-09 18:08:58 +0000 | [diff] [blame] | 1961 | // If we accept numbers then dont return TRUE. (they will be values)
|
| 1962 | //
|
jcarsey | 658bf43 | 2014-11-04 22:33:16 +0000 | [diff] [blame] | 1963 | if (((Name[0] == L'-' || Name[0] == L'+') && InternalShellIsHexOrDecimalNumber(Name+1, FALSE, FALSE, TimeNumbers)) && AlwaysAllowNumbers) {
|
jcarsey | 2247dde | 2009-11-09 18:08:58 +0000 | [diff] [blame] | 1964 | return (FALSE);
|
| 1965 | }
|
| 1966 |
|
| 1967 | //
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 1968 | // If the Name has a /, +, or - as the first character return TRUE
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 1969 | //
|
jcarsey | 1e6e84c | 2010-01-25 20:05:08 +0000 | [diff] [blame] | 1970 | if ((Name[0] == L'/') ||
|
jcarsey | d2b4564 | 2009-05-11 18:02:16 +0000 | [diff] [blame] | 1971 | (Name[0] == L'-') ||
|
| 1972 | (Name[0] == L'+')
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 1973 | ) {
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 1974 | return (TRUE);
|
| 1975 | }
|
| 1976 | return (FALSE);
|
| 1977 | }
|
| 1978 |
|
| 1979 | /**
|
jcarsey | 1e6e84c | 2010-01-25 20:05:08 +0000 | [diff] [blame] | 1980 | Checks the command line arguments passed against the list of valid ones.
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 1981 |
|
| 1982 | If no initialization is required, then return RETURN_SUCCESS.
|
jcarsey | 1e6e84c | 2010-01-25 20:05:08 +0000 | [diff] [blame] | 1983 |
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 1984 | @param[in] CheckList pointer to list of parameters to check
|
| 1985 | @param[out] CheckPackage pointer to pointer to list checked values
|
| 1986 | @param[out] ProblemParam optional pointer to pointer to unicode string for
|
jcarsey | d2b4564 | 2009-05-11 18:02:16 +0000 | [diff] [blame] | 1987 | the paramater that caused failure. If used then the
|
| 1988 | caller is responsible for freeing the memory.
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 1989 | @param[in] AutoPageBreak will automatically set PageBreakEnabled for "b" parameter
|
| 1990 | @param[in] Argv pointer to array of parameters
|
| 1991 | @param[in] Argc Count of parameters in Argv
|
| 1992 | @param[in] AlwaysAllowNumbers TRUE to allow numbers always, FALSE otherwise.
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 1993 |
|
| 1994 | @retval EFI_SUCCESS The operation completed sucessfully.
|
| 1995 | @retval EFI_OUT_OF_RESOURCES A memory allocation failed
|
| 1996 | @retval EFI_INVALID_PARAMETER A parameter was invalid
|
jcarsey | 1e6e84c | 2010-01-25 20:05:08 +0000 | [diff] [blame] | 1997 | @retval EFI_VOLUME_CORRUPTED the command line was corrupt. an argument was
|
| 1998 | duplicated. the duplicated command line argument
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 1999 | was returned in ProblemParam if provided.
|
jcarsey | 1e6e84c | 2010-01-25 20:05:08 +0000 | [diff] [blame] | 2000 | @retval EFI_NOT_FOUND a argument required a value that was missing.
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 2001 | the invalid command line argument was returned in
|
| 2002 | ProblemParam if provided.
|
| 2003 | **/
|
| 2004 | EFI_STATUS
|
| 2005 | EFIAPI
|
| 2006 | InternalCommandLineParse (
|
| 2007 | IN CONST SHELL_PARAM_ITEM *CheckList,
|
| 2008 | OUT LIST_ENTRY **CheckPackage,
|
| 2009 | OUT CHAR16 **ProblemParam OPTIONAL,
|
| 2010 | IN BOOLEAN AutoPageBreak,
|
| 2011 | IN CONST CHAR16 **Argv,
|
jcarsey | 2247dde | 2009-11-09 18:08:58 +0000 | [diff] [blame] | 2012 | IN UINTN Argc,
|
| 2013 | IN BOOLEAN AlwaysAllowNumbers
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 2014 | )
|
| 2015 | {
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 2016 | UINTN LoopCounter;
|
jcarsey | 252d945 | 2011-03-25 20:49:53 +0000 | [diff] [blame] | 2017 | SHELL_PARAM_TYPE CurrentItemType;
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 2018 | SHELL_PARAM_PACKAGE *CurrentItemPackage;
|
jcarsey | 125c2cf | 2009-11-18 21:36:50 +0000 | [diff] [blame] | 2019 | UINTN GetItemValue;
|
| 2020 | UINTN ValueSize;
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 2021 | UINTN Count;
|
jcarsey | 252d945 | 2011-03-25 20:49:53 +0000 | [diff] [blame] | 2022 | CONST CHAR16 *TempPointer;
|
Jaben Carsey | 98c16be | 2014-08-19 21:00:34 +0000 | [diff] [blame] | 2023 | UINTN CurrentValueSize;
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 2024 |
|
| 2025 | CurrentItemPackage = NULL;
|
jcarsey | 125c2cf | 2009-11-18 21:36:50 +0000 | [diff] [blame] | 2026 | GetItemValue = 0;
|
| 2027 | ValueSize = 0;
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 2028 | Count = 0;
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 2029 |
|
| 2030 | //
|
| 2031 | // If there is only 1 item we dont need to do anything
|
| 2032 | //
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 2033 | if (Argc < 1) {
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 2034 | *CheckPackage = NULL;
|
| 2035 | return (EFI_SUCCESS);
|
| 2036 | }
|
| 2037 |
|
| 2038 | //
|
jcarsey | 2247dde | 2009-11-09 18:08:58 +0000 | [diff] [blame] | 2039 | // ASSERTs
|
| 2040 | //
|
| 2041 | ASSERT(CheckList != NULL);
|
| 2042 | ASSERT(Argv != NULL);
|
| 2043 |
|
| 2044 | //
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 2045 | // initialize the linked list
|
| 2046 | //
|
| 2047 | *CheckPackage = (LIST_ENTRY*)AllocateZeroPool(sizeof(LIST_ENTRY));
|
sfu5 | 02a758c | 2011-10-08 02:55:30 +0000 | [diff] [blame] | 2048 | if (*CheckPackage == NULL) {
|
jcarsey | beab0fc | 2011-10-10 17:26:25 +0000 | [diff] [blame] | 2049 | return (EFI_OUT_OF_RESOURCES);
|
sfu5 | 02a758c | 2011-10-08 02:55:30 +0000 | [diff] [blame] | 2050 | }
|
jcarsey | beab0fc | 2011-10-10 17:26:25 +0000 | [diff] [blame] | 2051 |
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 2052 | InitializeListHead(*CheckPackage);
|
| 2053 |
|
| 2054 | //
|
| 2055 | // loop through each of the arguments
|
| 2056 | //
|
| 2057 | for (LoopCounter = 0 ; LoopCounter < Argc ; ++LoopCounter) {
|
| 2058 | if (Argv[LoopCounter] == NULL) {
|
| 2059 | //
|
| 2060 | // do nothing for NULL argv
|
| 2061 | //
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 2062 | } else if (InternalIsOnCheckList(Argv[LoopCounter], CheckList, &CurrentItemType)) {
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 2063 | //
|
jcarsey | 2247dde | 2009-11-09 18:08:58 +0000 | [diff] [blame] | 2064 | // We might have leftover if last parameter didnt have optional value
|
| 2065 | //
|
jcarsey | 125c2cf | 2009-11-18 21:36:50 +0000 | [diff] [blame] | 2066 | if (GetItemValue != 0) {
|
| 2067 | GetItemValue = 0;
|
jcarsey | 2247dde | 2009-11-09 18:08:58 +0000 | [diff] [blame] | 2068 | InsertHeadList(*CheckPackage, &CurrentItemPackage->Link);
|
| 2069 | }
|
| 2070 | //
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 2071 | // this is a flag
|
| 2072 | //
|
jcarsey | 252d945 | 2011-03-25 20:49:53 +0000 | [diff] [blame] | 2073 | CurrentItemPackage = AllocateZeroPool(sizeof(SHELL_PARAM_PACKAGE));
|
jcarsey | beab0fc | 2011-10-10 17:26:25 +0000 | [diff] [blame] | 2074 | if (CurrentItemPackage == NULL) {
|
| 2075 | ShellCommandLineFreeVarList(*CheckPackage);
|
| 2076 | *CheckPackage = NULL;
|
| 2077 | return (EFI_OUT_OF_RESOURCES);
|
| 2078 | }
|
Jaben Carsey | 98c16be | 2014-08-19 21:00:34 +0000 | [diff] [blame] | 2079 | CurrentItemPackage->Name = AllocateCopyPool(StrSize(Argv[LoopCounter]), Argv[LoopCounter]);
|
jcarsey | beab0fc | 2011-10-10 17:26:25 +0000 | [diff] [blame] | 2080 | if (CurrentItemPackage->Name == NULL) {
|
| 2081 | ShellCommandLineFreeVarList(*CheckPackage);
|
| 2082 | *CheckPackage = NULL;
|
| 2083 | return (EFI_OUT_OF_RESOURCES);
|
| 2084 | }
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 2085 | CurrentItemPackage->Type = CurrentItemType;
|
| 2086 | CurrentItemPackage->OriginalPosition = (UINTN)(-1);
|
jcarsey | b1f95a0 | 2009-06-16 00:23:19 +0000 | [diff] [blame] | 2087 | CurrentItemPackage->Value = NULL;
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 2088 |
|
| 2089 | //
|
| 2090 | // Does this flag require a value
|
| 2091 | //
|
jcarsey | 125c2cf | 2009-11-18 21:36:50 +0000 | [diff] [blame] | 2092 | switch (CurrentItemPackage->Type) {
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 2093 | //
|
jcarsey | 125c2cf | 2009-11-18 21:36:50 +0000 | [diff] [blame] | 2094 | // possibly trigger the next loop(s) to populate the value of this item
|
jcarsey | 1e6e84c | 2010-01-25 20:05:08 +0000 | [diff] [blame] | 2095 | //
|
jcarsey | 125c2cf | 2009-11-18 21:36:50 +0000 | [diff] [blame] | 2096 | case TypeValue:
|
jcarsey | 658bf43 | 2014-11-04 22:33:16 +0000 | [diff] [blame] | 2097 | case TypeTimeValue:
|
jcarsey | 1e6e84c | 2010-01-25 20:05:08 +0000 | [diff] [blame] | 2098 | GetItemValue = 1;
|
jcarsey | 125c2cf | 2009-11-18 21:36:50 +0000 | [diff] [blame] | 2099 | ValueSize = 0;
|
| 2100 | break;
|
| 2101 | case TypeDoubleValue:
|
| 2102 | GetItemValue = 2;
|
| 2103 | ValueSize = 0;
|
| 2104 | break;
|
| 2105 | case TypeMaxValue:
|
| 2106 | GetItemValue = (UINTN)(-1);
|
| 2107 | ValueSize = 0;
|
| 2108 | break;
|
| 2109 | default:
|
| 2110 | //
|
| 2111 | // this item has no value expected; we are done
|
| 2112 | //
|
| 2113 | InsertHeadList(*CheckPackage, &CurrentItemPackage->Link);
|
| 2114 | ASSERT(GetItemValue == 0);
|
| 2115 | break;
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 2116 | }
|
Qiu Shumin | af7a3a5 | 2015-03-13 02:04:17 +0000 | [diff] [blame] | 2117 | } else if (GetItemValue != 0 && CurrentItemPackage != NULL && !InternalIsFlag(Argv[LoopCounter], AlwaysAllowNumbers, (BOOLEAN)(CurrentItemPackage->Type == TypeTimeValue))) {
|
jcarsey | b1f95a0 | 2009-06-16 00:23:19 +0000 | [diff] [blame] | 2118 | //
|
jcarsey | 125c2cf | 2009-11-18 21:36:50 +0000 | [diff] [blame] | 2119 | // get the item VALUE for a previous flag
|
jcarsey | b1f95a0 | 2009-06-16 00:23:19 +0000 | [diff] [blame] | 2120 | //
|
Qiu Shumin | 484dd08 | 2015-04-01 00:49:05 +0000 | [diff] [blame] | 2121 | CurrentValueSize = ValueSize + StrSize(Argv[LoopCounter]) + sizeof(CHAR16);
|
| 2122 | CurrentItemPackage->Value = ReallocatePool(ValueSize, CurrentValueSize, CurrentItemPackage->Value);
|
| 2123 | ASSERT(CurrentItemPackage->Value != NULL);
|
| 2124 | if (ValueSize == 0) {
|
Qiu Shumin | e75390f | 2015-06-30 03:18:31 +0000 | [diff] [blame] | 2125 | StrCpyS( CurrentItemPackage->Value,
|
| 2126 | CurrentValueSize/sizeof(CHAR16),
|
| 2127 | Argv[LoopCounter]
|
| 2128 | );
|
jcarsey | 125c2cf | 2009-11-18 21:36:50 +0000 | [diff] [blame] | 2129 | } else {
|
Qiu Shumin | e75390f | 2015-06-30 03:18:31 +0000 | [diff] [blame] | 2130 | StrCatS( CurrentItemPackage->Value,
|
| 2131 | CurrentValueSize/sizeof(CHAR16),
|
| 2132 | L" "
|
| 2133 | );
|
| 2134 | StrCatS( CurrentItemPackage->Value,
|
| 2135 | CurrentValueSize/sizeof(CHAR16),
|
| 2136 | Argv[LoopCounter]
|
| 2137 | );
|
jcarsey | 125c2cf | 2009-11-18 21:36:50 +0000 | [diff] [blame] | 2138 | }
|
Qiu Shumin | 484dd08 | 2015-04-01 00:49:05 +0000 | [diff] [blame] | 2139 | ValueSize += StrSize(Argv[LoopCounter]) + sizeof(CHAR16);
|
| 2140 |
|
jcarsey | 125c2cf | 2009-11-18 21:36:50 +0000 | [diff] [blame] | 2141 | GetItemValue--;
|
| 2142 | if (GetItemValue == 0) {
|
| 2143 | InsertHeadList(*CheckPackage, &CurrentItemPackage->Link);
|
| 2144 | }
|
jcarsey | 658bf43 | 2014-11-04 22:33:16 +0000 | [diff] [blame] | 2145 | } else if (!InternalIsFlag(Argv[LoopCounter], AlwaysAllowNumbers, FALSE)){
|
jcarsey | b1f95a0 | 2009-06-16 00:23:19 +0000 | [diff] [blame] | 2146 | //
|
| 2147 | // add this one as a non-flag
|
| 2148 | //
|
jcarsey | 252d945 | 2011-03-25 20:49:53 +0000 | [diff] [blame] | 2149 |
|
| 2150 | TempPointer = Argv[LoopCounter];
|
darylm503 | b0934ac | 2011-11-12 00:35:11 +0000 | [diff] [blame] | 2151 | if ((*TempPointer == L'^' && *(TempPointer+1) == L'-')
|
jcarsey | 252d945 | 2011-03-25 20:49:53 +0000 | [diff] [blame] | 2152 | || (*TempPointer == L'^' && *(TempPointer+1) == L'/')
|
| 2153 | || (*TempPointer == L'^' && *(TempPointer+1) == L'+')
|
| 2154 | ){
|
| 2155 | TempPointer++;
|
| 2156 | }
|
| 2157 | CurrentItemPackage = AllocateZeroPool(sizeof(SHELL_PARAM_PACKAGE));
|
jcarsey | beab0fc | 2011-10-10 17:26:25 +0000 | [diff] [blame] | 2158 | if (CurrentItemPackage == NULL) {
|
| 2159 | ShellCommandLineFreeVarList(*CheckPackage);
|
| 2160 | *CheckPackage = NULL;
|
| 2161 | return (EFI_OUT_OF_RESOURCES);
|
| 2162 | }
|
jcarsey | b1f95a0 | 2009-06-16 00:23:19 +0000 | [diff] [blame] | 2163 | CurrentItemPackage->Name = NULL;
|
| 2164 | CurrentItemPackage->Type = TypePosition;
|
Jaben Carsey | 98c16be | 2014-08-19 21:00:34 +0000 | [diff] [blame] | 2165 | CurrentItemPackage->Value = AllocateCopyPool(StrSize(TempPointer), TempPointer);
|
jcarsey | beab0fc | 2011-10-10 17:26:25 +0000 | [diff] [blame] | 2166 | if (CurrentItemPackage->Value == NULL) {
|
| 2167 | ShellCommandLineFreeVarList(*CheckPackage);
|
| 2168 | *CheckPackage = NULL;
|
| 2169 | return (EFI_OUT_OF_RESOURCES);
|
| 2170 | }
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 2171 | CurrentItemPackage->OriginalPosition = Count++;
|
jcarsey | 9b3bf08 | 2009-06-23 21:15:07 +0000 | [diff] [blame] | 2172 | InsertHeadList(*CheckPackage, &CurrentItemPackage->Link);
|
jcarsey | 252d945 | 2011-03-25 20:49:53 +0000 | [diff] [blame] | 2173 | } else {
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 2174 | //
|
| 2175 | // this was a non-recognised flag... error!
|
| 2176 | //
|
jcarsey | 252d945 | 2011-03-25 20:49:53 +0000 | [diff] [blame] | 2177 | if (ProblemParam != NULL) {
|
Jaben Carsey | 98c16be | 2014-08-19 21:00:34 +0000 | [diff] [blame] | 2178 | *ProblemParam = AllocateCopyPool(StrSize(Argv[LoopCounter]), Argv[LoopCounter]);
|
jcarsey | 252d945 | 2011-03-25 20:49:53 +0000 | [diff] [blame] | 2179 | }
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 2180 | ShellCommandLineFreeVarList(*CheckPackage);
|
| 2181 | *CheckPackage = NULL;
|
| 2182 | return (EFI_VOLUME_CORRUPTED);
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 2183 | }
|
| 2184 | }
|
jcarsey | 125c2cf | 2009-11-18 21:36:50 +0000 | [diff] [blame] | 2185 | if (GetItemValue != 0) {
|
| 2186 | GetItemValue = 0;
|
| 2187 | InsertHeadList(*CheckPackage, &CurrentItemPackage->Link);
|
| 2188 | }
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 2189 | //
|
| 2190 | // support for AutoPageBreak
|
| 2191 | //
|
| 2192 | if (AutoPageBreak && ShellCommandLineGetFlag(*CheckPackage, L"-b")) {
|
| 2193 | ShellSetPageBreakMode(TRUE);
|
| 2194 | }
|
| 2195 | return (EFI_SUCCESS);
|
| 2196 | }
|
| 2197 |
|
| 2198 | /**
|
jcarsey | 1e6e84c | 2010-01-25 20:05:08 +0000 | [diff] [blame] | 2199 | Checks the command line arguments passed against the list of valid ones.
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 2200 | Optionally removes NULL values first.
|
jcarsey | 1e6e84c | 2010-01-25 20:05:08 +0000 | [diff] [blame] | 2201 |
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 2202 | If no initialization is required, then return RETURN_SUCCESS.
|
jcarsey | 1e6e84c | 2010-01-25 20:05:08 +0000 | [diff] [blame] | 2203 |
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 2204 | @param[in] CheckList The pointer to list of parameters to check.
|
| 2205 | @param[out] CheckPackage The package of checked values.
|
| 2206 | @param[out] ProblemParam Optional pointer to pointer to unicode string for
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 2207 | the paramater that caused failure.
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 2208 | @param[in] AutoPageBreak Will automatically set PageBreakEnabled.
|
| 2209 | @param[in] AlwaysAllowNumbers Will never fail for number based flags.
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 2210 |
|
| 2211 | @retval EFI_SUCCESS The operation completed sucessfully.
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 2212 | @retval EFI_OUT_OF_RESOURCES A memory allocation failed.
|
| 2213 | @retval EFI_INVALID_PARAMETER A parameter was invalid.
|
| 2214 | @retval EFI_VOLUME_CORRUPTED The command line was corrupt.
|
| 2215 | @retval EFI_DEVICE_ERROR The commands contained 2 opposing arguments. One
|
jcarsey | 1e6e84c | 2010-01-25 20:05:08 +0000 | [diff] [blame] | 2216 | of the command line arguments was returned in
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 2217 | ProblemParam if provided.
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 2218 | @retval EFI_NOT_FOUND A argument required a value that was missing.
|
| 2219 | The invalid command line argument was returned in
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 2220 | ProblemParam if provided.
|
| 2221 | **/
|
| 2222 | EFI_STATUS
|
| 2223 | EFIAPI
|
jcarsey | 2247dde | 2009-11-09 18:08:58 +0000 | [diff] [blame] | 2224 | ShellCommandLineParseEx (
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 2225 | IN CONST SHELL_PARAM_ITEM *CheckList,
|
| 2226 | OUT LIST_ENTRY **CheckPackage,
|
| 2227 | OUT CHAR16 **ProblemParam OPTIONAL,
|
jcarsey | 2247dde | 2009-11-09 18:08:58 +0000 | [diff] [blame] | 2228 | IN BOOLEAN AutoPageBreak,
|
| 2229 | IN BOOLEAN AlwaysAllowNumbers
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 2230 | )
|
| 2231 | {
|
jcarsey | 1e6e84c | 2010-01-25 20:05:08 +0000 | [diff] [blame] | 2232 | //
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 2233 | // ASSERT that CheckList and CheckPackage aren't NULL
|
| 2234 | //
|
| 2235 | ASSERT(CheckList != NULL);
|
| 2236 | ASSERT(CheckPackage != NULL);
|
| 2237 |
|
jcarsey | 1e6e84c | 2010-01-25 20:05:08 +0000 | [diff] [blame] | 2238 | //
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 2239 | // Check for UEFI Shell 2.0 protocols
|
| 2240 | //
|
jcarsey | 366f81a | 2011-06-27 21:04:22 +0000 | [diff] [blame] | 2241 | if (gEfiShellParametersProtocol != NULL) {
|
jcarsey | 1e6e84c | 2010-01-25 20:05:08 +0000 | [diff] [blame] | 2242 | return (InternalCommandLineParse(CheckList,
|
| 2243 | CheckPackage,
|
| 2244 | ProblemParam,
|
| 2245 | AutoPageBreak,
|
jcarsey | 366f81a | 2011-06-27 21:04:22 +0000 | [diff] [blame] | 2246 | (CONST CHAR16**) gEfiShellParametersProtocol->Argv,
|
| 2247 | gEfiShellParametersProtocol->Argc,
|
jcarsey | 2247dde | 2009-11-09 18:08:58 +0000 | [diff] [blame] | 2248 | AlwaysAllowNumbers));
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 2249 | }
|
| 2250 |
|
jcarsey | 1e6e84c | 2010-01-25 20:05:08 +0000 | [diff] [blame] | 2251 | //
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 2252 | // ASSERT That EFI Shell is not required
|
| 2253 | //
|
| 2254 | ASSERT (mEfiShellInterface != NULL);
|
jcarsey | 1e6e84c | 2010-01-25 20:05:08 +0000 | [diff] [blame] | 2255 | return (InternalCommandLineParse(CheckList,
|
| 2256 | CheckPackage,
|
| 2257 | ProblemParam,
|
| 2258 | AutoPageBreak,
|
jljusten | 08d7f8e | 2009-06-15 18:42:13 +0000 | [diff] [blame] | 2259 | (CONST CHAR16**) mEfiShellInterface->Argv,
|
jcarsey | 2247dde | 2009-11-09 18:08:58 +0000 | [diff] [blame] | 2260 | mEfiShellInterface->Argc,
|
| 2261 | AlwaysAllowNumbers));
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 2262 | }
|
| 2263 |
|
| 2264 | /**
|
| 2265 | Frees shell variable list that was returned from ShellCommandLineParse.
|
| 2266 |
|
| 2267 | This function will free all the memory that was used for the CheckPackage
|
| 2268 | list of postprocessed shell arguments.
|
| 2269 |
|
| 2270 | this function has no return value.
|
| 2271 |
|
| 2272 | if CheckPackage is NULL, then return
|
| 2273 |
|
| 2274 | @param CheckPackage the list to de-allocate
|
| 2275 | **/
|
| 2276 | VOID
|
| 2277 | EFIAPI
|
| 2278 | ShellCommandLineFreeVarList (
|
| 2279 | IN LIST_ENTRY *CheckPackage
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 2280 | )
|
| 2281 | {
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 2282 | LIST_ENTRY *Node;
|
| 2283 |
|
| 2284 | //
|
| 2285 | // check for CheckPackage == NULL
|
| 2286 | //
|
| 2287 | if (CheckPackage == NULL) {
|
| 2288 | return;
|
| 2289 | }
|
| 2290 |
|
| 2291 | //
|
| 2292 | // for each node in the list
|
| 2293 | //
|
jcarsey | 9eb53ac | 2009-07-08 17:26:58 +0000 | [diff] [blame] | 2294 | for ( Node = GetFirstNode(CheckPackage)
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 2295 | ; !IsListEmpty(CheckPackage)
|
jcarsey | 9eb53ac | 2009-07-08 17:26:58 +0000 | [diff] [blame] | 2296 | ; Node = GetFirstNode(CheckPackage)
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 2297 | ){
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 2298 | //
|
| 2299 | // Remove it from the list
|
| 2300 | //
|
| 2301 | RemoveEntryList(Node);
|
| 2302 |
|
| 2303 | //
|
| 2304 | // if it has a name free the name
|
| 2305 | //
|
| 2306 | if (((SHELL_PARAM_PACKAGE*)Node)->Name != NULL) {
|
| 2307 | FreePool(((SHELL_PARAM_PACKAGE*)Node)->Name);
|
| 2308 | }
|
| 2309 |
|
| 2310 | //
|
| 2311 | // if it has a value free the value
|
| 2312 | //
|
| 2313 | if (((SHELL_PARAM_PACKAGE*)Node)->Value != NULL) {
|
| 2314 | FreePool(((SHELL_PARAM_PACKAGE*)Node)->Value);
|
| 2315 | }
|
jcarsey | 1e6e84c | 2010-01-25 20:05:08 +0000 | [diff] [blame] | 2316 |
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 2317 | //
|
| 2318 | // free the node structure
|
| 2319 | //
|
| 2320 | FreePool((SHELL_PARAM_PACKAGE*)Node);
|
| 2321 | }
|
| 2322 | //
|
| 2323 | // free the list head node
|
| 2324 | //
|
| 2325 | FreePool(CheckPackage);
|
| 2326 | }
|
| 2327 | /**
|
| 2328 | Checks for presence of a flag parameter
|
| 2329 |
|
| 2330 | flag arguments are in the form of "-<Key>" or "/<Key>", but do not have a value following the key
|
| 2331 |
|
| 2332 | if CheckPackage is NULL then return FALSE.
|
| 2333 | if KeyString is NULL then ASSERT()
|
jcarsey | 1e6e84c | 2010-01-25 20:05:08 +0000 | [diff] [blame] | 2334 |
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 2335 | @param CheckPackage The package of parsed command line arguments
|
| 2336 | @param KeyString the Key of the command line argument to check for
|
| 2337 |
|
| 2338 | @retval TRUE the flag is on the command line
|
| 2339 | @retval FALSE the flag is not on the command line
|
| 2340 | **/
|
| 2341 | BOOLEAN
|
| 2342 | EFIAPI
|
| 2343 | ShellCommandLineGetFlag (
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 2344 | IN CONST LIST_ENTRY * CONST CheckPackage,
|
| 2345 | IN CONST CHAR16 * CONST KeyString
|
| 2346 | )
|
| 2347 | {
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 2348 | LIST_ENTRY *Node;
|
jcarsey | 252d945 | 2011-03-25 20:49:53 +0000 | [diff] [blame] | 2349 | CHAR16 *TempString;
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 2350 |
|
| 2351 | //
|
ydong10 | 0c1950b | 2011-10-13 02:37:35 +0000 | [diff] [blame] | 2352 | // return FALSE for no package or KeyString is NULL
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 2353 | //
|
ydong10 | 0c1950b | 2011-10-13 02:37:35 +0000 | [diff] [blame] | 2354 | if (CheckPackage == NULL || KeyString == NULL) {
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 2355 | return (FALSE);
|
| 2356 | }
|
| 2357 |
|
| 2358 | //
|
| 2359 | // enumerate through the list of parametrs
|
| 2360 | //
|
jcarsey | 1e6e84c | 2010-01-25 20:05:08 +0000 | [diff] [blame] | 2361 | for ( Node = GetFirstNode(CheckPackage)
|
| 2362 | ; !IsNull (CheckPackage, Node)
|
| 2363 | ; Node = GetNextNode(CheckPackage, Node)
|
jcarsey | 252d945 | 2011-03-25 20:49:53 +0000 | [diff] [blame] | 2364 | ){
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 2365 | //
|
| 2366 | // If the Name matches, return TRUE (and there may be NULL name)
|
| 2367 | //
|
| 2368 | if (((SHELL_PARAM_PACKAGE*)Node)->Name != NULL) {
|
jcarsey | 9eb53ac | 2009-07-08 17:26:58 +0000 | [diff] [blame] | 2369 | //
|
| 2370 | // If Type is TypeStart then only compare the begining of the strings
|
| 2371 | //
|
jcarsey | 252d945 | 2011-03-25 20:49:53 +0000 | [diff] [blame] | 2372 | if (((SHELL_PARAM_PACKAGE*)Node)->Type == TypeStart) {
|
| 2373 | if (StrnCmp(KeyString, ((SHELL_PARAM_PACKAGE*)Node)->Name, StrLen(KeyString)) == 0) {
|
| 2374 | return (TRUE);
|
| 2375 | }
|
| 2376 | TempString = NULL;
|
| 2377 | TempString = StrnCatGrow(&TempString, NULL, KeyString, StrLen(((SHELL_PARAM_PACKAGE*)Node)->Name));
|
| 2378 | if (TempString != NULL) {
|
| 2379 | if (StringNoCaseCompare(&KeyString, &((SHELL_PARAM_PACKAGE*)Node)->Name) == 0) {
|
| 2380 | FreePool(TempString);
|
| 2381 | return (TRUE);
|
| 2382 | }
|
| 2383 | FreePool(TempString);
|
| 2384 | }
|
| 2385 | } else if (StringNoCaseCompare(&KeyString, &((SHELL_PARAM_PACKAGE*)Node)->Name) == 0) {
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 2386 | return (TRUE);
|
| 2387 | }
|
| 2388 | }
|
| 2389 | }
|
| 2390 | return (FALSE);
|
| 2391 | }
|
| 2392 | /**
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 2393 | Returns value from command line argument.
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 2394 |
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 2395 | Value parameters are in the form of "-<Key> value" or "/<Key> value".
|
jcarsey | 1e6e84c | 2010-01-25 20:05:08 +0000 | [diff] [blame] | 2396 |
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 2397 | If CheckPackage is NULL, then return NULL.
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 2398 |
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 2399 | @param[in] CheckPackage The package of parsed command line arguments.
|
| 2400 | @param[in] KeyString The Key of the command line argument to check for.
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 2401 |
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 2402 | @retval NULL The flag is not on the command line.
|
| 2403 | @retval !=NULL The pointer to unicode string of the value.
|
| 2404 | **/
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 2405 | CONST CHAR16*
|
| 2406 | EFIAPI
|
| 2407 | ShellCommandLineGetValue (
|
| 2408 | IN CONST LIST_ENTRY *CheckPackage,
|
| 2409 | IN CHAR16 *KeyString
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 2410 | )
|
| 2411 | {
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 2412 | LIST_ENTRY *Node;
|
jcarsey | 252d945 | 2011-03-25 20:49:53 +0000 | [diff] [blame] | 2413 | CHAR16 *TempString;
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 2414 |
|
| 2415 | //
|
ydong10 | 0c1950b | 2011-10-13 02:37:35 +0000 | [diff] [blame] | 2416 | // return NULL for no package or KeyString is NULL
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 2417 | //
|
ydong10 | 0c1950b | 2011-10-13 02:37:35 +0000 | [diff] [blame] | 2418 | if (CheckPackage == NULL || KeyString == NULL) {
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 2419 | return (NULL);
|
| 2420 | }
|
| 2421 |
|
| 2422 | //
|
| 2423 | // enumerate through the list of parametrs
|
| 2424 | //
|
jcarsey | 1e6e84c | 2010-01-25 20:05:08 +0000 | [diff] [blame] | 2425 | for ( Node = GetFirstNode(CheckPackage)
|
| 2426 | ; !IsNull (CheckPackage, Node)
|
| 2427 | ; Node = GetNextNode(CheckPackage, Node)
|
jcarsey | 252d945 | 2011-03-25 20:49:53 +0000 | [diff] [blame] | 2428 | ){
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 2429 | //
|
jcarsey | 252d945 | 2011-03-25 20:49:53 +0000 | [diff] [blame] | 2430 | // If the Name matches, return TRUE (and there may be NULL name)
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 2431 | //
|
| 2432 | if (((SHELL_PARAM_PACKAGE*)Node)->Name != NULL) {
|
jcarsey | 9eb53ac | 2009-07-08 17:26:58 +0000 | [diff] [blame] | 2433 | //
|
| 2434 | // If Type is TypeStart then only compare the begining of the strings
|
| 2435 | //
|
jcarsey | 252d945 | 2011-03-25 20:49:53 +0000 | [diff] [blame] | 2436 | if (((SHELL_PARAM_PACKAGE*)Node)->Type == TypeStart) {
|
| 2437 | if (StrnCmp(KeyString, ((SHELL_PARAM_PACKAGE*)Node)->Name, StrLen(KeyString)) == 0) {
|
| 2438 | return (((SHELL_PARAM_PACKAGE*)Node)->Name + StrLen(KeyString));
|
| 2439 | }
|
| 2440 | TempString = NULL;
|
| 2441 | TempString = StrnCatGrow(&TempString, NULL, KeyString, StrLen(((SHELL_PARAM_PACKAGE*)Node)->Name));
|
| 2442 | if (TempString != NULL) {
|
| 2443 | if (StringNoCaseCompare(&KeyString, &((SHELL_PARAM_PACKAGE*)Node)->Name) == 0) {
|
| 2444 | FreePool(TempString);
|
| 2445 | return (((SHELL_PARAM_PACKAGE*)Node)->Name + StrLen(KeyString));
|
| 2446 | }
|
| 2447 | FreePool(TempString);
|
| 2448 | }
|
| 2449 | } else if (StringNoCaseCompare(&KeyString, &((SHELL_PARAM_PACKAGE*)Node)->Name) == 0) {
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 2450 | return (((SHELL_PARAM_PACKAGE*)Node)->Value);
|
| 2451 | }
|
| 2452 | }
|
| 2453 | }
|
| 2454 | return (NULL);
|
| 2455 | }
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 2456 |
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 2457 | /**
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 2458 | Returns raw value from command line argument.
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 2459 |
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 2460 | Raw value parameters are in the form of "value" in a specific position in the list.
|
jcarsey | 1e6e84c | 2010-01-25 20:05:08 +0000 | [diff] [blame] | 2461 |
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 2462 | If CheckPackage is NULL, then return NULL.
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 2463 |
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 2464 | @param[in] CheckPackage The package of parsed command line arguments.
|
| 2465 | @param[in] Position The position of the value.
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 2466 |
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 2467 | @retval NULL The flag is not on the command line.
|
| 2468 | @retval !=NULL The pointer to unicode string of the value.
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 2469 | **/
|
| 2470 | CONST CHAR16*
|
| 2471 | EFIAPI
|
| 2472 | ShellCommandLineGetRawValue (
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 2473 | IN CONST LIST_ENTRY * CONST CheckPackage,
|
| 2474 | IN UINTN Position
|
| 2475 | )
|
| 2476 | {
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 2477 | LIST_ENTRY *Node;
|
| 2478 |
|
| 2479 | //
|
| 2480 | // check for CheckPackage == NULL
|
| 2481 | //
|
| 2482 | if (CheckPackage == NULL) {
|
| 2483 | return (NULL);
|
| 2484 | }
|
| 2485 |
|
| 2486 | //
|
| 2487 | // enumerate through the list of parametrs
|
| 2488 | //
|
jcarsey | 1e6e84c | 2010-01-25 20:05:08 +0000 | [diff] [blame] | 2489 | for ( Node = GetFirstNode(CheckPackage)
|
| 2490 | ; !IsNull (CheckPackage, Node)
|
| 2491 | ; Node = GetNextNode(CheckPackage, Node)
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 2492 | ){
|
jcarsey | 94b17fa | 2009-05-07 18:46:18 +0000 | [diff] [blame] | 2493 | //
|
| 2494 | // If the position matches, return the value
|
| 2495 | //
|
| 2496 | if (((SHELL_PARAM_PACKAGE*)Node)->OriginalPosition == Position) {
|
| 2497 | return (((SHELL_PARAM_PACKAGE*)Node)->Value);
|
| 2498 | }
|
| 2499 | }
|
| 2500 | return (NULL);
|
jcarsey | b1f95a0 | 2009-06-16 00:23:19 +0000 | [diff] [blame] | 2501 | }
|
jcarsey | 2247dde | 2009-11-09 18:08:58 +0000 | [diff] [blame] | 2502 |
|
| 2503 | /**
|
jcarsey | 1e6e84c | 2010-01-25 20:05:08 +0000 | [diff] [blame] | 2504 | returns the number of command line value parameters that were parsed.
|
| 2505 |
|
jcarsey | 2247dde | 2009-11-09 18:08:58 +0000 | [diff] [blame] | 2506 | this will not include flags.
|
| 2507 |
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 2508 | @param[in] CheckPackage The package of parsed command line arguments.
|
| 2509 |
|
jcarsey | 2247dde | 2009-11-09 18:08:58 +0000 | [diff] [blame] | 2510 | @retval (UINTN)-1 No parsing has ocurred
|
| 2511 | @return other The number of value parameters found
|
| 2512 | **/
|
| 2513 | UINTN
|
| 2514 | EFIAPI
|
| 2515 | ShellCommandLineGetCount(
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 2516 | IN CONST LIST_ENTRY *CheckPackage
|
jcarsey | 125c2cf | 2009-11-18 21:36:50 +0000 | [diff] [blame] | 2517 | )
|
| 2518 | {
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 2519 | LIST_ENTRY *Node1;
|
| 2520 | UINTN Count;
|
| 2521 |
|
| 2522 | if (CheckPackage == NULL) {
|
| 2523 | return (0);
|
| 2524 | }
|
| 2525 | for ( Node1 = GetFirstNode(CheckPackage), Count = 0
|
| 2526 | ; !IsNull (CheckPackage, Node1)
|
| 2527 | ; Node1 = GetNextNode(CheckPackage, Node1)
|
| 2528 | ){
|
| 2529 | if (((SHELL_PARAM_PACKAGE*)Node1)->Name == NULL) {
|
| 2530 | Count++;
|
| 2531 | }
|
| 2532 | }
|
| 2533 | return (Count);
|
jcarsey | 2247dde | 2009-11-09 18:08:58 +0000 | [diff] [blame] | 2534 | }
|
| 2535 |
|
jcarsey | 975136a | 2009-06-16 19:03:54 +0000 | [diff] [blame] | 2536 | /**
|
Bruce Cran | cceb4eb | 2015-07-08 01:54:46 +0000 | [diff] [blame] | 2537 | Determines if a parameter is duplicated.
|
jcarsey | 36a9d67 | 2009-11-20 21:13:41 +0000 | [diff] [blame] | 2538 |
|
jcarsey | 1e6e84c | 2010-01-25 20:05:08 +0000 | [diff] [blame] | 2539 | If Param is not NULL then it will point to a callee allocated string buffer
|
jcarsey | 36a9d67 | 2009-11-20 21:13:41 +0000 | [diff] [blame] | 2540 | with the parameter value if a duplicate is found.
|
| 2541 |
|
| 2542 | If CheckPackage is NULL, then ASSERT.
|
| 2543 |
|
| 2544 | @param[in] CheckPackage The package of parsed command line arguments.
|
| 2545 | @param[out] Param Upon finding one, a pointer to the duplicated parameter.
|
| 2546 |
|
| 2547 | @retval EFI_SUCCESS No parameters were duplicated.
|
| 2548 | @retval EFI_DEVICE_ERROR A duplicate was found.
|
| 2549 | **/
|
| 2550 | EFI_STATUS
|
| 2551 | EFIAPI
|
| 2552 | ShellCommandLineCheckDuplicate (
|
| 2553 | IN CONST LIST_ENTRY *CheckPackage,
|
| 2554 | OUT CHAR16 **Param
|
| 2555 | )
|
| 2556 | {
|
| 2557 | LIST_ENTRY *Node1;
|
| 2558 | LIST_ENTRY *Node2;
|
jcarsey | 1e6e84c | 2010-01-25 20:05:08 +0000 | [diff] [blame] | 2559 |
|
jcarsey | 36a9d67 | 2009-11-20 21:13:41 +0000 | [diff] [blame] | 2560 | ASSERT(CheckPackage != NULL);
|
| 2561 |
|
jcarsey | 1e6e84c | 2010-01-25 20:05:08 +0000 | [diff] [blame] | 2562 | for ( Node1 = GetFirstNode(CheckPackage)
|
| 2563 | ; !IsNull (CheckPackage, Node1)
|
| 2564 | ; Node1 = GetNextNode(CheckPackage, Node1)
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 2565 | ){
|
jcarsey | 1e6e84c | 2010-01-25 20:05:08 +0000 | [diff] [blame] | 2566 | for ( Node2 = GetNextNode(CheckPackage, Node1)
|
| 2567 | ; !IsNull (CheckPackage, Node2)
|
| 2568 | ; Node2 = GetNextNode(CheckPackage, Node2)
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 2569 | ){
|
| 2570 | if ((((SHELL_PARAM_PACKAGE*)Node1)->Name != NULL) && (((SHELL_PARAM_PACKAGE*)Node2)->Name != NULL) && StrCmp(((SHELL_PARAM_PACKAGE*)Node1)->Name, ((SHELL_PARAM_PACKAGE*)Node2)->Name) == 0) {
|
jcarsey | 36a9d67 | 2009-11-20 21:13:41 +0000 | [diff] [blame] | 2571 | if (Param != NULL) {
|
| 2572 | *Param = NULL;
|
| 2573 | *Param = StrnCatGrow(Param, NULL, ((SHELL_PARAM_PACKAGE*)Node1)->Name, 0);
|
| 2574 | }
|
| 2575 | return (EFI_DEVICE_ERROR);
|
| 2576 | }
|
| 2577 | }
|
| 2578 | }
|
| 2579 | return (EFI_SUCCESS);
|
| 2580 | }
|
| 2581 |
|
| 2582 | /**
|
jcarsey | 1e6e84c | 2010-01-25 20:05:08 +0000 | [diff] [blame] | 2583 | This is a find and replace function. Upon successful return the NewString is a copy of
|
jcarsey | 975136a | 2009-06-16 19:03:54 +0000 | [diff] [blame] | 2584 | SourceString with each instance of FindTarget replaced with ReplaceWith.
|
| 2585 |
|
jcarsey | b3011f4 | 2010-01-11 21:49:04 +0000 | [diff] [blame] | 2586 | If SourceString and NewString overlap the behavior is undefined.
|
| 2587 |
|
jcarsey | 975136a | 2009-06-16 19:03:54 +0000 | [diff] [blame] | 2588 | If the string would grow bigger than NewSize it will halt and return error.
|
| 2589 |
|
ydong10 | 4ff7e37 | 2011-09-02 08:05:34 +0000 | [diff] [blame] | 2590 | @param[in] SourceString The string with source buffer.
|
| 2591 | @param[in, out] NewString The string with resultant buffer.
|
| 2592 | @param[in] NewSize The size in bytes of NewString.
|
| 2593 | @param[in] FindTarget The string to look for.
|
| 2594 | @param[in] ReplaceWith The string to replace FindTarget with.
|
| 2595 | @param[in] SkipPreCarrot If TRUE will skip a FindTarget that has a '^'
|
| 2596 | immediately before it.
|
| 2597 | @param[in] ParameterReplacing If TRUE will add "" around items with spaces.
|
jcarsey | 975136a | 2009-06-16 19:03:54 +0000 | [diff] [blame] | 2598 |
|
jcarsey | 969c783 | 2010-01-13 16:46:33 +0000 | [diff] [blame] | 2599 | @retval EFI_INVALID_PARAMETER SourceString was NULL.
|
| 2600 | @retval EFI_INVALID_PARAMETER NewString was NULL.
|
| 2601 | @retval EFI_INVALID_PARAMETER FindTarget was NULL.
|
| 2602 | @retval EFI_INVALID_PARAMETER ReplaceWith was NULL.
|
| 2603 | @retval EFI_INVALID_PARAMETER FindTarget had length < 1.
|
| 2604 | @retval EFI_INVALID_PARAMETER SourceString had length < 1.
|
jcarsey | 1e6e84c | 2010-01-25 20:05:08 +0000 | [diff] [blame] | 2605 | @retval EFI_BUFFER_TOO_SMALL NewSize was less than the minimum size to hold
|
jcarsey | 969c783 | 2010-01-13 16:46:33 +0000 | [diff] [blame] | 2606 | the new string (truncation occurred).
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 2607 | @retval EFI_SUCCESS The string was successfully copied with replacement.
|
jcarsey | 975136a | 2009-06-16 19:03:54 +0000 | [diff] [blame] | 2608 | **/
|
jcarsey | 975136a | 2009-06-16 19:03:54 +0000 | [diff] [blame] | 2609 | EFI_STATUS
|
| 2610 | EFIAPI
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 2611 | ShellCopySearchAndReplace(
|
jcarsey | 975136a | 2009-06-16 19:03:54 +0000 | [diff] [blame] | 2612 | IN CHAR16 CONST *SourceString,
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 2613 | IN OUT CHAR16 *NewString,
|
jcarsey | 975136a | 2009-06-16 19:03:54 +0000 | [diff] [blame] | 2614 | IN UINTN NewSize,
|
| 2615 | IN CONST CHAR16 *FindTarget,
|
jcarsey | 969c783 | 2010-01-13 16:46:33 +0000 | [diff] [blame] | 2616 | IN CONST CHAR16 *ReplaceWith,
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 2617 | IN CONST BOOLEAN SkipPreCarrot,
|
| 2618 | IN CONST BOOLEAN ParameterReplacing
|
jcarsey | 1e6e84c | 2010-01-25 20:05:08 +0000 | [diff] [blame] | 2619 | )
|
jcarsey | 2247dde | 2009-11-09 18:08:58 +0000 | [diff] [blame] | 2620 | {
|
jcarsey | 0158294 | 2009-07-10 19:46:17 +0000 | [diff] [blame] | 2621 | UINTN Size;
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 2622 | CHAR16 *Replace;
|
| 2623 |
|
jcarsey | 975136a | 2009-06-16 19:03:54 +0000 | [diff] [blame] | 2624 | if ( (SourceString == NULL)
|
| 2625 | || (NewString == NULL)
|
| 2626 | || (FindTarget == NULL)
|
| 2627 | || (ReplaceWith == NULL)
|
| 2628 | || (StrLen(FindTarget) < 1)
|
| 2629 | || (StrLen(SourceString) < 1)
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 2630 | ){
|
jcarsey | 975136a | 2009-06-16 19:03:54 +0000 | [diff] [blame] | 2631 | return (EFI_INVALID_PARAMETER);
|
| 2632 | }
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 2633 | Replace = NULL;
|
| 2634 | if (StrStr(ReplaceWith, L" ") == NULL || !ParameterReplacing) {
|
| 2635 | Replace = StrnCatGrow(&Replace, NULL, ReplaceWith, 0);
|
| 2636 | } else {
|
| 2637 | Replace = AllocateZeroPool(StrSize(ReplaceWith) + 2*sizeof(CHAR16));
|
jcarsey | beab0fc | 2011-10-10 17:26:25 +0000 | [diff] [blame] | 2638 | if (Replace != NULL) {
|
| 2639 | UnicodeSPrint(Replace, StrSize(ReplaceWith) + 2*sizeof(CHAR16), L"\"%s\"", ReplaceWith);
|
| 2640 | }
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 2641 | }
|
jcarsey | 3e082d5 | 2010-10-04 16:44:57 +0000 | [diff] [blame] | 2642 | if (Replace == NULL) {
|
| 2643 | return (EFI_OUT_OF_RESOURCES);
|
| 2644 | }
|
Jaben Carsey | 98c16be | 2014-08-19 21:00:34 +0000 | [diff] [blame] | 2645 | NewString = ZeroMem(NewString, NewSize);
|
jcarsey | 2247dde | 2009-11-09 18:08:58 +0000 | [diff] [blame] | 2646 | while (*SourceString != CHAR_NULL) {
|
jcarsey | 969c783 | 2010-01-13 16:46:33 +0000 | [diff] [blame] | 2647 | //
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 2648 | // if we find the FindTarget and either Skip == FALSE or Skip and we
|
jcarsey | 969c783 | 2010-01-13 16:46:33 +0000 | [diff] [blame] | 2649 | // dont have a carrot do a replace...
|
| 2650 | //
|
jcarsey | 1e6e84c | 2010-01-25 20:05:08 +0000 | [diff] [blame] | 2651 | if (StrnCmp(SourceString, FindTarget, StrLen(FindTarget)) == 0
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 2652 | && ((SkipPreCarrot && *(SourceString-1) != L'^') || !SkipPreCarrot)
|
| 2653 | ){
|
jcarsey | 975136a | 2009-06-16 19:03:54 +0000 | [diff] [blame] | 2654 | SourceString += StrLen(FindTarget);
|
jcarsey | 0158294 | 2009-07-10 19:46:17 +0000 | [diff] [blame] | 2655 | Size = StrSize(NewString);
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 2656 | if ((Size + (StrLen(Replace)*sizeof(CHAR16))) > NewSize) {
|
| 2657 | FreePool(Replace);
|
jcarsey | 975136a | 2009-06-16 19:03:54 +0000 | [diff] [blame] | 2658 | return (EFI_BUFFER_TOO_SMALL);
|
| 2659 | }
|
Qiu Shumin | e75390f | 2015-06-30 03:18:31 +0000 | [diff] [blame] | 2660 | StrCatS(NewString, NewSize/sizeof(CHAR16), Replace);
|
jcarsey | 975136a | 2009-06-16 19:03:54 +0000 | [diff] [blame] | 2661 | } else {
|
jcarsey | 0158294 | 2009-07-10 19:46:17 +0000 | [diff] [blame] | 2662 | Size = StrSize(NewString);
|
| 2663 | if (Size + sizeof(CHAR16) > NewSize) {
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 2664 | FreePool(Replace);
|
jcarsey | 975136a | 2009-06-16 19:03:54 +0000 | [diff] [blame] | 2665 | return (EFI_BUFFER_TOO_SMALL);
|
| 2666 | }
|
Qiu Shumin | e75390f | 2015-06-30 03:18:31 +0000 | [diff] [blame] | 2667 | StrnCatS(NewString, NewSize/sizeof(CHAR16), SourceString, 1);
|
jcarsey | 975136a | 2009-06-16 19:03:54 +0000 | [diff] [blame] | 2668 | SourceString++;
|
| 2669 | }
|
| 2670 | }
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 2671 | FreePool(Replace);
|
jcarsey | 975136a | 2009-06-16 19:03:54 +0000 | [diff] [blame] | 2672 | return (EFI_SUCCESS);
|
| 2673 | }
|
jcarsey | b1f95a0 | 2009-06-16 00:23:19 +0000 | [diff] [blame] | 2674 |
|
| 2675 | /**
|
jcarsey | e2f8297 | 2009-12-01 05:40:24 +0000 | [diff] [blame] | 2676 | Internal worker function to output a string.
|
| 2677 |
|
| 2678 | This function will output a string to the correct StdOut.
|
| 2679 |
|
| 2680 | @param[in] String The string to print out.
|
| 2681 |
|
| 2682 | @retval EFI_SUCCESS The operation was sucessful.
|
| 2683 | @retval !EFI_SUCCESS The operation failed.
|
| 2684 | **/
|
| 2685 | EFI_STATUS
|
| 2686 | EFIAPI
|
| 2687 | InternalPrintTo (
|
| 2688 | IN CONST CHAR16 *String
|
| 2689 | )
|
| 2690 | {
|
| 2691 | UINTN Size;
|
| 2692 | Size = StrSize(String) - sizeof(CHAR16);
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 2693 | if (Size == 0) {
|
| 2694 | return (EFI_SUCCESS);
|
| 2695 | }
|
jcarsey | 366f81a | 2011-06-27 21:04:22 +0000 | [diff] [blame] | 2696 | if (gEfiShellParametersProtocol != NULL) {
|
| 2697 | return (gEfiShellProtocol->WriteFile(gEfiShellParametersProtocol->StdOut, &Size, (VOID*)String));
|
jcarsey | e2f8297 | 2009-12-01 05:40:24 +0000 | [diff] [blame] | 2698 | }
|
| 2699 | if (mEfiShellInterface != NULL) {
|
jcarsey | 06c355b | 2012-03-26 21:00:39 +0000 | [diff] [blame] | 2700 | if (mEfiShellInterface->RedirArgc == 0) {
|
jcarsey | 49bd498 | 2012-01-27 18:42:43 +0000 | [diff] [blame] | 2701 | //
|
| 2702 | // Divide in half for old shell. Must be string length not size.
|
jcarsey | 06c355b | 2012-03-26 21:00:39 +0000 | [diff] [blame] | 2703 | //
|
| 2704 | Size /=2; // Divide in half only when no redirection.
|
| 2705 | }
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 2706 | return (mEfiShellInterface->StdOut->Write(mEfiShellInterface->StdOut, &Size, (VOID*)String));
|
jcarsey | e2f8297 | 2009-12-01 05:40:24 +0000 | [diff] [blame] | 2707 | }
|
| 2708 | ASSERT(FALSE);
|
| 2709 | return (EFI_UNSUPPORTED);
|
| 2710 | }
|
| 2711 |
|
| 2712 | /**
|
jcarsey | b1f95a0 | 2009-06-16 00:23:19 +0000 | [diff] [blame] | 2713 | Print at a specific location on the screen.
|
| 2714 |
|
jcarsey | f1b87e7 | 2009-06-17 00:52:11 +0000 | [diff] [blame] | 2715 | This function will move the cursor to a given screen location and print the specified string
|
jcarsey | 1e6e84c | 2010-01-25 20:05:08 +0000 | [diff] [blame] | 2716 |
|
| 2717 | If -1 is specified for either the Row or Col the current screen location for BOTH
|
jcarsey | f1b87e7 | 2009-06-17 00:52:11 +0000 | [diff] [blame] | 2718 | will be used.
|
jcarsey | b1f95a0 | 2009-06-16 00:23:19 +0000 | [diff] [blame] | 2719 |
|
| 2720 | if either Row or Col is out of range for the current console, then ASSERT
|
| 2721 | if Format is NULL, then ASSERT
|
| 2722 |
|
jcarsey | 1e6e84c | 2010-01-25 20:05:08 +0000 | [diff] [blame] | 2723 | In addition to the standard %-based flags as supported by UefiLib Print() this supports
|
jcarsey | b1f95a0 | 2009-06-16 00:23:19 +0000 | [diff] [blame] | 2724 | the following additional flags:
|
| 2725 | %N - Set output attribute to normal
|
| 2726 | %H - Set output attribute to highlight
|
| 2727 | %E - Set output attribute to error
|
| 2728 | %B - Set output attribute to blue color
|
| 2729 | %V - Set output attribute to green color
|
| 2730 |
|
| 2731 | Note: The background color is controlled by the shell command cls.
|
| 2732 |
|
jcarsey | b1f95a0 | 2009-06-16 00:23:19 +0000 | [diff] [blame] | 2733 | @param[in] Col the column to print at
|
jcarsey | 252d945 | 2011-03-25 20:49:53 +0000 | [diff] [blame] | 2734 | @param[in] Row the row to print at
|
jcarsey | b1f95a0 | 2009-06-16 00:23:19 +0000 | [diff] [blame] | 2735 | @param[in] Format the format string
|
jcarsey | 2247dde | 2009-11-09 18:08:58 +0000 | [diff] [blame] | 2736 | @param[in] Marker the marker for the variable argument list
|
jcarsey | b1f95a0 | 2009-06-16 00:23:19 +0000 | [diff] [blame] | 2737 |
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 2738 | @return EFI_SUCCESS The operation was successful.
|
| 2739 | @return EFI_DEVICE_ERROR The console device reported an error.
|
jcarsey | b1f95a0 | 2009-06-16 00:23:19 +0000 | [diff] [blame] | 2740 | **/
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 2741 | EFI_STATUS
|
jcarsey | b1f95a0 | 2009-06-16 00:23:19 +0000 | [diff] [blame] | 2742 | EFIAPI
|
jcarsey | 2247dde | 2009-11-09 18:08:58 +0000 | [diff] [blame] | 2743 | InternalShellPrintWorker(
|
jcarsey | b1f95a0 | 2009-06-16 00:23:19 +0000 | [diff] [blame] | 2744 | IN INT32 Col OPTIONAL,
|
| 2745 | IN INT32 Row OPTIONAL,
|
| 2746 | IN CONST CHAR16 *Format,
|
jcarsey | 252d945 | 2011-03-25 20:49:53 +0000 | [diff] [blame] | 2747 | IN VA_LIST Marker
|
jcarsey | 1e6e84c | 2010-01-25 20:05:08 +0000 | [diff] [blame] | 2748 | )
|
jcarsey | 2247dde | 2009-11-09 18:08:58 +0000 | [diff] [blame] | 2749 | {
|
jcarsey | b1f95a0 | 2009-06-16 00:23:19 +0000 | [diff] [blame] | 2750 | EFI_STATUS Status;
|
jcarsey | 975136a | 2009-06-16 19:03:54 +0000 | [diff] [blame] | 2751 | CHAR16 *ResumeLocation;
|
| 2752 | CHAR16 *FormatWalker;
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 2753 | UINTN OriginalAttribute;
|
jcarsey | 89e8537 | 2011-04-13 23:37:50 +0000 | [diff] [blame] | 2754 | CHAR16 *mPostReplaceFormat;
|
| 2755 | CHAR16 *mPostReplaceFormat2;
|
| 2756 |
|
| 2757 | mPostReplaceFormat = AllocateZeroPool (PcdGet16 (PcdShellPrintBufferSize));
|
| 2758 | mPostReplaceFormat2 = AllocateZeroPool (PcdGet16 (PcdShellPrintBufferSize));
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 2759 |
|
jcarsey | f8d3e68 | 2011-04-19 17:54:42 +0000 | [diff] [blame] | 2760 | if (mPostReplaceFormat == NULL || mPostReplaceFormat2 == NULL) {
|
| 2761 | SHELL_FREE_NON_NULL(mPostReplaceFormat);
|
| 2762 | SHELL_FREE_NON_NULL(mPostReplaceFormat2);
|
| 2763 | return (EFI_OUT_OF_RESOURCES);
|
| 2764 | }
|
| 2765 |
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 2766 | Status = EFI_SUCCESS;
|
| 2767 | OriginalAttribute = gST->ConOut->Mode->Attribute;
|
jcarsey | 1e6e84c | 2010-01-25 20:05:08 +0000 | [diff] [blame] | 2768 |
|
jcarsey | 975136a | 2009-06-16 19:03:54 +0000 | [diff] [blame] | 2769 | //
|
| 2770 | // Back and forth each time fixing up 1 of our flags...
|
| 2771 | //
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 2772 | Status = ShellCopySearchAndReplace(Format, mPostReplaceFormat, PcdGet16 (PcdShellPrintBufferSize), L"%N", L"%%N", FALSE, FALSE);
|
jcarsey | 975136a | 2009-06-16 19:03:54 +0000 | [diff] [blame] | 2773 | ASSERT_EFI_ERROR(Status);
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 2774 | Status = ShellCopySearchAndReplace(mPostReplaceFormat, mPostReplaceFormat2, PcdGet16 (PcdShellPrintBufferSize), L"%E", L"%%E", FALSE, FALSE);
|
jcarsey | 975136a | 2009-06-16 19:03:54 +0000 | [diff] [blame] | 2775 | ASSERT_EFI_ERROR(Status);
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 2776 | Status = ShellCopySearchAndReplace(mPostReplaceFormat2, mPostReplaceFormat, PcdGet16 (PcdShellPrintBufferSize), L"%H", L"%%H", FALSE, FALSE);
|
jcarsey | 975136a | 2009-06-16 19:03:54 +0000 | [diff] [blame] | 2777 | ASSERT_EFI_ERROR(Status);
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 2778 | Status = ShellCopySearchAndReplace(mPostReplaceFormat, mPostReplaceFormat2, PcdGet16 (PcdShellPrintBufferSize), L"%B", L"%%B", FALSE, FALSE);
|
jcarsey | 975136a | 2009-06-16 19:03:54 +0000 | [diff] [blame] | 2779 | ASSERT_EFI_ERROR(Status);
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 2780 | Status = ShellCopySearchAndReplace(mPostReplaceFormat2, mPostReplaceFormat, PcdGet16 (PcdShellPrintBufferSize), L"%V", L"%%V", FALSE, FALSE);
|
jcarsey | 975136a | 2009-06-16 19:03:54 +0000 | [diff] [blame] | 2781 | ASSERT_EFI_ERROR(Status);
|
| 2782 |
|
| 2783 | //
|
| 2784 | // Use the last buffer from replacing to print from...
|
| 2785 | //
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 2786 | UnicodeVSPrint (mPostReplaceFormat2, PcdGet16 (PcdShellPrintBufferSize), mPostReplaceFormat, Marker);
|
jcarsey | b1f95a0 | 2009-06-16 00:23:19 +0000 | [diff] [blame] | 2787 |
|
| 2788 | if (Col != -1 && Row != -1) {
|
jcarsey | b1f95a0 | 2009-06-16 00:23:19 +0000 | [diff] [blame] | 2789 | Status = gST->ConOut->SetCursorPosition(gST->ConOut, Col, Row);
|
jcarsey | 975136a | 2009-06-16 19:03:54 +0000 | [diff] [blame] | 2790 | }
|
| 2791 |
|
jcarsey | ecd3d59 | 2009-12-07 18:05:00 +0000 | [diff] [blame] | 2792 | FormatWalker = mPostReplaceFormat2;
|
jcarsey | 2247dde | 2009-11-09 18:08:58 +0000 | [diff] [blame] | 2793 | while (*FormatWalker != CHAR_NULL) {
|
jcarsey | 975136a | 2009-06-16 19:03:54 +0000 | [diff] [blame] | 2794 | //
|
| 2795 | // Find the next attribute change request
|
| 2796 | //
|
| 2797 | ResumeLocation = StrStr(FormatWalker, L"%");
|
| 2798 | if (ResumeLocation != NULL) {
|
jcarsey | 2247dde | 2009-11-09 18:08:58 +0000 | [diff] [blame] | 2799 | *ResumeLocation = CHAR_NULL;
|
jcarsey | 975136a | 2009-06-16 19:03:54 +0000 | [diff] [blame] | 2800 | }
|
| 2801 | //
|
| 2802 | // print the current FormatWalker string
|
| 2803 | //
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 2804 | if (StrLen(FormatWalker)>0) {
|
| 2805 | Status = InternalPrintTo(FormatWalker);
|
| 2806 | if (EFI_ERROR(Status)) {
|
| 2807 | break;
|
| 2808 | }
|
| 2809 | }
|
| 2810 |
|
jcarsey | 975136a | 2009-06-16 19:03:54 +0000 | [diff] [blame] | 2811 | //
|
| 2812 | // update the attribute
|
| 2813 | //
|
| 2814 | if (ResumeLocation != NULL) {
|
jcarsey | 5d46f17 | 2011-08-23 15:34:23 +0000 | [diff] [blame] | 2815 | if (*(ResumeLocation-1) == L'^') {
|
| 2816 | //
|
jcarsey | 8bb7441 | 2012-01-30 18:44:41 +0000 | [diff] [blame] | 2817 | // Move cursor back 1 position to overwrite the ^
|
| 2818 | //
|
| 2819 | gST->ConOut->SetCursorPosition(gST->ConOut, gST->ConOut->Mode->CursorColumn - 1, gST->ConOut->Mode->CursorRow);
|
| 2820 |
|
| 2821 | //
|
jcarsey | 5d46f17 | 2011-08-23 15:34:23 +0000 | [diff] [blame] | 2822 | // Print a simple '%' symbol
|
| 2823 | //
|
| 2824 | Status = InternalPrintTo(L"%");
|
| 2825 | ResumeLocation = ResumeLocation - 1;
|
| 2826 | } else {
|
| 2827 | switch (*(ResumeLocation+1)) {
|
| 2828 | case (L'N'):
|
| 2829 | gST->ConOut->SetAttribute(gST->ConOut, OriginalAttribute);
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 2830 | break;
|
jcarsey | 5d46f17 | 2011-08-23 15:34:23 +0000 | [diff] [blame] | 2831 | case (L'E'):
|
| 2832 | gST->ConOut->SetAttribute(gST->ConOut, EFI_TEXT_ATTR(EFI_YELLOW, ((OriginalAttribute&(BIT4|BIT5|BIT6))>>4)));
|
| 2833 | break;
|
| 2834 | case (L'H'):
|
| 2835 | gST->ConOut->SetAttribute(gST->ConOut, EFI_TEXT_ATTR(EFI_WHITE, ((OriginalAttribute&(BIT4|BIT5|BIT6))>>4)));
|
| 2836 | break;
|
| 2837 | case (L'B'):
|
| 2838 | gST->ConOut->SetAttribute(gST->ConOut, EFI_TEXT_ATTR(EFI_BLUE, ((OriginalAttribute&(BIT4|BIT5|BIT6))>>4)));
|
| 2839 | break;
|
| 2840 | case (L'V'):
|
| 2841 | gST->ConOut->SetAttribute(gST->ConOut, EFI_TEXT_ATTR(EFI_GREEN, ((OriginalAttribute&(BIT4|BIT5|BIT6))>>4)));
|
| 2842 | break;
|
| 2843 | default:
|
| 2844 | //
|
| 2845 | // Print a simple '%' symbol
|
| 2846 | //
|
| 2847 | Status = InternalPrintTo(L"%");
|
| 2848 | if (EFI_ERROR(Status)) {
|
| 2849 | break;
|
| 2850 | }
|
| 2851 | ResumeLocation = ResumeLocation - 1;
|
| 2852 | break;
|
| 2853 | }
|
jcarsey | 975136a | 2009-06-16 19:03:54 +0000 | [diff] [blame] | 2854 | }
|
| 2855 | } else {
|
| 2856 | //
|
| 2857 | // reset to normal now...
|
| 2858 | //
|
jcarsey | 975136a | 2009-06-16 19:03:54 +0000 | [diff] [blame] | 2859 | break;
|
| 2860 | }
|
| 2861 |
|
| 2862 | //
|
| 2863 | // update FormatWalker to Resume + 2 (skip the % and the indicator)
|
| 2864 | //
|
| 2865 | FormatWalker = ResumeLocation + 2;
|
| 2866 | }
|
jcarsey | b1f95a0 | 2009-06-16 00:23:19 +0000 | [diff] [blame] | 2867 |
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 2868 | gST->ConOut->SetAttribute(gST->ConOut, OriginalAttribute);
|
jcarsey | 89e8537 | 2011-04-13 23:37:50 +0000 | [diff] [blame] | 2869 |
|
| 2870 | SHELL_FREE_NON_NULL(mPostReplaceFormat);
|
| 2871 | SHELL_FREE_NON_NULL(mPostReplaceFormat2);
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 2872 | return (Status);
|
jcarsey | 5f7431d | 2009-07-10 18:06:01 +0000 | [diff] [blame] | 2873 | }
|
jcarsey | 2247dde | 2009-11-09 18:08:58 +0000 | [diff] [blame] | 2874 |
|
| 2875 | /**
|
| 2876 | Print at a specific location on the screen.
|
| 2877 |
|
jcarsey | e2f8297 | 2009-12-01 05:40:24 +0000 | [diff] [blame] | 2878 | This function will move the cursor to a given screen location and print the specified string.
|
jcarsey | 1e6e84c | 2010-01-25 20:05:08 +0000 | [diff] [blame] | 2879 |
|
| 2880 | If -1 is specified for either the Row or Col the current screen location for BOTH
|
jcarsey | 2247dde | 2009-11-09 18:08:58 +0000 | [diff] [blame] | 2881 | will be used.
|
| 2882 |
|
jcarsey | e2f8297 | 2009-12-01 05:40:24 +0000 | [diff] [blame] | 2883 | If either Row or Col is out of range for the current console, then ASSERT.
|
| 2884 | If Format is NULL, then ASSERT.
|
jcarsey | 2247dde | 2009-11-09 18:08:58 +0000 | [diff] [blame] | 2885 |
|
jcarsey | 1e6e84c | 2010-01-25 20:05:08 +0000 | [diff] [blame] | 2886 | In addition to the standard %-based flags as supported by UefiLib Print() this supports
|
jcarsey | 2247dde | 2009-11-09 18:08:58 +0000 | [diff] [blame] | 2887 | the following additional flags:
|
| 2888 | %N - Set output attribute to normal
|
| 2889 | %H - Set output attribute to highlight
|
| 2890 | %E - Set output attribute to error
|
| 2891 | %B - Set output attribute to blue color
|
| 2892 | %V - Set output attribute to green color
|
| 2893 |
|
| 2894 | Note: The background color is controlled by the shell command cls.
|
| 2895 |
|
jcarsey | 2247dde | 2009-11-09 18:08:58 +0000 | [diff] [blame] | 2896 | @param[in] Col the column to print at
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 2897 | @param[in] Row the row to print at
|
jcarsey | 2247dde | 2009-11-09 18:08:58 +0000 | [diff] [blame] | 2898 | @param[in] Format the format string
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 2899 | @param[in] ... The variable argument list.
|
jcarsey | 2247dde | 2009-11-09 18:08:58 +0000 | [diff] [blame] | 2900 |
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 2901 | @return EFI_SUCCESS The printing was successful.
|
| 2902 | @return EFI_DEVICE_ERROR The console device reported an error.
|
jcarsey | 2247dde | 2009-11-09 18:08:58 +0000 | [diff] [blame] | 2903 | **/
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 2904 | EFI_STATUS
|
jcarsey | 2247dde | 2009-11-09 18:08:58 +0000 | [diff] [blame] | 2905 | EFIAPI
|
| 2906 | ShellPrintEx(
|
| 2907 | IN INT32 Col OPTIONAL,
|
| 2908 | IN INT32 Row OPTIONAL,
|
| 2909 | IN CONST CHAR16 *Format,
|
| 2910 | ...
|
jcarsey | 1e6e84c | 2010-01-25 20:05:08 +0000 | [diff] [blame] | 2911 | )
|
jcarsey | 2247dde | 2009-11-09 18:08:58 +0000 | [diff] [blame] | 2912 | {
|
| 2913 | VA_LIST Marker;
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 2914 | EFI_STATUS RetVal;
|
jcarsey | 3e082d5 | 2010-10-04 16:44:57 +0000 | [diff] [blame] | 2915 | if (Format == NULL) {
|
| 2916 | return (EFI_INVALID_PARAMETER);
|
| 2917 | }
|
jcarsey | 2247dde | 2009-11-09 18:08:58 +0000 | [diff] [blame] | 2918 | VA_START (Marker, Format);
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 2919 | RetVal = InternalShellPrintWorker(Col, Row, Format, Marker);
|
jcarsey | e2f8297 | 2009-12-01 05:40:24 +0000 | [diff] [blame] | 2920 | VA_END(Marker);
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 2921 | return(RetVal);
|
jcarsey | 2247dde | 2009-11-09 18:08:58 +0000 | [diff] [blame] | 2922 | }
|
| 2923 |
|
| 2924 | /**
|
| 2925 | Print at a specific location on the screen.
|
| 2926 |
|
jcarsey | e2f8297 | 2009-12-01 05:40:24 +0000 | [diff] [blame] | 2927 | This function will move the cursor to a given screen location and print the specified string.
|
jcarsey | 1e6e84c | 2010-01-25 20:05:08 +0000 | [diff] [blame] | 2928 |
|
| 2929 | If -1 is specified for either the Row or Col the current screen location for BOTH
|
jcarsey | e2f8297 | 2009-12-01 05:40:24 +0000 | [diff] [blame] | 2930 | will be used.
|
jcarsey | 2247dde | 2009-11-09 18:08:58 +0000 | [diff] [blame] | 2931 |
|
jcarsey | e2f8297 | 2009-12-01 05:40:24 +0000 | [diff] [blame] | 2932 | If either Row or Col is out of range for the current console, then ASSERT.
|
| 2933 | If Format is NULL, then ASSERT.
|
jcarsey | 2247dde | 2009-11-09 18:08:58 +0000 | [diff] [blame] | 2934 |
|
jcarsey | 1e6e84c | 2010-01-25 20:05:08 +0000 | [diff] [blame] | 2935 | In addition to the standard %-based flags as supported by UefiLib Print() this supports
|
jcarsey | 2247dde | 2009-11-09 18:08:58 +0000 | [diff] [blame] | 2936 | the following additional flags:
|
jcarsey | 1e6e84c | 2010-01-25 20:05:08 +0000 | [diff] [blame] | 2937 | %N - Set output attribute to normal.
|
| 2938 | %H - Set output attribute to highlight.
|
| 2939 | %E - Set output attribute to error.
|
| 2940 | %B - Set output attribute to blue color.
|
| 2941 | %V - Set output attribute to green color.
|
jcarsey | 2247dde | 2009-11-09 18:08:58 +0000 | [diff] [blame] | 2942 |
|
| 2943 | Note: The background color is controlled by the shell command cls.
|
| 2944 |
|
jcarsey | 1e6e84c | 2010-01-25 20:05:08 +0000 | [diff] [blame] | 2945 | @param[in] Col The column to print at.
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 2946 | @param[in] Row The row to print at.
|
jcarsey | 1e6e84c | 2010-01-25 20:05:08 +0000 | [diff] [blame] | 2947 | @param[in] Language The language of the string to retrieve. If this parameter
|
| 2948 | is NULL, then the current platform language is used.
|
| 2949 | @param[in] HiiFormatStringId The format string Id for getting from Hii.
|
| 2950 | @param[in] HiiFormatHandle The format string Handle for getting from Hii.
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 2951 | @param[in] ... The variable argument list.
|
jcarsey | 2247dde | 2009-11-09 18:08:58 +0000 | [diff] [blame] | 2952 |
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 2953 | @return EFI_SUCCESS The printing was successful.
|
| 2954 | @return EFI_DEVICE_ERROR The console device reported an error.
|
jcarsey | 2247dde | 2009-11-09 18:08:58 +0000 | [diff] [blame] | 2955 | **/
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 2956 | EFI_STATUS
|
jcarsey | 2247dde | 2009-11-09 18:08:58 +0000 | [diff] [blame] | 2957 | EFIAPI
|
| 2958 | ShellPrintHiiEx(
|
| 2959 | IN INT32 Col OPTIONAL,
|
| 2960 | IN INT32 Row OPTIONAL,
|
jcarsey | 1e6e84c | 2010-01-25 20:05:08 +0000 | [diff] [blame] | 2961 | IN CONST CHAR8 *Language OPTIONAL,
|
jcarsey | 2247dde | 2009-11-09 18:08:58 +0000 | [diff] [blame] | 2962 | IN CONST EFI_STRING_ID HiiFormatStringId,
|
| 2963 | IN CONST EFI_HANDLE HiiFormatHandle,
|
| 2964 | ...
|
| 2965 | )
|
| 2966 | {
|
| 2967 | VA_LIST Marker;
|
| 2968 | CHAR16 *HiiFormatString;
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 2969 | EFI_STATUS RetVal;
|
jcarsey | 2247dde | 2009-11-09 18:08:58 +0000 | [diff] [blame] | 2970 |
|
| 2971 | VA_START (Marker, HiiFormatHandle);
|
jcarsey | 1e6e84c | 2010-01-25 20:05:08 +0000 | [diff] [blame] | 2972 | HiiFormatString = HiiGetString(HiiFormatHandle, HiiFormatStringId, Language);
|
jcarsey | 2247dde | 2009-11-09 18:08:58 +0000 | [diff] [blame] | 2973 | ASSERT(HiiFormatString != NULL);
|
| 2974 |
|
| 2975 | RetVal = InternalShellPrintWorker(Col, Row, HiiFormatString, Marker);
|
| 2976 |
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 2977 | SHELL_FREE_NON_NULL(HiiFormatString);
|
jcarsey | e2f8297 | 2009-12-01 05:40:24 +0000 | [diff] [blame] | 2978 | VA_END(Marker);
|
jcarsey | 2247dde | 2009-11-09 18:08:58 +0000 | [diff] [blame] | 2979 |
|
| 2980 | return (RetVal);
|
| 2981 | }
|
| 2982 |
|
| 2983 | /**
|
| 2984 | Function to determine if a given filename represents a file or a directory.
|
| 2985 |
|
| 2986 | @param[in] DirName Path to directory to test.
|
| 2987 |
|
jcarsey | c8c2259 | 2011-10-17 17:49:21 +0000 | [diff] [blame] | 2988 | @retval EFI_SUCCESS The Path represents a directory
|
| 2989 | @retval EFI_NOT_FOUND The Path does not represent a directory
|
| 2990 | @retval EFI_OUT_OF_RESOURCES A memory allocation failed.
|
| 2991 | @return The path failed to open
|
jcarsey | 2247dde | 2009-11-09 18:08:58 +0000 | [diff] [blame] | 2992 | **/
|
| 2993 | EFI_STATUS
|
| 2994 | EFIAPI
|
| 2995 | ShellIsDirectory(
|
| 2996 | IN CONST CHAR16 *DirName
|
| 2997 | )
|
| 2998 | {
|
| 2999 | EFI_STATUS Status;
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 3000 | SHELL_FILE_HANDLE Handle;
|
jcarsey | 3e082d5 | 2010-10-04 16:44:57 +0000 | [diff] [blame] | 3001 | CHAR16 *TempLocation;
|
| 3002 | CHAR16 *TempLocation2;
|
jcarsey | 2247dde | 2009-11-09 18:08:58 +0000 | [diff] [blame] | 3003 |
|
jcarsey | ecd3d59 | 2009-12-07 18:05:00 +0000 | [diff] [blame] | 3004 | ASSERT(DirName != NULL);
|
| 3005 |
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 3006 | Handle = NULL;
|
| 3007 | TempLocation = NULL;
|
jcarsey | 2247dde | 2009-11-09 18:08:58 +0000 | [diff] [blame] | 3008 |
|
| 3009 | Status = ShellOpenFileByName(DirName, &Handle, EFI_FILE_MODE_READ, 0);
|
| 3010 | if (EFI_ERROR(Status)) {
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 3011 | //
|
| 3012 | // try good logic first.
|
| 3013 | //
|
jcarsey | 366f81a | 2011-06-27 21:04:22 +0000 | [diff] [blame] | 3014 | if (gEfiShellProtocol != NULL) {
|
jcarsey | 3e082d5 | 2010-10-04 16:44:57 +0000 | [diff] [blame] | 3015 | TempLocation = StrnCatGrow(&TempLocation, NULL, DirName, 0);
|
jcarsey | c8c2259 | 2011-10-17 17:49:21 +0000 | [diff] [blame] | 3016 | if (TempLocation == NULL) {
|
| 3017 | ShellCloseFile(&Handle);
|
| 3018 | return (EFI_OUT_OF_RESOURCES);
|
| 3019 | }
|
jcarsey | 3e082d5 | 2010-10-04 16:44:57 +0000 | [diff] [blame] | 3020 | TempLocation2 = StrStr(TempLocation, L":");
|
| 3021 | if (TempLocation2 != NULL && StrLen(StrStr(TempLocation, L":")) == 2) {
|
| 3022 | *(TempLocation2+1) = CHAR_NULL;
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 3023 | }
|
jcarsey | 366f81a | 2011-06-27 21:04:22 +0000 | [diff] [blame] | 3024 | if (gEfiShellProtocol->GetDevicePathFromMap(TempLocation) != NULL) {
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 3025 | FreePool(TempLocation);
|
| 3026 | return (EFI_SUCCESS);
|
| 3027 | }
|
| 3028 | FreePool(TempLocation);
|
| 3029 | } else {
|
| 3030 | //
|
| 3031 | // probably a map name?!?!!?
|
| 3032 | //
|
| 3033 | TempLocation = StrStr(DirName, L"\\");
|
| 3034 | if (TempLocation != NULL && *(TempLocation+1) == CHAR_NULL) {
|
| 3035 | return (EFI_SUCCESS);
|
| 3036 | }
|
| 3037 | }
|
jcarsey | 2247dde | 2009-11-09 18:08:58 +0000 | [diff] [blame] | 3038 | return (Status);
|
| 3039 | }
|
| 3040 |
|
| 3041 | if (FileHandleIsDirectory(Handle) == EFI_SUCCESS) {
|
| 3042 | ShellCloseFile(&Handle);
|
| 3043 | return (EFI_SUCCESS);
|
| 3044 | }
|
| 3045 | ShellCloseFile(&Handle);
|
| 3046 | return (EFI_NOT_FOUND);
|
| 3047 | }
|
| 3048 |
|
jcarsey | 125c2cf | 2009-11-18 21:36:50 +0000 | [diff] [blame] | 3049 | /**
|
jcarsey | 36a9d67 | 2009-11-20 21:13:41 +0000 | [diff] [blame] | 3050 | Function to determine if a given filename represents a file.
|
| 3051 |
|
| 3052 | @param[in] Name Path to file to test.
|
| 3053 |
|
| 3054 | @retval EFI_SUCCESS The Path represents a file.
|
| 3055 | @retval EFI_NOT_FOUND The Path does not represent a file.
|
| 3056 | @retval other The path failed to open.
|
| 3057 | **/
|
| 3058 | EFI_STATUS
|
| 3059 | EFIAPI
|
| 3060 | ShellIsFile(
|
| 3061 | IN CONST CHAR16 *Name
|
| 3062 | )
|
| 3063 | {
|
| 3064 | EFI_STATUS Status;
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 3065 | SHELL_FILE_HANDLE Handle;
|
jcarsey | 36a9d67 | 2009-11-20 21:13:41 +0000 | [diff] [blame] | 3066 |
|
jcarsey | ecd3d59 | 2009-12-07 18:05:00 +0000 | [diff] [blame] | 3067 | ASSERT(Name != NULL);
|
| 3068 |
|
jcarsey | 36a9d67 | 2009-11-20 21:13:41 +0000 | [diff] [blame] | 3069 | Handle = NULL;
|
| 3070 |
|
| 3071 | Status = ShellOpenFileByName(Name, &Handle, EFI_FILE_MODE_READ, 0);
|
| 3072 | if (EFI_ERROR(Status)) {
|
| 3073 | return (Status);
|
| 3074 | }
|
| 3075 |
|
| 3076 | if (FileHandleIsDirectory(Handle) != EFI_SUCCESS) {
|
| 3077 | ShellCloseFile(&Handle);
|
| 3078 | return (EFI_SUCCESS);
|
| 3079 | }
|
| 3080 | ShellCloseFile(&Handle);
|
| 3081 | return (EFI_NOT_FOUND);
|
| 3082 | }
|
| 3083 |
|
| 3084 | /**
|
jcarsey | b3011f4 | 2010-01-11 21:49:04 +0000 | [diff] [blame] | 3085 | Function to determine if a given filename represents a file.
|
| 3086 |
|
| 3087 | This will search the CWD and then the Path.
|
| 3088 |
|
| 3089 | If Name is NULL, then ASSERT.
|
| 3090 |
|
| 3091 | @param[in] Name Path to file to test.
|
| 3092 |
|
| 3093 | @retval EFI_SUCCESS The Path represents a file.
|
| 3094 | @retval EFI_NOT_FOUND The Path does not represent a file.
|
| 3095 | @retval other The path failed to open.
|
| 3096 | **/
|
| 3097 | EFI_STATUS
|
| 3098 | EFIAPI
|
| 3099 | ShellIsFileInPath(
|
| 3100 | IN CONST CHAR16 *Name
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 3101 | )
|
| 3102 | {
|
jcarsey | b3011f4 | 2010-01-11 21:49:04 +0000 | [diff] [blame] | 3103 | CHAR16 *NewName;
|
| 3104 | EFI_STATUS Status;
|
| 3105 |
|
| 3106 | if (!EFI_ERROR(ShellIsFile(Name))) {
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 3107 | return (EFI_SUCCESS);
|
jcarsey | b3011f4 | 2010-01-11 21:49:04 +0000 | [diff] [blame] | 3108 | }
|
| 3109 |
|
| 3110 | NewName = ShellFindFilePath(Name);
|
| 3111 | if (NewName == NULL) {
|
| 3112 | return (EFI_NOT_FOUND);
|
| 3113 | }
|
| 3114 | Status = ShellIsFile(NewName);
|
| 3115 | FreePool(NewName);
|
| 3116 | return (Status);
|
| 3117 | }
|
jcarsey | 252d945 | 2011-03-25 20:49:53 +0000 | [diff] [blame] | 3118 |
|
jcarsey | b3011f4 | 2010-01-11 21:49:04 +0000 | [diff] [blame] | 3119 | /**
|
Jaben Carsey | 74b0fb8 | 2013-11-22 21:37:34 +0000 | [diff] [blame] | 3120 | Function return the number converted from a hex representation of a number.
|
| 3121 |
|
| 3122 | Note: this function cannot be used when (UINTN)(-1), (0xFFFFFFFF) may be a valid
|
| 3123 | result. Use ShellConvertStringToUint64 instead.
|
| 3124 |
|
| 3125 | @param[in] String String representation of a number.
|
| 3126 |
|
| 3127 | @return The unsigned integer result of the conversion.
|
| 3128 | @retval (UINTN)(-1) An error occured.
|
| 3129 | **/
|
| 3130 | UINTN
|
| 3131 | EFIAPI
|
| 3132 | ShellHexStrToUintn(
|
| 3133 | IN CONST CHAR16 *String
|
| 3134 | )
|
| 3135 | {
|
| 3136 | UINT64 RetVal;
|
| 3137 |
|
| 3138 | if (!EFI_ERROR(ShellConvertStringToUint64(String, &RetVal, TRUE, TRUE))) {
|
| 3139 | return ((UINTN)RetVal);
|
| 3140 | }
|
| 3141 |
|
| 3142 | return ((UINTN)(-1));
|
| 3143 | }
|
| 3144 |
|
| 3145 | /**
|
jcarsey | 1e6e84c | 2010-01-25 20:05:08 +0000 | [diff] [blame] | 3146 | Function to determine whether a string is decimal or hex representation of a number
|
Jaben Carsey | d59fc24 | 2013-11-14 23:52:43 +0000 | [diff] [blame] | 3147 | and return the number converted from the string. Spaces are always skipped.
|
jcarsey | 125c2cf | 2009-11-18 21:36:50 +0000 | [diff] [blame] | 3148 |
|
| 3149 | @param[in] String String representation of a number
|
| 3150 |
|
jcarsey | 252d945 | 2011-03-25 20:49:53 +0000 | [diff] [blame] | 3151 | @return the number
|
| 3152 | @retval (UINTN)(-1) An error ocurred.
|
jcarsey | 125c2cf | 2009-11-18 21:36:50 +0000 | [diff] [blame] | 3153 | **/
|
| 3154 | UINTN
|
| 3155 | EFIAPI
|
| 3156 | ShellStrToUintn(
|
| 3157 | IN CONST CHAR16 *String
|
| 3158 | )
|
| 3159 | {
|
jcarsey | 252d945 | 2011-03-25 20:49:53 +0000 | [diff] [blame] | 3160 | UINT64 RetVal;
|
| 3161 | BOOLEAN Hex;
|
| 3162 |
|
| 3163 | Hex = FALSE;
|
| 3164 |
|
jcarsey | 658bf43 | 2014-11-04 22:33:16 +0000 | [diff] [blame] | 3165 | if (!InternalShellIsHexOrDecimalNumber(String, Hex, TRUE, FALSE)) {
|
jcarsey | 252d945 | 2011-03-25 20:49:53 +0000 | [diff] [blame] | 3166 | Hex = TRUE;
|
jcarsey | 125c2cf | 2009-11-18 21:36:50 +0000 | [diff] [blame] | 3167 | }
|
jcarsey | 252d945 | 2011-03-25 20:49:53 +0000 | [diff] [blame] | 3168 |
|
| 3169 | if (!EFI_ERROR(ShellConvertStringToUint64(String, &RetVal, Hex, TRUE))) {
|
| 3170 | return ((UINTN)RetVal);
|
| 3171 | }
|
| 3172 | return ((UINTN)(-1));
|
jcarsey | 125c2cf | 2009-11-18 21:36:50 +0000 | [diff] [blame] | 3173 | }
|
| 3174 |
|
| 3175 | /**
|
| 3176 | Safely append with automatic string resizing given length of Destination and
|
| 3177 | desired length of copy from Source.
|
| 3178 |
|
| 3179 | append the first D characters of Source to the end of Destination, where D is
|
| 3180 | the lesser of Count and the StrLen() of Source. If appending those D characters
|
| 3181 | will fit within Destination (whose Size is given as CurrentSize) and
|
jcarsey | 1e6e84c | 2010-01-25 20:05:08 +0000 | [diff] [blame] | 3182 | still leave room for a NULL terminator, then those characters are appended,
|
| 3183 | starting at the original terminating NULL of Destination, and a new terminating
|
| 3184 | NULL is appended.
|
jcarsey | 125c2cf | 2009-11-18 21:36:50 +0000 | [diff] [blame] | 3185 |
|
| 3186 | If appending D characters onto Destination will result in a overflow of the size
|
| 3187 | given in CurrentSize the string will be grown such that the copy can be performed
|
| 3188 | and CurrentSize will be updated to the new size.
|
| 3189 |
|
| 3190 | If Source is NULL, there is nothing to append, just return the current buffer in
|
| 3191 | Destination.
|
| 3192 |
|
| 3193 | if Destination is NULL, then ASSERT()
|
| 3194 | if Destination's current length (including NULL terminator) is already more then
|
| 3195 | CurrentSize, then ASSERT()
|
| 3196 |
|
ydong10 | 4ff7e37 | 2011-09-02 08:05:34 +0000 | [diff] [blame] | 3197 | @param[in, out] Destination The String to append onto
|
| 3198 | @param[in, out] CurrentSize on call the number of bytes in Destination. On
|
jcarsey | 125c2cf | 2009-11-18 21:36:50 +0000 | [diff] [blame] | 3199 | return possibly the new size (still in bytes). if NULL
|
| 3200 | then allocate whatever is needed.
|
| 3201 | @param[in] Source The String to append from
|
| 3202 | @param[in] Count Maximum number of characters to append. if 0 then
|
| 3203 | all are appended.
|
| 3204 |
|
| 3205 | @return Destination return the resultant string.
|
| 3206 | **/
|
| 3207 | CHAR16*
|
| 3208 | EFIAPI
|
| 3209 | StrnCatGrow (
|
| 3210 | IN OUT CHAR16 **Destination,
|
| 3211 | IN OUT UINTN *CurrentSize,
|
| 3212 | IN CONST CHAR16 *Source,
|
| 3213 | IN UINTN Count
|
| 3214 | )
|
| 3215 | {
|
| 3216 | UINTN DestinationStartSize;
|
| 3217 | UINTN NewSize;
|
| 3218 |
|
| 3219 | //
|
| 3220 | // ASSERTs
|
| 3221 | //
|
| 3222 | ASSERT(Destination != NULL);
|
| 3223 |
|
| 3224 | //
|
| 3225 | // If there's nothing to do then just return Destination
|
| 3226 | //
|
| 3227 | if (Source == NULL) {
|
| 3228 | return (*Destination);
|
| 3229 | }
|
| 3230 |
|
| 3231 | //
|
| 3232 | // allow for un-initialized pointers, based on size being 0
|
| 3233 | //
|
| 3234 | if (CurrentSize != NULL && *CurrentSize == 0) {
|
| 3235 | *Destination = NULL;
|
| 3236 | }
|
| 3237 |
|
| 3238 | //
|
| 3239 | // allow for NULL pointers address as Destination
|
| 3240 | //
|
| 3241 | if (*Destination != NULL) {
|
| 3242 | ASSERT(CurrentSize != 0);
|
| 3243 | DestinationStartSize = StrSize(*Destination);
|
| 3244 | ASSERT(DestinationStartSize <= *CurrentSize);
|
| 3245 | } else {
|
| 3246 | DestinationStartSize = 0;
|
| 3247 | // ASSERT(*CurrentSize == 0);
|
| 3248 | }
|
| 3249 |
|
| 3250 | //
|
| 3251 | // Append all of Source?
|
| 3252 | //
|
| 3253 | if (Count == 0) {
|
| 3254 | Count = StrLen(Source);
|
| 3255 | }
|
| 3256 |
|
| 3257 | //
|
| 3258 | // Test and grow if required
|
| 3259 | //
|
| 3260 | if (CurrentSize != NULL) {
|
| 3261 | NewSize = *CurrentSize;
|
ydong10 | f480fdc | 2012-09-07 01:55:33 +0000 | [diff] [blame] | 3262 | if (NewSize < DestinationStartSize + (Count * sizeof(CHAR16))) {
|
| 3263 | while (NewSize < (DestinationStartSize + (Count*sizeof(CHAR16)))) {
|
| 3264 | NewSize += 2 * Count * sizeof(CHAR16);
|
| 3265 | }
|
| 3266 | *Destination = ReallocatePool(*CurrentSize, NewSize, *Destination);
|
| 3267 | *CurrentSize = NewSize;
|
jcarsey | 125c2cf | 2009-11-18 21:36:50 +0000 | [diff] [blame] | 3268 | }
|
jcarsey | 125c2cf | 2009-11-18 21:36:50 +0000 | [diff] [blame] | 3269 | } else {
|
Qiu Shumin | c587fd3 | 2015-07-02 01:12:03 +0000 | [diff] [blame] | 3270 | NewSize = (Count+1)*sizeof(CHAR16);
|
| 3271 | *Destination = AllocateZeroPool(NewSize);
|
jcarsey | 125c2cf | 2009-11-18 21:36:50 +0000 | [diff] [blame] | 3272 | }
|
| 3273 |
|
| 3274 | //
|
| 3275 | // Now use standard StrnCat on a big enough buffer
|
| 3276 | //
|
jcarsey | c9d92df | 2010-02-03 15:37:54 +0000 | [diff] [blame] | 3277 | if (*Destination == NULL) {
|
| 3278 | return (NULL);
|
| 3279 | }
|
Qiu Shumin | e75390f | 2015-06-30 03:18:31 +0000 | [diff] [blame] | 3280 |
|
Qiu Shumin | c587fd3 | 2015-07-02 01:12:03 +0000 | [diff] [blame] | 3281 | StrnCatS(*Destination, NewSize/sizeof(CHAR16), Source, Count);
|
Qiu Shumin | e75390f | 2015-06-30 03:18:31 +0000 | [diff] [blame] | 3282 | return *Destination;
|
jcarsey | 125c2cf | 2009-11-18 21:36:50 +0000 | [diff] [blame] | 3283 | }
|
jcarsey | c9d92df | 2010-02-03 15:37:54 +0000 | [diff] [blame] | 3284 |
|
| 3285 | /**
|
| 3286 | Prompt the user and return the resultant answer to the requestor.
|
| 3287 |
|
| 3288 | This function will display the requested question on the shell prompt and then
|
Mudusuru, Giri P | 1d32246 | 2016-07-07 00:47:45 -0700 | [diff] [blame] | 3289 | wait for an appropriate answer to be input from the console.
|
jcarsey | c9d92df | 2010-02-03 15:37:54 +0000 | [diff] [blame] | 3290 |
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 3291 | if the SHELL_PROMPT_REQUEST_TYPE is SHELL_PROMPT_REQUEST_TYPE_YESNO, ShellPromptResponseTypeQuitContinue
|
jcarsey | c9d92df | 2010-02-03 15:37:54 +0000 | [diff] [blame] | 3292 | or SHELL_PROMPT_REQUEST_TYPE_YESNOCANCEL then *Response is of type SHELL_PROMPT_RESPONSE.
|
| 3293 |
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 3294 | if the SHELL_PROMPT_REQUEST_TYPE is ShellPromptResponseTypeFreeform then *Response is of type
|
jcarsey | c9d92df | 2010-02-03 15:37:54 +0000 | [diff] [blame] | 3295 | CHAR16*.
|
| 3296 |
|
| 3297 | In either case *Response must be callee freed if Response was not NULL;
|
| 3298 |
|
| 3299 | @param Type What type of question is asked. This is used to filter the input
|
| 3300 | to prevent invalid answers to question.
|
| 3301 | @param Prompt Pointer to string prompt to use to request input.
|
| 3302 | @param Response Pointer to Response which will be populated upon return.
|
| 3303 |
|
| 3304 | @retval EFI_SUCCESS The operation was sucessful.
|
| 3305 | @retval EFI_UNSUPPORTED The operation is not supported as requested.
|
| 3306 | @retval EFI_INVALID_PARAMETER A parameter was invalid.
|
| 3307 | @return other The operation failed.
|
| 3308 | **/
|
| 3309 | EFI_STATUS
|
| 3310 | EFIAPI
|
| 3311 | ShellPromptForResponse (
|
| 3312 | IN SHELL_PROMPT_REQUEST_TYPE Type,
|
| 3313 | IN CHAR16 *Prompt OPTIONAL,
|
| 3314 | IN OUT VOID **Response OPTIONAL
|
| 3315 | )
|
| 3316 | {
|
| 3317 | EFI_STATUS Status;
|
| 3318 | EFI_INPUT_KEY Key;
|
| 3319 | UINTN EventIndex;
|
| 3320 | SHELL_PROMPT_RESPONSE *Resp;
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 3321 | UINTN Size;
|
| 3322 | CHAR16 *Buffer;
|
jcarsey | c9d92df | 2010-02-03 15:37:54 +0000 | [diff] [blame] | 3323 |
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 3324 | Status = EFI_UNSUPPORTED;
|
| 3325 | Resp = NULL;
|
| 3326 | Buffer = NULL;
|
| 3327 | Size = 0;
|
| 3328 | if (Type != ShellPromptResponseTypeFreeform) {
|
jcarsey | 252d945 | 2011-03-25 20:49:53 +0000 | [diff] [blame] | 3329 | Resp = (SHELL_PROMPT_RESPONSE*)AllocateZeroPool(sizeof(SHELL_PROMPT_RESPONSE));
|
jcarsey | 3e082d5 | 2010-10-04 16:44:57 +0000 | [diff] [blame] | 3330 | if (Resp == NULL) {
|
| 3331 | return (EFI_OUT_OF_RESOURCES);
|
| 3332 | }
|
xdu2 | 90bfa22 | 2010-07-19 05:21:27 +0000 | [diff] [blame] | 3333 | }
|
jcarsey | c9d92df | 2010-02-03 15:37:54 +0000 | [diff] [blame] | 3334 |
|
| 3335 | switch(Type) {
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 3336 | case ShellPromptResponseTypeQuitContinue:
|
jcarsey | c9d92df | 2010-02-03 15:37:54 +0000 | [diff] [blame] | 3337 | if (Prompt != NULL) {
|
| 3338 | ShellPrintEx(-1, -1, L"%s", Prompt);
|
| 3339 | }
|
| 3340 | //
|
| 3341 | // wait for valid response
|
| 3342 | //
|
| 3343 | gBS->WaitForEvent (1, &gST->ConIn->WaitForKey, &EventIndex);
|
| 3344 | Status = gST->ConIn->ReadKeyStroke (gST->ConIn, &Key);
|
Jaben Carsey | 31b018a | 2014-01-16 16:52:39 +0000 | [diff] [blame] | 3345 | if (EFI_ERROR(Status)) {
|
| 3346 | break;
|
| 3347 | }
|
jcarsey | c9d92df | 2010-02-03 15:37:54 +0000 | [diff] [blame] | 3348 | ShellPrintEx(-1, -1, L"%c", Key.UnicodeChar);
|
| 3349 | if (Key.UnicodeChar == L'Q' || Key.UnicodeChar ==L'q') {
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 3350 | *Resp = ShellPromptResponseQuit;
|
jcarsey | c9d92df | 2010-02-03 15:37:54 +0000 | [diff] [blame] | 3351 | } else {
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 3352 | *Resp = ShellPromptResponseContinue;
|
jcarsey | c9d92df | 2010-02-03 15:37:54 +0000 | [diff] [blame] | 3353 | }
|
| 3354 | break;
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 3355 | case ShellPromptResponseTypeYesNoCancel:
|
jcarsey | c9d92df | 2010-02-03 15:37:54 +0000 | [diff] [blame] | 3356 | if (Prompt != NULL) {
|
| 3357 | ShellPrintEx(-1, -1, L"%s", Prompt);
|
| 3358 | }
|
| 3359 | //
|
| 3360 | // wait for valid response
|
| 3361 | //
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 3362 | *Resp = ShellPromptResponseMax;
|
| 3363 | while (*Resp == ShellPromptResponseMax) {
|
Jaben Carsey | 194ae48 | 2013-12-09 22:55:13 +0000 | [diff] [blame] | 3364 | if (ShellGetExecutionBreakFlag()) {
|
| 3365 | Status = EFI_ABORTED;
|
| 3366 | break;
|
| 3367 | }
|
jcarsey | c9d92df | 2010-02-03 15:37:54 +0000 | [diff] [blame] | 3368 | gBS->WaitForEvent (1, &gST->ConIn->WaitForKey, &EventIndex);
|
| 3369 | Status = gST->ConIn->ReadKeyStroke (gST->ConIn, &Key);
|
Jaben Carsey | 31b018a | 2014-01-16 16:52:39 +0000 | [diff] [blame] | 3370 | if (EFI_ERROR(Status)) {
|
| 3371 | break;
|
| 3372 | }
|
jcarsey | c9d92df | 2010-02-03 15:37:54 +0000 | [diff] [blame] | 3373 | ShellPrintEx(-1, -1, L"%c", Key.UnicodeChar);
|
| 3374 | switch (Key.UnicodeChar) {
|
| 3375 | case L'Y':
|
| 3376 | case L'y':
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 3377 | *Resp = ShellPromptResponseYes;
|
jcarsey | c9d92df | 2010-02-03 15:37:54 +0000 | [diff] [blame] | 3378 | break;
|
| 3379 | case L'N':
|
| 3380 | case L'n':
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 3381 | *Resp = ShellPromptResponseNo;
|
jcarsey | c9d92df | 2010-02-03 15:37:54 +0000 | [diff] [blame] | 3382 | break;
|
| 3383 | case L'C':
|
| 3384 | case L'c':
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 3385 | *Resp = ShellPromptResponseCancel;
|
| 3386 | break;
|
| 3387 | }
|
| 3388 | }
|
| 3389 | break; case ShellPromptResponseTypeYesNoAllCancel:
|
| 3390 | if (Prompt != NULL) {
|
| 3391 | ShellPrintEx(-1, -1, L"%s", Prompt);
|
| 3392 | }
|
| 3393 | //
|
| 3394 | // wait for valid response
|
| 3395 | //
|
| 3396 | *Resp = ShellPromptResponseMax;
|
| 3397 | while (*Resp == ShellPromptResponseMax) {
|
Jaben Carsey | 194ae48 | 2013-12-09 22:55:13 +0000 | [diff] [blame] | 3398 | if (ShellGetExecutionBreakFlag()) {
|
| 3399 | Status = EFI_ABORTED;
|
| 3400 | break;
|
| 3401 | }
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 3402 | gBS->WaitForEvent (1, &gST->ConIn->WaitForKey, &EventIndex);
|
| 3403 | Status = gST->ConIn->ReadKeyStroke (gST->ConIn, &Key);
|
Jaben Carsey | 31b018a | 2014-01-16 16:52:39 +0000 | [diff] [blame] | 3404 | if (EFI_ERROR(Status)) {
|
| 3405 | break;
|
| 3406 | }
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 3407 | ShellPrintEx(-1, -1, L"%c", Key.UnicodeChar);
|
| 3408 | switch (Key.UnicodeChar) {
|
| 3409 | case L'Y':
|
| 3410 | case L'y':
|
| 3411 | *Resp = ShellPromptResponseYes;
|
| 3412 | break;
|
| 3413 | case L'N':
|
| 3414 | case L'n':
|
| 3415 | *Resp = ShellPromptResponseNo;
|
| 3416 | break;
|
| 3417 | case L'A':
|
| 3418 | case L'a':
|
| 3419 | *Resp = ShellPromptResponseAll;
|
| 3420 | break;
|
| 3421 | case L'C':
|
| 3422 | case L'c':
|
| 3423 | *Resp = ShellPromptResponseCancel;
|
jcarsey | c9d92df | 2010-02-03 15:37:54 +0000 | [diff] [blame] | 3424 | break;
|
| 3425 | }
|
| 3426 | }
|
| 3427 | break;
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 3428 | case ShellPromptResponseTypeEnterContinue:
|
| 3429 | case ShellPromptResponseTypeAnyKeyContinue:
|
jcarsey | c9d92df | 2010-02-03 15:37:54 +0000 | [diff] [blame] | 3430 | if (Prompt != NULL) {
|
| 3431 | ShellPrintEx(-1, -1, L"%s", Prompt);
|
| 3432 | }
|
| 3433 | //
|
| 3434 | // wait for valid response
|
| 3435 | //
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 3436 | *Resp = ShellPromptResponseMax;
|
| 3437 | while (*Resp == ShellPromptResponseMax) {
|
Jaben Carsey | 194ae48 | 2013-12-09 22:55:13 +0000 | [diff] [blame] | 3438 | if (ShellGetExecutionBreakFlag()) {
|
| 3439 | Status = EFI_ABORTED;
|
| 3440 | break;
|
| 3441 | }
|
jcarsey | c9d92df | 2010-02-03 15:37:54 +0000 | [diff] [blame] | 3442 | gBS->WaitForEvent (1, &gST->ConIn->WaitForKey, &EventIndex);
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 3443 | if (Type == ShellPromptResponseTypeEnterContinue) {
|
jcarsey | c9d92df | 2010-02-03 15:37:54 +0000 | [diff] [blame] | 3444 | Status = gST->ConIn->ReadKeyStroke (gST->ConIn, &Key);
|
Jaben Carsey | 31b018a | 2014-01-16 16:52:39 +0000 | [diff] [blame] | 3445 | if (EFI_ERROR(Status)) {
|
| 3446 | break;
|
| 3447 | }
|
jcarsey | c9d92df | 2010-02-03 15:37:54 +0000 | [diff] [blame] | 3448 | ShellPrintEx(-1, -1, L"%c", Key.UnicodeChar);
|
| 3449 | if (Key.UnicodeChar == CHAR_CARRIAGE_RETURN) {
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 3450 | *Resp = ShellPromptResponseContinue;
|
jcarsey | c9d92df | 2010-02-03 15:37:54 +0000 | [diff] [blame] | 3451 | break;
|
| 3452 | }
|
| 3453 | }
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 3454 | if (Type == ShellPromptResponseTypeAnyKeyContinue) {
|
| 3455 | Status = gST->ConIn->ReadKeyStroke (gST->ConIn, &Key);
|
| 3456 | ASSERT_EFI_ERROR(Status);
|
| 3457 | *Resp = ShellPromptResponseContinue;
|
jcarsey | c9d92df | 2010-02-03 15:37:54 +0000 | [diff] [blame] | 3458 | break;
|
| 3459 | }
|
| 3460 | }
|
| 3461 | break;
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 3462 | case ShellPromptResponseTypeYesNo:
|
| 3463 | if (Prompt != NULL) {
|
| 3464 | ShellPrintEx(-1, -1, L"%s", Prompt);
|
| 3465 | }
|
| 3466 | //
|
| 3467 | // wait for valid response
|
| 3468 | //
|
| 3469 | *Resp = ShellPromptResponseMax;
|
| 3470 | while (*Resp == ShellPromptResponseMax) {
|
Jaben Carsey | 194ae48 | 2013-12-09 22:55:13 +0000 | [diff] [blame] | 3471 | if (ShellGetExecutionBreakFlag()) {
|
| 3472 | Status = EFI_ABORTED;
|
| 3473 | break;
|
| 3474 | }
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 3475 | gBS->WaitForEvent (1, &gST->ConIn->WaitForKey, &EventIndex);
|
| 3476 | Status = gST->ConIn->ReadKeyStroke (gST->ConIn, &Key);
|
Jaben Carsey | 31b018a | 2014-01-16 16:52:39 +0000 | [diff] [blame] | 3477 | if (EFI_ERROR(Status)) {
|
| 3478 | break;
|
| 3479 | }
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 3480 | ShellPrintEx(-1, -1, L"%c", Key.UnicodeChar);
|
| 3481 | switch (Key.UnicodeChar) {
|
| 3482 | case L'Y':
|
| 3483 | case L'y':
|
| 3484 | *Resp = ShellPromptResponseYes;
|
| 3485 | break;
|
| 3486 | case L'N':
|
| 3487 | case L'n':
|
| 3488 | *Resp = ShellPromptResponseNo;
|
| 3489 | break;
|
| 3490 | }
|
| 3491 | }
|
| 3492 | break;
|
| 3493 | case ShellPromptResponseTypeFreeform:
|
| 3494 | if (Prompt != NULL) {
|
| 3495 | ShellPrintEx(-1, -1, L"%s", Prompt);
|
| 3496 | }
|
| 3497 | while(1) {
|
Jaben Carsey | 194ae48 | 2013-12-09 22:55:13 +0000 | [diff] [blame] | 3498 | if (ShellGetExecutionBreakFlag()) {
|
| 3499 | Status = EFI_ABORTED;
|
| 3500 | break;
|
| 3501 | }
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 3502 | gBS->WaitForEvent (1, &gST->ConIn->WaitForKey, &EventIndex);
|
| 3503 | Status = gST->ConIn->ReadKeyStroke (gST->ConIn, &Key);
|
Jaben Carsey | 31b018a | 2014-01-16 16:52:39 +0000 | [diff] [blame] | 3504 | if (EFI_ERROR(Status)) {
|
| 3505 | break;
|
| 3506 | }
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 3507 | ShellPrintEx(-1, -1, L"%c", Key.UnicodeChar);
|
| 3508 | if (Key.UnicodeChar == CHAR_CARRIAGE_RETURN) {
|
| 3509 | break;
|
| 3510 | }
|
| 3511 | ASSERT((Buffer == NULL && Size == 0) || (Buffer != NULL));
|
| 3512 | StrnCatGrow(&Buffer, &Size, &Key.UnicodeChar, 1);
|
| 3513 | }
|
| 3514 | break;
|
| 3515 | //
|
| 3516 | // This is the location to add new prompt types.
|
Jaben Carsey | 194ae48 | 2013-12-09 22:55:13 +0000 | [diff] [blame] | 3517 | // If your new type loops remember to add ExecutionBreak support.
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 3518 | //
|
jcarsey | c9d92df | 2010-02-03 15:37:54 +0000 | [diff] [blame] | 3519 | default:
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 3520 | ASSERT(FALSE);
|
jcarsey | c9d92df | 2010-02-03 15:37:54 +0000 | [diff] [blame] | 3521 | }
|
| 3522 |
|
| 3523 | if (Response != NULL) {
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 3524 | if (Resp != NULL) {
|
| 3525 | *Response = Resp;
|
| 3526 | } else if (Buffer != NULL) {
|
| 3527 | *Response = Buffer;
|
| 3528 | }
|
jcarsey | c9d92df | 2010-02-03 15:37:54 +0000 | [diff] [blame] | 3529 | } else {
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 3530 | if (Resp != NULL) {
|
| 3531 | FreePool(Resp);
|
| 3532 | }
|
| 3533 | if (Buffer != NULL) {
|
| 3534 | FreePool(Buffer);
|
| 3535 | }
|
jcarsey | c9d92df | 2010-02-03 15:37:54 +0000 | [diff] [blame] | 3536 | }
|
| 3537 |
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 3538 | ShellPrintEx(-1, -1, L"\r\n");
|
jcarsey | c9d92df | 2010-02-03 15:37:54 +0000 | [diff] [blame] | 3539 | return (Status);
|
| 3540 | }
|
| 3541 |
|
| 3542 | /**
|
| 3543 | Prompt the user and return the resultant answer to the requestor.
|
| 3544 |
|
| 3545 | This function is the same as ShellPromptForResponse, except that the prompt is
|
| 3546 | automatically pulled from HII.
|
| 3547 |
|
| 3548 | @param Type What type of question is asked. This is used to filter the input
|
| 3549 | to prevent invalid answers to question.
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 3550 | @param[in] HiiFormatStringId The format string Id for getting from Hii.
|
| 3551 | @param[in] HiiFormatHandle The format string Handle for getting from Hii.
|
| 3552 | @param Response Pointer to Response which will be populated upon return.
|
jcarsey | c9d92df | 2010-02-03 15:37:54 +0000 | [diff] [blame] | 3553 |
|
| 3554 | @retval EFI_SUCCESS the operation was sucessful.
|
| 3555 | @return other the operation failed.
|
| 3556 |
|
| 3557 | @sa ShellPromptForResponse
|
| 3558 | **/
|
| 3559 | EFI_STATUS
|
| 3560 | EFIAPI
|
| 3561 | ShellPromptForResponseHii (
|
| 3562 | IN SHELL_PROMPT_REQUEST_TYPE Type,
|
| 3563 | IN CONST EFI_STRING_ID HiiFormatStringId,
|
| 3564 | IN CONST EFI_HANDLE HiiFormatHandle,
|
| 3565 | IN OUT VOID **Response
|
| 3566 | )
|
| 3567 | {
|
| 3568 | CHAR16 *Prompt;
|
| 3569 | EFI_STATUS Status;
|
| 3570 |
|
| 3571 | Prompt = HiiGetString(HiiFormatHandle, HiiFormatStringId, NULL);
|
| 3572 | Status = ShellPromptForResponse(Type, Prompt, Response);
|
| 3573 | FreePool(Prompt);
|
| 3574 | return (Status);
|
| 3575 | }
|
| 3576 |
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 3577 | /**
|
| 3578 | Function to determin if an entire string is a valid number.
|
jcarsey | c9d92df | 2010-02-03 15:37:54 +0000 | [diff] [blame] | 3579 |
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 3580 | If Hex it must be preceeded with a 0x or has ForceHex, set TRUE.
|
| 3581 |
|
| 3582 | @param[in] String The string to evaluate.
|
| 3583 | @param[in] ForceHex TRUE - always assume hex.
|
| 3584 | @param[in] StopAtSpace TRUE to halt upon finding a space, FALSE to keep going.
|
jcarsey | 658bf43 | 2014-11-04 22:33:16 +0000 | [diff] [blame] | 3585 | @param[in] TimeNumbers TRUE to allow numbers with ":", FALSE otherwise.
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 3586 |
|
| 3587 | @retval TRUE It is all numeric (dec/hex) characters.
|
| 3588 | @retval FALSE There is a non-numeric character.
|
| 3589 | **/
|
| 3590 | BOOLEAN
|
| 3591 | EFIAPI
|
jcarsey | 252d945 | 2011-03-25 20:49:53 +0000 | [diff] [blame] | 3592 | InternalShellIsHexOrDecimalNumber (
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 3593 | IN CONST CHAR16 *String,
|
| 3594 | IN CONST BOOLEAN ForceHex,
|
jcarsey | 658bf43 | 2014-11-04 22:33:16 +0000 | [diff] [blame] | 3595 | IN CONST BOOLEAN StopAtSpace,
|
| 3596 | IN CONST BOOLEAN TimeNumbers
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 3597 | )
|
| 3598 | {
|
| 3599 | BOOLEAN Hex;
|
| 3600 |
|
| 3601 | //
|
| 3602 | // chop off a single negative sign
|
| 3603 | //
|
| 3604 | if (String != NULL && *String == L'-') {
|
| 3605 | String++;
|
| 3606 | }
|
darylm503 | b0934ac | 2011-11-12 00:35:11 +0000 | [diff] [blame] | 3607 |
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 3608 | if (String == NULL) {
|
| 3609 | return (FALSE);
|
| 3610 | }
|
| 3611 |
|
| 3612 | //
|
| 3613 | // chop leading zeroes
|
| 3614 | //
|
| 3615 | while(String != NULL && *String == L'0'){
|
| 3616 | String++;
|
| 3617 | }
|
| 3618 | //
|
| 3619 | // allow '0x' or '0X', but not 'x' or 'X'
|
| 3620 | //
|
| 3621 | if (String != NULL && (*String == L'x' || *String == L'X')) {
|
| 3622 | if (*(String-1) != L'0') {
|
| 3623 | //
|
| 3624 | // we got an x without a preceeding 0
|
| 3625 | //
|
| 3626 | return (FALSE);
|
| 3627 | }
|
| 3628 | String++;
|
| 3629 | Hex = TRUE;
|
| 3630 | } else if (ForceHex) {
|
| 3631 | Hex = TRUE;
|
| 3632 | } else {
|
| 3633 | Hex = FALSE;
|
| 3634 | }
|
| 3635 |
|
| 3636 | //
|
| 3637 | // loop through the remaining characters and use the lib function
|
| 3638 | //
|
| 3639 | for ( ; String != NULL && *String != CHAR_NULL && !(StopAtSpace && *String == L' ') ; String++){
|
jcarsey | 658bf43 | 2014-11-04 22:33:16 +0000 | [diff] [blame] | 3640 | if (TimeNumbers && (String[0] == L':')) {
|
| 3641 | continue;
|
| 3642 | }
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 3643 | if (Hex) {
|
| 3644 | if (!ShellIsHexaDecimalDigitCharacter(*String)) {
|
| 3645 | return (FALSE);
|
| 3646 | }
|
| 3647 | } else {
|
| 3648 | if (!ShellIsDecimalDigitCharacter(*String)) {
|
| 3649 | return (FALSE);
|
| 3650 | }
|
| 3651 | }
|
| 3652 | }
|
jcarsey | 252d945 | 2011-03-25 20:49:53 +0000 | [diff] [blame] | 3653 |
|
jcarsey | a405b86 | 2010-09-14 05:18:09 +0000 | [diff] [blame] | 3654 | return (TRUE);
|
| 3655 | }
|
| 3656 |
|
| 3657 | /**
|
| 3658 | Function to determine if a given filename exists.
|
| 3659 |
|
| 3660 | @param[in] Name Path to test.
|
| 3661 |
|
| 3662 | @retval EFI_SUCCESS The Path represents a file.
|
| 3663 | @retval EFI_NOT_FOUND The Path does not represent a file.
|
| 3664 | @retval other The path failed to open.
|
| 3665 | **/
|
| 3666 | EFI_STATUS
|
| 3667 | EFIAPI
|
| 3668 | ShellFileExists(
|
| 3669 | IN CONST CHAR16 *Name
|
| 3670 | )
|
| 3671 | {
|
| 3672 | EFI_STATUS Status;
|
| 3673 | EFI_SHELL_FILE_INFO *List;
|
| 3674 |
|
| 3675 | ASSERT(Name != NULL);
|
| 3676 |
|
| 3677 | List = NULL;
|
| 3678 | Status = ShellOpenFileMetaArg((CHAR16*)Name, EFI_FILE_MODE_READ, &List);
|
| 3679 | if (EFI_ERROR(Status)) {
|
| 3680 | return (Status);
|
| 3681 | }
|
| 3682 |
|
| 3683 | ShellCloseFileMetaArg(&List);
|
| 3684 |
|
| 3685 | return (EFI_SUCCESS);
|
| 3686 | }
|
jcarsey | 252d945 | 2011-03-25 20:49:53 +0000 | [diff] [blame] | 3687 |
|
| 3688 | /**
|
darylm503 | b0934ac | 2011-11-12 00:35:11 +0000 | [diff] [blame] | 3689 | Convert a Unicode character to upper case only if
|
jcarsey | 252d945 | 2011-03-25 20:49:53 +0000 | [diff] [blame] | 3690 | it maps to a valid small-case ASCII character.
|
| 3691 |
|
| 3692 | This internal function only deal with Unicode character
|
| 3693 | which maps to a valid small-case ASCII character, i.e.
|
| 3694 | L'a' to L'z'. For other Unicode character, the input character
|
| 3695 | is returned directly.
|
| 3696 |
|
| 3697 | @param Char The character to convert.
|
| 3698 |
|
| 3699 | @retval LowerCharacter If the Char is with range L'a' to L'z'.
|
| 3700 | @retval Unchanged Otherwise.
|
| 3701 |
|
| 3702 | **/
|
| 3703 | CHAR16
|
| 3704 | EFIAPI
|
| 3705 | InternalShellCharToUpper (
|
| 3706 | IN CHAR16 Char
|
| 3707 | )
|
| 3708 | {
|
| 3709 | if (Char >= L'a' && Char <= L'z') {
|
| 3710 | return (CHAR16) (Char - (L'a' - L'A'));
|
| 3711 | }
|
| 3712 |
|
| 3713 | return Char;
|
| 3714 | }
|
| 3715 |
|
| 3716 | /**
|
| 3717 | Convert a Unicode character to numerical value.
|
| 3718 |
|
| 3719 | This internal function only deal with Unicode character
|
| 3720 | which maps to a valid hexadecimal ASII character, i.e.
|
darylm503 | b0934ac | 2011-11-12 00:35:11 +0000 | [diff] [blame] | 3721 | L'0' to L'9', L'a' to L'f' or L'A' to L'F'. For other
|
jcarsey | 252d945 | 2011-03-25 20:49:53 +0000 | [diff] [blame] | 3722 | Unicode character, the value returned does not make sense.
|
| 3723 |
|
| 3724 | @param Char The character to convert.
|
| 3725 |
|
| 3726 | @return The numerical value converted.
|
| 3727 |
|
| 3728 | **/
|
| 3729 | UINTN
|
| 3730 | EFIAPI
|
| 3731 | InternalShellHexCharToUintn (
|
| 3732 | IN CHAR16 Char
|
| 3733 | )
|
| 3734 | {
|
| 3735 | if (ShellIsDecimalDigitCharacter (Char)) {
|
| 3736 | return Char - L'0';
|
| 3737 | }
|
| 3738 |
|
| 3739 | return (UINTN) (10 + InternalShellCharToUpper (Char) - L'A');
|
| 3740 | }
|
| 3741 |
|
| 3742 | /**
|
| 3743 | Convert a Null-terminated Unicode hexadecimal string to a value of type UINT64.
|
| 3744 |
|
Jaben Carsey | 80f3e34 | 2015-07-02 17:26:42 +0000 | [diff] [blame] | 3745 | This function returns a value of type UINT64 by interpreting the contents
|
jcarsey | 252d945 | 2011-03-25 20:49:53 +0000 | [diff] [blame] | 3746 | of the Unicode string specified by String as a hexadecimal number.
|
| 3747 | The format of the input Unicode string String is:
|
| 3748 |
|
| 3749 | [spaces][zeros][x][hexadecimal digits].
|
| 3750 |
|
| 3751 | The valid hexadecimal digit character is in the range [0-9], [a-f] and [A-F].
|
| 3752 | The prefix "0x" is optional. Both "x" and "X" is allowed in "0x" prefix.
|
| 3753 | If "x" appears in the input string, it must be prefixed with at least one 0.
|
| 3754 | The function will ignore the pad space, which includes spaces or tab characters,
|
| 3755 | before [zeros], [x] or [hexadecimal digit]. The running zero before [x] or
|
| 3756 | [hexadecimal digit] will be ignored. Then, the decoding starts after [x] or the
|
| 3757 | first valid hexadecimal digit. Then, the function stops at the first character that is
|
| 3758 | a not a valid hexadecimal character or NULL, whichever one comes first.
|
| 3759 |
|
| 3760 | If String has only pad spaces, then zero is returned.
|
| 3761 | If String has no leading pad spaces, leading zeros or valid hexadecimal digits,
|
| 3762 | then zero is returned.
|
| 3763 |
|
| 3764 | @param[in] String A pointer to a Null-terminated Unicode string.
|
| 3765 | @param[out] Value Upon a successful return the value of the conversion.
|
| 3766 | @param[in] StopAtSpace FALSE to skip spaces.
|
| 3767 |
|
| 3768 | @retval EFI_SUCCESS The conversion was successful.
|
| 3769 | @retval EFI_INVALID_PARAMETER A parameter was NULL or invalid.
|
| 3770 | @retval EFI_DEVICE_ERROR An overflow occured.
|
| 3771 | **/
|
| 3772 | EFI_STATUS
|
| 3773 | EFIAPI
|
| 3774 | InternalShellStrHexToUint64 (
|
| 3775 | IN CONST CHAR16 *String,
|
| 3776 | OUT UINT64 *Value,
|
| 3777 | IN CONST BOOLEAN StopAtSpace
|
| 3778 | )
|
| 3779 | {
|
| 3780 | UINT64 Result;
|
| 3781 |
|
| 3782 | if (String == NULL || StrSize(String) == 0 || Value == NULL) {
|
| 3783 | return (EFI_INVALID_PARAMETER);
|
| 3784 | }
|
darylm503 | b0934ac | 2011-11-12 00:35:11 +0000 | [diff] [blame] | 3785 |
|
jcarsey | 252d945 | 2011-03-25 20:49:53 +0000 | [diff] [blame] | 3786 | //
|
darylm503 | b0934ac | 2011-11-12 00:35:11 +0000 | [diff] [blame] | 3787 | // Ignore the pad spaces (space or tab)
|
jcarsey | 252d945 | 2011-03-25 20:49:53 +0000 | [diff] [blame] | 3788 | //
|
| 3789 | while ((*String == L' ') || (*String == L'\t')) {
|
| 3790 | String++;
|
| 3791 | }
|
| 3792 |
|
| 3793 | //
|
| 3794 | // Ignore leading Zeros after the spaces
|
| 3795 | //
|
| 3796 | while (*String == L'0') {
|
| 3797 | String++;
|
| 3798 | }
|
| 3799 |
|
| 3800 | if (InternalShellCharToUpper (*String) == L'X') {
|
| 3801 | if (*(String - 1) != L'0') {
|
| 3802 | return 0;
|
| 3803 | }
|
| 3804 | //
|
| 3805 | // Skip the 'X'
|
| 3806 | //
|
| 3807 | String++;
|
| 3808 | }
|
| 3809 |
|
| 3810 | Result = 0;
|
darylm503 | b0934ac | 2011-11-12 00:35:11 +0000 | [diff] [blame] | 3811 |
|
jcarsey | 252d945 | 2011-03-25 20:49:53 +0000 | [diff] [blame] | 3812 | //
|
Jaben Carsey | 80f3e34 | 2015-07-02 17:26:42 +0000 | [diff] [blame] | 3813 | // there is a space where there should't be
|
jcarsey | 252d945 | 2011-03-25 20:49:53 +0000 | [diff] [blame] | 3814 | //
|
Jaben Carsey | 80f3e34 | 2015-07-02 17:26:42 +0000 | [diff] [blame] | 3815 | if (*String == L' ') {
|
| 3816 | return (EFI_INVALID_PARAMETER);
|
jcarsey | 252d945 | 2011-03-25 20:49:53 +0000 | [diff] [blame] | 3817 | }
|
darylm503 | b0934ac | 2011-11-12 00:35:11 +0000 | [diff] [blame] | 3818 |
|
jcarsey | 252d945 | 2011-03-25 20:49:53 +0000 | [diff] [blame] | 3819 | while (ShellIsHexaDecimalDigitCharacter (*String)) {
|
| 3820 | //
|
darylm503 | b0934ac | 2011-11-12 00:35:11 +0000 | [diff] [blame] | 3821 | // If the Hex Number represented by String overflows according
|
Jaben Carsey | 80f3e34 | 2015-07-02 17:26:42 +0000 | [diff] [blame] | 3822 | // to the range defined by UINT64, then return EFI_DEVICE_ERROR.
|
jcarsey | 252d945 | 2011-03-25 20:49:53 +0000 | [diff] [blame] | 3823 | //
|
| 3824 | if (!(Result <= (RShiftU64((((UINT64) ~0) - InternalShellHexCharToUintn (*String)), 4)))) {
|
| 3825 | // if (!(Result <= ((((UINT64) ~0) - InternalShellHexCharToUintn (*String)) >> 4))) {
|
| 3826 | return (EFI_DEVICE_ERROR);
|
| 3827 | }
|
| 3828 |
|
| 3829 | Result = (LShiftU64(Result, 4));
|
| 3830 | Result += InternalShellHexCharToUintn (*String);
|
| 3831 | String++;
|
| 3832 |
|
| 3833 | //
|
jcarsey | 49bd498 | 2012-01-27 18:42:43 +0000 | [diff] [blame] | 3834 | // stop at spaces if requested
|
jcarsey | 252d945 | 2011-03-25 20:49:53 +0000 | [diff] [blame] | 3835 | //
|
jcarsey | 49bd498 | 2012-01-27 18:42:43 +0000 | [diff] [blame] | 3836 | if (StopAtSpace && *String == L' ') {
|
| 3837 | break;
|
jcarsey | 252d945 | 2011-03-25 20:49:53 +0000 | [diff] [blame] | 3838 | }
|
| 3839 | }
|
| 3840 |
|
| 3841 | *Value = Result;
|
| 3842 | return (EFI_SUCCESS);
|
| 3843 | }
|
| 3844 |
|
| 3845 | /**
|
| 3846 | Convert a Null-terminated Unicode decimal string to a value of
|
| 3847 | type UINT64.
|
| 3848 |
|
| 3849 | This function returns a value of type UINT64 by interpreting the contents
|
| 3850 | of the Unicode string specified by String as a decimal number. The format
|
| 3851 | of the input Unicode string String is:
|
| 3852 |
|
| 3853 | [spaces] [decimal digits].
|
| 3854 |
|
| 3855 | The valid decimal digit character is in the range [0-9]. The
|
| 3856 | function will ignore the pad space, which includes spaces or
|
| 3857 | tab characters, before [decimal digits]. The running zero in the
|
| 3858 | beginning of [decimal digits] will be ignored. Then, the function
|
| 3859 | stops at the first character that is a not a valid decimal character
|
| 3860 | or a Null-terminator, whichever one comes first.
|
| 3861 |
|
| 3862 | If String has only pad spaces, then 0 is returned.
|
| 3863 | If String has no pad spaces or valid decimal digits,
|
| 3864 | then 0 is returned.
|
| 3865 |
|
| 3866 | @param[in] String A pointer to a Null-terminated Unicode string.
|
| 3867 | @param[out] Value Upon a successful return the value of the conversion.
|
| 3868 | @param[in] StopAtSpace FALSE to skip spaces.
|
| 3869 |
|
| 3870 | @retval EFI_SUCCESS The conversion was successful.
|
| 3871 | @retval EFI_INVALID_PARAMETER A parameter was NULL or invalid.
|
| 3872 | @retval EFI_DEVICE_ERROR An overflow occured.
|
| 3873 | **/
|
| 3874 | EFI_STATUS
|
| 3875 | EFIAPI
|
| 3876 | InternalShellStrDecimalToUint64 (
|
| 3877 | IN CONST CHAR16 *String,
|
| 3878 | OUT UINT64 *Value,
|
| 3879 | IN CONST BOOLEAN StopAtSpace
|
| 3880 | )
|
| 3881 | {
|
| 3882 | UINT64 Result;
|
| 3883 |
|
| 3884 | if (String == NULL || StrSize (String) == 0 || Value == NULL) {
|
| 3885 | return (EFI_INVALID_PARAMETER);
|
| 3886 | }
|
| 3887 |
|
| 3888 | //
|
| 3889 | // Ignore the pad spaces (space or tab)
|
| 3890 | //
|
| 3891 | while ((*String == L' ') || (*String == L'\t')) {
|
| 3892 | String++;
|
| 3893 | }
|
| 3894 |
|
| 3895 | //
|
| 3896 | // Ignore leading Zeros after the spaces
|
| 3897 | //
|
| 3898 | while (*String == L'0') {
|
| 3899 | String++;
|
| 3900 | }
|
| 3901 |
|
| 3902 | Result = 0;
|
| 3903 |
|
| 3904 | //
|
Jaben Carsey | 80f3e34 | 2015-07-02 17:26:42 +0000 | [diff] [blame] | 3905 | // Stop upon space if requested
|
| 3906 | // (if the whole value was 0)
|
jcarsey | 252d945 | 2011-03-25 20:49:53 +0000 | [diff] [blame] | 3907 | //
|
Jaben Carsey | 80f3e34 | 2015-07-02 17:26:42 +0000 | [diff] [blame] | 3908 | if (StopAtSpace && *String == L' ') {
|
| 3909 | *Value = Result;
|
| 3910 | return (EFI_SUCCESS);
|
jcarsey | 252d945 | 2011-03-25 20:49:53 +0000 | [diff] [blame] | 3911 | }
|
Jaben Carsey | 80f3e34 | 2015-07-02 17:26:42 +0000 | [diff] [blame] | 3912 |
|
jcarsey | 252d945 | 2011-03-25 20:49:53 +0000 | [diff] [blame] | 3913 | while (ShellIsDecimalDigitCharacter (*String)) {
|
| 3914 | //
|
darylm503 | b0934ac | 2011-11-12 00:35:11 +0000 | [diff] [blame] | 3915 | // If the number represented by String overflows according
|
Jaben Carsey | 80f3e34 | 2015-07-02 17:26:42 +0000 | [diff] [blame] | 3916 | // to the range defined by UINT64, then return EFI_DEVICE_ERROR.
|
jcarsey | 252d945 | 2011-03-25 20:49:53 +0000 | [diff] [blame] | 3917 | //
|
darylm503 | b0934ac | 2011-11-12 00:35:11 +0000 | [diff] [blame] | 3918 |
|
jcarsey | 252d945 | 2011-03-25 20:49:53 +0000 | [diff] [blame] | 3919 | if (!(Result <= (DivU64x32((((UINT64) ~0) - (*String - L'0')),10)))) {
|
| 3920 | return (EFI_DEVICE_ERROR);
|
| 3921 | }
|
| 3922 |
|
| 3923 | Result = MultU64x32(Result, 10) + (*String - L'0');
|
| 3924 | String++;
|
| 3925 |
|
| 3926 | //
|
| 3927 | // Stop at spaces if requested
|
| 3928 | //
|
| 3929 | if (StopAtSpace && *String == L' ') {
|
| 3930 | break;
|
| 3931 | }
|
| 3932 | }
|
| 3933 |
|
| 3934 | *Value = Result;
|
darylm503 | b0934ac | 2011-11-12 00:35:11 +0000 | [diff] [blame] | 3935 |
|
jcarsey | 252d945 | 2011-03-25 20:49:53 +0000 | [diff] [blame] | 3936 | return (EFI_SUCCESS);
|
| 3937 | }
|
| 3938 |
|
| 3939 | /**
|
| 3940 | Function to verify and convert a string to its numerical value.
|
| 3941 |
|
| 3942 | If Hex it must be preceeded with a 0x, 0X, or has ForceHex set TRUE.
|
| 3943 |
|
| 3944 | @param[in] String The string to evaluate.
|
| 3945 | @param[out] Value Upon a successful return the value of the conversion.
|
| 3946 | @param[in] ForceHex TRUE - always assume hex.
|
| 3947 | @param[in] StopAtSpace FALSE to skip spaces.
|
darylm503 | b0934ac | 2011-11-12 00:35:11 +0000 | [diff] [blame] | 3948 |
|
jcarsey | 252d945 | 2011-03-25 20:49:53 +0000 | [diff] [blame] | 3949 | @retval EFI_SUCCESS The conversion was successful.
|
| 3950 | @retval EFI_INVALID_PARAMETER String contained an invalid character.
|
| 3951 | @retval EFI_NOT_FOUND String was a number, but Value was NULL.
|
| 3952 | **/
|
| 3953 | EFI_STATUS
|
| 3954 | EFIAPI
|
| 3955 | ShellConvertStringToUint64(
|
| 3956 | IN CONST CHAR16 *String,
|
| 3957 | OUT UINT64 *Value,
|
| 3958 | IN CONST BOOLEAN ForceHex,
|
| 3959 | IN CONST BOOLEAN StopAtSpace
|
| 3960 | )
|
| 3961 | {
|
| 3962 | UINT64 RetVal;
|
| 3963 | CONST CHAR16 *Walker;
|
| 3964 | EFI_STATUS Status;
|
| 3965 | BOOLEAN Hex;
|
| 3966 |
|
| 3967 | Hex = ForceHex;
|
| 3968 |
|
jcarsey | 658bf43 | 2014-11-04 22:33:16 +0000 | [diff] [blame] | 3969 | if (!InternalShellIsHexOrDecimalNumber(String, Hex, StopAtSpace, FALSE)) {
|
jcarsey | 252d945 | 2011-03-25 20:49:53 +0000 | [diff] [blame] | 3970 | if (!Hex) {
|
| 3971 | Hex = TRUE;
|
jcarsey | 658bf43 | 2014-11-04 22:33:16 +0000 | [diff] [blame] | 3972 | if (!InternalShellIsHexOrDecimalNumber(String, Hex, StopAtSpace, FALSE)) {
|
jcarsey | 252d945 | 2011-03-25 20:49:53 +0000 | [diff] [blame] | 3973 | return (EFI_INVALID_PARAMETER);
|
| 3974 | }
|
| 3975 | } else {
|
| 3976 | return (EFI_INVALID_PARAMETER);
|
| 3977 | }
|
| 3978 | }
|
| 3979 |
|
| 3980 | //
|
| 3981 | // Chop off leading spaces
|
| 3982 | //
|
| 3983 | for (Walker = String; Walker != NULL && *Walker != CHAR_NULL && *Walker == L' '; Walker++);
|
| 3984 |
|
| 3985 | //
|
| 3986 | // make sure we have something left that is numeric.
|
| 3987 | //
|
jcarsey | 658bf43 | 2014-11-04 22:33:16 +0000 | [diff] [blame] | 3988 | if (Walker == NULL || *Walker == CHAR_NULL || !InternalShellIsHexOrDecimalNumber(Walker, Hex, StopAtSpace, FALSE)) {
|
jcarsey | 252d945 | 2011-03-25 20:49:53 +0000 | [diff] [blame] | 3989 | return (EFI_INVALID_PARAMETER);
|
darylm503 | b0934ac | 2011-11-12 00:35:11 +0000 | [diff] [blame] | 3990 | }
|
jcarsey | 252d945 | 2011-03-25 20:49:53 +0000 | [diff] [blame] | 3991 |
|
| 3992 | //
|
| 3993 | // do the conversion.
|
| 3994 | //
|
| 3995 | if (Hex || StrnCmp(Walker, L"0x", 2) == 0 || StrnCmp(Walker, L"0X", 2) == 0){
|
| 3996 | Status = InternalShellStrHexToUint64(Walker, &RetVal, StopAtSpace);
|
| 3997 | } else {
|
| 3998 | Status = InternalShellStrDecimalToUint64(Walker, &RetVal, StopAtSpace);
|
| 3999 | }
|
| 4000 |
|
| 4001 | if (Value == NULL && !EFI_ERROR(Status)) {
|
| 4002 | return (EFI_NOT_FOUND);
|
| 4003 | }
|
| 4004 |
|
| 4005 | if (Value != NULL) {
|
| 4006 | *Value = RetVal;
|
| 4007 | }
|
| 4008 |
|
| 4009 | return (Status);
|
| 4010 | }
|
| 4011 |
|
| 4012 | /**
|
| 4013 | Function to determin if an entire string is a valid number.
|
| 4014 |
|
| 4015 | If Hex it must be preceeded with a 0x or has ForceHex, set TRUE.
|
| 4016 |
|
| 4017 | @param[in] String The string to evaluate.
|
| 4018 | @param[in] ForceHex TRUE - always assume hex.
|
| 4019 | @param[in] StopAtSpace TRUE to halt upon finding a space, FALSE to keep going.
|
| 4020 |
|
| 4021 | @retval TRUE It is all numeric (dec/hex) characters.
|
| 4022 | @retval FALSE There is a non-numeric character.
|
| 4023 | **/
|
| 4024 | BOOLEAN
|
| 4025 | EFIAPI
|
| 4026 | ShellIsHexOrDecimalNumber (
|
| 4027 | IN CONST CHAR16 *String,
|
| 4028 | IN CONST BOOLEAN ForceHex,
|
| 4029 | IN CONST BOOLEAN StopAtSpace
|
| 4030 | )
|
| 4031 | {
|
| 4032 | if (ShellConvertStringToUint64(String, NULL, ForceHex, StopAtSpace) == EFI_NOT_FOUND) {
|
| 4033 | return (TRUE);
|
| 4034 | }
|
| 4035 | return (FALSE);
|
| 4036 | }
|
jcarsey | 4d0a4fc | 2011-07-06 22:28:36 +0000 | [diff] [blame] | 4037 |
|
| 4038 | /**
|
| 4039 | Function to read a single line from a SHELL_FILE_HANDLE. The \n is not included in the returned
|
| 4040 | buffer. The returned buffer must be callee freed.
|
| 4041 |
|
| 4042 | If the position upon start is 0, then the Ascii Boolean will be set. This should be
|
| 4043 | maintained and not changed for all operations with the same file.
|
| 4044 |
|
ydong10 | 4ff7e37 | 2011-09-02 08:05:34 +0000 | [diff] [blame] | 4045 | @param[in] Handle SHELL_FILE_HANDLE to read from.
|
| 4046 | @param[in, out] Ascii Boolean value for indicating whether the file is
|
| 4047 | Ascii (TRUE) or UCS2 (FALSE).
|
jcarsey | 4d0a4fc | 2011-07-06 22:28:36 +0000 | [diff] [blame] | 4048 |
|
jcarsey | beab0fc | 2011-10-10 17:26:25 +0000 | [diff] [blame] | 4049 | @return The line of text from the file.
|
| 4050 | @retval NULL There was not enough memory available.
|
jcarsey | 4d0a4fc | 2011-07-06 22:28:36 +0000 | [diff] [blame] | 4051 |
|
| 4052 | @sa ShellFileHandleReadLine
|
| 4053 | **/
|
| 4054 | CHAR16*
|
| 4055 | EFIAPI
|
| 4056 | ShellFileHandleReturnLine(
|
| 4057 | IN SHELL_FILE_HANDLE Handle,
|
| 4058 | IN OUT BOOLEAN *Ascii
|
| 4059 | )
|
| 4060 | {
|
| 4061 | CHAR16 *RetVal;
|
| 4062 | UINTN Size;
|
| 4063 | EFI_STATUS Status;
|
| 4064 |
|
| 4065 | Size = 0;
|
| 4066 | RetVal = NULL;
|
| 4067 |
|
| 4068 | Status = ShellFileHandleReadLine(Handle, RetVal, &Size, FALSE, Ascii);
|
| 4069 | if (Status == EFI_BUFFER_TOO_SMALL) {
|
| 4070 | RetVal = AllocateZeroPool(Size);
|
jcarsey | beab0fc | 2011-10-10 17:26:25 +0000 | [diff] [blame] | 4071 | if (RetVal == NULL) {
|
| 4072 | return (NULL);
|
| 4073 | }
|
jcarsey | 4d0a4fc | 2011-07-06 22:28:36 +0000 | [diff] [blame] | 4074 | Status = ShellFileHandleReadLine(Handle, RetVal, &Size, FALSE, Ascii);
|
darylm503 | b0934ac | 2011-11-12 00:35:11 +0000 | [diff] [blame] | 4075 |
|
jcarsey | 4d0a4fc | 2011-07-06 22:28:36 +0000 | [diff] [blame] | 4076 | }
|
Qiu Shumin | e3b76f3 | 2016-02-22 10:21:38 +0800 | [diff] [blame] | 4077 | if (Status == EFI_END_OF_FILE && RetVal != NULL && *RetVal != CHAR_NULL) {
|
Qiu Shumin | f79d7b6 | 2016-02-18 13:12:58 +0800 | [diff] [blame] | 4078 | Status = EFI_SUCCESS;
|
| 4079 | }
|
jcarsey | 4d0a4fc | 2011-07-06 22:28:36 +0000 | [diff] [blame] | 4080 | if (EFI_ERROR(Status) && (RetVal != NULL)) {
|
| 4081 | FreePool(RetVal);
|
| 4082 | RetVal = NULL;
|
| 4083 | }
|
| 4084 | return (RetVal);
|
| 4085 | }
|
| 4086 |
|
| 4087 | /**
|
| 4088 | Function to read a single line (up to but not including the \n) from a SHELL_FILE_HANDLE.
|
| 4089 |
|
| 4090 | If the position upon start is 0, then the Ascii Boolean will be set. This should be
|
| 4091 | maintained and not changed for all operations with the same file.
|
| 4092 |
|
Jim Dailey | 2dda8a1 | 2016-02-10 08:53:00 -0800 | [diff] [blame] | 4093 | NOTE: LINES THAT ARE RETURNED BY THIS FUNCTION ARE UCS2, EVEN IF THE FILE BEING READ
|
| 4094 | IS IN ASCII FORMAT.
|
| 4095 |
|
ydong10 | 4ff7e37 | 2011-09-02 08:05:34 +0000 | [diff] [blame] | 4096 | @param[in] Handle SHELL_FILE_HANDLE to read from.
|
Jim Dailey | 2dda8a1 | 2016-02-10 08:53:00 -0800 | [diff] [blame] | 4097 | @param[in, out] Buffer The pointer to buffer to read into. If this function
|
| 4098 | returns EFI_SUCCESS, then on output Buffer will
|
| 4099 | contain a UCS2 string, even if the file being
|
| 4100 | read is ASCII.
|
| 4101 | @param[in, out] Size On input, pointer to number of bytes in Buffer.
|
| 4102 | On output, unchanged unless Buffer is too small
|
| 4103 | to contain the next line of the file. In that
|
| 4104 | case Size is set to the number of bytes needed
|
| 4105 | to hold the next line of the file (as a UCS2
|
| 4106 | string, even if it is an ASCII file).
|
ydong10 | 4ff7e37 | 2011-09-02 08:05:34 +0000 | [diff] [blame] | 4107 | @param[in] Truncate If the buffer is large enough, this has no effect.
|
| 4108 | If the buffer is is too small and Truncate is TRUE,
|
| 4109 | the line will be truncated.
|
| 4110 | If the buffer is is too small and Truncate is FALSE,
|
| 4111 | then no read will occur.
|
jcarsey | 4d0a4fc | 2011-07-06 22:28:36 +0000 | [diff] [blame] | 4112 |
|
ydong10 | 4ff7e37 | 2011-09-02 08:05:34 +0000 | [diff] [blame] | 4113 | @param[in, out] Ascii Boolean value for indicating whether the file is
|
| 4114 | Ascii (TRUE) or UCS2 (FALSE).
|
jcarsey | 4d0a4fc | 2011-07-06 22:28:36 +0000 | [diff] [blame] | 4115 |
|
| 4116 | @retval EFI_SUCCESS The operation was successful. The line is stored in
|
| 4117 | Buffer.
|
jaben carsey | 9ed2194 | 2016-02-08 15:59:04 -0800 | [diff] [blame] | 4118 | @retval EFI_END_OF_FILE There are no more lines in the file.
|
jcarsey | 4d0a4fc | 2011-07-06 22:28:36 +0000 | [diff] [blame] | 4119 | @retval EFI_INVALID_PARAMETER Handle was NULL.
|
| 4120 | @retval EFI_INVALID_PARAMETER Size was NULL.
|
| 4121 | @retval EFI_BUFFER_TOO_SMALL Size was not large enough to store the line.
|
| 4122 | Size was updated to the minimum space required.
|
| 4123 | **/
|
| 4124 | EFI_STATUS
|
| 4125 | EFIAPI
|
| 4126 | ShellFileHandleReadLine(
|
| 4127 | IN SHELL_FILE_HANDLE Handle,
|
| 4128 | IN OUT CHAR16 *Buffer,
|
| 4129 | IN OUT UINTN *Size,
|
| 4130 | IN BOOLEAN Truncate,
|
| 4131 | IN OUT BOOLEAN *Ascii
|
| 4132 | )
|
| 4133 | {
|
| 4134 | EFI_STATUS Status;
|
| 4135 | CHAR16 CharBuffer;
|
| 4136 | UINTN CharSize;
|
| 4137 | UINTN CountSoFar;
|
| 4138 | UINT64 OriginalFilePosition;
|
| 4139 |
|
| 4140 |
|
| 4141 | if (Handle == NULL
|
| 4142 | ||Size == NULL
|
| 4143 | ){
|
| 4144 | return (EFI_INVALID_PARAMETER);
|
| 4145 | }
|
| 4146 | if (Buffer == NULL) {
|
| 4147 | ASSERT(*Size == 0);
|
| 4148 | } else {
|
| 4149 | *Buffer = CHAR_NULL;
|
| 4150 | }
|
| 4151 | gEfiShellProtocol->GetFilePosition(Handle, &OriginalFilePosition);
|
| 4152 | if (OriginalFilePosition == 0) {
|
| 4153 | CharSize = sizeof(CHAR16);
|
| 4154 | Status = gEfiShellProtocol->ReadFile(Handle, &CharSize, &CharBuffer);
|
| 4155 | ASSERT_EFI_ERROR(Status);
|
| 4156 | if (CharBuffer == gUnicodeFileTag) {
|
| 4157 | *Ascii = FALSE;
|
| 4158 | } else {
|
| 4159 | *Ascii = TRUE;
|
| 4160 | gEfiShellProtocol->SetFilePosition(Handle, OriginalFilePosition);
|
| 4161 | }
|
| 4162 | }
|
| 4163 |
|
jaben carsey | 9ed2194 | 2016-02-08 15:59:04 -0800 | [diff] [blame] | 4164 | if (*Ascii) {
|
| 4165 | CharSize = sizeof(CHAR8);
|
| 4166 | } else {
|
| 4167 | CharSize = sizeof(CHAR16);
|
| 4168 | }
|
jcarsey | 4d0a4fc | 2011-07-06 22:28:36 +0000 | [diff] [blame] | 4169 | for (CountSoFar = 0;;CountSoFar++){
|
| 4170 | CharBuffer = 0;
|
jcarsey | 4d0a4fc | 2011-07-06 22:28:36 +0000 | [diff] [blame] | 4171 | Status = gEfiShellProtocol->ReadFile(Handle, &CharSize, &CharBuffer);
|
| 4172 | if ( EFI_ERROR(Status)
|
| 4173 | || CharSize == 0
|
| 4174 | || (CharBuffer == L'\n' && !(*Ascii))
|
| 4175 | || (CharBuffer == '\n' && *Ascii)
|
| 4176 | ){
|
jaben carsey | 9ed2194 | 2016-02-08 15:59:04 -0800 | [diff] [blame] | 4177 | if (CharSize == 0) {
|
| 4178 | Status = EFI_END_OF_FILE;
|
| 4179 | }
|
jcarsey | 4d0a4fc | 2011-07-06 22:28:36 +0000 | [diff] [blame] | 4180 | break;
|
| 4181 | }
|
| 4182 | //
|
| 4183 | // if we have space save it...
|
| 4184 | //
|
Jim Dailey | 1095b43 | 2016-02-10 13:17:56 -0800 | [diff] [blame] | 4185 | if ((CountSoFar+1)*sizeof(CHAR16) < *Size){
|
jcarsey | 4d0a4fc | 2011-07-06 22:28:36 +0000 | [diff] [blame] | 4186 | ASSERT(Buffer != NULL);
|
Jim Dailey | 1095b43 | 2016-02-10 13:17:56 -0800 | [diff] [blame] | 4187 | ((CHAR16*)Buffer)[CountSoFar] = CharBuffer;
|
| 4188 | ((CHAR16*)Buffer)[CountSoFar+1] = CHAR_NULL;
|
jcarsey | 4d0a4fc | 2011-07-06 22:28:36 +0000 | [diff] [blame] | 4189 | }
|
| 4190 | }
|
| 4191 |
|
| 4192 | //
|
| 4193 | // if we ran out of space tell when...
|
| 4194 | //
|
Jim Dailey | 1095b43 | 2016-02-10 13:17:56 -0800 | [diff] [blame] | 4195 | if ((CountSoFar+1)*sizeof(CHAR16) > *Size){
|
| 4196 | *Size = (CountSoFar+1)*sizeof(CHAR16);
|
| 4197 | if (!Truncate) {
|
| 4198 | gEfiShellProtocol->SetFilePosition(Handle, OriginalFilePosition);
|
| 4199 | } else {
|
| 4200 | DEBUG((DEBUG_WARN, "The line was truncated in ShellFileHandleReadLine"));
|
jcarsey | 4d0a4fc | 2011-07-06 22:28:36 +0000 | [diff] [blame] | 4201 | }
|
Jim Dailey | 1095b43 | 2016-02-10 13:17:56 -0800 | [diff] [blame] | 4202 | return (EFI_BUFFER_TOO_SMALL);
|
| 4203 | }
|
| 4204 | while(Buffer[StrLen(Buffer)-1] == L'\r') {
|
| 4205 | Buffer[StrLen(Buffer)-1] = CHAR_NULL;
|
jcarsey | 4d0a4fc | 2011-07-06 22:28:36 +0000 | [diff] [blame] | 4206 | }
|
| 4207 |
|
| 4208 | return (Status);
|
| 4209 | }
|
jcarsey | fb5278e | 2013-02-20 18:21:14 +0000 | [diff] [blame] | 4210 |
|
| 4211 | /**
|
jcarsey | 365aa98 | 2013-03-04 21:54:02 +0000 | [diff] [blame] | 4212 | Function to print help file / man page content in the spec from the UEFI Shell protocol GetHelpText function.
|
| 4213 |
|
| 4214 | @param[in] CommandToGetHelpOn Pointer to a string containing the command name of help file to be printed.
|
| 4215 | @param[in] SectionToGetHelpOn Pointer to the section specifier(s).
|
| 4216 | @param[in] PrintCommandText If TRUE, prints the command followed by the help content, otherwise prints
|
| 4217 | the help content only.
|
| 4218 | @retval EFI_DEVICE_ERROR The help data format was incorrect.
|
| 4219 | @retval EFI_NOT_FOUND The help data could not be found.
|
| 4220 | @retval EFI_SUCCESS The operation was successful.
|
| 4221 | **/
|
| 4222 | EFI_STATUS
|
| 4223 | EFIAPI
|
| 4224 | ShellPrintHelp (
|
| 4225 | IN CONST CHAR16 *CommandToGetHelpOn,
|
| 4226 | IN CONST CHAR16 *SectionToGetHelpOn,
|
| 4227 | IN BOOLEAN PrintCommandText
|
| 4228 | )
|
| 4229 | {
|
| 4230 | EFI_STATUS Status;
|
| 4231 | CHAR16 *OutText;
|
| 4232 |
|
| 4233 | OutText = NULL;
|
| 4234 |
|
| 4235 | //
|
| 4236 | // Get the string to print based
|
| 4237 | //
|
| 4238 | Status = gEfiShellProtocol->GetHelpText (CommandToGetHelpOn, SectionToGetHelpOn, &OutText);
|
| 4239 |
|
| 4240 | //
|
| 4241 | // make sure we got a valid string
|
| 4242 | //
|
| 4243 | if (EFI_ERROR(Status)){
|
| 4244 | return Status;
|
| 4245 | }
|
| 4246 | if (OutText == NULL || StrLen(OutText) == 0) {
|
| 4247 | return EFI_NOT_FOUND;
|
| 4248 | }
|
| 4249 |
|
| 4250 | //
|
| 4251 | // Chop off trailing stuff we dont need
|
| 4252 | //
|
| 4253 | while (OutText[StrLen(OutText)-1] == L'\r' || OutText[StrLen(OutText)-1] == L'\n' || OutText[StrLen(OutText)-1] == L' ') {
|
| 4254 | OutText[StrLen(OutText)-1] = CHAR_NULL;
|
| 4255 | }
|
| 4256 |
|
| 4257 | //
|
| 4258 | // Print this out to the console
|
| 4259 | //
|
| 4260 | if (PrintCommandText) {
|
| 4261 | ShellPrintEx(-1, -1, L"%H%-14s%N- %s\r\n", CommandToGetHelpOn, OutText);
|
| 4262 | } else {
|
| 4263 | ShellPrintEx(-1, -1, L"%N%s\r\n", OutText);
|
| 4264 | }
|
| 4265 |
|
| 4266 | SHELL_FREE_NON_NULL(OutText);
|
| 4267 |
|
| 4268 | return EFI_SUCCESS;
|
| 4269 | }
|
| 4270 |
|
| 4271 | /**
|
jcarsey | fb5278e | 2013-02-20 18:21:14 +0000 | [diff] [blame] | 4272 | Function to delete a file by name
|
| 4273 |
|
| 4274 | @param[in] FileName Pointer to file name to delete.
|
| 4275 |
|
| 4276 | @retval EFI_SUCCESS the file was deleted sucessfully
|
| 4277 | @retval EFI_WARN_DELETE_FAILURE the handle was closed, but the file was not
|
| 4278 | deleted
|
| 4279 | @retval EFI_INVALID_PARAMETER One of the parameters has an invalid value.
|
| 4280 | @retval EFI_NOT_FOUND The specified file could not be found on the
|
| 4281 | device or the file system could not be found
|
| 4282 | on the device.
|
| 4283 | @retval EFI_NO_MEDIA The device has no medium.
|
| 4284 | @retval EFI_MEDIA_CHANGED The device has a different medium in it or the
|
| 4285 | medium is no longer supported.
|
| 4286 | @retval EFI_DEVICE_ERROR The device reported an error.
|
| 4287 | @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.
|
| 4288 | @retval EFI_WRITE_PROTECTED The file or medium is write protected.
|
| 4289 | @retval EFI_ACCESS_DENIED The file was opened read only.
|
| 4290 | @retval EFI_OUT_OF_RESOURCES Not enough resources were available to open the
|
| 4291 | file.
|
| 4292 | @retval other The file failed to open
|
| 4293 | **/
|
| 4294 | EFI_STATUS
|
| 4295 | EFIAPI
|
| 4296 | ShellDeleteFileByName(
|
| 4297 | IN CONST CHAR16 *FileName
|
| 4298 | )
|
| 4299 | {
|
| 4300 | EFI_STATUS Status;
|
| 4301 | SHELL_FILE_HANDLE FileHandle;
|
| 4302 |
|
| 4303 | Status = ShellFileExists(FileName);
|
| 4304 |
|
| 4305 | if (Status == EFI_SUCCESS){
|
| 4306 | Status = ShellOpenFileByName(FileName, &FileHandle, EFI_FILE_MODE_READ | EFI_FILE_MODE_WRITE | EFI_FILE_MODE_CREATE, 0x0);
|
| 4307 | if (Status == EFI_SUCCESS){
|
| 4308 | Status = ShellDeleteFile(&FileHandle);
|
| 4309 | }
|
| 4310 | }
|
| 4311 |
|
| 4312 | return(Status);
|
| 4313 |
|
| 4314 | }
|
Qiu Shumin | 0960ba1 | 2014-09-17 07:58:31 +0000 | [diff] [blame] | 4315 |
|
| 4316 | /**
|
| 4317 | Cleans off all the quotes in the string.
|
| 4318 |
|
| 4319 | @param[in] OriginalString pointer to the string to be cleaned.
|
| 4320 | @param[out] CleanString The new string with all quotes removed.
|
| 4321 | Memory allocated in the function and free
|
| 4322 | by caller.
|
| 4323 |
|
| 4324 | @retval EFI_SUCCESS The operation was successful.
|
| 4325 | **/
|
| 4326 | EFI_STATUS
|
| 4327 | EFIAPI
|
| 4328 | InternalShellStripQuotes (
|
| 4329 | IN CONST CHAR16 *OriginalString,
|
| 4330 | OUT CHAR16 **CleanString
|
| 4331 | )
|
| 4332 | {
|
| 4333 | CHAR16 *Walker;
|
| 4334 |
|
| 4335 | if (OriginalString == NULL || CleanString == NULL) {
|
| 4336 | return EFI_INVALID_PARAMETER;
|
| 4337 | }
|
| 4338 |
|
| 4339 | *CleanString = AllocateCopyPool (StrSize (OriginalString), OriginalString);
|
| 4340 | if (*CleanString == NULL) {
|
| 4341 | return EFI_OUT_OF_RESOURCES;
|
| 4342 | }
|
| 4343 |
|
| 4344 | for (Walker = *CleanString; Walker != NULL && *Walker != CHAR_NULL ; Walker++) {
|
| 4345 | if (*Walker == L'\"') {
|
| 4346 | CopyMem(Walker, Walker+1, StrSize(Walker) - sizeof(Walker[0]));
|
| 4347 | }
|
| 4348 | }
|
| 4349 |
|
| 4350 | return EFI_SUCCESS;
|
| 4351 | }
|
| 4352 |
|