/*static char *SCCSID = "@(#)filemode.h	6.2 91/01/21";*/
//	SCCSID = @(#)filemode.h	6.2 91/01/21


#define stdin	    0
#define stdout	    1
#define stderr	    2
#define stdaux	    3
#define stdprn	    4


//
//	The OS/2 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 L L L 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.)
//		LLL (8-10): Locality of reference (sequential, random, etc.)
//		M (3) : Monitor open
//		I (7) : Not inherited by child
//		R (11): Rumored to be used by spooler. API caller must set
//			this to zero.
//		C (12): Advise device driver not to cache data. This is
//			stored in JFN flags.
//		F (13): Fail errors
//		W (14): write through
//		D (15): Direct access open
//
//	The DosOpen2 and $Extended_Open2 calls has an additional word for
//	openmode. The layout of this word is
//
//		5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0
//		P U U U U U U U U U U M T N C C
//
//	with:
//		P (15): Open physical disk (used by FDISK program). This bit
//			is set by procedure DevReturnHandle. API/INT21h
//			caller must set this bit to zero. This bit is stored
//			in sft.
//
//    H  (14): Protected file handle, if set.
//
//    E  (5): Essential EA's, if set.
//
//		M  (4): Console I/O Mode. 1 => Raw I/O; 0 => Cooked IO
//		
//		T  (3): Console Handle, if set; (r/o bit)
//
//		N  (2): Non-spooled access
//
//		C  (0,1): Consistency mode
//
//		U     : Unused anywhere. API caller must set these bits to
//			zero.
//
//	NOTE:	Please document all use of the openmode bits including those
//		that are internal to the kernel (e.g. the P bit).

//			wwwwxxxxyyyyzzzz
//			5432109876543210
#define open_access	0x0007
#define open_for_read	0x00
#define open_for_write	0x01
#define open_for_both	0x02
#define open_max	0x02
#define open_for_exec	0x03		// open via internal exec call
					//   (not available to API)

#define open_monitor		0x0008
#define open_sharing_mode	0x0070
#define sharing_compat		0x000
#define sharing_deny_both	0x010
#define sharing_deny_write	0x020
#define sharing_deny_read	0x030
#define sharing_deny_none	0x040
#define sharing_max		0x040	// max value for check_access_AX
					//  (check_access_ax handles

// these bits are for openmode
					// sharing_net_FCB as a special case)
#define open_no_inherit		0x0080	// Child does not inherit handle
#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_no_cache		0x1000	// don't cache data
#define open_locality		0x0700	// locality of reference

#define locality_unknown	0x0000
#define locality_sequential	0x0100
#define locality_random		0x0200
#define locality_semirandom	0x0300

// these bits are for openmode2 available to DosOpen3/DosOpen2/$Extended_Open2
#define open2_consist_bits	0x0001	// first consistency bit (for now)
#define open2_nonspooled	0x0004	// nonspooled access
#define open2_essentialea	0x0010	// essential ea for reads
#define open2_phys_disk		0x8000	// open physical disk
#define open2_protected_filehandle	0x4000 // protected filehandle access

#define open2_io_mode		0x0010	// raw/cooked mode for CON only
#define open2_console		0x0008	// handle is for Console device
// open2_io_mode & open2_console bits are also carried in JFN flags

// Bits carried in SFT mode field (@PhysDisk)
#define o_mode_in_sft  (open_direct|open_monitor|open_sharing_mode|open_access|open_locality)

// Bits carried in JFN flags
#define o_mode_in_flags	 open_write_through|open_autofail|open_no_inherit|open_no_cache

// Bits carried in openmode2
#define o_mode2_in_flags (open2_consist_bits | open2_nonspooled | open2_io_mode | open2_essentialea | open2_protected_filehandle )

// Reserved bits
#define o_mode_reserved	 ~(o_mode_in_sft|o_mode_in_flags)
#define o_mode2_reserved  ~(o_mode2_in_flags)
