1 /* 2 * CDDL HEADER START 3 * 4 * The contents of this file are subject to the terms of the 5 * Common Development and Distribution License, Version 1.0 only 6 * (the "License"). You may not use this file except in compliance 7 * with the License. 8 * 9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10 * or http://www.opensolaris.org/os/licensing. 11 * See the License for the specific language governing permissions 12 * and limitations under the License. 13 * 14 * When distributing Covered Code, include this CDDL HEADER in each 15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16 * If applicable, add the following below this CDDL HEADER, with the 17 * fields enclosed by brackets "[]" replaced with your own identifying 18 * information: Portions Copyright [yyyy] [name of copyright owner] 19 * 20 * CDDL HEADER END 21 */ 22 /* 23 * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 24 * Use is subject to license terms. 25 */ 26 27 #include <sys/types.h> 28 #include <sys/param.h> 29 #include <sys/mdesc.h> 30 #include <sys/mdesc_impl.h> 31 32 mde_cookie_t 33 md_find_node_prop(md_impl_t *mdp, 34 mde_cookie_t node, 35 mde_str_cookie_t prop_name, 36 int tag_type) 37 { 38 md_element_t *mdep; 39 int idx; 40 41 if (node == MDE_INVAL_ELEM_COOKIE || 42 prop_name == MDE_INVAL_STR_COOKIE) { 43 return (MDE_INVAL_ELEM_COOKIE); 44 } 45 46 idx = (int)node; 47 mdep = &(mdp->mdep[idx]); 48 49 /* Skip over any empty elements */ 50 while (MDE_TAG(mdep) == MDET_NULL) { 51 idx++; 52 mdep++; 53 } 54 55 /* see if cookie is infact a node */ 56 if (MDE_TAG(mdep) != MDET_NODE) { 57 return (MDE_INVAL_ELEM_COOKIE); 58 } 59 60 /* 61 * Simply walk the elements in the node 62 * looking for a property with a matching name. 63 */ 64 65 for (idx++, mdep++; MDE_TAG(mdep) != MDET_NODE_END; idx++, mdep++) { 66 if (MDE_TAG(mdep) == tag_type) { 67 if (MDE_NAME(mdep) == prop_name) { 68 return ((mde_cookie_t)idx); 69 } 70 } 71 } 72 73 return (MDE_INVAL_ELEM_COOKIE); /* no such property name */ 74 } 75