/*
* Copyright 2000, International Business Machines Corporation and others.
* All Rights Reserved.
- *
+ *
* This software has been released under the terms of the IBM Public
* License. For details, see the LICENSE file in the top-level source
* directory or online at http://www.openafs.org/dl/license10.html
*/
+#include <afsconfig.h>
#include <afs/param.h>
+#include <roken.h>
+
#include <afs/stds.h>
#include <errno.h>
long cm_MapRPCError(long error, cm_req_t *reqp)
{
- if (error == 0)
+ if (error == 0)
return 0;
/* If we had to stop retrying, report our saved error code. */
if (error == RX_CALL_DEAD ||
error == RX_CALL_TIMEOUT ||
- error == RX_RESTARTING)
- error = CM_ERROR_RETRY;
+ error == RX_CALL_BUSY ||
+ error == RX_MSGSIZE ||
+ error == VNOSERVICE)
+ error = CM_ERROR_TIMEDOUT;
+ else if (error == RX_CALL_IDLE)
+ error = EIO;
+ else if (error == RX_INVALID_OPERATION)
+ error = CM_ERROR_INVAL_NET_RESP;
else if (error < 0)
error = CM_ERROR_UNKNOWN;
- else if (error == EROFS)
+ else if (error == EINVAL)
+ error = CM_ERROR_INVAL;
+ else if (error == EROFS)
error = CM_ERROR_READONLY;
- else if (error == EACCES)
+ else if (error == EACCES)
error = CM_ERROR_NOACCESS;
- else if (error == EXDEV)
+ else if (error == EXDEV)
error = CM_ERROR_CROSSDEVLINK;
- else if (error == EEXIST)
+ else if (error == EEXIST)
error = CM_ERROR_EXISTS;
- else if (error == ENOTDIR)
+ else if (error == ENOTDIR)
error = CM_ERROR_NOTDIR;
else if (error == ENOENT)
error = CM_ERROR_NOSUCHFILE;
error = CM_ERROR_QUOTA;
else if (error == VNOVNODE)
error = CM_ERROR_BADFD;
- else if (error == VNOSERVICE || error == VSALVAGE || error == VOFFLINE)
+ else if (error == VSALVAGE || error == VOFFLINE)
error = CM_ERROR_ALLOFFLINE;
+ else if (error == VBUSY || error == VRESTARTING)
+ error = CM_ERROR_ALLBUSY;
else if (error == EISDIR)
return CM_ERROR_ISDIR;
return error;
long cm_MapRPCErrorRmdir(long error, cm_req_t *reqp)
{
- if (error == 0)
+ if (error == 0)
return 0;
/* If we had to stop retrying, report our saved error code. */
if (error == RX_CALL_DEAD ||
error == RX_CALL_TIMEOUT ||
- error == RX_RESTARTING)
- error = CM_ERROR_RETRY;
+ error == RX_CALL_BUSY ||
+ error == RX_CALL_IDLE ||
+ error == RX_MSGSIZE ||
+ error == VNOSERVICE)
+ error = CM_ERROR_TIMEDOUT;
+ else if (error == VNOVNODE)
+ error = CM_ERROR_BADFD;
+ else if (error == VSALVAGE || error == VOFFLINE)
+ error = CM_ERROR_ALLOFFLINE;
+ else if (error == VBUSY || error == VRESTARTING)
+ error = CM_ERROR_ALLBUSY;
+ else if (error == RX_INVALID_OPERATION)
+ error = CM_ERROR_INVAL_NET_RESP;
else if (error < 0)
error = CM_ERROR_UNKNOWN;
- else if (error == EROFS)
+ else if (error == EROFS)
error = CM_ERROR_READONLY;
- else if (error == ENOTDIR)
+ else if (error == ENOTDIR)
error = CM_ERROR_NOTDIR;
- else if (error == EACCES)
+ else if (error == EACCES)
error = CM_ERROR_NOACCESS;
- else if (error == ENOENT)
+ else if (error == ENOENT)
error = CM_ERROR_NOSUCHFILE;
- else if (error == ENOTEMPTY
+ else if (error == EINVAL)
+ error = CM_ERROR_INVAL;
+ else if (error == ENOTEMPTY
+ || error == EEXIST
|| error == 17 /* AIX */
|| error == 66 /* SunOS 4, Digital UNIX */
|| error == 93 /* Solaris 2, IRIX */
|| error == 247) /* HP/UX */
error = CM_ERROR_NOTEMPTY;
return error;
-}
+}
long cm_MapVLRPCError(long error, cm_req_t *reqp)
{
if (error == RX_CALL_DEAD ||
error == RX_CALL_TIMEOUT ||
- error == RX_RESTARTING)
- error = CM_ERROR_RETRY;
+ error == RX_CALL_BUSY ||
+ error == RX_CALL_IDLE ||
+ error == RX_MSGSIZE ||
+ error == VNOSERVICE)
+ error = CM_ERROR_TIMEDOUT;
+ else if (error == RX_INVALID_OPERATION)
+ error = CM_ERROR_INVAL_NET_RESP;
+ else if (error == RX_RESTARTING)
+ error = CM_ERROR_ALLBUSY;
else if (error < 0)
error = CM_ERROR_UNKNOWN;
- else if (error == VL_NOENT || error == VL_BADNAME)
+ else if (error == EINVAL)
+ error = CM_ERROR_INVAL;
+ else if (error == VL_NOENT || error == VL_BADNAME)
error = CM_ERROR_NOSUCHVOLUME;
return error;
}
else tsp = (cm_space_t *) malloc(sizeof(cm_space_t));
(void) memset(tsp, 0, sizeof(cm_space_t));
lock_ReleaseWrite(&cm_utilsLock);
-
+
return tsp;
}
int sawDot = 0;
clientchar_t tc;
int charCount = 0;
-
+
if (namep == NULL || !namep[0])
return 0;
/*
* Number unparsing map for generating 8.3 names;
- * The version taken from DFS was on drugs.
+ * The version taken from DFS was on drugs.
* You can't include '&' and '@' in a file name.
*/
char cm_8Dot3Mapping[42] =
{'0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
- 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'J', 'K',
- 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U',
+ 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'J', 'K',
+ 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U',
'V', 'W', 'X', 'Y', 'Z', '_', '-', '$', '#', '!', '{', '}'
};
int cm_8Dot3MapSize = sizeof(cm_8Dot3Mapping);
*shortNameEndp = shortName;
}
+void cm_Gen8Dot3VolNameW(afs_uint32 cell, afs_uint32 volume,
+ clientchar_t *shortName, clientchar_t **shortNameEndp)
+{
+ clientchar_t number[12];
+ int i, nsize = 0;
+ int validExtension = 0;
+
+ /* Unparse the file's cell and volume numbers */
+ do {
+ number[nsize] = cm_8Dot3Mapping[cell % cm_8Dot3MapSize];
+ nsize++;
+ cell /= cm_8Dot3MapSize;
+ } while (cell);
+ do {
+ number[nsize] = cm_8Dot3Mapping[volume % cm_8Dot3MapSize];
+ nsize++;
+ volume /= cm_8Dot3MapSize;
+ } while (volume && nsize < 8);
+
+ /* Copy uniquifier characters */
+ for (i=0; i < nsize; i++) {
+ *shortName++ = number[i];
+ }
+
+ /* Add extension characters */
+ *shortName++ = '.'; /* copy dot */
+ *shortName++ = 'v';
+ *shortName++ = 'o';
+ *shortName++ = 'l';
+
+ /* Trailing null */
+ *shortName = 0;
+
+ if (shortNameEndp)
+ *shortNameEndp = shortName;
+}
+
/*! \brief Compare 'pattern' (containing metacharacters '*' and '?') with the file name 'name'.
\note This procedure works recursively calling itself.
\return BOOL : TRUE/FALSE (match/mistmatch)
*/
-static BOOL
-szWildCardMatchFileName(clientchar_t * pattern, clientchar_t * name, int casefold)
+static BOOL
+szWildCardMatchFileName(clientchar_t * pattern, clientchar_t * name, int casefold)
{
clientchar_t upattern[MAX_PATH];
clientchar_t uname[MAX_PATH];
/* do a case-folding search of the star name mask with the name in namep.
* Return 1 if we match, otherwise 0.
*/
-int cm_MatchMask(clientchar_t *namep, clientchar_t *maskp, int flags)
+int cm_MatchMask(clientchar_t *namep, clientchar_t *maskp, int flags)
{
clientchar_t *newmask, lastchar = _C('\0');
int i, j, casefold, retval;
int star = 0, qmark = 0, dot = 0;
/* make sure we only match 8.3 names, if requested */
- if ((flags & CM_FLAG_8DOT3) && !cm_Is8Dot3(namep))
+ if ((flags & CM_FLAG_8DOT3) && !cm_Is8Dot3(namep))
return 0;
casefold = (flags & CM_FLAG_CASEFOLD) ? 1 : 0;
return FALSE;
}
-HANDLE
+HANDLE
cm_LoadAfsdHookLib(void)
{
char dllname[260];
typedef BOOL (WINAPI *LPFN_DISABLEWOW64FSREDIRECTION) (PVOID *);
typedef BOOL (WINAPI *LPFN_REVERTWOW64FSREDIRECTION) (PVOID);
-BOOL msftSMBRedirectorSupportsExtendedTimeouts(void)
+BOOL msftSMBRedirectorSupportsExtendedTimeouts(void)
{
static BOOL fChecked = FALSE;
static BOOL fSupportsExtendedTimeouts = FALSE;
LARGE_INTEGER fvFile, fvHotFixMin;
h1 = GetModuleHandle("kernel32.dll"); /* no refcount increase */
- /*
+ /*
* If we don't find the fnIsWow64Process function then we
* are not running in a Wow64 environment
*/
Version.dwOSVersionInfoSize = sizeof(Version);
GetVersionEx((OSVERSIONINFO *) &Version);
- /*
+ /*
* Support is available as hot fixes / service packs on:
* XP SP2
* XP SP3
/* 32-bit XP */
if (Version.dwMajorVersion == 5 &&
Version.dwMinorVersion == 1) {
-
+
fvHotFixMin.HighPart = (5 << 16) | 1;
switch (Version.wServicePackMajor) {
/* 64-bit XP and Server 2003 */
else if (Version.dwMajorVersion == 5 &&
Version.dwMinorVersion == 2) {
-
+
fvHotFixMin.HighPart = (5 << 16) | 2;
switch (Version.wServicePackMajor) {
/* Vista and Server 2008 */
else if (Version.dwMajorVersion == 6 &&
Version.dwMinorVersion == 0) {
-
+
fvHotFixMin.HighPart = (6 << 16) | 0;
switch (Version.wServicePackMajor) {
}
/* If wow64, disable wow64 redirection and preserve the existing state */
- if (fnIsWow64Process &&
+ if (fnIsWow64Process &&
fnIsWow64Process(GetCurrentProcess(), &isWow64) &&
isWow64) {
fnDisableWow64FsRedirection =
(LPFN_REVERTWOW64FSREDIRECTION)GetProcAddress(h1, "Wow64RevertWow64FsRedirection");
fnDisableWow64FsRedirection(&Wow64RedirectionState);
}
-
+
if (cm_GetOSFileVersion("drivers\\mrxsmb.sys", &fvFile) ||
(fvFile.QuadPart >= fvHotFixMin.QuadPart))
fSupportsExtendedTimeouts = TRUE;
/* If wow64, restore the previous redirection state */
if (fnIsWow64Process && isWow64) {
fnRevertWow64FsRedirection(Wow64RedirectionState);
- }
+ }
}
checked:
fChecked = TRUE;
if (!TlsSetValue(cm_TlsRequestSlot, tp))
free(tp);
- }
+ }
}
void cm_UpdateServerPriority()
-{
+{
time_t *tp = TlsGetValue(cm_TlsRequestSlot);
if (tp) {
void cm_LargeSearchTimeFromUnixTime(FILETIME *largeTimep, time_t unixTime)
{
// Note that LONGLONG is a 64-bit value
- LONGLONG ll;
-
- ll = Int32x32To64(unixTime, 10000000) + 116444736000000000;
- largeTimep->dwLowDateTime = (DWORD)(ll & 0xFFFFFFFF);
- largeTimep->dwHighDateTime = (DWORD)(ll >> 32);
+ LARGE_INTEGER ll;
+
+#ifdef _USE_32BIT_TIME_T
+ ll.QuadPart = UInt32x32To64(unixTime, 10000000) + 116444736000000000;
+#else
+ ll.QuadPart = unixTime * 10000000 + 116444736000000000;
+#endif
+ largeTimep->dwLowDateTime = ll.LowPart;
+ largeTimep->dwHighDateTime = ll.HighPart;
}
void cm_UnixTimeFromLargeSearchTime(time_t *unixTimep, FILETIME *largeTimep)
{
// Note that LONGLONG is a 64-bit value
- LONGLONG ll;
+ LARGE_INTEGER ll;
- ll = largeTimep->dwHighDateTime;
- ll <<= 32;
- ll += largeTimep->dwLowDateTime;
+ ll.HighPart = largeTimep->dwHighDateTime;
+ ll.LowPart = largeTimep->dwLowDateTime;
- ll -= 116444736000000000;
- ll /= 10000000;
+ ll.QuadPart -= 116444736000000000;
+ ll.QuadPart /= 10000000;
- *unixTimep = (DWORD)ll;
+ *unixTimep = (time_t)ll.QuadPart;
}
void cm_SearchTimeFromUnixTime(afs_uint32 *searchTimep, time_t unixTime)
localJunk.tm_hour = 0;
localJunk.tm_min = 0;
localJunk.tm_sec = 0;
- }
+ }
dosDate = ((ltp->tm_year-80)<<9) | ((ltp->tm_mon+1) << 5) | (ltp->tm_mday);
dosTime = (ltp->tm_hour<<11) | (ltp->tm_min << 5) | (ltp->tm_sec / 2);
*searchTimep = (dosDate<<16) | dosTime;
-}
+}
void cm_UnixTimeFromSearchTime(time_t *unixTimep, afs_uint32 searchTime)
{
unsigned short dosDate;
unsigned short dosTime;
struct tm localTm;
-
+
dosDate = (unsigned short) (searchTime & 0xffff);
dosTime = (unsigned short) ((searchTime >> 16) & 0xffff);
*unixTimep = mktime(&localTm);
}
+
+afs_uint32
+cm_NextHighestPowerOf2(afs_uint32 n)
+{
+ n--;
+ n |= n >> 1;
+ n |= n >> 2;
+ n |= n >> 4;
+ n |= n >> 8;
+ n |= n >> 16;
+ n++;
+ return n;
+}