ReactOS 0.4.15-dev-8419-g7f0e8a3
fs.c File Reference
#include <ntoskrnl.h>
#include <debug.h>
Include dependency graph for fs.c:

Go to the source code of this file.

Macros

#define NDEBUG
 

Functions

LARGE_INTEGER NTAPI CcGetDirtyPages (IN PVOID LogHandle, IN PDIRTY_PAGE_ROUTINE DirtyPageRoutine, IN PVOID Context1, IN PVOID Context2)
 
PFILE_OBJECT NTAPI CcGetFileObjectFromBcb (IN PVOID Bcb)
 
LARGE_INTEGER NTAPI CcGetLsnForFileObject (IN PFILE_OBJECT FileObject, OUT PLARGE_INTEGER OldestLsn OPTIONAL)
 
VOID NTAPI CcInitializeCacheMap (IN PFILE_OBJECT FileObject, IN PCC_FILE_SIZES FileSizes, IN BOOLEAN PinAccess, IN PCACHE_MANAGER_CALLBACKS CallBacks, IN PVOID LazyWriterContext)
 
BOOLEAN NTAPI CcIsThereDirtyData (IN PVPB Vpb)
 
BOOLEAN NTAPI CcPurgeCacheSection (IN PSECTION_OBJECT_POINTERS SectionObjectPointer, IN PLARGE_INTEGER FileOffset OPTIONAL, IN ULONG Length, IN BOOLEAN UninitializeCacheMaps)
 
VOID NTAPI CcSetFileSizes (IN PFILE_OBJECT FileObject, IN PCC_FILE_SIZES FileSizes)
 
VOID NTAPI CcSetLogHandleForFile (IN PFILE_OBJECT FileObject, IN PVOID LogHandle, IN PFLUSH_TO_LSN FlushToLsnRoutine)
 
BOOLEAN NTAPI CcUninitializeCacheMap (IN PFILE_OBJECT FileObject, IN PLARGE_INTEGER TruncateSize OPTIONAL, IN PCACHE_UNINITIALIZE_EVENT UninitializeCompleteEvent OPTIONAL)
 
BOOLEAN NTAPI CcGetFileSizes (IN PFILE_OBJECT FileObject, IN PCC_FILE_SIZES FileSizes)
 

Macro Definition Documentation

◆ NDEBUG

#define NDEBUG

Definition at line 14 of file fs.c.

Function Documentation

◆ CcGetDirtyPages()

LARGE_INTEGER NTAPI CcGetDirtyPages ( IN PVOID  LogHandle,
IN PDIRTY_PAGE_ROUTINE  DirtyPageRoutine,
IN PVOID  Context1,
IN PVOID  Context2 
)

Definition at line 24 of file fs.c.

29{
31
32 CCTRACE(CC_API_DEBUG, "LogHandle=%p DirtyPageRoutine=%p Context1=%p Context2=%p\n",
33 LogHandle, DirtyPageRoutine, Context1, Context2);
34
36 i.QuadPart = 0;
37 return i;
38}
#define UNIMPLEMENTED
Definition: debug.h:118
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
_In_ UINT _Out_ PNDIS_HANDLE LogHandle
Definition: ndis.h:5382
#define CC_API_DEBUG
Definition: cc.h:11
#define CCTRACE(x, fmt,...)
Definition: cc.h:36
_In_ PNET_PNP_EVENT _In_ PTDI_PNP_CONTEXT Context1
Definition: tdikrnl.h:1095
_In_ PNET_PNP_EVENT _In_ PTDI_PNP_CONTEXT _In_ PTDI_PNP_CONTEXT Context2
Definition: tdikrnl.h:1096

◆ CcGetFileObjectFromBcb()

PFILE_OBJECT NTAPI CcGetFileObjectFromBcb ( IN PVOID  Bcb)

Definition at line 45 of file fs.c.

47{
49
50 CCTRACE(CC_API_DEBUG, "Bcb=%p\n", Bcb);
51
52 return iBcb->Vacb->SharedCacheMap->FileObject;
53}
IN PVCB IN VBO IN ULONG OUT PBCB * Bcb
Definition: fatprocs.h:414
Definition: cdstruc.h:902
PROS_VACB Vacb
Definition: cc.h:235
PFILE_OBJECT FileObject
Definition: cc.h:179
PROS_SHARED_CACHE_MAP SharedCacheMap
Definition: cc.h:226
#define CONTAINING_RECORD(address, type, field)
Definition: typedefs.h:260

◆ CcGetFileSizes()

BOOLEAN NTAPI CcGetFileSizes ( IN PFILE_OBJECT  FileObject,
IN PCC_FILE_SIZES  FileSizes 
)

Definition at line 403 of file fs.c.

406{
407 PROS_SHARED_CACHE_MAP SharedCacheMap;
408
409 SharedCacheMap = FileObject->SectionObjectPointer->SharedCacheMap;
410
411 if (!SharedCacheMap)
412 return FALSE;
413
414 FileSizes->AllocationSize = SharedCacheMap->SectionSize;
416 return TRUE;
417}
static CC_FILE_SIZES FileSizes
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
LARGE_INTEGER FileSize
Definition: cctypes.h:16
LARGE_INTEGER ValidDataLength
Definition: cctypes.h:17
LARGE_INTEGER AllocationSize
Definition: cctypes.h:15
LARGE_INTEGER FileSize
Definition: cc.h:175
LARGE_INTEGER SectionSize
Definition: cc.h:177
_In_ WDFREQUEST _In_ WDFFILEOBJECT FileObject
Definition: wdfdevice.h:550

◆ CcGetLsnForFileObject()

LARGE_INTEGER NTAPI CcGetLsnForFileObject ( IN PFILE_OBJECT  FileObject,
OUT PLARGE_INTEGER OldestLsn  OPTIONAL 
)

Definition at line 60 of file fs.c.

63{
65
66 CCTRACE(CC_API_DEBUG, "FileObject=%p\n", FileObject);
67
69 i.QuadPart = 0;
70 return i;
71}

◆ CcInitializeCacheMap()

VOID NTAPI CcInitializeCacheMap ( IN PFILE_OBJECT  FileObject,
IN PCC_FILE_SIZES  FileSizes,
IN BOOLEAN  PinAccess,
IN PCACHE_MANAGER_CALLBACKS  CallBacks,
IN PVOID  LazyWriterContext 
)

Definition at line 78 of file fs.c.

84{
86
89
90 CCTRACE(CC_API_DEBUG, "FileObject=%p FileSizes=%p PinAccess=%d CallBacks=%p LazyWriterContext=%p\n",
91 FileObject, FileSizes, PinAccess, CallBacks, LazyWriterContext);
92
93 /* Call old ROS cache init function */
96 PinAccess,
97 CallBacks,
98 LazyWriterContext);
99 if (!NT_SUCCESS(Status))
101}
LONG NTSTATUS
Definition: precomp.h:26
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:33
Status
Definition: gdiplustypes.h:25
#define ASSERT(a)
Definition: mode.c:44
NTSTATUS CcRosInitializeFileCache(PFILE_OBJECT FileObject, PCC_FILE_SIZES FileSizes, BOOLEAN PinAccess, PCACHE_MANAGER_CALLBACKS CallBacks, PVOID LazyWriterContext)
Definition: view.c:1277
#define ExRaiseStatus
Definition: ntoskrnl.h:114

◆ CcIsThereDirtyData()

BOOLEAN NTAPI CcIsThereDirtyData ( IN PVPB  Vpb)

Definition at line 108 of file fs.c.

110{
111 PROS_VACB Vacb;
113 KIRQL oldIrql;
114 /* Assume no dirty data */
115 BOOLEAN Dirty = FALSE;
116
117 CCTRACE(CC_API_DEBUG, "Vpb=%p\n", Vpb);
118
120
121 /* Browse dirty VACBs */
123 {
124 Vacb = CONTAINING_RECORD(Entry, ROS_VACB, DirtyVacbListEntry);
125 /* Look for these associated with our volume */
126 if (Vacb->SharedCacheMap->FileObject->Vpb != Vpb)
127 {
128 continue;
129 }
130
131 /* From now on, we are associated with our VPB */
132
133 /* Temporary files are not counted as dirty */
135 {
136 continue;
137 }
138
139 /* A single dirty VACB is enough to have dirty data */
140 if (Vacb->Dirty)
141 {
142 Dirty = TRUE;
143 break;
144 }
145 }
146
148
149 return Dirty;
150}
unsigned char BOOLEAN
UCHAR KIRQL
Definition: env_spec_w32.h:591
#define BooleanFlagOn(F, SF)
Definition: ext2fs.h:183
IN OUT PVCB IN PDEVICE_OBJECT IN PVPB Vpb
Definition: fatprocs.h:1675
VOID FASTCALL KeReleaseQueuedSpinLock(IN KSPIN_LOCK_QUEUE_NUMBER LockNumber, IN KIRQL OldIrql)
Definition: spinlock.c:154
KIRQL FASTCALL KeAcquireQueuedSpinLock(IN KSPIN_LOCK_QUEUE_NUMBER LockNumber)
Definition: spinlock.c:108
LIST_ENTRY DirtyVacbListHead
Definition: view.c:41
base of all file and directory entries
Definition: entries.h:83
Definition: typedefs.h:120
struct _LIST_ENTRY * Flink
Definition: typedefs.h:121
Definition: cc.h:207
BOOLEAN Dirty
Definition: cc.h:211
#define FO_TEMPORARY_FILE
Definition: iotypes.h:1791
@ LockQueueMasterLock
Definition: ketypes.h:663

◆ CcPurgeCacheSection()

BOOLEAN NTAPI CcPurgeCacheSection ( IN PSECTION_OBJECT_POINTERS  SectionObjectPointer,
IN PLARGE_INTEGER FileOffset  OPTIONAL,
IN ULONG  Length,
IN BOOLEAN  UninitializeCacheMaps 
)

Definition at line 157 of file fs.c.

162{
163 PROS_SHARED_CACHE_MAP SharedCacheMap;
164 PPRIVATE_CACHE_MAP PrivateCacheMap;
165 LONGLONG StartOffset;
166 LONGLONG EndOffset;
167 LIST_ENTRY FreeList;
169 PLIST_ENTRY ListEntry;
170 PROS_VACB Vacb;
171 LONGLONG ViewEnd;
173
174 CCTRACE(CC_API_DEBUG, "SectionObjectPointer=%p\n FileOffset=%p Length=%lu UninitializeCacheMaps=%d",
175 SectionObjectPointer, FileOffset, Length, UninitializeCacheMaps);
176
177 /* Obtain the shared cache from the section */
178 SharedCacheMap = SectionObjectPointer->SharedCacheMap;
179 if (!SharedCacheMap)
180 {
181 Success = TRUE;
182 goto purgeMm;
183 }
184
185 if (UninitializeCacheMaps)
186 {
187 /*
188 * We have gotten the acknowledgement that
189 * the caller wants to unintialize the private
190 * cache maps so let's do this. Since we already
191 * have the shared cache map from above, iterate
192 * over that cache's private lists.
193 */
194 while (!IsListEmpty(&SharedCacheMap->PrivateList))
195 {
196 /*
197 * This list is not empty, grab the
198 * private cache map.
199 */
200 PrivateCacheMap = CONTAINING_RECORD(SharedCacheMap->PrivateList.Flink, PRIVATE_CACHE_MAP, PrivateLinks);
201
202 /* Unintialize the private cache now */
203 CcUninitializeCacheMap(PrivateCacheMap->FileObject, NULL, NULL);
204 }
205 }
206
207 StartOffset = FileOffset != NULL ? FileOffset->QuadPart : 0;
208 if (Length == 0 || FileOffset == NULL)
209 {
210 EndOffset = MAXLONGLONG;
211 }
212 else
213 {
214 EndOffset = StartOffset + Length;
215 ASSERT(EndOffset > StartOffset);
216 }
217
218 InitializeListHead(&FreeList);
219
220 /* Assume success */
221 Success = TRUE;
222
225 ListEntry = SharedCacheMap->CacheMapVacbListHead.Flink;
226 while (ListEntry != &SharedCacheMap->CacheMapVacbListHead)
227 {
228 ULONG Refs;
229
230 Vacb = CONTAINING_RECORD(ListEntry, ROS_VACB, CacheMapVacbListEntry);
231 ListEntry = ListEntry->Flink;
232
233 /* Skip VACBs outside the range, or only partially in range */
234 if (Vacb->FileOffset.QuadPart < StartOffset)
235 {
236 continue;
237 }
239 SharedCacheMap->SectionSize.QuadPart);
240 if (ViewEnd >= EndOffset)
241 {
242 break;
243 }
244
245 /* Still in use, it cannot be purged, fail
246 * Allow one ref: VACB is supposed to be always 1-referenced
247 */
248 Refs = CcRosVacbGetRefCount(Vacb);
249 if ((Refs > 1 && !Vacb->Dirty) ||
250 (Refs > 2 && Vacb->Dirty))
251 {
252 Success = FALSE;
253 break;
254 }
255
256 /* This VACB is in range, so unlink it and mark for free */
257 ASSERT(Refs == 1 || Vacb->Dirty);
260 if (Vacb->Dirty)
261 {
263 }
265 InsertHeadList(&FreeList, &Vacb->CacheMapVacbListEntry);
266 }
269
270 while (!IsListEmpty(&FreeList))
271 {
272 ULONG Refs;
273
274 Vacb = CONTAINING_RECORD(RemoveHeadList(&FreeList),
275 ROS_VACB,
276 CacheMapVacbListEntry);
278 Refs = CcRosVacbDecRefCount(Vacb);
279 ASSERT(Refs == 0);
280 }
281
282 /* Now make sure that Mm doesn't hold some pages here. */
283purgeMm:
284 if (Success)
286
287 return Success;
288}
_In_ PFCB _In_ LONGLONG FileOffset
Definition: cdprocs.h:160
#define NULL
Definition: types.h:112
#define RemoveEntryList(Entry)
Definition: env_spec_w32.h:986
#define InsertHeadList(ListHead, Entry)
#define IsListEmpty(ListHead)
Definition: env_spec_w32.h:954
#define RemoveHeadList(ListHead)
Definition: env_spec_w32.h:964
#define InitializeListHead(ListHead)
Definition: env_spec_w32.h:944
@ Success
Definition: eventcreate.c:712
_Must_inspect_result_ _In_ PDEVICE_OBJECT _In_ PSECTION_OBJECT_POINTERS SectionObjectPointer
Definition: fsrtlfuncs.h:1369
#define min(a, b)
Definition: monoChain.cc:55
#define MAXLONGLONG
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:102
BOOLEAN NTAPI CcUninitializeCacheMap(IN PFILE_OBJECT FileObject, IN PLARGE_INTEGER TruncateSize OPTIONAL, IN PCACHE_UNINITIALIZE_EVENT UninitializeCompleteEvent OPTIONAL)
Definition: fs.c:365
VOID CcRosUnmarkDirtyVacb(PROS_VACB Vacb, BOOLEAN LockViews)
Definition: view.c:702
#define CcRosVacbGetRefCount(vacb)
Definition: cc.h:510
FORCEINLINE ULONG CcRosVacbDecRefCount(PROS_VACB vacb)
Definition: cc.h:498
BOOLEAN NTAPI MmPurgeSegment(_In_ PSECTION_OBJECT_POINTERS SectionObjectPointer, _In_opt_ PLARGE_INTEGER Offset, _In_ ULONG Length)
Definition: section.c:4828
#define KeAcquireSpinLockAtDpcLevel(SpinLock)
Definition: ke.h:125
#define KeReleaseSpinLockFromDpcLevel(SpinLock)
Definition: ke.h:135
PFILE_OBJECT FileObject
Definition: cctypes.h:76
LIST_ENTRY CacheMapVacbListHead
Definition: cc.h:193
KSPIN_LOCK CacheMapLock
Definition: cc.h:195
LIST_ENTRY PrivateList
Definition: cc.h:187
LIST_ENTRY CacheMapVacbListEntry
Definition: cc.h:216
LARGE_INTEGER FileOffset
Definition: cc.h:222
LIST_ENTRY VacbLruListEntry
Definition: cc.h:220
int64_t LONGLONG
Definition: typedefs.h:68
uint32_t ULONG
Definition: typedefs.h:59
LONGLONG QuadPart
Definition: typedefs.h:114
#define VACB_MAPPING_GRANULARITY
_Requires_lock_held_ Interrupt _Releases_lock_ Interrupt _In_ _IRQL_restores_ KIRQL OldIrql
Definition: kefuncs.h:778

Referenced by CcSetFileSizes(), and CcUninitializeCacheMap().

◆ CcSetFileSizes()

VOID NTAPI CcSetFileSizes ( IN PFILE_OBJECT  FileObject,
IN PCC_FILE_SIZES  FileSizes 
)

Definition at line 295 of file fs.c.

298{
300 PROS_SHARED_CACHE_MAP SharedCacheMap;
301 LARGE_INTEGER OldSectionSize;
302
303 CCTRACE(CC_API_DEBUG, "FileObject=%p FileSizes=%p\n",
305
306 DPRINT("CcSetFileSizes(FileObject 0x%p, FileSizes 0x%p)\n",
308 DPRINT("AllocationSize %I64d, FileSize %I64d, ValidDataLength %I64d\n",
312
313 SharedCacheMap = FileObject->SectionObjectPointer->SharedCacheMap;
314
315 /*
316 * It is valid to call this function on file objects that weren't
317 * initialized for caching. In this case it's simple no-op.
318 */
319 if (SharedCacheMap == NULL)
320 return;
321
322 /* Update the relevant fields */
323 KeAcquireSpinLock(&SharedCacheMap->CacheMapLock, &OldIrql);
324 OldSectionSize = SharedCacheMap->SectionSize;
325 SharedCacheMap->SectionSize = FileSizes->AllocationSize;
326 SharedCacheMap->FileSize = FileSizes->FileSize;
327 SharedCacheMap->ValidDataLength = FileSizes->ValidDataLength;
328 KeReleaseSpinLock(&SharedCacheMap->CacheMapLock, OldIrql);
329
330 if (FileSizes->AllocationSize.QuadPart < OldSectionSize.QuadPart)
331 {
332 CcPurgeCacheSection(FileObject->SectionObjectPointer,
334 0,
335 FALSE);
336 }
337 else
338 {
339 /* Extend our section object */
340 MmExtendSection(SharedCacheMap->Section, &SharedCacheMap->SectionSize);
341 }
342}
#define KeReleaseSpinLock(sl, irql)
Definition: env_spec_w32.h:627
#define KeAcquireSpinLock(sl, irql)
Definition: env_spec_w32.h:609
BOOLEAN NTAPI CcPurgeCacheSection(IN PSECTION_OBJECT_POINTERS SectionObjectPointer, IN PLARGE_INTEGER FileOffset OPTIONAL, IN ULONG Length, IN BOOLEAN UninitializeCacheMaps)
Definition: fs.c:157
NTSTATUS NTAPI MmExtendSection(_In_ PVOID Section, _Inout_ PLARGE_INTEGER NewSize)
Definition: section.c:5273
#define DPRINT
Definition: sndvol32.h:73
LARGE_INTEGER ValidDataLength
Definition: cc.h:178

◆ CcSetLogHandleForFile()

VOID NTAPI CcSetLogHandleForFile ( IN PFILE_OBJECT  FileObject,
IN PVOID  LogHandle,
IN PFLUSH_TO_LSN  FlushToLsnRoutine 
)

Definition at line 349 of file fs.c.

353{
354 CCTRACE(CC_API_DEBUG, "FileObject=%p LogHandle=%p FlushToLsnRoutine=%p\n",
355 FileObject, LogHandle, FlushToLsnRoutine);
356
358}

◆ CcUninitializeCacheMap()

BOOLEAN NTAPI CcUninitializeCacheMap ( IN PFILE_OBJECT  FileObject,
IN PLARGE_INTEGER TruncateSize  OPTIONAL,
IN PCACHE_UNINITIALIZE_EVENT UninitializeCompleteEvent  OPTIONAL 
)

Definition at line 365 of file fs.c.

369{
371 PROS_SHARED_CACHE_MAP SharedCacheMap;
373
374 CCTRACE(CC_API_DEBUG, "FileObject=%p TruncateSize=%p UninitializeCompleteEvent=%p\n",
375 FileObject, TruncateSize, UninitializeCompleteEvent);
376
377 if (TruncateSize != NULL &&
378 FileObject->SectionObjectPointer->SharedCacheMap != NULL)
379 {
380 SharedCacheMap = FileObject->SectionObjectPointer->SharedCacheMap;
381 KeAcquireSpinLock(&SharedCacheMap->CacheMapLock, &OldIrql);
382 if (SharedCacheMap->FileSize.QuadPart > TruncateSize->QuadPart)
383 {
384 SharedCacheMap->FileSize = *TruncateSize;
385 }
386 KeReleaseSpinLock(&SharedCacheMap->CacheMapLock, OldIrql);
387 CcPurgeCacheSection(FileObject->SectionObjectPointer,
388 TruncateSize,
389 0,
390 FALSE);
391 }
392
394 if (UninitializeCompleteEvent)
395 {
396 KeSetEvent(&UninitializeCompleteEvent->Event, IO_NO_INCREMENT, FALSE);
397 }
398 return NT_SUCCESS(Status);
399}
#define KeSetEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:476
NTSTATUS CcRosReleaseFileCache(PFILE_OBJECT FileObject)
Definition: view.c:1221
#define IO_NO_INCREMENT
Definition: iotypes.h:598

Referenced by CcPurgeCacheSection().