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