xref: /illumos-gate/usr/src/common/smbios/smb_error.c (revision 5d9d9091f564c198a760790b0bfa72c44e17912b)
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 /*
24  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
25  * Use is subject to license terms.
26  */
27 
28 #include <sys/smbios_impl.h>
29 
30 static const char *const _smb_errlist[] = {
31 	"System does not export an SMBIOS table",	/* ESMB_NOTFOUND */
32 	"Failed to map SMBIOS table",			/* ESMB_MAPDEV */
33 	"Failed to locate specified structure",		/* ESMB_NOENT */
34 	"Failed to allocate memory",			/* ESMB_NOMEM */
35 	"Failed to read SMBIOS entry point",		/* ESMB_NOHDR */
36 	"Failed to read SMBIOS structure table",	/* ESMB_NOSTAB */
37 	"Generic info not available for structure",	/* ESMB_NOINFO */
38 	"Structure table is shorter than expected",	/* ESMB_SHORT */
39 	"SMBIOS data structure is corrupted",		/* ESMB_CORRUPT */
40 	"Requested library version is not supported",	/* ESMB_VERSION */
41 	"Structure type is not supported by this BIOS",	/* ESMB_NOTSUP */
42 	"Header is not a valid SMBIOS entry point",	/* ESMB_HEADER */
43 	"SMBIOS format is too old for processing",	/* ESMB_OLD */
44 	"SMBIOS format is new and not yet supported",	/* ESMB_NEW */
45 	"SMBIOS header checksum mismatch",		/* ESMB_CKSUM */
46 	"Invalid argument specified in library call",	/* ESMB_INVAL */
47 	"Structure is not of the expected type",	/* ESMB_TYPE */
48 	"Unknown SMBIOS error"				/* ESMB_UNKNOWN */
49 };
50 
51 static const int _smb_nerr = sizeof (_smb_errlist) / sizeof (_smb_errlist[0]);
52 
53 const char *
54 smbios_errmsg(int error)
55 {
56 	const char *str;
57 
58 	if (error >= ESMB_BASE && (error - ESMB_BASE) < _smb_nerr)
59 		str = _smb_errlist[error - ESMB_BASE];
60 	else
61 		str = smb_strerror(error);
62 
63 	return (str ? str : "Unknown error");
64 }
65 
66 int
67 smbios_errno(smbios_hdl_t *shp)
68 {
69 	return (shp->sh_err);
70 }
71 
72 int
73 smb_set_errno(smbios_hdl_t *shp, int error)
74 {
75 	shp->sh_err = error;
76 	return (SMB_ERR);
77 }
78