File Control Block: Difference between revisions

Content deleted Content added
I8086 (talk | contribs)
m Changed up the wording and used a link.
mNo edit summary
 
(32 intermediate revisions by 15 users not shown)
Line 1:
{{Multiple issues|
{{refimprove|date=January 2014}}
{{Technical|date=October 2022}}
A '''File Control Block''' ('''FCB''') is a file system structure in which the state of an open [[Computer file|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.
}}
{{Use dmy dates|date=May 2019|cs1-dates=y}}
A '''File Control Block''' ('''FCB''') is a file system structure in which the state of an open [[Computer file|file]] is maintained. AnA 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 backwardsbackward 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, leadled 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:<ref name="stanislavs"/>
{|class="wikitable"
|-
! Offset !! Byte<br />size !! Contents
|-
| 000x00
|align=right| 1 || Drive number — 0 for default, 1 for A:, 2 for B:, ...
|-
| 010x01
|align=right| 8
|rowspan=2| File name and [[Filename extension|extension]] — together these form a [[8.3 filename|8.3 file name]].
|-
| 090x09
|align=right| 3
|-
| 0C0x0C
|align=right| 20 || Implementation dependent — should be initialised to zero before the FCB is opened.
|-
| 200x20
|align=right| 1 || Record number in the current section of the file — used when performing [[sequential access]].
|-
| 210x21
|align=right| 3 || Record number to use when performing [[random access]].
|}
 
The 20-byte-long field starting at offset 0x0C contained fields which (among others) provided further information about the file:<ref name="Programacion_Ensamblador_MSDOS"/>
{|class="wikitable"
|-
! Offset !! Byte<br/>size !! Contents
|-
| 0x0E
|align=right| 2 || File's record length in bytes.
|-
| 0x10
|align=right| 4 || Total file size in bytes.
|-
| 0x14
|align=right| 2 || Date of last modification to file contents.
|-
| 0x16
|align=right| 2 || Time of last modification.
|}
 
Further values were used by newer versions of DOS until new information could no longer fit in these 20 bytes. Some preceding "negative offset" bytes were squeezed from reserved spaces in CP/M Zero Page and DOS [[Program Segment Prefix]] for storing file attributes.<ref name="stanislavs"/>
 
==Usage==
In CP/M, [[86-DOS]] and [[PC DOS]] 1.x/[[MS-DOS]] 1.xx, the FCB was the only method of accessing files. Under DOS a few INT 21h subfunctions provided the interface to operate on files using the FCB.<ref name="stanislavs"/><ref name="Duncan_1988_MS-DOS_Encyclopedia"/><ref name="Chappell_1994_DOS-Internals"/> When, with MS-DOS 2, preparations were made to support multiple processes or users,<ref name="Duncan_1988_MS-DOS_Encyclopedia"/><ref name="Chappell_1994_DOS-Internals"/> use other filesystems<ref name="Duncan_1988_MS-DOS_Encyclopedia"/><ref name="Chappell_1994_DOS-Internals"/> than FAT or to share files<ref name="Chappell_1994_DOS-Internals"/> over networks in the future, FCBs were felt to be too small to handle the extra data required for such features<ref name="Chappell_1994_DOS-Internals"/> and therefore FCBs were seen as inadequate for various future expansion paths.<ref name="Duncan_1988_MS-DOS_Encyclopedia"/> Also, they didn't provide a field to specify sub-directories.<ref name="Duncan_1988_MS-DOS_Encyclopedia"/> Exposing file system related data to user-space was also seen as a security risk.<ref name="Chappell_1994_DOS-Internals"/> FCBs were thus superseded by [[file handle]]s, as used on [[UNIX]] and its derivatives.<ref name="Duncan_1988_MS-DOS_Encyclopedia"/> 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 (CONFIG.SYS directive)|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 23 or later, the FCBsFCB areformat dummiesdepends thaton storewhether referencesSHARE.EXE tois loaded and whether the actualFCB refers to a local or remote file managementand dataoften inrefers to operatinga systemSFT memoryentry. Because of this, the number of FCBs which can be kept open at once in DOS 23 or higher is limited as well, usually to 4; using the [[FCBS (CONFIG.SYS directive)|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.<ref name="Paul_1997_NWDOSTIP"/>
 
FCBs were supported in all versions of MS-DOS and [[Microsoft Windows|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 grown32-bit cluster bitwidthnumbers,<ref name="Chappell_1994_DOS-Internals"/><!-- While this source predates the introduction of FAT32, it discusses the various real and potential future limitations of the FCB approach and the cumbersome workarounds introduced in DOS 23, DOS 4 and DOS 5 to keep FCBs alive for a bit longer --> except to read the volume label. This caused some old DOS applications, including [[WordstarWordStar]], to fail under these versions of Windows.
 
The FCB interface does not work properly on [[Windows NT]], [[Windows 2000|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.
 
== Disk Transfer Area ==
A companion data structure used together with the FCB was the '''Disk Transfer Area''' (DTA).<ref name="Programacion_Ensamblador_MSDOS"/> This is the name given to the buffer where file contents (records) would be read into/written from. File access functions in DOS that used the FCB assumed a fixed ___location for the DTA, initially pointing to a part of the PSP (see next section); this ___location could be changed by calling a DOS function, with subsequent file accesses implicitly using the new ___location.
 
With the deprecation of the FCB method, the new file access functions which used file handles also provided a means to specify a memory buffer for file contents with every function call, such that maintaining concurrent, independent buffers (either for different files or for the same file) became much more practical.
 
== Program Segment Prefix & Program Initialisation ==
Every DOS executable started from the shell ([[COMMAND.COM]]) was provided with a pre-filled 256-byte long data structure called the ''[[Program Segment Prefix]]'' (PSP). Relevant fields within this structure include:<ref name="Programacion_Ensamblador_MSDOS"/>
{|class="wikitable"
|-
! Offset !! Byte<br/>size !! Contents
|-
| 0x02
|align=right| 2 || Available memory for the program in 16-byte chunks.
|-
| 0x2C
|align=right| 2 || Segment address containing the program's environment variables.
|-
| 0x5C
|align=right| 16 || Prepared FCB for first command line argument (unopened).
|-
| 0x6C
|align=right| 20 || Prepared FCB for second command line argument (unopened).
|-
| 0x80
|align=right| 1 || Length of command line.
|-
| 0x81
|align=right| 127 || Command line contents.
|}
 
This data structure could be found at the beginning of the data segment whose address was provided by DOS at program start in the DS and ES segment registers. Besides providing the program's command line verbatim at address 0x81, DOS also tried to construct two FCB's corresponding to the first two words in the command line, the purpose being to save work for the programmer in the common case where these words were filenames to operate on. Since these FCB's remained unopened, no problem would ensue even if these command line words did not refer to files.
 
The initial address for the DTA was set to overlay the area in the PSP (at address 0x80) where the command line arguments were stored, such that a program needed to parse this area for command line arguments before invoking DOS functions that made use of the DTA (such as reading in a file record), unless the program took care to change the address of the DTA to some other memory region (or not use the DTA/FCB functions altogether, which soon became deprecated in favour of file handles).
 
== See also ==
Line 42 ⟶ 100:
 
== References ==
{{Reflist|refs=
<references><ref name="Chappell_1994_DOS-Internals">Geoff Chappell (1994). ''DOS Internals''. Addison Wesley. ISBN 0-201-60835-9, ISBN 978-0-201-60835-9.</ref>
<ref name="Duncan_1988_MS-DOS_Encyclopedia">{{cite book |title=The MS-DOS Encyclopedia: versions 1.0 through 3.2 |author-first1=Ray |author-last1=Duncan |author-first2=Steve |author-last2=Bostwick |author-first3=Keith |author-last3=Burgoyne |author-first4=Robert A. |author-last4=Byers |author-first5=Thom |author-last5=Hogan |author-first6=Jim |author-last6=Kyle |author-first7=Gordon |author-last7=Letwin |author-link7=Gordon Letwin |author-first8=Charles |author-last8=Petzold |author-link8=Charles Petzold |author-first9=Chip |author-last9=Rabinowitz |author-first10=Jim |author-last10=Tomlin |author-first11=Richard |author-last11=Wilton |author-first12=Van |author-last12=Wolverton |author-first13=William |author-last13=Wong |author-first14=JoAnne |author-last14=Woodcock |contribution=Technical advisors |contributor-first1=Mark |contributor-last1=Zbikowski |contributor-link1=Mark Zbikowski |contributor-first2=Paul |contributor-last2=Allen |contributor-link2=Paul Allen |contributor-first3=Steve |contributor-last3=Ballmer |contributor-link3=Steve Ballmer |contributor-first4=Reuben |contributor-last4=Borman |contributor-first5=Rob |contributor-last5=Borman |contributor-first6=John |contributor-last6=Butler |contributor-first7=Chuck |contributor-last7=Carroll |contributor-first8=Mark |contributor-last8=Chamberlain |contributor-first9=David |contributor-last9=Chell |contributor-first10=Mike |contributor-last10=Colee |contributor-first11=Mike |contributor-last11=Courtney |contributor-first12=Mike |contributor-last12=Dryfoos |contributor-first13=Rachel |contributor-last13=Duncan |contributor-first14=Kurt |contributor-last14=Eckhardt |contributor-first15=Eric |contributor-last15=Evans |contributor-first16=Rick |contributor-last16=Farmer |contributor-first17=Bill |contributor-last17=Gates |contributor-link17=Bill Gates |contributor-first18=Michael |contributor-last18=Geary |contributor-first19=Bob |contributor-last19=Griffin |contributor-first20=Doug |contributor-last20=Hogarth |contributor-first21=James W. |contributor-last21=Johnson |contributor-first22=Kaamel |contributor-last22=Kermaani |contributor-first23=Adrian |contributor-last23=King |contributor-first24=Reed |contributor-last24=Koch |contributor-first25=James |contributor-last25=Landowski |contributor-first26=Chris |contributor-last26=Larson |contributor-first27=Thomas |contributor-last27=Lennon |contributor-first28=Dan |contributor-last28=Lipkie |contributor-first29=Marc |contributor-last29=McDonald |contributor-link29=Marc McDonald |contributor-first30=Bruce |contributor-last30=McKinney |contributor-first31=Pascal |contributor-last31=Martin |contributor-first32=Estelle |contributor-last32=Mathers |contributor-first33=Bob |contributor-last33=Matthews <!-- |contributor-link33=Robert Matthews (scientist)??? --> |contributor-first34=David |contributor-last34=Melin |contributor-first35=Charles |contributor-last35=Mergentime |contributor-first36=Randy |contributor-last36=Nevin |contributor-first37=Dan |contributor-last37=Newell |contributor-first38=Tani |contributor-last38=Newell |contributor-first39=David |contributor-last39=Norris |contributor-first40=Mike |contributor-last40=O'Leary |contributor-first41=Bob |contributor-last41=O'Rear |contributor-link41=Bob O'Rear |contributor-first42=Mike |contributor-last42=Olsson |contributor-first43=Larry |contributor-last43=Osterman |contributor-first44=Ridge |contributor-last44=Ostling |contributor-first45=Sunil |contributor-last45=Pai |contributor-first46=Tim |contributor-last46=Paterson |contributor-link46=Tim Paterson |contributor-first47=Gary |contributor-last47=Perez |contributor-first48=Chris |contributor-last48=Peters |contributor-first49=Charles |contributor-last49=Petzold |contributor-link49=Charles Petzold |contributor-first50=John |contributor-last50=Pollock |contributor-first51=Aaron |contributor-last51=Reynolds |contributor-link51=Aaron R. Reynolds |contributor-first52=Darryl |contributor-last52=Rubin |contributor-first53=Ralph |contributor-last53=Ryan |contributor-first54=Karl |contributor-last54=Schulmeisters |contributor-first55=Rajen |contributor-last55=Shah |contributor-first56=Barry |contributor-last56=Shaw |contributor-first57=Anthony |contributor-last57=Short |contributor-first58=Ben |contributor-last58=Slivka |contributor-first59=Jon |contributor-last59=Smirl |contributor-first60=Betty |contributor-last60=Stillmaker |contributor-first61=John |contributor-last61=Stoddard |contributor-first62=Dennis |contributor-last62=Tillman |contributor-first63=Greg |contributor-last63=Whitten |contributor-first64=Natalie |contributor-last64=Yount |contributor-first65=Steve |contributor-last65=Zeck |date=1988 |edition=Completely reworked |publisher=[[Microsoft Press]] |___location=Redmond, Washington, USA |isbn=1-55615-049-0 |lccn=87-21452 |oclc=16581341}} (xix+1570 pages; 26&nbsp;cm) (NB. This edition was published in 1988 after extensive rework of the withdrawn 1986 first edition by a different team of authors. [https://www.pcjs.org/pubs/pc/reference/microsoft/mspl13/msdos/encyclopedia/])</ref>
<ref name="Duncan_1988_MS-DOS_Encyclopedia">Ray Duncan (1988). ''The MS-DOS Encyclopedia - version 1.0 through 3.2''. Microsoft Press. ISBN 1-55615-049-0.</ref><!-- While mostly based on DOS 3.2, this book has an appendix covering changes introducted with DOS 3.3 -->
<ref name="Chappell_1994_DOS-Internals">{{cite book |title=DOS Internals |author-first=Geoff |author-last=Chappell |editor-first1=Andrew |editor-last1=Schulman |editor-first2=Amorette |editor-last2=Pedersen |date=January 1994 |edition=1st printing, 1st |series=The Andrew Schulman Programming Series |publisher=[[Addison Wesley Publishing Company]] |isbn=978-0-201-60835-9 }} (xxvi+738+iv pages, 3.5"-floppy [https://web.archive.org/web/20190421200111/https://gopher.tildeverse.org/gopher.viste.fr/9/programming/PC/DOS/DOS%2520Internals/DOS_Internals.zip][https://web.archive.org/web/20200222111608/https://www.pcjs.org/pubs/pc/programming/DOS_Internals/]) Errata: [https://web.archive.org/web/20200222111742/http://www.geoffchappell.com/notes/dos/internals/][https://web.archive.org/web/20200222111853/https://gopher.tildeverse.org/gopher.viste.fr/1/programming/PC/DOS/DOS%2520Internals/crtdrvr][https://web.archive.org/web/20200222111945/https://gopher.tildeverse.org/gopher.viste.fr/1/programming/PC/DOS/DOS%2520Internals/xmswatch]</ref>
<ref name="Paul_1997_NWDOSTIP">{{cite book | title = NWDOS-TIPs &mdash; Tips &amp; Tricks rund um Novell DOS 7, mit Blick auf undokumentierte Details, Bugs und Workarounds | work= MPDOSTIP | author -first= Matthias R. |author-last=Paul | date = 1997-07-30 | edition = edition 3, release|version=Release 157 | language= Germande | format url= ehttp://www.antonis.de/dos/dos-booktuts/mpdostip/html/nwdostip.htm |access-date=2012-01-11 |url -status=live |archive-url=https://web.archive.org/web/20170823014801/http://www.antonis.de/dos/dos-tuts/mpdostip/html/nwdostip.htm | accessdate archive-date= 20122017-0108-1123}} (NB. 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.)</ref></references><references/>
<ref name="Programacion_Ensamblador_MSDOS">{{cite book |author-first=Miguel |author-last=Rodriguez-Rosello |date=1992 |title=8088-8086/8087 Programacion Ensamblador En Entorno MSDOS |publisher=Ediciones Anaya Multimedia |isbn=84-7614-128-9 |language=es}}</ref>
<ref name="stanislavs">{{cite web |title=FCB - Standard DOS File Control Block |url=http://stanislavs.org/helppc/fcb.html}}</ref>
}}
 
==Further reading==
* {{cite web |title=210F: DOS 1+ - OPEN FILE USING FCB |editor-first=Ralf D. |editor-last=Brown |editor-link=Ralf D. Brown |date=2000-07-17 |work=[[Ralf Brown's Interrupt List]] 61 |publisher=ctyme.com |url=http://www.ctyme.com/intr/rb-2574.htm |url-status=dead |archive-url=https://web.archive.org/web/20160619060655/http://www.ctyme.com/intr/rb-2574.htm |archive-date=2016-06-19}} [http://www.delorie.com/djgpp/doc/rbinter/id/85/25.html]
* {{cite web |author-first=John C. |author-last=Elliott |title=CP/M File Control Block |date=2002-12-29 |work=Seasip.info |url=http://seasip.info/Cpm/fcb.html |access-date=2017-08-23 |url-status=live |archive-url=https://web.archive.org/web/20170823020604/http://seasip.info/Cpm/fcb.html |archive-date=2017-08-23}}
* {{cite web |title=CP/M Internals |date=2017-08-23 |url=http://obsolescence.wix.com/obsolescence#!cpm-internals/c247i |access-date=2017-08-23 |url-status=dead |archive-url=https://web.archive.org/web/20170823015253/http://obsolescence.wixsite.com/obsolescence/cpm-internals?_escaped_fragment_=cpm-internals%2Fc247i#!cpm-internals/c247i |archive-date=2017-08-23}} - In-depth description of CP/M FCB
 
{{Digital Research}}
== External links ==
* [http://www.ctyme.com/intr/rb-2574.htm ctyme.com - DOS 1+ Open file using FCB]
* [http://obsolescence.wix.com/obsolescence#!cpm-internals/c247i CP/M Internals] - In-depth description of CP/M FCB
 
[[Category:Disk file systems| ]]