xref: /titanic_44/usr/src/cmd/ldmad/mdesc_mutable.h (revision fc256490629fe68815f7e0f23cf9b3545720cfac)
1*fc256490SJason Beloro /*
2*fc256490SJason Beloro  * CDDL HEADER START
3*fc256490SJason Beloro  *
4*fc256490SJason Beloro  * The contents of this file are subject to the terms of the
5*fc256490SJason Beloro  * Common Development and Distribution License (the "License").
6*fc256490SJason Beloro  * You may not use this file except in compliance with the License.
7*fc256490SJason Beloro  *
8*fc256490SJason Beloro  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9*fc256490SJason Beloro  * or http://www.opensolaris.org/os/licensing.
10*fc256490SJason Beloro  * See the License for the specific language governing permissions
11*fc256490SJason Beloro  * and limitations under the License.
12*fc256490SJason Beloro  *
13*fc256490SJason Beloro  * When distributing Covered Code, include this CDDL HEADER in each
14*fc256490SJason Beloro  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15*fc256490SJason Beloro  * If applicable, add the following below this CDDL HEADER, with the
16*fc256490SJason Beloro  * fields enclosed by brackets "[]" replaced with your own identifying
17*fc256490SJason Beloro  * information: Portions Copyright [yyyy] [name of copyright owner]
18*fc256490SJason Beloro  *
19*fc256490SJason Beloro  * CDDL HEADER END
20*fc256490SJason Beloro  */
21*fc256490SJason Beloro 
22*fc256490SJason Beloro /*
23*fc256490SJason Beloro  * Copyright 2010 Sun Microsystems, Inc.  All rights reserved.
24*fc256490SJason Beloro  * Use is subject to license terms.
25*fc256490SJason Beloro  */
26*fc256490SJason Beloro 
27*fc256490SJason Beloro #ifndef	_MDESC_MUTABLE_H_
28*fc256490SJason Beloro #define	_MDESC_MUTABLE_H_
29*fc256490SJason Beloro 
30*fc256490SJason Beloro #ifdef DEBUG
31*fc256490SJason Beloro #include <assert.h>
32*fc256490SJason Beloro #endif
33*fc256490SJason Beloro 
34*fc256490SJason Beloro #ifdef __cplusplus
35*fc256490SJason Beloro extern "C" {
36*fc256490SJason Beloro #endif
37*fc256490SJason Beloro 
38*fc256490SJason Beloro #ifdef DEBUG
39*fc256490SJason Beloro 
40*fc256490SJason Beloro #define	ASSERT(_s)	assert(_s)
41*fc256490SJason Beloro 
42*fc256490SJason Beloro #else	/* DEBUG */
43*fc256490SJason Beloro 
44*fc256490SJason Beloro #define	ASSERT(_s)
45*fc256490SJason Beloro 
46*fc256490SJason Beloro #endif	/* DEBUG */
47*fc256490SJason Beloro 
48*fc256490SJason Beloro #define	MD_ALIGNMENT_SIZE	0x10
49*fc256490SJason Beloro #define	MD_OFFSET_UNDEF		(uint32_t)-1
50*fc256490SJason Beloro /*
51*fc256490SJason Beloro  * List management macros for mutable MD structure
52*fc256490SJason Beloro  */
53*fc256490SJason Beloro #define	CHAIN(_type, _chain)						\
54*fc256490SJason Beloro 	struct {							\
55*fc256490SJason Beloro 		_type	*startp;					\
56*fc256490SJason Beloro 		_type	*endp;						\
57*fc256490SJason Beloro 		int	count;						\
58*fc256490SJason Beloro 	} _chain
59*fc256490SJason Beloro 
60*fc256490SJason Beloro #define	CHAIN_ITER(_chain, _itv)					\
61*fc256490SJason Beloro 	for ((_itv) = CHAIN_START(_chain); (_itv) != NULL;		\
62*fc256490SJason Beloro 		(_itv) = (_itv)->nextp)
63*fc256490SJason Beloro 
64*fc256490SJason Beloro #define	CHAIN_START(_name)	((_name).startp)
65*fc256490SJason Beloro #define	CHAIN_LENGTH(_name)	((_name).count)
66*fc256490SJason Beloro 
67*fc256490SJason Beloro /*
68*fc256490SJason Beloro  * Add node _nodep to the end of _chain via the required 'nextp' element.
69*fc256490SJason Beloro  */
70*fc256490SJason Beloro #define	CHAIN_ADD(_chain, _nodep)					\
71*fc256490SJason Beloro 	do {								\
72*fc256490SJason Beloro 		if ((_chain).startp == NULL) {				\
73*fc256490SJason Beloro 			(_chain).startp = (_nodep);			\
74*fc256490SJason Beloro 		} else {						\
75*fc256490SJason Beloro 			(_chain).endp->nextp = (_nodep);		\
76*fc256490SJason Beloro 		}							\
77*fc256490SJason Beloro 		(_chain).endp = (_nodep);				\
78*fc256490SJason Beloro 		(_nodep)->nextp = NULL;					\
79*fc256490SJason Beloro 		(_chain).count++;					\
80*fc256490SJason Beloro 	NOTE(CONSTCOND) } while (0)
81*fc256490SJason Beloro 
82*fc256490SJason Beloro /*
83*fc256490SJason Beloro  * Internal definitions.
84*fc256490SJason Beloro  */
85*fc256490SJason Beloro 
86*fc256490SJason Beloro typedef struct md_string md_string_t;
87*fc256490SJason Beloro typedef struct md_data_block md_data_block_t;
88*fc256490SJason Beloro typedef struct md_prop md_prop_t;
89*fc256490SJason Beloro typedef struct md_node md_node_t;
90*fc256490SJason Beloro typedef struct mmd mmd_t;
91*fc256490SJason Beloro 
92*fc256490SJason Beloro struct md_string {
93*fc256490SJason Beloro 	md_string_t	*nextp;
94*fc256490SJason Beloro 	char		*strp;
95*fc256490SJason Beloro 	int		size;	/* strlen()+1 */
96*fc256490SJason Beloro 	uint32_t	hash;
97*fc256490SJason Beloro 	int		ref_cnt;
98*fc256490SJason Beloro 	uint32_t	build_offset;
99*fc256490SJason Beloro };
100*fc256490SJason Beloro 
101*fc256490SJason Beloro struct md_data_block {
102*fc256490SJason Beloro 	md_data_block_t *nextp;
103*fc256490SJason Beloro 	uint8_t		*datap;
104*fc256490SJason Beloro 	uint32_t	size;
105*fc256490SJason Beloro 	uint32_t	hash;
106*fc256490SJason Beloro 	int		ref_cnt;
107*fc256490SJason Beloro 	uint32_t	build_offset;
108*fc256490SJason Beloro };
109*fc256490SJason Beloro 
110*fc256490SJason Beloro struct md_prop {
111*fc256490SJason Beloro 	uint8_t		type;
112*fc256490SJason Beloro 	md_string_t	*sp;
113*fc256490SJason Beloro 	union {
114*fc256490SJason Beloro 		uint64_t	value;
115*fc256490SJason Beloro 		struct {
116*fc256490SJason Beloro 			boolean_t	is_ptr;
117*fc256490SJason Beloro 			union {
118*fc256490SJason Beloro 				uint64_t	index;
119*fc256490SJason Beloro 				md_node_t	*nodep;
120*fc256490SJason Beloro 			} val;
121*fc256490SJason Beloro 		} arc;
122*fc256490SJason Beloro 		md_data_block_t *dbp;
123*fc256490SJason Beloro 	} d;
124*fc256490SJason Beloro 	md_prop_t	*nextp;
125*fc256490SJason Beloro };
126*fc256490SJason Beloro 
127*fc256490SJason Beloro struct md_node {
128*fc256490SJason Beloro 	md_string_t	*typep;
129*fc256490SJason Beloro 	CHAIN(md_prop_t, prop_list);
130*fc256490SJason Beloro 	md_node_t	*nextp;
131*fc256490SJason Beloro 	int		build_index;	/* for building a binary md & cloning */
132*fc256490SJason Beloro 	int		next_index;	/* for building a binary md */
133*fc256490SJason Beloro 	char		seen;		/* seen flag (md_scan_dag/md_scour) */
134*fc256490SJason Beloro 	char		deleted;	/* pending deletion flag */
135*fc256490SJason Beloro };
136*fc256490SJason Beloro 
137*fc256490SJason Beloro struct mmd {
138*fc256490SJason Beloro 	CHAIN(md_node_t, node_list);
139*fc256490SJason Beloro 	CHAIN(md_string_t, string_list);
140*fc256490SJason Beloro 	CHAIN(md_data_block_t, data_block_list);
141*fc256490SJason Beloro };
142*fc256490SJason Beloro 
143*fc256490SJason Beloro md_node_t *md_new_node(mmd_t *mdp, char *sp);
144*fc256490SJason Beloro int md_add_value_property(mmd_t *mdp,
145*fc256490SJason Beloro     md_node_t *nodep, char *sp, uint64_t value);
146*fc256490SJason Beloro int md_add_string_property(mmd_t *mdp, md_node_t *nodep, char *sp, char *bufp);
147*fc256490SJason Beloro int md_add_data_property(mmd_t *mdp, md_node_t *nodep, char *sp, int len,
148*fc256490SJason Beloro     uint8_t *bufp);
149*fc256490SJason Beloro int md_gen_bin(mmd_t *mdp, uint8_t **bufpp);
150*fc256490SJason Beloro md_node_t *md_link_new_node(mmd_t *mdp, char *nodenamep, md_node_t *parentnodep,
151*fc256490SJason Beloro     char *linktonewp, char *linkbackp);
152*fc256490SJason Beloro mmd_t *md_new_md(void);
153*fc256490SJason Beloro void md_free_node(mmd_t *mdp, md_node_t *nodep);
154*fc256490SJason Beloro void md_destroy(mmd_t *);
155*fc256490SJason Beloro 
156*fc256490SJason Beloro #ifdef __cplusplus
157*fc256490SJason Beloro }
158*fc256490SJason Beloro #endif
159*fc256490SJason Beloro 
160*fc256490SJason Beloro #endif	/* _MDESC_MUTABLE_H_ */
161