Skip to content

The TOS file system

Andrew edited this page Nov 29, 2020 · 19 revisions

This is a collection of my observations about the TOS disk system while developing SerialDisk. There's a lot of unclear information out on the web, so this is my personal reference based on actual testing.

Having said that, the AHDI 3.00 Release Notes (April 18 1990) document by Atari Corporation is technically very (if not completely) accurate, and I recommend it as a reference when working with disks in TOS.

Partition types

This is not an exhaustive list, but is provided to demonstrate why 32MiB is the maximum virtual disk size without using additional drivers.

The partition type is set in the disk boot sector in the partition header.

Partition header 0 is a 12 byte structure located at offset 0x01C6.

Within the header, the three bytes at offset 0x01 determine the partition type:
'GEM' Regular Partition
'BGM' Big Partition
'XGM' Extended Partition

The number of sectors per cluster is always 2.

GEM

GEM is the default partition type and requires no additional drivers.

TOS version Supported sector sizes Maximum clusters Maximum disk size (bytes)
< 1.04 512 bytes ONLY 0x3FFF (14 bits) 16,776,192 bytes (approx 16MiB)
1.04+ 512 bytes ONLY 0x7FFF (15 bits) 33,553,408 bytes (approx 32MiB)

BGM

TOS version Supported sector sizes Maximum clusters Maximum disk size (bytes)
< 1.04 512 - 8192 bytes 0x3FFF (14 bits) 268,419,072 bytes (approx 256MiB)
1.04+ 512 - 8192 bytes 0x7FFF (15 bits) 536,854,528 bytes (approx 512MiB)

Why 15 bits?

For some reason, Atari decided to use a signed 16-bit integer for the number of clusters. If they had used an unsigned integer, 65,535 clusters would have been possible.

The BIOS Parameter Block

Offset Length (bytes) Value
0 2 Bytes per sector
2 2 Sectors per cluster
4 2 Bytes per cluster
6 2 Root Directory length
8 2 Length of the FAT in sectors
10 2 Start of the 2nd FAT
12 2 1st free sector
14 2 Total numbr of clusters
16 2 Flags as bit-vector

Flags:
Bit 0: 0 (12-Bit-FAT), 1 16-Bit-FAT
Bit 1: 0 (two FATs), 1 (one FAT)

Cluster values

Cluster values are slightly different to DOS FAT16.

value meaning
0x0000 free cluster
0x0001 (impossible)
0x0002 - 0x7FFF next cluster number
0x8000 - 0xFFEF (impossible)
0xFFF0 - 0xFFF7 bad sector
0xFFF8 - 0xFFFF end of cluster chain

TOS disk write process for a new file

Update target directory

  • Read the target directory cluster
  • Add new file metadata into the cluster (e.g. filename). First cluster is unassigned i.e 0
  • Update entire directory cluster
  • Find a free cluster in the FAT
  • Read the target directory cluster
  • Assign free cluster index to the new file metadata
  • Update entire directory cluster

Write file to disk

For each cluster in the file:

  • Write file data to cluster
  • If this is not the last cluster:
    • get next free cluster from the FAT
    • Assign new cluster index to the current cluster in FAT
    • Go back to write file data
  • If this is the last cluster, set FAT entry for this cluster to 0xFFFF

References
http://www.yardley.cc/atari/compendium/atari-compendium-chapter-4-XBIOS.htm
http://toshyp.atari.org/en/00300b.html#BPB
http://joo.kie.sk/wp-content/uploads/2013/05/Atari_HD_File_Sytem_Reference_Guide.pdf
https://archive.org/details/Atari_GEMDOS_Reference_Manual_Apr_4_1986
AHDI 3.00 Release Notes (April 18 1990) - Atari Corporation