/* $Copyright:	$
 * Copyright (c) 1984, 1985, 1986, 1987, 1988, 1989, 1990 
 * Sequent Computer Systems, Inc.   All rights reserved.
 *  
 * This software is furnished under a license and may be used
 * only in accordance with the terms of that license and with the
 * inclusion of the above copyright notice.   This software may not
 * be provided or otherwise made available to, or used by, any
 * other person.  No title to or ownership of the software is
 * hereby transferred.
 */

/*	Copyright (c) 1984 AT&T	*/
/*	  All Rights Reserved  	*/

/*	THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF AT&T	*/
/*	The copyright notice above does not evidence any   	*/
/*	actual or intended publication of such source code.	*/

#ident	"$Header: types.h 1.21 90/05/16 $"

#ifndef	_SYS_TYPES_H_


/* $Log:	types.h,v $
*/

/*----------------------------------------------------------------------*
 * This file must meet the requirements in volume 2 of the X/Open	*
 * Portability Guide, Issue 3, which should be consulted before any	*
 * changes are made.							*
 *----------------------------------------------------------------------*/

/*____________________________________________________________________*
 * This file forms part of the POSIX requirement described in section *
 * 2.6 of 1003.1-1988 which should be refered to before making any    *
 * changes.							      *
 *____________________________________________________________________*/


typedef	long		daddr_t;	/* <disk address> type */
typedef	char *		caddr_t;	/* ?<core address> type */
typedef	unsigned long	ino_t;		/* <inode> type */
typedef	short		cnt_t;		/* ?<count> type */
#ifndef	_POSIX_SOURCE
typedef struct _quad { long val[2]; } quad;
typedef	unsigned char	unchar;
typedef	unsigned short	ushort;
typedef	unsigned int	uint;
typedef	unsigned long	ulong;
#endif /* _POSIX_SOURCE */

/*
 * For both POSIX and SVID compatablity, time_t and clock_t must
 * always be the same.
 */
typedef	long		time_t;		/* <time> type */
typedef long		clock_t;	/* <clock> type for POSIX */

typedef	long		dev_t;		/* <old device number> type */
typedef	long		off_t;		/* ?<offset> type */
typedef	long		paddr_t;	/* <physical address> type */
typedef	int		key_t;		/* IPC key type */
typedef	unsigned char	use_t;		/* use count for swap.  */
typedef	short		sysid_t;
typedef	short		index_t;
#ifndef _SIZE_T
typedef	unsigned int	size_t;		/* len param for string funcs */
#define _SIZE_T
#endif	/* _SIZE_T */
typedef int		bool_t;
typedef int		spl_t;
typedef long		swblk_t;
typedef short		pid_t;		/* for POSIX terminal proc groups */
typedef unsigned short	gid_t;		/* group IDs for POSIX */
typedef unsigned short 	uid_t;		/* user IDs for POSIX */
typedef unsigned short	mode_t;		/* file modes for POSIX */
typedef short		nlink_t;	/* link count type for POSIX */

/*
 * Savejmp/longjmp context.  Also used in context switching.
 */

#ifdef	ns32000
#ifndef _POSIX_SOURCE
typedef	struct	_physadr { int r[1]; } *physadr;
#endif
typedef struct	label_t {
	int	lt_r3;
	int	lt_r4;
	int	lt_r5;
	int	lt_r6;
	int	lt_r7;
	int	lt_fp;
	int	lt_sp;
        int	lt_pc;
} label_t;
#endif	/* ns32000 */

#ifdef	i386
#ifndef _POSIX_SOURCE
typedef	struct	_physadr { int	r[1]; } *physadr;
#endif
typedef struct	label_t {
	int	lt_esp;
	int	lt_ebp;
        int	lt_eip;
	int	lt_ebx;
	int	lt_esi;
	int	lt_edi;
} label_t;
#endif	/* i386 */

/*
 * For mutex data-structures.
 *
 * For ease of use for user-level code, we declare lock and sema struct's
 * here.  More detail is in sys/mutex.h and machine/mc_mutex.h.
 */

typedef	unsigned char	gate_t;

#ifdef	ns32000
typedef	struct	{
	gate_t		l_gate;
	char		l_state;
} lock_t;
#endif	/* ns32000 */

#ifdef	i386
typedef	unsigned char	lock_t;
#endif	/* i386 */

#ifdef	INKERNEL
typedef	struct	{
	struct	proc	*s_head;
	struct	proc	*s_tail;
	short		s_count;
	gate_t		s_gate;
	char		s_flags;
	struct	semstat	{
		unsigned long	ss_visit;
		unsigned long	ss_block;
		unsigned long	ss_totqlen;
	}		s_semstat;
} sema_t;

typedef struct list {
	struct list *l_flink;
	struct list *l_rlink;
} list_t;
#else
/*
 * Version for lint and other user needs.
 */
typedef	struct	{
	int		*s_head;
	int		*s_tail;
	short		s_count;
	gate_t		s_gate;
	char		s_flags;
	struct	semstat	{
		unsigned long	ss_visit;
		unsigned long	ss_block;
		unsigned long	ss_totqlen;
	}		s_semstat;
} sema_t;
#endif	/* INKERNEL */

#ifndef	_POSIX_SOURCE
/*
 * Structure used for inode time stamping,
 * setitimer/getitimer, and nfs
 */
typedef struct timeval {
	time_t	tv_sec;		/* seconds */
	time_t	tv_usec;	/* and microseconds */
} timeval_t;
#else	/* _POSIX_SOURCE */
/*
 * Structure used for inode time stamping.
 */
typedef struct {
	time_t	tv_sec;		/* seconds */
	time_t	tv_usec;	/* and microseconds */
} timeval_t;
#endif	/* _POSIX_SOURCE */

/*
 * Multiple "reader" / Single "writer" semaphores.  Can also be viewed as
 * shared/exclusive.
 *
 * Selectable policy: Strong Writer Preference (SWP) blocks new readers if a
 * waiting writer exists.  Weak Writer Preference (WWP) always allows new
 * readers if no writers queued, but v_writer() wakes writers ahead of readers.
 */
#ifdef	INKERNEL
#include "sys/llist.h"
#else	/* !INKERNEL */
typedef	caddr_t	slink_t;
#endif	/* INKERNEL */

typedef	struct	rwsema	{	/* reader/writer semaphore */
	gate_t	rw_mutex;	/* overall mutex */
	char	rw_policy;	/* strong/weak writer preference */
	short	rw_count;	/* -1 = busy writer, N>0 = # readers */
	slink_t	rw_wrwait;	/* queued writers */
	slink_t	rw_rdwait;	/* queued readers */
} rwsema_t;

#define	_SYS_TYPES_H_
#endif	/*_SYS_TYPES_H_*/
