Index: /trunk/include/iprt/linux/sysfs.h
===================================================================
--- /trunk/include/iprt/linux/sysfs.h	(revision 60389)
+++ /trunk/include/iprt/linux/sysfs.h	(revision 60390)
@@ -84,4 +84,27 @@
 
 /**
+ * Opens a sysfs file for reading.
+ *
+ * @returns IPRT status code.
+ * @param   phFile      Where to store the file handle on success.
+ * @param   pszFormat   The name format, either absolute or relative to "/sys/".
+ * @param   va          The format args.
+ *
+ * @note Close the file using RTFileClose().
+ */
+RTDECL(int) RTLinuxSysFsOpenV(PRTFILE phFile, const char *pszFormat, va_list va) RT_IPRT_FORMAT_ATTR(2, 0);
+
+/**
+ * Opens a sysfs file - extended version.
+ *
+ * @returns IPRT status code.
+ * @param   phFile      Where to store the file handle on success.
+ * @param   fOpen       Open flags, see RTFileOpen().
+ * @param   pszFormat   The name format, either absolute or relative to "/sys/".
+ * @param   va          The format args.
+ */
+RTDECL(int) RTLinuxSysFsOpenExV(PRTFILE phFile, uint64_t fOpen, const char *pszFormat, va_list va) RT_IPRT_FORMAT_ATTR(3, 0);
+
+/**
  * Opens a sysfs file.
  *
@@ -89,21 +112,20 @@
  * @param   phFile      Where to store the file handle on success.
  * @param   pszFormat   The name format, either absolute or relative to "/sys/".
- * @param   va          The format args.
+ * @param   ...         The format args.
  *
  * @note Close the file using RTFileClose().
  */
-RTDECL(int) RTLinuxSysFsOpenV(PRTFILE phFile, const char *pszFormat, va_list va) RT_IPRT_FORMAT_ATTR(1, 0);
-
-/**
- * Opens a sysfs file.
+RTDECL(int) RTLinuxSysFsOpen(PRTFILE phFile, const char *pszFormat, ...) RT_IPRT_FORMAT_ATTR(2, 3);
+
+/**
+ * Opens a sysfs file - extended version.
  *
  * @returns IPRT status code.
  * @param   phFile      Where to store the file handle on success.
+ * @param   fOpen       Open flags, see RTFileOpen().
  * @param   pszFormat   The name format, either absolute or relative to "/sys/".
  * @param   ...         The format args.
- *
- * @note Close the file using RTFileClose().
- */
-RTDECL(int) RTLinuxSysFsOpen(PRTFILE phFile, const char *pszFormat, ...) RT_IPRT_FORMAT_ATTR(1, 2);
+ */
+RTDECL(int) RTLinuxSysFsOpenEx(PRTFILE phFile, uint64_t fOpen, const char *pszFormat, ...) RT_IPRT_FORMAT_ATTR(3, 4);
 
 /**
@@ -119,4 +141,16 @@
 
 /**
+ * Writes a string to a file opened with RTLinuxSysFsOpenEx or RTLinuxSysFsOpenExV for writing.
+ *
+ * @returns IPRT status code.
+ * @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   pcchWritten Where to store the amount of characters written on success - optional.
+ */
+RTDECL(int) RTLinuxSysFsWriteStr(RTFILE hFile, const char *pszBuf, size_t cchBuf, size_t *pcchWritten);
+
+/**
  * Reads the remainder of a file opened with RTLinuxSysFsOpen or
  * RTLinuxSysFsOpenV.
@@ -131,4 +165,16 @@
 
 /**
+ * Writes the given buffer to a file opened with RTLinuxSysFsOpenEx or
+ * RTLinuxSysFsOpenExV.
+ *
+ * @returns IPRT status code.
+ * @param   hFile       The file descriptor returned by RTLinuxSysFsOpenEx or RTLinuxSysFsOpenExV.
+ * @param   pvBuf       The data to write.
+ * @param   cbBuf       The size of the buffer.
+ * @param   pcbWritten  Where to return the number of bytes read.  Optional.
+ */
+RTDECL(int) RTLinuxSysFsWriteFile(RTFILE hFile, void *pvBuf, size_t cbBuf, size_t *pcbWritten);
+
+/**
  * Reads a number from a sysfs file.
  *
@@ -139,5 +185,5 @@
  * @param   va          Format args.
  */
-RTDECL(int) RTLinuxSysFsReadIntFileV(unsigned uBase, int64_t *pi64, const char *pszFormat, va_list va) RT_IPRT_FORMAT_ATTR(2, 0);
+RTDECL(int) RTLinuxSysFsReadIntFileV(unsigned uBase, int64_t *pi64, const char *pszFormat, va_list va) RT_IPRT_FORMAT_ATTR(3, 0);
 
 /**
@@ -150,5 +196,101 @@
  * @param   ...         Format args.
  */
-RTDECL(int) RTLinuxSysFsReadIntFile(unsigned uBase, int64_t *pi64, const char *pszFormat, ...) RT_IPRT_FORMAT_ATTR(2, 3);
+RTDECL(int) RTLinuxSysFsReadIntFile(unsigned uBase, int64_t *pi64, const char *pszFormat, ...) RT_IPRT_FORMAT_ATTR(3, 4);
+
+/**
+ * Writes an unsigned 8-bit number to a sysfs file.
+ *
+ * @returns IPRT status code.
+ * @param   uBase       The base format to write the number. Passing 16 here for
+ *                      example writes the number as a hexadecimal string with 0x prepended.
+ * @param   u8          The number to write.
+ * @param   pszFormat   The filename format, either absolute or relative to "/sys/".
+ * @param   va          Format args.
+ */
+RTDECL(int) RTLinuxSysFsWriteU8FileV(unsigned uBase, uint8_t u8, const char *pszFormat, va_list va) RT_IPRT_FORMAT_ATTR(3, 0);
+
+/**
+ * Writes an unsigned 8-bit number to a sysfs file.
+ *
+ * @returns IPRT status code.
+ * @param   uBase       The base format to write the number. Passing 16 here for
+ *                      example writes the number as a hexadecimal string with 0x prepended.
+ * @param   u8          The number to write.
+ * @param   pszFormat   The filename format, either absolute or relative to "/sys/".
+ * @param   ...         Format args.
+ */
+RTDECL(int) RTLinuxSysFsWriteU8File(unsigned uBase, uint8_t u8, const char *pszFormat, ...) RT_IPRT_FORMAT_ATTR(3, 4);
+
+/**
+ * Writes an unsigned 16-bit number to a sysfs file.
+ *
+ * @returns IPRT status code.
+ * @param   uBase       The base format to write the number. Passing 16 here for
+ *                      example writes the number as a hexadecimal string with 0x prepended.
+ * @param   u16         The number to write.
+ * @param   pszFormat   The filename format, either absolute or relative to "/sys/".
+ * @param   va          Format args.
+ */
+RTDECL(int) RTLinuxSysFsWriteU16FileV(unsigned uBase, uint16_t u16, const char *pszFormat, va_list va) RT_IPRT_FORMAT_ATTR(3, 0);
+
+/**
+ * Writes an unsigned 16-bit number to a sysfs file.
+ *
+ * @returns IPRT status code.
+ * @param   uBase       The base format to write the number. Passing 16 here for
+ *                      example writes the number as a hexadecimal string with 0x prepended.
+ * @param   u16         The number to write.
+ * @param   pszFormat   The filename format, either absolute or relative to "/sys/".
+ * @param   ...         Format args.
+ */
+RTDECL(int) RTLinuxSysFsWriteU16File(unsigned uBase, uint16_t u16, const char *pszFormat, ...) RT_IPRT_FORMAT_ATTR(3, 4);
+
+/**
+ * Writes an unsigned 32-bit number to a sysfs file.
+ *
+ * @returns IPRT status code.
+ * @param   uBase       The base format to write the number. Passing 16 here for
+ *                      example writes the number as a hexadecimal string with 0x prepended.
+ * @param   u32         The number to write.
+ * @param   pszFormat   The filename format, either absolute or relative to "/sys/".
+ * @param   va          Format args.
+ */
+RTDECL(int) RTLinuxSysFsWriteU32FileV(unsigned uBase, uint32_t u32, const char *pszFormat, va_list va) RT_IPRT_FORMAT_ATTR(3, 0);
+
+/**
+ * Writes an unsigned 8-bit number to a sysfs file.
+ *
+ * @returns IPRT status code.
+ * @param   uBase       The base format to write the number. Passing 16 here for
+ *                      example writes the number as a hexadecimal string with 0x prepended.
+ * @param   u32         The number to write.
+ * @param   pszFormat   The filename format, either absolute or relative to "/sys/".
+ * @param   ...         Format args.
+ */
+RTDECL(int) RTLinuxSysFsWriteU32File(unsigned uBase, uint32_t u32, const char *pszFormat, ...) RT_IPRT_FORMAT_ATTR(3, 4);
+
+/**
+ * Writes an unsigned 64-bit number to a sysfs file.
+ *
+ * @returns IPRT status code.
+ * @param   uBase       The base format to write the number. Passing 16 here for
+ *                      example writes the number as a hexadecimal string with 0x prepended.
+ * @param   u64         The number to write.
+ * @param   pszFormat   The filename format, either absolute or relative to "/sys/".
+ * @param   va          Format args.
+ */
+RTDECL(int) RTLinuxSysFsWriteU64FileV(unsigned uBase, uint64_t u64, const char *pszFormat, va_list va) RT_IPRT_FORMAT_ATTR(3, 0);
+
+/**
+ * Writes an unsigned 8-bit number to a sysfs file.
+ *
+ * @returns IPRT status code.
+ * @param   uBase       The base format to write the number. Passing 16 here for
+ *                      example writes the number as a hexadecimal string with 0x prepended.
+ * @param   u64         The number to write.
+ * @param   pszFormat   The filename format, either absolute or relative to "/sys/".
+ * @param   ...         Format args.
+ */
+RTDECL(int) RTLinuxSysFsWriteU64File(unsigned uBase, uint32_t u64, const char *pszFormat, ...) RT_IPRT_FORMAT_ATTR(3, 4);
 
 /**
@@ -160,5 +302,5 @@
  * @param   va          Format args.
  */
-RTDECL(int) RTLinuxSysFsReadDevNumFileV(dev_t *pDevNum, const char *pszFormat, va_list va) RT_IPRT_FORMAT_ATTR(1, 0);
+RTDECL(int) RTLinuxSysFsReadDevNumFileV(dev_t *pDevNum, const char *pszFormat, va_list va) RT_IPRT_FORMAT_ATTR(2, 0);
 
 /**
@@ -170,5 +312,5 @@
  * @param   ...         Format args.
  */
-RTDECL(int) RTLinuxSysFsReadDevNumFile(dev_t *pDevNum, const char *pszFormat, ...) RT_IPRT_FORMAT_ATTR(1, 2);
+RTDECL(int) RTLinuxSysFsReadDevNumFile(dev_t *pDevNum, const char *pszFormat, ...) RT_IPRT_FORMAT_ATTR(2, 3);
 
 /**
@@ -184,5 +326,5 @@
  * @param   va          Format args.
  */
-RTDECL(int) RTLinuxSysFsReadStrFileV(char *pszBuf, size_t cchBuf, size_t *pcchRead, const char *pszFormat, va_list va) RT_IPRT_FORMAT_ATTR(3, 0);
+RTDECL(int) RTLinuxSysFsReadStrFileV(char *pszBuf, size_t cchBuf, size_t *pcchRead, const char *pszFormat, va_list va) RT_IPRT_FORMAT_ATTR(4, 0);
 
 /**
@@ -198,5 +340,29 @@
  * @param   ...         Format args.
  */
-RTDECL(int) RTLinuxSysFsReadStrFile(char *pszBuf, size_t cchBuf, size_t *pcchRead, const char *pszFormat, ...) RT_IPRT_FORMAT_ATTR(3, 4);
+RTDECL(int) RTLinuxSysFsReadStrFile(char *pszBuf, size_t cchBuf, size_t *pcchRead, const char *pszFormat, ...) RT_IPRT_FORMAT_ATTR(4, 5);
+
+/**
+ * Writes a string to a sysfs file.
+ *
+ * @returns IPRT status code.
+ * @param   pszBuf      The string to write.
+ * @param   cchBuf      The size of the buffer pointed to by @a pszBuf.
+ * @param   pcchWritten Where to store the amount of characters written on success - optional.
+ * @param   pszFormat   The filename format, either absolute or relative to "/sys/".
+ * @param   va          Format args.
+ */
+RTDECL(int) RTLinuxSysFsWriteStrFileV(const char *pszBuf, size_t cchBuf, size_t *pcchWritten, const char *pszFormat, va_list va) RT_IPRT_FORMAT_ATTR(4, 0);
+
+/**
+ * Writes a string to a sysfs file.
+ *
+ * @returns IPRT status code.
+ * @param   pszBuf      The string to write.
+ * @param   cchBuf      The size of the buffer pointed to by @a pszBuf.
+ * @param   pcchWritten Where to store the amount of characters written on success - optional.
+ * @param   pszFormat   The filename format, either absolute or relative to "/sys/".
+ * @param   ...         Format args.
+ */
+RTDECL(int) RTLinuxSysFsReadStrFile(char *pszBuf, size_t cchBuf, size_t *pcchWritten, const char *pszFormat, ...) RT_IPRT_FORMAT_ATTR(4, 5);
 
 /**
@@ -216,5 +382,5 @@
  * @param   va           Format args.
  */
-RTDECL(int) RTLinuxSysFsGetLinkDestV(char *pszBuf, size_t cchBuf, size_t *pchBuf, const char *pszFormat, va_list va) RT_IPRT_FORMAT_ATTR(3, 0);
+RTDECL(int) RTLinuxSysFsGetLinkDestV(char *pszBuf, size_t cchBuf, size_t *pchBuf, const char *pszFormat, va_list va) RT_IPRT_FORMAT_ATTR(4, 0);
 
 /**
@@ -234,5 +400,5 @@
  * @param   ...         Format args.
  */
-RTDECL(int) RTLinuxSysFsGetLinkDest(char *pszBuf, size_t cchBuf, size_t *pchBuf, const char *pszFormat, ...) RT_IPRT_FORMAT_ATTR(3, 4);
+RTDECL(int) RTLinuxSysFsGetLinkDest(char *pszBuf, size_t cchBuf, size_t *pchBuf, const char *pszFormat, ...) RT_IPRT_FORMAT_ATTR(4, 5);
 
 /**
Index: /trunk/include/iprt/mangling.h
===================================================================
--- /trunk/include/iprt/mangling.h	(revision 60389)
+++ /trunk/include/iprt/mangling.h	(revision 60390)
@@ -997,9 +997,11 @@
 # define RTLinuxSysFsExists                             RT_MANGLER(RTLinuxSysFsExists)
 # define RTLinuxSysFsExistsEx                           RT_MANGLER(RTLinuxSysFsExistsEx)
-# define RTLinuxSysFsExistsExV                           RT_MANGLER(RTLinuxSysFsExistsExV)
+# define RTLinuxSysFsExistsExV                          RT_MANGLER(RTLinuxSysFsExistsExV)
 # define RTLinuxSysFsExistsV                            RT_MANGLER(RTLinuxSysFsExistsV)
 # define RTLinuxSysFsGetLinkDest                        RT_MANGLER(RTLinuxSysFsGetLinkDest)
 # define RTLinuxSysFsGetLinkDestV                       RT_MANGLER(RTLinuxSysFsGetLinkDestV)
 # define RTLinuxSysFsOpen                               RT_MANGLER(RTLinuxSysFsOpen)
+# define RTLinuxSysFsOpenEx                             RT_MANGLER(RTLinuxSysFsOpenEx)
+# define RTLinuxSysFsOpenExV                            RT_MANGLER(RTLinuxSysFsOpenExV)
 # define RTLinuxSysFsOpenV                              RT_MANGLER(RTLinuxSysFsOpenV)
 # define RTLinuxSysFsReadDevNumFile                     RT_MANGLER(RTLinuxSysFsReadDevNumFile)
@@ -1011,4 +1013,16 @@
 # define RTLinuxSysFsReadStrFile                        RT_MANGLER(RTLinuxSysFsReadStrFile)
 # define RTLinuxSysFsReadStrFileV                       RT_MANGLER(RTLinuxSysFsReadStrFileV)
+# define RTLinuxSysFsWriteFile                          RT_MANGLER(RTLinuxSysFsWriteFile)
+# define RTLinuxSysFsWriteStr                           RT_MANGLER(RTLinuxSysFsWriteStr)
+# define RTLinuxSysFsWriteStrFile                       RT_MANGLER(RTLinuxSysFsWriteStrFile)
+# define RTLinuxSysFsWriteStrFileV                      RT_MANGLER(RTLinuxSysFsWriteStrFileV)
+# define RTLinuxSysFsWriteU8File                        RT_MANGLER(RTLinuxSysFsWriteU8File)
+# define RTLinuxSysFsWriteU8FileV                       RT_MANGLER(RTLinuxSysFsWriteU8FileV)
+# define RTLinuxSysFsWriteU16File                       RT_MANGLER(RTLinuxSysFsWriteU16File)
+# define RTLinuxSysFsWriteU16FileV                      RT_MANGLER(RTLinuxSysFsWriteU16FileV)
+# define RTLinuxSysFsWriteU32File                       RT_MANGLER(RTLinuxSysFsWriteU32File)
+# define RTLinuxSysFsWriteU32FileV                      RT_MANGLER(RTLinuxSysFsWriteU32FileV)
+# define RTLinuxSysFsWriteU64File                       RT_MANGLER(RTLinuxSysFsWriteU64File)
+# define RTLinuxSysFsWriteU64FileV                      RT_MANGLER(RTLinuxSysFsWriteU64FileV)
 # define RTLocalIpcServerCreate                         RT_MANGLER(RTLocalIpcServerCreate)
 # define RTLocalIpcServerDestroy                        RT_MANGLER(RTLocalIpcServerDestroy)
Index: /trunk/src/VBox/Runtime/r3/linux/sysfs.cpp
===================================================================
--- /trunk/src/VBox/Runtime/r3/linux/sysfs.cpp	(revision 60389)
+++ /trunk/src/VBox/Runtime/r3/linux/sysfs.cpp	(revision 60390)
@@ -192,4 +192,17 @@
 
 
+RTDECL(int) RTLinuxSysFsOpenExV(PRTFILE phFile, uint64_t fOpen, const char *pszFormat, va_list va)
+{
+    /*
+     * Construct the filename and call open.
+     */
+    char szFilename[RTPATH_MAX];
+    int rc = rtLinuxSysFsConstructPath(szFilename, sizeof(szFilename), pszFormat, va);
+    if (RT_SUCCESS(rc))
+        rc = RTFileOpen(phFile, szFilename, fOpen);
+    return rc;
+}
+
+
 RTDECL(int) RTLinuxSysFsOpen(PRTFILE phFile, const char *pszFormat, ...)
 {
@@ -197,4 +210,14 @@
     va_start(va, pszFormat);
     int rc = RTLinuxSysFsOpenV(phFile, pszFormat, va);
+    va_end(va);
+    return rc;
+}
+
+
+RTDECL(int) RTLinuxSysFsOpenEx(PRTFILE phFile, uint64_t fOpen, const char *pszFormat, ...)
+{
+    va_list va;
+    va_start(va, pszFormat);
+    int rc = RTLinuxSysFsOpenExV(phFile, fOpen, pszFormat, va);
     va_end(va);
     return rc;
@@ -213,4 +236,12 @@
 
     return rc;
+}
+
+
+RTDECL(int) RTLinuxSysFsWriteStr(RTFILE hFile, const char *pszBuf, size_t cchBuf, size_t *pcchWritten)
+{
+    if (!cchBuf)
+        cchBuf = strlen(pszBuf);
+    return RTFileWrite(hFile, pszBuf, cchBuf, pcchWritten);
 }
 
@@ -247,4 +278,10 @@
 
 
+RTDECL(int) RTLinuxSysFsWriteFile(RTFILE hFile, void *pvBuf, size_t cbBuf, size_t *pcbWritten)
+{
+    return RTFileWrite(hFile, pvBuf, cbBuf, pcbWritten);
+}
+
+
 RTDECL(int) RTLinuxSysFsReadIntFileV(unsigned uBase, int64_t *pi64, const char *pszFormat, va_list va)
 {
@@ -284,4 +321,105 @@
     va_start(va, pszFormat);
     int rc = RTLinuxSysFsReadIntFileV(uBase, pi64, pszFormat, va);
+    va_end(va);
+    return rc;
+}
+
+
+RTDECL(int) RTLinuxSysFsWriteU8FileV(unsigned uBase, uint8_t u8, const char *pszFormat, va_list va)
+{
+    return RTLinuxSysFsWriteU64FileV(uBase, u8, pszFormat, va);
+}
+
+
+RTDECL(int) RTLinuxSysFsWriteU8File(unsigned uBase, uint8_t u8, const char *pszFormat, ...)
+{
+    va_list va;
+    va_start(va, pszFormat);
+    int rc = RTLinuxSysFsWriteU64FileV(uBase, u8, pszFormat, va);
+    va_end(va);
+    return rc;
+}
+
+
+RTDECL(int) RTLinuxSysFsWriteU16FileV(unsigned uBase, uint16_t u16, const char *pszFormat, va_list va)
+{
+    return RTLinuxSysFsWriteU64FileV(uBase, u16, pszFormat, va);
+}
+
+
+RTDECL(int) RTLinuxSysFsWriteU16File(unsigned uBase, uint16_t u16, const char *pszFormat, ...)
+{
+    va_list va;
+    va_start(va, pszFormat);
+    int rc = RTLinuxSysFsWriteU64FileV(uBase, u16, pszFormat, va);
+    va_end(va);
+    return rc;
+}
+
+
+RTDECL(int) RTLinuxSysFsWriteU32FileV(unsigned uBase, uint32_t u32, const char *pszFormat, va_list va)
+{
+    return RTLinuxSysFsWriteU64FileV(uBase, u32, pszFormat, va);
+}
+
+
+RTDECL(int) RTLinuxSysFsWriteU32File(unsigned uBase, uint32_t u32, const char *pszFormat, ...)
+{
+    va_list va;
+    va_start(va, pszFormat);
+    int rc = RTLinuxSysFsWriteU64FileV(uBase, u32, pszFormat, va);
+    va_end(va);
+    return rc;
+}
+
+
+RTDECL(int) RTLinuxSysFsWriteU64FileV(unsigned uBase, uint64_t u64, const char *pszFormat, va_list va)
+{
+    RTFILE hFile;
+
+    const char *pszFmt = NULL;
+    switch (uBase)
+    {
+        case 8:
+            pszFmt = "%#llo";
+            break;
+        case 10:
+            pszFmt = "%llu";
+            break;
+        case 16:
+            pszFmt = "%#llx";
+            break;
+        default:
+            return VERR_INVALID_PARAMETER;
+    }
+
+    int rc = RTLinuxSysFsOpenV(&hFile, pszFormat, va);
+    if (RT_SUCCESS(rc))
+    {
+        char szNum[128];
+        size_t cchNum = RTStrPrintf(szNum, sizeof(szNum), pszFmt, u64);
+        if (cchNum > 0)
+        {
+            size_t cbWritten = 0;
+            rc = RTLinuxSysFsWriteStr(hFile, &szNum[0], cchNum, &cbWritten);
+            if (   RT_SUCCESS(rc)
+                && cbWritten != cchNum)
+                rc = VERR_BUFFER_OVERFLOW;
+        }
+        else
+            rc = VERR_INVALID_PARAMETER;
+
+        RTFileClose(hFile);
+    }
+
+    return rc;
+}
+
+
+RTDECL(int) RTLinuxSysFsWriteU64File(unsigned uBase, uint32_t u64, const char *pszFormat, ...)
+{
+    va_list va;
+    va_start(va, pszFormat);
+    int rc = RTLinuxSysFsWriteU64FileV(uBase, u64, pszFormat, va);
     va_end(va);
     return rc;
