Windows: print the value of cm_OfflineROIsValid to afsd_init.log
[openafs.git] / src / WINNT / afsd / afsd_init.c
index ca7c985..80d3914 100644 (file)
 
 #include <osi.h>
 #include "afsd.h"
+#ifdef USE_BPLUS
+#include "cm_btree.h"
+#endif
 #include <rx\rx.h>
 #include <rx\rx_null.h>
+#include <rx\rxstat.h>
 #include <WINNT/syscfg.h>
 #include <WINNT/afsreg.h>
+#include <afs\afscbint.h>
 
 #include "smb.h"
 #include "cm_rpc.h"
 #include "lanahelper.h"
 #include <strsafe.h>
 #include "cm_memmap.h"
+#include "msrpc.h"
+#ifdef DEBUG
+#include <crtdbg.h>
+#endif
 
-extern int RXAFSCB_ExecuteRequest(struct rx_call *z_call);
-extern int RXSTATS_ExecuteRequest(struct rx_call *z_call);
-
-extern afs_int32 cryptall;
+extern afs_uint32 cryptall;
+extern afs_uint32 cm_anonvldb;
 extern int cm_enableServerLocks;
+extern int cm_followBackupPath;
 extern int cm_deleteReadOnly;
+#ifdef USE_BPLUS
 extern afs_int32 cm_BPlusTrees;
-extern const char **smb_ExecutableExtensions;
+#endif
+extern afs_int32 cm_OfflineROIsValid;
+extern afs_int32 cm_giveUpAllCBs;
+extern const clientchar_t **smb_ExecutableExtensions;
 
 osi_log_t *afsd_logp;
 
 cm_config_data_t        cm_data;
 
-char cm_rootVolumeName[VL_MAXNAMELEN];
+fschar_t cm_rootVolumeName[VL_MAXNAMELEN];
 DWORD cm_rootVolumeNameLen;
-char cm_mountRoot[1024];
+
+fschar_t cm_mountRoot[1024];
 DWORD cm_mountRootLen;
+
+clientchar_t cm_mountRootC[1024];
+DWORD cm_mountRootCLen;
+
+int cm_readonlyVolumeVersioning = 0;
 int cm_logChunkSize;
 int cm_chunkSize;
-#ifdef AFS_FREELANCE_CLIENT
-char *cm_FakeRootDir;
-#endif /* freelance */
 
 int smb_UseV3 = 1;
 
@@ -72,19 +87,19 @@ char cm_HostName[200];
 long cm_HostAddr;
 unsigned short cm_callbackport = CM_DEFAULT_CALLBACKPORT;
 
-char cm_NetbiosName[MAX_NB_NAME_LENGTH] = "";
+char cm_NetbiosName[MAX_NB_NAME_LENGTH] = "NOT.YET.SET";
+clientchar_t cm_NetbiosNameC[MAX_NB_NAME_LENGTH] = _C("NOT.YET.SET");
 
 char cm_CachePath[MAX_PATH];
-DWORD cm_CachePathLen;
 DWORD cm_ValidateCache = 1;
 
 BOOL reportSessionStartups = FALSE;
 
 cm_initparams_v1 cm_initParams;
 
-char *cm_sysName = 0;
-unsigned int   cm_sysNameCount = 0;
-char *cm_sysNameList[MAXNUMSYSNAMES];
+clientchar_t *cm_sysName = 0;
+unsigned int  cm_sysNameCount = 0;
+clientchar_t *cm_sysNameList[MAXNUMSYSNAMES];
 
 DWORD TraceOption = 0;
 
@@ -98,9 +113,7 @@ DWORD TraceOption = 0;
 
 HANDLE afsi_file;
 
-#ifdef AFS_AFSDB_ENV
 int cm_dnsEnabled = 1;
-#endif
 
 
 static int afsi_log_useTimestamp = 1;
@@ -129,12 +142,6 @@ afsi_log(char *pattern, ...)
     }
 }
 
-extern initUpperCaseTable();
-void afsd_initUpperCaseTable() 
-{
-    initUpperCaseTable();
-}
-
 void
 afsi_start()
 {
@@ -232,159 +239,6 @@ void afsd_ForceTrace(BOOL flush)
     CloseHandle(handle);
 }
 
-static void
-configureBackConnectionHostNames(void)
-{
-    /* On Windows XP SP2, Windows 2003 SP1, and all future Windows operating systems
-     * there is a restriction on the use of SMB authentication on loopback connections.
-     * There are two work arounds available:
-     * 
-     *   (1) We can disable the check for matching host names.  This does not
-     *   require a reboot:
-     *   [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Lsa]
-     *     "DisableLoopbackCheck"=dword:00000001
-     *
-     *   (2) We can add the AFS SMB/CIFS service name to an approved list.  This
-     *   does require a reboot:
-     *   [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Lsa\MSV1_0]
-     *     "BackConnectionHostNames"=multi-sz
-     *
-     * The algorithm will be:
-     *   (1) Check to see if cm_NetbiosName exists in the BackConnectionHostNames list
-     *   (2a) If not, add it to the list.  (This will not take effect until the next reboot.)
-     *   (2b1)    and check to see if DisableLoopbackCheck is set.
-     *   (2b2)    If not set, set the DisableLoopbackCheck value to 0x1 
-     *   (2b3)                and create HKLM\SOFTWARE\OpenAFS\Client  UnsetDisableLoopbackCheck
-     *   (2c) else If cm_NetbiosName exists in the BackConnectionHostNames list,
-     *             check for the UnsetDisableLoopbackCheck value.  
-     *             If set, set the DisableLoopbackCheck flag to 0x0 
-     *             and delete the UnsetDisableLoopbackCheck value
-     *
-     * Starting in Longhorn Beta 1, an entry in the BackConnectionHostNames value will
-     * force Windows to use the loopback authentication mechanism for the specified 
-     * services.
-     */
-    HKEY hkLsa;
-    HKEY hkMSV10;
-    HKEY hkClient;
-    DWORD dwType;
-    DWORD dwSize, dwAllocSize;
-    DWORD dwValue;
-    PBYTE pHostNames = NULL, pName = NULL;
-    BOOL  bNameFound = FALSE;   
-
-    if ( RegOpenKeyEx( HKEY_LOCAL_MACHINE, 
-                       "SYSTEM\\CurrentControlSet\\Control\\Lsa\\MSV1_0",
-                       0,
-                       KEY_READ|KEY_WRITE,
-                       &hkMSV10) == ERROR_SUCCESS )
-    {
-        if ((RegQueryValueEx( hkMSV10, "BackConnectionHostNames", 0, 
-                            &dwType, NULL, &dwAllocSize) == ERROR_SUCCESS) &&
-            (dwType == REG_MULTI_SZ)) 
-        {
-           dwAllocSize += 1 /* in case the source string is not nul terminated */
-               + strlen(cm_NetbiosName) + 2;
-           pHostNames = malloc(dwAllocSize);
-           dwSize = dwAllocSize;
-            if (RegQueryValueEx( hkMSV10, "BackConnectionHostNames", 0, &dwType, 
-                                pHostNames, &dwSize) == ERROR_SUCCESS) 
-            {
-               for (pName = pHostNames; 
-                    (pName - pHostNames < dwSize) && *pName ; 
-                    pName += strlen(pName) + 1)
-               {
-                   if ( !stricmp(pName, cm_NetbiosName) ) {
-                       bNameFound = TRUE;
-                       break;
-                   }   
-               }
-           }
-        }
-             
-        if ( !bNameFound ) {
-            size_t size = strlen(cm_NetbiosName) + 2;
-            if ( !pHostNames ) {
-                pHostNames = malloc(size);
-               pName = pHostNames;
-            }
-            StringCbCopyA(pName, size, cm_NetbiosName);
-            pName += size - 1;
-            *pName = '\0';  /* add a second nul terminator */
-
-            dwType = REG_MULTI_SZ;
-           dwSize = pName - pHostNames + 1;
-            RegSetValueEx( hkMSV10, "BackConnectionHostNames", 0, dwType, pHostNames, dwSize);
-
-            if ( RegOpenKeyEx( HKEY_LOCAL_MACHINE, 
-                               "SYSTEM\\CurrentControlSet\\Control\\Lsa",
-                               0,
-                               KEY_READ|KEY_WRITE,
-                               &hkLsa) == ERROR_SUCCESS )
-            {
-                dwSize = sizeof(DWORD);
-                if ( RegQueryValueEx( hkLsa, "DisableLoopbackCheck", 0, &dwType, (LPBYTE)&dwValue, &dwSize) != ERROR_SUCCESS ||
-                     dwValue == 0 ) {
-                    dwType = REG_DWORD;
-                    dwSize = sizeof(DWORD);
-                    dwValue = 1;
-                    RegSetValueEx( hkLsa, "DisableLoopbackCheck", 0, dwType, (LPBYTE)&dwValue, dwSize);
-
-                    if (RegCreateKeyEx( HKEY_LOCAL_MACHINE, 
-                                        AFSREG_CLT_OPENAFS_SUBKEY,
-                                        0,
-                                        NULL,
-                                        REG_OPTION_NON_VOLATILE,
-                                        KEY_READ|KEY_WRITE,
-                                        NULL,
-                                        &hkClient,
-                                        NULL) == ERROR_SUCCESS) {
-
-                        dwType = REG_DWORD;
-                        dwSize = sizeof(DWORD);
-                        dwValue = 1;
-                        RegSetValueEx( hkClient, "RemoveDisableLoopbackCheck", 0, dwType, (LPBYTE)&dwValue, dwSize);
-                        RegCloseKey(hkClient);
-                    }
-                    RegCloseKey(hkLsa);
-                }
-            }
-        } else {
-            if (RegCreateKeyEx( HKEY_LOCAL_MACHINE, 
-                                AFSREG_CLT_OPENAFS_SUBKEY,
-                                0,
-                                NULL,
-                                REG_OPTION_NON_VOLATILE,
-                                KEY_READ|KEY_WRITE,
-                                NULL,
-                                &hkClient,
-                                NULL) == ERROR_SUCCESS) {
-
-                dwSize = sizeof(DWORD);
-                if ( RegQueryValueEx( hkClient, "RemoveDisableLoopbackCheck", 0, &dwType, (LPBYTE)&dwValue, &dwSize) == ERROR_SUCCESS &&
-                     dwValue == 1 ) {
-                    if ( RegOpenKeyEx( HKEY_LOCAL_MACHINE, 
-                                       "SYSTEM\\CurrentControlSet\\Control\\Lsa",
-                                       0,
-                                       KEY_READ|KEY_WRITE,
-                                       &hkLsa) == ERROR_SUCCESS )
-                    {
-                        RegDeleteValue(hkLsa, "DisableLoopbackCheck");
-                        RegCloseKey(hkLsa);
-                    }
-                }
-                RegDeleteValue(hkClient, "RemoveDisableLoopbackCheck");
-                RegCloseKey(hkClient);
-            }
-        }
-        RegCloseKey(hkMSV10);
-    }
-
-    if (pHostNames)
-       free(pHostNames);
-}
-
-
 static void afsd_InitServerPreferences(void)
 {
     HKEY hkPrefs = 0;
@@ -442,13 +296,18 @@ static void afsd_InitServerPreferences(void)
 
                 saddr.sin_addr.S_un.S_addr = *(unsigned long *)pEntry->h_addr;
             }
+            saddr.sin_port = htons(7003);
             saddr.sin_family = AF_INET;
             dwRank += (rand() & 0x000f);
 
             tsp = cm_FindServer(&saddr, CM_SERVER_VLDB);
             if ( tsp )         /* an existing server - ref count increased */
             {
-                tsp->ipRank = (USHORT)dwRank; /* no need to protect by mutex*/
+                lock_ObtainMutex(&tsp->mx);
+                tsp->ipRank = (USHORT)dwRank;
+                tsp->flags |= CM_SERVERFLAG_PREF_SET;
+               tsp->adminRank = tsp->ipRank;
+                lock_ReleaseMutex(&tsp->mx);
 
                 /* set preferences for an existing vlserver */
                 cm_ChangeRankCellVLServer(tsp);
@@ -456,8 +315,12 @@ static void afsd_InitServerPreferences(void)
             }
             else       /* add a new server without a cell */
             {
-                tsp = cm_NewServer(&saddr, CM_SERVER_VLDB, NULL); /* refcount = 1 */
+                tsp = cm_NewServer(&saddr, CM_SERVER_VLDB, NULL, NULL, CM_FLAG_NOPROBE); /* refcount = 1 */
+                lock_ObtainMutex(&tsp->mx);
                 tsp->ipRank = (USHORT)dwRank;
+                tsp->flags |= CM_SERVERFLAG_PREF_SET;
+               tsp->adminRank = tsp->ipRank;
+                lock_ReleaseMutex(&tsp->mx);
             }
         }
 
@@ -509,13 +372,18 @@ static void afsd_InitServerPreferences(void)
 
                 saddr.sin_addr.S_un.S_addr = *(unsigned long *)pEntry->h_addr;
             }
+            saddr.sin_port = htons(7000);
             saddr.sin_family = AF_INET;
             dwRank += (rand() & 0x000f);
 
             tsp = cm_FindServer(&saddr, CM_SERVER_FILE);
             if ( tsp )         /* an existing server - ref count increased */
             {
-                tsp->ipRank = (USHORT)dwRank; /* no need to protect by mutex*/
+                lock_ObtainMutex(&tsp->mx);
+                tsp->ipRank = (USHORT)dwRank;
+               tsp->flags |= CM_SERVERFLAG_PREF_SET;
+               tsp->adminRank = tsp->ipRank;
+                lock_ReleaseMutex(&tsp->mx);
 
                 /* find volumes which might have RO copy 
                 /* on server and change the ordering of 
@@ -526,8 +394,12 @@ static void afsd_InitServerPreferences(void)
             }
             else       /* add a new server without a cell */
             {
-                tsp = cm_NewServer(&saddr, CM_SERVER_FILE, NULL); /* refcount = 1 */
+                tsp = cm_NewServer(&saddr, CM_SERVER_FILE, NULL, NULL, CM_FLAG_NOPROBE); /* refcount = 1 */
+                lock_ObtainMutex(&tsp->mx);
                 tsp->ipRank = (USHORT)dwRank;
+                tsp->flags |= CM_SERVERFLAG_PREF_SET;
+               tsp->adminRank = tsp->ipRank;
+                lock_ReleaseMutex(&tsp->mx);
             }
         }
 
@@ -535,11 +407,84 @@ static void afsd_InitServerPreferences(void)
     }
 }
 
+
+#ifndef _WIN64
+typedef BOOL (WINAPI *LPFN_ISWOW64PROCESS) (HANDLE, PBOOL);
+
+static BOOL
+is_wow64(void)
+{
+    static BOOL bChecked = FALSE;
+    static BOOL bIsWow64 = FALSE;
+
+    if (!bChecked)
+    {
+        HANDLE h1 = NULL;
+        LPFN_ISWOW64PROCESS fnIsWow64Process = NULL;
+
+        h1 = GetModuleHandle("kernel32.dll");
+        fnIsWow64Process =
+            (LPFN_ISWOW64PROCESS)GetProcAddress(h1, "IsWow64Process");
+
+        /* If we don't find the fnIsWow64Process function then we
+         * are not running in a broken Wow64
+         */
+        if (fnIsWow64Process)
+            fnIsWow64Process(GetCurrentProcess(), &bIsWow64);
+
+        bChecked = TRUE;
+    }
+
+    return bIsWow64;
+}
+#endif /* _WIN64 */
+
 /*
  * AFSD Initialization
  */
 
-int afsd_InitCM(char **reasonP)
+static int
+afsd_InitRoot(char **reasonP)
+{
+    long code;
+    cm_req_t req;
+
+    cm_InitReq(&req);
+
+    if (cm_freelanceEnabled) {
+        cm_FakeRootFid(&cm_data.rootFid);
+    } else {
+       int attempts = 10;
+
+        osi_Log0(afsd_logp, "Loading Root Volume from cell");
+       do {
+           code = cm_FindVolumeByName(cm_data.rootCellp, cm_rootVolumeName, cm_rootUserp,
+                                      &req, CM_GETVOL_FLAG_CREATE, &cm_data.rootVolumep);
+           afsi_log("cm_FindVolumeByName code %x root vol %x", code,
+                     (code ? (cm_volume_t *)-1 : cm_data.rootVolumep));
+       } while (code && --attempts);
+        if (code != 0) {
+            *reasonP = "can't find root volume in root cell";
+            return -1;
+        }
+
+        /* compute the root fid */
+        cm_SetFid(&cm_data.rootFid, cm_data.rootCellp->cellID, cm_GetROVolumeID(cm_data.rootVolumep), 1, 1);
+    }
+
+    code = cm_GetSCache(&cm_data.rootFid, &cm_data.rootSCachep, cm_rootUserp, &req);
+    afsi_log("cm_GetSCache code %x scache %x", code,
+             (code ? (cm_scache_t *)-1 : cm_data.rootSCachep));
+    if (code != 0) {
+        *reasonP = "unknown error";
+        return -1;
+    }
+
+    return 0;
+}
+
+int
+afsd_InitCM(char **reasonP)
 {
     osi_uid_t debugID;
     afs_uint64 cacheBlocks;
@@ -547,15 +492,22 @@ int afsd_InitCM(char **reasonP)
     DWORD blockSize;
     long logChunkSize;
     DWORD stats;
+    DWORD volumes;
+    DWORD cells;
     DWORD dwValue;
-    DWORD rx_enable_peer_stats = 0;
-    DWORD rx_enable_process_stats = 0;
+    DWORD rx_enable_peer_stats;
+    DWORD rx_enable_process_stats;
+    DWORD rx_udpbufsize = -1;
+    DWORD lockOrderValidation;
     long traceBufSize;
     long maxcpus;
     long ltt, ltto;
     long rx_nojumbo;
+    int  rx_max_rwin_size;
+    int  rx_max_swin_size;
+    int  rx_min_peer_timeout;
     long virtualCache = 0;
-    char rootCellName[256];
+    fschar_t rootCellName[256];
     struct rx_service *serverp;
     static struct rx_securityClass *nullServerSecurityClassp;
     struct hostent *thp;
@@ -568,23 +520,32 @@ int afsd_InitCM(char **reasonP)
     /*int freelanceEnabled;*/
     WSADATA WSAjunk;
     int i;
-    char *p, *q; 
     int cm_noIPAddr;         /* number of client network interfaces */
     int cm_IPAddr[CM_MAXINTERFACE_ADDR];    /* client's IP address in host order */
     int cm_SubnetMask[CM_MAXINTERFACE_ADDR];/* client's subnet mask in host order*/
     int cm_NetMtu[CM_MAXINTERFACE_ADDR];    /* client's MTU sizes */
     int cm_NetFlags[CM_MAXINTERFACE_ADDR];  /* network flags */
+    DWORD dwPriority;
 
     WSAStartup(0x0101, &WSAjunk);
 
-    afsd_initUpperCaseTable();
     init_et_to_sys_error();
 
+    cm_utilsInit();
+
     /* setup osidebug server at RPC slot 1000 */
     osi_LongToUID(1000, &debugID);
     code = osi_InitDebug(&debugID);
     afsi_log("osi_InitDebug code %d", code);
 
+#ifndef _WIN64
+    if (is_wow64())
+    {
+        *reasonP = "32-bit OpenAFS Service is incompatible with the WOW64 environment";
+        return -1;
+    }
+#endif
+
     // osi_LockTypeSetDefault("stat"); /* comment this out for speed */
     if (code != 0) {
         if (code == RPC_S_NO_PROTSEQS)
@@ -605,7 +566,7 @@ int afsd_InitCM(char **reasonP)
 
     /* Look up configuration parameters in Registry */
     code = RegOpenKeyEx(HKEY_LOCAL_MACHINE, AFSREG_CLT_SVC_PARAM_SUBKEY,
-                         0, KEY_QUERY_VALUE, &parmKey);
+                        0, KEY_QUERY_VALUE, &parmKey);
     if (code != ERROR_SUCCESS) {
         FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM
                        | FORMAT_MESSAGE_ALLOCATE_BUFFER,
@@ -616,6 +577,29 @@ int afsd_InitCM(char **reasonP)
         osi_panic(buf, __FILE__, __LINE__);
     }
 
+    dummyLen = sizeof(dwPriority);
+    code = RegQueryValueEx(parmKey, "PriorityClass", NULL, NULL,
+                            (BYTE *) &dwPriority, &dummyLen);
+    if (code != ERROR_SUCCESS || dwPriority == 0) {
+        dwPriority = HIGH_PRIORITY_CLASS;
+    }
+    if (dwPriority != GetPriorityClass(GetCurrentProcess()))
+        SetPriorityClass(GetCurrentProcess(), dwPriority);
+    afsi_log("PriorityClass 0x%x", GetPriorityClass(GetCurrentProcess()));
+
+    dummyLen = sizeof(lockOrderValidation);
+    code = RegQueryValueEx(parmKey, "LockOrderValidation", NULL, NULL,
+                            (BYTE *) &lockOrderValidation, &dummyLen);
+    if (code != ERROR_SUCCESS) {
+#ifdef DEBUG
+        lockOrderValidation = 1;
+#else
+        lockOrderValidation = 0;
+#endif
+    }
+    osi_SetLockOrderValidation(lockOrderValidation);
+    afsi_log("Lock Order Validation %s", lockOrderValidation ? "On" : "Off");
+
     dummyLen = sizeof(maxcpus);
     code = RegQueryValueEx(parmKey, "MaxCPUs", NULL, NULL,
                             (BYTE *) &maxcpus, &dummyLen);
@@ -681,6 +665,11 @@ int afsd_InitCM(char **reasonP)
 
     osi_Log0(afsd_logp, "Log init");
 
+    dummyLen = sizeof(smb_monitorReqs);
+    code = RegQueryValueEx(parmKey, "SMBRequestMonitor", NULL, NULL,
+                           (BYTE *) &smb_monitorReqs, &dummyLen);
+    afsi_log("SMB request monitoring is %s", (smb_monitorReqs != 0)? "enabled": "disabled");
+
     dummyLen = sizeof(cacheSize);
     code = RegQueryValueEx(parmKey, "CacheSize", NULL, NULL,
                             (BYTE *) &cacheSize, &dummyLen);
@@ -742,9 +731,11 @@ int afsd_InitCM(char **reasonP)
     dummyLen = sizeof(numBkgD);
     code = RegQueryValueEx(parmKey, "Daemons", NULL, NULL,
                             (BYTE *) &numBkgD, &dummyLen);
-    if (code == ERROR_SUCCESS)
+    if (code == ERROR_SUCCESS) {
+        if (numBkgD > CM_MAX_DAEMONS)
+            numBkgD = CM_MAX_DAEMONS;
         afsi_log("%d background daemons", numBkgD);
-    else {
+    } else {
         numBkgD = CM_CONFIGDEFAULT_DAEMONS;
         afsi_log("Defaulting to %d background daemons", numBkgD);
     }
@@ -763,10 +754,30 @@ int afsd_InitCM(char **reasonP)
     code = RegQueryValueEx(parmKey, "Stats", NULL, NULL,
                             (BYTE *) &stats, &dummyLen);
     if (code == ERROR_SUCCESS)
-        afsi_log("Status cache size %d", stats);
+        afsi_log("Status cache entries: %d", stats);
     else {
         stats = CM_CONFIGDEFAULT_STATS;
-        afsi_log("Default status cache size %d", stats);
+        afsi_log("Default status cache entries: %d", stats);
+    }
+
+    dummyLen = sizeof(volumes);
+    code = RegQueryValueEx(parmKey, "Volumes", NULL, NULL,
+                            (BYTE *) &volumes, &dummyLen);
+    if (code == ERROR_SUCCESS)
+        afsi_log("Volumes cache entries: %d", volumes);
+    else {
+        volumes = CM_CONFIGDEFAULT_STATS / 3;
+        afsi_log("Default volume cache entries: %d", volumes);
+    }
+
+    dummyLen = sizeof(cells);
+    code = RegQueryValueEx(parmKey, "Cells", NULL, NULL,
+                            (BYTE *) &cells, &dummyLen);
+    if (code == ERROR_SUCCESS)
+        afsi_log("Cell cache entries: %d", cells);
+    else {
+        cells = CM_CONFIGDEFAULT_CELLS;
+        afsi_log("Default cell cache entries: %d", cells);
     }
 
     dummyLen = sizeof(ltt);
@@ -791,29 +802,32 @@ int afsd_InitCM(char **reasonP)
 
     dummyLen = sizeof(cm_rootVolumeName);
     code = RegQueryValueEx(parmKey, "RootVolume", NULL, NULL,
-                            cm_rootVolumeName, &dummyLen);
+                            (LPBYTE) cm_rootVolumeName, &dummyLen);
     if (code == ERROR_SUCCESS)
         afsi_log("Root volume %s", cm_rootVolumeName);
     else {
-        StringCbCopyA(cm_rootVolumeName, sizeof(cm_rootVolumeName), "root.afs");
+        cm_FsStrCpy(cm_rootVolumeName, lengthof(cm_rootVolumeName), "root.afs");
         afsi_log("Default root volume name root.afs");
     }
 
-    cm_mountRootLen = sizeof(cm_mountRoot);
-    code = RegQueryValueEx(parmKey, "MountRoot", NULL, NULL,
-                            cm_mountRoot, &cm_mountRootLen);
+    cm_mountRootCLen = sizeof(cm_mountRootC);
+    code = RegQueryValueExW(parmKey, L"MountRoot", NULL, NULL,
+                            (LPBYTE) cm_mountRootC, &cm_mountRootCLen);
     if (code == ERROR_SUCCESS) {
-        afsi_log("Mount root %s", cm_mountRoot);
-        cm_mountRootLen = (DWORD)strlen(cm_mountRoot);
+        afsi_log("Mount root %S", cm_mountRootC);
+        cm_mountRootCLen = (DWORD)cm_ClientStrLen(cm_mountRootC);
     } else {
-        StringCbCopyA(cm_mountRoot, sizeof(cm_mountRoot), "/afs");
-        cm_mountRootLen = 4;
+        cm_ClientStrCpy(cm_mountRootC, lengthof(cm_mountRootC), _C("/afs"));
+        cm_mountRootCLen = (DWORD)cm_ClientStrLen(cm_mountRootC);
         /* Don't log */
     }
 
+    cm_ClientStringToFsString(cm_mountRootC, -1, cm_mountRoot, lengthof(cm_mountRoot));
+    cm_mountRootLen = (DWORD)cm_FsStrLen(cm_mountRoot);
+
     dummyLen = sizeof(buf);
     code = RegQueryValueEx(parmKey, "CachePath", NULL, &regType,
-                            buf, &dummyLen);
+                           buf, &dummyLen);
     if (code == ERROR_SUCCESS && buf[0]) {
         if (regType == REG_EXPAND_SZ) {
             dummyLen = ExpandEnvironmentStrings(buf, cm_CachePath, sizeof(cm_CachePath));
@@ -878,60 +892,68 @@ int afsd_InitCM(char **reasonP)
     }
 
     for ( i=0; i < MAXNUMSYSNAMES; i++ ) {
-        cm_sysNameList[i] = osi_Alloc(MAXSYSNAME);
+        cm_sysNameList[i] = osi_Alloc(MAXSYSNAME * sizeof(clientchar_t));
         cm_sysNameList[i][0] = '\0';
     }
     cm_sysName = cm_sysNameList[0];
 
-    dummyLen = sizeof(buf);
-    code = RegQueryValueEx(parmKey, "SysName", NULL, NULL, buf, &dummyLen);
-    if (code != ERROR_SUCCESS || !buf[0]) {
+    {
+        clientchar_t *p, *q;
+        clientchar_t * cbuf = (clientchar_t *) buf;
+        dummyLen = sizeof(buf);
+        code = RegQueryValueExW(parmKey, L"SysName", NULL, NULL, (LPBYTE) cbuf, &dummyLen);
+        if (code != ERROR_SUCCESS || !cbuf[0]) {
 #if defined(_IA64_)
-        StringCbCopyA(buf, sizeof(buf), "ia64_win64");
+            cm_ClientStrCpy(cbuf, lengthof(buf), _C("ia64_win64"));
 #elif defined(_AMD64_)
-        StringCbCopyA(buf, sizeof(buf), "amd64_win64 x86_win32 i386_w2k");
+            cm_ClientStrCpy(cbuf, lengthof(buf), _C("amd64_win64 x86_win32 i386_w2k"));
 #else /* assume x86 32-bit */
-        StringCbCopyA(buf, sizeof(buf), "x86_win32 i386_w2k i386_nt40");
+            cm_ClientStrCpy(cbuf, lengthof(buf), _C("x86_win32 i386_w2k i386_nt40"));
 #endif
-    }
-    afsi_log("Sys name %s", buf); 
-
-    /* breakup buf into individual search string entries */
-    for (p = q = buf; p < buf + dummyLen; p++)
-    {
-        if (*p == '\0' || isspace(*p)) {
-            memcpy(cm_sysNameList[cm_sysNameCount],q,p-q);
-            cm_sysNameList[cm_sysNameCount][p-q] = '\0';
-            cm_sysNameCount++;
-
-            do {
-                if (*p == '\0')
-                    goto done_sysname;
-                p++;
-            } while (*p == '\0' || isspace(*p));
-            q = p;
-            p--;
+        }
+        afsi_log("Sys name %S", cbuf); 
+
+        /* breakup buf into individual search string entries */
+        for (p = q = cbuf; p < cbuf + dummyLen; p++) {
+            if (*p == '\0' || iswspace(*p)) {
+                memcpy(cm_sysNameList[cm_sysNameCount],q,(p-q) * sizeof(clientchar_t));
+                cm_sysNameList[cm_sysNameCount][p-q] = '\0';
+                cm_sysNameCount++;
+                do {
+                    if (*p == '\0')
+                        goto done_sysname;
+                    p++;
+                } while (*p == '\0' || isspace(*p));
+                q = p;
+                p--;
+            }
         }
     }
   done_sysname:
-    StringCbCopyA(cm_sysName, MAXSYSNAME, cm_sysNameList[0]);
+    cm_ClientStrCpy(cm_sysName, MAXSYSNAME, cm_sysNameList[0]);
 
     dummyLen = sizeof(cryptall);
     code = RegQueryValueEx(parmKey, "SecurityLevel", NULL, NULL,
-                            (BYTE *) &cryptall, &dummyLen);
+                           (BYTE *) &cryptall, &dummyLen);
     if (code == ERROR_SUCCESS) {
-        afsi_log("SecurityLevel is %s", cryptall?"crypt":"clear");
+        afsi_log("SecurityLevel is %s", cryptall == 1?"crypt": cryptall == 2?"auth":"clear");
     } else {
         cryptall = 0;
         afsi_log("Default SecurityLevel is clear");
     }
 
-    if (cryptall)
+    if (cryptall == 1)
        LogEvent(EVENTLOG_INFORMATION_TYPE, MSG_CRYPT_ON);
+    else if (cryptall == 2)
+       LogEvent(EVENTLOG_INFORMATION_TYPE, MSG_CRYPT_AUTH);
     else
        LogEvent(EVENTLOG_INFORMATION_TYPE, MSG_CRYPT_OFF);
 
-#ifdef AFS_AFSDB_ENV
+    dummyLen = sizeof(cryptall);
+    code = RegQueryValueEx(parmKey, "ForceAnonVLDB", NULL, NULL,
+                            (BYTE *) &cm_anonvldb, &dummyLen);
+    afsi_log("CM ForceAnonVLDB is %s", cm_anonvldb ? "on" : "off");
+
     dummyLen = sizeof(cm_dnsEnabled);
     code = RegQueryValueEx(parmKey, "UseDNS", NULL, NULL,
                             (BYTE *) &cm_dnsEnabled, &dummyLen);
@@ -943,23 +965,30 @@ int afsd_InitCM(char **reasonP)
         cm_dnsEnabled = 1;   /* default on */
         afsi_log("Default to use DNS to find AFS cell servers");
     }
-#else /* AFS_AFSDB_ENV */
-    afsi_log("AFS not built with DNS support to find AFS cell servers");
-#endif /* AFS_AFSDB_ENV */
 
 #ifdef AFS_FREELANCE_CLIENT
     dummyLen = sizeof(cm_freelanceEnabled);
     code = RegQueryValueEx(parmKey, "FreelanceClient", NULL, NULL,
                             (BYTE *) &cm_freelanceEnabled, &dummyLen);
-    if (code == ERROR_SUCCESS) {
-        afsi_log("Freelance client feature %s activated",
-                  cm_freelanceEnabled ? "is" : "is not");
-    }       
-    else {
-        cm_freelanceEnabled = 1;  /* default on */
-    }
+    afsi_log("Freelance client feature %s activated",
+              cm_freelanceEnabled ? "is" : "is not");
+
+    dummyLen = sizeof(cm_freelanceImportCellServDB);
+    code = RegQueryValueEx(parmKey, "FreelanceImportCellServDB", NULL, NULL,
+                            (BYTE *) &cm_freelanceImportCellServDB, &dummyLen);
+    afsi_log("Freelance client %s import CellServDB",
+              cm_freelanceImportCellServDB ? "does" : "does not");
 #endif /* AFS_FREELANCE_CLIENT */
 
+    dummyLen = sizeof(smb_UseUnicode);
+    code = RegQueryValueEx(parmKey, "NegotiateUnicode", NULL, NULL,
+                           (BYTE *) &smb_UseUnicode, &dummyLen);
+    if (code != ERROR_SUCCESS) {
+        smb_UseUnicode = 1; /* default on */
+    }
+    afsi_log("SMB Server Unicode Support is %s",
+              smb_UseUnicode ? "enabled" : "disabled");
+
     dummyLen = sizeof(smb_hideDotFiles);
     code = RegQueryValueEx(parmKey, "HideDotFiles", NULL, NULL,
                            (BYTE *) &smb_hideDotFiles, &dummyLen);
@@ -969,6 +998,22 @@ int afsd_InitCM(char **reasonP)
     afsi_log("Dot files/dirs will %sbe marked hidden",
               smb_hideDotFiles ? "" : "not ");
 
+    dummyLen = sizeof(dwValue);
+    code = RegQueryValueEx(parmKey, "UnixModeFileDefault", NULL, NULL,
+                           (BYTE *) &dwValue, &dummyLen);
+    if (code == ERROR_SUCCESS) {
+        smb_unixModeDefaultFile = (dwValue & 07777);
+    }
+    afsi_log("Default unix mode bits for files is 0%04o", smb_unixModeDefaultFile);
+
+    dummyLen = sizeof(dwValue);
+    code = RegQueryValueEx(parmKey, "UnixModeDirDefault", NULL, NULL,
+                           (BYTE *) &dwValue, &dummyLen);
+    if (code == ERROR_SUCCESS) {
+        smb_unixModeDefaultDir = (dwValue & 07777);
+    }
+    afsi_log("Default unix mode bits for directories is 0%04o", smb_unixModeDefaultDir);
+
     dummyLen = sizeof(smb_maxMpxRequests);
     code = RegQueryValueEx(parmKey, "MaxMpxRequests", NULL, NULL,
                            (BYTE *) &smb_maxMpxRequests, &dummyLen);
@@ -995,14 +1040,63 @@ int afsd_InitCM(char **reasonP)
     }
     afsi_log("SMB authentication type is %s", ((smb_authType == SMB_AUTH_NONE)?"NONE":((smb_authType == SMB_AUTH_EXTENDED)?"EXTENDED":"NTLM")));
 
+    dummyLen = sizeof(rx_max_rwin_size);
+    code = RegQueryValueEx(parmKey, "RxMaxRecvWinSize", NULL, NULL,
+                           (BYTE *) &rx_max_rwin_size, &dummyLen);
+    if (code == ERROR_SUCCESS)
+        rx_SetMaxReceiveWindow(rx_max_rwin_size);
+    afsi_log("Rx Maximum Receive Window Size is %d", rx_GetMaxReceiveWindow());
+
+    dummyLen = sizeof(rx_max_swin_size);
+    code = RegQueryValueEx(parmKey, "RxMaxSendWinSize", NULL, NULL,
+                           (BYTE *) &rx_max_swin_size, &dummyLen);
+    if (code == ERROR_SUCCESS)
+        rx_SetMaxSendWindow(rx_max_swin_size);
+    afsi_log("Rx Maximum Send Window Size is %d", rx_GetMaxSendWindow());
+
+    dummyLen = sizeof(rx_min_peer_timeout);
+    code = RegQueryValueEx(parmKey, "RxMinPeerTimeout", NULL, NULL,
+                           (BYTE *) &rx_min_peer_timeout, &dummyLen);
+    if (code == ERROR_SUCCESS)
+        rx_SetMinPeerTimeout(rx_min_peer_timeout);
+    afsi_log("Rx Minimum Peer Timeout is %d ms", rx_GetMinPeerTimeout());
+
     dummyLen = sizeof(rx_nojumbo);
     code = RegQueryValueEx(parmKey, "RxNoJumbo", NULL, NULL,
                            (BYTE *) &rx_nojumbo, &dummyLen);
     if (code != ERROR_SUCCESS) {
-        rx_nojumbo = 0;
+        DWORD jumbo;
+        dummyLen = sizeof(jumbo);
+        code = RegQueryValueEx(parmKey, "RxJumbo", NULL, NULL,
+                                (BYTE *) &jumbo, &dummyLen);
+        if (code != ERROR_SUCCESS) {
+            rx_nojumbo = 1;
+        } else {
+            rx_nojumbo = !jumbo;
+        }
     }
     if (rx_nojumbo)
         afsi_log("RX Jumbograms are disabled");
+    else
+        afsi_log("RX Jumbograms are enabled");
+
+    dummyLen = sizeof(rx_extraPackets);
+    code = RegQueryValueEx(parmKey, "RxExtraPackets", NULL, NULL,
+                           (BYTE *) &rx_extraPackets, &dummyLen);
+    if (code != ERROR_SUCCESS) {
+        rx_extraPackets = (numBkgD + numSvThreads + 5) * 64;
+    }
+    if (rx_extraPackets)
+        afsi_log("RX extraPackets is %d", rx_extraPackets);
+
+    dummyLen = sizeof(rx_udpbufsize);
+    code = RegQueryValueEx(parmKey, "RxUdpBufSize", NULL, NULL,
+                           (BYTE *) &rx_udpbufsize, &dummyLen);
+    if (code != ERROR_SUCCESS) {
+        rx_udpbufsize = 256*1024;
+    }
+    if (rx_udpbufsize != -1)
+        afsi_log("RX udpbufsize is %d", rx_udpbufsize);
 
     dummyLen = sizeof(rx_mtu);
     code = RegQueryValueEx(parmKey, "RxMaxMTU", NULL, NULL,
@@ -1017,19 +1111,34 @@ int afsd_InitCM(char **reasonP)
     code = RegQueryValueEx(parmKey, "RxEnablePeerStats", NULL, NULL,
                            (BYTE *) &rx_enable_peer_stats, &dummyLen);
     if (code != ERROR_SUCCESS) {
-        rx_enable_peer_stats = 0;
+        rx_enable_peer_stats = 1;
     }
     if (rx_enable_peer_stats)
         afsi_log("RX Peer Statistics gathering is enabled");
+    else
+        afsi_log("RX Peer Statistics gathering is disabled");
 
     dummyLen = sizeof(rx_enable_process_stats);
     code = RegQueryValueEx(parmKey, "RxEnableProcessStats", NULL, NULL,
                            (BYTE *) &rx_enable_process_stats, &dummyLen);
     if (code != ERROR_SUCCESS) {
-        rx_enable_process_stats = 0;
+        rx_enable_process_stats = 1;
     }
     if (rx_enable_process_stats)
         afsi_log("RX Process Statistics gathering is enabled");
+    else
+        afsi_log("RX Process Statistics gathering is disabled");
+
+    dummyLen = sizeof(dwValue);
+    dwValue = 0;
+    code = RegQueryValueEx(parmKey, "RxEnableHotThread", NULL, NULL,
+                            (BYTE *) &dwValue, &dummyLen);
+     if (code != ERROR_SUCCESS || dwValue != 0) {
+         rx_EnableHotThread();
+         afsi_log("RX Hot Thread is enabled");
+     }
+     else
+         afsi_log("RX Hot Thread is disabled");
 
     dummyLen = sizeof(DWORD);
     code = RegQueryValueEx(parmKey, "CallBackPort", NULL, NULL,
@@ -1066,6 +1175,7 @@ int afsd_InitCM(char **reasonP)
     } 
     afsi_log("CM DeleteReadOnly is %u", cm_deleteReadOnly);
     
+#ifdef USE_BPLUS
     dummyLen = sizeof(DWORD);
     code = RegQueryValueEx(parmKey, "BPlusTrees", NULL, NULL,
                            (BYTE *) &dwValue, &dummyLen);
@@ -1074,28 +1184,35 @@ int afsd_InitCM(char **reasonP)
     } 
     afsi_log("CM BPlusTrees is %u", cm_BPlusTrees);
 
-    if ((RegQueryValueEx( parmKey, "PrefetchExecutableExtensions", 0, 
-                          &regType, NULL, &dummyLen) == ERROR_SUCCESS) &&
+    if (cm_BPlusTrees && !cm_InitBPlusDir()) {
+        cm_BPlusTrees = 0;
+        afsi_log("CM BPlusTree initialization failure; disabled for this session");
+    }
+#else
+    afsi_log("CM BPlusTrees is not supported");
+#endif
+
+    if ((RegQueryValueExW( parmKey, L"PrefetchExecutableExtensions", 0, 
+                           &regType, NULL, &dummyLen) == ERROR_SUCCESS) &&
          (regType == REG_MULTI_SZ)) 
     {
-        char * pSz;
+        clientchar_t * pSz;
         dummyLen += 3; /* in case the source string is not nul terminated */
         pSz = malloc(dummyLen);
-        if ((RegQueryValueEx( parmKey, "PrefetchExecutableExtensions", 0, &regType, 
-                             pSz, &dummyLen) == ERROR_SUCCESS) &&
+        if ((RegQueryValueExW( parmKey, L"PrefetchExecutableExtensions", 0, &regType, 
+                               (LPBYTE) pSz, &dummyLen) == ERROR_SUCCESS) &&
              (regType == REG_MULTI_SZ))
         {
             int cnt;
-            char * p;
+            clientchar_t * p;
 
-            for (cnt = 0, p = pSz; (p - pSz < dummyLen) && *p; cnt++, p += strlen(p) + 1);
+            for (cnt = 0, p = pSz; (p - pSz < dummyLen) && *p; cnt++, p += cm_ClientStrLen(p) + 1);
 
-            smb_ExecutableExtensions = malloc(sizeof(char *) * (cnt+1));
+            smb_ExecutableExtensions = malloc(sizeof(clientchar_t *) * (cnt+1));
 
-            for (cnt = 0, p = pSz; (p - pSz < dummyLen) && *p; cnt++, p += strlen(p) + 1)
-            {
+            for (cnt = 0, p = pSz; (p - pSz < dummyLen) && *p; cnt++, p += cm_ClientStrLen(p) + 1) {
                 smb_ExecutableExtensions[cnt] = p;
-                afsi_log("PrefetchExecutableExtension: \"%s\"", p);
+                afsi_log("PrefetchExecutableExtension: \"%S\"", p);
             }
             smb_ExecutableExtensions[cnt] = NULL;
         }
@@ -1106,6 +1223,46 @@ int afsd_InitCM(char **reasonP)
     if (!smb_ExecutableExtensions)
         afsi_log("No PrefetchExecutableExtensions");
 
+    dummyLen = sizeof(DWORD);
+    code = RegQueryValueEx(parmKey, "OfflineReadOnlyIsValid", NULL, NULL,
+                           (BYTE *) &dwValue, &dummyLen);
+    if (code == ERROR_SUCCESS) {
+        cm_OfflineROIsValid = (unsigned short) dwValue;
+    } 
+    afsi_log("CM OfflineReadOnlyIsValid is %u", cm_OfflineROIsValid);
+    
+    dummyLen = sizeof(DWORD);
+    code = RegQueryValueEx(parmKey, "GiveUpAllCallBacks", NULL, NULL,
+                           (BYTE *) &dwValue, &dummyLen);
+    if (code == ERROR_SUCCESS) {
+        cm_giveUpAllCBs = (unsigned short) dwValue;
+    } 
+    afsi_log("CM GiveUpAllCallBacks is %u", cm_giveUpAllCBs);
+
+    dummyLen = sizeof(DWORD);
+    code = RegQueryValueEx(parmKey, "FollowBackupPath", NULL, NULL,
+                           (BYTE *) &dwValue, &dummyLen);
+    if (code == ERROR_SUCCESS) {
+        cm_followBackupPath = (unsigned short) dwValue;
+    } 
+    afsi_log("CM FollowBackupPath is %u", cm_followBackupPath);
+
+    dummyLen = sizeof(DWORD);
+    code = RegQueryValueEx(parmKey, "PerFileAccessCheck", NULL, NULL,
+                           (BYTE *) &dwValue, &dummyLen);
+    if (code == ERROR_SUCCESS) {
+        cm_accessPerFileCheck = (int) dwValue;
+    } 
+    afsi_log("CM PerFileAccessCheck is %d", cm_accessPerFileCheck);
+
+    dummyLen = sizeof(DWORD);
+    code = RegQueryValueEx(parmKey, "ReadOnlyVolumeVersioning", NULL, NULL,
+                           (BYTE *) &dwValue, &dummyLen);
+    if (code == ERROR_SUCCESS) {
+        cm_readonlyVolumeVersioning = (unsigned short) dwValue;
+    }
+    afsi_log("CM ReadOnlyVolumeVersioning is %u", cm_readonlyVolumeVersioning);
+
     RegCloseKey (parmKey);
 
     cacheBlocks = ((afs_uint64)cacheSize * 1024) / blockSize;
@@ -1128,16 +1285,13 @@ int afsd_InitCM(char **reasonP)
     cm_initParams.nChunkFiles = 0;
     cm_initParams.nStatCaches = stats;
     cm_initParams.nDataCaches = (afs_uint32)(cacheBlocks > 0xFFFFFFFF ? 0xFFFFFFFF : cacheBlocks);
-    cm_initParams.nVolumeCaches = stats/2;
+    cm_initParams.nVolumeCaches = volumes;
     cm_initParams.firstChunkSize = cm_chunkSize;
     cm_initParams.otherChunkSize = cm_chunkSize;
     cm_initParams.cacheSize = cacheSize;
     cm_initParams.setTime = 0;
     cm_initParams.memCache = 1;
 
-    /* Ensure the AFS Netbios Name is registered to allow loopback access */
-    configureBackConnectionHostNames();
-
     /* init user daemon, and other packages */
     cm_InitUser();
 
@@ -1150,21 +1304,21 @@ int afsd_InitCM(char **reasonP)
     smb_InitIoctl();
         
     cm_InitCallback();
-        
-    code = cm_InitMappedMemory(virtualCache, cm_CachePath, stats, cm_chunkSize, cacheBlocks, blockSize);
+
+    cm_InitNormalization();
+
+    code = cm_InitMappedMemory(virtualCache, cm_CachePath, stats, volumes, cells, cm_chunkSize, cacheBlocks, blockSize);
     afsi_log("cm_InitMappedMemory code %x", code);
     if (code != 0) {
         *reasonP = "error initializing cache file";
         return -1;
     }
 
-#ifdef AFS_AFSDB_ENV
 #if !defined(_WIN32_WINNT) || (_WIN32_WINNT < 0x0500)
     if (cm_InitDNS(cm_dnsEnabled) == -1)
         cm_dnsEnabled = 0;  /* init failed, so deactivate */
     afsi_log("cm_InitDNS %d", cm_dnsEnabled);
 #endif
-#endif
 
     /* Set RX parameters before initializing RX */
     if ( rx_nojumbo ) {
@@ -1173,10 +1327,17 @@ int afsd_InitCM(char **reasonP)
     }
 
     if ( rx_mtu != -1 ) {
+        extern void rx_SetMaxMTU(int);
+
         rx_SetMaxMTU(rx_mtu);
         afsi_log("rx_SetMaxMTU %d successful", rx_mtu);
     }
 
+    if ( rx_udpbufsize != -1 ) {
+        rx_SetUdpBufSize(rx_udpbufsize);
+        afsi_log("rx_SetUdpBufSize %d", rx_udpbufsize);
+    }
+
     /* initialize RX, and tell it to listen to the callbackport, 
      * which is used for callback RPC messages.
      */
@@ -1200,6 +1361,9 @@ int afsd_InitCM(char **reasonP)
         *reasonP = "unknown error";
         return -1;
     }
+    rx_SetMinProcs(serverp, 2);
+    rx_SetMaxProcs(serverp, 4);
+    rx_SetCheckReach(serverp, 1);
 
     nullServerSecurityClassp = rxnull_NewServerSecurityObject();
     serverp = rx_NewService(0, RX_STATS_SERVICE_ID, "rpcstats",
@@ -1209,6 +1373,8 @@ int afsd_InitCM(char **reasonP)
         *reasonP = "unknown error";
         return -1;
     }
+    rx_SetMinProcs(serverp, 2);
+    rx_SetMaxProcs(serverp, 4);
         
     /* start server threads, *not* donating this one to the pool */
     rx_StartServer(0);
@@ -1222,10 +1388,10 @@ int afsd_InitCM(char **reasonP)
 
     code = cm_GetRootCellName(rootCellName);
     afsi_log("cm_GetRootCellName code %d, cm_freelanceEnabled= %d, rcn= %s", 
-              code, cm_freelanceEnabled, (code ? "<none>" : rootCellName));
+             code, cm_freelanceEnabled, (code ? "<none>" : rootCellName));
     if (code != 0 && !cm_freelanceEnabled) 
     {
-        *reasonP = "can't find root cell name in CellServDB";
+        *reasonP = "can't find root cell name in " AFS_CELLSERVDB;
         return -1;
     }   
     else if (cm_freelanceEnabled)
@@ -1237,7 +1403,7 @@ int afsd_InitCM(char **reasonP)
         afsi_log("cm_GetCell addr %x", PtrToUlong(cm_data.rootCellp));
         if (cm_data.rootCellp == NULL) 
         {
-            *reasonP = "can't find root cell in afsdcell.ini";
+            *reasonP = "can't find root cell in " AFS_CELLSERVDB;
             return -1;
         }
     }
@@ -1250,60 +1416,31 @@ int afsd_InitCM(char **reasonP)
     /* Initialize the RPC server for session keys */
     RpcInit();
 
+    /* Initialize the RPC server for pipe services */
+    MSRPC_Init();
+
     afsd_InitServerPreferences();
-    return 0;
+
+    code = afsd_InitRoot(reasonP);
+
+    return code;
 }
 
 int afsd_ShutdownCM(void)
 {
+    MSRPC_Shutdown();
+
     cm_ReleaseSCache(cm_data.rootSCachep);
 
+    cm_utilsCleanup();
+
+    cm_shutdown = 1;
+
     return 0;
 }
 
 int afsd_InitDaemons(char **reasonP)
 {
-    long code;
-    cm_req_t req;
-
-    cm_InitReq(&req);
-
-    /* this should really be in an init daemon from here on down */
-
-    if (!cm_freelanceEnabled) {
-       int attempts = 10;
-
-        osi_Log0(afsd_logp, "Loading Root Volume from cell");
-       do {
-           code = cm_GetVolumeByName(cm_data.rootCellp, cm_rootVolumeName, cm_rootUserp,
-                                      &req, CM_GETVOL_FLAG_CREATE, &cm_data.rootVolumep);
-           afsi_log("cm_GetVolumeByName code %x root vol %x", code,
-                     (code ? (cm_volume_t *)-1 : cm_data.rootVolumep));
-       } while (code && --attempts);
-        if (code != 0) {
-            *reasonP = "can't find root volume in root cell";
-            return -1;
-        }
-    }
-
-    /* compute the root fid */
-    if (!cm_freelanceEnabled) {
-        cm_data.rootFid.cell = cm_data.rootCellp->cellID;
-        cm_data.rootFid.volume = cm_GetROVolumeID(cm_data.rootVolumep);
-        cm_data.rootFid.vnode = 1;
-        cm_data.rootFid.unique = 1;
-    }
-    else
-        cm_FakeRootFid(&cm_data.rootFid);
-        
-    code = cm_GetSCache(&cm_data.rootFid, &cm_data.rootSCachep, cm_rootUserp, &req);
-    afsi_log("cm_GetSCache code %x scache %x", code,
-             (code ? (cm_scache_t *)-1 : cm_data.rootSCachep));
-    if (code != 0) {
-        *reasonP = "unknown error";
-        return -1;
-    }
-
     cm_InitDaemon(numBkgD);
     afsi_log("cm_InitDaemon complete");
 
@@ -1325,6 +1462,30 @@ int afsd_InitSMB(char **reasonP, void *aMBfunc)
                                 (BYTE *) &dwValue, &dummyLen);
         if (code == ERROR_SUCCESS)
             smb_StoreAnsiFilenames = dwValue ? 1 : 0;
+        afsi_log("StoreAnsiFilenames = %d", smb_StoreAnsiFilenames);
+
+        dummyLen = sizeof(DWORD);
+        code = RegQueryValueEx(parmKey, "EnableSMBAsyncStore", NULL, NULL,
+                                (BYTE *) &dwValue, &dummyLen);
+        if (code == ERROR_SUCCESS)
+            smb_AsyncStore = dwValue == 2 ? 2 : (dwValue ? 1 : 0);
+        afsi_log("EnableSMBAsyncStore = %d", smb_AsyncStore);
+
+        dummyLen = sizeof(DWORD);
+        code = RegQueryValueEx(parmKey, "SMBAsyncStoreSize", NULL, NULL,
+                                (BYTE *) &dwValue, &dummyLen);
+        if (code == ERROR_SUCCESS) {
+            /* Should check for >= blocksize && <= chunksize && round down to multiple of blocksize */
+            if (dwValue > cm_chunkSize)
+                smb_AsyncStoreSize = cm_chunkSize;
+            else if (dwValue <  cm_data.buf_blockSize)
+                smb_AsyncStoreSize = cm_data.buf_blockSize;
+            else
+                smb_AsyncStoreSize = (dwValue & ~(cm_data.buf_blockSize-1));
+        } else 
+            smb_AsyncStoreSize = CM_CONFIGDEFAULT_ASYNCSTORESIZE;
+        afsi_log("SMBAsyncStoreSize = %d", smb_AsyncStoreSize);
+        
         RegCloseKey (parmKey);
     }
 
@@ -1353,7 +1514,6 @@ int afsd_InitSMB(char **reasonP, void *aMBfunc)
 
 void afsd_printStack(HANDLE hThread, CONTEXT *c)
 {
-#if defined(_X86_)
     HANDLE hProcess = GetCurrentProcess();
     int frameNum;
 #if defined(_AMD64_)
@@ -1400,9 +1560,9 @@ void afsd_printStack(HANDLE hThread, CONTEXT *c)
 #error The STACKFRAME initialization in afsd_printStack() for this platform
 #error must be properly configured
 #elif defined(_AMD64_)
-    s.AddrPC.Offset = 0;
+    s.AddrPC.Offset = c->Rip;
     s.AddrPC.Mode = AddrModeFlat;
-    s.AddrFrame.Offset = 0;
+    s.AddrFrame.Offset = c->Rbp;
     s.AddrFrame.Mode = AddrModeFlat;
 #else
     s.AddrPC.Offset = c->Eip;
@@ -1502,7 +1662,6 @@ void afsd_printStack(HANDLE hThread, CONTEXT *c)
   
     SymCleanup(hProcess);
     GlobalFree(pSym);
-#endif /* _X86_ */
 }
 
 #ifdef _DEBUG
@@ -1521,16 +1680,21 @@ static BOOL (WINAPI *pMiniDumpWriteDump)(HANDLE hProcess,DWORD ProcessId,HANDLE
 static HANDLE
 OpenDumpFile(void)
 {
+    char tmp[256];
     char wd[256];
+    SYSTEMTIME st;
     DWORD code;
 
-    code = GetEnvironmentVariable("TEMP", wd, sizeof(wd));
-    if ( code == 0 || code > sizeof(wd) )
+    code = GetEnvironmentVariable("TEMP", tmp, sizeof(tmp));
+    if ( code == 0 || code > sizeof(tmp) )
     {
-        if (!GetWindowsDirectory(wd, sizeof(wd)))
+        if (!GetWindowsDirectory(tmp, sizeof(tmp)))
             return NULL;
     }
-    StringCbCatA(wd, sizeof(wd), "\\afsd.dmp");
+    GetLocalTime(&st);
+    StringCbPrintfA(wd, sizeof(wd),
+                    "%s\\afsd-%04d-%02d-%02d-%02d_%02d_%02d.dmp", tmp,
+                    st.wYear, st.wMonth, st.wDay, st.wHour, st.wMinute, st.wSecond);
     return CreateFile( wd, GENERIC_WRITE, FILE_SHARE_READ, NULL,
                             CREATE_ALWAYS, FILE_FLAG_WRITE_THROUGH, NULL);
 }
@@ -1538,8 +1702,8 @@ OpenDumpFile(void)
 void 
 GenerateMiniDump(PEXCEPTION_POINTERS ep)
 {
-       if (IsDebuggerPresent())
-               return;
+    if (IsDebuggerPresent())
+        return;
 
     if (ep == NULL) 
     {
@@ -1652,6 +1816,9 @@ LONG __stdcall afsd_ExceptionFilter(EXCEPTION_POINTERS *ep)
 #if defined(_X86)    
         ep->ContextRecord->Eip++;
 #endif
+#if defined(_AMD64_)
+        ep->ContextRecord->Rip++;
+#endif
         return EXCEPTION_CONTINUE_EXECUTION;
     }
     else
@@ -1662,9 +1829,11 @@ LONG __stdcall afsd_ExceptionFilter(EXCEPTION_POINTERS *ep)
   
 void afsd_SetUnhandledExceptionFilter()
 {
+#ifndef NOTRACE
     SetUnhandledExceptionFilter(afsd_ExceptionFilter);
+#endif
 }
-  
+
 #ifdef _DEBUG
 void afsd_DbgBreakAllocInit()
 {