4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
23 * Copyright 2010 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 #ifndef _MDESC_MUTABLE_H_
28 #define _MDESC_MUTABLE_H_
40 #define ASSERT(_s) assert(_s)
48 #define MD_ALIGNMENT_SIZE 0x10
49 #define MD_OFFSET_UNDEF (uint32_t)-1
51 * List management macros for mutable MD structure
53 #define CHAIN(_type, _chain) \
60 #define CHAIN_ITER(_chain, _itv) \
61 for ((_itv) = CHAIN_START(_chain); (_itv) != NULL; \
62 (_itv) = (_itv)->nextp)
64 #define CHAIN_START(_name) ((_name).startp)
65 #define CHAIN_LENGTH(_name) ((_name).count)
68 * Add node _nodep to the end of _chain via the required 'nextp' element.
70 #define CHAIN_ADD(_chain, _nodep) \
72 if ((_chain).startp == NULL) { \
73 (_chain).startp = (_nodep); \
75 (_chain).endp->nextp = (_nodep); \
77 (_chain).endp = (_nodep); \
78 (_nodep)->nextp = NULL; \
80 NOTE(CONSTCOND) } while (0)
83 * Internal definitions.
86 typedef struct md_string md_string_t
;
87 typedef struct md_data_block md_data_block_t
;
88 typedef struct md_prop md_prop_t
;
89 typedef struct md_node md_node_t
;
90 typedef struct mmd mmd_t
;
95 int size
; /* strlen()+1 */
98 uint32_t build_offset
;
101 struct md_data_block
{
102 md_data_block_t
*nextp
;
107 uint32_t build_offset
;
122 md_data_block_t
*dbp
;
129 CHAIN(md_prop_t
, prop_list
);
131 int build_index
; /* for building a binary md & cloning */
132 int next_index
; /* for building a binary md */
133 char seen
; /* seen flag (md_scan_dag/md_scour) */
134 char deleted
; /* pending deletion flag */
138 CHAIN(md_node_t
, node_list
);
139 CHAIN(md_string_t
, string_list
);
140 CHAIN(md_data_block_t
, data_block_list
);
143 md_node_t
*md_new_node(mmd_t
*mdp
, char *sp
);
144 int md_add_value_property(mmd_t
*mdp
,
145 md_node_t
*nodep
, char *sp
, uint64_t value
);
146 int md_add_string_property(mmd_t
*mdp
, md_node_t
*nodep
, char *sp
, char *bufp
);
147 int md_add_data_property(mmd_t
*mdp
, md_node_t
*nodep
, char *sp
, int len
,
149 int md_gen_bin(mmd_t
*mdp
, uint8_t **bufpp
);
150 md_node_t
*md_link_new_node(mmd_t
*mdp
, char *nodenamep
, md_node_t
*parentnodep
,
151 char *linktonewp
, char *linkbackp
);
152 mmd_t
*md_new_md(void);
153 void md_free_node(mmd_t
*mdp
, md_node_t
*nodep
);
154 void md_destroy(mmd_t
*);
160 #endif /* _MDESC_MUTABLE_H_ */