417 lines
118 KiB
Plaintext
417 lines
118 KiB
Plaintext
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. |