I need to find the cluster size of the users hard drive, through C or C++. The hard drive uses NTFS (though I'd appreciate knowing how it's done on other file systems as well).
I guess what I need is some combination of win32 API calls, but I don't know which.
For instance, typing "fsutil fsinfo ntfsinfo c:" in the windows console gives you "Bytes per cluster", which is what I need. (Though for obvious reasons, I don't want to run that command and parse it's output.)
To calculate the cluster size, simply take the size of the partition and divide it among the number of available clusters. For example, the maximum size of a FAT16 partition is 2 GB.
Cluster size represents the smallest amount of disk space that can be used to hold a file. When file sizes do not come out to an even multiple of the cluster size, additional space must be used to hold the file (up to the next multiple of the cluster size).
Use the GetDiskFreeSpace
BOOL WINAPI GetDiskFreeSpace(
__in LPCTSTR lpRootPathName,
__out LPDWORD lpSectorsPerCluster, // <--
__out LPDWORD lpBytesPerSector, // <--
__out LPDWORD lpNumberOfFreeClusters,
__out LPDWORD lpTotalNumberOfClusters
);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With