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