%!PS-Adobe-3.0 %%Creator: groff version 1.16.1 %%CreationDate: Mon Jun 17 01:28:48 2002 %%DocumentNeededResources: font Times-Roman %%+ font Times-Italic %%+ font Times-Bold %%+ font Symbol %%DocumentSuppliedResources: procset grops 1.16 1 %%Pages: 8 %%PageOrder: Ascend %%Orientation: Portrait %%EndComments %%BeginProlog %%BeginResource: procset grops 1.16 1 /setpacking where{ pop currentpacking true setpacking }if /grops 120 dict dup begin /SC 32 def /A/show load def /B{0 SC 3 -1 roll widthshow}bind def /C{0 exch ashow}bind def /D{0 exch 0 SC 5 2 roll awidthshow}bind def /E{0 rmoveto show}bind def /F{0 rmoveto 0 SC 3 -1 roll widthshow}bind def /G{0 rmoveto 0 exch ashow}bind def /H{0 rmoveto 0 exch 0 SC 5 2 roll awidthshow}bind def /I{0 exch rmoveto show}bind def /J{0 exch rmoveto 0 SC 3 -1 roll widthshow}bind def /K{0 exch rmoveto 0 exch ashow}bind def /L{0 exch rmoveto 0 exch 0 SC 5 2 roll awidthshow}bind def /M{rmoveto show}bind def /N{rmoveto 0 SC 3 -1 roll widthshow}bind def /O{rmoveto 0 exch ashow}bind def /P{rmoveto 0 exch 0 SC 5 2 roll awidthshow}bind def /Q{moveto show}bind def /R{moveto 0 SC 3 -1 roll widthshow}bind def /S{moveto 0 exch ashow}bind def /T{moveto 0 exch 0 SC 5 2 roll awidthshow}bind def /SF{ findfont exch [exch dup 0 exch 0 exch neg 0 0]makefont dup setfont [exch/setfont cvx]cvx bind def }bind def /MF{ findfont [5 2 roll 0 3 1 roll neg 0 0]makefont dup setfont [exch/setfont cvx]cvx bind def }bind def /level0 0 def /RES 0 def /PL 0 def /LS 0 def /MANUAL{ statusdict begin/manualfeed true store end }bind def /PLG{ gsave newpath clippath pathbbox grestore exch pop add exch pop }bind def /BP{ /level0 save def 1 setlinecap 1 setlinejoin 72 RES div dup scale LS{ 90 rotate }{ 0 PL translate }ifelse 1 -1 scale }bind def /EP{ level0 restore showpage }bind def /DA{ newpath arcn stroke }bind def /SN{ transform .25 sub exch .25 sub exch round .25 add exch round .25 add exch itransform }bind def /DL{ SN moveto SN lineto stroke }bind def /DC{ newpath 0 360 arc closepath }bind def /TM matrix def /DE{ TM currentmatrix pop translate scale newpath 0 0 .5 0 360 arc closepath TM setmatrix }bind def /RC/rcurveto load def /RL/rlineto load def /ST/stroke load def /MT/moveto load def /CL/closepath load def /FL{ currentgray exch setgray fill setgray }bind def /BL/fill load def /LW/setlinewidth load def /RE{ findfont dup maxlength 1 index/FontName known not{1 add}if dict begin { 1 index/FID ne{def}{pop pop}ifelse }forall /Encoding exch def dup/FontName exch def currentdict end definefont pop }bind def /DEFS 0 def /EBEGIN{ moveto DEFS begin }bind def /EEND/end load def /CNT 0 def /level1 0 def /PBEGIN{ /level1 save def translate div 3 1 roll div exch scale neg exch neg exch translate 0 setgray 0 setlinecap 1 setlinewidth 0 setlinejoin 10 setmiterlimit []0 setdash /setstrokeadjust where{ pop false setstrokeadjust }if /setoverprint where{ pop false setoverprint }if newpath /CNT countdictstack def userdict begin /showpage{}def }bind def /PEND{ clear countdictstack CNT sub{end}repeat level1 restore }bind def end def /setpacking where{ pop setpacking }if %%EndResource %%IncludeResource: font Times-Roman %%IncludeResource: font Times-Italic %%IncludeResource: font Times-Bold %%IncludeResource: font Symbol grops begin/DEFS 1 dict def DEFS begin/u{.001 mul}bind def end/RES 72 def/PL 792 def/LS false def/ENC0[/asciicircum/asciitilde/Scaron/Zcaron /scaron/zcaron/Ydieresis/trademark/quotesingle/.notdef/.notdef/.notdef /.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef /.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef /.notdef/.notdef/space/exclam/quotedbl/numbersign/dollar/percent /ampersand/quoteright/parenleft/parenright/asterisk/plus/comma/hyphen /period/slash/zero/one/two/three/four/five/six/seven/eight/nine/colon /semicolon/less/equal/greater/question/at/A/B/C/D/E/F/G/H/I/J/K/L/M/N/O /P/Q/R/S/T/U/V/W/X/Y/Z/bracketleft/backslash/bracketright/circumflex /underscore/quoteleft/a/b/c/d/e/f/g/h/i/j/k/l/m/n/o/p/q/r/s/t/u/v/w/x/y /z/braceleft/bar/braceright/tilde/.notdef/quotesinglbase/guillemotleft /guillemotright/bullet/florin/fraction/perthousand/dagger/daggerdbl /endash/emdash/ff/fi/fl/ffi/ffl/dotlessi/dotlessj/grave/hungarumlaut /dotaccent/breve/caron/ring/ogonek/quotedblleft/quotedblright/oe/lslash /quotedblbase/OE/Lslash/.notdef/exclamdown/cent/sterling/currency/yen /brokenbar/section/dieresis/copyright/ordfeminine/guilsinglleft /logicalnot/minus/registered/macron/degree/plusminus/twosuperior /threesuperior/acute/mu/paragraph/periodcentered/cedilla/onesuperior /ordmasculine/guilsinglright/onequarter/onehalf/threequarters /questiondown/Agrave/Aacute/Acircumflex/Atilde/Adieresis/Aring/AE /Ccedilla/Egrave/Eacute/Ecircumflex/Edieresis/Igrave/Iacute/Icircumflex /Idieresis/Eth/Ntilde/Ograve/Oacute/Ocircumflex/Otilde/Odieresis /multiply/Oslash/Ugrave/Uacute/Ucircumflex/Udieresis/Yacute/Thorn /germandbls/agrave/aacute/acircumflex/atilde/adieresis/aring/ae/ccedilla /egrave/eacute/ecircumflex/edieresis/igrave/iacute/icircumflex/idieresis /eth/ntilde/ograve/oacute/ocircumflex/otilde/odieresis/divide/oslash /ugrave/uacute/ucircumflex/udieresis/yacute/thorn/ydieresis]def /Times-Bold@0 ENC0/Times-Bold RE/Times-Italic@0 ENC0/Times-Italic RE /Times-Roman@0 ENC0/Times-Roman RE %%EndProlog %%Page: 1 1 %%BeginPageSetup BP %%EndPageSetup /F0 10/Times-Roman@0 SF(-)72 11 Q/F1 16/Times-Roman@0 SF (The Unix I/O System)237.336 130 Q/F2 10/Times-Italic@0 SF (Dennis M. Ritc)269.83 159 Q(hie)-.15 E(Bell T)249.035 170 Q (elephone Labor)-.92 E(atories)-.15 E F0 .494(This paper gi)72 231.4 R -.15(ve)-.25 G 2.994(sa).15 G 2.994(no)-2.994 G -.15(ve)-3.144 G(rvie) .15 E 2.994(wo)-.25 G 2.994(ft)-2.994 G .494(he w)-2.994 F .494 (orkings of the Unix I/O system.)-.1 F .493(It w)5.493 F .493 (as written with an e)-.1 F .493(ye to)-.15 F -.1(wa)-.25 G .493(rd pro) .1 F(viding)-.15 E .46(guidance to writers of de)72 242.4 R .46 (vice dri)-.25 F -.15(ve)-.25 G 2.96(rr).15 G .461 (outines, and is oriented more to)-2.96 F -.1(wa)-.25 G .461 (rd describing the en).1 F .461(vironment and nature of)-.4 F(de)72 253.4 Q(vice dri)-.25 E -.15(ve)-.25 G(rs than the implementation of th\ at part of the \214le system which deals with ordinary \214les.).15 E .393(It is assumed that the reader has a good kno)72 269.9 R .392 (wledge of the o)-.25 F -.15(ve)-.15 G .392 (rall structure of the \214le system as discussed in the pa-).15 F .265 (per `)72 280.9 R .265(`The Unix T)-.74 F .265(ime-sharing System.)-.35 F 4.245 -.74('' M)-.7 H(oreo).74 E -.15(ve)-.15 G 2.765(rt).15 G .265 (he present document is intended to be used in conjunction with a)-2.765 F(cop)72 291.9 Q 2.5(yo)-.1 G 2.5(ft)-2.5 G (he system code, since it is basically an e)-2.5 E -.15(xeg)-.15 G (esis of that code.).15 E/F3 10/Times-Bold@0 SF(De)72 313.9 Q (vice Classes)-.15 E F0 .924(There are tw)72 330.4 R 3.424(oc)-.1 G .924 (lasses of de)-3.424 F(vice:)-.25 E F2(bloc)3.424 E(k)-.2 E F0(and)3.424 E F2 -.15(ch)3.424 G(ar).15 E(acter)-.15 E(.)-1.11 E F0 .924 (The block interf)5.924 F .924(ace is suitable for de)-.1 F .924 (vices lik)-.25 F 3.423(ed)-.1 G .923(isks, tapes,)-3.423 F .208 (and DECtape which w)72 341.4 R .209(ork, or can w)-.1 F .209 (ork, with addressible 512-byte blocks.)-.1 F .209 (Ordinary magnetic tape just barely \214ts in)5.209 F .699(this cate)72 352.4 R(gory)-.15 E 3.199(,s)-.65 G .699(ince by use of forw)-3.199 F .699(ard backw)-.1 F .699(ard spacing an)-.1 F 3.199(yb)-.15 G .699 (lock can be read, e)-3.199 F -.15(ve)-.25 G 3.199(nt).15 G .699 (hough blocks can be written)-3.199 F .782(only at the end of the tape.) 72 363.4 R .782(Block de)5.782 F .782 (vices can at least potentially contain a mounted \214le system.)-.25 F .782(The interf)5.782 F .782(ace to)-.1 F .245(block de)72 374.4 R .245 (vices is v)-.25 F .245(ery highly structured; the dri)-.15 F -.15(ve) -.25 G .244(rs for these de).15 F .244(vices share a great man)-.25 F 2.744(yr)-.15 G .244(outines as well as a pool of)-2.744 F -.2(bu)72 385.4 S -.25(ff).2 G(ers.).25 E(Character)72 401.9 Q .271(-type de)-.2 F .271(vices ha)-.25 F .571 -.15(ve a m)-.2 H .271(uch more straightforw) .15 F .271(ard interf)-.1 F .271(ace, although more w)-.1 F .272 (ork must be done by the dri)-.1 F -.15(ve)-.25 G(r).15 E(itself.)72 412.9 Q(De)72 429.4 Q .653(vices of both types are named by a)-.25 F F2 (major)3.153 E F0 .653(and a)3.153 F F2(minor)3.152 E F0(de)3.152 E .652 (vice number)-.25 F 5.652(.T)-.55 G .652 (hese numbers are generally stored as a)-5.652 F -.1(wo)72 440.4 S .027 (rd with the minor de).1 F .027(vice number as the lo)-.25 F 2.527(wb) -.25 G .027(yte and the major de)-2.527 F .027 (vice number as the high byte.)-.25 F .028(The major de)5.028 F(vice) -.25 E .202(number selects which dri)72 451.4 R -.15(ve)-.25 G 2.702(rw) .15 G .202(ill deal with the de)-2.702 F .202(vice; the minor de)-.25 F .202(vice number is not used by the rest of the system)-.25 F -.2(bu)72 462.4 S 2.988(ti).2 G 2.989(sp)-2.988 G .489(assed to the dri)-2.989 F -.15(ve)-.25 G 2.989(ra).15 G 2.989(ta)-2.989 G .489(ppropriate times.) -2.989 F -.8(Ty)5.489 G .489(pically the minor number selects a subde).8 F .489(vice attached to a gi)-.25 F -.15(ve)-.25 G(n).15 E(controller)72 473.4 Q 2.5(,o)-.4 G 2.5(ro)-2.5 G(ne of se)-2.5 E -.15(ve)-.25 G (ral similar hardw).15 E(are interf)-.1 E(aces.)-.1 E .3(The major de)72 489.9 R .3(vice numbers for block and character de)-.25 F .299 (vices are used as indices in separate tables; the)-.25 F 2.799(yb)-.15 G .299(oth start at 0)-2.799 F(and therefore o)72 500.9 Q -.15(ve)-.15 G (rlap.).15 E F3(Ov)72 522.9 Q(er)-.1 E(view of I/O)-.1 E F0 .282 (The purpose of the)72 539.4 R F2(open)2.782 E F0(and)2.782 E F2(cr) 2.782 E(eat)-.37 E F0 .283 (system calls is to set up entries in three separate system tables.) 2.783 F .283(The \214rst of these)5.283 F .276(is the)72 550.4 R .4 LW 106.442 552.9 101.442 552.9 DL F2 5(uo)96.442 550.4 S(\214le)-5 E F0 .276(table, which is stored in the system')2.776 F 2.776(sp)-.55 G(er) -2.776 E .276(-process data area)-.2 F F2(u.)2.776 E F0 .275 (This table is inde)5.276 F -.15(xe)-.15 G 2.775(db).15 G 2.775(yt) -2.775 G .275(he \214le descrip-)-2.775 F .317(tor returned by the)72 561.4 R F2(open)2.817 E F0(or)2.817 E F2(cr)2.817 E(eat,)-.37 E F0 .317 (and is accessed during a)2.817 F F2 -.37(re)2.817 G .317(ad, write).37 F(,)-.1 E F0 .318(or other operation on the open \214le.)2.817 F .318 (An entry)5.318 F .157 (contains only a pointer to the corresponding entry of the)72 572.4 R F2 (\214le)2.657 E F0 .157(table, which is a per)2.657 F .156 (-system data base.)-.2 F .156(There is one en-)5.156 F .192(try in the) 72 583.4 R F2(\214le)2.692 E F0 .192(table for each instance of)2.692 F F2(open)2.692 E F0(or)2.692 E F2(cr)2.692 E(eat.)-.37 E F0 .192 (This table is per)5.192 F .193 (-system because the same instance of an open)-.2 F .312 (\214le must be shared among the se)72 594.4 R -.15(ve)-.25 G .312 (ral processes which can result from).15 F F2(forks)2.812 E F0 .312 (after the \214le is opened.)2.812 F(A)5.312 E F2(\214le)2.812 E F0 .311 (table en-)2.811 F .51 (try contains \215ags which indicate whether the \214le w)72 605.4 R .511(as open for reading or writing or is a pipe, and a count which is) -.1 F .187(used to decide when all processes using the entry ha)72 616.4 R .487 -.15(ve t)-.2 H .186 (erminated or closed the \214le \(so the entry can be abandoned\).).15 F .288(There is also a 32-bit \214le of)72 627.4 R .288 (fset which is used to indicate where in the \214le the ne)-.25 F .288 (xt read or write will tak)-.15 F 2.788(ep)-.1 G 2.788(lace. Fi-)-2.788 F(nally)72 638.4 Q 2.896(,t)-.65 G .395 (here is a pointer to the entry for the \214le in the)-2.896 F F2(inode) 2.895 E F0 .395(table, which contains a cop)2.895 F 2.895(yo)-.1 G 2.895 (ft)-2.895 G .395(he \214le')-2.895 F 2.895(si)-.55 G 2.895 (-node. Notice)-2.895 F .327(that an entry in the)72 649.4 R F2(\214le) 2.827 E F0 .327(table corresponds precisely to an instance of)2.827 F F2 (open)2.827 E F0(or)2.827 E F2(cr)2.827 E(eat;)-.37 E F0 .328 (if the same \214le is opened se)2.827 F -.15(ve)-.25 G(ral).15 E .181 (times, it will ha)72 660.4 R .481 -.15(ve s)-.2 H -2.15 -.25(ev e).15 H .181(ral entries in this table.).25 F(Ho)5.181 E(we)-.25 E -.15(ve)-.25 G .981 -.4(r, t).15 H .18(here is at most one entry in the).4 F F2 (inode)2.68 E F0 .18(table for a gi)2.68 F -.15(ve)-.25 G 2.68<6e8c>.15 G(le.)-2.68 E .25(Also, a \214le may enter the)72 671.4 R F2(inode)2.751 E F0 .251(table not only because it is open, b)2.751 F .251 (ut also because it is the current directory of some)-.2 F(process or b\ ecause it is a special \214le containing a currently-mounted \214le sys\ tem.)72 682.4 Q .466(An entry in the)72 698.9 R F2(inode)2.966 E F0 .465 (table dif)2.966 F .465(fers some)-.25 F .465(what from the correspondi\ ng i-node as stored on the disk; the modi\214ed and)-.25 F .713(accesse\ d times are not stored, and the entry is augmented by a \215ag w)72 709.9 R .713(ord containing information about the entry)-.1 F 3.214(,a) -.65 G(count used to determine when it may be allo)72 720.9 Q (wed to disappear)-.25 E 2.5(,a)-.4 G(nd the de)-2.5 E (vice and i-number whence the entry came.)-.25 E EP %%Page: 2 2 %%BeginPageSetup BP %%EndPageSetup /F0 10/Times-Roman@0 SF(-)72 11 Q/F1 10/Times-Italic@0 SF 2.5(2-U)72 58 S(nix I/O System)-2.5 E F0 .319(During the processing of an)72 105 R F1 (open)2.818 E F0(or)2.818 E F1(cr)2.818 E(eat)-.37 E F0 .318 (call for a special \214le, the system al)2.818 F -.1(wa)-.1 G .318 (ys calls the de).1 F(vice')-.25 E(s)-.55 E F1(open)2.818 E F0 .318 (routine to)2.818 F(allo)72 116 Q 3.568(wf)-.25 G 1.068(or an)-3.568 F 3.568(ys)-.15 G 1.068(pecial processing required \(re)-3.568 F 1.068 (winding a tape, turning on the data-terminal-ready lead of a modem,) -.25 F 2.87(etc.\). Ho)72 127 R(we)-.25 E -.15(ve)-.25 G 1.169 -.4(r, t) .15 H(he).4 E F1(close)2.869 E F0 .369(routine is called only when the \ last process closes a \214le, that is, when the i-node table en-)2.869 F .314(try is being deallocated.)72 138 R .314 (Thus it is not feasible for a de)5.314 F .315 (vice to maintain, or depend on, a count of its users, although)-.25 F (it is quite possible to implement an e)72 149 Q(xclusi)-.15 E -.15(ve) -.25 G(-use de).15 E (vice which cannot be reopened until it has been closed.)-.25 E 1.566 (When a)72 165.5 R F1 -.37(re)4.066 G(ad).37 E F0(or)4.066 E F1(write) 4.066 E F0(tak)4.066 E 1.566(es place, the user')-.1 F 4.066(sa)-.55 G -.18(rg)-4.066 G 1.566(uments and the).18 F F1(\214le)4.066 E F0 1.565 (table entry are used to set up the v)4.066 F(ariables)-.25 E .4 LW 89.5 179 84.5 179 DL F1 2.5(u.u base)72 176.5 R 3.65(,u)-.1 G 131.38 179 126.38 179 DL 2.5(.u count,)118.88 176.5 R F0(and)3.65 E 195.34 179 190.34 179 DL F1 2.5(u.u of)177.84 176.5 R(fset)-.18 E F0 1.15 (which respecti)3.65 F -.15(ve)-.25 G 1.15 (ly contain the \(user\) address of the I/O tar).15 F 1.15 (get area, the byte-)-.18 F .094(count for the transfer)72 187.5 R 2.594 (,a)-.4 G .094(nd the current location in the \214le.)-2.594 F .093 (If the \214le referred to is a character)5.094 F .093 (-type special \214le, the ap-)-.2 F .324(propriate read or write routi\ ne is called; it is responsible for transferring data and updating the \ count and current lo-)72 198.5 R .371 (cation appropriately as discussed belo)72 209.5 R 4.171 -.65(w. O)-.25 H .37(therwise, the current location is used to calculate a logical blo\ ck number).65 F .316(in the \214le.)72 220.5 R .317(If the \214le is an\ ordinary \214le the logical block number must be mapped \(possibly usi\ ng an indirect block\))5.316 F .255(to a ph)72 231.5 R .254 (ysical block number; a block-type special \214le need not be mapped.) -.05 F .254(In an)5.254 F 2.754(ye)-.15 G -.15(ve)-3.004 G .254 (nt, the resulting ph).15 F .254(ysical block)-.05 F (number is used, as discussed belo)72 242.5 Q 1.3 -.65(w, t)-.25 H 2.5 (or).65 G(ead or write the appropriate de)-2.5 E(vice.)-.25 E/F2 10 /Times-Bold@0 SF(Character de)72 264.5 Q(vice dri)-.15 E -.1(ve)-.1 G (rs).1 E F0(The)72 281 Q F1(cde)3.241 E(vsw)-.15 E F0 .741 (table speci\214es the interf)3.241 F .741 (ace routines present for character de)-.1 F 3.242(vices. Each)-.25 F (de)3.242 E .742(vice pro)-.25 F .742(vides \214v)-.15 F 3.242(er)-.15 G (outines:)-3.242 E .717(open, close, read, write, and special-function.) 72 292 R(An)5.717 E 3.217(yo)-.15 G 3.217(ft)-3.217 G .717 (hese may be missing.)-3.217 F .717 (If a call on the routine should be ig-)5.717 F .724(nored, \(e.g.)72 303 R F1(open)5.724 E F0 .724(on non-e)3.224 F(xclusi)-.15 E 1.024 -.15 (ve d)-.25 H -.25(ev).15 G .725(ices which require no setup\) the).25 F F1(cde)3.225 E(vsw)-.15 E F0 .725(entry can be gi)3.225 F -.15(ve)-.25 G 3.225(na).15 G(s)-3.225 E F1(nullde)3.225 E(v;)-.15 E F0 .725(if it) 3.225 F(should be considered an error)72 314 Q 2.5(,\()-.4 G(e.g.)-2.5 E F1(write)5 E F0(on read-only de)2.5 E(vices\))-.25 E F1(node)2.5 E(v) -.15 E F0(is used.)2.5 E(The)72 330.5 Q F1(open)3.102 E F0 .602 (routine is called each time the \214le is opened with the full de)3.102 F .601(vice number as ar)-.25 F 3.101(gument. The)-.18 F .601(second ar) 3.101 F(gu-)-.18 E(ment is a \215ag which is non-zero only if the de)72 341.5 Q(vice is to be written upon.)-.25 E(The)72 358 Q F1(close)3.001 E F0 .502(routine is called only when the \214le is closed for the last t\ ime, that is when the v)3.001 F .502(ery last process in which)-.15 F .315(the \214le is open closes it.)72 369 R .315 (This means it is not possible for the dri)5.315 F -.15(ve)-.25 G 2.814 (rt).15 G 2.814(om)-2.814 G .314(aintain its o)-2.814 F .314 (wn count of its users.)-.25 F .314(The \214rst)5.314 F(ar)72 380 Q .365 (gument is the de)-.18 F .366 (vice number; the second is a \215ag which is non-zero if the \214le w) -.25 F .366(as open for writing in the process)-.1 F (which performs the \214nal)72 391 Q F1(close)2.5 E(.)-.15 E F0(When)72 407.5 Q F1(write)2.559 E F0 .059(is called, it is supplied the de)2.559 F .059(vice as ar)-.25 F 2.559(gument. The)-.18 F(per)2.559 E .059 (-user v)-.2 F(ariable)-.25 E 417.996 410 412.996 410 DL F1 2.5 (u.u count)400.496 407.5 R F0 .059(has been set to the num-)2.559 F .167 (ber of characters indicated by the user; for character de)72 418.5 R .167(vices, this number may be 0 initially)-.25 F(.)-.65 E 464.789 421 459.789 421 DL F1 2.5(u.u base)447.289 418.5 R F0 .167(is the address) 2.667 F .868 (supplied by the user from which to start taking characters.)72 429.5 R .868(The system may call the routine internally)5.868 F 3.368(,s)-.65 G 3.367(ot)-3.368 G .867(he \215ag)-3.367 F 89.5 443 84.5 443 DL F1 2.5 (u.u se)72 440.5 R(g\215g)-.4 E F0(is supplied which indicates, if)2.5 E F1(on,)2.5 E F0(that)2.5 E 286.59 443 281.59 443 DL F1 2.5(u.u base) 269.09 440.5 R F0 (refers to the system address space instead of the user')2.5 E(s.)-.55 E (The)72 457 Q F1(write)4.86 E F0 2.36(routine should cop)4.86 F 4.86(yu) -.1 G 4.86(pt)-4.86 G(o)-4.86 E 251.751 459.5 246.751 459.5 DL F1 2.5 (u.u count)234.251 457 R F0 2.361(characters from the user')4.861 F 4.861(sb)-.55 G(uf)-5.061 E 2.361(fer to the de)-.25 F 2.361 (vice, decrementing)-.25 F 89.5 470.5 84.5 470.5 DL F1 2.5(u.u count)72 468 R F0(for each character passed.)2.5 E -.15(Fo)5 G 2.5(rm).15 G (ost dri)-2.5 E -.15(ve)-.25 G(rs, which w).15 E (ork one character at a time, the routine)-.1 E F1(cpass\( \))122 484.5 Q F0 .808(is used to pick up characters from the user')72 501 R 3.308 (sb)-.55 G(uf)-3.508 E(fer)-.25 E 5.808(.S)-.55 G(uccessi)-5.808 E 1.108 -.15(ve c)-.25 H .808 (alls on it return the characters to be written until).15 F 89.5 514.5 84.5 514.5 DL F1 2.5(u.u count)72 512 R F0 .107 (goes to 0 or an error occurs, when it returns)2.606 F/F3 10/Symbol SF (-)2.607 E F0(1.)A F1(Cpass)5.107 E F0(tak)2.607 E .107 (es care of interrog)-.1 F(ating)-.05 E 462.416 514.5 457.416 514.5 DL F1 2.5(u.u se)444.916 512 R(g\215g)-.4 E F0 .107(and updating)2.607 F 89.5 525.5 84.5 525.5 DL F1 2.5(u.u count.)72 523 R F0 .305 (Write routines which w)72 539.5 R .305(ant to transfer a probably lar) -.1 F .305(ge number of characters into an internal b)-.18 F(uf)-.2 E .304(fer may also use the)-.25 F(routine)72 550.5 Q F1(iomo)122 567 Q (ve\(b)-.1 E(uf)-.2 E(fer)-.18 E 2.5(,o)-1.11 G -.18(ff)-2.5 G (set, count, \215a).18 E(g\))-.1 E F0 .476(which is f)72 583.5 R .476 (aster when man)-.1 F 2.976(yc)-.15 G .477(haracters must be mo)-2.976 F -.15(ve)-.15 G(d.).15 E F1(Iomo)5.477 E(ve)-.1 E F0 .477 (transfers up to)2.977 F F1(count)2.977 E F0 .477(characters into the) 2.977 F F1 -.2(bu)2.977 G -.18(ff).2 G(er).18 E F0(start-)2.977 E(ing)72 594.5 Q F1(of)3.461 E(fset)-.18 E F0 .961(bytes from the start of the b) 3.461 F(uf)-.2 E(fer;)-.25 E F1<8d61>3.461 E(g)-.1 E F0 .96(should be) 3.461 F 327.22 597 322.22 597 DL F1 5(BW)316.11 594.5 S(RITE)-5 E F0 .96 (\(which is 0\) in the write case.)3.46 F .96(Caution: the)5.96 F 1.118 (caller is responsible for making sure the count is not too lar)72 605.5 R 1.119(ge and is non-zero.)-.18 F 1.119(As an ef)6.119 F(\214cienc)-.25 E 3.619(yn)-.15 G(ote,)-3.619 E F1(iomo)3.619 E(ve)-.1 E F0(is)3.619 E (much slo)72 616.5 Q(wer if an)-.25 E 2.5(yo)-.15 G(f)-2.5 E F1 -.2(bu) 2.5 G -.18(ff).2 G(er+of).18 E(fset, count)-.18 E F0(or)2.5 E 271.66 619 266.66 619 DL F1 2.5(u.u base)254.16 616.5 R F0(is odd.)2.5 E .465 (The de)72 633 R(vice')-.25 E(s)-.55 E F1 -.37(re)2.965 G(ad).37 E F0 .465(routine is called under conditions similar to)2.965 F F1(write) 2.965 E(,)-.1 E F0 -.15(ex)2.965 G .465(cept that).15 F 416.865 635.5 411.865 635.5 DL F1 2.5(u.u count)399.365 633 R F0 .465 (is guaranteed to be non-)2.965 F 2.5(zero. T)72 644 R 2.5(or)-.8 G (eturn characters to the user)-2.5 E 2.5(,t)-.4 G(he routine)-2.5 E F1 (passc\(c\))122 660.5 Q F0 .154(is a)72 677 R -.25(va)-.2 G .154 (ilable; it tak).25 F .154(es care of housek)-.1 F .154(eeping lik)-.1 F (e)-.1 E F1(cpass)2.654 E F0 .154(and returns)2.654 F F3(-)2.654 E F0 2.654(1a)C 2.654(st)-2.654 G .154(he last character speci\214ed by) -2.654 F 494.702 679.5 489.702 679.5 DL F1 2.5(u.u count)477.202 677 R F0 .154(is re-)2.654 F .574 (turned to the user; before that time, 0 is returned.)72 688 R F1(Iomo) 5.574 E(ve)-.1 E F0 .574(is also usable as with)3.074 F F1(write;)3.074 E F0 .573(the \215ag should be)3.074 F 514.45 690.5 509.45 690.5 DL F1 5 (BR)503.34 688 S(EAD)-5 E F0 -.2(bu)72 699 S 2.5(tt).2 G (he same cautions apply)-2.5 E(.)-.65 E(The `)72 715.5 Q (`special-functions')-.74 E 2.5('r)-.74 G(outine is in)-2.5 E -.2(vo)-.4 G -.1(ke).2 G 2.5(db).1 G 2.5(yt)-2.5 G(he)-2.5 E F1(stty)2.5 E F0(and) 2.5 E F1(gtty)2.5 E F0(system calls as follo)2.5 E(ws:)-.25 E EP %%Page: 3 3 %%BeginPageSetup BP %%EndPageSetup /F0 10/Times-Roman@0 SF(-)72 11 Q/F1 10/Times-Italic@0 SF (Unix I/O System - 3)461.13 58 Q(\(*p\) \(de)122 105 Q 1.48 -.74(v, v) -.15 H(\)).74 E F0(where)72 121.5 Q F1(p)2.615 E F0 .115 (is a pointer to the de)2.615 F(vice')-.25 E 2.615(sr)-.55 G(outine,) -2.615 E F1(de)2.615 E(v)-.15 E F0 .115(is the de)2.615 F .115 (vice number)-.25 F 2.615(,a)-.4 G(nd)-2.615 E F1(v)2.615 E F0 .115 (is a v)2.615 F(ector)-.15 E 5.115(.I)-.55 G 2.615(nt)-5.115 G(he)-2.615 E F1(gtty)2.616 E F0 .116(case, the de)2.616 F .116(vice is)-.25 F .554 (supposed to place up to 3 w)72 132.5 R .554 (ords of status information into the v)-.1 F .553 (ector; this will be returned to the caller)-.15 F 5.553(.I)-.55 G 3.053 (nt)-5.553 G(he)-3.053 E F1(stty)3.053 E F0(case,)72 143.5 Q F1(v)2.5 E F0(is 0; the de)2.5 E(vice should tak)-.25 E 2.5(eu)-.1 G 2.5(pt)-2.5 G 2.5(o3w)-2.5 G(ords of control information from the array)-2.6 E .4 LW 437.6 146 432.6 146 DL F1 2.5(u.u ar)420.1 143.5 R(g[0...2].)-.37 E F0 (Finally)72 160 Q 2.705(,e)-.65 G .205(ach de)-2.705 F .205 (vice should ha)-.25 F .505 -.15(ve a)-.2 H .205 (ppropriate interrupt-time routines.).15 F .206 (When an interrupt occurs, it is turned into a C-)5.205 F .501 (compatible call on the de)72 171 R(vices')-.25 E 3.001(si)-.55 G .501 (nterrupt routine.)-3.001 F .501(The interrupt-catching mechanism mak) 5.501 F .5(es the lo)-.1 F .5(w-order four bits)-.25 F .713(of the `)72 182 R(`ne)-.74 E 3.213(wP)-.25 G(S')-3.213 E 3.213('w)-.74 G .713 (ord in the trap v)-3.313 F .713(ector for the interrupt a)-.15 F -.25 (va)-.2 G .713(ilable to the interrupt handler).25 F 5.714(.T)-.55 G .714(his is con)-5.714 F -.15(ve)-.4 G(ntionally).15 E .19(used by dri) 72 193 R -.15(ve)-.25 G .19(rs which deal with multiple similar de).15 F .189(vices to encode the minor de)-.25 F .189(vice number)-.25 F 5.189 (.A)-.55 G .189(fter the interrupt has)-5.189 F(been processed, a retur\ n from the interrupt handler will return from the interrupt itself.)72 204 Q 3.005(An)72 220.5 S .505(umber of subroutines are a)-3.005 F -.25 (va)-.2 G .505(ilable which are useful to character de).25 F .506 (vice dri)-.25 F -.15(ve)-.25 G 3.006(rs. Most).15 F .506 (of these handlers, for e)3.006 F(x-)-.15 E .48 (ample, need a place to b)72 231.5 R(uf)-.2 E .479 (fer characters in the internal interf)-.25 F .479(ace between their `) -.1 F .479(`top half)-.74 F 1.959 -.74('' \().55 H .479 (read/write\) and `).74 F(`bottom)-.74 E -1.95(half ')72 242.5 R 3.864 ('\()-.74 G 1.364(interrupt\) routines.)-3.864 F -.15(Fo)6.364 G 3.864 (rr).15 G(elati)-3.864 E -.15(ve)-.25 G 1.364(ly lo).15 F 3.864(wd)-.25 G 1.364(ata-rate de)-3.864 F 1.364 (vices, the best mechanism is the character queue main-)-.25 F (tained by the routines)72 253.5 Q F1 -.1(ge)2.5 G(tc).1 E F0(and)2.5 E F1(putc.)2.5 E F0 2.5(Aq)5 G(ueue header has the structure)-2.5 E F1 (struct {)122 270 Q 203.44 283.5 198.44 283.5 DL 22.94(int c)158 281 R 11.85(cc; /*)5 F -.15(ch)2.5 G(ar).15 E(acter count */)-.15 E -.15(ch) 158 292 S 208.44 294.5 203.44 294.5 DL 15.32(ar *c)167.29 292 R 8.51 (cf; /*)5 F<8c72>2.5 E(st c)-.1 E(har)-.15 E(acter */)-.15 E -.15(ch)158 303 S 208.44 305.5 203.44 305.5 DL 15.32(ar *c)167.29 303 R 8.51(cl; /*) 5 F(last c)2.5 E(har)-.15 E(acter */)-.15 E 2.5(}q)122 314 S(ueue;)-2.5 E F0 2.5(Ac)72 330.5 S(haracter is placed on the end of a queue by)-2.5 E F1(putc\(c, &queue\))122 347 Q F0(where)72 363.5 Q F1(c)2.7 E F0 .2 (is the character and)2.7 F F1(queue)2.7 E F0 .2(is the queue header)2.7 F 5.2(.T)-.55 G .2(he routine returns)-5.2 F/F2 10/Symbol SF(-)2.699 E F0 2.699(1i)C 2.699(ft)-2.699 G .199 (here is no space to put the charac-)-2.699 F(ter)72 374.5 Q 2.5(,0o)-.4 G 2.5(therwise. The)-2.5 F(\214rst character on the queue may be retrie) 2.5 E -.15(ve)-.25 G 2.5(db).15 G(y)-2.5 E F1 -.1(ge)122 391 S (tc\(&queue\)).1 E F0(which returns either the \(non-ne)72 407.5 Q -.05 (ga)-.15 G(ti).05 E -.15(ve)-.25 G 2.5(\)c).15 G(haracter or)-2.5 E F2 (-)2.5 E F0 2.5(1i)C 2.5(ft)-2.5 G(he queue is empty)-2.5 E(.)-.65 E .528 (Notice that the space for characters in queues is shared among all de) 72 424 R .528(vices in the system and in the standard system)-.25 F .344 (there are only some 600 character slots a)72 435 R -.25(va)-.2 G 2.844 (ilable. Thus).25 F(de)2.844 E .344 (vice handlers, especially write routines, must tak)-.25 F 2.844(ec)-.1 G .344(are to)-2.844 F -.2(avo)72 446 S(id gobbling up e).2 E(xcessi) -.15 E .3 -.15(ve n)-.25 H(umbers of characters.).15 E (The other major help a)72 462.5 Q -.25(va)-.2 G(ilable to de).25 E (vice handlers is the sleep-w)-.25 E(ak)-.1 E(eup mechanism.)-.1 E (The call)5 E F1(sleep\(e)122 479 Q(vent, priority\))-.15 E F0 .087 (causes the process to w)72 495.5 R .087(ait \(allo)-.1 F .087 (wing other processes to run\) until the)-.25 F F1 -.15(ev)2.587 G(ent) .15 E F0 .087(occurs; at that time, the process is mark)2.587 F(ed)-.1 E (ready-to-run and the call will return when there is no process with hi\ gher)72 506.5 Q F1(priority)2.5 E(.)-.55 E F0(The call)72 523 Q F1(wak) 122 539.5 Q(eup\(e)-.1 E(vent\))-.15 E F0 .014(indicates that the)72 556 R F1 -.15(ev)2.514 G(ent).15 E F0 .014 (has happened, that is, causes processes sleeping on the e)2.514 F -.15 (ve)-.25 G .013(nt to be a).15 F -.1(wa)-.15 G -.1(ke).1 G 2.513 (ned. The).1 F F1 -.15(ev)2.513 G(ent).15 E F0 .013(is an)2.513 F .622 (arbitrary quantity agreed upon by the sleeper and the w)72 567 R(ak)-.1 E(er)-.1 E 3.123(-up. By)-.2 F(con)3.123 E -.15(ve)-.4 G .623 (ntion, it is the address of some data area).15 F(used by the dri)72 578 Q -.15(ve)-.25 G .8 -.4(r, w).15 H(hich guarantees that e).4 E -.15(ve) -.25 G(nts are unique.).15 E .051(Processes sleeping on an e)72 594.5 R -.15(ve)-.25 G .051(nt should not assume that the e).15 F -.15(ve)-.25 G .051(nt has really happened; the).15 F 2.551(ys)-.15 G .051 (hould check that the con-)-2.551 F (ditions which caused them to sleep no longer hold.)72 605.5 Q .049 (Priorities can range from 127 to)72 622 R F2(-)2.549 E F0 .049 (127; a higher numerical v)B .05(alue indicates a less-f)-.25 F -.2(avo) -.1 G .05(red scheduling situation.).2 F 2.55(Ap)5.05 G(ro-)-2.55 E 1.522(cess sleeping at ne)72 633 R -.05(ga)-.15 G(ti).05 E 1.821 -.15 (ve p)-.25 H 1.521(riority cannot be terminated for an).15 F 4.021(yr) -.15 G 1.521(eason, although it is concei)-4.021 F -.25(va)-.25 G 1.521 (ble that it may be).25 F(sw)72 644 Q .055(apped out.)-.1 F .056 (Thus it is a bad idea to sleep with ne)5.055 F -.05(ga)-.15 G(ti).05 E .356 -.15(ve p)-.25 H .056(riority on an e).15 F -.15(ve)-.25 G .056 (nt which might ne).15 F -.15(ve)-.25 G 2.556(ro).15 G(ccur)-2.556 E 5.056(.O)-.55 G 2.556(nt)-5.056 G .056(he other)-2.556 F .887 (hand, calls to)72 655 R F1(sleep)3.387 E F0 .887(with non-ne)3.387 F -.05(ga)-.15 G(ti).05 E 1.187 -.15(ve p)-.25 H .886(riority may ne).15 F -.15(ve)-.25 G 3.386(rr).15 G .886 (eturn if the process is terminated by some signal in the)-3.386 F 2.558 (meantime. Incidentally)72 666 R 2.558(,i)-.65 G 2.558(ti)-2.558 G 2.558 (sag)-2.558 G .058(ross error to call)-2.558 F F1(sleep)2.558 E F0 .058 (in a routine called at interrupt time, since the process which is)2.558 F .059 (running is almost certainly not the process which should go to sleep.) 72 677 R(Lik)5.058 E -.25(ew)-.1 G .058(ise, none of the v).25 F .058 (ariables in the user area)-.25 F -.74(``)72 688 S F1(u).74 E/F3 10 /Times-Bold@0 SF(.)A F0 3.98 -.74('' s)D (hould be touched, let alone changed, by an interrupt routine.).74 E .522(If a de)72 704.5 R .522(vice dri)-.25 F -.15(ve)-.25 G 3.023(rw).15 G .523(ishes to w)-3.023 F .523(ait for some e)-.1 F -.15(ve)-.25 G .523 (nt for which it is incon).15 F -.15(ve)-.4 G .523 (nient or impossible to supply a).15 F F1(wak)3.023 E(eup,)-.1 E F0 (\(for)3.023 E -.15(ex)72 715.5 S(ample, a de).15 E(vice going on-line,\ which does not generally cause an interrupt\), the call)-.25 E EP %%Page: 4 4 %%BeginPageSetup BP %%EndPageSetup /F0 10/Times-Roman@0 SF(-)72 11 Q/F1 10/Times-Italic@0 SF 2.5(4-U)72 58 S(nix I/O System)-2.5 E(sleep\(&lbolt, priority\))122 105 Q F0 .331 (may be gi)72 121.5 R -.15(ve)-.25 G(n.).15 E F1(Lbolt)5.331 E F0 .331 (is an e)2.831 F .331(xternal cell whose address is a)-.15 F -.1(wa)-.15 G -.1(ke).1 G .331(ned once e).1 F -.15(ve)-.25 G .331 (ry 4 seconds by the clock interrupt rou-).15 F(tine.)72 132.5 Q (The routines)72 149 Q F1(spl4\( \), spl5\( \), spl6\( \), spl7\( \))122 165.5 Q F0(are a)72 182 Q -.25(va)-.2 G (ilable to set the processor priority le).25 E -.15(ve)-.25 G 2.5(la).15 G 2.5(si)-2.5 G(ndicated to a)-2.5 E -.2(vo)-.2 G(id incon).2 E -.15(ve) -.4 G(nient interrupts from the de).15 E(vice.)-.25 E(If a de)72 198.5 Q (vice needs to kno)-.25 E 2.5(wa)-.25 G(bout real-time interv)-2.5 E (als, then)-.25 E F1(timeout\(func, ar)122 215 Q .2 -.1(g, i)-.37 H (nterval\)).1 E F0 .066(will be useful.)72 231.5 R .066 (This routine arranges that after)5.066 F F1(interval)2.567 E F0 .067 (sixtieths of a second, the)2.567 F F1(func)2.567 E F0 .067 (will be called with)2.567 F F1(ar)2.567 E(g)-.37 E F0 .067(as ar)2.567 F(gu-)-.18 E(ment, in the style)72 242.5 Q F1(\(*func\)\(ar)122 259 Q (g\))-.37 E F0 -.35(Ti)72 275.5 S .618(meouts are used, for e).35 F .618 (xample, to pro)-.15 F .618 (vide real-time delays after function characters lik)-.15 F 3.117(en)-.1 G -.25(ew)-3.117 G .617(-line and tab in type-).25 F .889 (writer output, and to terminate an attempt to read the 201 Dataphone)72 286.5 R F1(dp)3.39 E F0 .89 (if there is no response within a speci\214ed)3.39 F .648 (number of seconds.)72 297.5 R .648(Notice that the number of sixtieths\ of a second is limited to 32767, since it must appear to be)5.648 F (positi)72 308.5 Q -.15(ve)-.25 G 3.021(,a).15 G .521 (nd that only a bounded number of timeouts can be going on at once.) -3.021 F .522(Also, the speci\214ed)5.522 F F1(func)3.022 E F0 .522 (is called at)3.022 F(clock-interrupt time, so it should conform to the\ requirements of interrupt routines in general.)72 319.5 Q F1(An e)72 341.5 Q(xample)-.2 E F0 .304(The dri)72 358 R -.15(ve)-.25 G 2.804(rf) .15 G .304(or the paper)-2.804 F .304(-tape reader/punch is w)-.2 F .304 (orth e)-.1 F .304(xamining as a f)-.15 F .304(airly simple e)-.1 F .304 (xample of man)-.15 F 2.804(yo)-.15 G 2.803(ft)-2.804 G .303 (he techniques)-2.803 F .434(used in writing character de)72 369 R .434 (vice handlers.)-.25 F(The)5.434 E F1(pc11)2.934 E F0 .435 (structure contains a state \(used for the reader\), an input queue,) 2.934 F .316(and an output queue.)72 380 R 2.816(As)5.316 G .316 (tructure, rather than three indi)-2.816 F .316(vidual v)-.25 F .315 (ariables, w)-.25 F .315(as used to cut do)-.1 F .315 (wn on the number of e)-.25 F(x-)-.15 E (ternal symbols which might be confused with symbols in other routines.) 72 391 Q .649(When the \214le is opened for reading, the)72 407.5 R F1 (open)3.149 E F0 .649(routine checks to see if its state is not)3.149 F F1(CLOSED;)3.149 E F0 .65(if so an error is re-)3.149 F .38 (turned since it is considered a bad idea to let se)72 418.5 R -.15(ve) -.25 G .379(ral people read one tape simultaneously).15 F 5.379(.T)-.65 G .379(he state is set to)-5.379 F F1 -.6(WA)2.879 G(IT).6 E(-)-.74 E (ING,)72 429.5 Q F0 .485 (the interrupt is enabled, and a character is requested.)2.985 F .485 (The reason for this g)5.485 F .486(ambit is that there is no direct w) -.05 F(ay)-.1 E .729(to determine if there is an)72 440.5 R 3.228(yt) -.15 G .728(ape in the reader or if the reader is on-line.)-3.228 F .728 (In these situations an interrupt will occur)5.728 F .16 (immediately and an error indicated.)72 451.5 R .16 (As will be seen, the interrupt routine ignores errors if the state is) 5.16 F F1 -.6(WA)2.66 G(ITING,).6 E F0 -.2(bu)2.66 G(t).2 E .073 (if a good character comes in while in the)72 462.5 R F1 -.6(WA)2.573 G (ITING).6 E F0 .072(state the interrupt routine sets the state to)2.573 F F1(READING.)2.572 E F0(Thus)5.072 E F1(open)2.572 E F0 .896 (loops until the state changes, meanwhile sleeping on the `)72 473.5 R .896(`lightning bolt')-.74 F(')-.74 E F1(lbolt.)3.397 E F0 .897 (If it did not sleep at all, it w)5.897 F(ould)-.1 E(pre)72 484.5 Q -.15 (ve)-.25 G .217(nt an).15 F 2.717(yo)-.15 G .217(ther process from runn\ ing until the reader came on-line; if it depended on the interrupt rout\ ine to w)-2.717 F(ak)-.1 E(e)-.1 E(it up, the ef)72 495.5 Q(fect w)-.25 E(ould be the same, since the error interrupt is almost instantaneous.) -.1 E(The open-write case is much simpler; the punch is enabled and a 1\ 00-character leader is punched using)72 512 Q F1(pcleader)2.5 E(.)-1.11 E F0(The)72 528.5 Q F1(close)4.043 E F0 1.544 (routine is also simple; if the reader w)4.043 F 1.544(as open, an)-.1 F 4.044(yu)-.15 G 1.544 (ncollected characters are \215ushed, the interrupt is)-4.044 F .663 (turned of)72 539.5 R .663(f, and the state is set to)-.25 F F1(CLOSED.) 3.163 E F0 .662(In the write case a 100-character trailer is punched.) 5.662 F .662(The routine has a)5.662 F -.2(bu)72 550.5 S 2.727(gi).2 G 2.727(nt)-2.727 G .227(hat if both the reader and punch are open)-2.727 F F1(close)2.727 E F0 .228 (will be called only once, so that either the lefto)2.727 F -.15(ve)-.15 G 2.728(rc).15 G(haracters)-2.728 E .932 (are \215ushed or the trailer is punched, b)72 561.5 R .931 (ut not both.)-.2 F .931(It is hard to see ho)5.931 F 3.431(wt)-.25 G 3.431<6f8c>-3.431 G 3.431(xt)-3.431 G .931(his problem e)-3.431 F .931 (xcept by making the)-.15 F(reader and punch separate de)72 572.5 Q (vices.)-.25 E(The)72 589 Q F1(pcr)2.704 E(ead)-.37 E F0 .204(routine t\ ries to pick up characters from the input queue and passes them back un\ til the user')2.704 F 2.705(sr)-.55 G .205(ead call is)-2.705 F 2.793 (satis\214ed. If)72 600 R .293 (there are no characters it checks whether the state has gone to)2.793 F F1(EOF)2.792 E(,)-1.35 E F0 .292(which means that the interrupt rou-) 2.792 F .006(tine detected an error in the)72 611 R F1(READ)2.506 E F0 .007(state \(assumed to indicate the end of the tape\).)2.506 F .007 (If so,)5.007 F F1(pcr)2.507 E(ead)-.37 E F0 .007 (returns; either during)2.507 F .022(this call or the ne)72 622 R .022 (xt one no characters will be passed back, indicating an end-of-\214le.) -.15 F .021(If the state is still)5.021 F F1(READING)2.521 E F0(the) 2.521 E(routine enables another character by \214ddling the de)72 633 Q (vice')-.25 E 2.5(sr)-.55 G(eader control re)-2.5 E(gister)-.15 E 2.5 (,p)-.4 G(ro)-2.5 E(vided it is not acti)-.15 E -.15(ve)-.25 G 2.5(,a) .15 G(nd goes to)-2.5 E(sleep.)72 644 Q .254 (When a reader interrupt occurs and the state is)72 660.5 R F1 -.6(WA) 2.754 G(ITING,).6 E F0 .254(and the de)2.754 F(vice')-.25 E 2.754(se) -.55 G .254(rror bit is set, the interrupt is ignored; if)-2.754 F .32 (there is no error the state is set to)72 671.5 R F1(READING,)2.82 E F0 .321(as indicated in the discussion of)2.82 F F1(pcr)2.821 E(ead.)-.37 E F0 .321(If the state is)5.321 F F1(READING)2.821 E F0(and)2.821 E .367 (there is an error)72 682.5 R 2.867(,t)-.4 G .367(he state is set to) -2.867 F F1(EOF;)2.867 E F0 .367 (it is assumed that the error represents the end of the tape.)2.867 F .367(If there is no er)5.367 F(-)-.2 E(ror)72 693.5 Q 2.716(,t)-.4 G .216(he character is pick)-2.716 F .216 (ed up and stored in the input queue.)-.1 F .216(Then, pro)5.216 F .216 (vided the number of characters already in the)-.15 F .261 (queue is less than the high-w)72 704.5 R .261(ater mark)-.1 F F1(PCIHW) 2.761 E -.37(AT)-.6 G(,)-.37 E F0 .261(the reader is enabled ag)2.761 F .261(ain to read another character)-.05 F 5.261(.T)-.55 G .261 (his strate-)-5.261 F .023(gy k)72 715.5 R .023(eeps the tape mo)-.1 F .023(ving without \215ooding the input queue with unread characters.) -.15 F(Finally)5.024 E 2.524(,t)-.65 G .024(he top half is a)-2.524 F -.1(wa)-.15 G -.1(ke).1 G(ned.).1 E EP %%Page: 5 5 %%BeginPageSetup BP %%EndPageSetup /F0 10/Times-Roman@0 SF(-)72 11 Q/F1 10/Times-Italic@0 SF (Unix I/O System - 5)461.13 58 Q F0 .186(Looking ag)72 105 R .186 (ain at)-.05 F F1(pcr)2.686 E(ead,)-.37 E F0 .186 (notice that the priority)2.686 F(le)5.186 E -.15(ve)-.25 G 2.686(li).15 G 2.686(sr)-2.686 G .185(aised by)-2.686 F F1 .185(spl4\( \))2.685 F F0 .185(to pre)2.685 F -.15(ve)-.25 G .185(nt interrupts during the loop.) .15 F(This)5.185 E .181 (is done because of the possibility that the input queue is empty)72 116 R 2.681(,a)-.65 G .181 (nd just after the EOF test is made an error interrupt)-2.681 F .021 (occurs because the tape runs out.)72 127 R(Then)5.021 E F1(sleep)2.521 E F0 .02(will be called with no possibility of a)2.521 F F1(wak)2.52 E (eup.)-.1 E F0 .02(In general the processor)5.02 F .423 (priority should be raised when a routine is about to sleep a)72 138 R -.1(wa)-.15 G .424 (iting some condition where the presence of the condi-).1 F .454 (tion, and the consequent)72 149 R F1(wak)2.954 E(eup,)-.1 E F0 .454 (is indicated by an interrupt.)2.954 F .454 (The danger is that the interrupt might occur between)5.454 F (the test for the condition and the call to)72 160 Q F1(sleep,)2.5 E F0 (so that the)2.5 E F1(wak)2.5 E(eup)-.1 E F0(apparently ne)2.5 E -.15 (ve)-.25 G 2.5(rh).15 G(appens.)-2.5 E .77 (At the same time it is a bad idea to raise the processor priority le)72 176.5 R -.15(ve)-.25 G 3.27(lf).15 G .77(or an e)-3.27 F .77 (xtended period of time, since de)-.15 F(vices)-.25 E .183(with real-ti\ me requirements may be shut out so long as to cause an error)72 187.5 R 5.183(.T)-.55 G(he)-5.183 E F1(pcr)2.683 E(ead)-.37 E F0 .183 (routine is perhaps o)2.683 F -.15(ve)-.15 G(rzealous).15 E (in this respect, although since most de)72 198.5 Q(vices ha)-.25 E .3 -.15(ve a p)-.2 H(riority le).15 E -.15(ve)-.25 G 2.5(lh).15 G (igher than 4 this dif)-2.5 E(\214culty is not v)-.25 E(ery important.) -.15 E(The)72 215 Q F1(pcwrite)2.69 E F0 .19 (routine simply gets characters from the user and passes them to)2.69 F F1(pcoutput,)2.691 E F0 .191(which is separated out so that)2.691 F F1 (pcleader)72 226 Q F0 .833(can call it also.)3.333 F F1(Pcoutput)5.833 E F0 .833(checks for errors \(lik)3.333 F 3.333(eo)-.1 G .832 (ut-of-tape\) and if none are present mak)-3.333 F .832 (es sure that the)-.1 F .315 (number of characters in the output queue does not e)72 237 R(xceed)-.15 E F1(PCOHW)2.815 E -.37(AT)-.6 G(;)-.28 E F0 .315(if it does,)2.815 F F1 (sleep)2.815 E F0 .316(is called.)2.816 F .316(Then the character)5.316 F .331(is placed on the output queue.)72 248 R .331(There is a small b) 5.331 F .331(ug here in that)-.2 F F1(pcoutput)2.831 E F0 .331 (does not check that the character w)2.831 F .33(as suc-)-.1 F .011 (cessfully put on the queue \(all character)72 259 R .011(-queue space \ might be empty\); perhaps in this case it might be a good idea to)-.2 F .188(sleep on the lightning-bolt until things quiet do)72 270 R 2.688 (wn. Finally)-.25 F F1(pcstart)2.688 E F0 .187 (is called, which checks to see if the punch is cur)2.688 F(-)-.2 E (rently b)72 281 Q(usy)-.2 E 2.5(,a)-.65 G(nd if not starts the punchin\ g of the \214rst character on the output queue.)-2.5 E .181 (When punch interrupts occur)72 297.5 R(,)-.4 E F1(pcpint)2.681 E F0 .181(is called; it starts the punching of the ne)2.681 F .182 (xt character on the output queue, and if)-.15 F .695 (the number of characters remaining on the queue is less than the lo)72 308.5 R(w-w)-.25 E .695(ater mark)-.1 F F1(PCOL)3.195 E -1.67 -.6(WA T) -.55 H F0 .695(it w)3.795 F(ak)-.1 E .695(es up the write)-.1 F (routine, which is presumably w)72 319.5 Q (aiting for the queue to empty)-.1 E(.)-.65 E/F2 10/Times-Bold@0 SF (The Block-de)72 341.5 Q(vice Interface)-.15 E F0 .505 (Handling of block de)72 358 R .506 (vices is mediated by a collection of routines which manage a set of b) -.25 F(uf)-.2 E .506(fers containing the im-)-.25 F .282 (ages of blocks of data on the v)72 369 R .282(arious de)-.25 F 2.782 (vices. The)-.25 F .282 (most important purpose of these routines is to assure that se)2.782 F -.15(ve)-.25 G(ral).15 E .612 (processes which access the same block of the same de)72 380 R .612 (vice in multiprogrammed f)-.25 F .612(ashion maintain a consistent vie) -.1 F(w)-.25 E .299(of the data in the block.)72 391 R 2.799(As)5.299 G .299(econdary b)-2.799 F .299 (ut still important purpose is to increase the ef)-.2 F(\214cienc)-.25 E 2.798(yo)-.15 G 2.798(ft)-2.798 G .298(he system by k)-2.798 F(eep-)-.1 E .007(ing in-core copies of blocks which are being accessed frequently) 72 402 R 5.007(.T)-.65 G .008 (he main data base for this mechanism is the table)-5.007 F .578(of b)72 413 R(uf)-.2 E(fers)-.25 E F1 -.2(bu)3.078 G -.15(f.).2 G F0 .578 (Each b)5.728 F(uf)-.2 E .578(fer header contains a pair of pointers) -.25 F .4 LW 337.308 415.5 332.308 415.5 DL F1 2.5(\(b forw)323.978 413 R 370.485 415.5 365.485 415.5 DL -3.654 3.077(,b b)354.908 413 T(ac) -3.077 E(k\))-.2 E F0 .577(which maintain a doubly-link)3.077 F .577 (ed list)-.1 F .818(of the b)72 424 R(uf)-.2 E .819 (fers associated with a particular block de)-.25 F .819 (vice, and a pair of pointers)-.25 F 411.843 426.5 406.843 426.5 DL F1 2.5(\(av forw)394.073 424 R 3.319(,a)-.74 G 449.702 426.5 444.702 426.5 DL 5(vb)440.262 424 S(ac)-5 E(k\))-.2 E F0 .819(which generally)3.319 F .839(maintain a doubly-link)72 435 R .839(ed list of blocks which are `) -.1 F(`free,)-.74 E 2.319 -.74('' t)-.7 H .839 (hat is, eligible to be reallocated for another transaction.).74 F(Buf) 72 446 Q .458(fers which ha)-.25 F .758 -.15(ve I)-.2 H .458 (/O in progress or are b).15 F .459 (usy for other purposes do not appear in this list.)-.2 F .459(The b) 5.459 F(uf)-.2 E .459(fer header also)-.25 F .493(contains the de)72 457 R .493(vice and block number to which the b)-.25 F(uf)-.2 E .492 (fer refers, and a pointer to the actual storage associated with)-.25 F 1.207(the b)72 468 R(uf)-.2 E(fer)-.25 E 6.207(.T)-.55 G 1.207 (here is a w)-6.207 F 1.208(ord count which is the ne)-.1 F -.05(ga)-.15 G(ti).05 E 1.508 -.15(ve o)-.25 H 3.708(ft).15 G 1.208(he number of w) -3.708 F 1.208(ords to be transferred to or from the)-.1 F -.2(bu)72 479 S -.25(ff).2 G .182(er; there is also an error byte and a residual w).25 F .182(ord count used to communicate information from an I/O routine to) -.1 F .36(its caller)72 490 R 5.36(.F)-.55 G(inally)-5.36 E 2.86(,t)-.65 G .36(here is a \215ag w)-2.86 F .36 (ord with bits indicating the status of the b)-.1 F(uf)-.2 E(fer)-.25 E 5.361(.T)-.55 G .361(hese \215ags will be discussed be-)-5.361 F(lo)72 501 Q -.65(w.)-.25 G .163 (Six routines constitute the most important part of the interf)72 517.5 R .162(ace with the rest of the system.)-.1 F(Gi)5.162 E -.15(ve)-.25 G 2.662(nad).15 G -.25(ev)-2.662 G .162(ice and block).25 F(number)72 528.5 Q 2.529(,b)-.4 G(oth)-2.529 E F1(br)2.529 E(ead)-.37 E F0(and) 2.529 E F1 -.1(ge)2.529 G(tblk).1 E F0 .029(return a pointer to a b) 2.529 F(uf)-.2 E .029(fer header for the block; the dif)-.25 F .029 (ference is that)-.25 F F1(br)2.529 E(ead)-.37 E F0 .03(is guaran-)2.529 F .188(teed to return a b)72 539.5 R(uf)-.2 E .187 (fer actually containing the current data for the block, while)-.25 F F1 -.1(ge)2.687 G(tblk).1 E F0 .187(returns a b)2.687 F(uf)-.2 E .187 (fer which contains)-.25 F .165(the data in the block only if it is alr\ eady in core \(whether it is or not is indicated by the)72 550.5 R 435.156 553 430.156 553 DL F1 5(BD)424.046 550.5 S(ONE)-5 E F0 .166 (bit; see belo)2.666 F 2.666(w\). In)-.25 F .236(either case the b)72 561.5 R(uf)-.2 E(fer)-.25 E 2.736(,a)-.4 G .236(nd the corresponding de) -2.736 F .236(vice block, is made `)-.25 F(`b)-.74 E(usy)-.2 E -.7(,') -.65 G 2.736('s)-.04 G 2.736(ot)-2.736 G .235 (hat other processes referring to it are)-2.736 F .566(obliged to w)72 572.5 R .566(ait until it becomes free.)-.1 F F1(Getblk)5.566 E F0 .566 (is used, for e)3.066 F .566 (xample, when a block is about to be totally re)-.15 F .567(written, so) -.25 F .161(that its pre)72 583.5 R .161 (vious contents are not useful; still, no other process can be allo)-.25 F .161(wed to refer to the block until the ne)-.25 F 2.66(wd)-.25 G(ata) -2.66 E(is placed into it.)72 594.5 Q(Gi)72 611 Q -.15(ve)-.25 G 2.584 (nap).15 G .084(ointer to a b)-2.584 F(uf)-.2 E(fer)-.25 E 2.584(,t)-.4 G(he)-2.584 E F1(br)2.584 E(else)-.37 E F0 .084(routine mak)2.584 F .084 (es the b)-.1 F(uf)-.2 E .084(fer ag)-.25 F .084(ain a)-.05 F -.25(va) -.2 G .084(ilable to other processes.).25 F .085(It is called, for e) 5.085 F(x-)-.15 E .489(ample, after data has been e)72 622 R .489 (xtracted follo)-.15 F .489(wing a)-.25 F F1(br)2.989 E(ead.)-.37 E F0 .489(There are three subtly-dif)5.489 F .488 (ferent write routines, all of which)-.25 F(tak)72 633 Q 3.061(eab)-.1 G (uf)-3.261 E .561(fer pointer as ar)-.25 F .561 (gument, and all of which logically release the b)-.18 F(uf)-.2 E .562 (fer for use by others and place it on the)-.25 F .01(free list.)72 644 R F1(Bwrite)5.01 E F0 .01(puts the b)2.51 F(uf)-.2 E .01 (fer on the appropriate de)-.25 F .01(vice queue, w)-.25 F .009 (aits for the write to be done, and sets the user')-.1 F 2.509(se)-.55 G -.2(r-)-2.509 G(ror \215ag if required.)72 655 Q F1(Bawrite)72 677 Q F0 .463(places the b)2.963 F(uf)-.2 E .463(fer on the de)-.25 F(vice')-.25 E 2.964(sq)-.55 G .464(ueue, b)-2.964 F .464(ut does not w)-.2 F .464 (ait for completion, so that errors cannot be re\215ected)-.1 F .315 (directly to the user)72 688 R(.)-.55 E F1(Bdwrite)5.314 E F0 .314 (does not start an)2.814 F 2.814(yI)-.15 G .314(/O operation at all, b) -2.814 F .314(ut merely marks the b)-.2 F(uf)-.2 E .314 (fer so that if it happens)-.25 F(to be grabbed from the free list to c\ ontain data from some other block, the data in it will \214rst be writt\ en out.)72 699 Q F1(Bwrite)72 715.5 Q F0 .142(is used when one w)2.642 F .142(ants to be sure that I/O tak)-.1 F .142(es place correctly)-.1 F 2.642(,a)-.65 G .143(nd that errors are re\215ected to the proper us-) -2.642 F .881(er; it is used, for e)72 726.5 R .881 (xample, when updating i-nodes.)-.15 F F1(Bawrite)5.881 E F0 .88 (is useful when more ef)3.381 F(\214cienc)-.25 E 3.38(yi)-.15 G 3.38(sd) -3.38 G .88(esired \(because no)-3.38 F EP %%Page: 6 6 %%BeginPageSetup BP %%EndPageSetup /F0 10/Times-Roman@0 SF(-)72 11 Q/F1 10/Times-Italic@0 SF 2.5(6-U)72 58 S(nix I/O System)-2.5 E F0 -.1(wa)72 105 S .517 (it is required for I/O to \214nish\) b).1 F .517 (ut when it is reasonably certain that the write is really required.)-.2 F F1(Bdwrite)5.518 E F0 .518(is used)3.018 F .595 (when there is doubt that the write is needed at the moment.)72 116 R -.15(Fo)5.595 G 3.094(re).15 G(xample,)-3.244 E F1(bdwrite)3.094 E F0 .594(is called when the last byte of a)3.094 F F1(write)72 127 Q F0 .071 (system call f)2.571 F .072 (alls short of the end of a block, on the assumption that another)-.1 F F1(write)2.572 E F0 .072(will be gi)2.572 F -.15(ve)-.25 G 2.572(ns).15 G .072(oon which will)-2.572 F .077(re-use the same block.)72 138 R .077 (On the other hand, as the end of a block is passed,)5.077 F F1(bawrite) 2.577 E F0 .076(is called, since probably the block)2.577 F (will not be accessed ag)72 149 Q(ain soon and one might as well start \ the writing process as soon as possible.)-.05 E .661(In an)72 165.5 R 3.161(ye)-.15 G -.15(ve)-3.411 G .661(nt, notice that the routines).15 F F1 -.1(ge)3.161 G(tblk).1 E F0(and)3.161 E F1(br)3.161 E(ead)-.37 E F0 .662(dedicate the gi)3.161 F -.15(ve)-.25 G 3.162(nb).15 G .662(lock e) -3.162 F(xclusi)-.15 E -.15(ve)-.25 G .662(ly to the use of the caller) .15 F(,)-.4 E .161(and mak)72 176.5 R 2.661(eo)-.1 G .161(thers w)-2.661 F .161(ait, while one of)-.1 F F1(br)2.661 E(else)-.37 E 2.661(,b)-.1 G (write)-2.661 E 2.661(,b)-.1 G(awrite)-2.661 E(,)-.1 E F0(or)2.661 E F1 (bdwrite)2.661 E F0 .161(must e)2.661 F -.15(ve)-.25 G .161 (ntually be called to free the block for).15 F(use by others.)72 187.5 Q .63(As mentioned, each b)72 204 R(uf)-.2 E .63 (fer header contains a \215ag w)-.25 F .63 (ord which indicates the status of the b)-.1 F(uf)-.2 E(fer)-.25 E 5.63 (.S)-.55 G .63(ince the)-5.63 F 3.13(yp)-.15 G(ro)-3.13 E(vide)-.15 E .824(one important channel for information between the dri)72 215 R -.15 (ve)-.25 G .824 (rs and the block I/O system, it is important to understand).15 F (these \215ags.)72 226 Q(The follo)5 E(wing names are manifest constant\ s which select the associated \215ag bits.)-.25 E .4 LW 83.11 250.5 78.11 250.5 DL F1 5(BR)72 248 S(EAD)-5 E F0 .345 (This bit is set when the b)72 264.5 R(uf)-.2 E .345 (fer is handed to the de)-.25 F .345(vice strate)-.25 F .345 (gy routine \(see belo)-.15 F .346(w\) to indicate a read operation.) -.25 F(The)5.346 E(symbol)72 275.5 Q 115.517 278 110.517 278 DL F1 5(BW) 104.407 275.5 S(RITE)-5 E F0 .457 (is de\214ned as 0 and does not de\214ne a \215ag; it is pro)2.957 F .456(vided as a mnemonic con)-.15 F -.15(ve)-.4 G .456 (nience to callers of).15 F(routines lik)72 286.5 Q(e)-.1 E F1(swap)2.5 E F0(which ha)2.5 E .3 -.15(ve a s)-.2 H(eparate ar).15 E (gument which indicates read or write.)-.18 E 83.11 311 78.11 311 DL F1 5(BD)72 308.5 S(ONE)-5 E F0 .935 (This bit is set to 0 when a block is handed to the the de)72 325 R .935 (vice strate)-.25 F .936(gy routine and is turned on when the operation) -.15 F .216(completes, whether normally as the result of an error)72 336 R 5.216(.I)-.55 G 2.716(ti)-5.216 G 2.716(sa)-2.716 G .216 (lso used as part of the return ar)-2.716 F .216(gument of)-.18 F F1 -.1 (ge)2.716 G(tblk).1 E F0 .215(to indi-)2.715 F (cate if 1 that the returned b)72 347 Q(uf)-.2 E (fer actually contains the data in the requested block.)-.25 E 83.11 371.5 78.11 371.5 DL F1 5(BE)72 369 S(RR)-5 E(OR)-.4 E F0 .418 (This bit may be set to 1 when)72 385.5 R 207.004 388 202.004 388 DL F1 5(BD)195.894 385.5 S(ONE)-5 E F0 .418 (is set to indicate that an I/O or other error occurred.)2.918 F .419 (If it is set the)5.419 F 519.34 388 514.34 388 DL F1 5(be)509.34 385.5 S(rr)-5 E(or)-.45 E F0 .862(byte of the b)72 396.5 R(uf)-.2 E .862 (fer header may contain an error code if it is non-zero.)-.25 F(If)5.862 E 380.78 399 375.78 399 DL F1 5(be)370.78 396.5 S(rr)-5 E(or)-.45 E F0 .861(is 0 the nature of the error is not)3.362 F 2.62 (speci\214ed. Actually)72 407.5 R .12(no dri)2.62 F -.15(ve)-.25 G 2.62 (ra).15 G 2.62(tp)-2.62 G .12(resent sets)-2.62 F 259.91 410 254.91 410 DL F1 5(be)249.91 407.5 S(rr)-5 E(or;)-.45 E F0 .121(the latter is pro) 2.62 F .121(vided for a future impro)-.15 F -.15(ve)-.15 G .121 (ment whereby a more).15 F(detailed error)72 418.5 Q (-reporting scheme may be implemented.)-.2 E 83.11 443 78.11 443 DL F1 5 (BB)72 440.5 S(USY)-5.1 E F0 1.301(This bit indicates that the b)72 457 R(uf)-.2 E 1.3 (fer header is not on the free list, i.e. is dedicated to someone')-.25 F 3.8(se)-.55 G(xclusi)-3.95 E 1.6 -.15(ve u)-.25 H 3.8(se. The).15 F -.2(bu)72 468 S -.25(ff).2 G .426 (er still remains attached to the list of blocks associated with its de) .25 F .426(vice, ho)-.25 F(we)-.25 E -.15(ve)-.25 G 4.026 -.55(r. W).15 H(hen).55 E F1 -.1(ge)2.926 G(tblk).1 E F0(\(or)2.926 E F1(br)2.927 E (ead,)-.37 E F0(which)2.927 E .181(calls it\) searches the b)72 479 R (uf)-.2 E .181(fer list for a gi)-.25 F -.15(ve)-.25 G 2.681(nd).15 G -.25(ev)-2.681 G .18(ice and \214nds the requested block with this bit \ on, it sleeps until the bit).25 F(clears.)72 490 Q 83.11 514.5 78.11 514.5 DL F1 5(BW)72 512 S(ANTED)-5.6 E F0 .434 (This \215ag is used in conjunction with the)72 528.5 R 249.362 531 244.362 531 DL F1 5(BB)238.252 528.5 S(USY)-5.1 E F0 2.934(bit. Before) 2.934 F .434(sleeping as described just abo)2.934 F -.15(ve)-.15 G(,).15 E F1 -.1(ge)2.935 G(tblk).1 E F0 .435(sets this \215ag.)2.935 F(Con)72 539.5 Q -.15(ve)-.4 G(rsely).15 E 3.19(,w)-.65 G .69 (hen the block is freed and the b)-3.19 F .69(usy bit goes do)-.2 F .69 (wn \(in)-.25 F F1(br)3.19 E(else\))-.37 E F0(a)3.19 E F1(wak)3.19 E (eup)-.1 E F0 .69(is gi)3.19 F -.15(ve)-.25 G 3.19(nf).15 G .69 (or the block header)-3.19 F(whene)72 550.5 Q -.15(ve)-.25 G(r).15 E 125.127 553 120.127 553 DL F1 5(BW)114.017 550.5 S(ANTED)-5.6 E F0 1.047 (is on.)3.547 F 1.048(This strate)6.047 F 1.048(gem a)-.15 F -.2(vo)-.2 G 1.048(ids the o).2 F -.15(ve)-.15 G 1.048(rhead of ha).15 F 1.048 (ving to call)-.2 F F1(wak)3.548 E(eup)-.1 E F0 -2.15 -.25(ev e)3.548 H 1.048(ry time a b).25 F(uf)-.2 E 1.048(fer is)-.25 F (freed on the chance that someone might w)72 561.5 Q(ant it.)-.1 E 83.11 586 78.11 586 DL F1 5(BA)72 583.5 S(SYNC)-5 E F0 .001 (This bit is set by)72 600 R F1(bawrite)2.501 E F0 .001 (to indicate to the appropriate de)2.501 F(vice dri)-.25 E -.15(ve)-.25 G 2.5(rt).15 G(hat the b)-2.5 E(uf)-.2 E (fer should be released when the write)-.25 E .307 (has been \214nished, usually at interrupt time.)72 611 R .308(The dif) 5.308 F .308(ference between)-.25 F F1(bwrite)2.808 E F0(and)2.808 E F1 (bawrite)2.808 E F0 .308(is that the former starts I/O,)2.808 F -.1(wa) 72 622 S .522(its until it is done, and frees the b).1 F(uf)-.2 E(fer) -.25 E 5.521(.T)-.55 G .521 (he latter merely sets this bit and starts I/O.)-5.521 F .521 (The bit indicates that)5.521 F F1 -.37(re)3.021 G(lse).37 E F0 (should be called for the b)72 633 Q(uf)-.2 E(fer on completion.)-.25 E 83.11 657.5 78.11 657.5 DL F1 5(BD)72 655 S(EL)-5 E(WRI)-.55 E F0 .058 (This bit is set by)72 671.5 R F1(bdwrite)2.558 E F0 .058 (before releasing the b)2.558 F(uf)-.2 E(fer)-.25 E 5.058(.W)-.55 G(hen) -5.058 E F1 -.1(ge)2.558 G(tblk,).1 E F0 .058 (while searching for a free block, disco)2.558 F -.15(ve)-.15 G .058 (rs the bit).15 F(is 1 in a b)72 682.5 Q(uf)-.2 E(fer it w)-.25 E(ould \ otherwise grab, it causes the block to be written out before reusing it\ .)-.1 E 83.11 707 78.11 707 DL F1 5(BX)72 704.5 S(MEM)-5 E F0 .146(This\ is actually a mask for the pair of bits which contain the high-order t\ w)72 721 R 2.646(ob)-.1 G .146(its of the ph)-2.646 F .146 (ysical address of the origin)-.05 F EP %%Page: 7 7 %%BeginPageSetup BP %%EndPageSetup /F0 10/Times-Roman@0 SF(-)72 11 Q/F1 10/Times-Italic@0 SF (Unix I/O System - 7)461.13 58 Q F0(of the b)72 105 Q(uf)-.2 E (fer; these bits are an e)-.25 E(xtension of the 16 address bits else) -.15 E(where in the b)-.25 E(uf)-.2 E(fer header)-.25 E(.)-.55 E .4 LW 83.11 129.5 78.11 129.5 DL F1 5(BR)72 127 S(ELOC)-5 E F0 .929 (This bit is currently unused; it pre)72 143.5 R .929 (viously indicated that a system-wide relocation constant w)-.25 F .93 (as to be added to the)-.1 F -.2(bu)72 154.5 S -.25(ff).2 G 1.186 (er address.).25 F 1.186(It w)6.186 F 1.186(as needed during a period w\ hen addresses of data in the system \(including the b)-.1 F(uf)-.2 E 1.185(fers\) were)-.25 F(mapped by the relocation hardw)72 165.5 Q (are to a ph)-.1 E(ysical address dif)-.05 E (fering from its virtual address.)-.25 E/F2 10/Times-Bold@0 SF(Block De) 72 187.5 Q(vice Dri)-.15 E -.1(ve)-.1 G(rs).1 E F0(The)72 204 Q F1(bde) 2.5 E(vsw)-.15 E F0(table contains the names of the interf)2.5 E (ace routines and that of a table for each block de)-.1 E(vice.)-.25 E 1.155(Just as for character de)72 220.5 R 1.155(vices, block de)-.25 F 1.155(vice dri)-.25 F -.15(ve)-.25 G 1.156(rs may supply an).15 F F1 (open)3.656 E F0 1.156(and a)3.656 F F1(close)3.656 E F0 1.156 (routine called respecti)3.656 F -.15(ve)-.25 G 1.156(ly on).15 F .355 (each open and on the \214nal close of the de)72 231.5 R 2.855 (vice. Instead)-.25 F .354 (of separate read and write routines, each block de)2.854 F .354 (vice dri)-.25 F -.15(ve)-.25 G(r).15 E .306(has a)72 242.5 R F1(str) 2.806 E(ate)-.15 E(gy)-.4 E F0 .306 (routine which is called with a pointer to a b)2.806 F(uf)-.2 E .307 (fer header as ar)-.25 F 2.807(gument. As)-.18 F .307(discussed, the b) 2.807 F(uf)-.2 E .307(fer header)-.25 F .624 (contains a read/write \215ag, the core address \(including e)72 253.5 R .623(xtended-memory bits\), the block number)-.15 F 3.123(,a\()-.4 G(ne) -3.123 E -.05(ga)-.15 G(ti).05 E -.15(ve)-.25 G 3.123(\)w).15 G(ord) -3.223 E .615(count, and the major and minor de)72 264.5 R .616 (vice number)-.25 F 5.616(.T)-.55 G .616(he ro)-5.616 F .835(^l)-4.165 G 3.116(eo)-.835 G 3.116(ft)-3.116 G .616(he strate)-3.116 F .616 (gy routine is to carry out the operation as re-)-.15 F .779 (quested by the information in the b)72 275.5 R(uf)-.2 E .779 (fer header)-.25 F 5.779(.W)-.55 G .779 (hen the transaction is complete the)-5.779 F 439.616 278 434.616 278 DL F1 5(BD)428.506 275.5 S(ONE)-5 E F0 .778(\(and possibly the)3.278 F 83.11 289 78.11 289 DL F1 5(BE)72 286.5 S(RR)-5 E(OR\))-.4 E F0 .22 (bits should be set.)2.72 F .22(Then if the)5.22 F 256.12 289 251.12 289 DL F1 5(BA)245.01 286.5 S(SYNC)-5 E F0 .221(bit is set,)2.72 F F1(br) 2.721 E(else)-.37 E F0 .221(should be called; otherwise,)2.721 F F1(wak) 2.721 E(eup.)-.1 E F0 .221(In cases)5.221 F 1.503(where the de)72 297.5 R 1.503(vice is capable, under error)-.25 F 1.503 (-free operation, of transferring fe)-.2 F 1.502(wer w)-.25 F 1.502 (ords than requested, the de)-.1 F(vice')-.25 E(s)-.55 E -.1(wo)72 308.5 S 1.04(rd-count re).1 F 1.04 (gister should be placed in the residual count slot of the b)-.15 F(uf) -.2 E 1.04(fer header; otherwise, the residual count)-.25 F .563 (should be set to 0.)72 319.5 R .562(This particular mechanism is reall\ y for the bene\214t of the magtape dri)5.563 F -.15(ve)-.25 G .562 (r; when reading this de-).15 F 1.231(vice records shorter than request\ ed are quite normal, and the user should be told the actual length of t\ he record.)72 330.5 R([Ho)72 341.5 Q(we)-.25 E -.15(ve)-.25 G 2.658(rt) .15 G .158(he mechanism has not been inte)-2.658 F .158 (grated into normal I/O e)-.15 F -.15(ve)-.25 G 2.657(no).15 G 2.657(nm) -2.657 G .157(agtape and is used only in `)-2.657 F(`ra)-.74 E(w')-.15 E 2.657('I)-.74 G .157(/O as)-2.657 F(discussed belo)72 352.5 Q -.65(w.) -.25 G(]).65 E 1.078(Notice that although the most usual ar)72 369 R 1.078(gument to the strate)-.18 F 1.078(gy routines is a genuine b)-.15 F(uf)-.2 E 1.079(fer header allocated as dis-)-.25 F .526(cussed abo)72 380 R -.15(ve)-.15 G 3.026(,a).15 G .526 (ll that is actually required is that the ar)-3.026 F .525 (gument be a pointer to a place containing the appropriate in-)-.18 F 3.081(formation. F)72 391 R .581(or e)-.15 F .581(xample the)-.15 F F1 (swap)3.081 E F0 .581(routine, which manages mo)3.081 F -.15(ve)-.15 G .581(ment of core images to and from the sw).15 F .582(apping de-)-.1 F .51(vice, uses the strate)72 402 R .51(gy routine for this de)-.15 F 3.01(vice. Care)-.25 F .51(has to be tak)3.01 F .51(en that no e)-.1 F .51(xtraneous bits get turned on in the \215ag)-.15 F -.1(wo)72 413 S (rd.).1 E .467(The de)72 429.5 R(vice')-.25 E 2.967(st)-.55 G .467 (able speci\214ed by)-2.967 F F1(bde)2.967 E(vsw)-.15 E F0 .467 (has a byte to contain an acti)2.967 F .767 -.15(ve \215)-.25 H .468 (ag and an error count, a pair of links which).15 F .78 (constitute the head of the chain of b)72 440.5 R(uf)-.2 E .78 (fers for the de)-.25 F(vice)-.25 E 319.54 443 314.54 443 DL F1 2.5 (\(b forw)306.21 440.5 R 352.92 443 347.92 443 DL -4.06 3.28(,b b)337.14 440.5 T(ac)-3.28 E(k\),)-.2 E F0 .78 (and a \214rst and last pointer for a de)3.28 F(vice)-.25 E 2.874 (queue. Of)72 451.5 R .374(these things, all are used solely by the de) 2.874 F .375(vice dri)-.25 F -.15(ve)-.25 G 2.875(ri).15 G .375(tself e) -2.875 F .375(xcept for the b)-.15 F(uf)-.2 E(fer)-.25 E .375 (-chain pointers.)-.2 F -.8(Ty)5.375 G(pically).8 E .354 (the \215ag encodes the state of the de)72 462.5 R .354 (vice, and is used at a minimum to indicate that the de)-.25 F .354 (vice is currently eng)-.25 F .354(aged in)-.05 F .212 (transferring information and no ne)72 473.5 R 2.712(wc)-.25 G .212 (ommand should be issued.)-2.712 F .213 (The error count is useful for counting retries when)5.212 F .2 (errors occur)72 484.5 R 5.2(.T)-.55 G .2(he de)-5.2 F .2 (vice queue is used to remember stack)-.25 F .2 (ed requests; in the simplest case it may be maintained as a)-.1 F .403 (\214rst-in \214rst-out list.)72 495.5 R .403(Since b)5.403 F(uf)-.2 E .403(fers which ha)-.25 F .703 -.15(ve b)-.2 H .403(een handed o).15 F -.15(ve)-.15 G 2.903(rt).15 G 2.904(ot)-2.903 G .404(he strate)-2.904 F .404(gy routines are ne)-.15 F -.15(ve)-.25 G 2.904(ro).15 G 2.904(nt) -2.904 G .404(he list of free)-2.904 F -.2(bu)72 506.5 S -.25(ff).2 G .42(ers, the pointers in the b).25 F(uf)-.2 E .42 (fer which maintain the free list)-.25 F 340.11 509 335.11 509 DL F1 2.5 (\(av forw)322.34 506.5 R 2.92(,a)-.74 G 377.57 509 372.57 509 DL 5(vb) 368.13 506.5 S(ac)-5 E(k\))-.2 E F0 .42 (are also used to contain the point-)2.92 F(ers which maintain the de)72 517.5 Q(vice queues.)-.25 E 2.5(Ac)72 534 S(ouple of routines are pro) -2.5 E(vided which are useful to block de)-.15 E(vice dri)-.25 E -.15 (ve)-.25 G(rs.).15 E F1 2.5(iodone\(bp\) ,)122 550.5 R F0 .75 (arranges that the b)72 567 R(uf)-.2 E .75(fer to which)-.25 F F1(bp) 3.25 E F0 .751(points be released or a)3.25 F -.1(wa)-.15 G -.1(ke).1 G .751(ned, as appropriate, when the strate).1 F .751(gy module has)-.15 F .434(\214nished with the b)72 578 R(uf)-.2 E(fer)-.25 E 2.934(,e)-.4 G .434(ither normally or after an error)-2.934 F 5.434(.\()-.55 G .434 (In the latter case the)-5.434 F 407.578 580.5 402.578 580.5 DL F1 5(BE) 396.468 578 S(RR)-5 E(OR)-.4 E F0 .433(bit has presumably been)2.933 F (set.\))72 589 Q(When the de)72 605.5 Q(vice conforms to some rather lo\ ose standards adhered to by certain DEC hardw)-.25 E(are, the routine) -.1 E F1(de)122 622 Q(vstart\(bp, de)-.15 E(vloc, de)-.15 E (vblk, hbcom\))-.15 E F0 .52(is useful.)72 638.5 R(Here)5.52 E F1(bp) 3.02 E F0 .52(is the address of the b)3.02 F(uf)-.2 E .52(fer header) -.25 F(,)-.4 E F1(de)3.02 E(vloc)-.15 E F0 .521 (is the address of the slot in the de)3.02 F .521(vice re)-.25 F .521 (gisters which)-.15 F .212(accepts a perhaps-encoded de)72 649.5 R .212 (vice block number)-.25 F(,)-.4 E F1(de)2.712 E(vblk)-.15 E F0 .212 (is the block number)2.712 F 2.712(,a)-.4 G(nd)-2.712 E F1(hbcom)2.711 E F0 .211(is a quantity to be stored in)2.711 F .769 (the high byte of the de)72 660.5 R(vice')-.25 E 3.269(sc)-.55 G .769 (ommand re)-3.269 F(gister)-.15 E 5.769(.I)-.55 G 3.269(ti)-5.769 G 3.269(su)-3.269 G .77(nderstood, when using this routine, that the de) -3.269 F .77(vice re)-.25 F(gisters)-.15 E(are laid out in the order)72 671.5 Q(command re)122 688 Q(gister)-.15 E -.1(wo)122 699 S(rd count).1 E(core address)122 710 Q(block \(or track or sector\))122 721 Q EP %%Page: 8 8 %%BeginPageSetup BP %%EndPageSetup /F0 10/Times-Roman@0 SF(-)72 11 Q/F1 10/Times-Italic@0 SF 2.5(8-U)72 58 S(nix I/O System)-2.5 E F0 .279 (where the address of the last corresponds to)72 105 R F1(de)2.779 E (vloc.)-.15 E F0(Moreo)5.278 E -.15(ve)-.15 G 1.078 -.4(r, t).15 H .278 (he de).4 F .278(vice should correspond to the RP)-.25 F 2.778(,R)-1.11 G .278(K, and RF)-2.778 F(de)72 116 Q (vices with respect to its layout of e)-.25 E (xtended-memory bits and structure of read and write commands.)-.15 E (The routine)72 132.5 Q F1 -.1(ge)122 149 S(terr).1 E(or\(bp\))-.45 E F0 .092(can be used to e)72 165.5 R .092(xamine the error bit in a b)-.15 F (uf)-.2 E .092(fer header and arrange that an)-.25 F 2.593(ye)-.15 G .093(rror indication found therein is re\215ected)-2.593 F .55 (to the user)72 176.5 R 5.55(.I)-.55 G 3.05(tm)-5.55 G .55 (ay be called only in the non-interrupt part of a dri)-3.05 F -.15(ve) -.25 G 3.049(rw).15 G .549(hen I/O has completed)-3.049 F .4 LW 474.472 179 469.472 179 DL F1 2.5(\(B DONE)460.032 176.5 R F0 .549(has been) 3.049 F(set\).)72 187.5 Q F1(An e)72 209.5 Q(xample)-.2 E F0 .697 (The RF disk dri)72 226 R -.15(ve)-.25 G 3.197(ri).15 G 3.197(sw)-3.197 G .697(orth studying as the simplest e)-3.297 F .697 (xample of a block I/O de)-.15 F 3.197(vice. Its)-.25 F F1(str)3.197 E (ate)-.15 E(gy)-.4 E F0 .697(routine checks to)3.197 F .405 (see if the requested block lies be)72 237 R .404 (yond the end of the de)-.15 F .404 (vice; the size of the disk, in this instance, is indicated by the)-.25 F .042(minor de)72 248 R .042(vice number)-.25 F 5.042(.I)-.55 G 2.542 (ft)-5.042 G .042(he request is plausible, the b)-2.542 F(uf)-.2 E .043 (fer is placed at the end of the de)-.25 F .043 (vice queue, and if the disk is)-.25 F(not running,)72 259 Q F1(rfstart) 2.5 E F0(is called.)2.5 E F1(Rfstart)72 275.5 Q F0 .349 (merely returns if there is nothing to do, b)2.849 F .349 (ut otherwise sets the de)-.2 F(vice-acti)-.25 E .649 -.15(ve \215)-.25 H .349(ag, loads the address e).15 F(xtension)-.15 E(re)72 286.5 Q (gister)-.15 E 2.5(,a)-.4 G(nd calls)-2.5 E F1(de)2.5 E(vstart)-.15 E F0 (to perform the remaining tasks attendant on be)2.5 E (ginning a data transfer)-.15 E(.)-.55 E .637 (When a completion or error interrupt occurs,)72 303 R F1(r\214ntr)3.137 E F0 .637(is called.)3.137 F .637 (If an error is indicated, and if the error count has not)5.637 F -.15 (ex)72 314 S .324(ceeded 10, the same transaction is reattempted; other\ wise the error bit is set.).15 F .323(If there w)5.323 F .323 (as no error or if 10 f)-.1 F(ailing)-.1 E(transfers ha)72 325 Q .3 -.15 (ve b)-.2 H(een issued the queue is adv).15 E(anced and)-.25 E F1 (rfstart)2.5 E F0(is called to be)2.5 E(gin another transaction.)-.15 E /F2 10/Times-Bold@0 SF(Raw Block-de)72 347 Q(vice I/O)-.15 E F0 2.963 (As)72 363.5 S .463(cheme has been set up whereby block de)-2.963 F .463 (vice dri)-.25 F -.15(ve)-.25 G .463(rs may pro).15 F .464 (vide the ability to transfer information directly be-)-.15 F .72 (tween the user')72 374.5 R 3.219(sc)-.55 G .719(ore image and the de) -3.219 F .719(vice without the use of b)-.25 F(uf)-.2 E .719 (fers and in blocks as lar)-.25 F .719(ge as the caller requests.)-.18 F .275(The method in)72 385.5 R -.2(vo)-.4 G(lv).2 E .275 (es setting up a character)-.15 F .275 (-type special \214le corresponding to the ra)-.2 F 2.776(wd)-.15 G -.25 (ev)-2.776 G .276(ice and pro).25 F(viding)-.15 E F1 -.37(re)2.776 G(ad) .37 E F0(and)2.776 E F1(write)72 396.5 Q F0 .336 (routines which set up what is usually a pri)2.836 F -.25(va)-.25 G .335 (te, non-shared b).25 F(uf)-.2 E .335 (fer header with the appropriate information and)-.25 F .055 (call the de)72 407.5 R(vice')-.25 E 2.555(ss)-.55 G(trate)-2.555 E .055 (gy routine.)-.15 F .055(If desired, separate)5.055 F F1(open)2.555 E F0 (and)2.555 E F1(close)2.555 E F0 .055(routines may be pro)2.555 F .056 (vided b)-.15 F .056(ut this is usually un-)-.2 F(necessary)72 418.5 Q 5 (.A)-.65 G(special-function routine might come in handy)-2.5 E 2.5(,e) -.65 G(specially for magtape.)-2.5 E 2.9(Ag)72 435 S .399 (reat deal of w)-2.9 F .399(ork has to be done to generate the `)-.1 F .399(`appropriate information')-.74 F 2.899('t)-.74 G 2.899(op)-2.899 G .399(ut in the ar)-2.899 F .399(gument b)-.18 F(uf)-.2 E .399 (fer for the)-.25 F(strate)72 446 Q .46(gy module; the w)-.15 F .46 (orst part is to map relocated user addresses to ph)-.1 F .46 (ysical addresses.)-.05 F .46(Most of this w)5.46 F .46(ork is done)-.1 F(by)72 457 Q F1(physio\(str)122 473.5 Q(at, bp, de)-.15 E 1.48 -.74 (v, r)-.15 H(w\)).74 E F0 .162(whose ar)72 490 R .162 (guments are the name of the strate)-.18 F .162(gy routine)-.15 F F1 (str)2.662 E(at,)-.15 E F0 .162(the b)2.662 F(uf)-.2 E .162(fer pointer) -.25 F F1(bp,)2.662 E F0 .162(the de)2.662 F .162(vice number)-.25 F F1 (de)2.662 E -.74(v,)-.15 G F0 .162(and a read-)3.402 F .165 (write \215ag)72 501 R F1(rw)2.665 E F0 .165(whose v)2.665 F .166 (alue is either)-.25 F 224.278 503.5 219.278 503.5 DL F1 5(BR)213.168 501 S(EAD)-5 E F0(or)2.666 E 274.6 503.5 269.6 503.5 DL F1 5(BW)263.49 501 S 2.666(RITE. Physio)-5 F F0(mak)2.666 E .166 (es sure that the user')-.1 F 2.666(sb)-.55 G .166 (ase address and count)-2.666 F .242(are e)72 512 R -.15(ve)-.25 G 2.742 (n\().15 G .242(because most de)-2.742 F .242(vices w)-.25 F .242 (ork in w)-.1 F .242(ords\) and that the core area af)-.1 F .241 (fected is contiguous in ph)-.25 F .241(ysical space; it de-)-.05 F .323 (lays until the b)72 523 R(uf)-.2 E .323(fer is not b)-.25 F(usy)-.2 E 2.823(,a)-.65 G .323(nd mak)-2.823 F .323(es it b)-.1 F .323(usy while \ the operation is in progress; and it sets up user error return)-.2 F (information.)72 534 Q .177(The magtape dri)72 550.5 R -.15(ve)-.25 G 2.677(ri).15 G 2.677(st)-2.677 G .177 (he only one which as of this writing pro)-2.677 F .177(vides a ra)-.15 F 2.676(wI)-.15 G .176(/O capability; gi)-2.676 F -.15(ve)-.25 G(n).15 E F1(physio,)2.676 E F0 .176(the w)2.676 F .176(ork in-)-.1 F -.2(vo)72 561.5 S(lv).2 E .988(ed is tri)-.15 F .989(vial, and amounts to passing\ back to the user information on the length of the record read or writt\ en.)-.25 F .01 (\(There is some funniness because the magtape, uniquely among DEC de)72 572.5 R .01(vices, w)-.25 F .01(orks in bytes, not w)-.1 F 2.51 (ords.\) Putting)-.1 F(in)2.51 E(ra)72 583.5 Q 3.251(wI)-.15 G .751 (/O for disks should be equally tri)-3.251 F .751(vial e)-.25 F .752 (xcept that the disk address has to be carefully check)-.15 F .752 (ed to mak)-.1 F 3.252(es)-.1 G .752(ure it)-3.252 F(does not o)72 594.5 Q -.15(ve)-.15 G(r\215o).15 E 2.5(wf)-.25 G(rom one logical de)-2.5 E (vice to another on which the caller may not ha)-.25 E .3 -.15(ve w)-.2 H(rite permission.).15 E EP %%Trailer end %%EOF