ReactOS  0.4.15-dev-2103-g9dff498
cc.h File Reference

Go to the source code of this file.

Classes

struct  _PF_SCENARIO_ID
 
struct  _PF_LOG_ENTRY
 
struct  _PFSN_LOG_ENTRIES
 
struct  _PF_SECTION_INFO
 
struct  _PF_TRACE_HEADER
 
struct  _PFSN_TRACE_DUMP
 
struct  _PFSN_TRACE_HEADER
 
struct  _PFSN_PREFETCHER_GLOBALS
 
struct  _ROS_SHARED_CACHE_MAP
 
struct  _ROS_VACB
 
struct  _INTERNAL_BCB
 
struct  _LAZY_WRITER
 
struct  _WORK_QUEUE_ENTRY
 

Macros

#define _CC_DEBUG_   0x00
 
#define CC_API_DEBUG   0x01
 
#define CCTRACE(x, fmt, ...)   DPRINT(fmt, ##__VA_ARGS__)
 
#define READAHEAD_DISABLED   0x1
 
#define WRITEBEHIND_DISABLED   0x2
 
#define SHARED_CACHE_MAP_IN_CREATION   0x4
 
#define SHARED_CACHE_MAP_IN_LAZYWRITE   0x8
 
#define NODE_TYPE_DEFERRED_WRITE   0x02FC
 
#define NODE_TYPE_PRIVATE_MAP   0x02FE
 
#define NODE_TYPE_SHARED_MAP   0x02FF
 
#define CcBugCheck(A, B, C)   KeBugCheckEx(CACHE_MANAGER, BugCheckFileId | ((ULONG)(__LINE__)), A, B, C)
 
#define CcRosVacbIncRefCount(vacb)   InterlockedIncrement((PLONG)&(vacb)->ReferenceCount)
 
#define CcRosVacbGetRefCount(vacb)   InterlockedCompareExchange((PLONG)&(vacb)->ReferenceCount, 0, 0)
 

Typedefs

typedef struct _PF_SCENARIO_ID PF_SCENARIO_ID
 
typedef struct _PF_SCENARIO_IDPPF_SCENARIO_ID
 
typedef struct _PF_LOG_ENTRY PF_LOG_ENTRY
 
typedef struct _PF_LOG_ENTRYPPF_LOG_ENTRY
 
typedef struct _PFSN_LOG_ENTRIES PFSN_LOG_ENTRIES
 
typedef struct _PFSN_LOG_ENTRIESPPFSN_LOG_ENTRIES
 
typedef struct _PF_SECTION_INFO PF_SECTION_INFO
 
typedef struct _PF_SECTION_INFOPPF_SECTION_INFO
 
typedef struct _PF_TRACE_HEADER PF_TRACE_HEADER
 
typedef struct _PF_TRACE_HEADERPPF_TRACE_HEADER
 
typedef struct _PFSN_TRACE_DUMP PFSN_TRACE_DUMP
 
typedef struct _PFSN_TRACE_DUMPPPFSN_TRACE_DUMP
 
typedef struct _PFSN_TRACE_HEADER PFSN_TRACE_HEADER
 
typedef struct _PFSN_TRACE_HEADERPPFSN_TRACE_HEADER
 
typedef struct _PFSN_PREFETCHER_GLOBALS PFSN_PREFETCHER_GLOBALS
 
typedef struct _PFSN_PREFETCHER_GLOBALSPPFSN_PREFETCHER_GLOBALS
 
typedef struct _ROS_SHARED_CACHE_MAP ROS_SHARED_CACHE_MAP
 
typedef struct _ROS_SHARED_CACHE_MAPPROS_SHARED_CACHE_MAP
 
typedef struct _ROS_VACB ROS_VACB
 
typedef struct _ROS_VACBPROS_VACB
 
typedef struct _INTERNAL_BCB INTERNAL_BCB
 
typedef struct _INTERNAL_BCBPINTERNAL_BCB
 
typedef struct _LAZY_WRITER LAZY_WRITER
 
typedef struct _LAZY_WRITERPLAZY_WRITER
 
typedef struct _WORK_QUEUE_ENTRY WORK_QUEUE_ENTRY
 
typedef struct _WORK_QUEUE_ENTRYPWORK_QUEUE_ENTRY
 
typedef enum _WORK_QUEUE_FUNCTIONS WORK_QUEUE_FUNCTIONS
 
typedef enum _WORK_QUEUE_FUNCTIONSPWORK_QUEUE_FUNCTIONS
 

Enumerations

enum  _WORK_QUEUE_FUNCTIONS { ReadAhead = 1, WriteBehind = 2, LazyScan = 3, SetDone = 4 }
 

Functions

VOID NTAPI CcPfInitializePrefetcher (VOID)
 
VOID NTAPI CcMdlReadComplete2 (IN PFILE_OBJECT FileObject, IN PMDL MemoryDescriptorList)
 
VOID NTAPI CcMdlWriteComplete2 (IN PFILE_OBJECT FileObject, IN PLARGE_INTEGER FileOffset, IN PMDL MdlChain)
 
NTSTATUS CcRosFlushVacb (PROS_VACB Vacb, PIO_STATUS_BLOCK Iosb)
 
NTSTATUS CcRosGetVacb (PROS_SHARED_CACHE_MAP SharedCacheMap, LONGLONG FileOffset, PROS_VACB *Vacb)
 
BOOLEAN CcRosEnsureVacbResident (_In_ PROS_VACB Vacb, _In_ BOOLEAN Wait, _In_ BOOLEAN NoRead, _In_ ULONG Offset, _In_ ULONG Length)
 
VOID NTAPI CcInitView (VOID)
 
VOID NTAPI CcShutdownLazyWriter (VOID)
 
BOOLEAN CcInitializeCacheManager (VOID)
 
PROS_VACB CcRosLookupVacb (PROS_SHARED_CACHE_MAP SharedCacheMap, LONGLONG FileOffset)
 
VOID NTAPI CcInitCacheZeroPage (VOID)
 
VOID CcRosMarkDirtyVacb (PROS_VACB Vacb)
 
VOID CcRosUnmarkDirtyVacb (PROS_VACB Vacb, BOOLEAN LockViews)
 
NTSTATUS CcRosFlushDirtyPages (ULONG Target, PULONG Count, BOOLEAN Wait, BOOLEAN CalledFromLazy)
 
VOID CcRosDereferenceCache (PFILE_OBJECT FileObject)
 
VOID CcRosReferenceCache (PFILE_OBJECT FileObject)
 
NTSTATUS CcRosReleaseVacb (PROS_SHARED_CACHE_MAP SharedCacheMap, PROS_VACB Vacb, BOOLEAN Dirty, BOOLEAN Mapped)
 
NTSTATUS CcRosRequestVacb (PROS_SHARED_CACHE_MAP SharedCacheMap, LONGLONG FileOffset, PROS_VACB *Vacb)
 
NTSTATUS CcRosInitializeFileCache (PFILE_OBJECT FileObject, PCC_FILE_SIZES FileSizes, BOOLEAN PinAccess, PCACHE_MANAGER_CALLBACKS CallBacks, PVOID LazyWriterContext)
 
NTSTATUS CcRosReleaseFileCache (PFILE_OBJECT FileObject)
 
VOID NTAPI CcShutdownSystem (VOID)
 
VOID NTAPI CcWorkerThread (PVOID Parameter)
 
VOID NTAPI CcScanDpc (PKDPC Dpc, PVOID DeferredContext, PVOID SystemArgument1, PVOID SystemArgument2)
 
VOID CcScheduleLazyWriteScan (BOOLEAN NoDelay)
 
VOID CcPostDeferredWrites (VOID)
 
VOID CcPostWorkQueue (IN PWORK_QUEUE_ENTRY WorkItem, IN PLIST_ENTRY WorkQueue)
 
VOID CcPerformReadAhead (IN PFILE_OBJECT FileObject)
 
NTSTATUS CcRosInternalFreeVacb (IN PROS_VACB Vacb)
 
FORCEINLINE BOOLEAN DoRangesIntersect (_In_ LONGLONG Offset1, _In_ LONGLONG Length1, _In_ LONGLONG Offset2, _In_ LONGLONG Length2)
 
FORCEINLINE BOOLEAN IsPointInRange (_In_ LONGLONG Offset1, _In_ LONGLONG Length1, _In_ LONGLONG Point)
 
FORCEINLINE ULONG CcRosVacbDecRefCount (PROS_VACB vacb)
 

Variables

ULONG CcRosTraceLevel
 
LIST_ENTRY DirtyVacbListHead
 
ULONG CcDirtyPageThreshold
 
ULONG CcTotalDirtyPages
 
LIST_ENTRY CcDeferredWrites
 
KSPIN_LOCK CcDeferredWriteSpinLock
 
ULONG CcNumberWorkerThreads
 
LIST_ENTRY CcIdleWorkerThreadList
 
LIST_ENTRY CcExpressWorkQueue
 
LIST_ENTRY CcRegularWorkQueue
 
LIST_ENTRY CcPostTickWorkQueue
 
NPAGED_LOOKASIDE_LIST CcTwilightLookasideList
 
LARGE_INTEGER CcIdleDelay
 
ULONG CcLazyWritePages
 
ULONG CcLazyWriteIos
 
ULONG CcMapDataWait
 
ULONG CcMapDataNoWait
 
ULONG CcPinReadWait
 
ULONG CcPinReadNoWait
 
ULONG CcPinMappedDataCount
 
ULONG CcDataPages
 
ULONG CcDataFlushes
 
LAZY_WRITER LazyWriter
 

Macro Definition Documentation

◆ _CC_DEBUG_

#define _CC_DEBUG_   0x00

Definition at line 6 of file cc.h.

◆ CC_API_DEBUG

#define CC_API_DEBUG   0x01

Definition at line 11 of file cc.h.

◆ CcBugCheck

#define CcBugCheck (   A,
  B,
  C 
)    KeBugCheckEx(CACHE_MANAGER, BugCheckFileId | ((ULONG)(__LINE__)), A, B, C)

Definition at line 463 of file cc.h.

◆ CcRosVacbGetRefCount

#define CcRosVacbGetRefCount (   vacb)    InterlockedCompareExchange((PLONG)&(vacb)->ReferenceCount, 0, 0)

Definition at line 504 of file cc.h.

◆ CcRosVacbIncRefCount

#define CcRosVacbIncRefCount (   vacb)    InterlockedIncrement((PLONG)&(vacb)->ReferenceCount)

Definition at line 489 of file cc.h.

◆ CCTRACE

#define CCTRACE (   x,
  fmt,
  ... 
)    DPRINT(fmt, ##__VA_ARGS__)

Definition at line 36 of file cc.h.

◆ NODE_TYPE_DEFERRED_WRITE

#define NODE_TYPE_DEFERRED_WRITE   0x02FC

Definition at line 286 of file cc.h.

◆ NODE_TYPE_PRIVATE_MAP

#define NODE_TYPE_PRIVATE_MAP   0x02FE

Definition at line 287 of file cc.h.

◆ NODE_TYPE_SHARED_MAP

#define NODE_TYPE_SHARED_MAP   0x02FF

Definition at line 288 of file cc.h.

◆ READAHEAD_DISABLED

#define READAHEAD_DISABLED   0x1

Definition at line 201 of file cc.h.

◆ SHARED_CACHE_MAP_IN_CREATION

#define SHARED_CACHE_MAP_IN_CREATION   0x4

Definition at line 203 of file cc.h.

◆ SHARED_CACHE_MAP_IN_LAZYWRITE

#define SHARED_CACHE_MAP_IN_LAZYWRITE   0x8

Definition at line 204 of file cc.h.

◆ WRITEBEHIND_DISABLED

#define WRITEBEHIND_DISABLED   0x2

Definition at line 202 of file cc.h.

Typedef Documentation

◆ INTERNAL_BCB

◆ LAZY_WRITER

◆ PF_LOG_ENTRY

◆ PF_SCENARIO_ID

◆ PF_SECTION_INFO

◆ PF_TRACE_HEADER

◆ PFSN_LOG_ENTRIES

◆ PFSN_PREFETCHER_GLOBALS

◆ PFSN_TRACE_DUMP

◆ PFSN_TRACE_HEADER

◆ PINTERNAL_BCB

◆ PLAZY_WRITER

◆ PPF_LOG_ENTRY

◆ PPF_SCENARIO_ID

◆ PPF_SECTION_INFO

◆ PPF_TRACE_HEADER

◆ PPFSN_LOG_ENTRIES

◆ PPFSN_PREFETCHER_GLOBALS

◆ PPFSN_TRACE_DUMP

◆ PPFSN_TRACE_HEADER

◆ PROS_SHARED_CACHE_MAP

◆ PROS_VACB

◆ PWORK_QUEUE_ENTRY

◆ PWORK_QUEUE_FUNCTIONS

◆ ROS_SHARED_CACHE_MAP

◆ ROS_VACB

◆ WORK_QUEUE_ENTRY

◆ WORK_QUEUE_FUNCTIONS

Enumeration Type Documentation

◆ _WORK_QUEUE_FUNCTIONS

Enumerator
ReadAhead 
WriteBehind 
LazyScan 
SetDone 

Definition at line 276 of file cc.h.

277 {
278  ReadAhead = 1,
279  WriteBehind = 2,
280  LazyScan = 3,
281  SetDone = 4,
Definition: cc.h:280
Definition: cc.h:281
Definition: cc.h:278
enum _WORK_QUEUE_FUNCTIONS WORK_QUEUE_FUNCTIONS
enum _WORK_QUEUE_FUNCTIONS * PWORK_QUEUE_FUNCTIONS

Function Documentation

◆ CcInitCacheZeroPage()

VOID NTAPI CcInitCacheZeroPage ( VOID  )

Definition at line 56 of file copy.c.

58 {
60 
62  //MI_SET_PROCESS2(PsGetCurrentProcess()->ImageFileName);
64  if (!NT_SUCCESS(Status))
65  {
66  DbgPrint("Can't allocate CcZeroPage.\n");
67  KeBugCheck(CACHE_MANAGER);
68  }
70 }
#define DbgPrint
Definition: loader.c:25
#define TRUE
Definition: types.h:120
LONG NTSTATUS
Definition: precomp.h:26
NTSTATUS NTAPI MmRequestPageMemoryConsumer(ULONG Consumer, BOOLEAN MyWait, PPFN_NUMBER AllocatedPage)
Definition: balance.c:275
#define MC_SYSTEM
Definition: mm.h:93
VOID NTAPI MiZeroPhysicalPage(IN PFN_NUMBER PageFrameIndex)
Definition: pfnlist.c:122
DECLSPEC_NORETURN VOID NTAPI KeBugCheck(ULONG BugCheckCode)
Definition: bug.c:1427
#define MI_SET_USAGE(x)
Definition: mm.h:250
Status
Definition: gdiplustypes.h:24
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
static PFN_NUMBER CcZeroPage
Definition: copy.c:19

◆ CcInitializeCacheManager()

BOOLEAN CcInitializeCacheManager ( VOID  )

Definition at line 83 of file fssup.c.

84 {
85  int i;
86 
87  DPRINT("Initialize\n");
88  for (i = 0; i < CACHE_NUM_SECTIONS; i++)
89  {
90  KeInitializeEvent(&CcCacheSections[i].ExclusiveWait,
92  FALSE);
93 
94  InitializeListHead(&CcCacheSections[i].ThisFileList);
95  }
96 
98 
102 
105  DPRINT1("Cache has %d entries\n", CcCacheBitmap->SizeOfBitMap);
107 
108  return TRUE;
109 }
KEVENT CcpLazyWriteEvent
Definition: lazyrite.c:18
PULONG Buffer
Definition: typedefs.h:91
FAST_MUTEX CcMutex
Definition: pinsup.c:101
#define ROUND_UP(n, align)
Definition: eventvwr.h:31
#define TRUE
Definition: types.h:120
#define CACHE_NUM_SECTIONS
Definition: newcc.h:123
NOCC_BCB CcCacheSections[CACHE_NUM_SECTIONS]
Definition: pinsup.c:98
#define FALSE
Definition: types.h:117
KEVENT CcDeleteEvent
Definition: pinsup.c:102
FORCEINLINE VOID ExInitializeFastMutex(_Out_ PFAST_MUTEX FastMutex)
Definition: exfuncs.h:274
KEVENT CcFinalizeEvent
Definition: pinsup.c:103
PRTL_BITMAP CcCacheBitmap
Definition: pinsup.c:100
ULONG SizeOfBitMap
Definition: typedefs.h:90
LIST_ENTRY CcpAllSharedCacheMaps
Definition: fssup.c:76
#define KeInitializeEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:477
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
#define InitializeListHead(ListHead)
Definition: env_spec_w32.h:944
unsigned int * PULONG
Definition: retypes.h:1
#define DPRINT1
Definition: precomp.h:8
#define DPRINT
Definition: sndvol32.h:71

Referenced by Phase1InitializationDiscard().

◆ CcInitView()

VOID NTAPI CcInitView ( VOID  )

Definition at line 1374 of file view.c.

1376 {
1377  DPRINT("CcInitView()\n");
1378 
1385  NULL,
1386  NULL,
1387  0,
1388  sizeof(INTERNAL_BCB),
1389  TAG_BCB,
1390  20);
1392  NULL,
1393  NULL,
1394  0,
1395  sizeof(ROS_SHARED_CACHE_MAP),
1397  20);
1399  NULL,
1400  NULL,
1401  0,
1402  sizeof(ROS_VACB),
1403  TAG_VACB,
1404  20);
1405 
1407 }
Definition: cc.h:206
#define TAG_VACB
Definition: tag.h:5
static NPAGED_LOOKASIDE_LIST VacbLookasideList
Definition: view.c:46
#define TAG_BCB
Definition: nodetype.h:157
static LIST_ENTRY VacbLruListHead
Definition: view.c:42
#define TAG_SHARED_CACHE_MAP
Definition: tag.h:6
FORCEINLINE VOID KeInitializeSpinLock(_Out_ PKSPIN_LOCK SpinLock)
Definition: kefuncs.h:238
LIST_ENTRY CcCleanSharedCacheMapList
Definition: view.c:59
VOID NTAPI CcInitCacheZeroPage(VOID)
Definition: copy.c:56
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
static NPAGED_LOOKASIDE_LIST SharedCacheMapLookasideList
Definition: view.c:45
LIST_ENTRY CcDeferredWrites
Definition: view.c:57
KSPIN_LOCK CcDeferredWriteSpinLock
Definition: view.c:58
#define InitializeListHead(ListHead)
Definition: env_spec_w32.h:944
NPAGED_LOOKASIDE_LIST iBcbLookasideList
Definition: view.c:44
#define NULL
Definition: types.h:112
#define DPRINT
Definition: sndvol32.h:71
LIST_ENTRY DirtyVacbListHead
Definition: view.c:41

◆ CcMdlReadComplete2()

VOID NTAPI CcMdlReadComplete2 ( IN PFILE_OBJECT  FileObject,
IN PMDL  MemoryDescriptorList 
)

Definition at line 83 of file mdlsup.c.

85 {
87 }
#define UNIMPLEMENTED
Definition: debug.h:115

Referenced by CcMdlReadComplete(), and FsRtlMdlReadCompleteDev().

◆ CcMdlWriteComplete2()

VOID NTAPI CcMdlWriteComplete2 ( IN PFILE_OBJECT  FileObject,
IN PLARGE_INTEGER  FileOffset,
IN PMDL  MdlChain 
)

Definition at line 111 of file mdlsup.c.

114 {
116 }
#define UNIMPLEMENTED
Definition: debug.h:115

Referenced by CcMdlWriteComplete(), and FsRtlMdlWriteCompleteDev().

◆ CcPerformReadAhead()

VOID CcPerformReadAhead ( IN PFILE_OBJECT  FileObject)

Definition at line 147 of file copy.c.

149 {
151  LONGLONG CurrentOffset;
152  KIRQL OldIrql;
153  PROS_SHARED_CACHE_MAP SharedCacheMap;
154  PROS_VACB Vacb;
155  ULONG PartialLength;
156  ULONG Length;
157  PPRIVATE_CACHE_MAP PrivateCacheMap;
158  BOOLEAN Locked;
159 
160  SharedCacheMap = FileObject->SectionObjectPointer->SharedCacheMap;
161 
162  /* Critical:
163  * PrivateCacheMap might disappear in-between if the handle
164  * to the file is closed (private is attached to the handle not to
165  * the file), so we need to lock the master lock while we deal with
166  * it. It won't disappear without attempting to lock such lock.
167  */
169  PrivateCacheMap = FileObject->PrivateCacheMap;
170  /* If the handle was closed since the read ahead was scheduled, just quit */
171  if (PrivateCacheMap == NULL)
172  {
175  return;
176  }
177  /* Otherwise, extract read offset and length and release private map */
178  else
179  {
181  CurrentOffset = PrivateCacheMap->ReadAheadOffset[1].QuadPart;
182  Length = PrivateCacheMap->ReadAheadLength[1];
184  }
186 
187  /* Time to go! */
188  DPRINT("Doing ReadAhead for %p\n", FileObject);
189  /* Lock the file, first */
190  if (!SharedCacheMap->Callbacks->AcquireForReadAhead(SharedCacheMap->LazyWriteContext, FALSE))
191  {
192  Locked = FALSE;
193  goto Clear;
194  }
195 
196  /* Remember it's locked */
197  Locked = TRUE;
198 
199  /* Don't read past the end of the file */
200  if (CurrentOffset >= SharedCacheMap->FileSize.QuadPart)
201  {
202  goto Clear;
203  }
204  if (CurrentOffset + Length > SharedCacheMap->FileSize.QuadPart)
205  {
206  Length = SharedCacheMap->FileSize.QuadPart - CurrentOffset;
207  }
208 
209  /* Next of the algorithm will lock like CcCopyData with the slight
210  * difference that we don't copy data back to an user-backed buffer
211  * We just bring data into Cc
212  */
213  PartialLength = CurrentOffset % VACB_MAPPING_GRANULARITY;
214  if (PartialLength != 0)
215  {
216  PartialLength = min(Length, VACB_MAPPING_GRANULARITY - PartialLength);
217  Status = CcRosRequestVacb(SharedCacheMap,
218  ROUND_DOWN(CurrentOffset, VACB_MAPPING_GRANULARITY),
219  &Vacb);
220  if (!NT_SUCCESS(Status))
221  {
222  DPRINT1("Failed to request VACB: %lx!\n", Status);
223  goto Clear;
224  }
225 
227  CurrentOffset % VACB_MAPPING_GRANULARITY, PartialLength);
228  if (!NT_SUCCESS(Status))
229  {
230  CcRosReleaseVacb(SharedCacheMap, Vacb, FALSE, FALSE);
231  DPRINT1("Failed to read data: %lx!\n", Status);
232  goto Clear;
233  }
234 
235  CcRosReleaseVacb(SharedCacheMap, Vacb, FALSE, FALSE);
236 
237  Length -= PartialLength;
238  CurrentOffset += PartialLength;
239  }
240 
241  while (Length > 0)
242  {
243  ASSERT(CurrentOffset % VACB_MAPPING_GRANULARITY == 0);
244  PartialLength = min(VACB_MAPPING_GRANULARITY, Length);
245  Status = CcRosRequestVacb(SharedCacheMap,
246  CurrentOffset,
247  &Vacb);
248  if (!NT_SUCCESS(Status))
249  {
250  DPRINT1("Failed to request VACB: %lx!\n", Status);
251  goto Clear;
252  }
253 
254  Status = CcRosEnsureVacbResident(Vacb, TRUE, FALSE, 0, PartialLength);
255  if (!NT_SUCCESS(Status))
256  {
257  CcRosReleaseVacb(SharedCacheMap, Vacb, FALSE, FALSE);
258  DPRINT1("Failed to read data: %lx!\n", Status);
259  goto Clear;
260  }
261 
262  CcRosReleaseVacb(SharedCacheMap, Vacb, FALSE, FALSE);
263 
264  Length -= PartialLength;
265  CurrentOffset += PartialLength;
266  }
267 
268 Clear:
269  /* See previous comment about private cache map */
271  PrivateCacheMap = FileObject->PrivateCacheMap;
272  if (PrivateCacheMap != NULL)
273  {
274  /* Mark read ahead as unactive */
276  InterlockedAnd((volatile long *)&PrivateCacheMap->UlongFlags, ~PRIVATE_CACHE_MAP_READ_AHEAD_ACTIVE);
278  }
280 
281  /* If file was locked, release it */
282  if (Locked)
283  {
284  SharedCacheMap->Callbacks->ReleaseFromReadAhead(SharedCacheMap->LazyWriteContext);
285  }
286 
287  /* And drop our extra reference (See: CcScheduleReadAhead) */
289 
290  return;
291 }
#define InterlockedAnd
Definition: interlocked.h:62
Definition: cc.h:206
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
#define TRUE
Definition: types.h:120
VOID NTAPI KeAcquireSpinLockAtDpcLevel(IN PKSPIN_LOCK SpinLock)
Definition: spinlock.c:192
LONG NTSTATUS
Definition: precomp.h:26
UCHAR KIRQL
Definition: env_spec_w32.h:591
#define FALSE
Definition: types.h:117
_In_ PMEMORY_AREA _In_ PVOID _In_ BOOLEAN Locked
Definition: newmm.h:217
NTSTATUS CcRosRequestVacb(PROS_SHARED_CACHE_MAP SharedCacheMap, LONGLONG FileOffset, PROS_VACB *Vacb)
Definition: view.c:933
unsigned char BOOLEAN
PCACHE_MANAGER_CALLBACKS Callbacks
Definition: cc.h:185
_In_ WDFREQUEST _In_ WDFFILEOBJECT FileObject
Definition: wdfdevice.h:547
KSPIN_LOCK ReadAheadSpinLock
Definition: cctypes.h:83
Status
Definition: gdiplustypes.h:24
int64_t LONGLONG
Definition: typedefs.h:68
#define ASSERT(a)
Definition: mode.c:45
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
VOID NTAPI KeReleaseSpinLockFromDpcLevel(IN PKSPIN_LOCK SpinLock)
Definition: spinlock.c:215
#define ObDereferenceObject
Definition: obfuncs.h:203
VOID FASTCALL KeReleaseQueuedSpinLock(IN KSPIN_LOCK_QUEUE_NUMBER LockNumber, IN KIRQL OldIrql)
Definition: spinlock.c:154
PACQUIRE_FOR_READ_AHEAD AcquireForReadAhead
Definition: cctypes.h:41
_Requires_lock_held_ Interrupt _Releases_lock_ Interrupt _In_ _IRQL_restores_ KIRQL OldIrql
Definition: kefuncs.h:790
PRELEASE_FROM_READ_AHEAD ReleaseFromReadAhead
Definition: cctypes.h:42
KIRQL FASTCALL KeAcquireQueuedSpinLock(IN KSPIN_LOCK_QUEUE_NUMBER LockNumber)
Definition: spinlock.c:108
#define ROUND_DOWN(n, align)
Definition: eventvwr.h:30
BOOLEAN CcRosEnsureVacbResident(_In_ PROS_VACB Vacb, _In_ BOOLEAN Wait, _In_ BOOLEAN NoRead, _In_ ULONG Offset, _In_ ULONG Length)
Definition: view.c:835
LARGE_INTEGER ReadAheadOffset[2]
Definition: cctypes.h:81
#define min(a, b)
Definition: monoChain.cc:55
#define NULL
Definition: types.h:112
#define DPRINT1
Definition: precomp.h:8
#define VACB_MAPPING_GRANULARITY
PVOID LazyWriteContext
Definition: cc.h:186
LARGE_INTEGER FileSize
Definition: cc.h:175
unsigned int ULONG
Definition: retypes.h:1
NTSTATUS CcRosReleaseVacb(PROS_SHARED_CACHE_MAP SharedCacheMap, PROS_VACB Vacb, BOOLEAN Dirty, BOOLEAN Mapped)
Definition: view.c:453
void Clear(USHORT Window)
Definition: hardware.c:684
#define DPRINT
Definition: sndvol32.h:71
ULONG UlongFlags
Definition: cctypes.h:73
#define PRIVATE_CACHE_MAP_READ_AHEAD_ACTIVE
Definition: cctypes.h:64
ULONG ReadAheadLength[2]
Definition: cctypes.h:82
LONGLONG QuadPart
Definition: typedefs.h:114

Referenced by CcWorkerThread().

◆ CcPfInitializePrefetcher()

VOID NTAPI CcPfInitializePrefetcher ( VOID  )

Definition at line 114 of file fssup.c.

115 {
116  /* Notify debugger */
119  "CCPF: InitializePrefetecher()\n");
120 
121  /* Setup the Prefetcher Data */
125 
126  /* FIXME: Setup the rest of the prefetecher */
127 }
FAST_MUTEX CompletedTracesLock
Definition: cc.h:164
NTSYSAPI ULONG __cdecl DbgPrintEx(_In_ ULONG ComponentId, _In_ ULONG Level, _In_z_ _Printf_format_string_ PCSTR Format,...)
LIST_ENTRY CompletedTraces
Definition: cc.h:163
FORCEINLINE VOID ExInitializeFastMutex(_Out_ PFAST_MUTEX FastMutex)
Definition: exfuncs.h:274
PFSN_PREFETCHER_GLOBALS CcPfGlobals
Definition: fssup.c:20
#define InitializeListHead(ListHead)
Definition: env_spec_w32.h:944
LIST_ENTRY ActiveTraces
Definition: cc.h:160
#define DPFLTR_TRACE_LEVEL
Definition: kdtypes.h:32

Referenced by Phase1InitializationDiscard().

◆ CcPostDeferredWrites()

VOID CcPostDeferredWrites ( VOID  )

Definition at line 73 of file copy.c.

74 {
75  ULONG WrittenBytes;
76 
77  /* We'll try to write as much as we can */
78  WrittenBytes = 0;
79  while (TRUE)
80  {
81  KIRQL OldIrql;
82  PLIST_ENTRY ListEntry;
83  PDEFERRED_WRITE DeferredWrite;
84 
85  DeferredWrite = NULL;
86 
87  /* Lock our deferred writes list */
89  for (ListEntry = CcDeferredWrites.Flink;
90  ListEntry != &CcDeferredWrites;
91  ListEntry = ListEntry->Flink)
92  {
93  /* Extract an entry */
94  DeferredWrite = CONTAINING_RECORD(ListEntry, DEFERRED_WRITE, DeferredWriteLinks);
95 
96  /* Compute the modified bytes, based on what we already wrote */
97  WrittenBytes += DeferredWrite->BytesToWrite;
98  /* We overflowed, give up */
99  if (WrittenBytes < DeferredWrite->BytesToWrite)
100  {
101  DeferredWrite = NULL;
102  break;
103  }
104 
105  /* Check we can write */
106  if (CcCanIWrite(DeferredWrite->FileObject, WrittenBytes, FALSE, RetryForceCheckPerFile))
107  {
108  /* We can, so remove it from the list and stop looking for entry */
109  RemoveEntryList(&DeferredWrite->DeferredWriteLinks);
110  break;
111  }
112 
113  /* If we don't accept modified pages, stop here */
114  if (!DeferredWrite->LimitModifiedPages)
115  {
116  DeferredWrite = NULL;
117  break;
118  }
119 
120  /* Reset count as nothing was written yet */
121  WrittenBytes -= DeferredWrite->BytesToWrite;
122  DeferredWrite = NULL;
123  }
125 
126  /* Nothing to write found, give up */
127  if (DeferredWrite == NULL)
128  {
129  break;
130  }
131 
132  /* If we have an event, set it and quit */
133  if (DeferredWrite->Event)
134  {
135  KeSetEvent(DeferredWrite->Event, IO_NO_INCREMENT, FALSE);
136  }
137  /* Otherwise, call the write routine and free the context */
138  else
139  {
140  DeferredWrite->PostRoutine(DeferredWrite->Context1, DeferredWrite->Context2);
141  ExFreePoolWithTag(DeferredWrite, 'CcDw');
142  }
143  }
144 }
BOOLEAN LimitModifiedPages
Definition: cctypes.h:178
#define TRUE
Definition: types.h:120
BOOLEAN NTAPI CcCanIWrite(IN PFILE_OBJECT FileObject, IN ULONG BytesToWrite, IN BOOLEAN Wait, IN BOOLEAN Retrying)
Definition: copy.c:298
LONG NTAPI KeSetEvent(IN PKEVENT Event, IN KPRIORITY Increment, IN BOOLEAN Wait)
Definition: eventobj.c:159
FORCEINLINE BOOLEAN RemoveEntryList(_In_ PLIST_ENTRY Entry)
Definition: rtlfuncs.h:105
UCHAR KIRQL
Definition: env_spec_w32.h:591
#define FALSE
Definition: types.h:117
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
struct _LIST_ENTRY * Flink
Definition: typedefs.h:121
LIST_ENTRY DeferredWriteLinks
Definition: cctypes.h:173
#define KeAcquireSpinLock(sl, irql)
Definition: env_spec_w32.h:609
LIST_ENTRY CcDeferredWrites
Definition: view.c:57
KSPIN_LOCK CcDeferredWriteSpinLock
Definition: view.c:58
_Requires_lock_held_ Interrupt _Releases_lock_ Interrupt _In_ _IRQL_restores_ KIRQL OldIrql
Definition: kefuncs.h:790
Definition: typedefs.h:119
PFILE_OBJECT FileObject
Definition: cctypes.h:171
PVOID Context1
Definition: cctypes.h:176
#define NULL
Definition: types.h:112
PCC_POST_DEFERRED_WRITE PostRoutine
Definition: cctypes.h:175
#define KeReleaseSpinLock(sl, irql)
Definition: env_spec_w32.h:627
unsigned int ULONG
Definition: retypes.h:1
#define IO_NO_INCREMENT
Definition: iotypes.h:598
ULONG BytesToWrite
Definition: cctypes.h:172
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1099
PKEVENT Event
Definition: cctypes.h:174
PVOID Context2
Definition: cctypes.h:177

Referenced by CcCanIWrite(), CcDeferWrite(), and CcLazyWriteScan().

◆ CcPostWorkQueue()

VOID CcPostWorkQueue ( IN PWORK_QUEUE_ENTRY  WorkItem,
IN PLIST_ENTRY  WorkQueue 
)

Definition at line 53 of file lazywrite.c.

56 {
57  KIRQL OldIrql;
58  PWORK_QUEUE_ITEM ThreadToSpawn;
59 
60  /* First of all, insert the item in the queue */
62  InsertTailList(WorkQueue, &WorkItem->WorkQueueLinks);
63 
64  /* Now, define whether we have to spawn a new work thread
65  * We will spawn a new one if:
66  * - There's no throttle in action
67  * - There's still at least one idle thread
68  */
69  ThreadToSpawn = NULL;
71  {
72  PLIST_ENTRY ListEntry;
73 
74  /* Get the idle thread */
76  ThreadToSpawn = CONTAINING_RECORD(ListEntry, WORK_QUEUE_ITEM, List);
77 
78  /* We're going to have one more! */
80  }
81 
83 
84  /* If we have a thread to spawn, do it! */
85  if (ThreadToSpawn != NULL)
86  {
87  /* We NULLify it to be consistent with initialization */
88  ThreadToSpawn->List.Flink = NULL;
89  ExQueueWorkItem(ThreadToSpawn, CriticalWorkQueue);
90  }
91 }
VOID NTAPI ExQueueWorkItem(IN PWORK_QUEUE_ITEM WorkItem, IN WORK_QUEUE_TYPE QueueType)
Definition: work.c:711
LIST_ENTRY List
Definition: extypes.h:203
#define InsertTailList(ListHead, Entry)
_Must_inspect_result_ FORCEINLINE BOOLEAN IsListEmpty(_In_ const LIST_ENTRY *ListHead)
Definition: rtlfuncs.h:57
UCHAR KIRQL
Definition: env_spec_w32.h:591
LIST_ENTRY CcIdleWorkerThreadList
Definition: lazywrite.c:41
LIST_ENTRY WorkQueue
Definition: workqueue.c:20
ULONG CcNumberActiveWorkerThreads
Definition: lazywrite.c:44
FORCEINLINE PLIST_ENTRY RemoveHeadList(_Inout_ PLIST_ENTRY ListHead)
Definition: rtlfuncs.h:128
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
struct _LIST_ENTRY * Flink
Definition: typedefs.h:121
VOID FASTCALL KeReleaseQueuedSpinLock(IN KSPIN_LOCK_QUEUE_NUMBER LockNumber, IN KIRQL OldIrql)
Definition: spinlock.c:154
_Requires_lock_held_ Interrupt _Releases_lock_ Interrupt _In_ _IRQL_restores_ KIRQL OldIrql
Definition: kefuncs.h:790
_Must_inspect_result_ _In_ WDFCMRESLIST List
Definition: wdfresource.h:550
Definition: typedefs.h:119
KIRQL FASTCALL KeAcquireQueuedSpinLock(IN KSPIN_LOCK_QUEUE_NUMBER LockNumber)
Definition: spinlock.c:108
#define NULL
Definition: types.h:112
BOOLEAN CcQueueThrottle
Definition: lazywrite.c:43
_Must_inspect_result_ _In_ PWDF_WORKITEM_CONFIG _In_ PWDF_OBJECT_ATTRIBUTES _Out_ WDFWORKITEM * WorkItem
Definition: wdfworkitem.h:110

Referenced by CcLazyWriteScan(), CcScanDpc(), and CcScheduleReadAhead().

◆ CcRosDereferenceCache()

VOID CcRosDereferenceCache ( PFILE_OBJECT  FileObject)

◆ CcRosEnsureVacbResident()

BOOLEAN CcRosEnsureVacbResident ( _In_ PROS_VACB  Vacb,
_In_ BOOLEAN  Wait,
_In_ BOOLEAN  NoRead,
_In_ ULONG  Offset,
_In_ ULONG  Length 
)

Definition at line 835 of file view.c.

842 {
844 
846 
847 #if 0
848  if ((Vacb->FileOffset.QuadPart + Offset) > Vacb->SharedCacheMap->SectionSize.QuadPart)
849  {
850  DPRINT1("Vacb read beyond the file size!\n");
851  return FALSE;
852  }
853 #endif
854 
855  BaseAddress = (PVOID)((ULONG_PTR)Vacb->BaseAddress + Offset);
856 
857  /* Check if the pages are resident */
859  {
860  if (!Wait)
861  {
862  return FALSE;
863  }
864 
865  if (!NoRead)
866  {
867  PROS_SHARED_CACHE_MAP SharedCacheMap = Vacb->SharedCacheMap;
868  NTSTATUS Status = MmMakeDataSectionResident(SharedCacheMap->FileObject->SectionObjectPointer,
869  Vacb->FileOffset.QuadPart + Offset,
870  Length,
871  &SharedCacheMap->ValidDataLength);
872  if (!NT_SUCCESS(Status))
874  }
875  }
876 
877  return TRUE;
878 }
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
#define TRUE
Definition: types.h:120
NTSTATUS NTAPI MmMakeDataSectionResident(_In_ PSECTION_OBJECT_POINTERS SectionObjectPointer, _In_ LONGLONG Offset, _In_ ULONG Length, _In_ PLARGE_INTEGER ValidDataLength)
Definition: section.c:4728
_In_ WDFDPC _In_ BOOLEAN Wait
Definition: wdfdpc.h:167
BOOLEAN NTAPI MmArePagesResident(_In_ PEPROCESS Process, _In_ PVOID BaseAddress, _In_ ULONG Length)
Definition: section.c:4508
LONG NTSTATUS
Definition: precomp.h:26
#define ExRaiseStatus
Definition: ntoskrnl.h:104
uint32_t ULONG_PTR
Definition: typedefs.h:65
#define FALSE
Definition: types.h:117
void * PVOID
Definition: retypes.h:9
Status
Definition: gdiplustypes.h:24
_In_ HANDLE _Outptr_result_bytebuffer_ ViewSize PVOID * BaseAddress
Definition: mmfuncs.h:404
#define ASSERT(a)
Definition: mode.c:45
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
_In_ ULONG _In_ ULONG Offset
Definition: ntddpcm.h:101
#define NULL
Definition: types.h:112
#define DPRINT1
Definition: precomp.h:8
#define VACB_MAPPING_GRANULARITY
LARGE_INTEGER ValidDataLength
Definition: cc.h:178
PFILE_OBJECT FileObject
Definition: cc.h:179

Referenced by CcCopyRead(), CcCopyWrite(), CcMapData(), CcPerformReadAhead(), CcpPinData(), and CcZeroData().

◆ CcRosFlushDirtyPages()

NTSTATUS CcRosFlushDirtyPages ( ULONG  Target,
PULONG  Count,
BOOLEAN  Wait,
BOOLEAN  CalledFromLazy 
)

Definition at line 305 of file view.c.

310 {
311  PLIST_ENTRY current_entry;
313  KIRQL OldIrql;
314  BOOLEAN FlushAll = (Target == MAXULONG);
315 
316  DPRINT("CcRosFlushDirtyPages(Target %lu)\n", Target);
317 
318  (*Count) = 0;
319 
322 
323  current_entry = DirtyVacbListHead.Flink;
324  if (current_entry == &DirtyVacbListHead)
325  {
326  DPRINT("No Dirty pages\n");
327  }
328 
329  while (((current_entry != &DirtyVacbListHead) && (Target > 0)) || FlushAll)
330  {
331  PROS_SHARED_CACHE_MAP SharedCacheMap;
333  BOOLEAN Locked;
334 
335  if (current_entry == &DirtyVacbListHead)
336  {
337  ASSERT(FlushAll);
339  break;
340  current_entry = DirtyVacbListHead.Flink;
341  }
342 
343  current = CONTAINING_RECORD(current_entry,
344  ROS_VACB,
345  DirtyVacbListEntry);
346  current_entry = current_entry->Flink;
347 
349 
350  SharedCacheMap = current->SharedCacheMap;
351 
352  /* When performing lazy write, don't handle temporary files */
353  if (CalledFromLazy && BooleanFlagOn(SharedCacheMap->FileObject->Flags, FO_TEMPORARY_FILE))
354  {
356  continue;
357  }
358 
359  /* Don't attempt to lazy write the files that asked not to */
360  if (CalledFromLazy && BooleanFlagOn(SharedCacheMap->Flags, WRITEBEHIND_DISABLED))
361  {
363  continue;
364  }
365 
366  ASSERT(current->Dirty);
367 
368  /* Do not lazy-write the same file concurrently. Fastfat ASSERTS on that */
369  if (SharedCacheMap->Flags & SHARED_CACHE_MAP_IN_LAZYWRITE)
370  {
372  continue;
373  }
374 
375  SharedCacheMap->Flags |= SHARED_CACHE_MAP_IN_LAZYWRITE;
376 
377  /* Keep a ref on the shared cache map */
378  SharedCacheMap->OpenCount++;
379 
381 
382  Locked = SharedCacheMap->Callbacks->AcquireForLazyWrite(SharedCacheMap->LazyWriteContext, Wait);
383  if (!Locked)
384  {
385  DPRINT("Not locked!");
386  ASSERT(!Wait);
389  SharedCacheMap->Flags &= ~SHARED_CACHE_MAP_IN_LAZYWRITE;
390 
391  if (--SharedCacheMap->OpenCount == 0)
392  CcRosDeleteFileCache(SharedCacheMap->FileObject, SharedCacheMap, &OldIrql);
393 
394  continue;
395  }
396 
399 
400  SharedCacheMap->Callbacks->ReleaseFromLazyWrite(SharedCacheMap->LazyWriteContext);
401 
402  /* We release the VACB before acquiring the lock again, because
403  * CcRosVacbDecRefCount might free the VACB, as CcRosFlushVacb dropped a
404  * Refcount. Freeing must be done outside of the lock.
405  * The refcount is decremented atomically. So this is OK. */
408 
409  SharedCacheMap->Flags &= ~SHARED_CACHE_MAP_IN_LAZYWRITE;
410 
411  if (--SharedCacheMap->OpenCount == 0)
412  CcRosDeleteFileCache(SharedCacheMap->FileObject, SharedCacheMap, &OldIrql);
413 
414  if (!NT_SUCCESS(Status) && (Status != STATUS_END_OF_FILE) &&
416  {
417  DPRINT1("CC: Failed to flush VACB.\n");
418  }
419  else
420  {
421  ULONG PagesFreed;
422 
423  /* How many pages did we free? */
424  PagesFreed = Iosb.Information / PAGE_SIZE;
425  (*Count) += PagesFreed;
426 
427  if (!Wait)
428  {
429  /* Make sure we don't overflow target! */
430  if (Target < PagesFreed)
431  {
432  /* If we would have, jump to zero directly */
433  Target = 0;
434  }
435  else
436  {
437  Target -= PagesFreed;
438  }
439  }
440  }
441 
442  current_entry = DirtyVacbListHead.Flink;
443  }
444 
447 
448  DPRINT("CcRosFlushDirtyPages() finished\n");
449  return STATUS_SUCCESS;
450 }
Definition: cc.h:206
ULONG OpenCount
Definition: cc.h:174
#define BooleanFlagOn(F, SF)
Definition: ext2fs.h:183
_In_ WDFDPC _In_ BOOLEAN Wait
Definition: wdfdpc.h:167
LONG NTSTATUS
Definition: precomp.h:26
_Must_inspect_result_ FORCEINLINE BOOLEAN IsListEmpty(_In_ const LIST_ENTRY *ListHead)
Definition: rtlfuncs.h:57
#define SHARED_CACHE_MAP_IN_LAZYWRITE
Definition: cc.h:204
#define STATUS_END_OF_FILE
Definition: shellext.h:67
UCHAR KIRQL
Definition: env_spec_w32.h:591
_In_ PMEMORY_AREA _In_ PVOID _In_ BOOLEAN Locked
Definition: newmm.h:217
unsigned char BOOLEAN
#define STATUS_MEDIA_WRITE_PROTECTED
Definition: udferr_usr.h:161
PCACHE_MANAGER_CALLBACKS Callbacks
Definition: cc.h:185
#define WRITEBEHIND_DISABLED
Definition: cc.h:202
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
Status
Definition: gdiplustypes.h:24
struct _LIST_ENTRY * Flink
Definition: typedefs.h:121
#define ASSERT(a)
Definition: mode.c:45
return Iosb
Definition: create.c:4402
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
PACQUIRE_FOR_LAZY_WRITE AcquireForLazyWrite
Definition: cctypes.h:39
VOID FASTCALL KeReleaseQueuedSpinLock(IN KSPIN_LOCK_QUEUE_NUMBER LockNumber, IN KIRQL OldIrql)
Definition: spinlock.c:154
FORCEINLINE ULONG CcRosVacbDecRefCount(PROS_VACB vacb)
Definition: cc.h:492
_Requires_lock_held_ Interrupt _Releases_lock_ Interrupt _In_ _IRQL_restores_ KIRQL OldIrql
Definition: kefuncs.h:790
#define CcRosVacbIncRefCount(vacb)
Definition: cc.h:489
#define KeEnterCriticalRegion()
Definition: ke_x.h:83
#define PAGE_SIZE
Definition: env_spec_w32.h:49
Definition: typedefs.h:119
KIRQL FASTCALL KeAcquireQueuedSpinLock(IN KSPIN_LOCK_QUEUE_NUMBER LockNumber)
Definition: spinlock.c:108
NTSTATUS CcRosFlushVacb(_In_ PROS_VACB Vacb, _In_ PIO_STATUS_BLOCK Iosb)
Definition: view.c:159
#define MAXULONG
Definition: typedefs.h:251
#define KeLeaveCriticalRegion()
Definition: ke_x.h:114
static NTSTATUS CcRosDeleteFileCache(PFILE_OBJECT FileObject, PROS_SHARED_CACHE_MAP SharedCacheMap, PKIRQL OldIrql)
Definition: view.c:205
#define FO_TEMPORARY_FILE
Definition: iotypes.h:1788
_In_ WDFIOTARGET Target
Definition: wdfrequest.h:306
#define DPRINT1
Definition: precomp.h:8
PVOID LazyWriteContext
Definition: cc.h:186
PRELEASE_FROM_LAZY_WRITE ReleaseFromLazyWrite
Definition: cctypes.h:40
unsigned int ULONG
Definition: retypes.h:1
#define STATUS_SUCCESS
Definition: shellext.h:65
PFILE_OBJECT FileObject
Definition: cc.h:179
#define DPRINT
Definition: sndvol32.h:71
LIST_ENTRY DirtyVacbListHead
Definition: view.c:41
struct task_struct * current
Definition: linux.c:32

Referenced by CcWriteBehind(), and NtSetSystemPowerState().

◆ CcRosFlushVacb()

NTSTATUS CcRosFlushVacb ( PROS_VACB  Vacb,
PIO_STATUS_BLOCK  Iosb 
)

◆ CcRosGetVacb()

NTSTATUS CcRosGetVacb ( PROS_SHARED_CACHE_MAP  SharedCacheMap,
LONGLONG  FileOffset,
PROS_VACB Vacb 
)

Definition at line 882 of file view.c.

886 {
889  ULONG Refs;
890  KIRQL OldIrql;
891 
892  ASSERT(SharedCacheMap);
893 
894  DPRINT("CcRosGetVacb()\n");
895 
896  /*
897  * Look for a VACB already mapping the same data.
898  */
899  current = CcRosLookupVacb(SharedCacheMap, FileOffset);
900  if (current == NULL)
901  {
902  /*
903  * Otherwise create a new VACB.
904  */
905  Status = CcRosCreateVacb(SharedCacheMap, FileOffset, &current);
906  if (!NT_SUCCESS(Status))
907  {
908  return Status;
909  }
910  }
911 
913 
915 
916  /* Move to the tail of the LRU list */
917  RemoveEntryList(&current->VacbLruListEntry);
918  InsertTailList(&VacbLruListHead, &current->VacbLruListEntry);
919 
921 
922  /*
923  * Return the VACB to the caller.
924  */
925  *Vacb = current;
926 
927  ASSERT(Refs > 1);
928 
929  return STATUS_SUCCESS;
930 }
Definition: cc.h:206
LONG NTSTATUS
Definition: precomp.h:26
static LIST_ENTRY VacbLruListHead
Definition: view.c:42
#define InsertTailList(ListHead, Entry)
FORCEINLINE BOOLEAN RemoveEntryList(_In_ PLIST_ENTRY Entry)
Definition: rtlfuncs.h:105
UCHAR KIRQL
Definition: env_spec_w32.h:591
#define CcRosVacbGetRefCount(vacb)
Definition: cc.h:504
Status
Definition: gdiplustypes.h:24
#define ASSERT(a)
Definition: mode.c:45
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
VOID FASTCALL KeReleaseQueuedSpinLock(IN KSPIN_LOCK_QUEUE_NUMBER LockNumber, IN KIRQL OldIrql)
Definition: spinlock.c:154
_Requires_lock_held_ Interrupt _Releases_lock_ Interrupt _In_ _IRQL_restores_ KIRQL OldIrql
Definition: kefuncs.h:790
KIRQL FASTCALL KeAcquireQueuedSpinLock(IN KSPIN_LOCK_QUEUE_NUMBER LockNumber)
Definition: spinlock.c:108
static NTSTATUS CcRosCreateVacb(PROS_SHARED_CACHE_MAP SharedCacheMap, LONGLONG FileOffset, PROS_VACB *Vacb)
Definition: view.c:682
_In_ PFCB _In_ LONGLONG FileOffset
Definition: cdprocs.h:159
#define NULL
Definition: types.h:112
unsigned int ULONG
Definition: retypes.h:1
PROS_VACB CcRosLookupVacb(PROS_SHARED_CACHE_MAP SharedCacheMap, LONGLONG FileOffset)
Definition: view.c:485
#define STATUS_SUCCESS
Definition: shellext.h:65
#define DPRINT
Definition: sndvol32.h:71
struct task_struct * current
Definition: linux.c:32

Referenced by CcCopyRead(), CcCopyWrite(), CcMapData(), CcpPinData(), CcRosRequestVacb(), and CcZeroData().

◆ CcRosInitializeFileCache()

NTSTATUS CcRosInitializeFileCache ( PFILE_OBJECT  FileObject,
PCC_FILE_SIZES  FileSizes,
BOOLEAN  PinAccess,
PCACHE_MANAGER_CALLBACKS  CallBacks,
PVOID  LazyWriterContext 
)

Definition at line 1185 of file view.c.

1194 {
1195  KIRQL OldIrql;
1197  PROS_SHARED_CACHE_MAP SharedCacheMap;
1198 
1199  DPRINT("CcRosInitializeFileCache(FileObject 0x%p)\n", FileObject);
1200 
1202 
1203  Allocated = FALSE;
1204  SharedCacheMap = FileObject->SectionObjectPointer->SharedCacheMap;
1205  if (SharedCacheMap == NULL)
1206  {
1207  Allocated = TRUE;
1208  SharedCacheMap = ExAllocateFromNPagedLookasideList(&SharedCacheMapLookasideList);
1209  if (SharedCacheMap == NULL)
1210  {
1212  }
1213  RtlZeroMemory(SharedCacheMap, sizeof(*SharedCacheMap));
1214  SharedCacheMap->NodeTypeCode = NODE_TYPE_SHARED_MAP;
1215  SharedCacheMap->NodeByteSize = sizeof(*SharedCacheMap);
1216  SharedCacheMap->FileObject = FileObject;
1217  SharedCacheMap->Callbacks = CallBacks;
1218  SharedCacheMap->LazyWriteContext = LazyWriterContext;
1219  SharedCacheMap->SectionSize = FileSizes->AllocationSize;
1220  SharedCacheMap->FileSize = FileSizes->FileSize;
1221  SharedCacheMap->ValidDataLength = FileSizes->ValidDataLength;
1222  SharedCacheMap->PinAccess = PinAccess;
1223  SharedCacheMap->DirtyPageThreshold = 0;
1224  SharedCacheMap->DirtyPages = 0;
1225  InitializeListHead(&SharedCacheMap->PrivateList);
1226  KeInitializeSpinLock(&SharedCacheMap->CacheMapLock);
1227  InitializeListHead(&SharedCacheMap->CacheMapVacbListHead);
1228  InitializeListHead(&SharedCacheMap->BcbList);
1229 
1230  SharedCacheMap->Flags = SHARED_CACHE_MAP_IN_CREATION;
1231 
1234  NULL,
1235  KernelMode);
1236 
1237  FileObject->SectionObjectPointer->SharedCacheMap = SharedCacheMap;
1238 
1239  //CcRosTraceCacheMap(SharedCacheMap, TRUE);
1240  }
1241  else if (SharedCacheMap->Flags & SHARED_CACHE_MAP_IN_CREATION)
1242  {
1243  /* The shared cache map is being created somewhere else. Wait for that to happen */
1244  KEVENT Waiter;
1245  PKEVENT PreviousWaiter = SharedCacheMap->CreateEvent;
1246 
1248  SharedCacheMap->CreateEvent = &Waiter;
1249 
1251 
1253 
1254  if (PreviousWaiter)
1255  KeSetEvent(PreviousWaiter, IO_NO_INCREMENT, FALSE);
1256 
1258  }
1259 
1260  if (FileObject->PrivateCacheMap == NULL)
1261  {
1262  PPRIVATE_CACHE_MAP PrivateMap;
1263 
1264  /* Allocate the private cache map for this handle */
1265  if (SharedCacheMap->PrivateCacheMap.NodeTypeCode != 0)
1266  {
1268  }
1269  else
1270  {
1271  PrivateMap = &SharedCacheMap->PrivateCacheMap;
1272  }
1273 
1274  if (PrivateMap == NULL)
1275  {
1276  /* If we also allocated the shared cache map for this file, kill it */
1277  if (Allocated)
1278  {
1279  RemoveEntryList(&SharedCacheMap->SharedCacheMapLinks);
1280 
1281  FileObject->SectionObjectPointer->SharedCacheMap = NULL;
1283  ExFreeToNPagedLookasideList(&SharedCacheMapLookasideList, SharedCacheMap);
1284  }
1285 
1288  }
1289 
1290  /* Initialize it */
1291  RtlZeroMemory(PrivateMap, sizeof(PRIVATE_CACHE_MAP));
1292  PrivateMap->NodeTypeCode = NODE_TYPE_PRIVATE_MAP;
1293  PrivateMap->ReadAheadMask = PAGE_SIZE - 1;
1294  PrivateMap->FileObject = FileObject;
1296 
1297  /* Link it to the file */
1298  KeAcquireSpinLockAtDpcLevel(&SharedCacheMap->CacheMapLock);
1299  InsertTailList(&SharedCacheMap->PrivateList, &PrivateMap->PrivateLinks);
1300  KeReleaseSpinLockFromDpcLevel(&SharedCacheMap->CacheMapLock);
1301 
1302  FileObject->PrivateCacheMap = PrivateMap;
1303  SharedCacheMap->OpenCount++;
1304  }
1305 
1307 
1308  /* Create the section */
1309  if (Allocated)
1310  {
1311  NTSTATUS Status;
1312 
1313  ASSERT(SharedCacheMap->Section == NULL);
1314 
1316  &SharedCacheMap->Section,
1318  NULL,
1319  &SharedCacheMap->SectionSize,
1321  SEC_RESERVE,
1322  NULL,
1323  FileObject);
1324 
1326 
1327  if (!NT_SUCCESS(Status))
1328  {
1330  return Status;
1331  }
1332 
1334 
1336  SharedCacheMap->Flags &= ~SHARED_CACHE_MAP_IN_CREATION;
1337 
1338  if (SharedCacheMap->CreateEvent)
1339  {
1340  KeSetEvent(SharedCacheMap->CreateEvent, IO_NO_INCREMENT, FALSE);
1341  SharedCacheMap->CreateEvent = NULL;
1342  }
1343 
1345  }
1346 
1347  return STATUS_SUCCESS;
1348 }
BOOLEAN PinAccess
Definition: cc.h:194
LIST_ENTRY PrivateList
Definition: cc.h:187
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
#define FILE_ALL_ACCESS
Definition: nt_native.h:651
ULONG OpenCount
Definition: cc.h:174
LARGE_INTEGER SectionSize
Definition: cc.h:177
#define SHARED_CACHE_MAP_IN_CREATION
Definition: cc.h:203
#define TRUE
Definition: types.h:120
LIST_ENTRY SharedCacheMapLinks
Definition: cc.h:181
VOID NTAPI KeAcquireSpinLockAtDpcLevel(IN PKSPIN_LOCK SpinLock)
Definition: spinlock.c:192
LONG NTSTATUS
Definition: precomp.h:26
LIST_ENTRY BcbList
Definition: cc.h:176
static CC_FILE_SIZES FileSizes
#define InsertTailList(ListHead, Entry)
LONG NTAPI KeSetEvent(IN PKEVENT Event, IN KPRIORITY Increment, IN BOOLEAN Wait)
Definition: eventobj.c:159
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
ULONG ReadAheadMask
Definition: cctypes.h:75
LARGE_INTEGER FileSize
Definition: cctypes.h:16
FORCEINLINE BOOLEAN RemoveEntryList(_In_ PLIST_ENTRY Entry)
Definition: rtlfuncs.h:105
UCHAR KIRQL
Definition: env_spec_w32.h:591
#define SECTION_ALL_ACCESS
Definition: nt_native.h:1293
#define FALSE
Definition: types.h:117
#define SEC_RESERVE
Definition: nt_native.h:1323
FORCEINLINE VOID KeInitializeSpinLock(_Out_ PKSPIN_LOCK SpinLock)
Definition: kefuncs.h:238
unsigned char BOOLEAN
IN PFCB IN VBO OUT PLBO OUT PULONG OUT PBOOLEAN Allocated
Definition: fatprocs.h:306
NTSTATUS NTAPI ObReferenceObjectByPointer(IN PVOID Object, IN ACCESS_MASK DesiredAccess, IN POBJECT_TYPE ObjectType, IN KPROCESSOR_MODE AccessMode)
Definition: obref.c:383
PCACHE_MANAGER_CALLBACKS Callbacks
Definition: cc.h:185
LIST_ENTRY CcCleanSharedCacheMapList
Definition: view.c:59
_In_ WDFREQUEST _In_ WDFFILEOBJECT FileObject
Definition: wdfdevice.h:547
LIST_ENTRY CacheMapVacbListHead
Definition: cc.h:193
KSPIN_LOCK ReadAheadSpinLock
Definition: cctypes.h:83
Status
Definition: gdiplustypes.h:24
static NPAGED_LOOKASIDE_LIST SharedCacheMapLookasideList
Definition: view.c:45
#define ASSERT(a)
Definition: mode.c:45
LIST_ENTRY PrivateLinks
Definition: cctypes.h:84
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
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:4353
VOID NTAPI KeReleaseSpinLockFromDpcLevel(IN PKSPIN_LOCK SpinLock)
Definition: spinlock.c:215
#define ObDereferenceObject
Definition: obfuncs.h:203
VOID FASTCALL KeReleaseQueuedSpinLock(IN KSPIN_LOCK_QUEUE_NUMBER LockNumber, IN KIRQL OldIrql)
Definition: spinlock.c:154
CSHORT NodeTypeCode
Definition: cc.h:172
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
NTSTATUS CcRosReleaseFileCache(PFILE_OBJECT FileObject)
Definition: view.c:1129
_Requires_lock_held_ Interrupt _Releases_lock_ Interrupt _In_ _IRQL_restores_ KIRQL OldIrql
Definition: kefuncs.h:790
LARGE_INTEGER ValidDataLength
Definition: cctypes.h:17
#define PAGE_SIZE
Definition: env_spec_w32.h:49
KIRQL FASTCALL KeAcquireQueuedSpinLock(IN KSPIN_LOCK_QUEUE_NUMBER LockNumber)
Definition: spinlock.c:108
PFILE_OBJECT FileObject
Definition: cctypes.h:76
CSHORT NodeByteSize
Definition: cc.h:173
#define NODE_TYPE_PRIVATE_MAP
Definition: cc.h:287
PRIVATE_CACHE_MAP PrivateCacheMap
Definition: cc.h:190
#define KeInitializeEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:477
LARGE_INTEGER AllocationSize
Definition: cctypes.h:15
#define InitializeListHead(ListHead)
Definition: env_spec_w32.h:944
#define NULL
Definition: types.h:112
PVOID LazyWriteContext
Definition: cc.h:186
LARGE_INTEGER FileSize
Definition: cc.h:175
#define IO_NO_INCREMENT
Definition: iotypes.h:598
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
LARGE_INTEGER ValidDataLength
Definition: cc.h:178
#define TAG_PRIVATE_CACHE_MAP
Definition: tag.h:7
PKEVENT CreateEvent
Definition: cc.h:184
#define STATUS_SUCCESS
Definition: shellext.h:65
KSPIN_LOCK CacheMapLock
Definition: cc.h:195
CSHORT NodeTypeCode
Definition: cctypes.h:71
PFILE_OBJECT FileObject
Definition: cc.h:179
#define DPRINT
Definition: sndvol32.h:71
ULONG DirtyPageThreshold
Definition: cc.h:188
#define NODE_TYPE_SHARED_MAP
Definition: cc.h:288
ULONG DirtyPages
Definition: cc.h:180
#define PAGE_READWRITE
Definition: nt_native.h:1304

Referenced by CcInitializeCacheMap().

◆ CcRosInternalFreeVacb()

NTSTATUS CcRosInternalFreeVacb ( IN PROS_VACB  Vacb)

Referenced by CcRosVacbDecRefCount().

◆ CcRosLookupVacb()

PROS_VACB CcRosLookupVacb ( PROS_SHARED_CACHE_MAP  SharedCacheMap,
LONGLONG  FileOffset 
)

Definition at line 485 of file view.c.

488 {
489  PLIST_ENTRY current_entry;
491  KIRQL oldIrql;
492 
493  ASSERT(SharedCacheMap);
494 
495  DPRINT("CcRosLookupVacb(SharedCacheMap 0x%p, FileOffset %I64u)\n",
496  SharedCacheMap, FileOffset);
497 
499  KeAcquireSpinLockAtDpcLevel(&SharedCacheMap->CacheMapLock);
500 
501  current_entry = SharedCacheMap->CacheMapVacbListHead.Flink;
502  while (current_entry != &SharedCacheMap->CacheMapVacbListHead)
503  {
504  current = CONTAINING_RECORD(current_entry,
505  ROS_VACB,
506  CacheMapVacbListEntry);
507  if (IsPointInRange(current->FileOffset.QuadPart,
509  FileOffset))
510  {
514  return current;
515  }
516  if (current->FileOffset.QuadPart > FileOffset)
517  break;
518  current_entry = current_entry->Flink;
519  }
520 
523 
524  return NULL;
525 }
Definition: cc.h:206
VOID NTAPI KeAcquireSpinLockAtDpcLevel(IN PKSPIN_LOCK SpinLock)
Definition: spinlock.c:192
UCHAR KIRQL
Definition: env_spec_w32.h:591
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
LIST_ENTRY CacheMapVacbListHead
Definition: cc.h:193
FORCEINLINE BOOLEAN IsPointInRange(_In_ LONGLONG Offset1, _In_ LONGLONG Length1, _In_ LONGLONG Point)
Definition: cc.h:455
struct _LIST_ENTRY * Flink
Definition: typedefs.h:121
#define ASSERT(a)
Definition: mode.c:45
VOID NTAPI KeReleaseSpinLockFromDpcLevel(IN PKSPIN_LOCK SpinLock)
Definition: spinlock.c:215
VOID FASTCALL KeReleaseQueuedSpinLock(IN KSPIN_LOCK_QUEUE_NUMBER LockNumber, IN KIRQL OldIrql)
Definition: spinlock.c:154
#define CcRosVacbIncRefCount(vacb)
Definition: cc.h:489
Definition: typedefs.h:119
KIRQL FASTCALL KeAcquireQueuedSpinLock(IN KSPIN_LOCK_QUEUE_NUMBER LockNumber)
Definition: spinlock.c:108
_In_ PFCB _In_ LONGLONG FileOffset
Definition: cdprocs.h:159
#define NULL
Definition: types.h:112
#define VACB_MAPPING_GRANULARITY
KSPIN_LOCK CacheMapLock
Definition: cc.h:195
#define DPRINT
Definition: sndvol32.h:71
struct task_struct * current
Definition: linux.c:32

Referenced by CcFlushCache(), and CcRosGetVacb().

◆ CcRosMarkDirtyVacb()

VOID CcRosMarkDirtyVacb ( PROS_VACB  Vacb)

Definition at line 528 of file view.c.

530 {
531  KIRQL oldIrql;
532  PROS_SHARED_CACHE_MAP SharedCacheMap;
533 
534  SharedCacheMap = Vacb->SharedCacheMap;
535 
537  KeAcquireSpinLockAtDpcLevel(&SharedCacheMap->CacheMapLock);
538 
539  ASSERT(!Vacb->Dirty);
540 
542  /* FIXME: There is no reason to account for the whole VACB. */
545  CcRosVacbIncRefCount(Vacb);
546 
547  /* Move to the tail of the LRU list */
550 
551  Vacb->Dirty = TRUE;
552 
554 
555  /* Schedule a lazy writer run to now that we have dirty VACB */
556  if (!LazyWriter.ScanActive)
557  {
559  }
561 }
#define TRUE
Definition: types.h:120
VOID NTAPI KeAcquireSpinLockAtDpcLevel(IN PKSPIN_LOCK SpinLock)
Definition: spinlock.c:192
static LIST_ENTRY VacbLruListHead
Definition: view.c:42
#define InsertTailList(ListHead, Entry)
FORCEINLINE BOOLEAN RemoveEntryList(_In_ PLIST_ENTRY Entry)
Definition: rtlfuncs.h:105
UCHAR KIRQL
Definition: env_spec_w32.h:591
LAZY_WRITER LazyWriter
Definition: lazywrite.c:37
#define FALSE
Definition: types.h:117
PROS_SHARED_CACHE_MAP SharedCacheMap
Definition: cc.h:226
#define ASSERT(a)
Definition: mode.c:45
VOID NTAPI KeReleaseSpinLockFromDpcLevel(IN PKSPIN_LOCK SpinLock)
Definition: spinlock.c:215
BOOLEAN ScanActive
Definition: cc.h:246
VOID FASTCALL KeReleaseQueuedSpinLock(IN KSPIN_LOCK_QUEUE_NUMBER LockNumber, IN KIRQL OldIrql)
Definition: spinlock.c:154
BOOLEAN Dirty
Definition: cc.h:211
ULONG CcTotalDirtyPages
Definition: view.c:56
#define CcRosVacbIncRefCount(vacb)
Definition: cc.h:489
#define PAGE_SIZE
Definition: env_spec_w32.h:49
KIRQL FASTCALL KeAcquireQueuedSpinLock(IN KSPIN_LOCK_QUEUE_NUMBER LockNumber)
Definition: spinlock.c:108
VOID CcScheduleLazyWriteScan(IN BOOLEAN NoDelay)
Definition: lazywrite.c:200
#define VACB_MAPPING_GRANULARITY
LIST_ENTRY DirtyVacbListEntry
Definition: cc.h:218
KSPIN_LOCK CacheMapLock
Definition: cc.h:195
LIST_ENTRY DirtyVacbListHead
Definition: view.c:41
ULONG DirtyPages
Definition: cc.h:180
LIST_ENTRY VacbLruListEntry
Definition: cc.h:220

Referenced by CcRosFlushVacb(), CcRosReleaseVacb(), and CcSetDirtyPinnedData().

◆ CcRosReferenceCache()

VOID CcRosReferenceCache ( PFILE_OBJECT  FileObject)

◆ CcRosReleaseFileCache()

NTSTATUS CcRosReleaseFileCache ( PFILE_OBJECT  FileObject)

Definition at line 1129 of file view.c.

1135 {
1136  KIRQL OldIrql;
1137  PPRIVATE_CACHE_MAP PrivateMap;
1138  PROS_SHARED_CACHE_MAP SharedCacheMap;
1139 
1141 
1142  if (FileObject->SectionObjectPointer->SharedCacheMap != NULL)
1143  {
1144  SharedCacheMap = FileObject->SectionObjectPointer->SharedCacheMap;
1145 
1146  /* Closing the handle, so kill the private cache map
1147  * Before you event try to remove it from FO, always
1148  * lock the master lock, to be sure not to race
1149  * with a potential read ahead ongoing!
1150  */
1151  PrivateMap = FileObject->PrivateCacheMap;
1152  FileObject->PrivateCacheMap = NULL;
1153 
1154  if (PrivateMap != NULL)
1155  {
1156  /* Remove it from the file */
1157  KeAcquireSpinLockAtDpcLevel(&SharedCacheMap->CacheMapLock);
1158  RemoveEntryList(&PrivateMap->PrivateLinks);
1159  KeReleaseSpinLockFromDpcLevel(&SharedCacheMap->CacheMapLock);
1160 
1161  /* And free it. */
1162  if (PrivateMap != &SharedCacheMap->PrivateCacheMap)
1163  {
1165  }
1166  else
1167  {
1168  PrivateMap->NodeTypeCode = 0;
1169  }
1170 
1171  ASSERT(SharedCacheMap->OpenCount > 0);
1172 
1173  SharedCacheMap->OpenCount--;
1174  if (SharedCacheMap->OpenCount == 0)
1175  {
1176  CcRosDeleteFileCache(FileObject, SharedCacheMap, &OldIrql);
1177  }
1178  }
1179  }
1181  return STATUS_SUCCESS;
1182 }
ULONG OpenCount
Definition: cc.h:174
VOID NTAPI KeAcquireSpinLockAtDpcLevel(IN PKSPIN_LOCK SpinLock)
Definition: spinlock.c:192
FORCEINLINE BOOLEAN RemoveEntryList(_In_ PLIST_ENTRY Entry)
Definition: rtlfuncs.h:105
UCHAR KIRQL
Definition: env_spec_w32.h:591
_In_ WDFREQUEST _In_ WDFFILEOBJECT FileObject
Definition: wdfdevice.h:547
#define ASSERT(a)
Definition: mode.c:45
LIST_ENTRY PrivateLinks
Definition: cctypes.h:84
VOID NTAPI KeReleaseSpinLockFromDpcLevel(IN PKSPIN_LOCK SpinLock)
Definition: spinlock.c:215
VOID FASTCALL KeReleaseQueuedSpinLock(IN KSPIN_LOCK_QUEUE_NUMBER LockNumber, IN KIRQL OldIrql)
Definition: spinlock.c:154
_Requires_lock_held_ Interrupt _Releases_lock_ Interrupt _In_ _IRQL_restores_ KIRQL OldIrql
Definition: kefuncs.h:790
KIRQL FASTCALL KeAcquireQueuedSpinLock(IN KSPIN_LOCK_QUEUE_NUMBER LockNumber)
Definition: spinlock.c:108
PRIVATE_CACHE_MAP PrivateCacheMap
Definition: cc.h:190
static NTSTATUS CcRosDeleteFileCache(PFILE_OBJECT FileObject, PROS_SHARED_CACHE_MAP SharedCacheMap, PKIRQL OldIrql)
Definition: view.c:205
#define NULL
Definition: types.h:112
#define TAG_PRIVATE_CACHE_MAP
Definition: tag.h:7
#define STATUS_SUCCESS
Definition: shellext.h:65
KSPIN_LOCK CacheMapLock
Definition: cc.h:195
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1099
CSHORT NodeTypeCode
Definition: cctypes.h:71

Referenced by CcRosInitializeFileCache(), and CcUninitializeCacheMap().

◆ CcRosReleaseVacb()

NTSTATUS CcRosReleaseVacb ( PROS_SHARED_CACHE_MAP  SharedCacheMap,
PROS_VACB  Vacb,
BOOLEAN  Dirty,
BOOLEAN  Mapped 
)

Definition at line 453 of file view.c.

458 {
459  ULONG Refs;
460  ASSERT(SharedCacheMap);
461 
462  DPRINT("CcRosReleaseVacb(SharedCacheMap 0x%p, Vacb 0x%p)\n", SharedCacheMap, Vacb);
463 
464  if (Dirty && !Vacb->Dirty)
465  {
466  CcRosMarkDirtyVacb(Vacb);
467  }
468 
469  if (Mapped)
470  {
471  if (InterlockedIncrement((PLONG)&Vacb->MappedCount) == 1)
472  {
473  CcRosVacbIncRefCount(Vacb);
474  }
475  }
476 
477  Refs = CcRosVacbDecRefCount(Vacb);
478  ASSERT(Refs > 0);
479 
480  return STATUS_SUCCESS;
481 }
ULONG MappedCount
Definition: cc.h:214
#define ASSERT(a)
Definition: mode.c:45
FORCEINLINE ULONG CcRosVacbDecRefCount(PROS_VACB vacb)
Definition: cc.h:492
VOID CcRosMarkDirtyVacb(PROS_VACB Vacb)
Definition: view.c:528
BOOLEAN Dirty
Definition: cc.h:211
#define CcRosVacbIncRefCount(vacb)
Definition: cc.h:489
#define InterlockedIncrement
Definition: armddk.h:53
unsigned int ULONG
Definition: retypes.h:1
#define STATUS_SUCCESS
Definition: shellext.h:65
#define DPRINT
Definition: sndvol32.h:71
signed int * PLONG
Definition: retypes.h:5

Referenced by CcCopyRead(), CcCopyWrite(), CcFlushCache(), CcMapData(), CcpDereferenceBcb(), CcPerformReadAhead(), CcpGetAppropriateBcb(), CcpPinData(), CcUnpinRepinnedBcb(), and CcZeroData().

◆ CcRosRequestVacb()

NTSTATUS CcRosRequestVacb ( PROS_SHARED_CACHE_MAP  SharedCacheMap,
LONGLONG  FileOffset,
PROS_VACB Vacb 
)

Definition at line 933 of file view.c.

940 {
941 
942  ASSERT(SharedCacheMap);
943 
945  {
946  DPRINT1("Bad fileoffset %I64x should be multiple of %x",
948  KeBugCheck(CACHE_MANAGER);
949  }
950 
951  return CcRosGetVacb(SharedCacheMap,
952  FileOffset,
953  Vacb);
954 }
NTSTATUS CcRosGetVacb(PROS_SHARED_CACHE_MAP SharedCacheMap, LONGLONG FileOffset, PROS_VACB *Vacb)
Definition: view.c:882
DECLSPEC_NORETURN VOID NTAPI KeBugCheck(ULONG BugCheckCode)
Definition: bug.c:1427
#define ASSERT(a)
Definition: mode.c:45
_In_ PFCB _In_ LONGLONG FileOffset
Definition: cdprocs.h:159
#define DPRINT1
Definition: precomp.h:8
#define VACB_MAPPING_GRANULARITY

Referenced by CcPerformReadAhead().

◆ CcRosUnmarkDirtyVacb()

VOID CcRosUnmarkDirtyVacb ( PROS_VACB  Vacb,
BOOLEAN  LockViews 
)

Definition at line 564 of file view.c.

567 {
568  KIRQL oldIrql;
569  PROS_SHARED_CACHE_MAP SharedCacheMap;
570 
571  SharedCacheMap = Vacb->SharedCacheMap;
572 
573  if (LockViews)
574  {
576  KeAcquireSpinLockAtDpcLevel(&SharedCacheMap->CacheMapLock);
577  }
578 
579  ASSERT(Vacb->Dirty);
580 
581  Vacb->Dirty = FALSE;
582 
585 
588 
589  CcRosVacbDecRefCount(Vacb);
590 
591  if (LockViews)
592  {
595  }
596 }
VOID NTAPI KeAcquireSpinLockAtDpcLevel(IN PKSPIN_LOCK SpinLock)
Definition: spinlock.c:192
FORCEINLINE BOOLEAN RemoveEntryList(_In_ PLIST_ENTRY Entry)
Definition: rtlfuncs.h:105
UCHAR KIRQL
Definition: env_spec_w32.h:591
#define FALSE
Definition: types.h:117
PROS_SHARED_CACHE_MAP SharedCacheMap
Definition: cc.h:226
#define ASSERT(a)
Definition: mode.c:45
VOID NTAPI KeReleaseSpinLockFromDpcLevel(IN PKSPIN_LOCK SpinLock)
Definition: spinlock.c:215
VOID FASTCALL KeReleaseQueuedSpinLock(IN KSPIN_LOCK_QUEUE_NUMBER LockNumber, IN KIRQL OldIrql)
Definition: spinlock.c:154
FORCEINLINE ULONG CcRosVacbDecRefCount(PROS_VACB vacb)
Definition: cc.h:492
BOOLEAN Dirty
Definition: cc.h:211
ULONG CcTotalDirtyPages
Definition: view.c:56
#define PAGE_SIZE
Definition: env_spec_w32.h:49
KIRQL FASTCALL KeAcquireQueuedSpinLock(IN KSPIN_LOCK_QUEUE_NUMBER LockNumber)
Definition: spinlock.c:108
#define InitializeListHead(ListHead)
Definition: env_spec_w32.h:944
#define VACB_MAPPING_GRANULARITY
LIST_ENTRY DirtyVacbListEntry
Definition: cc.h:218
KSPIN_LOCK CacheMapLock
Definition: cc.h:195
ULONG DirtyPages
Definition: cc.h:180

Referenced by CcPurgeCacheSection(), CcRosDeleteFileCache(), and CcRosFlushVacb().

◆ CcRosVacbDecRefCount()

FORCEINLINE ULONG CcRosVacbDecRefCount ( PROS_VACB  vacb)

Definition at line 492 of file cc.h.

494 {
495  ULONG Refs;
496 
497  Refs = InterlockedDecrement((PLONG)&vacb->ReferenceCount);
498  if (Refs == 0)
499  {
500  CcRosInternalFreeVacb(vacb);
501  }
502  return Refs;
503 }
volatile ULONG ReferenceCount
Definition: cc.h:224
#define InterlockedDecrement
Definition: armddk.h:52
unsigned int ULONG
Definition: retypes.h:1
NTSTATUS CcRosInternalFreeVacb(IN PROS_VACB Vacb)
signed int * PLONG
Definition: retypes.h:5

Referenced by CcPurgeCacheSection(), CcRosCreateVacb(), CcRosDeleteFileCache(), CcRosFlushDirtyPages(), CcRosFreeUnusedVacb(), CcRosReleaseVacb(), and CcRosUnmarkDirtyVacb().

◆ CcScanDpc()

VOID NTAPI CcScanDpc ( PKDPC  Dpc,
PVOID  DeferredContext,
PVOID  SystemArgument1,
PVOID  SystemArgument2 
)

◆ CcScheduleLazyWriteScan()

VOID CcScheduleLazyWriteScan ( BOOLEAN  NoDelay)

◆ CcShutdownLazyWriter()

VOID NTAPI CcShutdownLazyWriter ( VOID  )

◆ CcShutdownSystem()

VOID NTAPI CcShutdownSystem ( VOID  )

Definition at line 299 of file cachesub.c.

300 {
301  ULONG i, Result;
303 
304  DPRINT1("CC: Shutdown\n");
305 
306  for (i = 0; i < CACHE_NUM_SECTIONS; i++)
307  {
309  if (Bcb->SectionObject)
310  {
311  DPRINT1("Evicting #%02x %08x%08x %wZ\n",
312  i,
313  Bcb->FileOffset.u.HighPart,
314  Bcb->FileOffset.u.LowPart,
315  &MmGetFileObjectForSection((PROS_SECTION_OBJECT)Bcb->SectionObject)->FileName);
316 
317  CcpFlushCache(Bcb->Map, NULL, 0, NULL, TRUE);
318  Bcb->Dirty = FALSE;
319  }
320  }
321 
322  /* Evict all section pages */
323  Status = MiRosTrimCache(~0, 0, &Result);
324 
325  DPRINT1("Done (Evicted %d, Status %x)\n", Result, Status);
326 }
PFILE_OBJECT NTAPI MmGetFileObjectForSection(IN PVOID Section)
Definition: section.c:1733
IN PVCB IN VBO IN ULONG OUT PBCB * Bcb
Definition: fatprocs.h:411
#define TRUE
Definition: types.h:120
#define CACHE_NUM_SECTIONS
Definition: newcc.h:123
LONG NTSTATUS
Definition: precomp.h:26
#define CcpFlushCache(M, F, L, I, D)
Definition: newcc.h:89
NTSTATUS MiRosTrimCache(ULONG Target, ULONG Priority, PULONG NrFreed)
Definition: swapout.c:633
Definition: newcc.h:3
NOCC_BCB CcCacheSections[CACHE_NUM_SECTIONS]
Definition: pinsup.c:98
#define FALSE
Definition: types.h:117
_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
Status
Definition: gdiplustypes.h:24
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
#define NULL
Definition: types.h:112
#define DPRINT1
Definition: precomp.h:8
unsigned int ULONG
Definition: retypes.h:1

Referenced by PopGracefulShutdown().

◆ CcWorkerThread()

VOID NTAPI CcWorkerThread ( PVOID  Parameter)

◆ DoRangesIntersect()

FORCEINLINE BOOLEAN DoRangesIntersect ( _In_ LONGLONG  Offset1,
_In_ LONGLONG  Length1,
_In_ LONGLONG  Offset2,
_In_ LONGLONG  Length2 
)

Definition at line 440 of file cc.h.

445 {
446  if (Offset1 + Length1 <= Offset2)
447  return FALSE;
448  if (Offset2 + Length2 <= Offset1)
449  return FALSE;
450  return TRUE;
451 }
#define TRUE
Definition: types.h:120
INT Length2
Definition: FsRtlDissect.c:16
INT Length1
Definition: FsRtlDissect.c:15
#define FALSE
Definition: types.h:117
INT Offset1
Definition: FsRtlDissect.c:13
INT Offset2
Definition: FsRtlDissect.c:14

Referenced by IsPointInRange().

◆ IsPointInRange()

FORCEINLINE BOOLEAN IsPointInRange ( _In_ LONGLONG  Offset1,
_In_ LONGLONG  Length1,
_In_ LONGLONG  Point 
)

Definition at line 455 of file cc.h.

459 {
460  return DoRangesIntersect(Offset1, Length1, Point, 1);
461 }
INT Length1
Definition: FsRtlDissect.c:15
FORCEINLINE BOOLEAN DoRangesIntersect(_In_ LONGLONG Offset1, _In_ LONGLONG Length1, _In_ LONGLONG Offset2, _In_ LONGLONG Length2)
Definition: cc.h:440
INT Offset1
Definition: FsRtlDissect.c:13

Referenced by CcRosCreateVacb(), and CcRosLookupVacb().

Variable Documentation

◆ CcDataFlushes

ULONG CcDataFlushes

Definition at line 44 of file copy.c.

Referenced by IoSynchronousPageWrite(), and QSI_DEF().

◆ CcDataPages

ULONG CcDataPages

Definition at line 43 of file copy.c.

Referenced by IoSynchronousPageWrite(), and QSI_DEF().

◆ CcDeferredWrites

LIST_ENTRY CcDeferredWrites

◆ CcDeferredWriteSpinLock

KSPIN_LOCK CcDeferredWriteSpinLock

Definition at line 58 of file view.c.

Referenced by CcCanIWrite(), CcDeferWrite(), CcInitView(), and CcPostDeferredWrites().

◆ CcDirtyPageThreshold

ULONG CcDirtyPageThreshold

Definition at line 55 of file view.c.

Referenced by CcCanIWrite(), and CcInitializeCacheManager().

◆ CcExpressWorkQueue

LIST_ENTRY CcExpressWorkQueue

Definition at line 39 of file lazywrite.c.

Referenced by CcInitializeCacheManager(), CcScheduleReadAhead(), and CcWorkerThread().

◆ CcIdleDelay

LARGE_INTEGER CcIdleDelay

Definition at line 46 of file lazywrite.c.

Referenced by CcCanIWrite(), and CcScheduleLazyWriteScan().

◆ CcIdleWorkerThreadList

LIST_ENTRY CcIdleWorkerThreadList

Definition at line 41 of file lazywrite.c.

Referenced by CcInitializeCacheManager(), CcPostWorkQueue(), and CcWorkerThread().

◆ CcLazyWriteIos

ULONG CcLazyWriteIos

Definition at line 21 of file lazywrite.c.

Referenced by CcWriteBehind(), and QSI_DEF().

◆ CcLazyWritePages

ULONG CcLazyWritePages

Definition at line 20 of file lazywrite.c.

Referenced by CcWriteBehind(), and QSI_DEF().

◆ CcMapDataNoWait

ULONG CcMapDataNoWait

Definition at line 29 of file pin.c.

Referenced by CcMapData(), and QSI_DEF().

◆ CcMapDataWait

ULONG CcMapDataWait

Definition at line 28 of file pin.c.

Referenced by CcMapData(), and QSI_DEF().

◆ CcNumberWorkerThreads

ULONG CcNumberWorkerThreads

Definition at line 48 of file lazywrite.c.

Referenced by CcInitializeCacheManager().

◆ CcPinMappedDataCount

ULONG CcPinMappedDataCount

Definition at line 32 of file pin.c.

Referenced by CcPinMappedData(), and QSI_DEF().

◆ CcPinReadNoWait

ULONG CcPinReadNoWait

Definition at line 31 of file pin.c.

Referenced by CcPinRead(), and QSI_DEF().

◆ CcPinReadWait

ULONG CcPinReadWait

Definition at line 30 of file pin.c.

Referenced by CcPinRead(), and QSI_DEF().

◆ CcPostTickWorkQueue

LIST_ENTRY CcPostTickWorkQueue

◆ CcRegularWorkQueue

LIST_ENTRY CcRegularWorkQueue

Definition at line 40 of file lazywrite.c.

Referenced by CcInitializeCacheManager(), CcLazyWriteScan(), CcScanDpc(), and CcWorkerThread().

◆ CcRosTraceLevel

ULONG CcRosTraceLevel

Definition at line 31 of file copy.c.

◆ CcTotalDirtyPages

ULONG CcTotalDirtyPages

◆ CcTwilightLookasideList

◆ DirtyVacbListHead

LIST_ENTRY DirtyVacbListHead

Definition at line 41 of file view.c.

Referenced by CcInitView(), CcIsThereDirtyData(), CcRosFlushDirtyPages(), and CcRosMarkDirtyVacb().

◆ LazyWriter