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