File format

How files are stored on the disk

In the directory a file's location on the disk is stored with the first Track/Sector it occupies and the file length is in sectors not bytes.

This is done because on the disk a file is a linked list of sectors with each sector consisting of two bytes containing the Track/Sector of the next sector then 254 bytes of data.

The last sector of the file is marked when the Track ID is set to 0. When this happens the Sector portion indicates how many bytes remain for the file, a value from 1 to 254 bytes.

Byte First sectors Last sector
00 15 Next sector location 8 EOF marker Header
01 7 0 Number of bytes
02 254 bytes data remaining bytes data Data
nn
  Undefined
FF

Example

Let's imaging we have a file that's 1322 bytes long spread over 6 sectors. The first sector of the file is stored at Track 17 Sector 21.

In the directory we have the start sector set to 17/21.

1 2 3 4 5 6
T S T S T S T S T S T S
17 0 17 10 17 20 17 1 17 11 0 52

The first 2 bytes of that sector consists of 17 and 0 indicating the next sector is track 17 sector 0. The rest of that sector is 254 bytes of data.

The second sector at Track 17 Sector 0 consists of 17 and 10 which points to the third sector. It also has 254 bytes.

The sixth and final sector has Track set to 0. This is not a valid track as they start from 1, so it marks this sector as the final one in the file.

Here, the sectorId is taken as the number of bytes in this sector which contains data, 52 bytes in this instance. All other bytes in the sector after the data is ignored.