/*	@(#)types.h	13.2 (RC International) 91/03/04	*/

#ifndef	_TYPES_H
#define	_TYPES_H


/*
 *  POSIX typedefs must be guarded against
 *  definitions in other include files.
 *
 */

#ifndef _CLOCK_T
#define _CLOCK_T
typedef	unsigned long clock_t;
#endif /* _CLOCK_T */

#ifndef _DEV_T
#define _DEV_T
typedef	unsigned short dev_t;
#endif /* _DEV_T */

#ifndef _GID_T
#define _GID_T
typedef unsigned short gid_t;
#endif /* _GID_T */

#ifndef _INO_T
#define _INO_T
typedef	unsigned long ino_t;
#endif /* _INO_T */

#ifndef _KEY_T
#define _KEY_T
typedef	long key_t;
#endif /* _KEY_T */

#ifndef _MODE_T
#define _MODE_T
typedef	unsigned long mode_t;
#endif /* _MODE_T */

#ifndef _NLINK_T
#define _NLINK_T
typedef	unsigned long nlink_t;
#endif /* _NLINK_T */

#ifndef _OFF_T
#define _OFF_T
typedef	long off_t;
#endif /* _OFF_T */

#ifndef _PID_T
#define _PID_T
typedef int pid_t;
#endif /* _PID_T */

#ifndef _SIZE_T
#define _SIZE_T
typedef unsigned int size_t;
#endif /* _SIZE_T */

#ifndef _TIME_T
#define _TIME_T
typedef	long time_t;
#endif /* _TIME_T */

#ifndef _UID_T
#define _UID_T
typedef long uid_t;
#endif /* _UID_T */

/*
 *  Various other typedefs
 */

typedef	unsigned char	u_char;
typedef	unsigned short	u_short;
typedef	unsigned int	u_int;
typedef	unsigned long	u_long;

/* The following are for backwards compatibility */
/* (SYSV) and should not be used in new sources. */
typedef	unsigned short	ushort;
typedef unsigned int	uint;

typedef	char *	caddr_t;
typedef	long	daddr_t;
typedef	long	fbaddr_t;
typedef	long	paddr_t;
typedef	long	swblk_t;
typedef u_long	spin_t;
typedef u_long	logsn_t;
typedef u_long	rlim_t;
typedef char	bool_t;
typedef	struct	_quad { long val[2]; } quad;


/*
 *  Useful constants
 */

#ifndef FALSE
#define FALSE	((bool_t) 0)
#endif /* FALSE */
#ifndef TRUE
#define TRUE	((bool_t) 1)
#endif /* TRUE */

/*
 * WARNING:
 * this must match the definition of kernel jmp_buf's in rc/pcb.h
 */
typedef	struct	label_t	{
	int	val[12];
} label_t;


/*
 * Select uses bit masks of file descriptors in longs.
 * These macros manipulate such bit fields (the filesystem macros use chars).
 * FD_SETSIZE may be defined by the user, but the default here
 * should be >= (NBBY * NBPW).
 */

#include <sys/param.h>

#ifndef	FD_SETSIZE
#define	FD_SETSIZE	256
#endif /* FD_SETSIZE */

typedef	long	fd_mask;
#define	NFDBITS	(sizeof(fd_mask) * NBBY)	/* Bits per mask */
#ifndef	howmany
#define	howmany(x, y)	(((x)+((y)-1))/(y))
#endif /* howmany */

typedef	struct	fd_set	{
	fd_mask fds_bits[howmany(FD_SETSIZE, NFDBITS)];
} fd_set;

#define	FD_SET(n, p)	((p)->fds_bits[(n)/NFDBITS] |= (1 << ((n) % NFDBITS)))
#define	FD_CLR(n, p)	((p)->fds_bits[(n)/NFDBITS] &= ~(1 << ((n) % NFDBITS)))
#define	FD_ISSET(n, p)	((p)->fds_bits[(n)/NFDBITS] & (1 << ((n) % NFDBITS)))
#define	FD_ZERO(p)	lzero((long *)(p), sizeof(*(p))/sizeof(long))


/*
 *  UID_T -- TX unique identifier structure.
 *  Used to identify devices, file systems, ...
 *  in the TX distributed environment.
 */

typedef union {
    u_long	uid_data[2];		/* External definition */
    struct {
	u_int	       	timestamp;		/* A clock value */
	u_int       	seqno	: 10;		/* If timestamps are equal */
	u_int       	machine	: 22;		/* RPU serial # */
    }		uid_internal;		/* Real structure */
} UID_T;

/* UID comparison functions */
#define uid_equal(a,b)	( (a.uid_data[0] == b.uid_data[0]) && \
			  (a.uid_data[1] == b.uid_data[1]) )

#define uid_less(a,b)	( (a.uid_data[0] < b.uid_data[0]) ? TRUE  : \
			  (a.uid_data[0] > b.uid_data[0]) ? FALSE : \
			  (a.uid_data[1] < b.uid_data[1]) )



/*
 *  The following are not used by TX (TX uses UID's instead,
 *  refer to UID above) but are kept for compatibility.
 */

/* major part of a device */
#define	major(x)	((int)(((unsigned)(x)>>8)&0377))

/* minor part of a device */
#define	minor(x)	((int)((x)&0377))

/* make a device number */
#define	makedev(x,y)	((dev_t)(((x)<<8) | (y)))


#endif /* _TYPES_H */
