xref: /onnv-gate/usr/src/cmd/fm/schemes/dev/scheme.c (revision 4198:6bdfb19526db)
10Sstevel@tonic-gate /*
20Sstevel@tonic-gate  * CDDL HEADER START
30Sstevel@tonic-gate  *
40Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5555Stimh  * Common Development and Distribution License (the "License").
6555Stimh  * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate  *
80Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate  * See the License for the specific language governing permissions
110Sstevel@tonic-gate  * and limitations under the License.
120Sstevel@tonic-gate  *
130Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate  *
190Sstevel@tonic-gate  * CDDL HEADER END
200Sstevel@tonic-gate  */
21555Stimh 
220Sstevel@tonic-gate /*
23*4198Seschrock  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
240Sstevel@tonic-gate  * Use is subject to license terms.
250Sstevel@tonic-gate  */
260Sstevel@tonic-gate 
270Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
280Sstevel@tonic-gate 
290Sstevel@tonic-gate #include <fm/fmd_fmri.h>
30*4198Seschrock #include <fm/libtopo.h>
31*4198Seschrock #include <fm/topo_mod.h>
320Sstevel@tonic-gate #include <libdevinfo.h>
330Sstevel@tonic-gate #include <alloca.h>
340Sstevel@tonic-gate #include <string.h>
350Sstevel@tonic-gate 
36*4198Seschrock int
37*4198Seschrock fmd_fmri_init(void)
380Sstevel@tonic-gate {
39*4198Seschrock 	return (0);
400Sstevel@tonic-gate }
410Sstevel@tonic-gate 
42*4198Seschrock void
43*4198Seschrock fmd_fmri_fini(void)
44*4198Seschrock {
45*4198Seschrock }
460Sstevel@tonic-gate 
470Sstevel@tonic-gate ssize_t
480Sstevel@tonic-gate fmd_fmri_nvl2str(nvlist_t *nvl, char *buf, size_t buflen)
490Sstevel@tonic-gate {
50*4198Seschrock 	int err;
51*4198Seschrock 	ssize_t len;
52*4198Seschrock 	topo_hdl_t *thp;
53*4198Seschrock 	char *str;
54*4198Seschrock 
55*4198Seschrock 	if ((thp = fmd_fmri_topo_hold(TOPO_VERSION)) == NULL)
56*4198Seschrock 		return (fmd_fmri_set_errno(EINVAL));
57*4198Seschrock 
58*4198Seschrock 	if (topo_fmri_nvl2str(thp, nvl, &str, &err) != 0) {
59*4198Seschrock 		fmd_fmri_topo_rele(thp);
60*4198Seschrock 		return (fmd_fmri_set_errno(EINVAL));
61*4198Seschrock 	}
62*4198Seschrock 
63*4198Seschrock 	if (buf != NULL)
64*4198Seschrock 		len = snprintf(buf, buflen, "%s", str);
65*4198Seschrock 	else
66*4198Seschrock 		len = strlen(str);
67*4198Seschrock 
68*4198Seschrock 	topo_hdl_strfree(thp, str);
69*4198Seschrock 	fmd_fmri_topo_rele(thp);
70*4198Seschrock 
71*4198Seschrock 	return (len);
72*4198Seschrock }
73*4198Seschrock 
74*4198Seschrock int
75*4198Seschrock fmd_fmri_present(nvlist_t *nvl)
76*4198Seschrock {
77*4198Seschrock 	int err, present;
78*4198Seschrock 	topo_hdl_t *thp;
79*4198Seschrock 
80*4198Seschrock 	if ((thp = fmd_fmri_topo_hold(TOPO_VERSION)) == NULL)
81*4198Seschrock 		return (fmd_fmri_set_errno(EINVAL));
82*4198Seschrock 	err = 0;
83*4198Seschrock 	present = topo_fmri_present(thp, nvl, &err);
84*4198Seschrock 	fmd_fmri_topo_rele(thp);
85*4198Seschrock 
86*4198Seschrock 	if (err != 0)
87*4198Seschrock 		return (0);
88*4198Seschrock 	else
89*4198Seschrock 		return (present);
90*4198Seschrock }
91*4198Seschrock 
92*4198Seschrock int
93*4198Seschrock fmd_fmri_unusable(nvlist_t *nvl)
94*4198Seschrock {
950Sstevel@tonic-gate 	uint8_t version;
96*4198Seschrock 	int err, unusable;
97*4198Seschrock 	topo_hdl_t *thp;
980Sstevel@tonic-gate 
990Sstevel@tonic-gate 	if (nvlist_lookup_uint8(nvl, FM_VERSION, &version) != 0 ||
1000Sstevel@tonic-gate 	    version > FM_DEV_SCHEME_VERSION)
1010Sstevel@tonic-gate 		return (fmd_fmri_set_errno(EINVAL));
1020Sstevel@tonic-gate 
103*4198Seschrock 	if ((thp = fmd_fmri_topo_hold(TOPO_VERSION)) == NULL)
1040Sstevel@tonic-gate 		return (fmd_fmri_set_errno(EINVAL));
105*4198Seschrock 	err = 0;
106*4198Seschrock 	unusable = topo_fmri_unusable(thp, nvl, &err);
107*4198Seschrock 	fmd_fmri_topo_rele(thp);
1080Sstevel@tonic-gate 
109*4198Seschrock 	if (err != 0)
110*4198Seschrock 		return (0);
111*4198Seschrock 	else
112*4198Seschrock 		return (unusable);
1130Sstevel@tonic-gate }
114