/* @(#)src/unix/pagecache/sol/common/kernel/base/dmattr_drv.h	3.4 05/29/02 11:11:04 */
/* #ident "@(#)vxfs:src/unix/pagecache/sol/common/kernel/base/dmattr_drv.h	3.4" */

/*
 * (c) Copyright 1991-2003 VERITAS Software Corporation. All rights reserved.
 */

#ifndef	_DMATTR_DRV_H
#define	_DMATTR_DRV_H

#define _KERNEL 1

#include <sys/types.h>
#include <sys/systm.h>
#include <sys/errno.h>
#include <sys/cred.h>
#include <sys/kmem.h>
#include <sys/vnode.h>
#include <sys/conf.h>
#include <sys/modctl.h>
#include <sys/sunddi.h>
#include <sys/fs/dmapi.h>

/*
 * Class and subclass fields are of type 32 bit unsigned. Class ids
 * in range of (vx_32_t)-999 to 999 are now reserved. The unsignedness
 * of class/subclass invalidates the check for negative ids, however,
 * there are set of attribute tests that specify negative class ids
 * and expect failure. Until we change the attribute test suite not
 * to test with negative class ids, we'll reject any 'reserved' class
 * ids in range of (vx_u32_t)-999 to (vx_u32_t)-1 (used by fsqa test
 * suite) as invalid negative classes.
 */

#define VX_PUBLIC_CLASS		1000		/* classes <1000 are reserved */
#define VX_PUBLIC_CLASS_MIN	(uint32_t)-999	/* smallest reserved class id */
#define VX_PUBLIC_CLASS_MAX	(uint32_t)999	/* largest reserved class id */
#define VX_MAX_CLASS		(uint32_t)-999	/* maximum class id */
#define VX_INVALID_CLASS(class)	((class) >= VX_MAX_CLASS || (class) == 0)

#define VX_ATTR_IGNORE	1	/* Don't allow operation to see attribute */
#define VX_ATTR_KEEP	2	/* Perform operation as requested */
#define VX_ATTR_NEW	3	/* Substitute new attribute data */
#define VX_ATTR_LINK	4	/* Link to parent attribute */

struct vx_attrop {
		/* Listing/Reading attributes */
	int	(*paop_listop)(void *, uint32_t, uint32_t, uint64_t, caddr_t,
			       uint32_t, caddr_t *, uint32_t *, uint32_t *,
			       cred_t *);
		/* Setting/Removing attributes */
	int	(*paop_changeop)(void *, void *, uint32_t, uint32_t, uint32_t,
				 caddr_t, uint32_t, caddr_t *, uint32_t *,
				 uint32_t *, cred_t *);
		/* Inheriting attributes */
	int	(*paop_creatop)(void *, void *, uint32_t, uint64_t, caddr_t,
				uint32_t, caddr_t *, uint32_t *, void **,
				uint32_t *, void *, cred_t *, struct vattr *);
		/* New attributes on file create */
	int	(*paop_newop)(void *, void *, uint32_t *, uint64_t, caddr_t *,
			      uint32_t *, uint32_t *, void *, cred_t *);
};

struct vx_attrreg {
	struct vx_attrreg	*ar_next;	/* next registered class */
	uint32_t		ar_class;	/* registered class */
	struct vx_attrop	ar_aops;	/* attribute operations */
	struct vx_attrreg	*ar_newop_next;	/* next class with newop */
};

/*
 * OS-dependent system calls
 */

#ifdef TED_
#define VX_ALLOC(size, slp)	\
			xted_alloc((size), (slp), __FILE__, __LINE__, NULL)
#define VX_FREE(ptr, size)	xted_free((ptr), (size), NULL)
#else /* TED_ */
#define VX_ALLOC(size, slp)	kmem_alloc((size), (slp))
#define VX_FREE(ptr, size)	kmem_free((ptr), (size))
#endif /* TED_ */
#define VX_MEMWAIT		KM_SLEEP

/*
 * Values for the set attribute functions.
 */

#define VX_AREMOVE	0x1	/* Remove an attribute */
#define VX_ASET		0x2	/* Set an attribute */
#define VX_ARESTORE	0x3	/* Restore an attribute */

/*
 * kdm_vnode flags
 */

#define KDM_MRVALID	0x0001	/* MR structure is valid */

/*
 * vxfs functions
 */

extern int32_t		kdm_fs_set_region(void *, int32_t, dm_region_t *);
extern int32_t		vx_attr_register(uint32_t, struct vx_attrop *);
extern int32_t		vx_attr_deregister(uint32_t);
extern int32_t		vx_attr_name_register(dm_attrname_t *, int32_t, int32_t,
					      int32_t (*)(void *, caddr_t,
							  size_t));
extern int32_t		vx_attr_name_deregister(dm_attrname_t *, int32_t,
						int32_t);
extern int32_t		vx_attr_getnonimmed(void *, uint64_t, caddr_t *,
					    uint32_t, void **, void *);
extern int32_t		vx_attr_fsid_register(dm_attrname_t *,
					      int32_t (*)(caddr_t, size_t,
							  uint32_t *));
extern int32_t		vx_attr_fsid_deregister(dm_attrname_t *);
extern uint32_t		vx_get_igen(void *);
extern uint64_t		vx_get_ino(void *);
extern uint32_t		vx_get_imode(void *);
extern struct vnode	*vx_get_vnode(void *);
extern int32_t		vx_get_flags(void *);
extern void		*xted_alloc(size_t, int32_t, char *, int32_t, void *);
extern void		xted_free(void *, size_t, void *);

#endif	/* _DMATTR_DRV_H */
