ReactOS  0.4.14-dev-583-g2a1ba2c
pinsup.c File Reference
#include <ntoskrnl.h>
#include "newcc.h"
#include "section/newmm.h"
#include <debug.h>
Include dependency graph for pinsup.c:

Go to the source code of this file.

Classes

struct  _WORK_QUEUE_WITH_CONTEXT
 

Macros

#define NDEBUG
 
#define TAG_MAP_SEC   TAG('C', 'c', 'S', 'x')
 
#define TAG_MAP_READ   TAG('M', 'c', 'p', 'y')
 
#define TAG_MAP_BCB   TAG('B', 'c', 'b', ' ')
 

Typedefs

typedef struct _WORK_QUEUE_WITH_CONTEXT WORK_QUEUE_WITH_CONTEXT
 
typedef struct _WORK_QUEUE_WITH_CONTEXTPWORK_QUEUE_WITH_CONTEXT
 

Functions

VOID _CcpLock (const char *file, int line)
 
VOID _CcpUnlock (const char *file, int line)
 
PDEVICE_OBJECT NTAPI MmGetDeviceObjectForFile (IN PFILE_OBJECT FileObject)
 
NTSTATUS CcpAllocateSection (PFILE_OBJECT FileObject, ULONG Length, ULONG Protect, PROS_SECTION_OBJECT *Result)
 
VOID CcpUnmapCache (PVOID Context)
 
VOID CcpDereferenceCache (ULONG Start, BOOLEAN Immediate)
 
ULONG CcpAllocateCacheSections (PFILE_OBJECT FileObject, PROS_SECTION_OBJECT SectionObject)
 
VOID CcpReferenceCache (ULONG Start)
 
VOID CcpMarkForExclusive (ULONG Start)
 
VOID CcpReferenceCacheExclusive (ULONG Start)
 
ULONG CcpFindMatchingMap (PLIST_ENTRY Head, PLARGE_INTEGER FileOffset, ULONG Length)
 
BOOLEAN NTAPI CcpMapData (IN PFILE_OBJECT FileObject, IN PLARGE_INTEGER FileOffset, IN ULONG Length, IN ULONG Flags, OUT PVOID *BcbResult, OUT PVOID *Buffer)
 
BOOLEAN NTAPI CcMapData (IN PFILE_OBJECT FileObject, IN PLARGE_INTEGER FileOffset, IN ULONG Length, IN ULONG Flags, OUT PVOID *BcbResult, OUT PVOID *Buffer)
 
BOOLEAN NTAPI CcpPinMappedData (IN PNOCC_CACHE_MAP Map, IN PLARGE_INTEGER FileOffset, IN ULONG Length, IN ULONG Flags, IN OUT PVOID *Bcb)
 
BOOLEAN NTAPI CcPinMappedData (IN PFILE_OBJECT FileObject, IN PLARGE_INTEGER FileOffset, IN ULONG Length, IN ULONG Flags, IN OUT PVOID *Bcb)
 
BOOLEAN NTAPI CcPinRead (IN PFILE_OBJECT FileObject, IN PLARGE_INTEGER FileOffset, IN ULONG Length, IN ULONG Flags, OUT PVOID *Bcb, OUT PVOID *Buffer)
 
BOOLEAN NTAPI CcPreparePinWrite (IN PFILE_OBJECT FileObject, IN PLARGE_INTEGER FileOffset, IN ULONG Length, IN BOOLEAN Zero, IN ULONG Flags, OUT PVOID *Bcb, OUT PVOID *Buffer)
 
BOOLEAN NTAPI CcpUnpinData (IN PNOCC_BCB RealBcb, BOOLEAN ReleaseBit)
 
VOID NTAPI CcUnpinData (IN PVOID Bcb)
 
VOID NTAPI CcSetBcbOwnerPointer (IN PVOID Bcb, IN PVOID OwnerPointer)
 
VOID NTAPI CcUnpinDataForThread (IN PVOID Bcb, IN ERESOURCE_THREAD ResourceThreadId)
 

Variables

NOCC_BCB CcCacheSections [CACHE_NUM_SECTIONS]
 
CHAR CcpBitmapBuffer [sizeof(RTL_BITMAP)+ROUND_UP((CACHE_NUM_SECTIONS), 32)/8]
 
PRTL_BITMAP CcCacheBitmap = (PRTL_BITMAP)&CcpBitmapBuffer
 
FAST_MUTEX CcMutex
 
KEVENT CcDeleteEvent
 
KEVENT CcFinalizeEvent
 
ULONG CcCacheClockHand
 
LONG CcOutstandingDeletes
 
PETHREAD LastThread
 

Macro Definition Documentation

◆ NDEBUG

#define NDEBUG

Definition at line 15 of file pinsup.c.

◆ TAG_MAP_BCB

#define TAG_MAP_BCB   TAG('B', 'c', 'b', ' ')

Definition at line 96 of file pinsup.c.

◆ TAG_MAP_READ

#define TAG_MAP_READ   TAG('M', 'c', 'p', 'y')

Definition at line 95 of file pinsup.c.

◆ TAG_MAP_SEC

#define TAG_MAP_SEC   TAG('C', 'c', 'S', 'x')

Definition at line 94 of file pinsup.c.

Typedef Documentation

◆ PWORK_QUEUE_WITH_CONTEXT

◆ WORK_QUEUE_WITH_CONTEXT

Function Documentation

◆ _CcpLock()

VOID _CcpLock ( const char file,
int  line 
)

Definition at line 112 of file pinsup.c.

114 {
115  //DPRINT("<<<---<<< CC In Mutex(%s:%d %x)!\n", file, line, PsGetCurrentThread());
117 }
FAST_MUTEX CcMutex
Definition: pinsup.c:101
VOID FASTCALL ExAcquireFastMutex(IN PFAST_MUTEX FastMutex)
Definition: fmutex.c:23

◆ _CcpUnlock()

VOID _CcpUnlock ( const char file,
int  line 
)

Definition at line 120 of file pinsup.c.

122 {
124  //DPRINT(">>>--->>> CC Exit Mutex!\n", file, line);
125 }
FAST_MUTEX CcMutex
Definition: pinsup.c:101
VOID FASTCALL ExReleaseFastMutex(IN PFAST_MUTEX FastMutex)
Definition: fmutex.c:31

◆ CcMapData()

BOOLEAN NTAPI CcMapData ( IN PFILE_OBJECT  FileObject,
IN PLARGE_INTEGER  FileOffset,
IN ULONG  Length,
IN ULONG  Flags,
OUT PVOID BcbResult,
OUT PVOID Buffer 
)

Definition at line 694 of file pinsup.c.

700 {
701  BOOLEAN Result;
702 
704  FileOffset,
705  Length,
706  Flags,
707  BcbResult,
708  Buffer);
709 
710  if (Result)
711  {
712  PNOCC_BCB Bcb = (PNOCC_BCB)*BcbResult;
713 
716 
717  ASSERT(Bcb->BaseAddress);
718  CcpLock();
720  CcpUnlock();
721  }
722 
723  return Result;
724 }
IN PVCB IN VBO IN ULONG OUT PBCB * Bcb
Definition: fatprocs.h:402
#define CcpLock()
Definition: newcc.h:143
#define CACHE_NUM_SECTIONS
Definition: newcc.h:130
Definition: newcc.h:3
_Must_inspect_result_ _In_ ULONG Flags
Definition: wsk.h:170
NOCC_BCB CcCacheSections[CACHE_NUM_SECTIONS]
Definition: pinsup.c:98
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
Definition: bufpool.h:45
_Inout_ PFILE_OBJECT FileObject
Definition: cdprocs.h:593
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
VOID CcpReferenceCache(ULONG Start)
Definition: pinsup.c:368
_In_ PFCB _In_ LONGLONG FileOffset
Definition: cdprocs.h:151
BOOLEAN NTAPI CcpMapData(IN PFILE_OBJECT FileObject, IN PLARGE_INTEGER FileOffset, IN ULONG Length, IN ULONG Flags, OUT PVOID *BcbResult, OUT PVOID *Buffer)
Definition: pinsup.c:465
struct _NOCC_BCB * PNOCC_BCB
#define CcpUnlock()
Definition: newcc.h:144

Referenced by CcpBuildCacheMdl(), CdLookupDirent(), CdLookupNextDirent(), CdMapPathTableBlock(), FAT12CountAvailableClusters(), FAT12GetNextCluster(), FAT16CountAvailableClusters(), FAT16GetNextCluster(), FAT32CountAvailableClusters(), FAT32GetNextCluster(), FATGetNextDirEntry(), FATIsDirectoryEmpty(), FatReadVolumeFile(), FATXGetNextDirEntry(), FATXIsDirectoryEmpty(), MapInAnotherThread(), PerformTest(), PinInAnotherThread(), PinInAnotherThreadExclusive(), and ReadVolumeLabel().

◆ CcpAllocateCacheSections()

ULONG CcpAllocateCacheSections ( PFILE_OBJECT  FileObject,
PROS_SECTION_OBJECT  SectionObject 
)

Definition at line 310 of file pinsup.c.

312 {
314  PNOCC_CACHE_MAP Map;
315  PNOCC_BCB Bcb;
316 
317  DPRINT("AllocateCacheSections: FileObject %x\n", FileObject);
318 
319  if (!FileObject->SectionObjectPointer)
320  return INVALID_CACHE;
321 
322  Map = (PNOCC_CACHE_MAP)FileObject->SectionObjectPointer->SharedCacheMap;
323 
324  if (!Map)
325  return INVALID_CACHE;
326 
327  DPRINT("Allocating Cache Section\n");
328 
331 
332  if (i != INVALID_CACHE)
333  {
334  DPRINT("Setting up Bcb #%x\n", i);
335 
336  Bcb = &CcCacheSections[i];
337 
338  ASSERT(Bcb->RefCount < 2);
339 
340  if (Bcb->RefCount > 0)
341  {
343  }
344 
345  ASSERT(!Bcb->RefCount);
346  Bcb->RefCount = 1;
347 
348  DPRINT("Bcb #%x RefCount %d\n", Bcb - CcCacheSections, Bcb->RefCount);
349 
350  if (!RtlTestBit(CcCacheBitmap, i))
351  {
352  DPRINT1("Somebody stoeled BCB #%x\n", i);
353  }
355 
356  DPRINT("Allocated #%x\n", i);
357  ASSERT(CcCacheSections[i].RefCount);
358  }
359  else
360  {
361  DPRINT1("Failed to allocate cache segment\n");
362  }
363  return i;
364 }
#define INVALID_CACHE
Definition: newcc.h:133
PRTL_BITMAP CcCacheBitmap
Definition: pinsup.c:100
ULONG CcCacheClockHand
Definition: pinsup.c:104
IN PVCB IN VBO IN ULONG OUT PBCB * Bcb
Definition: fatprocs.h:402
#define CACHE_NUM_SECTIONS
Definition: newcc.h:130
Definition: newcc.h:3
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
NOCC_BCB CcCacheSections[CACHE_NUM_SECTIONS]
Definition: pinsup.c:98
void DPRINT(...)
Definition: polytest.cpp:61
_Inout_ PFILE_OBJECT FileObject
Definition: cdprocs.h:593
if(!(yy_init))
Definition: macro.lex.yy.c:714
_Must_inspect_result_ NTSYSAPI BOOLEAN NTAPI RtlTestBit(_In_ PRTL_BITMAP BitMapHeader, _In_range_(<, BitMapHeader->SizeOfBitMap) ULONG BitNumber)
Definition: bitmap.c:434
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
NTSYSAPI ULONG WINAPI RtlFindClearBitsAndSet(PRTL_BITMAP, ULONG, ULONG)
#define DPRINT1
Definition: precomp.h:8
unsigned int ULONG
Definition: retypes.h:1
VOID CcpDereferenceCache(ULONG Start, BOOLEAN Immediate)
Definition: pinsup.c:213
struct _NOCC_CACHE_MAP * PNOCC_CACHE_MAP

Referenced by CcpMapData().

◆ CcpAllocateSection()

NTSTATUS CcpAllocateSection ( PFILE_OBJECT  FileObject,
ULONG  Length,
ULONG  Protect,
PROS_SECTION_OBJECT Result 
)

Definition at line 140 of file pinsup.c.

144 {
146  LARGE_INTEGER MaxSize;
147 
148  MaxSize.QuadPart = Length;
149 
150  DPRINT("Making Section for File %x\n", FileObject);
151  DPRINT("File name %wZ\n", &FileObject->FileName);
152 
155  NULL,
156  &MaxSize,
157  Protect,
159  NULL,
160  FileObject);
161 
162  return Status;
163 }
_In_ HANDLE _Outptr_result_bytebuffer_ ViewSize PVOID _In_ ULONG_PTR _In_ SIZE_T _Inout_opt_ PLARGE_INTEGER _Inout_ PSIZE_T _In_ SECTION_INHERIT _In_ ULONG _In_ ULONG Protect
Definition: zwfuncs.h:214
LONG NTSTATUS
Definition: precomp.h:26
#define SEC_CACHE
Definition: newmm.h:36
#define SEC_RESERVE
Definition: nt_native.h:1323
smooth NULL
Definition: ftsmooth.c:416
_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
void DPRINT(...)
Definition: polytest.cpp:61
_Inout_ PFILE_OBJECT FileObject
Definition: cdprocs.h:593
NTSTATUS NTAPI MmCreateSection(OUT PVOID *Section, IN ACCESS_MASK DesiredAccess, IN POBJECT_ATTRIBUTES ObjectAttributes OPTIONAL, IN PLARGE_INTEGER MaximumSize, IN ULONG SectionPageProtection, IN ULONG AllocationAttributes, IN HANDLE FileHandle OPTIONAL, IN PFILE_OBJECT FileObject OPTIONAL)
Definition: section.c:4975
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
Status
Definition: gdiplustypes.h:24
#define STANDARD_RIGHTS_REQUIRED
Definition: nt_native.h:63
LONGLONG QuadPart
Definition: typedefs.h:112

Referenced by CcpMapData().

◆ CcpDereferenceCache()

VOID CcpDereferenceCache ( ULONG  Start,
BOOLEAN  Immediate 
)

Definition at line 213 of file pinsup.c.

215 {
216  PVOID ToUnmap;
217  PNOCC_BCB Bcb;
218  BOOLEAN Dirty;
219  LARGE_INTEGER MappedSize;
220  LARGE_INTEGER BaseOffset;
221  PWORK_QUEUE_WITH_CONTEXT WorkItem;
222 
223  DPRINT("CcpDereferenceCache(#%x)\n", Start);
224 
226 
227  Dirty = Bcb->Dirty;
228  ToUnmap = Bcb->BaseAddress;
229  BaseOffset = Bcb->FileOffset;
230  MappedSize = Bcb->Map->FileSizes.ValidDataLength;
231 
232  DPRINT("Dereference #%x (count %d)\n", Start, Bcb->RefCount);
233  ASSERT(Bcb->SectionObject);
234  ASSERT(Bcb->RefCount == 1);
235 
236  DPRINT("Firing work item for %x\n", Bcb->BaseAddress);
237 
238  if (Dirty) {
239  CcpUnlock();
240  Bcb->RefCount++;
241  MiFlushMappedSection(ToUnmap, &BaseOffset, &MappedSize, Dirty);
242  Bcb->RefCount--;
243  CcpLock();
244  }
245 
246  if (Immediate)
247  {
248  PROS_SECTION_OBJECT ToDeref = Bcb->SectionObject;
249  Bcb->Map = NULL;
250  Bcb->SectionObject = NULL;
251  Bcb->BaseAddress = NULL;
252  Bcb->FileOffset.QuadPart = 0;
253  Bcb->Length = 0;
254  Bcb->RefCount = 0;
255  Bcb->Dirty = FALSE;
256  RemoveEntryList(&Bcb->ThisFileList);
257 
258  CcpUnlock();
260  ObDereferenceObject(ToDeref);
261  CcpLock();
262  }
263  else
264  {
265  WorkItem = ExAllocatePool(NonPagedPool, sizeof(*WorkItem));
266  if (!WorkItem) KeBugCheck(0);
267  WorkItem->ToUnmap = Bcb->BaseAddress;
268  WorkItem->FileOffset = Bcb->FileOffset;
269  WorkItem->Dirty = Bcb->Dirty;
270  WorkItem->MapSize = MappedSize;
271  WorkItem->ToDeref = Bcb->SectionObject;
272  WorkItem->AcquireForLazyWrite = Bcb->Map->Callbacks.AcquireForLazyWrite;
273  WorkItem->ReleaseFromLazyWrite = Bcb->Map->Callbacks.ReleaseFromLazyWrite;
274  WorkItem->LazyContext = Bcb->Map->LazyContext;
275 
276  ExInitializeWorkItem(&WorkItem->WorkItem,
278  WorkItem);
279 
280  Bcb->Map = NULL;
281  Bcb->SectionObject = NULL;
282  Bcb->BaseAddress = NULL;
283  Bcb->FileOffset.QuadPart = 0;
284  Bcb->Length = 0;
285  Bcb->RefCount = 0;
286  Bcb->Dirty = FALSE;
287  RemoveEntryList(&Bcb->ThisFileList);
288 
289  CcpUnlock();
291  CcpLock();
292  }
293  DPRINT("Done\n");
294 }
LARGE_INTEGER FileOffset
Definition: pinsup.c:169
VOID NTAPI ExQueueWorkItem(IN PWORK_QUEUE_ITEM WorkItem, IN WORK_QUEUE_TYPE QueueType)
Definition: work.c:717
IN PVCB IN VBO IN ULONG OUT PBCB * Bcb
Definition: fatprocs.h:402
#define CcpLock()
Definition: newcc.h:143
VOID NTAPI ObDereferenceObject(IN PVOID Object)
Definition: obref.c:375
Definition: newcc.h:3
FORCEINLINE BOOLEAN RemoveEntryList(_In_ PLIST_ENTRY Entry)
Definition: rtlfuncs.h:105
PACQUIRE_FOR_LAZY_WRITE AcquireForLazyWrite
Definition: pinsup.c:172
NOCC_BCB CcCacheSections[CACHE_NUM_SECTIONS]
Definition: pinsup.c:98
unsigned char BOOLEAN
smooth NULL
Definition: ftsmooth.c:416
LARGE_INTEGER MapSize
Definition: pinsup.c:170
VOID CcpUnmapCache(PVOID Context)
Definition: pinsup.c:187
void DPRINT(...)
Definition: polytest.cpp:61
VOID NTAPI KeBugCheck(ULONG BugCheckCode)
Definition: bug.c:1507
NTSTATUS NTAPI MmUnmapCacheViewInSystemSpace(IN PVOID MappedBase)
Definition: data.c:830
PRELEASE_FROM_LAZY_WRITE ReleaseFromLazyWrite
Definition: pinsup.c:173
#define ExInitializeWorkItem(Item, Routine, Context)
Definition: exfuncs.h:265
#define MiFlushMappedSection(A, O, S, D)
Definition: newmm.h:402
Definition: partlist.h:33
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#define ExAllocatePool(type, size)
Definition: fbtusb.h:44
WORK_QUEUE_ITEM WorkItem
Definition: pinsup.c:167
PROS_SECTION_OBJECT ToDeref
Definition: pinsup.c:171
#define CcpUnlock()
Definition: newcc.h:144
WORKER_THREAD_ROUTINE * PWORKER_THREAD_ROUTINE
Definition: extypes.h:200

Referenced by _CcpFlushCache(), CcpAllocateCacheSections(), and CcUninitializeCacheMap().

◆ CcpFindMatchingMap()

ULONG CcpFindMatchingMap ( PLIST_ENTRY  Head,
PLARGE_INTEGER  FileOffset,
ULONG  Length 
)

Definition at line 430 of file pinsup.c.

433 {
435  //DPRINT("Find Matching Map: (%x) %x:%x\n", FileOffset->LowPart, Length);
436  for (Entry = Head->Flink; Entry != Head; Entry = Entry->Flink)
437  {
438  //DPRINT("Link @%x\n", Entry);
439  PNOCC_BCB Bcb = CONTAINING_RECORD(Entry, NOCC_BCB, ThisFileList);
440  //DPRINT("Selected BCB %x #%x\n", Bcb, Bcb - CcCacheSections);
441  //DPRINT("This File: %x:%x\n", Bcb->FileOffset.LowPart, Bcb->Length);
442  if (FileOffset->QuadPart >= Bcb->FileOffset.QuadPart &&
443  FileOffset->QuadPart < Bcb->FileOffset.QuadPart + CACHE_STRIPE)
444  {
445  //DPRINT("Found match at #%x\n", Bcb - CcCacheSections);
446  return Bcb - CcCacheSections;
447  }
448  }
449 
450  //DPRINT("This region isn't mapped\n");
451 
452  return INVALID_CACHE;
453 }
#define INVALID_CACHE
Definition: newcc.h:133
IN PVCB IN VBO IN ULONG OUT PBCB * Bcb
Definition: fatprocs.h:402
struct _Entry Entry
Definition: kefuncs.h:640
Definition: newcc.h:3
NOCC_BCB CcCacheSections[CACHE_NUM_SECTIONS]
Definition: pinsup.c:98
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
#define CACHE_STRIPE
Definition: newcc.h:128
struct _LIST_ENTRY * Flink
Definition: typedefs.h:119
Definition: typedefs.h:117
_In_ PFCB _In_ LONGLONG FileOffset
Definition: cdprocs.h:151
base of all file and directory entries
Definition: entries.h:82

Referenced by CcpMapData(), and CcpPinMappedData().

◆ CcPinMappedData()

BOOLEAN NTAPI CcPinMappedData ( IN PFILE_OBJECT  FileObject,
IN PLARGE_INTEGER  FileOffset,
IN ULONG  Length,
IN ULONG  Flags,
IN OUT PVOID Bcb 
)

Definition at line 774 of file pinsup.c.

779 {
780  PVOID Buffer;
781  PNOCC_CACHE_MAP Map = (PNOCC_CACHE_MAP)FileObject->SectionObjectPointer->SharedCacheMap;
782 
783  if (!Map)
784  {
785  DPRINT1("Not cached\n");
786  return FALSE;
787  }
788 
790  {
791  return CcpPinMappedData(Map, FileOffset, Length, Flags, Bcb);
792  }
793  else
794  {
795  DPRINT1("could not map\n");
796  return FALSE;
797  }
798 }
IN PVCB IN VBO IN ULONG OUT PBCB * Bcb
Definition: fatprocs.h:402
_Must_inspect_result_ _In_ ULONG Flags
Definition: wsk.h:170
Definition: bufpool.h:45
_Inout_ PFILE_OBJECT FileObject
Definition: cdprocs.h:593
if(!(yy_init))
Definition: macro.lex.yy.c:714
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
_In_ PFCB _In_ LONGLONG FileOffset
Definition: cdprocs.h:151
BOOLEAN NTAPI CcpMapData(IN PFILE_OBJECT FileObject, IN PLARGE_INTEGER FileOffset, IN ULONG Length, IN ULONG Flags, OUT PVOID *BcbResult, OUT PVOID *Buffer)
Definition: pinsup.c:465
#define DPRINT1
Definition: precomp.h:8
IN BOOLEAN OUT PSTR Buffer
Definition: progress.h:34
BOOLEAN NTAPI CcpPinMappedData(IN PNOCC_CACHE_MAP Map, IN PLARGE_INTEGER FileOffset, IN ULONG Length, IN ULONG Flags, IN OUT PVOID *Bcb)
Definition: pinsup.c:730
struct _NOCC_CACHE_MAP * PNOCC_CACHE_MAP

Referenced by CcPinRead(), FatPinMappedData(), PerformTest(), PinInAnotherThread(), and PinInAnotherThreadExclusive().

◆ CcPinRead()

BOOLEAN NTAPI CcPinRead ( IN PFILE_OBJECT  FileObject,
IN PLARGE_INTEGER  FileOffset,
IN ULONG  Length,
IN ULONG  Flags,
OUT PVOID Bcb,
OUT PVOID Buffer 
)

Definition at line 802 of file pinsup.c.

808 {
809  PNOCC_BCB RealBcb;
810  BOOLEAN Result;
811 
813 
814  if (Result)
815  {
816  CcpLock();
817  RealBcb = *Bcb;
818  *Buffer = ((PCHAR)RealBcb->BaseAddress) + (int)(FileOffset->QuadPart - RealBcb->FileOffset.QuadPart);
819  CcpUnlock();
820  }
821 
822  return Result;
823 }
IN PVCB IN VBO IN ULONG OUT PBCB * Bcb
Definition: fatprocs.h:402
#define CcpLock()
Definition: newcc.h:143
PVOID BaseAddress
Definition: newcc.h:12
Definition: newcc.h:3
_Must_inspect_result_ _In_ ULONG Flags
Definition: wsk.h:170
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
Definition: bufpool.h:45
_Inout_ PFILE_OBJECT FileObject
Definition: cdprocs.h:593
#define PCHAR
Definition: match.c:90
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
LARGE_INTEGER FileOffset
Definition: newcc.h:10
_In_ PFCB _In_ LONGLONG FileOffset
Definition: cdprocs.h:151
#define CcpUnlock()
Definition: newcc.h:144
BOOLEAN NTAPI CcPinMappedData(IN PFILE_OBJECT FileObject, IN PLARGE_INTEGER FileOffset, IN ULONG Length, IN ULONG Flags, IN OUT PVOID *Bcb)
Definition: pinsup.c:774
LONGLONG QuadPart
Definition: typedefs.h:112
unsigned int(__cdecl typeof(jpeg_read_scanlines))(struct jpeg_decompress_struct *
Definition: typeof.h:31

Referenced by _Requires_lock_held_(), CcCopyRead(), CcPreparePinWrite(), Ext2ExpandBlock(), Ext2FreeBlock(), Ext2GetBlock(), Ext2TruncateBlock(), FAT12FindAndMarkAvailableCluster(), FAT12WriteCluster(), FAT16FindAndMarkAvailableCluster(), FAT16GetDirtyStatus(), FAT16SetDirtyStatus(), FAT16WriteCluster(), FAT32FindAndMarkAvailableCluster(), FAT32GetDirtyStatus(), FAT32SetDirtyStatus(), FAT32UpdateFreeClustersCount(), FAT32WriteCluster(), FATAddEntry(), FATDelEntry(), FatFlushFat(), FatPinEaRange(), FATXAddEntry(), FATXDelEntry(), FFSCheckSetBlock(), FFSFreeBlock(), FFSFreeInode(), FFSNewBlock(), FFSNewInode(), FFSSaveBuffer(), FFSTruncateBlock(), FsdSetFsLabelInformation(), get_block_bh_mdl(), get_block_bh_pin(), MapInAnotherThread(), PerformTest(), PinInAnotherThread(), PinInAnotherThreadExclusive(), RfsdCheckSetBlock(), vfatFindDirSpace(), vfatRenameEntry(), and VfatUpdateEntry().

◆ CcpMapData()

BOOLEAN NTAPI CcpMapData ( IN PFILE_OBJECT  FileObject,
IN PLARGE_INTEGER  FileOffset,
IN ULONG  Length,
IN ULONG  Flags,
OUT PVOID BcbResult,
OUT PVOID Buffer 
)

Definition at line 465 of file pinsup.c.

471 {
472  BOOLEAN Success = FALSE, FaultIn = FALSE;
473  /* Note: windows 2000 drivers treat this as a bool */
474  //BOOLEAN Wait = (Flags & MAP_WAIT) || (Flags == TRUE);
475  LARGE_INTEGER Target, EndInterval;
476  ULONG BcbHead, SectionSize, ViewSize;
477  PNOCC_BCB Bcb = NULL;
480  PNOCC_CACHE_MAP Map = (PNOCC_CACHE_MAP)FileObject->SectionObjectPointer->SharedCacheMap;
482 
483  if (!Map)
484  {
485  DPRINT1("File object was not mapped\n");
486  return FALSE;
487  }
488 
489  DPRINT("CcMapData(F->%x, %I64x:%d)\n",
490  FileObject,
491  FileOffset->QuadPart,
492  Length);
493 
495 
496  Target.HighPart = FileOffset->HighPart;
497  Target.LowPart = CACHE_ROUND_DOWN(FileOffset->LowPart);
498 
499  CcpLock();
500 
501  /* Find out if any range is a superset of what we want */
502  /* Find an accomodating section */
504 
505  if (BcbHead != INVALID_CACHE)
506  {
507  Bcb = &CcCacheSections[BcbHead];
508  Success = TRUE;
509  *BcbResult = Bcb;
510  *Buffer = ((PCHAR)Bcb->BaseAddress) + (int)(FileOffset->QuadPart - Bcb->FileOffset.QuadPart);
511 
512  DPRINT("Bcb #%x Buffer maps (%I64x) At %x Length %x (Getting %p:%x) %wZ\n",
514  Bcb->FileOffset.QuadPart,
515  Bcb->BaseAddress,
516  Bcb->Length,
517  *Buffer,
518  Length,
519  &FileObject->FileName);
520 
521  DPRINT("w1n\n");
522  goto cleanup;
523  }
524 
525  DPRINT("File size %I64x\n",
527 
528  /* Not all files have length, in fact filesystems often use stream file
529  objects for various internal purposes and are loose about the file
530  length, since the filesystem promises itself to write the right number
531  of bytes to the internal stream. In these cases, we just allow the file
532  to have the full stripe worth of space. */
534  {
535  SectionSize = min(CACHE_STRIPE,
536  Map->FileSizes.ValidDataLength.QuadPart - Target.QuadPart);
537  }
538  else
539  {
540  SectionSize = CACHE_STRIPE;
541  }
542 
543  DPRINT("Allocating a cache stripe at %x:%d\n",
544  Target.LowPart, SectionSize);
545 
546  //ASSERT(SectionSize <= CACHE_STRIPE);
547 
548  CcpUnlock();
549  /* CcpAllocateSection doesn't need the lock, so we'll give other action
550  a chance in here. */
552  SectionSize,
553 #ifdef PIN_WRITE_ONLY
555 #else
557 #endif
558  &SectionObject);
559  CcpLock();
560 
561  if (!NT_SUCCESS(Status))
562  {
563  *BcbResult = NULL;
564  *Buffer = NULL;
565  DPRINT1("End %08x\n", Status);
566  goto cleanup;
567  }
568 
569 retry:
570  /* Returns a reference */
571  DPRINT("Allocating cache sections: %wZ\n", &FileObject->FileName);
573  /* XXX todo: we should handle the immediate fail case here, but don't */
574  if (BcbHead == INVALID_CACHE)
575  {
576  ULONG i;
577  DbgPrint("Cache Map:");
578  for (i = 0; i < CACHE_NUM_SECTIONS; i++)
579  {
580  if (!(i % 64)) DbgPrint("\n");
581  DbgPrint("%c",
582  CcCacheSections[i].RefCount + (RtlTestBit(CcCacheBitmap, i) ? '@' : '`'));
583  }
584  DbgPrint("\n");
585 
587  Executive,
588  KernelMode,
589  FALSE,
590  NULL);
591 
592  goto retry;
593  }
594 
595  DPRINT("BcbHead #%x (final)\n", BcbHead);
596 
597  if (BcbHead == INVALID_CACHE)
598  {
599  *BcbResult = NULL;
600  *Buffer = NULL;
601  DPRINT1("End\n");
602  goto cleanup;
603  }
604 
605  DPRINT("Selected BCB #%x\n", BcbHead);
607 
608  Bcb = &CcCacheSections[BcbHead];
609  /* MmMapCacheViewInSystemSpaceAtOffset is one of three methods of Mm
610  that are specific to NewCC. In this case, it's implementation
611  exactly mirrors MmMapViewInSystemSpace, but allows an offset to
612  be specified. */
614  &Bcb->BaseAddress,
615  &Target,
616  &ViewSize);
617 
618  /* Summary: Failure. Dereference our section and tell the user we failed */
619  if (!NT_SUCCESS(Status))
620  {
621  *BcbResult = NULL;
622  *Buffer = NULL;
624  RemoveEntryList(&Bcb->ThisFileList);
625  RtlZeroMemory(Bcb, sizeof(*Bcb));
626  RtlClearBit(CcCacheBitmap, BcbHead);
627  DPRINT1("Failed to map\n");
628  goto cleanup;
629  }
630 
631  /* Summary: Success. Put together a valid Bcb and link it with the others
632  * in the NOCC_CACHE_MAP.
633  */
634  Success = TRUE;
635 
636  Bcb->Length = MIN(Map->FileSizes.ValidDataLength.QuadPart - Target.QuadPart,
637  CACHE_STRIPE);
638 
639  Bcb->SectionObject = SectionObject;
640  Bcb->Map = Map;
641  Bcb->FileOffset = Target;
642  InsertTailList(&Map->AssociatedBcb, &Bcb->ThisFileList);
643 
644  *BcbResult = &CcCacheSections[BcbHead];
645  *Buffer = ((PCHAR)Bcb->BaseAddress) + (int)(FileOffset->QuadPart - Bcb->FileOffset.QuadPart);
646  FaultIn = TRUE;
647 
648  DPRINT("Bcb #%x Buffer maps (%I64x) At %x Length %x (Getting %p:%lx) %wZ\n",
650  Bcb->FileOffset.QuadPart,
651  Bcb->BaseAddress,
652  Bcb->Length,
653  *Buffer,
654  Length,
655  &FileObject->FileName);
656 
657  EndInterval.QuadPart = Bcb->FileOffset.QuadPart + Bcb->Length - 1;
658  ASSERT((EndInterval.QuadPart & ~(CACHE_STRIPE - 1)) ==
659  (Bcb->FileOffset.QuadPart & ~(CACHE_STRIPE - 1)));
660 
661 cleanup:
662  CcpUnlock();
663  if (Success)
664  {
665  if (FaultIn)
666  {
667  /* Fault in the pages. This forces reads to happen now. */
668  ULONG i;
669  PCHAR FaultIn = Bcb->BaseAddress;
670 
671  DPRINT("Faulting in pages at this point: file %wZ %I64x:%x\n",
672  &FileObject->FileName,
673  Bcb->FileOffset.QuadPart,
674  Bcb->Length);
675 
676  for (i = 0; i < Bcb->Length; i += PAGE_SIZE)
677  {
678  FaultIn[i] ^= 0;
679  }
680  }
683  }
684  else
685  {
686  ASSERT(FALSE);
687  }
688 
689  return Success;
690 }
_Must_inspect_result_ _Outptr_ PVOID * SectionObject
Definition: fsrtlfuncs.h:860
NTSTATUS CcpAllocateSection(PFILE_OBJECT FileObject, ULONG Length, ULONG Protect, PROS_SECTION_OBJECT *Result)
Definition: pinsup.c:140
#define KeGetCurrentIrql()
Definition: env_spec_w32.h:706
#define INVALID_CACHE
Definition: newcc.h:133
signed char * PCHAR
Definition: retypes.h:7
PRTL_BITMAP CcCacheBitmap
Definition: pinsup.c:100
KEVENT CcDeleteEvent
Definition: pinsup.c:102
#define TRUE
Definition: types.h:120
IN PVCB IN VBO IN ULONG OUT PBCB * Bcb
Definition: fatprocs.h:402
#define CcpLock()
Definition: newcc.h:143
#define DbgPrint
Definition: loader.c:25
NTSTATUS NTAPI MmMapCacheViewInSystemSpaceAtOffset(IN PMM_SECTION_SEGMENT Segment, OUT PVOID *MappedBase, PLARGE_INTEGER FileOffset, IN OUT PULONG ViewSize)
Definition: data.c:796
#define CACHE_NUM_SECTIONS
Definition: newcc.h:130
LONG NTSTATUS
Definition: precomp.h:26
VOID NTAPI ObDereferenceObject(IN PVOID Object)
Definition: obref.c:375
#define InsertTailList(ListHead, Entry)
Definition: newcc.h:3
NTSTATUS NTAPI KeWaitForSingleObject(IN PVOID Object, IN KWAIT_REASON WaitReason, IN KPROCESSOR_MODE WaitMode, IN BOOLEAN Alertable, IN PLARGE_INTEGER Timeout OPTIONAL)
Definition: wait.c:416
#define CACHE_ROUND_DOWN(x)
Definition: newcc.h:132
T MIN(T a, T b)
Definition: polytest.cpp:79
FORCEINLINE BOOLEAN RemoveEntryList(_In_ PLIST_ENTRY Entry)
Definition: rtlfuncs.h:105
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
NOCC_BCB CcCacheSections[CACHE_NUM_SECTIONS]
Definition: pinsup.c:98
unsigned char BOOLEAN
smooth NULL
Definition: ftsmooth.c:416
void DPRINT(...)
Definition: polytest.cpp:61
Definition: bufpool.h:45
LIST_ENTRY AssociatedBcb
Definition: newcc.h:29
_Inout_ PFILE_OBJECT FileObject
Definition: cdprocs.h:593
#define PCHAR
Definition: match.c:90
#define CACHE_STRIPE
Definition: newcc.h:128
ULONG CcpAllocateCacheSections(PFILE_OBJECT FileObject, PROS_SECTION_OBJECT SectionObject)
Definition: pinsup.c:310
if(!(yy_init))
Definition: macro.lex.yy.c:714
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
VOID NTAPI RtlClearBit(_In_ PRTL_BITMAP BitMapHeader, _In_ BITMAP_INDEX BitNumber)
Definition: bitmap.c:294
_Must_inspect_result_ NTSYSAPI BOOLEAN NTAPI RtlTestBit(_In_ PRTL_BITMAP BitMapHeader, _In_range_(<, BitMapHeader->SizeOfBitMap) ULONG BitNumber)
Definition: bitmap.c:434
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
_Must_inspect_result_ typedef _In_ ULONG _In_ BOOLEAN Target
Definition: iotypes.h:1068
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
LARGE_INTEGER ValidDataLength
Definition: cctypes.h:17
#define PAGE_SIZE
Definition: env_spec_w32.h:49
Status
Definition: gdiplustypes.h:24
#define DISPATCH_LEVEL
Definition: env_spec_w32.h:696
CC_FILE_SIZES FileSizes
Definition: newcc.h:33
_In_ PFCB _In_ LONGLONG FileOffset
Definition: cdprocs.h:151
#define min(a, b)
Definition: monoChain.cc:55
#define PAGE_READONLY
Definition: compat.h:127
ULONG CcpFindMatchingMap(PLIST_ENTRY Head, PLARGE_INTEGER FileOffset, ULONG Length)
Definition: pinsup.c:430
#define DPRINT1
Definition: precomp.h:8
_In_ HANDLE _Outptr_result_bytebuffer_ ViewSize PVOID _In_ ULONG_PTR _In_ SIZE_T _Inout_opt_ PLARGE_INTEGER _Inout_ PSIZE_T ViewSize
Definition: mmfuncs.h:404
unsigned int ULONG
Definition: retypes.h:1
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:261
char * cleanup(char *str)
Definition: wpickclick.c:99
#define CcpUnlock()
Definition: newcc.h:144
LONGLONG QuadPart
Definition: typedefs.h:112
struct _NOCC_CACHE_MAP * PNOCC_CACHE_MAP
#define PAGE_READWRITE
Definition: nt_native.h:1304
unsigned int(__cdecl typeof(jpeg_read_scanlines))(struct jpeg_decompress_struct *
Definition: typeof.h:31

Referenced by CcMapData(), and CcPinMappedData().

◆ CcpMarkForExclusive()

VOID CcpMarkForExclusive ( ULONG  Start)

Definition at line 379 of file pinsup.c.

380 {
381  PNOCC_BCB Bcb;
383  Bcb->ExclusiveWaiter++;
384 }
IN PVCB IN VBO IN ULONG OUT PBCB * Bcb
Definition: fatprocs.h:402
Definition: newcc.h:3
NOCC_BCB CcCacheSections[CACHE_NUM_SECTIONS]
Definition: pinsup.c:98
Definition: partlist.h:33

Referenced by CcpPinMappedData().

◆ CcpPinMappedData()

BOOLEAN NTAPI CcpPinMappedData ( IN PNOCC_CACHE_MAP  Map,
IN PLARGE_INTEGER  FileOffset,
IN ULONG  Length,
IN ULONG  Flags,
IN OUT PVOID Bcb 
)

Definition at line 730 of file pinsup.c.

735 {
736  BOOLEAN Exclusive = Flags & PIN_EXCLUSIVE;
737  ULONG BcbHead;
738  PNOCC_BCB TheBcb;
739 
740  CcpLock();
741 
742  ASSERT(Map->AssociatedBcb.Flink == &Map->AssociatedBcb || (CONTAINING_RECORD(Map->AssociatedBcb.Flink, NOCC_BCB, ThisFileList) >= CcCacheSections && CONTAINING_RECORD(Map->AssociatedBcb.Flink, NOCC_BCB, ThisFileList) < CcCacheSections + CACHE_NUM_SECTIONS));
743  BcbHead = CcpFindMatchingMap(&Map->AssociatedBcb, FileOffset, Length);
744  if (BcbHead == INVALID_CACHE)
745  {
746  CcpUnlock();
747  return FALSE;
748  }
749 
750  TheBcb = &CcCacheSections[BcbHead];
751 
752  if (Exclusive)
753  {
754  DPRINT("Requesting #%x Exclusive\n", BcbHead);
755  CcpMarkForExclusive(BcbHead);
756  }
757  else
758  {
759  DPRINT("Reference #%x\n", BcbHead);
760  CcpReferenceCache(BcbHead);
761  }
762 
763  if (Exclusive)
765 
766  CcpUnlock();
767 
768  *Bcb = TheBcb;
769  return TRUE;
770 }
#define INVALID_CACHE
Definition: newcc.h:133
#define TRUE
Definition: types.h:120
IN PVCB IN VBO IN ULONG OUT PBCB * Bcb
Definition: fatprocs.h:402
#define CcpLock()
Definition: newcc.h:143
#define CACHE_NUM_SECTIONS
Definition: newcc.h:130
VOID CcpMarkForExclusive(ULONG Start)
Definition: pinsup.c:379
Definition: newcc.h:3
_Must_inspect_result_ _In_ ULONG Flags
Definition: wsk.h:170
NOCC_BCB CcCacheSections[CACHE_NUM_SECTIONS]
Definition: pinsup.c:98
unsigned char BOOLEAN
void DPRINT(...)
Definition: polytest.cpp:61
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
VOID CcpReferenceCache(ULONG Start)
Definition: pinsup.c:368
VOID CcpReferenceCacheExclusive(ULONG Start)
Definition: pinsup.c:396
_In_ PFCB _In_ LONGLONG FileOffset
Definition: cdprocs.h:151
ULONG CcpFindMatchingMap(PLIST_ENTRY Head, PLARGE_INTEGER FileOffset, ULONG Length)
Definition: pinsup.c:430
#define PIN_EXCLUSIVE
unsigned int ULONG
Definition: retypes.h:1
#define CcpUnlock()
Definition: newcc.h:144

Referenced by CcPinMappedData().

◆ CcpReferenceCache()

VOID CcpReferenceCache ( ULONG  Start)

Definition at line 368 of file pinsup.c.

369 {
370  PNOCC_BCB Bcb;
372  ASSERT(Bcb->SectionObject);
373  Bcb->RefCount++;
375 
376 }
PRTL_BITMAP CcCacheBitmap
Definition: pinsup.c:100
IN PVCB IN VBO IN ULONG OUT PBCB * Bcb
Definition: fatprocs.h:402
NTSYSAPI VOID NTAPI RtlSetBit(_In_ PRTL_BITMAP BitMapHeader, _In_range_(<, BitMapHeader->SizeOfBitMap) ULONG BitNumber)
Definition: bitmap.c:304
Definition: newcc.h:3
NOCC_BCB CcCacheSections[CACHE_NUM_SECTIONS]
Definition: pinsup.c:98
Definition: partlist.h:33
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)

Referenced by _CcpFlushCache(), CcMapData(), CcpPinMappedData(), CcRemapBcb(), CcRepinBcb(), CcSetBcbOwnerPointer(), and CcZeroData().

◆ CcpReferenceCacheExclusive()

VOID CcpReferenceCacheExclusive ( ULONG  Start)

Definition at line 396 of file pinsup.c.

397 {
399 
400  KeWaitForSingleObject(&Bcb->ExclusiveWait,
401  Executive,
402  KernelMode,
403  FALSE,
404  NULL);
405 
406  CcpLock();
407  ASSERT(Bcb->ExclusiveWaiter);
408  ASSERT(Bcb->SectionObject);
409  Bcb->Exclusive = TRUE;
410  Bcb->ExclusiveWaiter--;
412  CcpUnlock();
413 }
PRTL_BITMAP CcCacheBitmap
Definition: pinsup.c:100
#define TRUE
Definition: types.h:120
IN PVCB IN VBO IN ULONG OUT PBCB * Bcb
Definition: fatprocs.h:402
#define CcpLock()
Definition: newcc.h:143
NTSYSAPI VOID NTAPI RtlSetBit(_In_ PRTL_BITMAP BitMapHeader, _In_range_(<, BitMapHeader->SizeOfBitMap) ULONG BitNumber)
Definition: bitmap.c:304
Definition: newcc.h:3
NTSTATUS NTAPI KeWaitForSingleObject(IN PVOID Object, IN KWAIT_REASON WaitReason, IN KPROCESSOR_MODE WaitMode, IN BOOLEAN Alertable, IN PLARGE_INTEGER Timeout OPTIONAL)
Definition: wait.c:416
NOCC_BCB CcCacheSections[CACHE_NUM_SECTIONS]
Definition: pinsup.c:98
smooth NULL
Definition: ftsmooth.c:416
Definition: partlist.h:33
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#define CcpUnlock()
Definition: newcc.h:144

Referenced by CcpPinMappedData().

◆ CcPreparePinWrite()

BOOLEAN NTAPI CcPreparePinWrite ( IN PFILE_OBJECT  FileObject,
IN PLARGE_INTEGER  FileOffset,
IN ULONG  Length,
IN BOOLEAN  Zero,
IN ULONG  Flags,
OUT PVOID Bcb,
OUT PVOID Buffer 
)

Definition at line 827 of file pinsup.c.

834 {
835  BOOLEAN Result;
836  PNOCC_BCB RealBcb;
837 #ifdef PIN_WRITE_ONLY
840  ULONG OldProtect;
841 #endif
842 
843  DPRINT("CcPreparePinWrite(%x:%x)\n", Buffer, Length);
844 
846 
847  if (Result)
848  {
849  CcpLock();
850  RealBcb = *Bcb;
851 
852 #ifdef PIN_WRITE_ONLY
853  BaseAddress = RealBcb->BaseAddress;
854  NumberOfBytes = RealBcb->Length;
855 
857  &BaseAddress,
858  &NumberOfBytes,
860  &OldProtect);
861 #endif
862 
863  CcpUnlock();
864  RealBcb->Dirty = TRUE;
865 
866  if (Zero)
867  {
868  DPRINT("Zero fill #%x %I64x:%x Buffer %x %wZ\n",
869  RealBcb - CcCacheSections,
870  FileOffset->QuadPart,
871  Length,
872  *Buffer,
873  &FileObject->FileName);
874 
875  DPRINT1("RtlZeroMemory(%p, %lx)\n", *Buffer, Length);
877  }
878  }
879 
880  return Result;
881 }
#define TRUE
Definition: types.h:120
IN PVCB IN VBO IN ULONG OUT PBCB * Bcb
Definition: fatprocs.h:402
#define CcpLock()
Definition: newcc.h:143
ULONG Length
Definition: newcc.h:11
NTSTATUS NTAPI MiProtectVirtualMemory(IN PEPROCESS Process, IN OUT PVOID *BaseAddress, IN OUT PSIZE_T NumberOfBytesToProtect, IN ULONG NewAccessProtection, OUT PULONG OldAccessProtection OPTIONAL)
Definition: virtual.c:2092
PVOID BaseAddress
Definition: newcc.h:12
Definition: newcc.h:3
_Must_inspect_result_ _In_ ULONG Flags
Definition: wsk.h:170
BOOLEAN Dirty
Definition: newcc.h:13
NOCC_BCB CcCacheSections[CACHE_NUM_SECTIONS]
Definition: pinsup.c:98
unsigned char BOOLEAN
smooth NULL
Definition: ftsmooth.c:416
_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
void DPRINT(...)
Definition: polytest.cpp:61
Definition: bufpool.h:45
_Inout_ PFILE_OBJECT FileObject
Definition: cdprocs.h:593
_In_ HANDLE _Outptr_result_bytebuffer_ ViewSize PVOID * BaseAddress
Definition: mmfuncs.h:404
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
BOOLEAN NTAPI CcPinRead(IN PFILE_OBJECT FileObject, IN PLARGE_INTEGER FileOffset, IN ULONG Length, IN ULONG Flags, OUT PVOID *Bcb, OUT PVOID *Buffer)
Definition: pinsup.c:802
ULONG_PTR SIZE_T
Definition: typedefs.h:78
_In_ PFCB _In_ LONGLONG FileOffset
Definition: cdprocs.h:151
IN PVCB IN VBO IN ULONG OUT PBCB OUT PVOID IN BOOLEAN IN BOOLEAN Zero
Definition: fatprocs.h:402
#define DPRINT1
Definition: precomp.h:8
_Must_inspect_result_ typedef _In_ PHYSICAL_ADDRESS _Inout_ PLARGE_INTEGER NumberOfBytes
Definition: iotypes.h:998
unsigned int ULONG
Definition: retypes.h:1
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:261
#define CcpUnlock()
Definition: newcc.h:144
#define PAGE_READWRITE
Definition: nt_native.h:1304

Referenced by CcCopyWrite(), CcZeroData(), get_block_bh_mdl(), get_block_bh_pin(), and submit_bh_mdl().

◆ CcpUnmapCache()

VOID CcpUnmapCache ( PVOID  Context)

Definition at line 187 of file pinsup.c.

188 {
190  DPRINT("Unmapping (finally) %x\n", WorkItem->ToUnmap);
192  ObDereferenceObject(WorkItem->ToDeref);
193  ExFreePool(WorkItem);
194  DPRINT("Done\n");
195 }
VOID NTAPI ObDereferenceObject(IN PVOID Object)
Definition: obref.c:375
void DPRINT(...)
Definition: polytest.cpp:61
NTSTATUS NTAPI MmUnmapCacheViewInSystemSpace(IN PVOID MappedBase)
Definition: data.c:830
struct _WORK_QUEUE_WITH_CONTEXT * PWORK_QUEUE_WITH_CONTEXT
PROS_SECTION_OBJECT ToDeref
Definition: pinsup.c:171
#define ExFreePool(addr)
Definition: env_spec_w32.h:352

Referenced by CcpDereferenceCache().

◆ CcpUnpinData()

BOOLEAN NTAPI CcpUnpinData ( IN PNOCC_BCB  RealBcb,
BOOLEAN  ReleaseBit 
)

Definition at line 911 of file pinsup.c.

912 {
913  if (RealBcb->RefCount <= 2)
914  {
915  RealBcb->Exclusive = FALSE;
916  if (RealBcb->ExclusiveWaiter)
917  {
918  DPRINT("Triggering exclusive waiter\n");
919  KeSetEvent(&RealBcb->ExclusiveWait, IO_NO_INCREMENT, FALSE);
920  return TRUE;
921  }
922  }
923  if (RealBcb->RefCount == 2 && !ReleaseBit)
924  return FALSE;
925  if (RealBcb->RefCount > 1)
926  {
927  DPRINT("Removing one reference #%x\n", RealBcb - CcCacheSections);
928  RealBcb->RefCount--;
930  }
931  if (RealBcb->RefCount == 1)
932  {
933  DPRINT("Clearing allocation bit #%x\n", RealBcb - CcCacheSections);
934 
936 
937 #ifdef PIN_WRITE_ONLY
938  PVOID BaseAddress = RealBcb->BaseAddress;
939  SIZE_T NumberOfBytes = RealBcb->Length;
940  ULONG OldProtect;
941 
943  &BaseAddress,
944  &NumberOfBytes,
946  &OldProtect);
947 #endif
948  }
949 
950  return TRUE;
951 }
PRTL_BITMAP CcCacheBitmap
Definition: pinsup.c:100
KEVENT CcDeleteEvent
Definition: pinsup.c:102
#define TRUE
Definition: types.h:120
NTSTATUS NTAPI MiProtectVirtualMemory(IN PEPROCESS Process, IN OUT PVOID *BaseAddress, IN OUT PSIZE_T NumberOfBytesToProtect, IN ULONG NewAccessProtection, OUT PULONG OldAccessProtection OPTIONAL)
Definition: virtual.c:2092
LONG NTAPI KeSetEvent(IN PKEVENT Event, IN KPRIORITY Increment, IN BOOLEAN Wait)
Definition: eventobj.c:159
#define IO_DISK_INCREMENT
Definition: iotypes.h:568
NOCC_BCB CcCacheSections[CACHE_NUM_SECTIONS]
Definition: pinsup.c:98
smooth NULL
Definition: ftsmooth.c:416
void DPRINT(...)
Definition: polytest.cpp:61
_In_ HANDLE _Outptr_result_bytebuffer_ ViewSize PVOID * BaseAddress
Definition: mmfuncs.h:404
VOID NTAPI RtlClearBit(_In_ PRTL_BITMAP BitMapHeader, _In_ BITMAP_INDEX BitNumber)
Definition: bitmap.c:294
ULONG_PTR SIZE_T
Definition: typedefs.h:78
#define PAGE_READONLY
Definition: compat.h:127
_Must_inspect_result_ typedef _In_ PHYSICAL_ADDRESS _Inout_ PLARGE_INTEGER NumberOfBytes
Definition: iotypes.h:998
unsigned int ULONG
Definition: retypes.h:1
#define IO_NO_INCREMENT
Definition: iotypes.h:566

Referenced by CcUnpinData().

◆ CcSetBcbOwnerPointer()

VOID NTAPI CcSetBcbOwnerPointer ( IN PVOID  Bcb,
IN PVOID  OwnerPointer 
)

Definition at line 979 of file pinsup.c.

981 {
982  PNOCC_BCB RealBcb = (PNOCC_BCB)Bcb;
983  CcpLock();
985  RealBcb->OwnerPointer = OwnerPointer;
986  CcpUnlock();
987 }
IN PVCB IN VBO IN ULONG OUT PBCB * Bcb
Definition: fatprocs.h:402
#define CcpLock()
Definition: newcc.h:143
_In_ PVOID OwnerPointer
Definition: exfuncs.h:862
Definition: newcc.h:3
NOCC_BCB CcCacheSections[CACHE_NUM_SECTIONS]
Definition: pinsup.c:98
VOID CcpReferenceCache(ULONG Start)
Definition: pinsup.c:368
struct _NOCC_BCB * PNOCC_BCB
PVOID OwnerPointer
Definition: newcc.h:14
#define CcpUnlock()
Definition: newcc.h:144

Referenced by get_block_bh_pin().

◆ CcUnpinData()

VOID NTAPI CcUnpinData ( IN PVOID  Bcb)

Definition at line 955 of file pinsup.c.

956 {
957  PNOCC_BCB RealBcb = (PNOCC_BCB)Bcb;
958  ULONG Selected = RealBcb - CcCacheSections;
959  BOOLEAN Released;
960 
961  ASSERT(RealBcb >= CcCacheSections &&
962  RealBcb - CcCacheSections < CACHE_NUM_SECTIONS);
963 
964  DPRINT("CcUnpinData Bcb #%x (RefCount %d)\n", Selected, RealBcb->RefCount);
965 
966  CcpLock();
967  Released = CcpUnpinData(RealBcb, FALSE);
968  CcpUnlock();
969 
970  if (!Released) {
971  CcpLock();
972  CcpUnpinData(RealBcb, TRUE);
973  CcpUnlock();
974  }
975 }
#define TRUE
Definition: types.h:120
IN PVCB IN VBO IN ULONG OUT PBCB * Bcb
Definition: fatprocs.h:402
#define CcpLock()
Definition: newcc.h:143
#define CACHE_NUM_SECTIONS
Definition: newcc.h:130
ULONG RefCount
Definition: newcc.h:17
Definition: newcc.h:3
BOOLEAN NTAPI CcpUnpinData(IN PNOCC_BCB RealBcb, BOOLEAN ReleaseBit)
Definition: pinsup.c:911
NOCC_BCB CcCacheSections[CACHE_NUM_SECTIONS]
Definition: pinsup.c:98
unsigned char BOOLEAN
void DPRINT(...)
Definition: polytest.cpp:61
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
struct _NOCC_BCB * PNOCC_BCB
unsigned int ULONG
Definition: retypes.h:1
#define CcpUnlock()
Definition: newcc.h:144

Referenced by CcCopyRead(), CcCopyWrite(), CcUnpinDataForThread(), CcUnpinRepinnedBcb(), Ext2ExpandBlock(), Ext2FreeBlock(), Ext2GetBlock(), Ext2TruncateBlock(), FAT12CountAvailableClusters(), FAT12FindAndMarkAvailableCluster(), FAT12GetNextCluster(), FAT12WriteCluster(), FAT16CountAvailableClusters(), FAT16FindAndMarkAvailableCluster(), FAT16GetDirtyStatus(), FAT16GetNextCluster(), FAT16SetDirtyStatus(), FAT16WriteCluster(), FAT32CountAvailableClusters(), FAT32FindAndMarkAvailableCluster(), FAT32GetDirtyStatus(), FAT32GetNextCluster(), FAT32SetDirtyStatus(), FAT32UpdateFreeClustersCount(), FAT32WriteCluster(), FATAddEntry(), FATDelEntry(), FatFlushFat(), FATGetNextDirEntry(), FATIsDirectoryEmpty(), FatUnpinEaRange(), FATXAddEntry(), FATXDelEntry(), FATXGetNextDirEntry(), FATXIsDirectoryEmpty(), FFSCheckSetBlock(), FFSFreeBlock(), FFSFreeInode(), FFSNewBlock(), FFSNewInode(), FFSSaveBuffer(), FFSTruncateBlock(), FindFile(), FsdSetFsLabelInformation(), get_block_bh_mdl(), MapInAnotherThread(), PerformTest(), PinInAnotherThread(), PinInAnotherThreadExclusive(), ReadVolumeLabel(), RfsdCheckSetBlock(), submit_bh_mdl(), vfatDirFindFile(), vfatFindDirSpace(), vfatRenameEntry(), and VfatUpdateEntry().

◆ CcUnpinDataForThread()

VOID NTAPI CcUnpinDataForThread ( IN PVOID  Bcb,
IN ERESOURCE_THREAD  ResourceThreadId 
)

Definition at line 991 of file pinsup.c.

993 {
994  CcUnpinData(Bcb);
995 }
IN PVCB IN VBO IN ULONG OUT PBCB * Bcb
Definition: fatprocs.h:402
VOID NTAPI CcUnpinData(IN PVOID Bcb)
Definition: pinsup.c:955

Referenced by free_buffer_head().

◆ MmGetDeviceObjectForFile()

PDEVICE_OBJECT NTAPI MmGetDeviceObjectForFile ( IN PFILE_OBJECT  FileObject)

Definition at line 62 of file io.c.

63 {
65 }
PDEVICE_OBJECT NTAPI IoGetRelatedDeviceObject(IN PFILE_OBJECT FileObject)
Definition: device.c:1539
_Inout_ PFILE_OBJECT FileObject
Definition: cdprocs.h:593

Referenced by _MiSimpleWrite(), and MiSimpleRead().

Variable Documentation

◆ CcCacheBitmap

◆ CcCacheClockHand

ULONG CcCacheClockHand

Definition at line 104 of file pinsup.c.

Referenced by CcpAllocateCacheSections().

◆ CcCacheSections

◆ CcDeleteEvent

KEVENT CcDeleteEvent

Definition at line 102 of file pinsup.c.

Referenced by CcInitializeCacheManager(), CcpMapData(), and CcpUnpinData().

◆ CcFinalizeEvent

KEVENT CcFinalizeEvent

Definition at line 103 of file pinsup.c.

Referenced by CcInitializeCacheManager().

◆ CcMutex

FAST_MUTEX CcMutex

Definition at line 101 of file pinsup.c.

Referenced by _CcpLock(), _CcpUnlock(), and CcInitializeCacheManager().

◆ CcOutstandingDeletes

LONG CcOutstandingDeletes

Definition at line 105 of file pinsup.c.

◆ CcpBitmapBuffer

CHAR CcpBitmapBuffer[sizeof(RTL_BITMAP)+ROUND_UP((CACHE_NUM_SECTIONS), 32)/8]

Definition at line 99 of file pinsup.c.

◆ LastThread