Use W32API for NTOSKRNL.
[reactos.git] / reactos / ntoskrnl / include / internal / cc.h
1 #ifndef __INCLUDE_INTERNAL_CC_H
2 #define __INCLUDE_INTERNAL_CC_H
3
4 typedef struct _BCB
5 {
6 LIST_ENTRY BcbSegmentListHead;
7 LIST_ENTRY BcbRemoveListEntry;
8 BOOLEAN RemoveOnClose;
9 ULONG TimeStamp;
10 PFILE_OBJECT FileObject;
11 ULONG CacheSegmentSize;
12 LARGE_INTEGER AllocationSize;
13 LARGE_INTEGER FileSize;
14 KSPIN_LOCK BcbLock;
15 ULONG RefCount;
16 } BCB, *PBCB;
17
18 typedef struct _CACHE_SEGMENT
19 {
20 /* Base address of the region where the cache segment data is mapped. */
21 PVOID BaseAddress;
22 /*
23 * Memory area representing the region where the cache segment data is
24 * mapped.
25 */
26 struct _MEMORY_AREA* MemoryArea;
27 /* Are the contents of the cache segment data valid. */
28 BOOLEAN Valid;
29 /* Are the contents of the cache segment data newer than those on disk. */
30 BOOLEAN Dirty;
31 /* Page out in progress */
32 BOOLEAN PageOut;
33 ULONG MappedCount;
34 /* Entry in the list of segments for this BCB. */
35 LIST_ENTRY BcbSegmentListEntry;
36 /* Entry in the list of segments which are dirty. */
37 LIST_ENTRY DirtySegmentListEntry;
38 /* Entry in the list of segments. */
39 LIST_ENTRY CacheSegmentListEntry;
40 LIST_ENTRY CacheSegmentLRUListEntry;
41 /* Offset in the file which this cache segment maps. */
42 ULONG FileOffset;
43 /* Lock. */
44 FAST_MUTEX Lock;
45 /* Number of references. */
46 ULONG ReferenceCount;
47 /* Pointer to the BCB for the file which this cache segment maps data for. */
48 PBCB Bcb;
49 /* Pointer to the next cache segment in a chain. */
50 struct _CACHE_SEGMENT* NextInChain;
51 } CACHE_SEGMENT, *PCACHE_SEGMENT;
52
53 typedef struct _INTERNAL_BCB
54 {
55 PUBLIC_BCB PFCB;
56 PCACHE_SEGMENT CacheSegment;
57 BOOLEAN Dirty;
58 CSHORT RefCount; /* (At offset 0x34 on WinNT4) */
59 } INTERNAL_BCB, *PINTERNAL_BCB;
60
61 VOID
62 STDCALL
63 CcMdlReadCompleteDev(IN PMDL MdlChain,
64 IN PFILE_OBJECT FileObject);
65
66 VOID
67 STDCALL
68 CcMdlWriteCompleteDev(IN PLARGE_INTEGER FileOffset,
69 IN PMDL MdlChain,
70 IN PFILE_OBJECT FileObject);
71
72 NTSTATUS
73 CcRosFlushCacheSegment(PCACHE_SEGMENT CacheSegment);
74
75 NTSTATUS
76 CcRosGetCacheSegment(PBCB Bcb,
77 ULONG FileOffset,
78 PULONG BaseOffset,
79 PVOID* BaseAddress,
80 PBOOLEAN UptoDate,
81 PCACHE_SEGMENT* CacheSeg);
82 VOID
83 CcInitView(VOID);
84
85 NTSTATUS
86 CcRosFreeCacheSegment(PBCB, PCACHE_SEGMENT);
87
88 NTSTATUS
89 ReadCacheSegment(PCACHE_SEGMENT CacheSeg);
90
91 NTSTATUS
92 WriteCacheSegment(PCACHE_SEGMENT CacheSeg);
93
94 VOID CcInit(VOID);
95
96 NTSTATUS
97 CcRosUnmapCacheSegment(PBCB Bcb, ULONG FileOffset, BOOLEAN NowDirty);
98
99 PCACHE_SEGMENT
100 CcRosLookupCacheSegment(PBCB Bcb, ULONG FileOffset);
101
102 NTSTATUS
103 CcRosGetCacheSegmentChain(PBCB Bcb,
104 ULONG FileOffset,
105 ULONG Length,
106 PCACHE_SEGMENT* CacheSeg);
107
108 VOID
109 CcInitCacheZeroPage(VOID);
110
111 NTSTATUS
112 CcRosMarkDirtyCacheSegment(PBCB Bcb, ULONG FileOffset);
113
114 NTSTATUS
115 CcRosFlushDirtyPages(ULONG Target, PULONG Count);
116
117 VOID
118 CcRosDereferenceCache(PFILE_OBJECT FileObject);
119
120 VOID
121 CcRosReferenceCache(PFILE_OBJECT FileObject);
122
123 VOID
124 CcRosSetRemoveOnClose(PSECTION_OBJECT_POINTERS SectionObjectPointer);
125
126 NTSTATUS
127 CcRosReleaseCacheSegment (BCB* Bcb,
128 CACHE_SEGMENT* CacheSeg,
129 BOOLEAN Valid,
130 BOOLEAN Dirty,
131 BOOLEAN Mapped);
132
133 NTSTATUS STDCALL
134 CcRosRequestCacheSegment (BCB* Bcb,
135 ULONG FileOffset,
136 PVOID* BaseAddress,
137 PBOOLEAN UptoDate,
138 CACHE_SEGMENT** CacheSeg);
139
140 NTSTATUS
141 CcTryToInitializeFileCache(PFILE_OBJECT FileObject);
142
143 /*
144 * Macro for generic cache manage bugchecking. Note that this macro assumes
145 * that the file name including extension is always longer than 4 characters.
146 */
147 #define KEBUGCHECKCC \
148 KEBUGCHECKEX(CACHE_MANAGER, \
149 (*(DWORD*)(__FILE__ + sizeof(__FILE__) - 4) << 16) | \
150 (__LINE__ & 0xFFFF), 0, 0, 0)
151
152 #endif