ClusterBitmap Allocation

Jul 1, 2016 at 7:12 AM
Edited Jul 1, 2016 at 8:09 AM
Hello again,

I've run into an issue where when I'm writing to an NTFS file system I get an "Out of disk space" exception when there is still >10% left available on the disk. I think I've tracked it down to how clusters are allocated.

In ClusterBitmap.cs there are these lines starting at line 103:
if (numFound < count)
                {
                    numFound += FindClusters(count - numFound, result, totalClusters / 8, totalClusters, isMft, false, 0);
                }

                if (numFound < count)
                {
                    numFound = FindClusters(count - numFound, result, totalClusters / 16, totalClusters / 8, isMft, false, 0);
                }

                if (numFound < count)
                {
                    numFound = FindClusters(count - numFound, result, totalClusters / 32, totalClusters / 16, isMft, false, 0);
                }

                if (numFound < count)
                {
                    numFound = FindClusters(count - numFound, result, 0, totalClusters / 32, isMft, false, 0);
                }
From what I can tell this is intended to implement the buffer that Windows maintains around the MFT in order to try and prevent fragmentation (https://flatcap.org/linux-ntfs/ntfs/files/bitmap.html).

The first issue I think is that we are not incrementing the number of clusters found.

The second issue is that I think this is quite a naive implementation, just putting a buffer around the beginning of the volume and not taking into account where the MFT actually lives. I've had a play around and haven't managed to fix it yet. If I simply remove the buffer then I end up getting an error when I try to mount the disk, so I guess there must be something in that section of the drive that is not included in the bitmap for some reason?

Thanks.
Jul 1, 2016 at 9:19 AM
After futher investigation, it looks like simply removing the buffering does work. I was running into errors because I was genuinely writing too much data when you take into account the size of the MFT etc. It seems that if you completely fill up a disk then Windows won't mount it.

However, I would rather not just remove the buffer, so any ideas about how to better calculate where the buffer should be would be much appreciated.