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