Move some profile stuff to NDK and fix some bugs in the executive implementation...
[reactos.git] / reactos / ntoskrnl / fs / fastio.c
1 /*
2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS Kernel
4 * FILE: ntoskrnl/fs/fastio.c
5 * PURPOSE: File System Routines which support Fast I/O or Cc Access.
6 *
7 * PROGRAMMERS: Alex Ionescu (alex@relsoft.net)
8 */
9
10 /* INCLUDES ****************************************************************/
11
12 #include <ntoskrnl.h>
13 #define NDEBUG
14 #include <internal/debug.h>
15
16 /* GLOBALS *******************************************************************/
17
18 extern ULONG CcFastReadNotPossible;
19 extern ULONG CcFastReadResourceMiss;
20 extern ULONG CcFastReadWait;
21 extern ULONG CcFastReadNoWait;
22
23 /* FUNCTIONS *****************************************************************/
24
25 /*
26 * @implemented
27 */
28 VOID
29 STDCALL
30 FsRtlIncrementCcFastReadResourceMiss( VOID )
31 {
32 CcFastReadResourceMiss++;
33 }
34
35 /*
36 * @implemented
37 */
38 VOID
39 STDCALL
40 FsRtlIncrementCcFastReadNotPossible( VOID )
41 {
42 CcFastReadNotPossible++;
43 }
44
45 /*
46 * @implemented
47 */
48 VOID
49 STDCALL
50 FsRtlIncrementCcFastReadWait( VOID )
51 {
52 CcFastReadWait++;
53 }
54
55 /*
56 * @implemented
57 */
58 VOID
59 STDCALL
60 FsRtlIncrementCcFastReadNoWait( VOID )
61 {
62 CcFastReadNoWait++;
63 }
64
65 /*
66 * NAME EXPORTED
67 * FsRtlCopyRead@32
68 *
69 * DESCRIPTION
70 *
71 * ARGUMENTS
72 *
73 * RETURN VALUE
74 *
75 * NOTE
76 * From Bo Branten's ntifs.h v12.
77 *
78 * @unimplemented
79 */
80 BOOLEAN
81 STDCALL
82 FsRtlCopyRead(IN PFILE_OBJECT FileObject,
83 IN PLARGE_INTEGER FileOffset,
84 IN ULONG Length,
85 IN BOOLEAN Wait,
86 IN ULONG LockKey,
87 OUT PVOID Buffer,
88 OUT PIO_STATUS_BLOCK IoStatus,
89 IN PDEVICE_OBJECT DeviceObject)
90 {
91 UNIMPLEMENTED;
92 return FALSE;
93 }
94
95 /*
96 * NAME EXPORTED
97 * FsRtlCopyWrite@32
98 *
99 * DESCRIPTION
100 *
101 * ARGUMENTS
102 *
103 * RETURN VALUE
104 *
105 * NOTE
106 * From Bo Branten's ntifs.h v12.
107 *
108 * @unimplemented
109 */
110 BOOLEAN
111 STDCALL
112 FsRtlCopyWrite(IN PFILE_OBJECT FileObject,
113 IN PLARGE_INTEGER FileOffset,
114 IN ULONG Length,
115 IN BOOLEAN Wait,
116 IN ULONG LockKey,
117 OUT PVOID Buffer,
118 OUT PIO_STATUS_BLOCK IoStatus,
119 IN PDEVICE_OBJECT DeviceObject)
120 {
121 UNIMPLEMENTED;
122 return FALSE;
123 }
124
125 /*
126 * NAME EXPORTED
127 * FsRtlGetFileSize@8
128 *
129 * DESCRIPTION
130 *
131 * ARGUMENTS
132 *
133 * RETURN VALUE
134 *
135 * @implemented
136 */
137 NTSTATUS
138 STDCALL
139 FsRtlGetFileSize(IN PFILE_OBJECT FileObject,
140 IN OUT PLARGE_INTEGER FileSize)
141 {
142 FILE_STANDARD_INFORMATION Info;
143 NTSTATUS Status;
144 IO_STATUS_BLOCK IoStatusBlock;
145 ULONG Length;
146 PDEVICE_OBJECT DeviceObject;
147 PFAST_IO_DISPATCH FastDispatch;
148
149 /* Get Device Object and Fast Calls */
150 DeviceObject = IoGetRelatedDeviceObject(FileObject);
151 FastDispatch = DeviceObject->DriverObject->FastIoDispatch;
152
153 /* Check if we support Fast Calls, and check this one */
154 if (FastDispatch && FastDispatch->FastIoQueryStandardInfo)
155 {
156 /* Fast Path */
157 FastDispatch->FastIoQueryStandardInfo(FileObject,
158 TRUE,
159 &Info,
160 &IoStatusBlock,
161 DeviceObject);
162 Status = IoStatusBlock.Status;
163 }
164 else
165 {
166 /* Slow Path */
167 Status = IoQueryFileInformation(FileObject,
168 FileStandardInformation,
169 sizeof(Info),
170 &Info,
171 &Length);
172 }
173
174 /* Check success */
175 if (NT_SUCCESS(Status))
176 {
177 *FileSize = Info.EndOfFile;
178 }
179
180 /* Return status */
181 return Status;
182 }
183
184 /*
185 * NAME EXPORTED
186 * FsRtlMdlRead@24
187 *
188 * DESCRIPTION
189 *
190 * ARGUMENTS
191 *
192 * RETURN VALUE
193 *
194 * @implemented
195 */
196 BOOLEAN
197 STDCALL
198 FsRtlMdlRead(IN PFILE_OBJECT FileObject,
199 IN PLARGE_INTEGER FileOffset,
200 IN ULONG Length,
201 IN ULONG LockKey,
202 OUT PMDL *MdlChain,
203 OUT PIO_STATUS_BLOCK IoStatus)
204 {
205 PDEVICE_OBJECT DeviceObject, BaseDeviceObject;
206 PFAST_IO_DISPATCH FastDispatch;
207
208 /* Get Device Object and Fast Calls */
209 DeviceObject = IoGetRelatedDeviceObject(FileObject);
210 FastDispatch = DeviceObject->DriverObject->FastIoDispatch;
211
212 /* Check if we support Fast Calls, and check this one */
213 if (FastDispatch && FastDispatch->MdlRead)
214 {
215 /* Use the fast path */
216 return FastDispatch->MdlRead(FileObject,
217 FileOffset,
218 Length,
219 LockKey,
220 MdlChain,
221 IoStatus,
222 DeviceObject);
223 }
224
225 /* Get the Base File System (Volume) and Fast Calls */
226 BaseDeviceObject = IoGetBaseFileSystemDeviceObject(FileObject);
227 FastDispatch = BaseDeviceObject->DriverObject->FastIoDispatch;
228
229 /* If the Base Device Object has its own FastDispatch Routine, fail */
230 if (FastDispatch && FastDispatch->MdlRead &&
231 BaseDeviceObject != DeviceObject)
232 {
233 return FALSE;
234 }
235
236 /* No fast path, use slow path */
237 return FsRtlMdlReadDev(FileObject,
238 FileOffset,
239 Length,
240 LockKey,
241 MdlChain,
242 IoStatus,
243 DeviceObject);
244 }
245
246 /*
247 * NAME EXPORTED
248 * FsRtlMdlReadComplete@8
249 *
250 * DESCRIPTION
251 *
252 * ARGUMENTS
253 *
254 * RETURN VALUE
255 *
256 * @implemented
257 */
258 BOOLEAN
259 STDCALL
260 FsRtlMdlReadComplete(IN PFILE_OBJECT FileObject,
261 IN OUT PMDL MdlChain)
262 {
263 PDEVICE_OBJECT DeviceObject, BaseDeviceObject;
264 PFAST_IO_DISPATCH FastDispatch;
265
266 /* Get Device Object and Fast Calls */
267 DeviceObject = IoGetRelatedDeviceObject(FileObject);
268 FastDispatch = DeviceObject->DriverObject->FastIoDispatch;
269
270 /* Check if we support Fast Calls, and check this one */
271 if (FastDispatch && FastDispatch->MdlReadComplete)
272 {
273 /* Use the fast path */
274 return FastDispatch->MdlReadComplete(FileObject,
275 MdlChain,
276 DeviceObject);
277 }
278
279 /* Get the Base File System (Volume) and Fast Calls */
280 BaseDeviceObject = IoGetBaseFileSystemDeviceObject(FileObject);
281 FastDispatch = BaseDeviceObject->DriverObject->FastIoDispatch;
282
283 /* If the Base Device Object has its own FastDispatch Routine, fail */
284 if (FastDispatch && FastDispatch->MdlReadComplete &&
285 BaseDeviceObject != DeviceObject)
286 {
287 return FALSE;
288 }
289
290 /* No fast path, use slow path */
291 return FsRtlMdlReadCompleteDev(FileObject, MdlChain, DeviceObject);
292 }
293
294
295 /*
296 * NAME EXPORTED
297 * FsRtlMdlReadCompleteDev@12
298 *
299 * DESCRIPTION
300 *
301 * ARGUMENTS
302 *
303 * RETURN VALUE
304 *
305 * NOTE
306 * From Bo Branten's ntifs.h v13.
307 * (CcMdlReadCompleteDev declared in internal/cc.h)
308 *
309 * @implemented
310 */
311 BOOLEAN
312 STDCALL
313 FsRtlMdlReadCompleteDev(IN PFILE_OBJECT FileObject,
314 IN PMDL MdlChain,
315 IN PDEVICE_OBJECT DeviceObject)
316 {
317 /* Call the Cache Manager */
318 CcMdlReadCompleteDev(MdlChain, FileObject);
319 return TRUE;
320 }
321
322 /*
323 * NAME EXPORTED
324 * FsRtlMdlReadDev@28
325 *
326 * DESCRIPTION
327 *
328 * ARGUMENTS
329 *
330 * RETURN VALUE
331 *
332 * @unimplemented
333 */
334 BOOLEAN
335 STDCALL
336 FsRtlMdlReadDev(IN PFILE_OBJECT FileObject,
337 IN PLARGE_INTEGER FileOffset,
338 IN ULONG Length,
339 IN ULONG LockKey,
340 OUT PMDL *MdlChain,
341 OUT PIO_STATUS_BLOCK IoStatus,
342 IN PDEVICE_OBJECT DeviceObject)
343 {
344 UNIMPLEMENTED;
345 return FALSE;
346 }
347
348
349 /*
350 * NAME EXPORTED
351 * FsRtlMdlWriteComplete@12
352 *
353 * DESCRIPTION
354 *
355 * ARGUMENTS
356 *
357 * RETURN VALUE
358 *
359 * @implemented
360 */
361 BOOLEAN
362 STDCALL
363 FsRtlMdlWriteComplete(IN PFILE_OBJECT FileObject,
364 IN PLARGE_INTEGER FileOffset,
365 IN PMDL MdlChain)
366 {
367 PDEVICE_OBJECT DeviceObject, BaseDeviceObject;
368 PFAST_IO_DISPATCH FastDispatch;
369
370 /* Get Device Object and Fast Calls */
371 DeviceObject = IoGetRelatedDeviceObject(FileObject);
372 FastDispatch = DeviceObject->DriverObject->FastIoDispatch;
373
374 /* Check if we support Fast Calls, and check this one */
375 if (FastDispatch && FastDispatch->MdlWriteComplete)
376 {
377 /* Use the fast path */
378 return FastDispatch->MdlWriteComplete(FileObject,
379 FileOffset,
380 MdlChain,
381 DeviceObject);
382 }
383
384 /* Get the Base File System (Volume) and Fast Calls */
385 BaseDeviceObject = IoGetBaseFileSystemDeviceObject(FileObject);
386 FastDispatch = BaseDeviceObject->DriverObject->FastIoDispatch;
387
388 /* If the Base Device Object has its own FastDispatch Routine, fail */
389 if (FastDispatch && FastDispatch->MdlWriteComplete &&
390 BaseDeviceObject != DeviceObject)
391 {
392 return FALSE;
393 }
394
395 /* No fast path, use slow path */
396 return FsRtlMdlWriteCompleteDev(FileObject,
397 FileOffset,
398 MdlChain,
399 DeviceObject);
400 }
401
402 /*
403 * NAME EXPORTED
404 * FsRtlMdlWriteCompleteDev@16
405 *
406 * DESCRIPTION
407 *
408 * ARGUMENTS
409 *
410 * RETURN VALUE
411 *
412 * @implemented
413 */
414 BOOLEAN
415 STDCALL
416 FsRtlMdlWriteCompleteDev(IN PFILE_OBJECT FileObject,
417 IN PLARGE_INTEGER FileOffset,
418 IN PMDL MdlChain,
419 IN PDEVICE_OBJECT DeviceObject)
420 {
421 /* Call the Cache Manager */
422 CcMdlWriteCompleteDev(FileOffset, MdlChain, FileObject);
423 return TRUE;
424 }
425
426
427 /*
428 * NAME EXPORTED
429 * FsRtlPrepareMdlWrite@24
430 *
431 * DESCRIPTION
432 *
433 * ARGUMENTS
434 *
435 * RETURN VALUE
436 *
437 * @implemented
438 */
439 BOOLEAN
440 STDCALL
441 FsRtlPrepareMdlWrite(IN PFILE_OBJECT FileObject,
442 IN PLARGE_INTEGER FileOffset,
443 IN ULONG Length,
444 IN ULONG LockKey,
445 OUT PMDL *MdlChain,
446 OUT PIO_STATUS_BLOCK IoStatus)
447 {
448 PDEVICE_OBJECT DeviceObject, BaseDeviceObject;
449 PFAST_IO_DISPATCH FastDispatch;
450
451 /* Get Device Object and Fast Calls */
452 DeviceObject = IoGetRelatedDeviceObject(FileObject);
453 FastDispatch = DeviceObject->DriverObject->FastIoDispatch;
454
455 /* Check if we support Fast Calls, and check this one */
456 if (FastDispatch && FastDispatch->PrepareMdlWrite)
457 {
458 /* Use the fast path */
459 return FastDispatch->PrepareMdlWrite(FileObject,
460 FileOffset,
461 Length,
462 LockKey,
463 MdlChain,
464 IoStatus,
465 DeviceObject);
466 }
467
468 /* Get the Base File System (Volume) and Fast Calls */
469 BaseDeviceObject = IoGetBaseFileSystemDeviceObject(FileObject);
470 FastDispatch = BaseDeviceObject->DriverObject->FastIoDispatch;
471
472 /* If the Base Device Object has its own FastDispatch Routine, fail */
473 if (FastDispatch && FastDispatch->PrepareMdlWrite &&
474 BaseDeviceObject != DeviceObject)
475 {
476 return FALSE;
477 }
478
479 /* No fast path, use slow path */
480 return FsRtlPrepareMdlWriteDev(FileObject,
481 FileOffset,
482 Length,
483 LockKey,
484 MdlChain,
485 IoStatus,
486 DeviceObject);
487 }
488
489 /*
490 * NAME EXPORTED
491 * FsRtlPrepareMdlWriteDev@28
492 *
493 * DESCRIPTION
494 *
495 * ARGUMENTS
496 *
497 * RETURN VALUE
498 *
499 * @unimplemented
500 */
501 BOOLEAN
502 STDCALL
503 FsRtlPrepareMdlWriteDev(IN PFILE_OBJECT FileObject,
504 IN PLARGE_INTEGER FileOffset,
505 IN ULONG Length,
506 IN ULONG LockKey,
507 OUT PMDL *MdlChain,
508 OUT PIO_STATUS_BLOCK IoStatus,
509 IN PDEVICE_OBJECT DeviceObject)
510 {
511 UNIMPLEMENTED;
512 return FALSE;
513 }
514
515 /* EOF */