Commit | Line | Data |
---|---|---|
805e021f CE |
1 | /* |
2 | * Copyright 2000, International Business Machines Corporation and others. | |
3 | * All Rights Reserved. | |
4 | * | |
5 | * This software has been released under the terms of the IBM Public | |
6 | * License. For details, see the LICENSE file in the top-level source | |
7 | * directory or online at http://www.openafs.org/dl/license10.html | |
8 | */ | |
9 | ||
10 | /* | |
11 | * Implements: | |
12 | */ | |
13 | #include <afsconfig.h> | |
14 | #include "afs/param.h" | |
15 | ||
16 | ||
17 | #include "afs/stds.h" | |
18 | #include "afs/sysincludes.h" /* Standard vendor system headers */ | |
19 | ||
20 | #ifndef UKERNEL | |
21 | #if !defined(AFS_LINUX20_ENV) && !defined(AFS_FBSD_ENV) | |
22 | #include <net/if.h> | |
23 | #include <netinet/in.h> | |
24 | #endif | |
25 | ||
26 | #ifdef AFS_SGI62_ENV | |
27 | #include "h/hashing.h" | |
28 | #endif | |
29 | #if !defined(AFS_HPUX110_ENV) && !defined(AFS_LINUX20_ENV) && !defined(AFS_FBSD_ENV) && !defined(AFS_DARWIN_ENV) | |
30 | #include <netinet/in_var.h> | |
31 | #endif | |
32 | #endif /* !UKERNEL */ | |
33 | ||
34 | #include "afsincludes.h" /* Afs-based standard headers */ | |
35 | #include "afs/afs_stats.h" /* afs statistics */ | |
36 | #include "afs/afs_util.h" | |
37 | #include "afs/unified_afs.h" | |
38 | ||
39 | #if defined(AFS_SUN5_ENV) | |
40 | #include <inet/led.h> | |
41 | #include <inet/common.h> | |
42 | #include <netinet/ip6.h> | |
43 | #include <inet/ip.h> | |
44 | #endif | |
45 | ||
46 | ||
47 | /* shouldn't do it this way, but for now will do */ | |
48 | #ifndef ERROR_TABLE_BASE_U | |
49 | #define ERROR_TABLE_BASE_U (5376L) | |
50 | #endif /* ubik error base define */ | |
51 | ||
52 | /* shouldn't do it this way, but for now will do */ | |
53 | #ifndef ERROR_TABLE_BASE_uae | |
54 | #define ERROR_TABLE_BASE_uae (49733376L) | |
55 | #endif /* unified afs error base define */ | |
56 | ||
57 | /* same hack for vlserver error base as for ubik error base */ | |
58 | #ifndef ERROR_TABLE_BASE_VL | |
59 | #define ERROR_TABLE_BASE_VL (363520L) | |
60 | #define VL_NOENT (363524L) | |
61 | #endif /* vlserver error base define */ | |
62 | ||
63 | ||
64 | static int et2sys[512]; | |
65 | ||
66 | void | |
67 | init_et_to_sys_error(void) | |
68 | { | |
69 | memset(&et2sys, 0, sizeof(et2sys)); | |
70 | et2sys[(UAEPERM - ERROR_TABLE_BASE_uae)] = EPERM; | |
71 | et2sys[(UAENOENT - ERROR_TABLE_BASE_uae)] = ENOENT; | |
72 | et2sys[(UAESRCH - ERROR_TABLE_BASE_uae)] = ESRCH; | |
73 | et2sys[(UAEINTR - ERROR_TABLE_BASE_uae)] = EINTR; | |
74 | et2sys[(UAEIO - ERROR_TABLE_BASE_uae)] = EIO; | |
75 | et2sys[(UAENXIO - ERROR_TABLE_BASE_uae)] = ENXIO; | |
76 | et2sys[(UAE2BIG - ERROR_TABLE_BASE_uae)] = E2BIG; | |
77 | et2sys[(UAENOEXEC - ERROR_TABLE_BASE_uae)] = ENOEXEC; | |
78 | et2sys[(UAEBADF - ERROR_TABLE_BASE_uae)] = EBADF; | |
79 | et2sys[(UAECHILD - ERROR_TABLE_BASE_uae)] = ECHILD; | |
80 | et2sys[(UAEAGAIN - ERROR_TABLE_BASE_uae)] = EAGAIN; | |
81 | et2sys[(UAENOMEM - ERROR_TABLE_BASE_uae)] = ENOMEM; | |
82 | et2sys[(UAEACCES - ERROR_TABLE_BASE_uae)] = EACCES; | |
83 | et2sys[(UAEFAULT - ERROR_TABLE_BASE_uae)] = EFAULT; | |
84 | et2sys[(UAENOTBLK - ERROR_TABLE_BASE_uae)] = ENOTBLK; | |
85 | et2sys[(UAEBUSY - ERROR_TABLE_BASE_uae)] = EBUSY; | |
86 | et2sys[(UAEEXIST - ERROR_TABLE_BASE_uae)] = EEXIST; | |
87 | et2sys[(UAEXDEV - ERROR_TABLE_BASE_uae)] = EXDEV; | |
88 | et2sys[(UAENODEV - ERROR_TABLE_BASE_uae)] = ENODEV; | |
89 | et2sys[(UAENOTDIR - ERROR_TABLE_BASE_uae)] = ENOTDIR; | |
90 | et2sys[(UAEISDIR - ERROR_TABLE_BASE_uae)] = EISDIR; | |
91 | et2sys[(UAEINVAL - ERROR_TABLE_BASE_uae)] = EINVAL; | |
92 | et2sys[(UAENFILE - ERROR_TABLE_BASE_uae)] = ENFILE; | |
93 | et2sys[(UAEMFILE - ERROR_TABLE_BASE_uae)] = EMFILE; | |
94 | et2sys[(UAENOTTY - ERROR_TABLE_BASE_uae)] = ENOTTY; | |
95 | et2sys[(UAETXTBSY - ERROR_TABLE_BASE_uae)] = ETXTBSY; | |
96 | et2sys[(UAEFBIG - ERROR_TABLE_BASE_uae)] = EFBIG; | |
97 | et2sys[(UAENOSPC - ERROR_TABLE_BASE_uae)] = ENOSPC; | |
98 | et2sys[(UAESPIPE - ERROR_TABLE_BASE_uae)] = ESPIPE; | |
99 | et2sys[(UAEROFS - ERROR_TABLE_BASE_uae)] = EROFS; | |
100 | et2sys[(UAEMLINK - ERROR_TABLE_BASE_uae)] = EMLINK; | |
101 | et2sys[(UAEPIPE - ERROR_TABLE_BASE_uae)] = EPIPE; | |
102 | et2sys[(UAEDOM - ERROR_TABLE_BASE_uae)] = EDOM; | |
103 | et2sys[(UAERANGE - ERROR_TABLE_BASE_uae)] = ERANGE; | |
104 | et2sys[(UAEDEADLK - ERROR_TABLE_BASE_uae)] = EDEADLK; | |
105 | et2sys[(UAENAMETOOLONG - ERROR_TABLE_BASE_uae)] = ENAMETOOLONG; | |
106 | et2sys[(UAENOLCK - ERROR_TABLE_BASE_uae)] = ENOLCK; | |
107 | et2sys[(UAENOSYS - ERROR_TABLE_BASE_uae)] = ENOSYS; | |
108 | et2sys[(UAENOTEMPTY - ERROR_TABLE_BASE_uae)] = ENOTEMPTY; | |
109 | et2sys[(UAELOOP - ERROR_TABLE_BASE_uae)] = ELOOP; | |
110 | et2sys[(UAEWOULDBLOCK - ERROR_TABLE_BASE_uae)] = EWOULDBLOCK; | |
111 | et2sys[(UAENOMSG - ERROR_TABLE_BASE_uae)] = ENOMSG; | |
112 | et2sys[(UAEIDRM - ERROR_TABLE_BASE_uae)] = EIDRM; | |
113 | et2sys[(UAECHRNG - ERROR_TABLE_BASE_uae)] = ECHRNG; | |
114 | et2sys[(UAEL2NSYNC - ERROR_TABLE_BASE_uae)] = EL2NSYNC; | |
115 | et2sys[(UAEL3HLT - ERROR_TABLE_BASE_uae)] = EL3HLT; | |
116 | et2sys[(UAEL3RST - ERROR_TABLE_BASE_uae)] = EL3RST; | |
117 | et2sys[(UAELNRNG - ERROR_TABLE_BASE_uae)] = ELNRNG; | |
118 | et2sys[(UAEUNATCH - ERROR_TABLE_BASE_uae)] = EUNATCH; | |
119 | et2sys[(UAENOCSI - ERROR_TABLE_BASE_uae)] = ENOCSI; | |
120 | et2sys[(UAEL2HLT - ERROR_TABLE_BASE_uae)] = EL2HLT; | |
121 | et2sys[(UAEBADE - ERROR_TABLE_BASE_uae)] = EBADE; | |
122 | et2sys[(UAEBADR - ERROR_TABLE_BASE_uae)] = EBADR; | |
123 | et2sys[(UAEXFULL - ERROR_TABLE_BASE_uae)] = EXFULL; | |
124 | et2sys[(UAENOANO - ERROR_TABLE_BASE_uae)] = ENOANO; | |
125 | et2sys[(UAEBADRQC - ERROR_TABLE_BASE_uae)] = EBADRQC; | |
126 | et2sys[(UAEBADSLT - ERROR_TABLE_BASE_uae)] = EBADSLT; | |
127 | et2sys[(UAEBFONT - ERROR_TABLE_BASE_uae)] = EBFONT; | |
128 | et2sys[(UAENOSTR - ERROR_TABLE_BASE_uae)] = ENOSTR; | |
129 | et2sys[(UAENODATA - ERROR_TABLE_BASE_uae)] = ENODATA; | |
130 | et2sys[(UAETIME - ERROR_TABLE_BASE_uae)] = ETIME; | |
131 | et2sys[(UAENOSR - ERROR_TABLE_BASE_uae)] = ENOSR; | |
132 | et2sys[(UAENONET - ERROR_TABLE_BASE_uae)] = ENONET; | |
133 | et2sys[(UAENOPKG - ERROR_TABLE_BASE_uae)] = ENOPKG; | |
134 | et2sys[(UAEREMOTE - ERROR_TABLE_BASE_uae)] = EREMOTE; | |
135 | et2sys[(UAENOLINK - ERROR_TABLE_BASE_uae)] = ENOLINK; | |
136 | et2sys[(UAEADV - ERROR_TABLE_BASE_uae)] = EADV; | |
137 | et2sys[(UAESRMNT - ERROR_TABLE_BASE_uae)] = ESRMNT; | |
138 | et2sys[(UAECOMM - ERROR_TABLE_BASE_uae)] = ECOMM; | |
139 | et2sys[(UAEPROTO - ERROR_TABLE_BASE_uae)] = EPROTO; | |
140 | et2sys[(UAEMULTIHOP - ERROR_TABLE_BASE_uae)] = EMULTIHOP; | |
141 | et2sys[(UAEDOTDOT - ERROR_TABLE_BASE_uae)] = EDOTDOT; | |
142 | et2sys[(UAEBADMSG - ERROR_TABLE_BASE_uae)] = EBADMSG; | |
143 | et2sys[(UAEOVERFLOW - ERROR_TABLE_BASE_uae)] = EOVERFLOW; | |
144 | et2sys[(UAENOTUNIQ - ERROR_TABLE_BASE_uae)] = ENOTUNIQ; | |
145 | et2sys[(UAEBADFD - ERROR_TABLE_BASE_uae)] = EBADFD; | |
146 | et2sys[(UAEREMCHG - ERROR_TABLE_BASE_uae)] = EREMCHG; | |
147 | et2sys[(UAELIBACC - ERROR_TABLE_BASE_uae)] = ELIBACC; | |
148 | et2sys[(UAELIBBAD - ERROR_TABLE_BASE_uae)] = ELIBBAD; | |
149 | et2sys[(UAELIBSCN - ERROR_TABLE_BASE_uae)] = ELIBSCN; | |
150 | et2sys[(UAELIBMAX - ERROR_TABLE_BASE_uae)] = ELIBMAX; | |
151 | et2sys[(UAELIBEXEC - ERROR_TABLE_BASE_uae)] = ELIBEXEC; | |
152 | et2sys[(UAEILSEQ - ERROR_TABLE_BASE_uae)] = EILSEQ; | |
153 | et2sys[(UAERESTART - ERROR_TABLE_BASE_uae)] = ERESTART; | |
154 | et2sys[(UAESTRPIPE - ERROR_TABLE_BASE_uae)] = ESTRPIPE; | |
155 | et2sys[(UAEUSERS - ERROR_TABLE_BASE_uae)] = EUSERS; | |
156 | et2sys[(UAENOTSOCK - ERROR_TABLE_BASE_uae)] = ENOTSOCK; | |
157 | et2sys[(UAEDESTADDRREQ - ERROR_TABLE_BASE_uae)] = EDESTADDRREQ; | |
158 | et2sys[(UAEMSGSIZE - ERROR_TABLE_BASE_uae)] = EMSGSIZE; | |
159 | et2sys[(UAEPROTOTYPE - ERROR_TABLE_BASE_uae)] = EPROTOTYPE; | |
160 | et2sys[(UAENOPROTOOPT - ERROR_TABLE_BASE_uae)] = ENOPROTOOPT; | |
161 | et2sys[(UAEPROTONOSUPPORT - ERROR_TABLE_BASE_uae)] = EPROTONOSUPPORT; | |
162 | et2sys[(UAESOCKTNOSUPPORT - ERROR_TABLE_BASE_uae)] = ESOCKTNOSUPPORT; | |
163 | et2sys[(UAEOPNOTSUPP - ERROR_TABLE_BASE_uae)] = EOPNOTSUPP; | |
164 | et2sys[(UAEPFNOSUPPORT - ERROR_TABLE_BASE_uae)] = EPFNOSUPPORT; | |
165 | et2sys[(UAEAFNOSUPPORT - ERROR_TABLE_BASE_uae)] = EAFNOSUPPORT; | |
166 | et2sys[(UAEADDRINUSE - ERROR_TABLE_BASE_uae)] = EADDRINUSE; | |
167 | et2sys[(UAEADDRNOTAVAIL - ERROR_TABLE_BASE_uae)] = EADDRNOTAVAIL; | |
168 | et2sys[(UAENETDOWN - ERROR_TABLE_BASE_uae)] = ENETDOWN; | |
169 | et2sys[(UAENETUNREACH - ERROR_TABLE_BASE_uae)] = ENETUNREACH; | |
170 | et2sys[(UAENETRESET - ERROR_TABLE_BASE_uae)] = ENETRESET; | |
171 | et2sys[(UAECONNABORTED - ERROR_TABLE_BASE_uae)] = ECONNABORTED; | |
172 | et2sys[(UAECONNRESET - ERROR_TABLE_BASE_uae)] = ECONNRESET; | |
173 | et2sys[(UAENOBUFS - ERROR_TABLE_BASE_uae)] = ENOBUFS; | |
174 | et2sys[(UAEISCONN - ERROR_TABLE_BASE_uae)] = EISCONN; | |
175 | et2sys[(UAENOTCONN - ERROR_TABLE_BASE_uae)] = ENOTCONN; | |
176 | et2sys[(UAESHUTDOWN - ERROR_TABLE_BASE_uae)] = ESHUTDOWN; | |
177 | et2sys[(UAETOOMANYREFS - ERROR_TABLE_BASE_uae)] = ETOOMANYREFS; | |
178 | et2sys[(UAETIMEDOUT - ERROR_TABLE_BASE_uae)] = ETIMEDOUT; | |
179 | et2sys[(UAECONNREFUSED - ERROR_TABLE_BASE_uae)] = ECONNREFUSED; | |
180 | et2sys[(UAEHOSTDOWN - ERROR_TABLE_BASE_uae)] = EHOSTDOWN; | |
181 | et2sys[(UAEHOSTUNREACH - ERROR_TABLE_BASE_uae)] = EHOSTUNREACH; | |
182 | et2sys[(UAEALREADY - ERROR_TABLE_BASE_uae)] = EALREADY; | |
183 | et2sys[(UAEINPROGRESS - ERROR_TABLE_BASE_uae)] = EINPROGRESS; | |
184 | et2sys[(UAESTALE - ERROR_TABLE_BASE_uae)] = ESTALE; | |
185 | et2sys[(UAEUCLEAN - ERROR_TABLE_BASE_uae)] = EUCLEAN; | |
186 | et2sys[(UAENOTNAM - ERROR_TABLE_BASE_uae)] = ENOTNAM; | |
187 | et2sys[(UAENAVAIL - ERROR_TABLE_BASE_uae)] = ENAVAIL; | |
188 | et2sys[(UAEISNAM - ERROR_TABLE_BASE_uae)] = EISNAM; | |
189 | et2sys[(UAEREMOTEIO - ERROR_TABLE_BASE_uae)] = EREMOTEIO; | |
190 | et2sys[(UAEDQUOT - ERROR_TABLE_BASE_uae)] = EDQUOT; | |
191 | et2sys[(UAENOMEDIUM - ERROR_TABLE_BASE_uae)] = ENOMEDIUM; | |
192 | et2sys[(UAEMEDIUMTYPE - ERROR_TABLE_BASE_uae)] = EMEDIUMTYPE; | |
193 | } | |
194 | ||
195 | afs_int32 | |
196 | et_to_sys_error(afs_int32 in) | |
197 | { | |
198 | if (in < ERROR_TABLE_BASE_uae || in >= ERROR_TABLE_BASE_uae + 512) | |
199 | return in; | |
200 | if (et2sys[in - ERROR_TABLE_BASE_uae] != 0) | |
201 | return et2sys[in - ERROR_TABLE_BASE_uae]; | |
202 | return in; | |
203 | } | |
204 | ||
205 | void | |
206 | afs_CopyError(struct vrequest *afrom, struct vrequest *ato) | |
207 | { | |
208 | int i = 0; | |
209 | AFS_STATCNT(afs_CopyError); | |
210 | if (!afrom->initd) | |
211 | return; | |
212 | afs_FinalizeReq(ato); | |
213 | while (i < AFS_MAXHOSTS) { | |
214 | ato->skipserver[i] = afrom->skipserver[i]; | |
215 | ato->lasterror[i] = afrom->lasterror[i]; | |
216 | i++; | |
217 | } | |
218 | if (afrom->tokenError) | |
219 | ato->tokenError = afrom->tokenError; | |
220 | if (afrom->idleError) | |
221 | ato->idleError = afrom->idleError; | |
222 | if (afrom->accessError) | |
223 | ato->accessError = 1; | |
224 | if (afrom->volumeError) | |
225 | ato->volumeError = 1; | |
226 | if (afrom->networkError) | |
227 | ato->networkError = 1; | |
228 | if (afrom->permWriteError) | |
229 | ato->permWriteError = 1; | |
230 | ||
231 | } | |
232 | ||
233 | void | |
234 | afs_FinalizeReq(struct vrequest *areq) | |
235 | { | |
236 | int i = 0; | |
237 | AFS_STATCNT(afs_FinalizeReq); | |
238 | if (areq->initd) | |
239 | return; | |
240 | while (i < AFS_MAXHOSTS) { | |
241 | areq->skipserver[i] = 0; | |
242 | areq->lasterror[i] = 0; | |
243 | i++; | |
244 | } | |
245 | areq->busyCount = 0; | |
246 | areq->idleError = 0; | |
247 | areq->tokenError = 0; | |
248 | areq->accessError = 0; | |
249 | areq->volumeError = 0; | |
250 | areq->networkError = 0; | |
251 | areq->permWriteError = 0; | |
252 | areq->initd = 1; | |
253 | ||
254 | } | |
255 | ||
256 | int | |
257 | afs_CheckCode(afs_int32 acode, struct vrequest *areq, int where) | |
258 | { | |
259 | AFS_STATCNT(afs_CheckCode); | |
260 | if (acode) { | |
261 | afs_Trace2(afs_iclSetp, CM_TRACE_CHECKCODE, ICL_TYPE_INT32, acode, | |
262 | ICL_TYPE_INT32, where); | |
263 | } | |
264 | if ((acode & ~0xff) == ERROR_TABLE_BASE_uae) | |
265 | acode = et_to_sys_error(acode); | |
266 | if (!areq || !areq->initd) | |
267 | return acode; | |
268 | if (areq->networkError) | |
269 | return ETIMEDOUT; | |
270 | if (acode == 0) | |
271 | return 0; | |
272 | if (areq->accessError) | |
273 | return EACCES; | |
274 | if (areq->volumeError == VOLMISSING) | |
275 | return ENODEV; | |
276 | if (areq->volumeError == VOLBUSY) | |
277 | return EWOULDBLOCK; | |
278 | if (acode == VNOVNODE) | |
279 | return EIO; | |
280 | if (acode == VDISKFULL) | |
281 | return ENOSPC; | |
282 | if (acode == VOVERQUOTA) | |
283 | return | |
284 | #ifdef EDQUOT | |
285 | EDQUOT | |
286 | #else | |
287 | ENOSPC | |
288 | #endif | |
289 | ; | |
290 | /* Some fileservers kill overly-idle calls with VNOSERVICE. */ | |
291 | if (acode == VNOSERVICE) | |
292 | return ETIMEDOUT; | |
293 | ||
294 | return acode; | |
295 | ||
296 | } /*afs_CheckCode */ |