xref: /illumos-gate/usr/src/lib/libndmp/common/libndmp_error.c (revision b41e2fb6b2658a36accc73b3b86d99375e700dba)
1 /*
2  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
3  * Use is subject to license terms.
4  */
5 
6 /*
7  * BSD 3 Clause License
8  *
9  * Copyright (c) 2007, The Storage Networking Industry Association.
10  *
11  * Redistribution and use in source and binary forms, with or without
12  * modification, are permitted provided that the following conditions
13  * are met:
14  * 	- Redistributions of source code must retain the above copyright
15  *	  notice, this list of conditions and the following disclaimer.
16  *
17  * 	- Redistributions in binary form must reproduce the above copyright
18  *	  notice, this list of conditions and the following disclaimer in
19  *	  the documentation and/or other materials provided with the
20  *	  distribution.
21  *
22  *	- Neither the name of The Storage Networking Industry Association (SNIA)
23  *	  nor the names of its contributors may be used to endorse or promote
24  *	  products derived from this software without specific prior written
25  *	  permission.
26  *
27  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
28  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
29  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
30  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
31  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
32  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
33  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
34  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
35  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
36  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
37  * POSSIBILITY OF SUCH DAMAGE.
38  */
39 
40 #include <string.h>
41 #include <libndmp.h>
42 
43 int ndmp_errno;
44 
45 static const struct {
46 	int err;
47 	const char *msg;
48 } ndmp_errlist[] = {
49 	{ ENDMP_DOOR_SRV_TIMEOUT, "No answer from ndmpd service." },
50 	{ ENDMP_INVALID_ARG, "Invalid argument." },
51 	{ ENDMP_DOOR_SRV_OPERATION, "NDMP server operation failed." },
52 	{ ENDMP_DOOR_OPEN, "Door file open error." },
53 	{ ENDMP_MEM_ALLOC, "Out of memory." },
54 	{ ENDMP_DOOR_ENCODE_START, "Data encode start failed." },
55 	{ ENDMP_DOOR_ENCODE_FINISH, "Data encode finish failed." },
56 	{ ENDMP_DOOR_DECODE_FINISH, "Data decode finish failed." },
57 	{ ENDMP_SMF_PERM, "SMF permission denied." },
58 	{ ENDMP_SMF_INTERNAL, "SMF internal error." },
59 	{ ENDMP_SMF_PROP, "SMF property not set." },
60 	{ ENDMP_SMF_PROP_GRP, "Invalid SMF property group" }
61 };
62 
63 static const int ndmp_nerr = sizeof (ndmp_errlist) / sizeof (ndmp_errlist[0]);
64 
65 const char *
66 ndmp_strerror(int errnum)
67 {
68 	int i;
69 
70 	if (((errnum >= ENDMP_BASE) && (errnum - ENDMP_BASE)) < ndmp_nerr) {
71 		for (i = 0; i < ndmp_nerr; i++) {
72 			if (ndmp_errlist[i].err == errnum)
73 				return (ndmp_errlist[i].msg);
74 			}
75 	}
76 	return ("Unknown error");
77 }
78