/* Ported to GNU C openVMS/Alpha by Klaus Kämpf, kkaempf@progis.de  */
/* <xabprodef.h>
 *
 *	RMS file protection XAB definitions
 */
#ifndef _XABPRODEF_H
#define _XABPRODEF_H

#ifdef __cplusplus
extern "C" {
#endif

#define XAB$C_PRO	19	/* xabpro ID code */
/* protection bit mask values */
#define XAB$V_SYS	0	/* system */
#define XAB$S_SYS	4
#define XAB$M_SYS	0x000F
#define XAB$V_OWN	4	/* owner */
#define XAB$S_OWN	4
#define XAB$M_OWN	0x00F0
#define XAB$V_GRP	8	/* group */
#define XAB$S_GRP	4
#define XAB$M_GRP	0x0F00
#define XAB$V_WLD	12	/* world */
#define XAB$S_WLD	4
#define XAB$M_WLD	0xF000
#define XAB$V_NOREAD	0
#define XAB$V_NOWRITE	1
#define XAB$V_NOEXE	2
#define XAB$V_NODEL	3
#define XAB$M_NOREAD	(1<<XAB$V_NOREAD)	/* 0x01 */
#define XAB$M_NOWRITE	(1<<XAB$V_NOWRITE)	/* 0x02 */
#define XAB$M_NOEXE	(1<<XAB$V_NOEXE)	/* 0x04 */
#define XAB$M_NODEL	(1<<XAB$V_NODEL)	/* 0x08 */
/* protection options (PROT_OPT) bit mask values */
#define XAB$V_PROPAGATE 0
#define XAB$M_PROPAGATE (1<<XAB$V_PROPAGATE)	/* 0x01 */
/* miscellaneous constants */
#define XAB$K_PROLEN_V3 16	/* V3a xabpro length */
#define XAB$C_PROLEN_V3 16
#define XAB$K_PROLEN	88	/* xabpro length */
#define XAB$C_PROLEN	88

#ifndef __XABSTART_FIELDS
#include <vms/xabdef.h>
#endif

#ifdef __ALPHA
#define XABPRO xabprodef1
#else
struct XABPRO {
  __XABSTART_FIELDS
    unsigned short xab$w_pro;		/* protection mask */
    unsigned char  xab$b_mtacc;		/* magtape access control char. */
    unsigned char  xab$b_prot_opt;	/* XABPRO options field */
    unsigned long  xab$l_uic;		/* uic code */
    unsigned long  xab$q_prot_mode[2];	/* protection mode */
    void	  *xab$l_aclbuf;	/* address of user's ACL buffer */
    unsigned short xab$w_aclsiz;	/* size of user's ACL buffer */
    unsigned short xab$w_acllen;	/* return length of entire ACL */
    unsigned long  xab$l_aclctx;	/* ACL context field */
    unsigned long  xab$l_aclsts;	/* ACL return err status */
	unsigned : 32, : 32, : 32, : 32, : 32, : 32,	/* spare */
		 : 32, : 32, : 32, : 32, : 32, : 32;	/*long[12]*/
} __attribute__ ((packed));
#endif

#ifdef __ALPHA
struct  _xabprodef {
  unsigned char xab$v_noread  : 1;	/* deny read  */
  unsigned char xab$v_nowrite : 1;	/* deny write  */
  unsigned char xab$v_noexe   : 1;	/* deny execution  */
  unsigned char xab$v_nodel   : 1;	/* deny deletion  */
  unsigned char		      : 1;
} __attribute__ ((packed));
struct xabprodef1 {
#else
struct xabprodef {
#endif
  __XABSTART_FIELDS
    union {
	unsigned short xab$w_pro;	/* protection mask */
#define xab$w_pro xab$r_pro_overlay.xab$w_pro
	struct {
	    unsigned short xab$v_sys : 4; /* system */
	    unsigned short xab$v_own : 4; /* owner */
	    unsigned short xab$v_grp : 4; /* group */
	    unsigned short xab$v_wld : 4; /* world */
	} xab$r_pro_bits;
#define xab$v_sys xab$r_pro_overlay.xab$r_pro_bits.xab$v_sys
#define xab$v_own xab$r_pro_overlay.xab$r_pro_bits.xab$v_own
#define xab$v_grp xab$r_pro_overlay.xab$r_pro_bits.xab$v_grp
#define xab$v_wld xab$r_pro_overlay.xab$r_pro_bits.xab$v_wld
    } xab$r_pro_overlay;
    unsigned char xab$b_mtacc;		/* magtape access control char. */
    union {
	unsigned char xab$b_prot_opt;	/* XABPRO options field */
#define xab$b_prot_opt xab$r_prot_opt_overlay.xab$b_prot_opt
	struct {
	    unsigned char xab$v_propagate : 1; /* Propagate security attributes on $ENTER and $RENAME */
	    unsigned char		  : 7;
	} xab$r_prot_opt_fields;
#define xab$v_propagate xab$r_prot_opt_overlay.xab$r_prot_opt_fields.xab$v_propagate
    } xab$r_prot_opt_overlay;
    union {
	unsigned long xab$l_uic;	/* uic code */
#define xab$l_uic xab$r_uic_overlay.xab$l_uic
	struct {
	    unsigned short xab$w_mbm;	/* member code */
	    unsigned short xab$w_grp;	/* group code */
	} xab$r_uic_fields;
#define xab$w_mbm xab$r_uic_overlay.xab$r_uic_fields.xab$w_mbm
#define xab$w_grp xab$r_uic_overlay.xab$r_uic_fields.xab$w_grp
    } xab$r_uic_overlay;
    union {				/* RWED/mode protection for file */
	unsigned long xab$q_prot_mode[2]; /* eventually may be a quadword */
#define xab$q_prot_mode xab$r_prot_mode_overlay.xab$q_prot_mode
	struct {			  /* but currently only a byte	  */
	    unsigned char xab$b_prot_mode;
	} xab$r_prot_mode_fields;
#define xab$b_prot_mode xab$r_prot_mode_overlay.xab$r_prot_mode_fields.xab$b_prot_mode
    } xab$r_prot_mode_overlay;
    void *xab$l_aclbuf;			/* address of user's ACL buffer */
    unsigned short xab$w_aclsiz;	/* size of user's ACL buffer */
    unsigned short xab$w_acllen;	/* return length of entire ACL */
    unsigned long xab$l_aclctx;		/* ACL context field */
    unsigned long xab$l_aclsts;		/* ACL return err status */
    unsigned	: 32, : 32, : 32, : 32, /* long fill1, fill2, ...; spare */
		: 32, : 32, : 32, : 32,
		: 32, : 32, : 32, : 32;
} __attribute__ ((packed));

/* declare initialized prototype data structure */
#ifdef __ALPHA
extern struct XABPRO *cc$rms_xabpro_ptr __asm("DECC$GA_RMS_XABPRO");
#define cc$rms_xabpro (*cc$rms_xabpro_ptr)
#else
extern struct XABPRO cc$rms_xabpro __asm("_$$PsectAttributes_GLOBALSYMBOL$$cc$rms_xabpro");
/* globalref struct XABPRO cc$rms_xabpro; */
#endif

#ifdef __cplusplus
  }
#endif

#endif	/*_XABPRODEF_H*/
