File Control Block: Difference between revisions

Content deleted Content added
mNo edit summary
mNo edit summary
 
(10 intermediate revisions by 7 users not shown)
Line 1:
{{Multiple issues|
{{refimprove|date=January 2014}}
{{Technical|date=October 2022}}
}}
{{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. A 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"
|-
Line 43 ⟶ 46:
| 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 3 or later, the FCB format depends on ifwhether SHARE.EXE is loaded and ifwhether the FCB refers to a local or remote file and often referrefers to a SFT entry. Because of this, the number of FCBs which can be kept open at once in DOS 3 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 32-bit cluster numbers,<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 3, 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 [[WordStar]], to fail under these versions of Windows.
Line 94 ⟶ 102:
{{Reflist|refs=
<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="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 |titleedition=DOS1st Internalsprinting, 1st |series=The Andrew Schulman Programming Series |publisher=[[Addison Wesley Publishing Company]] |isbn=978-0-201-60835-9 |id={{ISBN|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%20Internals2520Internals/DOS_Internals.zip][https://web.archive.org/web/20200222111608/https://www.pcjs.org/pubs/pc/programming/DOS_Internals/<!--]) httpErrata: [https://web.archive.isorg/web/20200222111742/NA9ip -->] Errata: [http://www.geoffchappell.com/notes/dos/internals/<!-- 2017-01-23 -->][https://web.archive.org/web/20200222111853/https://gopher.tildeverse.org/gopher.viste.fr/1/programming/PC/DOS/DOS%20Internals2520Internals/crtdrvr<!-- 1997-07-20, 2008-06-16. http][https://web.archive.isorg/web/20200222111945/nSR1C -->][https://gopher.tildeverse.org/gopher.viste.fr/1/programming/PC/DOS/DOS%20Internals2520Internals/xmswatch<!-- 2008-03-24, 2009-08-30. http://archive.is/lV1NR -->] (NB. While mostly based on DOS 3.2, this book has an appendix covering changes introducted with DOS 3.3.)</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=3 |version=Release 157 |language=de |url=http://www.antonis.de/dos/dos-tuts/mpdostip/html/nwdostip.htm |access-date=2012-01-11 |dead-url-status=nolive |archive-url=https://web.archive.org/web/20170823014801/http://www.antonis.de/dos/dos-tuts/mpdostip/html/nwdostip.htm |archive-date=2017-08-23}} (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>
<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 |dead-url-status=yesdead |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 |dead-url-status=nolive |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 |dead-url-status=nodead |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}}