windows-unused-var-20080528
[openafs.git] / src / WINNT / afsd / afsd_init.c
index 75fa0e7..bef18a1 100644 (file)
@@ -23,6 +23,9 @@
 
 #include <osi.h>
 #include "afsd.h"
+#ifdef USE_BPLUS
+#include "cm_btree.h"
+#endif
 #include <rx\rx.h>
 #include <rx\rx_null.h>
 #include <WINNT/syscfg.h>
 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;
+#endif
+extern afs_int32 cm_OfflineROIsValid;
+extern afs_int32 cm_giveUpAllCBs;
+extern const char **smb_ExecutableExtensions;
 
 osi_log_t *afsd_logp;
 
@@ -50,9 +62,6 @@ char cm_mountRoot[1024];
 DWORD cm_mountRootLen;
 int cm_logChunkSize;
 int cm_chunkSize;
-#ifdef AFS_FREELANCE_CLIENT
-char *cm_FakeRootDir;
-#endif /* freelance */
 
 int smb_UseV3 = 1;
 
@@ -72,11 +81,8 @@ unsigned short cm_callbackport = CM_DEFAULT_CALLBACKPORT;
 char cm_NetbiosName[MAX_NB_NAME_LENGTH] = "";
 
 char cm_CachePath[MAX_PATH];
-DWORD cm_CachePathLen;
 DWORD cm_ValidateCache = 1;
 
-BOOL isGateway = FALSE;
-
 BOOL reportSessionStartups = FALSE;
 
 cm_initparams_v1 cm_initParams;
@@ -116,7 +122,7 @@ afsi_log(char *pattern, ...)
     if ( afsi_log_useTimestamp ) {
         GetTimeFormat(LOCALE_SYSTEM_DEFAULT, 0, NULL, NULL, t, sizeof(t));
         GetDateFormat(LOCALE_SYSTEM_DEFAULT, 0, NULL, NULL, d, sizeof(d));
-        StringCbPrintfA(u, sizeof(u), "%s %s: %s\n", d, t, s);
+        StringCbPrintfA(u, sizeof(u), "%s %s: %s\r\n", d, t, s);
         if (afsi_file != INVALID_HANDLE_VALUE)
             WriteFile(afsi_file, u, (DWORD)strlen(u), &zilch, NULL);
 #ifdef NOTSERVICE
@@ -137,7 +143,7 @@ void afsd_initUpperCaseTable()
 void
 afsi_start()
 {
-    char wd[256];
+    char wd[MAX_PATH+1];
     char t[100], u[100], *p, *path;
     int zilch;
     DWORD code;
@@ -147,13 +153,10 @@ afsi_start()
     DWORD maxLogSize = 100 * 1024;
 
     afsi_file = INVALID_HANDLE_VALUE;
-    code = GetEnvironmentVariable("TEMP", wd, sizeof(wd));
-    if ( code == 0 || code > sizeof(wd) )
-    {
-        code = GetWindowsDirectory(wd, sizeof(wd));
-        if (code == 0) 
-            return;
-    }
+    code = GetTempPath(sizeof(wd)-15, wd);
+    if ( code == 0 || code > (sizeof(wd)-15) )
+        return;         /* unable to create a log */
+
     StringCbCatA(wd, sizeof(wd), "\\afsd_init.log");
     GetTimeFormat(LOCALE_SYSTEM_DEFAULT, 0, NULL, NULL, t, sizeof(t));
     afsi_file = CreateFile(wd, GENERIC_WRITE, FILE_SHARE_READ, NULL,
@@ -179,8 +182,8 @@ afsi_start()
 
     SetFilePointer(afsi_file, 0, NULL, FILE_END);
     GetTimeFormat(LOCALE_SYSTEM_DEFAULT, 0, NULL, NULL, u, sizeof(u));
-    StringCbCatA(t, sizeof(t), ": Create log file\n");
-    StringCbCatA(u, sizeof(u), ": Created log file\n");
+    StringCbCatA(t, sizeof(t), ": Create log file\r\n");
+    StringCbCatA(u, sizeof(u), ": Created log file\r\n");
     WriteFile(afsi_file, t, (DWORD)strlen(t), &zilch, NULL);
     WriteFile(afsi_file, u, (DWORD)strlen(u), &zilch, NULL);
     p = "PATH=";
@@ -189,7 +192,7 @@ afsi_start()
     code = GetEnvironmentVariable("PATH", path, code);
     WriteFile(afsi_file, p, (DWORD)strlen(p), &zilch, NULL);
     WriteFile(afsi_file, path, (DWORD)strlen(path), &zilch, NULL);
-    WriteFile(afsi_file, "\n", (DWORD)1, &zilch, NULL);
+    WriteFile(afsi_file, "\r\n", (DWORD)1, &zilch, NULL);
     free(path);
 
     /* Initialize C RTL Code Page conversion functions */
@@ -281,19 +284,22 @@ configureBackConnectionHostNames(void)
                        KEY_READ|KEY_WRITE,
                        &hkMSV10) == ERROR_SUCCESS )
     {
-        if (RegQueryValueEx( hkMSV10, "BackConnectionHostNames", 0, 
-                            &dwType, NULL, &dwSize) == 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) {
+                                pHostNames, &dwSize) == ERROR_SUCCESS) 
+            {
                for (pName = pHostNames; 
                     (pName - pHostNames < dwSize) && *pName ; 
                     pName += strlen(pName) + 1)
                {
-                   if ( !stricmp(pName, cm_NetbiosName) ) {
+                   if ( !cm_stricmp_utf8(pName, cm_NetbiosName) ) {
                        bNameFound = TRUE;
                        break;
                    }   
@@ -455,7 +461,7 @@ 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, CM_FLAG_NOPROBE); /* refcount = 1 */
                 tsp->ipRank = (USHORT)dwRank;
             }
         }
@@ -525,7 +531,7 @@ 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, CM_FLAG_NOPROBE); /* refcount = 1 */
                 tsp->ipRank = (USHORT)dwRank;
             }
         }
@@ -543,11 +549,14 @@ int afsd_InitCM(char **reasonP)
     osi_uid_t debugID;
     afs_uint64 cacheBlocks;
     DWORD cacheSize;
+    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;
     long traceBufSize;
     long maxcpus;
     long ltt, ltto;
@@ -565,7 +574,6 @@ int afsd_InitCM(char **reasonP)
     long code;
     /*int freelanceEnabled;*/
     WSADATA WSAjunk;
-    lana_number_t lanaNum;
     int i;
     char *p, *q; 
     int cm_noIPAddr;         /* number of client network interfaces */
@@ -699,20 +707,53 @@ int afsd_InitCM(char **reasonP)
                       logChunkSize);
             logChunkSize = CM_CONFIGDEFAULT_CHUNKSIZE;
         }
-        afsi_log("Chunk size %d", logChunkSize);
     } else {
         logChunkSize = CM_CONFIGDEFAULT_CHUNKSIZE;
-        afsi_log("Default chunk size %d", logChunkSize);
     }
     cm_logChunkSize = logChunkSize;
     cm_chunkSize = 1 << logChunkSize;
+    afsi_log("Chunk size %u (%d)", cm_chunkSize, cm_logChunkSize);
+
+    dummyLen = sizeof(blockSize);
+    code = RegQueryValueEx(parmKey, "blockSize", NULL, NULL,
+                            (BYTE *) &blockSize, &dummyLen);
+    if (code == ERROR_SUCCESS) {
+        if (blockSize < 1 || 
+            (blockSize > 1024 && (blockSize % CM_CONFIGDEFAULT_BLOCKSIZE != 0))) 
+        {
+            afsi_log("Invalid block size %u specified, using default", blockSize);
+            blockSize = CM_CONFIGDEFAULT_BLOCKSIZE;
+        } else {
+            /* 
+             * if the blockSize is less than 1024 we permit the blockSize to be
+             * specified in multiples of the default blocksize
+             */
+            if (blockSize <= 1024)
+                blockSize *= CM_CONFIGDEFAULT_BLOCKSIZE;
+        }
+    } else {
+        blockSize = CM_CONFIGDEFAULT_BLOCKSIZE;
+    }
+    if (blockSize > cm_chunkSize) {
+        afsi_log("Block size (%d) cannot be larger than Chunk size (%d).", 
+                  blockSize, cm_chunkSize);
+        blockSize = cm_chunkSize;
+    }
+    if (cm_chunkSize % blockSize != 0) {
+        afsi_log("Block size (%d) must be a factor of Chunk size (%d).",
+                  blockSize, cm_chunkSize);
+        blockSize = CM_CONFIGDEFAULT_BLOCKSIZE;
+    }
+    afsi_log("Block size %u", blockSize);
 
     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);
     }
@@ -731,10 +772,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);
@@ -899,6 +960,11 @@ int afsd_InitCM(char **reasonP)
     else
        LogEvent(EVENTLOG_INFORMATION_TYPE, MSG_CRYPT_OFF);
 
+    dummyLen = sizeof(cryptall);
+    code = RegQueryValueEx(parmKey, "ForceAnonVLDB", NULL, NULL,
+                            (BYTE *) &cm_anonvldb, &dummyLen);
+    afsi_log("CM ForceAnonVLDB is %s", cm_anonvldb ? "on" : "off");
+
 #ifdef AFS_AFSDB_ENV
     dummyLen = sizeof(cm_dnsEnabled);
     code = RegQueryValueEx(parmKey, "UseDNS", NULL, NULL,
@@ -928,6 +994,15 @@ int afsd_InitCM(char **reasonP)
     }
 #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);
@@ -972,6 +1047,15 @@ int afsd_InitCM(char **reasonP)
     if (rx_nojumbo)
         afsi_log("RX Jumbograms are disabled");
 
+    dummyLen = sizeof(rx_extraPackets);
+    code = RegQueryValueEx(parmKey, "RxExtraPackets", NULL, NULL,
+                           (BYTE *) &rx_extraPackets, &dummyLen);
+    if (code != ERROR_SUCCESS) {
+        rx_extraPackets = 120;
+    }
+    if (rx_extraPackets)
+        afsi_log("RX extraPackets is %d", rx_extraPackets);
+
     dummyLen = sizeof(rx_mtu);
     code = RegQueryValueEx(parmKey, "RxMaxMTU", NULL, NULL,
                            (BYTE *) &rx_mtu, &dummyLen);
@@ -985,61 +1069,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");
-
-    dummyLen = sizeof(DWORD);
-    code = RegQueryValueEx(parmKey, "daemonCheckDownInterval", NULL, NULL,
-                           (BYTE *) &dwValue, &dummyLen);
-    if (code == ERROR_SUCCESS)
-       cm_daemonCheckDownInterval = dwValue;
-    afsi_log("daemonCheckDownInterval is %d", cm_daemonCheckDownInterval);
-
-    dummyLen = sizeof(DWORD);
-    code = RegQueryValueEx(parmKey, "daemonCheckUpInterval", NULL, NULL,
-                           (BYTE *) &dwValue, &dummyLen);
-    if (code == ERROR_SUCCESS)
-       cm_daemonCheckUpInterval = dwValue;
-    afsi_log("daemonCheckUpInterval is %d", cm_daemonCheckUpInterval);
-
-    dummyLen = sizeof(DWORD);
-    code = RegQueryValueEx(parmKey, "daemonCheckVolInterval", NULL, NULL,
-                           (BYTE *) &dwValue, &dummyLen);
-    if (code == ERROR_SUCCESS)
-       cm_daemonCheckVolInterval = dwValue;
-    afsi_log("daemonCheckVolInterval is %d", cm_daemonCheckVolInterval);
-
-    dummyLen = sizeof(DWORD);
-    code = RegQueryValueEx(parmKey, "daemonCheckCBInterval", NULL, NULL,
-                           (BYTE *) &dwValue, &dummyLen);
-    if (code == ERROR_SUCCESS)
-       cm_daemonCheckCBInterval = dwValue;
-    afsi_log("daemonCheckCBInterval is %d", cm_daemonCheckCBInterval);
-
-    dummyLen = sizeof(DWORD);
-    code = RegQueryValueEx(parmKey, "daemonCheckLockInterval", NULL, NULL,
-                           (BYTE *) &dwValue, &dummyLen);
-    if (code == ERROR_SUCCESS)
-       cm_daemonCheckLockInterval = dwValue;
-    afsi_log("daemonCheckLockInterval is %d", cm_daemonCheckLockInterval);
-
-    dummyLen = sizeof(DWORD);
-    code = RegQueryValueEx(parmKey, "daemonCheckTokenInterval", NULL, NULL,
-                           (BYTE *) &dwValue, &dummyLen);
-    if (code == ERROR_SUCCESS)
-       cm_daemonTokenCheckInterval = dwValue;
-    afsi_log("daemonCheckTokenInterval is %d", cm_daemonTokenCheckInterval);
+    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,
@@ -1067,28 +1124,91 @@ int afsd_InitCM(char **reasonP)
        afsi_log("EnableServerLocks: server requested");
        break;
     }
-    RegCloseKey (parmKey);
 
-    /* Call lanahelper to get Netbios name, lan adapter number and gateway flag */
-    if (SUCCEEDED(code = lana_GetUncServerNameEx(cm_NetbiosName, &lanaNum, &isGateway, LANA_NETBIOS_NAME_FULL))) {
-        LANadapter = (lanaNum == LANA_INVALID)? -1: lanaNum;
+    dummyLen = sizeof(DWORD);
+    code = RegQueryValueEx(parmKey, "DeleteReadOnly", NULL, NULL,
+                           (BYTE *) &dwValue, &dummyLen);
+    if (code == ERROR_SUCCESS) {
+        cm_deleteReadOnly = (unsigned short) dwValue;
+    } 
+    afsi_log("CM DeleteReadOnly is %u", cm_deleteReadOnly);
+    
+#ifdef USE_BPLUS
+    dummyLen = sizeof(DWORD);
+    code = RegQueryValueEx(parmKey, "BPlusTrees", NULL, NULL,
+                           (BYTE *) &dwValue, &dummyLen);
+    if (code == ERROR_SUCCESS) {
+        cm_BPlusTrees = (unsigned short) dwValue;
+    } 
+    afsi_log("CM BPlusTrees is %u", cm_BPlusTrees);
 
-        if (LANadapter != -1)
-            afsi_log("LAN adapter number %d", LANadapter);
-        else
-            afsi_log("LAN adapter number not determined");
+    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 (isGateway)
-            afsi_log("Set for gateway service");
+    if ((RegQueryValueEx( parmKey, "PrefetchExecutableExtensions", 0, 
+                          &regType, NULL, &dummyLen) == ERROR_SUCCESS) &&
+         (regType == REG_MULTI_SZ)) 
+    {
+        char * 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) &&
+             (regType == REG_MULTI_SZ))
+        {
+            int cnt;
+            char * p;
 
-        afsi_log("Using >%s< as SMB server name", cm_NetbiosName);
-    } else {
-        /* something went horribly wrong.  We can't proceed without a netbios name */
-        StringCbPrintfA(buf,sizeof(buf),"Netbios name could not be determined: %li", code);
-        osi_panic(buf, __FILE__, __LINE__);
+            for (cnt = 0, p = pSz; (p - pSz < dummyLen) && *p; cnt++, p += strlen(p) + 1);
+
+            smb_ExecutableExtensions = malloc(sizeof(char *) * (cnt+1));
+
+            for (cnt = 0, p = pSz; (p - pSz < dummyLen) && *p; cnt++, p += strlen(p) + 1)
+            {
+                smb_ExecutableExtensions[cnt] = p;
+                afsi_log("PrefetchExecutableExtension: \"%s\"", p);
+            }
+            smb_ExecutableExtensions[cnt] = NULL;
+        }
+        
+        if (!smb_ExecutableExtensions)
+            free(pSz);
     }
+    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_deleteReadOnly);
+    
+    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);
 
-    cacheBlocks = ((afs_uint64)cacheSize * 1024) / CM_CONFIGDEFAULT_BLOCKSIZE;
+    RegCloseKey (parmKey);
+
+    cacheBlocks = ((afs_uint64)cacheSize * 1024) / blockSize;
         
     /* get network related info */
     cm_noIPAddr = CM_MAXINTERFACE_ADDR;
@@ -1108,7 +1228,7 @@ 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;
@@ -1130,8 +1250,10 @@ int afsd_InitCM(char **reasonP)
     smb_InitIoctl();
         
     cm_InitCallback();
-        
-    code = cm_InitMappedMemory(virtualCache, cm_CachePath, stats, cm_chunkSize, cacheBlocks);
+
+    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";
@@ -1205,7 +1327,7 @@ int afsd_InitCM(char **reasonP)
               code, cm_freelanceEnabled, (code ? "<none>" : rootCellName));
     if (code != 0 && !cm_freelanceEnabled) 
     {
-        *reasonP = "can't find root cell name in afsd.ini";
+        *reasonP = "can't find root cell name in " AFS_CELLSERVDB;
         return -1;
     }   
     else if (cm_freelanceEnabled)
@@ -1217,7 +1339,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;
         }
     }
@@ -1234,6 +1356,13 @@ int afsd_InitCM(char **reasonP)
     return 0;
 }
 
+int afsd_ShutdownCM(void)
+{
+    cm_ReleaseSCache(cm_data.rootSCachep);
+
+    return 0;
+}
+
 int afsd_InitDaemons(char **reasonP)
 {
     long code;
@@ -1248,9 +1377,9 @@ int afsd_InitDaemons(char **reasonP)
 
         osi_Log0(afsd_logp, "Loading Root Volume from cell");
        do {
-           code = cm_GetVolumeByName(cm_data.rootCellp, cm_rootVolumeName, cm_rootUserp,
-                                      &req, CM_FLAG_CREATE, &cm_data.rootVolumep);
-           afsi_log("cm_GetVolumeByName code %x root vol %x", code,
+           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) {
@@ -1261,10 +1390,7 @@ int afsd_InitDaemons(char **reasonP)
 
     /* 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;
+        cm_SetFid(&cm_data.rootFid, cm_data.rootCellp->cellID, cm_GetROVolumeID(cm_data.rootVolumep), 1, 1);
     }
     else
         cm_FakeRootFid(&cm_data.rootFid);
@@ -1298,13 +1424,37 @@ 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);
     }
 
     /* Do this last so that we don't handle requests before init is done.
      * Here we initialize the SMB listener.
      */
-    smb_Init(afsd_logp, cm_NetbiosName, smb_UseV3, LANadapter, numSvThreads, aMBfunc);
+    smb_Init(afsd_logp, smb_UseV3, numSvThreads, aMBfunc);
     afsi_log("smb_Init complete");
 
     return 0;
@@ -1326,7 +1476,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_)
@@ -1373,9 +1522,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;
@@ -1475,7 +1624,6 @@ void afsd_printStack(HANDLE hThread, CONTEXT *c)
   
     SymCleanup(hProcess);
     GlobalFree(pSym);
-#endif /* _X86_ */
 }
 
 #ifdef _DEBUG
@@ -1511,6 +1659,9 @@ OpenDumpFile(void)
 void 
 GenerateMiniDump(PEXCEPTION_POINTERS ep)
 {
+       if (IsDebuggerPresent())
+               return;
+
     if (ep == NULL) 
     {
         // Generate exception to get proper context in dump
@@ -1622,6 +1773,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
@@ -1632,7 +1786,9 @@ LONG __stdcall afsd_ExceptionFilter(EXCEPTION_POINTERS *ep)
   
 void afsd_SetUnhandledExceptionFilter()
 {
+#ifndef NOTRACE
     SetUnhandledExceptionFilter(afsd_ExceptionFilter);
+#endif
 }
   
 #ifdef _DEBUG