mirror of
https://github.com/reactos/reactos.git
synced 2024-12-28 10:04:49 +00:00
Based on a patch by Herve Poussineau <poussine@freesurf.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. svn path=/trunk/; revision=12961
This commit is contained in:
parent
d8fda17a06
commit
4b208cd9ff
8 changed files with 185 additions and 11 deletions
|
@ -49,7 +49,11 @@ VfatCleanupFile(PVFAT_IRP_CONTEXT IrpContext)
|
|||
/* 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--;
|
||||
|
|
79
reactos/drivers/fs/vfat/fastio.c
Normal file
79
reactos/drivers/fs/vfat/fastio.c
Normal file
|
@ -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@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));
|
||||
}
|
|
@ -228,7 +228,11 @@ vfatReleaseFCB(PDEVICE_EXTENSION pVCB, PVFATFCB pFCB)
|
|||
/* 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 @@ vfatGrabFCBFromTable(PDEVICE_EXTENSION pVCB, PUNICODE_STRING PathNameU)
|
|||
NTSTATUS
|
||||
vfatFCBInitializeCacheFromVolume (PVCB vcb, PVFATFCB fcb)
|
||||
{
|
||||
#ifdef USE_ROS_CC_AND_FS
|
||||
NTSTATUS status;
|
||||
PFILE_OBJECT fileObject;
|
||||
ULONG fileCacheQuantum;
|
||||
#endif
|
||||
PFILE_OBJECT fileObject;
|
||||
PVFATCCB newCCB;
|
||||
|
||||
fileObject = IoCreateStreamFileObject (NULL, vcb->StorageDevice);
|
||||
|
@ -344,7 +350,7 @@ vfatFCBInitializeCacheFromVolume (PVCB vcb, PVFATFCB fcb)
|
|||
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 @@ vfatFCBInitializeCacheFromVolume (PVCB vcb, PVFATFCB fcb)
|
|||
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
|
||||
|
|
|
@ -517,6 +517,7 @@ VfatMount (PVFAT_IRP_CONTEXT IrpContext)
|
|||
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 @@ VfatMount (PVFAT_IRP_CONTEXT IrpContext)
|
|||
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 @@ VfatMoveFile(PVFAT_IRP_CONTEXT IrpContext)
|
|||
return STATUS_INVALID_DEVICE_REQUEST;
|
||||
}
|
||||
|
||||
#ifdef USE_ROS_CC_AND_FS
|
||||
static NTSTATUS
|
||||
VfatRosQueryLcnMapping(PVFAT_IRP_CONTEXT IrpContext)
|
||||
{
|
||||
|
@ -765,6 +775,7 @@ VfatRosQueryLcnMapping(PVFAT_IRP_CONTEXT IrpContext)
|
|||
IrpContext->Irp->IoStatus.Information = sizeof(ROS_QUERY_LCN_MAPPING);
|
||||
return(STATUS_SUCCESS);
|
||||
}
|
||||
#endif
|
||||
|
||||
NTSTATUS VfatFileSystemControl(PVFAT_IRP_CONTEXT IrpContext)
|
||||
/*
|
||||
|
@ -796,9 +807,11 @@ NTSTATUS VfatFileSystemControl(PVFAT_IRP_CONTEXT IrpContext)
|
|||
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;
|
||||
}
|
||||
|
|
|
@ -49,6 +49,7 @@ DriverEntry(PDRIVER_OBJECT DriverObject,
|
|||
{
|
||||
PDEVICE_OBJECT DeviceObject;
|
||||
UNICODE_STRING DeviceName = RTL_CONSTANT_STRING(L"\\Fat");
|
||||
PFAST_IO_DISPATCH pFastIoDispatch;
|
||||
NTSTATUS Status;
|
||||
|
||||
Status = IoCreateDevice(DriverObject,
|
||||
|
@ -87,6 +88,18 @@ DriverEntry(PDRIVER_OBJECT DriverObject,
|
|||
|
||||
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,
|
||||
|
|
|
@ -19,6 +19,7 @@ TARGET_OBJECTS = \
|
|||
direntry.o \
|
||||
dirwr.o \
|
||||
fat.o \
|
||||
fastio.o \
|
||||
fcb.o \
|
||||
finfo.o \
|
||||
iface.o \
|
||||
|
|
|
@ -680,10 +680,19 @@ VfatRead(PVFAT_IRP_CONTEXT IrpContext)
|
|||
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 @@ NTSTATUS VfatWrite (PVFAT_IRP_CONTEXT IrpContext)
|
|||
|
||||
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))
|
||||
|
|
|
@ -269,6 +269,8 @@ typedef struct
|
|||
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 VfatCloseFile(PDEVICE_EXTENSION DeviceExt,
|
|||
|
||||
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);
|
||||
|
|
Loading…
Reference in a new issue