ReactOS 0.4.15-dev-8109-gd7be748
cachesub.c File Reference
#include <ntoskrnl.h>
#include "newcc.h"
#include "section/newmm.h"
#include <debug.h>
Include dependency graph for cachesub.c:

Go to the source code of this file.

Classes

struct  _WORK_QUEUE_WITH_READ_AHEAD
 

Macros

#define NDEBUG
 

Typedefs

typedef struct _WORK_QUEUE_WITH_READ_AHEAD WORK_QUEUE_WITH_READ_AHEAD
 
typedef struct _WORK_QUEUE_WITH_READ_AHEADPWORK_QUEUE_WITH_READ_AHEAD
 

Functions

PDEVICE_OBJECT NTAPI MmGetDeviceObjectForFile (IN PFILE_OBJECT FileObject)
 
VOID NTAPI CcSetReadAheadGranularity (IN PFILE_OBJECT FileObject, IN ULONG Granularity)
 
VOID NTAPI CcpReadAhead (PVOID Context)
 
VOID NTAPI CcScheduleReadAhead (IN PFILE_OBJECT FileObject, IN PLARGE_INTEGER FileOffset, IN ULONG Length)
 
VOID NTAPI CcSetDirtyPinnedData (IN PVOID BcbVoid, IN OPTIONAL PLARGE_INTEGER Lsn)
 
LARGE_INTEGER NTAPI CcGetFlushedValidData (IN PSECTION_OBJECT_POINTERS SectionObjectPointer, IN BOOLEAN CcInternalCaller)
 
VOID NTAPI _CcpFlushCache (IN PNOCC_CACHE_MAP Map, IN OPTIONAL PLARGE_INTEGER FileOffset, IN ULONG Length, OUT OPTIONAL PIO_STATUS_BLOCK IoStatus, BOOLEAN Delete, const char *File, int Line)
 
VOID NTAPI CcFlushCache (IN PSECTION_OBJECT_POINTERS SectionObjectPointer, IN OPTIONAL PLARGE_INTEGER FileOffset, IN ULONG Length, OUT OPTIONAL PIO_STATUS_BLOCK IoStatus)
 
BOOLEAN NTAPI CcFlushImageSection (PSECTION_OBJECT_POINTERS SectionObjectPointer, MMFLUSH_TYPE FlushType)
 
PVOID NTAPI CcRemapBcb (IN PVOID Bcb)
 
VOID NTAPI CcShutdownSystem (VOID)
 
VOID NTAPI CcRepinBcb (IN PVOID Bcb)
 
VOID NTAPI CcUnpinRepinnedBcb (IN PVOID Bcb, IN BOOLEAN WriteThrough, OUT PIO_STATUS_BLOCK IoStatus)
 

Macro Definition Documentation

◆ NDEBUG

#define NDEBUG

Definition at line 15 of file cachesub.c.

Typedef Documentation

◆ PWORK_QUEUE_WITH_READ_AHEAD

◆ WORK_QUEUE_WITH_READ_AHEAD

Function Documentation

◆ _CcpFlushCache()

VOID NTAPI _CcpFlushCache ( IN PNOCC_CACHE_MAP  Map,
IN OPTIONAL PLARGE_INTEGER  FileOffset,
IN ULONG  Length,
OUT OPTIONAL PIO_STATUS_BLOCK  IoStatus,
BOOLEAN  Delete,
const char File,
int  Line 
)

Definition at line 142 of file cachesub.c.

149{
151 LARGE_INTEGER LowerBound, UpperBound;
152 PLIST_ENTRY ListEntry;
153 IO_STATUS_BLOCK IOSB;
154
155 RtlZeroMemory(&IOSB, sizeof(IO_STATUS_BLOCK));
156
157 DPRINT("CcFlushCache (while file) (%s:%d)\n", File, Line);
158
159 if (FileOffset && Length)
160 {
161 LowerBound.QuadPart = FileOffset->QuadPart;
162 UpperBound.QuadPart = LowerBound.QuadPart + Length;
163 }
164 else
165 {
166 LowerBound.QuadPart = 0;
167 UpperBound.QuadPart = 0x7fffffffffffffffull;
168 }
169
170 CcpLock();
171 ListEntry = Map->AssociatedBcb.Flink;
172
173 while (ListEntry != &Map->AssociatedBcb)
174 {
175 Bcb = CONTAINING_RECORD(ListEntry, NOCC_BCB, ThisFileList);
177
178 if (Bcb->FileOffset.QuadPart + Bcb->Length >= LowerBound.QuadPart &&
179 Bcb->FileOffset.QuadPart < UpperBound.QuadPart)
180 {
181 DPRINT("Bcb #%x (@%08x%08x)\n",
183 Bcb->FileOffset.u.HighPart, Bcb->FileOffset.u.LowPart);
184
185 Bcb->RefCount++;
186 CcpUnlock();
187 MiFlushMappedSection(Bcb->BaseAddress,
188 &Bcb->FileOffset,
189 &Map->FileSizes.FileSize,
190 Bcb->Dirty);
191 CcpLock();
192 Bcb->RefCount--;
193
194 Bcb->Dirty = FALSE;
195
196 ListEntry = ListEntry->Flink;
197 if (Delete && Bcb->RefCount < 2)
198 {
199 Bcb->RefCount = 1;
201 }
202 else
203 {
205 }
206 }
207 else
208 {
209 ListEntry = ListEntry->Flink;
211 }
212
213 DPRINT("End loop\n");
214 }
215 CcpUnlock();
216
217 if (IoStatus) *IoStatus = IOSB;
218}
BOOL Delete(LPCTSTR ServiceName)
Definition: delete.c:12
_In_ PFCB _In_ LONGLONG FileOffset
Definition: cdprocs.h:160
Definition: File.h:16
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
IN PVCB IN VBO IN ULONG OUT PBCB * Bcb
Definition: fatprocs.h:414
__in UCHAR __in POWER_STATE __in_opt PVOID __in PIO_STATUS_BLOCK IoStatus
Definition: mxum.h:159
BOOLEAN NTAPI CcpUnpinData(PNOCC_BCB Bcb, BOOLEAN ActuallyRelease)
NOCC_BCB CcCacheSections[CACHE_NUM_SECTIONS]
Definition: pinsup.c:98
VOID CcpReferenceCache(ULONG Sector)
Definition: pinsup.c:368
VOID CcpDereferenceCache(ULONG Sector, BOOLEAN Immediate)
Definition: pinsup.c:213
#define CcpLock()
Definition: newcc.h:138
#define CcpUnlock()
Definition: newcc.h:139
#define MiFlushMappedSection(A, O, S, D)
Definition: newmm.h:333
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:102
#define DPRINT
Definition: sndvol32.h:73
Definition: ncftp.h:79
Definition: typedefs.h:120
struct _LIST_ENTRY * Flink
Definition: typedefs.h:121
Definition: newcc.h:4
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
#define CONTAINING_RECORD(address, type, field)
Definition: typedefs.h:260
uint32_t ULONG
Definition: typedefs.h:59
LONGLONG QuadPart
Definition: typedefs.h:114

◆ CcFlushCache()

VOID NTAPI CcFlushCache ( IN PSECTION_OBJECT_POINTERS  SectionObjectPointer,
IN OPTIONAL PLARGE_INTEGER FileOffset  ,
IN ULONG  Length,
OUT OPTIONAL PIO_STATUS_BLOCK  IoStatus 
)

Definition at line 222 of file cachesub.c.

226{
228
229 /* Not cached */
230 if (!Map)
231 {
232 if (IoStatus)
233 {
234 IoStatus->Status = STATUS_SUCCESS;
235 IoStatus->Information = 0;
236 }
237 return;
238 }
239
241}
_Must_inspect_result_ _In_ PDEVICE_OBJECT _In_ PSECTION_OBJECT_POINTERS SectionObjectPointer
Definition: fsrtlfuncs.h:1369
if(dx< 0)
Definition: linetemp.h:194
#define CcpFlushCache(M, F, L, I, D)
Definition: newcc.h:91
struct _NOCC_CACHE_MAP * PNOCC_CACHE_MAP
#define STATUS_SUCCESS
Definition: shellext.h:65

Referenced by __attribute__(), _Dispatch_type_(), _Requires_lock_held_(), CcCopyWrite(), CcFlushImageSection(), CcUnpinRepinnedBcb(), CcZeroData(), Ext2Cleanup(), Ext2CreateFile(), Ext2FloppyFlush(), Ext2FlushFile(), Ext2FlushRange(), Ext2FlushVcb(), Ext2PurgeFile(), Ext2PurgeVolume(), Ext2ReadFile(), Ext2TearDownStream(), Ext2WriteFile(), Ext2WriteVolume(), FatCloseEaFile(), FatCommonSetEa(), FatDeferredFlush(), FatFlushDirentForFile(), FatFlushFatEntries(), flush_fcb_caches(), flush_subvol_fcbs(), MmCreateImageSection(), PerformTest(), RxCommonRead(), RxCommonWrite(), RxFlushFcbInSystemCache(), set_rename_information(), set_zero_data(), TestIrpHandler(), UDFCloseAllXXXDelayedInDir(), UDFCommonCleanup(), UDFCommonCreate(), UDFCommonRead(), UDFCommonWrite(), UDFFlushAFile(), UDFPurgeCacheEx_(), VfatFlushFile(), VfatMoveEntry(), vfatRenameEntry(), and vfatUpdateFCB().

◆ CcFlushImageSection()

BOOLEAN NTAPI CcFlushImageSection ( PSECTION_OBJECT_POINTERS  SectionObjectPointer,
MMFLUSH_TYPE  FlushType 
)

Definition at line 245 of file cachesub.c.

247{
251 IO_STATUS_BLOCK IOSB;
253
254 if (!Map) return TRUE;
255
256 for (Entry = Map->AssociatedBcb.Flink;
257 Entry != &Map->AssociatedBcb;
258 Entry = Entry->Flink)
259 {
260 Bcb = CONTAINING_RECORD(Entry, NOCC_BCB, ThisFileList);
261
262 if (!Bcb->Dirty) continue;
263
264 switch (FlushType)
265 {
266 case MmFlushForDelete:
268 &Bcb->FileOffset,
269 Bcb->Length,
270 FALSE);
271 break;
272 case MmFlushForWrite:
274 &Bcb->FileOffset,
275 Bcb->Length,
276 &IOSB);
277 break;
278 }
279 }
280
281 return Result;
282}
unsigned char BOOLEAN
VOID NTAPI CcFlushCache(IN PSECTION_OBJECT_POINTERS SectionObjectPointer, IN OPTIONAL PLARGE_INTEGER FileOffset, IN ULONG Length, OUT OPTIONAL PIO_STATUS_BLOCK IoStatus)
Definition: cachesub.c:222
IN PFCB IN FAT_FLUSH_TYPE FlushType
Definition: fatprocs.h:1082
BOOLEAN NTAPI CcPurgeCacheSection(IN PSECTION_OBJECT_POINTERS SectionObjectPointer, IN OPTIONAL PLARGE_INTEGER FileOffset, IN ULONG Length, IN BOOLEAN UninitializeCacheMaps)
Definition: fssup.c:386
base of all file and directory entries
Definition: entries.h:83
LIST_ENTRY AssociatedBcb
Definition: newcc.h:29
_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:409

◆ CcGetFlushedValidData()

LARGE_INTEGER NTAPI CcGetFlushedValidData ( IN PSECTION_OBJECT_POINTERS  SectionObjectPointer,
IN BOOLEAN  CcInternalCaller 
)

Definition at line 130 of file cachesub.c.

132{
133 LARGE_INTEGER Result = {{0}};
135 return Result;
136}
#define UNIMPLEMENTED_DBGBREAK(...)
Definition: debug.h:57

Referenced by PerformTest().

◆ CcpReadAhead()

VOID NTAPI CcpReadAhead ( PVOID  Context)

Definition at line 48 of file cachesub.c.

49{
52 PNOCC_CACHE_MAP Map = (PNOCC_CACHE_MAP)WorkItem->FileObject->SectionObjectPointer->SharedCacheMap;
53
54 DPRINT1("Reading ahead %08x%08x:%x %wZ\n",
55 WorkItem->FileOffset.HighPart,
56 WorkItem->FileOffset.LowPart,
57 WorkItem->Length,
58 &WorkItem->FileObject->FileName);
59
60 Offset.HighPart = WorkItem->FileOffset.HighPart;
61 Offset.LowPart = PAGE_ROUND_DOWN(WorkItem->FileOffset.LowPart);
62 if (Map)
63 {
64 PLIST_ENTRY ListEntry;
65 volatile char *chptr;
67 for (ListEntry = Map->AssociatedBcb.Flink;
68 ListEntry != &Map->AssociatedBcb;
69 ListEntry = ListEntry->Flink)
70 {
71 Bcb = CONTAINING_RECORD(ListEntry, NOCC_BCB, ThisFileList);
72 if ((Offset.QuadPart + WorkItem->Length < Bcb->FileOffset.QuadPart) ||
73 (Bcb->FileOffset.QuadPart + Bcb->Length < Offset.QuadPart))
74 continue;
75 for (chptr = Bcb->BaseAddress, Offset = Bcb->FileOffset;
76 chptr < ((PCHAR)Bcb->BaseAddress) + Bcb->Length &&
77 Offset.QuadPart <
78 WorkItem->FileOffset.QuadPart + WorkItem->Length;
79 chptr += PAGE_SIZE, Offset.QuadPart += PAGE_SIZE)
80 {
81 *chptr ^= 0;
82 }
83 }
84 }
85 ObDereferenceObject(WorkItem->FileObject);
87 DPRINT("Done\n");
88}
#define DPRINT1
Definition: precomp.h:8
struct _WORK_QUEUE_WITH_READ_AHEAD * PWORK_QUEUE_WITH_READ_AHEAD
#define PAGE_SIZE
Definition: env_spec_w32.h:49
#define ExFreePool(addr)
Definition: env_spec_w32.h:352
#define PAGE_ROUND_DOWN(x)
Definition: mmtypes.h:36
_In_ ULONG _In_ ULONG Offset
Definition: ntddpcm.h:101
char * PCHAR
Definition: typedefs.h:51
_Must_inspect_result_ _In_ PWDF_WORKITEM_CONFIG _In_ PWDF_OBJECT_ATTRIBUTES _Out_ WDFWORKITEM * WorkItem
Definition: wdfworkitem.h:115
#define ObDereferenceObject
Definition: obfuncs.h:203

Referenced by CcScheduleReadAhead().

◆ CcRemapBcb()

PVOID NTAPI CcRemapBcb ( IN PVOID  Bcb)

Definition at line 287 of file cachesub.c.

288{
290 CcpLock();
293 CcpUnlock();
294 return Bcb;
295}
#define ASSERT(a)
Definition: mode.c:44
PRTL_BITMAP CcCacheBitmap
Definition: pinsup.c:100
_In_opt_ PENTER_STATE_SYSTEM_HANDLER _In_opt_ PVOID _In_ LONG _In_opt_ LONG volatile * Number
Definition: ntpoapi.h:207
_Must_inspect_result_ NTSYSAPI BOOLEAN NTAPI RtlTestBit(_In_ PRTL_BITMAP BitMapHeader, _In_range_(<, BitMapHeader->SizeOfBitMap) ULONG BitNumber)
Definition: bitmap.c:434

◆ CcRepinBcb()

VOID NTAPI CcRepinBcb ( IN PVOID  Bcb)

Definition at line 331 of file cachesub.c.

332{
334 CcpLock();
336 DPRINT("CcRepinBcb(#%x)\n", Number);
338 CcpUnlock();
339}

Referenced by FatFlushFat(), and FatRepinBcb().

◆ CcScheduleReadAhead()

VOID NTAPI CcScheduleReadAhead ( IN PFILE_OBJECT  FileObject,
IN PLARGE_INTEGER  FileOffset,
IN ULONG  Length 
)

Definition at line 92 of file cachesub.c.

95{
97
98 DPRINT("Schedule read ahead %08x%08x:%x %wZ\n",
99 FileOffset->HighPart,
100 FileOffset->LowPart,
101 Length,
102 &FileObject->FileName);
103
105 if (!WorkItem) KeBugCheck(0);
107 WorkItem->FileObject = FileObject;
108 WorkItem->FileOffset = *FileOffset;
109 WorkItem->Length = Length;
110
113 WorkItem);
114
116 DPRINT("Done\n");
117}
DECLSPEC_NORETURN VOID NTAPI KeBugCheck(ULONG BugCheckCode)
Definition: bug.c:1430
VOID NTAPI CcpReadAhead(PVOID Context)
Definition: cachesub.c:48
#define NonPagedPool
Definition: env_spec_w32.h:307
#define ExAllocatePool(type, size)
Definition: fbtusb.h:44
_In_ WDFREQUEST _In_ WDFFILEOBJECT FileObject
Definition: wdfdevice.h:550
VOID NTAPI ExQueueWorkItem(IN PWORK_QUEUE_ITEM WorkItem, IN WORK_QUEUE_TYPE QueueType)
Definition: work.c:723
#define ExInitializeWorkItem(Item, Routine, Context)
Definition: exfuncs.h:265
@ DelayedWorkQueue
Definition: extypes.h:190
WORKER_THREAD_ROUTINE * PWORKER_THREAD_ROUTINE
Definition: extypes.h:200
#define ObReferenceObject
Definition: obfuncs.h:204

Referenced by CcCopyRead().

◆ CcSetDirtyPinnedData()

◆ CcSetReadAheadGranularity()

VOID NTAPI CcSetReadAheadGranularity ( IN PFILE_OBJECT  FileObject,
IN ULONG  Granularity 
)

Definition at line 36 of file cachesub.c.

38{
39 PNOCC_CACHE_MAP Map = (PNOCC_CACHE_MAP)FileObject->SectionObjectPointer->SharedCacheMap;
40 if (Map)
41 {
42 Map->ReadAheadGranularity = Granularity;
43 }
44}
ULONG ReadAheadGranularity
Definition: newcc.h:38

Referenced by _Requires_lock_held_(), Ext2ReadFile(), Ext2WriteFile(), init_file_cache(), RxCommonRead(), RxCommonWrite(), UDFCommonRead(), and UDFCommonWrite().

◆ 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}
LONG NTSTATUS
Definition: precomp.h:26
Status
Definition: gdiplustypes.h:25
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 CACHE_NUM_SECTIONS
Definition: newcc.h:125
NTSTATUS MiRosTrimCache(ULONG Target, ULONG Priority, PULONG NrFreed)
Definition: swapout.c:633
PFILE_OBJECT NTAPI MmGetFileObjectForSection(IN PVOID Section)
Definition: section.c:1541

Referenced by PopGracefulShutdown().

◆ CcUnpinRepinnedBcb()

VOID NTAPI CcUnpinRepinnedBcb ( IN PVOID  Bcb,
IN BOOLEAN  WriteThrough,
OUT PIO_STATUS_BLOCK  IoStatus 
)

Definition at line 343 of file cachesub.c.

346{
347 PNOCC_BCB RealBcb = (PNOCC_BCB)Bcb;
348
349 if (WriteThrough)
350 {
351 DPRINT("BCB #%x\n", RealBcb - CcCacheSections);
352
353 CcpFlushCache(RealBcb->Map,
354 &RealBcb->FileOffset,
355 RealBcb->Length,
356 IoStatus,
357 RealBcb->Dirty);
358 }
359
361}
VOID NTAPI CcUnpinData(IN PVOID Bcb)
Definition: pinsup.c:955
struct _NOCC_CACHE_MAP * Map
Definition: newcc.h:8
ULONG Length
Definition: newcc.h:11
BOOLEAN Dirty
Definition: newcc.h:13
LARGE_INTEGER FileOffset
Definition: newcc.h:10

Referenced by FatFlushFat(), and FatUnpinRepinnedBcbs().

◆ MmGetDeviceObjectForFile()

PDEVICE_OBJECT NTAPI MmGetDeviceObjectForFile ( IN PFILE_OBJECT  FileObject)

Definition at line 57 of file io.c.

58{
60}
PDEVICE_OBJECT NTAPI IoGetRelatedDeviceObject(IN PFILE_OBJECT FileObject)
Definition: device.c:1539