]>
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 | |
1e6e84c7 | 1642 | Walker = (CHAR16*)Path;\r |
125c2cf4 | 1643 | do {\r |
1644 | CopyMem(TestPath, Walker, StrSize(Walker));\r | |
1cd45e78 | 1645 | TempChar = StrStr(TestPath, L";");\r |
1646 | if (TempChar != NULL) {\r | |
1647 | *TempChar = CHAR_NULL;\r | |
125c2cf4 | 1648 | }\r |
a405b86d | 1649 | if (TestPath[StrLen(TestPath)-1] != L'\\') {\r |
1650 | StrCat(TestPath, L"\\");\r | |
1651 | }\r | |
125c2cf4 | 1652 | StrCat(TestPath, FileName);\r |
1653 | if (StrStr(Walker, L";") != NULL) {\r | |
1654 | Walker = StrStr(Walker, L";") + 1;\r | |
1655 | } else {\r | |
1656 | Walker = NULL;\r | |
1657 | }\r | |
1658 | Status = ShellOpenFileByName(TestPath, &Handle, EFI_FILE_MODE_READ, 0);\r | |
1659 | if (!EFI_ERROR(Status)){\r | |
a405b86d | 1660 | if (FileHandleIsDirectory(Handle) != EFI_SUCCESS) {\r |
1661 | ASSERT(RetVal == NULL);\r | |
1662 | RetVal = StrnCatGrow(&RetVal, NULL, TestPath, 0);\r | |
1663 | ShellCloseFile(&Handle);\r | |
1664 | break;\r | |
1665 | } else {\r | |
1666 | ShellCloseFile(&Handle);\r | |
1667 | }\r | |
125c2cf4 | 1668 | }\r |
1669 | } while (Walker != NULL && Walker[0] != CHAR_NULL);\r | |
1670 | FreePool(TestPath);\r | |
1671 | }\r | |
1672 | return (RetVal);\r | |
1673 | }\r | |
1674 | \r | |
b3011f40 | 1675 | /**\r |
1e6e84c7 | 1676 | Find a file by searching the CWD and then the path with a variable set of file\r |
1677 | extensions. If the file is not found it will append each extension in the list\r | |
b3011f40 | 1678 | in the order provided and return the first one that is successful.\r |
1679 | \r | |
1680 | If FileName is NULL, then ASSERT.\r | |
1681 | If FileExtension is NULL, then behavior is identical to ShellFindFilePath.\r | |
1682 | \r | |
1683 | If the return value is not NULL then the memory must be caller freed.\r | |
1684 | \r | |
1685 | @param[in] FileName Filename string.\r | |
1686 | @param[in] FileExtension Semi-colon delimeted list of possible extensions.\r | |
1687 | \r | |
1688 | @retval NULL The file was not found.\r | |
1689 | @retval !NULL The path to the file.\r | |
1690 | **/\r | |
1691 | CHAR16 *\r | |
1692 | EFIAPI\r | |
1693 | ShellFindFilePathEx (\r | |
1694 | IN CONST CHAR16 *FileName,\r | |
1695 | IN CONST CHAR16 *FileExtension\r | |
1696 | )\r | |
1697 | {\r | |
1698 | CHAR16 *TestPath;\r | |
1699 | CHAR16 *RetVal;\r | |
1700 | CONST CHAR16 *ExtensionWalker;\r | |
9e926b69 | 1701 | UINTN Size;\r |
1cd45e78 | 1702 | CHAR16 *TempChar;\r |
c9d92df0 | 1703 | CHAR16 *TempChar2;\r |
1cd45e78 | 1704 | \r |
b3011f40 | 1705 | ASSERT(FileName != NULL);\r |
1706 | if (FileExtension == NULL) {\r | |
1707 | return (ShellFindFilePath(FileName));\r | |
1708 | }\r | |
1709 | RetVal = ShellFindFilePath(FileName);\r | |
1710 | if (RetVal != NULL) {\r | |
1711 | return (RetVal);\r | |
1712 | }\r | |
9e926b69 | 1713 | Size = StrSize(FileName);\r |
1714 | Size += StrSize(FileExtension);\r | |
1715 | TestPath = AllocateZeroPool(Size);\r | |
c9d92df0 | 1716 | ASSERT(TestPath != NULL);\r |
1717 | if (TestPath == NULL) {\r | |
1718 | return (NULL);\r | |
1719 | }\r | |
a405b86d | 1720 | for (ExtensionWalker = FileExtension, TempChar2 = (CHAR16*)FileExtension; TempChar2 != NULL ; ExtensionWalker = TempChar2 + 1){\r |
b3011f40 | 1721 | StrCpy(TestPath, FileName);\r |
a405b86d | 1722 | if (ExtensionWalker != NULL) {\r |
1723 | StrCat(TestPath, ExtensionWalker);\r | |
1724 | }\r | |
1cd45e78 | 1725 | TempChar = StrStr(TestPath, L";");\r |
1726 | if (TempChar != NULL) {\r | |
1727 | *TempChar = CHAR_NULL;\r | |
b3011f40 | 1728 | }\r |
1729 | RetVal = ShellFindFilePath(TestPath);\r | |
1730 | if (RetVal != NULL) {\r | |
1731 | break;\r | |
1732 | }\r | |
a405b86d | 1733 | ASSERT(ExtensionWalker != NULL);\r |
c9d92df0 | 1734 | TempChar2 = StrStr(ExtensionWalker, L";");\r |
b3011f40 | 1735 | }\r |
1736 | FreePool(TestPath);\r | |
1737 | return (RetVal);\r | |
1738 | }\r | |
1739 | \r | |
94b17fa1 | 1740 | typedef struct {\r |
9b3bf083 | 1741 | LIST_ENTRY Link;\r |
94b17fa1 | 1742 | CHAR16 *Name;\r |
a405b86d | 1743 | SHELL_PARAM_TYPE Type;\r |
94b17fa1 | 1744 | CHAR16 *Value;\r |
1745 | UINTN OriginalPosition;\r | |
1746 | } SHELL_PARAM_PACKAGE;\r | |
1747 | \r | |
1748 | /**\r | |
1e6e84c7 | 1749 | Checks the list of valid arguments and returns TRUE if the item was found. If the\r |
94b17fa1 | 1750 | return value is TRUE then the type parameter is set also.\r |
1e6e84c7 | 1751 | \r |
94b17fa1 | 1752 | if CheckList is NULL then ASSERT();\r |
1753 | if Name is NULL then ASSERT();\r | |
1754 | if Type is NULL then ASSERT();\r | |
1755 | \r | |
94b17fa1 | 1756 | @param Name pointer to Name of parameter found\r |
1757 | @param CheckList List to check against\r | |
a405b86d | 1758 | @param Type pointer to type of parameter if it was found\r |
94b17fa1 | 1759 | \r |
1760 | @retval TRUE the Parameter was found. Type is valid.\r | |
1761 | @retval FALSE the Parameter was not found. Type is not valid.\r | |
1762 | **/\r | |
1763 | BOOLEAN\r | |
1764 | EFIAPI\r | |
d2b4564b | 1765 | InternalIsOnCheckList (\r |
94b17fa1 | 1766 | IN CONST CHAR16 *Name,\r |
1767 | IN CONST SHELL_PARAM_ITEM *CheckList,\r | |
a405b86d | 1768 | OUT SHELL_PARAM_TYPE *Type\r |
1769 | )\r | |
1770 | {\r | |
94b17fa1 | 1771 | SHELL_PARAM_ITEM *TempListItem;\r |
1772 | \r | |
1773 | //\r | |
1774 | // ASSERT that all 3 pointer parameters aren't NULL\r | |
1775 | //\r | |
1776 | ASSERT(CheckList != NULL);\r | |
1777 | ASSERT(Type != NULL);\r | |
1778 | ASSERT(Name != NULL);\r | |
1779 | \r | |
d2b4564b | 1780 | //\r |
1781 | // question mark and page break mode are always supported\r | |
1782 | //\r | |
1783 | if ((StrCmp(Name, L"-?") == 0) ||\r | |
1784 | (StrCmp(Name, L"-b") == 0)\r | |
a405b86d | 1785 | ) {\r |
d2b4564b | 1786 | return (TRUE);\r |
1787 | }\r | |
1788 | \r | |
94b17fa1 | 1789 | //\r |
1790 | // Enumerate through the list\r | |
1791 | //\r | |
1792 | for (TempListItem = (SHELL_PARAM_ITEM*)CheckList ; TempListItem->Name != NULL ; TempListItem++) {\r | |
1793 | //\r | |
9eb53ac3 | 1794 | // If the Type is TypeStart only check the first characters of the passed in param\r |
1795 | // If it matches set the type and return TRUE\r | |
94b17fa1 | 1796 | //\r |
9eb53ac3 | 1797 | if (TempListItem->Type == TypeStart && StrnCmp(Name, TempListItem->Name, StrLen(TempListItem->Name)) == 0) {\r |
1798 | *Type = TempListItem->Type;\r | |
1799 | return (TRUE);\r | |
1800 | } else if (StrCmp(Name, TempListItem->Name) == 0) {\r | |
94b17fa1 | 1801 | *Type = TempListItem->Type;\r |
1802 | return (TRUE);\r | |
1803 | }\r | |
1804 | }\r | |
2247dde4 | 1805 | \r |
94b17fa1 | 1806 | return (FALSE);\r |
1807 | }\r | |
1808 | /**\r | |
d2b4564b | 1809 | Checks the string for indicators of "flag" status. this is a leading '/', '-', or '+'\r |
94b17fa1 | 1810 | \r |
a405b86d | 1811 | @param[in] Name pointer to Name of parameter found\r |
1812 | @param[in] AlwaysAllowNumbers TRUE to allow numbers, FALSE to not.\r | |
94b17fa1 | 1813 | \r |
1814 | @retval TRUE the Parameter is a flag.\r | |
a405b86d | 1815 | @retval FALSE the Parameter not a flag.\r |
94b17fa1 | 1816 | **/\r |
1817 | BOOLEAN\r | |
1818 | EFIAPI\r | |
d2b4564b | 1819 | InternalIsFlag (\r |
2247dde4 | 1820 | IN CONST CHAR16 *Name,\r |
1821 | IN BOOLEAN AlwaysAllowNumbers\r | |
94b17fa1 | 1822 | )\r |
1823 | {\r | |
1824 | //\r | |
1825 | // ASSERT that Name isn't NULL\r | |
1826 | //\r | |
1827 | ASSERT(Name != NULL);\r | |
1828 | \r | |
2247dde4 | 1829 | //\r |
1830 | // If we accept numbers then dont return TRUE. (they will be values)\r | |
1831 | //\r | |
a405b86d | 1832 | if (((Name[0] == L'-' || Name[0] == L'+') && ShellIsHexaDecimalDigitCharacter(Name[1])) && AlwaysAllowNumbers) {\r |
2247dde4 | 1833 | return (FALSE);\r |
1834 | }\r | |
1835 | \r | |
94b17fa1 | 1836 | //\r |
a405b86d | 1837 | // If the Name has a /, +, or - as the first character return TRUE\r |
94b17fa1 | 1838 | //\r |
1e6e84c7 | 1839 | if ((Name[0] == L'/') ||\r |
d2b4564b | 1840 | (Name[0] == L'-') ||\r |
1841 | (Name[0] == L'+')\r | |
a405b86d | 1842 | ) {\r |
94b17fa1 | 1843 | return (TRUE);\r |
1844 | }\r | |
1845 | return (FALSE);\r | |
1846 | }\r | |
1847 | \r | |
1848 | /**\r | |
1e6e84c7 | 1849 | Checks the command line arguments passed against the list of valid ones.\r |
94b17fa1 | 1850 | \r |
1851 | If no initialization is required, then return RETURN_SUCCESS.\r | |
1e6e84c7 | 1852 | \r |
a405b86d | 1853 | @param[in] CheckList pointer to list of parameters to check\r |
1854 | @param[out] CheckPackage pointer to pointer to list checked values\r | |
1855 | @param[out] ProblemParam optional pointer to pointer to unicode string for\r | |
d2b4564b | 1856 | the paramater that caused failure. If used then the\r |
1857 | caller is responsible for freeing the memory.\r | |
a405b86d | 1858 | @param[in] AutoPageBreak will automatically set PageBreakEnabled for "b" parameter\r |
1859 | @param[in] Argv pointer to array of parameters\r | |
1860 | @param[in] Argc Count of parameters in Argv\r | |
1861 | @param[in] AlwaysAllowNumbers TRUE to allow numbers always, FALSE otherwise.\r | |
94b17fa1 | 1862 | \r |
1863 | @retval EFI_SUCCESS The operation completed sucessfully.\r | |
1864 | @retval EFI_OUT_OF_RESOURCES A memory allocation failed\r | |
1865 | @retval EFI_INVALID_PARAMETER A parameter was invalid\r | |
1e6e84c7 | 1866 | @retval EFI_VOLUME_CORRUPTED the command line was corrupt. an argument was\r |
1867 | duplicated. the duplicated command line argument\r | |
94b17fa1 | 1868 | was returned in ProblemParam if provided.\r |
1e6e84c7 | 1869 | @retval EFI_NOT_FOUND a argument required a value that was missing.\r |
94b17fa1 | 1870 | the invalid command line argument was returned in\r |
1871 | ProblemParam if provided.\r | |
1872 | **/\r | |
1873 | EFI_STATUS\r | |
1874 | EFIAPI\r | |
1875 | InternalCommandLineParse (\r | |
1876 | IN CONST SHELL_PARAM_ITEM *CheckList,\r | |
1877 | OUT LIST_ENTRY **CheckPackage,\r | |
1878 | OUT CHAR16 **ProblemParam OPTIONAL,\r | |
1879 | IN BOOLEAN AutoPageBreak,\r | |
1880 | IN CONST CHAR16 **Argv,\r | |
2247dde4 | 1881 | IN UINTN Argc,\r |
1882 | IN BOOLEAN AlwaysAllowNumbers\r | |
a405b86d | 1883 | )\r |
1884 | {\r | |
94b17fa1 | 1885 | UINTN LoopCounter;\r |
a405b86d | 1886 | SHELL_PARAM_TYPE CurrentItemType;\r |
94b17fa1 | 1887 | SHELL_PARAM_PACKAGE *CurrentItemPackage;\r |
125c2cf4 | 1888 | UINTN GetItemValue;\r |
1889 | UINTN ValueSize;\r | |
a405b86d | 1890 | UINTN Count;\r |
94b17fa1 | 1891 | \r |
1892 | CurrentItemPackage = NULL;\r | |
125c2cf4 | 1893 | GetItemValue = 0;\r |
1894 | ValueSize = 0;\r | |
a405b86d | 1895 | Count = 0;\r |
94b17fa1 | 1896 | \r |
1897 | //\r | |
1898 | // If there is only 1 item we dont need to do anything\r | |
1899 | //\r | |
a405b86d | 1900 | if (Argc < 1) {\r |
94b17fa1 | 1901 | *CheckPackage = NULL;\r |
1902 | return (EFI_SUCCESS);\r | |
1903 | }\r | |
1904 | \r | |
2247dde4 | 1905 | //\r |
1906 | // ASSERTs\r | |
1907 | //\r | |
1908 | ASSERT(CheckList != NULL);\r | |
1909 | ASSERT(Argv != NULL);\r | |
1910 | \r | |
94b17fa1 | 1911 | //\r |
1912 | // initialize the linked list\r | |
1913 | //\r | |
1914 | *CheckPackage = (LIST_ENTRY*)AllocateZeroPool(sizeof(LIST_ENTRY));\r | |
1915 | InitializeListHead(*CheckPackage);\r | |
1916 | \r | |
1917 | //\r | |
1918 | // loop through each of the arguments\r | |
1919 | //\r | |
1920 | for (LoopCounter = 0 ; LoopCounter < Argc ; ++LoopCounter) {\r | |
1921 | if (Argv[LoopCounter] == NULL) {\r | |
1922 | //\r | |
1923 | // do nothing for NULL argv\r | |
1924 | //\r | |
a405b86d | 1925 | } else if (InternalIsOnCheckList(Argv[LoopCounter], CheckList, &CurrentItemType)) {\r |
2247dde4 | 1926 | //\r |
1927 | // We might have leftover if last parameter didnt have optional value\r | |
1928 | //\r | |
125c2cf4 | 1929 | if (GetItemValue != 0) {\r |
1930 | GetItemValue = 0;\r | |
2247dde4 | 1931 | InsertHeadList(*CheckPackage, &CurrentItemPackage->Link);\r |
1932 | }\r | |
94b17fa1 | 1933 | //\r |
1934 | // this is a flag\r | |
1935 | //\r | |
1936 | CurrentItemPackage = AllocatePool(sizeof(SHELL_PARAM_PACKAGE));\r | |
1937 | ASSERT(CurrentItemPackage != NULL);\r | |
1938 | CurrentItemPackage->Name = AllocatePool(StrSize(Argv[LoopCounter]));\r | |
1939 | ASSERT(CurrentItemPackage->Name != NULL);\r | |
1940 | StrCpy(CurrentItemPackage->Name, Argv[LoopCounter]);\r | |
1941 | CurrentItemPackage->Type = CurrentItemType;\r | |
1942 | CurrentItemPackage->OriginalPosition = (UINTN)(-1);\r | |
b1f95a06 | 1943 | CurrentItemPackage->Value = NULL;\r |
94b17fa1 | 1944 | \r |
1945 | //\r | |
1946 | // Does this flag require a value\r | |
1947 | //\r | |
125c2cf4 | 1948 | switch (CurrentItemPackage->Type) {\r |
94b17fa1 | 1949 | //\r |
125c2cf4 | 1950 | // possibly trigger the next loop(s) to populate the value of this item\r |
1e6e84c7 | 1951 | //\r |
125c2cf4 | 1952 | case TypeValue:\r |
1e6e84c7 | 1953 | GetItemValue = 1;\r |
125c2cf4 | 1954 | ValueSize = 0;\r |
1955 | break;\r | |
1956 | case TypeDoubleValue:\r | |
1957 | GetItemValue = 2;\r | |
1958 | ValueSize = 0;\r | |
1959 | break;\r | |
1960 | case TypeMaxValue:\r | |
1961 | GetItemValue = (UINTN)(-1);\r | |
1962 | ValueSize = 0;\r | |
1963 | break;\r | |
1964 | default:\r | |
1965 | //\r | |
1966 | // this item has no value expected; we are done\r | |
1967 | //\r | |
1968 | InsertHeadList(*CheckPackage, &CurrentItemPackage->Link);\r | |
1969 | ASSERT(GetItemValue == 0);\r | |
1970 | break;\r | |
94b17fa1 | 1971 | }\r |
a405b86d | 1972 | } else if (GetItemValue != 0 && !InternalIsFlag(Argv[LoopCounter], AlwaysAllowNumbers)) {\r |
b1f95a06 | 1973 | ASSERT(CurrentItemPackage != NULL);\r |
1974 | //\r | |
125c2cf4 | 1975 | // get the item VALUE for a previous flag\r |
b1f95a06 | 1976 | //\r |
125c2cf4 | 1977 | CurrentItemPackage->Value = ReallocatePool(ValueSize, ValueSize + StrSize(Argv[LoopCounter]) + sizeof(CHAR16), CurrentItemPackage->Value);\r |
b1f95a06 | 1978 | ASSERT(CurrentItemPackage->Value != NULL);\r |
125c2cf4 | 1979 | if (ValueSize == 0) {\r |
1980 | StrCpy(CurrentItemPackage->Value, Argv[LoopCounter]);\r | |
1981 | } else {\r | |
1982 | StrCat(CurrentItemPackage->Value, L" ");\r | |
1983 | StrCat(CurrentItemPackage->Value, Argv[LoopCounter]);\r | |
1984 | }\r | |
1985 | ValueSize += StrSize(Argv[LoopCounter]) + sizeof(CHAR16);\r | |
1986 | GetItemValue--;\r | |
1987 | if (GetItemValue == 0) {\r | |
1988 | InsertHeadList(*CheckPackage, &CurrentItemPackage->Link);\r | |
1989 | }\r | |
a405b86d | 1990 | } else if (!InternalIsFlag(Argv[LoopCounter], AlwaysAllowNumbers) ){ //|| ProblemParam == NULL) {\r |
b1f95a06 | 1991 | //\r |
1992 | // add this one as a non-flag\r | |
1993 | //\r | |
1994 | CurrentItemPackage = AllocatePool(sizeof(SHELL_PARAM_PACKAGE));\r | |
1995 | ASSERT(CurrentItemPackage != NULL);\r | |
1996 | CurrentItemPackage->Name = NULL;\r | |
1997 | CurrentItemPackage->Type = TypePosition;\r | |
1998 | CurrentItemPackage->Value = AllocatePool(StrSize(Argv[LoopCounter]));\r | |
1999 | ASSERT(CurrentItemPackage->Value != NULL);\r | |
2000 | StrCpy(CurrentItemPackage->Value, Argv[LoopCounter]);\r | |
a405b86d | 2001 | CurrentItemPackage->OriginalPosition = Count++;\r |
9b3bf083 | 2002 | InsertHeadList(*CheckPackage, &CurrentItemPackage->Link);\r |
a405b86d | 2003 | } else if (ProblemParam != NULL) {\r |
94b17fa1 | 2004 | //\r |
2005 | // this was a non-recognised flag... error!\r | |
2006 | //\r | |
d2b4564b | 2007 | *ProblemParam = AllocatePool(StrSize(Argv[LoopCounter]));\r |
2008 | ASSERT(*ProblemParam != NULL);\r | |
2009 | StrCpy(*ProblemParam, Argv[LoopCounter]);\r | |
94b17fa1 | 2010 | ShellCommandLineFreeVarList(*CheckPackage);\r |
2011 | *CheckPackage = NULL;\r | |
2012 | return (EFI_VOLUME_CORRUPTED);\r | |
2013 | } else {\r | |
a405b86d | 2014 | //ASSERT(FALSE);\r |
94b17fa1 | 2015 | }\r |
2016 | }\r | |
125c2cf4 | 2017 | if (GetItemValue != 0) {\r |
2018 | GetItemValue = 0;\r | |
2019 | InsertHeadList(*CheckPackage, &CurrentItemPackage->Link);\r | |
2020 | }\r | |
94b17fa1 | 2021 | //\r |
2022 | // support for AutoPageBreak\r | |
2023 | //\r | |
2024 | if (AutoPageBreak && ShellCommandLineGetFlag(*CheckPackage, L"-b")) {\r | |
2025 | ShellSetPageBreakMode(TRUE);\r | |
2026 | }\r | |
2027 | return (EFI_SUCCESS);\r | |
2028 | }\r | |
2029 | \r | |
2030 | /**\r | |
1e6e84c7 | 2031 | Checks the command line arguments passed against the list of valid ones.\r |
94b17fa1 | 2032 | Optionally removes NULL values first.\r |
1e6e84c7 | 2033 | \r |
94b17fa1 | 2034 | If no initialization is required, then return RETURN_SUCCESS.\r |
1e6e84c7 | 2035 | \r |
a405b86d | 2036 | @param[in] CheckList The pointer to list of parameters to check.\r |
2037 | @param[out] CheckPackage The package of checked values.\r | |
2038 | @param[out] ProblemParam Optional pointer to pointer to unicode string for\r | |
94b17fa1 | 2039 | the paramater that caused failure.\r |
a405b86d | 2040 | @param[in] AutoPageBreak Will automatically set PageBreakEnabled.\r |
2041 | @param[in] AlwaysAllowNumbers Will never fail for number based flags.\r | |
94b17fa1 | 2042 | \r |
2043 | @retval EFI_SUCCESS The operation completed sucessfully.\r | |
a405b86d | 2044 | @retval EFI_OUT_OF_RESOURCES A memory allocation failed.\r |
2045 | @retval EFI_INVALID_PARAMETER A parameter was invalid.\r | |
2046 | @retval EFI_VOLUME_CORRUPTED The command line was corrupt.\r | |
2047 | @retval EFI_DEVICE_ERROR The commands contained 2 opposing arguments. One\r | |
1e6e84c7 | 2048 | of the command line arguments was returned in\r |
94b17fa1 | 2049 | ProblemParam if provided.\r |
a405b86d | 2050 | @retval EFI_NOT_FOUND A argument required a value that was missing.\r |
2051 | The invalid command line argument was returned in\r | |
94b17fa1 | 2052 | ProblemParam if provided.\r |
2053 | **/\r | |
2054 | EFI_STATUS\r | |
2055 | EFIAPI\r | |
2247dde4 | 2056 | ShellCommandLineParseEx (\r |
94b17fa1 | 2057 | IN CONST SHELL_PARAM_ITEM *CheckList,\r |
2058 | OUT LIST_ENTRY **CheckPackage,\r | |
2059 | OUT CHAR16 **ProblemParam OPTIONAL,\r | |
2247dde4 | 2060 | IN BOOLEAN AutoPageBreak,\r |
2061 | IN BOOLEAN AlwaysAllowNumbers\r | |
a405b86d | 2062 | )\r |
2063 | {\r | |
1e6e84c7 | 2064 | //\r |
94b17fa1 | 2065 | // ASSERT that CheckList and CheckPackage aren't NULL\r |
2066 | //\r | |
2067 | ASSERT(CheckList != NULL);\r | |
2068 | ASSERT(CheckPackage != NULL);\r | |
2069 | \r | |
1e6e84c7 | 2070 | //\r |
94b17fa1 | 2071 | // Check for UEFI Shell 2.0 protocols\r |
2072 | //\r | |
2073 | if (mEfiShellParametersProtocol != NULL) {\r | |
1e6e84c7 | 2074 | return (InternalCommandLineParse(CheckList,\r |
2075 | CheckPackage,\r | |
2076 | ProblemParam,\r | |
2077 | AutoPageBreak,\r | |
08d7f8e8 | 2078 | (CONST CHAR16**) mEfiShellParametersProtocol->Argv,\r |
2247dde4 | 2079 | mEfiShellParametersProtocol->Argc,\r |
2080 | AlwaysAllowNumbers));\r | |
94b17fa1 | 2081 | }\r |
2082 | \r | |
1e6e84c7 | 2083 | //\r |
94b17fa1 | 2084 | // ASSERT That EFI Shell is not required\r |
2085 | //\r | |
2086 | ASSERT (mEfiShellInterface != NULL);\r | |
1e6e84c7 | 2087 | return (InternalCommandLineParse(CheckList,\r |
2088 | CheckPackage,\r | |
2089 | ProblemParam,\r | |
2090 | AutoPageBreak,\r | |
08d7f8e8 | 2091 | (CONST CHAR16**) mEfiShellInterface->Argv,\r |
2247dde4 | 2092 | mEfiShellInterface->Argc,\r |
2093 | AlwaysAllowNumbers));\r | |
94b17fa1 | 2094 | }\r |
2095 | \r | |
2096 | /**\r | |
2097 | Frees shell variable list that was returned from ShellCommandLineParse.\r | |
2098 | \r | |
2099 | This function will free all the memory that was used for the CheckPackage\r | |
2100 | list of postprocessed shell arguments.\r | |
2101 | \r | |
2102 | this function has no return value.\r | |
2103 | \r | |
2104 | if CheckPackage is NULL, then return\r | |
2105 | \r | |
2106 | @param CheckPackage the list to de-allocate\r | |
2107 | **/\r | |
2108 | VOID\r | |
2109 | EFIAPI\r | |
2110 | ShellCommandLineFreeVarList (\r | |
2111 | IN LIST_ENTRY *CheckPackage\r | |
a405b86d | 2112 | )\r |
2113 | {\r | |
94b17fa1 | 2114 | LIST_ENTRY *Node;\r |
2115 | \r | |
2116 | //\r | |
2117 | // check for CheckPackage == NULL\r | |
2118 | //\r | |
2119 | if (CheckPackage == NULL) {\r | |
2120 | return;\r | |
2121 | }\r | |
2122 | \r | |
2123 | //\r | |
2124 | // for each node in the list\r | |
2125 | //\r | |
9eb53ac3 | 2126 | for ( Node = GetFirstNode(CheckPackage)\r |
a405b86d | 2127 | ; !IsListEmpty(CheckPackage)\r |
9eb53ac3 | 2128 | ; Node = GetFirstNode(CheckPackage)\r |
a405b86d | 2129 | ){\r |
94b17fa1 | 2130 | //\r |
2131 | // Remove it from the list\r | |
2132 | //\r | |
2133 | RemoveEntryList(Node);\r | |
2134 | \r | |
2135 | //\r | |
2136 | // if it has a name free the name\r | |
2137 | //\r | |
2138 | if (((SHELL_PARAM_PACKAGE*)Node)->Name != NULL) {\r | |
2139 | FreePool(((SHELL_PARAM_PACKAGE*)Node)->Name);\r | |
2140 | }\r | |
2141 | \r | |
2142 | //\r | |
2143 | // if it has a value free the value\r | |
2144 | //\r | |
2145 | if (((SHELL_PARAM_PACKAGE*)Node)->Value != NULL) {\r | |
2146 | FreePool(((SHELL_PARAM_PACKAGE*)Node)->Value);\r | |
2147 | }\r | |
1e6e84c7 | 2148 | \r |
94b17fa1 | 2149 | //\r |
2150 | // free the node structure\r | |
2151 | //\r | |
2152 | FreePool((SHELL_PARAM_PACKAGE*)Node);\r | |
2153 | }\r | |
2154 | //\r | |
2155 | // free the list head node\r | |
2156 | //\r | |
2157 | FreePool(CheckPackage);\r | |
2158 | }\r | |
2159 | /**\r | |
2160 | Checks for presence of a flag parameter\r | |
2161 | \r | |
2162 | flag arguments are in the form of "-<Key>" or "/<Key>", but do not have a value following the key\r | |
2163 | \r | |
2164 | if CheckPackage is NULL then return FALSE.\r | |
2165 | if KeyString is NULL then ASSERT()\r | |
1e6e84c7 | 2166 | \r |
94b17fa1 | 2167 | @param CheckPackage The package of parsed command line arguments\r |
2168 | @param KeyString the Key of the command line argument to check for\r | |
2169 | \r | |
2170 | @retval TRUE the flag is on the command line\r | |
2171 | @retval FALSE the flag is not on the command line\r | |
2172 | **/\r | |
2173 | BOOLEAN\r | |
2174 | EFIAPI\r | |
2175 | ShellCommandLineGetFlag (\r | |
a405b86d | 2176 | IN CONST LIST_ENTRY * CONST CheckPackage,\r |
2177 | IN CONST CHAR16 * CONST KeyString\r | |
2178 | )\r | |
2179 | {\r | |
94b17fa1 | 2180 | LIST_ENTRY *Node;\r |
2181 | \r | |
2182 | //\r | |
2183 | // ASSERT that both CheckPackage and KeyString aren't NULL\r | |
2184 | //\r | |
2185 | ASSERT(KeyString != NULL);\r | |
2186 | \r | |
2187 | //\r | |
2188 | // return FALSE for no package\r | |
2189 | //\r | |
2190 | if (CheckPackage == NULL) {\r | |
2191 | return (FALSE);\r | |
2192 | }\r | |
2193 | \r | |
2194 | //\r | |
2195 | // enumerate through the list of parametrs\r | |
2196 | //\r | |
1e6e84c7 | 2197 | for ( Node = GetFirstNode(CheckPackage)\r |
2198 | ; !IsNull (CheckPackage, Node)\r | |
2199 | ; Node = GetNextNode(CheckPackage, Node)\r | |
a405b86d | 2200 | ){\r |
94b17fa1 | 2201 | //\r |
2202 | // If the Name matches, return TRUE (and there may be NULL name)\r | |
2203 | //\r | |
2204 | if (((SHELL_PARAM_PACKAGE*)Node)->Name != NULL) {\r | |
9eb53ac3 | 2205 | //\r |
2206 | // If Type is TypeStart then only compare the begining of the strings\r | |
2207 | //\r | |
1e6e84c7 | 2208 | if ( ((SHELL_PARAM_PACKAGE*)Node)->Type == TypeStart\r |
9eb53ac3 | 2209 | && StrnCmp(KeyString, ((SHELL_PARAM_PACKAGE*)Node)->Name, StrLen(KeyString)) == 0\r |
a405b86d | 2210 | ){\r |
9eb53ac3 | 2211 | return (TRUE);\r |
2212 | } else if (StrCmp(KeyString, ((SHELL_PARAM_PACKAGE*)Node)->Name) == 0) {\r | |
94b17fa1 | 2213 | return (TRUE);\r |
2214 | }\r | |
2215 | }\r | |
2216 | }\r | |
2217 | return (FALSE);\r | |
2218 | }\r | |
2219 | /**\r | |
a405b86d | 2220 | Returns value from command line argument.\r |
94b17fa1 | 2221 | \r |
a405b86d | 2222 | Value parameters are in the form of "-<Key> value" or "/<Key> value".\r |
1e6e84c7 | 2223 | \r |
a405b86d | 2224 | If CheckPackage is NULL, then return NULL.\r |
94b17fa1 | 2225 | \r |
a405b86d | 2226 | @param[in] CheckPackage The package of parsed command line arguments.\r |
2227 | @param[in] KeyString The Key of the command line argument to check for.\r | |
94b17fa1 | 2228 | \r |
a405b86d | 2229 | @retval NULL The flag is not on the command line.\r |
2230 | @retval !=NULL The pointer to unicode string of the value.\r | |
2231 | **/\r | |
94b17fa1 | 2232 | CONST CHAR16*\r |
2233 | EFIAPI\r | |
2234 | ShellCommandLineGetValue (\r | |
2235 | IN CONST LIST_ENTRY *CheckPackage,\r | |
2236 | IN CHAR16 *KeyString\r | |
a405b86d | 2237 | )\r |
2238 | {\r | |
94b17fa1 | 2239 | LIST_ENTRY *Node;\r |
2240 | \r | |
2241 | //\r | |
2242 | // check for CheckPackage == NULL\r | |
2243 | //\r | |
2244 | if (CheckPackage == NULL) {\r | |
2245 | return (NULL);\r | |
2246 | }\r | |
2247 | \r | |
2248 | //\r | |
2249 | // enumerate through the list of parametrs\r | |
2250 | //\r | |
1e6e84c7 | 2251 | for ( Node = GetFirstNode(CheckPackage)\r |
2252 | ; !IsNull (CheckPackage, Node)\r | |
2253 | ; Node = GetNextNode(CheckPackage, Node)\r | |
a405b86d | 2254 | ){\r |
94b17fa1 | 2255 | //\r |
2256 | // If the Name matches, return the value (name can be NULL)\r | |
2257 | //\r | |
2258 | if (((SHELL_PARAM_PACKAGE*)Node)->Name != NULL) {\r | |
9eb53ac3 | 2259 | //\r |
2260 | // If Type is TypeStart then only compare the begining of the strings\r | |
2261 | //\r | |
1e6e84c7 | 2262 | if ( ((SHELL_PARAM_PACKAGE*)Node)->Type == TypeStart\r |
9eb53ac3 | 2263 | && StrnCmp(KeyString, ((SHELL_PARAM_PACKAGE*)Node)->Name, StrLen(KeyString)) == 0\r |
a405b86d | 2264 | ){\r |
9eb53ac3 | 2265 | //\r |
2266 | // return the string part after the flag\r | |
2267 | //\r | |
2268 | return (((SHELL_PARAM_PACKAGE*)Node)->Name + StrLen(KeyString));\r | |
2269 | } else if (StrCmp(KeyString, ((SHELL_PARAM_PACKAGE*)Node)->Name) == 0) {\r | |
2270 | //\r | |
2271 | // return the value\r | |
2272 | //\r | |
94b17fa1 | 2273 | return (((SHELL_PARAM_PACKAGE*)Node)->Value);\r |
2274 | }\r | |
2275 | }\r | |
2276 | }\r | |
2277 | return (NULL);\r | |
2278 | }\r | |
a405b86d | 2279 | \r |
94b17fa1 | 2280 | /**\r |
a405b86d | 2281 | Returns raw value from command line argument.\r |
94b17fa1 | 2282 | \r |
a405b86d | 2283 | Raw value parameters are in the form of "value" in a specific position in the list.\r |
1e6e84c7 | 2284 | \r |
a405b86d | 2285 | If CheckPackage is NULL, then return NULL.\r |
94b17fa1 | 2286 | \r |
a405b86d | 2287 | @param[in] CheckPackage The package of parsed command line arguments.\r |
2288 | @param[in] Position The position of the value.\r | |
94b17fa1 | 2289 | \r |
a405b86d | 2290 | @retval NULL The flag is not on the command line.\r |
2291 | @retval !=NULL The pointer to unicode string of the value.\r | |
94b17fa1 | 2292 | **/\r |
2293 | CONST CHAR16*\r | |
2294 | EFIAPI\r | |
2295 | ShellCommandLineGetRawValue (\r | |
a405b86d | 2296 | IN CONST LIST_ENTRY * CONST CheckPackage,\r |
2297 | IN UINTN Position\r | |
2298 | )\r | |
2299 | {\r | |
94b17fa1 | 2300 | LIST_ENTRY *Node;\r |
2301 | \r | |
2302 | //\r | |
2303 | // check for CheckPackage == NULL\r | |
2304 | //\r | |
2305 | if (CheckPackage == NULL) {\r | |
2306 | return (NULL);\r | |
2307 | }\r | |
2308 | \r | |
2309 | //\r | |
2310 | // enumerate through the list of parametrs\r | |
2311 | //\r | |
1e6e84c7 | 2312 | for ( Node = GetFirstNode(CheckPackage)\r |
2313 | ; !IsNull (CheckPackage, Node)\r | |
2314 | ; Node = GetNextNode(CheckPackage, Node)\r | |
a405b86d | 2315 | ){\r |
94b17fa1 | 2316 | //\r |
2317 | // If the position matches, return the value\r | |
2318 | //\r | |
2319 | if (((SHELL_PARAM_PACKAGE*)Node)->OriginalPosition == Position) {\r | |
2320 | return (((SHELL_PARAM_PACKAGE*)Node)->Value);\r | |
2321 | }\r | |
2322 | }\r | |
2323 | return (NULL);\r | |
b1f95a06 | 2324 | }\r |
2247dde4 | 2325 | \r |
2326 | /**\r | |
1e6e84c7 | 2327 | returns the number of command line value parameters that were parsed.\r |
2328 | \r | |
2247dde4 | 2329 | this will not include flags.\r |
2330 | \r | |
a405b86d | 2331 | @param[in] CheckPackage The package of parsed command line arguments.\r |
2332 | \r | |
2247dde4 | 2333 | @retval (UINTN)-1 No parsing has ocurred\r |
2334 | @return other The number of value parameters found\r | |
2335 | **/\r | |
2336 | UINTN\r | |
2337 | EFIAPI\r | |
2338 | ShellCommandLineGetCount(\r | |
a405b86d | 2339 | IN CONST LIST_ENTRY *CheckPackage\r |
125c2cf4 | 2340 | )\r |
2341 | {\r | |
a405b86d | 2342 | LIST_ENTRY *Node1;\r |
2343 | UINTN Count;\r | |
2344 | \r | |
2345 | if (CheckPackage == NULL) {\r | |
2346 | return (0);\r | |
2347 | }\r | |
2348 | for ( Node1 = GetFirstNode(CheckPackage), Count = 0\r | |
2349 | ; !IsNull (CheckPackage, Node1)\r | |
2350 | ; Node1 = GetNextNode(CheckPackage, Node1)\r | |
2351 | ){\r | |
2352 | if (((SHELL_PARAM_PACKAGE*)Node1)->Name == NULL) {\r | |
2353 | Count++;\r | |
2354 | }\r | |
2355 | }\r | |
2356 | return (Count);\r | |
2247dde4 | 2357 | }\r |
2358 | \r | |
36a9d672 | 2359 | /**\r |
2360 | Determins if a parameter is duplicated.\r | |
2361 | \r | |
1e6e84c7 | 2362 | If Param is not NULL then it will point to a callee allocated string buffer\r |
36a9d672 | 2363 | with the parameter value if a duplicate is found.\r |
2364 | \r | |
2365 | If CheckPackage is NULL, then ASSERT.\r | |
2366 | \r | |
2367 | @param[in] CheckPackage The package of parsed command line arguments.\r | |
2368 | @param[out] Param Upon finding one, a pointer to the duplicated parameter.\r | |
2369 | \r | |
2370 | @retval EFI_SUCCESS No parameters were duplicated.\r | |
2371 | @retval EFI_DEVICE_ERROR A duplicate was found.\r | |
2372 | **/\r | |
2373 | EFI_STATUS\r | |
2374 | EFIAPI\r | |
2375 | ShellCommandLineCheckDuplicate (\r | |
2376 | IN CONST LIST_ENTRY *CheckPackage,\r | |
2377 | OUT CHAR16 **Param\r | |
2378 | )\r | |
2379 | {\r | |
2380 | LIST_ENTRY *Node1;\r | |
2381 | LIST_ENTRY *Node2;\r | |
1e6e84c7 | 2382 | \r |
36a9d672 | 2383 | ASSERT(CheckPackage != NULL);\r |
2384 | \r | |
1e6e84c7 | 2385 | for ( Node1 = GetFirstNode(CheckPackage)\r |
2386 | ; !IsNull (CheckPackage, Node1)\r | |
2387 | ; Node1 = GetNextNode(CheckPackage, Node1)\r | |
a405b86d | 2388 | ){\r |
1e6e84c7 | 2389 | for ( Node2 = GetNextNode(CheckPackage, Node1)\r |
2390 | ; !IsNull (CheckPackage, Node2)\r | |
2391 | ; Node2 = GetNextNode(CheckPackage, Node2)\r | |
a405b86d | 2392 | ){\r |
2393 | 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 | 2394 | if (Param != NULL) {\r |
2395 | *Param = NULL;\r | |
2396 | *Param = StrnCatGrow(Param, NULL, ((SHELL_PARAM_PACKAGE*)Node1)->Name, 0);\r | |
2397 | }\r | |
2398 | return (EFI_DEVICE_ERROR);\r | |
2399 | }\r | |
2400 | }\r | |
2401 | }\r | |
2402 | return (EFI_SUCCESS);\r | |
2403 | }\r | |
2404 | \r | |
975136ab | 2405 | /**\r |
1e6e84c7 | 2406 | This is a find and replace function. Upon successful return the NewString is a copy of\r |
975136ab | 2407 | SourceString with each instance of FindTarget replaced with ReplaceWith.\r |
2408 | \r | |
b3011f40 | 2409 | If SourceString and NewString overlap the behavior is undefined.\r |
2410 | \r | |
975136ab | 2411 | If the string would grow bigger than NewSize it will halt and return error.\r |
2412 | \r | |
a405b86d | 2413 | @param[in] SourceString The string with source buffer.\r |
2414 | @param[in,out] NewString The string with resultant buffer.\r | |
2415 | @param[in] NewSize The size in bytes of NewString.\r | |
2416 | @param[in] FindTarget The string to look for.\r | |
2417 | @param[in] ReplaceWith The string to replace FindTarget with.\r | |
969c783b | 2418 | @param[in] SkipPreCarrot If TRUE will skip a FindTarget that has a '^'\r |
2419 | immediately before it.\r | |
a405b86d | 2420 | @param[in] ParameterReplacing If TRUE will add "" around items with spaces.\r |
969c783b | 2421 | \r |
2422 | @retval EFI_INVALID_PARAMETER SourceString was NULL.\r | |
2423 | @retval EFI_INVALID_PARAMETER NewString was NULL.\r | |
2424 | @retval EFI_INVALID_PARAMETER FindTarget was NULL.\r | |
2425 | @retval EFI_INVALID_PARAMETER ReplaceWith was NULL.\r | |
2426 | @retval EFI_INVALID_PARAMETER FindTarget had length < 1.\r | |
2427 | @retval EFI_INVALID_PARAMETER SourceString had length < 1.\r | |
1e6e84c7 | 2428 | @retval EFI_BUFFER_TOO_SMALL NewSize was less than the minimum size to hold\r |
969c783b | 2429 | the new string (truncation occurred).\r |
a405b86d | 2430 | @retval EFI_SUCCESS The string was successfully copied with replacement.\r |
975136ab | 2431 | **/\r |
975136ab | 2432 | EFI_STATUS\r |
2433 | EFIAPI\r | |
a405b86d | 2434 | ShellCopySearchAndReplace(\r |
975136ab | 2435 | IN CHAR16 CONST *SourceString,\r |
a405b86d | 2436 | IN OUT CHAR16 *NewString,\r |
975136ab | 2437 | IN UINTN NewSize,\r |
2438 | IN CONST CHAR16 *FindTarget,\r | |
969c783b | 2439 | IN CONST CHAR16 *ReplaceWith,\r |
a405b86d | 2440 | IN CONST BOOLEAN SkipPreCarrot,\r |
2441 | IN CONST BOOLEAN ParameterReplacing\r | |
1e6e84c7 | 2442 | )\r |
2247dde4 | 2443 | {\r |
0158294b | 2444 | UINTN Size;\r |
a405b86d | 2445 | CHAR16 *Replace;\r |
2446 | \r | |
975136ab | 2447 | if ( (SourceString == NULL)\r |
2448 | || (NewString == NULL)\r | |
2449 | || (FindTarget == NULL)\r | |
2450 | || (ReplaceWith == NULL)\r | |
2451 | || (StrLen(FindTarget) < 1)\r | |
2452 | || (StrLen(SourceString) < 1)\r | |
a405b86d | 2453 | ){\r |
975136ab | 2454 | return (EFI_INVALID_PARAMETER);\r |
2455 | }\r | |
a405b86d | 2456 | Replace = NULL;\r |
2457 | if (StrStr(ReplaceWith, L" ") == NULL || !ParameterReplacing) {\r | |
2458 | Replace = StrnCatGrow(&Replace, NULL, ReplaceWith, 0);\r | |
2459 | } else {\r | |
2460 | Replace = AllocateZeroPool(StrSize(ReplaceWith) + 2*sizeof(CHAR16));\r | |
2461 | UnicodeSPrint(Replace, StrSize(ReplaceWith) + 2*sizeof(CHAR16), L"\"%s\"", ReplaceWith);\r | |
2462 | }\r | |
2247dde4 | 2463 | NewString = SetMem16(NewString, NewSize, CHAR_NULL);\r |
2464 | while (*SourceString != CHAR_NULL) {\r | |
969c783b | 2465 | //\r |
a405b86d | 2466 | // if we find the FindTarget and either Skip == FALSE or Skip and we\r |
969c783b | 2467 | // dont have a carrot do a replace...\r |
2468 | //\r | |
1e6e84c7 | 2469 | if (StrnCmp(SourceString, FindTarget, StrLen(FindTarget)) == 0\r |
a405b86d | 2470 | && ((SkipPreCarrot && *(SourceString-1) != L'^') || !SkipPreCarrot)\r |
2471 | ){\r | |
975136ab | 2472 | SourceString += StrLen(FindTarget);\r |
0158294b | 2473 | Size = StrSize(NewString);\r |
a405b86d | 2474 | if ((Size + (StrLen(Replace)*sizeof(CHAR16))) > NewSize) {\r |
2475 | FreePool(Replace);\r | |
975136ab | 2476 | return (EFI_BUFFER_TOO_SMALL);\r |
2477 | }\r | |
a405b86d | 2478 | StrCat(NewString, Replace);\r |
975136ab | 2479 | } else {\r |
0158294b | 2480 | Size = StrSize(NewString);\r |
2481 | if (Size + sizeof(CHAR16) > NewSize) {\r | |
a405b86d | 2482 | FreePool(Replace);\r |
975136ab | 2483 | return (EFI_BUFFER_TOO_SMALL);\r |
2484 | }\r | |
2485 | StrnCat(NewString, SourceString, 1);\r | |
2486 | SourceString++;\r | |
2487 | }\r | |
2488 | }\r | |
a405b86d | 2489 | FreePool(Replace);\r |
975136ab | 2490 | return (EFI_SUCCESS);\r |
2491 | }\r | |
b1f95a06 | 2492 | \r |
e2f8297f | 2493 | /**\r |
2494 | Internal worker function to output a string.\r | |
2495 | \r | |
2496 | This function will output a string to the correct StdOut.\r | |
2497 | \r | |
2498 | @param[in] String The string to print out.\r | |
2499 | \r | |
2500 | @retval EFI_SUCCESS The operation was sucessful.\r | |
2501 | @retval !EFI_SUCCESS The operation failed.\r | |
2502 | **/\r | |
2503 | EFI_STATUS\r | |
2504 | EFIAPI\r | |
2505 | InternalPrintTo (\r | |
2506 | IN CONST CHAR16 *String\r | |
2507 | )\r | |
2508 | {\r | |
2509 | UINTN Size;\r | |
2510 | Size = StrSize(String) - sizeof(CHAR16);\r | |
a405b86d | 2511 | if (Size == 0) {\r |
2512 | return (EFI_SUCCESS);\r | |
2513 | }\r | |
e2f8297f | 2514 | if (mEfiShellParametersProtocol != NULL) {\r |
a405b86d | 2515 | return (mEfiShellProtocol->WriteFile(mEfiShellParametersProtocol->StdOut, &Size, (VOID*)String));\r |
e2f8297f | 2516 | }\r |
2517 | if (mEfiShellInterface != NULL) {\r | |
ecd3d59f | 2518 | //\r |
2519 | // Divide in half for old shell. Must be string length not size.\r | |
2520 | //\r | |
2521 | Size /= 2;\r | |
a405b86d | 2522 | return (mEfiShellInterface->StdOut->Write(mEfiShellInterface->StdOut, &Size, (VOID*)String));\r |
e2f8297f | 2523 | }\r |
2524 | ASSERT(FALSE);\r | |
2525 | return (EFI_UNSUPPORTED);\r | |
2526 | }\r | |
2527 | \r | |
b1f95a06 | 2528 | /**\r |
2529 | Print at a specific location on the screen.\r | |
2530 | \r | |
f1b87e7a | 2531 | This function will move the cursor to a given screen location and print the specified string\r |
1e6e84c7 | 2532 | \r |
2533 | If -1 is specified for either the Row or Col the current screen location for BOTH\r | |
f1b87e7a | 2534 | will be used.\r |
b1f95a06 | 2535 | \r |
2536 | if either Row or Col is out of range for the current console, then ASSERT\r | |
2537 | if Format is NULL, then ASSERT\r | |
2538 | \r | |
1e6e84c7 | 2539 | In addition to the standard %-based flags as supported by UefiLib Print() this supports\r |
b1f95a06 | 2540 | the following additional flags:\r |
2541 | %N - Set output attribute to normal\r | |
2542 | %H - Set output attribute to highlight\r | |
2543 | %E - Set output attribute to error\r | |
2544 | %B - Set output attribute to blue color\r | |
2545 | %V - Set output attribute to green color\r | |
2546 | \r | |
2547 | Note: The background color is controlled by the shell command cls.\r | |
2548 | \r | |
2549 | @param[in] Row the row to print at\r | |
2550 | @param[in] Col the column to print at\r | |
2551 | @param[in] Format the format string\r | |
2247dde4 | 2552 | @param[in] Marker the marker for the variable argument list\r |
b1f95a06 | 2553 | \r |
a405b86d | 2554 | @return EFI_SUCCESS The operation was successful.\r |
2555 | @return EFI_DEVICE_ERROR The console device reported an error.\r | |
b1f95a06 | 2556 | **/\r |
a405b86d | 2557 | EFI_STATUS\r |
b1f95a06 | 2558 | EFIAPI\r |
2247dde4 | 2559 | InternalShellPrintWorker(\r |
b1f95a06 | 2560 | IN INT32 Col OPTIONAL,\r |
2561 | IN INT32 Row OPTIONAL,\r | |
2562 | IN CONST CHAR16 *Format,\r | |
2247dde4 | 2563 | VA_LIST Marker\r |
1e6e84c7 | 2564 | )\r |
2247dde4 | 2565 | {\r |
b1f95a06 | 2566 | EFI_STATUS Status;\r |
975136ab | 2567 | CHAR16 *ResumeLocation;\r |
2568 | CHAR16 *FormatWalker;\r | |
a405b86d | 2569 | UINTN OriginalAttribute;\r |
2570 | \r | |
2571 | Status = EFI_SUCCESS;\r | |
2572 | OriginalAttribute = gST->ConOut->Mode->Attribute;\r | |
1e6e84c7 | 2573 | \r |
975136ab | 2574 | //\r |
2575 | // Back and forth each time fixing up 1 of our flags...\r | |
2576 | //\r | |
a405b86d | 2577 | Status = ShellCopySearchAndReplace(Format, mPostReplaceFormat, PcdGet16 (PcdShellPrintBufferSize), L"%N", L"%%N", FALSE, FALSE);\r |
975136ab | 2578 | ASSERT_EFI_ERROR(Status);\r |
a405b86d | 2579 | Status = ShellCopySearchAndReplace(mPostReplaceFormat, mPostReplaceFormat2, PcdGet16 (PcdShellPrintBufferSize), L"%E", L"%%E", FALSE, FALSE);\r |
975136ab | 2580 | ASSERT_EFI_ERROR(Status);\r |
a405b86d | 2581 | Status = ShellCopySearchAndReplace(mPostReplaceFormat2, mPostReplaceFormat, PcdGet16 (PcdShellPrintBufferSize), L"%H", L"%%H", FALSE, FALSE);\r |
975136ab | 2582 | ASSERT_EFI_ERROR(Status);\r |
a405b86d | 2583 | Status = ShellCopySearchAndReplace(mPostReplaceFormat, mPostReplaceFormat2, PcdGet16 (PcdShellPrintBufferSize), L"%B", L"%%B", FALSE, FALSE);\r |
975136ab | 2584 | ASSERT_EFI_ERROR(Status);\r |
a405b86d | 2585 | Status = ShellCopySearchAndReplace(mPostReplaceFormat2, mPostReplaceFormat, PcdGet16 (PcdShellPrintBufferSize), L"%V", L"%%V", FALSE, FALSE);\r |
975136ab | 2586 | ASSERT_EFI_ERROR(Status);\r |
2587 | \r | |
2588 | //\r | |
2589 | // Use the last buffer from replacing to print from...\r | |
2590 | //\r | |
a405b86d | 2591 | UnicodeVSPrint (mPostReplaceFormat2, PcdGet16 (PcdShellPrintBufferSize), mPostReplaceFormat, Marker);\r |
b1f95a06 | 2592 | \r |
2593 | if (Col != -1 && Row != -1) {\r | |
b1f95a06 | 2594 | Status = gST->ConOut->SetCursorPosition(gST->ConOut, Col, Row);\r |
2595 | ASSERT_EFI_ERROR(Status);\r | |
975136ab | 2596 | }\r |
2597 | \r | |
ecd3d59f | 2598 | FormatWalker = mPostReplaceFormat2;\r |
2247dde4 | 2599 | while (*FormatWalker != CHAR_NULL) {\r |
975136ab | 2600 | //\r |
2601 | // Find the next attribute change request\r | |
2602 | //\r | |
2603 | ResumeLocation = StrStr(FormatWalker, L"%");\r | |
2604 | if (ResumeLocation != NULL) {\r | |
2247dde4 | 2605 | *ResumeLocation = CHAR_NULL;\r |
975136ab | 2606 | }\r |
2607 | //\r | |
2608 | // print the current FormatWalker string\r | |
2609 | //\r | |
a405b86d | 2610 | if (StrLen(FormatWalker)>0) {\r |
2611 | Status = InternalPrintTo(FormatWalker);\r | |
2612 | if (EFI_ERROR(Status)) {\r | |
2613 | break;\r | |
2614 | }\r | |
2615 | }\r | |
2616 | \r | |
975136ab | 2617 | //\r |
2618 | // update the attribute\r | |
2619 | //\r | |
2620 | if (ResumeLocation != NULL) {\r | |
2621 | switch (*(ResumeLocation+1)) {\r | |
2622 | case (L'N'):\r | |
a405b86d | 2623 | gST->ConOut->SetAttribute(gST->ConOut, OriginalAttribute);\r |
975136ab | 2624 | break;\r |
2625 | case (L'E'):\r | |
a405b86d | 2626 | gST->ConOut->SetAttribute(gST->ConOut, EFI_TEXT_ATTR(EFI_YELLOW, ((OriginalAttribute&(BIT4|BIT5|BIT6))>>4)));\r |
975136ab | 2627 | break;\r |
2628 | case (L'H'):\r | |
a405b86d | 2629 | gST->ConOut->SetAttribute(gST->ConOut, EFI_TEXT_ATTR(EFI_WHITE, ((OriginalAttribute&(BIT4|BIT5|BIT6))>>4)));\r |
975136ab | 2630 | break;\r |
2631 | case (L'B'):\r | |
a405b86d | 2632 | gST->ConOut->SetAttribute(gST->ConOut, EFI_TEXT_ATTR(EFI_BLUE, ((OriginalAttribute&(BIT4|BIT5|BIT6))>>4)));\r |
975136ab | 2633 | break;\r |
2634 | case (L'V'):\r | |
a405b86d | 2635 | gST->ConOut->SetAttribute(gST->ConOut, EFI_TEXT_ATTR(EFI_GREEN, ((OriginalAttribute&(BIT4|BIT5|BIT6))>>4)));\r |
975136ab | 2636 | break;\r |
2637 | default:\r | |
e2f8297f | 2638 | //\r |
2639 | // Print a simple '%' symbol\r | |
2640 | //\r | |
2641 | Status = InternalPrintTo(L"%");\r | |
a405b86d | 2642 | if (EFI_ERROR(Status)) {\r |
2643 | break;\r | |
2644 | }\r | |
e2f8297f | 2645 | ResumeLocation = ResumeLocation - 1;\r |
975136ab | 2646 | break;\r |
2647 | }\r | |
2648 | } else {\r | |
2649 | //\r | |
2650 | // reset to normal now...\r | |
2651 | //\r | |
975136ab | 2652 | break;\r |
2653 | }\r | |
2654 | \r | |
2655 | //\r | |
2656 | // update FormatWalker to Resume + 2 (skip the % and the indicator)\r | |
2657 | //\r | |
2658 | FormatWalker = ResumeLocation + 2;\r | |
2659 | }\r | |
b1f95a06 | 2660 | \r |
a405b86d | 2661 | gST->ConOut->SetAttribute(gST->ConOut, OriginalAttribute);\r |
2662 | return (Status);\r | |
5f7431d0 | 2663 | }\r |
2247dde4 | 2664 | \r |
2665 | /**\r | |
2666 | Print at a specific location on the screen.\r | |
2667 | \r | |
e2f8297f | 2668 | This function will move the cursor to a given screen location and print the specified string.\r |
1e6e84c7 | 2669 | \r |
2670 | If -1 is specified for either the Row or Col the current screen location for BOTH\r | |
2247dde4 | 2671 | will be used.\r |
2672 | \r | |
e2f8297f | 2673 | If either Row or Col is out of range for the current console, then ASSERT.\r |
2674 | If Format is NULL, then ASSERT.\r | |
2247dde4 | 2675 | \r |
1e6e84c7 | 2676 | In addition to the standard %-based flags as supported by UefiLib Print() this supports\r |
2247dde4 | 2677 | the following additional flags:\r |
2678 | %N - Set output attribute to normal\r | |
2679 | %H - Set output attribute to highlight\r | |
2680 | %E - Set output attribute to error\r | |
2681 | %B - Set output attribute to blue color\r | |
2682 | %V - Set output attribute to green color\r | |
2683 | \r | |
2684 | Note: The background color is controlled by the shell command cls.\r | |
2685 | \r | |
2247dde4 | 2686 | @param[in] Col the column to print at\r |
a405b86d | 2687 | @param[in] Row the row to print at\r |
2247dde4 | 2688 | @param[in] Format the format string\r |
a405b86d | 2689 | @param[in] ... The variable argument list.\r |
2247dde4 | 2690 | \r |
a405b86d | 2691 | @return EFI_SUCCESS The printing was successful.\r |
2692 | @return EFI_DEVICE_ERROR The console device reported an error.\r | |
2247dde4 | 2693 | **/\r |
a405b86d | 2694 | EFI_STATUS\r |
2247dde4 | 2695 | EFIAPI\r |
2696 | ShellPrintEx(\r | |
2697 | IN INT32 Col OPTIONAL,\r | |
2698 | IN INT32 Row OPTIONAL,\r | |
2699 | IN CONST CHAR16 *Format,\r | |
2700 | ...\r | |
1e6e84c7 | 2701 | )\r |
2247dde4 | 2702 | {\r |
2703 | VA_LIST Marker;\r | |
a405b86d | 2704 | EFI_STATUS RetVal;\r |
2247dde4 | 2705 | VA_START (Marker, Format);\r |
a405b86d | 2706 | RetVal = InternalShellPrintWorker(Col, Row, Format, Marker);\r |
e2f8297f | 2707 | VA_END(Marker);\r |
a405b86d | 2708 | return(RetVal);\r |
2247dde4 | 2709 | }\r |
2710 | \r | |
2711 | /**\r | |
2712 | Print at a specific location on the screen.\r | |
2713 | \r | |
e2f8297f | 2714 | This function will move the cursor to a given screen location and print the specified string.\r |
1e6e84c7 | 2715 | \r |
2716 | If -1 is specified for either the Row or Col the current screen location for BOTH\r | |
e2f8297f | 2717 | will be used.\r |
2247dde4 | 2718 | \r |
e2f8297f | 2719 | If either Row or Col is out of range for the current console, then ASSERT.\r |
2720 | If Format is NULL, then ASSERT.\r | |
2247dde4 | 2721 | \r |
1e6e84c7 | 2722 | In addition to the standard %-based flags as supported by UefiLib Print() this supports\r |
2247dde4 | 2723 | the following additional flags:\r |
1e6e84c7 | 2724 | %N - Set output attribute to normal.\r |
2725 | %H - Set output attribute to highlight.\r | |
2726 | %E - Set output attribute to error.\r | |
2727 | %B - Set output attribute to blue color.\r | |
2728 | %V - Set output attribute to green color.\r | |
2247dde4 | 2729 | \r |
2730 | Note: The background color is controlled by the shell command cls.\r | |
2731 | \r | |
1e6e84c7 | 2732 | @param[in] Col The column to print at.\r |
a405b86d | 2733 | @param[in] Row The row to print at.\r |
1e6e84c7 | 2734 | @param[in] Language The language of the string to retrieve. If this parameter\r |
2735 | is NULL, then the current platform language is used.\r | |
2736 | @param[in] HiiFormatStringId The format string Id for getting from Hii.\r | |
2737 | @param[in] HiiFormatHandle The format string Handle for getting from Hii.\r | |
a405b86d | 2738 | @param[in] ... The variable argument list.\r |
2247dde4 | 2739 | \r |
a405b86d | 2740 | @return EFI_SUCCESS The printing was successful.\r |
2741 | @return EFI_DEVICE_ERROR The console device reported an error.\r | |
2247dde4 | 2742 | **/\r |
a405b86d | 2743 | EFI_STATUS\r |
2247dde4 | 2744 | EFIAPI\r |
2745 | ShellPrintHiiEx(\r | |
2746 | IN INT32 Col OPTIONAL,\r | |
2747 | IN INT32 Row OPTIONAL,\r | |
1e6e84c7 | 2748 | IN CONST CHAR8 *Language OPTIONAL,\r |
2247dde4 | 2749 | IN CONST EFI_STRING_ID HiiFormatStringId,\r |
2750 | IN CONST EFI_HANDLE HiiFormatHandle,\r | |
2751 | ...\r | |
2752 | )\r | |
2753 | {\r | |
2754 | VA_LIST Marker;\r | |
2755 | CHAR16 *HiiFormatString;\r | |
a405b86d | 2756 | EFI_STATUS RetVal;\r |
2247dde4 | 2757 | \r |
2758 | VA_START (Marker, HiiFormatHandle);\r | |
1e6e84c7 | 2759 | HiiFormatString = HiiGetString(HiiFormatHandle, HiiFormatStringId, Language);\r |
2247dde4 | 2760 | ASSERT(HiiFormatString != NULL);\r |
2761 | \r | |
2762 | RetVal = InternalShellPrintWorker(Col, Row, HiiFormatString, Marker);\r | |
2763 | \r | |
a405b86d | 2764 | SHELL_FREE_NON_NULL(HiiFormatString);\r |
e2f8297f | 2765 | VA_END(Marker);\r |
2247dde4 | 2766 | \r |
2767 | return (RetVal);\r | |
2768 | }\r | |
2769 | \r | |
2770 | /**\r | |
2771 | Function to determine if a given filename represents a file or a directory.\r | |
2772 | \r | |
2773 | @param[in] DirName Path to directory to test.\r | |
2774 | \r | |
2775 | @retval EFI_SUCCESS The Path represents a directory\r | |
2776 | @retval EFI_NOT_FOUND The Path does not represent a directory\r | |
2777 | @return other The path failed to open\r | |
2778 | **/\r | |
2779 | EFI_STATUS\r | |
2780 | EFIAPI\r | |
2781 | ShellIsDirectory(\r | |
2782 | IN CONST CHAR16 *DirName\r | |
2783 | )\r | |
2784 | {\r | |
2785 | EFI_STATUS Status;\r | |
a405b86d | 2786 | SHELL_FILE_HANDLE Handle;\r |
2787 | CHAR16 *TempLocation;\r | |
2247dde4 | 2788 | \r |
ecd3d59f | 2789 | ASSERT(DirName != NULL);\r |
2790 | \r | |
a405b86d | 2791 | Handle = NULL;\r |
2792 | TempLocation = NULL;\r | |
2247dde4 | 2793 | \r |
2794 | Status = ShellOpenFileByName(DirName, &Handle, EFI_FILE_MODE_READ, 0);\r | |
2795 | if (EFI_ERROR(Status)) {\r | |
a405b86d | 2796 | //\r |
2797 | // try good logic first.\r | |
2798 | //\r | |
2799 | if (mEfiShellProtocol != NULL) {\r | |
2800 | TempLocation = StrnCatGrow(&TempLocation, NULL, DirName, 0);\r | |
2801 | if (StrStr(TempLocation, L":") != NULL && StrLen(StrStr(TempLocation, L":")) == 2) {\r | |
2802 | *(StrStr(TempLocation, L":")+1) = CHAR_NULL;\r | |
2803 | }\r | |
2804 | if (mEfiShellProtocol->GetDevicePathFromMap(TempLocation) != NULL) {\r | |
2805 | FreePool(TempLocation);\r | |
2806 | return (EFI_SUCCESS);\r | |
2807 | }\r | |
2808 | FreePool(TempLocation);\r | |
2809 | } else {\r | |
2810 | //\r | |
2811 | // probably a map name?!?!!?\r | |
2812 | //\r | |
2813 | TempLocation = StrStr(DirName, L"\\");\r | |
2814 | if (TempLocation != NULL && *(TempLocation+1) == CHAR_NULL) {\r | |
2815 | return (EFI_SUCCESS);\r | |
2816 | }\r | |
2817 | }\r | |
2247dde4 | 2818 | return (Status);\r |
2819 | }\r | |
2820 | \r | |
2821 | if (FileHandleIsDirectory(Handle) == EFI_SUCCESS) {\r | |
2822 | ShellCloseFile(&Handle);\r | |
2823 | return (EFI_SUCCESS);\r | |
2824 | }\r | |
2825 | ShellCloseFile(&Handle);\r | |
2826 | return (EFI_NOT_FOUND);\r | |
2827 | }\r | |
2828 | \r | |
36a9d672 | 2829 | /**\r |
2830 | Function to determine if a given filename represents a file.\r | |
2831 | \r | |
2832 | @param[in] Name Path to file to test.\r | |
2833 | \r | |
2834 | @retval EFI_SUCCESS The Path represents a file.\r | |
2835 | @retval EFI_NOT_FOUND The Path does not represent a file.\r | |
2836 | @retval other The path failed to open.\r | |
2837 | **/\r | |
2838 | EFI_STATUS\r | |
2839 | EFIAPI\r | |
2840 | ShellIsFile(\r | |
2841 | IN CONST CHAR16 *Name\r | |
2842 | )\r | |
2843 | {\r | |
2844 | EFI_STATUS Status;\r | |
a405b86d | 2845 | SHELL_FILE_HANDLE Handle;\r |
36a9d672 | 2846 | \r |
ecd3d59f | 2847 | ASSERT(Name != NULL);\r |
2848 | \r | |
36a9d672 | 2849 | Handle = NULL;\r |
2850 | \r | |
2851 | Status = ShellOpenFileByName(Name, &Handle, EFI_FILE_MODE_READ, 0);\r | |
2852 | if (EFI_ERROR(Status)) {\r | |
2853 | return (Status);\r | |
2854 | }\r | |
2855 | \r | |
2856 | if (FileHandleIsDirectory(Handle) != EFI_SUCCESS) {\r | |
2857 | ShellCloseFile(&Handle);\r | |
2858 | return (EFI_SUCCESS);\r | |
2859 | }\r | |
2860 | ShellCloseFile(&Handle);\r | |
2861 | return (EFI_NOT_FOUND);\r | |
2862 | }\r | |
2863 | \r | |
b3011f40 | 2864 | /**\r |
2865 | Function to determine if a given filename represents a file.\r | |
2866 | \r | |
2867 | This will search the CWD and then the Path.\r | |
2868 | \r | |
2869 | If Name is NULL, then ASSERT.\r | |
2870 | \r | |
2871 | @param[in] Name Path to file to test.\r | |
2872 | \r | |
2873 | @retval EFI_SUCCESS The Path represents a file.\r | |
2874 | @retval EFI_NOT_FOUND The Path does not represent a file.\r | |
2875 | @retval other The path failed to open.\r | |
2876 | **/\r | |
2877 | EFI_STATUS\r | |
2878 | EFIAPI\r | |
2879 | ShellIsFileInPath(\r | |
2880 | IN CONST CHAR16 *Name\r | |
a405b86d | 2881 | )\r |
2882 | {\r | |
b3011f40 | 2883 | CHAR16 *NewName;\r |
2884 | EFI_STATUS Status;\r | |
2885 | \r | |
2886 | if (!EFI_ERROR(ShellIsFile(Name))) {\r | |
a405b86d | 2887 | return (EFI_SUCCESS);\r |
b3011f40 | 2888 | }\r |
2889 | \r | |
2890 | NewName = ShellFindFilePath(Name);\r | |
2891 | if (NewName == NULL) {\r | |
2892 | return (EFI_NOT_FOUND);\r | |
2893 | }\r | |
2894 | Status = ShellIsFile(NewName);\r | |
2895 | FreePool(NewName);\r | |
2896 | return (Status);\r | |
2897 | }\r | |
125c2cf4 | 2898 | /**\r |
1e6e84c7 | 2899 | Function to determine whether a string is decimal or hex representation of a number\r |
125c2cf4 | 2900 | and return the number converted from the string.\r |
2901 | \r | |
2902 | @param[in] String String representation of a number\r | |
2903 | \r | |
2904 | @retval all the number\r | |
2905 | **/\r | |
2906 | UINTN\r | |
2907 | EFIAPI\r | |
2908 | ShellStrToUintn(\r | |
2909 | IN CONST CHAR16 *String\r | |
2910 | )\r | |
2911 | {\r | |
2912 | CONST CHAR16 *Walker;\r | |
b3011f40 | 2913 | for (Walker = String; Walker != NULL && *Walker != CHAR_NULL && *Walker == L' '; Walker++);\r |
1cd45e78 | 2914 | if (Walker == NULL || *Walker == CHAR_NULL) {\r |
2915 | ASSERT(FALSE);\r | |
2916 | return ((UINTN)(-1));\r | |
2917 | } else {\r | |
2918 | if (StrnCmp(Walker, L"0x", 2) == 0 || StrnCmp(Walker, L"0X", 2) == 0){\r | |
2919 | return (StrHexToUintn(Walker));\r | |
2920 | }\r | |
2921 | return (StrDecimalToUintn(Walker));\r | |
125c2cf4 | 2922 | }\r |
125c2cf4 | 2923 | }\r |
2924 | \r | |
2925 | /**\r | |
2926 | Safely append with automatic string resizing given length of Destination and\r | |
2927 | desired length of copy from Source.\r | |
2928 | \r | |
2929 | append the first D characters of Source to the end of Destination, where D is\r | |
2930 | the lesser of Count and the StrLen() of Source. If appending those D characters\r | |
2931 | will fit within Destination (whose Size is given as CurrentSize) and\r | |
1e6e84c7 | 2932 | still leave room for a NULL terminator, then those characters are appended,\r |
2933 | starting at the original terminating NULL of Destination, and a new terminating\r | |
2934 | NULL is appended.\r | |
125c2cf4 | 2935 | \r |
2936 | If appending D characters onto Destination will result in a overflow of the size\r | |
2937 | given in CurrentSize the string will be grown such that the copy can be performed\r | |
2938 | and CurrentSize will be updated to the new size.\r | |
2939 | \r | |
2940 | If Source is NULL, there is nothing to append, just return the current buffer in\r | |
2941 | Destination.\r | |
2942 | \r | |
2943 | if Destination is NULL, then ASSERT()\r | |
2944 | if Destination's current length (including NULL terminator) is already more then\r | |
2945 | CurrentSize, then ASSERT()\r | |
2946 | \r | |
2947 | @param[in,out] Destination The String to append onto\r | |
2948 | @param[in,out] CurrentSize on call the number of bytes in Destination. On\r | |
2949 | return possibly the new size (still in bytes). if NULL\r | |
2950 | then allocate whatever is needed.\r | |
2951 | @param[in] Source The String to append from\r | |
2952 | @param[in] Count Maximum number of characters to append. if 0 then\r | |
2953 | all are appended.\r | |
2954 | \r | |
2955 | @return Destination return the resultant string.\r | |
2956 | **/\r | |
2957 | CHAR16*\r | |
2958 | EFIAPI\r | |
2959 | StrnCatGrow (\r | |
2960 | IN OUT CHAR16 **Destination,\r | |
2961 | IN OUT UINTN *CurrentSize,\r | |
2962 | IN CONST CHAR16 *Source,\r | |
2963 | IN UINTN Count\r | |
2964 | )\r | |
2965 | {\r | |
2966 | UINTN DestinationStartSize;\r | |
2967 | UINTN NewSize;\r | |
2968 | \r | |
2969 | //\r | |
2970 | // ASSERTs\r | |
2971 | //\r | |
2972 | ASSERT(Destination != NULL);\r | |
2973 | \r | |
2974 | //\r | |
2975 | // If there's nothing to do then just return Destination\r | |
2976 | //\r | |
2977 | if (Source == NULL) {\r | |
2978 | return (*Destination);\r | |
2979 | }\r | |
2980 | \r | |
2981 | //\r | |
2982 | // allow for un-initialized pointers, based on size being 0\r | |
2983 | //\r | |
2984 | if (CurrentSize != NULL && *CurrentSize == 0) {\r | |
2985 | *Destination = NULL;\r | |
2986 | }\r | |
2987 | \r | |
2988 | //\r | |
2989 | // allow for NULL pointers address as Destination\r | |
2990 | //\r | |
2991 | if (*Destination != NULL) {\r | |
2992 | ASSERT(CurrentSize != 0);\r | |
2993 | DestinationStartSize = StrSize(*Destination);\r | |
2994 | ASSERT(DestinationStartSize <= *CurrentSize);\r | |
2995 | } else {\r | |
2996 | DestinationStartSize = 0;\r | |
2997 | // ASSERT(*CurrentSize == 0);\r | |
2998 | }\r | |
2999 | \r | |
3000 | //\r | |
3001 | // Append all of Source?\r | |
3002 | //\r | |
3003 | if (Count == 0) {\r | |
3004 | Count = StrLen(Source);\r | |
3005 | }\r | |
3006 | \r | |
3007 | //\r | |
3008 | // Test and grow if required\r | |
3009 | //\r | |
3010 | if (CurrentSize != NULL) {\r | |
3011 | NewSize = *CurrentSize;\r | |
3012 | while (NewSize < (DestinationStartSize + (Count*sizeof(CHAR16)))) {\r | |
3013 | NewSize += 2 * Count * sizeof(CHAR16);\r | |
3014 | }\r | |
3015 | *Destination = ReallocatePool(*CurrentSize, NewSize, *Destination);\r | |
c9d92df0 | 3016 | ASSERT(*Destination != NULL);\r |
125c2cf4 | 3017 | *CurrentSize = NewSize;\r |
3018 | } else {\r | |
3019 | *Destination = AllocateZeroPool((Count+1)*sizeof(CHAR16));\r | |
c9d92df0 | 3020 | ASSERT(*Destination != NULL);\r |
125c2cf4 | 3021 | }\r |
3022 | \r | |
3023 | //\r | |
3024 | // Now use standard StrnCat on a big enough buffer\r | |
3025 | //\r | |
c9d92df0 | 3026 | if (*Destination == NULL) {\r |
3027 | return (NULL);\r | |
3028 | }\r | |
125c2cf4 | 3029 | return StrnCat(*Destination, Source, Count);\r |
3030 | }\r | |
c9d92df0 | 3031 | \r |
3032 | /**\r | |
3033 | Prompt the user and return the resultant answer to the requestor.\r | |
3034 | \r | |
3035 | This function will display the requested question on the shell prompt and then\r | |
3036 | wait for an apropriate answer to be input from the console.\r | |
3037 | \r | |
a405b86d | 3038 | if the SHELL_PROMPT_REQUEST_TYPE is SHELL_PROMPT_REQUEST_TYPE_YESNO, ShellPromptResponseTypeQuitContinue\r |
c9d92df0 | 3039 | or SHELL_PROMPT_REQUEST_TYPE_YESNOCANCEL then *Response is of type SHELL_PROMPT_RESPONSE.\r |
3040 | \r | |
a405b86d | 3041 | if the SHELL_PROMPT_REQUEST_TYPE is ShellPromptResponseTypeFreeform then *Response is of type\r |
c9d92df0 | 3042 | CHAR16*.\r |
3043 | \r | |
3044 | In either case *Response must be callee freed if Response was not NULL;\r | |
3045 | \r | |
3046 | @param Type What type of question is asked. This is used to filter the input\r | |
3047 | to prevent invalid answers to question.\r | |
3048 | @param Prompt Pointer to string prompt to use to request input.\r | |
3049 | @param Response Pointer to Response which will be populated upon return.\r | |
3050 | \r | |
3051 | @retval EFI_SUCCESS The operation was sucessful.\r | |
3052 | @retval EFI_UNSUPPORTED The operation is not supported as requested.\r | |
3053 | @retval EFI_INVALID_PARAMETER A parameter was invalid.\r | |
3054 | @return other The operation failed.\r | |
3055 | **/\r | |
3056 | EFI_STATUS\r | |
3057 | EFIAPI\r | |
3058 | ShellPromptForResponse (\r | |
3059 | IN SHELL_PROMPT_REQUEST_TYPE Type,\r | |
3060 | IN CHAR16 *Prompt OPTIONAL,\r | |
3061 | IN OUT VOID **Response OPTIONAL\r | |
3062 | )\r | |
3063 | {\r | |
3064 | EFI_STATUS Status;\r | |
3065 | EFI_INPUT_KEY Key;\r | |
3066 | UINTN EventIndex;\r | |
3067 | SHELL_PROMPT_RESPONSE *Resp;\r | |
a405b86d | 3068 | UINTN Size;\r |
3069 | CHAR16 *Buffer;\r | |
c9d92df0 | 3070 | \r |
a405b86d | 3071 | Status = EFI_UNSUPPORTED;\r |
3072 | Resp = NULL;\r | |
3073 | Buffer = NULL;\r | |
3074 | Size = 0;\r | |
3075 | if (Type != ShellPromptResponseTypeFreeform) {\r | |
3076 | Resp = (SHELL_PROMPT_RESPONSE*)AllocatePool(sizeof(SHELL_PROMPT_RESPONSE));\r | |
90bfa227 | 3077 | }\r |
c9d92df0 | 3078 | \r |
3079 | switch(Type) {\r | |
a405b86d | 3080 | case ShellPromptResponseTypeQuitContinue:\r |
c9d92df0 | 3081 | if (Prompt != NULL) {\r |
3082 | ShellPrintEx(-1, -1, L"%s", Prompt);\r | |
3083 | }\r | |
3084 | //\r | |
3085 | // wait for valid response\r | |
3086 | //\r | |
3087 | gBS->WaitForEvent (1, &gST->ConIn->WaitForKey, &EventIndex);\r | |
3088 | Status = gST->ConIn->ReadKeyStroke (gST->ConIn, &Key);\r | |
3089 | ASSERT_EFI_ERROR(Status);\r | |
3090 | ShellPrintEx(-1, -1, L"%c", Key.UnicodeChar);\r | |
3091 | if (Key.UnicodeChar == L'Q' || Key.UnicodeChar ==L'q') {\r | |
a405b86d | 3092 | *Resp = ShellPromptResponseQuit;\r |
c9d92df0 | 3093 | } else {\r |
a405b86d | 3094 | *Resp = ShellPromptResponseContinue;\r |
c9d92df0 | 3095 | }\r |
3096 | break;\r | |
a405b86d | 3097 | case ShellPromptResponseTypeYesNoCancel:\r |
c9d92df0 | 3098 | if (Prompt != NULL) {\r |
3099 | ShellPrintEx(-1, -1, L"%s", Prompt);\r | |
3100 | }\r | |
3101 | //\r | |
3102 | // wait for valid response\r | |
3103 | //\r | |
a405b86d | 3104 | *Resp = ShellPromptResponseMax;\r |
3105 | while (*Resp == ShellPromptResponseMax) {\r | |
c9d92df0 | 3106 | gBS->WaitForEvent (1, &gST->ConIn->WaitForKey, &EventIndex);\r |
3107 | Status = gST->ConIn->ReadKeyStroke (gST->ConIn, &Key);\r | |
3108 | ASSERT_EFI_ERROR(Status);\r | |
3109 | ShellPrintEx(-1, -1, L"%c", Key.UnicodeChar);\r | |
3110 | switch (Key.UnicodeChar) {\r | |
3111 | case L'Y':\r | |
3112 | case L'y':\r | |
a405b86d | 3113 | *Resp = ShellPromptResponseYes;\r |
c9d92df0 | 3114 | break;\r |
3115 | case L'N':\r | |
3116 | case L'n':\r | |
a405b86d | 3117 | *Resp = ShellPromptResponseNo;\r |
3118 | break;\r | |
3119 | case L'C':\r | |
3120 | case L'c':\r | |
3121 | *Resp = ShellPromptResponseCancel;\r | |
3122 | break;\r | |
3123 | }\r | |
3124 | }\r | |
3125 | break; case ShellPromptResponseTypeYesNoAllCancel:\r | |
3126 | if (Prompt != NULL) {\r | |
3127 | ShellPrintEx(-1, -1, L"%s", Prompt);\r | |
3128 | }\r | |
3129 | //\r | |
3130 | // wait for valid response\r | |
3131 | //\r | |
3132 | *Resp = ShellPromptResponseMax;\r | |
3133 | while (*Resp == ShellPromptResponseMax) {\r | |
3134 | gBS->WaitForEvent (1, &gST->ConIn->WaitForKey, &EventIndex);\r | |
3135 | Status = gST->ConIn->ReadKeyStroke (gST->ConIn, &Key);\r | |
3136 | ASSERT_EFI_ERROR(Status);\r | |
3137 | ShellPrintEx(-1, -1, L"%c", Key.UnicodeChar);\r | |
3138 | switch (Key.UnicodeChar) {\r | |
3139 | case L'Y':\r | |
3140 | case L'y':\r | |
3141 | *Resp = ShellPromptResponseYes;\r | |
3142 | break;\r | |
3143 | case L'N':\r | |
3144 | case L'n':\r | |
3145 | *Resp = ShellPromptResponseNo;\r | |
c9d92df0 | 3146 | break;\r |
3147 | case L'A':\r | |
3148 | case L'a':\r | |
a405b86d | 3149 | *Resp = ShellPromptResponseAll;\r |
c9d92df0 | 3150 | break;\r |
3151 | case L'C':\r | |
3152 | case L'c':\r | |
a405b86d | 3153 | *Resp = ShellPromptResponseCancel;\r |
c9d92df0 | 3154 | break;\r |
3155 | }\r | |
3156 | }\r | |
3157 | break;\r | |
a405b86d | 3158 | case ShellPromptResponseTypeEnterContinue:\r |
3159 | case ShellPromptResponseTypeAnyKeyContinue:\r | |
c9d92df0 | 3160 | if (Prompt != NULL) {\r |
3161 | ShellPrintEx(-1, -1, L"%s", Prompt);\r | |
3162 | }\r | |
3163 | //\r | |
3164 | // wait for valid response\r | |
3165 | //\r | |
a405b86d | 3166 | *Resp = ShellPromptResponseMax;\r |
3167 | while (*Resp == ShellPromptResponseMax) {\r | |
c9d92df0 | 3168 | gBS->WaitForEvent (1, &gST->ConIn->WaitForKey, &EventIndex);\r |
a405b86d | 3169 | if (Type == ShellPromptResponseTypeEnterContinue) {\r |
c9d92df0 | 3170 | Status = gST->ConIn->ReadKeyStroke (gST->ConIn, &Key);\r |
3171 | ASSERT_EFI_ERROR(Status);\r | |
3172 | ShellPrintEx(-1, -1, L"%c", Key.UnicodeChar);\r | |
3173 | if (Key.UnicodeChar == CHAR_CARRIAGE_RETURN) {\r | |
a405b86d | 3174 | *Resp = ShellPromptResponseContinue;\r |
c9d92df0 | 3175 | break;\r |
3176 | }\r | |
3177 | }\r | |
a405b86d | 3178 | if (Type == ShellPromptResponseTypeAnyKeyContinue) {\r |
3179 | Status = gST->ConIn->ReadKeyStroke (gST->ConIn, &Key);\r | |
3180 | ASSERT_EFI_ERROR(Status);\r | |
3181 | *Resp = ShellPromptResponseContinue;\r | |
3182 | break;\r | |
3183 | }\r | |
3184 | }\r | |
3185 | break;\r | |
3186 | case ShellPromptResponseTypeYesNo:\r | |
3187 | if (Prompt != NULL) {\r | |
3188 | ShellPrintEx(-1, -1, L"%s", Prompt);\r | |
3189 | }\r | |
3190 | //\r | |
3191 | // wait for valid response\r | |
3192 | //\r | |
3193 | *Resp = ShellPromptResponseMax;\r | |
3194 | while (*Resp == ShellPromptResponseMax) {\r | |
3195 | gBS->WaitForEvent (1, &gST->ConIn->WaitForKey, &EventIndex);\r | |
3196 | Status = gST->ConIn->ReadKeyStroke (gST->ConIn, &Key);\r | |
3197 | ASSERT_EFI_ERROR(Status);\r | |
3198 | ShellPrintEx(-1, -1, L"%c", Key.UnicodeChar);\r | |
3199 | switch (Key.UnicodeChar) {\r | |
3200 | case L'Y':\r | |
3201 | case L'y':\r | |
3202 | *Resp = ShellPromptResponseYes;\r | |
3203 | break;\r | |
3204 | case L'N':\r | |
3205 | case L'n':\r | |
3206 | *Resp = ShellPromptResponseNo;\r | |
3207 | break;\r | |
3208 | }\r | |
3209 | }\r | |
3210 | break;\r | |
3211 | case ShellPromptResponseTypeFreeform:\r | |
3212 | if (Prompt != NULL) {\r | |
3213 | ShellPrintEx(-1, -1, L"%s", Prompt);\r | |
3214 | }\r | |
3215 | while(1) {\r | |
3216 | gBS->WaitForEvent (1, &gST->ConIn->WaitForKey, &EventIndex);\r | |
3217 | Status = gST->ConIn->ReadKeyStroke (gST->ConIn, &Key);\r | |
3218 | ASSERT_EFI_ERROR(Status);\r | |
3219 | ShellPrintEx(-1, -1, L"%c", Key.UnicodeChar);\r | |
3220 | if (Key.UnicodeChar == CHAR_CARRIAGE_RETURN) {\r | |
c9d92df0 | 3221 | break;\r |
3222 | }\r | |
a405b86d | 3223 | ASSERT((Buffer == NULL && Size == 0) || (Buffer != NULL));\r |
3224 | StrnCatGrow(&Buffer, &Size, &Key.UnicodeChar, 1);\r | |
c9d92df0 | 3225 | }\r |
3226 | break;\r | |
a405b86d | 3227 | //\r |
3228 | // This is the location to add new prompt types.\r | |
3229 | //\r | |
c9d92df0 | 3230 | default:\r |
a405b86d | 3231 | ASSERT(FALSE);\r |
c9d92df0 | 3232 | }\r |
3233 | \r | |
3234 | if (Response != NULL) {\r | |
a405b86d | 3235 | if (Resp != NULL) {\r |
3236 | *Response = Resp;\r | |
3237 | } else if (Buffer != NULL) {\r | |
3238 | *Response = Buffer;\r | |
3239 | }\r | |
c9d92df0 | 3240 | } else {\r |
a405b86d | 3241 | if (Resp != NULL) {\r |
3242 | FreePool(Resp);\r | |
3243 | }\r | |
3244 | if (Buffer != NULL) {\r | |
3245 | FreePool(Buffer);\r | |
3246 | }\r | |
c9d92df0 | 3247 | }\r |
3248 | \r | |
a405b86d | 3249 | ShellPrintEx(-1, -1, L"\r\n");\r |
c9d92df0 | 3250 | return (Status);\r |
3251 | }\r | |
3252 | \r | |
3253 | /**\r | |
3254 | Prompt the user and return the resultant answer to the requestor.\r | |
3255 | \r | |
3256 | This function is the same as ShellPromptForResponse, except that the prompt is\r | |
3257 | automatically pulled from HII.\r | |
3258 | \r | |
3259 | @param Type What type of question is asked. This is used to filter the input\r | |
3260 | to prevent invalid answers to question.\r | |
a405b86d | 3261 | @param[in] HiiFormatStringId The format string Id for getting from Hii.\r |
3262 | @param[in] HiiFormatHandle The format string Handle for getting from Hii.\r | |
3263 | @param Response Pointer to Response which will be populated upon return.\r | |
c9d92df0 | 3264 | \r |
3265 | @retval EFI_SUCCESS the operation was sucessful.\r | |
3266 | @return other the operation failed.\r | |
3267 | \r | |
3268 | @sa ShellPromptForResponse\r | |
3269 | **/\r | |
3270 | EFI_STATUS\r | |
3271 | EFIAPI\r | |
3272 | ShellPromptForResponseHii (\r | |
3273 | IN SHELL_PROMPT_REQUEST_TYPE Type,\r | |
3274 | IN CONST EFI_STRING_ID HiiFormatStringId,\r | |
3275 | IN CONST EFI_HANDLE HiiFormatHandle,\r | |
3276 | IN OUT VOID **Response\r | |
3277 | )\r | |
3278 | {\r | |
3279 | CHAR16 *Prompt;\r | |
3280 | EFI_STATUS Status;\r | |
3281 | \r | |
3282 | Prompt = HiiGetString(HiiFormatHandle, HiiFormatStringId, NULL);\r | |
3283 | Status = ShellPromptForResponse(Type, Prompt, Response);\r | |
3284 | FreePool(Prompt);\r | |
3285 | return (Status);\r | |
3286 | }\r | |
3287 | \r | |
a405b86d | 3288 | /**\r |
3289 | Function to determin if an entire string is a valid number.\r | |
3290 | \r | |
3291 | If Hex it must be preceeded with a 0x or has ForceHex, set TRUE.\r | |
c9d92df0 | 3292 | \r |
a405b86d | 3293 | @param[in] String The string to evaluate.\r |
3294 | @param[in] ForceHex TRUE - always assume hex.\r | |
3295 | @param[in] StopAtSpace TRUE to halt upon finding a space, FALSE to keep going.\r | |
3296 | \r | |
3297 | @retval TRUE It is all numeric (dec/hex) characters.\r | |
3298 | @retval FALSE There is a non-numeric character.\r | |
3299 | **/\r | |
3300 | BOOLEAN\r | |
3301 | EFIAPI\r | |
3302 | ShellIsHexOrDecimalNumber (\r | |
3303 | IN CONST CHAR16 *String,\r | |
3304 | IN CONST BOOLEAN ForceHex,\r | |
3305 | IN CONST BOOLEAN StopAtSpace\r | |
3306 | )\r | |
3307 | {\r | |
3308 | BOOLEAN Hex;\r | |
3309 | \r | |
3310 | //\r | |
3311 | // chop off a single negative sign\r | |
3312 | //\r | |
3313 | if (String != NULL && *String == L'-') {\r | |
3314 | String++;\r | |
3315 | }\r | |
3316 | \r | |
3317 | if (String == NULL) {\r | |
3318 | return (FALSE);\r | |
3319 | }\r | |
3320 | \r | |
3321 | //\r | |
3322 | // chop leading zeroes\r | |
3323 | //\r | |
3324 | while(String != NULL && *String == L'0'){\r | |
3325 | String++;\r | |
3326 | }\r | |
3327 | //\r | |
3328 | // allow '0x' or '0X', but not 'x' or 'X'\r | |
3329 | //\r | |
3330 | if (String != NULL && (*String == L'x' || *String == L'X')) {\r | |
3331 | if (*(String-1) != L'0') {\r | |
3332 | //\r | |
3333 | // we got an x without a preceeding 0\r | |
3334 | //\r | |
3335 | return (FALSE);\r | |
3336 | }\r | |
3337 | String++;\r | |
3338 | Hex = TRUE;\r | |
3339 | } else if (ForceHex) {\r | |
3340 | Hex = TRUE;\r | |
3341 | } else {\r | |
3342 | Hex = FALSE;\r | |
3343 | }\r | |
3344 | \r | |
3345 | //\r | |
3346 | // loop through the remaining characters and use the lib function\r | |
3347 | //\r | |
3348 | for ( ; String != NULL && *String != CHAR_NULL && !(StopAtSpace && *String == L' ') ; String++){\r | |
3349 | if (Hex) {\r | |
3350 | if (!ShellIsHexaDecimalDigitCharacter(*String)) {\r | |
3351 | return (FALSE);\r | |
3352 | }\r | |
3353 | } else {\r | |
3354 | if (!ShellIsDecimalDigitCharacter(*String)) {\r | |
3355 | return (FALSE);\r | |
3356 | }\r | |
3357 | }\r | |
3358 | }\r | |
3359 | return (TRUE);\r | |
3360 | }\r | |
3361 | \r | |
3362 | /**\r | |
3363 | Function to determine if a given filename exists.\r | |
3364 | \r | |
3365 | @param[in] Name Path to test.\r | |
3366 | \r | |
3367 | @retval EFI_SUCCESS The Path represents a file.\r | |
3368 | @retval EFI_NOT_FOUND The Path does not represent a file.\r | |
3369 | @retval other The path failed to open.\r | |
3370 | **/\r | |
3371 | EFI_STATUS\r | |
3372 | EFIAPI\r | |
3373 | ShellFileExists(\r | |
3374 | IN CONST CHAR16 *Name\r | |
3375 | )\r | |
3376 | {\r | |
3377 | EFI_STATUS Status;\r | |
3378 | EFI_SHELL_FILE_INFO *List;\r | |
3379 | \r | |
3380 | ASSERT(Name != NULL);\r | |
3381 | \r | |
3382 | List = NULL;\r | |
3383 | Status = ShellOpenFileMetaArg((CHAR16*)Name, EFI_FILE_MODE_READ, &List);\r | |
3384 | if (EFI_ERROR(Status)) {\r | |
3385 | return (Status);\r | |
3386 | }\r | |
3387 | \r | |
3388 | ShellCloseFileMetaArg(&List);\r | |
3389 | \r | |
3390 | return (EFI_SUCCESS);\r | |
3391 | }\r |