DEFINITION MODULE IOFform;

FROM K32baseTypes IMPORT

	bits16, cardinal16, cardinal32, maxCardinal32;

FROM K32types IMPORT

	fBlockNumber, tiiStruct;

FROM IOform IMPORT

	itemKind, labelName, mBlockNumber, security, timeStamp;

EXPORT QUALIFIED

	allocMap, allocMapMax, allocMapSize, allocSlot,
	badBlockLocation, EMPTYFILLSZ, emptySlot, fileCond,
	firstUserSlot, freeLocation, INDEXFILLSZ, indirectItem,
	initialFreeItem, initialIndirectItem, initialJnode, jNode,
	JNODEFILLSZ, mapCapacity, mapNumber, maxDirectInIndirect,
	maxDirectInJnode, maxIndirect, MNTFILLSZ, mountInfo,
	mountItem, mountLocation, nullPointer32, reservedSlot,
	slotNumber, treeNumber;

(*	DISK STRUCTURE DEFINITIONS ARE INCLUDED HERE		*)

(*
	Data Structures For KSOS File Systems

	The data structures defined here give the layout of the control
	information of the file system in an extent.  These data structures
	are used by both the KSOS kernel file system and the KSOS
	NKSR file recovery, initialization, dump, and restore utilities.

	These structures are for use by trusted software only.

HISTORY:
  AUTHOR:   J. Nagle
  VERSION:  1.1 of 6/18/86
*)
					(* @(#)IOFform.mod	1.1 WHAT(I) identification string *)
CONST
    (*  Fillers for index slot items.  All must be exactly 102 bytes long. *)
    (*  Only the PACKED on-disk structures are 102 bytes. In memory they are
        204 bytes long. tep TEMP 1/23/87 *)
    EMPTYFILLSZ = 196 (*98*);
    JNODEFILLSZ = 76  (* 4*);
    INDEXFILLSZ = 100 (* 3*);
    MNTFILLSZ =   116 (*36*);



TYPE
slotNumber   = cardinal32;              (* Item number within extent *)
treeNumber   = cardinal16;                (* Item number in file tree *)
mapNumber    = cardinal16;		(* which alloc slot amongst slots *)
fileCond =     (FILESAFE,               (* File OK and not open for writing *)
		FILEWRITING,            (* File open for write *)
		FILEDAMAGED,            (* File was FILEWRITING at recovery *)
		FILEDESTROYED,          (* File was fouled up at recovery *)
		FILERESLOCK);           (* File restore locked *)





(* ========================================================================= *)
(*          Structures which appear in the kernel's part of a file system    *)
(*          Collectively, we call these 'items'.                             *)
(*          These are all the same size, with fill as required.              *)
(* ========================================================================= *)

CONST
    maxIndirect = 9;                    (* max link per any item *)
    maxDirectInJnode = 5;               (* max link in a jNode *)
    maxDirectInIndirect = 12;           (* max link in an Index Item *)
    allocMapSize= 96 DIV 2;             (* words per alloc map - fills map *)
    allocMapMax = allocMapSize - 1;     (* high word in alloc map *)
    mapCapacity = allocMapSize * 16;	(* bits represented by one map *)
					(* nullPointer16 in the hi order word of a *)
					(* direct or indirect pointer indicates that *)
					(* pointer is not valid *)
    nullPointer32 = maxCardinal32;	(* this is a full null pointer *)

					(* locations of some fixed items *)
    mountLocation    = 0;		(* the mount item *)
    badBlockLocation = 1;		(* the file of bad blocks jNode *)
    freeLocation     = 2;		(* free file jNode *)
					(* 3 : RESERVED for future expansion*)
					(* 4 : RESERVED for future expansion*)
    firstUserSlot    = 5;		(* lowest dynamically allocated slot *)


TYPE
emptySlot = RECORD                      (* Unallocated block *)
		checkSum: cardinal16;     (* [2] item checksum *)
		kind: itemKind;         (* [1] always freeKind *)
		fill: ARRAY [1 .. EMPTYFILLSZ]  OF CHAR; (* fill area, always null *)
	    END;

reservedSlot = RECORD                       (* Reseved for future system use *)
		checkSum: cardinal16;         (* [2] item checksum *)
		kind: itemKind;             (* [1] always reservedKind *)
		fill: ARRAY [1 .. EMPTYFILLSZ]  OF CHAR; (* fill area, always null *)
	    END;

allocMap  = ARRAY [0..allocMapMax] OF bits16;(* one map item - part of allocSlot *)

allocSlot = RECORD                      (* bit map for allocation *)
		checkSum: cardinal16;     (* item checksum *)
		kind: itemKind;         (* always allocKind *)
	        self: mapNumber;	(* own position *)
			(* NOTE: self = nullPointer after unrecovered crash*)
		map:  allocMap;         (* allocation bit map *)
	    END;

jNode = RECORD
		checkSum:cardinal16;      (* item checksum *)
		kind: itemKind;         (* always jNodeKind *)
					(* pointers to indirect items *)
		indirectTable: ARRAY [1 .. maxIndirect] OF slotNumber;
					(* pointers to data blocks *)
		directTable:   ARRAY [1 .. maxDirectInJnode] OF mBlockNumber;
		cond: fileCond;         (* for recovery *)
		rights: security;       (* access control information *)
		self: slotNumber;       (* location of self (redundant) *)
		highBlock: fBlockNumber;(* Maximum block number in file *)
		trailCount: cardinal16;	(* bytes to ignore in last block *)
		linkCount: cardinal16;    (* Use count *)
		textLastMod: timeStamp; (* Time of last modification *)
		fill: ARRAY [1 .. JNODEFILLSZ]  OF CHAR; (* fill area, always null *)
	END;

indirectItem = RECORD                   (* Describes blocks from one file *)
		checkSum: cardinal16;     (* item checksum *)
		kind: itemKind;         (* always indirectKind *)
		indirectTable: ARRAY [1 .. maxIndirect] OF slotNumber;
					(* must match jNode to this point *)
		directTable:   ARRAY [1 .. maxDirectInIndirect] OF mBlockNumber;
		homeJnode: slotNumber;  (* redundant *)
		parent: slotNumber;     (* back link to indirect item or jNode *)
		treeN: treeNumber;      (* position in tree of this item *)
		fill: ARRAY [1 .. INDEXFILLSZ]  OF CHAR; (* fill area, always null *)
	    END;

mountInfo = RECORD                      (* subpart of mountItem *)
		slotsDefined: cardinal32;(* Slots defined in this fs *)
		blocksDefined:cardinal32;(* Data blocks defined in this fs *)
		firstAllocItem: slotNumber; (* slot of first allocItem *)
		firstUserBlock: mBlockNumber;(* Beginning of user area *)
		tii: tiiStruct;        (* Max levels and owner of this fs *)
		mounted: BOOLEAN;       (* TRUE if currently mounted *)
	    END;

mountItem = RECORD                      (* Describes one file system *)
		checkSum: cardinal16;     (* item checksum *)
		kind: itemKind;         (* always mountKind *)
		revLevel: cardinal16;	(* revision level of design *)
		mInfo: mountInfo;       (* counts, as above *)
		sysNo: cardinal16;        (* number of system on which file system was initialized *)
		initDate: timeStamp;    (* date-time file system was initialized *)
		label: labelName;       (* name of this file system *)
		fill: ARRAY [1 .. MNTFILLSZ] OF CHAR; (* fill area, always null *)
	    END;


(*      END DISK STRUCTURE DEFINITIONS COMMON TO FILE SYSTEM AND NKSR *)

VAR
	initialIndirectItem : indirectItem;

(*
	initial jNode   --   prototype used by K_create
*)
	initialJnode : jNode;		(* filler *)
(*
	initial free item  --  used when releasing slots
*)
	initialFreeItem : emptySlot;

END IOFform.
