Thursday, February 16, 2006

FAT versions

FAT12, FAT16 and FAT32 are all different versions of the FAT file system. As far as I know, the FAT was originally designed to work on floppy disks, on which it does a decent job. Soon after, it was adapted to work on hard disks (bigger capacity) and hence FAT16 was born. Much later, and due to the introduction of bigger disks — which means something over 500MB — FAT32 was created.

In order to understand what the number attached to the name means, we first need to outline how FAT internally works. FAT divides the disk area targetted to user data into clusters; you can imagine this area as a linear succession of sectors. A cluster is then defined as the agrupation of a set of consecutive sectors and is the minimum addressable block by FAT.

Each of these cluster is identified by a number; let's call this number the CID (Cluster IDentifier) for the scope of this post. This obviously drives us to the question: how big can the CID be? Well, it depends on the FAT version. This is exactly what the number after the name specifies: the number of bits reserved to address the CIDs.

If we do some numbers, FAT12 can have a maximum of 212 = 4096 clusters, more than enough for a floppy disk in which a cluster is a single sector. Now consider a 100MB disk; if we used FAT12 on such a disk, each cluster could be 100MB/4096 = 25KB long approximately, which introduces a lot of fragmentation for small files (think about the average file size when 100MB disks were considered big). But not only that: 12 bits, or 3 bytes, is an odd number to do arithmetic manipulations in a 16-bit computer (the 8086), introducing a computation penalty on every I/O operation. Hence, FAT16 was born, providing 16 bits to addess CIDs.

The birth of FAT32 is similar to the FAT16's one. With bigger disks appearing between 1995 and 2000, 216 = 65536 clusters were not enough to address them in a fine-grained fashion: few clusters introduced way too much fragmentation. For example, a 4GB disk could gave 4GB/65536 = 64KB long clusters, a number that drives to a lot of wasted space. FAT32 was therefore created, which increasing the CID address space to 32 bits. FAT32 also introduced some improvements to the file system such as the ability to place the FATs and the root directory anywhere on the file system (not restricted to the beginning).

To sum it up, there is the Long File Name (LFN) extension. This was introduced with Windows 95 and extends the traditional FAT file system so as to allow 255-character long file names preserving the compatibility with the 8.3 naming scheme.

For more information check out the Wikipedia's FAT article.