// IfsLeaf.decl - Leaf - Declarations
// Copyright Xerox Corporation 1979, 1980

// Last modified May 24, 1979  3:08 PM by Boggs
// Last modified June 20, 1979  4:21 PM by Taft
// Last modified by Wobber, April 9, 1981  3:08 PM
// Last modified by Butterfield, October 12, 1979  1:52 PM

get "IfsRs.decl";
get "Pup0.decl";
get "IfsFiles.decl";

//---------------------------------------------------------------------------
manifest
//---------------------------------------------------------------------------
[
signBit = #100000;  //used for tests where the difference may exceed 2**15-1
checkOvBytes = 2;
bitsPerWord = 16; bitsPerByte = 8; bytesPerPage = 2048; logBytesPerPage = 11;
wordsPerPage = 1024; logPagesPerWord = bitsPerWord - logBytesPerPage;
leafPageSize = wordsPerPage; leafPageSizeMask = not (wordsPerPage - 1);
atAnyRate = 0; bytesPerUserPage = 512;

// Leaf reset ops
resetAllHosts = -1;
resetThisHost = 0;
resetBrokenLeaf = 1;
]

//---------------------------------------------------------------------------
structure GetPageOp:
//---------------------------------------------------------------------------
[
inCore bit 1; noRead bit 1; lock bit 1; waste bit 5;
dirty byte;
]
manifest 
[ // Flags for LeafGetPage. Must agree with GetPageOp structure.
cleanPage = 0; dirtyPage = #377;
inCoreOp = #100000; dontReadOp = #40000; lockOp = #20000;
]

//---------------------------------------------------------------------------
structure LeafAddress:
//---------------------------------------------------------------------------
[
high word =
[ signExtend bit 5 = [ mode bit 2; newEOF bit 1; extra bit 2 ];
  highAddr bit 11; ]
low word;
]
manifest [ anywhere = 0; noHoles = 1; dontExtend = 2; checkExtend = 3; ]

//---------------------------------------------------------------------------
structure FH:   // file handle
//---------------------------------------------------------------------------
[
link word;
lvmd word; mode word; fd word;
ui @UserInfo;
]
manifest lenFH = size FH/16;

//---------------------------------------------------------------------------
structure LVMD:   // Leaf virtual memory descriptor
//---------------------------------------------------------------------------
[
link word;
lastAddress: [ high word; low word; ]
written byte; refCount byte;
fileIndex word;
fmap word 0;  // FMap begins here.
]
manifest lenLVMD = size LVMD/16;

//---------------------------------------------------------------------------
structure Op: [ code bit 5; answer bit 1; length bit 10 ]
//---------------------------------------------------------------------------
manifest
[
opError = 0; opOpen = 1; opClose = 2; opDelete = 3; opCloseTransaction = 4;
opTruncate = 5; opRead = 6; opWrite = 7; opReset = 8; opNoop = 9;
opTelnet = 10; opParams = 11;
opCodeShift = bitsPerWord - offset Op.answer;
opCodeMask = -1 lshift opCodeShift;
opAnswerBit = #2000; opAnswer = 1; opRequest = 0

// Returns possible from LeafOp routines
leafOpComplete = -1; leafOpError = 1; leafOpPupFull = 2; leafOpPupNotFull = 3;
]

//---------------------------------------------------------------------------
structure Mode:
//---------------------------------------------------------------------------
[
read bit; write bit; extend bit; multiple bit; create bit;
vExplicit bit 2; vDefault bit 2; leaderInfo bit; listMultiple bit;
multipleWriters bit 1; blank bit 4
]
manifest
[
noExplicit = 0; oldExplicit = 2; nextOrOldExplicit = 3; anyExplicit = 3;
vDontDefault = 0; vLowest = 1; vHighest = 2; vNext = 3;
badVersionControl = 0; defaultLowest = 1; defaultHighest = 2; defaultNext = 3;
bangStar = 4; bangLowest = 5; bangHighest = 6; bangNext = 7;
explicitOld = 8; explicitLowest = 9; explicitHighest = 10; explicitNext = 11;
explicitNew = 12; explicitLess = 13; explicitBetween = 14; explicitGreater=15;
]

//---------------------------------------------------------------------------
structure NoopRequest: [ op @Op; ]
structure ResetRequest: [ op @Op; resetOp word; strings↑0,0 word ]
structure OpenRequest: [ op @Op; handle word; mode @Mode; strings↑0,0 word ]
//null filename could be Login
//OpenAnother could be OpenRequest with null user name followed by handle
//OpenNext could be OpenAnother with null filename, no filename could be Login 
//structure LengthRequest: [ op @Op; handle word ]  //handle optional
//structure HandleRequest: [ op @Op; handle word ]
structure TelnetRequest: [ op @Op; flags word; userName↑0,0 word; ]
structure ParamsRequest: [ op @Op; pupDataBytes word; lockTimeout word;
 connTimeout word; ];
// This is for Read, Write, Delete, Truncate, Close, CloseTransaction
structure FileRequest: [ op @Op; handle word; address @LeafAddress
 length word; rate word = words↑0,0 word; ]
manifest writeRequestOv = offset FileRequest.words/bitsPerByte
//---------------------------------------------------------------------------

//---------------------------------------------------------------------------
structure ErrorAnswer: [ op @Op; error word; errorOp @Op; handle word ]
manifest lenErrorAnswer = size ErrorAnswer/bitsPerWord
structure OpenAnswer: [ op @Op; handle word; length @LeafAddress; mode @Mode ]
manifest lenOpenAnswer = size OpenAnswer/bitsPerWord
// This generic is for Noop, Reset, Close, CloseTransaction,
// Delete, Truncate, Params
structure LeafAnswer: [ op @Op; handle word ]
manifest lenLeafAnswer = size LeafAnswer/bitsPerWord
structure TelnetAnswer: [ op @Op; flags word; subOp @Op; errorCode word ];
manifest lenTelnetAnswer = size TelnetAnswer/bitsPerWord
structure FileAnswer: [ op @Op; handle word; address @LeafAddress
 length word; rate word = words↑0,0 word ];
manifest readAnswerOv = offset FileAnswer.words/bitsPerByte
manifest lenWriteAnswer = size FileAnswer/bitsPerWord
manifest lenLargestLeafAnswer = lenWriteAnswer
//---------------------------------------------------------------------------