/*  DO NOT EDIT THIS FILE.

    It has been auto-edited by fixincludes from:

	"/usr/include/sys/file.h"

    This had to be done to correct non-standard usages in the
    original, manufacturer supplied header file.  */

/* $Header: file.h,v 1.38.98.9 95/12/07 14:07:41 wbooth Exp $ */

#ifndef _SYS_FILE_INCLUDED /* allows multiple inclusion */
#define _SYS_FILE_INCLUDED

#ifndef _SYS_STDSYMS_INCLUDED
#ifdef _KERNEL_BUILD
#    include "../h/stdsyms.h"
#else  /* ! _KERNEL_BUILD */
#    include <sys/stdsyms.h>
#endif /* _KERNEL_BUILD */
#endif   /* _SYS_STDSYMS_INCLUDED  */

#ifdef _KERNEL
#    define _INCLUDE_STRUCT_FILE
#endif

#ifdef _KERNEL_BUILD
#include "../h/types.h"
#include "../h/fcntl.h"
#include "../h/sem_beta.h"
#undef	ovbcopy
#else  /* ! _KERNEL_BUILD */
#include <sys/types.h>
#include <fcntl.h>
#ifdef _INCLUDE_STRUCT_FILE
#include <sys/sem_beta.h>
#endif /* _INCLUDE_STRUCT_FILE */
#endif /* _KERNEL_BUILD */

#ifdef _INCLUDE_HPUX_SOURCE

#ifdef _INCLUDE_STRUCT_FILE
/*
 * Descriptor table entry.
 * One for each kernel object.
 */
struct	file {
	int	f_flag;		/* see below */
	short	f_type;		/* descriptor type */
	short	f_msgcount;	/* references from message queue */
	int	f_count;	/* reference count */
#ifdef __cplusplus
	struct	fileops {
		int	(*fo_rw)(struct file *, ...);
		int	(*fo_ioctl)(struct file *, ...);
		int	(*fo_select)(struct file *, ...);
		int	(*fo_close)(struct file *, ...);
	} *f_ops;
#else /* not __cplusplus */
	struct	fileops {
		int	(*fo_rw)();
		int	(*fo_ioctl)();
		int	(*fo_select)();
		int	(*fo_close)();
	} *f_ops;
#endif /* not __cplusplus */
	caddr_t	f_data;		/* ptr to file specific struct (vnode/socket) */
#if !defined(__STDC_32_MODE__)
	k_off_t	f_offset;
#else
	off32_t	f_offset[2];
#endif
	caddr_t	f_buf;
	struct	ucred *f_cred;	/* credentials of user who opened file */
	b_sema_t f_b_sema;
};
#endif /* _INCLUDE_STRUCT_FILE */

#ifdef _KERNEL

extern	struct	file *file, *fileNFILE, *file_reserve;
extern	int	nfile;
extern  int     file_pad;
extern  struct  file *getf();
extern	struct	file **getfp();
extern	char	getp();
extern	char 	*getpp();
extern  struct  file *falloc();
#endif /* _KERNEL */

/* 
 * flags- also for fcntl call.
 */
#define	FOPEN		(-1)
#define	FREAD		000001		/* descriptor read/receive'able */
#define	FWRITE		000002		/* descriptor write/send'able */
/*
  FNDELAY and FAPPEND have equivalents in fcntl.h.  The numbers should 
  be the same!  HP replicates them because Bell replicates them.
 */
#define	FNDELAY		000004		/* no delay */
#define	FAPPEND		000010		/* append on each write */
#define	FMARK		000020		/* mark during gc() */
#define	FDEFER		000040		/* defer for next gc pass */
#define	FCOPYAVOID	000200		/* uio copy avoidance flag */
#define FNBLOCK	       0200000		/* POSIX */

/* bits to save after open */
/* FMASK defines the bits to save after open */
/* FCNTLCANT defines the bits that can't be modified with fcntl() */
/* FNOCTTY has equivalent in fcntl.h, O_NOCTTY. */
#define FNOCTTY		0400000 /* do not affiliate terminal device on open */
#define FMASK (FREAD|FWRITE|FNDELAY|FNBLOCK|FAPPEND|FSYNC|FDSYNC|FRSYNC|FNOCTTY|FLARGEFILE)
#define FCNTLCANT	(FREAD|FWRITE|FMARK|FDEFER|FNOCTTY)

/*
  FCREAT, FTRUNC and FEXCL have equivalents in fcntl.h.  The numbers must
  be the same!  HP replicates them because Bell replicates them.
 */
/* open only modes */
#define	FCREAT		00400		/* create if nonexistant */
#define	FTRUNC		01000		/* truncate to zero length */
#define	FEXCL		02000		/* error if already created */

/*
 * Access call.
 */
/*
  These have equivalents in unistd.h.  The numbers must
  be the same!  HP replicates them because Bell replicates them.
 */
#ifndef R_OK    
#define	F_OK		0	/* does file exist */
#define	X_OK		1	/* is it executable by caller */
#define	W_OK		2	/* writable by caller */
#define	R_OK		4	/* readable by caller */
#endif

/*
 * Lseek call.
 */
/*
  These have equivalents in unistd.h (SEEK_*).  The numbers must
  be the same!  HP replicates them because Bell replicates them.
 */
#define	L_SET		0	/* absolute offset */
#define	L_INCR		1	/* relative to current offset */
#define	L_XTND		2	/* relative to end of file */

#ifdef _KERNEL
/*
 * Convert a user supplied file descriptor into a pointer, with side effect
 * of returning if there is no file pointer for this file descriptor.
 */
#define GETF(fp, fd) { \
	if (((fp) = getf((fd))) == NULL) \
		return; \
}

extern void putf();

#define PUTF(i) { \
	putf(i); \
}

#define PUTSOCK PUTF

#define FREEFP(fd, fp) { \
        if ((fp) != NULL) { \
                uffree(fd); \
                crfree((fp)->f_cred); \
		FPENTRYFREE(fp); \
                } \
}
/*
 * FPENTRYFREE frees an active (in-use) file table entry and decrements the 
 * number of active file table entries (for sar(1), etc. support).
 */
#define FPENTRYFREE(fp) { \
	register u_int reg_temp; \
	(fp)->f_count = 0; \
	MPCNTR(reg_temp).activefiles--; \
}

/* 
 * spinlock for the file table entry.
 */
#define MP_FTE_LOCK(fp,lockpp) \
	MP_H_SPINLOCK(ft_h_sl_pool,fp,lockpp)
#define MP_FTE_LOCK_USAV(fp,lockpp,contextp) \
	MP_H_SPINLOCK_USAV(ft_h_sl_pool,fp,lockpp,contextp)

#endif /* _KERNEL */

#define	DTYPE_VNODE	1	/* file */
#define	DTYPE_SOCKET	2	/* Berkeley IPC Socket */
#define DTYPE_STREAMS   3       /* Streams file type */
#define DTYPE_UNSP      5       /* user nsp control */
#define DTYPE_LLA	6	/* link-level lan access */

#endif /* _INCLUDE_HPUX_SOURCE */

#endif /* _SYS_FILE_INCLUDED */
