Author: fireball
Date: Mon Apr 29 10:28:58 2013
New Revision: 58890
URL:
http://svn.reactos.org/svn/reactos?rev=58890&view=rev
Log:
[FSRTL]
- Reformat the code for better readability. Sacrifice 80 chars max line width in favor of
a readable code (sorry, but when the indentation eats 12 chars, formulas for calculating
sizes are hard to fit into less than 70 chars, and they become totally unreadable).
Modified:
trunk/reactos/ntoskrnl/fsrtl/largemcb.c
Modified: trunk/reactos/ntoskrnl/fsrtl/largemcb.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/fsrtl/largemcb.c?…
==============================================================================
--- trunk/reactos/ntoskrnl/fsrtl/largemcb.c [iso-8859-1] (original)
+++ trunk/reactos/ntoskrnl/fsrtl/largemcb.c [iso-8859-1] Mon Apr 29 10:28:58 2013
@@ -21,10 +21,10 @@
typedef struct _LARGE_MCB_MAPPING_ENTRY
{
- LARGE_INTEGER RunStartVbn;
- LARGE_INTEGER SectorCount;
- LARGE_INTEGER StartingLbn;
- LIST_ENTRY Sequence;
+ LARGE_INTEGER RunStartVbn;
+ LARGE_INTEGER SectorCount;
+ LARGE_INTEGER StartingLbn;
+ LIST_ENTRY Sequence;
} LARGE_MCB_MAPPING_ENTRY, *PLARGE_MCB_MAPPING_ENTRY;
typedef struct _LARGE_MCB_MAPPING
@@ -44,29 +44,27 @@
static PVOID NTAPI McbMappingAllocate(PRTL_GENERIC_TABLE Table, CLONG Bytes)
{
- PVOID Result;
- PBASE_MCB Mcb = (PBASE_MCB)Table->TableContext;
- Result = ExAllocatePoolWithTag(Mcb->PoolType, Bytes, 'LMCB');
- DPRINT("McbMappingAllocate(%d) => %p\n", Bytes, Result);
- return Result;
+ PVOID Result;
+ PBASE_MCB Mcb = (PBASE_MCB)Table->TableContext;
+ Result = ExAllocatePoolWithTag(Mcb->PoolType, Bytes, 'LMCB');
+ DPRINT("McbMappingAllocate(%d) => %p\n", Bytes, Result);
+ return Result;
}
static VOID NTAPI McbMappingFree(PRTL_GENERIC_TABLE Table, PVOID Buffer)
{
- DPRINT("McbMappingFree(%p)\n", Buffer);
- ExFreePoolWithTag(Buffer, 'LMCB');
+ DPRINT("McbMappingFree(%p)\n", Buffer);
+ ExFreePoolWithTag(Buffer, 'LMCB');
}
static RTL_GENERIC_COMPARE_RESULTS NTAPI McbMappingCompare
(RTL_GENERIC_TABLE Table, PVOID PtrA, PVOID PtrB)
{
- PLARGE_MCB_MAPPING_ENTRY A = PtrA, B = PtrB;
- return
- (A->RunStartVbn.QuadPart + A->SectorCount.QuadPart <
- B->RunStartVbn.QuadPart) ? GenericLessThan :
- (A->RunStartVbn.QuadPart >
- B->RunStartVbn.QuadPart + B->SectorCount.QuadPart) ?
- GenericGreaterThan : GenericEqual;
+ PLARGE_MCB_MAPPING_ENTRY A = PtrA, B = PtrB;
+
+ return
+ (A->RunStartVbn.QuadPart + A->SectorCount.QuadPart <
B->RunStartVbn.QuadPart) ? GenericLessThan :
+ (A->RunStartVbn.QuadPart > B->RunStartVbn.QuadPart +
B->SectorCount.QuadPart) ? GenericGreaterThan : GenericEqual;
}
/* PUBLIC FUNCTIONS **********************************************************/
@@ -82,66 +80,64 @@
IN LONGLONG SectorCount)
{
PBASE_MCB_INTERNAL Mcb = (PBASE_MCB_INTERNAL)OpaqueMcb;
- LARGE_MCB_MAPPING_ENTRY Node;
- PLARGE_MCB_MAPPING_ENTRY Existing = NULL;
- BOOLEAN NewElement = FALSE;
-
- Node.RunStartVbn.QuadPart = Vbn;
- Node.StartingLbn.QuadPart = Lbn;
- Node.SectorCount.QuadPart = SectorCount;
-
- while (!NewElement)
- {
- DPRINT("Inserting %x:%x\n", Node.RunStartVbn.LowPart,
Node.SectorCount.LowPart);
- Existing = RtlInsertElementGenericTable(&Mcb->Mapping->Table, &Node,
sizeof(Node), &NewElement);
- DPRINT("Existing %x\n", Existing);
- if (!Existing) break;
-
- DPRINT("NewElement %d\n", NewElement);
- if (!NewElement)
- {
- // We merge the existing runs
- LARGE_INTEGER StartVbn, FinalVbn;
- DPRINT("Existing: %x:%x\n", Existing->RunStartVbn.LowPart,
Node.SectorCount.LowPart);
- if (Existing->RunStartVbn.QuadPart < Node.RunStartVbn.QuadPart)
- {
- StartVbn = Existing->RunStartVbn;
- Node.StartingLbn = Existing->StartingLbn;
- }
- else
- {
- StartVbn = Node.RunStartVbn;
- }
- DPRINT("StartVbn %x\n", StartVbn.LowPart);
- if (Existing->RunStartVbn.QuadPart + Existing->SectorCount.QuadPart >
- Node.RunStartVbn.QuadPart + Node.SectorCount.QuadPart)
- {
- FinalVbn.QuadPart =
- Existing->RunStartVbn.QuadPart + Existing->SectorCount.QuadPart;
- }
- else
- {
- FinalVbn.QuadPart =
- Node.RunStartVbn.QuadPart + Node.SectorCount.QuadPart;
- }
- DPRINT("FinalVbn %x\n", FinalVbn.LowPart);
- Node.RunStartVbn.QuadPart = StartVbn.QuadPart;
- Node.SectorCount.QuadPart = FinalVbn.QuadPart - StartVbn.QuadPart;
- RemoveHeadList(&Existing->Sequence);
- RtlDeleteElementGenericTable(&Mcb->Mapping->Table, Existing);
- Mcb->PairCount--;
- }
- else
- {
- DPRINT("Mapping added %x\n", Existing);
- Mcb->MaximumPairCount++;
- Mcb->PairCount++;
- InsertHeadList(&Mcb->Mapping->SequenceList, &Existing->Sequence);
- }
- }
-
- DPRINT("!!Existing %d\n", !!Existing);
- return !!Existing;
+ LARGE_MCB_MAPPING_ENTRY Node;
+ PLARGE_MCB_MAPPING_ENTRY Existing = NULL;
+ BOOLEAN NewElement = FALSE;
+
+ Node.RunStartVbn.QuadPart = Vbn;
+ Node.StartingLbn.QuadPart = Lbn;
+ Node.SectorCount.QuadPart = SectorCount;
+
+ while (!NewElement)
+ {
+ DPRINT("Inserting %x:%x\n", Node.RunStartVbn.LowPart,
Node.SectorCount.LowPart);
+ Existing = RtlInsertElementGenericTable(&Mcb->Mapping->Table,
&Node, sizeof(Node), &NewElement);
+ DPRINT("Existing %x\n", Existing);
+ if (!Existing) break;
+
+ DPRINT("NewElement %d\n", NewElement);
+ if (!NewElement)
+ {
+ // We merge the existing runs
+ LARGE_INTEGER StartVbn, FinalVbn;
+ DPRINT("Existing: %x:%x\n", Existing->RunStartVbn.LowPart,
Node.SectorCount.LowPart);
+ if (Existing->RunStartVbn.QuadPart < Node.RunStartVbn.QuadPart)
+ {
+ StartVbn = Existing->RunStartVbn;
+ Node.StartingLbn = Existing->StartingLbn;
+ }
+ else
+ {
+ StartVbn = Node.RunStartVbn;
+ }
+ DPRINT("StartVbn %x\n", StartVbn.LowPart);
+ if (Existing->RunStartVbn.QuadPart + Existing->SectorCount.QuadPart
>
+ Node.RunStartVbn.QuadPart + Node.SectorCount.QuadPart)
+ {
+ FinalVbn.QuadPart = Existing->RunStartVbn.QuadPart +
Existing->SectorCount.QuadPart;
+ }
+ else
+ {
+ FinalVbn.QuadPart = Node.RunStartVbn.QuadPart +
Node.SectorCount.QuadPart;
+ }
+ DPRINT("FinalVbn %x\n", FinalVbn.LowPart);
+ Node.RunStartVbn.QuadPart = StartVbn.QuadPart;
+ Node.SectorCount.QuadPart = FinalVbn.QuadPart - StartVbn.QuadPart;
+ RemoveHeadList(&Existing->Sequence);
+ RtlDeleteElementGenericTable(&Mcb->Mapping->Table, Existing);
+ Mcb->PairCount--;
+ }
+ else
+ {
+ DPRINT("Mapping added %x\n", Existing);
+ Mcb->MaximumPairCount++;
+ Mcb->PairCount++;
+ InsertHeadList(&Mcb->Mapping->SequenceList,
&Existing->Sequence);
+ }
+ }
+
+ DPRINT("!!Existing %d\n", !!Existing);
+ return !!Existing;
}
/*
@@ -156,7 +152,7 @@
{
BOOLEAN Result;
- DPRINT("Mcb %x Vbn %x Lbn %x SectorCount %x\n", Mcb, Vbn, Lbn, SectorCount);
+ DPRINT("Mcb %x Vbn %x Lbn %x SectorCount %x\n", Mcb, Vbn, Lbn,
SectorCount);
KeAcquireGuardedMutex(Mcb->GuardedMutex);
Result = FsRtlAddBaseMcbEntry(&(Mcb->BaseMcb),
@@ -165,7 +161,7 @@
SectorCount);
KeReleaseGuardedMutex(Mcb->GuardedMutex);
- DPRINT("Done %d\n", Result);
+ DPRINT("Done %d\n", Result);
return Result;
}
@@ -182,26 +178,26 @@
OUT PLONGLONG SectorCount)
{
PBASE_MCB_INTERNAL Mcb = (PBASE_MCB_INTERNAL)OpaqueMcb;
- ULONG i = 0;
- BOOLEAN Result = FALSE;
- PLARGE_MCB_MAPPING_ENTRY Entry;
- for (Entry = (PLARGE_MCB_MAPPING_ENTRY)
- RtlEnumerateGenericTable(&Mcb->Mapping->Table, TRUE);
- Entry && i < RunIndex;
- Entry = (PLARGE_MCB_MAPPING_ENTRY)
- RtlEnumerateGenericTable(&Mcb->Mapping->Table, FALSE), i++);
- if (Entry)
- {
- Result = TRUE;
- if (Vbn)
- *Vbn = Entry->RunStartVbn.QuadPart;
- if (Lbn)
- *Lbn = Entry->StartingLbn.QuadPart;
- if (SectorCount)
- *SectorCount = Entry->SectorCount.QuadPart;
- }
-
- return Result;
+ ULONG i = 0;
+ BOOLEAN Result = FALSE;
+ PLARGE_MCB_MAPPING_ENTRY Entry;
+
+ for (Entry =
(PLARGE_MCB_MAPPING_ENTRY)RtlEnumerateGenericTable(&Mcb->Mapping->Table, TRUE);
+ Entry && (i < RunIndex);
+ Entry =
(PLARGE_MCB_MAPPING_ENTRY)RtlEnumerateGenericTable(&Mcb->Mapping->Table, FALSE),
i++);
+
+ if (Entry)
+ {
+ Result = TRUE;
+ if (Vbn)
+ *Vbn = Entry->RunStartVbn.QuadPart;
+ if (Lbn)
+ *Lbn = Entry->StartingLbn.QuadPart;
+ if (SectorCount)
+ *SectorCount = Entry->SectorCount.QuadPart;
+ }
+
+ return Result;
}
/*
@@ -217,7 +213,7 @@
{
BOOLEAN Result;
- DPRINT("FsRtlGetNextLargeMcbEntry Mcb %x RunIndex %x\n", Mcb, RunIndex);
+ DPRINT("FsRtlGetNextLargeMcbEntry Mcb %x RunIndex %x\n", Mcb, RunIndex);
KeAcquireGuardedMutex(Mcb->GuardedMutex);
Result = FsRtlGetNextBaseMcbEntry(&(Mcb->BaseMcb),
@@ -227,7 +223,7 @@
SectorCount);
KeReleaseGuardedMutex(Mcb->GuardedMutex);
- DPRINT("Done %d\n", Result);
+ DPRINT("Done %d\n", Result);
return Result;
}
@@ -250,19 +246,18 @@
else
{
Mcb->Mapping = ExAllocatePoolWithTag(PoolType |
POOL_RAISE_IF_ALLOCATION_FAILURE,
- sizeof(LARGE_MCB_MAPPING),
+ sizeof(LARGE_MCB_MAPPING),
'FSBC');
}
Mcb->PoolType = PoolType;
Mcb->MaximumPairCount = MAXIMUM_PAIR_COUNT;
- RtlInitializeGenericTable
- (&Mcb->Mapping->Table,
- (PRTL_GENERIC_COMPARE_ROUTINE)McbMappingCompare,
- McbMappingAllocate,
- McbMappingFree,
- Mcb);
- InitializeListHead(&Mcb->Mapping->SequenceList);
+ RtlInitializeGenericTable(&Mcb->Mapping->Table,
+ (PRTL_GENERIC_COMPARE_ROUTINE)McbMappingCompare,
+ McbMappingAllocate,
+ McbMappingFree,
+ Mcb);
+ InitializeListHead(&Mcb->Mapping->SequenceList);
}
/*
@@ -302,7 +297,7 @@
NULL,
NULL,
POOL_RAISE_IF_ALLOCATION_FAILURE,
- sizeof(LARGE_MCB_MAPPING),
+ sizeof(LARGE_MCB_MAPPING),
IFS_POOL_TAG,
0); /* FIXME: Should be 4 */
@@ -330,43 +325,43 @@
OUT PULONG Index OPTIONAL)
{
PBASE_MCB_INTERNAL Mcb = (PBASE_MCB_INTERNAL)OpaqueMcb;
- BOOLEAN Result = FALSE;
- LARGE_MCB_MAPPING_ENTRY ToLookup;
- PLARGE_MCB_MAPPING_ENTRY Entry;
-
- ToLookup.RunStartVbn.QuadPart = Vbn;
- ToLookup.SectorCount.QuadPart = 1;
-
- Entry = RtlLookupElementGenericTable(&Mcb->Mapping->Table, &ToLookup);
+ BOOLEAN Result = FALSE;
+ LARGE_MCB_MAPPING_ENTRY ToLookup;
+ PLARGE_MCB_MAPPING_ENTRY Entry;
+
+ ToLookup.RunStartVbn.QuadPart = Vbn;
+ ToLookup.SectorCount.QuadPart = 1;
+
+ Entry = RtlLookupElementGenericTable(&Mcb->Mapping->Table, &ToLookup);
DPRINT("Entry %p\n", Entry);
- if (!Entry)
- {
- // Find out if we have a following entry. The spec says we should return
- // found with Lbn == -1 when we're beneath the largest map.
- ToLookup.SectorCount.QuadPart = (1ull<<62) - ToLookup.RunStartVbn.QuadPart;
- Entry = RtlLookupElementGenericTable(&Mcb->Mapping->Table, &ToLookup);
+ if (!Entry)
+ {
+ // Find out if we have a following entry. The spec says we should return
+ // found with Lbn == -1 when we're beneath the largest map.
+ ToLookup.SectorCount.QuadPart = (1ull<<62) -
ToLookup.RunStartVbn.QuadPart;
+ Entry = RtlLookupElementGenericTable(&Mcb->Mapping->Table,
&ToLookup);
DPRINT("Entry %p\n", Entry);
- if (Entry)
- {
- Result = TRUE;
- if (Lbn) *Lbn = ~0ull;
- }
- else
- {
- Result = FALSE;
- }
- }
- else
- {
- LARGE_INTEGER Offset;
- Offset.QuadPart = Vbn - Entry->RunStartVbn.QuadPart;
- Result = TRUE;
- if (Lbn) *Lbn = Entry->StartingLbn.QuadPart + Offset.QuadPart;
- if (SectorCountFromLbn) *SectorCountFromLbn = Entry->SectorCount.QuadPart -
Offset.QuadPart;
- if (StartingLbn) *StartingLbn = Entry->StartingLbn.QuadPart;
- if (SectorCountFromStartingLbn) *SectorCountFromStartingLbn =
Entry->SectorCount.QuadPart;
- }
- DPRINT("Done\n");
+ if (Entry)
+ {
+ Result = TRUE;
+ if (Lbn) *Lbn = ~0ull;
+ }
+ else
+ {
+ Result = FALSE;
+ }
+ }
+ else
+ {
+ LARGE_INTEGER Offset;
+ Offset.QuadPart = Vbn - Entry->RunStartVbn.QuadPart;
+ Result = TRUE;
+ if (Lbn) *Lbn = Entry->StartingLbn.QuadPart + Offset.QuadPart;
+ if (SectorCountFromLbn) *SectorCountFromLbn = Entry->SectorCount.QuadPart -
Offset.QuadPart;
+ if (StartingLbn) *StartingLbn = Entry->StartingLbn.QuadPart;
+ if (SectorCountFromStartingLbn) *SectorCountFromStartingLbn =
Entry->SectorCount.QuadPart;
+ }
+ DPRINT("Done\n");
return Result;
}
@@ -385,7 +380,7 @@
{
BOOLEAN Result;
- DPRINT("FsRtlLookupLargeMcbEntry Mcb %x Vbn %x\n", Mcb, (ULONG)Vbn);
+ DPRINT("FsRtlLookupLargeMcbEntry Mcb %x Vbn %x\n", Mcb, (ULONG)Vbn);
KeAcquireGuardedMutex(Mcb->GuardedMutex);
Result = FsRtlLookupBaseMcbEntry(&(Mcb->BaseMcb),
@@ -397,7 +392,7 @@
Index);
KeReleaseGuardedMutex(Mcb->GuardedMutex);
- DPRINT("Done %d\n", Result);
+ DPRINT("Done %d\n", Result);
return Result;
}
@@ -413,28 +408,28 @@
IN OUT PULONG Index)
{
PBASE_MCB_INTERNAL Mcb = (PBASE_MCB_INTERNAL)OpaqueMcb;
- ULONG i = 0;
- BOOLEAN Result = FALSE;
- PLIST_ENTRY ListEntry;
- PLARGE_MCB_MAPPING_ENTRY Entry;
- PLARGE_MCB_MAPPING_ENTRY CountEntry;
-
- ListEntry = &Mcb->Mapping->SequenceList;
- if (!IsListEmpty(ListEntry))
- {
- Entry = CONTAINING_RECORD(ListEntry->Flink, LARGE_MCB_MAPPING_ENTRY, Sequence);
- Result = TRUE;
- *LargeVbn = Entry->RunStartVbn.QuadPart;
- *LargeLbn = Entry->StartingLbn.QuadPart;
-
- for (i = 0, CountEntry = RtlEnumerateGenericTable(&Mcb->Mapping->Table,
TRUE);
- CountEntry != Entry;
- CountEntry = RtlEnumerateGenericTable(&Mcb->Mapping->Table, FALSE));
+ ULONG i = 0;
+ BOOLEAN Result = FALSE;
+ PLIST_ENTRY ListEntry;
+ PLARGE_MCB_MAPPING_ENTRY Entry;
+ PLARGE_MCB_MAPPING_ENTRY CountEntry;
+
+ ListEntry = &Mcb->Mapping->SequenceList;
+ if (!IsListEmpty(ListEntry))
+ {
+ Entry = CONTAINING_RECORD(ListEntry->Flink, LARGE_MCB_MAPPING_ENTRY,
Sequence);
+ Result = TRUE;
+ *LargeVbn = Entry->RunStartVbn.QuadPart;
+ *LargeLbn = Entry->StartingLbn.QuadPart;
+
+ for (i = 0, CountEntry = RtlEnumerateGenericTable(&Mcb->Mapping->Table,
TRUE);
+ CountEntry != Entry;
+ CountEntry = RtlEnumerateGenericTable(&Mcb->Mapping->Table,
FALSE));
DPRINT1("Most probably we are returning shit now\n");
- *Index = i;
- }
-
- return Result;
+ *Index = i;
+ }
+
+ return Result;
}
/*
@@ -449,7 +444,7 @@
{
BOOLEAN Result;
- DPRINT("FsRtlLookupLastLargeMcbEntryAndIndex %x\n", OpaqueMcb);
+ DPRINT("FsRtlLookupLastLargeMcbEntryAndIndex %x\n", OpaqueMcb);
KeAcquireGuardedMutex(OpaqueMcb->GuardedMutex);
Result = FsRtlLookupLastBaseMcbEntryAndIndex(&(OpaqueMcb->BaseMcb),
@@ -458,7 +453,7 @@
Index);
KeReleaseGuardedMutex(OpaqueMcb->GuardedMutex);
- DPRINT("Done %d\n", Result);
+ DPRINT("Done %d\n", Result);
return Result;
}
@@ -473,20 +468,20 @@
OUT PLONGLONG Lbn)
{
PBASE_MCB_INTERNAL Mcb = (PBASE_MCB_INTERNAL)OpaqueMcb;
- BOOLEAN Result = FALSE;
- PLIST_ENTRY ListEntry;
- PLARGE_MCB_MAPPING_ENTRY Entry;
-
- ListEntry = &Mcb->Mapping->SequenceList;
- if (!IsListEmpty(ListEntry))
- {
- Entry = CONTAINING_RECORD(ListEntry->Flink, LARGE_MCB_MAPPING_ENTRY, Sequence);
- Result = TRUE;
- *Vbn = Entry->RunStartVbn.QuadPart;
- *Lbn = Entry->StartingLbn.QuadPart;
- }
-
- return Result;
+ BOOLEAN Result = FALSE;
+ PLIST_ENTRY ListEntry;
+ PLARGE_MCB_MAPPING_ENTRY Entry;
+
+ ListEntry = &Mcb->Mapping->SequenceList;
+ if (!IsListEmpty(ListEntry))
+ {
+ Entry = CONTAINING_RECORD(ListEntry->Flink, LARGE_MCB_MAPPING_ENTRY,
Sequence);
+ Result = TRUE;
+ *Vbn = Entry->RunStartVbn.QuadPart;
+ *Lbn = Entry->StartingLbn.QuadPart;
+ }
+
+ return Result;
}
/*
@@ -500,7 +495,7 @@
{
BOOLEAN Result;
- DPRINT("FsRtlLookupLastLargeMcbEntry Mcb %x\n", Mcb);
+ DPRINT("FsRtlLookupLastLargeMcbEntry Mcb %x\n", Mcb);
KeAcquireGuardedMutex(Mcb->GuardedMutex);
Result = FsRtlLookupLastBaseMcbEntry(&(Mcb->BaseMcb),
@@ -508,7 +503,7 @@
Lbn);
KeReleaseGuardedMutex(Mcb->GuardedMutex);
- DPRINT("Done %d\n", Result);
+ DPRINT("Done %d\n", Result);
return Result;
}
@@ -533,14 +528,14 @@
{
ULONG NumberOfRuns;
- DPRINT("FsRtlNumberOfRunsInLargeMcb Mcb %x\n", Mcb);
+ DPRINT("FsRtlNumberOfRunsInLargeMcb Mcb %x\n", Mcb);
/* Read the number of runs while holding the MCB lock */
KeAcquireGuardedMutex(Mcb->GuardedMutex);
NumberOfRuns = Mcb->BaseMcb.PairCount;
KeReleaseGuardedMutex(Mcb->GuardedMutex);
- DPRINT("Done %d\n", NumberOfRuns);
+ DPRINT("Done %d\n", NumberOfRuns);
/* Return the count */
return NumberOfRuns;
@@ -556,87 +551,81 @@
IN LONGLONG SectorCount)
{
PBASE_MCB_INTERNAL Mcb = (PBASE_MCB_INTERNAL)OpaqueMcb;
- LARGE_MCB_MAPPING_ENTRY Node;
- LARGE_MCB_MAPPING_ENTRY NewElement;
- PLARGE_MCB_MAPPING_ENTRY Element;
- PLARGE_MCB_MAPPING_ENTRY Reinserted, Inserted;
- LARGE_INTEGER StartHole, EndHole, EndRun;
-
- Node.RunStartVbn.QuadPart = Vbn;
- Node.SectorCount.QuadPart = SectorCount;
-
- while ((Element = RtlLookupElementGenericTable(&Mcb->Mapping->Table,
&Node)))
- {
+ LARGE_MCB_MAPPING_ENTRY Node;
+ LARGE_MCB_MAPPING_ENTRY NewElement;
+ PLARGE_MCB_MAPPING_ENTRY Element;
+ PLARGE_MCB_MAPPING_ENTRY Reinserted, Inserted;
+ LARGE_INTEGER StartHole, EndHole, EndRun;
+
+ Node.RunStartVbn.QuadPart = Vbn;
+ Node.SectorCount.QuadPart = SectorCount;
+
+ while ((Element = RtlLookupElementGenericTable(&Mcb->Mapping->Table,
&Node)))
+ {
DPRINT1("Node.RunStartVbn %I64d, Node.SectorCount %I64d\n",
Node.RunStartVbn.QuadPart, Node.SectorCount.QuadPart);
DPRINT1("Element %p, .RunStartVbn %I64d, .SectorCount %I64d\n",
Element, Element->RunStartVbn.QuadPart, Element->SectorCount.QuadPart);
- // Must split
- if (Element->RunStartVbn.QuadPart < Node.RunStartVbn.QuadPart &&
- Element->SectorCount.QuadPart > Node.SectorCount.QuadPart)
- {
- LARGE_MCB_MAPPING_ENTRY Upper, Reinsert;
- StartHole = Node.RunStartVbn;
- EndHole.QuadPart = Node.RunStartVbn.QuadPart + Node.SectorCount.QuadPart;
-
- Upper.RunStartVbn.QuadPart = EndHole.QuadPart;
- Upper.StartingLbn.QuadPart =
- Element->StartingLbn.QuadPart +
- EndHole.QuadPart -
- Element->RunStartVbn.QuadPart;
- Upper.SectorCount.QuadPart =
- Element->SectorCount.QuadPart -
- (EndHole.QuadPart - Element->RunStartVbn.QuadPart);
- Reinsert = *Element;
- Reinsert.SectorCount.QuadPart =
- Element->RunStartVbn.QuadPart - StartHole.QuadPart;
- RemoveEntryList(&Element->Sequence);
- RtlDeleteElementGenericTable(&Mcb->Mapping->Table, Element);
- Mcb->PairCount--;
-
- Reinserted = RtlInsertElementGenericTable(&Mcb->Mapping->Table,
&Reinsert, sizeof(Reinsert), NULL);
- InsertHeadList(&Mcb->Mapping->SequenceList, &Reinserted->Sequence);
- Mcb->PairCount++;
-
- Inserted = RtlInsertElementGenericTable(&Mcb->Mapping->Table, &Upper,
sizeof(Upper), NULL);
- InsertHeadList(&Mcb->Mapping->SequenceList, &Inserted->Sequence);
- Mcb->PairCount++;
- }
- else if (Element->RunStartVbn.QuadPart < Node.RunStartVbn.QuadPart)
- {
- StartHole = Node.RunStartVbn;
- NewElement.RunStartVbn = Element->RunStartVbn;
- NewElement.StartingLbn = Element->StartingLbn;
- NewElement.SectorCount.QuadPart = StartHole.QuadPart -
Element->StartingLbn.QuadPart;
-
- RemoveEntryList(&Element->Sequence);
- RtlDeleteElementGenericTable(&Mcb->Mapping->Table, Element);
- Mcb->PairCount--;
-
- Reinserted = RtlInsertElementGenericTable(&Mcb->Mapping->Table,
&NewElement, sizeof(NewElement), NULL);
- InsertHeadList(&Mcb->Mapping->SequenceList, &Reinserted->Sequence);
- Mcb->PairCount++;
- }
- else
- {
- EndHole = Element->RunStartVbn;
- EndRun.QuadPart = Element->RunStartVbn.QuadPart +
Element->SectorCount.QuadPart;
- NewElement.RunStartVbn = EndHole;
- NewElement.StartingLbn.QuadPart = Element->StartingLbn.QuadPart + (EndHole.QuadPart
- Element->RunStartVbn.QuadPart);
- NewElement.SectorCount.QuadPart = EndRun.QuadPart - EndHole.QuadPart;
-
- RemoveEntryList(&Element->Sequence);
- RtlDeleteElementGenericTable(&Mcb->Mapping->Table, Element);
- Mcb->PairCount--;
-
- Reinserted = RtlInsertElementGenericTable(&Mcb->Mapping->Table,
&NewElement, sizeof(NewElement), NULL);
- InsertHeadList(&Mcb->Mapping->SequenceList, &Reinserted->Sequence);
- Mcb->PairCount++;
+ // Must split
+ if (Element->RunStartVbn.QuadPart < Node.RunStartVbn.QuadPart &&
+ Element->SectorCount.QuadPart > Node.SectorCount.QuadPart)
+ {
+ LARGE_MCB_MAPPING_ENTRY Upper, Reinsert;
+ StartHole = Node.RunStartVbn;
+ EndHole.QuadPart = Node.RunStartVbn.QuadPart + Node.SectorCount.QuadPart;
+
+ Upper.RunStartVbn.QuadPart = EndHole.QuadPart;
+ Upper.StartingLbn.QuadPart = Element->StartingLbn.QuadPart +
EndHole.QuadPart - Element->RunStartVbn.QuadPart;
+ Upper.SectorCount.QuadPart = Element->SectorCount.QuadPart -
(EndHole.QuadPart - Element->RunStartVbn.QuadPart);
+ Reinsert = *Element;
+ Reinsert.SectorCount.QuadPart = Element->RunStartVbn.QuadPart -
StartHole.QuadPart;
+ RemoveEntryList(&Element->Sequence);
+ RtlDeleteElementGenericTable(&Mcb->Mapping->Table, Element);
+ Mcb->PairCount--;
+
+ Reinserted = RtlInsertElementGenericTable(&Mcb->Mapping->Table,
&Reinsert, sizeof(Reinsert), NULL);
+ InsertHeadList(&Mcb->Mapping->SequenceList,
&Reinserted->Sequence);
+ Mcb->PairCount++;
+
+ Inserted = RtlInsertElementGenericTable(&Mcb->Mapping->Table,
&Upper, sizeof(Upper), NULL);
+ InsertHeadList(&Mcb->Mapping->SequenceList,
&Inserted->Sequence);
+ Mcb->PairCount++;
+ }
+ else if (Element->RunStartVbn.QuadPart < Node.RunStartVbn.QuadPart)
+ {
+ StartHole = Node.RunStartVbn;
+ NewElement.RunStartVbn = Element->RunStartVbn;
+ NewElement.StartingLbn = Element->StartingLbn;
+ NewElement.SectorCount.QuadPart = StartHole.QuadPart -
Element->StartingLbn.QuadPart;
+
+ RemoveEntryList(&Element->Sequence);
+ RtlDeleteElementGenericTable(&Mcb->Mapping->Table, Element);
+ Mcb->PairCount--;
+
+ Reinserted = RtlInsertElementGenericTable(&Mcb->Mapping->Table,
&NewElement, sizeof(NewElement), NULL);
+ InsertHeadList(&Mcb->Mapping->SequenceList,
&Reinserted->Sequence);
+ Mcb->PairCount++;
+ }
+ else
+ {
+ EndHole = Element->RunStartVbn;
+ EndRun.QuadPart = Element->RunStartVbn.QuadPart +
Element->SectorCount.QuadPart;
+ NewElement.RunStartVbn = EndHole;
+ NewElement.StartingLbn.QuadPart = Element->StartingLbn.QuadPart +
(EndHole.QuadPart - Element->RunStartVbn.QuadPart);
+ NewElement.SectorCount.QuadPart = EndRun.QuadPart - EndHole.QuadPart;
+
+ RemoveEntryList(&Element->Sequence);
+ RtlDeleteElementGenericTable(&Mcb->Mapping->Table, Element);
+ Mcb->PairCount--;
+
+ Reinserted = RtlInsertElementGenericTable(&Mcb->Mapping->Table,
&NewElement, sizeof(NewElement), NULL);
+ InsertHeadList(&Mcb->Mapping->SequenceList,
&Reinserted->Sequence);
+ Mcb->PairCount++;
DPRINT1("Reinserted %p, .RunStartVbn %I64d, .SectorCount %I64d\n",
Reinserted, Reinserted->RunStartVbn.QuadPart, Reinserted->SectorCount.QuadPart);
DPRINT1("NewElement .RunStartVbn %I64d, .SectorCount %I64d\n",
NewElement.RunStartVbn.QuadPart, NewElement.SectorCount.QuadPart);
- }
- }
-
- return TRUE;
+ }
+ }
+
+ return TRUE;
}
/*
@@ -648,15 +637,13 @@
IN LONGLONG Vbn,
IN LONGLONG SectorCount)
{
- DPRINT("FsRtlRemoveLargeMcbEntry Mcb %x, Vbn %I64d, SectorCount %I64d\n", Mcb,
(ULONG)Vbn, (ULONG)SectorCount);
+ DPRINT("FsRtlRemoveLargeMcbEntry Mcb %x, Vbn %I64d, SectorCount %I64d\n",
Mcb, (ULONG)Vbn, (ULONG)SectorCount);
KeAcquireGuardedMutex(Mcb->GuardedMutex);
- FsRtlRemoveBaseMcbEntry(&(Mcb->BaseMcb),
- Vbn,
- SectorCount);
+ FsRtlRemoveBaseMcbEntry(&(Mcb->BaseMcb), Vbn, SectorCount);
KeReleaseGuardedMutex(Mcb->GuardedMutex);
- DPRINT("Done\n");
+ DPRINT("Done\n");
}
/*
@@ -667,16 +654,16 @@
FsRtlResetBaseMcb(IN PBASE_MCB OpaqueMcb)
{
PBASE_MCB_INTERNAL Mcb = (PBASE_MCB_INTERNAL)OpaqueMcb;
- PLARGE_MCB_MAPPING_ENTRY Element;
-
- while (RtlNumberGenericTableElements(&Mcb->Mapping->Table) &&
- (Element =
(PLARGE_MCB_MAPPING_ENTRY)RtlGetElementGenericTable(&Mcb->Mapping->Table, 0)))
- {
- RtlDeleteElementGenericTable(&Mcb->Mapping->Table, Element);
- }
-
- Mcb->PairCount = 0;
- Mcb->MaximumPairCount = 0;
+ PLARGE_MCB_MAPPING_ENTRY Element;
+
+ while (RtlNumberGenericTableElements(&Mcb->Mapping->Table) &&
+ (Element =
(PLARGE_MCB_MAPPING_ENTRY)RtlGetElementGenericTable(&Mcb->Mapping->Table, 0)))
+ {
+ RtlDeleteElementGenericTable(&Mcb->Mapping->Table, Element);
+ }
+
+ Mcb->PairCount = 0;
+ Mcb->MaximumPairCount = 0;
}
/*
@@ -688,17 +675,12 @@
IN BOOLEAN SelfSynchronized)
{
if (!SelfSynchronized)
- {
KeAcquireGuardedMutex(Mcb->GuardedMutex);
- }
-
- FsRtlResetBaseMcb(&Mcb->BaseMcb);
-
+
+ FsRtlResetBaseMcb(&Mcb->BaseMcb);
if (!SelfSynchronized)
- {
- KeReleaseGuardedMutex(Mcb->GuardedMutex);
- }
+ KeReleaseGuardedMutex(Mcb->GuardedMutex);
}
#define MCB_BUMP_NO_MORE 0
@@ -706,34 +688,36 @@
static ULONG NTAPI McbBump(PBASE_MCB_INTERNAL Mcb, PLARGE_MCB_MAPPING_ENTRY FixedPart)
{
- LARGE_MCB_MAPPING_ENTRY Reimagined;
- PLARGE_MCB_MAPPING_ENTRY Found = NULL;
-
- DPRINT("McbBump %x (%x:%x)\n", Mcb, FixedPart->RunStartVbn.LowPart,
FixedPart->SectorCount.LowPart);
-
- Reimagined = *FixedPart;
- while ((Found = RtlLookupElementGenericTable(&Mcb->Mapping->Table,
&Reimagined)))
- {
- Reimagined = *Found;
- Reimagined.RunStartVbn.QuadPart =
- FixedPart->RunStartVbn.QuadPart + FixedPart->SectorCount.QuadPart;
- DPRINT("Reimagined %x\n", Reimagined.RunStartVbn.LowPart);
- }
-
- DPRINT("Found %x\n", Found);
- if (!Found) return MCB_BUMP_NO_MORE;
- DPRINT1
- ("Moving %x-%x to %x because %x-%x overlaps\n",
- Found->RunStartVbn.LowPart,
- Found->RunStartVbn.LowPart + Found->SectorCount.QuadPart,
- Reimagined.RunStartVbn.LowPart + Reimagined.SectorCount.LowPart,
- Reimagined.RunStartVbn.LowPart,
- Reimagined.RunStartVbn.LowPart + Reimagined.SectorCount.LowPart);
- Found->RunStartVbn.QuadPart = Reimagined.RunStartVbn.QuadPart +
Reimagined.SectorCount.QuadPart;
- Found->StartingLbn.QuadPart = Reimagined.StartingLbn.QuadPart +
Reimagined.SectorCount.QuadPart;
-
- DPRINT("Again\n");
- return MCB_BUMP_AGAIN;
+ LARGE_MCB_MAPPING_ENTRY Reimagined;
+ PLARGE_MCB_MAPPING_ENTRY Found = NULL;
+
+ DPRINT("McbBump %x (%x:%x)\n", Mcb, FixedPart->RunStartVbn.LowPart,
FixedPart->SectorCount.LowPart);
+
+ Reimagined = *FixedPart;
+ while ((Found = RtlLookupElementGenericTable(&Mcb->Mapping->Table,
&Reimagined)))
+ {
+ Reimagined = *Found;
+ Reimagined.RunStartVbn.QuadPart =
+ FixedPart->RunStartVbn.QuadPart + FixedPart->SectorCount.QuadPart;
+ DPRINT("Reimagined %x\n", Reimagined.RunStartVbn.LowPart);
+ }
+
+ DPRINT("Found %x\n", Found);
+ if (!Found) return MCB_BUMP_NO_MORE;
+
+ DPRINT1
+ ("Moving %x-%x to %x because %x-%x overlaps\n",
+ Found->RunStartVbn.LowPart,
+ Found->RunStartVbn.LowPart + Found->SectorCount.QuadPart,
+ Reimagined.RunStartVbn.LowPart + Reimagined.SectorCount.LowPart,
+ Reimagined.RunStartVbn.LowPart,
+ Reimagined.RunStartVbn.LowPart + Reimagined.SectorCount.LowPart);
+
+ Found->RunStartVbn.QuadPart = Reimagined.RunStartVbn.QuadPart +
Reimagined.SectorCount.QuadPart;
+ Found->StartingLbn.QuadPart = Reimagined.StartingLbn.QuadPart +
Reimagined.SectorCount.QuadPart;
+
+ DPRINT("Again\n");
+ return MCB_BUMP_AGAIN;
}
/*
@@ -746,72 +730,72 @@
IN LONGLONG Amount)
{
PBASE_MCB_INTERNAL Mcb = (PBASE_MCB_INTERNAL)OpaqueMcb;
- ULONG Result;
- LARGE_MCB_MAPPING_ENTRY Node;
- PLARGE_MCB_MAPPING_ENTRY Existing = NULL;
-
- Node.RunStartVbn.QuadPart = Vbn;
- Node.SectorCount.QuadPart = 0;
-
- Existing = RtlLookupElementGenericTable(&Mcb->Mapping->Table, &Node);
-
- if (Existing)
- {
- // We're in the middle of a run
- LARGE_MCB_MAPPING_ENTRY UpperPart;
- LARGE_MCB_MAPPING_ENTRY LowerPart;
- PLARGE_MCB_MAPPING_ENTRY InsertedUpper;
-
- UpperPart.RunStartVbn.QuadPart = Node.RunStartVbn.QuadPart + Amount;
- UpperPart.SectorCount.QuadPart = Existing->RunStartVbn.QuadPart +
- (Existing->SectorCount.QuadPart - Node.RunStartVbn.QuadPart);
- UpperPart.StartingLbn.QuadPart = Existing->StartingLbn.QuadPart +
- (Node.RunStartVbn.QuadPart - Existing->RunStartVbn.QuadPart);
- LowerPart.RunStartVbn.QuadPart = Existing->RunStartVbn.QuadPart;
- LowerPart.SectorCount.QuadPart = Node.RunStartVbn.QuadPart -
Existing->RunStartVbn.QuadPart;
- LowerPart.StartingLbn.QuadPart = Existing->StartingLbn.QuadPart;
-
- Node = UpperPart;
-
- DPRINT("Loop: %x\n", Node.RunStartVbn.LowPart);
- while ((Result = McbBump(Mcb, &Node)) == MCB_BUMP_AGAIN)
- {
- DPRINT("Node: %x\n", Node.RunStartVbn.LowPart);
- }
- DPRINT("Done\n");
-
- if (Result == MCB_BUMP_NO_MORE)
- {
- Node = *Existing;
- RemoveHeadList(&Existing->Sequence);
- RtlDeleteElementGenericTable(&Mcb->Mapping->Table, Existing);
- Mcb->PairCount--;
-
- // Adjust the element we found.
- Existing->SectorCount = LowerPart.SectorCount;
-
- InsertedUpper = RtlInsertElementGenericTable(&Mcb->Mapping->Table,
&UpperPart, sizeof(UpperPart), NULL);
- if (!InsertedUpper)
- {
- // Just make it like it was
- Existing->SectorCount = Node.SectorCount;
- return FALSE;
- }
- InsertHeadList(&Mcb->Mapping->SequenceList,
&InsertedUpper->Sequence);
- Mcb->PairCount++;
- }
- else
- {
- Node.RunStartVbn.QuadPart = Vbn;
- Node.SectorCount.QuadPart = Amount;
- while ((Result = McbBump(Mcb, &Node)) == MCB_BUMP_AGAIN);
- return Result == MCB_BUMP_NO_MORE;
- }
- }
-
- DPRINT("Done\n");
-
- return TRUE;
+ ULONG Result;
+ LARGE_MCB_MAPPING_ENTRY Node;
+ PLARGE_MCB_MAPPING_ENTRY Existing = NULL;
+
+ Node.RunStartVbn.QuadPart = Vbn;
+ Node.SectorCount.QuadPart = 0;
+
+ Existing = RtlLookupElementGenericTable(&Mcb->Mapping->Table, &Node);
+
+ if (Existing)
+ {
+ // We're in the middle of a run
+ LARGE_MCB_MAPPING_ENTRY UpperPart;
+ LARGE_MCB_MAPPING_ENTRY LowerPart;
+ PLARGE_MCB_MAPPING_ENTRY InsertedUpper;
+
+ UpperPart.RunStartVbn.QuadPart = Node.RunStartVbn.QuadPart + Amount;
+ UpperPart.SectorCount.QuadPart = Existing->RunStartVbn.QuadPart +
+ (Existing->SectorCount.QuadPart - Node.RunStartVbn.QuadPart);
+ UpperPart.StartingLbn.QuadPart = Existing->StartingLbn.QuadPart +
+ (Node.RunStartVbn.QuadPart - Existing->RunStartVbn.QuadPart);
+ LowerPart.RunStartVbn.QuadPart = Existing->RunStartVbn.QuadPart;
+ LowerPart.SectorCount.QuadPart = Node.RunStartVbn.QuadPart -
Existing->RunStartVbn.QuadPart;
+ LowerPart.StartingLbn.QuadPart = Existing->StartingLbn.QuadPart;
+
+ Node = UpperPart;
+
+ DPRINT("Loop: %x\n", Node.RunStartVbn.LowPart);
+ while ((Result = McbBump(Mcb, &Node)) == MCB_BUMP_AGAIN)
+ {
+ DPRINT("Node: %x\n", Node.RunStartVbn.LowPart);
+ }
+ DPRINT("Done\n");
+
+ if (Result == MCB_BUMP_NO_MORE)
+ {
+ Node = *Existing;
+ RemoveHeadList(&Existing->Sequence);
+ RtlDeleteElementGenericTable(&Mcb->Mapping->Table, Existing);
+ Mcb->PairCount--;
+
+ // Adjust the element we found.
+ Existing->SectorCount = LowerPart.SectorCount;
+
+ InsertedUpper = RtlInsertElementGenericTable(&Mcb->Mapping->Table,
&UpperPart, sizeof(UpperPart), NULL);
+ if (!InsertedUpper)
+ {
+ // Just make it like it was
+ Existing->SectorCount = Node.SectorCount;
+ return FALSE;
+ }
+ InsertHeadList(&Mcb->Mapping->SequenceList,
&InsertedUpper->Sequence);
+ Mcb->PairCount++;
+ }
+ else
+ {
+ Node.RunStartVbn.QuadPart = Vbn;
+ Node.SectorCount.QuadPart = Amount;
+ while ((Result = McbBump(Mcb, &Node)) == MCB_BUMP_AGAIN);
+ return Result == MCB_BUMP_NO_MORE;
+ }
+ }
+
+ DPRINT("Done\n");
+
+ return TRUE;
}
/*
@@ -825,7 +809,7 @@
{
BOOLEAN Result;
- DPRINT("FsRtlSplitLargeMcb %x, Vbn %x, Amount %x\n", Mcb, (ULONG)Vbn,
(ULONG)Amount);
+ DPRINT("FsRtlSplitLargeMcb %x, Vbn %x, Amount %x\n", Mcb, (ULONG)Vbn,
(ULONG)Amount);
KeAcquireGuardedMutex(Mcb->GuardedMutex);
Result = FsRtlSplitBaseMcb(&(Mcb->BaseMcb),
@@ -833,7 +817,7 @@
Amount);
KeReleaseGuardedMutex(Mcb->GuardedMutex);
- DPRINT("Done %d\n", Result);
+ DPRINT("Done %d\n", Result);
return Result;
}
@@ -847,23 +831,23 @@
IN LONGLONG Vbn)
{
PBASE_MCB_INTERNAL Mcb = (PBASE_MCB_INTERNAL)OpaqueMcb;
- if (!Vbn)
- {
- FsRtlResetBaseMcb(OpaqueMcb);
- }
- else
- {
- LARGE_MCB_MAPPING_ENTRY Truncate;
- PLARGE_MCB_MAPPING_ENTRY Found;
- Truncate.RunStartVbn.QuadPart = Vbn;
- Truncate.SectorCount.QuadPart = (1ull<<62) - Truncate.RunStartVbn.QuadPart;
- while ((Found = RtlLookupElementGenericTable(&Mcb->Mapping->Table,
&Truncate)))
- {
- RemoveEntryList(&Found->Sequence);
- RtlDeleteElementGenericTable(&Mcb->Mapping->Table, Found);
- Mcb->PairCount--;
- }
- }
+ if (!Vbn)
+ {
+ FsRtlResetBaseMcb(OpaqueMcb);
+ }
+ else
+ {
+ LARGE_MCB_MAPPING_ENTRY Truncate;
+ PLARGE_MCB_MAPPING_ENTRY Found;
+ Truncate.RunStartVbn.QuadPart = Vbn;
+ Truncate.SectorCount.QuadPart = (1ull<<62) -
Truncate.RunStartVbn.QuadPart;
+ while ((Found = RtlLookupElementGenericTable(&Mcb->Mapping->Table,
&Truncate)))
+ {
+ RemoveEntryList(&Found->Sequence);
+ RtlDeleteElementGenericTable(&Mcb->Mapping->Table, Found);
+ Mcb->PairCount--;
+ }
+ }
}
/*
@@ -874,12 +858,11 @@
FsRtlTruncateLargeMcb(IN PLARGE_MCB Mcb,
IN LONGLONG Vbn)
{
- DPRINT("FsRtlTruncateLargeMcb %x Vbn %x\n", Mcb, (ULONG)Vbn);
+ DPRINT("FsRtlTruncateLargeMcb %x Vbn %x\n", Mcb, (ULONG)Vbn);
KeAcquireGuardedMutex(Mcb->GuardedMutex);
- FsRtlTruncateBaseMcb(&(Mcb->BaseMcb),
- Vbn);
+ FsRtlTruncateBaseMcb(&(Mcb->BaseMcb), Vbn);
KeReleaseGuardedMutex(Mcb->GuardedMutex);
- DPRINT("Done\n");
+ DPRINT("Done\n");
}
/*
@@ -889,7 +872,7 @@
NTAPI
FsRtlUninitializeBaseMcb(IN PBASE_MCB Mcb)
{
- FsRtlResetBaseMcb(Mcb);
+ FsRtlResetBaseMcb(Mcb);
if ((Mcb->PoolType == PagedPool) && (Mcb->MaximumPairCount ==
MAXIMUM_PAIR_COUNT))
{
@@ -916,4 +899,3 @@
FsRtlUninitializeBaseMcb(&(Mcb->BaseMcb));
}
}
-