/* IBM_PROLOG_BEGIN_TAG                                                   */
/* This is an automatically generated prolog.                             */
/*                                                                        */
/* bos720 src/bos/kernel/j2/include/j2_ea.h 1.18                          */
/*                                                                        */
/* Licensed Materials - Property of IBM                                   */
/*                                                                        */
/* Restricted Materials of IBM                                            */
/*                                                                        */
/* COPYRIGHT International Business Machines Corp. 2000,2007              */
/* 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                                                     */

/* @(#)29       1.18  src/bos/kernel/j2/include/j2_ea.h, sysj2, bos720 3/29/07 16:38:42 */

/*
 * COMPONENT_NAME: (SYSJ2) JFS2 Physical File System
 *
 * FUNCTIONS:
 
 * ORIGINS: 27
 *
 * (C) COPYRIGHT International Business Machines Corp. 1996, 1999
 * All Rights Reserved
 * Licensed Materials - Property of IBM
 *
 * US Government Users Restricted Rights - Use, duplication or
 * disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
 */

#ifndef	_H_J2_EA
#define _H_J2_EA	

#include <j2/j2_filsys.h>

/*
 * This header describes the obsolescent EA version 1 format.
 */

/*
 *	 ea_type: client attribute type
 *
 * Upper 12 bits are used for type and the lower 4 bits are reserved
 * for flags (e.g. entry or ea directory, etc).  The high-order bit 
 * of the flag is for attributes set through the syscall interface.
 *
 * For backward compatibility, types that can be persistent in previous
 * AIX versions (acl & pcl) have two macros, one for what their bit pattern
 * looks like in the inode, the other for the eaEntry itself now that type
 * and flag have been combined. All other types get to use a single mask.
 */
#define EAMASK_TYPE		0xFFF0
#define EAMASK_FLAGS		0x000F

#define	EATYPE_AIXACL_I		0x0002
#define	EATYPE_AIXACL		0x0200
#define	EATYPE_AIXPCL_I		0x0004
#define	EATYPE_AIXPCL		0x0400

#ifdef _J2_WIP_EXTVAL
#define EATYPE_EV       	0x0800
#endif 

/* Note that while there are three names here, managed regions and pevlist
 * are combined in a single attribute in order to reduce the number of
 * J2 EA entries DMAPI actually uses. See j2_dmapi.c for details.
 */
#define	EATYPE_DMAPI_NAMED	0x0010 /* user-defined named attributes     */
#define	EATYPE_DMAPI_KERNEL	0x0020 /* j2-managed state (pevlist, etc)   */
#define	EATYPE_DMAPI_PMREGION	0x0040 /* persistent managed regions        */


/*
 *	ea metric
 */
/* eaFile line size: unit of allocation */
#define	EA_LINESIZE		64
#define	EA_L2LINESIZE		6

/* number of lines in inodex */
#define	EA_LINES_PER_DINODEX	8
#define	EA_L2LINES_PER_DINODEX	3

/* number of lines per meta-data page */
#define	EA_LINES_PER_PAGE	64
#define	EA_L2LINES_PER_PAGE	6

/* number of pages in per ea logical addressspace */
#define EA_PAGES_PER_REGION	4

/* max number of eaEntry in eaDirectory */
#define	EA_MAXENTRY		8

/* first line which is a real entry */
#define EA_ENTRYSTART		2

/* roundup ea data size to line boundary */
#define	eaRoundUp2Line(n)	(((n) + ((EA_LINESIZE)-1)) & ~((EA_LINESIZE)-1))

/* nBytes to nLines */
#define	eaSize2nLine(n)		(((n) + (EA_LINESIZE-1)) >> EA_L2LINESIZE)

#define	eaLineOffsetInPage(n)	((n) & (EA_LINES_PER_PAGE - 1))
#define eaPageNumber(n)		((n) >> EA_L2LINES_PER_PAGE)

/*
 *	ea descriptor in inode: i_ea (variation of xd_t)
 *
 * ref. j2_types.h
 */

/*
 *	ea line
 */
typedef struct {
	char	line[EA_LINESIZE];
} eaLine_t;

/*
 *	ea entry (eaEntry_t)
 */
typedef struct eaEntry {
	uint16	ea_type;
	int16	ea_reserved;
	int16	ea_offset;	/* entry extent offset in line */
	union {
		int16	_length;	/* entry data length in byte  */
		struct {
			int8	_nEntry;	/* # of directory entries */
			int8	_length; /* directory length in unit of line */
		} _s;
	} un;
} eaEntry_t;

#define	ea_length	un._length	
#define	ead_nEntry	un._s._nEntry
#define	ead_length	un._s._length
#define	ea_next	ea_reserved

/* ea_type:FFF0 client attribute type */
/* ea_type:000F entry structure type  */
#define	EAFLAG_ENTRY		0x0001
#define	EAFLAG_DIRECTORY	0x0002
#define	EAFLAG_USER		0x0008

/*
 *	inode extension (inodex_t)
 */
typedef struct dinodex {
	uint64	bitMap[EA_PAGES_PER_REGION];
	pxd_t	pxdTable[EA_PAGES_PER_REGION];
	eaEntry_t	eaDirectory[EA_MAXENTRY];
	eaLine_t	line[EA_MAXENTRY - EA_ENTRYSTART];	
} dinodex_t;

#endif	/* _H_J2_EA */