Cluster size vs Sector size

Programming, for all ages and all languages.
Post Reply
User avatar
siavoshkc
Member
Member
Posts: 40
Joined: Wed Feb 19, 2014 11:10 am

Cluster size vs Sector size

Post by siavoshkc »

I have a confusion on this matter. I read about how FAT16 works and took me 6 hours to understand its working. But I don't know that why we have a sector size and cluster size at the same time? Is it because sector size has to do with hard disk physical property? The unit that FAT16 actually uses is cluster, instead of saving sector per cluster in boot sector, it could save bytes per cluster. This way the HDD geometry could be totally separated from the required data for using it.
Check out my FSB Data Integrity Tester at http://fsbdit.sourceforge.net/.

Siavosh
nullplan
Member
Member
Posts: 1766
Joined: Wed Aug 30, 2017 8:24 am

Re: Cluster size vs Sector size

Post by nullplan »

Sector size is what the drive says it is. Usually 512 bytes, but with more modern AHCI drives, it might also be 4096 bytes. It is not so much a physical property as one of the protocol the drive speaks.

Cluster size is an integer shift of sector size. You usually want to minimize it to minimize fragmentation, but the smaller the cluster size, the more clusters have to be managed, obviously. And for each FAT type there is a maximum number of clusters that can be supported. Also, the smaller the clusters, the more often writing a file has to allocate a new one, which takes time and might introduce internal fragmentation, so it is a bit of a tradeoff.

Saving "bytes per cluster" instead of "sectors per cluster" would in theory uncouple disk geometry from the FS, but for one, sector size has been 512 bytes on many types of drive (so there would be no point), and for two, it is unlikely anyone would ever transfer an FAT image onto a hard disk using large sector sizes.
Carpe diem!
Post Reply