First post, by chartreuse
Like many other people I've been finding myself annoyed at the 15-30s delay on XT class machines to calculate free disk space on drives >32MB using FAT16 (32k to 64k total clusters). After only finding somewhat janky solutions such as caching the value on shutdown to disk. I decided to tackle the problem myself.
Having heard that the DOS calculation is inefficient due to doing smaller reads and possibly even traversing the file and directory structures as part of its check, I set out to try just calculating the free space my self from the FAT. My approach was simple, load the FAT into RAM and count the number of in-use clusters and subtract that from the total clusters on disk, then populate that back into the Drive Parameter Block field.
I wasn't certain at first if this method would be faster or not, but after getting to the point of scanning the entire fat and counting up the clusters I found that it was a significant improvement over DOS's calculation. On my 8MHz Turbo XT my program was calculating and populating the free cluster count in approximately 1 second, vs 14 seconds for DIR to calculate it. And at 4.77MHz the calculation was performed in under 2 seconds compared with 25s.
The program can be placed into autoexec.bat to pre-populate the free space for any desired disks on the system.
The drive being run on must by FAT16, and have 512 bytes per sector (basically all hard drives will meet this).
If a program is run which performs raw disk access (int 25h/26h) such as CHKDSK the value cached by DOS is invalidated (set to FFFF) which means the calculation needs to be performed again. As this program is not a TSR (Yet! I'm working on that) the next time the disk free space is calculated will be done by DOS's slow method, you can manually run FREESP again if you like but running these programs is less common.
This program requires DOS 4 or greater, and has been tested on 5.0 and 6.22, which is where you'd run into this delay in the first place. I've not been able to find documentation on how Compaq DOS 3.31 handles the int 25h system call or how it's DPB is laid out so I'm unable to confirm how this works using it's limited FAT16 large disk support.
The disk space calculation returned by this in my testing always matches that done by DOS itself, but if there's some odd edge case you encounter let me know and I can try to fix it.
The program is available at https://github.com/ChartreuseK/FREESP in both source code and binary form. You can find the assembled COM file under the Releases section, or you can assemble the source with Borland TASM 2.0 or later.
This will pre-calculate free space on the C partition. The drive letter is required, if you want to pre-calculate multiple partitions run the program multiple times in your autoexec.bat