1 /*
2  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
3  * Use is subject to license terms.
4  */
5 
6 #pragma ident	"@(#)mkerror.sh	1.2	05/06/08 SMI"
7 
8 #include <strings.h>
9 #include <topo_error.h>
10 #include <topo_mod.h>
11 
12 
13 static const char *const _topo_errstrs[] = {
14 	"unknown libtopo error",
15 	"memory limit exceeded",
16 	"module detected or caused an error",
17 	"failed to initialize module",
18 	"failed to uninitialize module",
19 	"specified module is already loaded",
20 	"specified module is not loaded",
21 	"module registered with invalid ABI version",
22 	"module invalid argument",
23 	"module duplicate node entry",
24 	"module failed to register",
25 	"module path invalid",
26 	"unable to read topology map file",
27 	"unable to enumerate from a topology map file",
28 	"enumerator not supported in this module",
29 	"module version mismatch while loading",
30 	"rtld failed to open shared library plug-in",
31 	"shared library plug-in does not define _topo_init",
32 	"memory limit exceeded when opening shared library",
33 	"built-in plug-in name not found in definition list",
34 	"built-in plug-in does not define init function",
35 	"plugin compiled using an obsolete topo ABI",
36 	"plugin is compiled using a newer topo ABI",
37 	"partial enumeration completed for client",
38 	"no topology map file for enumeration",
39 	"fatal enumeration error",
40 	"recursive enumertation detected",
41 	"invalid nvlist function argument",
42 	"no topology file found",
43 	"unrecognized grouping",
44 	"unable to interpret attribute numerically",
45 	"non-sensical range",
46 	"unrecognized scheme",
47 	"unrecognized stability",
48 	"unrecognized property value type",
49 	"tag missing attribute",
50 	"topology xml file not found",
51 	"range missing enum-method",
52 	"properties as nvlist missing crucial field",
53 	"node instance out of declared range",
54 	"failed to register property method",
55 	"empty topology",
56 	"scheme based topology not found",
57 	"no facility node of specified type found",
58 	"end of custom errno list (to ease auto-merge)",
59 };
60 
61 static const int _topo_nerrstrs =
62     sizeof (_topo_errstrs) / sizeof (_topo_errstrs[0]);
63 
64 
65 int
66 topo_hdl_errno(topo_hdl_t *thp)
67 {
68 	return (thp->th_errno);
69 }
70 
71 int
72 topo_hdl_seterrno(topo_hdl_t *thp, int err)
73 {
74 	thp->th_errno = err;
75 	return (-1);
76 }
77 
78 const char *
79 topo_hdl_errmsg(topo_hdl_t *thp)
80 {
81 	return (topo_strerror(thp->th_errno));
82 }
83 
84 static const char *const _topo_properrstrs[] = {
85 	"unknown topo prop error",
86 	"undefined property or property group",
87 	"static property already defined",
88 	"memory limit exceeded during property allocation",
89 	"invalid property type",
90 	"invalid property name",
91 	"can not inherit property",
92 	"malformed property nvlist",
93 	"get property method failed",
94 	"end of prop errno list (to ease auto-merge)",
95 };
96 
97 static const int _topo_nproperrstrs =
98     sizeof (_topo_properrstrs) / sizeof (_topo_properrstrs[0]);
99 
100 static const char *const _topo_methoderrstrs[] = {
101 	"unknown topo method error",
102 	"invalid method registration",
103 	"method not supported",
104 	"method failed",
105 	"app is compiled to use obsolete method",
106 	"app is compiled to use obsolete method",
107 	"memory limit exceeded during method op",
108 	"method op already defined",
109 	"end of method errno list",
110 };
111 
112 static const int _topo_nmethoderrstrs =
113     sizeof (_topo_methoderrstrs) / sizeof (_topo_methoderrstrs[0]);
114 
115 static const char *const _topo_fmrierrstrs[] = {
116 	"unknown topo fmri error",
117 	"nvlist allocation failure for FMRI",
118 	"invalid FMRI scheme version",
119 	"malformed FMRI",
120 	"memory limit exceeded",
121 	"end of fmri errno list",
122 };
123 
124 static const int _topo_nfmrierrstrs =
125     sizeof (_topo_fmrierrstrs) / sizeof (_topo_fmrierrstrs[0]);
126 
127 static const char *const _topo_hdlerrstrs[] = {
128 	"unknown topo handle error",
129 	"handle opened with invalid ABI version",
130 	"snapshot already taken",
131 	"invalid argument specified",
132 	"uuid already set",
133 	"memory limit exceeded",
134 	"end of handle errno list",
135 };
136 
137 static const int _topo_nhdlerrstrs =
138     sizeof (_topo_hdlerrstrs) / sizeof (_topo_hdlerrstrs[0]);
139 
140 static const char *const _topo_moderrstrs[] = {
141 	"unknown libtopo error",
142 	"module memory limit exceeded",
143 	"module completed partial enumeration",
144 	"method arguments invalid",
145 	"method not supported",
146 	"nvlist allocation failure for FMRI",
147 	"invalid FMRI scheme version",
148 	"malformed FMRI",
149 	"node already bound",
150 	"duplicate node",
151 	"node not found",
152 	"invalid node range",
153 	"registered with invalid ABI version",
154 	"attempt to load obsolete module",
155 	"attempt to load a newer module",
156 	"invalid nvlist",
157 	"non-canonical component name requested",
158 	"module lookup failed",
159 	"unknown enumeration error",
160 	"end of mod errno list (to ease auto-merge)",
161 };
162 static const int _topo_nmoderrstrs =
163     sizeof (_topo_moderrstrs) / sizeof (_topo_moderrstrs[0]);
164 
165 
166 int
167 topo_mod_errno(topo_mod_t *mp)
168 {
169 	return (mp->tm_errno);
170 }
171 
172 int
173 topo_mod_seterrno(topo_mod_t *mp, int err)
174 {
175 	mp->tm_errno = err;
176 	return (-1);
177 }
178 
179 const char *
180 topo_mod_errmsg(topo_mod_t *mp)
181 {
182 	return (topo_strerror(mp->tm_errno));
183 }
184 
185 const char *
186 topo_strerror(int err)
187 {
188 	const char *s;
189 
190 	if (err >= ETOPO_UNKNOWN && (err - ETOPO_UNKNOWN) < _topo_nerrstrs)
191 		s = _topo_errstrs[err - ETOPO_UNKNOWN];
192 	else if (err >= EMOD_UNKNOWN && (err - EMOD_UNKNOWN) <
193 	    _topo_nmoderrstrs)
194 		s = _topo_moderrstrs[err - EMOD_UNKNOWN];
195 	else if (err >= ETOPO_PROP_UNKNOWN && (err - ETOPO_PROP_UNKNOWN) <
196 	    _topo_nproperrstrs)
197 		s = _topo_properrstrs[err - ETOPO_PROP_UNKNOWN];
198 	else if (err >= ETOPO_METHOD_UNKNOWN && (err - ETOPO_METHOD_UNKNOWN) <
199 	    _topo_nmethoderrstrs)
200 		s = _topo_methoderrstrs[err - ETOPO_METHOD_UNKNOWN];
201 	else if (err >= ETOPO_HDL_UNKNOWN && (err - ETOPO_HDL_UNKNOWN) <
202 	    _topo_nhdlerrstrs)
203 		s = _topo_hdlerrstrs[err - ETOPO_HDL_UNKNOWN];
204 	else if (err >= ETOPO_FMRI_UNKNOWN && (err - ETOPO_FMRI_UNKNOWN) <
205 	    _topo_nfmrierrstrs)
206 		s = _topo_fmrierrstrs[err - ETOPO_FMRI_UNKNOWN];
207 	else
208 		s = _topo_errstrs[0];
209 
210 	return (s);
211 }
212