TheUNIXI/OSystem DennisM.Ritchie ThispapergivesanoverviewoftheworkingsoftheUNIX†I/Osystem.Itwaswrittenwith aneyetowardprovidingguidancetowritersofdevicedriverroutines,andisorientedmoretoward describingtheenvironmentandnatureofdevicedriversthantheimplementationofthatpartof thefilesystemwhichdealswithordinaryfiles. Itisassumedthatthereaderhasagoodknowledgeoftheoverallstructureofthefilesystem asdiscussedinthepaper‘‘TheUNIXTime-sharingSystem.’’Amoredetaileddiscussionappears in‘‘UNIXImplementation;’’thecurrentdocumentrestatespartsofthatone,butisstillmore detailed.Itismostusefulinconjunctionwithacopyofthesystemcode,sinceitisbasicallyan exegesisofthatcode. DeviceClasses Therearetwoclassesofdevice:blockandcharacter.Theblockinterfaceissuitablefor deviceslikedisks,tapes,andDECtapewhichwork,orcanwork,withaddressible512-byteblocks. Ordinarymagnetictapejustbarelyfitsinthiscategory,sincebyuseofforwardandbackward spacinganyblockcanberead,eventhoughblockscanbewrittenonlyattheendofthetape. Blockdevicescanatleastpotentiallycontainamountedfilesystem.Theinterfacetoblock devicesisveryhighlystructured;thedriversforthesedevicesshareagreatmanyroutinesaswell asapoolofbuffers. Character-typedeviceshaveamuchmorestraightforwardinterface,althoughmorework mustbedonebythedriveritself. Devicesofbothtypesarenamedbyamajorandaminordevicenumber.Thesenumbers aregenerallystoredasanintegerwiththeminordevicenumberinthelow-order8bitsandthe majordevicenumberinthenext-higher8bits;macrosmajorandminorareavailabletoaccess thesenumbers.Themajordevicenumberselectswhichdriverwilldealwiththedevice;theminor devicenumberisnotusedbytherestofthesystembutispassedtothedriveratappropriate times.Typicallytheminornumberselectsasubdeviceattachedtoagivencontroller,oroneof severalsimilarhardwareinterfaces. Themajordevicenumbersforblockandcharacterdevicesareusedasindicesinseparate tables;theybothstartat0andthereforeoverlap. OverviewofI/O Thepurposeoftheopenandcreatsystemcallsistosetupentriesinthreeseparatesystem tables.Thefirstoftheseistheuofiletable,whichisstoredinthesystem’sper-processdataarea u.Thistableisindexedbythefiledescriptorreturnedbytheopenorcreat,andisaccessedduringaread,write,orotheroperationontheopenfile.Anentrycontainsonlyapointertothecorrespondingentryofthefiletable,whichisaper-systemdatabase.Thereisoneentryinthefile tableforeachinstanceofopenorcreat.Thistableisper-systembecausethesameinstanceofan openfilemustbesharedamongtheseveralprocesseswhichcanresultfromforksafterthefileis opened.Afiletableentrycontainsflagswhichindicatewhetherthefilewasopenforreadingor writingorisapipe,andacountwhichisusedtodecidewhenallprocessesusingtheentryhave terminatedorclosedthefile(sotheentrycanbeabandoned).Thereisalsoa32-bitfileoffset whichisusedtoindicatewhereinthefilethenextreadorwritewilltakeplace.Finally,thereis apointertotheentryforthefileintheinodetable,whichcontainsacopyofthefile’si-node. †UNIXisaTrademarkofBellLaboratories.

-2-Certainopenfilescanbedesignated‘‘multiplexed’’files,andseveralotherflagsapplyto suchchannels.Insuchacase,insteadofanoffset,thereisapointertoanassociatedmultiplex channeltable.Multiplexchannelswillnotbediscussedhere. Anentryinthefiletablecorrespondspreciselytoaninstanceofopenorcreat;ifthesame fileisopenedseveraltimes,itwillhaveseveralentriesinthistable.However,thereisatmostone entryintheinodetableforagivenfile.Also,afilemayentertheinodetablenotonlybecauseit isopen,butalsobecauseitisthecurrentdirectoryofsomeprocessorbecauseitisaspecialfile containingacurrently-mountedfilesystem. Anentryintheinodetabledifferssomewhatfromthecorrespondingi-nodeasstoredonthe disk;themodifiedandaccessedtimesarenotstored,andtheentryisaugmentedbyaflagword containinginformationabouttheentry,acountusedtodeterminewhenitmaybeallowedtodisappear,andthedeviceandi-numberwhencetheentrycame.Also,theseveralblocknumbers thatgiveaddressinginformationforthefileareexpandedfromthe3-byte,compressedformat usedonthedisktofulllongquantities. Duringtheprocessingofanopenorcreatcallforaspecialfile,thesystemalwayscallsthe device’sopenroutinetoallowforanyspecialprocessingrequired(rewindingatape,turningon thedata-terminal-readyleadofamodem,etc.).However,thecloseroutineiscalledonlywhen thelastprocessclosesafile,thatis,whenthei-nodetableentryisbeingdeallocated.Thusitis notfeasibleforadevicetomaintain,ordependon,acountofitsusers,althoughitisquitepossibletoimplementanexclusive-usedevicewhichcannotbereopeneduntilithasbeenclosed. Whenareadorwritetakesplace,theuser’sargumentsandthefiletableentryareusedto setupthevariablesu.ubase,u.ucount,andu.uoffsetwhichrespectivelycontainthe(user) addressoftheI/Otargetarea,thebyte-countforthetransfer,andthecurrentlocationinthefile. Ifthefilereferredtoisacharacter-typespecialfile,theappropriatereadorwriteroutineiscalled; itisresponsiblefortransferringdataandupdatingthecountandcurrentlocationappropriately asdiscussedbelow.Otherwise,thecurrentlocationisusedtocalculatealogicalblocknumberin thefile.Ifthefileisanordinaryfilethelogicalblocknumbermustbemapped(possiblyusing indirectblocks)toaphysicalblocknumber;ablock-typespecialfileneednotbemapped.This mappingisperformedbythebmaproutine.Inanyevent,theresultingphysicalblocknumberis used,asdiscussedbelow,toreadorwritetheappropriatedevice. CharacterDeviceDrivers Thecdevswtablespecifiestheinterfaceroutinespresentforcharacterdevices.Eachdevice providesfiveroutines:open,close,read,write,andspecial-function(toimplementtheioctlsystem call).Anyofthesemaybemissing.Ifacallontheroutineshouldbeignored,(e.g.openonnonexclusivedevicesthatrequirenosetup)thecdevswentrycanbegivenasnulldev;ifitshouldbe consideredanerror,(e.g.writeonread-onlydevices)nodevisused.Forterminals,thecdevsw structurealsocontainsapointertothettystructureassociatedwiththeterminal. Theopenroutineiscalledeachtimethefileisopenedwiththefulldevicenumberasargument.Thesecondargumentisaflagwhichisnon-zeroonlyifthedeviceistobewrittenupon. Thecloseroutineiscalledonlywhenthefileisclosedforthelasttime,thatiswhenthe verylastprocessinwhichthefileisopenclosesit.Thismeansitisnotpossibleforthedriverto maintainitsowncountofitsusers.Thefirstargumentisthedevicenumber;thesecondisaflag whichisnon-zeroifthefilewasopenforwritingintheprocesswhichperformsthefinalclose. Whenwriteiscalled,itissuppliedthedeviceasargument.Theper-uservariableu.ucount hasbeensettothenumberofcharactersindicatedbytheuser;forcharacterdevices,thisnumber maybe0initially.u.ubaseistheaddresssuppliedbytheuserfromwhichtostarttakingcharacters.Thesystemmaycalltheroutineinternally,sotheflagu.usegflgissuppliedthatindicates,if on,thatu.ubasereferstothesystemaddressspaceinsteadoftheuser’s. Thewriteroutineshouldcopyuptou.ucountcharactersfromtheuser’sbuffertothe device,decrementingu.ucountforeachcharacterpassed.Formostdrivers,whichworkonecharacteratatime,theroutinecpass()isusedtopickupcharactersfromtheuser’sbuffer.

-3-Successivecallsonitreturnthecharacterstobewrittenuntilu.ucountgoesto0oranerror occurs,whenitreturns−1.Cpasstakescareofinterrogatingu.usegflgandupdatingu.ucount. Writeroutineswhichwanttotransferaprobablylargenumberofcharactersintoaninternal buffermayalsousetheroutineiomove(buffer,offset,count,flag)whichisfasterwhenmanycharactersmustbemoved.Iomovetransfersuptocountcharactersintothebufferstartingoffset bytesfromthestartofthebuffer;flagshouldbeBWRITE(whichis0)inthewritecase.Caution:thecallerisresponsibleformakingsurethecountisnottoolargeandisnon-zero.Asan efficiencynote,iomoveismuchslowerifanyofbuffer+offset,countoru.ubaseisodd. Thedevice’sreadroutineiscalledunderconditionssimilartowrite,exceptthatu.ucountis guaranteedtobenon-zero.Toreturncharacterstotheuser,theroutinepassc(c)isavailable;it takescareofhousekeepinglikecpassandreturns−1asthelastcharacterspecifiedbyu.ucountis returnedtotheuser;beforethattime,0isreturned.Iomoveisalsousableaswithwrite;theflag shouldbeBREADbutthesamecautionsapply. The‘‘special-functions’’routineisinvokedbythesttyandgttysystemcallsasfollows:(*p) (dev,v)wherepisapointertothedevice’sroutine,devisthedevicenumber,andvisavector. Inthegttycase,thedeviceissupposedtoplaceupto3wordsofstatusinformationintothevector;thiswillbereturnedtothecaller.Inthesttycase,vis0;thedeviceshouldtakeupto3 wordsofcontrolinformationfromthearrayu.uarg[0...2]. Finally,eachdeviceshouldhaveappropriateinterrupt-timeroutines.Whenaninterrupt occurs,itisturnedintoaC-compatiblecallonthedevices’sinterruptroutine.Theinterrupt-catchingmechanismmakesthelow-orderfourbitsofthe‘‘newPS’’wordinthetrapvectorforthe interruptavailabletotheinterrupthandler.Thisisconventionallyusedbydriverswhichdeal withmultiplesimilardevicestoencodetheminordevicenumber.Aftertheinterrupthasbeen processed,areturnfromtheinterrupthandlerwillreturnfromtheinterruptitself. Anumberofsubroutinesareavailablewhichareusefultocharacterdevicedrivers.Mostof thesehandlers,forexample,needaplacetobuffercharactersintheinternalinterfacebetween their‘‘tophalf’’(read/write)and‘‘bottomhalf’’(interrupt)routines.Forrelativelylowdata-rate devices,thebestmechanismisthecharacterqueuemaintainedbytheroutinesgetcandputc.A queueheaderhasthestructure struct{ intccc;/*charactercount*/ char*ccf;/*firstcharacter*/ char*ccl;/*lastcharacter*/ }queue; Acharacterisplacedontheendofaqueuebyputc(c,&queue)wherecisthecharacterandqueue isthequeueheader.Theroutinereturns−1ifthereisnospacetoputthecharacter,0otherwise. Thefirstcharacteronthequeuemayberetrievedbygetc(&queue)whichreturnseitherthe(nonnegative)characteror−1ifthequeueisempty. Noticethatthespaceforcharactersinqueuesissharedamongalldevicesinthesystemand inthestandardsystemthereareonlysome600characterslotsavailable.Thusdevicehandlers, especiallywriteroutines,musttakecaretoavoidgobblingupexcessivenumbersofcharacters. Theothermajorhelpavailabletodevicehandlersisthesleep-wakeupmechanism.Thecall sleep(event,priority)causestheprocesstowait(allowingotherprocessestorun)untiltheevent occurs;atthattime,theprocessismarkedready-to-runandthecallwillreturnwhenthereisno processwithhigherpriority. Thecallwakeup(event)indicatesthattheeventhashappened,thatis,causesprocesses sleepingontheeventtobeawakened.Theeventisanarbitraryquantityagreeduponbythe sleeperandthewaker-up.Byconvention,itistheaddressofsomedataareausedbythedriver, whichguaranteesthateventsareunique. Processessleepingonaneventshouldnotassumethattheeventhasreallyhappened;they shouldcheckthattheconditionswhichcausedthemtosleepnolongerhold.

-4-Prioritiescanrangefrom0to127;ahighernumericalvalueindicatesaless-favoredschedul-ingsituation.Adistinctionismadebetweenprocessessleepingatprioritylessthantheparameter PZEROandthoseatnumericallylargerpriorities.Theformercannotbeinterruptedbysignals, althoughitisconceivablethatitmaybeswappedout.Thusitisabadideatosleepwithpriority lessthanPZEROonaneventwhichmightneveroccur.Ontheotherhand,callstosleepwith largerprioritymayneverreturniftheprocessisterminatedbysomesignalinthemeantime. Incidentally,itisagrosserrortocallsleepinaroutinecalledatinterrupttime,sincetheprocess whichisrunningisalmostcertainlynottheprocesswhichshouldgotosleep.Likewise,noneof thevariablesintheuserarea‘‘u.’’shouldbetouched,letalonechanged,byaninterruptroutine. Ifadevicedriverwishestowaitforsomeeventforwhichitisinconvenientorimpossibleto supplyawakeup,(forexample,adevicegoingon-line,whichdoesnotgenerallycauseaninter-rupt),thecallsleep(&lbolt,priority)maybegiven.Lboltisanexternalcellwhoseaddressis awakenedonceevery4secondsbytheclockinterruptroutine. Theroutinesspl4(),spl5(),spl6(),spl7()areavailabletosettheprocessorprioritylevel asindicatedtoavoidinconvenientinterruptsfromthedevice. Ifadeviceneedstoknowaboutreal-timeintervals,thentimeout(func,arg,interval)willbe useful.Thisroutinearrangesthatafterintervalsixtiethsofasecond,thefuncwillbecalledwith argasargument,inthestyle(*func)(arg).Timeoutsareused,forexample,toprovidereal-time delaysafterfunctioncharacterslikenew-lineandtabintypewriteroutput,andtoterminatean attempttoreadthe201Dataphonedpifthereisnoresponsewithinaspecifiednumberofseconds.Noticethatthenumberofsixtiethsofasecondislimitedto32767,sinceitmustappearto bepositive,andthatonlyaboundednumberoftimeoutscanbegoingonatonce.Also,thespecifiedfunciscalledatclock-interrupttime,soitshouldconformtotherequirementsofinterrupt routinesingeneral. TheBlock-deviceInterface Handlingofblockdevicesismediatedbyacollectionofroutinesthatmanageasetofbuffers containingtheimagesofblocksofdataonthevariousdevices.Themostimportantpurposeof theseroutinesistoassurethatseveralprocessesthataccessthesameblockofthesamedevicein multiprogrammedfashionmaintainaconsistentviewofthedataintheblock.Asecondarybut stillimportantpurposeistoincreasetheefficiencyofthesystembykeepingin-corecopiesof blocksthatarebeingaccessedfrequently.Themaindatabaseforthismechanismisthetableof buffersbuf.Eachbufferheadercontainsapairofpointers(bforw,bback)whichmaintainadoubly-linkedlistofthebuffersassociatedwithaparticularblockdevice,andapairofpointers (avforw,avback)whichgenerallymaintainadoubly-linkedlistofblockswhichare‘‘free,’’that is,eligibletobereallocatedforanothertransaction.BuffersthathaveI/Oinprogressorarebusy forotherpurposesdonotappearinthislist.Thebufferheaderalsocontainsthedeviceandblock numbertowhichthebufferrefers,andapointertotheactualstorageassociatedwiththebuffer. Thereisawordcountwhichisthenegativeofthenumberofwordstobetransferredtoorfrom thebuffer;thereisalsoanerrorbyteandaresidualwordcountusedtocommunicateinformation fromanI/Oroutinetoitscaller.Finally,thereisaflagwordwithbitsindicatingthestatusof thebuffer.Theseflagswillbediscussedbelow. Sevenroutinesconstitutethemostimportantpartoftheinterfacewiththerestofthesystem.Givenadeviceandblocknumber,bothbreadandgetblkreturnapointertoabufferheader fortheblock;thedifferenceisthatbreadisguaranteedtoreturnabufferactuallycontainingthe currentdatafortheblock,whilegetblkreturnsabufferwhichcontainsthedataintheblockonly ifitisalreadyincore(whetheritisornotisindicatedbytheBDONEbit;seebelow).Ineither casethebuffer,andthecorrespondingdeviceblock,ismade‘‘busy,’’sothatotherprocessesreferringtoitareobligedtowaituntilitbecomesfree.Getblkisused,forexample,whenablockis abouttobetotallyrewritten,sothatitspreviouscontentsarenotuseful;still,nootherprocess canbeallowedtorefertotheblockuntilthenewdataisplacedintoit. Thebreadaroutineisusedtoimplementread-ahead.itislogicallysimilartobread,but takesasanadditionalargumentthenumberofablock(onthesamedevice)toberead -5-asynchronouslyafterthespecificallyrequestedblockisavailable. Givenapointertoabuffer,thebrelseroutinemakesthebufferagainavailabletootherprocesses.Itiscalled,forexample,afterdatahasbeenextractedfollowingabread.Therearethree subtly-differentwriteroutines,allofwhichtakeabufferpointerasargument,andallofwhichlog-icallyreleasethebufferforusebyothersandplaceitonthefreelist.Bwriteputsthebufferon theappropriatedevicequeue,waitsforthewritetobedone,andsetstheuser’serrorflagif required.Bawriteplacesthebufferonthedevice’squeue,butdoesnotwaitforcompletion,so thaterrorscannotbereflecteddirectlytotheuser.BdwritedoesnotstartanyI/Ooperationat all,butmerelymarksthebuffersothatifithappenstobegrabbedfromthefreelisttocontain datafromsomeotherblock,thedatainitwillfirstbewrittenout. BwriteisusedwhenonewantstobesurethatI/Otakesplacecorrectly,andthaterrorsare reflectedtotheproperuser;itisused,forexample,whenupdatingi-nodes.Bawriteisuseful whenmoreoverlapisdesired(becausenowaitisrequiredforI/Otofinish)butwhenitisreasonablycertainthatthewriteisreallyrequired.Bdwriteisusedwhenthereisdoubtthatthewrite isneededatthemoment.Forexample,bdwriteiscalledwhenthelastbyteofawritesystemcall fallsshortoftheendofablock,ontheassumptionthatanotherwritewillbegivensoonwhich willre-usethesameblock.Ontheotherhand,astheendofablockispassed,bawriteiscalled, sinceprobablytheblockwillnotbeaccessedagainsoonandonemightaswellstartthewriting processassoonaspossible. Inanyevent,noticethattheroutinesgetblkandbreaddedicatethegivenblockexclusivelyto theuseofthecaller,andmakeotherswait,whileoneofbrelse,bwrite,bawrite,orbdwritemust eventuallybecalledtofreetheblockforusebyothers. Asmentioned,eachbufferheadercontainsaflagwordwhichindicatesthestatusofthe buffer.Sincetheyprovideoneimportantchannelforinformationbetweenthedriversandthe blockI/Osystem,itisimportanttounderstandtheseflags.Thefollowingnamesaremanifest constantswhichselecttheassociatedflagbits. BREADThisbitissetwhenthebufferishandedtothedevicestrategyroutine(seebelow)to indicateareadoperation.ThesymbolBWRITEisdefinedas0anddoesnotdefinea flag;itisprovidedasamnemonicconveniencetocallersofroutineslikeswapwhich haveaseparateargumentwhichindicatesreadorwrite. BDONEThisbitissetto0whenablockishandedtothethedevicestrategyroutineandis turnedonwhentheoperationcompletes,whethernormallyastheresultofanerror. Itisalsousedaspartofthereturnargumentofgetblktoindicateif1thatthe returnedbufferactuallycontainsthedataintherequestedblock. BERROR Thisbitmaybesetto1whenBDONEissettoindicatethatanI/Oorothererror occurred.Ifitissettheberrorbyteofthebufferheadermaycontainanerrorcodeif itisnon-zero.Ifberroris0thenatureoftheerrorisnotspecified.Actuallyno driveratpresentsetsberror;thelatterisprovidedforafutureimprovementwhereby amoredetailederror-reportingschememaybeimplemented. BBUSYThisbitindicatesthatthebufferheaderisnotonthefreelist,i.e.isdedicatedto someone’sexclusiveuse.Thebufferstillremainsattachedtothelistofblocksassociatedwithitsdevice,however.Whengetblk(orbread,whichcallsit)searchesthe bufferlistforagivendeviceandfindstherequestedblockwiththisbiton,itsleeps untilthebitclears. BPHYSThisbitissetforrawI/OtransactionsthatneedtoallocatetheUnibusmaponan 11/70. BMAPThisbitissetonbuffersthathavetheUnibusmapallocated,sothattheiodoneroutineknowstodeallocatethemap. BWANTED ThisflagisusedinconjunctionwiththeBBUSYbit.Beforesleepingasdescribed -6-justabove,getblksetsthisflag.Conversely,whentheblockisfreedandthebusybit goesdown(inbrelse)awakeupisgivenfortheblockheaderwheneverBWANTEDis on.Thisstrategemavoidstheoverheadofhavingtocallwakeupeverytimeabufferis freedonthechancethatsomeonemightwantit. BAGEThisbitmaybesetonbuffersjustbeforereleasingthem;ifitison,thebufferis placedattheheadofthefreelist,ratherthanatthetail.Itisaperformanceheuristic usedwhenthecallerjudgesthatthesameblockwillnotsoonbeusedagain. BASYNC Thisbitissetbybawritetoindicatetotheappropriatedevicedriverthatthebuffer shouldbereleasedwhenthewritehasbeenfinished,usuallyatinterrupttime.The differencebetweenbwriteandbawriteisthattheformerstartsI/O,waitsuntilitis done,andfreesthebuffer.ThelattermerelysetsthisbitandstartsI/O.Thebit indicatesthatrelseshouldbecalledforthebufferoncompletion. BDELWRI Thisbitissetbybdwritebeforereleasingthebuffer.Whengetblk,whilesearchingfor afreeblock,discoversthebitis1inabufferitwouldotherwisegrab,itcausesthe blocktobewrittenoutbeforereusingit. BlockDeviceDrivers Thebdevswtablecontainsthenamesoftheinterfaceroutinesandthatofatableforeach blockdevice. Justasforcharacterdevices,blockdevicedriversmaysupplyanopenandacloseroutine calledrespectivelyoneachopenandonthefinalcloseofthedevice.Insteadofseparatereadand writeroutines,eachblockdevicedriverhasastrategyroutinewhichiscalledwithapointertoa bufferheaderasargument.Asdiscussed,thebufferheadercontainsaread/writeflag,thecore address,theblocknumber,a(negative)wordcount,andthemajorandminordevicenumber. Theroleofthestrategyroutineistocarryouttheoperationasrequestedbytheinformationin thebufferheader.WhenthetransactioniscompletetheBDONE(andpossiblytheBERROR) bitsshouldbeset.TheniftheBASYNCbitisset,brelseshouldbecalled;otherwise,wakeup. Incaseswherethedeviceiscapable,undererror-freeoperation,oftransferringfewerwordsthan requested,thedevice’sword-countregistershouldbeplacedintheresidualcountslotofthebuffer header;otherwise,theresidualcountshouldbesetto0.Thisparticularmechanismisreallyfor thebenefitofthemagtapedriver;whenreadingthisdevicerecordsshorterthanrequestedare quitenormal,andtheusershouldbetoldtheactuallengthoftherecord. Althoughthemostusualargumenttothestrategyroutinesisagenuinebufferheaderallocatedasdiscussedabove,allthatisactuallyrequiredisthattheargumentbeapointertoaplace containingtheappropriateinformation.Forexampletheswaproutine,whichmanagesmovement ofcoreimagestoandfromtheswappingdevice,usesthestrategyroutineforthisdevice.Care hastobetakenthatnoextraneousbitsgetturnedonintheflagword. Thedevice’stablespecifiedbybdevswhasabytetocontainanactiveflagandanerror count,apairoflinkswhichconstitutetheheadofthechainofbuffersforthedevice(bforw, bback),andafirstandlastpointerforadevicequeue.Ofthesethings,allareusedsolelybythe devicedriveritselfexceptforthebuffer-chainpointers.Typicallytheflagencodesthestateofthe device,andisusedataminimumtoindicatethatthedeviceiscurrentlyengagedintransferring informationandnonewcommandshouldbeissued.Theerrorcountisusefulforcountingretries whenerrorsoccur.Thedevicequeueisusedtorememberstackedrequests;inthesimplestcaseit maybemaintainedasafirst-infirst-outlist.Sincebufferswhichhavebeenhandedovertothe strategyroutinesareneveronthelistoffreebuffers,thepointersinthebufferwhichmaintainthe freelist(avforw,avback)arealsousedtocontainthepointerswhichmaintainthedevice queues. Acoupleofroutinesareprovidedwhichareusefultoblockdevicedrivers.iodone(bp) arrangesthatthebuffertowhichbppointsbereleasedorawakened,asappropriate,whenthe -7-strategymodulehasfinishedwiththebuffer,eithernormallyorafteranerror.(Inthelattercase theBERRORbithaspresumablybeenset.) Theroutinegeterror(bp)canbeusedtoexaminetheerrorbitinabufferheaderandarrange thatanyerrorindicationfoundthereinisreflectedtotheuser.ItmaybecalledonlyinthenoninterruptpartofadriverwhenI/Ohascompleted(BDONEhasbeenset). RawBlock-deviceI/O Aschemehasbeensetupwherebyblockdevicedriversmayprovidetheabilitytotransfer informationdirectlybetweentheuser’scoreimageandthedevicewithouttheuseofbuffersand inblocksaslargeasthecallerrequests.Themethodinvolvessettingupacharacter-typespecial filecorrespondingtotherawdeviceandprovidingreadandwriteroutineswhichsetupwhatis usuallyaprivate,non-sharedbufferheaderwiththeappropriateinformationandcallthedevice’s strategyroutine.Ifdesired,separateopenandcloseroutinesmaybeprovidedbutthisisusually unnecessary.Aspecial-functionroutinemightcomeinhandy,especiallyformagtape. Agreatdealofworkhastobedonetogeneratethe‘‘appropriateinformation’’toputinthe argumentbufferforthestrategymodule;theworstpartistomaprelocateduseraddressesto physicaladdresses.Mostofthisworkisdonebyphysio(strat,bp,dev,rw)whoseargumentsare thenameofthestrategyroutinestrat,thebufferpointerbp,thedevicenumberdev,andareadwriteflagrwwhosevalueiseitherBREADorBWRITE.Physiomakessurethattheuser’s baseaddressandcountareeven(becausemostdevicesworkinwords)andthatthecorearea affectediscontiguousinphysicalspace;itdelaysuntilthebufferisnotbusy,andmakesitbusy whiletheoperationisinprogress;anditsetsupusererrorreturninformation.