Thursday, 14 April 2016

Initial FAT16

In 1984 IBM released the PC AT, which featured a 20 MB hard disk. Microsoft introduced
MS-DOS 3.0 in parallel. Cluster addresses were increased to 16-bit, allowing for a greater number
of clusters (up to 65,517) and consequently much greater filesystem sizes. However, the maximum
possible number of sectors and the maximum (partition, rather than disk) size of 32 MB did not
change. Therefore, although technically already "FAT16", this format was not yet what today is
commonly understood under this name. A 20 MB hard disk formatted under MS-DOS 3.0, was not
accessible by the older MS-DOS 2.0. Of course, MS-DOS 3.0 could still access MS-DOS 2.0 style
8 KB cluster partitions.

MS-DOS 3.0 also introduced support for high-density 1.2 MB 5.25" diskettes, which
notably had 15 sectors per track, hence more space for FAT. This probably prompted a dubious
optimization of the cluster size, which went down from 2 sectors to just 1. The net effect was that
high density diskettes were significantly slower than older double density ones.

Extended partition and logical drives

Apart from improving the structure of the FAT filesystem itself, a parallel development
allowing an increase in the maximum possible FAT storage space was the introduction of disk
partitions. PC hard disks can only have up to 4 primary partitions, due to the fixed structure of the
partition table in the master boot record (MBR). However, by design choice DOS would only use
the partition marked as active, which was also the one the MBR would boot. It was not possible to
create multiple primary DOS partitions using DOS tools, and third party tools would warn that such
a scheme would not be compatible with DOS.

To allow the use of more partitions in a compatible way a new partition type was introduced (in
MS-DOS 3.2, January 1986), the extended partition, which was actually just a container for
additional partitions called logical drives. Originally only 1 logical drive was possible, allowing the
use of hard-disks up to 64 MB. In MS-DOS 3.3 (August 1987) this limit was increased to 24 drives;
it probably came from the compulsory letter-based C: - Z: disk naming. The logical drives were
described by on-disk structures which closely resemble MBRs, probably to simplify coding, and
they were chained/nested in a way analogous to Russian matryoshka dolls. Only one extended
partition was allowed.

Prior to the introduction of extended partitions, some hard disk controllers (which at that
time were separate option boards, since the IDE standard did not yet exist) could make large hard
disks appear as two separate disks. Alternatively, special software drivers, like Ontrack's Disk
Manager could be installed for the same purpose.

Final FAT16

Finally in November 1987, in Compaq DOS 3.31, came what is today called the FAT16
format, with the expansion of the 16-bit disk sector index to 32 bits. The result was initially called
the DOS 3.31 Large File System. Although the on-disk changes were apparently minor, the entire
DOS disk code had to be converted to use 32-bit sector numbers, a task complicated by the fact that
it was written in 16-bit assembly language.

In 1988 the improvement became more generally available through MS-DOS 4.0. The limit
on partition size was now dictated by the 8-bit signed count of sectors-per-cluster, which had a
maximum power-of-two value of 64. With the usual hard disk sector size of 512 bytes, this gives 32
KB clusters, hence fixing the "definitive" limit for the FAT16 partition size at 2 gigabytes. On
magneto-optical media, which can have 1 or 2 KB sectors, the limit is proportionally greater.
Much later, Windows NT increased the maximum cluster size to 64 KB by considering the sectorsper-cluster count as unsigned. However, the resulting format was not compatible with any other FAT implementation of the time, and anyway, generated massive internal fragmentation. Windows 98 also supported reading and writing this variant, but its disk utilities didn't work with it.

Long File Names (VFAT, LFNs)

One of the "user experience" goals for the designers of Windows 95 was the ability to use
long file names (LFNs), in addition to classic 8.3 names. LFNs were implemented using a workaround in the way directory entries are laid out (see below). The version of the file system with this extension is usually known as VFAT after the Windows 95 VxD device driver.

Interestingly, the VFAT driver actually appeared before Windows 95, in Windows for
Workgroups 3.11, but was only used for implementing 32-bit File Access, a higher performance
protected mode file access method, bypassing DOS and directly using either the BIOS, or, better,
the Windows-native protected mode disk drivers. It was a backport; Microsoft's ads for WfW 3.11
said 32-bit File Access was based on "the 32-bit file system from our Chicago project".

In Windows NT, support for long file names on FAT started from version 3.5.

FAT32

In order to overcome the volume size limit of FAT16, while still allowing DOS real-mode
code to handle the format without unnecessarily reducing the available conventional memory,
Microsoft decided to implement a newer generation of FAT, known as FAT32, with cluster counts
held in a 32-bit field, of which 28 bits are currently used.

In theory, this should support a total of approximately 268,435,438 (< 228) clusters, allowing
for drive sizes in the range of 2 terabytes. However, due to limitations in Microsoft's scandisk
utility, the FAT is not allowed to grow beyond 4,177,920 (< 222) clusters, placing the volume limit
at 124.55 gigabytes, unless "scandisk" is not needed.

FAT32 was introduced with Windows 95 OSR2, although reformatting was needed to use it,
and DriveSpace 3 (the version that came with Windows 95 OSR2 and Windows 98) never
supported it. Windows 98 introduced a utility to convert existing hard disks from FAT16 to FAT32
without loss of data. In the NT line, support for FAT32 arrived in Windows 2000.

Windows 2000 and Windows XP can read and write to FAT32 filesystems of any size, but
the format program on these platforms can only create FAT32 filesystems up to 32 GB. Thompson
and Thompson (2003) write[4] that "Bizarrely, Microsoft states that this behavior is by design."
Microsoft's knowledge base article 184006[3] indeed confirms the limitation and the by design
statement, but gives no rationale or explanation. Peter Norton's opinion[5] is that "Microsoft has
intentionally crippled the FAT32 file system."

The maximum possible size for a file on a FAT32 volume is 4 GiB minus 1 B (232-1 bytes).
For most users, this has become the most nagging limit of FAT32 as of 2005, since video capture
and editing applications can easily exceed this limit, as can the system swap file.

Third party support

The alternative IBM PC operating systems — such as Linux, FreeBSD, and BeOS — have
all supported FAT, and most added support for VFAT and FAT32 shortly after the corresponding
Windows versions were released. Early Linux distributions also supported a format known as
UMSDOS, which was FAT with Unix file attributes (such as long file name and access
permissions) stored in a separate file called --linux-.---. UMSDOS fell into disuse after VFAT was
released and is not enabled by default in Linux kernels from version 2.5.7 onwards [5]. The Mac OS
X operating system also supports the FAT filesystems on volumes other than the boot disk.

FAT and Alternate Data Streams

The FAT filesystem itself is not designed for supporting ADS, but some operating systems
that heavily depend on them have devised various methods for handling them in FAT drives. Such
methods either store the additional information in extra files and directories (Mac OS), or give new
semantics to previously unused fields of the FAT on-disk data structures (OS/2 and Windows NT).
The second design, while presumably more efficient, prevents any copying or backing-up of those
volumes using non-aware tools; manipulating such volumes using non-aware disk utilities (e.g.
defragmenters or CHKDSK) will probably lose the information.

Mac OS using PC Exchange stores its various dates, file attributes and long filenames in a
hidden file called FINDER.DAT, and Resource Forks (a common Mac OS ADS) in a subdirectory
called RESOURCE.FRK, in every directory where they are used. From PC Exchange 2.1 onwards,
they store the Mac OS long filenames as standard FAT long filenames and convert FAT filenames
longer than 31 characters to unique 31-character filenames, which can then be made visible to
Macintosh applications.

Mac OS X stores metadata (Resource Forks, file attributes, other ADS) in a hidden file with
a name constructed from the owner filename prefixed with "._", and Finder stores some folder and
file metadata in a hidden file called ".DS_Store".

OS/2 heavily depends on extended attributes (EAs) and stores them in a hidden file called
"EA DATA. SF" in the root directory of the FAT12 or FAT16 volume. This file is indexed by 2
previously reserved bytes in the file's (or directory's) directory entry. In the FAT32 format, these
bytes hold the upper 16 bits of the starting cluster number of the file or directory, hence making it
difficult to store EAs on FAT32. Extended attributes are accessible via the Workplace Shell
desktop, through REXX scripts, and many system GUI and command-line utilities (such as 4OS2).
Windows NT supports the handling of extended attributes in HPFS, NTFS, and FAT. It stores EAs
on FAT using exactly the same scheme as OS/2, but does not support any other kind of ADS as
held on NTFS volumes. Trying to copy a file with any ADS other than EAs from an NTFS volume
to a FAT volume gives a warning message with the names of the ADSs that will be lost.

Windows 2000 onward acts exactly as Windows NT, except that it ignores EAs when
copying to FAT32 without any warning (but shows the warning for other ADSs, like "Macintosh
Finder Info" and "Macintosh Resource Fork").

Future

Microsoft has recently secured patents for VFAT and FAT32 (but not the original FAT),
which is causing concern that the company might later seek royalties from Linux distros and from
media vendors that pre-format their products (see FAT Licensing below). Despite two earlier
rulings against them, Microsoft prevailed and was awarded the patents.

Since Microsoft has announced the discontinuation of its MS-DOS-based consumer
operating systems with Windows Me, it remains unlikely that any new versions of FAT will appear.
For most purposes, the NTFS file system that was developed for the Windows NT line is superior to
FAT from the points of view of efficiency, performance and reliability; its main drawbacks are the
size overhead for small volumes and the very limited support by anything other than the NT-based
versions of Windows, since the exact specification is a trade secret of Microsoft, which in turn
makes it difficult to use a DOS floppy for recovery purposes. Microsoft provided a recovery
console to work around this issue, but for security reasons it severely limited what could be done
through the Recovery Console by default.

FAT is still the normal filesystem for removable media (with the exception of CDs and
DVDs), with FAT12 used on floppies, and FAT16 on most other removable media (such as flash
memory cards for digital cameras and USB flash drives). Most removable media is not yet large
enough to benefit from FAT32, although some larger flash drives do make use of it. FAT is used on
these drives for reasons of compatibility and size overhead, as well as the fact that file permissions
on removable media are likely to be more trouble than they are worth.

The FAT32 formatting support in Windows 2000 and XP is limited to drives of 32
gigabytes, which effectively forces users of modern hard drives either to use NTFS or to format the
drive using third party tools such as a port of mkdosfs or fat32format.

Main disk structures

Master
Boot
Record
File
Allocation
Table #1
File
Allocation
Table #2
Root
Directory
All Other Data ... The Rest of the Disk

A FAT file system is composed of four different sections.

1. The Reserved sectors, located at the very beginning. The first reserved sector is the Boot
Sector (aka Partition Boot Record). It includes an area called the BIOS Parameter Block (with some
basic file system information, in particular its type, and pointers to the location of the other
sections) and usually contains the operating system's boot loader code. The total count of reserved
sectors is indicated by a field inside the Boot Sector. Important information from the Boot Sector is
accessible through an operating system structure called the Drive Parameter Block in DOS and
OS/2.

2. The FAT Region. This contains two copies of the File Allocation Table for the sake of
redundancy, although the extra copy is rarely used, even by disk repair utilities. These are maps of
the partition, indicating how the clusters are allocated.

3. The Root Directory Region. This is a Directory Table that stores information about the
files and directories in the root directory. With FAT32 it can be stored anywhere in the partition,
however with earlier versions it is always located immediately after the FAT Region.

4. The Data Region. This is where the actual file and directory data is stored and takes up
most of the partition. The size of files and subdirectories can be increased arbitrarily (as long as
there are free clusters) by simply adding more links to the file's chain in the FAT. Note however,
that each cluster can be taken only by one file, and so if a 1 KB file resides in a 32 KB cluster, 31
KB are wasted.

Boot Sector
The Boot Sector is of the following format:
Byte
Offset
Length
(bytes)
Description
0x00 3 Jump instruction (to skip over header on boot)
0x03 8
OEM Name (padded with spaces). MS-DOS checks this field to determine
which other parts of the boot record can be relied on [6] [7]. Common values
are IBM 3.3 (with two spaces between the "IBM" and the "3.3") and MSDOS5.0.
0x0b 2 Bytes per sector. The BIOS Parameter Block starts here.
0x0d 1 Sectors per cluster
0x0e 2 Reserved sector count (including boot sector)
0x10 1 Number of file allocation tables
0x11 2 Maximum number of root directory entries
0x13 2 Total sectors (if zero, use 4 byte value at offset 0x20)
0x15 1
Media descriptor
0xF8 Single sided, 80 tracks per side, 9 sectors per track
0xF9 Double sided, 80 tracks per side, 9 sectors per track
0xFA Single sided, 80 tracks per side, 8 sectors per track
0xFB Double sided, 80 tracks per side, 8 sectors per track
0xFC Single sided, 40 tracks per side, 9 sectors per track
0xFD Double sided, 40 tracks per side, 9 sectors per track
0xFE Single sided, 40 tracks per side, 8 sectors per track
0xFF Double sided, 40 tracks per side, 8 sectors per track
Same value of media descriptor should be repeated as first byte of each copy of
FAT. Certain operating systems (MSX-DOS version 1.0) ignore boot sector
parameters altogether and use media descriptor value from the first byte of FAT
to determine filesystem parameters.
0x16 2 Sectors per file allocation table (FAT16)
0x18 2 Sectors per track
0x1a 2 Number of heads
0x1c 4 Hidden sectors
0x20 4 Total sectors (if greater than 65535; see offset 0x13)
0x24 4
Sectors per file allocation table (FAT32). The Extended BIOS Parameter Block
starts here.
0x24 1 Physical drive number (FAT16)
0x25 1 Current head (FAT16)
0x26 1 Signature (FAT16)
0x27 4 ID (FAT16)
0x2b 11 Volume Label
0x36 8 FAT file system type (e.g. FAT, FAT12, FAT16, FAT32)
0x3e 448 Operating system boot code
0x1FE 2 End of sector marker (0x55 0xAA)

The boot sector is portrayed here as found on e.g. an OS/2 1.3 boot diskette. Earlier versions used a
shorter BIOS Parameter Block and their boot code would start earlier (for example at offset 0x2b in
OS/2 1.1).

Exceptions

The implementation of FAT used in MS-DOS for the Apricot PC had a different boot sector
layout, to accommodate that computer's non-IBM compatible BIOS. The jump instruction and
OEM name were omitted, and the MS-DOS filesystem parameters (offsets 0x0B - 0x17 in the
standard sector) were located at offset 0x50. Later versions of Apricot MS-DOS gained the ability
to read and write disks with the standard boot sector in addition to those with the Apricot one.

DOS Plus on the BBC Master 512 did not use conventional boot sectors at all. Data disks
omitted the boot sector and began with a single copy of the FAT (the first byte of the FAT was used
to determine disk capacity) while boot disks began with a miniature ADFS filesystem containing
the boot loader, followed by a single FAT. It could also access standard PC disks formatted to 180
KB or 360 KB, again using the first byte of the FAT to determine capacity.

No comments:

Post a Comment

Popular Posts