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