summaryrefslogtreecommitdiff
path: root/ShellPkg/Library/UefiShellDebug1CommandsLib/UefiShellDebug1CommandsLib.c
diff options
context:
space:
mode:
authorjcarsey <jcarsey@6f19259b-4bc3-4df7-8a09-765794883524>2011-03-25 21:22:20 +0000
committerjcarsey <jcarsey@6f19259b-4bc3-4df7-8a09-765794883524>2011-03-25 21:22:20 +0000
commit3737ac2bc3c2e6589d88be97345d641ea2006933 (patch)
treed2798373c799cb9c728d2ec4e7b1bb39f2d59d11 /ShellPkg/Library/UefiShellDebug1CommandsLib/UefiShellDebug1CommandsLib.c
parent2442e62af75a0c5087fce3fb2040e26a485b0d31 (diff)
downloadedk2-3737ac2bc3c2e6589d88be97345d641ea2006933.zip
edk2-3737ac2bc3c2e6589d88be97345d641ea2006933.tar.gz
edk2-3737ac2bc3c2e6589d88be97345d641ea2006933.tar.bz2
comp - add comments and add input verification
bcfg - updated for bugs. compress - rename for coding standards. add comments. dblk - add comments, input verification, and a header line dmem - add comments, add input verification, add system table info dmpstore - add comments eficompress - add comments and add input verification efidecompress - add comments and add input verification loadpcirom - add comments and more output messages memmap - add more output to exceed the spec. mm - move functions, add comments, add input verification. mode - add comment pci - add input verification. SerMode - add comments and add input verification setsize - add comments and add input verification setvar - add comments and add input verification smbiosview - add input verification. clarify error messages. git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@11438 6f19259b-4bc3-4df7-8a09-765794883524
Diffstat (limited to 'ShellPkg/Library/UefiShellDebug1CommandsLib/UefiShellDebug1CommandsLib.c')
-rw-r--r--ShellPkg/Library/UefiShellDebug1CommandsLib/UefiShellDebug1CommandsLib.c484
1 files changed, 434 insertions, 50 deletions
diff --git a/ShellPkg/Library/UefiShellDebug1CommandsLib/UefiShellDebug1CommandsLib.c b/ShellPkg/Library/UefiShellDebug1CommandsLib/UefiShellDebug1CommandsLib.c
index 094e429..226dd90 100644
--- a/ShellPkg/Library/UefiShellDebug1CommandsLib/UefiShellDebug1CommandsLib.c
+++ b/ShellPkg/Library/UefiShellDebug1CommandsLib/UefiShellDebug1CommandsLib.c
@@ -1,7 +1,7 @@
/** @file
Main file for NULL named library for debug1 profile shell command functions.
- Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>
+ Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
@@ -21,6 +21,12 @@ CONST EFI_GUID gShellDebug1HiiGuid = \
0x25f200aa, 0xd3cb, 0x470a, { 0xbf, 0x51, 0xe7, 0xd1, 0x62, 0xd2, 0x2e, 0x6f } \
};
+/**
+ Gets the debug file name. This will be used if HII is not working.
+
+ @retval NULL No file is available.
+ @return The NULL-terminated filename to get help from.
+**/
CONST CHAR16*
EFIAPI
ShellCommandGetManFileNameDebug1 (
@@ -64,21 +70,23 @@ UefiShellDebug1CommandsLibConstructor (
//
// install our shell command handlers that are always installed
//
- ShellCommandRegisterCommandName(L"SetSize", ShellCommandRunSetSize , ShellCommandGetManFileNameDebug1, 0, L"Debug1", TRUE, gShellDebug1HiiHandle, STRING_TOKEN(STR_GET_HELP_SETSIZE) );
+ ShellCommandRegisterCommandName(L"setsize", ShellCommandRunSetSize , ShellCommandGetManFileNameDebug1, 0, L"Debug1", TRUE, gShellDebug1HiiHandle, STRING_TOKEN(STR_GET_HELP_SETSIZE) );
ShellCommandRegisterCommandName(L"comp", ShellCommandRunComp , ShellCommandGetManFileNameDebug1, 0, L"Debug1", TRUE, gShellDebug1HiiHandle, STRING_TOKEN(STR_GET_HELP_COMP) );
ShellCommandRegisterCommandName(L"mode", ShellCommandRunMode , ShellCommandGetManFileNameDebug1, 0, L"Debug1", TRUE, gShellDebug1HiiHandle, STRING_TOKEN(STR_GET_HELP_MODE) );
ShellCommandRegisterCommandName(L"memmap", ShellCommandRunMemMap , ShellCommandGetManFileNameDebug1, 0, L"Debug1", TRUE, gShellDebug1HiiHandle, STRING_TOKEN(STR_GET_HELP_MEMMAP) );
ShellCommandRegisterCommandName(L"eficompress", ShellCommandRunEfiCompress , ShellCommandGetManFileNameDebug1, 0, L"Debug1", TRUE, gShellDebug1HiiHandle, STRING_TOKEN(STR_GET_HELP_EFICOMPRESS) );
ShellCommandRegisterCommandName(L"efidecompress", ShellCommandRunEfiDecompress , ShellCommandGetManFileNameDebug1, 0, L"Debug1", TRUE, gShellDebug1HiiHandle, STRING_TOKEN(STR_GET_HELP_EFIDCOMPRESS) );
ShellCommandRegisterCommandName(L"dmem", ShellCommandRunDmem , ShellCommandGetManFileNameDebug1, 0, L"Debug1", TRUE, gShellDebug1HiiHandle, STRING_TOKEN(STR_GET_HELP_DMEM) );
- ShellCommandRegisterCommandName(L"LoadPciRom", ShellCommandRunLoadPciRom , ShellCommandGetManFileNameDebug1, 0, L"Debug1", TRUE, gShellDebug1HiiHandle, STRING_TOKEN(STR_GET_HELP_LOAD_PCI_ROM) );
+ ShellCommandRegisterCommandName(L"loadpcirom", ShellCommandRunLoadPciRom , ShellCommandGetManFileNameDebug1, 0, L"Debug1", TRUE, gShellDebug1HiiHandle, STRING_TOKEN(STR_GET_HELP_LOAD_PCI_ROM) );
ShellCommandRegisterCommandName(L"mm", ShellCommandRunMm , ShellCommandGetManFileNameDebug1, 0, L"Debug1", TRUE, gShellDebug1HiiHandle, STRING_TOKEN(STR_GET_HELP_MM) );
- ShellCommandRegisterCommandName(L"SetVar", ShellCommandRunSetVar , ShellCommandGetManFileNameDebug1, 0, L"Debug1", TRUE, gShellDebug1HiiHandle, STRING_TOKEN(STR_GET_HELP_SETVAR) );
- ShellCommandRegisterCommandName(L"SerMode", ShellCommandRunSerMode , ShellCommandGetManFileNameDebug1, 0, L"Debug1", TRUE, gShellDebug1HiiHandle, STRING_TOKEN(STR_GET_HELP_SERMODE) );
- ShellCommandRegisterCommandName(L"Pci", ShellCommandRunPci , ShellCommandGetManFileNameDebug1, 0, L"Debug1", TRUE, gShellDebug1HiiHandle, STRING_TOKEN(STR_GET_HELP_PCI) );
+ ShellCommandRegisterCommandName(L"setvar", ShellCommandRunSetVar , ShellCommandGetManFileNameDebug1, 0, L"Debug1", TRUE, gShellDebug1HiiHandle, STRING_TOKEN(STR_GET_HELP_SETVAR) );
+ ShellCommandRegisterCommandName(L"sermode", ShellCommandRunSerMode , ShellCommandGetManFileNameDebug1, 0, L"Debug1", TRUE, gShellDebug1HiiHandle, STRING_TOKEN(STR_GET_HELP_SERMODE) );
+ ShellCommandRegisterCommandName(L"pci", ShellCommandRunPci , ShellCommandGetManFileNameDebug1, 0, L"Debug1", TRUE, gShellDebug1HiiHandle, STRING_TOKEN(STR_GET_HELP_PCI) );
ShellCommandRegisterCommandName(L"smbiosview", ShellCommandRunSmbiosView , ShellCommandGetManFileNameDebug1, 0, L"Debug1", TRUE, gShellDebug1HiiHandle, STRING_TOKEN(STR_GET_HELP_SMBIOSVIEW) );
ShellCommandRegisterCommandName(L"dmpstore", ShellCommandRunDmpStore , ShellCommandGetManFileNameDebug1, 0, L"Debug1", TRUE, gShellDebug1HiiHandle, STRING_TOKEN(STR_GET_HELP_DMPSTORE) );
ShellCommandRegisterCommandName(L"dblk", ShellCommandRunDblk , ShellCommandGetManFileNameDebug1, 0, L"Debug1", TRUE, gShellDebug1HiiHandle, STRING_TOKEN(STR_GET_HELP_DBLK) );
+ ShellCommandRegisterCommandName(L"edit", ShellCommandRunEdit , ShellCommandGetManFileNameDebug1, 0, L"Debug1", TRUE, gShellDebug1HiiHandle, STRING_TOKEN(STR_GET_HELP_EDIT) );
+ ShellCommandRegisterCommandName(L"hexedit", ShellCommandRunHexEdit , ShellCommandGetManFileNameDebug1, 0, L"Debug1", TRUE, gShellDebug1HiiHandle, STRING_TOKEN(STR_GET_HELP_HEXEDIT) );
//
// check install profile bit of the profiles mask is set
@@ -87,10 +95,8 @@ UefiShellDebug1CommandsLibConstructor (
ShellCommandRegisterCommandName(L"bcfg", ShellCommandRunBcfg , ShellCommandGetManFileNameDebug1, 0, L"Debug1", TRUE, gShellDebug1HiiHandle, STRING_TOKEN(STR_GET_HELP_BCFG) );
}
-/*
- ShellCommandRegisterCommandName(L"hexedit", ShellCommandRunHexEdit , ShellCommandGetManFileNameDebug1, 0, L"Debug1", TRUE, gShellDebug1HiiHandle, STRING_TOKEN(STR_GET_HELP_HEXEDIT );
- ShellCommandRegisterCommandName(L"edit", ShellCommandRunEdit , ShellCommandGetManFileNameDebug1, 0, L"Debug1", TRUE, gShellDebug1HiiHandle, STRING_TOKEN(STR_GET_HELP_EDIT) );
-*/
+
+
ShellCommandRegisterAlias(L"dmem", L"mem");
@@ -99,6 +105,9 @@ UefiShellDebug1CommandsLibConstructor (
/**
Destructor for the library. free any resources.
+
+ @param ImageHandle The image handle of the process.
+ @param SystemTable The EFI System Table pointer.
**/
EFI_STATUS
EFIAPI
@@ -132,6 +141,14 @@ STATIC CONST CHAR8 Hex[] = {
'F'
};
+/**
+ Dump some hexadecimal data to the screen.
+
+ @param[in] Indent How many spaces to indent the output.
+ @param[in] Offset The offset of the printing.
+ @param[in] DataSize The size in bytes of UserData.
+ @param[in] UserData The data to print out.
+**/
VOID
EFIAPI
DumpHex (
@@ -147,12 +164,10 @@ DumpHex (
CHAR8 Str[20];
- UINT8 c;
+ UINT8 TempByte;
UINTN Size;
UINTN Index;
- ASSERT (UserData != NULL);
-
Data = UserData;
while (DataSize != 0) {
Size = 16;
@@ -161,11 +176,11 @@ DumpHex (
}
for (Index = 0; Index < Size; Index += 1) {
- c = Data[Index];
- Val[Index * 3 + 0] = Hex[c >> 4];
- Val[Index * 3 + 1] = Hex[c & 0xF];
+ TempByte = Data[Index];
+ Val[Index * 3 + 0] = Hex[TempByte >> 4];
+ Val[Index * 3 + 1] = Hex[TempByte & 0xF];
Val[Index * 3 + 2] = (CHAR8) ((Index == 7) ? '-' : ' ');
- Str[Index] = (CHAR8) ((c < ' ' || c > 'z') ? '.' : c);
+ Str[Index] = (CHAR8) ((TempByte < ' ' || TempByte > 'z') ? '.' : TempByte);
}
Val[Index * 3] = 0;
@@ -213,7 +228,7 @@ CharToUpper (
EFI System Table based on the provided GUID.
@param[in] TableGuid A pointer to the table's GUID type.
- @param[out] Table On exit, a pointer to a system configuration table.
+ @param[in,out] Table On exit, a pointer to a system configuration table.
@retval EFI_SUCCESS A configuration table matching TableGuid was found.
@retval EFI_NOT_FOUND A configuration table matching TableGuid was not found.
@@ -229,7 +244,7 @@ GetSystemConfigurationTable (
ASSERT (Table != NULL);
for (Index = 0; Index < gST->NumberOfTableEntries; Index++) {
- if (CompareGuid (TableGuid, &(gST->ConfigurationTable[Index].VendorGuid)) == 0) {
+ if (CompareGuid (TableGuid, &(gST->ConfigurationTable[Index].VendorGuid))) {
*Table = gST->ConfigurationTable[Index].VendorTable;
return EFI_SUCCESS;
}
@@ -264,6 +279,15 @@ HexCharToUintn (
return (UINTN) (10 + CharToUpper (Char) - L'A');
}
+/**
+ Convert a string representation of a guid to a Guid value.
+
+ @param[in] StringGuid The pointer to the string of a guid.
+ @param[in,out] Guid The pointer to the GUID structure to populate.
+
+ @retval EFI_INVALID_PARAMETER A parameter was invalid.
+ @retval EFI_SUCCESS The conversion was successful.
+**/
EFI_STATUS
EFIAPI
ConvertStringToGuid (
@@ -271,39 +295,399 @@ ConvertStringToGuid (
IN OUT EFI_GUID *Guid
)
{
- if (StrLen(StringGuid) != 35) {
+ CHAR16 *TempCopy;
+ CHAR16 *TempSpot;
+ CHAR16 *Walker;
+ UINT64 TempVal;
+ EFI_STATUS Status;
+
+ if (StringGuid == NULL) {
+ return (EFI_INVALID_PARAMETER);
+ } else if (StrLen(StringGuid) != 36) {
return (EFI_INVALID_PARAMETER);
+ }
+ TempCopy = NULL;
+ TempCopy = StrnCatGrow(&TempCopy, NULL, StringGuid, 0);
+ Walker = TempCopy;
+ TempSpot = StrStr(Walker, L"-");
+ *TempSpot = CHAR_NULL;
+ Status = ShellConvertStringToUint64(Walker, &TempVal, TRUE, FALSE);
+ if (EFI_ERROR(Status)) {
+ FreePool(TempCopy);
+ return (Status);
+ }
+ Guid->Data1 = (UINT32)TempVal;
+ Walker += 9;
+ TempSpot = StrStr(Walker, L"-");
+ *TempSpot = CHAR_NULL;
+ Status = ShellConvertStringToUint64(Walker, &TempVal, TRUE, FALSE);
+ if (EFI_ERROR(Status)) {
+ FreePool(TempCopy);
+ return (Status);
+ }
+ Guid->Data2 = (UINT16)TempVal;
+ Walker += 5;
+ TempSpot = StrStr(Walker, L"-");
+ *TempSpot = CHAR_NULL;
+ Status = ShellConvertStringToUint64(Walker, &TempVal, TRUE, FALSE);
+ if (EFI_ERROR(Status)) {
+ FreePool(TempCopy);
+ return (Status);
+ }
+ Guid->Data3 = (UINT16)TempVal;
+ Walker += 5;
+ Guid->Data4[0] = (UINT8)(HexCharToUintn(Walker[0]) * 16);
+ Guid->Data4[0] = (UINT8)(Guid->Data4[0]+ (UINT8)HexCharToUintn(Walker[1]));
+ Walker += 2;
+ Guid->Data4[1] = (UINT8)(HexCharToUintn(Walker[0]) * 16);
+ Guid->Data4[1] = (UINT8)(Guid->Data4[1] + (UINT8)HexCharToUintn(Walker[1]));
+ Walker += 3;
+ Guid->Data4[2] = (UINT8)(HexCharToUintn(Walker[0]) * 16);
+ Guid->Data4[2] = (UINT8)(Guid->Data4[2] + (UINT8)HexCharToUintn(Walker[1]));
+ Walker += 2;
+ Guid->Data4[3] = (UINT8)(HexCharToUintn(Walker[0]) * 16);
+ Guid->Data4[3] = (UINT8)(Guid->Data4[3] + (UINT8)HexCharToUintn(Walker[1]));
+ Walker += 2;
+ Guid->Data4[4] = (UINT8)(HexCharToUintn(Walker[0]) * 16);
+ Guid->Data4[4] = (UINT8)(Guid->Data4[4] + (UINT8)HexCharToUintn(Walker[1]));
+ Walker += 2;
+ Guid->Data4[5] = (UINT8)(HexCharToUintn(Walker[0]) * 16);
+ Guid->Data4[5] = (UINT8)(Guid->Data4[5] + (UINT8)HexCharToUintn(Walker[1]));
+ Walker += 2;
+ Guid->Data4[6] = (UINT8)(HexCharToUintn(Walker[0]) * 16);
+ Guid->Data4[6] = (UINT8)(Guid->Data4[6] + (UINT8)HexCharToUintn(Walker[1]));
+ Walker += 2;
+ Guid->Data4[7] = (UINT8)(HexCharToUintn(Walker[0]) * 16);
+ Guid->Data4[7] = (UINT8)(Guid->Data4[7] + (UINT8)HexCharToUintn(Walker[1]));
+ FreePool(TempCopy);
+ return (EFI_SUCCESS);
+}
+
+CHAR16 TempBufferCatSPrint[1000];
+/**
+ Appends a formatted Unicode string to a Null-terminated Unicode string
+
+ This function appends a formatted Unicode string to the Null-terminated
+ Unicode string specified by String. String is optional and may be NULL.
+ Storage for the formatted Unicode string returned is allocated using
+ AllocateZeroPool(). The pointer to the appended string is returned. The caller
+ is responsible for freeing the returned string.
+
+ If String is not NULL and not aligned on a 16-bit boundary, then ASSERT().
+ If Format is NULL, then ASSERT().
+ If Format is not aligned on a 16-bit boundary, then ASSERT().
+
+ @param String A null-terminated Unicode string.
+ @param FormatString A null-terminated Unicode format string.
+ @param ... The variable argument list whose contents are accessed based
+ on the format string specified by Format.
+
+ @retval NULL There was not enough available memory.
+ @return Null terminated Unicode string is that is the formatted
+ string appended to String.
+ @sa CatVSPrint
+**/
+CHAR16*
+EFIAPI
+CatSPrint (
+ IN CONST CHAR16 *String OPTIONAL,
+ IN CONST CHAR16 *FormatString,
+ ...
+ )
+{
+ VA_LIST Marker;
+ UINTN StringLength;
+ if (String != NULL) {
+ StrCpy(TempBufferCatSPrint, String);
+ } else {
+ *TempBufferCatSPrint = CHAR_NULL;
+ }
+ VA_START (Marker, FormatString);
+ StringLength = StrLen(TempBufferCatSPrint);
+
+ UnicodeVSPrint(TempBufferCatSPrint+StrLen(TempBufferCatSPrint), 1000-StringLength, FormatString, Marker);
+ return (AllocateCopyPool(StrSize(TempBufferCatSPrint), TempBufferCatSPrint));
+}
+
+/**
+ Clear the line at the specified Row.
+
+ @param[in] Row The row number to be cleared ( start from 1 )
+ @param[in] LastCol The last printable column.
+ @param[in] LastRow The last printable row.
+**/
+VOID
+EFIAPI
+EditorClearLine (
+ IN UINTN Row,
+ IN UINTN LastCol,
+ IN UINTN LastRow
+ )
+{
+ CHAR16 Line[200];
+
+ if (Row == 0) {
+ Row = 1;
+ }
+
+ //
+ // prepare a blank line
+ //
+ SetMem16(Line, LastCol*sizeof(CHAR16), L' ');
+
+ if (Row == LastRow) {
+ //
+ // if CHAR_NULL is still at position 80, it will cause first line error
+ //
+ Line[LastCol - 1] = CHAR_NULL;
} else {
- Guid->Data1 = (UINT32)StrHexToUintn(StringGuid);
- StringGuid += 9;
- Guid->Data2 = (UINT16)StrHexToUintn(StringGuid);
- StringGuid += 5;
- Guid->Data3 = (UINT16)StrHexToUintn(StringGuid);
- StringGuid += 5;
- Guid->Data4[0] = (UINT8)(HexCharToUintn(StringGuid[0]) * 16);
- Guid->Data4[0] = (UINT8)(Guid->Data4[0]+ (UINT8)HexCharToUintn(StringGuid[1]));
- StringGuid += 2;
- Guid->Data4[1] = (UINT8)(HexCharToUintn(StringGuid[0]) * 16);
- Guid->Data4[1] = (UINT8)(Guid->Data4[1] + (UINT8)HexCharToUintn(StringGuid[1]));
- StringGuid += 2;
- Guid->Data4[2] = (UINT8)(HexCharToUintn(StringGuid[0]) * 16);
- Guid->Data4[2] = (UINT8)(Guid->Data4[2] + (UINT8)HexCharToUintn(StringGuid[1]));
- StringGuid += 2;
- Guid->Data4[3] = (UINT8)(HexCharToUintn(StringGuid[0]) * 16);
- Guid->Data4[3] = (UINT8)(Guid->Data4[3] + (UINT8)HexCharToUintn(StringGuid[1]));
- StringGuid += 2;
- Guid->Data4[4] = (UINT8)(HexCharToUintn(StringGuid[0]) * 16);
- Guid->Data4[4] = (UINT8)(Guid->Data4[4] + (UINT8)HexCharToUintn(StringGuid[1]));
- StringGuid += 2;
- Guid->Data4[5] = (UINT8)(HexCharToUintn(StringGuid[0]) * 16);
- Guid->Data4[5] = (UINT8)(Guid->Data4[5] + (UINT8)HexCharToUintn(StringGuid[1]));
- StringGuid += 2;
- Guid->Data4[6] = (UINT8)(HexCharToUintn(StringGuid[0]) * 16);
- Guid->Data4[6] = (UINT8)(Guid->Data4[6] + (UINT8)HexCharToUintn(StringGuid[1]));
- StringGuid += 2;
- Guid->Data4[7] = (UINT8)(HexCharToUintn(StringGuid[0]) * 16);
- Guid->Data4[7] = (UINT8)(Guid->Data4[7] = (UINT8)HexCharToUintn(StringGuid[1]));
- return (EFI_SUCCESS);
+ Line[LastCol] = CHAR_NULL;
+ }
+
+ //
+ // print out the blank line
+ //
+ ShellPrintEx (0, ((INT32)Row) - 1, Line);
+}
+
+/**
+ Determine if the character is valid for a filename.
+
+ @param[in] Ch The character to test.
+
+ @retval TRUE The character is valid.
+ @retval FALSE The character is not valid.
+**/
+BOOLEAN
+EFIAPI
+IsValidFileNameChar (
+ IN CONST CHAR16 Ch
+ )
+{
+ //
+ // See if there are any illegal characters within the name
+ //
+ if (Ch < 0x20 || Ch == L'\"' || Ch == L'*' || Ch == L'/' || Ch == L'<' || Ch == L'>' || Ch == L'?' || Ch == L'|' || Ch == L' ') {
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
+/**
+ Check if file name has illegal characters.
+
+ @param Name The filename to check.
+
+ @retval TRUE The filename is ok.
+ @retval FALSE The filename is not ok.
+**/
+BOOLEAN
+EFIAPI
+IsValidFileName (
+ IN CONST CHAR16 *Name
+ )
+{
+
+ UINTN Index;
+ UINTN Len;
+
+ //
+ // check the length of Name
+ //
+ for (Len = 0, Index = StrLen (Name) - 1; Index + 1 != 0; Index--, Len++) {
+ if (Name[Index] == '\\' || Name[Index] == ':') {
+ break;
+ }
+ }
+
+ if (Len == 0 || Len > 255) {
+ return FALSE;
+ }
+ //
+ // check whether any char in Name not appears in valid file name char
+ //
+ for (Index = 0; Index < StrLen (Name); Index++) {
+ if (!IsValidFileNameChar (Name[Index])) {
+ return FALSE;
+ }
}
+
+ return TRUE;
+}
+
+/**
+ Find a filename that is valid (not taken) with the given extension.
+
+ @param[in] Extension The file extension.
+
+ @retval NULL Something went wrong.
+ @return the valid filename.
+**/
+CHAR16 *
+EFIAPI
+EditGetDefaultFileName (
+ IN CONST CHAR16 *Extension
+ )
+{
+ EFI_STATUS Status;
+ UINTN Suffix;
+ BOOLEAN FoundNewFile;
+ CHAR16 *FileNameTmp;
+
+ Suffix = 0;
+ FoundNewFile = FALSE;
+
+ do {
+ FileNameTmp = CatSPrint (NULL, L"NewFile%d.%s", Suffix, Extension);
+
+ //
+ // after that filename changed to path
+ //
+ Status = ShellFileExists (FileNameTmp);
+
+ if (Status == EFI_NOT_FOUND) {
+ return FileNameTmp;
+ }
+
+ FreePool (FileNameTmp);
+ FileNameTmp = NULL;
+ Suffix++;
+ } while (Suffix != 0);
+
+ FreePool (FileNameTmp);
+ return NULL;
}
+/**
+ Read a file into an allocated buffer. The buffer is the responsibility
+ of the caller to free.
+
+ @param[in] FileName The filename of the file to open.
+ @param[out] Buffer Upon successful return, the pointer to the
+ address of the allocated buffer.
+ @param[out] BufferSize If not NULL, then the pointer to the size
+ of the allocated buffer.
+ @param[out] ReadOnly Upon successful return TRUE if the file is
+ read only. FALSE otherwise.
+
+ @retval EFI_NOT_FOUND The filename did not represent a file in the
+ file system.
+ @retval EFI_SUCCESS The file was read into the buffer.
+ @retval EFI_OUT_OF_RESOURCES A memory allocation failed.
+ @retval EFI_LOAD_ERROR The file read operation failed.
+ @retval EFI_INVALID_PARAMETER A parameter was invalid.
+ @retval EFI_INVALID_PARAMETER FileName was NULL.
+ @retval EFI_INVALID_PARAMETER FileName was a directory.
+**/
+EFI_STATUS
+EFIAPI
+ReadFileIntoBuffer (
+ IN CONST CHAR16 *FileName,
+ OUT VOID **Buffer,
+ OUT UINTN *BufferSize OPTIONAL,
+ OUT BOOLEAN *ReadOnly
+ )
+{
+ VOID *InternalBuffer;
+ UINTN FileSize;
+ SHELL_FILE_HANDLE FileHandle;
+ BOOLEAN CreateFile;
+ EFI_STATUS Status;
+ EFI_FILE_INFO *Info;
+
+ InternalBuffer = NULL;
+ FileSize = 0;
+ FileHandle = NULL;
+ CreateFile = FALSE;
+ Status = EFI_SUCCESS;
+ Info = NULL;
+
+ if (FileName == NULL || Buffer == NULL || ReadOnly == NULL) {
+ return (EFI_INVALID_PARAMETER);
+ }
+
+ //
+ // try to open the file
+ //
+ Status = ShellOpenFileByName (FileName, &FileHandle, EFI_FILE_MODE_READ, 0);
+
+ if (!EFI_ERROR(Status)) {
+ ASSERT(CreateFile == FALSE);
+ if (FileHandle == NULL) {
+ return EFI_LOAD_ERROR;
+ }
+
+ Info = ShellGetFileInfo(FileHandle);
+
+ if (Info->Attribute & EFI_FILE_DIRECTORY) {
+ FreePool (Info);
+ return EFI_INVALID_PARAMETER;
+ }
+
+ if (Info->Attribute & EFI_FILE_READ_ONLY) {
+ *ReadOnly = TRUE;
+ } else {
+ *ReadOnly = FALSE;
+ }
+ //
+ // get file size
+ //
+ FileSize = (UINTN) Info->FileSize;
+
+ FreePool (Info);
+ } else if (Status == EFI_NOT_FOUND) {
+ //
+ // file not exists. add create and try again
+ //
+ Status = ShellOpenFileByName (FileName, &FileHandle, EFI_FILE_MODE_READ|EFI_FILE_MODE_WRITE|EFI_FILE_MODE_CREATE, 0);
+ if (EFI_ERROR (Status)) {
+ return Status;
+ } else {
+ //
+ // it worked. now delete it and move on with the name (now validated)
+ //
+ Status = ShellDeleteFile (&FileHandle);
+ if (Status == EFI_WARN_DELETE_FAILURE) {
+ Status = EFI_ACCESS_DENIED;
+ }
+ if (EFI_ERROR (Status)) {
+ return Status;
+ }
+ }
+ //
+ // file doesn't exist, so set CreateFile to TRUE and can't be read-only
+ //
+ CreateFile = TRUE;
+ *ReadOnly = FALSE;
+ }
+
+ //
+ // the file exists
+ //
+ if (!CreateFile) {
+ //
+ // allocate buffer to read file
+ //
+ InternalBuffer = AllocateZeroPool (FileSize);
+ if (InternalBuffer == NULL) {
+ return EFI_OUT_OF_RESOURCES;
+ }
+ //
+ // read file into InternalBuffer
+ //
+ Status = ShellReadFile (FileHandle, &FileSize, InternalBuffer);
+ ShellCloseFile(&FileHandle);
+ FileHandle = NULL;
+ if (EFI_ERROR (Status)) {
+ SHELL_FREE_NON_NULL (InternalBuffer);
+ return EFI_LOAD_ERROR;
+ }
+ }
+ *Buffer = InternalBuffer;
+ if (BufferSize != NULL) {
+ *BufferSize = FileSize;
+ }
+ return (EFI_SUCCESS);
+
+}