windows-virtual-memory-20041224
[openafs.git] / src / WINNT / afsd / cm_buf.c
index 06c9cc1..ed31f37 100644 (file)
@@ -86,6 +86,9 @@ int buf_cacheType = CM_BUF_CACHETYPE_FILE;
 static
 HANDLE CacheHandle;
 
+static 
+VOID * ViewOfFile;
+
 static
 SYSTEM_INFO sysInfo;
 #endif /* !DJGPP */
@@ -334,17 +337,20 @@ long buf_Init(cm_buf_ops_t *opsp)
             }
             return CM_ERROR_INVAL;
         }
-        data = MapViewOfFile(hm,
-                              FILE_MAP_ALL_ACCESS,
-                              0, 0,   
-                              buf_nbuffers * buf_bufferSize);
-        if (data == NULL) {
+        ViewOfFile = MapViewOfFile(hm,
+                                   FILE_MAP_ALL_ACCESS,
+                                   0, 0,   
+                                   buf_nbuffers * buf_bufferSize);
+        if (ViewOfFile == NULL) {
+            afsi_log("Error mapping view of file: 0x%X", GetLastError());
             if (hf != INVALID_HANDLE_VALUE)
                 CloseHandle(hf);
             CloseHandle(hm);
             return CM_ERROR_INVAL;
         }
         CloseHandle(hm);
+
+        data = ViewOfFile;
 #else   
         /* djgpp doesn't support memory mapped files */
         data = malloc(buf_nbuffers * buf_bufferSize);
@@ -405,6 +411,13 @@ long buf_Init(cm_buf_ops_t *opsp)
     return 0;
 }
 
+void
+buf_Shutdown(void)
+{
+    UnmapViewOfFile(ViewOfFile);
+    CloseHandle(CacheHandle);
+}
+
 /* add nbuffers to the buffer pool, if possible.
  * Called with no locks held.
  */
@@ -1464,17 +1477,16 @@ int cm_DumpBufHashTable(FILE *outputFile, char *cookie)
 
     lock_ObtainRead(&buf_globalLock);
   
-    sprintf(output, "%s - dumping buf_HashTable - buf_hashSize=%d\n", cookie, buf_hashSize);
+    StringCbPrintfA(output, sizeof(output), "%s - dumping buf_HashTable - buf_hashSize=%d\n", cookie, buf_hashSize);
     WriteFile(outputFile, output, strlen(output), &zilch, NULL);
   
     for (i = 0; i < buf_hashSize; i++)
     {
-        for(bp = buf_hashTablepp[i]; bp; bp=bp->hashp) 
+        for (bp = buf_hashTablepp[i]; bp; bp=bp->hashp) 
         {
             if (bp->refCount)
             {
-                sprintf(output, "%s bp=0x%08X, hash=%d, fid (cell=%d, volume=%d,"
-                        "vnode=%d, unique=%d), size=%d refCount=%d\n", 
+                StringCbPrintfA(output, sizeof(output), "vnode=%d, unique=%d), size=%d refCount=%d\n", 
                         cookie, (void *)bp, i, bp->fid.cell, bp->fid.volume, 
                         bp->fid.vnode, bp->fid.unique, bp->size, bp->refCount);
                 WriteFile(outputFile, output, strlen(output), &zilch, NULL);
@@ -1482,7 +1494,7 @@ int cm_DumpBufHashTable(FILE *outputFile, char *cookie)
         }
     }
   
-    sprintf(output, "%s - Done dumping buf_HashTable.\n", cookie);
+    StringCbPrintfA(output, sizeof(output), "%s - Done dumping buf_HashTable.\n", cookie);
     WriteFile(outputFile, output, strlen(output), &zilch, NULL);
 
     lock_ReleaseRead(&buf_globalLock);