// IFSGetCreate.bcpl -- dialogue to get parameters for IFS creation
// Copyright Xerox Corporation 1979, 1980

// Last modified November 14, 1981  10:38 AM by Taft

get "Ifs.decl"
get "IfsFiles.decl"

external
[
// Outgoing procedures
GetCreateParams; DestroyCreateParams

// Incoming procedures
Allocate; Free; Zero; FreePointer
InitCmd; GetString; GetNumber; Confirm; EnableCatch; EndCatch
BeginDefaultPhrase; EndDefaultPhrase; CmdError; BackupPhrase; TelnetAborting
Closes; Wss; Wns; PutTemplate; ExtractSubstring

// Incoming statics
sysZone; driveTab
]

//----------------------------------------------------------------------------
let GetCreateParams(ifsType) = valof
//----------------------------------------------------------------------------
// Requests the operator to specify parameters for creating an IFS.
// ifsType should be either ifsTypePrimary or ifsTypeBackup.
// Returns a filled-in CPar structure (see ifs.decl).
// Returns zero if the user aborts out.
[
let cPar, cs = nil, nil
   [ // repeat
   cs = InitCmd(100+30*nDrives, nDrives+5)
   if cs ne 0 break
   if TelnetAborting() resultis 0
   ] repeat
if EnableCatch(cs) then [ DestroyCreateParams(cPar); EndCatch(cs) ]
cPar = Allocate(sysZone, lenCPar)
Zero(cPar, lenCPar)
cPar>>CPar.type = ifsType
unless Confirm(cs, "*nDo you really want to create a file system?")
   do [ Closes(cs); DestroyCreateParams(cPar); resultis 0 ]

let errMsg = valof
   [
   Wss(cs, "*nNumber of disk units: ")
   let numUnits = GetNumber(cs)
   if numUnits le 0 % numUnits gr nDrives resultis " ?"
   cPar>>CPar.numUnits = numUnits
   for u = 0 to numUnits-1 do
      [
      PutTemplate(cs, "*nLogical unit $2O = Disk drive: ", u)
      let pUnit = GetNumber(cs, 8)
      if pUnit ls 0 % pUnit ge nDrives resultis " ?"
      if driveTab>>DriveTab↑pUnit.ifs ne 0 resultis " drive already in use"
      for i = 0 to u-1 do
         if pUnit eq cPar>>CPar.lpMap↑i resultis " drive repeated"
      cPar>>CPar.lpMap↑u = pUnit
      ]
   test ifsType eq ifsTypePrimary
      ifso cPar>>CPar.id = ExtractSubstring("Primary")
      ifnot
         [
         Wss(cs, "*nFile system ID: ")
         cPar>>CPar.id = GetString(cs)
         ]
   Wss(cs, "*nFile system name: ")
   let BreakCr(cs, char) = char eq $*n
   cPar>>CPar.name = GetString(cs, BreakCr)
   cPar>>CPar.dirSize = numUnits*1000  // default directory size
   Wss(cs, "*nDirectory size (pages): ")
   BeginDefaultPhrase(cs)
   Wns(cs, cPar>>CPar.dirSize)
   EndDefaultPhrase(cs)
   cPar>>CPar.dirSize = GetNumber(cs)
   resultis 0
   ]
if errMsg ne 0 then
   [ CmdError(cs, errMsg); BackupPhrase(cs) ]

let ok = Confirm(cs, "*nOk?")
Closes(cs)
if ok resultis cPar
DestroyCreateParams(cPar)
] repeat

//----------------------------------------------------------------------------
and DestroyCreateParams(cPar) be
//----------------------------------------------------------------------------
[
FreePointer(lv cPar>>CPar.id, lv cPar>>CPar.name)
Free(sysZone, cPar)
]