Color BASIC Disk Format

Low level format

CoCo disks are formatted to contain 35 tracks, numbered 0 through 34. Each track has 18 sectors, numbered 1 through 18. A sector contains 256 bytes.

High level format

Track number 17 is special; it contains the directory and File Allocation Table (or FAT). Every other track is divided into two granules; in those tracks, sectors 1 through 9 form one granule, and sectors 10 through 18 form the other. So there are 68 granules on a disk, numbered 0 through 67, each containing 2304 bytes. Disk space for files is allocated by the granule, so even if you create a file that contains only one byte, a whole granule of 2304 bytes is reserved for it. While it may seem wasteful at first, this reduces the amount of work in allocating space for the file as you add to it. The computer only has to do that allocation work once for every 2304 bytes that you add. It also reduces fragmentation - by reserving space in such big chunks, your file can't possibly end up scattered all over the disk in little tiny pieces.

The directory track (17) contains the file allocation table in sector 2, and the directory of files in sectors 3 through 11. The remaining sectors on the directory track are unused ("reserved for future use" - shyeah, right).

The file allocation table is 68 bytes long; one byte for each granule on the disk. If one of these bytes is between 0 and 67, it tells the number of the next granule used by the same file. If it is between 192 and 201 (hex C0 and C9), then this is the last granule allocated for its file, and the least significant four bits tell how many sectors of the granule are used. If it is FF then it is unused, and may be allocated as needed. So the bytes in the FAT form a linked list for each file, telling which granules the file consists of.

Each directory sector contains eight entries of 32 bytes each. So the entire directory has room for 72 files. (There is room in the directory for more files than there are granules on the disk!) Each entry contains:

Color Disk BASIC reserves track 17 for the directory because that is the middle position for the read/write head of the disk drive, so it should be efficient for frequent access. When allocating granules to be used in files, it chooses granules that are close to the directory first, so in a half-full disk you would expect the outermost and innermost tracks to be empty, and the tracks near the directory to be full.

You can use the "G" and "P" commands in my "MON80" program to read and write ("get" and "put") individual disk sectors, to see this stuff for yourself. But be careful; that program will let you easily write over any sector on the disk, including the FAT or the directory. With just a few loose keystrokes, you could trash your disk! On the other hand, now that you know what you are doing, if you have a crashed disk, you might be able to repair it.

Back to my top-level CoCo page


15-Jun-98
yakowenk@csx.unxc.edu
(remove all "x"s to get a valid address)