]> git.proxmox.com Git - mirror_edk2.git/blobdiff - ShellPkg/Application/Shell/FileHandleWrappers.c
ShellPkg: Clean up source files
[mirror_edk2.git] / ShellPkg / Application / Shell / FileHandleWrappers.c
index 0d38e9d5fe61ce72c9d59577b5ece7ba0292f77a..8c62eb58628c26489478d4f4f72224ecf5bf85ea 100644 (file)
@@ -3,7 +3,7 @@
   StdIn, StdOut, StdErr, etc...).\r
 \r
   Copyright 2016 Dell Inc.\r
-  Copyright (c) 2009 - 2016, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2009 - 2018, 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
 #define MEM_WRITE_REALLOC_OVERHEAD 1024\r
 \r
 /**\r
-  File style interface for console (Open).  \r
-  \r
+  File style interface for console (Open).\r
+\r
   @param[in] This       Ignored.\r
   @param[out] NewHandle Ignored.\r
   @param[in] FileName   Ignored.\r
   @param[in] OpenMode   Ignored.\r
   @param[in] Attributes Ignored.\r
-  \r
+\r
   @retval EFI_NOT_FOUND\r
 **/\r
 EFI_STATUS\r
@@ -46,9 +46,9 @@ FileInterfaceOpenNotFound(
 \r
 /**\r
   File style interface for console (Close, Delete, & Flush)\r
-  \r
+\r
   @param[in] This       Ignored.\r
-  \r
+\r
   @retval EFI_SUCCESS\r
 **/\r
 EFI_STATUS\r
@@ -65,7 +65,7 @@ FileInterfaceNopGeneric(
 \r
   @param[in] This       Ignored.\r
   @param[out] Position  Ignored.\r
-  \r
+\r
   @retval EFI_UNSUPPORTED\r
 **/\r
 EFI_STATUS\r
@@ -80,10 +80,10 @@ FileInterfaceNopGetPosition(
 \r
 /**\r
   File style interface for console (SetPosition).\r
-  \r
+\r
   @param[in] This       Ignored.\r
   @param[in] Position   Ignored.\r
-  \r
+\r
   @retval EFI_UNSUPPORTED\r
 **/\r
 EFI_STATUS\r
@@ -98,12 +98,12 @@ FileInterfaceNopSetPosition(
 \r
 /**\r
   File style interface for console (GetInfo).\r
-  \r
+\r
   @param[in] This              Ignored.\r
   @param[in] InformationType   Ignored.\r
   @param[in, out] BufferSize   Ignored.\r
   @param[out] Buffer           Ignored.\r
-  \r
+\r
   @retval EFI_UNSUPPORTED\r
 **/\r
 EFI_STATUS\r
@@ -120,12 +120,12 @@ FileInterfaceNopGetInfo(
 \r
 /**\r
   File style interface for console (SetInfo).\r
-  \r
+\r
   @param[in] This       Ignored.\r
   @param[in] InformationType   Ignored.\r
   @param[in] BufferSize Ignored.\r
   @param[in] Buffer     Ignored.\r
-  \r
+\r
   @retval EFI_UNSUPPORTED\r
 **/\r
 EFI_STATUS\r
@@ -144,11 +144,11 @@ FileInterfaceNopSetInfo(
   File style interface for StdOut (Write).\r
 \r
   Writes data to the screen.\r
-  \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
-  \r
+\r
   @retval EFI_UNSUPPORTED No output console is supported.\r
   @return A return value from gST->ConOut->OutputString.\r
 **/\r
@@ -171,11 +171,11 @@ FileInterfaceStdOutWrite(
 \r
 /**\r
   File style interface for StdIn (Write).\r
-  \r
+\r
   @param[in] This            Ignored.\r
   @param[in, out] BufferSize Ignored.\r
   @param[in] Buffer          Ignored.\r
-  \r
+\r
   @retval EFI_UNSUPPORTED\r
 **/\r
 EFI_STATUS\r
@@ -193,11 +193,11 @@ FileInterfaceStdInWrite(
   File style interface for console StdErr (Write).\r
 \r
   Writes error to the error output.\r
-  \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
-  \r
+\r
   @return A return value from gST->StdErr->OutputString.\r
 **/\r
 EFI_STATUS\r
@@ -213,11 +213,11 @@ FileInterfaceStdErrWrite(
 \r
 /**\r
   File style interface for console StdOut (Read).\r
-  \r
+\r
   @param[in] This              Ignored.\r
   @param[in, out] BufferSize   Ignored.\r
   @param[out] Buffer           Ignored.\r
-  \r
+\r
   @retval EFI_UNSUPPORTED\r
 **/\r
 EFI_STATUS\r
@@ -233,11 +233,11 @@ FileInterfaceStdOutRead(
 \r
 /**\r
   File style interface for console StdErr (Read).\r
-  \r
+\r
   @param[in] This              Ignored.\r
   @param[in, out] BufferSize   Ignored.\r
   @param[out] Buffer           Ignored.\r
-  \r
+\r
   @retval EFI_UNSUPPORTED Always.\r
 **/\r
 EFI_STATUS\r
@@ -253,11 +253,11 @@ FileInterfaceStdErrRead(
 \r
 /**\r
   File style interface for NUL file (Read).\r
-  \r
+\r
   @param[in] This              Ignored.\r
   @param[in, out] BufferSize   Poiner to 0 upon return.\r
   @param[out] Buffer           Ignored.\r
-  \r
+\r
   @retval EFI_SUCCESS Always.\r
 **/\r
 EFI_STATUS\r
@@ -274,11 +274,11 @@ FileInterfaceNulRead(
 \r
 /**\r
   File style interface for NUL file (Write).\r
-  \r
+\r
   @param[in] This              Ignored.\r
   @param[in, out] BufferSize   Ignored.\r
   @param[in] Buffer            Ignored.\r
-  \r
+\r
   @retval EFI_SUCCESS\r
 **/\r
 EFI_STATUS\r
@@ -298,14 +298,13 @@ FileInterfaceNulWrite(
   @param[in]  InputString       The command line to expand.\r
   @param[in]  StringLen         Length of the command line.\r
   @param[in]  BufferSize        Buffer size.\r
-  @param[out] TabCompletionList Return the TAB completion list.\r
-  @param[out] TabUpdatePos      Return the TAB update position.\r
+  @param[in, out] TabCompletionList Return the TAB completion list.\r
+  @param[in, out] TabUpdatePos      Return the TAB update position.\r
 **/\r
 EFI_STATUS\r
-EFIAPI\r
 CreateTabCompletionList (\r
   IN CONST CHAR16             *InputString,\r
-  IN CONST UINTN              StringLen, \r
+  IN CONST UINTN              StringLen,\r
   IN CONST UINTN              BufferSize,\r
   IN OUT EFI_SHELL_FILE_INFO  **TabCompletionList,\r
   IN OUT   UINTN              *TabUpdatePos\r
@@ -1026,9 +1025,9 @@ typedef struct {
   File style interface for Environment Variable (Close).\r
 \r
   Frees the memory for this object.\r
-  \r
+\r
   @param[in] This       The pointer to the EFI_FILE_PROTOCOL object.\r
-  \r
+\r
   @retval EFI_SUCCESS\r
 **/\r
 EFI_STATUS\r
@@ -1041,15 +1040,17 @@ FileInterfaceEnvClose(
   UINTN       NewSize;\r
   EFI_STATUS  Status;\r
   BOOLEAN     Volatile;\r
+  UINTN       TotalSize;\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
+  // 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
+  TotalSize   = 0;\r
 \r
   Status = IsVolatileEnv (((EFI_FILE_PROTOCOL_ENVIRONMENT*)This)->Name, &Volatile);\r
   if (EFI_ERROR (Status)) {\r
@@ -1058,30 +1059,61 @@ FileInterfaceEnvClose(
 \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
+    TotalSize = NewSize + sizeof (CHAR16);\r
+    NewBuffer = AllocateZeroPool (TotalSize);\r
     if (NewBuffer == NULL) {\r
       return EFI_OUT_OF_RESOURCES;\r
-    }  \r
+    }\r
     Status = SHELL_GET_ENVIRONMENT_VARIABLE(((EFI_FILE_PROTOCOL_ENVIRONMENT*)This)->Name, &NewSize, NewBuffer);\r
   }\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
+    if (TotalSize / sizeof (CHAR16) >= 3) {\r
+      if ( (((CHAR16*)NewBuffer)[TotalSize / sizeof (CHAR16) - 2] == CHAR_LINEFEED) &&\r
+           (((CHAR16*)NewBuffer)[TotalSize / sizeof (CHAR16) - 3] == CHAR_CARRIAGE_RETURN)\r
+         ) {\r
+        ((CHAR16*)NewBuffer)[TotalSize / sizeof (CHAR16) - 3] = CHAR_NULL;\r
+        //\r
+        // If the NewBuffer end with \r\n\0, We will repace '\r' by '\0' and then update TotalSize.\r
+        //\r
+        TotalSize -= sizeof(CHAR16) * 2;\r
       }\r
 \r
       if (Volatile) {\r
-        Status = SHELL_SET_ENVIRONMENT_VARIABLE_V(((EFI_FILE_PROTOCOL_ENVIRONMENT*)This)->Name, StrSize(NewBuffer), NewBuffer);\r
+        Status = SHELL_SET_ENVIRONMENT_VARIABLE_V (\r
+                   ((EFI_FILE_PROTOCOL_ENVIRONMENT*)This)->Name,\r
+                   TotalSize - sizeof (CHAR16),\r
+                   NewBuffer\r
+                   );\r
+\r
+        if (!EFI_ERROR(Status)) {\r
+          Status = ShellAddEnvVarToList (\r
+                     ((EFI_FILE_PROTOCOL_ENVIRONMENT*)This)->Name,\r
+                     NewBuffer,\r
+                     TotalSize,\r
+                     EFI_VARIABLE_BOOTSERVICE_ACCESS\r
+                     );\r
+        }\r
       } else {\r
-        Status = SHELL_SET_ENVIRONMENT_VARIABLE_NV(((EFI_FILE_PROTOCOL_ENVIRONMENT*)This)->Name, StrSize(NewBuffer), NewBuffer);\r
+        Status = SHELL_SET_ENVIRONMENT_VARIABLE_NV (\r
+                   ((EFI_FILE_PROTOCOL_ENVIRONMENT*)This)->Name,\r
+                   TotalSize - sizeof (CHAR16),\r
+                   NewBuffer\r
+                   );\r
+\r
+        if (!EFI_ERROR(Status)) {\r
+          Status = ShellAddEnvVarToList (\r
+                     ((EFI_FILE_PROTOCOL_ENVIRONMENT*)This)->Name,\r
+                     NewBuffer,\r
+                     TotalSize,\r
+                     EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS\r
+                     );\r
+        }\r
       }\r
     }\r
-  } \r
-  \r
+  }\r
+\r
   SHELL_FREE_NON_NULL(NewBuffer);\r
   FreePool((EFI_FILE_PROTOCOL_ENVIRONMENT*)This);\r
   return (Status);\r
@@ -1089,9 +1121,9 @@ FileInterfaceEnvClose(
 \r
 /**\r
   File style interface for Environment Variable (Delete).\r
-  \r
+\r
   @param[in] This       The pointer to the EFI_FILE_PROTOCOL object.\r
-  \r
+\r
   @retval The return value from FileInterfaceEnvClose().\r
 **/\r
 EFI_STATUS\r
@@ -1106,11 +1138,11 @@ FileInterfaceEnvDelete(
 \r
 /**\r
   File style interface for Environment Variable (Read).\r
-  \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
-  \r
+\r
   @retval EFI_SUCCESS   The data was read.\r
 **/\r
 EFI_STATUS\r
@@ -1129,12 +1161,14 @@ FileInterfaceEnvRead(
 \r
 /**\r
   File style interface for Volatile Environment Variable (Write).\r
-  \r
+  This function also caches the environment variable into gShellEnvVarList.\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
-  \r
-  @retval EFI_SUCCESS   The data was read.\r
+\r
+  @retval EFI_SUCCESS             The data was successfully write to variable.\r
+  @retval SHELL_OUT_OF_RESOURCES  A memory allocation failed.\r
 **/\r
 EFI_STATUS\r
 EFIAPI\r
@@ -1147,41 +1181,71 @@ FileInterfaceEnvVolWrite(
   VOID*       NewBuffer;\r
   UINTN       NewSize;\r
   EFI_STATUS  Status;\r
+  UINTN       TotalSize;\r
 \r
   NewBuffer   = NULL;\r
   NewSize     = 0;\r
+  TotalSize   = 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 + *BufferSize + sizeof(CHAR16));\r
+  if (Status == EFI_BUFFER_TOO_SMALL) {\r
+    TotalSize = NewSize + *BufferSize + sizeof (CHAR16);\r
+  } else if (Status == EFI_NOT_FOUND) {\r
+    TotalSize = *BufferSize + sizeof(CHAR16);\r
+  } else {\r
+    return Status;\r
+  }\r
+\r
+  NewBuffer = AllocateZeroPool (TotalSize);\r
+  if (NewBuffer == NULL) {\r
+    return EFI_OUT_OF_RESOURCES;\r
+  }\r
+\r
+  if (Status == EFI_BUFFER_TOO_SMALL) {\r
     Status = SHELL_GET_ENVIRONMENT_VARIABLE(((EFI_FILE_PROTOCOL_ENVIRONMENT*)This)->Name, &NewSize, NewBuffer);\r
   }\r
-  if (!EFI_ERROR(Status) && NewBuffer != NULL) {\r
-    while (((CHAR16*)NewBuffer)[NewSize/2] == CHAR_NULL) {\r
-      //\r
-      // We want to overwrite the CHAR_NULL\r
-      //\r
-      NewSize -= 2;\r
-    }\r
-    CopyMem((UINT8*)NewBuffer + NewSize + 2, Buffer, *BufferSize);\r
-    Status = SHELL_SET_ENVIRONMENT_VARIABLE_V(((EFI_FILE_PROTOCOL_ENVIRONMENT*)This)->Name, StrSize(NewBuffer), NewBuffer);\r
-    FreePool(NewBuffer);\r
-    return (Status);\r
-  } else {\r
-    SHELL_FREE_NON_NULL(NewBuffer);\r
-    return (SHELL_SET_ENVIRONMENT_VARIABLE_V(((EFI_FILE_PROTOCOL_ENVIRONMENT*)This)->Name, *BufferSize, Buffer));\r
+\r
+  if (EFI_ERROR (Status) && Status != EFI_NOT_FOUND) {\r
+    FreePool (NewBuffer);\r
+    return Status;\r
+  }\r
+\r
+  CopyMem ((UINT8*)NewBuffer + NewSize, Buffer, *BufferSize);\r
+  Status = ShellAddEnvVarToList (\r
+             ((EFI_FILE_PROTOCOL_ENVIRONMENT*)This)->Name,\r
+             NewBuffer,\r
+             TotalSize,\r
+             EFI_VARIABLE_BOOTSERVICE_ACCESS\r
+             );\r
+  if (EFI_ERROR(Status)) {\r
+    FreePool (NewBuffer);\r
+    return Status;\r
+  }\r
+\r
+  Status = SHELL_SET_ENVIRONMENT_VARIABLE_V (\r
+             ((EFI_FILE_PROTOCOL_ENVIRONMENT*)This)->Name,\r
+             TotalSize - sizeof (CHAR16),\r
+             NewBuffer\r
+             );\r
+  if (EFI_ERROR(Status)) {\r
+    ShellRemvoeEnvVarFromList (((EFI_FILE_PROTOCOL_ENVIRONMENT*)This)->Name);\r
   }\r
+\r
+  FreePool (NewBuffer);\r
+  return Status;\r
 }\r
 \r
 \r
 /**\r
   File style interface for Non Volatile Environment Variable (Write).\r
-  \r
+  This function also caches the environment variable into gShellEnvVarList.\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
-  \r
-  @retval EFI_SUCCESS   The data was read.\r
+\r
+  @retval EFI_SUCCESS             The data was successfully write to variable.\r
+  @retval SHELL_OUT_OF_RESOURCES  A memory allocation failed.\r
 **/\r
 EFI_STATUS\r
 EFIAPI\r
@@ -1194,27 +1258,58 @@ FileInterfaceEnvNonVolWrite(
   VOID*       NewBuffer;\r
   UINTN       NewSize;\r
   EFI_STATUS  Status;\r
+  UINTN       TotalSize;\r
 \r
   NewBuffer   = NULL;\r
   NewSize     = 0;\r
+  TotalSize   = 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 + *BufferSize);\r
+  if (Status == EFI_BUFFER_TOO_SMALL) {\r
+    TotalSize = NewSize + *BufferSize + sizeof (CHAR16);\r
+  } else if (Status == EFI_NOT_FOUND) {\r
+    TotalSize = *BufferSize + sizeof (CHAR16);\r
+  } else {\r
+    return Status;\r
+  }\r
+\r
+  NewBuffer = AllocateZeroPool (TotalSize);\r
+  if (NewBuffer == NULL) {\r
+    return EFI_OUT_OF_RESOURCES;\r
+  }\r
+\r
+  if (Status == EFI_BUFFER_TOO_SMALL) {\r
     Status = SHELL_GET_ENVIRONMENT_VARIABLE(((EFI_FILE_PROTOCOL_ENVIRONMENT*)This)->Name, &NewSize, NewBuffer);\r
   }\r
-  if (!EFI_ERROR(Status)) {\r
-    CopyMem((UINT8*)NewBuffer + NewSize, Buffer, *BufferSize);\r
-    return (SHELL_SET_ENVIRONMENT_VARIABLE_NV(\r
-    ((EFI_FILE_PROTOCOL_ENVIRONMENT*)This)->Name,\r
-    NewSize + *BufferSize,\r
-    NewBuffer));\r
-  } else {\r
-    return (SHELL_SET_ENVIRONMENT_VARIABLE_NV(\r
-    ((EFI_FILE_PROTOCOL_ENVIRONMENT*)This)->Name,\r
-    *BufferSize,\r
-    Buffer));\r
+\r
+  if (EFI_ERROR(Status) && Status != EFI_NOT_FOUND) {\r
+    FreePool (NewBuffer);\r
+    return Status;\r
+  }\r
+\r
+  CopyMem ((UINT8*) NewBuffer + NewSize, Buffer, *BufferSize);\r
+  Status = ShellAddEnvVarToList (\r
+             ((EFI_FILE_PROTOCOL_ENVIRONMENT*)This)->Name,\r
+             NewBuffer,\r
+             TotalSize,\r
+             EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS\r
+             );\r
+  if (EFI_ERROR (Status)) {\r
+    FreePool (NewBuffer);\r
+    return Status;\r
   }\r
+\r
+  Status = SHELL_SET_ENVIRONMENT_VARIABLE_NV (\r
+             ((EFI_FILE_PROTOCOL_ENVIRONMENT*)This)->Name,\r
+             TotalSize - sizeof (CHAR16),\r
+             NewBuffer\r
+             );\r
+  if (EFI_ERROR (Status)) {\r
+    ShellRemvoeEnvVarFromList (((EFI_FILE_PROTOCOL_ENVIRONMENT*)This)->Name);\r
+  }\r
+\r
+  FreePool (NewBuffer);\r
+  return Status;\r
 }\r
 \r
 /**\r
@@ -1227,7 +1322,6 @@ FileInterfaceEnvNonVolWrite(
   @return other     a pointer to an EFI_FILE_PROTOCOL structure\r
 **/\r
 EFI_FILE_PROTOCOL*\r
-EFIAPI\r
 CreateFileInterfaceEnv(\r
   IN CONST CHAR16 *EnvName\r
   )\r
@@ -1268,7 +1362,7 @@ CreateFileInterfaceEnv(
   EnvFileInterface->Flush       = FileInterfaceNopGeneric;\r
   EnvFileInterface->Delete      = FileInterfaceEnvDelete;\r
   EnvFileInterface->Read        = FileInterfaceEnvRead;\r
-  \r
+\r
   CopyMem(EnvFileInterface->Name, EnvName, EnvNameSize);\r
 \r
   //\r
@@ -1290,7 +1384,6 @@ CreateFileInterfaceEnv(
   @param[in, out] Row         Current row of the cursor position\r
 **/\r
 VOID\r
-EFIAPI\r
 MoveCursorBackward (\r
   IN     UINTN                   LineLength,\r
   IN OUT UINTN                   *Column,\r
@@ -1320,7 +1413,6 @@ MoveCursorBackward (
   @param[in, out] Row         Current row of the cursor position\r
 **/\r
 VOID\r
-EFIAPI\r
 MoveCursorForward (\r
   IN     UINTN                   LineLength,\r
   IN     UINTN                   TotalRow,\r
@@ -1352,7 +1444,6 @@ MoveCursorForward (
   @param[in] StartColumn  which column to start at\r
 **/\r
 VOID\r
-EFIAPI\r
 PrintCommandHistory (\r
   IN CONST UINTN TotalCols,\r
   IN CONST UINTN TotalRows,\r
@@ -1422,10 +1513,10 @@ typedef struct {
 \r
 /**\r
   File style interface for Mem (SetPosition).\r
-  \r
+\r
   @param[in] This       The pointer to the EFI_FILE_PROTOCOL object.\r
   @param[out] Position  The position to set.\r
-  \r
+\r
   @retval EFI_SUCCESS             The position was successfully changed.\r
   @retval EFI_INVALID_PARAMETER   The Position was invalid.\r
 **/\r
@@ -1446,12 +1537,12 @@ FileInterfaceMemSetPosition(
 \r
 /**\r
   File style interface for Mem (GetPosition).\r
-  \r
+\r
   @param[in] This       The pointer to the EFI_FILE_PROTOCOL object.\r
   @param[out] Position  The pointer to the position.\r
-  \r
+\r
   @retval EFI_SUCCESS   The position was retrieved.\r
-**/ \r
+**/\r
 EFI_STATUS\r
 EFIAPI\r
 FileInterfaceMemGetPosition(\r
@@ -1463,13 +1554,61 @@ FileInterfaceMemGetPosition(
   return (EFI_SUCCESS);\r
 }\r
 \r
+/**\r
+  File style interface for Mem (GetInfo).\r
+\r
+  @param  This            Protocol instance pointer.\r
+  @param  InformationType Type of information to return in Buffer.\r
+  @param  BufferSize      On input size of buffer, on output amount of data in buffer.\r
+  @param  Buffer          The buffer to return data.\r
+\r
+  @retval EFI_SUCCESS          Data was returned.\r
+  @retval EFI_UNSUPPORT        InformationType is not supported.\r
+  @retval EFI_NO_MEDIA         The device has no media.\r
+  @retval EFI_DEVICE_ERROR     The device reported an error.\r
+  @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.\r
+  @retval EFI_WRITE_PROTECTED  The device is write protected.\r
+  @retval EFI_ACCESS_DENIED    The file was open for read only.\r
+  @retval EFI_BUFFER_TOO_SMALL Buffer was too small; required size returned in BufferSize.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+FileInterfaceMemGetInfo(\r
+  IN EFI_FILE_PROTOCOL        *This,\r
+  IN EFI_GUID                 *InformationType,\r
+  IN OUT UINTN                *BufferSize,\r
+  OUT VOID                    *Buffer\r
+  )\r
+{\r
+  EFI_FILE_INFO               *FileInfo;\r
+\r
+  if (CompareGuid (InformationType, &gEfiFileInfoGuid)) {\r
+    if (*BufferSize < sizeof (EFI_FILE_INFO)) {\r
+      *BufferSize = sizeof (EFI_FILE_INFO);\r
+      return EFI_BUFFER_TOO_SMALL;\r
+    }\r
+    if (Buffer == NULL) {\r
+      return EFI_INVALID_PARAMETER;\r
+    }\r
+    FileInfo = (EFI_FILE_INFO *)Buffer;\r
+    FileInfo->Size = sizeof (*FileInfo);\r
+    ZeroMem (FileInfo, sizeof (*FileInfo));\r
+    FileInfo->FileSize = ((EFI_FILE_PROTOCOL_MEM*)This)->FileSize;\r
+    FileInfo->PhysicalSize = FileInfo->FileSize;\r
+    return EFI_SUCCESS;\r
+  }\r
+\r
+  return EFI_UNSUPPORTED;\r
+}\r
+\r
 /**\r
   File style interface for Mem (Write).\r
-  \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
-  \r
+\r
   @retval EFI_OUT_OF_RESOURCES The operation failed due to lack of resources.\r
   @retval EFI_SUCCESS          The data was written.\r
 **/\r
@@ -1520,11 +1659,11 @@ FileInterfaceMemWrite(
 \r
 /**\r
   File style interface for Mem (Read).\r
-  \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
-  \r
+\r
   @retval EFI_SUCCESS   The data was read.\r
 **/\r
 EFI_STATUS\r
@@ -1550,11 +1689,11 @@ FileInterfaceMemRead(
   File style interface for Mem (Close).\r
 \r
   Frees all memory associated with this object.\r
-  \r
+\r
   @param[in] This       The pointer to the EFI_FILE_PROTOCOL object.\r
-  \r
+\r
   @retval EFI_SUCCESS   The 'file' was closed.\r
-**/ \r
+**/\r
 EFI_STATUS\r
 EFIAPI\r
 FileInterfaceMemClose(\r
@@ -1576,7 +1715,6 @@ FileInterfaceMemClose(
   @return other     A pointer to an EFI_FILE_PROTOCOL structure.\r
 **/\r
 EFI_FILE_PROTOCOL*\r
-EFIAPI\r
 CreateFileInterfaceMem(\r
   IN CONST BOOLEAN Unicode\r
   )\r
@@ -1599,7 +1737,7 @@ CreateFileInterfaceMem(
   FileInterface->Close       = FileInterfaceMemClose;\r
   FileInterface->GetPosition = FileInterfaceMemGetPosition;\r
   FileInterface->SetPosition = FileInterfaceMemSetPosition;\r
-  FileInterface->GetInfo     = FileInterfaceNopGetInfo;\r
+  FileInterface->GetInfo     = FileInterfaceMemGetInfo;\r
   FileInterface->SetInfo     = FileInterfaceNopSetInfo;\r
   FileInterface->Flush       = FileInterfaceNopGeneric;\r
   FileInterface->Delete      = FileInterfaceNopGeneric;\r
@@ -1646,7 +1784,7 @@ typedef struct {
 \r
   @param  This            Protocol instance pointer.\r
   @param  Position        Byte position from the start of the file.\r
-                          \r
+\r
   @retval EFI_SUCCESS     Data was written.\r
   @retval EFI_UNSUPPORTED Seek request for non-zero is not valid on open.\r
 \r
@@ -1666,7 +1804,7 @@ FileInterfaceFileSetPosition(
 \r
   @param  This            Protocol instance pointer.\r
   @param  Position        Byte position from the start of the file.\r
-                          \r
+\r
   @retval EFI_SUCCESS     Data was written.\r
   @retval EFI_UNSUPPORTED Seek request for non-zero is not valid on open..\r
 \r
@@ -1861,7 +1999,7 @@ FileInterfaceFileOpen (
   Close and delete the file handle.\r
 \r
   @param  This                     Protocol instance pointer.\r
-                                   \r
+\r
   @retval EFI_SUCCESS              The device was opened.\r
   @retval EFI_WARN_DELETE_FAILURE  The handle was closed but the file was not deleted.\r
 \r
@@ -1880,9 +2018,9 @@ FileInterfaceFileDelete(
 \r
 /**\r
   File style interface for File (Close).\r
-  \r
+\r
   @param[in] This       The pointer to the EFI_FILE_PROTOCOL object.\r
-  \r
+\r
   @retval EFI_SUCCESS   The file was closed.\r
 **/\r
 EFI_STATUS\r
@@ -1900,13 +2038,13 @@ FileInterfaceFileClose(
 /**\r
   File style interface for File (Write).\r
 \r
-  If the file was opened with ASCII mode the data will be processed through \r
+  If the file was opened with ASCII mode the data will be processed through\r
   AsciiSPrint before writing.\r
-  \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
-  \r
+\r
   @retval EFI_SUCCESS   The data was written.\r
 **/\r
 EFI_STATUS\r
@@ -1943,10 +2081,10 @@ FileInterfaceFileWrite(
 \r
   This will create a new EFI_FILE_PROTOCOL identical to the Templace\r
   except that the new one has Unicode and Ascii knowledge.\r
-  \r
+\r
   @param[in] Template   A pointer to the EFI_FILE_PROTOCOL object.\r
   @param[in] Unicode    TRUE for UCS-2, FALSE for ASCII.\r
-  \r
+\r
   @return a new EFI_FILE_PROTOCOL object to be used instead of the template.\r
 **/\r
 EFI_FILE_PROTOCOL*\r