// IfsVMemFileRes.bcpl -- VMem access to IFS files -- resident
// Copyright Xerox Corporation 1979, 1980, 1981

// Last modified November 14, 1981  4:43 PM by Taft

get "IfsVMem.decl"

external
[
//outgoing procedures
VFileReadPage; VFileWritePage
VFilePageType; VFilePageGroupSize; VFilePageGroupBase; VFilePageGroupAlign
VFileDOPAGEIO

//incoming procedures
CallProc; @VRRP; @VWRP; IndexedPageIO; Yield
]


// Top-level procedures to access a specified page of a file designated by
// a File Virtual Memory Descriptor (FVMD).  File page numbers are used;
// i.e., page zero is the leader page, page 1 is the first data page, etc.

//----------------------------------------------------------------------------
let VFileReadPage(vmd, page) = valof
//----------------------------------------------------------------------------
[
Yield()
resultis VRRP(vmd>>VMD.base + page lshift vmd>>FVMD.logVPagesPerDiskPage)
]

//----------------------------------------------------------------------------
and VFileWritePage(vmd, page) = valof
//----------------------------------------------------------------------------
[
Yield()
resultis VWRP(vmd>>VMD.base + page lshift vmd>>FVMD.logVPagesPerDiskPage)
]


// Underlying procedures called by VMEM

//----------------------------------------------------------------------------
and VFilePageType(vmd, vPage) = 1
//----------------------------------------------------------------------------

//----------------------------------------------------------------------------
and VFilePageGroupSize(vmd, vPage) = -1 lshift vmd>>FVMD.logPageGroupSize
//----------------------------------------------------------------------------

//----------------------------------------------------------------------------
and VFilePageGroupBase(vmd, vPage) =
//----------------------------------------------------------------------------
   vPage & (-1 lshift vmd>>FVMD.logPageGroupSize)

//----------------------------------------------------------------------------
and VFilePageGroupAlign(vmd, vPage) = (1 lshift vmd>>FVMD.logPageGroupSize)-1
//----------------------------------------------------------------------------

//----------------------------------------------------------------------------
and VFileDOPAGEIO(vmd, vPage, core, np, wflag) be
//----------------------------------------------------------------------------
[
CallProc(IndexedPageIO, vmd>>FVMD.fileMap,
 (vPage-vmd>>VMD.base) rshift vmd>>FVMD.logVPagesPerDiskPage,
 core, np rshift vmd>>FVMD.logVPagesPerDiskPage, (wflag? -1, 1))

// set dirty bit if writing a page other than the leader page
if wflag & vPage ne vmd>>VMD.base then vmd>>FVMD.dirty = true
]