/*static char *SCCSID = "@(#)const.h	6.4 92/01/31";*/
/* Constants for File System/
 *
 *	HISTORY
 *	    8-Nov-1988 Thomas Fenwick [thomasf] pickup volume changes
 *	    14-Sep-1988 11:41 by Leif Pederson [leifp] resynch w/Gordon
 */

/*  Conditional compilation switches
 *
 *  DEBUG	    enables full internal debugging and internal error checking
 *  DEBUG_HOLDS	    enables internal debugging for INCR_HOLDS & DECR_HOLDS
 *  DEBUGHEAP	    enables heap scrubbing/checking
 *  DEBUG_ASYNC	    enables asynchronous I/O tracing (dprintfs)
 *  FIND_NOTIFY	    enables find-notify support (turn on/off in notify.h to
 *			save from recompiling the world)
 *  USE_DEVIOCTL    causes fs_fsctl to use fsh_devioctl rather than
 *			fsh_dovolio2
 *  EAFIX	    enables EA support
 *  TEFTI	    produce version containing timing code
 *  BUFZAP	    clears buffers on writes
 *  DISK_READ_TEST  scans disk for bad reads on mount
 *  RAHEAD_VARS	    enables code which allows read ahead params to be
 *			changed via fsctl entry points.
 *  RAHEAD	    enables read ahead using auxiliary thread and causes
 *			a buffer to be allocated
 *  STATIC	    allows control over scope of captive functions and
 *			variables
 */

/* XLATOFF */
#ifndef MINIFSD
#define RAHEAD			/* enables read ahead support */
#define PERFVIEW		/* enable PerfView hooks      */
/* #define PERFVIEW2  */	     /* enable Guru PerfView hooks */
#endif
#define EAFIX			/* enable EAs */
#define STATIC			/* make static have global scope */

/* XLATON */

/* for now, do hold count checking whenever DEBUG is turned on */
#ifdef DEBUG
#define DEBUG_HOLDS
#endif

/*
 * The normal minimum number of sectors that we pre-allocate when a
 * file grows as a result of writing.
 */
#define GROWDELT	16

/*
 * The number of sectors that we pre-allocate when a file is created.
 */
#define PRIMARY_ALLOCATION  8   /* primary space allocation (sectors) */

/* Sector sizes */

#define SECSIZE		512		/* 512 bytes per sector */
#define SECSHIFT	9		/* 2^9 = SECSIZE */


/* XLATOFF */

/***	Max size for a cracked path buffer.  Remember that this includes
 *	the hVPB as well as the total length of the cracked path.
 */

#define CPATHBUFSIZE (CCHMAXPATH + sizeof (USHORT) + sizeof (HVOL))

/*** Max path component in pinball
 */
#define PB_CCHMAXPATHCOMP   255

/* XLATON */

/* Cache Sizes */

#define SPB		4		/* sectors per buffer */
#define SPB4
/* #define SPB8 */

#ifdef SPB4
#define SPBMASK		3		/* mask for SPB */
#define SPBSHIFT	2
#define SPBBITS		0x0f		/* SPB number of one bits, low order */
#endif

#ifdef SPB8
#define SPBMASK		7		/* mask for SPB */
#define SPBSHIFT	3
#define SPBBITS		0xff		/* SPB number of one bits, low order */
#endif

#define PERCENT_CACHE	10		/* percent of DosMemAvail used
					 * for cache */

#define MINBUF		(64/(SPB/2))	/* minimum of 64KByte cache */





#define BMASK		(SPB*SECSIZE-1) /* mask offset in to cache block */
#define BSHIFT		(SECSHIFT+SPBSHIFT)

#define LWBUFCT		16		/* size of lazy writer buffer */

#define LZ_RD_BIT_MAP_SIZE		256		/* size of lazy read buffer */


/*	OFT Hash Table Size   (8 bytes each)  */

#define OFTHASHCNT 16		/* 16 hash chains for open files */
#define OFTHASHMSK 0x78		/* mask for computing hash offset */




/* Number of I/O command blocks which aren't associated with buffers */
#define IOBCNT		16		/* 16 should be enough */


/* # of OS/2 ram semaphores that we can be blocked on, simultaneously. */
#define SEMCNT		32


/*
 * Cache Hash
 *
 * A sector hash is used to locate the start of a chain; the chain
 * is then scanned linearly.
 *
 * For our current size of 256 hash chains, we get:
 *
 * 1 meg of cache RAM =	 512 blocks = 2 blocks per chain (average)
 * 2 meg of cache RAM = 1024 blocks = 4 blocks per chain (average)
 */

#define HASHCNT		256		/* # of bytes of hash header */


/* Directory Lookaside record count */

//#define DLCNT		10		/* 10 guys for now */
//test
#define DLCNT		20		/* 20 entries */


/*	Maximum DIRBLKs we may need to allocate for any given
 *	operation.  This is in effect the maximum tree depth.
 *
 *	Worst case, with 256 character file names and nearly empty
 *	DIRBLKs, 10 is enough levels for 60,000 files - about 40 megabytes
 *	of space just for that directory.  Given more practical file length
 *	names this is enough for 10s of millions of files in a directory.
 */

#define MAX_DIR_NEED  10


/**	Special Transition Locking Structure size */

#define TRANCNT 4		/* just need 4 spots */


/* Heap Definitions */

#define HHSIZ		4		/* size, in bytes, of heap header */

/*	Maximum number of volumes that we can mount
 *
 *	The volume ID is kept in the high bits of the sector numbers
 *	kept in our RAM structures,
 *	so there is a tradeoff between max volumes and max sectors.
 *
 *	32 max volumes gives us a 65 billion byte volume limit,
 *	which should last us for a while.  Since sector numbers
 *	are stored on the disk without their volume upper bits
 *	this is strictly an implimentation detail; we can adjust
 *	the number of volumes or eliminate this tradeoff in other
 *	implimentations which will be 100% media compatable.
 *
 *	We use the term VSector to indicate a vol/sector combination
 *	and PSector to indicate just the physical absolute sector #
 *
 */

#define VOLMNTMAX   27		/* max 27 volumes mounted normally */
				/* see fsdata\fsdata.c for details */
				/* We don't use slot 0 - means volbits == 0;
				 * 1-26 allows for drives A:-Z:
				 */

#define MAXSEC	134217728	/* 2^32/32 max sectors */

#define SECMASK 0x07FFFFFF	/* mask for sector number */

#define HSECMASK 0x07		/* high byte sector mask */

#define HVOLMASK 0xf8		/* high byte volume mask */
#define SVOLMASK 0x1f		/* shifted right volume mask */

#define VOLRSHIFT (32-5)	/* shift right to extract volume index */
#define VOLLSHIFT 5		/* shift left  to extract volume index */

/* XLATOFF */

#define VOLIDBITS(lsn)	 (HIBYTE (HIUSHORT (lsn)) >> (8-VOLLSHIFT))

#ifdef DEBUG
/* Since the volume id is 5 bits and the valid volumes are 0 - 26, will
 * make sure that we won't try to index an invalid entry.
 */
#define IVOLFROMLSN(lsn) ( (VOLIDBITS(lsn) < VOLMNTMAX) ? VOLIDBITS(lsn) :  \
			   ( INTERR(__FILE__"IVOLFROMLSN: Illegal volume."), \
			     (BYTE)0 ) )
#else
#define IVOLFROMLSN(lsn)    VOLIDBITS(lsn)
#endif

/* XLATON */

/*
 *	Signature Values for Disk Structures
 *
 *	These signature values help with debugging and they'll
 *	be used by the CHKDSK utility to help repair disks.
 */


#define VAL_J		  ((('J'-'A')*40+('G'-'A'))*40+'L'-'A')
#define VAL_R		  ((('R'-'A')*40+('P'-'A'))*40+'W'-'A')

/* indirect blks */
#define ABSIGVAL	((LONG)VAL_J*40*40*40 + (LONG)VAL_R)

/* dir blks */
#define DBSIGVAL	(0x40000000L + (LONG)VAL_J*40*40*40 + (LONG)VAL_R)

/* fnodes */
#define FNSIGVAL	(0xC0000000L + (LONG)VAL_J*40*40*40 + (LONG)VAL_R)


/**	FastFile bitmaps
 *
 *	0x00000000		 all checking disabled
 *	0x00000001  FF_FLUSHLAZY DoZap lazy writes are automatically flushed
 *	0x00000002  FF_ZAPSEC	 DoZap blasts sector numbers/sector data
 *	0x00000004  FF_LRUCHK	 vbs verification of LRU/dirty integrity
 *	0x00000008  FF_CHKSUM	 sector checksumming is omitted
 *	0x00000010  FF_PLACECHK	 placebuf verifies location of buffer
 *	0x00000020  FF_HEAPCHK	 verify heap headers
 *	0x00000040  FF_DIRMAP	 produce in-RAM map of directory tree
 *	0x00000080  FF_HOLDLOG	 produce log of hold inc/dec
 *	0x00000100  FF_CHKSBDIR	 recursive SBDIR consistency checking
 *	0x00000200  FF_GETBUFS	 check outstanding getbufs
 *	0x00000400  FF_CHKHCHN	 check hash chains for all bufnodes
 */

#define FF_FLUSHLAZY	0x00000001
#define FF_ZAPSEC	0x00000002
#define FF_LRUCHK	0x00000004
#define FF_CHKSUM	0x00000008
#define FF_PLACECHK	0x00000010
#define FF_HEAPCHK	0x00000020
#define FF_DIRMAP	0x00000040
#define FF_HOLDLOG	0x00000080
#define FF_CHKSBDIR	0x00000100
#define FF_GETBUFS	0x00000200
#define FF_CHKHCHN	0x00000400


/* XLATOFF */


/*  Timeout values
 */
#define TO_FOREVER  0xFFFFFFFF


/*
 * lsn's of useful sectors
 */
#define LSN_BOOT    ((LSN)0)

#define LSN_BOGUS   ((LSN)0xffffffff)

#ifdef DEBUG
/* size of fake disk error table - see diskio\dovolio.c */

#define FAKEERRORCT	10

#endif


/*
 * Constants for names
 */
#define CH_LASTNAME 0xFF	    /*Lexacally greatest name in a directory*/

#define CH_SECURE_FILL	0x00	    /* Byte value to use in zerofilling
				     * unwritten data before returning it to
				     * an FS_READ caller
				     */

/*
 * Constant for PAGER I/O support
 */
#define HPFS_MAXREQ 16		    /* maximum page requests per list */


/*
 * Maximum disk size constants
 */
#define CCH_BIGDISK   ((ULONG)0x80000000L)  /* anything >= 2Gig is
					     * considered big
					     */

#define CSEC_BIG_DISK (CCH_BIGDISK/SECSIZE) /* number of sectors on 2G dsk*/

#define CCH_MAXFILESIZE ((ULONG)0x80000000L)  /*2G is also limit on file size*/

/***	FSCTL constants
 *
 *	Codes 0x8000-0x8fff are RESERVED.
 */

#define FSC_LW_BOTH	0x9000	    /* perform block/flush loop til err	 */
#define FSC_LW_STOP	0x9001	    /* perform block/flush loop til err	 */
#define FSC_LW_SET	0x9002	    /* Set flushing parameters		 */
#define FSC_LW_GET	0x9003	    /* Get flushing parameters		 */
#define FSC_LW_VDU_START  0x9015  /* perform block/flush loop til err	 */
#define FSC_LW_VDU_STOP   0x9016  /* perform block/flush loop til err	 */
#define FSC_LW2_START   0x9017    /* perform block/flush loop til err	 */
#define FSC_LW3_START   0x9018    /* perform block/flush loop til err	 */
#define FSC_GETFN	0x9004	    /* Get FNODE number of an open file	 */
#define FSC_GETSEC	0x9005	    /* Get run start and length		 */
#define FSC_GETSTAT	0x9006	    /* Get statistics			 */
#define FSC_CLEAR	0x9007	    /* Clear statistics			 */
#define FSC_HVPB_GET	0x9008	    /* Return hVPB - not used		 */
#define FSC_MAKEBADSEC	0x9009	    /* Pretend a sector is bad		 */
#define FSC_INVALIDATE	0x900B	    /* Invalidate cache for a sector.	 */

#ifdef RAHEAD
#define FSC_RAHEAD	0x900C	    /* Perform Read ahead		 */
#ifdef RAHEAD_VARS
#define FSC_RA_STOP	0x900D	    /* Stop Read ahead			 */
#define FSC_RA_SET	0x900E	    /* Set Read ahead parameters	 */
#define FSC_RA_GET	0x900F	    /* Get Read ahead parameters	 */
#endif
#endif

#define FSC_IOLIST	0x9010	    /* various asynch I/O operations  */

#ifdef PERFVIEW
#define FSC_PVW_SIZE	0x9011	    /* Get PVW data & text block sizes	*/
#define FSC_PVW_TEXT	0x9012	    /* Get copy of Text block		*/
#define FSC_PVW_DATA	0x9013	    /* Get copy of data block		*/
#endif

#define FSC_SECTORIO	0x9014	    /* set DASD IO granularity to 512 bytes */
#define FSCP_PASSWD   0xDEADFACEL   /* password for FSC_SECTORIO call	*/

#ifdef DEBUG
/***	Special error returned from FsCtl - debugging only */

#define ERROR_HPFS_BADSECLISTFULL   0xf701
#define ERROR_HPFS_BADSECNOTINLIST  0xf702
#endif
