Changeset 6429 in vbox for trunk/src/VBox/Runtime
- Timestamp:
- Jan 21, 2008 10:22:11 PM (17 years ago)
- Location:
- trunk/src/VBox/Runtime
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Runtime/r3/fileio.cpp
r6421 r6429 219 219 220 220 /** 221 * Determine the maximum file size. Tested on Windows and Linux. 222 */ 223 RTR3DECL(uint64_t) RTFileGetMaxSize(RTFILE File) 224 { 221 * Determine the maximum file size. 222 * 223 * @returns The max size of the file. 224 * -1 on failure, the file position is undefined. 225 * @param File Handle to the file. 226 * @see RTFileGetMaxSizeEx. 227 */ 228 RTR3DECL(RTFOFF) RTFileGetMaxSize(RTFILE File) 229 { 230 RTFOFF cbMax; 231 int rc = RTFileGetMaxSizeEx(File, &cbMax); 232 return RT_SUCCESS(rc) ? cbMax : -1; 233 } 234 235 236 /** 237 * Determine the maximum file size. 238 * 239 * @returns IPRT status code. 240 * @param File Handle to the file. 241 * @param pcbMax Where to store the max file size. 242 * @see RTFileGetMaxSize. 243 */ 244 RTR3DECL(int) RTFileGetMaxSizeEx(RTFILE File, PRTFOFF pcbMax) 245 { 246 /* 247 * Save the current location 248 */ 249 uint64_t offOld; 250 int rc = RTFileSeek(File, 0, RTFILE_SEEK_CURRENT, &offOld); 251 if (RT_FAILURE(rc)) 252 return rc; 253 254 /* 255 * Perform a binary search for the max file size. 256 */ 225 257 uint64_t offLow = 0; 226 258 uint64_t offHigh = 8 * _1T; /* we don't need bigger files */ 227 uint64_t offOld = RTFileTell(File); 228 259 /** @todo r=bird: This isn't doing the trick for windows (at least not vista). 260 * Close to offHigh is returned regardless of NTFS or FAT32. 261 * We might have to make this code OS specific... */ 262 //uint64_t offHigh = INT64_MAX; 229 263 for (;;) 230 264 { 231 uint64_t interval = (offHigh - offLow) >> 1;232 if ( interval == 0)265 uint64_t cbInterval = (offHigh - offLow) >> 1; 266 if (cbInterval == 0) 233 267 { 234 RTFileSeek(File, offOld, RTFILE_SEEK_BEGIN, NULL); 235 return offLow; 268 if (pcbMax) 269 *pcbMax = offLow; 270 return RTFileSeek(File, offOld, RTFILE_SEEK_BEGIN, NULL); 236 271 } 237 if (RT_FAILURE(RTFileSeek(File, offLow + interval, RTFILE_SEEK_BEGIN, NULL))) 238 offHigh = offLow + interval; 272 273 rc = RTFileSeek(File, offLow + cbInterval, RTFILE_SEEK_BEGIN, NULL); 274 if (RT_FAILURE(rc)) 275 offHigh = offLow + cbInterval; 239 276 else 240 offLow = offLow + interval;277 offLow = offLow + cbInterval; 241 278 } 242 279 } -
trunk/src/VBox/Runtime/testcase/tstFile.cpp
r6421 r6429 50 50 } 51 51 52 RTPrintf("Maximum file size is %lld bytes.\n", RTFileGetMaxSize(File)); 52 RTFOFF cbMax = -2; 53 rc = RTFileGetMaxSizeEx(File, &cbMax); 54 if (RT_FAILURE(rc)) 55 { 56 RTPrintf("tstFile: RTFileGetMaxSizeEx failed: %Rrc\n", rc); 57 cErrors++; 58 } 59 else if (cbMax <= 0) 60 { 61 RTPrintf("tstFile: RTFileGetMaxSizeEx failed: cbMax=%RTfoff\n", cbMax); 62 cErrors++; 63 } 64 else if (RTFileGetMaxSize(File) != cbMax) 65 { 66 RTPrintf("tstFile: RTFileGetMaxSize failed; returns %RTfoff instead of %RTfoff\n", RTFileGetMaxSize(File), cbMax); 67 cErrors++; 68 } 69 else 70 RTPrintf("Maximum file size is %RTfoff bytes.\n", cbMax); 71 72 return 0; 53 73 54 74 /* grow file beyond 2G */
Note:
See TracChangeset
for help on using the changeset viewer.