/* IBM_PROLOG_BEGIN_TAG                                                   */
/* This is an automatically generated prolog.                             */
/*                                                                        */
/* bos72L src/bos/kernel/sys/file.h 1.43.1.12                             */
/*                                                                        */
/* Licensed Materials - Property of IBM                                   */
/*                                                                        */
/* COPYRIGHT International Business Machines Corp. 1985,2018              */
/* All Rights Reserved                                                    */
/*                                                                        */
/* US Government Users Restricted Rights - Use, duplication or            */
/* disclosure restricted by GSA ADP Schedule Contract with IBM Corp.      */
/*                                                                        */
/* IBM_PROLOG_END_TAG                                                     */
/* @(#)93     1.43.1.12  src/bos/kernel/sys/file.h, syslfs, bos72L, l2018_09C5 2/27/18 15:07:49 */
#ifndef _H_FILE
#define _H_FILE

/*
 * COMPONENT_NAME: SYSLFS - Logical File System
 *
 * FUNCTIONS:
 *
 * ORIGINS: 27, 3, 26
 *
 */

#include <sys/types.h>
#include <sys/param.h>
#include <sys/access.h>
#include <sys/lock_def.h>
#include <sys/cred.h>
#include <sys/uio.h>
#include <fcntl.h>

#ifdef __cplusplus
extern "C" {
#endif

#ifdef _KERNEL

typedef struct fileops
{
	int	(*fo_rw)(struct file *, enum uio_rw, struct uio *, 
			 ext_t, file_secattr_t *);
	int	(*fo_ioctl)(struct file *, long, caddr_t, ext_t, long);
	int	(*fo_select)(struct file *, int, ushort, ushort *, void (*)());
	int	(*fo_close)(struct file *);
	int	(*fo_fstat)(struct file *, struct stat *);
} fileops_t;

/* F_FDATASZ is the size of the f_fdata array to round up the size of the
 * file structure to 256 bytes, so it can embed file data (most of the
 * time) and not straddle a page boundary. If the file structure changes
 * size, modify the define below accordingly. 
*/
#define	F_FDATASZ (256 - (12 * sizeof(long)))

#define F_ALLOCATED(fp) \
	(((fp)->f_fnamep < &((fp)->f_fdata[0])) \
	 || ((fp)->f_fnamep > &((fp)->f_fdata[F_FDATASZ-1])))

#define FP_VNODE	0x00000001
#define FP_FID		0x00000010
#define F_PARENTISFID(fp) (((fdinfo_vn_fid_t *)((fp)->f_parentp))->flag \
				 == FP_FID)
#define F_PARENTISVP(fp)  (!F_PARENTISFID(fp))

/* One file structure is allocated for each open/creat/pipe call. Main use is
 * to hold the read/write pointer associated with each open file.
 *
 * Portions of this structure are overlaid when placed on the freelist.
 * Binary compatibility concerns require that fields *not* be rearranged for
 * sanity.
 */
__align(256) struct file {
	long	f_flag;		/* see fcntl.h for definitions		     */
	int	f_count;  	/* reference count			     */
	short	f_options;	/* file flags not passed through vnode layer */
	short	f_type;		/* descriptor type			     */

	/* The following fields are overloaded when the file struct is freed,
	 * except for the locks which must remain static. See struct freefile.
	 */

	struct vnode *f_data;		/* pointer to vnode struct	     */
#define	f_vnode	      f_data

	offset_t	f_offset;	/* read/write character pointer	     */
	off_t		f_dir_off;	/* BSD style dir offsets	     */
	struct ucred	*f_cred;	/* process cred at open		     */

	Simple_lock	f_lock;		/* file structure fields lock	     */
	Simple_lock	f_offset_lock;	/* file structure offset field lock  */

	caddr_t		f_vinfo;	/* any info vfs needs		     */
	fileops_t	*f_ops;		/* operations vector		     */
	
	caddr_t		f_parentp;	/* the file's parent vnode or fid    */
	caddr_t		f_fnamep;	/* fname pointer, may be embedded    */
	char		f_fdata[F_FDATASZ];/* embedded file data, pad to 256 */
};

/* f_type values */
#define	DTYPE_VNODE	1	/* file */
#define	DTYPE_SOCKET	2	/* communications endpoint */
#define	DTYPE_GNODE	3	/* device */
#define	DTYPE_RTSHM	4	/* posix rt shm */
#define	DTYPE_IOCP	5	/* iocp completion port */
#define	DTYPE_SMSOCK	15	/* shared memory transport socket */
#define	DTYPE_OTHER    -1	/* unknown */

/* defines for f_options -- file flags that don't need to be
 * passed through the vnode layer
 */
#define FAIO		0x0001		/* aio on this fp		*/
#define GCFMARK		0x0002		/* mark during unp_gc()		*/
#define GCFDEFER	0x0004		/* defer during unp_gc()	*/
#define FREVOKED	0x0008		/* file access has been revoked	*/
#define FAIO_FPATH	0x0010		/* Send down aio fast path	*/
#define FAIO_KPROC	0x0020		/* Send aio request to kproc	*/
#define FAIO_FSFP	0x0040		/* Send down aio fs fast path	*/
#define FAIO_FPVPATH	0x0080		/* fast path aio to PV          */
#define FLDR_SHMAT	0x0100
#define FOBIT9		0x0200
#define FOBIT10		0x0400
#define FOBIT11		0x0800
#define FOBIT12		0x1000
#define FOBIT13		0x2000
#define FOBIT14		0x4000
#define FZOMBIE         0x8000          /* fp is dead but not yet free  */

#ifdef __64BIT_KERNEL
extern struct file *file;	/* The file table itself */
#else
extern struct file file[];	/* The file table itself */
#endif /* __64BIT_KERNEL */
extern struct file *ffreelist;	/* Head of freelist pool */
extern Simple_lock ffree_lock;	/* File Table Free List Lock */
#endif /* _KERNEL */

/*
 * Flock call.
 */
#define	LOCK_SH		1	/* shared lock */
#define	LOCK_EX		2	/* exclusive lock */
#define	LOCK_NB		4	/* don't block when locking */
#define	LOCK_UN		8	/* unlock */

/*
 * Lseek call.
 */
#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
/* Definitions for named opens */
struct named_open_args {
	int		no_magic;	/* Magic number */
	struct vnode	*no_dvp;	/* Directory vnode */
	char		*no_path;	/* (full) Path name */
};
#define NAMED_OPEN_MAGIC 0x1badd00d
#endif

#ifdef _NO_PROTO
extern int flock();
#else
extern int flock(int,int);
#endif /*_NO_PROTO*/

#ifdef __cplusplus
}
#endif



#endif /* _H_FILE */
