/*
 * necessary definitions to interpret KSOS file systems.
 *
 * Derived from the KSOS-11 filesys.h, derived in turn from the Kernel
 * files:
 *	KERnad.mod
 * 	KIOnad.mod
 *	IOE.mod
 *	IOF.mod
 *
 */

#define BLKSZ           512
#define SPB             5               /* slots per block */
#define SLOTSZ          102
#define CHKSUM          31415

#define MOUNT           0
#define FREE            1
#define JNODE           2
#define INDIR           3
#define ALLOC           4
#define RSRVD           5
#define EXTENT          6

#define EXTMAP          5               /* abs block no of extent map */
#define EXTSIZE         35              /* number of slots in extmap */

#define MAXIND          9               /* size of indirect table */
#define MAXDIRJ         5               /* size of direct table in jnode */
#define MAXDIRI         12              /* size of direct table in indir */
#define MAPSIZE         48              /* size of alloc map (words) */

#define MOUNTLOC        0L              /* location of mount item */
#define ROOTLOC         5L              /* location of first user slot */

#define NULLP           ((integer16)(-1))
					/* a null block pointer within the filesystem */

#define SAME_NSP        ((byte) 128)


/****************************************************************
 *								*
 *	Packing FROB: any item of type FROB is defined as	*
 *	a byte[4] for on-disk packing purposes. It is actually	*
 *	a cardinal32, so the proper casts are needed		*
 ****************************************************************/
typedef byte FROB[4];


struct seid			/* from KERnad.mod - 4 bytes */
{
	byte            nsp;
	byte            uniq_id0;
	cardinal16      uniq_id1;
};

struct tii			/* from KERnad.mod - 16 bytes */
{
	byte            secur;
	byte            integ;
	FROB		comparts; /* actually bits32 */
	cardinal16      owner;
	cardinal16      group;
	bits16          da;
	FROB            priv;	/* actually bits32 */
};

struct security			/* from KERnad.mod - 20 bytes */
{
	struct tii      s_tii;
	struct seid     s_sub;	/* subtype */
};


struct eitem			/* from IOE.mod - 102 bytes */
{
	cardinal16      e_cksum;
	cardinal16      e_kind;
	cardinal16      e_extno;
	byte            e_label[20];
	struct security e_sec;
	FROB            e_first; /* actually cardinal32 */
	FROB            e_last;	/* cardinal32 */
	FROB            e_size;	/* cardinal32 */
	byte            e_fill[44];
};


struct aslot			/* from IOF.mod:allocSlot */
{
	cardinal16      a_cksum;
	cardinal16      a_kind;
	cardinal16      a_self;
	bits16          a_map[MAPSIZE];
};


struct mitem			/* from IOF.mod:mountItem - 102 bytes */
{
	cardinal16      m_cksum;
	cardinal16      m_kind;
	cardinal16      m_rev;
	FROB            m_slots; /* actually cardinal32 */
	FROB            m_blocks; /* actually cardinal32 */
	FROB            m_alloc; /* actually cardinal32 */
	FROB            m_user;	/* actually cardinal32 */
	struct tii      m_tii;
	cardinal16      m_mount;
	cardinal16      m_sysno;
	FROB            m_data;	/* actually cardinal32 */
	byte            m_label[20];
	byte            m_fill[36];
};


struct jnode			/* from IOF.mod:jNode - 102 bytes */
{
	cardinal16      j_cksum;
	cardinal16      j_kind;
	FROB            j_itable[MAXIND]; /* actually cardinal32 */
	FROB            j_dtable[MAXDIRJ]; /* actually cardinal32 */
	cardinal16      j_cond;
	struct security j_rights;
	FROB            j_self;	/* actually cardinal32 */
	FROB            j_high;	/* actually cardinal32 */
	cardinal16      j_trail;
	cardinal16      j_link;
	FROB            j_time;	/* actually cardinal32 */
	byte            j_fill[4];
};


struct indir			/* from IOF.mod:indirectItem - 102 bytes */
{
	cardinal16      i_cksum;
	cardinal16      i_kind;
	FROB            i_itable[MAXIND]; /* actually cardinal32 */
	FROB            i_dtable[MAXDIRI]; /* actually cardinal32 */
	FROB            i_home;	/* actually cardinal32 */
	FROB            i_parent; /* actually cardinal32 */
	cardinal16      i_tree;
	byte            i_fill[4];
};


struct extp
{
	integer32       x_unit;         /* extent is on this unit */
	cardinal32      x_offset;       /* offset to beginning of ext */
	cardinal32      x_slots;        /* from mount item */
	cardinal32      x_blocks;
	cardinal32      x_user;
};


struct filep
{
	struct extp     f_ext;          /* file is on this extent */
	cardinal32      f_jnumb;        /* j number of file */
	cardinal32      f_blocks;       /* number of blocks in file */
};
