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