Based on a patch by Herve Poussineau <poussine(a)freesurf.fr>fr>:
Add basic cache manager and Fast I/O callbacks and don't use ReactOS
specific cache manager / filesystem features if USE_ROS_CC_AND_FS is not
defined.
Modified: trunk/reactos/drivers/fs/vfat/cleanup.c
Added: trunk/reactos/drivers/fs/vfat/fastio.c
Modified: trunk/reactos/drivers/fs/vfat/fcb.c
Modified: trunk/reactos/drivers/fs/vfat/fsctl.c
Modified: trunk/reactos/drivers/fs/vfat/iface.c
Modified: trunk/reactos/drivers/fs/vfat/makefile
Modified: trunk/reactos/drivers/fs/vfat/rw.c
Modified: trunk/reactos/drivers/fs/vfat/vfat.h
_____
Modified: trunk/reactos/drivers/fs/vfat/cleanup.c
--- trunk/reactos/drivers/fs/vfat/cleanup.c 2005-01-12 12:33:57 UTC
(rev 12960)
+++ trunk/reactos/drivers/fs/vfat/cleanup.c 2005-01-12 13:00:43 UTC
(rev 12961)
@@ -49,7 +49,11 @@
/* Uninitialize file cache if initialized for this file object. */
if (FileObject->PrivateCacheMap)
{
+#ifdef USE_ROS_CC_AND_FS
CcRosReleaseFileCache (FileObject);
+#else
+ CcUninitializeCacheMap (FileObject, NULL, NULL);
+#endif
}
pFcb->OpenHandleCount--;
_____
Added: trunk/reactos/drivers/fs/vfat/fastio.c
--- trunk/reactos/drivers/fs/vfat/fastio.c 2005-01-12 12:33:57 UTC
(rev 12960)
+++ trunk/reactos/drivers/fs/vfat/fastio.c 2005-01-12 13:00:43 UTC
(rev 12961)
@@ -0,0 +1,79 @@
+/* $Id:
+ *
+ *
+ * FILE: drivers/fs/vfat/fastio.c
+ * PURPOSE: Fast IO routines.
+ * COPYRIGHT: See COPYING in the top level directory
+ * PROJECT: ReactOS kernel
+ * PROGRAMMER: Herve Poussineau (reactos(a)poussine.freesurf.fr)
+ */
+
+#define NDEBUG
+#include "vfat.h"
+
+BOOLEAN NTAPI
+VfatFastIoCheckIfPossible(IN PFILE_OBJECT FileObject,
+ IN PLARGE_INTEGER FileOffset,
+ IN ULONG Lenght,
+ IN BOOLEAN Wait,
+ IN ULONG LockKey,
+ IN BOOLEAN CheckForReadOperation,
+ OUT PIO_STATUS_BLOCK IoStatus,
+ IN PDEVICE_OBJECT DeviceObject)
+{
+ /* Prevent all Fast I/O requests */
+ DPRINT("VfatFastIoCheckIfPossible(): returning FALSE.\n");
+ return FALSE;
+}
+
+BOOLEAN NTAPI
+VfatAcquireForLazyWrite(IN PVOID Context,
+ IN BOOLEAN Wait)
+{
+ PVFATFCB Fcb = (PVFATFCB)Context;
+ ASSERT(Fcb);
+ DPRINT("VfatAcquireForLazyWrite(): Fcb %p\n", Fcb);
+
+ if (!ExAcquireResourceExclusiveLite(&(Fcb->MainResource), Wait))
+ {
+ DPRINT("VfatAcquireForLazyWrite(): ExReleaseResourceLite
failed.\n");
+ return FALSE;
+ }
+ return TRUE;
+}
+
+VOID NTAPI
+VfatReleaseFromLazyWrite(IN PVOID Context)
+{
+ PVFATFCB Fcb = (PVFATFCB)Context;
+ ASSERT(Fcb);
+ DPRINT("VfatReleaseFromLazyWrite(): Fcb %p\n", Fcb);
+
+ ExReleaseResourceLite(&(Fcb->MainResource));
+}
+
+BOOLEAN NTAPI
+VfatAcquireForReadAhead(IN PVOID Context,
+ IN BOOLEAN Wait)
+{
+ PVFATFCB Fcb = (PVFATFCB)Context;
+ ASSERT(Fcb);
+ DPRINT("VfatAcquireForReadAhead(): Fcb %p\n", Fcb);
+
+ if (!ExAcquireResourceExclusiveLite(&(Fcb->MainResource), Wait))
+ {
+ DPRINT("VfatAcquireForReadAhead(): ExReleaseResourceLite
failed.\n");
+ return FALSE;
+ }
+ return TRUE;
+}
+
+VOID NTAPI
+VfatReleaseFromReadAhead(IN PVOID Context)
+{
+ PVFATFCB Fcb = (PVFATFCB)Context;
+ ASSERT(Fcb);
+ DPRINT("VfatReleaseFromReadAhead(): Fcb %p\n", Fcb);
+
+ ExReleaseResourceLite(&(Fcb->MainResource));
+}
_____
Modified: trunk/reactos/drivers/fs/vfat/fcb.c
--- trunk/reactos/drivers/fs/vfat/fcb.c 2005-01-12 12:33:57 UTC (rev
12960)
+++ trunk/reactos/drivers/fs/vfat/fcb.c 2005-01-12 13:00:43 UTC (rev
12961)
@@ -228,7 +228,11 @@
/* Uninitialize file cache if initialized for this file
object. */
if (pFCB->FileObject->SectionObjectPointer->SharedCacheMap)
{
+#ifdef USE_ROS_CC_AND_FS
CcRosReleaseFileCache(pFCB->FileObject);
+#else
+ CcUninitializeCacheMap(pFCB->FileObject, NULL, NULL);
+#endif
}
vfatDestroyCCB(pFCB->FileObject->FsContext2);
pFCB->FileObject->FsContext2 = NULL;
@@ -325,9 +329,11 @@
NTSTATUS
vfatFCBInitializeCacheFromVolume (PVCB vcb, PVFATFCB fcb)
{
+#ifdef USE_ROS_CC_AND_FS
NTSTATUS status;
+ ULONG fileCacheQuantum;
+#endif
PFILE_OBJECT fileObject;
- ULONG fileCacheQuantum;
PVFATCCB newCCB;
fileObject = IoCreateStreamFileObject (NULL, vcb->StorageDevice);
@@ -344,7 +350,7 @@
fileObject->FsContext2 = newCCB;
fcb->FileObject = fileObject;
-
+#ifdef USE_ROS_CC_AND_FS
fileCacheQuantum = (vcb->FatInfo.BytesPerCluster >= PAGE_SIZE) ?
vcb->FatInfo.BytesPerCluster : PAGE_SIZE;
@@ -355,10 +361,22 @@
DbgPrint ("CcRosInitializeFileCache failed\n");
KEBUGCHECK (0);
}
+#else
+ /* FIXME: Guard by SEH. */
+ CcInitializeCacheMap(fileObject,
+ (PCC_FILE_SIZES)(&fcb->RFCB.AllocationSize),
+ FALSE,
+ &VfatGlobalData->CacheMgrCallbacks,
+ fcb);
+#endif
fcb->Flags |= FCB_CACHE_INITIALIZED;
+#ifdef USE_ROS_CC_AND_FS
return status;
+#else
+ return STATUS_SUCCESS;
+#endif
}
PVFATFCB
_____
Modified: trunk/reactos/drivers/fs/vfat/fsctl.c
--- trunk/reactos/drivers/fs/vfat/fsctl.c 2005-01-12 12:33:57 UTC
(rev 12960)
+++ trunk/reactos/drivers/fs/vfat/fsctl.c 2005-01-12 13:00:43 UTC
(rev 12961)
@@ -517,6 +517,7 @@
Fcb->RFCB.ValidDataLength = Fcb->RFCB.FileSize;
Fcb->RFCB.AllocationSize = Fcb->RFCB.FileSize;
+#ifdef USE_ROS_CC_AND_FS
if (DeviceExt->FatInfo.FatType != FAT12)
{
Status = CcRosInitializeFileCache(DeviceExt->FATFileObject,
CACHEPAGESIZE(DeviceExt));
@@ -530,6 +531,14 @@
DPRINT1 ("CcRosInitializeFileCache failed\n");
goto ByeBye;
}
+#else
+ /* FIXME: Guard by SEH. */
+ CcInitializeCacheMap(DeviceExt->FATFileObject,
+ (PCC_FILE_SIZES)(&Fcb->RFCB.AllocationSize),
+ FALSE,
+ &VfatGlobalData->CacheMgrCallbacks,
+ Fcb);
+#endif
DeviceExt->LastAvailableCluster = 2;
ExInitializeResourceLite(&DeviceExt->DirResource);
ExInitializeResourceLite(&DeviceExt->FatResource);
@@ -744,6 +753,7 @@
return STATUS_INVALID_DEVICE_REQUEST;
}
+#ifdef USE_ROS_CC_AND_FS
static NTSTATUS
VfatRosQueryLcnMapping(PVFAT_IRP_CONTEXT IrpContext)
{
@@ -765,6 +775,7 @@
IrpContext->Irp->IoStatus.Information =
sizeof(ROS_QUERY_LCN_MAPPING);
return(STATUS_SUCCESS);
}
+#endif
NTSTATUS VfatFileSystemControl(PVFAT_IRP_CONTEXT IrpContext)
/*
@@ -796,9 +807,11 @@
case FSCTL_MOVE_FILE:
Status = VfatMoveFile(IrpContext);
break;
+#ifdef USE_ROS_CC_AND_FS
case FSCTL_ROS_QUERY_LCN_MAPPING:
Status = VfatRosQueryLcnMapping(IrpContext);
break;
+#endif
default:
Status = STATUS_INVALID_DEVICE_REQUEST;
}
_____
Modified: trunk/reactos/drivers/fs/vfat/iface.c
--- trunk/reactos/drivers/fs/vfat/iface.c 2005-01-12 12:33:57 UTC
(rev 12960)
+++ trunk/reactos/drivers/fs/vfat/iface.c 2005-01-12 13:00:43 UTC
(rev 12961)
@@ -49,6 +49,7 @@
{
PDEVICE_OBJECT DeviceObject;
UNICODE_STRING DeviceName = RTL_CONSTANT_STRING(L"\\Fat");
+ PFAST_IO_DISPATCH pFastIoDispatch;
NTSTATUS Status;
Status = IoCreateDevice(DriverObject,
@@ -86,7 +87,19 @@
DriverObject->MajorFunction[IRP_MJ_FLUSH_BUFFERS] =
VfatBuildRequest;
DriverObject->DriverUnload = NULL;
+
+ /* Cache manager */
+ VfatGlobalData->CacheMgrCallbacks.AcquireForLazyWrite =
VfatAcquireForLazyWrite;
+ VfatGlobalData->CacheMgrCallbacks.ReleaseFromLazyWrite =
VfatReleaseFromLazyWrite;
+ VfatGlobalData->CacheMgrCallbacks.AcquireForReadAhead =
VfatAcquireForReadAhead;
+ VfatGlobalData->CacheMgrCallbacks.ReleaseFromReadAhead =
VfatReleaseFromReadAhead;
+
+ /* Fast I/O */
+ DriverObject->FastIoDispatch = pFastIoDispatch =
&VfatGlobalData->FastIoDispatch;
+ pFastIoDispatch->SizeOfFastIoDispatch = sizeof(FAST_IO_DISPATCH);
+ pFastIoDispatch->FastIoCheckIfPossible = VfatFastIoCheckIfPossible;
+ /* Private lists */
ExInitializeNPagedLookasideList(&VfatGlobalData->FcbLookasideList,
NULL, NULL, 0, sizeof(VFATFCB),
TAG_FCB, 0);
ExInitializeNPagedLookasideList(&VfatGlobalData->CcbLookasideList,
_____
Modified: trunk/reactos/drivers/fs/vfat/makefile
--- trunk/reactos/drivers/fs/vfat/makefile 2005-01-12 12:33:57 UTC
(rev 12960)
+++ trunk/reactos/drivers/fs/vfat/makefile 2005-01-12 13:00:43 UTC
(rev 12961)
@@ -19,6 +19,7 @@
direntry.o \
dirwr.o \
fat.o \
+ fastio.o \
fcb.o \
finfo.o \
iface.o \
_____
Modified: trunk/reactos/drivers/fs/vfat/rw.c
--- trunk/reactos/drivers/fs/vfat/rw.c 2005-01-12 12:33:57 UTC (rev
12960)
+++ trunk/reactos/drivers/fs/vfat/rw.c 2005-01-12 13:00:43 UTC (rev
12961)
@@ -680,10 +680,19 @@
CHECKPOINT;
if (IrpContext->FileObject->PrivateCacheMap == NULL)
{
- ULONG CacheSize;
- CacheSize =
max(IrpContext->DeviceExt->FatInfo.BytesPerCluster,
- 8 * PAGE_SIZE);
- CcRosInitializeFileCache(IrpContext->FileObject, CacheSize);
+#ifdef USE_ROS_CC_AND_FS
+ ULONG CacheSize;
+ CacheSize = max(IrpContext->DeviceExt->FatInfo.BytesPerCluster,
+ 8 * PAGE_SIZE);
+ CcRosInitializeFileCache(IrpContext->FileObject, CacheSize);
+#else
+ /* FIXME: Guard by SEH. */
+ CcInitializeCacheMap(IrpContext->FileObject,
+
(PCC_FILE_SIZES)(&Fcb->RFCB.AllocationSize),
+ FALSE,
+ &(VfatGlobalData->CacheMgrCallbacks),
+ Fcb);
+#endif
}
if (!CcCopyRead(IrpContext->FileObject, &ByteOffset, Length,
(BOOLEAN)(IrpContext->Flags &
IRPCONTEXT_CANWAIT), Buffer,
@@ -972,14 +981,23 @@
if (IrpContext->FileObject->PrivateCacheMap == NULL)
{
- ULONG CacheSize;
- CacheSize =
max(IrpContext->DeviceExt->FatInfo.BytesPerCluster,
- 8 * PAGE_SIZE);
- CcRosInitializeFileCache(IrpContext->FileObject, CacheSize);
+#ifdef USE_ROS_CC_AND_FS
+ ULONG CacheSize;
+ CacheSize =
max(IrpContext->DeviceExt->FatInfo.BytesPerCluster,
+ 8 * PAGE_SIZE);
+ CcRosInitializeFileCache(IrpContext->FileObject, CacheSize);
+#else
+ /* FIXME: Guard by SEH. */
+ CcInitializeCacheMap(IrpContext->FileObject,
+
(PCC_FILE_SIZES)(&Fcb->RFCB.AllocationSize),
+ FALSE,
+ &VfatGlobalData->CacheMgrCallbacks,
+ Fcb);
+#endif
}
if (ByteOffset.QuadPart > OldFileSize.QuadPart)
{
- CcZeroData(IrpContext->FileObject, &OldFileSize, &ByteOffset,
TRUE);
+ CcZeroData(IrpContext->FileObject, &OldFileSize, &ByteOffset,
TRUE);
}
if (CcCopyWrite(IrpContext->FileObject, &ByteOffset, Length,
1 /*IrpContext->Flags & IRPCONTEXT_CANWAIT*/,
Buffer))
_____
Modified: trunk/reactos/drivers/fs/vfat/vfat.h
--- trunk/reactos/drivers/fs/vfat/vfat.h 2005-01-12 12:33:57 UTC
(rev 12960)
+++ trunk/reactos/drivers/fs/vfat/vfat.h 2005-01-12 13:00:43 UTC
(rev 12961)
@@ -269,6 +269,8 @@
NPAGED_LOOKASIDE_LIST FcbLookasideList;
NPAGED_LOOKASIDE_LIST CcbLookasideList;
NPAGED_LOOKASIDE_LIST IrpContextLookasideList;
+ FAST_IO_DISPATCH FastIoDispatch;
+ CACHE_MANAGER_CALLBACKS CacheMgrCallbacks;
} VFAT_GLOBAL_DATA, *PVFAT_GLOBAL_DATA;
extern PVFAT_GLOBAL_DATA VfatGlobalData;
@@ -507,6 +509,32 @@
NTSTATUS VfatCleanup (PVFAT_IRP_CONTEXT IrpContext);
+/* --------------------------------------------------------- fastio.c
*/
+
+BOOLEAN NTAPI
+VfatFastIoCheckIfPossible(IN PFILE_OBJECT FileObject,
+ IN PLARGE_INTEGER FileOffset,
+ IN ULONG Lenght,
+ IN BOOLEAN Wait,
+ IN ULONG LockKey,
+ IN BOOLEAN CheckForReadOperation,
+ OUT PIO_STATUS_BLOCK IoStatus,
+ IN PDEVICE_OBJECT DeviceObject);
+
+BOOLEAN NTAPI
+VfatAcquireForLazyWrite(IN PVOID Context,
+ IN BOOLEAN Wait);
+
+VOID NTAPI
+VfatReleaseFromLazyWrite(IN PVOID Context);
+
+BOOLEAN NTAPI
+VfatAcquireForReadAhead(IN PVOID Context,
+ IN BOOLEAN Wait);
+
+VOID NTAPI
+VfatReleaseFromReadAhead(IN PVOID Context);
+
/* --------------------------------------------------------- fsctl.c
*/
NTSTATUS VfatFileSystemControl (PVFAT_IRP_CONTEXT IrpContext);