The 1541’s file system keeps everything about the disk on track 18: the block
availability map (BAM) and disk name in sector 0, and the directory from sector 1. Every
directory and file sector starts with a two-byte link to the next one. Text is
PETSCII, padded with A0. Numbers are little-endian. This page follows
the VICE manual, section 17.5 (The D64 disk image format).
Sector chains
| Offset | Size | Name | Description |
|---|---|---|---|
0x00 | 1 | Next track | Track of the next sector in the chain; 0 in the last sector. |
0x01 | 1 | Next sector | Its sector. In the last sector, this is instead the index of the last used byte (so the sector holds that − 1 bytes of data). |
0x02 | 254 | Data | Data bytes. |
VICE’s example: a chain ending in 00 34 means the last sector holds
bytes 0x02–0x34. Files are written with a sector interleave
of 10, the directory with 3 (see Allocation and interleave).
BAM: track 18, sector 0
| Offset | Size | Name | Description |
|---|---|---|---|
0x00 | 2 | Directory start | Track and sector of the first directory sector, normally 18/1. |
0x02 | 1 | DOS version | 0x41 (A). Any other value except 0 makes the 1541 treat the disk as write-protected. |
0x03 | 1 | – | Unused. |
0x04 | 140 | BAM entries | Four bytes for each of tracks 1 to 35; see below. |
0x90 | 16 | Disk name | Padded with A0. |
0xA0 | 2 | – | A0 A0. |
0xA2 | 2 | Disk ID | The two-character ID given when the disk was formatted. |
0xA4 | 1 | – | Usually A0. |
0xA5 | 2 | DOS type | Usually 2A. |
0xA7 | 4 | – | A0. |
0xAB | 1 | – | 0. |
0xAC | 20 | Dolphin DOS BAM | Entries for tracks 36–40 on 40-track disks made with Dolphin DOS. |
0xC0 | 20 | Speed DOS BAM | Entries for tracks 36–40 on 40-track disks made with Speed DOS. |
0xD4 | 44 | – | 0. |
Each BAM entry is a count of free sectors on the track, then three bytes of bitmap:
bit 0 of the first byte is sector 0, bit 7 sector 7, bit 0 of the second byte sector 8,
and so on. A set bit means the sector is free. For example 12 FF F9 17 is
a track 1 with 18 sectors free and sectors 9, 10 and 19 used.
BAM entries for tracks 36 to 40
The standard BAM covers tracks 1 to 35 only. A 40-track image (see image sizes) needs entries for tracks 36 to 40, five more 4-byte entries in the same form, and the three DOS extensions that write them keep them in different places of the same sector:
| DOS | Entries for tracks 36–40 | Disk name, ID and DOS type |
|---|---|---|
| SpeedDOS | 0xC0–0xD3 | Where the standard BAM has them |
| DolphinDOS | 0xAC–0xBF | Where the standard BAM has them |
| PrologicDOS | 0x90–0xA3 | Name moved to 0xA4 (the VICE manual says “name and ID”; where the ID and the DOS type go is not given there) |
Tracks 41 and 42 of a 42-track image have no BAM entries in any of these. A file does not
say which DOS wrote it, so the viewer works it out: an area counts when all five entries
in it agree with themselves (each count is at most 17 and equals the number of set
bits, no bits are set beyond sector 16) and are not all zero, tried in the order
SpeedDOS, DolphinDOS, PrologicDOS; the options bar overrides the choice. That test is
the viewer’s own, not part of any DOS, and has only been run on built images: none of
the real images on the Mac has 40 tracks. For PrologicDOS the viewer takes the name
from 0xA4 and shows no ID or DOS type.
Directory
Directory sectors start at 18/1 and chain like any other; each holds eight 32-byte entries, at most 144 in all. Only the first entry of each sector uses bytes 0–1, for the chain link.
| Offset | Size | Name | Description |
|---|---|---|---|
0x00 | 2 | Next directory sector | Track and sector link (first entry of the sector only; 00 00 elsewhere). |
0x02 | 1 | File type | See file types. 00 is an empty or deleted entry. |
0x03 | 2 | First sector | Track and sector of the file’s first sector. |
0x05 | 16 | File name | PETSCII, padded with A0. |
0x15 | 2 | Side-sector block | REL files only: track and sector of the first side-sector block (the record index). |
0x17 | 1 | Record length | REL files only: bytes per record, at most 254. |
0x18 | 6 | – | Unused, except on GEOS disks (see GEOS directory entries; the GEOS fields start at 0x15). |
0x1E | 2 | Size | The file’s length in sectors (“blocks”), low byte first. |
| Bits | Meaning |
|---|---|
| 0–3 | Type: 0 DEL, 1 SEQ (sequential data), 2 PRG (program), 3 USR (user), 4 REL (relative, record-based); 5–15 illegal (VICE: the 1541 treats these bits inconsistently, some routines ignoring bit 3). |
| 4 | Unused. |
| 5 | Set only while a file is being replaced with SAVE "@:…". |
| 6 | Locked: set produces “>” locked files in the listing. |
| 7 | Closed. A file left open (clear) is a “splat” file, listed with *. |
So 0x82 is an ordinary closed program, 0x81 a closed
sequential file and 0xC2 a locked program.
REL files and side sectors
VICE gives the side-sector and record-length fields of the directory entry but not the side sectors themselves. Their layout is in Peter Schepers’ and Immers and Neufeld’s REL (RELative file layout) (unusedino.de, revision 1.1, 2004); it is not in the VICE manual. A side sector is a 256-byte sector, chained like any file sector:
| Offset | Size | Meaning |
|---|---|---|
0x00 | 2 | Track and sector of the next side sector; track 0 in the last one |
0x02 | 1 | Side-sector block number: 0 for the first, then 1, 2… |
0x03 | 1 | Record size, as in the directory entry (at most 254) |
0x04 | 12 | Track and sector of the six side sectors (the first entry is this very sector); a 00/00 entry means no more. All of the up to six side sectors must have the same values here. |
0x10 | 240 | Track and sector of each data sector of the file, in order; 00/00 ends the list |
To reach record n, the byte offset is n × record size, and the sector index is that offset ÷ 254, the 254 being the data bytes per sector (256 less the 2-byte link), unrelated to the maximum record length.
GEOS directory entries
On GEOS disks the otherwise unused bytes 0x15–0x1D of a
directory entry are used. From Paul David Doherty, Andreas Varga and Joe Forster’s
GEOS VLIR page (unusedino.de, revision 1.4, 2005); the sources read for the
rest of this page do not describe them.
| Offset | Size | Meaning |
|---|---|---|
0x15 | 2 | Track and sector of the INFO block |
0x17 | 1 | GEOS file structure: 0 sequential, 1 VLIR |
0x18 | 1 | GEOS file type: 0 non-GEOS (an ordinary file), 1 BASIC, 2 assembler, 3 data file, 4 system file, 5 desk accessory, 6 application, 7 application data (documents), 8 font, 9 printer driver, 10 input driver, 11 disk driver, 12 system boot file, 13 temporary, 14 auto-execute; 15–255 undefined. A non-zero value makes it a GEOS file; REL files are not allowed. |
0x19 | 5 | Time stamp: year (1900 + the value), month 1–12, day 1–31, hour 0–23, minute 0–59 |
The first-sector field of a GEOS VLIR entry points to the single-sector
record block: up to 127 track/sector pointers, one per VLIR record, from
byte 2 (bytes 0–1 are 00 FF); 00/00 ends the list and
00/FF marks a record that is not available. The INFO
block is one sector:
| Offset | Size | Meaning |
|---|---|---|
0x00 | 2 | 00 FF, as it is one sector long |
0x02 | 3 | ID bytes; the source says the first is “likely” the icon width and the second the height, with rare exceptions |
0x05 | 63 | Icon bitmap, in C64 sprite format |
0x44 | 3 | C64 file type, GEOS file type and GEOS file structure, as in the directory entry |
0x47 | 2 | Program load address |
0x49 | 2 | Program end address (accessories only) |
0x4B | 2 | Program start address |
0x4D | 20 | Class text, ended by 0 |
0x61 | 20 | Author (for application data, the name of the application disk; may not be set or may be invalid) |
0x75 | 20 | For a document, the name of the application that made it |
0x89 | 23 | Free for applications |
0xA0 | 96 | Description, ended by 0 |
GEOS text is ASCII, not PETSCII. A GEOS-formatted disk’s BAM sector also carries a
signature from 0xAB to 0xBC (the source’s dump reads “GEOS format V1.0”);
what the other changed BAM bytes of GEOS disks mean is not described here.
Example
00016500 12 01 41 00 15 FF FF 1F 15 FF FF 1F 15 FF FF 1F ..A.............
…
00016540 02 00 00 11 00 00 00 00 10 EC FF 07 00 00 00 00 ................
…
00016590 43 49 41 56 41 52 49 4F 55 53 A0 A0 A0 A0 A0 A0 CIAVARIOUS......
000165A0 A0 A0 30 30 A0 32 41 A0 A0 A0 A0 00 00 00 00 00 ..00.2A.........
…
00016600 12 04 82 11 00 43 49 41 31 A0 A0 A0 A0 A0 A0 A0 .....CIA1.......
00016610 A0 A0 A0 A0 A0 00 00 00 00 00 00 00 00 00 03 00 ................
CIA/ciavarious/cia.d64, one of the VICE test disks.Reading it: the directory starts at 18/1; DOS version A; tracks 1 and
2 have all 21 sectors free (15 FF FF 1F). At 0x16540 track 16
has 2 free (the bitmap 00 00 11 frees sectors 16 and 20), track 17 none, track
18 16 free and track 19 none; the disk is named CIAVARIOUS, ID
00, DOS type 2A. The first directory sector (18/1, at
0x16600) links on to 18/4 (interleave 3); its first entry is a closed
PRG (82) called CIA1 starting at track 17 sector 0,
3 blocks long.