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