EFI_FILE_PROTOCOL wrappers for other items (Like Environment Variables,\r
StdIn, StdOut, StdErr, etc...).\r
\r
- Copyright (c) 2009 - 2011, Intel Corporation. All rights reserved.<BR>\r
+ Copyright 2016 Dell Inc.\r
+ Copyright (c) 2009 - 2015, Intel Corporation. All rights reserved.<BR>\r
+ (C) Copyright 2013 Hewlett-Packard Development Company, L.P.<BR>\r
This program and the accompanying materials\r
are licensed and made available under the terms and conditions of the BSD License\r
which accompanies this distribution. The full text of the license may be found at\r
/**\r
File style interface for console (GetInfo).\r
\r
- @param[in] This Ignored.\r
- @param[in] InformationType Ignored.\r
- @param[in,out] BufferSize Ignored.\r
- @param[out] Buffer Ignored.\r
+ @param[in] This Ignored.\r
+ @param[in] InformationType Ignored.\r
+ @param[in, out] BufferSize Ignored.\r
+ @param[out] Buffer Ignored.\r
\r
@retval EFI_UNSUPPORTED\r
**/\r
\r
Writes data to the screen.\r
\r
- @param[in] This The pointer to the EFI_FILE_PROTOCOL object.\r
- @param[in,out] BufferSize Size in bytes of Buffer.\r
- @param[in] Buffer The pointer to the buffer to write.\r
+ @param[in] This The pointer to the EFI_FILE_PROTOCOL object.\r
+ @param[in, out] BufferSize Size in bytes of Buffer.\r
+ @param[in] Buffer The pointer to the buffer to write.\r
\r
@retval EFI_UNSUPPORTED No output console is supported.\r
@return A return value from gST->ConOut->OutputString.\r
/**\r
File style interface for StdIn (Write).\r
\r
- @param[in] This Ignored.\r
- @param[in,out] BufferSize Ignored.\r
- @param[in] Buffer Ignored.\r
+ @param[in] This Ignored.\r
+ @param[in, out] BufferSize Ignored.\r
+ @param[in] Buffer Ignored.\r
\r
@retval EFI_UNSUPPORTED\r
**/\r
\r
Writes error to the error output.\r
\r
- @param[in] This The pointer to the EFI_FILE_PROTOCOL object.\r
- @param[in,out] BufferSize Size in bytes of Buffer.\r
- @param[in] Buffer The pointer to the buffer to write.\r
+ @param[in] This The pointer to the EFI_FILE_PROTOCOL object.\r
+ @param[in, out] BufferSize Size in bytes of Buffer.\r
+ @param[in] Buffer The pointer to the buffer to write.\r
\r
@return A return value from gST->StdErr->OutputString.\r
**/\r
/**\r
File style interface for console StdOut (Read).\r
\r
- @param[in] This Ignored.\r
- @param[in,out] BufferSize Ignored.\r
- @param[out] Buffer Ignored.\r
+ @param[in] This Ignored.\r
+ @param[in, out] BufferSize Ignored.\r
+ @param[out] Buffer Ignored.\r
\r
@retval EFI_UNSUPPORTED\r
**/\r
/**\r
File style interface for console StdErr (Read).\r
\r
- @param[in] This Ignored.\r
- @param[in,out] BufferSize Ignored.\r
- @param[out] Buffer Ignored.\r
+ @param[in] This Ignored.\r
+ @param[in, out] BufferSize Ignored.\r
+ @param[out] Buffer Ignored.\r
\r
@retval EFI_UNSUPPORTED Always.\r
**/\r
/**\r
File style interface for NUL file (Read).\r
\r
- @param[in] This Ignored.\r
- @param[in,out] BufferSize Ignored.\r
- @param[out] Buffer Ignored.\r
+ @param[in] This Ignored.\r
+ @param[in, out] BufferSize Poiner to 0 upon return.\r
+ @param[out] Buffer Ignored.\r
\r
@retval EFI_SUCCESS Always.\r
**/\r
OUT VOID *Buffer\r
)\r
{\r
+ *BufferSize = 0;\r
return (EFI_SUCCESS);\r
}\r
\r
/**\r
File style interface for NUL file (Write).\r
\r
- @param[in] This Ignored.\r
- @param[in,out] BufferSize Ignored.\r
- @param[in] Buffer Ignored.\r
+ @param[in] This Ignored.\r
+ @param[in, out] BufferSize Ignored.\r
+ @param[in] Buffer Ignored.\r
\r
@retval EFI_SUCCESS\r
**/\r
gBS->WaitForEvent (1, &gST->ConIn->WaitForKey, &EventIndex);\r
Status = gST->ConIn->ReadKeyStroke (gST->ConIn, &Key);\r
if (EFI_ERROR (Status)) {\r
- continue;\r
+ break;\r
}\r
\r
//\r
if (StrStr(CurrentString + TabPos, L":") == NULL) {\r
Cwd = ShellInfoObject.NewEfiShellProtocol->GetCurDir(NULL);\r
if (Cwd != NULL) {\r
- StrCpy(TabStr, Cwd);\r
+ StrnCpyS(TabStr, (*BufferSize)/sizeof(CHAR16), Cwd, (*BufferSize)/sizeof(CHAR16) - 1);\r
+ StrCatS(TabStr, (*BufferSize)/sizeof(CHAR16), L"\\");\r
if (TabStr[StrLen(TabStr)-1] == L'\\' && *(CurrentString + TabPos) == L'\\' ) {\r
TabStr[StrLen(TabStr)-1] = CHAR_NULL;\r
}\r
- StrnCat(TabStr, CurrentString + TabPos, (StringLen - TabPos) * sizeof (CHAR16));\r
+ StrnCatS( TabStr, \r
+ (*BufferSize)/sizeof(CHAR16), \r
+ CurrentString + TabPos, \r
+ StringLen - TabPos\r
+ );\r
} else {\r
- StrCpy(TabStr, L"");\r
- StrnCat(TabStr, CurrentString + TabPos, (StringLen - TabPos) * sizeof (CHAR16));\r
+ *TabStr = CHAR_NULL;\r
+ StrnCatS(TabStr, (*BufferSize)/sizeof(CHAR16), CurrentString + TabPos, StringLen - TabPos);\r
}\r
} else {\r
- StrCpy(TabStr, CurrentString + TabPos);\r
+ StrnCpyS(TabStr, (*BufferSize)/sizeof(CHAR16), CurrentString + TabPos, (*BufferSize)/sizeof(CHAR16) - 1);\r
}\r
- StrCat(TabStr, L"*");\r
+ StrnCatS(TabStr, (*BufferSize)/sizeof(CHAR16), L"*", (*BufferSize)/sizeof(CHAR16) - 1 - StrLen(TabStr));\r
FoundFileList = NULL;\r
-// TabStr = CleanPath(TabStr);\r
Status = ShellInfoObject.NewEfiShellProtocol->FindFiles(TabStr, &FoundFileList);\r
for ( TempStr = CurrentString\r
; *TempStr == L' '\r
//\r
ASSERT(FoundFileList == NULL);\r
\r
- return EFI_SUCCESS;\r
+ return Status;\r
}\r
\r
//\r
IN EFI_FILE_PROTOCOL *This\r
)\r
{\r
+ VOID* NewBuffer;\r
+ UINTN NewSize;\r
+ EFI_STATUS Status;\r
+\r
+ //\r
+ // Most if not all UEFI commands will have an '\r\n' at the end of any output. \r
+ // Since the output was redirected to a variable, it does not make sense to \r
+ // keep this. So, before closing, strip the trailing '\r\n' from the variable\r
+ // if it exists.\r
+ //\r
+ NewBuffer = NULL;\r
+ NewSize = 0;\r
+\r
+ Status = SHELL_GET_ENVIRONMENT_VARIABLE(((EFI_FILE_PROTOCOL_ENVIRONMENT*)This)->Name, &NewSize, NewBuffer);\r
+ if (Status == EFI_BUFFER_TOO_SMALL) {\r
+ NewBuffer = AllocateZeroPool(NewSize + sizeof(CHAR16));\r
+ if (NewBuffer == NULL) {\r
+ return EFI_OUT_OF_RESOURCES;\r
+ } \r
+ Status = SHELL_GET_ENVIRONMENT_VARIABLE(((EFI_FILE_PROTOCOL_ENVIRONMENT*)This)->Name, &NewSize, NewBuffer);\r
+ }\r
+ \r
+ if (!EFI_ERROR(Status) && NewBuffer != NULL) {\r
+ \r
+ if (StrSize(NewBuffer) > 6)\r
+ {\r
+ if ((((CHAR16*)NewBuffer)[(StrSize(NewBuffer)/2) - 2] == CHAR_LINEFEED) \r
+ && (((CHAR16*)NewBuffer)[(StrSize(NewBuffer)/2) - 3] == CHAR_CARRIAGE_RETURN)) {\r
+ ((CHAR16*)NewBuffer)[(StrSize(NewBuffer)/2) - 3] = CHAR_NULL; \r
+ }\r
+ \r
+ if (IsVolatileEnv(((EFI_FILE_PROTOCOL_ENVIRONMENT*)This)->Name)) {\r
+ Status = SHELL_SET_ENVIRONMENT_VARIABLE_V(((EFI_FILE_PROTOCOL_ENVIRONMENT*)This)->Name, StrSize(NewBuffer), NewBuffer);\r
+ } else {\r
+ Status = SHELL_SET_ENVIRONMENT_VARIABLE_NV(((EFI_FILE_PROTOCOL_ENVIRONMENT*)This)->Name, StrSize(NewBuffer), NewBuffer);\r
+ }\r
+ }\r
+ } \r
+ \r
+ SHELL_FREE_NON_NULL(NewBuffer);\r
FreePool((EFI_FILE_PROTOCOL_ENVIRONMENT*)This);\r
- return (EFI_SUCCESS);\r
+ return (Status);\r
}\r
\r
/**\r
/**\r
File style interface for Environment Variable (Read).\r
\r
- @param[in] This The pointer to the EFI_FILE_PROTOCOL object.\r
- @param[in,out] BufferSize Size in bytes of Buffer.\r
- @param[out] Buffer The pointer to the buffer to fill.\r
+ @param[in] This The pointer to the EFI_FILE_PROTOCOL object.\r
+ @param[in, out] BufferSize Size in bytes of Buffer.\r
+ @param[out] Buffer The pointer to the buffer to fill.\r
\r
@retval EFI_SUCCESS The data was read.\r
**/\r
/**\r
File style interface for Volatile Environment Variable (Write).\r
\r
- @param[in] This The pointer to the EFI_FILE_PROTOCOL object.\r
- @param[in,out] BufferSize Size in bytes of Buffer.\r
- @param[in] Buffer The pointer to the buffer to write.\r
+ @param[in] This The pointer to the EFI_FILE_PROTOCOL object.\r
+ @param[in, out] BufferSize Size in bytes of Buffer.\r
+ @param[in] Buffer The pointer to the buffer to write.\r
\r
@retval EFI_SUCCESS The data was read.\r
**/\r
/**\r
File style interface for Non Volatile Environment Variable (Write).\r
\r
- @param[in] This The pointer to the EFI_FILE_PROTOCOL object.\r
- @param[in,out] BufferSize Size in bytes of Buffer.\r
- @param[in] Buffer The pointer to the buffer to write.\r
+ @param[in] This The pointer to the EFI_FILE_PROTOCOL object.\r
+ @param[in, out] BufferSize Size in bytes of Buffer.\r
+ @param[in] Buffer The pointer to the buffer to write.\r
\r
@retval EFI_SUCCESS The data was read.\r
**/\r
)\r
{\r
EFI_FILE_PROTOCOL_ENVIRONMENT *EnvFileInterface;\r
+ UINTN EnvNameSize;\r
\r
if (EnvName == NULL) {\r
return (NULL);\r
//\r
// Get some memory\r
//\r
- EnvFileInterface = AllocateZeroPool(sizeof(EFI_FILE_PROTOCOL_ENVIRONMENT)+StrSize(EnvName));\r
+ EnvNameSize = StrSize(EnvName);\r
+ EnvFileInterface = AllocateZeroPool(sizeof(EFI_FILE_PROTOCOL_ENVIRONMENT)+EnvNameSize);\r
if (EnvFileInterface == NULL){\r
return (NULL);\r
}\r
EnvFileInterface->Flush = FileInterfaceNopGeneric;\r
EnvFileInterface->Delete = FileInterfaceEnvDelete;\r
EnvFileInterface->Read = FileInterfaceEnvRead;\r
-\r
- StrCpy(EnvFileInterface->Name, EnvName);\r
+ \r
+ CopyMem(EnvFileInterface->Name, EnvName, EnvNameSize);\r
\r
//\r
// Assign the different members for Volatile and Non-Volatile variables\r
Move the cursor position one character backward.\r
\r
@param[in] LineLength Length of a line. Get it by calling QueryMode\r
- @param[in,out] Column Current column of the cursor position\r
- @param[in,out] Row Current row of the cursor position\r
+ @param[in, out] Column Current column of the cursor position\r
+ @param[in, out] Row Current row of the cursor position\r
**/\r
VOID\r
EFIAPI\r
\r
@param[in] LineLength Length of a line.\r
@param[in] TotalRow Total row of a screen\r
- @param[in,out] Column Current column of the cursor position\r
- @param[in,out] Row Current row of the cursor position\r
+ @param[in, out] Column Current column of the cursor position\r
+ @param[in, out] Row Current row of the cursor position\r
**/\r
VOID\r
EFIAPI\r
/**\r
File style interface for Mem (Write).\r
\r
- @param[in] This The pointer to the EFI_FILE_PROTOCOL object.\r
- @param[in,out] BufferSize Size in bytes of Buffer.\r
- @param[in] Buffer The pointer to the buffer to write.\r
+ @param[in] This The pointer to the EFI_FILE_PROTOCOL object.\r
+ @param[in, out] BufferSize Size in bytes of Buffer.\r
+ @param[in] Buffer The pointer to the buffer to write.\r
\r
- @retval EFI_SUCCESS The data was written.\r
+ @retval EFI_OUT_OF_RESOURCES The operation failed due to lack of resources.\r
+ @retval EFI_SUCCESS The data was written.\r
**/\r
EFI_STATUS\r
EFIAPI\r
IN VOID *Buffer\r
)\r
{\r
- CHAR8 *AsciiBuffer;\r
- if (((EFI_FILE_PROTOCOL_MEM*)This)->Unicode) {\r
+ CHAR8 *AsciiBuffer;\r
+ EFI_FILE_PROTOCOL_MEM *MemFile;\r
+\r
+ MemFile = (EFI_FILE_PROTOCOL_MEM *) This;\r
+ if (MemFile->Unicode) {\r
//\r
// Unicode\r
//\r
- if ((UINTN)(((EFI_FILE_PROTOCOL_MEM*)This)->Position + (*BufferSize)) > (UINTN)(((EFI_FILE_PROTOCOL_MEM*)This)->BufferSize)) {\r
- ((EFI_FILE_PROTOCOL_MEM*)This)->Buffer = ReallocatePool((UINTN)(((EFI_FILE_PROTOCOL_MEM*)This)->BufferSize), (UINTN)(((EFI_FILE_PROTOCOL_MEM*)This)->BufferSize) + (*BufferSize) + 10, ((EFI_FILE_PROTOCOL_MEM*)This)->Buffer);\r
- ((EFI_FILE_PROTOCOL_MEM*)This)->BufferSize += (*BufferSize) + 10;\r
+ if ((UINTN)(MemFile->Position + (*BufferSize)) > (UINTN)(MemFile->BufferSize)) {\r
+ MemFile->Buffer = ReallocatePool((UINTN)(MemFile->BufferSize), (UINTN)(MemFile->BufferSize) + (*BufferSize) + 10, MemFile->Buffer);\r
+ MemFile->BufferSize += (*BufferSize) + 10;\r
}\r
- CopyMem(((UINT8*)((EFI_FILE_PROTOCOL_MEM*)This)->Buffer) + ((EFI_FILE_PROTOCOL_MEM*)This)->Position, Buffer, *BufferSize);\r
- ((EFI_FILE_PROTOCOL_MEM*)This)->Position += (*BufferSize);\r
+ CopyMem(((UINT8*)MemFile->Buffer) + MemFile->Position, Buffer, *BufferSize);\r
+ MemFile->Position += (*BufferSize);\r
return (EFI_SUCCESS);\r
} else {\r
//\r
// Ascii\r
//\r
AsciiBuffer = AllocateZeroPool(*BufferSize);\r
+ if (AsciiBuffer == NULL) {\r
+ return (EFI_OUT_OF_RESOURCES);\r
+ }\r
AsciiSPrint(AsciiBuffer, *BufferSize, "%S", Buffer);\r
- if ((UINTN)(((EFI_FILE_PROTOCOL_MEM*)This)->Position + AsciiStrSize(AsciiBuffer)) > (UINTN)(((EFI_FILE_PROTOCOL_MEM*)This)->BufferSize)) {\r
- ((EFI_FILE_PROTOCOL_MEM*)This)->Buffer = ReallocatePool((UINTN)(((EFI_FILE_PROTOCOL_MEM*)This)->BufferSize), (UINTN)(((EFI_FILE_PROTOCOL_MEM*)This)->BufferSize) + AsciiStrSize(AsciiBuffer) + 10, ((EFI_FILE_PROTOCOL_MEM*)This)->Buffer);\r
- ((EFI_FILE_PROTOCOL_MEM*)This)->BufferSize += AsciiStrSize(AsciiBuffer) + 10;\r
+ if ((UINTN)(MemFile->Position + AsciiStrSize(AsciiBuffer)) > (UINTN)(MemFile->BufferSize)) {\r
+ MemFile->Buffer = ReallocatePool((UINTN)(MemFile->BufferSize), (UINTN)(MemFile->BufferSize) + AsciiStrSize(AsciiBuffer) + 10, MemFile->Buffer);\r
+ MemFile->BufferSize += AsciiStrSize(AsciiBuffer) + 10;\r
}\r
- CopyMem(((UINT8*)((EFI_FILE_PROTOCOL_MEM*)This)->Buffer) + ((EFI_FILE_PROTOCOL_MEM*)This)->Position, AsciiBuffer, AsciiStrSize(AsciiBuffer));\r
- ((EFI_FILE_PROTOCOL_MEM*)This)->Position += AsciiStrSize(AsciiBuffer);\r
+ CopyMem(((UINT8*)MemFile->Buffer) + MemFile->Position, AsciiBuffer, AsciiStrSize(AsciiBuffer));\r
+ MemFile->Position += (*BufferSize / sizeof(CHAR16));\r
FreePool(AsciiBuffer);\r
return (EFI_SUCCESS);\r
}\r
/**\r
File style interface for Mem (Read).\r
\r
- @param[in] This The pointer to the EFI_FILE_PROTOCOL object.\r
- @param[in,out] BufferSize Size in bytes of Buffer.\r
- @param[in] Buffer The pointer to the buffer to fill.\r
+ @param[in] This The pointer to the EFI_FILE_PROTOCOL object.\r
+ @param[in, out] BufferSize Size in bytes of Buffer.\r
+ @param[in] Buffer The pointer to the buffer to fill.\r
\r
@retval EFI_SUCCESS The data was read.\r
**/\r
IN VOID *Buffer\r
)\r
{\r
- if (*BufferSize > (UINTN)((((EFI_FILE_PROTOCOL_MEM*)This)->BufferSize) - (UINTN)(((EFI_FILE_PROTOCOL_MEM*)This)->Position))) {\r
- (*BufferSize) = (UINTN)((((EFI_FILE_PROTOCOL_MEM*)This)->BufferSize) - (UINTN)(((EFI_FILE_PROTOCOL_MEM*)This)->Position));\r
+ EFI_FILE_PROTOCOL_MEM *MemFile;\r
+\r
+ MemFile = (EFI_FILE_PROTOCOL_MEM *) This;\r
+ if (*BufferSize > (UINTN)((MemFile->BufferSize) - (UINTN)(MemFile->Position))) {\r
+ (*BufferSize) = (UINTN)((MemFile->BufferSize) - (UINTN)(MemFile->Position));\r
}\r
- CopyMem(Buffer, ((UINT8*)((EFI_FILE_PROTOCOL_MEM*)This)->Buffer) + ((EFI_FILE_PROTOCOL_MEM*)This)->Position, (*BufferSize));\r
- ((EFI_FILE_PROTOCOL_MEM*)This)->Position = ((EFI_FILE_PROTOCOL_MEM*)This)->Position + (*BufferSize);\r
+ CopyMem(Buffer, ((UINT8*)MemFile->Buffer) + MemFile->Position, (*BufferSize));\r
+ MemFile->Position = MemFile->Position + (*BufferSize);\r
return (EFI_SUCCESS);\r
}\r
\r
ASSERT(FileInterface->BufferSize == 0);\r
ASSERT(FileInterface->Position == 0);\r
\r
+ if (Unicode) {\r
+ FileInterface->Buffer = AllocateZeroPool(sizeof(gUnicodeFileTag));\r
+ *((CHAR16 *) (FileInterface->Buffer)) = EFI_UNICODE_BYTE_ORDER_MARK;\r
+ FileInterface->BufferSize = 2;\r
+ FileInterface->Position = 2;\r
+ }\r
+\r
return ((EFI_FILE_PROTOCOL *)FileInterface);\r
}\r
\r
OUT VOID *Buffer\r
)\r
{\r
- CHAR8 *AsciiBuffer;\r
+ CHAR8 *AsciiStrBuffer;\r
+ CHAR16 *UscStrBuffer;\r
UINTN Size;\r
+ UINTN CharNum;\r
EFI_STATUS Status;\r
if (((EFI_FILE_PROTOCOL_FILE*)This)->Unicode) {\r
//\r
//\r
// Ascii\r
//\r
- AsciiBuffer = AllocateZeroPool((Size = *BufferSize));\r
- Status = (((EFI_FILE_PROTOCOL_FILE*)This)->Orig->Read(((EFI_FILE_PROTOCOL_FILE*)This)->Orig, &Size, AsciiBuffer));\r
- UnicodeSPrint(Buffer, *BufferSize, L"%a", AsciiBuffer);\r
- FreePool(AsciiBuffer);\r
+ Size = (*BufferSize) / sizeof(CHAR16);\r
+ AsciiStrBuffer = AllocateZeroPool(Size + sizeof(CHAR8));\r
+ if (AsciiStrBuffer == NULL) {\r
+ return EFI_OUT_OF_RESOURCES;\r
+ }\r
+ UscStrBuffer = AllocateZeroPool(*BufferSize + sizeof(CHAR16));\r
+ if (UscStrBuffer== NULL) {\r
+ SHELL_FREE_NON_NULL(AsciiStrBuffer);\r
+ return EFI_OUT_OF_RESOURCES;\r
+ }\r
+ Status = (((EFI_FILE_PROTOCOL_FILE*)This)->Orig->Read(((EFI_FILE_PROTOCOL_FILE*)This)->Orig, &Size, AsciiStrBuffer));\r
+ if (!EFI_ERROR(Status)) {\r
+ CharNum = UnicodeSPrint(UscStrBuffer, *BufferSize + sizeof(CHAR16), L"%a", AsciiStrBuffer);\r
+ if (CharNum == Size) {\r
+ CopyMem (Buffer, UscStrBuffer, *BufferSize);\r
+ } else {\r
+ Status = EFI_UNSUPPORTED;\r
+ }\r
+ }\r
+ SHELL_FREE_NON_NULL(AsciiStrBuffer);\r
+ SHELL_FREE_NON_NULL(UscStrBuffer);\r
return (Status);\r
}\r
}\r
If the file was opened with ASCII mode the data will be processed through \r
AsciiSPrint before writing.\r
\r
- @param[in] This The pointer to the EFI_FILE_PROTOCOL object.\r
- @param[in,out] BufferSize Size in bytes of Buffer.\r
- @param[in] Buffer The pointer to the buffer to write.\r
+ @param[in] This The pointer to the EFI_FILE_PROTOCOL object.\r
+ @param[in, out] BufferSize Size in bytes of Buffer.\r
+ @param[in] Buffer The pointer to the buffer to write.\r
\r
@retval EFI_SUCCESS The data was written.\r
**/\r