/*static char *SCCSID = "@(#)filemode.h	6.7 92/02/27";*/
/*
 *** File modes - passed to open, stored in sf_mode or JFN_Flags
 *
 *	HISTORY
 *	    14-Sep-1988 16:26 by Leif Pederson [leifp] resynch w/Gordon
 *		- don't need stdin, stdout, etc. as in Gordon's
 */

/*
 *	The dos 5 api calls DosOpen, DosSetFHandState, and DosQFHandState
 *	all use a mode word parameter.  Some of these values are stored
 *	in the sft (system file table) in the field sf_mode.  Others
 *	are stored in the JFN flags (JFN_Flg_Ptr).  The layout of
 *	sf_mode and the word parameter for the call is the same.  The
 *	following EQU's are used to get to these values.  The layout
 *	of the word is:
 *
 *		5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0
 *		D W F C R R R R I S S S M A A A
 *
 *	with:
 *		AAA (2-0): The Access mode (read only, etc.)
 *		SSS (6-4): Sharing mode (deny write acces to others, etc.)
 *		M (3): Monitor open
 *		I (7): Inherited by child
 *		C (12): Cache bypass
 *		F (13: Fail errors
 *		W (14): write through
 *		D (15): Direct access open
 *		R: reserved should be zero.  Some of these bits are defined
 *		   internally in the kernel.  See EQUs below.
 *	For more information see the Dos 5 spec.
 *
 *				wwwwxxxxyyyyzzzz
 *				5432109876543210
 */
#define OPEN_ACCESS		0x0007
#define OPEN_FOR_READ		0x0000
#define OPEN_FOR_WRITE		0x0001
#define OPEN_FOR_BOTH		0x0002
#define OPEN_MAX		0x0002
#define OPEN_FOR_EXEC		0x0003	/* open via internal exec call
					   (not available to API)     */

#define OPEN_MONITOR		0x0008

#define OPEN_SHARING_MODE	0x0070
#define SHARING_COMPAT		0x0000
#define SHARING_DENY_BOTH	0x0010
#define SHARING_DENY_WRITE	0x0020
#define SHARING_DENY_READ	0x0030
#define SHARING_DENY_NONE	0x0040
#define SHARING_NET_FCB		0x0070
#define SHARING_MAX		0x0040	/* max value for check_access_AX
					   (check_access_ax handles
					   sharing_net_FCB as a special case) */

#define OPEN_NO_INHERIT		0x0080	/* Child does not inherit handle */
#define OPEN_NO_CACHE		0x1000	/* bypass the cache   */
#define OPEN_AUTOFAIL		0x2000	/* hard errors failed */
#define OPEN_WRITE_THROUGH	0x4000	/* write through to disk */
#define OPEN_DIRECT		0x8000	/* open of a device for direct access */
#define OPEN_NON_CACHE		0x0100	/* @@ open for cache bypass
							(@PhysDisk) */
#define OPEN_PHYS_DISK		0x0200	/* @@ open physical disk (@PhysDisk) */
#define OPEN_SECTOR_IO		0x0800	/* only allow sector based I/O */
#define OPEN_SEQUENTIAL_ACCESS	0x0100	/* sequential read access */
#define OPEN_RANDOM_ACCESS	0x0200   /* mainly random access */
#define OPEN_RANDOM_SEQUENTIAL_ACCESS	0x0300 /* random access with some locality */

/* High word of extended mode is assumed for server open check
 * the bit used is not defined by DCR and can be changed after 2.0
 * if necessary. The bit is defined in the FHT only.
 * Felix Miro'
 */

#define OPEN_BY_SERVER     0x0001
/***************************************/

/* Bits carried in SFT mode field (@PhysDisk) */
#define O_MODE_IN_SFT	    (OPEN_DIRECT + \
				OPEN_MONITOR + \
				OPEN_SHARING_MODE + \
				OPEN_ACCESS + OPEN_NON_CACHE + \
				OPEN_PHYS_DISK)		/* @@ */

/* Bits carried in JFN flags */
#define O_MODE_IN_FLAGS	    (OPEN_WRITE_THROUGH + \
				OPEN_AUTOFAIL + \
				OPEN_NO_INHERIT)

/* Reserved bits */
#define O_MODE_RESERVED	    (~(O_MODE_IN_SFT + O_MODE_IN_FLAGS))



/*
 * Macro to convert from IOFlag parameters that get passed into FS_ functions
 * to open_mode type bits that the rest of Pinball expects to see
 *
 * Warning: currently only good for the IOFL_WRITETHRU bit
 *
 * BUGBUG: look at what code is produced by the compiler.
 */
#define IOFLAG_TO_OPENMODE( ioflag )	\
	(ULONG)( (((UINT)ioflag / IOFL_WRITETHRU) & 1) * OPEN_WRITE_THROUGH )
