/* <vms/lib/wcbdef.h>
 *
 *	LIB - window control block definitions		[not in Starlet]
 */
#ifndef _WCBDEF_H
#define _WCBDEF_H

/*
   There is a window control block for each file accessed by a process.
   It contains mapping information such that a large percentage of virtual
   file I/O can be mapped from virtual to logical block numbers without
   having to read the respective file header.
 */
#define WCB$V_READ	0
#define WCB$V_WRITE	1
#define WCB$V_NOTFCP	2
#define WCB$V_SHRWCB	3
#define WCB$V_OVERDRAWN 4
#define WCB$V_COMPLETE	5
#define WCB$V_CATHEDRAL 6
#define WCB$V_EXPIRE	7
#define WCB$M_READ	(1<<WCB$V_READ)		/* 0x01 */
#define WCB$M_WRITE	(1<<WCB$V_WRITE)	/* 0x02 */
#define WCB$M_NOTFCP	(1<<WCB$V_NOTFCP)	/* 0x04 */
#define WCB$M_SHRWCB	(1<<WCB$V_SHRWCB)	/* 0x08 */
#define WCB$M_OVERDRAWN (1<<WCB$V_OVERDRAWN)	/* 0x10 */
#define WCB$M_COMPLETE	(1<<WCB$V_COMPLETE)	/* 0x20 */
#define WCB$M_CATHEDRAL (1<<WCB$V_CATHEDRAL)	/* 0x40 */
#define WCB$M_EXPIRE	(1<<WCB$V_EXPIRE)	/* 0x80 */
#define WCB$V_NOWRITE		0
#define WCB$V_DLOCK		1
#define WCB$V_SPOOL		4
#define WCB$V_WRITECK		5
#define WCB$V_SEQONLY		6
#define WCB$V_SNAPSHOT		7
#define WCB$V_WRITEAC		8
#define WCB$V_READCK		9
#define WCB$V_NOREAD		10
#define WCB$V_NOTRUNC		11
#define WCB$V_CONTROL		12
#define WCB$V_NO_READ_DATA	13
#define WCB$M_NOWRITE		(1<<WCB$V_NOWRITE)	/* 0x01 */
#define WCB$M_DLOCK		(1<<WCB$V_DLOCK)	/* 0x02 */
#define WCB$M_SPOOL		(1<<WCB$V_SPOOL)	/* 0x10 */
#define WCB$M_WRITECK		(1<<WCB$V_WRITECK)	/* 0x20 */
#define WCB$M_SEQONLY		(1<<WCB$V_SEQONLY)	/* 0x40 */
#define WCB$M_SNAPSHOT		(1<<WCB$V_SNAPSHOT)	/* 0x80 */
#define WCB$M_WRITEAC		(1<<WCB$V_WRITEAC)	/* 0x0100 */
#define WCB$M_READCK		(1<<WCB$V_READCK)	/* 0x0200 */
#define WCB$M_NOREAD		(1<<WCB$V_NOREAD)	/* 0x0400 */
#define WCB$M_NOTRUNC		(1<<WCB$V_NOTRUNC)	/* 0x0800 */
#define WCB$M_CONTROL		(1<<WCB$V_CONTROL)	/* 0x1000 */
#define WCB$M_NO_READ_DATA	(1<<WCB$V_NO_READ_DATA) /* 0x2000 */
#define WCB$V_NOACCLOCK		2
#define WCB$V_READINIT		11
#define WCB$V_WRITE_TURN	12
#define WCB$M_NOACCLOCK		(1<<WCB$V_NOACCLOCK)	/* 0x04 */
#define WCB$M_READINIT		(1<<WCB$V_READINIT)	/* 0x0800 */
#define WCB$M_WRITE_TURN	(1<<WCB$V_WRITE_TURN)	/* 0x1000 */

#define WCB$K_MAP	48	/* map pointers start here */
#define WCB$C_MAP	48
#define WCB$K_LENGTH	48	/* length of standard WCB sans pointers */
#define WCB$C_LENGTH	48
#ifndef NO_VMS_V6
#define WCB$S_WCBDEF	72
#else
#define WCB$S_WCBDEF	60
#endif
struct wcbdef {
    unsigned long wcb$l_wlfl;		/* window list forward link */
    unsigned long wcb$l_wlbl;		/* window list backward link */
    unsigned short wcb$w_size;		/* size of window block in bytes */
    unsigned char wcb$b_type;		/* structure type of WCB */
    union {
	unsigned char wcb$b_access;	/* access control byte */
	struct {
	    unsigned wcb$v_read      : 1; /* read access allowed (1=yes) */
	    unsigned wcb$v_write     : 1; /* write access allowed (1=yes) */
	    unsigned wcb$v_notfcp    : 1; /* file not accessed by FCP if set */
	    unsigned wcb$v_shrwcb    : 1; /* shared window */
	    unsigned wcb$v_overdrawn : 1; /* file accessor has overdrawn his quota */
	    unsigned wcb$v_complete  : 1; /* set window maps entire file */
	    unsigned wcb$v_cathedral : 1; /* large, complex window (sic) to map file completely */
	    unsigned wcb$v_expire    : 1; /* file expiration date may need to be set */
	} wcb$r_access_bits;
    } wcb$r_access_overlay;
    union {
	unsigned long wcb$l_pid;	/* process ID of accessor process */
	struct {
	    unsigned	: 8, : 8;
	    unsigned short wcb$w_refcnt; /* reference count for shared window */
	} wcb$r_pid_fields;
    } wcb$r_pid_overlay;
    unsigned long wcb$l_orgucb;		/* address of original UCB from CCB */
    union {
	unsigned short wcb$w_acon;	/* access control information */
	struct {	/* note - these bits track the bits in FIB$L_ACCTL */
	    unsigned wcb$v_nowrite  : 1;	/* no other writers */
	    unsigned wcb$v_dlock    : 1;	/* enable deaccess lock */
	    unsigned		    : 2;
	    unsigned wcb$v_spool    : 1;	/* spool file on close */
	    unsigned wcb$v_writeck  : 1;	/* enable write check */
	    unsigned wcb$v_seqonly  : 1;	/* sequential only access */
	    unsigned wcb$v_snapshot : 1;	/* snapshot revalidation pending */
	    unsigned wcb$v_writeac  : 1;	/* write access */
	    unsigned wcb$v_readck   : 1;	/* enable read check */
	    unsigned wcb$v_noread   : 1;	/* no other readers */
	    unsigned wcb$v_notrunc  : 1;	/* no truncates */
	    unsigned wcb$v_control  : 1;	/* control access to file */
	    unsigned wcb$v_no_read_data : 1;	/* no read access to file data */
	    unsigned		    : 2;
	} wcb$r_acon_bits0;
	struct {
	    unsigned			: 2;
 /* the following field overlays the first unused flag in WCB$W_ACON above */
	    unsigned wcb$v_noacclock	: 1;	/* no access lock checking */
	    unsigned			: 8;
	    unsigned wcb$v_readinit	: 1;	/* a readinit was done over this channel */
	    unsigned wcb$v_write_turn	: 1;	/* force window turn on writes */
	    unsigned			: 3;
	} wcb$r_acon_bits1;
    } wcb$r_acon_overlay;
 /* size device independent part of WCB */
    unsigned short wcb$w_nmap;		/* number of mapping pointers */
    unsigned long wcb$l_fcb;		/* address of FCB */
    unsigned long wcb$l_rvt;		/* address of relative volume table */
    unsigned long wcb$l_link;		/* link to next window segment */
    unsigned long wcb$l_reads;		/* count of reads performed */
    unsigned long wcb$l_writes;		/* count of writes performed */
    unsigned long wcb$l_stvbn;		/* starting VBN mapped by window */
 /* note that virtual mapping needs P1_COUNT immediately following STVBN */
#ifndef NO_VMS_V6
    unsigned long wcb$l_p1_count;	/* count field of first pointer */
    unsigned long wcb$l_p1_lbn;		/* LBN field of first pointer */
    unsigned char wcb$b_p1_rvn;		/* RVN field of first pointer */
    unsigned	: 24;			/* padding */
    unsigned long wcb$l_p2_count;	/* count field of second pointer */
    unsigned long wcb$l_p2_lbn;		/* LBN field of second pointer */
    unsigned char wcb$b_p2_rvn;		/* RVN field of second pointer */
    unsigned	: 24;			/* padding */
#else
    unsigned short wcb$w_p1_count;	/* count field of first pointer */
    unsigned long wcb$l_p1_lbn;		/* LBN field of second pointer */
    unsigned short wcb$w_p2_count;	/* count field of second pointer */
    unsigned long wcb$l_p2_lbn;		/* LBN field of first pointer */
#endif
};

/* format of retrieval pointer */
#ifndef NO_VMS_V6
#define WCB$K_MAP_PTR_LENGTH 12
#define WCB$C_MAP_PTR_LENGTH 12
#define WCB$S_WCBDEF1	12
struct wcbdef1 {
    unsigned long wcb$l_count;		/* count field */
    unsigned long wcb$l_lbn;		/* LBN field */
    unsigned char wcb$b_rvn;		/* RVN field */
    unsigned	: 24;			/* padding */
};
#define WCB$S_WCBDEF2	13
struct wcbdef2 {	/* note: origin has offset of -12 */
    unsigned long wcb$l_prevcount;	/* previous retrieval pointer count */
    unsigned long wcb$l_prevlbn;	/* previous retrieval pointer lbn */
    unsigned char wcb$b_prevrvn;	/* previous retrieval pointer RVN */
    unsigned	: 24;			/* padding */
    unsigned	: 8;			/* retrieval pointer format */
};
#else
#define WCB$S_WCBDEF1	6
struct wcbdef1 {
    unsigned short wcb$w_count;		/* count field */
    unsigned long wcb$l_lbn;		/* LBN field */
};
#define WCB$S_WCBDEF2	7
struct wcbdef2 {	/* note: origin has offset of -6 */
    unsigned short wcb$w_prevcount;	/* previous retrieval pointer */
    unsigned long wcb$l_prevlbn;
    unsigned	: 8;			/* retrieval pointer format */
};
#endif

#endif	/*_WCBDEF_H*/
