/* $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.
 */

#ident	"$Header: file.h 1.15 90/01/24 $"

#ifndef	_SYS_FILE_H_

/*
 * file.h
 *	File-descriptor structure.
 */

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

#include	"unistd.h"

#ifdef	INKERNEL
/*
 * Descriptor table entry.
 * One for each kernel object.
 */
struct	file {
	int	f_flag;		/* see below */
	long	f_count;	/* reference count */
	lock_t	f_mutex;	/* lock access to this descriptor */
	short	f_next;		/* free-list thread */
 	struct vnode *f_vnode;		/* ptr to file's vnode */
	off_t	f_offset;
 	struct	ucred *f_cred;	/* credentials of user who opened file */
};

extern	struct	file *file;
extern	lock_t	file_list;
struct	file	*getf();
struct	file	*falloc();

/*
 * Lock/unlock, bump f_count macros.
 */

#define	FDLOCK(fp)	p_lock(&(fp)->f_mutex, SPLFD);
#define	FDUNLOCK(fp,s)	v_lock(&(fp)->f_mutex, (s));
#define	FDBUMP(fp)	{spl_t fd_spl; fd_spl = FDLOCK(fp); ++(fp)->f_count; FDUNLOCK(fp,fd_spl);}
#endif	/* INKERNEL */

/* flags */
/*
 * These values are 1 more than the corresponding value
 * from fcntl.h O_xxxxxxx
 * open() (vfs_syscalls.c) converts the O_xxx values by calling
 * copen() with  O_xxx - FOPEN.
 */

#define	FOPEN	0xffffffff
#define	FREAD	0x01		/* O_RDONLY set on open() or fcntl() */
#define	FWRITE	0x02		/* O_WRONLY set on open() or fcntl() */
#define	FNDELAY	0x04		/* O_NDELAY set on open() or fcntl() */
#define	FAPPEND	0x08		/* O_APPEND set on open() or fcntl() */
#define FSYNC	0x10		/* O_SYNC set on open() or fcntl() */
#define FRCACH  0x20		/* Used for file and record locking cache*/
#define	FMASK	0x7f		/* FMASK should be disjoint from FNET */
#define FNET	0x80		/* needed by 3bnet */

/* open only modes */

#define	FCREAT	0x100		/* O_CREAT set on open() */
#define	FTRUNC	0x200		/* O_TRUNC set on open() */
#define	FEXCL	0x400		/* O_EXCL set on open() */
#define FNOCTTY 0x800		/* O_NOCTTY set on open() */

#ifdef	INKERNEL
/*
 * special flag, used only internally to the kernel.
 */
#define FNOTOSTOP 0x1000	/* disable background stop jobs */
#define FVHANGUP  0x2000	/* about to vhangup flag  (passed on) */
#define FHUPED    0x4000	/* file vhanguped flag  (causes error) */
#define	FGENTTY	  0x8000	/* file accessed via /dev/tty */

#endif	/* INKERNEL  */

#define	_SYS_FILE_H_
#endif	/* _SYS_FILE_H_ */
