2 * Copyright 2000, International Business Machines Corporation and others.
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
10 #include <afs/param.h>
25 static osi_once_t cm_utilsOnce;
27 osi_rwlock_t cm_utilsLock;
29 cm_space_t *cm_spaceListp;
31 long cm_MapRPCError(long error, cm_req_t *reqp)
36 /* If we had to stop retrying, report our saved error code. */
37 if (reqp && error == CM_ERROR_TIMEDOUT) {
38 if (reqp->accessError)
39 return reqp->accessError;
40 if (reqp->volumeError)
41 return reqp->volumeError;
43 return reqp->rpcError;
48 error = CM_ERROR_TIMEDOUT;
50 error = CM_ERROR_READONLY;
52 error = CM_ERROR_NOACCESS;
54 error = CM_ERROR_CROSSDEVLINK;
56 error = CM_ERROR_EXISTS;
58 error = CM_ERROR_NOTDIR;
60 error = CM_ERROR_NOSUCHFILE;
61 else if (error == 11 /* EAGAIN, most servers */
62 || error == 35) /* EAGAIN, Digital UNIX */
63 error = CM_ERROR_WOULDBLOCK;
64 else if (error == VDISKFULL
65 || error == 28) /* ENOSPC */
66 error = CM_ERROR_SPACE;
67 else if (error == VOVERQUOTA
68 || error == 49 /* EDQUOT on Solaris */
69 || error == 88 /* EDQUOT on AIX */
70 || error == 69 /* EDQUOT on Digital UNIX and HPUX */
71 || error == 122 /* EDQUOT on Linux */
72 || error == 1133) /* EDQUOT on Irix */
73 error = CM_ERROR_QUOTA;
74 else if (error == VNOVNODE)
75 error = CM_ERROR_BADFD;
77 return CM_ERROR_ISDIR;
81 long cm_MapRPCErrorRmdir(long error, cm_req_t *reqp)
83 if (error == 0) return 0;
85 /* If we had to stop retrying, report our saved error code. */
86 if (reqp && error == CM_ERROR_TIMEDOUT) {
87 if (reqp->accessError)
88 return reqp->accessError;
89 if (reqp->volumeError)
90 return reqp->volumeError;
92 return reqp->rpcError;
97 error = CM_ERROR_TIMEDOUT;
99 error = CM_ERROR_READONLY;
100 else if (error == 20)
101 error = CM_ERROR_NOTDIR;
102 else if (error == 13)
103 error = CM_ERROR_NOACCESS;
105 error = CM_ERROR_NOSUCHFILE;
106 else if (error == 17 /* AIX */
107 || error == 66 /* SunOS 4, Digital UNIX */
108 || error == 93 /* Solaris 2, IRIX */
109 || error == 247) /* HP/UX */
110 error = CM_ERROR_NOTEMPTY;
114 long cm_MapVLRPCError(long error, cm_req_t *reqp)
116 if (error == 0) return 0;
118 /* If we had to stop retrying, report our saved error code. */
119 if (reqp && error == CM_ERROR_TIMEDOUT) {
120 if (reqp->accessError)
121 return reqp->accessError;
122 if (reqp->volumeError)
123 return reqp->volumeError;
125 return reqp->rpcError;
130 error = CM_ERROR_TIMEDOUT;
131 else if (error == VL_NOENT)
132 error = CM_ERROR_NOSUCHVOLUME;
136 cm_space_t *cm_GetSpace(void)
140 if (osi_Once(&cm_utilsOnce)) {
141 lock_InitializeRWLock(&cm_utilsLock, "cm_utilsLock");
142 osi_EndOnce(&cm_utilsOnce);
145 lock_ObtainWrite(&cm_utilsLock);
146 if (tsp = cm_spaceListp) {
147 cm_spaceListp = tsp->nextp;
149 else tsp = (cm_space_t *) malloc(sizeof(cm_space_t));
150 (void) memset(tsp, 0, sizeof(cm_space_t));
151 lock_ReleaseWrite(&cm_utilsLock);
156 void cm_FreeSpace(cm_space_t *tsp)
158 lock_ObtainWrite(&cm_utilsLock);
159 tsp->nextp = cm_spaceListp;
161 lock_ReleaseWrite(&cm_utilsLock);