StreamsandFileDevicesEdited30Nov84,vanMelleAnInterlispStreamisanobjectofdatatypeSTREAMthatiscapableofperforming,attheleast,sequentialinputand/oroutputofbytes.Somestreamscandomuchmore.Streamsareusedforaccesstoopenfiles,forwritingtothedisplay,forchattingtoremotehosts,andwhateverotherusespeoplecomeupwith.Thisdocumentdescribeshowonegoesaboutdefininganewdevice,themeaningsoftherecordfieldsoftheSTREAMandFDEVdatatypes,andanythingelsethatseemedrelevantatthetime.TheimplementationofStreamsisstronglyobject-oriented.EverySTREAMhasapointertoadevice(thedatatypeFDEV),whichcontainsavectoroffunctionstobecalledwhencertainoperationsarerequiredofthestream.Therecanbemanystreamswiththesamedevice.Intheobject-orientedtermsofLOOPS,onecanthinkofthedeviceasaclass,whichprovidesasetofmethodsthatimplementclassoperations,andthestreamsasinstances.Devicesandstreamsalsohavelocalstate,whichmightbethoughtofasclassandinstancevariables.DeclarationsforSTREAMandFDEVcanbeobtainedbyloadingEXPORTS.ALL.OPENSTREAM,CLOSEF,FORCEOUTPUT,READP,EOFP,GETEOFPTR,GETFILEINFO,SETFILEINFO,DIRECTORY,COPYBYTES,DELFILE,RENAMEFILE,FULLNAMEaresomeoftheLispfunctionscalledbytheprogrammerthatultimatelyturnintooperationsatthedevicelevel.Thedescriptionsthatfollowsometimesalludetothesefunctions,andknowledgeofhowtheyoperatemayoccasionallygivethereaderadditionalcluesastohowthedeviceoperationswork.Typically,somepartoftheoperationishandledbythe``generic''filesystemcode,whichthencallsonthedevicetohandlethatpartoftheoperationthatisdevice-specific.Forexample,thefunctionOPENFILEtakesthenameofthefileitistoopenandfillsinhostanddirectorydefaults,anddecideswhichdevicehandlessuchafile.Itthencallsontheparticulardevicetoactuallyopenthefile.Afterthefileisopened,thegenericfilesystemcoderegistersthefileon(OPENP).Asanotherexample,operationsinvolvingopenstreamsfirstcoercenon-streams(e.g.filenames)toopenstreamsbeforecallingthedevice-specificoperation.DevicesAdeviceisanobjectoftypeFDEV(sonamedforhistoricalreasons:``FileDevice'').Thestandardwaytodefineanewdeviceistocreatesuchanobject,byperforming(createFDEV--),andthenpassthenewlycreatedFDEVtothefunction\DEFINEDEVICE.\DEFINEDEVICEisthewayadevice``announces''itselftothegenericfilesystem.(\DEFINEDEVICENAMEDEV)[Function]InstallsdeviceDEV,givingitthenameNAME.NAMEmustbeanuppercaselitatom.Thegenericfilesystemcodemakesuseofthenametolocatethedevicethatiswillingtodealwithfileswhosefullnamebegins{NAME}.Itispermissibletohavemorethanonenamemaptothesamedevice;thiseffectivelyprovidesdevicesynonyms.Devicesareencouraged,however,toalwayscreatefilenamesusingthecanonicaldevicename,independentofwhatnamewaspassedin.NAMEcanbeNIL,inwhichcasethegenericfilesystemcodeneverconsultsthedevicedirectly.However,itsEVENTFNisstillrunaroundLispexits,anditcanbeusedasthedeviceforastreamcreatedbynonstandardmethods. q?` p q?` g_paoq&**/I7|aorao7ao ]s [c] ZarDe%%ZatZa*ZarZa*-i.35 =>@Dr JJZa X u:$g&(,Y00z57:<@BKEHJJX VrH!W&),26R9[=ACGAGJJV Tof|:f#X( *-143:a<->BFHJJT S0tS0rS0VS0tS0;S0rS0 W#&^(-2436d9_S0 O t&$m.?.22OtO7OrO8d: <@B CHJJO MaaMtMMrM +"-#)+.- 04i8 ?VAFHJJM L1*Z F#W%)%-.5/2U;?A4A4LsLDLrL EHdJJL JF e(@ JFuJFyJFrJF - $n %n'a((JFuJF-JFrJF. 07a:f A;CEJJJF HiHiuHiHirHi zw~"]%),046<=?BEJJHi F ,FtFFrFV!!FtF%;FrF%')/1055FtF >FrF ?PF Ct ZCrC yyCtCCrC CtC "CrC ##CtC(1CrC )P)PCtC,CrC --CtC5ZCrC 6y6yCtC ?CrC @@CtC JCrC JJC A?tA?rA? bbA?tA?A?rA? A?tA? A?rA? !!A?tA? )A?rA? **A?tA?1A?rA?24k79<?3E-HJJA? ?l L!$ +s-D/4S8%8;CFJJ?l = ^#)+.169AZDJFJJ= ; 6yzO &)`; 8g >\ "<')x+ 14U8BGJJ4 3 s}p\ #%r*j-02368;+<}ACHJJ3 16F/FF16t16$'16r16 %%',2 9?CHJJ16 /c ` P#(X,w02; A/c *vj*r*p* '/ ,0'/t'/R'/r'/"&( .47 =>*A FIAJJ'/ %\ R!%' ..%\t%\ /%\w%\4R%\r%\44%\t%\8;~%\r%\ <<>ADFJJ%\ #t#tt#t#tr#tUkk#tt#t&V#tr#t ''q'q#tt#t2\#tr#t246A8 9>FIBJJ#t !%H! 0t 0x00t00x0D0t0 0r0DL Ob0C/``CxCCrC !$7''CxC+^CrC ,*,,CxC0CrC0357=BCcF)JJCy:b| "q$(V)-04'68&<>@CFJJy xr i ".#~ *,*/S258`<? @BF4JJ #,)*4/81s 9>@VDHJJ Q 1$E(. /1t483:>@l7x 7r77t7~7r7 V"$'C,.e269?AmEJKK7dhhdtdIdrd "%),0236W8-;M<?&CNEp FJJd * $ q?` 2Ifadeviceneverwantstobeinvokedbyname,andhasnointerestingEVENTFNorHOSTNAMEPmethods,thenthereisnoneedtoeverregisteritwith\DEFINEDEVICE.(\REMOVEDEVICEDEV)[Function]RemovesdeviceDEVfromthelistofknowndevices,aswellasanynamethatmapstothatdevice.(\GETDEVICEFROMNAMENAMENOERRORDONTCREATE)[Function]ReturnsthedeviceassociatedwithNAME.NAMEcanbealitatomorstring;itiscoercedtouppercase,andifitbeginswithanopenbrace,isassumedtobeafilename,fromwhichthehostnameisextracted.Ifnosuchdeviceisknown,attemptstofindonebypollingtheHOSTNAMEPmethodsofallknowndevices(seebelow);ifadeviceisstillnotfound,causesaFILENOTFOUNDerrorunlessNOERRORistrue.IfDONTCREATEistrue,itneverattemptstocreateadevice,justreturnsanexistingdeviceifthereisone,NILotherwise.ThefieldsofanFDEVaredividedupintoinformationalfieldsand``methods''.DEVICENAMEApointerfield,thenameofthedevice,standardlyalitatom.Useofthisfieldislargelyuptothedevice,butitisusuallyselectedtobethenamethatappearsinsidebracesinfilenamesopenedonthisdevice.Fordevicesthatdonotsupportthenotionofnamedfiles,DEVICENAMEcanbeanythingthattheimplementorcarestousefordebuggingassistance.RESETABLEAflag,trueif(SETFILEPTRstream0)canbeperformed.Currentlyunused.RANDOMACCESSPTrueifthestreamisrandomlyaccessable,i.e.,ifSETFILEPTRworksonthiskindofstream.NODIRECTORIESTrueiffilesopenedonthisdevicedonot(usually)haveadirectoryaspartoftheirname.TheprincipaluseforthisisbytheCONNcommand,whichwillnottrytoconnecttotheuser'shomedirectoryifgivenahostonly,e.g.,CONN{DSK}.BUFFEREDTrueifstreamsofthissortarebufferedinamannercompatiblewiththemicrocodedversionsofBINandBOUT.Morespecifically,BUFFEREDimpliesthatthedeviceimplementstheGETNEXTBUFFERmethod.Seedescriptionofbufferedstreams.PAGEMAPPEDTrueifthisstreamisimplementedbythepagemappedfunctions.Allpagemappedstreamsarealsobuffered,soifthisflagistrue,soshouldbeBUFFERED.Seedescriptionofpagemappedstreams.FDBINABLETrueifstreamsonthisdeviceobeytherulesformicrocodedBINwheneversuchstreamisopenforinputaccess.FDBOUTABLETrueifstreamsonthisdeviceobeytherulesformicrocodedBOUTwheneversuchstreamisopenforoutputaccess.Currentlyunused,asthespecneedsrevision.FDEXTENDABLESpecialkindofFDBOUTABLE.Currentlyunused,asthespecneedsrevision.DEVICEINFOApointertoarbitrarydevice-specificinformation.Thestandarduseforthisistoholdlocalstatespecifictooneofseveralsimilardevicesthatsharemethods.Forexample, $ fr hsp hsbr B ["7'_)F-H/2J4; ::btb@brbA,BBbtbJjbrbJJb`.G>"$\'2+-//`.t`.:`.r`. ;;`. \t \x\\t\ \r\DL Ob\YRffYxYYrY& ^"$&(*}/m035-7;1=A@BE_IxY VVtVVxVV8VVtVVVVxVV$VVtVV%%VVxVV -VVtVV .WVVrVVDL ObVVSiu #n&&SixSi*'SirSi +,++SixSi/RSirSi0 24 6:<AVBDhIBJJSiQ ;&e #%x(,.35+7 8:k>kAEGJJQOE S"'#(-U24{7]9;@BBOtOJiOrOJJON5 #&l+, .<2469]=B( CkCkNtNGK@K@NL/L/rL/+}L/xL/"4L/rL/"#''k((L/xL/ 0L/rL/12j56:i?AgEI FUJJL/J\I""6#i&(**J\tJ\-[J\rJ\- 3J\ F!ooFtFFrF#I"*.x17F Cht ZChrCh/ 5 "&i'*5. 5. 64;;s>?B)E1FwJJCh/A, !#%<&++0?1359<\AOE8IBJJA/?6!#&a*+E-2z5*79j>T@DFjJJ?/>kk>t> ">r>#N%'-]0!2w :=?BD;JJ>/<. <. 8t8r8/ n#VV8t8 (8r8(-,-,8t8.8r8/213R :;:@E?8 5Ct5Cr5C/."#* 03s445Ct5C =15Cr5C=ACF6I6JJ5C/3pu3p /t/r//#%(,.1R6:G ;xALCEGJJ//.,h$'),.90X22.,t.,66.,r.,6=ADGHIBJJ.,/,Y#l',-1i 2f508r;%;%,Yt,Y?XC,Yr,Y C,Y (t(r(/| "a$')/m1 2+7' >$A0C JJ(/'{{'t'! 'r'!$$'t'''r' ()-r44't';'r'