// IfsTelnetDirStat.bcpl -- IFS system statistics commands
// Copyright Xerox Corporation 1979, 1980

// Last modified March 5, 1980  8:52 AM by Taft

get "Ifs.decl"
get "IfsVMem.decl"
get "BTree.decl"
get "IfsIsf.d"

external
[
// outgoing procedures
DirStatistics

// incoming procedures
PutTemplate; WritePackedDT; ReadBTreePage; Lock; Unlock; Plural

// incoming statics
dsp; primaryIFS
]

//---------------------------------------------------------------------------
let DirStatistics() be
//---------------------------------------------------------------------------
[
PutTemplate(dsp, "*n*nPrimary file system created at $P",
 WritePackedDT, lv primaryIFS>>IFS.created)
let tree = primaryIFS>>IFS.dirBTree
let fmap = tree>>TREE.vmd>>FVMD.fileMap
let runs = (fmap>>FM.last-mapoffset) rshift 1
PutTemplate(dsp, "*n$UD directory pages assigned in $D run$S",
 fmap>>FM.onern, runs, Plural(runs))
Lock(lv primaryIFS>>IFS.dirLock)
let levels = 0
let page = tree>>TREE.RootPage
while page ne Empty do
   [ page = ReadBTreePage(tree, page)>>BTP.MinPtr; levels = levels+1 ]
Unlock(lv primaryIFS>>IFS.dirLock)
PutTemplate(dsp, "*nB-Tree uses $UD pages in $D levels",
 tree>>TREE.GreatestPage, levels)
PutTemplate(dsp, "*n$UD files in the system", tree>>TREE.RecordCount)
]