/*static char *SCCSID = "@(#)superb.h	6.2 91/10/20";*/
/**	superb.h - Super Block Definition
 *
 *	HISTORY
 *	    10-Jul-1989 by JR (John Rogers, JohnRo@Microsoft)
 *		- PTR B784106: Got rid of odd usage of SPF_HFUSED.
 *	    14-Sep-1988 10:56 by Leif Pederson [leifp] re-synched w/Gordon
 *	    8-Nov-1988	by Thomas Fenwick [thomasf] pickup volume changes
 *     @d01 73790  93SEP03 gy <Support V4FORMAT for HPFS386 extensions.
 *                            <GHASSAN@AUSVM1
 */


#define SEC_SUPERB	((LSN) 16)	/* superblock is sector 16  */
#define SEC_SPAREB	((LSN) 17)	/* spareblock is sector 17  */

/*
 *	Redundant sector pointer.
 */

typedef struct RSP { /* RSP */
	LSN lsnMain;
	LSN lsnSpare;
} RSP;

/* XLATOFF */

typedef RSP far *PRSP;

/* XLATON */

#define VOLNAMESIZE	32

typedef struct SUPERB { /* SUPERB */
    SIGNATURE sig1;	    /* SB_SIG1	    signature value 1 */
    SIGNATURE sig2;	    /* SB_SIG2	    signature value 2 */
    BYTE bVersion;	    /* SB_VER	    version # of filesystem structs */
    BYTE bFuncVersion;	 /* SB_FVER     functional version number - the
					                         smallest/oldest version of the
                     					    filesystem that can understand this
                      					    disk - some version enhancements may
                     					    define fields which can be ignored
					                         by earlier versions */
    USHORT usDummy;	       /* SB_DUMY	    free */
    LSN lsnRootFNode;	    /* SB_ROOT	    Psector # of root fnode */
    ULONG culSectsOnVol;    /* SB_SEC	    # of sectors on volume */
    ULONG culNumBadSects;   /* SB_BSEC	    # of bad sectors on volume */

    RSP rspBitMapIndBlk;    /* SB_BII	    Bitmap Indirect Block */
    RSP rspBadBlkList;	    /* SB_BBL	    badblock list chain #1 */

    DATE datLastChkdsk;	    /* SB_CDDAT	    date of last CHKDSK */
    DATE datLastOptimize;   /* SB_DODAT	    date of last Disk Optimize */

    ULONG clsnDirBlkBand;   /* SB_DBSIZE    # of sectors in dirblk band */
    LSN lsnFirstDirBlk;	    /* SB_DBLOW	  first Psector in DIRBLK band */
    LSN lsnLastDirBlk;	    /* SB_DBHIGH    last Psector in DIRBLK band */
    LSN lsnDirBlkMap;	    /* SB_DBMAP	  first Psector of DIRBLK band
					                             bit map.  Starts on a 2K boundary,
					                             2K bytes maximum */

    CHAR achVolName [VOLNAMESIZE]; /* SB_VOLNAME	volume name */
    LSN lsnSidTab;	       /* SB_SIDSEC    sector number of SID table */
    BYTE abFill [SECSIZE-100]; /* SB_FILL    fill definition out to full sector*/

} SUPERB;  /* superB */


/**	SpareB - Spare Block Definitions
 *
 *	SpareB contains various emergency supplies and fixup information.
 *	This stuff isn't in the superblock in order for the superblock
 *	to be read only and decrease the liklihood that a flakey write
 *	will cause the superblock to become unreadable.
 *
 *	This sector is located directly after the superblock - sector 17.
 *
 *	Note that the number of spare DIRBLKs is a format option, given
 *	that they all have to fit into the SpareB, giving us a max of
 *	101 of them.
 *
 *	Checksums.  Done on both Super Block and the Spare Block.
 *	Both checksums are stored in the Spare Block.  The checksum
 *	field for the Super Block (SPB_SUPERBSUM) must be set when
 *	calculating the checksum for the Spare Block.  The checksum
 *	field for the Spare Block (SPB_SPAREBSUM) must be zero when
 *	calculating the checksum for the Spare Block.
 *	If both checksum fields are zero, the checksums have not been
 *	calculated for the volume.
 */

#define SPAREDB 20	/* 20 spare DIRBLKs */

typedef struct SpareB { /* SpareB */
    SIGNATURE sig1;		/* SPB_SIG1	signature value 1 */
    SIGNATURE sig2;		/* SPB_SIG2	signature value 2 */

    BYTE bFlag;			/* SPB_FLAG	cleanliness flag */

#ifdef  V4FORMAT                /* @d01 */
    BYTE bFlag2;                /* SPB_FLAG2    other flag*/
    BYTE bContigFactor;         /* SPB_CF       Contiguity Factor for MM */
    BYTE bAlign;                /* SPB_ALIGN    alignment */
#else
    BYTE bAlign[3];		/* SPB_ALIGN	alignment */
#endif

    LSN lsnHotFix;		/* SPB_HFSEC	first hotfix list Psector */
    ULONG culHotFixes;		/* SPB_HFUSE	# of hot fixes in effect */
    ULONG culMaxHotFixes;	/* SPB_HFMAX	max size of hot fix list */

    ULONG cdbSpares;		/* SPB_SDBCNT	# of spare dirblks */
    ULONG cdbMaxSpare;		/* SPB_SDBMAX	max num of spare DB values. */
    LSN lsnCPInfo;		/* SPB_xxxxx	code page info sector */
    ULONG culCP;		/* SPB_xxxxx	number of code pages */
    ULONG SPB_SUPERBSUM;	/* Checksum of Super Block */
    ULONG SPB_SPAREBSUM;	/* Checksum of Spare Block */
    ULONG aulExtra[15];		/* some extra space for future use */
    LSN alsnSpareDirBlks[101];	/* SPB_SPARDB	Psector #s of spare dirblks */
} SpareB;	/* SpareB */

/* XLATOFF */

typedef struct SpareB SPAREB;
typedef SPAREB far *PSPAREB;

typedef SUPERB far *PSUPERB;

/* XLATON */

/*	Super Block Signature */

#define SBSIG1	0xf995e849		/* two signatures cause we got lotsa */
#define SBSIG2	0xFA53E9C5		/* space	*/

/*	Spare Block Signature */

#define SPSIG1	0xf9911849		/* two signatures cause we got lotsa */
#define SPSIG2	0xFA5229C5		/* space	*/


/*	Superblock Versions */

#define SBBASEV	      2			/*base version */

#ifdef  V4FORMAT
/*  We use version v4 to describe all sizes (in contrast to v3 and v2).
 *  Version 4 supports the following extensions:
 *              MultiMedia, DASD Limits, and DCE ACLs
 */
#define SBBASEFV             4   /* DASD LIMITS, MM, DACLs             */
#define SBBASEOLDFV_BIGDISK  3   /*base functional version (3=bigdisk) */
#define SBBASEOLDFV          2   /*base functional version (2=<2gbdisk)*/

/**  Values for SPB_FLAG2  **/

#define SPF2_DASD_INSTALL   0x01  /* Install DASD LIMITS         */
#define SPF2_DASD_SYNCH     0x02  /* Resynch DR_USE information  */
#define SPF2_DASD_RUNNING   0x04  /* DASD LIMITS operational     */
#define SPF2_MM             0x08  /* MultiMedia active           */
#define SPF2_DCE_ACL        0x10  /* DCE ACLs active             */
#define SPF2_DASD_DIRTY     0x20  /* DASD Limits: disk is dirty  */

#define SPF2_DASD_SUPPORT   (SPF2_DASD_RUNNING|SPF2_DASD_SYNCH|SPF2_DASD_INSTALL)

#else

#define SBBASEFV      3			/*base functional version (3=bigdisk)*/
#define SBBASEOLDFV   2			/*base functional version (2=<2gbdisk)*/

#endif

/*	Spare Block Flags
 */

#define SPF_DIRT	0x0001		/* file system is dirty */
#define SPF_SPARE	0x0002		/* spare DIRBLKs have been used */
#define SPF_HFUSED	0x0004		/* hot fix sectors have been used */

#define SPF_BADSEC	0x0008		/* bad sector, corrupt disk */
#define SPF_BADBM	0x0010		/* bad bitmap block */
//#86635
#define SPF_FASTFMT	0x0020		/* fast-formatted volume */
#define SPF_VER		0x0080		/* file system was written by a version
                                  * < SB_VER, so some of the new fields
					                   * may have not been updated */


/**	 Bit maps
 *
 *	PFS keeps track of free space in a series of bit maps.
 *	Currently, each bit map is 2048 bytes, which covers about
 *	8 megabytes of disk space.  We could rearrange these to be
 *	more cylinder sensitive...
 *
 *	The superblock has the address of a section of contiguous sectors
 *	that contains a double word sector # for each bit map block.  This
 *	will be a maximum of 2048 bytes (4 sectors)
 *
 *  Max # of   size	RAM (K)	   size 2nd lvl
 *   bitmaps   (meg)   to reside    bitmap
 *			 bitmap	     (bytes)
 *
 *	1      8.39	    2	    256
 *	2     16.78	    4	    512
 *	3     25.17	    6	    768
 *	4     33.55	    8	   1024
 *	5     41.94	   10	   1280
 *	6     50.33	   12	   1536
 *	7     58.72	   14	   1792
 *	8     67.11	   16	   2048
 *	9     75.50	   18	   2304
 *     10     83.89	   20	   2560
 *     15    125.83	   30	   3840
 *     20    167.77	   40	   5120
 *     30    251.66	   60	   7680
 *     40    335.54	   80	  10240
 *     50    419.43	  100	  12800
 *    100    838.86	  200	  25600
 *    200   1677.72	  400	  51200
 *    300   2516.58	  600	  76800
 *    400   3355.44	  800	 102400
 *    500   4194.30	 1000	 128000
 */



/**	Hot Fixing
 *
 *	Each file system maintains a structure listing N "hot fix"
 *	disk clusters of HOTFIXSIZ sectors each, each starting on
 *	a multiple of HOTFIXSIZ.  Whenever the file system discovers
 *	that it's trying to write to a bad spot on the disk it will
 *	instead select a free hot fix cluster and write there, instead.
 *	The substitution will be recorded in the hot fix list, and the
 *	SBF_SPARE bit will be set.  The file system sill describes the
 *	data as being in the bad old sectors; the disk interface will
 *	do a mapping between the `believed' location and the true location.
 *
 *	CHKDSK will be run as soon as possible; it will move the
 *	hot fixed data from the hot fix cluster to somewhere else,
 *	freeing that hot fix cluster, and adjusting the disk structure
 *	to point to the new location of the data.  As a result, entrys
 *	on the hot fix list should be transient and few.
 *
 *	The superblock contains the first sector of the hot fix list
 *	which takes the following format:
 *
 *	long oldsec[SB_HFMAX];		sector # of start of bad clusters
 *	long newsec[SB_HFMAX];		sector # of start of subst. cluster
 *	long fnode [SB_HFMAX];		fnode sector of file/directory
 *					involved with bad cluster.  May be
 *					0 (don't know) or invalid.  The
 *					repair program must verify that it
 *					*is* an FNODE and must see if other
 *					structures might also involve this
 *					bad cluster.
 *
 *	the SB_HFUSE field describes the number of these records which is
 *	in use - unused ones should have oldsec[i] = 0.  The list will
 *	be 'dense' - no oldsec[i] will be 0 where i < SB_HFUSE.
 *
 *	The sector(s) which contain the hot fix list must be contiguous
 *	and may not themselves be defective.
 */
