4 * Copyright 1987 by the Student Information Processing Board
5 * of the Massachusetts Institute of Technology
7 * For copyright info, see "mit-sipb-cr.h".
10 #include <afsconfig.h>
11 #include <afs/param.h>
16 #include "error_table.h"
17 #include "mit-sipb-cr.h"
18 #include <afs/errors.h>
19 #include <afs/afsutil.h>
23 static const char copyright[] =
24 "Copyright 1986, 1987, 1988 by the Student Information Processing Board\nand the department of Information Systems\nof the Massachusetts Institute of Technology";
26 static char buffer[64];
28 static struct et_list *_et_list = (struct et_list *)NULL;
30 #ifdef AFS_PTHREAD_ENV
35 * This mutex protects the following variables:
39 static pthread_mutex_t et_list_mutex;
40 static int et_list_done = 0;
41 static pthread_once_t et_list_once = PTHREAD_ONCE_INIT;
44 * Function to initialize the et_list_mutex
50 assert(!pthread_mutex_init
51 (&et_list_mutex, (const pthread_mutexattr_t *)0));
55 #define LOCK_ET_LIST \
57 (et_list_done || pthread_once(&et_list_once, et_mutex_once)); \
58 assert(pthread_mutex_lock(&et_list_mutex)==0); \
60 #define UNLOCK_ET_LIST assert(pthread_mutex_unlock(&et_list_mutex)==0)
63 #define UNLOCK_ET_LIST
64 #endif /* AFS_PTHREAD_ENV */
67 static char *vmsgs[] = {
68 "volume needs to be salvaged", /* 101, in Pittsburghese */
69 "no such entry (vnode)", /* 102 */
70 "volume does not exist / did not salvage", /* 103 */
71 "volume already exists", /* 104 */
72 "volume out of service", /* 105 */
73 "volume offline (utility running)", /* 106 */
74 "volume already online", /* 107 */
75 "unknown volume error 108", /* 108 */
76 "unknown volume error 109", /* 109 */
77 "volume temporarily busy", /* 110 */
78 "volume moved", /* 111 */
83 negative_message(int code)
86 return "server or network not responding";
88 return "invalid RPC (RX) operation";
90 return "server not responding promptly";
92 return "port address already in use";
93 else if (code <= -450 && code > -500) {
94 sprintf(buffer, "RPC interface mismatch (%d)", code);
97 sprintf(buffer, "unknown RPC error (%d)", code);
103 volume_message(int code)
105 if (code >= 101 && code <= 111)
106 return vmsgs[code - 101];
108 return "unknown volume error";
112 afs_error_message(afs_int32 code)
121 /* check for rpc errors first */
123 return negative_message(code);
125 offset = code & ((1 << ERRCODE_RANGE) - 1);
126 table_num = code - offset;
128 if ((err_msg = strerror(offset)) != NULL)
130 else if (offset < 140)
131 return volume_message(code);
136 for (et = _et_list; et; et = et->next) {
137 if (et->table->base == table_num) {
138 /* This is the right table */
139 if (et->table->n_msgs <= offset)
142 return (et->table->msgs[offset]);
147 strlcpy(buffer, "Unknown code ", sizeof buffer);
149 strlcat(buffer, afs_error_table_name(table_num), sizeof buffer);
150 strlcat(buffer, " ", sizeof buffer);
152 for (cp = buffer; *cp; cp++);
154 *cp++ = '0' + offset / 100;
158 if (started || offset >= 10) {
159 *cp++ = '0' + offset / 10;
162 *cp++ = '0' + offset;
164 sprintf(cp, " (%d)", code);
171 afs_add_to_error_table(struct et_list *new_table)
177 * Protect against adding the same error table twice
179 for (et = _et_list; et; et = et->next) {
180 if (et->table->base == new_table->table->base) {
186 new_table->next = _et_list;
187 _et_list = new_table;