Index: /trunk/src/VBox/Additions/common/VBoxService/VBoxServiceControlSession.cpp
===================================================================
--- /trunk/src/VBox/Additions/common/VBoxService/VBoxServiceControlSession.cpp	(revision 71780)
+++ /trunk/src/VBox/Additions/common/VBoxService/VBoxServiceControlSession.cpp	(revision 71781)
@@ -183,10 +183,9 @@
             if (RT_SUCCESS(rc))
             {
-                /** @todo r=bird: Plase, use RTStrCopy for stuff like this! */
-                RTStrPrintf(pFile->szName, sizeof(pFile->szName), "%s", szFile);
+                RTStrCopy(pFile->szName, sizeof(pFile->szName), szFile);
 
                 uint64_t fFlags;
                 rc = RTFileModeToFlagsEx(szAccess, szDisposition, NULL /* pszSharing, not used yet */, &fFlags);
-                VGSvcVerbose(4, "[File %s]: Opening with fFlags=0x%x, rc=%Rrc\n", pFile->szName, fFlags, rc);
+                VGSvcVerbose(4, "[File %s] Opening with fFlags=0x%x, rc=%Rrc\n", pFile->szName, fFlags, rc);
 
                 if (RT_SUCCESS(rc))
@@ -199,8 +198,8 @@
                     rc = RTFileSeek(pFile->hFile, (int64_t)offOpen, RTFILE_SEEK_BEGIN, NULL /* Current offset */);
                     if (RT_FAILURE(rc))
-                        VGSvcError("[File %s]: Seeking to offset %RU64 failed; rc=%Rrc\n", pFile->szName, offOpen, rc);
+                        VGSvcError("[File %s] Seeking to offset %RU64 failed; rc=%Rrc\n", pFile->szName, offOpen, rc);
                 }
                 else if (RT_FAILURE(rc))
-                    VGSvcError("[File %s]: Opening failed with rc=%Rrc\n", pFile->szName, rc);
+                    VGSvcError("[File %s] Opening failed with rc=%Rrc\n", pFile->szName, rc);
             }
 
@@ -212,5 +211,5 @@
                 RTListAppend(&pSession->lstFiles, &pFile->Node);
 
-                VGSvcVerbose(3, "[File %s]: Opened (ID=%RU32)\n", pFile->szName, pFile->uHandle);
+                VGSvcVerbose(2, "[File %s] Opened (ID=%RU32)\n", pFile->szName, pFile->uHandle);
             }
 
@@ -233,8 +232,6 @@
     }
 
-#ifdef DEBUG
-    VGSvcVerbose(4, "Opening file '%s' (open mode='%s', disposition='%s', creation mode=0x%x returned rc=%Rrc\n",
+    VGSvcVerbose(4, "[File %s] Opening (open mode='%s', disposition='%s', creation mode=0x%x) returned rc=%Rrc\n",
                  szFile, szAccess, szDisposition, uCreationMode, rc);
-#endif
     return rc;
 }
@@ -246,13 +243,15 @@
     AssertPtrReturn(pHostCtx, VERR_INVALID_POINTER);
 
-    PVBOXSERVICECTRLFILE pFile = NULL;
-
     uint32_t uHandle = 0;
     int rc = VbglR3GuestCtrlFileGetClose(pHostCtx, &uHandle /* File handle to close */);
     if (RT_SUCCESS(rc))
     {
-        pFile = vgsvcGstCtrlSessionFileGetLocked(pSession, uHandle);
+        PVBOXSERVICECTRLFILE pFile = vgsvcGstCtrlSessionFileGetLocked(pSession, uHandle);
         if (pFile)
+        {
+            VGSvcVerbose(2, "[File %s] Closing (handle=%RU32)\n", pFile ? pFile->szName : "<Not found>", uHandle);
+
             rc = vgsvcGstCtrlSessionFileDestroy(pFile);
+        }
         else
             rc = VERR_NOT_FOUND;
@@ -266,7 +265,4 @@
     }
 
-#ifdef DEBUG
-    VGSvcVerbose(4, "Closing file '%s' (handle=%RU32) returned rc=%Rrc\n", pFile ? pFile->szName : "<Not found>", uHandle, rc);
-#endif
     return rc;
 }
@@ -278,6 +274,4 @@
     AssertPtrReturn(pSession, VERR_INVALID_POINTER);
     AssertPtrReturn(pHostCtx, VERR_INVALID_POINTER);
-
-    PVBOXSERVICECTRLFILE pFile = NULL;
 
     uint32_t uHandle = 0;
@@ -289,5 +283,5 @@
         size_t cbRead = 0;
 
-        pFile = vgsvcGstCtrlSessionFileGetLocked(pSession, uHandle);
+        PVBOXSERVICECTRLFILE pFile = vgsvcGstCtrlSessionFileGetLocked(pSession, uHandle);
         if (pFile)
         {
@@ -310,4 +304,6 @@
             rc = VERR_NOT_FOUND;
 
+        VGSvcVerbose(4, "[File %s] Read %zu/%RU32 bytes, rc=%Rrc\n", pFile ? pFile->szName : "<Not found>", cbRead, cbToRead, rc);
+
         /* Report back in any case. */
         int rc2 = VbglR3GuestCtrlFileCbRead(pHostCtx, rc, pvDataRead, (uint32_t)cbRead);
@@ -322,7 +318,4 @@
     }
 
-#ifdef DEBUG
-    VGSvcVerbose(4, "Reading file '%s' (handle=%RU32) returned rc=%Rrc\n", pFile ? pFile->szName : "<Not found>", uHandle, rc);
-#endif
     return rc;
 }
@@ -334,6 +327,4 @@
     AssertPtrReturn(pSession, VERR_INVALID_POINTER);
     AssertPtrReturn(pHostCtx, VERR_INVALID_POINTER);
-
-    PVBOXSERVICECTRLFILE pFile = NULL;
 
     uint32_t uHandle = 0;
@@ -346,5 +337,5 @@
         size_t cbRead = 0;
 
-        pFile = vgsvcGstCtrlSessionFileGetLocked(pSession, uHandle);
+        PVBOXSERVICECTRLFILE pFile = vgsvcGstCtrlSessionFileGetLocked(pSession, uHandle);
         if (pFile)
         {
@@ -360,4 +351,7 @@
                 if (RT_SUCCESS(rc))
                     rc = RTFileReadAt(pFile->hFile, (RTFOFF)offReadAt, pvDataRead, cbToRead, &cbRead);
+
+                VGSvcVerbose(4, "[File %s] Read %zu bytes @ %RU64, rc=%Rrc\n",
+                             pFile ? pFile->szName : "<Not found>", cbRead, offReadAt, rc);
             }
             else
@@ -379,8 +373,4 @@
     }
 
-#ifdef DEBUG
-    VGSvcVerbose(4, "Reading file '%s' at offset (handle=%RU32) returned rc=%Rrc\n",
-                 pFile ? pFile->szName : "<Not found>", uHandle, rc);
-#endif
     return rc;
 }
@@ -395,6 +385,4 @@
     AssertPtrReturn(cbScratchBuf, VERR_INVALID_PARAMETER);
 
-    PVBOXSERVICECTRLFILE pFile = NULL;
-
     uint32_t uHandle = 0;
     uint32_t cbToWrite;
@@ -403,10 +391,10 @@
     {
         size_t cbWritten = 0;
-        pFile = vgsvcGstCtrlSessionFileGetLocked(pSession, uHandle);
+        PVBOXSERVICECTRLFILE pFile = vgsvcGstCtrlSessionFileGetLocked(pSession, uHandle);
         if (pFile)
         {
             rc = RTFileWrite(pFile->hFile, pvScratchBuf, cbToWrite, &cbWritten);
 #ifdef DEBUG
-            VGSvcVerbose(4, "[File %s]: Writing pvScratchBuf=%p, cbToWrite=%RU32, cbWritten=%zu, rc=%Rrc\n",
+            VGSvcVerbose(4, "[File %s] Writing pvScratchBuf=%p, cbToWrite=%RU32, cbWritten=%zu, rc=%Rrc\n",
                          pFile->szName, pvScratchBuf, cbToWrite, cbWritten, rc);
 #endif
@@ -423,7 +411,4 @@
     }
 
-#ifdef DEBUG
-    VGSvcVerbose(4, "Writing file '%s' (handle=%RU32) returned rc=%Rrc\n", pFile ? pFile->szName : "<Not found>", uHandle, rc);
-#endif
     return rc;
 }
@@ -438,6 +423,4 @@
     AssertPtrReturn(cbScratchBuf, VERR_INVALID_PARAMETER);
 
-    PVBOXSERVICECTRLFILE pFile = NULL;
-
     uint32_t uHandle = 0;
     uint32_t cbToWrite;
@@ -448,10 +431,10 @@
     {
         size_t cbWritten = 0;
-        pFile = vgsvcGstCtrlSessionFileGetLocked(pSession, uHandle);
+        PVBOXSERVICECTRLFILE pFile = vgsvcGstCtrlSessionFileGetLocked(pSession, uHandle);
         if (pFile)
         {
             rc = RTFileWriteAt(pFile->hFile, (RTFOFF)offWriteAt, pvScratchBuf, cbToWrite, &cbWritten);
 #ifdef DEBUG
-            VGSvcVerbose(4, "[File %s]: Writing offWriteAt=%RI64, pvScratchBuf=%p, cbToWrite=%RU32, cbWritten=%zu, rc=%Rrc\n",
+            VGSvcVerbose(4, "[File %s] Writing offWriteAt=%RI64, pvScratchBuf=%p, cbToWrite=%RU32, cbWritten=%zu, rc=%Rrc\n",
                          pFile->szName, offWriteAt, pvScratchBuf, cbToWrite, cbWritten, rc);
 #endif
@@ -468,8 +451,4 @@
     }
 
-#ifdef DEBUG
-    VGSvcVerbose(4, "Writing file '%s' at offset (handle=%RU32) returned rc=%Rrc\n",
-                 pFile ? pFile->szName : "<Not found>", uHandle, rc);
-#endif
     return rc;
 }
@@ -480,6 +459,4 @@
     AssertPtrReturn(pSession, VERR_INVALID_POINTER);
     AssertPtrReturn(pHostCtx, VERR_INVALID_POINTER);
-
-    PVBOXSERVICECTRLFILE pFile = NULL;
 
     uint32_t uHandle = 0;
@@ -490,5 +467,5 @@
     {
         uint64_t offActual = 0;
-        pFile = vgsvcGstCtrlSessionFileGetLocked(pSession, uHandle);
+        PVBOXSERVICECTRLFILE pFile = vgsvcGstCtrlSessionFileGetLocked(pSession, uHandle);
         if (pFile)
         {
@@ -534,7 +511,4 @@
     }
 
-#ifdef DEBUG
-    VGSvcVerbose(4, "Seeking file '%s' (handle=%RU32) returned rc=%Rrc\n", pFile ? pFile->szName : "<Not found>", uHandle, rc);
-#endif
     return rc;
 }
@@ -546,17 +520,15 @@
     AssertPtrReturn(pHostCtx, VERR_INVALID_POINTER);
 
-    PVBOXSERVICECTRLFILE pFile = NULL;
-
     uint32_t uHandle = 0;
     int rc = VbglR3GuestCtrlFileGetTell(pHostCtx, &uHandle);
     if (RT_SUCCESS(rc))
     {
-        uint64_t off = 0;
-        pFile = vgsvcGstCtrlSessionFileGetLocked(pSession, uHandle);
+        uint64_t uOffCurrent = 0;
+        PVBOXSERVICECTRLFILE pFile = vgsvcGstCtrlSessionFileGetLocked(pSession, uHandle);
         if (pFile)
         {
-            off = RTFileTell(pFile->hFile);
+            uOffCurrent = RTFileTell(pFile->hFile);
 #ifdef DEBUG
-            VGSvcVerbose(4, "[File %s]: Telling off=%RU64\n", pFile->szName, off);
+            VGSvcVerbose(4, "[File %s]: Telling uOffCurrent=%RU64\n", pFile->szName, uOffCurrent);
 #endif
         }
@@ -565,5 +537,5 @@
 
         /* Report back in any case. */
-        int rc2 = VbglR3GuestCtrlFileCbTell(pHostCtx, rc, off);
+        int rc2 = VbglR3GuestCtrlFileCbTell(pHostCtx, rc, uOffCurrent);
         if (RT_FAILURE(rc2))
             VGSvcError("Failed to report file tell status, rc=%Rrc\n", rc2);
@@ -572,7 +544,4 @@
     }
 
-#ifdef DEBUG
-    VGSvcVerbose(4, "Telling file '%s' (handle=%RU32) returned rc=%Rrc\n", pFile ? pFile->szName : "<Not found>", uHandle, rc);
-#endif
     return rc;
 }
