9128 cw(1onbld) should be able to run multiple shadows
[unleashed.git] / usr / src / common / mdesc / mdesc_getproparcs.c
blob31fffcf25d3ef12f4e5e51eb763bfbacdd5c3a10
1 /*
2 * CDDL HEADER START
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]
19 * CDDL HEADER END
22 * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
26 #pragma ident "%Z%%M% %I% %E% SMI"
28 #include <sys/types.h>
29 #include <sys/mdesc.h>
30 #include <sys/mdesc_impl.h>
32 static int md_find_node_arcs(md_impl_t *, mde_cookie_t, mde_str_cookie_t, int,
33 mde_cookie_t *, size_t);
37 * Return an array containing the node indexes for the arcs in
38 * the given node. The array is allocated using the allocator
39 * defined at machine description initialization time and the
40 * number of arcs found returned.
42 * Input Description
43 * ------------------- ----------------------------------------
44 * md_t * Pointer to md session
45 * mde_cookie_t Node containing arcs
46 * char * Arc name to count (e.g. "fwd" or "back")
47 * mde_cookie_t * Buffer to store indexes, or NULL
48 * size_t Size of buffer
50 * Output Description
51 * ------------------- ----------------------------------------
52 * int Count of arcs in node
54 int
55 md_get_prop_arcs(md_t *ptr, mde_cookie_t node, char *namep, mde_cookie_t *arcp,
56 size_t arcsize)
58 int result;
59 mde_str_cookie_t prop_name;
60 md_impl_t *mdp;
62 mdp = (md_impl_t *)ptr;
64 if (node == MDE_INVAL_ELEM_COOKIE) {
65 return (-1);
68 prop_name = md_find_name(ptr, namep);
69 if (prop_name == MDE_INVAL_STR_COOKIE) {
70 return (-1);
73 result = md_find_node_arcs(mdp, node, prop_name, MDET_PROP_ARC, arcp,
74 arcsize);
76 return (result);
81 * Find the number of arcs in the node of the requested prop_name. If storage
82 * is given in arcp, store the first arcsize number of node indexes.
84 static int
85 md_find_node_arcs(md_impl_t *mdp, mde_cookie_t node,
86 mde_str_cookie_t prop_name, int tag_type, mde_cookie_t *arcp,
87 size_t arcsize)
89 int result;
90 md_element_t *mdep;
91 int idx;
93 /* Get the private node information from session data */
94 idx = (int)node;
95 mdep = &(mdp->mdep[idx]);
97 /* Make sure the cookie is in fact a node */
98 if (MDE_TAG(mdep) != MDET_NODE) {
99 return (-1);
103 * Walk the elements in the node and find all the arcs of the
104 * requested type, and store them in an array.
106 result = 0;
107 for (idx++, mdep++; MDE_TAG(mdep) != MDET_NODE_END; idx++, mdep++) {
108 if ((MDE_TAG(mdep) == tag_type) &&
109 (MDE_NAME(mdep) == prop_name)) {
110 if (arcp != NULL && result < arcsize) {
111 arcp[result] =
112 (mde_cookie_t)MDE_PROP_INDEX(mdep);
115 /* Increment the count of arcs found */
116 result++;
120 /* Return the total count of arcs in the node */
121 return (result);