]> git.proxmox.com Git - mirror_edk2.git/blame - ShellPkg/Library/UefiShellDebug1CommandsLib/UefiShellDebug1CommandsLib.c
MdeModulePkg-DxeCore: rename CoreGetMemoryMapPropertiesTable
[mirror_edk2.git] / ShellPkg / Library / UefiShellDebug1CommandsLib / UefiShellDebug1CommandsLib.c
CommitLineData
5d73d92f 1/** @file\r
2 Main file for NULL named library for debug1 profile shell command functions.\r
3\r
3737ac2b 4 Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>\r
5d73d92f 5 This program and the accompanying materials\r
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
9\r
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
12\r
13**/\r
14\r
15#include "UefiShellDebug1CommandsLib.h"\r
fba9b6ba 16#include <Library/BcfgCommandLib.h>\r
5d73d92f 17\r
18STATIC CONST CHAR16 mFileName[] = L"Debug1Commands";\r
19EFI_HANDLE gShellDebug1HiiHandle = NULL;\r
5d73d92f 20\r
3737ac2b 21/**\r
22 Gets the debug file name. This will be used if HII is not working.\r
23\r
24 @retval NULL No file is available.\r
25 @return The NULL-terminated filename to get help from.\r
26**/\r
5d73d92f 27CONST CHAR16*\r
28EFIAPI\r
29ShellCommandGetManFileNameDebug1 (\r
30 VOID\r
31 )\r
32{\r
33 return (mFileName);\r
34}\r
35\r
36/**\r
37 Constructor for the Shell Debug1 Commands library.\r
38\r
39 @param ImageHandle the image handle of the process\r
40 @param SystemTable the EFI System Table pointer\r
41\r
42 @retval EFI_SUCCESS the shell command handlers were installed sucessfully\r
43 @retval EFI_UNSUPPORTED the shell level required was not found.\r
44**/\r
45EFI_STATUS\r
46EFIAPI\r
47UefiShellDebug1CommandsLibConstructor (\r
48 IN EFI_HANDLE ImageHandle,\r
49 IN EFI_SYSTEM_TABLE *SystemTable\r
50 )\r
51{\r
52 //\r
53 // check our bit of the profiles mask\r
54 //\r
55 if ((PcdGet8(PcdShellProfileMask) & BIT1) == 0) {\r
82571fb5 56 return (EFI_SUCCESS);\r
5d73d92f 57 }\r
58\r
59 //\r
60 // install the HII stuff.\r
61 //\r
62 gShellDebug1HiiHandle = HiiAddPackages (&gShellDebug1HiiGuid, gImageHandle, UefiShellDebug1CommandsLibStrings, NULL);\r
63 if (gShellDebug1HiiHandle == NULL) {\r
64 return (EFI_DEVICE_ERROR);\r
65 }\r
66\r
67 //\r
68 // install our shell command handlers that are always installed\r
69 //\r
3737ac2b 70 ShellCommandRegisterCommandName(L"setsize", ShellCommandRunSetSize , ShellCommandGetManFileNameDebug1, 0, L"Debug1", TRUE, gShellDebug1HiiHandle, STRING_TOKEN(STR_GET_HELP_SETSIZE) );\r
5d73d92f 71 ShellCommandRegisterCommandName(L"comp", ShellCommandRunComp , ShellCommandGetManFileNameDebug1, 0, L"Debug1", TRUE, gShellDebug1HiiHandle, STRING_TOKEN(STR_GET_HELP_COMP) );\r
72 ShellCommandRegisterCommandName(L"mode", ShellCommandRunMode , ShellCommandGetManFileNameDebug1, 0, L"Debug1", TRUE, gShellDebug1HiiHandle, STRING_TOKEN(STR_GET_HELP_MODE) );\r
73 ShellCommandRegisterCommandName(L"memmap", ShellCommandRunMemMap , ShellCommandGetManFileNameDebug1, 0, L"Debug1", TRUE, gShellDebug1HiiHandle, STRING_TOKEN(STR_GET_HELP_MEMMAP) );\r
74 ShellCommandRegisterCommandName(L"eficompress", ShellCommandRunEfiCompress , ShellCommandGetManFileNameDebug1, 0, L"Debug1", TRUE, gShellDebug1HiiHandle, STRING_TOKEN(STR_GET_HELP_EFICOMPRESS) );\r
75 ShellCommandRegisterCommandName(L"efidecompress", ShellCommandRunEfiDecompress , ShellCommandGetManFileNameDebug1, 0, L"Debug1", TRUE, gShellDebug1HiiHandle, STRING_TOKEN(STR_GET_HELP_EFIDCOMPRESS) );\r
76 ShellCommandRegisterCommandName(L"dmem", ShellCommandRunDmem , ShellCommandGetManFileNameDebug1, 0, L"Debug1", TRUE, gShellDebug1HiiHandle, STRING_TOKEN(STR_GET_HELP_DMEM) );\r
3737ac2b 77 ShellCommandRegisterCommandName(L"loadpcirom", ShellCommandRunLoadPciRom , ShellCommandGetManFileNameDebug1, 0, L"Debug1", TRUE, gShellDebug1HiiHandle, STRING_TOKEN(STR_GET_HELP_LOAD_PCI_ROM) );\r
5d73d92f 78 ShellCommandRegisterCommandName(L"mm", ShellCommandRunMm , ShellCommandGetManFileNameDebug1, 0, L"Debug1", TRUE, gShellDebug1HiiHandle, STRING_TOKEN(STR_GET_HELP_MM) );\r
3737ac2b 79 ShellCommandRegisterCommandName(L"setvar", ShellCommandRunSetVar , ShellCommandGetManFileNameDebug1, 0, L"Debug1", TRUE, gShellDebug1HiiHandle, STRING_TOKEN(STR_GET_HELP_SETVAR) );\r
80 ShellCommandRegisterCommandName(L"sermode", ShellCommandRunSerMode , ShellCommandGetManFileNameDebug1, 0, L"Debug1", TRUE, gShellDebug1HiiHandle, STRING_TOKEN(STR_GET_HELP_SERMODE) );\r
81 ShellCommandRegisterCommandName(L"pci", ShellCommandRunPci , ShellCommandGetManFileNameDebug1, 0, L"Debug1", TRUE, gShellDebug1HiiHandle, STRING_TOKEN(STR_GET_HELP_PCI) );\r
5d73d92f 82 ShellCommandRegisterCommandName(L"smbiosview", ShellCommandRunSmbiosView , ShellCommandGetManFileNameDebug1, 0, L"Debug1", TRUE, gShellDebug1HiiHandle, STRING_TOKEN(STR_GET_HELP_SMBIOSVIEW) );\r
83 ShellCommandRegisterCommandName(L"dmpstore", ShellCommandRunDmpStore , ShellCommandGetManFileNameDebug1, 0, L"Debug1", TRUE, gShellDebug1HiiHandle, STRING_TOKEN(STR_GET_HELP_DMPSTORE) );\r
84 ShellCommandRegisterCommandName(L"dblk", ShellCommandRunDblk , ShellCommandGetManFileNameDebug1, 0, L"Debug1", TRUE, gShellDebug1HiiHandle, STRING_TOKEN(STR_GET_HELP_DBLK) );\r
3737ac2b 85 ShellCommandRegisterCommandName(L"edit", ShellCommandRunEdit , ShellCommandGetManFileNameDebug1, 0, L"Debug1", TRUE, gShellDebug1HiiHandle, STRING_TOKEN(STR_GET_HELP_EDIT) );\r
86 ShellCommandRegisterCommandName(L"hexedit", ShellCommandRunHexEdit , ShellCommandGetManFileNameDebug1, 0, L"Debug1", TRUE, gShellDebug1HiiHandle, STRING_TOKEN(STR_GET_HELP_HEXEDIT) );\r
5d73d92f 87\r
5d73d92f 88 ShellCommandRegisterAlias(L"dmem", L"mem");\r
89\r
fba9b6ba
JC
90 BcfgLibraryRegisterBcfgCommand(ImageHandle, SystemTable, L"Debug1");\r
91\r
5d73d92f 92 return (EFI_SUCCESS);\r
93}\r
94\r
95/**\r
96 Destructor for the library. free any resources.\r
3737ac2b 97\r
98 @param ImageHandle The image handle of the process.\r
99 @param SystemTable The EFI System Table pointer.\r
5d73d92f 100**/\r
101EFI_STATUS\r
102EFIAPI\r
103UefiShellDebug1CommandsLibDestructor (\r
104 IN EFI_HANDLE ImageHandle,\r
105 IN EFI_SYSTEM_TABLE *SystemTable\r
106 )\r
107{\r
108 if (gShellDebug1HiiHandle != NULL) {\r
109 HiiRemovePackages(gShellDebug1HiiHandle);\r
110 }\r
fba9b6ba
JC
111\r
112 BcfgLibraryUnregisterBcfgCommand(ImageHandle, SystemTable);\r
5d73d92f 113 return (EFI_SUCCESS);\r
114}\r
115\r
5d73d92f 116/**\r
117 Convert a Unicode character to upper case only if\r
118 it maps to a valid small-case ASCII character.\r
119\r
120 This internal function only deal with Unicode character\r
121 which maps to a valid small-case ASCII character, i.e.\r
122 L'a' to L'z'. For other Unicode character, the input character\r
123 is returned directly.\r
124\r
125 @param Char The character to convert.\r
126\r
127 @retval LowerCharacter If the Char is with range L'a' to L'z'.\r
128 @retval Unchanged Otherwise.\r
129\r
130\r
131 //Stolen from MdePkg Baselib\r
132**/\r
133CHAR16\r
134EFIAPI\r
135CharToUpper (\r
136 IN CHAR16 Char\r
137 )\r
138{\r
139 if (Char >= L'a' && Char <= L'z') {\r
140 return (CHAR16) (Char - (L'a' - L'A'));\r
141 }\r
142\r
143 return Char;\r
144}\r
145\r
146/**\r
147 Function returns a system configuration table that is stored in the\r
148 EFI System Table based on the provided GUID.\r
149\r
4ff7e37b
ED
150 @param[in] TableGuid A pointer to the table's GUID type.\r
151 @param[in, out] Table On exit, a pointer to a system configuration table.\r
5d73d92f 152\r
153 @retval EFI_SUCCESS A configuration table matching TableGuid was found.\r
154 @retval EFI_NOT_FOUND A configuration table matching TableGuid was not found.\r
155**/\r
156EFI_STATUS\r
157EFIAPI\r
158GetSystemConfigurationTable (\r
159 IN EFI_GUID *TableGuid,\r
160 IN OUT VOID **Table\r
161 )\r
162{\r
163 UINTN Index;\r
164 ASSERT (Table != NULL);\r
165\r
166 for (Index = 0; Index < gST->NumberOfTableEntries; Index++) {\r
3737ac2b 167 if (CompareGuid (TableGuid, &(gST->ConfigurationTable[Index].VendorGuid))) {\r
5d73d92f 168 *Table = gST->ConfigurationTable[Index].VendorTable;\r
169 return EFI_SUCCESS;\r
170 }\r
171 }\r
172\r
173 return EFI_NOT_FOUND;\r
174}\r
175\r
176/**\r
177 Convert a Unicode character to numerical value.\r
178\r
179 This internal function only deal with Unicode character\r
180 which maps to a valid hexadecimal ASII character, i.e.\r
181 L'0' to L'9', L'a' to L'f' or L'A' to L'F'. For other\r
182 Unicode character, the value returned does not make sense.\r
183\r
184 @param Char The character to convert.\r
185\r
186 @return The numerical value converted.\r
187\r
188**/\r
189UINTN\r
190EFIAPI\r
191HexCharToUintn (\r
192 IN CHAR16 Char\r
193 )\r
194{\r
195 if (Char >= L'0' && Char <= L'9') {\r
196 return Char - L'0';\r
197 }\r
198\r
199 return (UINTN) (10 + CharToUpper (Char) - L'A');\r
200}\r
201\r
3737ac2b 202/**\r
203 Convert a string representation of a guid to a Guid value.\r
204\r
4ff7e37b
ED
205 @param[in] StringGuid The pointer to the string of a guid.\r
206 @param[in, out] Guid The pointer to the GUID structure to populate.\r
3737ac2b 207\r
208 @retval EFI_INVALID_PARAMETER A parameter was invalid.\r
209 @retval EFI_SUCCESS The conversion was successful.\r
210**/\r
5d73d92f 211EFI_STATUS\r
212EFIAPI\r
213ConvertStringToGuid (\r
214 IN CONST CHAR16 *StringGuid,\r
215 IN OUT EFI_GUID *Guid\r
216 )\r
217{\r
3737ac2b 218 CHAR16 *TempCopy;\r
219 CHAR16 *TempSpot;\r
220 CHAR16 *Walker;\r
221 UINT64 TempVal;\r
222 EFI_STATUS Status;\r
223\r
224 if (StringGuid == NULL) {\r
225 return (EFI_INVALID_PARAMETER);\r
226 } else if (StrLen(StringGuid) != 36) {\r
5d73d92f 227 return (EFI_INVALID_PARAMETER);\r
3737ac2b 228 } \r
229 TempCopy = NULL;\r
230 TempCopy = StrnCatGrow(&TempCopy, NULL, StringGuid, 0);\r
532691c8 231 if (TempCopy == NULL) {\r
232 return (EFI_OUT_OF_RESOURCES);\r
233 }\r
3737ac2b 234 Walker = TempCopy;\r
235 TempSpot = StrStr(Walker, L"-");\r
33c031ee 236 if (TempSpot != NULL) {\r
237 *TempSpot = CHAR_NULL;\r
238 }\r
3737ac2b 239 Status = ShellConvertStringToUint64(Walker, &TempVal, TRUE, FALSE);\r
240 if (EFI_ERROR(Status)) {\r
241 FreePool(TempCopy);\r
242 return (Status);\r
243 }\r
244 Guid->Data1 = (UINT32)TempVal;\r
245 Walker += 9;\r
246 TempSpot = StrStr(Walker, L"-");\r
33c031ee 247 if (TempSpot != NULL) {\r
248 *TempSpot = CHAR_NULL;\r
249 }\r
3737ac2b 250 Status = ShellConvertStringToUint64(Walker, &TempVal, TRUE, FALSE);\r
251 if (EFI_ERROR(Status)) {\r
252 FreePool(TempCopy);\r
253 return (Status);\r
254 }\r
255 Guid->Data2 = (UINT16)TempVal;\r
256 Walker += 5;\r
257 TempSpot = StrStr(Walker, L"-");\r
33c031ee 258 if (TempSpot != NULL) {\r
259 *TempSpot = CHAR_NULL;\r
260 }\r
3737ac2b 261 Status = ShellConvertStringToUint64(Walker, &TempVal, TRUE, FALSE);\r
262 if (EFI_ERROR(Status)) {\r
263 FreePool(TempCopy);\r
264 return (Status);\r
265 }\r
266 Guid->Data3 = (UINT16)TempVal;\r
267 Walker += 5;\r
268 Guid->Data4[0] = (UINT8)(HexCharToUintn(Walker[0]) * 16);\r
269 Guid->Data4[0] = (UINT8)(Guid->Data4[0]+ (UINT8)HexCharToUintn(Walker[1]));\r
270 Walker += 2;\r
271 Guid->Data4[1] = (UINT8)(HexCharToUintn(Walker[0]) * 16);\r
272 Guid->Data4[1] = (UINT8)(Guid->Data4[1] + (UINT8)HexCharToUintn(Walker[1]));\r
273 Walker += 3;\r
274 Guid->Data4[2] = (UINT8)(HexCharToUintn(Walker[0]) * 16);\r
275 Guid->Data4[2] = (UINT8)(Guid->Data4[2] + (UINT8)HexCharToUintn(Walker[1]));\r
276 Walker += 2;\r
277 Guid->Data4[3] = (UINT8)(HexCharToUintn(Walker[0]) * 16);\r
278 Guid->Data4[3] = (UINT8)(Guid->Data4[3] + (UINT8)HexCharToUintn(Walker[1]));\r
279 Walker += 2;\r
280 Guid->Data4[4] = (UINT8)(HexCharToUintn(Walker[0]) * 16);\r
281 Guid->Data4[4] = (UINT8)(Guid->Data4[4] + (UINT8)HexCharToUintn(Walker[1]));\r
282 Walker += 2;\r
283 Guid->Data4[5] = (UINT8)(HexCharToUintn(Walker[0]) * 16);\r
284 Guid->Data4[5] = (UINT8)(Guid->Data4[5] + (UINT8)HexCharToUintn(Walker[1]));\r
285 Walker += 2;\r
286 Guid->Data4[6] = (UINT8)(HexCharToUintn(Walker[0]) * 16);\r
287 Guid->Data4[6] = (UINT8)(Guid->Data4[6] + (UINT8)HexCharToUintn(Walker[1]));\r
288 Walker += 2;\r
289 Guid->Data4[7] = (UINT8)(HexCharToUintn(Walker[0]) * 16);\r
290 Guid->Data4[7] = (UINT8)(Guid->Data4[7] + (UINT8)HexCharToUintn(Walker[1]));\r
291 FreePool(TempCopy);\r
292 return (EFI_SUCCESS);\r
293}\r
294\r
3737ac2b 295/**\r
296 Clear the line at the specified Row.\r
297 \r
298 @param[in] Row The row number to be cleared ( start from 1 )\r
299 @param[in] LastCol The last printable column.\r
300 @param[in] LastRow The last printable row.\r
301**/\r
302VOID\r
303EFIAPI\r
304EditorClearLine (\r
305 IN UINTN Row,\r
306 IN UINTN LastCol,\r
307 IN UINTN LastRow\r
308 )\r
309{\r
310 CHAR16 Line[200];\r
311\r
312 if (Row == 0) {\r
313 Row = 1;\r
314 }\r
315\r
316 //\r
317 // prepare a blank line\r
318 //\r
319 SetMem16(Line, LastCol*sizeof(CHAR16), L' ');\r
320\r
321 if (Row == LastRow) {\r
322 //\r
323 // if CHAR_NULL is still at position 80, it will cause first line error\r
324 //\r
325 Line[LastCol - 1] = CHAR_NULL;\r
5d73d92f 326 } else {\r
3737ac2b 327 Line[LastCol] = CHAR_NULL;\r
328 }\r
329\r
330 //\r
331 // print out the blank line\r
332 //\r
333 ShellPrintEx (0, ((INT32)Row) - 1, Line);\r
334}\r
335\r
336/**\r
337 Determine if the character is valid for a filename.\r
338\r
339 @param[in] Ch The character to test.\r
340\r
341 @retval TRUE The character is valid.\r
342 @retval FALSE The character is not valid.\r
343**/\r
344BOOLEAN\r
345EFIAPI\r
346IsValidFileNameChar (\r
347 IN CONST CHAR16 Ch\r
348 )\r
349{\r
350 //\r
351 // See if there are any illegal characters within the name\r
352 //\r
d16efcae 353 if (Ch < 0x20 || Ch == L'\"' || Ch == L'*' || Ch == L'/' || Ch == L'<' || Ch == L'>' || Ch == L'?' || Ch == L'|') {\r
3737ac2b 354 return FALSE;\r
355 }\r
356\r
357 return TRUE;\r
358}\r
359\r
360/**\r
361 Check if file name has illegal characters.\r
362 \r
363 @param Name The filename to check.\r
364\r
365 @retval TRUE The filename is ok.\r
366 @retval FALSE The filename is not ok.\r
367**/\r
368BOOLEAN\r
369EFIAPI\r
370IsValidFileName (\r
371 IN CONST CHAR16 *Name\r
372 )\r
373{\r
374\r
375 UINTN Index;\r
376 UINTN Len;\r
377\r
378 //\r
379 // check the length of Name\r
380 //\r
381 for (Len = 0, Index = StrLen (Name) - 1; Index + 1 != 0; Index--, Len++) {\r
382 if (Name[Index] == '\\' || Name[Index] == ':') {\r
383 break;\r
384 }\r
385 }\r
386\r
387 if (Len == 0 || Len > 255) {\r
388 return FALSE;\r
389 }\r
390 //\r
391 // check whether any char in Name not appears in valid file name char\r
392 //\r
393 for (Index = 0; Index < StrLen (Name); Index++) {\r
394 if (!IsValidFileNameChar (Name[Index])) {\r
395 return FALSE;\r
396 }\r
5d73d92f 397 }\r
3737ac2b 398\r
399 return TRUE;\r
400}\r
401\r
402/**\r
403 Find a filename that is valid (not taken) with the given extension.\r
404\r
405 @param[in] Extension The file extension.\r
406\r
407 @retval NULL Something went wrong.\r
408 @return the valid filename.\r
409**/\r
410CHAR16 *\r
411EFIAPI\r
412EditGetDefaultFileName (\r
413 IN CONST CHAR16 *Extension\r
414 )\r
415{\r
416 EFI_STATUS Status;\r
417 UINTN Suffix;\r
3737ac2b 418 CHAR16 *FileNameTmp;\r
419\r
420 Suffix = 0;\r
3737ac2b 421\r
422 do {\r
423 FileNameTmp = CatSPrint (NULL, L"NewFile%d.%s", Suffix, Extension);\r
424\r
425 //\r
426 // after that filename changed to path\r
427 //\r
428 Status = ShellFileExists (FileNameTmp);\r
429\r
430 if (Status == EFI_NOT_FOUND) {\r
431 return FileNameTmp;\r
432 }\r
433\r
434 FreePool (FileNameTmp);\r
435 FileNameTmp = NULL;\r
436 Suffix++;\r
437 } while (Suffix != 0);\r
438\r
439 FreePool (FileNameTmp);\r
440 return NULL;\r
5d73d92f 441}\r
442\r
3737ac2b 443/**\r
444 Read a file into an allocated buffer. The buffer is the responsibility \r
445 of the caller to free.\r
446\r
447 @param[in] FileName The filename of the file to open.\r
448 @param[out] Buffer Upon successful return, the pointer to the \r
449 address of the allocated buffer. \r
450 @param[out] BufferSize If not NULL, then the pointer to the size\r
451 of the allocated buffer.\r
452 @param[out] ReadOnly Upon successful return TRUE if the file is\r
453 read only. FALSE otherwise.\r
454\r
455 @retval EFI_NOT_FOUND The filename did not represent a file in the \r
456 file system.\r
457 @retval EFI_SUCCESS The file was read into the buffer.\r
458 @retval EFI_OUT_OF_RESOURCES A memory allocation failed.\r
459 @retval EFI_LOAD_ERROR The file read operation failed.\r
460 @retval EFI_INVALID_PARAMETER A parameter was invalid.\r
461 @retval EFI_INVALID_PARAMETER FileName was NULL.\r
462 @retval EFI_INVALID_PARAMETER FileName was a directory.\r
463**/\r
464EFI_STATUS\r
465EFIAPI\r
466ReadFileIntoBuffer (\r
467 IN CONST CHAR16 *FileName,\r
468 OUT VOID **Buffer,\r
469 OUT UINTN *BufferSize OPTIONAL,\r
470 OUT BOOLEAN *ReadOnly\r
471 )\r
472{\r
473 VOID *InternalBuffer;\r
474 UINTN FileSize;\r
475 SHELL_FILE_HANDLE FileHandle;\r
476 BOOLEAN CreateFile;\r
477 EFI_STATUS Status;\r
478 EFI_FILE_INFO *Info;\r
479\r
480 InternalBuffer = NULL;\r
481 FileSize = 0;\r
482 FileHandle = NULL;\r
483 CreateFile = FALSE;\r
484 Status = EFI_SUCCESS;\r
485 Info = NULL;\r
486\r
487 if (FileName == NULL || Buffer == NULL || ReadOnly == NULL) {\r
488 return (EFI_INVALID_PARAMETER);\r
489 }\r
490\r
491 //\r
492 // try to open the file\r
493 //\r
494 Status = ShellOpenFileByName (FileName, &FileHandle, EFI_FILE_MODE_READ, 0);\r
495\r
496 if (!EFI_ERROR(Status)) {\r
497 ASSERT(CreateFile == FALSE);\r
498 if (FileHandle == NULL) {\r
499 return EFI_LOAD_ERROR;\r
500 }\r
501\r
502 Info = ShellGetFileInfo(FileHandle);\r
503 \r
504 if (Info->Attribute & EFI_FILE_DIRECTORY) {\r
505 FreePool (Info);\r
506 return EFI_INVALID_PARAMETER;\r
507 }\r
508\r
509 if (Info->Attribute & EFI_FILE_READ_ONLY) {\r
510 *ReadOnly = TRUE;\r
511 } else {\r
512 *ReadOnly = FALSE;\r
513 }\r
514 //\r
515 // get file size\r
516 //\r
517 FileSize = (UINTN) Info->FileSize;\r
518\r
519 FreePool (Info);\r
520 } else if (Status == EFI_NOT_FOUND) {\r
521 //\r
522 // file not exists. add create and try again\r
523 //\r
524 Status = ShellOpenFileByName (FileName, &FileHandle, EFI_FILE_MODE_READ|EFI_FILE_MODE_WRITE|EFI_FILE_MODE_CREATE, 0);\r
525 if (EFI_ERROR (Status)) {\r
526 return Status;\r
527 } else {\r
528 //\r
529 // it worked. now delete it and move on with the name (now validated)\r
530 //\r
531 Status = ShellDeleteFile (&FileHandle);\r
532 if (Status == EFI_WARN_DELETE_FAILURE) {\r
533 Status = EFI_ACCESS_DENIED;\r
534 }\r
535 if (EFI_ERROR (Status)) {\r
536 return Status;\r
537 }\r
538 }\r
539 //\r
540 // file doesn't exist, so set CreateFile to TRUE and can't be read-only\r
541 //\r
542 CreateFile = TRUE;\r
543 *ReadOnly = FALSE;\r
544 }\r
545\r
546 //\r
547 // the file exists\r
548 //\r
549 if (!CreateFile) {\r
550 //\r
551 // allocate buffer to read file\r
552 //\r
553 InternalBuffer = AllocateZeroPool (FileSize);\r
554 if (InternalBuffer == NULL) {\r
555 return EFI_OUT_OF_RESOURCES;\r
556 }\r
557 //\r
558 // read file into InternalBuffer\r
559 //\r
560 Status = ShellReadFile (FileHandle, &FileSize, InternalBuffer);\r
561 ShellCloseFile(&FileHandle);\r
562 FileHandle = NULL;\r
563 if (EFI_ERROR (Status)) {\r
564 SHELL_FREE_NON_NULL (InternalBuffer);\r
565 return EFI_LOAD_ERROR;\r
566 }\r
567 }\r
568 *Buffer = InternalBuffer;\r
569 if (BufferSize != NULL) {\r
570 *BufferSize = FileSize;\r
571 }\r
572 return (EFI_SUCCESS);\r
573\r
574}\r