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