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 (the "License"). 6 * You may not use this file except in compliance with the License. 7 * 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. 12 * 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] 18 * 19 * CDDL HEADER END 20 */ 21 22 /* 23 * Copyright 2007 Sun Microsystems, Inc. All rights reserved. 24 * Use is subject to license terms. 25 */ 26 27 #pragma ident "%Z%%M% %I% %E% SMI" 28 29 #include <sys/types.h> 30 #include <errno.h> 31 #include <malloc.h> 32 #include <mdesc.h> 33 #include <pri.h> 34 #include "priplugin.h" 35 36 static void pri_free(void *bufp, size_t size); 37 uint64_t *md_bufp; 38 39 md_t * 40 pri_devinit(void) 41 { 42 md_t *mdp; 43 uint64_t tok; 44 45 md_bufp = NULL; 46 tok = 0; 47 48 if (pri_init() != -1) { 49 if (pri_get(PRI_GET, &tok, &md_bufp, malloc, pri_free) == 50 (ssize_t)-1) { 51 pri_debug(LOG_NOTICE, "pri_devinit: can'r read from " 52 "the PRI: %d\n", errno); 53 } 54 if (md_bufp == NULL) { 55 pri_debug(LOG_NOTICE, "pri_devinit: pri_get returned" 56 "NULL buffer!\n"); 57 } 58 } else { 59 pri_debug(LOG_NOTICE, "pri_devinit: pri_init failed!\n"); 60 } 61 pri_fini(); 62 63 pri_debug(LOG_NOTICE, "pri_devinit: done reading PRI\n"); 64 65 /* 66 * The PRI and the MD use the same data format so they can be 67 * parsed by the same functions. 68 */ 69 if (md_bufp) { 70 mdp = md_init_intern(md_bufp, malloc, pri_free); 71 if (mdp == NULL) { 72 pri_debug(LOG_NOTICE, "pri_devinit: md_init_intern " 73 "failed\n"); 74 free(md_bufp); 75 md_bufp = NULL; 76 } else { 77 pri_debug(LOG_NOTICE, "pri_devinit: mdi_init_intern " 78 "completed successfully\n"); 79 } 80 } else 81 mdp = NULL; 82 83 pri_debug(LOG_NOTICE, "pri_devinit: returning\n"); 84 85 return (mdp); 86 } 87 88 /*ARGSUSED*/ 89 static void 90 pri_free(void *bufp, size_t size) 91 { 92 if (bufp) 93 free(bufp); 94 } 95 96 void 97 pri_devfini(md_t *mdp) 98 { 99 if (mdp) 100 (void) md_fini(mdp); 101 102 if (md_bufp) 103 free(md_bufp); 104 md_bufp = NULL; 105 } 106