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