Index: /trunk/include/iprt/mangling.h
===================================================================
--- /trunk/include/iprt/mangling.h	(revision 59523)
+++ /trunk/include/iprt/mangling.h	(revision 59524)
@@ -2207,4 +2207,5 @@
 # define RTVfsDirRetain                                 RT_MANGLER(RTVfsDirRetain)
 # define RTVfsFileFlush                                 RT_MANGLER(RTVfsFileFlush)
+# define RTVfsFileFromBuffer                            RT_MANGLER(RTVfsFileFromBuffer)
 # define RTVfsFileFromRTFile                            RT_MANGLER(RTVfsFileFromRTFile)
 # define RTVfsFileGetSize                               RT_MANGLER(RTVfsFileGetSize)
@@ -2255,4 +2256,5 @@
 # define RTVfsLockReleaseWriteSlow                      RT_MANGLER(RTVfsLockReleaseWriteSlow)
 # define RTVfsLockRetain                                RT_MANGLER(RTVfsLockRetain)
+# define RTVfsMemFileCreate                             RT_MANGLER(RTVfsMemFileCreate)
 # define RTVfsMemorizeIoStreamAsFile                    RT_MANGLER(RTVfsMemorizeIoStreamAsFile)
 # define RTVfsNew                                       RT_MANGLER(RTVfsNew)
Index: /trunk/include/iprt/vfs.h
===================================================================
--- /trunk/include/iprt/vfs.h	(revision 59523)
+++ /trunk/include/iprt/vfs.h	(revision 59524)
@@ -903,4 +903,35 @@
 
 /**
+ * Creates a VFS file from a memory buffer.
+ *
+ * @returns VBox status code.
+ *
+ * @param   hVfsIos         The VFS I/O stream to memorize.  This will be read
+ *                          to the end on success, on failure its position is
+ *                          undefined.
+ * @param   fFlags          A combination of RTFILE_O_READ and RTFILE_O_WRITE.
+ * @param   pvBuf           The buffer.  This will be copied and not referenced
+ *                          after this function returns.
+ * @param   cbBuf           The buffer size.
+ * @param   phVfsFile       Where to return the handle to the memory file on
+ *                          success.
+ */
+RTDECL(int) RTVfsFileFromBuffer(RTVFSIOSTREAM hVfsIos, uint32_t fFlags, void const *pvBuf, size_t cbBuf, PRTVFSFILE phVfsFile);
+
+/**
+ * Creates a memory backed VFS file object for read and write.
+ *
+ * @returns VBox status code.
+ *
+ * @param   hVfsIos         The VFS I/O stream to memorize.  This will be read
+ *                          to the end on success, on failure its position is
+ *                          undefined.
+ * @param   cbEstimate      The estimated file size.
+ * @param   phVfsFile       Where to return the handle to the memory file on
+ *                          success.
+ */
+RTDECL(int) RTVfsMemFileCreate(RTVFSIOSTREAM hVfsIos, size_t cbEstimate, PRTVFSFILE phVfsFile);
+
+/**
  * Pumps data from one I/O stream to another.
  *
Index: /trunk/src/VBox/Runtime/common/vfs/vfsmemory.cpp
===================================================================
--- /trunk/src/VBox/Runtime/common/vfs/vfsmemory.cpp	(revision 59523)
+++ /trunk/src/VBox/Runtime/common/vfs/vfsmemory.cpp	(revision 59524)
@@ -702,7 +702,7 @@
 
 /**
- * Standard file operations.
- */
-DECL_HIDDEN_CONST(const RTVFSFILEOPS) g_rtVfsStdFileOps =
+ * Memory file operations.
+ */
+DECL_HIDDEN_CONST(const RTVFSFILEOPS) g_rtVfsMemFileOps =
 {
     { /* Stream */
@@ -742,5 +742,98 @@
 
 
-
+/**
+ * Initialize the RTVFSMEMFILE specific members.
+ *
+ * @param   pThis           The memory file to initialize.
+ * @param   cbObject        The object size for estimating extent size.
+ * @param   fFlags          The user specified flags.
+ */
+static void rtVfsMemFileInit(PRTVFSMEMFILE pThis, RTFOFF cbObject, uint32_t fFlags)
+{
+    pThis->offCurPos    = 0;
+    pThis->pCurExt      = NULL;
+    RTListInit(&pThis->ExtentHead);
+    if (cbObject <= 0)
+        pThis->cbExtent = _4K;
+    else if (cbObject < RTVFSMEM_MAX_EXTENT_SIZE)
+        pThis->cbExtent = fFlags & RTFILE_O_WRITE ? _4K : cbObject;
+    else
+        pThis->cbExtent = RTVFSMEM_MAX_EXTENT_SIZE;
+}
+
+
+/**
+ * Rewinds the file to position 0 and clears the WRITE flag if necessary.
+ *
+ * @param   pThis           The memory file instance.
+ * @param   fFlags          The user specified flags.
+ */
+static void rtVfsMemFileResetAndFixWriteFlag(PRTVFSMEMFILE pThis, uint32_t fFlags)
+{
+    pThis->pCurExt   = RTListGetFirst(&pThis->ExtentHead, RTVFSMEMEXTENT, Entry);
+    pThis->offCurPos = 0;
+
+    if (!(fFlags & RTFILE_O_WRITE))
+    {
+        /** @todo clear RTFILE_O_WRITE from the resulting. */
+    }
+}
+
+
+RTDECL(int) RTVfsMemFileCreate(RTVFSIOSTREAM hVfsIos, size_t cbEstimate, PRTVFSFILE phVfsFile)
+{
+    /*
+     * Create a memory file instance and set the extension size according to the
+     * buffer size.  Add the WRITE flag so we can use normal write APIs for
+     * copying the buffer.
+     */
+    RTVFSFILE       hVfsFile;
+    PRTVFSMEMFILE   pThis;
+    int rc = RTVfsNewFile(&g_rtVfsMemFileOps, sizeof(*pThis), RTFILE_O_READ | RTFILE_O_WRITE, NIL_RTVFS, NIL_RTVFSLOCK,
+                          &hVfsFile, (void **)&pThis);
+    if (RT_SUCCESS(rc))
+    {
+        pThis->Base.ObjInfo.cbObject   = 0;
+        pThis->Base.ObjInfo.Attr.fMode = RTFS_DOS_NT_NORMAL | RTFS_TYPE_FILE | RTFS_UNIX_IRWXU;
+        rtVfsMemFileInit(pThis, cbEstimate, RTFILE_O_READ | RTFILE_O_WRITE);
+
+        *phVfsFile = hVfsFile;
+        return VINF_SUCCESS;
+    }
+    return rc;
+}
+
+
+RTDECL(int) RTVfsFileFromBuffer(RTVFSIOSTREAM hVfsIos, uint32_t fFlags, void const *pvBuf, size_t cbBuf, PRTVFSFILE phVfsFile)
+{
+    /*
+     * Create a memory file instance and set the extension size according to the
+     * buffer size.  Add the WRITE flag so we can use normal write APIs for
+     * copying the buffer.
+     */
+    RTVFSFILE       hVfsFile;
+    PRTVFSMEMFILE   pThis;
+    int rc = RTVfsNewFile(&g_rtVfsMemFileOps, sizeof(*pThis), fFlags | RTFILE_O_WRITE, NIL_RTVFS, NIL_RTVFSLOCK,
+                          &hVfsFile, (void **)&pThis);
+    if (RT_SUCCESS(rc))
+    {
+        pThis->Base.ObjInfo.cbObject   = cbBuf;
+        pThis->Base.ObjInfo.Attr.fMode = RTFS_DOS_NT_NORMAL | RTFS_TYPE_FILE | RTFS_UNIX_IRWXU;
+        rtVfsMemFileInit(pThis, cbBuf, fFlags);
+
+        /*
+         * Copy the buffer and reposition the file pointer to the start.
+         */
+        rc = RTVfsFileWrite(hVfsFile, pvBuf, cbBuf, NULL);
+        if (RT_SUCCESS(rc))
+        {
+            rtVfsMemFileResetAndFixWriteFlag(pThis, fFlags);
+            *phVfsFile = hVfsFile;
+            return VINF_SUCCESS;
+        }
+        RTVfsFileRelease(hVfsFile);
+    }
+    return rc;
+}
 
 
@@ -757,18 +850,10 @@
         RTVFSFILE       hVfsFile;
         PRTVFSMEMFILE   pThis;
-        rc = RTVfsNewFile(&g_rtVfsStdFileOps, sizeof(*pThis), fFlags | RTFILE_O_WRITE, NIL_RTVFS, NIL_RTVFSLOCK,
+        rc = RTVfsNewFile(&g_rtVfsMemFileOps, sizeof(*pThis), fFlags | RTFILE_O_WRITE, NIL_RTVFS, NIL_RTVFSLOCK,
                           &hVfsFile, (void **)&pThis);
         if (RT_SUCCESS(rc))
         {
             pThis->Base.ObjInfo = ObjInfo;
-            pThis->offCurPos    = 0;
-            pThis->pCurExt      = NULL;
-            RTListInit(&pThis->ExtentHead);
-            if (ObjInfo.cbObject <= 0)
-                pThis->cbExtent = _4K;
-            else if (ObjInfo.cbObject < RTVFSMEM_MAX_EXTENT_SIZE)
-                pThis->cbExtent = _4K /* ObjInfo.cbObject */;
-            else
-                pThis->cbExtent = RTVFSMEM_MAX_EXTENT_SIZE;
+            rtVfsMemFileInit(pThis, ObjInfo.cbObject, fFlags);
 
             /*
@@ -780,11 +865,5 @@
             if (RT_SUCCESS(rc))
             {
-                pThis->pCurExt   = RTListGetFirst(&pThis->ExtentHead, RTVFSMEMEXTENT, Entry);
-                pThis->offCurPos = 0;
-
-                if (!(fFlags & RTFILE_O_WRITE))
-                {
-                    /** @todo clear RTFILE_O_WRITE from the resulting. */
-                }
+                rtVfsMemFileResetAndFixWriteFlag(pThis, fFlags);
                 *phVfsFile = hVfsFile;
                 return VINF_SUCCESS;
@@ -795,2 +874,3 @@
     return rc;
 }
+
