VirtualBox

Changeset 8913 in vbox for trunk/src


Ignore:
Timestamp:
May 19, 2008 11:34:46 AM (17 years ago)
Author:
vboxsync
Message:

made RTFileGetMaxSizeEx() OS-specific

Location:
trunk/src/VBox/Runtime/r3
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Runtime/r3/fileio.cpp

    r8245 r8913  
    239239    int rc = RTFileGetMaxSizeEx(File, &cbMax);
    240240    return RT_SUCCESS(rc) ? cbMax : -1;
    241 }
    242 
    243 
    244 /**
    245  * Determine the maximum file size.
    246  *
    247  * @returns IPRT status code.
    248  * @param   File        Handle to the file.
    249  * @param   pcbMax      Where to store the max file size.
    250  * @see     RTFileGetMaxSize.
    251  */
    252 RTR3DECL(int) RTFileGetMaxSizeEx(RTFILE File, PRTFOFF pcbMax)
    253 {
    254     /*
    255      * Save the current location
    256      */
    257     uint64_t offOld;
    258     int rc = RTFileSeek(File, 0, RTFILE_SEEK_CURRENT, &offOld);
    259     if (RT_FAILURE(rc))
    260         return rc;
    261 
    262     /*
    263      * Perform a binary search for the max file size.
    264      */
    265     uint64_t offLow  =       0;
    266     uint64_t offHigh = 8 * _1T; /* we don't need bigger files */
    267     /** @todo r=bird: This isn't doing the trick for windows (at least not vista).
    268      * Close to offHigh is returned regardless of NTFS or FAT32.
    269      * We might have to make this code OS specific...
    270      * In the worse case, we'll have to try GetVolumeInformationByHandle on vista and fall
    271      * back on NtQueryVolumeInformationFile(,,,, FileFsAttributeInformation) else where, and
    272      * check for known file system names. (For LAN shares we'll have to figure out the remote
    273      * file system.) */
    274     //uint64_t offHigh = INT64_MAX;
    275     for (;;)
    276     {
    277         uint64_t cbInterval = (offHigh - offLow) >> 1;
    278         if (cbInterval == 0)
    279         {
    280             if (pcbMax)
    281                 *pcbMax = offLow;
    282             return RTFileSeek(File, offOld, RTFILE_SEEK_BEGIN, NULL);
    283         }
    284 
    285         rc = RTFileSeek(File, offLow + cbInterval, RTFILE_SEEK_BEGIN, NULL);
    286         if (RT_FAILURE(rc))
    287             offHigh = offLow + cbInterval;
    288         else
    289             offLow  = offLow + cbInterval;
    290     }
    291241}
    292242
  • trunk/src/VBox/Runtime/r3/posix/fileio-posix.cpp

    r8561 r8913  
    393393
    394394
     395/**
     396 * Determine the maximum file size.
     397 *
     398 * @returns IPRT status code.
     399 * @param   File        Handle to the file.
     400 * @param   pcbMax      Where to store the max file size.
     401 * @see     RTFileGetMaxSize.
     402 */
     403RTR3DECL(int) RTFileGetMaxSizeEx(RTFILE File, PRTFOFF pcbMax)
     404{
     405    /*
     406     * Save the current location
     407     */
     408    uint64_t offOld;
     409    int rc = RTFileSeek(File, 0, RTFILE_SEEK_CURRENT, &offOld);
     410    if (RT_FAILURE(rc))
     411        return rc;
     412
     413    /*
     414     * Perform a binary search for the max file size.
     415     */
     416    uint64_t offLow  =       0;
     417    uint64_t offHigh = 8 * _1T; /* we don't need bigger files */
     418    /** @todo Unfortunately this does not work for certain file system types,
     419     * for instance cifs mounts. Even worse, statvfs.f_fsid returns 0 for such
     420     * file systems. */
     421    //uint64_t offHigh = INT64_MAX;
     422    for (;;)
     423    {
     424        uint64_t cbInterval = (offHigh - offLow) >> 1;
     425        if (cbInterval == 0)
     426        {
     427            if (pcbMax)
     428                *pcbMax = offLow;
     429            return RTFileSeek(File, offOld, RTFILE_SEEK_BEGIN, NULL);
     430        }
     431
     432        rc = RTFileSeek(File, offLow + cbInterval, RTFILE_SEEK_BEGIN, NULL);
     433        if (RT_FAILURE(rc))
     434            offHigh = offLow + cbInterval;
     435        else
     436            offLow  = offLow + cbInterval;
     437    }
     438}
     439
     440
    395441RTR3DECL(bool) RTFileIsValid(RTFILE File)
    396442{
  • trunk/src/VBox/Runtime/r3/win/fileio-win.cpp

    r8560 r8913  
    496496
    497497
     498RTR3DECL(int) RTFileGetMaxSizeEx(RTFILE File, PRTFOFF pcbMax)
     499{
     500    /** @todo r=bird:
     501     * We might have to make this code OS specific...
     502     * In the worse case, we'll have to try GetVolumeInformationByHandle on vista and fall
     503     * back on NtQueryVolumeInformationFile(,,,, FileFsAttributeInformation) else where, and
     504     * check for known file system names. (For LAN shares we'll have to figure out the remote
     505     * file system.) */
     506    return VERR_NOT_IMPLEMENTED;
     507}
     508
     509
    498510RTR3DECL(bool) RTFileIsValid(RTFILE File)
    499511{
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