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]
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.
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
51 * ------------------- ----------------------------------------
52 * int Count of arcs in node
55 md_get_prop_arcs(md_t
*ptr
, mde_cookie_t node
, char *namep
, mde_cookie_t
*arcp
,
59 mde_str_cookie_t prop_name
;
62 mdp
= (md_impl_t
*)ptr
;
64 if (node
== MDE_INVAL_ELEM_COOKIE
) {
68 prop_name
= md_find_name(ptr
, namep
);
69 if (prop_name
== MDE_INVAL_STR_COOKIE
) {
73 result
= md_find_node_arcs(mdp
, node
, prop_name
, MDET_PROP_ARC
, arcp
,
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.
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
,
93 /* Get the private node information from session data */
95 mdep
= &(mdp
->mdep
[idx
]);
97 /* Make sure the cookie is in fact a node */
98 if (MDE_TAG(mdep
) != MDET_NODE
) {
103 * Walk the elements in the node and find all the arcs of the
104 * requested type, and store them in an array.
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
) {
112 (mde_cookie_t
)MDE_PROP_INDEX(mdep
);
115 /* Increment the count of arcs found */
120 /* Return the total count of arcs in the node */