This page was last modified 12:56, 5 December 2018 by Rderooy. Based on work by NYYRIKKI and Mars2000you and others.

File Control Block (FCB)

FCB is the area for storing information needed to handle files using system calls under MSX-DOS. FCB plays an important role for files and directories


File Control Blocks as we know them on MSX have a long history. FCBs originate from CP/M operating system that was released in 1974. MSX-DOS is actually pretty much compatible with CP/M programs up to CP/M version 2.2. There are some limitations, but most of them are related to the fact that file system has been changed to FAT. This means that CP/M programs have been blocked from accessing the disks in a way that would bypass the file system. This is done in order to keep the data safe. Some paper tape punch and paper tape reader related stuff has also needed to go.

In 1974 all of the floppy disks were 8" floppies and the de facto standard sector size of those disks was 128 bytes / sector. This is why we can see that all the CP/M compatible BDOS functions are fixed to record size of 128 bytes. This means that all file sizes are also multiple of 128. When 8-128 (in power of two) of these records were put together they formed an 1kB-16kB "extent" or "block" that is smallest allocatable storage unit similar to "cluster" on FAT. Originally there was only 1 byte reserved for extent number, but later a high byte was allocated from "S2".

In MSX-DOS the virtual extent size is fixed to 16kB. Because of FAT this is anyway just a calculation value. The location inside file can be calculated with formula: "Current record" * 128 + "extent number" * 16384

MSX-DOS also enhanced the random read/write routines with random block read/write. These two functions made it possible to define record size and give number of records as parameter. Since record size does not affect performance, it is common to set it to 1 and just think records as bytes. These changes anyway needed also FCB to be redefined. For compatibility reasons changing FCB size was not an option, so some of the bytes inside FCB needed to get double meanings. This is why FCB definition may look a bit of a mess.

When directory support was added to MSX-DOS2 some of the bytes inside allocated block (AL) needed to change again to make this possible. This area was also left undocumented in order to prevent more incompatibilities that could raise from future needs. FCB based file access does not directly let you to access directories, but all files will be read/written to currently active directory. Programmer needs to switch using FIB (File Info Block) in order to access files, directories and file attributes directly.

FCB Structure

Offset Name Length Description
0 DR 1 Drive number containing the file.
(0 for Default drive, 1 for A, 2 for B, ..., 8 for H)
1 Fn 11 8 bytes for filename and 3 bytes for its extension. When filename or extension has less than 8 or 3, the rest are filled in by spaces (20h). In case of search "?" (3Fh) may be used to represent any character.
12 EX 1 "Current block LO" or "Extent number LO" depending of function called.
13 S1 1 "Current block HI" or "File attributes" (DOS2) depending of function called.
14 S2 1 "Record size LO" or "Extent number HI" depending of function called. NOTE: Because of Extent number the record size must be manually defined after opening a file!
15 RC 1 "Record size HI" or "Record count" depending of function called.
16 AL 4 File size in bytes (1~4294967296).
20 2 Date (DOS1) / Volume ID (DOS2)
22 2 Time (DOS1) / Volume ID (DOS2)
24 1 Device ID. (DOS1)
  • FBh = PRN (Printer)
  • FCh = LST (List)
  • FCh = NUL (Null)
  • FEh = AUX (Auxiliary)
  • FFh = CON (Console)
25 1 Directory location. (DOS1)
26 2 Top cluster number of the file. (DOS1)
28 2 Last cluster number accessed (DOS1)
30 2 Relative location from top cluster of the file number of clusters from top of the file to the last cluster accessed. (DOS1)
32 CR 1 Current record within extent (0...127)
33 Rn 3-4 Random record number. If record size <64 then all 4 bytes will be used.

PLEASE NOTE: The information stored on FCB offsets 20-31 is not compatible with MSX-DOS2 and usage of this data should therefore be avoided.