/*static char *SCCSID = "@(#)misc.h	6.4 91/10/20";*/
/* XLATOFF */

/**	MISC.h - Miscellaneous structure definitions.
 *
 *	These need to be included first because other structures
 *	make use of them.
 *
 *	HISTORY
 *	    15-Aug-1989 by JR (John Rogers, JohnRo@Microsoft)
 *		- Implement FSC_INVALIDATE so CHKDSK can use FS_READ to get
 *		  sectors (which get cached) but use FS_IOCTL to write sectors
 *		  (which don't get cached, so the cache gets out of date).
 *	    14-Sep-1988 13:23 by Leif Pederson [leifp] resynch w/Gordon
 *		- secptr remains in buf.h since it needs a bufnode whereas
 *		  Gordon puts it here in misc.h
 */


/**	BITMAP - Bitmap
 *
 *	A bit map used for in-use and bad sector mapping on disk.
 *	BUGBUG - we need to update the size and the mount routine
 *	to reflect indirect blocks for the bitmap.
 */

#define BITMAPSIZE	(SECSIZE * SPB)

typedef struct BITMAP { /* BITMAP */
	ULONG	culSectors;
	ULONG	culLength;
	BYTE	bBits [BITMAPSIZE];
} BITMAP;

typedef BITMAP far *PBITMAP;


/**	CHECKSUM - checksum value used in a lot of data structures
 */

typedef ULONG CHECKSUM;
typedef CHECKSUM far *PCHECKSUM;

/* XLATON */

/**	DATE - date
 */

typedef ULONG DATE;
typedef DATE far *PDATE;


/**	LSN - Logical Sector Number
 *
 *	A logical sector number--used all over.
 */

typedef ULONG LSN;
typedef LSN far *PLSN;

/* XLATOFF */

/* typedef for volume handle */
typedef USHORT HVOL;


/**	PASCALSTRING - pascal string
 *
 *	PASCALSTRING is a string whose first byte is the count of
 *	chars in the string.
 */

typedef struct PASCALSTRING { /* PASCALSTRING */
	BYTE c;
	BYTE b [1];
} PASCALSTRING;

typedef PASCALSTRING far *PPASCALSTRING;


/**	CRACKEDPATH - cracked path
 *
 *	This is the way a path name is passed to many of the routines. A
 *	cracked path is an hVPB, a 16-bit count of bytes in the entire
 *	cracked path structure, followed by a byte containing the length of
 *	the component name, count followed by component name, etc.
 */

typedef struct CRACKEDPATH { /* CRACKEDPATH */
	HVOL hVPB;		/* handle of volume containing path */
	USHORT cbPath;		/* # of bytes in path component.  This is also
				 * the offset to the last name component */
	PASCALSTRING sp;	/* first name component */
} CRACKEDPATH;

typedef CRACKEDPATH far *PCRACKEDPATH;


/**	FILE_NAME - gets the last component of a cracked path which
 *	could be the file name if the length of this pascal string
 *	is non-zero.
 */

#define FILE_NAME(pcp)	((PPASCALSTRING)((PBYTE)&(pcp)->cbPath + (pcp)->cbPath))

/* XLATON */

/**	PERMMASK - permission mask quantity
 *
 *	PERMMASK is used in a directory entry and in the permissions
 *	data structure.
 */

typedef USHORT PERMMASK;
typedef PERMMASK far *PPERMMASK;

/**	SIGNATURE - Signature value used in many data structures on disk
 */
typedef ULONG SIGNATURE;
typedef SIGNATURE far *PSIGNATURE;


/**	TIME - time
 *
 *	Time used as access time, read time, etc.
 */

typedef ULONG TIME;
typedef TIME far *PTIME;

/* XLATOFF */

/**	UID - user id
 *
 *	UID is used in a directory entry as the owner of a file.
 */

typedef USHORT UID;
typedef UID far *PUID;


/**	VOLUME - the volume id
 */

typedef ULONG VOLUME;
typedef VOLUME far *PVOLUME;


/**	Write type flags for SDW
 */

#define WT_CACH	    0x01	     /* write via cache */
#define WT_DIR	    0x02	     /* write direct as much as possible */
#define WT_EXT	    0x04	     /* write is extending the file */
#define WT_SECTORIO 0x08	     /* write using sector seeks */


/**	Bit Map Sets   */

#define BITMAPL	    -4		    /* bit map length preceeds table */
#define BITMAPC	    -8		    /* count of sectors left in bitmap */


/**
 * Return codes for Namecmd to LDE
 */

#define NAMECMP_GREATER 0   /* if first string (search string) is greater */
#define NAMECMP_LESS 1	    /* else if second string (dir ent name) greater  */


/**
 * Return codes for LDE
 */

#define LDE_CREATED	0
#define LDE_FOUND	ERROR_ALREADY_EXISTS
#define LDE_NOT_FOUND	ERROR_FILE_NOT_FOUND
#define LDE_CANT_SPLIT	ERROR_DISK_FULL
#define LDE_READ_FAULT	ERROR_READ_FAULT


/**
 * Return codes for Open
 */

#define OPEN_EXISTS	1
#define OPEN_CREATED	2
#define OPEN_REPLACED	3

/**
 * Return codes for ReadEA
 */
#define READEA_NO_ERROR 0
#define READEA_ERROR	1
#define READEA_NO_MORE	2

/**
 * Return codes for RdAH
 */
#define RDAH_NO_ERROR 0
#define RDAH_NO_MORE  1
#define RDAH_ERROR    2


/**
 * Return codes for WBU
 */

#define WBU_SAME	((USHORT) 0)
#define WBU_NEW		((USHORT) 1)

/**
 * Return codes for VSV
 */

#define VSV_INVALID	((USHORT) 0)
#define VSV_VALID	((USHORT) 1)

/**
 * Return codes for DelEntry
 */

#define DELENTRY_NO_ERROR	((USHORT) 0)
#define DELENTRY_ERROR		((USHORT) 1)


/*
 * Return value masks for TFA
 */
#define TFA_RET_BIT_ERROR   0x0001	/* Error bit in return value */
#define TFA_RET_BIT_BLKDEL  0x0002	/* Block Deleted ret val bit */


/* flag bits for lockea */
#define LEAS_LOCKGEAS	0x01
#define LEAS_SET	0x02

/* flag bits for sdr and sdw */
#define IO_DONE_EVENT  0x80
#define VM_LOCK_DONE   0x40
/* flag bit for readahead and cachefile */
#define RA_CACHE_BLOCKS  0x20


/* these came from infoseg.inc in Gordon's assy code */
#define ATTR_READ_ONLY	0x01
#define ATTR_HIDDEN	0x02
#define ATTR_SYSTEM	0x04
#define ATTR_DIRECTORY	0x10
#define ATTR_ARCHIVE	0x20

#define ATTR_EXCLUDE_NORMAL 0x80

#define ATTR_NEWNAME	0x40
#define ATTR_SEARCH	(ATTR_HIDDEN | ATTR_SYSTEM | ATTR_DIRECTORY | \
			 ATTR_NEWNAME)

#define ATTR_MODE_BITS	(ATTR_HIDDEN | ATTR_SYSTEM | ATTR_DIRECTORY | \
			 ATTR_ARCHIVE | ATTR_READ_ONLY)

#define ATTR_CHANGEABLE (ATTR_READ_ONLY | ATTR_HIDDEN | ATTR_SYSTEM | ATTR_ARCHIVE)

/*
 * Gets the min of two numbers (these are also in stdlib.h!)
 */
#define MIN(x,y)	((x)<(y)?(x):(y))

/*
 * Gets the max of two numbers
 */
#define MAX(x,y)	((x)>(y)?(x):(y))

/*
 * gets the index field of a selector
 */
#define SEL_INDEX(sel)		((sel) >> 3)

/* XLATON */
/*
 * storage pointer shared between fnodes and eaat's
 */
typedef struct SPTR { /* SPTR */
	ULONG cbRun;
	LSN lsn;
} SPTR;
/* XLATOFF */
typedef SPTR far *PSPTR;


/*
 *  Structure passed between mini-FSD and real FSD.  Includes the address of
 *  a callback routine (part of the real FSD), and a list of selectors which
 *  need to be forced to ring 0.  It is assumed that no more than 16 code
 *  selectors will need to be changed.
 */

#define MAX_CODE_SELS	16

typedef struct PB_MFSDATA { /* PB_MFSDATA */
	INT (far pascal far *CallBack)
	      (struct sffsd far *, PVOID );
	USHORT cSels;
	SEL asel [MAX_CODE_SELS];
} PB_MFSDATA;

typedef PB_MFSDATA far * PPB_MFSDATA;


typedef BYTE VMLH[12];	    /* VMlock Handle */

typedef struct SWAP {	    /* Swappable code module info		 */
    USHORT usLockCnt;	    /* # of threads using it			 */
    ULONG semChgState;	    /* Set when module is being locked\unlocked	 */
    VMLH LockHandle;	    /* Lock handle for VMLock\Unlock		 */
    PVOID pModAddress;	    /* Module start address			 */
    USHORT usModSize;	    /* Module size				 */
} SWAP;

typedef SWAP *PSWAP;
