Index: /trunk/include/iprt/linux/sysfs.h
===================================================================
--- /trunk/include/iprt/linux/sysfs.h	(revision 60426)
+++ /trunk/include/iprt/linux/sysfs.h	(revision 60427)
@@ -146,6 +146,6 @@
  * @param   hFile       The file descriptor returned by RTLinuxSysFsOpenEx or RTLinuxSysFsOpenExV.
  * @param   pszBuf      The string to write.
- * @param   cchBuf      The string length without zero terminator - if 0 is given
- *                      the string length is determined before writing.
+ * @param   cchBuf      The length of the string to write - if 0 is given
+ *                      the string length is determined before writing it including the zero terminator.
  * @param   pcchWritten Where to store the amount of characters written on success - optional.
  */
Index: /trunk/src/VBox/Runtime/r3/linux/sysfs.cpp
===================================================================
--- /trunk/src/VBox/Runtime/r3/linux/sysfs.cpp	(revision 60426)
+++ /trunk/src/VBox/Runtime/r3/linux/sysfs.cpp	(revision 60427)
@@ -238,11 +238,20 @@
         /* Check for EOF */
         uint64_t offCur = 0;
-        uint64_t offEnd = 0;
+        uint8_t bRead;
         rc = RTFileSeek(hFile, 0, RTFILE_SEEK_CURRENT, &offCur);
         if (RT_SUCCESS(rc))
-            rc = RTFileSeek(hFile, 0, RTFILE_SEEK_END, &offEnd);
-        if (   RT_SUCCESS(rc)
-            && offEnd > offCur)
-            rc = VERR_BUFFER_OVERFLOW;
+        {
+            int rc2 = RTFileRead(hFile, &bRead, 1, NULL);
+            if (RT_SUCCESS(rc2))
+            {
+                rc = VERR_BUFFER_OVERFLOW;
+
+                rc2 = RTFileSeek(hFile, offCur, RTFILE_SEEK_BEGIN, NULL);
+                if (RT_FAILURE(rc2))
+                    rc = rc2;
+            }
+            else if (rc2 != VERR_EOF)
+                rc = rc2;
+        }
     }
     return rc;
@@ -253,5 +262,5 @@
 {
     if (!cchBuf)
-        cchBuf = strlen(pszBuf);
+        cchBuf = strlen(pszBuf) + 1; /* Include the terminator */
     return RTFileWrite(hFile, pszBuf, cchBuf, pcchWritten);
 }
@@ -274,11 +283,20 @@
             /* Check for EOF */
             uint64_t offCur = 0;
-            uint64_t offEnd = 0;
+            uint8_t bRead;
             rc = RTFileSeek(hFile, 0, RTFILE_SEEK_CURRENT, &offCur);
             if (RT_SUCCESS(rc))
-                rc = RTFileSeek(hFile, 0, RTFILE_SEEK_END, &offEnd);
-            if (   RT_SUCCESS(rc)
-                && offEnd > offCur)
-                rc = VERR_BUFFER_OVERFLOW;
+            {
+                int rc2 = RTFileRead(hFile, &bRead, 1, NULL);
+                if (RT_SUCCESS(rc2))
+                {
+                    rc = VERR_BUFFER_OVERFLOW;
+
+                    rc2 = RTFileSeek(hFile, offCur, RTFILE_SEEK_BEGIN, NULL);
+                    if (RT_FAILURE(rc2))
+                        rc = rc2;
+                }
+                else if (rc2 != VERR_EOF)
+                    rc = rc2;
+            }
         }
     }
@@ -502,5 +520,4 @@
         size_t cchRead = 0;
         rc = RTLinuxSysFsReadStr(hFile, pszBuf, cchBuf, &cchRead);
-        RTFileClose(hFile);
         if (   RT_SUCCESS(rc)
             && cchRead > 0)
@@ -508,6 +525,35 @@
             char *pchNewLine = (char *)memchr(pszBuf, '\n', cchRead);
             if (pchNewLine)
+            {
                 *pchNewLine = '\0';
-        }
+                cchRead--;
+            }
+        }
+        else if (   rc == VERR_BUFFER_OVERFLOW
+                 && cchRead > 0)
+        {
+            /*
+             * Check if the last character would have been a newline we filter out
+             * anyway and revert the buffer overflow.
+             */
+            char achBuf[2];
+            size_t cchPeek = 0;
+            uint64_t offCur = 0;
+
+            int rc2 = RTFileSeek(hFile, 0, RTFILE_SEEK_CURRENT, &offCur);
+            if (RT_SUCCESS(rc2))
+            {
+                rc2 = RTLinuxSysFsReadStr(hFile, &achBuf[0], sizeof(achBuf), &cchPeek);
+                if (   RT_SUCCESS(rc2)
+                    && cchPeek > 0)
+                    rc2 = RTFileSeek(hFile, offCur, RTFILE_SEEK_BEGIN, NULL);
+                if (   RT_SUCCESS(rc2)
+                    && cchPeek > 0
+                    && achBuf[0] == '\n')
+                    rc = VINF_SUCCESS;
+            }
+        }
+
+        RTFileClose(hFile);
 
         if (pcchRead)
