mirror of
https://github.com/reactos/reactos.git
synced 2025-06-09 03:10:18 +00:00
[NTOS:CC]
- Simplify cache segment range checks - Remove unused function CcRosFreeCacheSegment - Minor style fixes CORE-7491 svn path=/trunk/; revision=60456
This commit is contained in:
parent
e0b9f8f6af
commit
0df89bb1e8
5 changed files with 63 additions and 79 deletions
|
@ -355,13 +355,16 @@ CcCopyRead (
|
||||||
if (!Wait)
|
if (!Wait)
|
||||||
{
|
{
|
||||||
KeAcquireSpinLock(&Bcb->BcbLock, &oldirql);
|
KeAcquireSpinLock(&Bcb->BcbLock, &oldirql);
|
||||||
|
/* FIXME: this loop doesn't take into account areas that don't have
|
||||||
|
* a segment in the list yet */
|
||||||
current_entry = Bcb->BcbSegmentListHead.Flink;
|
current_entry = Bcb->BcbSegmentListHead.Flink;
|
||||||
while (current_entry != &Bcb->BcbSegmentListHead)
|
while (current_entry != &Bcb->BcbSegmentListHead)
|
||||||
{
|
{
|
||||||
current = CONTAINING_RECORD(current_entry, CACHE_SEGMENT,
|
current = CONTAINING_RECORD(current_entry, CACHE_SEGMENT,
|
||||||
BcbSegmentListEntry);
|
BcbSegmentListEntry);
|
||||||
if (!current->Valid && current->FileOffset < ReadOffset + Length
|
if (!current->Valid &&
|
||||||
&& current->FileOffset + Bcb->CacheSegmentSize > ReadOffset)
|
DoSegmentsIntersect(current->FileOffset, Bcb->CacheSegmentSize,
|
||||||
|
ReadOffset, Length))
|
||||||
{
|
{
|
||||||
KeReleaseSpinLock(&Bcb->BcbLock, oldirql);
|
KeReleaseSpinLock(&Bcb->BcbLock, oldirql);
|
||||||
IoStatus->Status = STATUS_UNSUCCESSFUL;
|
IoStatus->Status = STATUS_UNSUCCESSFUL;
|
||||||
|
@ -466,24 +469,21 @@ CcCopyWrite (
|
||||||
{
|
{
|
||||||
/* testing, if the requested datas are available */
|
/* testing, if the requested datas are available */
|
||||||
KeAcquireSpinLock(&Bcb->BcbLock, &oldirql);
|
KeAcquireSpinLock(&Bcb->BcbLock, &oldirql);
|
||||||
|
/* FIXME: this loop doesn't take into account areas that don't have
|
||||||
|
* a segment in the list yet */
|
||||||
current_entry = Bcb->BcbSegmentListHead.Flink;
|
current_entry = Bcb->BcbSegmentListHead.Flink;
|
||||||
while (current_entry != &Bcb->BcbSegmentListHead)
|
while (current_entry != &Bcb->BcbSegmentListHead)
|
||||||
{
|
{
|
||||||
CacheSeg = CONTAINING_RECORD(current_entry, CACHE_SEGMENT,
|
CacheSeg = CONTAINING_RECORD(current_entry, CACHE_SEGMENT,
|
||||||
BcbSegmentListEntry);
|
BcbSegmentListEntry);
|
||||||
if (!CacheSeg->Valid)
|
if (!CacheSeg->Valid &&
|
||||||
{
|
DoSegmentsIntersect(CacheSeg->FileOffset, Bcb->CacheSegmentSize,
|
||||||
if (((WriteOffset >= CacheSeg->FileOffset) &&
|
WriteOffset, Length))
|
||||||
(WriteOffset < CacheSeg->FileOffset + Bcb->CacheSegmentSize))
|
|
||||||
|| ((WriteOffset + Length > CacheSeg->FileOffset) &&
|
|
||||||
(WriteOffset + Length <= CacheSeg->FileOffset +
|
|
||||||
Bcb->CacheSegmentSize)))
|
|
||||||
{
|
{
|
||||||
KeReleaseSpinLock(&Bcb->BcbLock, oldirql);
|
KeReleaseSpinLock(&Bcb->BcbLock, oldirql);
|
||||||
/* datas not available */
|
/* datas not available */
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
current_entry = current_entry->Flink;
|
current_entry = current_entry->Flink;
|
||||||
}
|
}
|
||||||
KeReleaseSpinLock(&Bcb->BcbLock, oldirql);
|
KeReleaseSpinLock(&Bcb->BcbLock, oldirql);
|
||||||
|
@ -687,24 +687,21 @@ CcZeroData (
|
||||||
{
|
{
|
||||||
/* testing, if the requested datas are available */
|
/* testing, if the requested datas are available */
|
||||||
KeAcquireSpinLock(&Bcb->BcbLock, &oldirql);
|
KeAcquireSpinLock(&Bcb->BcbLock, &oldirql);
|
||||||
|
/* FIXME: this loop doesn't take into account areas that don't have
|
||||||
|
* a segment in the list yet */
|
||||||
current_entry = Bcb->BcbSegmentListHead.Flink;
|
current_entry = Bcb->BcbSegmentListHead.Flink;
|
||||||
while (current_entry != &Bcb->BcbSegmentListHead)
|
while (current_entry != &Bcb->BcbSegmentListHead)
|
||||||
{
|
{
|
||||||
CacheSeg = CONTAINING_RECORD(current_entry, CACHE_SEGMENT,
|
CacheSeg = CONTAINING_RECORD(current_entry, CACHE_SEGMENT,
|
||||||
BcbSegmentListEntry);
|
BcbSegmentListEntry);
|
||||||
if (!CacheSeg->Valid)
|
if (!CacheSeg->Valid &&
|
||||||
{
|
DoSegmentsIntersect(CacheSeg->FileOffset, Bcb->CacheSegmentSize,
|
||||||
if (((WriteOffset.u.LowPart >= CacheSeg->FileOffset) &&
|
WriteOffset.u.LowPart, Length))
|
||||||
(WriteOffset.u.LowPart < CacheSeg->FileOffset + Bcb->CacheSegmentSize))
|
|
||||||
|| ((WriteOffset.u.LowPart + Length > CacheSeg->FileOffset) &&
|
|
||||||
(WriteOffset.u.LowPart + Length <=
|
|
||||||
CacheSeg->FileOffset + Bcb->CacheSegmentSize)))
|
|
||||||
{
|
{
|
||||||
KeReleaseSpinLock(&Bcb->BcbLock, oldirql);
|
KeReleaseSpinLock(&Bcb->BcbLock, oldirql);
|
||||||
/* datas not available */
|
/* datas not available */
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
current_entry = current_entry->Flink;
|
current_entry = current_entry->Flink;
|
||||||
}
|
}
|
||||||
KeReleaseSpinLock(&Bcb->BcbLock, oldirql);
|
KeReleaseSpinLock(&Bcb->BcbLock, oldirql);
|
||||||
|
|
|
@ -159,7 +159,9 @@ CcSetFileSizes (
|
||||||
current_entry = Bcb->BcbSegmentListHead.Flink;
|
current_entry = Bcb->BcbSegmentListHead.Flink;
|
||||||
while (current_entry != &Bcb->BcbSegmentListHead)
|
while (current_entry != &Bcb->BcbSegmentListHead)
|
||||||
{
|
{
|
||||||
current = CONTAINING_RECORD(current_entry, CACHE_SEGMENT, BcbSegmentListEntry);
|
current = CONTAINING_RECORD(current_entry,
|
||||||
|
CACHE_SEGMENT,
|
||||||
|
BcbSegmentListEntry);
|
||||||
current_entry = current_entry->Flink;
|
current_entry = current_entry->Flink;
|
||||||
if (current->FileOffset > FileSizes->AllocationSize.QuadPart ||
|
if (current->FileOffset > FileSizes->AllocationSize.QuadPart ||
|
||||||
(current->FileOffset == 0 && FileSizes->AllocationSize.QuadPart == 0))
|
(current->FileOffset == 0 && FileSizes->AllocationSize.QuadPart == 0))
|
||||||
|
|
|
@ -261,7 +261,7 @@ CcUnpinRepinnedBcb (
|
||||||
{
|
{
|
||||||
IoStatus->Status = STATUS_SUCCESS;
|
IoStatus->Status = STATUS_SUCCESS;
|
||||||
}
|
}
|
||||||
KeReleaseMutex(&iBcb->CacheSegment->Mutex, 0);
|
KeReleaseMutex(&iBcb->CacheSegment->Mutex, FALSE);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
|
@ -236,7 +236,7 @@ CcRosFlushDirtyPages (
|
||||||
/* One reference is added above */
|
/* One reference is added above */
|
||||||
if (current->ReferenceCount > 2)
|
if (current->ReferenceCount > 2)
|
||||||
{
|
{
|
||||||
KeReleaseMutex(¤t->Mutex, 0);
|
KeReleaseMutex(¤t->Mutex, FALSE);
|
||||||
current->Bcb->Callbacks->ReleaseFromLazyWrite(
|
current->Bcb->Callbacks->ReleaseFromLazyWrite(
|
||||||
current->Bcb->LazyWriteContext);
|
current->Bcb->LazyWriteContext);
|
||||||
CcRosCacheSegmentDecRefCount(current);
|
CcRosCacheSegmentDecRefCount(current);
|
||||||
|
@ -249,7 +249,7 @@ CcRosFlushDirtyPages (
|
||||||
|
|
||||||
Status = CcRosFlushCacheSegment(current);
|
Status = CcRosFlushCacheSegment(current);
|
||||||
|
|
||||||
KeReleaseMutex(¤t->Mutex, 0);
|
KeReleaseMutex(¤t->Mutex, FALSE);
|
||||||
current->Bcb->Callbacks->ReleaseFromLazyWrite(
|
current->Bcb->Callbacks->ReleaseFromLazyWrite(
|
||||||
current->Bcb->LazyWriteContext);
|
current->Bcb->LazyWriteContext);
|
||||||
|
|
||||||
|
@ -446,7 +446,7 @@ CcRosReleaseCacheSegment (
|
||||||
|
|
||||||
KeReleaseSpinLock(&Bcb->BcbLock, oldIrql);
|
KeReleaseSpinLock(&Bcb->BcbLock, oldIrql);
|
||||||
KeReleaseGuardedMutex(&ViewLock);
|
KeReleaseGuardedMutex(&ViewLock);
|
||||||
KeReleaseMutex(&CacheSeg->Mutex, 0);
|
KeReleaseMutex(&CacheSeg->Mutex, FALSE);
|
||||||
|
|
||||||
return(STATUS_SUCCESS);
|
return(STATUS_SUCCESS);
|
||||||
}
|
}
|
||||||
|
@ -474,8 +474,8 @@ CcRosLookupCacheSegment (
|
||||||
{
|
{
|
||||||
current = CONTAINING_RECORD(current_entry, CACHE_SEGMENT,
|
current = CONTAINING_RECORD(current_entry, CACHE_SEGMENT,
|
||||||
BcbSegmentListEntry);
|
BcbSegmentListEntry);
|
||||||
if ((current->FileOffset <= FileOffset) &&
|
if (IsPointInSegment(current->FileOffset, Bcb->CacheSegmentSize,
|
||||||
((current->FileOffset + Bcb->CacheSegmentSize) > FileOffset))
|
FileOffset))
|
||||||
{
|
{
|
||||||
CcRosCacheSegmentIncRefCount(current);
|
CcRosCacheSegmentIncRefCount(current);
|
||||||
KeReleaseSpinLock(&Bcb->BcbLock, oldIrql);
|
KeReleaseSpinLock(&Bcb->BcbLock, oldIrql);
|
||||||
|
@ -485,7 +485,7 @@ CcRosLookupCacheSegment (
|
||||||
KernelMode,
|
KernelMode,
|
||||||
FALSE,
|
FALSE,
|
||||||
NULL);
|
NULL);
|
||||||
return(current);
|
return current;
|
||||||
}
|
}
|
||||||
current_entry = current_entry->Flink;
|
current_entry = current_entry->Flink;
|
||||||
}
|
}
|
||||||
|
@ -493,7 +493,7 @@ CcRosLookupCacheSegment (
|
||||||
KeReleaseSpinLock(&Bcb->BcbLock, oldIrql);
|
KeReleaseSpinLock(&Bcb->BcbLock, oldIrql);
|
||||||
KeReleaseGuardedMutex(&ViewLock);
|
KeReleaseGuardedMutex(&ViewLock);
|
||||||
|
|
||||||
return(NULL);
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
NTSTATUS
|
NTSTATUS
|
||||||
|
@ -536,7 +536,7 @@ CcRosMarkDirtyCacheSegment (
|
||||||
|
|
||||||
KeReleaseSpinLock(&Bcb->BcbLock, oldIrql);
|
KeReleaseSpinLock(&Bcb->BcbLock, oldIrql);
|
||||||
KeReleaseGuardedMutex(&ViewLock);
|
KeReleaseGuardedMutex(&ViewLock);
|
||||||
KeReleaseMutex(&CacheSeg->Mutex, 0);
|
KeReleaseMutex(&CacheSeg->Mutex, FALSE);
|
||||||
|
|
||||||
return(STATUS_SUCCESS);
|
return(STATUS_SUCCESS);
|
||||||
}
|
}
|
||||||
|
@ -589,7 +589,7 @@ CcRosUnmapCacheSegment (
|
||||||
|
|
||||||
KeReleaseSpinLock(&Bcb->BcbLock, oldIrql);
|
KeReleaseSpinLock(&Bcb->BcbLock, oldIrql);
|
||||||
KeReleaseGuardedMutex(&ViewLock);
|
KeReleaseGuardedMutex(&ViewLock);
|
||||||
KeReleaseMutex(&CacheSeg->Mutex, 0);
|
KeReleaseMutex(&CacheSeg->Mutex, FALSE);
|
||||||
|
|
||||||
return(STATUS_SUCCESS);
|
return(STATUS_SUCCESS);
|
||||||
}
|
}
|
||||||
|
@ -659,8 +659,8 @@ CcRosCreateCacheSegment (
|
||||||
{
|
{
|
||||||
current = CONTAINING_RECORD(current_entry, CACHE_SEGMENT,
|
current = CONTAINING_RECORD(current_entry, CACHE_SEGMENT,
|
||||||
BcbSegmentListEntry);
|
BcbSegmentListEntry);
|
||||||
if (current->FileOffset <= FileOffset &&
|
if (IsPointInSegment(current->FileOffset, Bcb->CacheSegmentSize,
|
||||||
(current->FileOffset + Bcb->CacheSegmentSize) > FileOffset)
|
FileOffset))
|
||||||
{
|
{
|
||||||
CcRosCacheSegmentIncRefCount(current);
|
CcRosCacheSegmentIncRefCount(current);
|
||||||
KeReleaseSpinLock(&Bcb->BcbLock, oldIrql);
|
KeReleaseSpinLock(&Bcb->BcbLock, oldIrql);
|
||||||
|
@ -673,7 +673,7 @@ CcRosCreateCacheSegment (
|
||||||
current );
|
current );
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
KeReleaseMutex(&(*CacheSeg)->Mutex, 0);
|
KeReleaseMutex(&(*CacheSeg)->Mutex, FALSE);
|
||||||
KeReleaseGuardedMutex(&ViewLock);
|
KeReleaseGuardedMutex(&ViewLock);
|
||||||
ExFreeToNPagedLookasideList(&CacheSegLookasideList, *CacheSeg);
|
ExFreeToNPagedLookasideList(&CacheSegLookasideList, *CacheSeg);
|
||||||
*CacheSeg = current;
|
*CacheSeg = current;
|
||||||
|
@ -996,38 +996,6 @@ CcRosInternalFreeCacheSegment (
|
||||||
return(STATUS_SUCCESS);
|
return(STATUS_SUCCESS);
|
||||||
}
|
}
|
||||||
|
|
||||||
NTSTATUS
|
|
||||||
NTAPI
|
|
||||||
CcRosFreeCacheSegment (
|
|
||||||
PBCB Bcb,
|
|
||||||
PCACHE_SEGMENT CacheSeg)
|
|
||||||
{
|
|
||||||
NTSTATUS Status;
|
|
||||||
KIRQL oldIrql;
|
|
||||||
|
|
||||||
ASSERT(Bcb);
|
|
||||||
|
|
||||||
DPRINT("CcRosFreeCacheSegment(Bcb 0x%p, CacheSeg 0x%p)\n",
|
|
||||||
Bcb, CacheSeg);
|
|
||||||
|
|
||||||
KeAcquireGuardedMutex(&ViewLock);
|
|
||||||
KeAcquireSpinLock(&Bcb->BcbLock, &oldIrql);
|
|
||||||
RemoveEntryList(&CacheSeg->BcbSegmentListEntry);
|
|
||||||
RemoveEntryList(&CacheSeg->CacheSegmentListEntry);
|
|
||||||
RemoveEntryList(&CacheSeg->CacheSegmentLRUListEntry);
|
|
||||||
if (CacheSeg->Dirty)
|
|
||||||
{
|
|
||||||
RemoveEntryList(&CacheSeg->DirtySegmentListEntry);
|
|
||||||
DirtyPageCount -= Bcb->CacheSegmentSize / PAGE_SIZE;
|
|
||||||
|
|
||||||
}
|
|
||||||
KeReleaseSpinLock(&Bcb->BcbLock, oldIrql);
|
|
||||||
KeReleaseGuardedMutex(&ViewLock);
|
|
||||||
|
|
||||||
Status = CcRosInternalFreeCacheSegment(CacheSeg);
|
|
||||||
return(Status);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* @implemented
|
* @implemented
|
||||||
*/
|
*/
|
||||||
|
@ -1081,7 +1049,7 @@ CcFlushCache (
|
||||||
IoStatus->Status = Status;
|
IoStatus->Status = Status;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
KeReleaseMutex(¤t->Mutex, 0);
|
KeReleaseMutex(¤t->Mutex, FALSE);
|
||||||
|
|
||||||
KeAcquireGuardedMutex(&ViewLock);
|
KeAcquireGuardedMutex(&ViewLock);
|
||||||
KeAcquireSpinLock(&Bcb->BcbLock, &oldIrql);
|
KeAcquireSpinLock(&Bcb->BcbLock, &oldIrql);
|
||||||
|
@ -1148,7 +1116,6 @@ CcRosDeleteFileCache (
|
||||||
*/
|
*/
|
||||||
InitializeListHead(&FreeList);
|
InitializeListHead(&FreeList);
|
||||||
KeAcquireSpinLock(&Bcb->BcbLock, &oldIrql);
|
KeAcquireSpinLock(&Bcb->BcbLock, &oldIrql);
|
||||||
current_entry = Bcb->BcbSegmentListHead.Flink;
|
|
||||||
while (!IsListEmpty(&Bcb->BcbSegmentListHead))
|
while (!IsListEmpty(&Bcb->BcbSegmentListHead))
|
||||||
{
|
{
|
||||||
current_entry = RemoveTailList(&Bcb->BcbSegmentListHead);
|
current_entry = RemoveTailList(&Bcb->BcbSegmentListHead);
|
||||||
|
|
|
@ -203,13 +203,6 @@ VOID
|
||||||
NTAPI
|
NTAPI
|
||||||
CcInitView(VOID);
|
CcInitView(VOID);
|
||||||
|
|
||||||
NTSTATUS
|
|
||||||
NTAPI
|
|
||||||
CcRosFreeCacheSegment(
|
|
||||||
PBCB,
|
|
||||||
PCACHE_SEGMENT
|
|
||||||
);
|
|
||||||
|
|
||||||
NTSTATUS
|
NTSTATUS
|
||||||
NTAPI
|
NTAPI
|
||||||
ReadCacheSegment(PCACHE_SEGMENT CacheSeg);
|
ReadCacheSegment(PCACHE_SEGMENT CacheSeg);
|
||||||
|
@ -315,3 +308,28 @@ CcRosReleaseFileCache(
|
||||||
NTSTATUS
|
NTSTATUS
|
||||||
NTAPI
|
NTAPI
|
||||||
CcTryToInitializeFileCache(PFILE_OBJECT FileObject);
|
CcTryToInitializeFileCache(PFILE_OBJECT FileObject);
|
||||||
|
|
||||||
|
FORCEINLINE
|
||||||
|
BOOLEAN
|
||||||
|
DoSegmentsIntersect(
|
||||||
|
_In_ ULONG Offset1,
|
||||||
|
_In_ ULONG Length1,
|
||||||
|
_In_ ULONG Offset2,
|
||||||
|
_In_ ULONG Length2)
|
||||||
|
{
|
||||||
|
if (Offset1 + Length1 <= Offset2)
|
||||||
|
return FALSE;
|
||||||
|
if (Offset2 + Length2 <= Offset1)
|
||||||
|
return FALSE;
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
FORCEINLINE
|
||||||
|
BOOLEAN
|
||||||
|
IsPointInSegment(
|
||||||
|
_In_ ULONG Offset1,
|
||||||
|
_In_ ULONG Length1,
|
||||||
|
_In_ ULONG Point)
|
||||||
|
{
|
||||||
|
return DoSegmentsIntersect(Offset1, Length1, Point, 1);
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue