1*7205Ssd77468 /*
2*7205Ssd77468 * CDDL HEADER START
3*7205Ssd77468 *
4*7205Ssd77468 * The contents of this file are subject to the terms of the
5*7205Ssd77468 * Common Development and Distribution License (the "License").
6*7205Ssd77468 * You may not use this file except in compliance with the License.
7*7205Ssd77468 *
8*7205Ssd77468 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9*7205Ssd77468 * or http://www.opensolaris.org/os/licensing.
10*7205Ssd77468 * See the License for the specific language governing permissions
11*7205Ssd77468 * and limitations under the License.
12*7205Ssd77468 *
13*7205Ssd77468 * When distributing Covered Code, include this CDDL HEADER in each
14*7205Ssd77468 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15*7205Ssd77468 * If applicable, add the following below this CDDL HEADER, with the
16*7205Ssd77468 * fields enclosed by brackets "[]" replaced with your own identifying
17*7205Ssd77468 * information: Portions Copyright [yyyy] [name of copyright owner]
18*7205Ssd77468 *
19*7205Ssd77468 * CDDL HEADER END
20*7205Ssd77468 */
21*7205Ssd77468 /*
22*7205Ssd77468 * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
23*7205Ssd77468 * Use is subject to license terms.
24*7205Ssd77468 */
25*7205Ssd77468
26*7205Ssd77468 #pragma ident "%Z%%M% %I% %E% SMI"
27*7205Ssd77468
28*7205Ssd77468 #include <sys/types.h>
29*7205Ssd77468 #include <sys/mdesc.h>
30*7205Ssd77468 #include <sys/mdesc_impl.h>
31*7205Ssd77468
32*7205Ssd77468 static int md_find_node_arcs(md_impl_t *, mde_cookie_t, mde_str_cookie_t, int,
33*7205Ssd77468 mde_cookie_t *, size_t);
34*7205Ssd77468
35*7205Ssd77468
36*7205Ssd77468 /*
37*7205Ssd77468 * Return an array containing the node indexes for the arcs in
38*7205Ssd77468 * the given node. The array is allocated using the allocator
39*7205Ssd77468 * defined at machine description initialization time and the
40*7205Ssd77468 * number of arcs found returned.
41*7205Ssd77468 *
42*7205Ssd77468 * Input Description
43*7205Ssd77468 * ------------------- ----------------------------------------
44*7205Ssd77468 * md_t * Pointer to md session
45*7205Ssd77468 * mde_cookie_t Node containing arcs
46*7205Ssd77468 * char * Arc name to count (e.g. "fwd" or "back")
47*7205Ssd77468 * mde_cookie_t * Buffer to store indexes, or NULL
48*7205Ssd77468 * size_t Size of buffer
49*7205Ssd77468 *
50*7205Ssd77468 * Output Description
51*7205Ssd77468 * ------------------- ----------------------------------------
52*7205Ssd77468 * int Count of arcs in node
53*7205Ssd77468 */
54*7205Ssd77468 int
md_get_prop_arcs(md_t * ptr,mde_cookie_t node,char * namep,mde_cookie_t * arcp,size_t arcsize)55*7205Ssd77468 md_get_prop_arcs(md_t *ptr, mde_cookie_t node, char *namep, mde_cookie_t *arcp,
56*7205Ssd77468 size_t arcsize)
57*7205Ssd77468 {
58*7205Ssd77468 int result;
59*7205Ssd77468 mde_str_cookie_t prop_name;
60*7205Ssd77468 md_impl_t *mdp;
61*7205Ssd77468
62*7205Ssd77468 mdp = (md_impl_t *)ptr;
63*7205Ssd77468
64*7205Ssd77468 if (node == MDE_INVAL_ELEM_COOKIE) {
65*7205Ssd77468 return (-1);
66*7205Ssd77468 }
67*7205Ssd77468
68*7205Ssd77468 prop_name = md_find_name(ptr, namep);
69*7205Ssd77468 if (prop_name == MDE_INVAL_STR_COOKIE) {
70*7205Ssd77468 return (-1);
71*7205Ssd77468 }
72*7205Ssd77468
73*7205Ssd77468 result = md_find_node_arcs(mdp, node, prop_name, MDET_PROP_ARC, arcp,
74*7205Ssd77468 arcsize);
75*7205Ssd77468
76*7205Ssd77468 return (result);
77*7205Ssd77468 }
78*7205Ssd77468
79*7205Ssd77468
80*7205Ssd77468 /*
81*7205Ssd77468 * Find the number of arcs in the node of the requested prop_name. If storage
82*7205Ssd77468 * is given in arcp, store the first arcsize number of node indexes.
83*7205Ssd77468 */
84*7205Ssd77468 static int
md_find_node_arcs(md_impl_t * mdp,mde_cookie_t node,mde_str_cookie_t prop_name,int tag_type,mde_cookie_t * arcp,size_t arcsize)85*7205Ssd77468 md_find_node_arcs(md_impl_t *mdp, mde_cookie_t node,
86*7205Ssd77468 mde_str_cookie_t prop_name, int tag_type, mde_cookie_t *arcp,
87*7205Ssd77468 size_t arcsize)
88*7205Ssd77468 {
89*7205Ssd77468 int result;
90*7205Ssd77468 md_element_t *mdep;
91*7205Ssd77468 int idx;
92*7205Ssd77468
93*7205Ssd77468 /* Get the private node information from session data */
94*7205Ssd77468 idx = (int)node;
95*7205Ssd77468 mdep = &(mdp->mdep[idx]);
96*7205Ssd77468
97*7205Ssd77468 /* Make sure the cookie is in fact a node */
98*7205Ssd77468 if (MDE_TAG(mdep) != MDET_NODE) {
99*7205Ssd77468 return (-1);
100*7205Ssd77468 }
101*7205Ssd77468
102*7205Ssd77468 /*
103*7205Ssd77468 * Walk the elements in the node and find all the arcs of the
104*7205Ssd77468 * requested type, and store them in an array.
105*7205Ssd77468 */
106*7205Ssd77468 result = 0;
107*7205Ssd77468 for (idx++, mdep++; MDE_TAG(mdep) != MDET_NODE_END; idx++, mdep++) {
108*7205Ssd77468 if ((MDE_TAG(mdep) == tag_type) &&
109*7205Ssd77468 (MDE_NAME(mdep) == prop_name)) {
110*7205Ssd77468 if (arcp != NULL && result < arcsize) {
111*7205Ssd77468 arcp[result] =
112*7205Ssd77468 (mde_cookie_t)MDE_PROP_INDEX(mdep);
113*7205Ssd77468 }
114*7205Ssd77468
115*7205Ssd77468 /* Increment the count of arcs found */
116*7205Ssd77468 result++;
117*7205Ssd77468 }
118*7205Ssd77468 }
119*7205Ssd77468
120*7205Ssd77468 /* Return the total count of arcs in the node */
121*7205Ssd77468 return (result);
122*7205Ssd77468 }
123