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