Technical information
© Jean Louis-Guérin – V1.2a – September 2014 Page 47 / 69
9.5.2 TOS File Allocation Table
The File Allocation Table structures (FAT) is an array used by the TOS to keep track of which clusters
on a drive have been allocated for each file or directory. As a program creates a new file or adds to an
existing one, the system allocates sectors for that file, writes the data to the given sectors, and keeps
track of the allocated sectors by recording them in the FAT. To conserve space and speed up record-
keeping, each record in the FAT corresponds to two or more consecutive sectors (called a cluster).
The number of sectors in a cluster depends on the type and capacity of the drive but is always a
power of 2 (the only value supported by GEMDOS is 2). Every logical drive has at least one FAT, and
most drives have two, one serving as a backup should the other fail. The FAT immediately follows the
Boot Sector and any other reserved sectors.
Depending on the number of clusters on the drive, the FAT consists of an array of either 12-bit or 16-
bit entries. Drives with more than 4086 clusters have a 16-bit FAT; those with 4086 or fewer clusters
have a 12-bit FAT (typically only used by Floppy disks).
The first two entries in a FAT are reserved. In most cases the first byte contains the media descriptor
(usually $F8) and the additional reserved bytes are set to $FF. Each FAT entry represents a
corresponding cluster on the drive. If the cluster is part of a file or directory, the entry contains either a
marker specifying the cluster as an index pointing to the next cluster in the file or directory, or the last
in that file or directory. If a cluster is not part of a file or directory, the entry contains a value indicating
the cluster's status. The SCLUSTER field in the Root Directory corresponding to the file or directory
specifies the index of the first FAT entry for the file or directory.
The following table shows possible FAT entry values:
FAT12 Value
FAT16 Value
Meaning
$000
$0000
Available cluster.
$002-$FEF
$0002-$FFEF
Index of entry for the next cluster in the file or directory. Note that $001 does not
appear in a FAT, since that value corresponds to the FAT's second reserved
entry. Index numbering is based on the beginning of the FAT
$FF0-$FF6
$FFF0-$FFF6
Reserved
$FF7
$FFF7
Bad sector in cluster; do not use cluster.
$FF8-$FFF
$FFF8-$FFFF
Last cluster of file or directory. (usually the value $FFF is used)
For example, the following segment of a 12-bit FAT shows the FAT entries for a file consisting of four
clusters:
$000 $F8 $FF $FF (2 reserved entries)
$003 Cluster 2 points to cluster 3
$005 Cluster 3 points to cluster 5
$FF7 Cluster 4 contains a bad sector
$006 Cluster 5 points to cluster 6
$FFF Cluster 6 is the last cluster for the file
$000 Clusters 7 is available
...
Note: If a cluster contains $000 this does not mean that it is empty but that it is available. This is due
to the fact that when a file is deleted the data are not erased but only the first letter of the name of
the file in the directory structure is set to $E5 and all clusters used by the deleted file are set to $000.
9.5.3 TOS Root Directory
The TOS arranges and stores file-system contents in directories. Every file system has at least one
directory, called the Root Directory (also referred as the Catalog in Atari), and may have additional
directories either in the Root Directory or ordered hierarchically below it. The contents of each
directory are described in individual directory entries. The TOS strictly controls the format and content
of directories.
The Root Directory is always the topmost directory and it is created during initialization of a partition.
The Root Directory can hold information for only a fixed number of files or other directories, and the
number cannot be changed without reformatting the partition. A program can identify this limit by
examining the NDIRS field in the BPB structure described in the Boot Sector. This field specifies the
maximum number of root-directory entries for the partition.
A user or a program can add new directories within the current directory, or within other directories.
Unlike the Root Directory, the new directory is limited only by the amount of space available on the