Flashpath for Linux

File Allocation Table (FAT)

The 4MB chip is always 12 bit but must 16 bit large media.
12 and 16 bit FAT
12 Bit16 BitMeaning
000 0000 Free space
FF1-FF7 FFF1-FFF7 Bad track marking
FF8-FFE FFF8-FFFE May be used to mark end of a file chain
FFF FFFF Standard marker for end of a file chain

Calculating 12 bit FAT Entries

  1. Get starting cluster from directory entry.
  2. Multiply the cluster number just used by 1.5
  3. The whole part of the product is the offset into the FAT, of the entry that maps to the cluster in the directory. This entry contains the number of the next cluster.
  4. Move the word at the calculated FAT into a register.
  5. If the last cluster used was an even number, keep the low order 12 bits of the register, otherwise, keep the high order 12 bits.
  6. If the resultant 12 bits are (0FF8h-0FFFh) no more clusters are in the file. Otherwise, the next 12 bits contain the cluster number of the next cluster in the file.

Calculating 16 Bit FAT Entries

  1. Get the starting cluster of the file from the directory.
  2. Multiply the cluster number found by 2.
  3. Load the word at the calculated FAT offset into a register.
  4. If the 16 bits are (0FFF8h-0FFFFh) no more clusters are in the file. Otherwise, the 16 bits contain the cluster number of the next cluster in the file.

To convert the cluster to a logical sector number (relative sector, similar to that used by DEBUG, int 25h and 26h):

  1. Subtract 2 from the cluster number
  2. Multiply the result by the number of sectors per cluster.
  3. Add the logical sector number of the beginning of the data area.