/*	@(#)file.h	13.3 (RC International) 91/06/28	*/

#ifndef _FILE_H
#define _FILE_H

#include <sys/types.h>


/*
 * flags - also for fcntl call
 */
#define	FOPEN		(-1)
#define	FREAD		0x000001	/* descriptor read/receive'able */
#define	FWRITE		0x000002	/* descriptor write/send'able */
#define	FNDELAY		0x000004	/* no delay */
#define	FAPPEND		0x000008	/* append on each write */
#define	FMARK		0x000010	/* mark during gc() */
#define	FDEFER		0x000020	/* defer for next gc pass */
#define	FASYNC		0x000040	/* signal pgrp when data ready */
#define	FSHLOCK		0x000080	/* shared lock present */
#define	FEXLOCK		0x000100	/* exclusive lock present */
#define FCONTROL	0x001000	/* open with controlled I/O */
#define FDETACH		0x002000	/* ipc open and detach */


#define	FSYNC		0x008000	/* make writes synchronous */
#define FRDLOG		0x400000	/* read log from a logical volume */

/* bits to save after open */
#define	FMASK		(FREAD|FWRITE|FNDELAY|FAPPEND|FASYNC|FCONTROL| \
			 FSHLOCK|FEXLOCK|FRDLOG|FSYNC)
/* bits not changeable by fcntl */
#define	FCNTLCANT	(FREAD|FWRITE|FMARK|FDEFER|FSHLOCK|FEXLOCK|FCONTROL| \
			 FDETACH|FRDLOG)

/* open only modes */
#define	FCREAT		0x000200	/* create if nonexistant */
#define	FTRUNC		0x000400	/* truncate to zero length */
#define	FEXCL		0x000800	/* error if already created */
#define	FUNLINK		0x004000	/* unlink before open if exists */

/*
 * User definitions
 */

/* fcntl(2) requests--from <fcntl.h> */
#define	F_DUPFD	0			/* Duplicate fildes */
#define	F_GETFD	1			/* Get fildes flags */
#define	F_SETFD	2			/* Set fildes flags */
#define	F_GETFL	3			/* Get file flags */
#define	F_SETFL	4			/* Set file flags */
#define	F_GETOWN 5			/* Get owner */
#define F_SETOWN 6			/* Set owner */
/* Byte Level Locking */
#define	F_GETLK	 101			/* Get file lock */
#define	F_SETLK	 102			/* Set file lock */
#define	F_SETLKW 103			/* Set file lock and wait */

/* constant for F_SETFD fcntl */
#define	FD_CLOEXEC  0x1			/* Close fp upon exec */
				/* MUST be same as UF_EXCLOSE in user.h */

/* Byte Level Locking */
#define	F_RDLCK	0			/* Read lock */
#define	F_WRLCK	1			/* Write lock */
#define	F_UNLCK	2			/* Remove lock(s) */

/* Byte Level Locking */
/* Lock structure for F_GETLK and F_SETLK */
struct flock
{
	short	l_type;			/* type of lock: */
	short	l_whence;		/* flag to choose starting offset */
	off_t	l_start;		/* relative offset in bytes */
	off_t	l_len;			/* if 0 then until EOF */
	pid_t	l_pid;			/* returned with F_GETLK */
};

/*
 * Open() and fcntl() call
 */
#define	O_RDONLY	0x00		/* open for reading */
#define	O_WRONLY	0x01		/* open for writing */
#define	O_RDWR		0x02		/* open for read & write */
#define O_ACCMODE   	0x03		/* Mask for file access mode */
#define	O_NDELAY	FNDELAY		/* non-blocking open */
#define O_NONBLOCK  	FNDELAY		/* Non-blocking mode */
#define	O_APPEND	FAPPEND		/* append on each write */
#define	O_CREAT		FCREAT		/* create before open */
#define	O_UNLINK	FUNLINK		/* rm before open (implies create) */
#define	O_TRUNC		FTRUNC		/* open with truncation */
#define	O_EXCL		FEXCL		/* error on create if file exists */
#define	O_SYNC		FSYNC		/* write synchronously */
#define O_NOCTTY	0x2000000	/* Do not assign controlling tty */

#define O_MESSAGE	0x020000	/* message (non-stream) IPC */
#define O_FORCEOPEN	0x040000	/* complete open even if no match */
#define O_MXIPC		0x080000	/* creat only: make an mxipc endpoint */

#define O_PEER		0x100000	/* IPC peer process */
#define O_CLIENT	0x200000	/* IPC client process */
#define O_SERVER	0x300000	/* IPC server process */

#define O_RDLOG		FRDLOG		/* read log from a logical volume */

#define O_CSP		(O_PEER|O_CLIENT|O_SERVER)
#define O_TXIPC		(O_PEER|O_CLIENT|O_SERVER|O_MESSAGE)

#define	O_EXLOCK	FEXLOCK		/* apply exclusive lock */
#define	O_SHLOCK	FSHLOCK		/* apply shared lock */
#define	O_CONTROL	FCONTROL	/* open with controlled I/O */
#define O_DETACH	FDETACH		/* ipc open and detach */

#define CREATEFILE_VERSION	1	/* version of params struct  */
struct createfile_params
{
    int		cfp_version;		/* version of params struct */
    int		cfp_user;		/* user  id for new file (or -1) */
    int		cfp_group;		/* group id for new file (or -1) */
    int		cfp_ptier;		/* prim. extent size in bytes (or -1) */
    int		cfp_stier;		/* sec.  extent size in bytes (or -1) */
    int		cfp_mode;		/* permissions, ISECURE, etc (NOT -1) */
    int		cfp_spare[4];		/* spare */
};

/*
 * Read() and Write() calls
 */
#define IO_NBLOCK	0x00020000	/* non-blocking operation */
#define IO_NOSIGERR	0x00040000	/* no SIGERR signal */
#define IO_NOSIGABORT	0x00080000	/* no SIGABORT signal */
#define IO_MBLOCKX	0x00100000	/* read with intent write X lock */
#define IO_MBLOCKS	0x00200000	/* read with manual block shared 
					   lock */
#define	IO_NOERROR	0x00400000	/* truncate data if not large enough */
#define IO_MBLOCKH	0x00800000	/* read/write with manual block hold 
					   lock */
#define IO_WINTENT	IO_MBLOCKX	/* alias */
#define IO_MBLOCK	IO_MBLOCKS	/* alias */
#define	IO_MXTRINVITE	0x01000000	/* mxipc transaction invitation */
#define IO_SIGERR	0x02000000	/* SIGERR signal */

/*
 * 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 */
#define LOCK_UNALL	16	/* unlock all locks on a file */
#define	LOCK_HO		32	/* hold lock */
#define LOCK_FIND	64	/* System V byte lock search op */

#define MAX_LOCK_OFFSET	2147483647	/* 2**31 - 1 */

/*
 * Access() call
 */
#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 /* R_OK */

/*
 * Lseek() call
 * For backwards compatibility.
 * The constants in unistd.h should be used for new programs.
 */
#define	L_SET		0	/* absolute offset */
#define	L_INCR		1	/* relative to current offset */
#define	L_XTND		2	/* relative to end of file */


/*
 * Structure for setext() call
 */
struct	extent_descriptor
{
    int		primary;	/* size of primary extent */
    int		secondary;	/* size of secondary extents */
};

#endif /* _FILE_H */
