Legacy Documentclose button

Important: The information in this document is obsolete and should not be used for new development.

Previous Book Contents Book Index Next

Inside Macintosh: Files /
Chapter 2 - File Manager / Data Organization in Memory


File Control Blocks

Each time a file is opened, the File Manager reads that file's catalog entry and builds a file control block (FCB) in the FCB buffer, which contains information about all access paths. The FCB buffer is a block in the system heap; the first word contains the length
of the buffer, and the remainder of the buffer is used to hold FCBs for open files.

The initial size of the FCB buffer is determined by the system startup information stored on a volume. Beginning in system software version 7.0, the File Manager attempts to resize the FCB buffer whenever the existing buffer is filled.

You can find the beginning of any particular FCB by adding the size of all preceding FCBs to the size of the FCB buffer length word (that is, 2). This offset from the head of the FCB buffer is used as the file reference number of the corresponding open file. Because the current size of an FCB is 94 bytes, the first few valid file reference numbers are 2, 96, 190, 284, 378, 472, and so on. The maximum size of an expandable FCB buffer is 32,535 bytes, so there is an absolute limit of 342 FCBs in the FCB buffer.

Note
The size and structure of an FCB will be different in future versions of Macintosh system software. To be safe, you should get information from the FCB allocated for an open file by calling the File Manager function PBGetFCBInfo.
When you close a file (for example, by calling FSClose), the FCB for that file is cleared, and the File Manager may use that space to hold the FCB for a file that is opened at a later time. Consequently, it is important that you do not attempt to close a file more
than once; you may inadvertently close a file that was opened by the system or by another application.

WARNING
Closing a volume's catalog file (perhaps by inadvertently calling FSClose or PBClose twice with the same file reference number) may result in damage to the volume's file system and loss of data.
The structure of a file control block is defined by the FCB data type.

TYPE FCB    =                 {file control block}
RECORD
   fcbFlNum:      LongInt;    {file ID}
   fcbFlags:      Integer;    {file flags}
   fcbSBlk:       Integer;    {reserved}
   fcbEOF:        LongInt;    {logical end-of-file}
   fcbPLen:       LongInt;    {physical end-of-file}
   fcbCrPs:       LongInt;    {current file mark position}
   fcbVPtr:       Ptr;        {pointer to volume control block}
   fcbBfAdr:      Ptr;        {pointer to access path buffer}
   fcbFlPos:      Integer;    {reserved}
   fcbClmpSize:   LongInt;    {file clump size}
   fcbBTCBPtr:    Ptr;        {pointer to B*-tree control block}
   fcbExtRec:     ExtDataRec; {first three file extents}
   fcbFType:      LongInt;    {file's four Finder type bytes}
   fcbCatPos:     LongInt;    {catalog hint for use on close}
   fcbDirID:      LongInt;    {file's parent directory ID}
   fcbCName:      String[31]; {name of file}
END;
Field Description
fcbFlNum
The file ID of this file.
fcbFlags
Flags describing the status of the file. Currently the following bits are defined:
 BitMeaning
 0-7Reserved
 8Set if data can be written to the file
 9Set if this FCB describes a resource fork
 10Set if the file has a locked byte range
 11Reserved
 12Set if the file has shared write permissions
 13Set if the file is locked (write-protected)
 14Set if the file's clump size is specified in the FCB
 15Set if the file has changed since it was last flushed
fcbSBlk
Reserved.
fcbEOF
The logical end-of-file of the file.
fcbPLen
The physical end-of-file of the file.
fcbCrPs
The position of the mark.
fcbVPtr
A pointer to the volume control block of the volume containing
the file.
fcbBfAdr
A pointer to the file's access path buffer.
fcbFlPos
Reserved.
fcbClmpSize
The clump size of the file.
fcbBTCBPtr
A pointer to the file's B*-tree control block.
fcbExtRec
An extent record (12 bytes) containing the first three extents of
the file.
fcbFType
The file's Finder type.
fcbCatPos
A catalog hint, used when you close the file.
fcbDirID
The file's parent directory ID.
fcbCName
The file's name (as contained in the volume catalog file).

Previous Book Contents Book Index Next

© Apple Computer, Inc.
2 JUL 1996