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)
86 /* If we had to stop retrying, report our saved error code. */
87 if (reqp && error == CM_ERROR_TIMEDOUT) {
88 if (reqp->accessError)
89 return reqp->accessError;
90 if (reqp->volumeError)
91 return reqp->volumeError;
93 return reqp->rpcError;
98 error = CM_ERROR_TIMEDOUT;
100 error = CM_ERROR_READONLY;
101 else if (error == 20)
102 error = CM_ERROR_NOTDIR;
103 else if (error == 13)
104 error = CM_ERROR_NOACCESS;
106 error = CM_ERROR_NOSUCHFILE;
107 else if (error == 17 /* AIX */
108 || error == 66 /* SunOS 4, Digital UNIX */
109 || error == 93 /* Solaris 2, IRIX */
110 || error == 247) /* HP/UX */
111 error = CM_ERROR_NOTEMPTY;
115 long cm_MapVLRPCError(long error, cm_req_t *reqp)
117 if (error == 0) return 0;
119 /* If we had to stop retrying, report our saved error code. */
120 if (reqp && error == CM_ERROR_TIMEDOUT) {
121 if (reqp->accessError)
122 return reqp->accessError;
123 if (reqp->volumeError)
124 return reqp->volumeError;
126 return reqp->rpcError;
131 error = CM_ERROR_TIMEDOUT;
132 else if (error == VL_NOENT)
133 error = CM_ERROR_NOSUCHVOLUME;
137 cm_space_t *cm_GetSpace(void)
141 if (osi_Once(&cm_utilsOnce)) {
142 lock_InitializeRWLock(&cm_utilsLock, "cm_utilsLock");
143 osi_EndOnce(&cm_utilsOnce);
146 lock_ObtainWrite(&cm_utilsLock);
147 if (tsp = cm_spaceListp) {
148 cm_spaceListp = tsp->nextp;
150 else tsp = (cm_space_t *) malloc(sizeof(cm_space_t));
151 (void) memset(tsp, 0, sizeof(cm_space_t));
152 lock_ReleaseWrite(&cm_utilsLock);
157 void cm_FreeSpace(cm_space_t *tsp)
159 lock_ObtainWrite(&cm_utilsLock);
160 tsp->nextp = cm_spaceListp;
162 lock_ReleaseWrite(&cm_utilsLock);