Changeset 85492 in vbox for trunk/src/VBox/Runtime/r3/posix
- Timestamp:
- Jul 28, 2020 4:36:42 PM (5 years ago)
- svn:sync-xref-src-repo-rev:
- 139548
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Runtime/r3/posix/fileio-posix.cpp
r84506 r85492 756 756 return rc; 757 757 758 /*759 * Perform a binary search for the max file size.760 */761 758 uint64_t offLow = 0; 762 uint64_t offHigh = 8 * _1T; /* we don't need bigger files */759 uint64_t offHigh = INT64_MAX; /* we don't need bigger files */ 763 760 /** @todo Unfortunately this does not work for certain file system types, 764 761 * for instance cifs mounts. Even worse, statvfs.f_fsid returns 0 for such 765 762 * file systems. */ 766 //uint64_t offHigh = INT64_MAX; 767 for (;;) 768 { 769 uint64_t cbInterval = (offHigh - offLow) >> 1; 770 if (cbInterval == 0) 771 { 772 if (pcbMax) 773 *pcbMax = offLow; 774 return RTFileSeek(hFile, offOld, RTFILE_SEEK_BEGIN, NULL); 775 } 776 777 rc = RTFileSeek(hFile, offLow + cbInterval, RTFILE_SEEK_BEGIN, NULL); 763 764 /* 765 * Quickly guess the order of magnitude for offHigh and offLow. 766 */ 767 { 768 uint64_t offHighPrev = offHigh; 769 while (offHigh >= INT32_MAX) 770 { 771 rc = RTFileSeek(hFile, offHigh, RTFILE_SEEK_BEGIN, NULL); 772 if (RT_SUCCESS(rc)) 773 { 774 offLow = offHigh; 775 offHigh = offHighPrev; 776 break; 777 } 778 else 779 { 780 offHighPrev = offHigh; 781 offHigh >>= 8; 782 } 783 } 784 } 785 786 /* 787 * Sanity: if the seek to the initial offHigh (INT64_MAX) works, then 788 * this algorithm cannot possibly work. Declare defeat. 789 */ 790 if (offLow == offHigh) 791 return VERR_NOT_SUPPORTED; 792 793 /* 794 * Perform a binary search for the max file size. 795 */ 796 while (offLow <= offHigh) 797 { 798 uint64_t offMid = offLow + (offHigh - offLow) / 2; 799 rc = RTFileSeek(hFile, offMid, RTFILE_SEEK_BEGIN, NULL); 778 800 if (RT_FAILURE(rc)) 779 offHigh = off Low + cbInterval;801 offHigh = offMid - 1; 780 802 else 781 offLow = offLow + cbInterval; 782 } 803 offLow = offMid + 1; 804 } 805 806 if (pcbMax) 807 *pcbMax = RT_MIN(offLow, offHigh); 808 return RTFileSeek(hFile, offOld, RTFILE_SEEK_BEGIN, NULL); 783 809 } 784 810
Note:
See TracChangeset
for help on using the changeset viewer.