how to calculate correctly the cluster size

Josiah Carlson jcarlson at uci.edu
Mon Apr 19 02:19:46 EDT 2004


> I am trying to find a way to calculate the cluster size for a drive. I
> looked at the GetDiskFreeSpaceEx function in Win32 and it turned out
> that it didn't provide the information I was looking for.
> Using the old GetDiskFreeSpace function I could just multiply the
> Bytes per
> Sector by the Sector per Cluster and get the cluster size.  I heard
> that the old GetDiskFreeSpace function may report not proper values
> for volume sizes that are greater than 2 gigabytes. The new version of
> that function (GetDiskFreeSpaceEx) returns the final disk free size
> without the ability to calculate the cluster size - and the old
> version does not work correctly with FAT 32... what can I do? Is there
> another function I can use?

Generally, I believe sectors are consistantly 512 bytes, and depending 
on the format of your drive, cluster size can vary.  Both NTFS and FAT32 
generally run with 4k clusters, and at least until mid-2002, there 
didn't exist a commercial defragmenter that could handle non-4k clusters 
in Windows (I had a drive with 16k clusters that I needed to repartition 
in order to fix that, thank god for partitionmagic).  I don't think you 
would be out of line to assume 4k clusters on installations using FAT32 
or NTFS.

In terms of volume sizes > 2 gigs, that sounds like the old cluster size 
and addressing limit for FAT 16, but considering how rare FAT 16 is 
nowadays (perhaps pre Win95 OSR2 installations still use it), I wouldn't 
worry too much (unless you are specifically writing for old operating 
systems).

  - Josiah



More information about the Python-list mailing list