ReactOS 0.4.15-dev-8138-g1e75ea8
cachesub.c
Go to the documentation of this file.
1/*
2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS Kernel
4 * FILE: ntoskrnl/cache/cachesub.c
5 * PURPOSE: Logging and configuration routines
6 * PROGRAMMERS: Alex Ionescu (alex.ionescu@reactos.org)
7 * Art Yerkes
8 */
9
10/* INCLUDES *******************************************************************/
11
12#include <ntoskrnl.h>
13#include "newcc.h"
14#include "section/newmm.h"
15#define NDEBUG
16#include <debug.h>
17
18/* STRUCTURES *****************************************************************/
19
21{
27
28/* FUNCTIONS ******************************************************************/
29
33
34VOID
37 IN ULONG Granularity)
38{
39 PNOCC_CACHE_MAP Map = (PNOCC_CACHE_MAP)FileObject->SectionObjectPointer->SharedCacheMap;
40 if (Map)
41 {
42 Map->ReadAheadGranularity = Granularity;
43 }
44}
45
46VOID
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}
89
90VOID
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}
118
119VOID
120NTAPI
123{
124 PNOCC_BCB Bcb = (PNOCC_BCB)BcbVoid;
125 Bcb->Dirty = TRUE;
126}
127
129NTAPI
131 IN BOOLEAN CcInternalCaller)
132{
133 LARGE_INTEGER Result = {{0}};
135 return Result;
136}
137
138
139
140VOID
141NTAPI
147 const char *File,
148 int Line)
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}
219
220VOID
221NTAPI
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}
242
244NTAPI
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}
283
284/* Always succeeds for us */
285PVOID
286NTAPI
288{
290 CcpLock();
293 CcpUnlock();
294 return Bcb;
295}
296
297VOID
298NTAPI
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}
327
328
329VOID
330NTAPI
332{
334 CcpLock();
336 DPRINT("CcRepinBcb(#%x)\n", Number);
338 CcpUnlock();
339}
340
341VOID
342NTAPI
344 IN BOOLEAN WriteThrough,
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}
362
363/* EOF */
unsigned char BOOLEAN
LONG NTSTATUS
Definition: precomp.h:26
#define DPRINT1
Definition: precomp.h:8
BOOL Delete(LPCTSTR ServiceName)
Definition: delete.c:12
DECLSPEC_NORETURN VOID NTAPI KeBugCheck(ULONG BugCheckCode)
Definition: bug.c:1430
PVOID NTAPI CcRemapBcb(IN PVOID Bcb)
Definition: cachesub.c:287
VOID NTAPI CcUnpinRepinnedBcb(IN PVOID Bcb, IN BOOLEAN WriteThrough, OUT PIO_STATUS_BLOCK IoStatus)
Definition: cachesub.c:343
VOID NTAPI CcShutdownSystem(VOID)
Definition: cachesub.c:299
VOID NTAPI CcSetReadAheadGranularity(IN PFILE_OBJECT FileObject, IN ULONG Granularity)
Definition: cachesub.c:36
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: cachesub.c:142
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
VOID NTAPI CcScheduleReadAhead(IN PFILE_OBJECT FileObject, IN PLARGE_INTEGER FileOffset, IN ULONG Length)
Definition: cachesub.c:92
VOID NTAPI CcpReadAhead(PVOID Context)
Definition: cachesub.c:48
PDEVICE_OBJECT NTAPI MmGetDeviceObjectForFile(IN PFILE_OBJECT FileObject)
Definition: io.c:57
struct _WORK_QUEUE_WITH_READ_AHEAD WORK_QUEUE_WITH_READ_AHEAD
LARGE_INTEGER NTAPI CcGetFlushedValidData(IN PSECTION_OBJECT_POINTERS SectionObjectPointer, IN BOOLEAN CcInternalCaller)
Definition: cachesub.c:130
VOID NTAPI CcSetDirtyPinnedData(IN PVOID BcbVoid, IN OPTIONAL PLARGE_INTEGER Lsn)
Definition: cachesub.c:121
struct _WORK_QUEUE_WITH_READ_AHEAD * PWORK_QUEUE_WITH_READ_AHEAD
BOOLEAN NTAPI CcFlushImageSection(PSECTION_OBJECT_POINTERS SectionObjectPointer, MMFLUSH_TYPE FlushType)
Definition: cachesub.c:245
VOID NTAPI CcRepinBcb(IN PVOID Bcb)
Definition: cachesub.c:331
_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
#define UNIMPLEMENTED_DBGBREAK(...)
Definition: debug.h:57
#define PAGE_SIZE
Definition: env_spec_w32.h:49
#define ExFreePool(addr)
Definition: env_spec_w32.h:352
#define NonPagedPool
Definition: env_spec_w32.h:307
IN PVCB IN VBO IN ULONG OUT PBCB * Bcb
Definition: fatprocs.h:414
IN PFCB IN FAT_FLUSH_TYPE FlushType
Definition: fatprocs.h:1082
#define ExAllocatePool(type, size)
Definition: fbtusb.h:44
_Must_inspect_result_ _In_ PDEVICE_OBJECT _In_ PSECTION_OBJECT_POINTERS SectionObjectPointer
Definition: fsrtlfuncs.h:1369
BOOLEAN NTAPI CcPurgeCacheSection(IN PSECTION_OBJECT_POINTERS SectionObjectPointer, IN OPTIONAL PLARGE_INTEGER FileOffset, IN ULONG Length, IN BOOLEAN UninitializeCacheMaps)
Definition: fssup.c:386
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
if(dx< 0)
Definition: linetemp.h:194
#define ASSERT(a)
Definition: mode.c:44
__in UCHAR __in POWER_STATE __in_opt PVOID __in PIO_STATUS_BLOCK IoStatus
Definition: mxum.h:159
#define PAGE_ROUND_DOWN(x)
Definition: mmtypes.h:36
#define CcpFlushCache(M, F, L, I, D)
Definition: newcc.h:91
BOOLEAN NTAPI CcpUnpinData(PNOCC_BCB Bcb, BOOLEAN ActuallyRelease)
NOCC_BCB CcCacheSections[CACHE_NUM_SECTIONS]
Definition: pinsup.c:98
struct _NOCC_BCB * PNOCC_BCB
struct _NOCC_CACHE_MAP * PNOCC_CACHE_MAP
VOID CcpReferenceCache(ULONG Sector)
Definition: pinsup.c:368
VOID CcpDereferenceCache(ULONG Sector, BOOLEAN Immediate)
Definition: pinsup.c:213
PRTL_BITMAP CcCacheBitmap
Definition: pinsup.c:100
#define CcpLock()
Definition: newcc.h:138
#define CcpUnlock()
Definition: newcc.h:139
#define CACHE_NUM_SECTIONS
Definition: newcc.h:125
NTSTATUS MiRosTrimCache(ULONG Target, ULONG Priority, PULONG NrFreed)
Definition: swapout.c:633
#define MiFlushMappedSection(A, O, S, D)
Definition: newmm.h:333
_In_ ULONG _In_ ULONG Offset
Definition: ntddpcm.h:101
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:102
PFILE_OBJECT NTAPI MmGetFileObjectForSection(IN PVOID Section)
Definition: section.c:1541
_In_opt_ PENTER_STATE_SYSTEM_HANDLER _In_opt_ PVOID _In_ LONG _In_opt_ LONG volatile * Number
Definition: ntpoapi.h:207
VOID NTAPI CcUnpinData(IN PVOID Bcb)
Definition: pinsup.c:955
#define STATUS_SUCCESS
Definition: shellext.h:65
#define DPRINT
Definition: sndvol32.h:73
PULONG MinorVersion OPTIONAL
Definition: CrossNt.h:68
base of all file and directory entries
Definition: entries.h:83
Definition: ncftp.h:79
Definition: typedefs.h:120
struct _LIST_ENTRY * Flink
Definition: typedefs.h:121
Definition: newcc.h:4
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
ULONG ReadAheadGranularity
Definition: newcc.h:38
LIST_ENTRY AssociatedBcb
Definition: newcc.h:29
WORK_QUEUE_ITEM WorkItem
Definition: cachesub.c:22
LARGE_INTEGER FileOffset
Definition: cachesub.c:24
PFILE_OBJECT FileObject
Definition: cachesub.c:23
#define NTAPI
Definition: typedefs.h:36
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
#define IN
Definition: typedefs.h:39
#define CONTAINING_RECORD(address, type, field)
Definition: typedefs.h:260
uint32_t ULONG
Definition: typedefs.h:59
#define OUT
Definition: typedefs.h:40
char * PCHAR
Definition: typedefs.h:51
LONGLONG QuadPart
Definition: typedefs.h:114
_In_ WDFREQUEST _In_ WDFFILEOBJECT FileObject
Definition: wdfdevice.h:550
_Must_inspect_result_ _In_ PWDF_WORKITEM_CONFIG _In_ PWDF_OBJECT_ATTRIBUTES _Out_ WDFWORKITEM * WorkItem
Definition: wdfworkitem.h:115
VOID NTAPI ExQueueWorkItem(IN PWORK_QUEUE_ITEM WorkItem, IN WORK_QUEUE_TYPE QueueType)
Definition: work.c:723
_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
#define ExInitializeWorkItem(Item, Routine, Context)
Definition: exfuncs.h:265
@ DelayedWorkQueue
Definition: extypes.h:190
WORKER_THREAD_ROUTINE * PWORKER_THREAD_ROUTINE
Definition: extypes.h:200
* PFILE_OBJECT
Definition: iotypes.h:1998
MMFLUSH_TYPE
Definition: mmtypes.h:183
#define ObDereferenceObject
Definition: obfuncs.h:203
#define ObReferenceObject
Definition: obfuncs.h:204
_Must_inspect_result_ NTSYSAPI BOOLEAN NTAPI RtlTestBit(_In_ PRTL_BITMAP BitMapHeader, _In_range_(<, BitMapHeader->SizeOfBitMap) ULONG BitNumber)
Definition: bitmap.c:434