DEFINITION MODULE NKFslotm;

FROM K32baseTypes IMPORT

	cardinal16, cardinal32, integer16;

FROM K32types IMPORT

	ioStatus, pBlock;

FROM K32except IMPORT

	exceptionType;

FROM IOform IMPORT

	BLKSZ, itemKind, slotsPerBlock;

FROM KernelCalls IMPORT

	KreadBlock, KwriteBlock;

FROM strio IMPORT

	getDecC, putChar, putDec, putDecC, putNl, putString;

EXPORT QUALIFIED

    slotInit, getSlot, putSlot, rewriteSlot, flushIncoreSlots, slotBlk,
    icFirst, icLast, nkfslotmVERSION, nkfslotmWHAT, diskOffset;

CONST

    SLOTBLKFILLSZ = 2;        (* bytes needed to fill slot blk to block size*)
    SLOTBLKSINCORE = 20;      (* size of cache in blocks *)

    nkfslotmVERSION = '1.6';
    nkfslotmWHAT = '@(#)nkfslotm.mod	1.6{0}';

TYPE
    ablock = RECORD     (* describes a system block on the disk *)
(*               slot: ARRAY [0..SlotsPerBlock-1] OF itemKind;*)
	       fill : ARRAY [0..SLOTBLKFILLSZ-1] OF CHAR;
             END;

VAR
    slotBlk: ARRAY [0..SLOTBLKSINCORE-1] OF ablock;(* an array of system blocks THE cache *)
                                                (* size of this array must be less than 2**16 bytes *)
    slots: integer16;                             (* useable size of incore cache in slots *)
    maxIncoreSlot: cardinal32;                  (* used when computing number of slot that can be held in cache*)
    icFirst, icLast: cardinal32;              (* first and last slot in cache *)
    maxFsSlot: cardinal32;                    (* max slot number in this filesystem *)
    dirty: BOOLEAN;                             (* indicates the incore slot cache has been modified*)
    incoreAdr: cardinal16;                       (* address of slotBlk *)
    loBlock: cardinal32;                       (* disk addr of low block of incore table*)
    byteCnt: cardinal16;                         (* bytes read in last table load *)

    diskOffset: cardinal32;                     (* offset of system space from
						   from object opened *)
    Pblk: pBlock;                              (* p block for IO *)
    status: exceptionType;                          (* IO error return *)
    errs: ioStatus;                             (* io status return *)


PROCEDURE convToMount (slt: itemKind; VAR mnt: itemKind); (*mountKind*)
(* PURPOSE: Used in loading mount item *)


PROCEDURE flushIncoreSlots;
(* PURPOSE: Write the cache to the disk *)

PROCEDURE loadSlotTable (desiredSlot: cardinal32     (* address of desired slot on disk*)
			  ) : BOOLEAN;
(* PURPOSE: Internal procedure that actually manages the loading of
	    the cache.
*)


PROCEDURE getSlot (desiredSlot: cardinal32;   (* filesystem slot number *)
		    VAR blkPtr,                (* index to block containing desired slot *)
			slotPtr: cardinal16      (* index to slot in block *)
		   ): BOOLEAN;                  (* returns true if slot found*)
(* PURPOSE: Gets the requested slot into the cache and returns indexes to it*)

PROCEDURE putSlot (desiredSlot: cardinal32;   (*filesystem slot number *)
		    VAR blkPtr,                (* cache block index *)
			slotPtr: cardinal16      (* slot index in block *)
		    ): BOOLEAN;
(* PURPOSE: Same as get slot buts marks the cache as dirty. Used if you
	     intent to modify the content of the slot *)

PROCEDURE rewriteSlot (desiredSlot: cardinal32;       (* filesystem slot number *)
			workBlk:  itemKind (*jNodeKind*)             (* item to be written to slot *)
		       ):BOOLEAN;
(* PURPOSE: Write the given item to the cache. *)


PROCEDURE slotInit (dkOffset: cardinal32; expectedKind: itemKind) : BOOLEAN;
(* PURPOSE: Initialize slot manager and read in the mount item for the filesystem *)

END NKFslotm.
