VirtualBox

Changeset 6421 in vbox


Ignore:
Timestamp:
Jan 21, 2008 5:48:46 PM (17 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
27387
Message:

iprt: added RTFileGetMaxSize()

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • 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 */
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