/* IBM_PROLOG_BEGIN_TAG                                                   */
/* This is an automatically generated prolog.                             */
/*                                                                        */
/* bos72Q src/bos/kernel/sys/ahafs_evProds.h 1.3.2.4                      */
/*                                                                        */
/* Licensed Materials - Property of IBM                                   */
/*                                                                        */
/* Restricted Materials of IBM                                            */
/*                                                                        */
/* COPYRIGHT International Business Machines Corp. 2008,2019              */
/* 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                                                     */
/* static char sccsid[] = "@(#)50  1.3.2.4  src/bos/kernel/sys/ahafs_evProds.h, sysxahafs, bos72Q, q2019_13A4 2/6/19 00:41:19"; */
#ifndef _H_AHAFS_EVPRODS
#define _H_AHAFS_EVPRODS

#include <sys/types.h>
#include <sys/lockl.h>
#include <sys/user.h>
#include <sys/dir.h>

#ifdef __cplusplus
extern "C" {
#endif

/* Maximum size of the evProd name */
#define AHAFS_EVPROD_NAME_MAXSZ        47

typedef struct _ahafs_cbFn_info
{
    int          cb_version;     /* Version of the structure*/
#define   AHAFS_CBFN_INFO_VERSION  3

    int          cb_flag;        /* Flag indicating what type
				  * of event has occurred.  If 
				  * non-zero, a special event
				  * has occurred */
    char         cb_name[AHAFS_EVPROD_NAME_MAXSZ+1];
				 /* evProd name including 
				  * '\0' */
    int          cb_evProdId;    /* Id of the event producer */
    uint64_t     cb_curValue;    /* Current value of the event 
				  * as returned by the event 
				  * producer */
    int		 cb_rc;		 /* Return code to pass from
				  * the event producer to the
				  * consumer */
    uint64_t     cb_opqId;       /* Unique identifier of the event */
    uint64_t	 cb_evGid;	 /* Event group ID */
    struct ucred *cb_crp;        /* Credential of the process which
				  * triggered the event */
    char	 *cb_msg;	 /* Message from event producer. */
    int		 cb_msg_len;	 /* Length of string pointed to by
				  * cb_msg, including \0 */
#define   AHAFS_MAX_CB_MSG_LEN    512 /* Maximum value of cb_msg_len*/

    uint32_t : 32;               /* Reserved fields */
    uint32_t : 32;
    uint32_t : 32;
    uint32_t : 32;
    uint32_t : 32;
    uint32_t : 32;
    uint32_t : 32;
    uint32_t : 32;
}ahafs_cbFn_info_t;

/* The flag could have the following values */
#define  AHAFS_GROUP_UNAVAILABLE   0x001  /* A group of events is no longer 
				           * available */
#define  AHAFS_EVENT_UNAVAILABLE   0x002  /* The specified event is no longer 
				           * available */
#define  AHAFS_EVPROD_AVAILABLE    0x004  /* An Event Producer is available.*/
#define  AHAFS_EVPROD_UNAVAILABLE  0x008  /* Event Producer is unavailable.*/
#define  AHAFS_REMOTE_EVENT        0x010  /* Remote event */
#define  AHAFS_SEND_EVENT	   0x020  /* Event should be propagated */

typedef struct _send_packet_info
{
	int          sp_version;        /* Version */
#define   AHAFS_SEND_PACKET_VERSION    1

	char         sp_evProdName[AHAFS_EVPROD_NAME_MAXSZ + 1];
				        /* name of event producer*/	
	char         sp_name[MAXPATHLEN];/* pathname of the event */
	int          sp_evProdId;       /* Id of the event producer */
	uint64_t     sp_curValue;       /* current value */
	int          sp_rc_evp;         /* reason code */	
	char	     sp_msg[512];	 /* Message from event producer. */
} _send_packet_info_t;

/* Return codes from event producers must not overlap with error
 * codes defined in sys/errno.h.  These values are reserved for
 * AHAFS to indicate errors encountered in registering / creating
 * new events
 */

/* utilFs return codes */
#define   AHAFS_UTILFS_THRESH_HIT       1000
#define   AHAFS_UTILFS_UNMOUNT          1001

/* modFile return codes */
#define AHAFS_MODFILE_WRITE             1000
#define AHAFS_MODFILE_UNMOUNT           1001
#define AHAFS_MODFILE_MAP               1002
#define AHAFS_MODFILE_REMOVE            1003
#define AHAFS_MODFILE_RENAME            1004
#define AHAFS_MODFILE_FCLEAR            1005
#define AHAFS_MODFILE_FTRUNC            1006
#define AHAFS_MODFILE_OVERMOUNT         1007

/* modDir return codes */
#define AHAFS_MODDIR_CREATE		1000
#define AHAFS_MODDIR_UNMOUNT		1001
#define AHAFS_MODDIR_REMOVE		1002
#define AHAFS_MODDIR_REMOVE_SELF	1003
#define AHAFS_MODDIR_OVERMOUNT		AHAFS_MODFILE_OVERMOUNT

/* modFileAttr return codes */
#define AHAFS_MODFILEATTR_UNMOUNT       AHAFS_MODFILE_UNMOUNT
#define AHAFS_MODFILEATTR_REMOVE        AHAFS_MODFILE_REMOVE
#define AHAFS_MODFILEATTR_RENAME        AHAFS_MODFILE_RENAME
#define AHAFS_MODFILEATTR_OVERMOUNT     AHAFS_MODFILE_OVERMOUNT
#define AHAFS_MODFILEATTR_SETACL        1008
#define AHAFS_MODFILEATTR_SETOWN        1009
#define AHAFS_MODFILEATTR_SETMODE       1010

/* Return code for rmcluster */
#define AHAFS_CLUSTER_REMOVE          -1

typedef struct _ahafs_evProd_info
{
    int   evp_version;      /* Version of the structure */
#define AHAFS_EVPROD_INFO_VERSION     3

    int   evp_id;        /* Id of the event producer.  This ID
			  * is generated by the kernel at event
			  * producer registration time */

    int   evp_size;      /* Maximum number of events that can 
			  * be monitored at one time by this 
			  * event producer.  Specified by the
			  * event producer at registration */
    int   evp_caps;      /* Capabilities of the event producer.
			  * Provided by the event producer at
			  * registration time */

    char  evp_name[AHAFS_EVPROD_NAME_MAXSZ + 1]; 
                       	 /* Name of the event producer.  Specified
			  * by the event producer at registration */ 
					   
    char evp_dirName[_D_NAME_MAX + 1];
		 	 /* Optional name of the directory which
		          * should exist between the root of AHAFS
			  * and the monitor factory for this
			  * event producer.  Specified by the event
			  * producer at registration time.  If the
			  * monitor factory should be directly under
			  * the root of the AHAFS filesystem, this
			  * string should just be '\0' */
    kerrno_t (*evp_func)();  
			 /* Handler function provided by an
                          * event producer at registration.  See
			  * description of the ahafs_evMon_info_t
			  * structure for more information on this
			  * function */
    uint32_t : 32;       /* Reserved fields */
    uint32_t : 32;
    uint32_t : 32;
    uint32_t : 32;
    uint32_t : 32;
    uint32_t : 32;
    uint32_t : 32;
    uint32_t : 32;
} ahafs_evProd_info_t;

/* Event Producer can have one or more of the following capabilities
 * The AHAFS_THRESHOLD_STATE capability should not be specified if one
 * or more of the AHAFS_THRESHOLD_VALUE capabilities is specified.
 */

/* The event producer monitors for a state change */
#define AHAFS_THRESHOLD_STATE          0x0001 

/* The event producer monitors for a value to go beneath a given 
 * threshold */
#define AHAFS_THRESHOLD_VALUE_LOW      0x0002

/* The event producer monitors for a value to exceed a given 
 * threshold */
#define AHAFS_THRESHOLD_VALUE_HIGH     0x0004

/* The event producer monitors for a value exceeding a given high
 * threshold or going beneath a given low threshold */
#define AHAFS_THRESHOLD_VALUE  (AHAFS_THRESHOLD_VALUE_LOW   | \
                                AHAFS_THRESHOLD_VALUE_HIGH)


/* The following capabilities may be used in combination with
 * the above threshold types */

/* A stack trace should be taken when an event occurs for this
 * event producer */
#define AHAFS_STKTRACE_AVAILABLE       0x0008

/* This event producer may produce and event in the interrupt 
 * environment */
#define AHAFS_CALLBACK_INTRCNTX        0x0010

#define AHAFS_REMOTE_EVENT_ENABLED     0x0020


/* The handler function evp_func() has the following 2 parameters
 * to handle enable/disable/check access, etc. for its events.
 *  1) int cmd;
 *           where cmd can have one of the following values:
 *                 AHAFS_EVMON_ENABLE
 *                 AHAFS_EVMON_DISABLE
 *                 AHAFS_EVMON_DISABLE_ALL
 *                 AHAFS_EVMON_CHK_ACCESS
 *                 AHAFS_EVMON_GET_ID.
 *
 *  2) ahafs_evMon_info_t * evMonInfo;
 */

typedef struct _ahafs_evMon_info
{
    int       evm_version;       /* Version of the structure */
#define AHAFS_EVMON_INFO_VERSION     3
    int       evm_evProdId;      /* Id of the event producer which
				  * was generated at event producer
				  * registration time. */
    char      evm_pathName[MAXPATHLEN];
				/* Path name of the event relative
				 * to the monitor factory corresponding
				 * with the event producer ID in
				 * evm_evProdId, including '\0'.
				 * E.g. /etc/passwd */
    int	      evm_threshType;   /* Which threshold is being updated
				 * or set in this ENABLE call.  Event
				 * producers who may have negative
				 * values in either threshold type
				 * must use this field in determining
				 * which threshold to update */
    uint64_t  evm_thresholdLo;  /* Low threshold to be monitored.
				 * Passed from AHAFS to the event 
				 * producer */
    uint64_t  evm_thresholdHi;  /* High threshold to be monitored.
                                 * Passed from AHAFS to the event
                                 * producer */
    uint64_t  evm_opqId;        /* Unique ID of the event, generated
				 * by the event producer at event 
				 * registration time. */
    uint64_t  evm_digest;       /* Digest generated by event producer */
    uint64_t  evm_evGid;	/* Group ID of event generated by event 
				 * producer at event registration */
    uint64_t  evm_curValue;     /* Current value reported by the event
				 * producer */
    uint32_t : 32;              /* Reserved fields */
    uint32_t : 32;
    uint32_t : 32;
    uint32_t : 32;
    uint32_t : 32;
    uint32_t : 32;
    uint32_t : 32;
    uint32_t : 32;
} ahafs_evMon_info_t;

/* Values for evm_threshType */
#define AHAFS_THRESH_HI	   	0x01
#define AHAFS_THRESH_LO	   	0x02
#define AHAFS_THRESH_INVALID	0x04

kerrno_t
ahafs_evprods      /* The single unified kernel service for AHAFS */
(
   ulong  cmd,     
   void   *buf,   
   size_t *bufSz 
);

/* Defined commands for ahafs_evprods are as follows */
#define AHAFS_CBFN_REG              1   /* Called by AHAFS kernel extension */
#define AHAFS_EVPRODS_GET_LIST      2   /* Called by AHAFS kernel extension */
#define AHAFS_EVPROD_GET_INFO       3   /* Called by AHAFS kernel extension */
#define AHAFS_EVMON_CHK_ACCESS      4   /* Called by AHAFS kernel extension */
#define AHAFS_EVMON_CHK_THRESH      5   /* Called by AHAFS kernel extension */
#define AHAFS_EVMON_GET_ID          6   /* Called by AHAFS kernel extension */
#define AHAFS_EVMON_ENABLE          7   /* Called by AHAFS kernel extension */
#define AHAFS_EVMON_DISABLE         8   /* Called by AHAFS kernel extension */
#define AHAFS_EVMON_DISABLE_ALL     9   /* Called by AHAFS kernel extension */ 
#define AHAFS_EVPROD_REG           10   /* Called by event producers */
#define AHAFS_EVPROD_UNREG         11   /* Called by event producers */
#define AHAFS_EVPROD_CALLBACK      12   /* Called by event producers */ 

typedef struct _ahafs_curThrd_info
{
    int       cth_version;             /* Version of the structure */
#define AHAFS_CURTHRD_INFO_VERSION     1
    ureg_t    cth_ustackp;             /* Addr of user stack */
    ureg_t    cth_kstackp;             /* Addr of kernel stack */
    ureg_t    cth_scsave_lr;           /* Link register at the time of 
				  	* calling syscall */
    ureg_t    sys_call_ret_symaddr;    /* Address of the symbol sys_call_ret*/
    char      cth_execName[MAXCOMLEN + 1]; 
				       /* NULL terminated program name */
} ahafs_curThrd_info_t;

kerrno_t
ahafs_get_curthrd_info (ahafs_curThrd_info_t *curThrdInfo);
int kcluster_send_ahafs(u_int16_t, 
                        void *, void *,
                        ahafs_cbFn_info_t *, char *, char *);
int kcluster_wraper_send (u_int16_t,
                          void *, void *, u_int16_t,
                          caddr_t);
void kcluster_get_node_info(char *, int);
#define SP_V1_AHAFS_CBFN_VERSION 3

#ifdef __cplusplus
}
#endif

#endif /* _H_AHAFS_EVPRODS */
