-/* 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;
IN PVOID Context2
)
{
+ LARGE_INTEGER i;
UNIMPLEMENTED;
-
- LARGE_INTEGER i;
i.QuadPart = 0;
return i;
}
/*
- * @unimplemented
+ * @implemented
*/
PFILE_OBJECT
STDCALL
IN PVOID Bcb
)
{
- UNIMPLEMENTED;
- return 0;
+ PINTERNAL_BCB iBcb = (PINTERNAL_BCB)Bcb;
+ return iBcb->CacheSegment->Bcb->FileObject;
}
/*
OUT PLARGE_INTEGER OldestLsn OPTIONAL
)
{
+ LARGE_INTEGER i;
UNIMPLEMENTED;
-
- LARGE_INTEGER i;
i.QuadPart = 0;
return i;
}
IN PVOID LazyWriterContext
)
{
- UNIMPLEMENTED;
+ CcRosInitializeFileCache(FileObject, VACB_MAPPING_GRANULARITY);
}
/*
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,
(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;
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)
Status = CcRosInternalFreeCacheSegment(current);
if (!NT_SUCCESS(Status))
{
- DPRINT1("CcRosInternalFreeCacheSegment failed, status = %x\n");
+ DPRINT1("CcRosInternalFreeCacheSegment failed, status = %x\n", Status);
KEBUGCHECK(0);
}
}
IN PCACHE_UNINITIALIZE_EVENT UninitializeCompleteEvent OPTIONAL
)
{
+#if 0
UNIMPLEMENTED;
return FALSE;
+#else
+ return CcRosReleaseFileCache(FileObject);
+#endif
}