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