Add missing processor architecture cases
[reactos.git] / reactos / ntoskrnl / cc / fs.c
index 8e8b3d5..be97a98 100644 (file)
@@ -1,25 +1,23 @@
-/* COPYRIGHT:       See COPYING in the top level directory
+/* $Id$
+ *
+ * COPYRIGHT:       See COPYING in the top level directory
  * PROJECT:         ReactOS kernel
  * FILE:            ntoskrnl/cc/fs.c
  * PURPOSE:         Implements cache managers functions useful for File Systems
- * PROGRAMMER:      Alex Ionescu
- * UPDATE HISTORY:
- *                  Created 20/06/04
+ *
+ * PROGRAMMERS:     Alex Ionescu
  */
 
 /* INCLUDES ******************************************************************/
 
-#include <ddk/ntddk.h>
-#include <ddk/ntifs.h>
-#include <internal/mm.h>
-#include <internal/cc.h>
-#include <internal/pool.h>
-#include <internal/io.h>
-#include <ntos/minmax.h>
-
+#include <ntoskrnl.h>
 #define NDEBUG
 #include <internal/debug.h>
 
+#ifndef VACB_MAPPING_GRANULARITY
+#define VACB_MAPPING_GRANULARITY (256 * 1024)
+#endif
+
 /* GLOBALS   *****************************************************************/
 
 extern FAST_MUTEX ViewLock;
@@ -41,15 +39,14 @@ CcGetDirtyPages (
        IN      PVOID                   Context2
        )
 {
+       LARGE_INTEGER i;
        UNIMPLEMENTED;
-
-       LARGE_INTEGER i; 
        i.QuadPart = 0;
        return i;
 }
 
 /*
- * @unimplemented
+ * @implemented
  */
 PFILE_OBJECT
 STDCALL
@@ -57,8 +54,8 @@ CcGetFileObjectFromBcb (
        IN      PVOID   Bcb
        )
 {
-       UNIMPLEMENTED;
-       return 0;
+       PINTERNAL_BCB iBcb = (PINTERNAL_BCB)Bcb;
+       return iBcb->CacheSegment->Bcb->FileObject;
 }
 
 /*
@@ -71,9 +68,8 @@ CcGetLsnForFileObject (
        OUT     PLARGE_INTEGER  OldestLsn OPTIONAL
        )
 {
+       LARGE_INTEGER i;
        UNIMPLEMENTED;
-
-       LARGE_INTEGER i; 
        i.QuadPart = 0;
        return i;
 }
@@ -91,7 +87,7 @@ CcInitializeCacheMap (
        IN      PVOID                           LazyWriterContext
        )
 {
-       UNIMPLEMENTED;
+    CcRosInitializeFileCache(FileObject, VACB_MAPPING_GRANULARITY);
 }
 
 /*
@@ -138,7 +134,7 @@ CcSetFileSizes (IN PFILE_OBJECT FileObject,
   LIST_ENTRY FreeListHead;
   NTSTATUS Status;
 
-  DPRINT("CcSetFileSizes(FileObject %x, FileSizes %x)\n", 
+  DPRINT("CcSetFileSizes(FileObject 0x%p, FileSizes 0x%p)\n",
         FileObject, FileSizes);
   DPRINT("AllocationSize %d, FileSize %d, ValidDataLength %d\n",
          (ULONG)FileSizes->AllocationSize.QuadPart,
@@ -146,12 +142,18 @@ CcSetFileSizes (IN PFILE_OBJECT FileObject,
          (ULONG)FileSizes->ValidDataLength.QuadPart);
 
   Bcb = FileObject->SectionObjectPointer->SharedCacheMap;
-  assert(Bcb);
+
+  /*
+   * It is valid to call this function on file objects that weren't
+   * initialized for caching. In this case it's simple no-op.
+   */
+  if (Bcb == NULL)
+     return;
+
   if (FileSizes->AllocationSize.QuadPart < Bcb->AllocationSize.QuadPart)
   {
      InitializeListHead(&FreeListHead);
-     ExAcquireFastMutex(&ViewLock);
+     ExEnterCriticalRegionAndAcquireFastMutexUnsafe(&ViewLock);
      KeAcquireSpinLock(&Bcb->BcbLock, &oldirql);
 
      current_entry = Bcb->BcbSegmentListHead.Flink;
@@ -176,15 +178,15 @@ CcSetFileSizes (IN PFILE_OBJECT FileObject,
           else
           {
              DPRINT1("Anyone has referenced a cache segment behind the new size.\n");
-             KEBUGCHECK(0);
+             KEBUGCHECKCC;
           }
        }
      }
-     
+
      Bcb->AllocationSize = FileSizes->AllocationSize;
      Bcb->FileSize = FileSizes->FileSize;
      KeReleaseSpinLock(&Bcb->BcbLock, oldirql);
-     ExReleaseFastMutex(&ViewLock);
+     ExReleaseFastMutexUnsafeAndLeaveCriticalRegion(&ViewLock);
 
      current_entry = FreeListHead.Flink;
      while(current_entry != &FreeListHead)
@@ -194,7 +196,7 @@ CcSetFileSizes (IN PFILE_OBJECT FileObject,
         Status = CcRosInternalFreeCacheSegment(current);
         if (!NT_SUCCESS(Status))
         {
-           DPRINT1("CcRosInternalFreeCacheSegment failed, status = %x\n");
+           DPRINT1("CcRosInternalFreeCacheSegment failed, status = %x\n", Status);
           KEBUGCHECK(0);
         }
      }
@@ -233,6 +235,10 @@ CcUninitializeCacheMap (
        IN      PCACHE_UNINITIALIZE_EVENT       UninitializeCompleteEvent OPTIONAL
        )
 {
+#if 0
        UNIMPLEMENTED;
        return FALSE;
+#else
+    return CcRosReleaseFileCache(FileObject);
+#endif
 }