Print this page
patch tsoome-feedback
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/lib/fm/topo/libtopo/common/topo_parse.c
+++ new/usr/src/lib/fm/topo/libtopo/common/topo_parse.c
1 1 /*
2 2 * CDDL HEADER START
3 3 *
4 4 * The contents of this file are subject to the terms of the
5 5 * Common Development and Distribution License (the "License").
6 6 * You may not use this file except in compliance with the License.
7 7 *
8 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 9 * or http://www.opensolaris.org/os/licensing.
10 10 * See the License for the specific language governing permissions
11 11 * and limitations under the License.
12 12 *
13 13 * When distributing Covered Code, include this CDDL HEADER in each
14 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 15 * If applicable, add the following below this CDDL HEADER, with the
16 16 * fields enclosed by brackets "[]" replaced with your own identifying
↓ open down ↓ |
16 lines elided |
↑ open up ↑ |
17 17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 18 *
19 19 * CDDL HEADER END
20 20 */
21 21
22 22 /*
23 23 * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
24 24 * Use is subject to license terms.
25 25 */
26 26
27 -#pragma ident "%Z%%M% %I% %E% SMI"
28 -
29 27 #include <libxml/parser.h>
30 28 #include <fm/libtopo.h>
31 29 #include <topo_alloc.h>
32 30 #include <topo_error.h>
33 31 #include <topo_parse.h>
34 32 #include <topo_subr.h>
35 33
36 34 tf_info_t *
37 35 tf_info_new(topo_mod_t *mp, xmlDocPtr doc, xmlChar *scheme)
38 36 {
39 37 tf_info_t *r;
40 38
41 39 if ((r = topo_mod_zalloc(mp, sizeof (tf_info_t))) == NULL)
42 40 return (NULL);
43 41 r->tf_flags = TF_LIVE;
44 42 if ((r->tf_scheme = topo_mod_strdup(mp, (char *)scheme)) == NULL) {
45 43 tf_info_free(mp, r);
46 44 return (NULL);
47 45 }
48 46 r->tf_xdoc = doc;
49 47 return (r);
50 48 }
51 49
52 50 void
53 51 tf_info_free(topo_mod_t *mp, tf_info_t *p)
54 52 {
55 53 if (p->tf_xdoc != NULL)
56 54 xmlFreeDoc(p->tf_xdoc);
57 55 if (p->tf_scheme != NULL)
58 56 topo_mod_strfree(mp, p->tf_scheme);
59 57 tf_rdata_free(mp, p->tf_rd);
60 58 topo_mod_free(mp, p, sizeof (tf_info_t));
61 59 }
62 60
63 61 tf_rdata_t *
64 62 tf_rdata_new(topo_mod_t *mp, tf_info_t *xinfo, xmlNodePtr n, tnode_t *troot)
65 63 {
66 64 tf_rdata_t *r;
67 65 uint64_t ui;
68 66 xmlChar *name = NULL;
69 67
70 68 topo_dprintf(mp->tm_hdl, TOPO_DBG_XML, "new rdata\n");
71 69 if ((r = topo_mod_zalloc(mp, sizeof (tf_rdata_t))) == NULL) {
72 70 (void) topo_mod_seterrno(mp, ETOPO_NOMEM);
73 71 return (NULL);
74 72 }
75 73 r->rd_pn = troot;
76 74 if ((name = xmlGetProp(n, (xmlChar *)Name)) == NULL) {
77 75 (void) topo_mod_seterrno(mp, ETOPO_PRSR_NOATTR);
78 76 goto rdata_nogood;
79 77 }
80 78 if ((r->rd_name = topo_mod_strdup(mp, (char *)name)) == NULL) {
81 79 (void) topo_mod_seterrno(mp, ETOPO_NOMEM);
82 80 goto rdata_nogood;
83 81 }
84 82 if (xmlattr_to_int(mp, n, Min, &ui) < 0)
85 83 goto rdata_nogood;
86 84 r->rd_min = (int)ui;
87 85 if (xmlattr_to_int(mp, n, Max, &ui) < 0)
88 86 goto rdata_nogood;
89 87 r->rd_max = (int)ui;
90 88 if (r->rd_min < 0 || r->rd_max < 0 || r->rd_max < r->rd_min) {
91 89 (void) topo_mod_seterrno(mp, ETOPO_PRSR_BADRNG);
92 90 goto rdata_nogood;
93 91 }
94 92 r->rd_finfo = xinfo;
95 93 r->rd_mod = mp;
96 94
97 95 if (topo_xml_range_process(mp, n, r) < 0)
98 96 goto rdata_nogood;
99 97
100 98 xmlFree(name);
101 99 return (r);
102 100
103 101 rdata_nogood:
104 102 if (name != NULL)
105 103 xmlFree(name);
106 104 tf_rdata_free(mp, r);
107 105 return (NULL);
108 106 }
109 107
110 108 void
111 109 tf_rdata_free(topo_mod_t *mp, tf_rdata_t *p)
112 110 {
113 111 if (p == NULL)
114 112 return;
115 113 tf_rdata_free(mp, p->rd_next);
116 114 if (p->rd_name != NULL)
117 115 topo_mod_strfree(mp, p->rd_name);
118 116 tf_edata_free(mp, p->rd_einfo);
119 117 tf_idata_free(mp, p->rd_instances);
120 118 tf_pad_free(mp, p->rd_pad);
121 119 topo_mod_free(mp, p, sizeof (tf_rdata_t));
122 120 }
123 121
124 122 tf_idata_t *
125 123 tf_idata_new(topo_mod_t *mp, topo_instance_t i, tnode_t *tn)
126 124 {
127 125 tf_idata_t *r;
128 126
129 127 topo_dprintf(mp->tm_hdl, TOPO_DBG_XML, "new idata %d\n", i);
130 128 if ((r = topo_mod_zalloc(mp, sizeof (tf_idata_t))) == NULL)
131 129 return (NULL);
132 130 r->ti_tn = tn;
133 131 r->ti_i = i;
134 132 return (r);
135 133 }
136 134
137 135 void
138 136 tf_idata_free(topo_mod_t *mp, tf_idata_t *p)
139 137 {
140 138 if (p == NULL)
141 139 return;
142 140 tf_idata_free(mp, p->ti_next);
143 141 tf_pad_free(mp, p->ti_pad);
144 142 topo_mod_free(mp, p, sizeof (tf_idata_t));
145 143 }
146 144
147 145 int
148 146 tf_idata_insert(tf_idata_t **head, tf_idata_t *ni)
149 147 {
150 148 tf_idata_t *l, *p;
151 149
152 150 p = NULL;
153 151 for (l = *head; l != NULL; l = l->ti_next) {
154 152 if (ni->ti_i < l->ti_i)
155 153 break;
156 154 p = l;
157 155 }
158 156 ni->ti_next = l;
159 157 if (p == NULL)
160 158 *head = ni;
161 159 else
162 160 p->ti_next = ni;
163 161 return (0);
164 162 }
165 163
166 164 tf_idata_t *
167 165 tf_idata_lookup(tf_idata_t *head, topo_instance_t i)
168 166 {
169 167 tf_idata_t *f;
170 168 for (f = head; f != NULL; f = f->ti_next)
171 169 if (i == f->ti_i)
172 170 break;
173 171 return (f);
174 172 }
175 173
176 174 tf_pad_t *
177 175 tf_pad_new(topo_mod_t *mp, int pcnt, int dcnt)
178 176 {
179 177 tf_pad_t *r;
180 178
181 179 topo_dprintf(mp->tm_hdl, TOPO_DBG_XML, "new pad p=%d, d=%d\n",
182 180 pcnt, dcnt);
183 181 if ((r = topo_mod_zalloc(mp, sizeof (tf_pad_t))) == NULL)
184 182 return (NULL);
185 183 r->tpad_pgcnt = pcnt;
186 184 r->tpad_dcnt = dcnt;
187 185 return (r);
↓ open down ↓ |
149 lines elided |
↑ open up ↑ |
188 186 }
189 187
190 188 void
191 189 tf_pad_free(topo_mod_t *mp, tf_pad_t *p)
192 190 {
193 191 int n;
194 192 if (p == NULL)
195 193 return;
196 194 if (p->tpad_pgs != NULL) {
197 195 for (n = 0; n < p->tpad_pgcnt; n++)
198 - if (p->tpad_pgs[n] != NULL)
199 - nvlist_free(p->tpad_pgs[n]);
196 + nvlist_free(p->tpad_pgs[n]);
200 197 topo_mod_free(mp,
201 198 p->tpad_pgs, p->tpad_pgcnt * sizeof (nvlist_t *));
202 199 }
203 200 tf_rdata_free(mp, p->tpad_child);
204 201 tf_rdata_free(mp, p->tpad_sibs);
205 202 topo_mod_free(mp, p, sizeof (tf_pad_t));
206 203 }
207 204
208 205 void
209 206 tf_edata_free(topo_mod_t *mp, tf_edata_t *p)
210 207 {
211 208 if (p == NULL)
212 209 return;
213 210 if (p->te_name != NULL)
214 211 xmlFree(p->te_name);
215 212 topo_mod_free(mp, p, sizeof (tf_edata_t));
216 213 }
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX