#include  "param.h"		/* /usr/include */
#include  "tty.h"		/* /usr/include */

#include  "KERcalls.h"		/* /kr/sunix/emulator/include */

/* Externals needed by some programs */
extern char gfiden[] ;
extern seid real_seid() ;

#define	BLOCKSZ		512
#define	TTYBLKSZ	(BLOCKSZ/4)
#define	MAXCHILD	10	/* # of spawned children known */
#define	MAXSEG		6	/* # of network segments per user */
#define	MAXSEGS		8	/* # of segments per user */
#define	TICKS		10	/* Ticks per second */

/* Character values needed by read and/or write functions */
#define	NL		012
#define	CR		015
#define	ESC		033

/* Values for accessing status data (statbuf) */
#define	OWNER		000700
#define	GROUP		000070
#define	OTHER		000007
#define	RACCESS		000004
#define	WACCESS		000002
#define	EACCESS		000001

#define	RWACCESS	(RACCESS|WACCESS)
#define	RWOWNER		(RWACCESS<<6)
#define	RWGROUP		(RWACCESS<<3)
#define	RWALL		(RWOWNER|RWGROUP|RWACCESS)

/* File access modes for open calls */
#define	MREAD		0		/* read only */
#define	MWRITE		1		/* write only */
#define	MREADWRITE	2		/* read/write */
#define	MEXCLUSIVE	4		/* exclusive use
					   bit */
#define	MEXWRITE	(MEXCLUSIVE|MWRITE)	/* exclusive write -
					   lock out other writers */
#define	MEXREADWRITE	(MEXCLUSIVE|MREADWRITE)	/* excl. use -
						   lock out all others */

#define	NEW			0		/* New file (creat) */
#define	OLD			1		/* Old file (creat) */

/* IPC message types */
#define	NO_SUCH_MSG		50		/* Invalid msg type */
#define	DEAD_CHILD		51		/* Child death IPC */
#define	LIVE_CHILD		52		/* Child birth IPC */
#define	DATA_PRESENT		55		/* Data present in a
						   pipe/port */
#define	SPACE_PRESENT		56		/* Space present in a
						   pipe/port */
#define	NO_MESSAGE		60		/* No IPC message */

/* File Types */
#define	TTY			1
#define	DISK			2
#define	DIRECTORY		3
#define	PIPE			4
#define	PORT			5

struct O_F_data			/* Open files data */
{
	int	ftype ;		/* Type of "file":
				   1 - terminal,
				   2 - ordinary file,
				   3 - directory,
				   4 - pipe,
				   5 - port */
	seid	fseid ;		/* switch on ftype:
				   1 - SEID of opened terminal,
				   2 - SEID of opened file,
				   3 - SEID of opened directory,
				   4 - not used,
				   5 - SEID of opened name file */
	seid	sseid ;		/* switch on ftype:
				   1 - tty ID (a la UNIX),
				   2 - not used,
				   3 - SEID of sub-type,
				   4 - SEID of sharable I/O
				   segment,
				   5 - SEID of sharable I/O
				   segment */
	char	fmode ;		/* User -specified access mode.
				   Bit map with bit meanings of:
				   0 - read only,
				   1 - write only,
				   2 - read/write,
				   3 - not used,
				   4 - not allowed,
				   5 - exclusive write,
				   6 - exclusive read/write */
	char	rmode ;		/* Real access mode for "file" if
				   different.See fmode for
				   values */
	int	dptr ;		/* Index into this object's buf_data item */
	char	fillOF[20] ;
} ;
/* NOTE: want NOFILE+1 * sizeof O_F_data to be a multiple of 512 */

struct buf_data			/* Open file buffer data */
{
	int	Block ;		/* switch on ftype:
				   1 - number of chars in input buffer,
				   2 - block number of current
				   file position,
				   3 - segment designator of I/O
				   segment if mapped in,
				   4 - segment designator of I/O
				   segment if mapped in */
	int	byte ;		/* switch on ftype:
				   1 - pointer into input buffer for next
				   char for user to read,
				   2 - byte position within current block,
				   3 - byte position within current block,
				   4,5 - flag indicating whether segment is
				   mapped in core */
	char	*fbuf ;		/* switch on ftype:
				   1 - index into this TTY's tty_data item,
				   2 - pointer to I/O buffer for
				   this file,
				   3 - pointer to I/O buffer for
				   this file,
				   4,5 - pointer to mapped in segment */
	int	BDused ;	/* Flag to indicate if this item is used */
	long	fsize;		/* file size */
	char	fillBD[20] ;
} ;
/* NOTE: want NOFILE+1 * sizeof buf_data to be a multiple of 512 */

#define	MAX_TTYS	5	/* Max number of ttys
				   which a single process may
				   have open at one time */

struct tty_data			/* Terminal specific data */
{
	char	Erase ;		/* erase character */
	char	Kill ;		/* kill line character */
	int	Mode ;		/* Mode bits:
				   000002 echo and print tabs as spaces,
				   000010 echo (full duplex),
				   000040 raw mode: wake up on all characters,
				 */
	char	*ibuf ;		/* pointer to input buffer
				   if terminal opened for
				   reading */
	char	*obuf ;		/* pointer to output buffer
				   if terminal opened for
				   writing */
	int	nchars ;	/* # of chars currently in output buffer */
	boolean	ipsent ;	/* INPUTWAIT request sent flag */
	boolean	iprec ;		/* INPUTWAIT request completed */
} ;
/* Kernel error numbers */
/*#define	XbdKcl			00001*/
#define	XbPrSd			00002
/*#define	XbStPm			00003*/
/*#define	XbTiiPm			00004*/
#define	XnoObj			00005
/*#define	XbadDa			00006*/
/*#define	XnoSLev			00007*/
/*#define	XnoSPriv		0008*/
#define	XnoPriv			00009
#define	XnoAcc			00010
/*#define	XseidEh			00011*/
#define	XncnDo			00012
/*#define	XbAddr			00013*/
/*#define	XbadFlow		0014*/
/*#define	Xerror			10101*/
/*#define	Xfault			10102*/
/*#define	Xdown			10103*/
#define	Xtimeout		10104
/*#define	XnoFunct		10105*/
/*#define	Xmark			10106*/
/*#define	XatEot			10107*/
#define	XendOfFile		10108
#define	Xbusy			10110
/*#define	XnoMode			10111*/
/*#define	XbadSize		10112*/
/*#define	XnoClass		10113*/
/*#define	XbadNsp			10115*/
#define	XbadOd			10116
/*#define	XbadPriv		10117*/
/*#define	XbadRefCount		10118*/
/*#define	XbadStCap		10119*/
/*#define	XbadSubtype		10120*/
/*#define	XbadSubtypeMatch	10121*/
/*#define	XcritExcl		10122*/
/*#define	XdapViol		10123*/
/*#define	XnoExclWrite		10124*/
/*#define	XnoFile			10125*/
/*#define	XnoOwner		10126*/
/*#define	XnoStCap		10127*/
/*#define	XnotWritable		10128*/
/*#define	XodSpace		10129*/
/*#define	XinBuf			10131*/
/*#define	XnotReadable		10132*/
/*#define	XprvFn			10134*/
#define	XbadModes		10135
/*#define	XbadBlockNo		10136*/
/*#define	XbadFs1			10137*/
/*#define	XbadFs2			10138*/
/*#define	XbadFs3			10139*/
#define	XnoSpace		10140
#define	XopenFiles		10141
/*#define	XnoTranquil		10142*/
/*#define	XmtSpace		10143*/
/*#define	XbadVol			10145*/
/*#define	XbadLink		10147*/
/*#define	XexSpace		10148*/
/*#define	XnoAsync		10149*/
#define	Xasync			10150
/*#define	Xmoving			10151*/
#define	Xaborted		10152
#define	Xattn			10153
/*#define	XexFile			10154*/
/*#define	XbSgSd			20101*/
/*#define	XbSgDes			20102*/
/*#define	XnSgDes			20103*/
/*#define	XsgNoAcc		20201*/
/*#define	XshSg			20301*/
/*#define	XinSgAldMap		20302*/
/*#define	XoutSgAldUmp		20303*/
/*#define	XbLcArgSg		20304*/
/*#define	XbSzArgSg		20305*/
/*#define	XnWrtArgSg		20306*/
/*#define	XnwOutSg		20307*/
/*#define	XsgMap			20308*/
/*#define	XnPvLkSg		20401*/
/*#define	XnPvStkSg		20402*/
/*#define	XchgSgOwn		20501*/
/*#define	XwOnlSg			20502*/
/*#define	XdupSg			20503*/
/*#define	XbSgSz			20504*/
/*#define	XchgIDspc		20505*/
/*#define	XpostEh			20601*/
/*#define	XgstEh			20602*/
/*#define	XswapEh			20603*/
/*#define	XmemEh			20604*/
/*#define	XbSgRng			20701*/
/*#define	XblAdVacMmu		20702*/
/*#define	XblNtInSg		20703*/
/*#define	XsgSw			20704*/
/*#define	XnPgSg			20705*/
/*#define	XvrtMmCfl		20706*/
/*#define	XbPcsRef		30001*/
/*#define	XbPcsSd			30002*/
/*#define	XcpuT			30100*/
/*#define	XiiT			30101*/
/*#define	XbpT			30102*/
/*#define	XioT			30103*/
/*#define	XmemT			30104*/
/*#define	XfloT			30105*/
/*#define	XmmT			30106*/
/*#define	XbdDm			30200*/
/*#define	XKemt			30201*/
/*#define	XMapPr			30400*/
/*#define	XnoMap			30401*/
/*#define	XindMap			30402*/
/*#define	XnoInit			30403*/
/*#define	XbParam			30500*/
/*#define	XbNoMes			30600*/
/*#define	XsltAl			30700*/
/*#define	XnoProc			30800*/
/*#define	XunInt			30801*/
/*#define	XcPsInt			30900*/
/*#define	XbPsLev			30901*/
/*#define	XbSchL			31100*/
/*#define	XnoHelp			31101*/
/*#define	XbadSlot		31400*/
/*#define	Xempty			31401*/
/*#define	XbMapIn			31500*/
/*#define	XbMapOut		31501*/
/*#define	XbSwp			31502*/
/*#define	XbMovIn			31503*/
/*#define	XbMovO			31504*/
/*#define	XbUt			40101*/
/*#define	XnNxUt			40102*/
/*#define	XplEh			40103*/
/*#define	XutAldAl		40104*/
/*#define	XutAldFr		40105*/
/*#define	XbOsb			40201*/
/*#define	XbOsd			40202*/
/*#define	XbSz			40203*/
/*#define	XnExtn			40204*/
/*#define	XpceAldFr		40205*/
/*#define	XrecEh			40206*/
/*#define	XspcEh			40207*/
/*#define	XpceAldAlc		40210*/
/*#define	XbEmt			40401*/
#define	XbFn			40402
/*#define	XbPm			40601*/

/* Subtype SEIDs */
#define	Udi_id0				100
#define	Kf_id0				100
#define	Ne_id0				100
#define	Udi_id1				0
#define	Kf_id1				1
#define	Ne_id1				2

/*
	Terminal mode bits for SETTERMMODES1 and GETTERMMODES

	To use the values in this list, coerce into cardinal and
	use as a bit subscript of the "blockNo" or "errs.devDep"
	argument to K_device_function.
terminal_mode_bits =
		(break_on_all_characters,
		 suppress_echo,
		 suppress_echo_of_break_character);
*/
#define	BREAK_ON_ALL_CHARS	1
#define	SUPPRESS_ECHO		2
#define	SUPP_ECHO_OF_BREAK	4

/* The following defines for use of UDM were in EFI.h, but have been
 * placed here because EFI.h contains so much that is not wanted */
/*
 *   pathOps = (po_MKENTRY, po_REMOVE, po_LOCATE, po_CHDIR, po_EXEC, po_CREAT, po_LINK)
 *              note: po_LINK is the same as po_MKENTRY;
 */

#define po_MKENTRY     0
#define po_REMOVE      1
#define po_LOCATE      2
#define po_CHDIR       3
#define po_EXEC        4
#define po_CREAT       5
#define po_LINK        0       /* link is the same as mkentry: dir */
				/* manager only knows about mkentry */
