mirror of
https://github.com/reactos/reactos.git
synced 2024-07-02 10:45:24 +00:00
- Experimentally switch fastfat driver to non-Ros Cc functions, and thus no FSD in ReactOS are using CcRos-specific functions anymore.
- Assume VACB_MAPPING_GRANULARITY as a default cache segment size. - Use FSD callbacks instead of direct accessing FCB's MainResource via FileObject/FsContext. This allows removing of ObReferenceObject(FileObject) which I had to add some time ago in order to keep FileObject alive for the lazy writer thread. - IMPORTANT: Testers should thoroughly try this revision in order to see if any new problems appear. If they do appear, this revision will most probably be reverted by me. svn path=/trunk/; revision=32612
This commit is contained in:
parent
c5caa4ae89
commit
0132307d9b
|
@ -78,11 +78,7 @@ VfatCleanupFile(PVFAT_IRP_CONTEXT IrpContext)
|
|||
if (tmpFileObject != NULL)
|
||||
{
|
||||
pFcb->FileObject = NULL;
|
||||
#ifdef USE_ROS_CC_AND_FS
|
||||
CcRosReleaseFileCache(tmpFileObject);
|
||||
#else
|
||||
CcUninitializeCacheMap(tmpFileObject, NULL, NULL);
|
||||
#endif
|
||||
ObDereferenceObject(tmpFileObject);
|
||||
}
|
||||
|
||||
|
@ -94,14 +90,10 @@ VfatCleanupFile(PVFAT_IRP_CONTEXT IrpContext)
|
|||
#endif
|
||||
}
|
||||
/* Uninitialize file cache if. */
|
||||
#ifdef USE_ROS_CC_AND_FS
|
||||
CcRosReleaseFileCache (FileObject);
|
||||
#else
|
||||
if (FileObject->SectionObjectPointer->SharedCacheMap)
|
||||
{
|
||||
CcUninitializeCacheMap (FileObject, &pFcb->RFCB.FileSize, NULL);
|
||||
}
|
||||
#endif
|
||||
if (pFcb->OpenHandleCount != 0)
|
||||
{
|
||||
IoRemoveShareAccess(FileObject, &pFcb->FCBShareAccess);
|
||||
|
|
|
@ -314,10 +314,6 @@ vfatGrabFCBFromTable(PDEVICE_EXTENSION pVCB, PUNICODE_STRING PathNameU)
|
|||
static NTSTATUS
|
||||
vfatFCBInitializeCacheFromVolume (PVCB vcb, PVFATFCB fcb)
|
||||
{
|
||||
#ifdef USE_ROS_CC_AND_FS
|
||||
NTSTATUS status;
|
||||
ULONG fileCacheQuantum;
|
||||
#endif
|
||||
PFILE_OBJECT fileObject;
|
||||
PVFATCCB newCCB;
|
||||
|
||||
|
@ -336,25 +332,12 @@ vfatFCBInitializeCacheFromVolume (PVCB vcb, PVFATFCB fcb)
|
|||
fcb->FileObject = fileObject;
|
||||
fcb->RefCount++;
|
||||
|
||||
#ifdef USE_ROS_CC_AND_FS
|
||||
fileCacheQuantum = (vcb->FatInfo.BytesPerCluster >= PAGE_SIZE) ?
|
||||
vcb->FatInfo.BytesPerCluster : PAGE_SIZE;
|
||||
|
||||
status = CcRosInitializeFileCache (fileObject,
|
||||
fileCacheQuantum);
|
||||
if (!NT_SUCCESS (status))
|
||||
{
|
||||
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;
|
||||
return STATUS_SUCCESS;
|
||||
|
|
|
@ -534,28 +534,13 @@ 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));
|
||||
}
|
||||
else
|
||||
{
|
||||
Status = CcRosInitializeFileCache(DeviceExt->FATFileObject, 2 * PAGE_SIZE);
|
||||
}
|
||||
if (!NT_SUCCESS (Status))
|
||||
{
|
||||
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);
|
||||
|
|
|
@ -671,19 +671,12 @@ VfatRead(PVFAT_IRP_CONTEXT IrpContext)
|
|||
CHECKPOINT;
|
||||
if (IrpContext->FileObject->PrivateCacheMap == NULL)
|
||||
{
|
||||
#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,19 +965,12 @@ NTSTATUS VfatWrite (PVFAT_IRP_CONTEXT IrpContext)
|
|||
|
||||
if (IrpContext->FileObject->PrivateCacheMap == NULL)
|
||||
{
|
||||
#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)
|
||||
{
|
||||
|
|
|
@ -92,7 +92,8 @@ CcInitializeCacheMap (
|
|||
|
||||
/* Call old ROS cache init function */
|
||||
CcRosInitializeFileCache(FileObject,
|
||||
PAGE_SIZE/*VACB_MAPPING_GRANULARITY*/);
|
||||
/*PAGE_SIZE*/ VACB_MAPPING_GRANULARITY, CallBacks,
|
||||
LazyWriterContext);
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
|
@ -238,23 +238,19 @@ CcRosFlushDirtyPages(ULONG Target, PULONG Count)
|
|||
DirtySegmentListEntry);
|
||||
current_entry = current_entry->Flink;
|
||||
|
||||
/* This Ros-specific function needs FileObject to be referenced,
|
||||
ohterwise it may be deleted while this function still works
|
||||
with it */
|
||||
ObReferenceObject(current->Bcb->FileObject);
|
||||
|
||||
Locked = ExTryToAcquireResourceExclusiveLite(((FSRTL_COMMON_FCB_HEADER*)(current->Bcb->FileObject->FsContext))->Resource);
|
||||
Locked = current->Bcb->Callbacks->AcquireForLazyWrite(
|
||||
current->Bcb->LazyWriteContext, FALSE);
|
||||
if (!Locked)
|
||||
{
|
||||
ObDereferenceObject(current->Bcb->FileObject);
|
||||
continue;
|
||||
}
|
||||
|
||||
Locked = ExTryToAcquirePushLockExclusive(¤t->Lock);
|
||||
if (!Locked)
|
||||
{
|
||||
ExReleaseResourceLite(((FSRTL_COMMON_FCB_HEADER*)(current->Bcb->FileObject->FsContext))->Resource);
|
||||
ObDereferenceObject(current->Bcb->FileObject);
|
||||
current->Bcb->Callbacks->ReleaseFromLazyWrite(
|
||||
current->Bcb->LazyWriteContext);
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -262,20 +258,20 @@ CcRosFlushDirtyPages(ULONG Target, PULONG Count)
|
|||
if (current->ReferenceCount > 1)
|
||||
{
|
||||
ExReleasePushLock(¤t->Lock);
|
||||
ExReleaseResourceLite(((FSRTL_COMMON_FCB_HEADER*)(current->Bcb->FileObject->FsContext))->Resource);
|
||||
ObDereferenceObject(current->Bcb->FileObject);
|
||||
current->Bcb->Callbacks->ReleaseFromLazyWrite(
|
||||
current->Bcb->LazyWriteContext);
|
||||
continue;
|
||||
}
|
||||
|
||||
PagesPerSegment = current->Bcb->CacheSegmentSize / PAGE_SIZE;
|
||||
|
||||
KeReleaseGuardedMutex(&ViewLock);
|
||||
|
||||
|
||||
Status = CcRosFlushCacheSegment(current);
|
||||
|
||||
ExReleasePushLock(¤t->Lock);
|
||||
ExReleaseResourceLite(((FSRTL_COMMON_FCB_HEADER*)(current->Bcb->FileObject->FsContext))->Resource);
|
||||
ObDereferenceObject(current->Bcb->FileObject);
|
||||
current->Bcb->Callbacks->ReleaseFromLazyWrite(
|
||||
current->Bcb->LazyWriteContext);
|
||||
|
||||
if (!NT_SUCCESS(Status) && (Status != STATUS_END_OF_FILE))
|
||||
{
|
||||
|
@ -711,7 +707,7 @@ CcRosCreateCacheSegment(PBCB Bcb,
|
|||
KEBUGCHECKCC;
|
||||
}
|
||||
#endif
|
||||
Pfn = alloca(sizeof(PFN_TYPE) * (Bcb->CacheSegmentSize / PAGE_SIZE));
|
||||
Pfn = alloca(sizeof(PFN_TYPE) * ((Bcb->CacheSegmentSize / PAGE_SIZE)));
|
||||
for (i = 0; i < (Bcb->CacheSegmentSize / PAGE_SIZE); i++)
|
||||
{
|
||||
Status = MmRequestPageMemoryConsumer(MC_CACHE, TRUE, &Pfn[i]);
|
||||
|
@ -729,6 +725,7 @@ CcRosCreateCacheSegment(PBCB Bcb,
|
|||
{
|
||||
KEBUGCHECKCC;
|
||||
}
|
||||
|
||||
return(STATUS_SUCCESS);
|
||||
}
|
||||
|
||||
|
@ -1259,9 +1256,11 @@ CcTryToInitializeFileCache(PFILE_OBJECT FileObject)
|
|||
}
|
||||
|
||||
|
||||
NTSTATUS STDCALL
|
||||
NTSTATUS NTAPI
|
||||
CcRosInitializeFileCache(PFILE_OBJECT FileObject,
|
||||
ULONG CacheSegmentSize)
|
||||
ULONG CacheSegmentSize,
|
||||
PCACHE_MANAGER_CALLBACKS CallBacks,
|
||||
PVOID LazyWriterContext)
|
||||
/*
|
||||
* FUNCTION: Initializes a BCB for a file object
|
||||
*/
|
||||
|
@ -1275,39 +1274,41 @@ CcRosInitializeFileCache(PFILE_OBJECT FileObject,
|
|||
KeAcquireGuardedMutex(&ViewLock);
|
||||
if (Bcb == NULL)
|
||||
{
|
||||
Bcb = ExAllocateFromNPagedLookasideList(&BcbLookasideList);
|
||||
if (Bcb == NULL)
|
||||
{
|
||||
KeReleaseGuardedMutex(&ViewLock);
|
||||
return(STATUS_UNSUCCESSFUL);
|
||||
}
|
||||
memset(Bcb, 0, sizeof(BCB));
|
||||
ObReferenceObjectByPointer(FileObject,
|
||||
FILE_ALL_ACCESS,
|
||||
NULL,
|
||||
KernelMode);
|
||||
Bcb->FileObject = FileObject;
|
||||
Bcb->CacheSegmentSize = CacheSegmentSize;
|
||||
if (FileObject->FsContext)
|
||||
{
|
||||
Bcb->AllocationSize =
|
||||
((PFSRTL_COMMON_FCB_HEADER)FileObject->FsContext)->AllocationSize;
|
||||
Bcb->FileSize =
|
||||
((PFSRTL_COMMON_FCB_HEADER)FileObject->FsContext)->FileSize;
|
||||
}
|
||||
KeInitializeSpinLock(&Bcb->BcbLock);
|
||||
InitializeListHead(&Bcb->BcbSegmentListHead);
|
||||
FileObject->SectionObjectPointer->SharedCacheMap = Bcb;
|
||||
Bcb = ExAllocateFromNPagedLookasideList(&BcbLookasideList);
|
||||
if (Bcb == NULL)
|
||||
{
|
||||
KeReleaseGuardedMutex(&ViewLock);
|
||||
return(STATUS_UNSUCCESSFUL);
|
||||
}
|
||||
memset(Bcb, 0, sizeof(BCB));
|
||||
ObReferenceObjectByPointer(FileObject,
|
||||
FILE_ALL_ACCESS,
|
||||
NULL,
|
||||
KernelMode);
|
||||
Bcb->FileObject = FileObject;
|
||||
Bcb->CacheSegmentSize = CacheSegmentSize;
|
||||
Bcb->Callbacks = CallBacks;
|
||||
Bcb->LazyWriteContext = LazyWriterContext;
|
||||
if (FileObject->FsContext)
|
||||
{
|
||||
Bcb->AllocationSize =
|
||||
((PFSRTL_COMMON_FCB_HEADER)FileObject->FsContext)->AllocationSize;
|
||||
Bcb->FileSize =
|
||||
((PFSRTL_COMMON_FCB_HEADER)FileObject->FsContext)->FileSize;
|
||||
}
|
||||
KeInitializeSpinLock(&Bcb->BcbLock);
|
||||
InitializeListHead(&Bcb->BcbSegmentListHead);
|
||||
FileObject->SectionObjectPointer->SharedCacheMap = Bcb;
|
||||
}
|
||||
if (FileObject->PrivateCacheMap == NULL)
|
||||
{
|
||||
FileObject->PrivateCacheMap = Bcb;
|
||||
Bcb->RefCount++;
|
||||
FileObject->PrivateCacheMap = Bcb;
|
||||
Bcb->RefCount++;
|
||||
}
|
||||
if (Bcb->BcbRemoveListEntry.Flink != NULL)
|
||||
{
|
||||
RemoveEntryList(&Bcb->BcbRemoveListEntry);
|
||||
Bcb->BcbRemoveListEntry.Flink = NULL;
|
||||
RemoveEntryList(&Bcb->BcbRemoveListEntry);
|
||||
Bcb->BcbRemoveListEntry.Flink = NULL;
|
||||
}
|
||||
KeReleaseGuardedMutex(&ViewLock);
|
||||
|
||||
|
|
|
@ -112,6 +112,8 @@ typedef struct _BCB
|
|||
ULONG CacheSegmentSize;
|
||||
LARGE_INTEGER AllocationSize;
|
||||
LARGE_INTEGER FileSize;
|
||||
PCACHE_MANAGER_CALLBACKS Callbacks;
|
||||
PVOID LazyWriteContext;
|
||||
KSPIN_LOCK BcbLock;
|
||||
ULONG RefCount;
|
||||
#if defined(DBG) || defined(KDBG)
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
; ReactOS Operating System
|
||||
;
|
||||
EXPORTS
|
||||
CcRosInitializeFileCache@8
|
||||
CcRosInitializeFileCache
|
||||
CcRosReleaseFileCache@4
|
||||
CcRosTraceCacheMap@8
|
||||
CcCanIWrite@16
|
||||
|
|
Loading…
Reference in a new issue