]> git.proxmox.com Git - mirror_edk2.git/blame - ShellPkg/Library/UefiShellDebug1CommandsLib/UefiShellDebug1CommandsLib.c
ShellPkg/UefiShellDebug1CommandsLib: Remove unnecessary EFIAPI
[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
5d73d92f 134CharToUpper (\r
135 IN CHAR16 Char\r
136 )\r
137{\r
138 if (Char >= L'a' && Char <= L'z') {\r
139 return (CHAR16) (Char - (L'a' - L'A'));\r
140 }\r
141\r
142 return Char;\r
143}\r
144\r
145/**\r
146 Function returns a system configuration table that is stored in the\r
147 EFI System Table based on the provided GUID.\r
148\r
4ff7e37b
ED
149 @param[in] TableGuid A pointer to the table's GUID type.\r
150 @param[in, out] Table On exit, a pointer to a system configuration table.\r
5d73d92f 151\r
152 @retval EFI_SUCCESS A configuration table matching TableGuid was found.\r
153 @retval EFI_NOT_FOUND A configuration table matching TableGuid was not found.\r
154**/\r
155EFI_STATUS\r
5d73d92f 156GetSystemConfigurationTable (\r
157 IN EFI_GUID *TableGuid,\r
158 IN OUT VOID **Table\r
159 )\r
160{\r
161 UINTN Index;\r
162 ASSERT (Table != NULL);\r
163\r
164 for (Index = 0; Index < gST->NumberOfTableEntries; Index++) {\r
3737ac2b 165 if (CompareGuid (TableGuid, &(gST->ConfigurationTable[Index].VendorGuid))) {\r
5d73d92f 166 *Table = gST->ConfigurationTable[Index].VendorTable;\r
167 return EFI_SUCCESS;\r
168 }\r
169 }\r
170\r
171 return EFI_NOT_FOUND;\r
172}\r
173\r
174/**\r
175 Convert a Unicode character to numerical value.\r
176\r
177 This internal function only deal with Unicode character\r
178 which maps to a valid hexadecimal ASII character, i.e.\r
179 L'0' to L'9', L'a' to L'f' or L'A' to L'F'. For other\r
180 Unicode character, the value returned does not make sense.\r
181\r
182 @param Char The character to convert.\r
183\r
184 @return The numerical value converted.\r
185\r
186**/\r
187UINTN\r
5d73d92f 188HexCharToUintn (\r
189 IN CHAR16 Char\r
190 )\r
191{\r
192 if (Char >= L'0' && Char <= L'9') {\r
193 return Char - L'0';\r
194 }\r
195\r
196 return (UINTN) (10 + CharToUpper (Char) - L'A');\r
197}\r
198\r
3737ac2b 199/**\r
200 Convert a string representation of a guid to a Guid value.\r
201\r
4ff7e37b
ED
202 @param[in] StringGuid The pointer to the string of a guid.\r
203 @param[in, out] Guid The pointer to the GUID structure to populate.\r
3737ac2b 204\r
205 @retval EFI_INVALID_PARAMETER A parameter was invalid.\r
206 @retval EFI_SUCCESS The conversion was successful.\r
207**/\r
5d73d92f 208EFI_STATUS\r
5d73d92f 209ConvertStringToGuid (\r
210 IN CONST CHAR16 *StringGuid,\r
211 IN OUT EFI_GUID *Guid\r
212 )\r
213{\r
3737ac2b 214 CHAR16 *TempCopy;\r
215 CHAR16 *TempSpot;\r
216 CHAR16 *Walker;\r
217 UINT64 TempVal;\r
218 EFI_STATUS Status;\r
219\r
220 if (StringGuid == NULL) {\r
221 return (EFI_INVALID_PARAMETER);\r
222 } else if (StrLen(StringGuid) != 36) {\r
5d73d92f 223 return (EFI_INVALID_PARAMETER);\r
3737ac2b 224 } \r
225 TempCopy = NULL;\r
226 TempCopy = StrnCatGrow(&TempCopy, NULL, StringGuid, 0);\r
532691c8 227 if (TempCopy == NULL) {\r
228 return (EFI_OUT_OF_RESOURCES);\r
229 }\r
3737ac2b 230 Walker = TempCopy;\r
231 TempSpot = StrStr(Walker, L"-");\r
33c031ee 232 if (TempSpot != NULL) {\r
233 *TempSpot = CHAR_NULL;\r
234 }\r
3737ac2b 235 Status = ShellConvertStringToUint64(Walker, &TempVal, TRUE, FALSE);\r
236 if (EFI_ERROR(Status)) {\r
237 FreePool(TempCopy);\r
238 return (Status);\r
239 }\r
240 Guid->Data1 = (UINT32)TempVal;\r
241 Walker += 9;\r
242 TempSpot = StrStr(Walker, L"-");\r
33c031ee 243 if (TempSpot != NULL) {\r
244 *TempSpot = CHAR_NULL;\r
245 }\r
3737ac2b 246 Status = ShellConvertStringToUint64(Walker, &TempVal, TRUE, FALSE);\r
247 if (EFI_ERROR(Status)) {\r
248 FreePool(TempCopy);\r
249 return (Status);\r
250 }\r
251 Guid->Data2 = (UINT16)TempVal;\r
252 Walker += 5;\r
253 TempSpot = StrStr(Walker, L"-");\r
33c031ee 254 if (TempSpot != NULL) {\r
255 *TempSpot = CHAR_NULL;\r
256 }\r
3737ac2b 257 Status = ShellConvertStringToUint64(Walker, &TempVal, TRUE, FALSE);\r
258 if (EFI_ERROR(Status)) {\r
259 FreePool(TempCopy);\r
260 return (Status);\r
261 }\r
262 Guid->Data3 = (UINT16)TempVal;\r
263 Walker += 5;\r
264 Guid->Data4[0] = (UINT8)(HexCharToUintn(Walker[0]) * 16);\r
265 Guid->Data4[0] = (UINT8)(Guid->Data4[0]+ (UINT8)HexCharToUintn(Walker[1]));\r
266 Walker += 2;\r
267 Guid->Data4[1] = (UINT8)(HexCharToUintn(Walker[0]) * 16);\r
268 Guid->Data4[1] = (UINT8)(Guid->Data4[1] + (UINT8)HexCharToUintn(Walker[1]));\r
269 Walker += 3;\r
270 Guid->Data4[2] = (UINT8)(HexCharToUintn(Walker[0]) * 16);\r
271 Guid->Data4[2] = (UINT8)(Guid->Data4[2] + (UINT8)HexCharToUintn(Walker[1]));\r
272 Walker += 2;\r
273 Guid->Data4[3] = (UINT8)(HexCharToUintn(Walker[0]) * 16);\r
274 Guid->Data4[3] = (UINT8)(Guid->Data4[3] + (UINT8)HexCharToUintn(Walker[1]));\r
275 Walker += 2;\r
276 Guid->Data4[4] = (UINT8)(HexCharToUintn(Walker[0]) * 16);\r
277 Guid->Data4[4] = (UINT8)(Guid->Data4[4] + (UINT8)HexCharToUintn(Walker[1]));\r
278 Walker += 2;\r
279 Guid->Data4[5] = (UINT8)(HexCharToUintn(Walker[0]) * 16);\r
280 Guid->Data4[5] = (UINT8)(Guid->Data4[5] + (UINT8)HexCharToUintn(Walker[1]));\r
281 Walker += 2;\r
282 Guid->Data4[6] = (UINT8)(HexCharToUintn(Walker[0]) * 16);\r
283 Guid->Data4[6] = (UINT8)(Guid->Data4[6] + (UINT8)HexCharToUintn(Walker[1]));\r
284 Walker += 2;\r
285 Guid->Data4[7] = (UINT8)(HexCharToUintn(Walker[0]) * 16);\r
286 Guid->Data4[7] = (UINT8)(Guid->Data4[7] + (UINT8)HexCharToUintn(Walker[1]));\r
287 FreePool(TempCopy);\r
288 return (EFI_SUCCESS);\r
289}\r
290\r
3737ac2b 291/**\r
292 Clear the line at the specified Row.\r
293 \r
294 @param[in] Row The row number to be cleared ( start from 1 )\r
295 @param[in] LastCol The last printable column.\r
296 @param[in] LastRow The last printable row.\r
297**/\r
298VOID\r
3737ac2b 299EditorClearLine (\r
300 IN UINTN Row,\r
301 IN UINTN LastCol,\r
302 IN UINTN LastRow\r
303 )\r
304{\r
305 CHAR16 Line[200];\r
306\r
307 if (Row == 0) {\r
308 Row = 1;\r
309 }\r
310\r
311 //\r
312 // prepare a blank line\r
313 //\r
314 SetMem16(Line, LastCol*sizeof(CHAR16), L' ');\r
315\r
316 if (Row == LastRow) {\r
317 //\r
318 // if CHAR_NULL is still at position 80, it will cause first line error\r
319 //\r
320 Line[LastCol - 1] = CHAR_NULL;\r
5d73d92f 321 } else {\r
3737ac2b 322 Line[LastCol] = CHAR_NULL;\r
323 }\r
324\r
325 //\r
326 // print out the blank line\r
327 //\r
328 ShellPrintEx (0, ((INT32)Row) - 1, Line);\r
329}\r
330\r
331/**\r
332 Determine if the character is valid for a filename.\r
333\r
334 @param[in] Ch The character to test.\r
335\r
336 @retval TRUE The character is valid.\r
337 @retval FALSE The character is not valid.\r
338**/\r
339BOOLEAN\r
3737ac2b 340IsValidFileNameChar (\r
341 IN CONST CHAR16 Ch\r
342 )\r
343{\r
344 //\r
345 // See if there are any illegal characters within the name\r
346 //\r
d16efcae 347 if (Ch < 0x20 || Ch == L'\"' || Ch == L'*' || Ch == L'/' || Ch == L'<' || Ch == L'>' || Ch == L'?' || Ch == L'|') {\r
3737ac2b 348 return FALSE;\r
349 }\r
350\r
351 return TRUE;\r
352}\r
353\r
354/**\r
355 Check if file name has illegal characters.\r
356 \r
357 @param Name The filename to check.\r
358\r
359 @retval TRUE The filename is ok.\r
360 @retval FALSE The filename is not ok.\r
361**/\r
362BOOLEAN\r
3737ac2b 363IsValidFileName (\r
364 IN CONST CHAR16 *Name\r
365 )\r
366{\r
367\r
368 UINTN Index;\r
369 UINTN Len;\r
370\r
371 //\r
372 // check the length of Name\r
373 //\r
374 for (Len = 0, Index = StrLen (Name) - 1; Index + 1 != 0; Index--, Len++) {\r
375 if (Name[Index] == '\\' || Name[Index] == ':') {\r
376 break;\r
377 }\r
378 }\r
379\r
380 if (Len == 0 || Len > 255) {\r
381 return FALSE;\r
382 }\r
383 //\r
384 // check whether any char in Name not appears in valid file name char\r
385 //\r
386 for (Index = 0; Index < StrLen (Name); Index++) {\r
387 if (!IsValidFileNameChar (Name[Index])) {\r
388 return FALSE;\r
389 }\r
5d73d92f 390 }\r
3737ac2b 391\r
392 return TRUE;\r
393}\r
394\r
395/**\r
396 Find a filename that is valid (not taken) with the given extension.\r
397\r
398 @param[in] Extension The file extension.\r
399\r
400 @retval NULL Something went wrong.\r
401 @return the valid filename.\r
402**/\r
403CHAR16 *\r
3737ac2b 404EditGetDefaultFileName (\r
405 IN CONST CHAR16 *Extension\r
406 )\r
407{\r
408 EFI_STATUS Status;\r
409 UINTN Suffix;\r
3737ac2b 410 CHAR16 *FileNameTmp;\r
411\r
412 Suffix = 0;\r
3737ac2b 413\r
414 do {\r
415 FileNameTmp = CatSPrint (NULL, L"NewFile%d.%s", Suffix, Extension);\r
416\r
417 //\r
418 // after that filename changed to path\r
419 //\r
420 Status = ShellFileExists (FileNameTmp);\r
421\r
422 if (Status == EFI_NOT_FOUND) {\r
423 return FileNameTmp;\r
424 }\r
425\r
426 FreePool (FileNameTmp);\r
427 FileNameTmp = NULL;\r
428 Suffix++;\r
429 } while (Suffix != 0);\r
430\r
431 FreePool (FileNameTmp);\r
432 return NULL;\r
5d73d92f 433}\r
434\r
3737ac2b 435/**\r
436 Read a file into an allocated buffer. The buffer is the responsibility \r
437 of the caller to free.\r
438\r
439 @param[in] FileName The filename of the file to open.\r
440 @param[out] Buffer Upon successful return, the pointer to the \r
441 address of the allocated buffer. \r
442 @param[out] BufferSize If not NULL, then the pointer to the size\r
443 of the allocated buffer.\r
444 @param[out] ReadOnly Upon successful return TRUE if the file is\r
445 read only. FALSE otherwise.\r
446\r
447 @retval EFI_NOT_FOUND The filename did not represent a file in the \r
448 file system.\r
449 @retval EFI_SUCCESS The file was read into the buffer.\r
450 @retval EFI_OUT_OF_RESOURCES A memory allocation failed.\r
451 @retval EFI_LOAD_ERROR The file read operation failed.\r
452 @retval EFI_INVALID_PARAMETER A parameter was invalid.\r
453 @retval EFI_INVALID_PARAMETER FileName was NULL.\r
454 @retval EFI_INVALID_PARAMETER FileName was a directory.\r
455**/\r
456EFI_STATUS\r
3737ac2b 457ReadFileIntoBuffer (\r
458 IN CONST CHAR16 *FileName,\r
459 OUT VOID **Buffer,\r
460 OUT UINTN *BufferSize OPTIONAL,\r
461 OUT BOOLEAN *ReadOnly\r
462 )\r
463{\r
464 VOID *InternalBuffer;\r
465 UINTN FileSize;\r
466 SHELL_FILE_HANDLE FileHandle;\r
467 BOOLEAN CreateFile;\r
468 EFI_STATUS Status;\r
469 EFI_FILE_INFO *Info;\r
470\r
471 InternalBuffer = NULL;\r
472 FileSize = 0;\r
473 FileHandle = NULL;\r
474 CreateFile = FALSE;\r
475 Status = EFI_SUCCESS;\r
476 Info = NULL;\r
477\r
478 if (FileName == NULL || Buffer == NULL || ReadOnly == NULL) {\r
479 return (EFI_INVALID_PARAMETER);\r
480 }\r
481\r
482 //\r
483 // try to open the file\r
484 //\r
485 Status = ShellOpenFileByName (FileName, &FileHandle, EFI_FILE_MODE_READ, 0);\r
486\r
487 if (!EFI_ERROR(Status)) {\r
488 ASSERT(CreateFile == FALSE);\r
489 if (FileHandle == NULL) {\r
490 return EFI_LOAD_ERROR;\r
491 }\r
492\r
493 Info = ShellGetFileInfo(FileHandle);\r
494 \r
495 if (Info->Attribute & EFI_FILE_DIRECTORY) {\r
496 FreePool (Info);\r
497 return EFI_INVALID_PARAMETER;\r
498 }\r
499\r
500 if (Info->Attribute & EFI_FILE_READ_ONLY) {\r
501 *ReadOnly = TRUE;\r
502 } else {\r
503 *ReadOnly = FALSE;\r
504 }\r
505 //\r
506 // get file size\r
507 //\r
508 FileSize = (UINTN) Info->FileSize;\r
509\r
510 FreePool (Info);\r
511 } else if (Status == EFI_NOT_FOUND) {\r
512 //\r
513 // file not exists. add create and try again\r
514 //\r
515 Status = ShellOpenFileByName (FileName, &FileHandle, EFI_FILE_MODE_READ|EFI_FILE_MODE_WRITE|EFI_FILE_MODE_CREATE, 0);\r
516 if (EFI_ERROR (Status)) {\r
517 return Status;\r
518 } else {\r
519 //\r
520 // it worked. now delete it and move on with the name (now validated)\r
521 //\r
522 Status = ShellDeleteFile (&FileHandle);\r
523 if (Status == EFI_WARN_DELETE_FAILURE) {\r
524 Status = EFI_ACCESS_DENIED;\r
525 }\r
526 if (EFI_ERROR (Status)) {\r
527 return Status;\r
528 }\r
529 }\r
530 //\r
531 // file doesn't exist, so set CreateFile to TRUE and can't be read-only\r
532 //\r
533 CreateFile = TRUE;\r
534 *ReadOnly = FALSE;\r
535 }\r
536\r
537 //\r
538 // the file exists\r
539 //\r
540 if (!CreateFile) {\r
541 //\r
542 // allocate buffer to read file\r
543 //\r
544 InternalBuffer = AllocateZeroPool (FileSize);\r
545 if (InternalBuffer == NULL) {\r
546 return EFI_OUT_OF_RESOURCES;\r
547 }\r
548 //\r
549 // read file into InternalBuffer\r
550 //\r
551 Status = ShellReadFile (FileHandle, &FileSize, InternalBuffer);\r
552 ShellCloseFile(&FileHandle);\r
553 FileHandle = NULL;\r
554 if (EFI_ERROR (Status)) {\r
555 SHELL_FREE_NON_NULL (InternalBuffer);\r
556 return EFI_LOAD_ERROR;\r
557 }\r
558 }\r
559 *Buffer = InternalBuffer;\r
560 if (BufferSize != NULL) {\r
561 *BufferSize = FileSize;\r
562 }\r
563 return (EFI_SUCCESS);\r
564\r
565}\r