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>
22 static const char copyright[] =
23 "Copyright 1986, 1987, 1988 by the Student Information Processing Board\nand the department of Information Systems\nof the Massachusetts Institute of Technology";
25 static char buffer[64];
27 static struct et_list *_et_list = (struct et_list *)NULL;
29 #ifdef AFS_PTHREAD_ENV
34 * This mutex protects the following variables:
38 static pthread_mutex_t et_list_mutex;
39 static int et_list_done = 0;
40 static pthread_once_t et_list_once = PTHREAD_ONCE_INIT;
43 * Function to initialize the et_list_mutex
49 assert(!pthread_mutex_init
50 (&et_list_mutex, (const pthread_mutexattr_t *)0));
54 #define LOCK_ET_LIST \
56 (et_list_done || pthread_once(&et_list_once, et_mutex_once)); \
57 assert(pthread_mutex_lock(&et_list_mutex)==0); \
59 #define UNLOCK_ET_LIST assert(pthread_mutex_unlock(&et_list_mutex)==0)
62 #define UNLOCK_ET_LIST
63 #endif /* AFS_PTHREAD_ENV */
66 static char *vmsgs[] = {
67 "volume needs to be salvaged", /* 101, in Pittsburghese */
68 "no such entry (vnode)", /* 102 */
69 "volume does not exist / did not salvage", /* 103 */
70 "volume already exists", /* 104 */
71 "volume out of service", /* 105 */
72 "volume offline (utility running)", /* 106 */
73 "volume already online", /* 107 */
74 "unknown volume error 108", /* 108 */
75 "unknown volume error 109", /* 109 */
76 "volume temporarily busy", /* 110 */
77 "volume moved", /* 111 */
82 negative_message(int code)
85 return "server or network not responding";
87 return "invalid RPC (RX) operation";
89 return "server not responding promptly";
91 return "port address already in use";
92 else if (code <= -450 && code > -500) {
93 sprintf(buffer, "RPC interface mismatch (%d)", code);
96 sprintf(buffer, "unknown RPC error (%d)", code);
102 volume_message(int code)
104 if (code >= 101 && code <= 111)
105 return vmsgs[code - 101];
107 return "unknown volume error";
111 afs_error_message(afs_int32 code)
120 /* check for rpc errors first */
122 return negative_message(code);
124 offset = code & ((1 << ERRCODE_RANGE) - 1);
125 table_num = code - offset;
127 if ((err_msg = strerror(offset)) != NULL)
129 else if (offset < 140)
130 return volume_message(code);
135 for (et = _et_list; et; et = et->next) {
136 if (et->table->base == table_num) {
137 /* This is the right table */
138 if (et->table->n_msgs <= offset)
141 return (et->table->msgs[offset]);
146 strlcpy(buffer, "Unknown code ", sizeof buffer);
148 strlcat(buffer, afs_error_table_name(table_num), sizeof buffer);
149 strlcat(buffer, " ", sizeof buffer);
151 for (cp = buffer; *cp; cp++);
153 *cp++ = '0' + offset / 100;
157 if (started || offset >= 10) {
158 *cp++ = '0' + offset / 10;
161 *cp++ = '0' + offset;
163 sprintf(cp, " (%d)", code);
170 afs_add_to_error_table(struct et_list *new_table)
176 * Protect against adding the same error table twice
178 for (et = _et_list; et; et = et->next) {
179 if (et->table->base == new_table->table->base) {
185 new_table->next = _et_list;
186 _et_list = new_table;