ReactOS  0.4.15-dev-3163-gf17c2c0
largemcb.c File Reference
#include <ntoskrnl.h>
#include <debug.h>
Include dependency graph for largemcb.c:

Go to the source code of this file.

Classes

struct  _LARGE_MCB_MAPPING_ENTRY
 
struct  _LARGE_MCB_MAPPING
 
struct  _BASE_MCB_INTERNAL
 

Macros

#define NDEBUG
 
#define MIN(x, y)   (((x)<(y))?(x):(y))
 
#define MAX(x, y)   (((x)>(y))?(x):(y))
 

Typedefs

typedef struct _LARGE_MCB_MAPPING_ENTRY LARGE_MCB_MAPPING_ENTRY
 
typedef struct _LARGE_MCB_MAPPING_ENTRYPLARGE_MCB_MAPPING_ENTRY
 
typedef struct _LARGE_MCB_MAPPING LARGE_MCB_MAPPING
 
typedef struct _LARGE_MCB_MAPPINGPLARGE_MCB_MAPPING
 
typedef struct _BASE_MCB_INTERNAL BASE_MCB_INTERNAL
 
typedef struct _BASE_MCB_INTERNALPBASE_MCB_INTERNAL
 

Functions

static PVOID NTAPI McbMappingAllocate (PRTL_GENERIC_TABLE Table, CLONG Bytes)
 
static VOID NTAPI McbMappingFree (PRTL_GENERIC_TABLE Table, PVOID Buffer)
 
static RTL_GENERIC_COMPARE_RESULTS NTAPI McbMappingCompare (PRTL_GENERIC_TABLE Table, PVOID PtrA, PVOID PtrB)
 
static RTL_GENERIC_COMPARE_RESULTS NTAPI McbMappingIntersectCompare (PRTL_GENERIC_TABLE Table, PVOID PtrA, PVOID PtrB)
 
BOOLEAN NTAPI FsRtlAddBaseMcbEntry (IN PBASE_MCB OpaqueMcb, IN LONGLONG Vbn, IN LONGLONG Lbn, IN LONGLONG SectorCount)
 
BOOLEAN NTAPI FsRtlAddLargeMcbEntry (IN PLARGE_MCB Mcb, IN LONGLONG Vbn, IN LONGLONG Lbn, IN LONGLONG SectorCount)
 
BOOLEAN NTAPI FsRtlGetNextBaseMcbEntry (IN PBASE_MCB OpaqueMcb, IN ULONG RunIndex, OUT PLONGLONG Vbn, OUT PLONGLONG Lbn, OUT PLONGLONG SectorCount)
 
BOOLEAN NTAPI FsRtlGetNextLargeMcbEntry (IN PLARGE_MCB Mcb, IN ULONG RunIndex, OUT PLONGLONG Vbn, OUT PLONGLONG Lbn, OUT PLONGLONG SectorCount)
 
VOID NTAPI FsRtlInitializeBaseMcb (IN PBASE_MCB OpaqueMcb, IN POOL_TYPE PoolType)
 
VOID NTAPI FsRtlInitializeLargeMcb (IN PLARGE_MCB Mcb, IN POOL_TYPE PoolType)
 
VOID NTAPI FsRtlInitializeLargeMcbs (VOID)
 
BOOLEAN NTAPI FsRtlLookupBaseMcbEntry (IN PBASE_MCB OpaqueMcb, IN LONGLONG Vbn, OUT PLONGLONG Lbn OPTIONAL, OUT PLONGLONG SectorCountFromLbn OPTIONAL, OUT PLONGLONG StartingLbn OPTIONAL, OUT PLONGLONG SectorCountFromStartingLbn OPTIONAL, OUT PULONG Index OPTIONAL)
 
BOOLEAN NTAPI FsRtlLookupLargeMcbEntry (IN PLARGE_MCB Mcb, IN LONGLONG Vbn, OUT PLONGLONG Lbn OPTIONAL, OUT PLONGLONG SectorCountFromLbn OPTIONAL, OUT PLONGLONG StartingLbn OPTIONAL, OUT PLONGLONG SectorCountFromStartingLbn OPTIONAL, OUT PULONG Index OPTIONAL)
 
static BOOLEAN NTAPI FsRtlLookupLastLargeMcbEntryAndIndex_internal (IN PBASE_MCB_INTERNAL Mcb, OUT PLONGLONG Vbn, OUT PLONGLONG Lbn, OUT PULONG Index OPTIONAL)
 
BOOLEAN NTAPI FsRtlLookupLastBaseMcbEntryAndIndex (IN PBASE_MCB OpaqueMcb, IN OUT PLONGLONG LargeVbn, IN OUT PLONGLONG LargeLbn, IN OUT PULONG Index)
 
BOOLEAN NTAPI FsRtlLookupLastLargeMcbEntryAndIndex (IN PLARGE_MCB OpaqueMcb, OUT PLONGLONG LargeVbn, OUT PLONGLONG LargeLbn, OUT PULONG Index)
 
BOOLEAN NTAPI FsRtlLookupLastBaseMcbEntry (IN PBASE_MCB OpaqueMcb, OUT PLONGLONG Vbn, OUT PLONGLONG Lbn)
 
BOOLEAN NTAPI FsRtlLookupLastLargeMcbEntry (IN PLARGE_MCB Mcb, OUT PLONGLONG Vbn, OUT PLONGLONG Lbn)
 
ULONG NTAPI FsRtlNumberOfRunsInBaseMcb (IN PBASE_MCB OpaqueMcb)
 
ULONG NTAPI FsRtlNumberOfRunsInLargeMcb (IN PLARGE_MCB Mcb)
 
BOOLEAN NTAPI FsRtlRemoveBaseMcbEntry (IN PBASE_MCB OpaqueMcb, IN LONGLONG Vbn, IN LONGLONG SectorCount)
 
VOID NTAPI FsRtlRemoveLargeMcbEntry (IN PLARGE_MCB Mcb, IN LONGLONG Vbn, IN LONGLONG SectorCount)
 
VOID NTAPI FsRtlResetBaseMcb (IN PBASE_MCB OpaqueMcb)
 
VOID NTAPI FsRtlResetLargeMcb (IN PLARGE_MCB Mcb, IN BOOLEAN SelfSynchronized)
 
BOOLEAN NTAPI FsRtlSplitBaseMcb (IN PBASE_MCB OpaqueMcb, IN LONGLONG Vbn, IN LONGLONG Amount)
 
BOOLEAN NTAPI FsRtlSplitLargeMcb (IN PLARGE_MCB Mcb, IN LONGLONG Vbn, IN LONGLONG Amount)
 
VOID NTAPI FsRtlTruncateBaseMcb (IN PBASE_MCB OpaqueMcb, IN LONGLONG Vbn)
 
VOID NTAPI FsRtlTruncateLargeMcb (IN PLARGE_MCB Mcb, IN LONGLONG Vbn)
 
VOID NTAPI FsRtlUninitializeBaseMcb (IN PBASE_MCB Mcb)
 
VOID NTAPI FsRtlUninitializeLargeMcb (IN PLARGE_MCB Mcb)
 

Variables

PAGED_LOOKASIDE_LIST FsRtlFirstMappingLookasideList
 
NPAGED_LOOKASIDE_LIST FsRtlFastMutexLookasideList
 

Macro Definition Documentation

◆ MAX

#define MAX (   x,
  y 
)    (((x)>(y))?(x):(y))

Definition at line 18 of file largemcb.c.

◆ MIN

#define MIN (   x,
  y 
)    (((x)<(y))?(x):(y))

Definition at line 17 of file largemcb.c.

◆ NDEBUG

#define NDEBUG

Definition at line 14 of file largemcb.c.

Typedef Documentation

◆ BASE_MCB_INTERNAL

◆ LARGE_MCB_MAPPING

◆ LARGE_MCB_MAPPING_ENTRY

◆ PBASE_MCB_INTERNAL

◆ PLARGE_MCB_MAPPING

◆ PLARGE_MCB_MAPPING_ENTRY

Function Documentation

◆ FsRtlAddBaseMcbEntry()

BOOLEAN NTAPI FsRtlAddBaseMcbEntry ( IN PBASE_MCB  OpaqueMcb,
IN LONGLONG  Vbn,
IN LONGLONG  Lbn,
IN LONGLONG  SectorCount 
)

Definition at line 135 of file largemcb.c.

139 {
140  BOOLEAN Result = TRUE;
141  BOOLEAN IntResult;
143  LARGE_MCB_MAPPING_ENTRY Node, NeedleRun;
144  PLARGE_MCB_MAPPING_ENTRY LowerRun, HigherRun;
145  BOOLEAN NewElement;
146  LONGLONG IntLbn, IntSectorCount;
147 
148  DPRINT("FsRtlAddBaseMcbEntry(%p, %I64d, %I64d, %I64d)\n", OpaqueMcb, Vbn, Lbn, SectorCount);
149 
150  if (Vbn < 0)
151  {
152  Result = FALSE;
153  goto quit;
154  }
155 
156  if (SectorCount <= 0)
157  {
158  Result = FALSE;
159  goto quit;
160  }
161 
162  IntResult = FsRtlLookupBaseMcbEntry(OpaqueMcb, Vbn, &IntLbn, &IntSectorCount, NULL, NULL, NULL);
163  if (IntResult)
164  {
165  if (IntLbn != -1 && IntLbn != Lbn)
166  {
167  Result = FALSE;
168  goto quit;
169  }
170 
171  if ((IntLbn != -1) && (IntSectorCount >= SectorCount))
172  {
173  /* This is a no-op */
174  goto quit;
175  }
176  }
177 
178  /* clean any possible previous entries in our range */
180 
181  // We need to map [Vbn, Vbn+SectorCount) to [Lbn, Lbn+SectorCount),
182  // taking in account the fact that we need to merge these runs if
183  // they are adjacent or overlap, but fail if new run fully fits into another run
184 
185  /* initially we think we will be inserted as a separate run */
186  Node.RunStartVbn.QuadPart = Vbn;
187  Node.RunEndVbn.QuadPart = Vbn + SectorCount;
188  Node.StartingLbn.QuadPart = Lbn;
189 
190  /* optionally merge with lower run */
191  NeedleRun.RunStartVbn.QuadPart = Node.RunStartVbn.QuadPart - 1;
192  NeedleRun.RunEndVbn.QuadPart = NeedleRun.RunStartVbn.QuadPart + 1;
193  NeedleRun.StartingLbn.QuadPart = ~0ULL;
194  Mcb->Mapping->Table.CompareRoutine = McbMappingIntersectCompare;
195  if ((LowerRun = RtlLookupElementGenericTable(&Mcb->Mapping->Table, &NeedleRun)) &&
196  (LowerRun->StartingLbn.QuadPart + (LowerRun->RunEndVbn.QuadPart - LowerRun->RunStartVbn.QuadPart) == Node.StartingLbn.QuadPart))
197  {
198  ASSERT(LowerRun->RunEndVbn.QuadPart == Node.RunStartVbn.QuadPart);
199  Node.RunStartVbn.QuadPart = LowerRun->RunStartVbn.QuadPart;
200  Node.StartingLbn.QuadPart = LowerRun->StartingLbn.QuadPart;
201  Mcb->Mapping->Table.CompareRoutine = McbMappingCompare;
202  RtlDeleteElementGenericTable(&Mcb->Mapping->Table, LowerRun);
203  --Mcb->PairCount;
204  DPRINT("Intersecting lower run found (%I64d,%I64d) Lbn: %I64d\n", LowerRun->RunStartVbn.QuadPart, LowerRun->RunEndVbn.QuadPart, LowerRun->StartingLbn.QuadPart);
205  }
206 
207  /* optionally merge with higher run */
208  NeedleRun.RunStartVbn.QuadPart = Node.RunEndVbn.QuadPart;
209  NeedleRun.RunEndVbn.QuadPart = NeedleRun.RunStartVbn.QuadPart + 1;
210  Mcb->Mapping->Table.CompareRoutine = McbMappingIntersectCompare;
211  if ((HigherRun = RtlLookupElementGenericTable(&Mcb->Mapping->Table, &NeedleRun)) &&
212  (Node.StartingLbn.QuadPart <= HigherRun->StartingLbn.QuadPart))
213  {
214  ASSERT(HigherRun->RunStartVbn.QuadPart == Node.RunEndVbn.QuadPart);
215  Node.RunEndVbn.QuadPart = HigherRun->RunEndVbn.QuadPart;
216  Mcb->Mapping->Table.CompareRoutine = McbMappingCompare;
217  RtlDeleteElementGenericTable(&Mcb->Mapping->Table, HigherRun);
218  --Mcb->PairCount;
219  DPRINT("Intersecting higher run found (%I64d,%I64d) Lbn: %I64d\n", HigherRun->RunStartVbn.QuadPart, HigherRun->RunEndVbn.QuadPart, HigherRun->StartingLbn.QuadPart);
220  }
221  Mcb->Mapping->Table.CompareRoutine = McbMappingCompare;
222 
223  /* finally insert the resulting run */
224  RtlInsertElementGenericTable(&Mcb->Mapping->Table, &Node, sizeof(Node), &NewElement);
225  ++Mcb->PairCount;
226  ASSERT(NewElement);
227 
228  // NB: Two consecutive runs can only be merged, if actual LBNs also match!
229 
230  /* 1.
231  Existing->RunStartVbn
232  |
233  |///////|
234  |/////////////|
235  |
236  Node->RunStartVbn
237 
238  2.
239  Existing->RunStartVbn
240  |
241  |///////|
242  |//////|
243  |
244  Node->RunStartVbn
245 
246  3.
247  Existing->RunStartVbn
248  |
249  |///////|
250  |///|
251  |
252  Node->RunStartVbn
253 
254  4.
255  Existing->RunStartVbn
256  |
257  |///////|
258  |///////////////|
259  |
260  Node->RunStartVbn
261 
262 
263  Situation with holes:
264  1. Holes at both ends
265  2. Hole at the right, new run merged with the previous run
266  3. Hole at the right, new run is not merged with the previous run
267  4. Hole at the left, new run merged with the next run
268  5. Hole at the left, new run is not merged with the next run
269  6. No holes, exact fit to merge with both previous and next runs
270  7. No holes, merges only with the next run
271  8. No holes, merges only with the previous run
272  9. No holes, does not merge with next or prev runs
273 
274 
275  Overwriting existing mapping is not possible and results in FALSE being returned
276  */
277 
278 quit:
279  DPRINT("FsRtlAddBaseMcbEntry(%p, %I64d, %I64d, %I64d) = %d\n", Mcb, Vbn, Lbn, SectorCount, Result);
280  return Result;
281 }
#define TRUE
Definition: types.h:120
void quit(int argc, const char *argv[])
Definition: cmds.c:1606
_Must_inspect_result_ _In_ LONGLONG _In_ LONGLONG Lbn
Definition: fsrtlfuncs.h:479
Definition: largemcb.c:26
LARGE_INTEGER StartingLbn
Definition: largemcb.c:30
struct _BASE_MCB_INTERNAL * PBASE_MCB_INTERNAL
BOOLEAN NTAPI FsRtlLookupBaseMcbEntry(IN PBASE_MCB OpaqueMcb, IN LONGLONG Vbn, OUT PLONGLONG Lbn OPTIONAL, OUT PLONGLONG SectorCountFromLbn OPTIONAL, OUT PLONGLONG StartingLbn OPTIONAL, OUT PLONGLONG SectorCountFromStartingLbn OPTIONAL, OUT PULONG Index OPTIONAL)
Definition: largemcb.c:505
static RTL_GENERIC_COMPARE_RESULTS NTAPI McbMappingCompare(PRTL_GENERIC_TABLE Table, PVOID PtrA, PVOID PtrB)
Definition: largemcb.c:72
#define FALSE
Definition: types.h:117
union node Node
Definition: types.h:1255
unsigned char BOOLEAN
_At_(*)(_In_ PWSK_CLIENT Client, _In_opt_ PUNICODE_STRING NodeName, _In_opt_ PUNICODE_STRING ServiceName, _In_opt_ ULONG NameSpace, _In_opt_ GUID *Provider, _In_opt_ PADDRINFOEXW Hints, _Outptr_ PADDRINFOEXW *Result, _In_opt_ PEPROCESS OwningProcess, _In_opt_ PETHREAD OwningThread, _Inout_ PIRP Irp Result)(Mem)) NTSTATUS(WSKAPI *PFN_WSK_GET_ADDRESS_INFO
Definition: wsk.h:426
#define ULL(a, b)
Definition: format_msg.c:27
_Must_inspect_result_ NTSYSAPI PVOID NTAPI RtlLookupElementGenericTable(_In_ PRTL_GENERIC_TABLE Table, _In_ PVOID Buffer)
int64_t LONGLONG
Definition: typedefs.h:68
#define ASSERT(a)
Definition: mode.c:44
LARGE_INTEGER RunStartVbn
Definition: largemcb.c:28
BOOLEAN NTAPI FsRtlRemoveBaseMcbEntry(IN PBASE_MCB OpaqueMcb, IN LONGLONG Vbn, IN LONGLONG SectorCount)
Definition: largemcb.c:795
ULONG SectorCount
Definition: part_xbox.c:31
static RTL_GENERIC_COMPARE_RESULTS NTAPI McbMappingIntersectCompare(PRTL_GENERIC_TABLE Table, PVOID PtrA, PVOID PtrB)
Definition: largemcb.c:97
NTSYSAPI BOOLEAN NTAPI RtlDeleteElementGenericTable(_In_ PRTL_GENERIC_TABLE Table, _In_ PVOID Buffer)
IN PVCB IN ULONG IN OUT PULONG IN BOOLEAN OUT PLARGE_MCB Mcb
Definition: fatprocs.h:343
#define NULL
Definition: types.h:112
_In_ LONGLONG Vbn
Definition: fsrtlfuncs.h:470
#define DPRINT
Definition: sndvol32.h:71
NTSYSAPI PVOID NTAPI RtlInsertElementGenericTable(_In_ PRTL_GENERIC_TABLE Table, _In_reads_bytes_(BufferSize) PVOID Buffer, _In_ CLONG BufferSize, _Out_opt_ PBOOLEAN NewElement)
LARGE_INTEGER RunEndVbn
Definition: largemcb.c:29
LONGLONG QuadPart
Definition: typedefs.h:114
Definition: dlist.c:348

Referenced by FsRtlAddLargeMcbEntry().

◆ FsRtlAddLargeMcbEntry()

BOOLEAN NTAPI FsRtlAddLargeMcbEntry ( IN PLARGE_MCB  Mcb,
IN LONGLONG  Vbn,
IN LONGLONG  Lbn,
IN LONGLONG  SectorCount 
)

Definition at line 288 of file largemcb.c.

292 {
293  BOOLEAN Result;
294 
295  DPRINT("FsRtlAddLargeMcbEntry(%p, %I64d, %I64d, %I64d)\n", Mcb, Vbn, Lbn, SectorCount);
296 
297  KeAcquireGuardedMutex(Mcb->GuardedMutex);
298  Result = FsRtlAddBaseMcbEntry(&(Mcb->BaseMcb),
299  Vbn,
300  Lbn,
301  SectorCount);
302  KeReleaseGuardedMutex(Mcb->GuardedMutex);
303 
304  DPRINT("FsRtlAddLargeMcbEntry(%p, %I64d, %I64d, %I64d) = %d\n", Mcb, Vbn, Lbn, SectorCount, Result);
305 
306  return Result;
307 }
VOID FASTCALL KeAcquireGuardedMutex(IN PKGUARDED_MUTEX GuardedMutex)
Definition: gmutex.c:42
_Must_inspect_result_ _In_ LONGLONG _In_ LONGLONG Lbn
Definition: fsrtlfuncs.h:479
unsigned char BOOLEAN
_At_(*)(_In_ PWSK_CLIENT Client, _In_opt_ PUNICODE_STRING NodeName, _In_opt_ PUNICODE_STRING ServiceName, _In_opt_ ULONG NameSpace, _In_opt_ GUID *Provider, _In_opt_ PADDRINFOEXW Hints, _Outptr_ PADDRINFOEXW *Result, _In_opt_ PEPROCESS OwningProcess, _In_opt_ PETHREAD OwningThread, _Inout_ PIRP Irp Result)(Mem)) NTSTATUS(WSKAPI *PFN_WSK_GET_ADDRESS_INFO
Definition: wsk.h:426
BOOLEAN NTAPI FsRtlAddBaseMcbEntry(IN PBASE_MCB OpaqueMcb, IN LONGLONG Vbn, IN LONGLONG Lbn, IN LONGLONG SectorCount)
Definition: largemcb.c:135
ULONG SectorCount
Definition: part_xbox.c:31
IN PVCB IN ULONG IN OUT PULONG IN BOOLEAN OUT PLARGE_MCB Mcb
Definition: fatprocs.h:343
VOID FASTCALL KeReleaseGuardedMutex(IN OUT PKGUARDED_MUTEX GuardedMutex)
Definition: gmutex.c:53
_In_ LONGLONG Vbn
Definition: fsrtlfuncs.h:470
#define DPRINT
Definition: sndvol32.h:71

Referenced by AddRun(), ConvertDataRunsToLargeMCB(), Ext2AddMcbExtent(), Ext2AddMcbMetaExts(), Ext2AddVcbExtent(), FatAddMcbEntry(), FsRtlAddMcbEntry(), FsRtlLargeMcbTest(), FsRtlLargeMcbTestsExt2(), FsRtlLargeMcbTestsFastFat(), FsRtlLargeMcbTestsFastFat_2(), and FsRtlLargeMcbTestsFastFat_3().

◆ FsRtlGetNextBaseMcbEntry()

BOOLEAN NTAPI FsRtlGetNextBaseMcbEntry ( IN PBASE_MCB  OpaqueMcb,
IN ULONG  RunIndex,
OUT PLONGLONG  Vbn,
OUT PLONGLONG  Lbn,
OUT PLONGLONG  SectorCount 
)

Definition at line 332 of file largemcb.c.

337 {
338  BOOLEAN Result = FALSE;
341  ULONG CurrentIndex = 0;
342  ULONGLONG LastVbn = 0;
343  ULONGLONG LastSectorCount = 0;
344 
345  // Traverse the tree
346  for (Run = (PLARGE_MCB_MAPPING_ENTRY)RtlEnumerateGenericTable(&Mcb->Mapping->Table, TRUE);
347  Run;
349  {
350  // is the current index a hole?
351  if (Run->RunStartVbn.QuadPart > (LastVbn + LastSectorCount))
352  {
353  // Is this the index we're looking for?
354  if (RunIndex == CurrentIndex)
355  {
356  *Vbn = LastVbn + LastSectorCount;
357  *Lbn = -1;
358  *SectorCount = Run->RunStartVbn.QuadPart - *Vbn;
359 
360  Result = TRUE;
361  goto quit;
362  }
363 
364  CurrentIndex++;
365  }
366 
367  if (RunIndex == CurrentIndex)
368  {
369  *Vbn = Run->RunStartVbn.QuadPart;
370  *Lbn = Run->StartingLbn.QuadPart;
371  *SectorCount = Run->RunEndVbn.QuadPart - Run->RunStartVbn.QuadPart;
372 
373  Result = TRUE;
374  goto quit;
375  }
376 
377  CurrentIndex++;
378  LastVbn = Run->RunStartVbn.QuadPart;
379  LastSectorCount = Run->RunEndVbn.QuadPart - Run->RunStartVbn.QuadPart;
380  }
381 
382 quit:
383  DPRINT("FsRtlGetNextBaseMcbEntry(%p, %d, %p, %p, %p) = %d (%I64d, %I64d, %I64d)\n", Mcb, RunIndex, Vbn, Lbn, SectorCount, Result, *Vbn, *Lbn, *SectorCount);
384  return Result;
385 }
Definition: bidi.c:433
#define TRUE
Definition: types.h:120
void quit(int argc, const char *argv[])
Definition: cmds.c:1606
_Must_inspect_result_ NTSYSAPI PVOID NTAPI RtlEnumerateGenericTable(_In_ PRTL_GENERIC_TABLE Table, _In_ BOOLEAN Restart)
_Must_inspect_result_ _In_ LONGLONG _In_ LONGLONG Lbn
Definition: fsrtlfuncs.h:479
Definition: largemcb.c:26
struct _BASE_MCB_INTERNAL * PBASE_MCB_INTERNAL
_Must_inspect_result_ _In_ ULONG RunIndex
Definition: fsrtlfuncs.h:538
#define FALSE
Definition: types.h:117
unsigned char BOOLEAN
_At_(*)(_In_ PWSK_CLIENT Client, _In_opt_ PUNICODE_STRING NodeName, _In_opt_ PUNICODE_STRING ServiceName, _In_opt_ ULONG NameSpace, _In_opt_ GUID *Provider, _In_opt_ PADDRINFOEXW Hints, _Outptr_ PADDRINFOEXW *Result, _In_opt_ PEPROCESS OwningProcess, _In_opt_ PETHREAD OwningThread, _Inout_ PIRP Irp Result)(Mem)) NTSTATUS(WSKAPI *PFN_WSK_GET_ADDRESS_INFO
Definition: wsk.h:426
struct tagRun Run
uint64_t ULONGLONG
Definition: typedefs.h:67
ULONG SectorCount
Definition: part_xbox.c:31
IN PVCB IN ULONG IN OUT PULONG IN BOOLEAN OUT PLARGE_MCB Mcb
Definition: fatprocs.h:343
#define NULL
Definition: types.h:112
struct _LARGE_MCB_MAPPING_ENTRY * PLARGE_MCB_MAPPING_ENTRY
_In_ LONGLONG Vbn
Definition: fsrtlfuncs.h:470
unsigned int ULONG
Definition: retypes.h:1
#define DPRINT
Definition: sndvol32.h:71

Referenced by FsRtlGetNextLargeMcbEntry(), FsRtlLookupBaseMcbEntry(), and FsRtlNumberOfRunsInBaseMcb().

◆ FsRtlGetNextLargeMcbEntry()

BOOLEAN NTAPI FsRtlGetNextLargeMcbEntry ( IN PLARGE_MCB  Mcb,
IN ULONG  RunIndex,
OUT PLONGLONG  Vbn,
OUT PLONGLONG  Lbn,
OUT PLONGLONG  SectorCount 
)

Definition at line 392 of file largemcb.c.

397 {
398  BOOLEAN Result;
399 
400  DPRINT("FsRtlGetNextLargeMcbEntry(%p, %d, %p, %p, %p)\n", Mcb, RunIndex, Vbn, Lbn, SectorCount);
401 
402  KeAcquireGuardedMutex(Mcb->GuardedMutex);
403  Result = FsRtlGetNextBaseMcbEntry(&(Mcb->BaseMcb),
404  RunIndex,
405  Vbn,
406  Lbn,
407  SectorCount);
408  KeReleaseGuardedMutex(Mcb->GuardedMutex);
409 
410  DPRINT("FsRtlGetNextLargeMcbEntry(%p, %d, %p, %p, %p) = %d (%I64d, %I64d, %I64d)\n", Mcb, RunIndex, Vbn, Lbn, SectorCount, Result, *Vbn, *Lbn, *SectorCount);
411 
412  return Result;
413 }
VOID FASTCALL KeAcquireGuardedMutex(IN PKGUARDED_MUTEX GuardedMutex)
Definition: gmutex.c:42
_Must_inspect_result_ _In_ LONGLONG _In_ LONGLONG Lbn
Definition: fsrtlfuncs.h:479
_Must_inspect_result_ _In_ ULONG RunIndex
Definition: fsrtlfuncs.h:538
unsigned char BOOLEAN
_At_(*)(_In_ PWSK_CLIENT Client, _In_opt_ PUNICODE_STRING NodeName, _In_opt_ PUNICODE_STRING ServiceName, _In_opt_ ULONG NameSpace, _In_opt_ GUID *Provider, _In_opt_ PADDRINFOEXW Hints, _Outptr_ PADDRINFOEXW *Result, _In_opt_ PEPROCESS OwningProcess, _In_opt_ PETHREAD OwningThread, _Inout_ PIRP Irp Result)(Mem)) NTSTATUS(WSKAPI *PFN_WSK_GET_ADDRESS_INFO
Definition: wsk.h:426
BOOLEAN NTAPI FsRtlGetNextBaseMcbEntry(IN PBASE_MCB OpaqueMcb, IN ULONG RunIndex, OUT PLONGLONG Vbn, OUT PLONGLONG Lbn, OUT PLONGLONG SectorCount)
Definition: largemcb.c:332
ULONG SectorCount
Definition: part_xbox.c:31
IN PVCB IN ULONG IN OUT PULONG IN BOOLEAN OUT PLARGE_MCB Mcb
Definition: fatprocs.h:343
VOID FASTCALL KeReleaseGuardedMutex(IN OUT PKGUARDED_MUTEX GuardedMutex)
Definition: gmutex.c:53
_In_ LONGLONG Vbn
Definition: fsrtlfuncs.h:470
#define DPRINT
Definition: sndvol32.h:71

Referenced by ConvertLargeMCBToDataRuns(), DumpAllRuns(), Ext2CheckExtent(), Ext2ListExtents(), Ext2TruncateIndirectFast(), FatGetNextMcbEntry(), FsRtlGetNextMcbEntry(), FsRtlLargeMcbTest(), FsRtlLargeMcbTestsExt2(), and FsRtlLargeMcbTestsFastFat_3().

◆ FsRtlInitializeBaseMcb()

VOID NTAPI FsRtlInitializeBaseMcb ( IN PBASE_MCB  OpaqueMcb,
IN POOL_TYPE  PoolType 
)

Definition at line 420 of file largemcb.c.

422 {
424 
425  if (PoolType == PagedPool)
426  {
427  Mcb->Mapping = ExAllocateFromPagedLookasideList(&FsRtlFirstMappingLookasideList);
428  }
429  else
430  {
432  sizeof(LARGE_MCB_MAPPING),
433  'CBSF');
434  }
435 
436  Mcb->PoolType = PoolType;
437  Mcb->PairCount = 0;
438  Mcb->MaximumPairCount = MAXIMUM_PAIR_COUNT;
439  RtlInitializeGenericTable(&Mcb->Mapping->Table,
443  Mcb);
444 }
PAGED_LOOKASIDE_LIST FsRtlFirstMappingLookasideList
Definition: largemcb.c:22
VOID NTAPI RtlInitializeGenericTable(IN PRTL_GENERIC_TABLE Table, IN PRTL_GENERIC_COMPARE_ROUTINE CompareRoutine, IN PRTL_GENERIC_ALLOCATE_ROUTINE AllocateRoutine, IN PRTL_GENERIC_FREE_ROUTINE FreeRoutine, IN PVOID TableContext)
Definition: generictable.c:100
struct _BASE_MCB_INTERNAL * PBASE_MCB_INTERNAL
static RTL_GENERIC_COMPARE_RESULTS NTAPI McbMappingCompare(PRTL_GENERIC_TABLE Table, PVOID PtrA, PVOID PtrB)
Definition: largemcb.c:72
static VOID NTAPI McbMappingFree(PRTL_GENERIC_TABLE Table, PVOID Buffer)
Definition: largemcb.c:63
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
IN PVCB IN ULONG IN OUT PULONG IN BOOLEAN OUT PLARGE_MCB Mcb
Definition: fatprocs.h:343
static PVOID NTAPI McbMappingAllocate(PRTL_GENERIC_TABLE Table, CLONG Bytes)
Definition: largemcb.c:54
_Must_inspect_result_ _In_ WDFDEVICE _In_ DEVICE_REGISTRY_PROPERTY _In_ _Strict_type_match_ POOL_TYPE PoolType
Definition: wdfdevice.h:3810
#define POOL_RAISE_IF_ALLOCATION_FAILURE
#define MAXIMUM_PAIR_COUNT
Definition: fsrtl.h:50

Referenced by FsRtlInitializeLargeMcb().

◆ FsRtlInitializeLargeMcb()

VOID NTAPI FsRtlInitializeLargeMcb ( IN PLARGE_MCB  Mcb,
IN POOL_TYPE  PoolType 
)

Definition at line 451 of file largemcb.c.

453 {
454  DPRINT("FsRtlInitializeLargeMcb(%p, %d)\n", Mcb, PoolType);
455 
456  Mcb->GuardedMutex = ExAllocateFromNPagedLookasideList(&FsRtlFastMutexLookasideList);
457 
458  KeInitializeGuardedMutex(Mcb->GuardedMutex);
459 
460  _SEH2_TRY
461  {
462  FsRtlInitializeBaseMcb(&(Mcb->BaseMcb), PoolType);
463  }
465  {
466  ExFreeToNPagedLookasideList(&FsRtlFastMutexLookasideList,
467  Mcb->GuardedMutex);
468  Mcb->GuardedMutex = NULL;
469  }
470  _SEH2_END;
471 }
_SEH2_TRY
Definition: create.c:4226
VOID NTAPI FsRtlInitializeBaseMcb(IN PBASE_MCB OpaqueMcb, IN POOL_TYPE PoolType)
Definition: largemcb.c:420
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:85
NPAGED_LOOKASIDE_LIST FsRtlFastMutexLookasideList
Definition: largemcb.c:23
_SEH2_END
Definition: create.c:4400
VOID FASTCALL KeInitializeGuardedMutex(OUT PKGUARDED_MUTEX GuardedMutex)
Definition: gmutex.c:31
IN PVCB IN ULONG IN OUT PULONG IN BOOLEAN OUT PLARGE_MCB Mcb
Definition: fatprocs.h:343
#define NULL
Definition: types.h:112
_Must_inspect_result_ _In_ WDFDEVICE _In_ DEVICE_REGISTRY_PROPERTY _In_ _Strict_type_match_ POOL_TYPE PoolType
Definition: wdfdevice.h:3810
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:40
#define DPRINT
Definition: sndvol32.h:71

Referenced by _Requires_lock_held_(), ConvertDataRunsToLargeMCB(), Ext2AllocateMcb(), Ext2InitializeVcb(), FatCreateDcb(), FatCreateFcb(), FsRtlInitializeMcb(), FsRtlLargeMcbTest(), FsRtlLargeMcbTestsExt2(), FsRtlLargeMcbTestsFastFat(), FsRtlLargeMcbTestsFastFat_2(), FsRtlLargeMcbTestsFastFat_3(), and SetResidentAttributeDataLength().

◆ FsRtlInitializeLargeMcbs()

VOID NTAPI FsRtlInitializeLargeMcbs ( VOID  )

Definition at line 479 of file largemcb.c.

480 {
481  /* Initialize the list for the MCB */
483  NULL,
484  NULL,
486  sizeof(LARGE_MCB_MAPPING),
487  IFS_POOL_TAG,
488  0); /* FIXME: Should be 4 */
489 
490  /* Initialize the list for the guarded mutex */
492  NULL,
493  NULL,
495  sizeof(KGUARDED_MUTEX),
496  IFS_POOL_TAG,
497  0); /* FIXME: Should be 32 */
498 }
VOID NTAPI ExInitializePagedLookasideList(IN PPAGED_LOOKASIDE_LIST Lookaside, IN PALLOCATE_FUNCTION Allocate OPTIONAL, IN PFREE_FUNCTION Free OPTIONAL, IN ULONG Flags, IN SIZE_T Size, IN ULONG Tag, IN USHORT Depth)
Definition: lookas.c:270
PAGED_LOOKASIDE_LIST FsRtlFirstMappingLookasideList
Definition: largemcb.c:22
#define IFS_POOL_TAG
Definition: tag.h:52
VOID NTAPI ExInitializeNPagedLookasideList(IN PNPAGED_LOOKASIDE_LIST Lookaside, IN PALLOCATE_FUNCTION Allocate OPTIONAL, IN PFREE_FUNCTION Free OPTIONAL, IN ULONG Flags, IN SIZE_T Size, IN ULONG Tag, IN USHORT Depth)
Definition: lookas.c:218
NPAGED_LOOKASIDE_LIST FsRtlFastMutexLookasideList
Definition: largemcb.c:23
#define NULL
Definition: types.h:112
#define POOL_RAISE_IF_ALLOCATION_FAILURE

Referenced by FsRtlInitSystem().

◆ FsRtlLookupBaseMcbEntry()

BOOLEAN NTAPI FsRtlLookupBaseMcbEntry ( IN PBASE_MCB  OpaqueMcb,
IN LONGLONG  Vbn,
OUT PLONGLONG Lbn  OPTIONAL,
OUT PLONGLONG SectorCountFromLbn  OPTIONAL,
OUT PLONGLONG StartingLbn  OPTIONAL,
OUT PLONGLONG SectorCountFromStartingLbn  OPTIONAL,
OUT PULONG Index  OPTIONAL 
)

Definition at line 505 of file largemcb.c.

512 {
513  BOOLEAN Result = FALSE;
514  ULONG i;
515  LONGLONG LastVbn = 0, LastLbn = 0, Count = 0; // the last values we've found during traversal
516 
517  DPRINT("FsRtlLookupBaseMcbEntry(%p, %I64d, %p, %p, %p, %p, %p)\n", OpaqueMcb, Vbn, Lbn, SectorCountFromLbn, StartingLbn, SectorCountFromStartingLbn, Index);
518 
519  for (i = 0; FsRtlGetNextBaseMcbEntry(OpaqueMcb, i, &LastVbn, &LastLbn, &Count); i++)
520  {
521  // have we reached the target mapping?
522  if (Vbn < LastVbn + Count)
523  {
524  if (Lbn)
525  {
526  if (LastLbn == -1)
527  *Lbn = -1;
528  else
529  *Lbn = LastLbn + (Vbn - LastVbn);
530  }
531 
532  if (SectorCountFromLbn)
533  *SectorCountFromLbn = LastVbn + Count - Vbn;
534  if (StartingLbn)
535  *StartingLbn = LastLbn;
537  *SectorCountFromStartingLbn = LastVbn + Count - LastVbn;
538  if (Index)
539  *Index = i;
540 
541  Result = TRUE;
542  goto quit;
543  }
544  }
545 
546 quit:
547  DPRINT("FsRtlLookupBaseMcbEntry(%p, %I64d, %p, %p, %p, %p, %p) = %d (%I64d, %I64d, %I64d, %I64d, %d)\n",
551 
552  return Result;
553 }
#define TRUE
Definition: types.h:120
void quit(int argc, const char *argv[])
Definition: cmds.c:1606
_In_ LONGLONG _Out_opt_ PLONGLONG _Out_opt_ PLONGLONG SectorCountFromLbn
Definition: fsrtlfuncs.h:498
_Must_inspect_result_ _In_ LONGLONG _In_ LONGLONG Lbn
Definition: fsrtlfuncs.h:479
#define FALSE
Definition: types.h:117
unsigned char BOOLEAN
_At_(*)(_In_ PWSK_CLIENT Client, _In_opt_ PUNICODE_STRING NodeName, _In_opt_ PUNICODE_STRING ServiceName, _In_opt_ ULONG NameSpace, _In_opt_ GUID *Provider, _In_opt_ PADDRINFOEXW Hints, _Outptr_ PADDRINFOEXW *Result, _In_opt_ PEPROCESS OwningProcess, _In_opt_ PETHREAD OwningThread, _Inout_ PIRP Irp Result)(Mem)) NTSTATUS(WSKAPI *PFN_WSK_GET_ADDRESS_INFO
Definition: wsk.h:426
_In_ LONGLONG _Out_opt_ PLONGLONG _Out_opt_ PLONGLONG _Out_opt_ PLONGLONG StartingLbn
Definition: fsrtlfuncs.h:498
int64_t LONGLONG
Definition: typedefs.h:68
int Count
Definition: noreturn.cpp:7
_In_ WDFCOLLECTION _In_ ULONG Index
uint64_t ULONGLONG
Definition: typedefs.h:67
BOOLEAN NTAPI FsRtlGetNextBaseMcbEntry(IN PBASE_MCB OpaqueMcb, IN ULONG RunIndex, OUT PLONGLONG Vbn, OUT PLONGLONG Lbn, OUT PLONGLONG SectorCount)
Definition: largemcb.c:332
_In_ LONGLONG _Out_opt_ PLONGLONG _Out_opt_ PLONGLONG _Out_opt_ PLONGLONG _Out_opt_ PLONGLONG SectorCountFromStartingLbn
Definition: fsrtlfuncs.h:498
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
_In_ LONGLONG Vbn
Definition: fsrtlfuncs.h:470
unsigned int ULONG
Definition: retypes.h:1
#define DPRINT
Definition: sndvol32.h:71

Referenced by FsRtlAddBaseMcbEntry(), and FsRtlLookupLargeMcbEntry().

◆ FsRtlLookupLargeMcbEntry()

BOOLEAN NTAPI FsRtlLookupLargeMcbEntry ( IN PLARGE_MCB  Mcb,
IN LONGLONG  Vbn,
OUT PLONGLONG Lbn  OPTIONAL,
OUT PLONGLONG SectorCountFromLbn  OPTIONAL,
OUT PLONGLONG StartingLbn  OPTIONAL,
OUT PLONGLONG SectorCountFromStartingLbn  OPTIONAL,
OUT PULONG Index  OPTIONAL 
)

Definition at line 560 of file largemcb.c.

567 {
568  BOOLEAN Result;
569 
570  DPRINT("FsRtlLookupLargeMcbEntry(%p, %I64d, %p, %p, %p, %p, %p)\n", Mcb, Vbn, Lbn, SectorCountFromLbn, StartingLbn, SectorCountFromStartingLbn, Index);
571 
572  KeAcquireGuardedMutex(Mcb->GuardedMutex);
573  Result = FsRtlLookupBaseMcbEntry(&(Mcb->BaseMcb),
574  Vbn,
575  Lbn,
577  StartingLbn,
579  Index);
580  KeReleaseGuardedMutex(Mcb->GuardedMutex);
581 
582  DPRINT("FsRtlLookupLargeMcbEntry(%p, %I64d, %p, %p, %p, %p, %p) = %d (%I64d, %I64d, %I64d, %I64d, %d)\n",
586 
587  return Result;
588 }
VOID FASTCALL KeAcquireGuardedMutex(IN PKGUARDED_MUTEX GuardedMutex)
Definition: gmutex.c:42
_In_ LONGLONG _Out_opt_ PLONGLONG _Out_opt_ PLONGLONG SectorCountFromLbn
Definition: fsrtlfuncs.h:498
_Must_inspect_result_ _In_ LONGLONG _In_ LONGLONG Lbn
Definition: fsrtlfuncs.h:479
BOOLEAN NTAPI FsRtlLookupBaseMcbEntry(IN PBASE_MCB OpaqueMcb, IN LONGLONG Vbn, OUT PLONGLONG Lbn OPTIONAL, OUT PLONGLONG SectorCountFromLbn OPTIONAL, OUT PLONGLONG StartingLbn OPTIONAL, OUT PLONGLONG SectorCountFromStartingLbn OPTIONAL, OUT PULONG Index OPTIONAL)
Definition: largemcb.c:505
unsigned char BOOLEAN
_At_(*)(_In_ PWSK_CLIENT Client, _In_opt_ PUNICODE_STRING NodeName, _In_opt_ PUNICODE_STRING ServiceName, _In_opt_ ULONG NameSpace, _In_opt_ GUID *Provider, _In_opt_ PADDRINFOEXW Hints, _Outptr_ PADDRINFOEXW *Result, _In_opt_ PEPROCESS OwningProcess, _In_opt_ PETHREAD OwningThread, _Inout_ PIRP Irp Result)(Mem)) NTSTATUS(WSKAPI *PFN_WSK_GET_ADDRESS_INFO
Definition: wsk.h:426
_In_ LONGLONG _Out_opt_ PLONGLONG _Out_opt_ PLONGLONG _Out_opt_ PLONGLONG StartingLbn
Definition: fsrtlfuncs.h:498
_In_ WDFCOLLECTION _In_ ULONG Index
uint64_t ULONGLONG
Definition: typedefs.h:67
_In_ LONGLONG _Out_opt_ PLONGLONG _Out_opt_ PLONGLONG _Out_opt_ PLONGLONG _Out_opt_ PLONGLONG SectorCountFromStartingLbn
Definition: fsrtlfuncs.h:498
IN PVCB IN ULONG IN OUT PULONG IN BOOLEAN OUT PLARGE_MCB Mcb
Definition: fatprocs.h:343
VOID FASTCALL KeReleaseGuardedMutex(IN OUT PKGUARDED_MUTEX GuardedMutex)
Definition: gmutex.c:53
_In_ LONGLONG Vbn
Definition: fsrtlfuncs.h:470
unsigned int ULONG
Definition: retypes.h:1
#define DPRINT
Definition: sndvol32.h:71

Referenced by Ext2CheckExtent(), Ext2LookupMcbExtent(), Ext2LookupVcbExtent(), FatLookupMcbEntry(), FsRtlLargeMcbTest(), FsRtlLargeMcbTestsExt2(), FsRtlLargeMcbTestsFastFat_3(), FsRtlLookupMcbEntry(), and SetNonResidentAttributeDataLength().

◆ FsRtlLookupLastBaseMcbEntry()

BOOLEAN NTAPI FsRtlLookupLastBaseMcbEntry ( IN PBASE_MCB  OpaqueMcb,
OUT PLONGLONG  Vbn,
OUT PLONGLONG  Lbn 
)

Definition at line 697 of file largemcb.c.

700 {
701  BOOLEAN Result;
703 
704  DPRINT("FsRtlLookupLastBaseMcbEntry(%p, %p, %p)\n", OpaqueMcb, Vbn, Lbn);
705 
707 
708  DPRINT("FsRtlLookupLastBaseMcbEntry(%p, %p, %p) = %d (%I64d, %I64d)\n", Mcb, Vbn, Lbn, Result, *Vbn, *Lbn);
709 
710  return Result;
711 }
_Must_inspect_result_ _In_ LONGLONG _In_ LONGLONG Lbn
Definition: fsrtlfuncs.h:479
struct _BASE_MCB_INTERNAL * PBASE_MCB_INTERNAL
unsigned char BOOLEAN
_At_(*)(_In_ PWSK_CLIENT Client, _In_opt_ PUNICODE_STRING NodeName, _In_opt_ PUNICODE_STRING ServiceName, _In_opt_ ULONG NameSpace, _In_opt_ GUID *Provider, _In_opt_ PADDRINFOEXW Hints, _Outptr_ PADDRINFOEXW *Result, _In_opt_ PEPROCESS OwningProcess, _In_opt_ PETHREAD OwningThread, _Inout_ PIRP Irp Result)(Mem)) NTSTATUS(WSKAPI *PFN_WSK_GET_ADDRESS_INFO
Definition: wsk.h:426
static BOOLEAN NTAPI FsRtlLookupLastLargeMcbEntryAndIndex_internal(IN PBASE_MCB_INTERNAL Mcb, OUT PLONGLONG Vbn, OUT PLONGLONG Lbn, OUT PULONG Index OPTIONAL)
Definition: largemcb.c:592
IN PVCB IN ULONG IN OUT PULONG IN BOOLEAN OUT PLARGE_MCB Mcb
Definition: fatprocs.h:343
#define NULL
Definition: types.h:112
_In_ LONGLONG Vbn
Definition: fsrtlfuncs.h:470
#define DPRINT
Definition: sndvol32.h:71

Referenced by FsRtlLookupLastLargeMcbEntry().

◆ FsRtlLookupLastBaseMcbEntryAndIndex()

BOOLEAN NTAPI FsRtlLookupLastBaseMcbEntryAndIndex ( IN PBASE_MCB  OpaqueMcb,
IN OUT PLONGLONG  LargeVbn,
IN OUT PLONGLONG  LargeLbn,
IN OUT PULONG  Index 
)

Definition at line 649 of file largemcb.c.

653 {
654  BOOLEAN Result;
656 
657  DPRINT("FsRtlLookupLastBaseMcbEntryAndIndex(%p, %p, %p, %p)\n", OpaqueMcb, LargeVbn, LargeLbn, Index);
658 
660 
661  DPRINT("FsRtlLookupLastBaseMcbEntryAndIndex(%p, %p, %p, %p) = %d (%I64d, %I64d, %d)\n", OpaqueMcb, LargeVbn, LargeLbn, Index, Result, *LargeVbn, *LargeLbn, *Index);
662 
663  return Result;
664 }
_Out_ PLONGLONG LargeVbn
Definition: fsrtlfuncs.h:520
struct _BASE_MCB_INTERNAL * PBASE_MCB_INTERNAL
unsigned char BOOLEAN
_At_(*)(_In_ PWSK_CLIENT Client, _In_opt_ PUNICODE_STRING NodeName, _In_opt_ PUNICODE_STRING ServiceName, _In_opt_ ULONG NameSpace, _In_opt_ GUID *Provider, _In_opt_ PADDRINFOEXW Hints, _Outptr_ PADDRINFOEXW *Result, _In_opt_ PEPROCESS OwningProcess, _In_opt_ PETHREAD OwningThread, _Inout_ PIRP Irp Result)(Mem)) NTSTATUS(WSKAPI *PFN_WSK_GET_ADDRESS_INFO
Definition: wsk.h:426
_In_ WDFCOLLECTION _In_ ULONG Index
static BOOLEAN NTAPI FsRtlLookupLastLargeMcbEntryAndIndex_internal(IN PBASE_MCB_INTERNAL Mcb, OUT PLONGLONG Vbn, OUT PLONGLONG Lbn, OUT PULONG Index OPTIONAL)
Definition: largemcb.c:592
IN PVCB IN ULONG IN OUT PULONG IN BOOLEAN OUT PLARGE_MCB Mcb
Definition: fatprocs.h:343
_Out_ PLONGLONG _Out_ PLONGLONG LargeLbn
Definition: fsrtlfuncs.h:520
#define DPRINT
Definition: sndvol32.h:71

Referenced by FsRtlLookupLastLargeMcbEntryAndIndex().

◆ FsRtlLookupLastLargeMcbEntry()

BOOLEAN NTAPI FsRtlLookupLastLargeMcbEntry ( IN PLARGE_MCB  Mcb,
OUT PLONGLONG  Vbn,
OUT PLONGLONG  Lbn 
)

Definition at line 718 of file largemcb.c.

721 {
722  BOOLEAN Result;
723 
724  DPRINT("FsRtlLookupLastLargeMcbEntry(%p, %p, %p)\n", Mcb, Vbn, Lbn);
725 
726  KeAcquireGuardedMutex(Mcb->GuardedMutex);
727  Result = FsRtlLookupLastBaseMcbEntry(&(Mcb->BaseMcb),
728  Vbn,
729  Lbn);
730  KeReleaseGuardedMutex(Mcb->GuardedMutex);
731 
732  DPRINT("FsRtlLookupLastLargeMcbEntry(%p, %p, %p) = %d (%I64d, %I64d)\n", Mcb, Vbn, Lbn, Result, *Vbn, *Lbn);
733 
734  return Result;
735 }
BOOLEAN NTAPI FsRtlLookupLastBaseMcbEntry(IN PBASE_MCB OpaqueMcb, OUT PLONGLONG Vbn, OUT PLONGLONG Lbn)
Definition: largemcb.c:697
VOID FASTCALL KeAcquireGuardedMutex(IN PKGUARDED_MUTEX GuardedMutex)
Definition: gmutex.c:42
_Must_inspect_result_ _In_ LONGLONG _In_ LONGLONG Lbn
Definition: fsrtlfuncs.h:479
unsigned char BOOLEAN
_At_(*)(_In_ PWSK_CLIENT Client, _In_opt_ PUNICODE_STRING NodeName, _In_opt_ PUNICODE_STRING ServiceName, _In_opt_ ULONG NameSpace, _In_opt_ GUID *Provider, _In_opt_ PADDRINFOEXW Hints, _Outptr_ PADDRINFOEXW *Result, _In_opt_ PEPROCESS OwningProcess, _In_opt_ PETHREAD OwningThread, _Inout_ PIRP Irp Result)(Mem)) NTSTATUS(WSKAPI *PFN_WSK_GET_ADDRESS_INFO
Definition: wsk.h:426
IN PVCB IN ULONG IN OUT PULONG IN BOOLEAN OUT PLARGE_MCB Mcb
Definition: fatprocs.h:343
VOID FASTCALL KeReleaseGuardedMutex(IN OUT PKGUARDED_MUTEX GuardedMutex)
Definition: gmutex.c:53
_In_ LONGLONG Vbn
Definition: fsrtlfuncs.h:470
#define DPRINT
Definition: sndvol32.h:71

Referenced by FreeClusters(), FsRtlLargeMcbTest(), and FsRtlLookupLastMcbEntry().

◆ FsRtlLookupLastLargeMcbEntryAndIndex()

BOOLEAN NTAPI FsRtlLookupLastLargeMcbEntryAndIndex ( IN PLARGE_MCB  OpaqueMcb,
OUT PLONGLONG  LargeVbn,
OUT PLONGLONG  LargeLbn,
OUT PULONG  Index 
)

Definition at line 671 of file largemcb.c.

675 {
676  BOOLEAN Result;
677 
678  DPRINT("FsRtlLookupLastLargeMcbEntryAndIndex(%p, %p, %p, %p)\n", OpaqueMcb, LargeVbn, LargeLbn, Index);
679 
680  KeAcquireGuardedMutex(OpaqueMcb->GuardedMutex);
681  Result = FsRtlLookupLastBaseMcbEntryAndIndex(&(OpaqueMcb->BaseMcb),
682  LargeVbn,
683  LargeLbn,
684  Index);
685  KeReleaseGuardedMutex(OpaqueMcb->GuardedMutex);
686 
687  DPRINT("FsRtlLookupLastLargeMcbEntryAndIndex(%p, %p, %p, %p) = %d (%I64d, %I64d, %d)\n", OpaqueMcb, LargeVbn, LargeLbn, Index, Result, *LargeVbn, *LargeLbn, *Index);
688 
689  return Result;
690 }
VOID FASTCALL KeAcquireGuardedMutex(IN PKGUARDED_MUTEX GuardedMutex)
Definition: gmutex.c:42
_Out_ PLONGLONG LargeVbn
Definition: fsrtlfuncs.h:520
unsigned char BOOLEAN
_At_(*)(_In_ PWSK_CLIENT Client, _In_opt_ PUNICODE_STRING NodeName, _In_opt_ PUNICODE_STRING ServiceName, _In_opt_ ULONG NameSpace, _In_opt_ GUID *Provider, _In_opt_ PADDRINFOEXW Hints, _Outptr_ PADDRINFOEXW *Result, _In_opt_ PEPROCESS OwningProcess, _In_opt_ PETHREAD OwningThread, _Inout_ PIRP Irp Result)(Mem)) NTSTATUS(WSKAPI *PFN_WSK_GET_ADDRESS_INFO
Definition: wsk.h:426
_In_ WDFCOLLECTION _In_ ULONG Index
BOOLEAN NTAPI FsRtlLookupLastBaseMcbEntryAndIndex(IN PBASE_MCB OpaqueMcb, IN OUT PLONGLONG LargeVbn, IN OUT PLONGLONG LargeLbn, IN OUT PULONG Index)
Definition: largemcb.c:649
VOID FASTCALL KeReleaseGuardedMutex(IN OUT PKGUARDED_MUTEX GuardedMutex)
Definition: gmutex.c:53
_Out_ PLONGLONG _Out_ PLONGLONG LargeLbn
Definition: fsrtlfuncs.h:520
#define DPRINT
Definition: sndvol32.h:71

Referenced by FatLookupLastMcbEntry(), and FsRtlLargeMcbTest().

◆ FsRtlLookupLastLargeMcbEntryAndIndex_internal()

static BOOLEAN NTAPI FsRtlLookupLastLargeMcbEntryAndIndex_internal ( IN PBASE_MCB_INTERNAL  Mcb,
OUT PLONGLONG  Vbn,
OUT PLONGLONG  Lbn,
OUT PULONG Index  OPTIONAL 
)
static

Definition at line 592 of file largemcb.c.

596 {
597  ULONG RunIndex = 0;
598  PLARGE_MCB_MAPPING_ENTRY Run, RunFound = NULL;
599  LONGLONG LastVbn = 0;
600 
601  for (Run = (PLARGE_MCB_MAPPING_ENTRY)RtlEnumerateGenericTable(&Mcb->Mapping->Table, TRUE);
602  Run;
604  {
605  /* Take care when we must emulate missing 'hole' runs. */
606  if (Run->RunStartVbn.QuadPart > LastVbn)
607  {
608  RunIndex++;
609  }
610  LastVbn = Run->RunEndVbn.QuadPart;
611  RunIndex++;
612  RunFound = Run;
613  }
614 
615  if (!RunFound)
616  {
617  return FALSE;
618  }
619 
620  if (Vbn)
621  {
622  *Vbn = RunFound->RunEndVbn.QuadPart - 1;
623  }
624  if (Lbn)
625  {
626  if (1)
627  {
628  *Lbn = RunFound->StartingLbn.QuadPart + (RunFound->RunEndVbn.QuadPart - RunFound->RunStartVbn.QuadPart) - 1;
629  }
630  else
631  {
632  *Lbn = ~0ULL;
633  }
634  }
635  if (Index)
636  {
637  *Index = RunIndex - 1;
638  }
639 
640  return TRUE;
641 }
Definition: bidi.c:433
#define TRUE
Definition: types.h:120
_Must_inspect_result_ NTSYSAPI PVOID NTAPI RtlEnumerateGenericTable(_In_ PRTL_GENERIC_TABLE Table, _In_ BOOLEAN Restart)
_Must_inspect_result_ _In_ LONGLONG _In_ LONGLONG Lbn
Definition: fsrtlfuncs.h:479
Definition: largemcb.c:26
LARGE_INTEGER StartingLbn
Definition: largemcb.c:30
_Must_inspect_result_ _In_ ULONG RunIndex
Definition: fsrtlfuncs.h:538
#define FALSE
Definition: types.h:117
struct tagRun Run
#define ULL(a, b)
Definition: format_msg.c:27
int64_t LONGLONG
Definition: typedefs.h:68
_In_ WDFCOLLECTION _In_ ULONG Index
LARGE_INTEGER RunStartVbn
Definition: largemcb.c:28
IN PVCB IN ULONG IN OUT PULONG IN BOOLEAN OUT PLARGE_MCB Mcb
Definition: fatprocs.h:343
#define NULL
Definition: types.h:112
_In_ LONGLONG Vbn
Definition: fsrtlfuncs.h:470
unsigned int ULONG
Definition: retypes.h:1
LARGE_INTEGER RunEndVbn
Definition: largemcb.c:29
LONGLONG QuadPart
Definition: typedefs.h:114

Referenced by FsRtlLookupLastBaseMcbEntry(), and FsRtlLookupLastBaseMcbEntryAndIndex().

◆ FsRtlNumberOfRunsInBaseMcb()

ULONG NTAPI FsRtlNumberOfRunsInBaseMcb ( IN PBASE_MCB  OpaqueMcb)

Definition at line 742 of file largemcb.c.

743 {
744  ULONG NumberOfRuns = 0;
745  LONGLONG Vbn, Lbn, Count;
746  int i;
747 
748  DPRINT("FsRtlNumberOfRunsInBaseMcb(%p)\n", OpaqueMcb);
749 
750  // Count how many Mcb entries there are
751  for (i = 0; FsRtlGetNextBaseMcbEntry(OpaqueMcb, i, &Vbn, &Lbn, &Count); i++)
752  {
753  NumberOfRuns++;
754  }
755 
756  DPRINT("FsRtlNumberOfRunsInBaseMcb(%p) = %d\n", OpaqueMcb, NumberOfRuns);
757  return NumberOfRuns;
758 }
_Must_inspect_result_ _In_ LONGLONG _In_ LONGLONG Lbn
Definition: fsrtlfuncs.h:479
int64_t LONGLONG
Definition: typedefs.h:68
int Count
Definition: noreturn.cpp:7
BOOLEAN NTAPI FsRtlGetNextBaseMcbEntry(IN PBASE_MCB OpaqueMcb, IN ULONG RunIndex, OUT PLONGLONG Vbn, OUT PLONGLONG Lbn, OUT PLONGLONG SectorCount)
Definition: largemcb.c:332
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
_In_ LONGLONG Vbn
Definition: fsrtlfuncs.h:470
unsigned int ULONG
Definition: retypes.h:1
#define DPRINT
Definition: sndvol32.h:71

Referenced by FsRtlNumberOfRunsInLargeMcb().

◆ FsRtlNumberOfRunsInLargeMcb()

ULONG NTAPI FsRtlNumberOfRunsInLargeMcb ( IN PLARGE_MCB  Mcb)

Definition at line 765 of file largemcb.c.

766 {
767  ULONG NumberOfRuns;
768 
769  DPRINT("FsRtlNumberOfRunsInLargeMcb(%p)\n", Mcb);
770 
771  /* Read the number of runs while holding the MCB lock */
772  KeAcquireGuardedMutex(Mcb->GuardedMutex);
773  NumberOfRuns = FsRtlNumberOfRunsInBaseMcb(&(Mcb->BaseMcb));
774  KeReleaseGuardedMutex(Mcb->GuardedMutex);
775 
776  DPRINT("FsRtlNumberOfRunsInLargeMcb(%p) = %d\n", Mcb, NumberOfRuns);
777 
778  /* Return the count */
779  return NumberOfRuns;
780 }
VOID FASTCALL KeAcquireGuardedMutex(IN PKGUARDED_MUTEX GuardedMutex)
Definition: gmutex.c:42
IN PVCB IN ULONG IN OUT PULONG IN BOOLEAN OUT PLARGE_MCB Mcb
Definition: fatprocs.h:343
VOID FASTCALL KeReleaseGuardedMutex(IN OUT PKGUARDED_MUTEX GuardedMutex)
Definition: gmutex.c:53
unsigned int ULONG
Definition: retypes.h:1
#define DPRINT
Definition: sndvol32.h:71
ULONG NTAPI FsRtlNumberOfRunsInBaseMcb(IN PBASE_MCB OpaqueMcb)
Definition: largemcb.c:742

Referenced by _Requires_lock_held_(), Ext2AddMcbExtent(), Ext2AddMcbMetaExts(), Ext2AddVcbExtent(), Ext2Flush(), Ext2FreeMcb(), Ext2ListExtents(), Ext2RemoveMcbExtent(), Ext2RemoveMcbMetaExts(), Ext2RemoveVcbExtent(), Ext2TruncateIndirectFast(), FsRtlLargeMcbTest(), FsRtlLargeMcbTestsExt2(), FsRtlLargeMcbTestsFastFat(), FsRtlLargeMcbTestsFastFat_2(), FsRtlLargeMcbTestsFastFat_3(), and FsRtlNumberOfRunsInMcb().

◆ FsRtlRemoveBaseMcbEntry()

BOOLEAN NTAPI FsRtlRemoveBaseMcbEntry ( IN PBASE_MCB  OpaqueMcb,
IN LONGLONG  Vbn,
IN LONGLONG  SectorCount 
)

Definition at line 795 of file largemcb.c.

798 {
800  LARGE_MCB_MAPPING_ENTRY NeedleRun;
801  PLARGE_MCB_MAPPING_ENTRY HaystackRun;
802  BOOLEAN Result = TRUE;
803 
804  DPRINT("FsRtlRemoveBaseMcbEntry(%p, %I64d, %I64d)\n", OpaqueMcb, Vbn, SectorCount);
805 
806  if (Vbn < 0 || SectorCount <= 0)
807  {
808  Result = FALSE;
809  goto quit;
810  }
811 
812  if (Vbn + SectorCount <= Vbn)
813  {
814  Result = FALSE;
815  goto quit;
816  }
817 
818  NeedleRun.RunStartVbn.QuadPart = Vbn;
819  NeedleRun.RunEndVbn.QuadPart = Vbn + SectorCount;
820  NeedleRun.StartingLbn.QuadPart = -1;
821 
822  /* adjust/destroy all intersecting ranges */
823  Mcb->Mapping->Table.CompareRoutine = McbMappingIntersectCompare;
824  while ((HaystackRun = RtlLookupElementGenericTable(&Mcb->Mapping->Table, &NeedleRun)))
825  {
826  if (HaystackRun->RunStartVbn.QuadPart < NeedleRun.RunStartVbn.QuadPart)
827  {
828  LONGLONG HaystackRunEnd = HaystackRun->RunEndVbn.QuadPart;
829  ASSERT(HaystackRun->RunEndVbn.QuadPart > NeedleRun.RunStartVbn.QuadPart);
830 
831  HaystackRun->RunEndVbn.QuadPart = NeedleRun.RunStartVbn.QuadPart;
832 
833  if (HaystackRunEnd > NeedleRun.RunEndVbn.QuadPart)
834  {
835  /* The run we are deleting is included in the run we just truncated.
836  * Add the tail back. */
837  LARGE_MCB_MAPPING_ENTRY TailRun;
838  BOOLEAN NewElement;
839 
840  TailRun.RunStartVbn.QuadPart = NeedleRun.RunEndVbn.QuadPart;
841  TailRun.RunEndVbn.QuadPart = HaystackRunEnd;
842  TailRun.StartingLbn.QuadPart = HaystackRun->StartingLbn.QuadPart + (NeedleRun.RunEndVbn.QuadPart - HaystackRun->RunStartVbn.QuadPart);
843 
844  Mcb->Mapping->Table.CompareRoutine = McbMappingCompare;
845 
846  RtlInsertElementGenericTable(&Mcb->Mapping->Table, &TailRun, sizeof(TailRun), &NewElement);
847  ++Mcb->PairCount;
848  ASSERT(NewElement);
849 
850  Mcb->Mapping->Table.CompareRoutine = McbMappingIntersectCompare;
851  }
852  }
853  else if (HaystackRun->RunEndVbn.QuadPart > NeedleRun.RunEndVbn.QuadPart)
854  {
855  LONGLONG HaystackRunStart = HaystackRun->RunStartVbn.QuadPart;
856  LONGLONG HaystackStartingLbn = HaystackRun->StartingLbn.QuadPart;
857 
858  ASSERT(HaystackRun->RunStartVbn.QuadPart < NeedleRun.RunEndVbn.QuadPart);
859  HaystackRun->RunStartVbn.QuadPart = NeedleRun.RunEndVbn.QuadPart;
860  /* Adjust the starting LBN */
861  HaystackRun->StartingLbn.QuadPart += NeedleRun.RunEndVbn.QuadPart - HaystackRunStart;
862 
863  if (HaystackRunStart < NeedleRun.RunStartVbn.QuadPart)
864  {
865  /* The run we are deleting is included in the run we just truncated.
866  * Add the head back. */
867  LARGE_MCB_MAPPING_ENTRY HeadRun;
868  BOOLEAN NewElement;
869 
870  HeadRun.RunStartVbn.QuadPart = HaystackRunStart;
871  HeadRun.RunEndVbn.QuadPart = NeedleRun.RunStartVbn.QuadPart;
872  HeadRun.StartingLbn.QuadPart = HaystackStartingLbn;
873 
874  Mcb->Mapping->Table.CompareRoutine = McbMappingCompare;
875 
876  RtlInsertElementGenericTable(&Mcb->Mapping->Table, &HeadRun, sizeof(HeadRun), &NewElement);
877  ++Mcb->PairCount;
878  ASSERT(NewElement);
879 
880  Mcb->Mapping->Table.CompareRoutine = McbMappingIntersectCompare;
881  }
882  }
883  else
884  {
885  //ASSERT(NeedleRun.RunStartVbn.QuadPart >= HaystackRun->RunStartVbn.QuadPart);
886  //ASSERT(NeedleRun.RunEndVbn.QuadPart <= HaystackRun->RunEndVbn.QuadPart);
887  Mcb->Mapping->Table.CompareRoutine = McbMappingCompare;
888  RtlDeleteElementGenericTable(&Mcb->Mapping->Table, HaystackRun);
889  --Mcb->PairCount;
890  Mcb->Mapping->Table.CompareRoutine = McbMappingIntersectCompare;
891  }
892  }
893  Mcb->Mapping->Table.CompareRoutine = McbMappingCompare;
894 
895 quit:
896  DPRINT("FsRtlRemoveBaseMcbEntry(%p, %I64d, %I64d) = %d\n", OpaqueMcb, Vbn, SectorCount, Result);
897  return Result;
898 }
#define TRUE
Definition: types.h:120
void quit(int argc, const char *argv[])
Definition: cmds.c:1606
Definition: largemcb.c:26
LARGE_INTEGER StartingLbn
Definition: largemcb.c:30
struct _BASE_MCB_INTERNAL * PBASE_MCB_INTERNAL
static RTL_GENERIC_COMPARE_RESULTS NTAPI McbMappingCompare(PRTL_GENERIC_TABLE Table, PVOID PtrA, PVOID PtrB)
Definition: largemcb.c:72
#define FALSE
Definition: types.h:117
unsigned char BOOLEAN
_At_(*)(_In_ PWSK_CLIENT Client, _In_opt_ PUNICODE_STRING NodeName, _In_opt_ PUNICODE_STRING ServiceName, _In_opt_ ULONG NameSpace, _In_opt_ GUID *Provider, _In_opt_ PADDRINFOEXW Hints, _Outptr_ PADDRINFOEXW *Result, _In_opt_ PEPROCESS OwningProcess, _In_opt_ PETHREAD OwningThread, _Inout_ PIRP Irp Result)(Mem)) NTSTATUS(WSKAPI *PFN_WSK_GET_ADDRESS_INFO
Definition: wsk.h:426
_Must_inspect_result_ NTSYSAPI PVOID NTAPI RtlLookupElementGenericTable(_In_ PRTL_GENERIC_TABLE Table, _In_ PVOID Buffer)
int64_t LONGLONG
Definition: typedefs.h:68
#define ASSERT(a)
Definition: mode.c:44
LARGE_INTEGER RunStartVbn
Definition: largemcb.c:28
ULONG SectorCount
Definition: part_xbox.c:31
static RTL_GENERIC_COMPARE_RESULTS NTAPI McbMappingIntersectCompare(PRTL_GENERIC_TABLE Table, PVOID PtrA, PVOID PtrB)
Definition: largemcb.c:97
NTSYSAPI BOOLEAN NTAPI RtlDeleteElementGenericTable(_In_ PRTL_GENERIC_TABLE Table, _In_ PVOID Buffer)
IN PVCB IN ULONG IN OUT PULONG IN BOOLEAN OUT PLARGE_MCB Mcb
Definition: fatprocs.h:343
_In_ LONGLONG Vbn
Definition: fsrtlfuncs.h:470
#define DPRINT
Definition: sndvol32.h:71
NTSYSAPI PVOID NTAPI RtlInsertElementGenericTable(_In_ PRTL_GENERIC_TABLE Table, _In_reads_bytes_(BufferSize) PVOID Buffer, _In_ CLONG BufferSize, _Out_opt_ PBOOLEAN NewElement)
LARGE_INTEGER RunEndVbn
Definition: largemcb.c:29
LONGLONG QuadPart
Definition: typedefs.h:114

Referenced by FsRtlAddBaseMcbEntry(), FsRtlRemoveLargeMcbEntry(), and FsRtlTruncateBaseMcb().

◆ FsRtlRemoveLargeMcbEntry()

VOID NTAPI FsRtlRemoveLargeMcbEntry ( IN PLARGE_MCB  Mcb,
IN LONGLONG  Vbn,
IN LONGLONG  SectorCount 
)

Definition at line 905 of file largemcb.c.

908 {
909  DPRINT("FsRtlRemoveLargeMcbEntry(%p, %I64d, %I64d)\n", Mcb, Vbn, SectorCount);
910 
911  KeAcquireGuardedMutex(Mcb->GuardedMutex);
913  KeReleaseGuardedMutex(Mcb->GuardedMutex);
914 }
VOID FASTCALL KeAcquireGuardedMutex(IN PKGUARDED_MUTEX GuardedMutex)
Definition: gmutex.c:42
BOOLEAN NTAPI FsRtlRemoveBaseMcbEntry(IN PBASE_MCB OpaqueMcb, IN LONGLONG Vbn, IN LONGLONG SectorCount)
Definition: largemcb.c:795
ULONG SectorCount
Definition: part_xbox.c:31
IN PVCB IN ULONG IN OUT PULONG IN BOOLEAN OUT PLARGE_MCB Mcb
Definition: fatprocs.h:343
VOID FASTCALL KeReleaseGuardedMutex(IN OUT PKGUARDED_MUTEX GuardedMutex)
Definition: gmutex.c:53
_In_ LONGLONG Vbn
Definition: fsrtlfuncs.h:470
#define DPRINT
Definition: sndvol32.h:71

Referenced by Ext2RemoveMcbExtent(), Ext2RemoveMcbMetaExts(), Ext2RemoveVcbExtent(), FatRemoveMcbEntry(), FatResetFcb(), FsRtlLargeMcbTest(), FsRtlLargeMcbTestsFastFat(), FsRtlLargeMcbTestsFastFat_2(), FsRtlLargeMcbTestsFastFat_3(), and FsRtlRemoveMcbEntry().

◆ FsRtlResetBaseMcb()

VOID NTAPI FsRtlResetBaseMcb ( IN PBASE_MCB  OpaqueMcb)

Definition at line 921 of file largemcb.c.

922 {
924  PLARGE_MCB_MAPPING_ENTRY Element;
925 
926  DPRINT("FsRtlResetBaseMcb(%p)\n", OpaqueMcb);
927 
928  while (RtlNumberGenericTableElements(&Mcb->Mapping->Table) &&
929  (Element = (PLARGE_MCB_MAPPING_ENTRY)RtlGetElementGenericTable(&Mcb->Mapping->Table, 0)))
930  {
931  RtlDeleteElementGenericTable(&Mcb->Mapping->Table, Element);
932  }
933 
934  Mcb->PairCount = 0;
935  Mcb->MaximumPairCount = 0;
936 }
NTSYSAPI ULONG NTAPI RtlNumberGenericTableElements(_In_ PRTL_GENERIC_TABLE Table)
Definition: largemcb.c:26
struct _BASE_MCB_INTERNAL * PBASE_MCB_INTERNAL
_Must_inspect_result_ NTSYSAPI PVOID NTAPI RtlGetElementGenericTable(_In_ PRTL_GENERIC_TABLE Table, _In_ ULONG I)
NTSYSAPI BOOLEAN NTAPI RtlDeleteElementGenericTable(_In_ PRTL_GENERIC_TABLE Table, _In_ PVOID Buffer)
IN PVCB IN ULONG IN OUT PULONG IN BOOLEAN OUT PLARGE_MCB Mcb
Definition: fatprocs.h:343
#define DPRINT
Definition: sndvol32.h:71

Referenced by FsRtlResetLargeMcb(), and FsRtlUninitializeBaseMcb().

◆ FsRtlResetLargeMcb()

VOID NTAPI FsRtlResetLargeMcb ( IN PLARGE_MCB  Mcb,
IN BOOLEAN  SelfSynchronized 
)

Definition at line 943 of file largemcb.c.

945 {
946  DPRINT("FsRtlResetLargeMcb(%p, %d)\n", Mcb, SelfSynchronized);
947 
948  if (!SelfSynchronized)
949  KeAcquireGuardedMutex(Mcb->GuardedMutex);
950 
951  FsRtlResetBaseMcb(&Mcb->BaseMcb);
952 
953  if (!SelfSynchronized)
954  KeReleaseGuardedMutex(Mcb->GuardedMutex);
955 }
_In_ BOOLEAN SelfSynchronized
Definition: fsrtlfuncs.h:462
VOID FASTCALL KeAcquireGuardedMutex(IN PKGUARDED_MUTEX GuardedMutex)
Definition: gmutex.c:42
VOID NTAPI FsRtlResetBaseMcb(IN PBASE_MCB OpaqueMcb)
Definition: largemcb.c:921
IN PVCB IN ULONG IN OUT PULONG IN BOOLEAN OUT PLARGE_MCB Mcb
Definition: fatprocs.h:343
VOID FASTCALL KeReleaseGuardedMutex(IN OUT PKGUARDED_MUTEX GuardedMutex)
Definition: gmutex.c:53
#define DPRINT
Definition: sndvol32.h:71

◆ FsRtlSplitBaseMcb()

BOOLEAN NTAPI FsRtlSplitBaseMcb ( IN PBASE_MCB  OpaqueMcb,
IN LONGLONG  Vbn,
IN LONGLONG  Amount 
)

Definition at line 962 of file largemcb.c.

965 {
967  PLARGE_MCB_MAPPING_ENTRY Run, InsertLowerRun = NULL, ExistingRun = NULL;
968  BOOLEAN NewElement;
969 
970  DPRINT("FsRtlSplitBaseMcb(%p, %I64d, %I64d)\n", OpaqueMcb, Vbn, Amount);
971 
972  /* Traverse the tree */
973  for (Run = (PLARGE_MCB_MAPPING_ENTRY)RtlEnumerateGenericTable(&Mcb->Mapping->Table, TRUE);
974  Run;
976  {
977  /* unaffected run? */
978  /* FIXME: performance: effective skip of all 'lower' runs without traversing them */
979  if (Vbn >= Run->RunEndVbn.QuadPart) { DPRINT("Skipping it\n"); continue; }
980 
981  /* crossing run to be split?
982  * 'lower_run' is created on the original place; just shortened.
983  * current 'run' is shifted up later
984  */
985  if (Vbn < Run->RunEndVbn.QuadPart)
986  {
987  /* FIXME: shift 'run->Lbn_start' ? */
988  Run->RunStartVbn.QuadPart = Vbn;
989 
990  InsertLowerRun = NULL;
991  }
992 
993  /* Shift the current 'run'.
994  * Ordering is not changed in Generic Tree so I hope I do not need to reinsert it.
995  */
996  Run->RunStartVbn.QuadPart += Amount;
997  ASSERT(Run->RunEndVbn.QuadPart + Amount > Run->RunEndVbn.QuadPart); /* overflow? */
998  Run->RunEndVbn.QuadPart += Amount;
999  /* FIXME: shift 'run->Lbn_start' ? */
1000 
1001  /* continue the traversal */
1002  }
1003 
1004  if (InsertLowerRun)
1005  {
1006  ExistingRun = RtlInsertElementGenericTable(&Mcb->Mapping->Table, InsertLowerRun, sizeof(*InsertLowerRun), &NewElement);
1007  ++Mcb->PairCount;
1008  }
1009 
1010  ASSERT(ExistingRun == NULL);
1011 
1012  DPRINT("FsRtlSplitBaseMcb(%p, %I64d, %I64d) = %d\n", OpaqueMcb, Vbn, Amount, TRUE);
1013 
1014  return TRUE;
1015 }
Definition: bidi.c:433
_Must_inspect_result_ _In_ LONGLONG _In_ LONGLONG Amount
Definition: fsrtlfuncs.h:550
#define TRUE
Definition: types.h:120
_Must_inspect_result_ NTSYSAPI PVOID NTAPI RtlEnumerateGenericTable(_In_ PRTL_GENERIC_TABLE Table, _In_ BOOLEAN Restart)
Definition: largemcb.c:26
struct _BASE_MCB_INTERNAL * PBASE_MCB_INTERNAL
#define FALSE
Definition: types.h:117
unsigned char BOOLEAN
struct tagRun Run
#define ASSERT(a)
Definition: mode.c:44
IN PVCB IN ULONG IN OUT PULONG IN BOOLEAN OUT PLARGE_MCB Mcb
Definition: fatprocs.h:343
#define NULL
Definition: types.h:112
_In_ LONGLONG Vbn
Definition: fsrtlfuncs.h:470
#define DPRINT
Definition: sndvol32.h:71
NTSYSAPI PVOID NTAPI RtlInsertElementGenericTable(_In_ PRTL_GENERIC_TABLE Table, _In_reads_bytes_(BufferSize) PVOID Buffer, _In_ CLONG BufferSize, _Out_opt_ PBOOLEAN NewElement)

Referenced by FsRtlSplitLargeMcb().

◆ FsRtlSplitLargeMcb()

BOOLEAN NTAPI FsRtlSplitLargeMcb ( IN PLARGE_MCB  Mcb,
IN LONGLONG  Vbn,
IN LONGLONG  Amount 
)

Definition at line 1022 of file largemcb.c.

1025 {
1026  BOOLEAN Result;
1027 
1028  DPRINT("FsRtlSplitLargeMcb(%p, %I64d, %I64d)\n", Mcb, Vbn, Amount);
1029 
1030  KeAcquireGuardedMutex(Mcb->GuardedMutex);
1031  Result = FsRtlSplitBaseMcb(&(Mcb->BaseMcb),
1032  Vbn,
1033  Amount);
1034  KeReleaseGuardedMutex(Mcb->GuardedMutex);
1035 
1036  DPRINT("FsRtlSplitLargeMcb(%p, %I64d, %I64d) = %d\n", Mcb, Vbn, Amount, Result);
1037 
1038  return Result;
1039 }
_Must_inspect_result_ _In_ LONGLONG _In_ LONGLONG Amount
Definition: fsrtlfuncs.h:550
VOID FASTCALL KeAcquireGuardedMutex(IN PKGUARDED_MUTEX GuardedMutex)
Definition: gmutex.c:42
BOOLEAN NTAPI FsRtlSplitBaseMcb(IN PBASE_MCB OpaqueMcb, IN LONGLONG Vbn, IN LONGLONG Amount)
Definition: largemcb.c:962
unsigned char BOOLEAN
_At_(*)(_In_ PWSK_CLIENT Client, _In_opt_ PUNICODE_STRING NodeName, _In_opt_ PUNICODE_STRING ServiceName, _In_opt_ ULONG NameSpace, _In_opt_ GUID *Provider, _In_opt_ PADDRINFOEXW Hints, _Outptr_ PADDRINFOEXW *Result, _In_opt_ PEPROCESS OwningProcess, _In_opt_ PETHREAD OwningThread, _Inout_ PIRP Irp Result)(Mem)) NTSTATUS(WSKAPI *PFN_WSK_GET_ADDRESS_INFO
Definition: wsk.h:426
IN PVCB IN ULONG IN OUT PULONG IN BOOLEAN OUT PLARGE_MCB Mcb
Definition: fatprocs.h:343
VOID FASTCALL KeReleaseGuardedMutex(IN OUT PKGUARDED_MUTEX GuardedMutex)
Definition: gmutex.c:53
_In_ LONGLONG Vbn
Definition: fsrtlfuncs.h:470
#define DPRINT
Definition: sndvol32.h:71

Referenced by FsRtlLargeMcbTest().

◆ FsRtlTruncateBaseMcb()

VOID NTAPI FsRtlTruncateBaseMcb ( IN PBASE_MCB  OpaqueMcb,
IN LONGLONG  Vbn 
)

Definition at line 1046 of file largemcb.c.

1048 {
1049  DPRINT("FsRtlTruncateBaseMcb(%p, %I64d)\n", OpaqueMcb, Vbn);
1050 
1051  FsRtlRemoveBaseMcbEntry(OpaqueMcb, Vbn, MAXLONG - Vbn + 1);
1052 }
#define MAXLONG
Definition: umtypes.h:116
BOOLEAN NTAPI FsRtlRemoveBaseMcbEntry(IN PBASE_MCB OpaqueMcb, IN LONGLONG Vbn, IN LONGLONG SectorCount)
Definition: largemcb.c:795
_In_ LONGLONG Vbn
Definition: fsrtlfuncs.h:470
#define DPRINT
Definition: sndvol32.h:71

Referenced by FsRtlTruncateLargeMcb().

◆ FsRtlTruncateLargeMcb()

VOID NTAPI FsRtlTruncateLargeMcb ( IN PLARGE_MCB  Mcb,
IN LONGLONG  Vbn 
)

Definition at line 1059 of file largemcb.c.

1061 {
1062  DPRINT("FsRtlTruncateLargeMcb(%p, %I64d)\n", Mcb, Vbn);
1063 
1064  KeAcquireGuardedMutex(Mcb->GuardedMutex);
1065  FsRtlTruncateBaseMcb(&(Mcb->BaseMcb), Vbn);
1066  KeReleaseGuardedMutex(Mcb->GuardedMutex);
1067 }
VOID FASTCALL KeAcquireGuardedMutex(IN PKGUARDED_MUTEX GuardedMutex)
Definition: gmutex.c:42
VOID NTAPI FsRtlTruncateBaseMcb(IN PBASE_MCB OpaqueMcb, IN LONGLONG Vbn)
Definition: largemcb.c:1046
IN PVCB IN ULONG IN OUT PULONG IN BOOLEAN OUT PLARGE_MCB Mcb
Definition: fatprocs.h:343
VOID FASTCALL KeReleaseGuardedMutex(IN OUT PKGUARDED_MUTEX GuardedMutex)
Definition: gmutex.c:53
_In_ LONGLONG Vbn
Definition: fsrtlfuncs.h:470
#define DPRINT
Definition: sndvol32.h:71

Referenced by Ext2ClearAllExtents(), FreeClusters(), FsRtlLargeMcbTest(), FsRtlLargeMcbTestsExt2(), and FsRtlTruncateMcb().

◆ FsRtlUninitializeBaseMcb()

VOID NTAPI FsRtlUninitializeBaseMcb ( IN PBASE_MCB  Mcb)

Definition at line 1074 of file largemcb.c.

1075 {
1076  DPRINT("FsRtlUninitializeBaseMcb(%p)\n", Mcb);
1077 
1079 
1080  if ((Mcb->PoolType == PagedPool)/* && (Mcb->MaximumPairCount == MAXIMUM_PAIR_COUNT)*/)
1081  {
1082  ExFreeToPagedLookasideList(&FsRtlFirstMappingLookasideList,
1083  Mcb->Mapping);
1084  }
1085  else
1086  {
1087  ExFreePoolWithTag(Mcb->Mapping, 'CBSF');
1088  }
1089 }
PAGED_LOOKASIDE_LIST FsRtlFirstMappingLookasideList
Definition: largemcb.c:22
VOID NTAPI FsRtlResetBaseMcb(IN PBASE_MCB OpaqueMcb)
Definition: largemcb.c:921
IN PVCB IN ULONG IN OUT PULONG IN BOOLEAN OUT PLARGE_MCB Mcb
Definition: fatprocs.h:343
#define DPRINT
Definition: sndvol32.h:71
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1099

Referenced by FsRtlUninitializeLargeMcb().

◆ FsRtlUninitializeLargeMcb()

VOID NTAPI FsRtlUninitializeLargeMcb ( IN PLARGE_MCB  Mcb)

Definition at line 1096 of file largemcb.c.

1097 {
1098  DPRINT("FsRtlUninitializeLargeMcb(%p)\n", Mcb);
1099 
1100  if (Mcb->GuardedMutex)
1101  {
1102  ExFreeToNPagedLookasideList(&FsRtlFastMutexLookasideList,
1103  Mcb->GuardedMutex);
1104  FsRtlUninitializeBaseMcb(&(Mcb->BaseMcb));
1105  }
1106 }
VOID NTAPI FsRtlUninitializeBaseMcb(IN PBASE_MCB Mcb)
Definition: largemcb.c:1074
NPAGED_LOOKASIDE_LIST FsRtlFastMutexLookasideList
Definition: largemcb.c:23
IN PVCB IN ULONG IN OUT PULONG IN BOOLEAN OUT PLARGE_MCB Mcb
Definition: fatprocs.h:343
#define DPRINT
Definition: sndvol32.h:71

Referenced by _Requires_lock_held_(), ConvertDataRunsToLargeMCB(), Ext2DestroyVcb(), Ext2FreeMcb(), Ext2InitializeVcb(), FatCreateDcb(), FatCreateFcb(), FatDeleteFcb(), FatDeleteVcb(), FsRtlLargeMcbTest(), FsRtlLargeMcbTestsExt2(), FsRtlLargeMcbTestsFastFat(), FsRtlLargeMcbTestsFastFat_2(), FsRtlLargeMcbTestsFastFat_3(), FsRtlUninitializeMcb(), and ReleaseAttributeContext().

◆ McbMappingAllocate()

static PVOID NTAPI McbMappingAllocate ( PRTL_GENERIC_TABLE  Table,
CLONG  Bytes 
)
static

Definition at line 54 of file largemcb.c.

55 {
56  PVOID Result;
57  PBASE_MCB Mcb = (PBASE_MCB)Table->TableContext;
58  Result = ExAllocatePoolWithTag(Mcb->PoolType, Bytes, 'BCML');
59  DPRINT("McbMappingAllocate(%lu) => %p\n", Bytes, Result);
60  return Result;
61 }
ASMGENDATA Table[]
Definition: genincdata.c:61
_In_ UINT Bytes
Definition: mmcopy.h:9
struct _BASE_MCB * PBASE_MCB
_At_(*)(_In_ PWSK_CLIENT Client, _In_opt_ PUNICODE_STRING NodeName, _In_opt_ PUNICODE_STRING ServiceName, _In_opt_ ULONG NameSpace, _In_opt_ GUID *Provider, _In_opt_ PADDRINFOEXW Hints, _Outptr_ PADDRINFOEXW *Result, _In_opt_ PEPROCESS OwningProcess, _In_opt_ PETHREAD OwningThread, _Inout_ PIRP Irp Result)(Mem)) NTSTATUS(WSKAPI *PFN_WSK_GET_ADDRESS_INFO
Definition: wsk.h:426
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
IN PVCB IN ULONG IN OUT PULONG IN BOOLEAN OUT PLARGE_MCB Mcb
Definition: fatprocs.h:343
#define DPRINT
Definition: sndvol32.h:71

Referenced by FsRtlInitializeBaseMcb().

◆ McbMappingCompare()

static RTL_GENERIC_COMPARE_RESULTS NTAPI McbMappingCompare ( PRTL_GENERIC_TABLE  Table,
PVOID  PtrA,
PVOID  PtrB 
)
static

Definition at line 72 of file largemcb.c.

75 {
76  PLARGE_MCB_MAPPING_ENTRY A = PtrA, B = PtrB;
78 
79  ASSERT(A);
80  ASSERT(B);
81 
82  if (A->RunStartVbn.QuadPart == B->RunStartVbn.QuadPart && A->RunEndVbn.QuadPart == B->RunEndVbn.QuadPart)
83  Res = GenericEqual;
84  else if (A->RunEndVbn.QuadPart <= B->RunStartVbn.QuadPart)
85  Res = GenericLessThan;
86  else if (A->RunEndVbn.QuadPart >= B->RunStartVbn.QuadPart)
87  Res = GenericGreaterThan;
88  else
89  {
90  ASSERT(FALSE);
91  Res = GenericEqual;
92  }
93 
94  return Res;
95 }
Definition: ehthrow.cxx:53
Definition: largemcb.c:26
Definition: ehthrow.cxx:92
#define FALSE
Definition: types.h:117
#define ASSERT(a)
Definition: mode.c:44
enum _RTL_GENERIC_COMPARE_RESULTS RTL_GENERIC_COMPARE_RESULTS

Referenced by FsRtlAddBaseMcbEntry(), FsRtlInitializeBaseMcb(), and FsRtlRemoveBaseMcbEntry().

◆ McbMappingFree()

static VOID NTAPI McbMappingFree ( PRTL_GENERIC_TABLE  Table,
PVOID  Buffer 
)
static

Definition at line 63 of file largemcb.c.

64 {
65  DPRINT("McbMappingFree(%p)\n", Buffer);
66  ExFreePoolWithTag(Buffer, 'BCML');
67 }
Definition: bufpool.h:45
#define DPRINT
Definition: sndvol32.h:71
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1099

Referenced by FsRtlInitializeBaseMcb().

◆ McbMappingIntersectCompare()

static RTL_GENERIC_COMPARE_RESULTS NTAPI McbMappingIntersectCompare ( PRTL_GENERIC_TABLE  Table,
PVOID  PtrA,
PVOID  PtrB 
)
static

Definition at line 97 of file largemcb.c.

98 {
99  PLARGE_MCB_MAPPING_ENTRY A = PtrA, B = PtrB;
101 
102  if (A->RunStartVbn.QuadPart <= B->RunStartVbn.QuadPart && A->RunEndVbn.QuadPart > B->RunStartVbn.QuadPart)
103  Res = GenericEqual;
104  else if (A->RunStartVbn.QuadPart >= B->RunStartVbn.QuadPart && B->RunEndVbn.QuadPart > A->RunStartVbn.QuadPart)
105  Res = GenericEqual;
106  else if (A->RunStartVbn.QuadPart < B->RunStartVbn.QuadPart)
107  Res = GenericLessThan;
108  else if (A->RunStartVbn.QuadPart > B->RunStartVbn.QuadPart)
109  Res = GenericGreaterThan;
110  else
111  Res = GenericEqual;
112 
113  return Res;
114 }
Definition: ehthrow.cxx:53
Definition: largemcb.c:26
Definition: ehthrow.cxx:92
enum _RTL_GENERIC_COMPARE_RESULTS RTL_GENERIC_COMPARE_RESULTS

Referenced by FsRtlAddBaseMcbEntry(), and FsRtlRemoveBaseMcbEntry().

Variable Documentation

◆ FsRtlFastMutexLookasideList

NPAGED_LOOKASIDE_LIST FsRtlFastMutexLookasideList

◆ FsRtlFirstMappingLookasideList

PAGED_LOOKASIDE_LIST FsRtlFirstMappingLookasideList