3 #include "fsrtl_glue.h"
9 This is the main test function. It is called from DriverEntry.
11 There is a DbgBreakPoint() call at the beginning of DriverEntry.
12 In order to run the test again, simply type
19 BOOLEAN
FsRtlTest_StartTest() {
21 PFILE_OBJECT Pfo
= NULL
;
24 PFILE_OBJECT DirPfo
= NULL
;
27 IO_STATUS_BLOCK IoStatus
;
29 NTSTATUS Status
= STATUS_SUCCESS
;
37 LARGE_INTEGER OldSize
;
39 /* Parameters we are going to use in the test from the FCB */
40 PFSRTL_COMMON_FCB_HEADER FcbHeader
;
41 PLARGE_INTEGER AllocationSize
;
42 PLARGE_INTEGER ValidDataLength
;
43 PLARGE_INTEGER FileSize
;
45 PDEVICE_OBJECT pRelatedDo
= NULL
;
47 /* Allocate a 100KB buffer to do IOs */
48 Buffer
= ExAllocatePool(PagedPool
,100*_1KB
);
50 /* ------------------------------------------------------------------------
54 FsRtlCopyWrite(IN PFILE_OBJECT FileObject,
55 IN PLARGE_INTEGER FileOffset,
60 OUT PIO_STATUS_BLOCK IoStatus,
61 IN PDEVICE_OBJECT DeviceObject)
65 ------------------------------------------------------------------------ */
66 FsRtlTest_OpenTestFile(&Fh
, &Pfo
);
67 FSRTL_TEST("Opening Test File.",((Pfo
!= NULL
) && (Fh
!= NULL
)));
69 /* Extract the test variable from the FCB struct */
70 FcbHeader
= (PFSRTL_COMMON_FCB_HEADER
)Pfo
->FsContext
;
71 AllocationSize
= &FcbHeader
->AllocationSize
;
72 ValidDataLength
= &FcbHeader
->ValidDataLength
;
73 FileSize
= &FcbHeader
->FileSize
;
75 /* Try to cache without caching having been initialized. This should fail.*/
77 FSRTL_TEST("FsRtlCopyWrite() - No cache map test.",!FsRtlCopyWrite(Pfo
,AllocationSize
,Length
,TRUE
,0,Buffer
,&IoStatus
,NULL
));
79 /* We are going to build a 100k file */
80 /* This will inititate caching and build some size */
83 Return
= FsRltTest_WritefileZw(Fh
,&Offset
,Length
, Buffer
, &IoStatus
);
84 FSRTL_TEST("FsRtlCopyWrite() - Building 100k filesize.",(NT_SUCCESS(Return
) && NT_SUCCESS(IoStatus
.Status
) && IoStatus
.Information
== Length
));
87 /* Extending the file by 1/2 sector, 256 bytes. */
88 Offset
.QuadPart
= 0x7fffffffffff;
90 Return
= FsRltTest_WritefileZw(Fh
,NULL
,Length
, Buffer
, &IoStatus
);
91 FSRTL_TEST("FsRtlCopyWrite() - Extending by 1/2 sector.",(NT_SUCCESS(Return
) && NT_SUCCESS(IoStatus
.Status
) && IoStatus
.Information
== Length
));
94 /* Append to the file past the allocation size*/
95 Offset
.LowPart
= 0xFFFFFFFF;
96 Offset
.HighPart
= 0xFFFFFFFF;
97 OldSize
.QuadPart
= FileSize
->QuadPart
;
98 Length
= (ULONG
) (AllocationSize
->QuadPart
-ValidDataLength
->QuadPart
);
99 FSRTL_TEST("FsRtlCopyWrite() - Testing extending past allocation size",!FsRtlCopyWrite(Pfo
,&Offset
,Length
+1,TRUE
,0,Buffer
,&IoStatus
,NULL
));
100 FSRTL_TEST("FsRtlCopyWrite() - Testing extending not past allocation size",FsRtlCopyWrite(Pfo
,&Offset
,Length
,TRUE
,0,Buffer
,&IoStatus
,NULL
));
101 FSRTL_TEST("FsRtlCopyWrite() - Check filesize",(FileSize
->QuadPart
= (OldSize
.QuadPart
+Length
)));
103 /* Try do write a 65kb IO and check that if fails. Maximum IO size for thus function is 64KB */
106 FSRTL_TEST("FsRtlCopyWrite() - 65KB IO Test",!FsRtlCopyWrite(Pfo
,&Offset
,Length
,TRUE
,0,Buffer
,&IoStatus
,NULL
));
108 /* Try do write a 64kb IO. Maximum IO size for thus function is 64KB */
110 FSRTL_TEST("FsRtlCopyWrite() - 64KB IO Test",FsRtlCopyWrite(Pfo
,&Offset
,Length
,TRUE
,0,Buffer
,&IoStatus
,NULL
))
112 /* Test the fast Io questionable flag
113 This test fails and should succeed. I am not sure why. When FsRtlCopyWrite() queries the FastIoTable of the related
114 device object, it comes back with no.
115 FcbHeader->IsFastIoPossible = FastIoIsQuestionable;
116 FSRTL_TEST("FastIo is questionable flag",FsRtlCopyWrite(Pfo,&Offset,Length,TRUE,0,Buffer,&IoStatus,NULL))
119 /* Test the fast Io not possible flag */
120 FcbHeader
->IsFastIoPossible
= FastIoIsNotPossible
;
121 FSRTL_TEST("FsRtlCopyWrite() - FastIo is not possible flag",!FsRtlCopyWrite(Pfo
,&Offset
,Length
,TRUE
,0,Buffer
,&IoStatus
,NULL
))
122 /* Set the flag back to what it was */
123 FcbHeader
->IsFastIoPossible
= FastIoIsPossible
;
124 FSRTL_TEST("FsRtlCopyWrite() - FastIo is possbile flag",FsRtlCopyWrite(Pfo
,&Offset
,Length
,TRUE
,0,Buffer
,&IoStatus
,NULL
))
128 ObDereferenceObject(Pfo
);
138 /* ------------------------------------------------------------------------
142 FsRtlCopyWrite(IN PFILE_OBJECT FileObject,
143 IN PLARGE_INTEGER FileOffset,
148 OUT PIO_STATUS_BLOCK IoStatus,
149 IN PDEVICE_OBJECT DeviceObject)
153 ------------------------------------------------------------------------ */
155 /* We are going to repeat the same bunch of tests but with Wait = FALSE. So we exercise the second part of the function. */
156 FsRtlTest_OpenTestFile(&Fh
, &Pfo
);
158 /* Extract the test variable from the FCB struct */
159 FcbHeader
= (PFSRTL_COMMON_FCB_HEADER
)Pfo
->FsContext
;
160 AllocationSize
= &FcbHeader
->AllocationSize
;
161 ValidDataLength
= &FcbHeader
->ValidDataLength
;
162 FileSize
= &FcbHeader
->FileSize
;
164 /* Try to cache without caching having been initialized. This should fail.*/
166 FSRTL_TEST("FsRtlCopyWrite() - No cache map test. Wait = FALSE",!FsRtlCopyWrite(Pfo
,AllocationSize
,Length
,FALSE
,0,Buffer
,&IoStatus
,NULL
));
168 /* We are going to build a 100k file */
169 /* This will inititate caching and build some size */
172 Return
= FsRltTest_WritefileZw(Fh
,&Offset
,Length
, Buffer
, &IoStatus
);
173 FSRTL_TEST("FsRtlCopyWrite() - Building 100k filesize. Wait = FALSE",(NT_SUCCESS(Return
) && NT_SUCCESS(IoStatus
.Status
) && IoStatus
.Information
== Length
));
176 /* Extending the file by 1/2 sector, 256 bytes. */
177 Offset
.QuadPart
= 0x7fffffffffff;
179 Return
= FsRltTest_WritefileZw(Fh
,NULL
,Length
, Buffer
, &IoStatus
);
180 FSRTL_TEST("FsRtlCopyWrite() - Extending by 1/2 sector. Wait = FALSE",(NT_SUCCESS(Return
) && NT_SUCCESS(IoStatus
.Status
) && IoStatus
.Information
== Length
));
183 /* Append to the file past the allocation size*/
184 Offset
.LowPart
= 0xFFFFFFFF;
185 Offset
.HighPart
= 0xFFFFFFFF;
186 OldSize
.QuadPart
= FileSize
->QuadPart
;
187 Length
= (ULONG
) (AllocationSize
->QuadPart
-ValidDataLength
->QuadPart
);
188 FSRTL_TEST("FsRtlCopyWrite() - Testing extending past allocation size Wait = FALSE",!FsRtlCopyWrite(Pfo
,&Offset
,Length
+1,FALSE
,0,Buffer
,&IoStatus
,NULL
));
189 FSRTL_TEST("FsRtlCopyWrite() - Testing extending not past allocation size. Wait = FALSE",FsRtlCopyWrite(Pfo
,&Offset
,Length
,FALSE
,0,Buffer
,&IoStatus
,NULL
));
190 FSRTL_TEST("FsRtlCopyWrite() - Check filesize",(FileSize
->QuadPart
= (OldSize
.QuadPart
+Length
)));
192 /* Try do write a 65kb IO and check that if fails. Maximum IO size for thus function is 64KB */
195 FSRTL_TEST("FsRtlCopyWrite() - 65KB IO Test. Wait = FALSE",!FsRtlCopyWrite(Pfo
,&Offset
,Length
,FALSE
,0,Buffer
,&IoStatus
,NULL
));
197 /* Try do write a 64kb IO. Maximum IO size for thus function is 64KB */
199 FSRTL_TEST("FsRtlCopyWrite() - 64KB IO Test. Wait = FALSE",FsRtlCopyWrite(Pfo
,&Offset
,Length
,FALSE
,0,Buffer
,&IoStatus
,NULL
))
201 /* Test the fast Io questionable flag
202 This test fails and should succeed. I am not sure why. When FsRtlCopyWrite() queries the FastIoTable of the related
203 device object, it comes back with no.
204 FcbHeader->IsFastIoPossible = FastIoIsQuestionable;
205 FSRTL_TEST("FastIo is questionable flag",FsRtlCopyWrite(Pfo,&Offset,Length,TRUE,0,Buffer,&IoStatus,NULL))
208 /* Test the fast Io not possible flag */
209 FcbHeader
->IsFastIoPossible
= FastIoIsNotPossible
;
210 FSRTL_TEST("FsRtlCopyWrite() - FastIo is not possible flag. Wait = FALSE",!FsRtlCopyWrite(Pfo
,&Offset
,Length
,FALSE
,0,Buffer
,&IoStatus
,NULL
))
211 /* Set the flag back to what it was */
212 FcbHeader
->IsFastIoPossible
= FastIoIsPossible
;
213 FSRTL_TEST("FsRtlCopyWrite() - FastIo is possbile flag. Wait = FALSE",FsRtlCopyWrite(Pfo
,&Offset
,Length
,FALSE
,0,Buffer
,&IoStatus
,NULL
))
216 /* ------------------------------------------------------------------------------------------
221 FsRtlCopyRead(IN PFILE_OBJECT FileObject,
222 IN PLARGE_INTEGER FileOffset,
227 OUT PIO_STATUS_BLOCK IoStatus,
228 IN PDEVICE_OBJECT DeviceObject)
230 ------------------------------------------------------------------------------------------ */
232 Offset
.LowPart
= 0x0;
233 Offset
.HighPart
= 0x0;
236 /* Testing a 64KB read with Wait = TRUE */
237 Return
= FsRtlCopyRead(Pfo
,&Offset
,Length
,TRUE
,0,Buffer
,&IoStatus
,NULL
);
238 FSRTL_TEST("FsRtlCopyRead() - Testing 64k IO Wait=TRUE",(NT_SUCCESS(Return
) && NT_SUCCESS(IoStatus
.Status
) && IoStatus
.Information
== Length
));
241 /* Testing a 64KB read with Wait = FALSE */
242 Return
= FsRtlCopyRead(Pfo
,&Offset
,Length
,FALSE
,0,Buffer
,&IoStatus
,NULL
);
243 FSRTL_TEST("FsRtlCopyRead() - Testing 64k IO Wait=FALSE",(NT_SUCCESS(Return
) && NT_SUCCESS(IoStatus
.Status
) && IoStatus
.Information
== Length
));
246 /* Testing read past the end of the file */
247 Offset
.QuadPart
= FileSize
->QuadPart
- (5 * _1KB
);
249 Return
= FsRtlCopyRead(Pfo
,&Offset
,Length
,TRUE
,0,Buffer
,&IoStatus
,NULL
);
250 FSRTL_TEST("FsRtlCopyRead() - Testing reading past end of file but starting before EOF",(NT_SUCCESS(Return
) && NT_SUCCESS(IoStatus
.Status
) && IoStatus
.Information
== (FileSize
->QuadPart
-Offset
.QuadPart
)));
252 Offset
.QuadPart
= FileSize
->QuadPart
+ 1;
254 Return
= FsRtlCopyRead(Pfo
,&Offset
,Length
,TRUE
,0,Buffer
,&IoStatus
,NULL
);
255 FSRTL_TEST("FsRtlCopyRead() - Testing reading past end of file but starting after EOF",(NT_SUCCESS(Return
) && (IoStatus
.Status
== STATUS_END_OF_FILE
) && IoStatus
.Information
== 0));
258 /* Testing a 64KB read with Wait = TRUE */
259 Offset
.LowPart
= 0x0;
260 Offset
.HighPart
= 0x0;
262 FcbHeader
->IsFastIoPossible
= FastIoIsNotPossible
;
263 FSRTL_TEST("FsRtlCopyRead() - FastIo is not possible flag. Wait = FALSE",!FsRtlCopyRead(Pfo
,&Offset
,Length
,FALSE
,0,Buffer
,&IoStatus
,NULL
));
264 FSRTL_TEST("FsRtlCopyRead() - FastIo is not possible flag. Wait = TRUE",!FsRtlCopyRead(Pfo
,&Offset
,Length
,TRUE
,0,Buffer
,&IoStatus
,NULL
));
265 FcbHeader
->IsFastIoPossible
= FastIoIsPossible
;
270 ObDereferenceObject(Pfo
);
280 /* ------------------------------------------------------------------------
284 FsRtlPrepareMdlWriteDev(IN PFILE_OBJECT FileObject,
285 IN PLARGE_INTEGER FileOffset,
289 OUT PIO_STATUS_BLOCK IoStatus,
290 IN PDEVICE_OBJECT DeviceObject)
292 ------------------------------------------------------------------------ */
294 /* We are going to repeat the same bunch of tests but with Wait = FALSE. So we exercise the second part of the function. */
295 FsRtlTest_OpenTestFile(&Fh
, &Pfo
);
297 /* Extract the test variable from the FCB struct */
298 FcbHeader
= (PFSRTL_COMMON_FCB_HEADER
)Pfo
->FsContext
;
299 AllocationSize
= &FcbHeader
->AllocationSize
;
300 ValidDataLength
= &FcbHeader
->ValidDataLength
;
301 FileSize
= &FcbHeader
->FileSize
;
303 /* Try to cache without caching having been initialized. This should fail.*/
305 FSRTL_TEST("FsRtlPrepareMdlWriteDev() - No cache map test. Wait = FALSE",
306 !FsRtlPrepareMdlWriteDev(Pfo
,AllocationSize
,Length
,0,MdlChain
,&IoStatus
,NULL
));
308 /* We are going to build a 100k file */
309 /* This will inititate caching and build some size */
312 Return
= FsRltTest_WritefileZw(Fh
,&Offset
,Length
, Buffer
, &IoStatus
);
313 FSRTL_TEST("FsRtlPrepareMdlWriteDev() - Building 100k filesize. Wait = FALSE",(NT_SUCCESS(Return
) && NT_SUCCESS(IoStatus
.Status
) && IoStatus
.Information
== Length
));
316 /* Extending the file by 1/2 sector, 256 bytes. */
317 Offset
.QuadPart
= 0x7fffffffffff;
319 Return
= FsRltTest_WritefileZw(Fh
,NULL
,Length
, Buffer
, &IoStatus
);
320 FSRTL_TEST("FsRtlPrepareMdlWriteDev() - Extending by 1/2 sector. Wait = FALSE",(NT_SUCCESS(Return
) && NT_SUCCESS(IoStatus
.Status
) && IoStatus
.Information
== Length
));
324 pRelatedDo
= IoGetRelatedDeviceObject(Pfo
);
325 FSRTL_TEST("FsRtlPrepareMdlWriteDev() - Did we get related DO ?",pRelatedDo
);
328 /* Append to the file past the allocation size*/
329 Offset
.QuadPart
= FileSize
->QuadPart
;
330 OldSize
.QuadPart
= FileSize
->QuadPart
;
331 Length
= (ULONG
) (AllocationSize
->QuadPart
-ValidDataLength
->QuadPart
);
332 FSRTL_TEST("FsRtlPrepareMdlWriteDev() - Testing extending past allocation size.",
333 !FsRtlPrepareMdlWriteDev(Pfo
,&Offset
,Length
+1,0,&MdlChain
,&IoStatus
,pRelatedDo
));
335 FSRTL_TEST("FsRtlPrepareMdlWriteDev() - Testing extending not past allocation size.",
336 FsRtlPrepareMdlWriteDev(Pfo
,&Offset
,Length
,0,&MdlChain
,&IoStatus
,pRelatedDo
));
337 FSRTL_TEST("FsRtlPrepareMdlWriteDev() - Check filesize",(FileSize
->QuadPart
= (OldSize
.QuadPart
+Length
)));
338 FSRTL_TEST("FsRtlPrepareMdlWriteDev() - Release the MDL.",FsRtlMdlWriteCompleteDev(Pfo
,&Offset
,MdlChain
,pRelatedDo
));
341 /* Try do write a 65kb IO and check that if fails. Maximum IO size for thus function is 64KB */
345 FSRTL_TEST("FsRtlPrepareMdlWriteDev() - 65KB IO Test.",
346 FsRtlPrepareMdlWriteDev(Pfo
,&Offset
,Length
,0,&MdlChain
,&IoStatus
,pRelatedDo
));
347 FSRTL_TEST("FsRtlPrepareMdlWriteDev() - Release the MDL.",FsRtlMdlWriteCompleteDev(Pfo
,&Offset
,MdlChain
,pRelatedDo
));
349 /* Try do write a 64kb IO. Maximum IO size for thus function is 64KB */
352 FSRTL_TEST("FsRtlPrepareMdlWriteDev() - 64KB IO Test.",
353 FsRtlPrepareMdlWriteDev(Pfo
,&Offset
,Length
,0,&MdlChain
,&IoStatus
,NULL
))
354 FSRTL_TEST("FsRtlPrepareMdlWriteDev() - Release the MDL.",FsRtlMdlWriteCompleteDev(Pfo
,&Offset
,MdlChain
,NULL
));
356 /* Test the fast Io not possible flag */
357 FcbHeader
->IsFastIoPossible
= FastIoIsNotPossible
;
358 FSRTL_TEST("FsRtlPrepareMdlWriteDev() - FastIo is not possible flag.",
359 !FsRtlPrepareMdlWriteDev(Pfo
,&Offset
,Length
,0,&MdlChain
,&IoStatus
,NULL
))
363 ObDereferenceObject(Pfo
);
373 /* ------------------------------------------------------------------------
377 FsRtlPrepareMdlWrite( IN PFILE_OBJECT FileObject,
378 IN PLARGE_INTEGER FileOffset,
382 OUT PIO_STATUS_BLOCK IoStatus,
383 IN PDEVICE_OBJECT DeviceObject)
385 ------------------------------------------------------------------------ */
387 /* We are going to repeat the same bunch of tests but with Wait = FALSE. So we exercise the second part of the function. */
388 FsRtlTest_OpenTestFile(&Fh
, &Pfo
);
390 /* Extract the test variable from the FCB struct */
391 FcbHeader
= (PFSRTL_COMMON_FCB_HEADER
)Pfo
->FsContext
;
392 AllocationSize
= &FcbHeader
->AllocationSize
;
393 ValidDataLength
= &FcbHeader
->ValidDataLength
;
394 FileSize
= &FcbHeader
->FileSize
;
396 /* Try to cache without caching having been initialized. This should fail.*/
398 FSRTL_TEST("FsRtlPrepareMdlWrite() - No cache map test. Wait = FALSE",
399 !FsRtlPrepareMdlWrite(Pfo
,AllocationSize
,Length
,0,MdlChain
,&IoStatus
));
401 /* We are going to build a 100k file */
402 /* This will inititate caching and build some size */
405 Return
= FsRltTest_WritefileZw(Fh
,&Offset
,Length
, Buffer
, &IoStatus
);
406 FSRTL_TEST("FsRtlPrepareMdlWrite() - Building 100k filesize. Wait = FALSE",(NT_SUCCESS(Return
) && NT_SUCCESS(IoStatus
.Status
) && IoStatus
.Information
== Length
));
409 /* Extending the file by 1/2 sector, 256 bytes. */
410 Offset
.QuadPart
= 0x7fffffffffff;
412 Return
= FsRltTest_WritefileZw(Fh
,NULL
,Length
, Buffer
, &IoStatus
);
413 FSRTL_TEST("FsRtlPrepareMdlWrite() - Extending by 1/2 sector. Wait = FALSE",(NT_SUCCESS(Return
) && NT_SUCCESS(IoStatus
.Status
) && IoStatus
.Information
== Length
));
417 /* Append to the file past the allocation size*/
419 Offset
.QuadPart
= FileSize
->QuadPart
;
420 OldSize
.QuadPart
= FileSize
->QuadPart
;
421 Length
= (ULONG
) (AllocationSize
->QuadPart
-ValidDataLength
->QuadPart
);
422 FSRTL_TEST("FsRtlPrepareMdlWrite() - Testing extending past allocation size.",
423 !FsRtlPrepareMdlWrite(Pfo
,&Offset
,Length
+1,0,&MdlChain
,&IoStatus
));
425 FSRTL_TEST("FsRtlPrepareMdlWrite() - Testing extending not past allocation size.",
426 FsRtlPrepareMdlWrite(Pfo
,&Offset
,Length
,0,&MdlChain
,&IoStatus
));
427 FSRTL_TEST("FsRtlPrepareMdlWrite() - Check filesize",(FileSize
->QuadPart
= (OldSize
.QuadPart
+Length
)));
428 FSRTL_TEST("FsRtlPrepareMdlWrite() - Release the MDL.",FsRtlMdlWriteComplete(Pfo
,&Offset
,MdlChain
));
431 /* Try do write a 65kb IO and check that if fails. Maximum IO size for thus function is 64KB */
435 FSRTL_TEST("FsRtlPrepareMdlWrite() - 65KB IO Test.",
436 !FsRtlPrepareMdlWrite(Pfo
,&Offset
,Length
,0,&MdlChain
,&IoStatus
));
437 //FSRTL_TEST("FsRtlPrepareMdlWrite() - Release the MDL.",FsRtlMdlWriteComplete(Pfo,&Offset,MdlChain));
439 /* Try do write a 64kb IO. Maximum IO size for thus function is 64KB */
442 FSRTL_TEST("FsRtlPrepareMdlWrite() - 64KB IO Test.",
443 FsRtlPrepareMdlWrite(Pfo
,&Offset
,Length
,0,&MdlChain
,&IoStatus
))
444 FSRTL_TEST("FsRtlPrepareMdlWrite() - Release the MDL.",FsRtlMdlWriteComplete(Pfo
,&Offset
,MdlChain
));
446 /* Test the fast Io not possible flag */
447 FcbHeader
->IsFastIoPossible
= FastIoIsNotPossible
;
448 FSRTL_TEST("FsRtlPrepareMdlWrite() - FastIo is not possible flag.",
449 !FsRtlPrepareMdlWrite(Pfo
,&Offset
,Length
,0,&MdlChain
,&IoStatus
))
453 ObDereferenceObject(Pfo
);
463 /* ------------------------------------------------------------------------------------------
466 FsRtlMdlReadDev(IN PFILE_OBJECT FileObject,
467 IN PLARGE_INTEGER FileOffset,
471 OUT PIO_STATUS_BLOCK IoStatus,
472 IN PDEVICE_OBJECT DeviceObject)
474 FsRtlMdlReadCompleteDev(IN PFILE_OBJECT FileObject,
475 IN PMDL MemoryDescriptorList,
476 IN PDEVICE_OBJECT DeviceObject)
478 ------------------------------------------------------------------------------------------
481 FsRtlTest_OpenTestFile(&Fh
, &Pfo
);
483 /* Extract the test variable from the FCB struct */
484 FcbHeader
= (PFSRTL_COMMON_FCB_HEADER
)Pfo
->FsContext
;
485 AllocationSize
= &FcbHeader
->AllocationSize
;
486 ValidDataLength
= &FcbHeader
->ValidDataLength
;
487 FileSize
= &FcbHeader
->FileSize
;
490 /* We are going to build a 100k file */
491 /* This will inititate caching and build some size */
494 Return
= FsRltTest_WritefileZw(Fh
,&Offset
,Length
, Buffer
, &IoStatus
);
495 FSRTL_TEST("FsRtlMdlReadDev() - Building 100k filesize.",(NT_SUCCESS(Return
) && NT_SUCCESS(IoStatus
.Status
) && IoStatus
.Information
== Length
));
499 Offset
.LowPart
= 0x0;
500 Offset
.HighPart
= 0x0;
503 /* Testing a 64KB read */
505 Return
= FsRtlMdlReadDev(Pfo
,&Offset
,Length
,0,&MdlChain
,&IoStatus
,NULL
);
506 FSRTL_TEST("FsRtlMdlReadDev() - Testing 64k IO",(NT_SUCCESS(Return
) && NT_SUCCESS(IoStatus
.Status
) && IoStatus
.Information
== Length
));
507 FSRTL_TEST("FsRtlMdlReadDev() - Releasing the MDL",FsRtlMdlReadCompleteDev(Pfo
,MdlChain
,NULL
));
510 /* Testing read past the end of the file */
511 Offset
.QuadPart
= FileSize
->QuadPart
- (5 * _1KB
);
514 Return
= FsRtlMdlReadDev(Pfo
,&Offset
,Length
,0,&MdlChain
,&IoStatus
,NULL
);
515 FSRTL_TEST("FsRtlMdlReadDev() - Testing reading past end of file but starting before EOF",(NT_SUCCESS(Return
) && NT_SUCCESS(IoStatus
.Status
) && IoStatus
.Information
== (FileSize
->QuadPart
-Offset
.QuadPart
)));
516 FSRTL_TEST("FsRtlMdlReadDev() - Releasing the MDL",FsRtlMdlReadCompleteDev(Pfo
,MdlChain
,NULL
));
518 Offset
.QuadPart
= FileSize
->QuadPart
+ 1;
521 Return
= FsRtlMdlReadDev(Pfo
,&Offset
,Length
,0,&MdlChain
,&IoStatus
,NULL
);
522 FSRTL_TEST("FsRtlMdlReadDev() - Testing reading past end of file but starting after EOF",(NT_SUCCESS(Return
) && (IoStatus
.Status
== STATUS_END_OF_FILE
) && IoStatus
.Information
== 0));
524 /* Testing FastIoIsNotPossible */
525 Offset
.LowPart
= 0x0;
526 Offset
.HighPart
= 0x0;
529 FcbHeader
->IsFastIoPossible
= FastIoIsNotPossible
;
530 FSRTL_TEST("FsRtlMdlReadDev() - FastIo is not possible flag. Wait = TRUE",!FsRtlMdlReadDev(Pfo
,&Offset
,Length
,0,&MdlChain
,&IoStatus
,NULL
));
536 ObDereferenceObject(Pfo
);
546 /* ------------------------------------------------------------------------------------------
549 FsRtlMdlRead(IN PFILE_OBJECT FileObject,
550 IN PLARGE_INTEGER FileOffset,
554 OUT PIO_STATUS_BLOCK IoStatus)
556 FsRtlMdlReadComplete(IN PFILE_OBJECT FileObject,
557 IN PMDL MemoryDescriptorList)
559 ------------------------------------------------------------------------------------------
562 FsRtlTest_OpenTestFile(&Fh
, &Pfo
);
564 /* Extract the test variable from the FCB struct */
565 FcbHeader
= (PFSRTL_COMMON_FCB_HEADER
)Pfo
->FsContext
;
566 AllocationSize
= &FcbHeader
->AllocationSize
;
567 ValidDataLength
= &FcbHeader
->ValidDataLength
;
568 FileSize
= &FcbHeader
->FileSize
;
571 /* We are going to build a 100k file */
572 /* This will inititate caching and build some size */
575 Return
= FsRltTest_WritefileZw(Fh
,&Offset
,Length
, Buffer
, &IoStatus
);
576 FSRTL_TEST("FsRtlMdlRead() - Building 100k filesize.",(NT_SUCCESS(Return
) && NT_SUCCESS(IoStatus
.Status
) && IoStatus
.Information
== Length
));
580 Offset
.LowPart
= 0x0;
581 Offset
.HighPart
= 0x0;
584 /* Testing a 64KB read */
586 Return
= FsRtlMdlRead(Pfo
,&Offset
,Length
,0,&MdlChain
,&IoStatus
);
587 FSRTL_TEST("FsRtlMdlRead() - Testing 64k IO",(NT_SUCCESS(Return
) && NT_SUCCESS(IoStatus
.Status
) && IoStatus
.Information
== Length
));
588 FSRTL_TEST("FsRtlMdlRead() - Releasing the MDL",FsRtlMdlReadComplete(Pfo
,MdlChain
));
591 /* Testing read past the end of the file */
592 Offset
.QuadPart
= FileSize
->QuadPart
- (5 * _1KB
);
595 Return
= FsRtlMdlRead(Pfo
,&Offset
,Length
,0,&MdlChain
,&IoStatus
);
596 FSRTL_TEST("FsRtlMdlRead() - Testing reading past end of file but starting before EOF",(NT_SUCCESS(Return
) && NT_SUCCESS(IoStatus
.Status
) && IoStatus
.Information
== (FileSize
->QuadPart
-Offset
.QuadPart
)));
597 FSRTL_TEST("FsRtlMdlRead() - Releasing the MDL",FsRtlMdlReadComplete(Pfo
,MdlChain
));
599 Offset
.QuadPart
= FileSize
->QuadPart
+ 1;
602 Return
= FsRtlMdlRead(Pfo
,&Offset
,Length
,0,&MdlChain
,&IoStatus
);
603 FSRTL_TEST("FsRtlMdlRead() - Testing reading past end of file but starting after EOF",(NT_SUCCESS(Return
) && (IoStatus
.Status
== STATUS_END_OF_FILE
) && IoStatus
.Information
== 0));
605 /* Testing FastIoIsNotPossible */
606 Offset
.LowPart
= 0x0;
607 Offset
.HighPart
= 0x0;
610 FcbHeader
->IsFastIoPossible
= FastIoIsNotPossible
;
611 FSRTL_TEST("FsRtlMdlRead() - FastIo is not possible flag. Wait = TRUE",!FsRtlMdlRead(Pfo
,&Offset
,Length
,0,&MdlChain
,&IoStatus
));
617 ObDereferenceObject(Pfo
);
629 /* ------------------------------------------------------------------------------------------
632 FsRtlGetFileSize(IN PFILE_OBJECT FileObject,
633 IN OUT PLARGE_INTEGER FileSize)
635 ------------------------------------------------------------------------------------------
637 FsRtlTest_OpenTestFile(&Fh
, &Pfo
);
638 FSRTL_TEST("FsRtlGetFileSize() - Opening Test File.",((Pfo
!= NULL
) && (Fh
!= NULL
)));
640 FsRtlTest_OpenTestDirectory(&DirFh
, &DirPfo
);
641 FSRTL_TEST("FsRtlGetFileSize() - Opening Test Directory.",((DirPfo
!= NULL
) && (DirFh
!= NULL
)));
643 Status
= FsRtlGetFileSize(Pfo
,&OldSize
);
644 FSRTL_TEST("FsRtlGetFileSize() - Get the size of a real file",NT_SUCCESS(Status
));
646 Status
= FsRtlGetFileSize(DirPfo
,&OldSize
);
647 FSRTL_TEST("FsRtlGetFileSize() - Get the size of a directory file",(Status
== STATUS_FILE_IS_A_DIRECTORY
));
650 /* The test if over. Do clean up */
656 ObDereferenceObject(DirPfo
);
667 ObDereferenceObject(Pfo
);
677 if (Buffer
!= NULL
) {
686 /* This function is just a wrapper around ZwWriteFile */
687 NTSTATUS
FsRltTest_WritefileZw(HANDLE fh
, PLARGE_INTEGER Offset
, ULONG Length
, PVOID Buffer
, PIO_STATUS_BLOCK pIoStatus
){
690 Return
= ZwWriteFile(
705 /* This function fills the buffer with a test pattern */
706 void FsRtlTest_FillBuffer(LARGE_INTEGER Start
, ULONG Length
, PVOID Buffer
) {
708 PULONGLONG Index
= (PULONGLONG
) Buffer
;
710 for (i
=0; i
<Length
/sizeof(ULONGLONG
); i
++) {
711 Index
[i
] = Start
.QuadPart
+ i
;
717 /* This function opens a test file with the FILE_DELETE_ON_CLOSE flag
718 and reference the file object
720 NTSTATUS
FsRtlTest_OpenTestFile(PHANDLE Pfh
, PFILE_OBJECT
*Ppfo
) {
721 UNICODE_STRING FileName
;
722 OBJECT_ATTRIBUTES oa
;
723 IO_STATUS_BLOCK IoStatus
;
726 RtlInitUnicodeString(&FileName
,L
"\\??\\C:\\fsrtl.bin");
728 InitializeObjectAttributes(
736 Return
= IoCreateFile(Pfh
,
741 FILE_ATTRIBUTE_NORMAL
,
744 FILE_SYNCHRONOUS_IO_ALERT
| FILE_DELETE_ON_CLOSE
,
751 Return
= ObReferenceObjectByHandle(
761 NTSTATUS
FsRtlTest_OpenTestDirectory(PHANDLE Pfh
, PFILE_OBJECT
*Ppfo
) {
762 UNICODE_STRING FileName
;
763 OBJECT_ATTRIBUTES oa
;
764 IO_STATUS_BLOCK IoStatus
;
767 RtlInitUnicodeString(&FileName
,L
"\\??\\C:\\testdir01");
769 InitializeObjectAttributes(
777 Return
= IoCreateFile(Pfh
,
782 FILE_ATTRIBUTE_NORMAL
,
785 FILE_DIRECTORY_FILE
,FILE_SYNCHRONOUS_IO_ALERT
| FILE_DELETE_ON_CLOSE
,
792 Return
= ObReferenceObjectByHandle(
802 /* All the testing is done from driver entry */
803 NTSTATUS
DriverEntry( IN PDRIVER_OBJECT DriverObject
, IN PUNICODE_STRING RegistryPath
)
805 PDEVICE_OBJECT DeviceObject
;
807 UNICODE_STRING uniName
, uniDOSName
;
810 DbgPrint("Loading the FSRTL test driver.\n");
813 /* register device functions */
814 DriverObject
->MajorFunction
[IRP_MJ_CREATE
] = FsRtlTest_DispatchCreateClose
;
815 DriverObject
->MajorFunction
[IRP_MJ_CLOSE
] = FsRtlTest_DispatchCreateClose
;
816 DriverObject
->DriverUnload
= FsRtlTest_Unload
;
818 if (!FsRtlTest_StartTest()) {
819 DbgPrint("FsRtl test failed.\n");
821 DbgPrint("FsRtl test OK.\n");
824 return STATUS_SUCCESS
;
832 NTSTATUS
FsRtlTest_DispatchCreateClose( IN PDEVICE_OBJECT devObj
, IN PIRP Irp
)
834 DbgPrint(("FsRtl: Open / Close\n"));
836 Irp
->IoStatus
.Information
= 0;
837 Irp
->IoStatus
.Status
= STATUS_SUCCESS
;
838 IoCompleteRequest( Irp
, IO_NO_INCREMENT
);
840 return STATUS_SUCCESS
;
843 VOID
FsRtlTest_Unload( IN PDRIVER_OBJECT DriverObject
)
845 DbgPrint(("FsRtl: Unloading.\n"));