title: Why is calculated Free & Total drive space capping out at 2G?
body: <p>I wrote a directory information utility and (because I, and the people I wrote this for collect &amp; use vintage hardware,) made it compatible with DOS and Windows 9x as well as Windows XP/Vista/7/8 64-bit (because we also use those.)  The problem I'm running into is that in Windows 9x it's reporting available drive space and total drive space as 2G (well 1.9997 G) even on larger drives.  On Windows XP and beyond (32-bit or 64-bit,) it reports the drive sizes correctly.  In DOS, of course, this isn't an issue as the maximum size in DOS is 2G already.</p>
  
  <p>The code I'm using is (DInfo.Path is the directory being accessed, with [0] being the drive letter - A, B, C, etc...):</p>
  
  <pre><code>_dos_getdiskfree(DInfo.Path[0] - 'A' + 1, &amp;Free);
  
  BlockSize = Free.sectors_per_cluster * Free.bytes_per_sector;
  
  for (i = 0; i &lt; BlockSize; i++) {
      DriveBytes += Free.total_clusters;
      if (DriveBytes &lt; Free.total_clusters) ++DBOverflow;
      FreeBytes += Free.avail_clusters;
      if (FreeBytes &lt; Free.avail_clusters) ++FBOverflow;
  }
  </code></pre>
  
  <p>The only difference between the code in the DOS stub and the Windows portion of the executable is the _dos_getdiskfree is replaced with _getdiskfree instead.  I use unsigned __int32 variables in the above code (or unsigned long for the DOS code.)  I used 32 bit for compatibility and to reduce re-writing the code as much as possible when converting the DOS code to Windows code.  In Windows XP+ I could probably have simplified things by using __int64 variables, but again, I wasn't sure if Windows 9x would provide those or not.  I wasn't even sure if the 32-bit versions of Windows XP+ would allow it or not, and really didn't want to research it just streamline it a bit.  Even on older HW it works fast enough with the loop.</p>
  
  <p>With the Overflow &amp; Byte variables both 32 bit integers, the size should max out at 8 exabytes (kilobytes, megabytes, gigabytes, terabytes, petabytes, exabytes in case you were wondering,) and since the largest drives currently available are measured in single digit terabytes, that limit shouldn't cause a problem for a while.  At least it's doubtful to do so during my lifetime.</p>