// IFSDisksOEP.bcpl
// Copyright Xerox Corporation 1979, 1980
// Last modified March 6, 1980  3:48 PM by Taft

get "IfsDDMgr.decl"
get "IfsInit.decl"

external
[
// Outgoing procedures
InitDisksOEP; InitDisksFinish

// Incoming procedures
DeclareOEP; DeclareXEP; IFSFinish; IFSError
TFSWritePages; TFSAssignDiskPage; TFSClose
TFSCreateFile; TFSDeletePages; TFSReleaseDiskPage
IFSOpenDD; IFSCloseDD; IFSLockDD; IFSUnlockDD; IFSReadDDPage
TFSDestroyDDMgr; TFSCloseDD; TFSLockDD; TFSUnlockDD; TFSReadDDPage; TFSFlushDD
ScanDirBuffer

// Incoming statics
lvUserFinishProc; primaryIFS; ifsDDMgr
]

manifest ecBadUFP = 23

// InitDisksOEP is called to declare IFSFinish (among others)
//  to the overlay package as being an OEP.
// InitDisksFinish is called after the overlay package has been
//  initialized, to store the OEP pointer into the finish procedure
//  cell (which previously contains a pointer to IFSFinish itself).
// The swappable procedures in the disk and ifsDDMgr objects
//  have to be handled similarly, since these objects are created
//  before OEPs have been set up and hence will contain pointers
//  to the copies of the procedures in the resident initialization.
// The analogous TFS DDMgr object does not have this problem because
//  no instance of it survives overlay initialization.

//----------------------------------------------------------------------------
let InitDisksOEP(oev) be
//----------------------------------------------------------------------------
[
if @lvUserFinishProc ne IFSFinish then IFSError(ecBadUFP)
DeclareOEP(oev, lv IFSFinish,
 lv TFSWritePages, lv TFSAssignDiskPage, lv TFSCreateFile,
 lv TFSDeletePages, lv TFSReleaseDiskPage, lv TFSClose)
DeclareOEP(oev, lv IFSOpenDD, lv IFSCloseDD, lv IFSLockDD,
 lv IFSUnlockDD, lv IFSReadDDPage)
DeclareOEP(oev, lv TFSDestroyDDMgr, lv TFSCloseDD, lv TFSLockDD,
 lv TFSUnlockDD, lv TFSReadDDPage, lv TFSFlushDD)
DeclareXEP(oev, lv ScanDirBuffer)
]

//----------------------------------------------------------------------------
and InitDisksFinish() be
//----------------------------------------------------------------------------
[
@lvUserFinishProc = IFSFinish
for i = 0 to primaryIFS>>IFS.numUnits-1 do
   [
   let disk = primaryIFS>>IFS.lpdt↑i
   disk>>DSK.WriteDiskPages = TFSWritePages
   disk>>DSK.AssignDiskPage = TFSAssignDiskPage
   disk>>DSK.CreateDiskFile = TFSCreateFile
   disk>>DSK.DeleteDiskPages = TFSDeletePages
   disk>>DSK.ReleaseDiskPage = TFSReleaseDiskPage
   disk>>DSK.CloseDisk = TFSClose
   ]
ifsDDMgr>>DDMgr.OpenDD = IFSOpenDD
ifsDDMgr>>DDMgr.CloseDD = IFSCloseDD
ifsDDMgr>>DDMgr.LockDD = IFSLockDD
ifsDDMgr>>DDMgr.UnlockDD = IFSUnlockDD
ifsDDMgr>>DDMgr.ReadDDPage = IFSReadDDPage
]