VirtualBox

Changeset 60390 in vbox for trunk/include/iprt/linux


Ignore:
Timestamp:
Apr 8, 2016 9:17:34 AM (9 years ago)
Author:
vboxsync
Message:

Runtime/linux/sysfs: Correct format string attributes and introduce new methods to write to sysfs files

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/iprt/linux/sysfs.h

    r60373 r60390  
    8484
    8585/**
     86 * Opens a sysfs file for reading.
     87 *
     88 * @returns IPRT status code.
     89 * @param   phFile      Where to store the file handle on success.
     90 * @param   pszFormat   The name format, either absolute or relative to "/sys/".
     91 * @param   va          The format args.
     92 *
     93 * @note Close the file using RTFileClose().
     94 */
     95RTDECL(int) RTLinuxSysFsOpenV(PRTFILE phFile, const char *pszFormat, va_list va) RT_IPRT_FORMAT_ATTR(2, 0);
     96
     97/**
     98 * Opens a sysfs file - extended version.
     99 *
     100 * @returns IPRT status code.
     101 * @param   phFile      Where to store the file handle on success.
     102 * @param   fOpen       Open flags, see RTFileOpen().
     103 * @param   pszFormat   The name format, either absolute or relative to "/sys/".
     104 * @param   va          The format args.
     105 */
     106RTDECL(int) RTLinuxSysFsOpenExV(PRTFILE phFile, uint64_t fOpen, const char *pszFormat, va_list va) RT_IPRT_FORMAT_ATTR(3, 0);
     107
     108/**
    86109 * Opens a sysfs file.
    87110 *
     
    89112 * @param   phFile      Where to store the file handle on success.
    90113 * @param   pszFormat   The name format, either absolute or relative to "/sys/".
    91  * @param   va          The format args.
     114 * @param   ...         The format args.
    92115 *
    93116 * @note Close the file using RTFileClose().
    94117 */
    95 RTDECL(int) RTLinuxSysFsOpenV(PRTFILE phFile, const char *pszFormat, va_list va) RT_IPRT_FORMAT_ATTR(1, 0);
    96 
    97 /**
    98  * Opens a sysfs file.
     118RTDECL(int) RTLinuxSysFsOpen(PRTFILE phFile, const char *pszFormat, ...) RT_IPRT_FORMAT_ATTR(2, 3);
     119
     120/**
     121 * Opens a sysfs file - extended version.
    99122 *
    100123 * @returns IPRT status code.
    101124 * @param   phFile      Where to store the file handle on success.
     125 * @param   fOpen       Open flags, see RTFileOpen().
    102126 * @param   pszFormat   The name format, either absolute or relative to "/sys/".
    103127 * @param   ...         The format args.
    104  *
    105  * @note Close the file using RTFileClose().
    106  */
    107 RTDECL(int) RTLinuxSysFsOpen(PRTFILE phFile, const char *pszFormat, ...) RT_IPRT_FORMAT_ATTR(1, 2);
     128 */
     129RTDECL(int) RTLinuxSysFsOpenEx(PRTFILE phFile, uint64_t fOpen, const char *pszFormat, ...) RT_IPRT_FORMAT_ATTR(3, 4);
    108130
    109131/**
     
    119141
    120142/**
     143 * Writes a string to a file opened with RTLinuxSysFsOpenEx or RTLinuxSysFsOpenExV for writing.
     144 *
     145 * @returns IPRT status code.
     146 * @param   hFile       The file descriptor returned by RTLinuxSysFsOpenEx or RTLinuxSysFsOpenExV.
     147 * @param   pszBuf      The string to write.
     148 * @param   cchBuf      The string length without zero terminator - if 0 is given
     149 *                      the string length is determined before writing.
     150 * @param   pcchWritten Where to store the amount of characters written on success - optional.
     151 */
     152RTDECL(int) RTLinuxSysFsWriteStr(RTFILE hFile, const char *pszBuf, size_t cchBuf, size_t *pcchWritten);
     153
     154/**
    121155 * Reads the remainder of a file opened with RTLinuxSysFsOpen or
    122156 * RTLinuxSysFsOpenV.
     
    131165
    132166/**
     167 * Writes the given buffer to a file opened with RTLinuxSysFsOpenEx or
     168 * RTLinuxSysFsOpenExV.
     169 *
     170 * @returns IPRT status code.
     171 * @param   hFile       The file descriptor returned by RTLinuxSysFsOpenEx or RTLinuxSysFsOpenExV.
     172 * @param   pvBuf       The data to write.
     173 * @param   cbBuf       The size of the buffer.
     174 * @param   pcbWritten  Where to return the number of bytes read.  Optional.
     175 */
     176RTDECL(int) RTLinuxSysFsWriteFile(RTFILE hFile, void *pvBuf, size_t cbBuf, size_t *pcbWritten);
     177
     178/**
    133179 * Reads a number from a sysfs file.
    134180 *
     
    139185 * @param   va          Format args.
    140186 */
    141 RTDECL(int) RTLinuxSysFsReadIntFileV(unsigned uBase, int64_t *pi64, const char *pszFormat, va_list va) RT_IPRT_FORMAT_ATTR(2, 0);
     187RTDECL(int) RTLinuxSysFsReadIntFileV(unsigned uBase, int64_t *pi64, const char *pszFormat, va_list va) RT_IPRT_FORMAT_ATTR(3, 0);
    142188
    143189/**
     
    150196 * @param   ...         Format args.
    151197 */
    152 RTDECL(int) RTLinuxSysFsReadIntFile(unsigned uBase, int64_t *pi64, const char *pszFormat, ...) RT_IPRT_FORMAT_ATTR(2, 3);
     198RTDECL(int) RTLinuxSysFsReadIntFile(unsigned uBase, int64_t *pi64, const char *pszFormat, ...) RT_IPRT_FORMAT_ATTR(3, 4);
     199
     200/**
     201 * Writes an unsigned 8-bit number to a sysfs file.
     202 *
     203 * @returns IPRT status code.
     204 * @param   uBase       The base format to write the number. Passing 16 here for
     205 *                      example writes the number as a hexadecimal string with 0x prepended.
     206 * @param   u8          The number to write.
     207 * @param   pszFormat   The filename format, either absolute or relative to "/sys/".
     208 * @param   va          Format args.
     209 */
     210RTDECL(int) RTLinuxSysFsWriteU8FileV(unsigned uBase, uint8_t u8, const char *pszFormat, va_list va) RT_IPRT_FORMAT_ATTR(3, 0);
     211
     212/**
     213 * Writes an unsigned 8-bit number to a sysfs file.
     214 *
     215 * @returns IPRT status code.
     216 * @param   uBase       The base format to write the number. Passing 16 here for
     217 *                      example writes the number as a hexadecimal string with 0x prepended.
     218 * @param   u8          The number to write.
     219 * @param   pszFormat   The filename format, either absolute or relative to "/sys/".
     220 * @param   ...         Format args.
     221 */
     222RTDECL(int) RTLinuxSysFsWriteU8File(unsigned uBase, uint8_t u8, const char *pszFormat, ...) RT_IPRT_FORMAT_ATTR(3, 4);
     223
     224/**
     225 * Writes an unsigned 16-bit number to a sysfs file.
     226 *
     227 * @returns IPRT status code.
     228 * @param   uBase       The base format to write the number. Passing 16 here for
     229 *                      example writes the number as a hexadecimal string with 0x prepended.
     230 * @param   u16         The number to write.
     231 * @param   pszFormat   The filename format, either absolute or relative to "/sys/".
     232 * @param   va          Format args.
     233 */
     234RTDECL(int) RTLinuxSysFsWriteU16FileV(unsigned uBase, uint16_t u16, const char *pszFormat, va_list va) RT_IPRT_FORMAT_ATTR(3, 0);
     235
     236/**
     237 * Writes an unsigned 16-bit number to a sysfs file.
     238 *
     239 * @returns IPRT status code.
     240 * @param   uBase       The base format to write the number. Passing 16 here for
     241 *                      example writes the number as a hexadecimal string with 0x prepended.
     242 * @param   u16         The number to write.
     243 * @param   pszFormat   The filename format, either absolute or relative to "/sys/".
     244 * @param   ...         Format args.
     245 */
     246RTDECL(int) RTLinuxSysFsWriteU16File(unsigned uBase, uint16_t u16, const char *pszFormat, ...) RT_IPRT_FORMAT_ATTR(3, 4);
     247
     248/**
     249 * Writes an unsigned 32-bit number to a sysfs file.
     250 *
     251 * @returns IPRT status code.
     252 * @param   uBase       The base format to write the number. Passing 16 here for
     253 *                      example writes the number as a hexadecimal string with 0x prepended.
     254 * @param   u32         The number to write.
     255 * @param   pszFormat   The filename format, either absolute or relative to "/sys/".
     256 * @param   va          Format args.
     257 */
     258RTDECL(int) RTLinuxSysFsWriteU32FileV(unsigned uBase, uint32_t u32, const char *pszFormat, va_list va) RT_IPRT_FORMAT_ATTR(3, 0);
     259
     260/**
     261 * Writes an unsigned 8-bit number to a sysfs file.
     262 *
     263 * @returns IPRT status code.
     264 * @param   uBase       The base format to write the number. Passing 16 here for
     265 *                      example writes the number as a hexadecimal string with 0x prepended.
     266 * @param   u32         The number to write.
     267 * @param   pszFormat   The filename format, either absolute or relative to "/sys/".
     268 * @param   ...         Format args.
     269 */
     270RTDECL(int) RTLinuxSysFsWriteU32File(unsigned uBase, uint32_t u32, const char *pszFormat, ...) RT_IPRT_FORMAT_ATTR(3, 4);
     271
     272/**
     273 * Writes an unsigned 64-bit number to a sysfs file.
     274 *
     275 * @returns IPRT status code.
     276 * @param   uBase       The base format to write the number. Passing 16 here for
     277 *                      example writes the number as a hexadecimal string with 0x prepended.
     278 * @param   u64         The number to write.
     279 * @param   pszFormat   The filename format, either absolute or relative to "/sys/".
     280 * @param   va          Format args.
     281 */
     282RTDECL(int) RTLinuxSysFsWriteU64FileV(unsigned uBase, uint64_t u64, const char *pszFormat, va_list va) RT_IPRT_FORMAT_ATTR(3, 0);
     283
     284/**
     285 * Writes an unsigned 8-bit number to a sysfs file.
     286 *
     287 * @returns IPRT status code.
     288 * @param   uBase       The base format to write the number. Passing 16 here for
     289 *                      example writes the number as a hexadecimal string with 0x prepended.
     290 * @param   u64         The number to write.
     291 * @param   pszFormat   The filename format, either absolute or relative to "/sys/".
     292 * @param   ...         Format args.
     293 */
     294RTDECL(int) RTLinuxSysFsWriteU64File(unsigned uBase, uint32_t u64, const char *pszFormat, ...) RT_IPRT_FORMAT_ATTR(3, 4);
    153295
    154296/**
     
    160302 * @param   va          Format args.
    161303 */
    162 RTDECL(int) RTLinuxSysFsReadDevNumFileV(dev_t *pDevNum, const char *pszFormat, va_list va) RT_IPRT_FORMAT_ATTR(1, 0);
     304RTDECL(int) RTLinuxSysFsReadDevNumFileV(dev_t *pDevNum, const char *pszFormat, va_list va) RT_IPRT_FORMAT_ATTR(2, 0);
    163305
    164306/**
     
    170312 * @param   ...         Format args.
    171313 */
    172 RTDECL(int) RTLinuxSysFsReadDevNumFile(dev_t *pDevNum, const char *pszFormat, ...) RT_IPRT_FORMAT_ATTR(1, 2);
     314RTDECL(int) RTLinuxSysFsReadDevNumFile(dev_t *pDevNum, const char *pszFormat, ...) RT_IPRT_FORMAT_ATTR(2, 3);
    173315
    174316/**
     
    184326 * @param   va          Format args.
    185327 */
    186 RTDECL(int) RTLinuxSysFsReadStrFileV(char *pszBuf, size_t cchBuf, size_t *pcchRead, const char *pszFormat, va_list va) RT_IPRT_FORMAT_ATTR(3, 0);
     328RTDECL(int) RTLinuxSysFsReadStrFileV(char *pszBuf, size_t cchBuf, size_t *pcchRead, const char *pszFormat, va_list va) RT_IPRT_FORMAT_ATTR(4, 0);
    187329
    188330/**
     
    198340 * @param   ...         Format args.
    199341 */
    200 RTDECL(int) RTLinuxSysFsReadStrFile(char *pszBuf, size_t cchBuf, size_t *pcchRead, const char *pszFormat, ...) RT_IPRT_FORMAT_ATTR(3, 4);
     342RTDECL(int) RTLinuxSysFsReadStrFile(char *pszBuf, size_t cchBuf, size_t *pcchRead, const char *pszFormat, ...) RT_IPRT_FORMAT_ATTR(4, 5);
     343
     344/**
     345 * Writes a string to a sysfs file.
     346 *
     347 * @returns IPRT status code.
     348 * @param   pszBuf      The string to write.
     349 * @param   cchBuf      The size of the buffer pointed to by @a pszBuf.
     350 * @param   pcchWritten Where to store the amount of characters written on success - optional.
     351 * @param   pszFormat   The filename format, either absolute or relative to "/sys/".
     352 * @param   va          Format args.
     353 */
     354RTDECL(int) RTLinuxSysFsWriteStrFileV(const char *pszBuf, size_t cchBuf, size_t *pcchWritten, const char *pszFormat, va_list va) RT_IPRT_FORMAT_ATTR(4, 0);
     355
     356/**
     357 * Writes a string to a sysfs file.
     358 *
     359 * @returns IPRT status code.
     360 * @param   pszBuf      The string to write.
     361 * @param   cchBuf      The size of the buffer pointed to by @a pszBuf.
     362 * @param   pcchWritten Where to store the amount of characters written on success - optional.
     363 * @param   pszFormat   The filename format, either absolute or relative to "/sys/".
     364 * @param   ...         Format args.
     365 */
     366RTDECL(int) RTLinuxSysFsReadStrFile(char *pszBuf, size_t cchBuf, size_t *pcchWritten, const char *pszFormat, ...) RT_IPRT_FORMAT_ATTR(4, 5);
    201367
    202368/**
     
    216382 * @param   va           Format args.
    217383 */
    218 RTDECL(int) RTLinuxSysFsGetLinkDestV(char *pszBuf, size_t cchBuf, size_t *pchBuf, const char *pszFormat, va_list va) RT_IPRT_FORMAT_ATTR(3, 0);
     384RTDECL(int) RTLinuxSysFsGetLinkDestV(char *pszBuf, size_t cchBuf, size_t *pchBuf, const char *pszFormat, va_list va) RT_IPRT_FORMAT_ATTR(4, 0);
    219385
    220386/**
     
    234400 * @param   ...         Format args.
    235401 */
    236 RTDECL(int) RTLinuxSysFsGetLinkDest(char *pszBuf, size_t cchBuf, size_t *pchBuf, const char *pszFormat, ...) RT_IPRT_FORMAT_ATTR(3, 4);
     402RTDECL(int) RTLinuxSysFsGetLinkDest(char *pszBuf, size_t cchBuf, size_t *pchBuf, const char *pszFormat, ...) RT_IPRT_FORMAT_ATTR(4, 5);
    237403
    238404/**
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette