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 \
58 pthread_once(&et_list_once, et_mutex_once); \
59 assert(pthread_mutex_lock(&et_list_mutex)==0); \
61 #define UNLOCK_ET_LIST assert(pthread_mutex_unlock(&et_list_mutex)==0)
64 #define UNLOCK_ET_LIST
65 #endif /* AFS_PTHREAD_ENV */
68 static char *vmsgs[] = {
69 "volume needs to be salvaged", /* 101, in Pittsburghese */
70 "no such entry (vnode)", /* 102 */
71 "volume does not exist / did not salvage", /* 103 */
72 "volume already exists", /* 104 */
73 "volume out of service", /* 105 */
74 "volume offline (utility running)", /* 106 */
75 "volume already online", /* 107 */
76 "unknown volume error 108", /* 108 */
77 "unknown volume error 109", /* 109 */
78 "volume temporarily busy", /* 110 */
79 "volume moved", /* 111 */
84 negative_message(int code)
87 return "server or network not responding";
89 return "invalid RPC (RX) operation";
91 return "server not responding promptly";
93 return "port address already in use";
94 else if (code <= -450 && code > -500) {
95 sprintf(buffer, "RPC interface mismatch (%d)", code);
98 sprintf(buffer, "unknown RPC error (%d)", code);
104 volume_message(int code)
106 if (code >= 101 && code <= 111)
107 return vmsgs[code - 101];
109 return "unknown volume error";
113 afs_error_message(afs_int32 code)
122 /* check for rpc errors first */
124 return negative_message(code);
126 offset = code & ((1 << ERRCODE_RANGE) - 1);
127 table_num = code - offset;
129 if ((err_msg = strerror(offset)) != NULL)
131 else if (offset < 140)
132 return volume_message(code);
137 for (et = _et_list; et; et = et->next) {
138 if (et->table->base == table_num) {
139 /* This is the right table */
140 if (et->table->n_msgs <= offset)
143 return (et->table->msgs[offset]);
148 strlcpy(buffer, "Unknown code ", sizeof buffer);
150 strlcat(buffer, afs_error_table_name(table_num), sizeof buffer);
151 strlcat(buffer, " ", sizeof buffer);
153 for (cp = buffer; *cp; cp++);
155 *cp++ = '0' + offset / 100;
159 if (started || offset >= 10) {
160 *cp++ = '0' + offset / 10;
163 *cp++ = '0' + offset;
165 sprintf(cp, " (%d)", code);
172 afs_add_to_error_table(struct et_list *new_table)
178 * Protect against adding the same error table twice
180 for (et = _et_list; et; et = et->next) {
181 if (et->table->base == new_table->table->base) {
187 new_table->next = _et_list;
188 _et_list = new_table;