File Control Block

A File Control Block (FCB) is a file system structure in which the state of an open file is maintained. An FCB is managed by the operating system, but it resides in the memory of the program that uses the file, not in operating system memory. This allows a process to have as many files open at one time as it wants to, provided it can spare enough memory for an FCB per file.

The FCB originates from CP/M and is also present in most variants of DOS, though only as a backwards compatibility measure in MS-DOS versions 2.0 and later. A full FCB is 36 bytes long; in early versions of CP/M, it was 33 bytes. This fixed size, which could not be increased without breaking application compatibility, lead to the FCB's eventual demise as the standard method of accessing files.

The meanings of several of the fields in the FCB differ between CP/M and DOS, and also depending on what operation is being performed. The following fields have consistent meanings:

Offset Byte
size
Contents
00 1 Drive number — 0 for default, 1 for A:, 2 for B:, ...
01 8 File name and extension — together these form a 8.3 file name
09 3
0C 20 Implementation dependent — should be initialised to zero before the FCB is opened.
20 1 Record number in the current section of the file — used when performing sequential access.
21 3 Record number to use when performing random access.

Usage

In CP/M, 86-DOS and PC DOS 1.x/MS-DOS 1.xx, the FCB was the only method of accessing files. When, with MS-DOS 2, preparations were made to support multiple processes or users,[1][2] use other filesystems[1][2] than FAT or to share files[2] over networks in the future, FCBs were felt to be too small to handle the extra data required for such features[2] and therefore FCBs were seen as inadequate for various future expansion paths.[1] Also, they didn't provide a field to specify sub-directories.[1] Exposing file system related data to user-space was also seen as a security risk.[2] FCBs were thus superseded by file handles, as used on UNIX and its derivatives.[1] File handles are simply consecutive integer numbers associated with specific open files.

If a program uses the newer file handle API to open a file, the operating system will manage its internal data structure associated with that file in its own memory area. This has the great advantage that these structures can grow in size in later operating system versions without breaking compatibility with application programs; its disadvantage is that, given the rather simplistic memory management of DOS, space for as many of these structures as the most "file-hungry" program is likely to use has to be reserved at boot time and cannot be used for any other purpose while the computer is running. Such memory reservation is done using the FILES= directive in the CONFIG.SYS file. This problem does not occur with FCBs in DOS 1 or in CP/M, since the operating system stores all that it needs to know about an open file inside the FCB and thus does not need to use any per-file memory in operating system memory space. When using FCBs in MS-DOS 2 or later, the FCBs are dummies that store references to the actual file management data in operating system memory. Because of this, the number of FCBs which can be kept open at once in DOS 2 or higher is limited as well, usually to 4; using the FCBS= directive in the CONFIG.SYS file, it may be increased beyond that number if necessary. Under DR-DOS, both FILES and FCBS come from the same internal pool of available handles structures and are assigned dynamically as needed.[3]

FCBs were supported in all versions of MS-DOS and Windows until the introduction of the FAT32 filesystem. Windows 95, Windows 98 and Windows Me do not support the use of FCBs on FAT32 drives due to its grown cluster bitwidth,[2] except to read the volume label. This caused some old DOS applications, including Wordstar, to fail under these versions of Windows.

The FCB interface does not work properly on Windows NT, 2000, etc. either - WordStar does not function properly on these operating systems. DOS emulators DOSEMU and DOSBox implement the FCB interface properly, thus they are a way to run older DOS programs that need FCBs on modern operating systems.

See also

References

  1. 1.0 1.1 1.2 1.3 1.4 Ray Duncan (1988). The MS-DOS Encyclopedia - version 1.0 through 3.2. Microsoft Press. ISBN 1-55615-049-0.
  2. 2.0 2.1 2.2 2.3 2.4 2.5 Geoff Chappell (1994). DOS Internals. Addison Wesley. ISBN 0-201-60835-9, ISBN 978-0-201-60835-9.
  3. Matthias Paul (1997-07-30). NWDOS-TIPs Tips & Tricks rund um Novell DOS 7, mit Blick auf undokumentierte Details, Bugs und Workarounds (E-BOOK). MPDOSTIP (in German) (edition 3, release 157 ed.). Retrieved 2012-01-11. NWDOSTIP.TXT is a comprehensive work on Novell DOS 7 and OpenDOS 7.01, including the description of many undocumented features and internals. It is part of the author's yet larger MPDOSTIP.ZIP collection maintained up to 2001 and distributed on many sites at the time. The provided link points to a HTML-converted older version of the NWDOSTIP.TXT file.

    External links