Changeset 60390 in vbox
- Timestamp:
- Apr 8, 2016 9:17:34 AM (8 years ago)
- Location:
- trunk
- Files:
-
- 3 edited
-
include/iprt/linux/sysfs.h (modified) (12 diffs)
-
include/iprt/mangling.h (modified) (2 diffs)
-
src/VBox/Runtime/r3/linux/sysfs.cpp (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/iprt/linux/sysfs.h
r60373 r60390 84 84 85 85 /** 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 */ 95 RTDECL(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 */ 106 RTDECL(int) RTLinuxSysFsOpenExV(PRTFILE phFile, uint64_t fOpen, const char *pszFormat, va_list va) RT_IPRT_FORMAT_ATTR(3, 0); 107 108 /** 86 109 * Opens a sysfs file. 87 110 * … … 89 112 * @param phFile Where to store the file handle on success. 90 113 * @param pszFormat The name format, either absolute or relative to "/sys/". 91 * @param vaThe format args.114 * @param ... The format args. 92 115 * 93 116 * @note Close the file using RTFileClose(). 94 117 */ 95 RTDECL(int) RTLinuxSysFsOpen V(PRTFILE phFile, const char *pszFormat, va_list va) RT_IPRT_FORMAT_ATTR(1, 0);96 97 /** 98 * Opens a sysfs file .118 RTDECL(int) RTLinuxSysFsOpen(PRTFILE phFile, const char *pszFormat, ...) RT_IPRT_FORMAT_ATTR(2, 3); 119 120 /** 121 * Opens a sysfs file - extended version. 99 122 * 100 123 * @returns IPRT status code. 101 124 * @param phFile Where to store the file handle on success. 125 * @param fOpen Open flags, see RTFileOpen(). 102 126 * @param pszFormat The name format, either absolute or relative to "/sys/". 103 127 * @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 */ 129 RTDECL(int) RTLinuxSysFsOpenEx(PRTFILE phFile, uint64_t fOpen, const char *pszFormat, ...) RT_IPRT_FORMAT_ATTR(3, 4); 108 130 109 131 /** … … 119 141 120 142 /** 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 */ 152 RTDECL(int) RTLinuxSysFsWriteStr(RTFILE hFile, const char *pszBuf, size_t cchBuf, size_t *pcchWritten); 153 154 /** 121 155 * Reads the remainder of a file opened with RTLinuxSysFsOpen or 122 156 * RTLinuxSysFsOpenV. … … 131 165 132 166 /** 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 */ 176 RTDECL(int) RTLinuxSysFsWriteFile(RTFILE hFile, void *pvBuf, size_t cbBuf, size_t *pcbWritten); 177 178 /** 133 179 * Reads a number from a sysfs file. 134 180 * … … 139 185 * @param va Format args. 140 186 */ 141 RTDECL(int) RTLinuxSysFsReadIntFileV(unsigned uBase, int64_t *pi64, const char *pszFormat, va_list va) RT_IPRT_FORMAT_ATTR( 2, 0);187 RTDECL(int) RTLinuxSysFsReadIntFileV(unsigned uBase, int64_t *pi64, const char *pszFormat, va_list va) RT_IPRT_FORMAT_ATTR(3, 0); 142 188 143 189 /** … … 150 196 * @param ... Format args. 151 197 */ 152 RTDECL(int) RTLinuxSysFsReadIntFile(unsigned uBase, int64_t *pi64, const char *pszFormat, ...) RT_IPRT_FORMAT_ATTR(2, 3); 198 RTDECL(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 */ 210 RTDECL(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 */ 222 RTDECL(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 */ 234 RTDECL(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 */ 246 RTDECL(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 */ 258 RTDECL(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 */ 270 RTDECL(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 */ 282 RTDECL(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 */ 294 RTDECL(int) RTLinuxSysFsWriteU64File(unsigned uBase, uint32_t u64, const char *pszFormat, ...) RT_IPRT_FORMAT_ATTR(3, 4); 153 295 154 296 /** … … 160 302 * @param va Format args. 161 303 */ 162 RTDECL(int) RTLinuxSysFsReadDevNumFileV(dev_t *pDevNum, const char *pszFormat, va_list va) RT_IPRT_FORMAT_ATTR( 1, 0);304 RTDECL(int) RTLinuxSysFsReadDevNumFileV(dev_t *pDevNum, const char *pszFormat, va_list va) RT_IPRT_FORMAT_ATTR(2, 0); 163 305 164 306 /** … … 170 312 * @param ... Format args. 171 313 */ 172 RTDECL(int) RTLinuxSysFsReadDevNumFile(dev_t *pDevNum, const char *pszFormat, ...) RT_IPRT_FORMAT_ATTR( 1, 2);314 RTDECL(int) RTLinuxSysFsReadDevNumFile(dev_t *pDevNum, const char *pszFormat, ...) RT_IPRT_FORMAT_ATTR(2, 3); 173 315 174 316 /** … … 184 326 * @param va Format args. 185 327 */ 186 RTDECL(int) RTLinuxSysFsReadStrFileV(char *pszBuf, size_t cchBuf, size_t *pcchRead, const char *pszFormat, va_list va) RT_IPRT_FORMAT_ATTR( 3, 0);328 RTDECL(int) RTLinuxSysFsReadStrFileV(char *pszBuf, size_t cchBuf, size_t *pcchRead, const char *pszFormat, va_list va) RT_IPRT_FORMAT_ATTR(4, 0); 187 329 188 330 /** … … 198 340 * @param ... Format args. 199 341 */ 200 RTDECL(int) RTLinuxSysFsReadStrFile(char *pszBuf, size_t cchBuf, size_t *pcchRead, const char *pszFormat, ...) RT_IPRT_FORMAT_ATTR(3, 4); 342 RTDECL(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 */ 354 RTDECL(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 */ 366 RTDECL(int) RTLinuxSysFsReadStrFile(char *pszBuf, size_t cchBuf, size_t *pcchWritten, const char *pszFormat, ...) RT_IPRT_FORMAT_ATTR(4, 5); 201 367 202 368 /** … … 216 382 * @param va Format args. 217 383 */ 218 RTDECL(int) RTLinuxSysFsGetLinkDestV(char *pszBuf, size_t cchBuf, size_t *pchBuf, const char *pszFormat, va_list va) RT_IPRT_FORMAT_ATTR( 3, 0);384 RTDECL(int) RTLinuxSysFsGetLinkDestV(char *pszBuf, size_t cchBuf, size_t *pchBuf, const char *pszFormat, va_list va) RT_IPRT_FORMAT_ATTR(4, 0); 219 385 220 386 /** … … 234 400 * @param ... Format args. 235 401 */ 236 RTDECL(int) RTLinuxSysFsGetLinkDest(char *pszBuf, size_t cchBuf, size_t *pchBuf, const char *pszFormat, ...) RT_IPRT_FORMAT_ATTR( 3, 4);402 RTDECL(int) RTLinuxSysFsGetLinkDest(char *pszBuf, size_t cchBuf, size_t *pchBuf, const char *pszFormat, ...) RT_IPRT_FORMAT_ATTR(4, 5); 237 403 238 404 /** -
trunk/include/iprt/mangling.h
r60373 r60390 997 997 # define RTLinuxSysFsExists RT_MANGLER(RTLinuxSysFsExists) 998 998 # define RTLinuxSysFsExistsEx RT_MANGLER(RTLinuxSysFsExistsEx) 999 # define RTLinuxSysFsExistsExV RT_MANGLER(RTLinuxSysFsExistsExV)999 # define RTLinuxSysFsExistsExV RT_MANGLER(RTLinuxSysFsExistsExV) 1000 1000 # define RTLinuxSysFsExistsV RT_MANGLER(RTLinuxSysFsExistsV) 1001 1001 # define RTLinuxSysFsGetLinkDest RT_MANGLER(RTLinuxSysFsGetLinkDest) 1002 1002 # define RTLinuxSysFsGetLinkDestV RT_MANGLER(RTLinuxSysFsGetLinkDestV) 1003 1003 # define RTLinuxSysFsOpen RT_MANGLER(RTLinuxSysFsOpen) 1004 # define RTLinuxSysFsOpenEx RT_MANGLER(RTLinuxSysFsOpenEx) 1005 # define RTLinuxSysFsOpenExV RT_MANGLER(RTLinuxSysFsOpenExV) 1004 1006 # define RTLinuxSysFsOpenV RT_MANGLER(RTLinuxSysFsOpenV) 1005 1007 # define RTLinuxSysFsReadDevNumFile RT_MANGLER(RTLinuxSysFsReadDevNumFile) … … 1011 1013 # define RTLinuxSysFsReadStrFile RT_MANGLER(RTLinuxSysFsReadStrFile) 1012 1014 # define RTLinuxSysFsReadStrFileV RT_MANGLER(RTLinuxSysFsReadStrFileV) 1015 # define RTLinuxSysFsWriteFile RT_MANGLER(RTLinuxSysFsWriteFile) 1016 # define RTLinuxSysFsWriteStr RT_MANGLER(RTLinuxSysFsWriteStr) 1017 # define RTLinuxSysFsWriteStrFile RT_MANGLER(RTLinuxSysFsWriteStrFile) 1018 # define RTLinuxSysFsWriteStrFileV RT_MANGLER(RTLinuxSysFsWriteStrFileV) 1019 # define RTLinuxSysFsWriteU8File RT_MANGLER(RTLinuxSysFsWriteU8File) 1020 # define RTLinuxSysFsWriteU8FileV RT_MANGLER(RTLinuxSysFsWriteU8FileV) 1021 # define RTLinuxSysFsWriteU16File RT_MANGLER(RTLinuxSysFsWriteU16File) 1022 # define RTLinuxSysFsWriteU16FileV RT_MANGLER(RTLinuxSysFsWriteU16FileV) 1023 # define RTLinuxSysFsWriteU32File RT_MANGLER(RTLinuxSysFsWriteU32File) 1024 # define RTLinuxSysFsWriteU32FileV RT_MANGLER(RTLinuxSysFsWriteU32FileV) 1025 # define RTLinuxSysFsWriteU64File RT_MANGLER(RTLinuxSysFsWriteU64File) 1026 # define RTLinuxSysFsWriteU64FileV RT_MANGLER(RTLinuxSysFsWriteU64FileV) 1013 1027 # define RTLocalIpcServerCreate RT_MANGLER(RTLocalIpcServerCreate) 1014 1028 # define RTLocalIpcServerDestroy RT_MANGLER(RTLocalIpcServerDestroy) -
trunk/src/VBox/Runtime/r3/linux/sysfs.cpp
r60373 r60390 192 192 193 193 194 RTDECL(int) RTLinuxSysFsOpenExV(PRTFILE phFile, uint64_t fOpen, const char *pszFormat, va_list va) 195 { 196 /* 197 * Construct the filename and call open. 198 */ 199 char szFilename[RTPATH_MAX]; 200 int rc = rtLinuxSysFsConstructPath(szFilename, sizeof(szFilename), pszFormat, va); 201 if (RT_SUCCESS(rc)) 202 rc = RTFileOpen(phFile, szFilename, fOpen); 203 return rc; 204 } 205 206 194 207 RTDECL(int) RTLinuxSysFsOpen(PRTFILE phFile, const char *pszFormat, ...) 195 208 { … … 197 210 va_start(va, pszFormat); 198 211 int rc = RTLinuxSysFsOpenV(phFile, pszFormat, va); 212 va_end(va); 213 return rc; 214 } 215 216 217 RTDECL(int) RTLinuxSysFsOpenEx(PRTFILE phFile, uint64_t fOpen, const char *pszFormat, ...) 218 { 219 va_list va; 220 va_start(va, pszFormat); 221 int rc = RTLinuxSysFsOpenExV(phFile, fOpen, pszFormat, va); 199 222 va_end(va); 200 223 return rc; … … 213 236 214 237 return rc; 238 } 239 240 241 RTDECL(int) RTLinuxSysFsWriteStr(RTFILE hFile, const char *pszBuf, size_t cchBuf, size_t *pcchWritten) 242 { 243 if (!cchBuf) 244 cchBuf = strlen(pszBuf); 245 return RTFileWrite(hFile, pszBuf, cchBuf, pcchWritten); 215 246 } 216 247 … … 247 278 248 279 280 RTDECL(int) RTLinuxSysFsWriteFile(RTFILE hFile, void *pvBuf, size_t cbBuf, size_t *pcbWritten) 281 { 282 return RTFileWrite(hFile, pvBuf, cbBuf, pcbWritten); 283 } 284 285 249 286 RTDECL(int) RTLinuxSysFsReadIntFileV(unsigned uBase, int64_t *pi64, const char *pszFormat, va_list va) 250 287 { … … 284 321 va_start(va, pszFormat); 285 322 int rc = RTLinuxSysFsReadIntFileV(uBase, pi64, pszFormat, va); 323 va_end(va); 324 return rc; 325 } 326 327 328 RTDECL(int) RTLinuxSysFsWriteU8FileV(unsigned uBase, uint8_t u8, const char *pszFormat, va_list va) 329 { 330 return RTLinuxSysFsWriteU64FileV(uBase, u8, pszFormat, va); 331 } 332 333 334 RTDECL(int) RTLinuxSysFsWriteU8File(unsigned uBase, uint8_t u8, const char *pszFormat, ...) 335 { 336 va_list va; 337 va_start(va, pszFormat); 338 int rc = RTLinuxSysFsWriteU64FileV(uBase, u8, pszFormat, va); 339 va_end(va); 340 return rc; 341 } 342 343 344 RTDECL(int) RTLinuxSysFsWriteU16FileV(unsigned uBase, uint16_t u16, const char *pszFormat, va_list va) 345 { 346 return RTLinuxSysFsWriteU64FileV(uBase, u16, pszFormat, va); 347 } 348 349 350 RTDECL(int) RTLinuxSysFsWriteU16File(unsigned uBase, uint16_t u16, const char *pszFormat, ...) 351 { 352 va_list va; 353 va_start(va, pszFormat); 354 int rc = RTLinuxSysFsWriteU64FileV(uBase, u16, pszFormat, va); 355 va_end(va); 356 return rc; 357 } 358 359 360 RTDECL(int) RTLinuxSysFsWriteU32FileV(unsigned uBase, uint32_t u32, const char *pszFormat, va_list va) 361 { 362 return RTLinuxSysFsWriteU64FileV(uBase, u32, pszFormat, va); 363 } 364 365 366 RTDECL(int) RTLinuxSysFsWriteU32File(unsigned uBase, uint32_t u32, const char *pszFormat, ...) 367 { 368 va_list va; 369 va_start(va, pszFormat); 370 int rc = RTLinuxSysFsWriteU64FileV(uBase, u32, pszFormat, va); 371 va_end(va); 372 return rc; 373 } 374 375 376 RTDECL(int) RTLinuxSysFsWriteU64FileV(unsigned uBase, uint64_t u64, const char *pszFormat, va_list va) 377 { 378 RTFILE hFile; 379 380 const char *pszFmt = NULL; 381 switch (uBase) 382 { 383 case 8: 384 pszFmt = "%#llo"; 385 break; 386 case 10: 387 pszFmt = "%llu"; 388 break; 389 case 16: 390 pszFmt = "%#llx"; 391 break; 392 default: 393 return VERR_INVALID_PARAMETER; 394 } 395 396 int rc = RTLinuxSysFsOpenV(&hFile, pszFormat, va); 397 if (RT_SUCCESS(rc)) 398 { 399 char szNum[128]; 400 size_t cchNum = RTStrPrintf(szNum, sizeof(szNum), pszFmt, u64); 401 if (cchNum > 0) 402 { 403 size_t cbWritten = 0; 404 rc = RTLinuxSysFsWriteStr(hFile, &szNum[0], cchNum, &cbWritten); 405 if ( RT_SUCCESS(rc) 406 && cbWritten != cchNum) 407 rc = VERR_BUFFER_OVERFLOW; 408 } 409 else 410 rc = VERR_INVALID_PARAMETER; 411 412 RTFileClose(hFile); 413 } 414 415 return rc; 416 } 417 418 419 RTDECL(int) RTLinuxSysFsWriteU64File(unsigned uBase, uint32_t u64, const char *pszFormat, ...) 420 { 421 va_list va; 422 va_start(va, pszFormat); 423 int rc = RTLinuxSysFsWriteU64FileV(uBase, u64, pszFormat, va); 286 424 va_end(va); 287 425 return rc;
Note:
See TracChangeset
for help on using the changeset viewer.

