Added Stubs for Cache Manager functions in their appropriate file.
[reactos.git] / reactos / ntoskrnl / cc / fs.c
1 /* COPYRIGHT: See COPYING in the top level directory
2 * PROJECT: ReactOS kernel
3 * FILE: ntoskrnl/cc/fs.c
4 * PURPOSE: Implements cache managers functions useful for File Systems
5 * PROGRAMMER: Alex Ionescu
6 * UPDATE HISTORY:
7 * Created 20/06/04
8 */
9
10 /* INCLUDES ******************************************************************/
11
12 #include <ddk/ntddk.h>
13 #include <ddk/ntifs.h>
14 #include <internal/mm.h>
15 #include <internal/cc.h>
16 #include <internal/pool.h>
17 #include <internal/io.h>
18 #include <ntos/minmax.h>
19
20 #define NDEBUG
21 #include <internal/debug.h>
22
23 /* GLOBALS *****************************************************************/
24
25 extern FAST_MUTEX ViewLock;
26 extern ULONG DirtyPageCount;
27
28 NTSTATUS CcRosInternalFreeCacheSegment(PCACHE_SEGMENT CacheSeg);
29
30 /* FUNCTIONS *****************************************************************/
31
32 /*
33 * @unimplemented
34 */
35 LARGE_INTEGER
36 STDCALL
37 CcGetDirtyPages (
38 IN PVOID LogHandle,
39 IN PDIRTY_PAGE_ROUTINE DirtyPageRoutine,
40 IN PVOID Context1,
41 IN PVOID Context2
42 )
43 {
44 UNIMPLEMENTED;
45
46 LARGE_INTEGER i;
47 i.QuadPart = 0;
48 return i;
49 }
50
51 /*
52 * @unimplemented
53 */
54 PFILE_OBJECT
55 STDCALL
56 CcGetFileObjectFromBcb (
57 IN PVOID Bcb
58 )
59 {
60 UNIMPLEMENTED;
61 return 0;
62 }
63
64 /*
65 * @unimplemented
66 */
67 LARGE_INTEGER
68 STDCALL
69 CcGetLsnForFileObject (
70 IN PFILE_OBJECT FileObject,
71 OUT PLARGE_INTEGER OldestLsn OPTIONAL
72 )
73 {
74 UNIMPLEMENTED;
75
76 LARGE_INTEGER i;
77 i.QuadPart = 0;
78 return i;
79 }
80
81 /*
82 * @unimplemented
83 */
84 VOID
85 STDCALL
86 CcInitializeCacheMap (
87 IN PFILE_OBJECT FileObject,
88 IN PCC_FILE_SIZES FileSizes,
89 IN BOOLEAN PinAccess,
90 IN PCACHE_MANAGER_CALLBACKS CallBacks,
91 IN PVOID LazyWriterContext
92 )
93 {
94 UNIMPLEMENTED;
95 }
96
97 /*
98 * @unimplemented
99 */
100 BOOLEAN
101 STDCALL
102 CcIsThereDirtyData (
103 IN PVPB Vpb
104 )
105 {
106 UNIMPLEMENTED;
107 return FALSE;
108 }
109
110 /*
111 * @unimplemented
112 */
113 BOOLEAN
114 STDCALL
115 CcPurgeCacheSection (
116 IN PSECTION_OBJECT_POINTERS SectionObjectPointer,
117 IN PLARGE_INTEGER FileOffset OPTIONAL,
118 IN ULONG Length,
119 IN BOOLEAN UninitializeCacheMaps
120 )
121 {
122 UNIMPLEMENTED;
123 return FALSE;
124 }
125
126
127 /*
128 * @implemented
129 */
130 VOID STDCALL
131 CcSetFileSizes (IN PFILE_OBJECT FileObject,
132 IN PCC_FILE_SIZES FileSizes)
133 {
134 KIRQL oldirql;
135 PBCB Bcb;
136 PLIST_ENTRY current_entry;
137 PCACHE_SEGMENT current;
138 LIST_ENTRY FreeListHead;
139 NTSTATUS Status;
140
141 DPRINT("CcSetFileSizes(FileObject %x, FileSizes %x)\n",
142 FileObject, FileSizes);
143 DPRINT("AllocationSize %d, FileSize %d, ValidDataLength %d\n",
144 (ULONG)FileSizes->AllocationSize.QuadPart,
145 (ULONG)FileSizes->FileSize.QuadPart,
146 (ULONG)FileSizes->ValidDataLength.QuadPart);
147
148 Bcb = FileObject->SectionObjectPointer->SharedCacheMap;
149 assert(Bcb);
150
151 if (FileSizes->AllocationSize.QuadPart < Bcb->AllocationSize.QuadPart)
152 {
153 InitializeListHead(&FreeListHead);
154 ExAcquireFastMutex(&ViewLock);
155 KeAcquireSpinLock(&Bcb->BcbLock, &oldirql);
156
157 current_entry = Bcb->BcbSegmentListHead.Flink;
158 while (current_entry != &Bcb->BcbSegmentListHead)
159 {
160 current = CONTAINING_RECORD(current_entry, CACHE_SEGMENT, BcbSegmentListEntry);
161 current_entry = current_entry->Flink;
162 if (current->FileOffset > FileSizes->AllocationSize.QuadPart)
163 {
164 if (current->ReferenceCount == 0 || (current->ReferenceCount == 1 && current->Dirty))
165 {
166 RemoveEntryList(&current->BcbSegmentListEntry);
167 RemoveEntryList(&current->CacheSegmentListEntry);
168 RemoveEntryList(&current->CacheSegmentLRUListEntry);
169 if (current->Dirty)
170 {
171 RemoveEntryList(&current->DirtySegmentListEntry);
172 DirtyPageCount -= Bcb->CacheSegmentSize / PAGE_SIZE;
173 }
174 InsertHeadList(&FreeListHead, &current->BcbSegmentListEntry);
175 }
176 else
177 {
178 DPRINT1("Anyone has referenced a cache segment behind the new size.\n");
179 KEBUGCHECK(0);
180 }
181 }
182 }
183
184 Bcb->AllocationSize = FileSizes->AllocationSize;
185 Bcb->FileSize = FileSizes->FileSize;
186 KeReleaseSpinLock(&Bcb->BcbLock, oldirql);
187 ExReleaseFastMutex(&ViewLock);
188
189 current_entry = FreeListHead.Flink;
190 while(current_entry != &FreeListHead)
191 {
192 current = CONTAINING_RECORD(current_entry, CACHE_SEGMENT, BcbSegmentListEntry);
193 current_entry = current_entry->Flink;
194 Status = CcRosInternalFreeCacheSegment(current);
195 if (!NT_SUCCESS(Status))
196 {
197 DPRINT1("CcRosInternalFreeCacheSegment failed, status = %x\n");
198 KEBUGCHECK(0);
199 }
200 }
201 }
202 else
203 {
204 KeAcquireSpinLock(&Bcb->BcbLock, &oldirql);
205 Bcb->AllocationSize = FileSizes->AllocationSize;
206 Bcb->FileSize = FileSizes->FileSize;
207 KeReleaseSpinLock(&Bcb->BcbLock, oldirql);
208 }
209 }
210
211 /*
212 * @unimplemented
213 */
214 VOID
215 STDCALL
216 CcSetLogHandleForFile (
217 IN PFILE_OBJECT FileObject,
218 IN PVOID LogHandle,
219 IN PFLUSH_TO_LSN FlushToLsnRoutine
220 )
221 {
222 UNIMPLEMENTED;
223 }
224
225 /*
226 * @unimplemented
227 */
228 BOOLEAN
229 STDCALL
230 CcUninitializeCacheMap (
231 IN PFILE_OBJECT FileObject,
232 IN PLARGE_INTEGER TruncateSize OPTIONAL,
233 IN PCACHE_UNINITIALIZE_EVENT UninitializeCompleteEvent OPTIONAL
234 )
235 {
236 UNIMPLEMENTED;
237 return FALSE;
238 }