VirtualBox

Changeset 6421

Show
Ignore:
Timestamp:
01/21/08 18:48:46 (11 months ago)
Author:
vboxsync
Message:

iprt: added RTFileGetMaxSize()

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/include/iprt/file.h

    r5999 r6421  
    266266 
    267267/** 
     268 * Determine the maximum file size depending on the file system the file is stored on. 
     269 */ 
     270RTR3DECL(uint64_t) RTFileGetMaxSize(RTFILE File); 
     271 
     272/** 
    268273 * Gets the current file position. 
    269274 * 
  • trunk/src/VBox/Runtime/r3/fileio.cpp

    r5999 r6421  
    215215    AssertMsgFailed(("RTFileSeek(%d) -> %d\n", File, rc)); 
    216216    return ~0ULL; 
     217} 
     218 
     219 
     220/** 
     221 * Determine the maximum file size. Tested on Windows and Linux. 
     222 */ 
     223RTR3DECL(uint64_t)  RTFileGetMaxSize(RTFILE File) 
     224{ 
     225    uint64_t offLow  =       0; 
     226    uint64_t offHigh = 8 * _1T; /* we don't need bigger files */ 
     227    uint64_t offOld  = RTFileTell(File); 
     228 
     229    for (;;) 
     230    { 
     231        uint64_t interval = (offHigh - offLow) >> 1; 
     232        if (interval == 0) 
     233        { 
     234            RTFileSeek(File, offOld, RTFILE_SEEK_BEGIN, NULL); 
     235            return offLow; 
     236        } 
     237        if (RT_FAILURE(RTFileSeek(File, offLow + interval, RTFILE_SEEK_BEGIN, NULL))) 
     238            offHigh = offLow + interval; 
     239        else 
     240            offLow  = offLow + interval; 
     241    } 
    217242} 
    218243 
  • trunk/src/VBox/Runtime/testcase/tstFile.cpp

    r5999 r6421  
    4949        return 1; 
    5050    } 
     51 
     52    RTPrintf("Maximum file size is %lld bytes.\n", RTFileGetMaxSize(File)); 
    5153 
    5254    /* grow file beyond 2G */ 

© 2008 Sun Microsystems, Inc.
ContactPrivacy policy