1*0Sstevel@tonic-gate /* 2*0Sstevel@tonic-gate * CDDL HEADER START 3*0Sstevel@tonic-gate * 4*0Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5*0Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 6*0Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 7*0Sstevel@tonic-gate * with the License. 8*0Sstevel@tonic-gate * 9*0Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10*0Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 11*0Sstevel@tonic-gate * See the License for the specific language governing permissions 12*0Sstevel@tonic-gate * and limitations under the License. 13*0Sstevel@tonic-gate * 14*0Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 15*0Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16*0Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 17*0Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 18*0Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 19*0Sstevel@tonic-gate * 20*0Sstevel@tonic-gate * CDDL HEADER END 21*0Sstevel@tonic-gate */ 22*0Sstevel@tonic-gate /* 23*0Sstevel@tonic-gate * Copyright 2004 Sun Microsystems, Inc. All rights reserved. 24*0Sstevel@tonic-gate * Use is subject to license terms. 25*0Sstevel@tonic-gate */ 26*0Sstevel@tonic-gate 27*0Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 28*0Sstevel@tonic-gate 29*0Sstevel@tonic-gate #include <fm/fmd_fmri.h> 30*0Sstevel@tonic-gate 31*0Sstevel@tonic-gate /* 32*0Sstevel@tonic-gate * buf_append -- Append str to buf (if it's non-NULL). Place prepend 33*0Sstevel@tonic-gate * in buf in front of str and append behind it (if they're non-NULL). 34*0Sstevel@tonic-gate * Continue to update size even if we run out of space to actually 35*0Sstevel@tonic-gate * stuff characters in the buffer. 36*0Sstevel@tonic-gate */ 37*0Sstevel@tonic-gate static void 38*0Sstevel@tonic-gate buf_append(ssize_t *sz, char *buf, size_t buflen, char *str, 39*0Sstevel@tonic-gate char *prepend, char *append) 40*0Sstevel@tonic-gate { 41*0Sstevel@tonic-gate ssize_t left; 42*0Sstevel@tonic-gate 43*0Sstevel@tonic-gate if (str == NULL) 44*0Sstevel@tonic-gate return; 45*0Sstevel@tonic-gate 46*0Sstevel@tonic-gate if (buflen == 0 || (left = buflen - *sz) < 0) 47*0Sstevel@tonic-gate left = 0; 48*0Sstevel@tonic-gate 49*0Sstevel@tonic-gate if (buf != NULL && left != 0) 50*0Sstevel@tonic-gate buf += *sz; 51*0Sstevel@tonic-gate 52*0Sstevel@tonic-gate if (prepend == NULL && append == NULL) 53*0Sstevel@tonic-gate *sz += snprintf(buf, left, "%s", str); 54*0Sstevel@tonic-gate else if (append == NULL) 55*0Sstevel@tonic-gate *sz += snprintf(buf, left, "%s%s", prepend, str); 56*0Sstevel@tonic-gate else if (prepend == NULL) 57*0Sstevel@tonic-gate *sz += snprintf(buf, left, "%s%s", str, append); 58*0Sstevel@tonic-gate else 59*0Sstevel@tonic-gate *sz += snprintf(buf, left, "%s%s%s", prepend, str, append); 60*0Sstevel@tonic-gate } 61*0Sstevel@tonic-gate 62*0Sstevel@tonic-gate /* 63*0Sstevel@tonic-gate * Maximum 32 bit integer is 2147483647, which is 10 digits. A buffer 64*0Sstevel@tonic-gate * of 11 bytes can therefore contain the null-terminated ascii 65*0Sstevel@tonic-gate * representation of any integer module id. 66*0Sstevel@tonic-gate */ 67*0Sstevel@tonic-gate #define MAXINTSTR 11 68*0Sstevel@tonic-gate 69*0Sstevel@tonic-gate ssize_t 70*0Sstevel@tonic-gate fmd_fmri_nvl2str(nvlist_t *nvl, char *buf, size_t buflen) 71*0Sstevel@tonic-gate { 72*0Sstevel@tonic-gate nvlist_t *anvl = NULL; 73*0Sstevel@tonic-gate uint8_t version; 74*0Sstevel@tonic-gate ssize_t size = 0; 75*0Sstevel@tonic-gate int32_t modid; 76*0Sstevel@tonic-gate char *achas = NULL; 77*0Sstevel@tonic-gate char *adom = NULL; 78*0Sstevel@tonic-gate char *aprod = NULL; 79*0Sstevel@tonic-gate char *asrvr = NULL; 80*0Sstevel@tonic-gate char *ahost = NULL; 81*0Sstevel@tonic-gate char *modname = NULL; 82*0Sstevel@tonic-gate char numbuf[MAXINTSTR]; 83*0Sstevel@tonic-gate int more_auth = 0; 84*0Sstevel@tonic-gate int err; 85*0Sstevel@tonic-gate 86*0Sstevel@tonic-gate if (nvlist_lookup_uint8(nvl, FM_VERSION, &version) != 0 || 87*0Sstevel@tonic-gate version > FM_MOD_SCHEME_VERSION) 88*0Sstevel@tonic-gate return (fmd_fmri_set_errno(EINVAL)); 89*0Sstevel@tonic-gate 90*0Sstevel@tonic-gate /* Get authority, if present */ 91*0Sstevel@tonic-gate err = nvlist_lookup_nvlist(nvl, FM_FMRI_AUTHORITY, &anvl); 92*0Sstevel@tonic-gate if (err != 0 && err != ENOENT) 93*0Sstevel@tonic-gate return (fmd_fmri_set_errno(err)); 94*0Sstevel@tonic-gate 95*0Sstevel@tonic-gate /* 96*0Sstevel@tonic-gate * For brevity, we only include the module name and id 97*0Sstevel@tonic-gate * present in the FMRI in our output string. The FMRI 98*0Sstevel@tonic-gate * also has data on the package containing the module. 99*0Sstevel@tonic-gate */ 100*0Sstevel@tonic-gate 101*0Sstevel@tonic-gate /* There must be a module name */ 102*0Sstevel@tonic-gate err = nvlist_lookup_string(nvl, FM_FMRI_MOD_NAME, &modname); 103*0Sstevel@tonic-gate if (err != 0 || modname == NULL) 104*0Sstevel@tonic-gate return (fmd_fmri_set_errno(EINVAL)); 105*0Sstevel@tonic-gate 106*0Sstevel@tonic-gate /* There must be a module id */ 107*0Sstevel@tonic-gate err = nvlist_lookup_int32(nvl, FM_FMRI_MOD_ID, &modid); 108*0Sstevel@tonic-gate if (err != 0) 109*0Sstevel@tonic-gate return (fmd_fmri_set_errno(EINVAL)); 110*0Sstevel@tonic-gate 111*0Sstevel@tonic-gate if (anvl != NULL) { 112*0Sstevel@tonic-gate (void) nvlist_lookup_string(anvl, 113*0Sstevel@tonic-gate FM_FMRI_AUTH_PRODUCT, &aprod); 114*0Sstevel@tonic-gate (void) nvlist_lookup_string(anvl, 115*0Sstevel@tonic-gate FM_FMRI_AUTH_CHASSIS, &achas); 116*0Sstevel@tonic-gate (void) nvlist_lookup_string(anvl, 117*0Sstevel@tonic-gate FM_FMRI_AUTH_DOMAIN, &adom); 118*0Sstevel@tonic-gate (void) nvlist_lookup_string(anvl, 119*0Sstevel@tonic-gate FM_FMRI_AUTH_SERVER, &asrvr); 120*0Sstevel@tonic-gate (void) nvlist_lookup_string(anvl, 121*0Sstevel@tonic-gate FM_FMRI_AUTH_HOST, &ahost); 122*0Sstevel@tonic-gate if (aprod != NULL) 123*0Sstevel@tonic-gate more_auth++; 124*0Sstevel@tonic-gate if (achas != NULL) 125*0Sstevel@tonic-gate more_auth++; 126*0Sstevel@tonic-gate if (adom != NULL) 127*0Sstevel@tonic-gate more_auth++; 128*0Sstevel@tonic-gate if (asrvr != NULL) 129*0Sstevel@tonic-gate more_auth++; 130*0Sstevel@tonic-gate if (ahost != NULL) 131*0Sstevel@tonic-gate more_auth++; 132*0Sstevel@tonic-gate } 133*0Sstevel@tonic-gate 134*0Sstevel@tonic-gate /* mod:// */ 135*0Sstevel@tonic-gate buf_append(&size, buf, buflen, FM_FMRI_SCHEME_MOD, NULL, "://"); 136*0Sstevel@tonic-gate 137*0Sstevel@tonic-gate /* authority, if any */ 138*0Sstevel@tonic-gate if (aprod != NULL) 139*0Sstevel@tonic-gate buf_append(&size, buf, buflen, aprod, FM_FMRI_AUTH_PRODUCT "=", 140*0Sstevel@tonic-gate --more_auth > 0 ? "," : NULL); 141*0Sstevel@tonic-gate if (achas != NULL) 142*0Sstevel@tonic-gate buf_append(&size, buf, buflen, achas, FM_FMRI_AUTH_CHASSIS "=", 143*0Sstevel@tonic-gate --more_auth > 0 ? "," : NULL); 144*0Sstevel@tonic-gate if (adom != NULL) 145*0Sstevel@tonic-gate buf_append(&size, buf, buflen, adom, FM_FMRI_AUTH_DOMAIN "=", 146*0Sstevel@tonic-gate --more_auth > 0 ? "," : NULL); 147*0Sstevel@tonic-gate if (asrvr != NULL) 148*0Sstevel@tonic-gate buf_append(&size, buf, buflen, asrvr, FM_FMRI_AUTH_SERVER "=", 149*0Sstevel@tonic-gate --more_auth > 0 ? "," : NULL); 150*0Sstevel@tonic-gate if (ahost != NULL) 151*0Sstevel@tonic-gate buf_append(&size, buf, buflen, ahost, FM_FMRI_AUTH_HOST "=", 152*0Sstevel@tonic-gate NULL); 153*0Sstevel@tonic-gate 154*0Sstevel@tonic-gate /* module parts */ 155*0Sstevel@tonic-gate buf_append(&size, buf, buflen, modname, "/" FM_FMRI_MOD_NAME "=", "/"); 156*0Sstevel@tonic-gate 157*0Sstevel@tonic-gate (void) snprintf(numbuf, MAXINTSTR, "%d", modid); 158*0Sstevel@tonic-gate buf_append(&size, buf, buflen, numbuf, FM_FMRI_MOD_ID "=", NULL); 159*0Sstevel@tonic-gate 160*0Sstevel@tonic-gate return (size); 161*0Sstevel@tonic-gate } 162*0Sstevel@tonic-gate 163*0Sstevel@tonic-gate /* 164*0Sstevel@tonic-gate * fmd_fmri_present() is called by fmadm to determine if a faulty ASRU 165*0Sstevel@tonic-gate * is still present in the system. In general we don't expect to get 166*0Sstevel@tonic-gate * ASRUs in this scheme, so it's unlikely this routine will get called. 167*0Sstevel@tonic-gate * In case it does, though, we just return true by default, as we have no 168*0Sstevel@tonic-gate * real way to look up the component in the system configuration. 169*0Sstevel@tonic-gate */ 170*0Sstevel@tonic-gate /*ARGSUSED*/ 171*0Sstevel@tonic-gate int 172*0Sstevel@tonic-gate fmd_fmri_present(nvlist_t *nvl) 173*0Sstevel@tonic-gate { 174*0Sstevel@tonic-gate return (1); 175*0Sstevel@tonic-gate } 176*0Sstevel@tonic-gate 177*0Sstevel@tonic-gate /* 178*0Sstevel@tonic-gate * fmd_fmri_unusable() is called by fmadm to determine if a faulty ASRU 179*0Sstevel@tonic-gate * is usable. In general we don't expect to get ASRUs in this scheme, 180*0Sstevel@tonic-gate * so it's unlikely this routine will get called. In case it does, 181*0Sstevel@tonic-gate * though, we just return false by default, as we have no real way to 182*0Sstevel@tonic-gate * find the component or determine the component's usability. 183*0Sstevel@tonic-gate */ 184*0Sstevel@tonic-gate /*ARGSUSED*/ 185*0Sstevel@tonic-gate int 186*0Sstevel@tonic-gate fmd_fmri_unusable(nvlist_t *nvl) 187*0Sstevel@tonic-gate { 188*0Sstevel@tonic-gate return (0); 189*0Sstevel@tonic-gate } 190