Home | Info | Community | Development | myReactOS | Contact Us
ReactOS Development > Doxygenfsrtl.c
Go to the documentation of this file.
00001 #include <ntifs.h> 00002 #include "ntndk.h" 00003 #include "fsrtl_glue.h" 00004 00005 #include "fastio.h" 00006 #include "fsrtl.h" 00007 00008 /* 00009 This is the main test function. It is called from DriverEntry. 00010 00011 There is a DbgBreakPoint() call at the beginning of DriverEntry. 00012 In order to run the test again, simply type 00013 net stop fsrtl 00014 net start fsrtl 00015 00016 Author: Dom Cote 00017 */ 00018 00019 BOOLEAN FsRtlTest_StartTest() { 00020 HANDLE Fh = NULL; 00021 PFILE_OBJECT Pfo = NULL; 00022 00023 HANDLE DirFh = NULL; 00024 PFILE_OBJECT DirPfo = NULL; 00025 00026 00027 IO_STATUS_BLOCK IoStatus; 00028 BOOLEAN Return; 00029 NTSTATUS Status = STATUS_SUCCESS; 00030 LONGLONG i = 0; 00031 00032 PCHAR Buffer; 00033 PMDL MdlChain = 0; 00034 00035 LARGE_INTEGER Offset; 00036 ULONG Length = 0; 00037 LARGE_INTEGER OldSize; 00038 00039 /* Parameters we are going to use in the test from the FCB */ 00040 PFSRTL_COMMON_FCB_HEADER FcbHeader; 00041 PLARGE_INTEGER AllocationSize; 00042 PLARGE_INTEGER ValidDataLength; 00043 PLARGE_INTEGER FileSize; 00044 00045 PDEVICE_OBJECT pRelatedDo = NULL; 00046 00047 /* Allocate a 100KB buffer to do IOs */ 00048 Buffer = ExAllocatePool(PagedPool,100*_1KB); 00049 00050 /* ------------------------------------------------------------------------ 00051 TESTING: 00052 BOOLEAN 00053 NTAPI 00054 FsRtlCopyWrite(IN PFILE_OBJECT FileObject, 00055 IN PLARGE_INTEGER FileOffset, 00056 IN ULONG Length, 00057 IN BOOLEAN Wait, 00058 IN ULONG LockKey, 00059 OUT PVOID Buffer, 00060 OUT PIO_STATUS_BLOCK IoStatus, 00061 IN PDEVICE_OBJECT DeviceObject) 00062 00063 with Wait = TRUE 00064 00065 ------------------------------------------------------------------------ */ 00066 FsRtlTest_OpenTestFile(&Fh, &Pfo); 00067 FSRTL_TEST("Opening Test File.",((Pfo != NULL) && (Fh != NULL))); 00068 00069 /* Extract the test variable from the FCB struct */ 00070 FcbHeader = (PFSRTL_COMMON_FCB_HEADER)Pfo->FsContext; 00071 AllocationSize = &FcbHeader->AllocationSize; 00072 ValidDataLength = &FcbHeader->ValidDataLength; 00073 FileSize = &FcbHeader->FileSize; 00074 00075 /* Try to cache without caching having been initialized. This should fail.*/ 00076 Length = 10*_1KB; 00077 FSRTL_TEST("FsRtlCopyWrite() - No cache map test.",!FsRtlCopyWrite(Pfo,AllocationSize,Length,TRUE,0,Buffer,&IoStatus,NULL)); 00078 00079 /* We are going to build a 100k file */ 00080 /* This will inititate caching and build some size */ 00081 Offset.QuadPart = 0; 00082 Length = 100*_1KB; 00083 Return = FsRltTest_WritefileZw(Fh,&Offset,Length, Buffer, &IoStatus); 00084 FSRTL_TEST("FsRtlCopyWrite() - Building 100k filesize.",(NT_SUCCESS(Return) && NT_SUCCESS(IoStatus.Status ) && IoStatus.Information == Length)); 00085 Return = TRUE; 00086 00087 /* Extending the file by 1/2 sector, 256 bytes. */ 00088 Offset.QuadPart = 0x7fffffffffff; 00089 Length = 0x100; 00090 Return = FsRltTest_WritefileZw(Fh,NULL,Length, Buffer, &IoStatus); 00091 FSRTL_TEST("FsRtlCopyWrite() - Extending by 1/2 sector.",(NT_SUCCESS(Return) && NT_SUCCESS(IoStatus.Status ) && IoStatus.Information == Length)); 00092 Return = TRUE; 00093 00094 /* Append to the file past the allocation size*/ 00095 Offset.LowPart = 0xFFFFFFFF; 00096 Offset.HighPart = 0xFFFFFFFF; 00097 OldSize.QuadPart = FileSize->QuadPart; 00098 Length = (ULONG) (AllocationSize->QuadPart -ValidDataLength->QuadPart); 00099 FSRTL_TEST("FsRtlCopyWrite() - Testing extending past allocation size",!FsRtlCopyWrite(Pfo,&Offset,Length+1,TRUE,0,Buffer,&IoStatus,NULL)); 00100 FSRTL_TEST("FsRtlCopyWrite() - Testing extending not past allocation size",FsRtlCopyWrite(Pfo,&Offset,Length,TRUE,0,Buffer,&IoStatus,NULL)); 00101 FSRTL_TEST("FsRtlCopyWrite() - Check filesize",(FileSize->QuadPart = (OldSize.QuadPart+Length))); 00102 00103 /* Try do write a 65kb IO and check that if fails. Maximum IO size for thus function is 64KB */ 00104 Offset.QuadPart = 0; 00105 Length = 65*_1KB; 00106 FSRTL_TEST("FsRtlCopyWrite() - 65KB IO Test",!FsRtlCopyWrite(Pfo,&Offset,Length,TRUE,0,Buffer,&IoStatus,NULL)); 00107 00108 /* Try do write a 64kb IO. Maximum IO size for thus function is 64KB */ 00109 Length = 64*_1KB; 00110 FSRTL_TEST("FsRtlCopyWrite() - 64KB IO Test",FsRtlCopyWrite(Pfo,&Offset,Length,TRUE,0,Buffer,&IoStatus,NULL)) 00111 00112 /* Test the fast Io questionable flag 00113 This test fails and should succeed. I am not sure why. When FsRtlCopyWrite() queries the FastIoTable of the related 00114 device object, it comes back with no. 00115 FcbHeader->IsFastIoPossible = FastIoIsQuestionable; 00116 FSRTL_TEST("FastIo is questionable flag",FsRtlCopyWrite(Pfo,&Offset,Length,TRUE,0,Buffer,&IoStatus,NULL)) 00117 */ 00118 00119 /* Test the fast Io not possible flag */ 00120 FcbHeader->IsFastIoPossible = FastIoIsNotPossible; 00121 FSRTL_TEST("FsRtlCopyWrite() - FastIo is not possible flag",!FsRtlCopyWrite(Pfo,&Offset,Length,TRUE,0,Buffer,&IoStatus,NULL)) 00122 /* Set the flag back to what it was */ 00123 FcbHeader->IsFastIoPossible = FastIoIsPossible; 00124 FSRTL_TEST("FsRtlCopyWrite() - FastIo is possbile flag",FsRtlCopyWrite(Pfo,&Offset,Length,TRUE,0,Buffer,&IoStatus,NULL)) 00125 00126 if (Pfo) 00127 { 00128 ObDereferenceObject(Pfo); 00129 Pfo = NULL; 00130 } 00131 00132 if (Fh) 00133 { 00134 ZwClose(Fh); 00135 Fh = NULL; 00136 } 00137 00138 /* ------------------------------------------------------------------------ 00139 TESTING: 00140 BOOLEAN 00141 NTAPI 00142 FsRtlCopyWrite(IN PFILE_OBJECT FileObject, 00143 IN PLARGE_INTEGER FileOffset, 00144 IN ULONG Length, 00145 IN BOOLEAN Wait, 00146 IN ULONG LockKey, 00147 OUT PVOID Buffer, 00148 OUT PIO_STATUS_BLOCK IoStatus, 00149 IN PDEVICE_OBJECT DeviceObject) 00150 00151 with Wait = FALSE 00152 00153 ------------------------------------------------------------------------ */ 00154 00155 /* We are going to repeat the same bunch of tests but with Wait = FALSE. So we exercise the second part of the function. */ 00156 FsRtlTest_OpenTestFile(&Fh, &Pfo); 00157 00158 /* Extract the test variable from the FCB struct */ 00159 FcbHeader = (PFSRTL_COMMON_FCB_HEADER)Pfo->FsContext; 00160 AllocationSize = &FcbHeader->AllocationSize; 00161 ValidDataLength = &FcbHeader->ValidDataLength; 00162 FileSize = &FcbHeader->FileSize; 00163 00164 /* Try to cache without caching having been initialized. This should fail.*/ 00165 Length = 10*_1KB; 00166 FSRTL_TEST("FsRtlCopyWrite() - No cache map test. Wait = FALSE",!FsRtlCopyWrite(Pfo,AllocationSize,Length,FALSE,0,Buffer,&IoStatus,NULL)); 00167 00168 /* We are going to build a 100k file */ 00169 /* This will inititate caching and build some size */ 00170 Offset.QuadPart = 0; 00171 Length = 100*_1KB; 00172 Return = FsRltTest_WritefileZw(Fh,&Offset,Length, Buffer, &IoStatus); 00173 FSRTL_TEST("FsRtlCopyWrite() - Building 100k filesize. Wait = FALSE",(NT_SUCCESS(Return) && NT_SUCCESS(IoStatus.Status ) && IoStatus.Information == Length)); 00174 Return = TRUE; 00175 00176 /* Extending the file by 1/2 sector, 256 bytes. */ 00177 Offset.QuadPart = 0x7fffffffffff; 00178 Length = 0x100; 00179 Return = FsRltTest_WritefileZw(Fh,NULL,Length, Buffer, &IoStatus); 00180 FSRTL_TEST("FsRtlCopyWrite() - Extending by 1/2 sector. Wait = FALSE",(NT_SUCCESS(Return) && NT_SUCCESS(IoStatus.Status ) && IoStatus.Information == Length)); 00181 Return = TRUE; 00182 00183 /* Append to the file past the allocation size*/ 00184 Offset.LowPart = 0xFFFFFFFF; 00185 Offset.HighPart = 0xFFFFFFFF; 00186 OldSize.QuadPart = FileSize->QuadPart; 00187 Length = (ULONG) (AllocationSize->QuadPart -ValidDataLength->QuadPart); 00188 FSRTL_TEST("FsRtlCopyWrite() - Testing extending past allocation size Wait = FALSE",!FsRtlCopyWrite(Pfo,&Offset,Length+1,FALSE,0,Buffer,&IoStatus,NULL)); 00189 FSRTL_TEST("FsRtlCopyWrite() - Testing extending not past allocation size. Wait = FALSE",FsRtlCopyWrite(Pfo,&Offset,Length,FALSE,0,Buffer,&IoStatus,NULL)); 00190 FSRTL_TEST("FsRtlCopyWrite() - Check filesize",(FileSize->QuadPart = (OldSize.QuadPart+Length))); 00191 00192 /* Try do write a 65kb IO and check that if fails. Maximum IO size for thus function is 64KB */ 00193 Offset.QuadPart = 0; 00194 Length = 65*_1KB; 00195 FSRTL_TEST("FsRtlCopyWrite() - 65KB IO Test. Wait = FALSE",!FsRtlCopyWrite(Pfo,&Offset,Length,FALSE,0,Buffer,&IoStatus,NULL)); 00196 00197 /* Try do write a 64kb IO. Maximum IO size for thus function is 64KB */ 00198 Length = 64*_1KB; 00199 FSRTL_TEST("FsRtlCopyWrite() - 64KB IO Test. Wait = FALSE",FsRtlCopyWrite(Pfo,&Offset,Length,FALSE,0,Buffer,&IoStatus,NULL)) 00200 00201 /* Test the fast Io questionable flag 00202 This test fails and should succeed. I am not sure why. When FsRtlCopyWrite() queries the FastIoTable of the related 00203 device object, it comes back with no. 00204 FcbHeader->IsFastIoPossible = FastIoIsQuestionable; 00205 FSRTL_TEST("FastIo is questionable flag",FsRtlCopyWrite(Pfo,&Offset,Length,TRUE,0,Buffer,&IoStatus,NULL)) 00206 */ 00207 00208 /* Test the fast Io not possible flag */ 00209 FcbHeader->IsFastIoPossible = FastIoIsNotPossible; 00210 FSRTL_TEST("FsRtlCopyWrite() - FastIo is not possible flag. Wait = FALSE",!FsRtlCopyWrite(Pfo,&Offset,Length,FALSE,0,Buffer,&IoStatus,NULL)) 00211 /* Set the flag back to what it was */ 00212 FcbHeader->IsFastIoPossible = FastIoIsPossible; 00213 FSRTL_TEST("FsRtlCopyWrite() - FastIo is possbile flag. Wait = FALSE",FsRtlCopyWrite(Pfo,&Offset,Length,FALSE,0,Buffer,&IoStatus,NULL)) 00214 00215 00216 /* ------------------------------------------------------------------------------------------ 00217 TESTING: 00218 00219 BOOLEAN 00220 NTAPI 00221 FsRtlCopyRead(IN PFILE_OBJECT FileObject, 00222 IN PLARGE_INTEGER FileOffset, 00223 IN ULONG Length, 00224 IN BOOLEAN Wait, 00225 IN ULONG LockKey, 00226 OUT PVOID Buffer, 00227 OUT PIO_STATUS_BLOCK IoStatus, 00228 IN PDEVICE_OBJECT DeviceObject) 00229 00230 ------------------------------------------------------------------------------------------ */ 00231 00232 Offset.LowPart = 0x0; 00233 Offset.HighPart = 0x0; 00234 Length = 0x10000; 00235 00236 /* Testing a 64KB read with Wait = TRUE */ 00237 Return = FsRtlCopyRead(Pfo,&Offset,Length,TRUE,0,Buffer,&IoStatus,NULL); 00238 FSRTL_TEST("FsRtlCopyRead() - Testing 64k IO Wait=TRUE",(NT_SUCCESS(Return) && NT_SUCCESS(IoStatus.Status ) && IoStatus.Information == Length)); 00239 Return = TRUE; 00240 00241 /* Testing a 64KB read with Wait = FALSE */ 00242 Return = FsRtlCopyRead(Pfo,&Offset,Length,FALSE,0,Buffer,&IoStatus,NULL); 00243 FSRTL_TEST("FsRtlCopyRead() - Testing 64k IO Wait=FALSE",(NT_SUCCESS(Return) && NT_SUCCESS(IoStatus.Status ) && IoStatus.Information == Length)); 00244 Return = TRUE; 00245 00246 /* Testing read past the end of the file */ 00247 Offset.QuadPart = FileSize->QuadPart - (5 * _1KB); 00248 Length = 10 * _1KB; 00249 Return = FsRtlCopyRead(Pfo,&Offset,Length,TRUE,0,Buffer,&IoStatus,NULL); 00250 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))); 00251 00252 Offset.QuadPart = FileSize->QuadPart + 1; 00253 Length = 10 * _1KB; 00254 Return = FsRtlCopyRead(Pfo,&Offset,Length,TRUE,0,Buffer,&IoStatus,NULL); 00255 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)); 00256 00257 00258 /* Testing a 64KB read with Wait = TRUE */ 00259 Offset.LowPart = 0x0; 00260 Offset.HighPart = 0x0; 00261 Length = 0x10000; 00262 FcbHeader->IsFastIoPossible = FastIoIsNotPossible; 00263 FSRTL_TEST("FsRtlCopyRead() - FastIo is not possible flag. Wait = FALSE",!FsRtlCopyRead(Pfo,&Offset,Length,FALSE,0,Buffer,&IoStatus,NULL)); 00264 FSRTL_TEST("FsRtlCopyRead() - FastIo is not possible flag. Wait = TRUE",!FsRtlCopyRead(Pfo,&Offset,Length,TRUE,0,Buffer,&IoStatus,NULL)); 00265 FcbHeader->IsFastIoPossible = FastIoIsPossible; 00266 Return = TRUE; 00267 00268 if (Pfo) 00269 { 00270 ObDereferenceObject(Pfo); 00271 Pfo = NULL; 00272 } 00273 00274 if (Fh) 00275 { 00276 ZwClose(Fh); 00277 Fh = NULL; 00278 } 00279 00280 /* ------------------------------------------------------------------------ 00281 TESTING: 00282 BOOLEAN 00283 NTAPI 00284 FsRtlPrepareMdlWriteDev(IN PFILE_OBJECT FileObject, 00285 IN PLARGE_INTEGER FileOffset, 00286 IN ULONG Length, 00287 IN ULONG LockKey, 00288 OUT PMDL *MdlChain, 00289 OUT PIO_STATUS_BLOCK IoStatus, 00290 IN PDEVICE_OBJECT DeviceObject) 00291 00292 ------------------------------------------------------------------------ */ 00293 00294 /* We are going to repeat the same bunch of tests but with Wait = FALSE. So we exercise the second part of the function. */ 00295 FsRtlTest_OpenTestFile(&Fh, &Pfo); 00296 00297 /* Extract the test variable from the FCB struct */ 00298 FcbHeader = (PFSRTL_COMMON_FCB_HEADER)Pfo->FsContext; 00299 AllocationSize = &FcbHeader->AllocationSize; 00300 ValidDataLength = &FcbHeader->ValidDataLength; 00301 FileSize = &FcbHeader->FileSize; 00302 00303 /* Try to cache without caching having been initialized. This should fail.*/ 00304 Length = 10*_1KB; 00305 FSRTL_TEST("FsRtlPrepareMdlWriteDev() - No cache map test. Wait = FALSE", 00306 !FsRtlPrepareMdlWriteDev(Pfo,AllocationSize,Length,0,MdlChain,&IoStatus,NULL)); 00307 00308 /* We are going to build a 100k file */ 00309 /* This will inititate caching and build some size */ 00310 Offset.QuadPart = 0; 00311 Length = 100*_1KB; 00312 Return = FsRltTest_WritefileZw(Fh,&Offset,Length, Buffer, &IoStatus); 00313 FSRTL_TEST("FsRtlPrepareMdlWriteDev() - Building 100k filesize. Wait = FALSE",(NT_SUCCESS(Return) && NT_SUCCESS(IoStatus.Status ) && IoStatus.Information == Length)); 00314 Return = TRUE; 00315 00316 /* Extending the file by 1/2 sector, 256 bytes. */ 00317 Offset.QuadPart = 0x7fffffffffff; 00318 Length = 0x100; 00319 Return = FsRltTest_WritefileZw(Fh,NULL,Length, Buffer, &IoStatus); 00320 FSRTL_TEST("FsRtlPrepareMdlWriteDev() - Extending by 1/2 sector. Wait = FALSE",(NT_SUCCESS(Return) && NT_SUCCESS(IoStatus.Status ) && IoStatus.Information == Length)); 00321 Return = TRUE; 00322 00323 00324 pRelatedDo = IoGetRelatedDeviceObject(Pfo); 00325 FSRTL_TEST("FsRtlPrepareMdlWriteDev() - Did we get related DO ?",pRelatedDo); 00326 00327 00328 /* Append to the file past the allocation size*/ 00329 Offset.QuadPart = FileSize->QuadPart; 00330 OldSize.QuadPart = FileSize->QuadPart; 00331 Length = (ULONG) (AllocationSize->QuadPart -ValidDataLength->QuadPart); 00332 FSRTL_TEST("FsRtlPrepareMdlWriteDev() - Testing extending past allocation size.", 00333 !FsRtlPrepareMdlWriteDev(Pfo,&Offset,Length+1,0,&MdlChain,&IoStatus,pRelatedDo)); 00334 00335 FSRTL_TEST("FsRtlPrepareMdlWriteDev() - Testing extending not past allocation size.", 00336 FsRtlPrepareMdlWriteDev(Pfo,&Offset,Length,0,&MdlChain,&IoStatus,pRelatedDo)); 00337 FSRTL_TEST("FsRtlPrepareMdlWriteDev() - Check filesize",(FileSize->QuadPart = (OldSize.QuadPart+Length))); 00338 FSRTL_TEST("FsRtlPrepareMdlWriteDev() - Release the MDL.",FsRtlMdlWriteCompleteDev(Pfo,&Offset,MdlChain,pRelatedDo)); 00339 00340 00341 /* Try do write a 65kb IO and check that if fails. Maximum IO size for thus function is 64KB */ 00342 Offset.QuadPart = 0; 00343 MdlChain = NULL; 00344 Length = 65*_1KB; 00345 FSRTL_TEST("FsRtlPrepareMdlWriteDev() - 65KB IO Test.", 00346 FsRtlPrepareMdlWriteDev(Pfo,&Offset,Length,0,&MdlChain,&IoStatus,pRelatedDo)); 00347 FSRTL_TEST("FsRtlPrepareMdlWriteDev() - Release the MDL.",FsRtlMdlWriteCompleteDev(Pfo,&Offset,MdlChain,pRelatedDo)); 00348 00349 /* Try do write a 64kb IO. Maximum IO size for thus function is 64KB */ 00350 Length = 64*_1KB; 00351 MdlChain = NULL; 00352 FSRTL_TEST("FsRtlPrepareMdlWriteDev() - 64KB IO Test.", 00353 FsRtlPrepareMdlWriteDev(Pfo,&Offset,Length,0,&MdlChain,&IoStatus,NULL)) 00354 FSRTL_TEST("FsRtlPrepareMdlWriteDev() - Release the MDL.",FsRtlMdlWriteCompleteDev(Pfo,&Offset,MdlChain,NULL)); 00355 00356 /* Test the fast Io not possible flag */ 00357 FcbHeader->IsFastIoPossible = FastIoIsNotPossible; 00358 FSRTL_TEST("FsRtlPrepareMdlWriteDev() - FastIo is not possible flag.", 00359 !FsRtlPrepareMdlWriteDev(Pfo,&Offset,Length,0,&MdlChain,&IoStatus,NULL)) 00360 00361 if (Pfo) 00362 { 00363 ObDereferenceObject(Pfo); 00364 Pfo = NULL; 00365 } 00366 00367 if (Fh) 00368 { 00369 ZwClose(Fh); 00370 Fh = NULL; 00371 } 00372 00373 /* ------------------------------------------------------------------------ 00374 TESTING: 00375 BOOLEAN 00376 NTAPI 00377 FsRtlPrepareMdlWrite( IN PFILE_OBJECT FileObject, 00378 IN PLARGE_INTEGER FileOffset, 00379 IN ULONG Length, 00380 IN ULONG LockKey, 00381 OUT PMDL *MdlChain, 00382 OUT PIO_STATUS_BLOCK IoStatus, 00383 IN PDEVICE_OBJECT DeviceObject) 00384 00385 ------------------------------------------------------------------------ */ 00386 00387 /* We are going to repeat the same bunch of tests but with Wait = FALSE. So we exercise the second part of the function. */ 00388 FsRtlTest_OpenTestFile(&Fh, &Pfo); 00389 00390 /* Extract the test variable from the FCB struct */ 00391 FcbHeader = (PFSRTL_COMMON_FCB_HEADER)Pfo->FsContext; 00392 AllocationSize = &FcbHeader->AllocationSize; 00393 ValidDataLength = &FcbHeader->ValidDataLength; 00394 FileSize = &FcbHeader->FileSize; 00395 00396 /* Try to cache without caching having been initialized. This should fail.*/ 00397 Length = 10*_1KB; 00398 FSRTL_TEST("FsRtlPrepareMdlWrite() - No cache map test. Wait = FALSE", 00399 !FsRtlPrepareMdlWrite(Pfo,AllocationSize,Length,0,MdlChain,&IoStatus)); 00400 00401 /* We are going to build a 100k file */ 00402 /* This will inititate caching and build some size */ 00403 Offset.QuadPart = 0; 00404 Length = 100*_1KB; 00405 Return = FsRltTest_WritefileZw(Fh,&Offset,Length, Buffer, &IoStatus); 00406 FSRTL_TEST("FsRtlPrepareMdlWrite() - Building 100k filesize. Wait = FALSE",(NT_SUCCESS(Return) && NT_SUCCESS(IoStatus.Status ) && IoStatus.Information == Length)); 00407 Return = TRUE; 00408 00409 /* Extending the file by 1/2 sector, 256 bytes. */ 00410 Offset.QuadPart = 0x7fffffffffff; 00411 Length = 0x100; 00412 Return = FsRltTest_WritefileZw(Fh,NULL,Length, Buffer, &IoStatus); 00413 FSRTL_TEST("FsRtlPrepareMdlWrite() - Extending by 1/2 sector. Wait = FALSE",(NT_SUCCESS(Return) && NT_SUCCESS(IoStatus.Status ) && IoStatus.Information == Length)); 00414 Return = TRUE; 00415 00416 00417 /* Append to the file past the allocation size*/ 00418 MdlChain = NULL; 00419 Offset.QuadPart = FileSize->QuadPart; 00420 OldSize.QuadPart = FileSize->QuadPart; 00421 Length = (ULONG) (AllocationSize->QuadPart -ValidDataLength->QuadPart); 00422 FSRTL_TEST("FsRtlPrepareMdlWrite() - Testing extending past allocation size.", 00423 !FsRtlPrepareMdlWrite(Pfo,&Offset,Length+1,0,&MdlChain,&IoStatus)); 00424 00425 FSRTL_TEST("FsRtlPrepareMdlWrite() - Testing extending not past allocation size.", 00426 FsRtlPrepareMdlWrite(Pfo,&Offset,Length,0,&MdlChain,&IoStatus)); 00427 FSRTL_TEST("FsRtlPrepareMdlWrite() - Check filesize",(FileSize->QuadPart = (OldSize.QuadPart+Length))); 00428 FSRTL_TEST("FsRtlPrepareMdlWrite() - Release the MDL.",FsRtlMdlWriteComplete(Pfo,&Offset,MdlChain)); 00429 00430 00431 /* Try do write a 65kb IO and check that if fails. Maximum IO size for thus function is 64KB */ 00432 Offset.QuadPart = 0; 00433 MdlChain = NULL; 00434 Length = 65*_1KB; 00435 FSRTL_TEST("FsRtlPrepareMdlWrite() - 65KB IO Test.", 00436 !FsRtlPrepareMdlWrite(Pfo,&Offset,Length,0,&MdlChain,&IoStatus)); 00437 //FSRTL_TEST("FsRtlPrepareMdlWrite() - Release the MDL.",FsRtlMdlWriteComplete(Pfo,&Offset,MdlChain)); 00438 00439 /* Try do write a 64kb IO. Maximum IO size for thus function is 64KB */ 00440 Length = 64*_1KB; 00441 MdlChain = NULL; 00442 FSRTL_TEST("FsRtlPrepareMdlWrite() - 64KB IO Test.", 00443 FsRtlPrepareMdlWrite(Pfo,&Offset,Length,0,&MdlChain,&IoStatus)) 00444 FSRTL_TEST("FsRtlPrepareMdlWrite() - Release the MDL.",FsRtlMdlWriteComplete(Pfo,&Offset,MdlChain)); 00445 00446 /* Test the fast Io not possible flag */ 00447 FcbHeader->IsFastIoPossible = FastIoIsNotPossible; 00448 FSRTL_TEST("FsRtlPrepareMdlWrite() - FastIo is not possible flag.", 00449 !FsRtlPrepareMdlWrite(Pfo,&Offset,Length,0,&MdlChain,&IoStatus)) 00450 00451 if (Pfo) 00452 { 00453 ObDereferenceObject(Pfo); 00454 Pfo = NULL; 00455 } 00456 00457 if (Fh) 00458 { 00459 ZwClose(Fh); 00460 Fh = NULL; 00461 } 00462 00463 /* ------------------------------------------------------------------------------------------ 00464 TESTING: 00465 00466 FsRtlMdlReadDev(IN PFILE_OBJECT FileObject, 00467 IN PLARGE_INTEGER FileOffset, 00468 IN ULONG Length, 00469 IN ULONG LockKey, 00470 OUT PMDL *MdlChain, 00471 OUT PIO_STATUS_BLOCK IoStatus, 00472 IN PDEVICE_OBJECT DeviceObject) 00473 00474 FsRtlMdlReadCompleteDev(IN PFILE_OBJECT FileObject, 00475 IN PMDL MemoryDescriptorList, 00476 IN PDEVICE_OBJECT DeviceObject) 00477 00478 ------------------------------------------------------------------------------------------ 00479 */ 00480 00481 FsRtlTest_OpenTestFile(&Fh, &Pfo); 00482 00483 /* Extract the test variable from the FCB struct */ 00484 FcbHeader = (PFSRTL_COMMON_FCB_HEADER)Pfo->FsContext; 00485 AllocationSize = &FcbHeader->AllocationSize; 00486 ValidDataLength = &FcbHeader->ValidDataLength; 00487 FileSize = &FcbHeader->FileSize; 00488 00489 00490 /* We are going to build a 100k file */ 00491 /* This will inititate caching and build some size */ 00492 Offset.QuadPart = 0; 00493 Length = 100*_1KB; 00494 Return = FsRltTest_WritefileZw(Fh,&Offset,Length, Buffer, &IoStatus); 00495 FSRTL_TEST("FsRtlMdlReadDev() - Building 100k filesize.",(NT_SUCCESS(Return) && NT_SUCCESS(IoStatus.Status ) && IoStatus.Information == Length)); 00496 Return = TRUE; 00497 00498 00499 Offset.LowPart = 0x0; 00500 Offset.HighPart = 0x0; 00501 Length = 0x10000; 00502 00503 /* Testing a 64KB read */ 00504 MdlChain = NULL; 00505 Return = FsRtlMdlReadDev(Pfo,&Offset,Length,0,&MdlChain,&IoStatus,NULL); 00506 FSRTL_TEST("FsRtlMdlReadDev() - Testing 64k IO",(NT_SUCCESS(Return) && NT_SUCCESS(IoStatus.Status ) && IoStatus.Information == Length)); 00507 FSRTL_TEST("FsRtlMdlReadDev() - Releasing the MDL",FsRtlMdlReadCompleteDev(Pfo,MdlChain,NULL)); 00508 00509 00510 /* Testing read past the end of the file */ 00511 Offset.QuadPart = FileSize->QuadPart - (5 * _1KB); 00512 Length = 10 * _1KB; 00513 MdlChain = NULL; 00514 Return = FsRtlMdlReadDev(Pfo,&Offset,Length,0,&MdlChain,&IoStatus,NULL); 00515 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))); 00516 FSRTL_TEST("FsRtlMdlReadDev() - Releasing the MDL",FsRtlMdlReadCompleteDev(Pfo,MdlChain,NULL)); 00517 00518 Offset.QuadPart = FileSize->QuadPart + 1; 00519 Length = 10 * _1KB; 00520 MdlChain = NULL; 00521 Return = FsRtlMdlReadDev(Pfo,&Offset,Length,0,&MdlChain,&IoStatus,NULL); 00522 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)); 00523 00524 /* Testing FastIoIsNotPossible */ 00525 Offset.LowPart = 0x0; 00526 Offset.HighPart = 0x0; 00527 MdlChain = NULL; 00528 Length = 0x10000; 00529 FcbHeader->IsFastIoPossible = FastIoIsNotPossible; 00530 FSRTL_TEST("FsRtlMdlReadDev() - FastIo is not possible flag. Wait = TRUE",!FsRtlMdlReadDev(Pfo,&Offset,Length,0,&MdlChain,&IoStatus,NULL)); 00531 00532 Return = TRUE; 00533 00534 if (Pfo) 00535 { 00536 ObDereferenceObject(Pfo); 00537 Pfo = NULL; 00538 } 00539 00540 if (Fh) 00541 { 00542 ZwClose(Fh); 00543 Fh = NULL; 00544 } 00545 00546 /* ------------------------------------------------------------------------------------------ 00547 TESTING: 00548 00549 FsRtlMdlRead(IN PFILE_OBJECT FileObject, 00550 IN PLARGE_INTEGER FileOffset, 00551 IN ULONG Length, 00552 IN ULONG LockKey, 00553 OUT PMDL *MdlChain, 00554 OUT PIO_STATUS_BLOCK IoStatus) 00555 00556 FsRtlMdlReadComplete(IN PFILE_OBJECT FileObject, 00557 IN PMDL MemoryDescriptorList) 00558 00559 ------------------------------------------------------------------------------------------ 00560 */ 00561 00562 FsRtlTest_OpenTestFile(&Fh, &Pfo); 00563 00564 /* Extract the test variable from the FCB struct */ 00565 FcbHeader = (PFSRTL_COMMON_FCB_HEADER)Pfo->FsContext; 00566 AllocationSize = &FcbHeader->AllocationSize; 00567 ValidDataLength = &FcbHeader->ValidDataLength; 00568 FileSize = &FcbHeader->FileSize; 00569 00570 00571 /* We are going to build a 100k file */ 00572 /* This will inititate caching and build some size */ 00573 Offset.QuadPart = 0; 00574 Length = 100*_1KB; 00575 Return = FsRltTest_WritefileZw(Fh,&Offset,Length, Buffer, &IoStatus); 00576 FSRTL_TEST("FsRtlMdlRead() - Building 100k filesize.",(NT_SUCCESS(Return) && NT_SUCCESS(IoStatus.Status ) && IoStatus.Information == Length)); 00577 Return = TRUE; 00578 00579 00580 Offset.LowPart = 0x0; 00581 Offset.HighPart = 0x0; 00582 Length = 0x10000; 00583 00584 /* Testing a 64KB read */ 00585 MdlChain = NULL; 00586 Return = FsRtlMdlRead(Pfo,&Offset,Length,0,&MdlChain,&IoStatus); 00587 FSRTL_TEST("FsRtlMdlRead() - Testing 64k IO",(NT_SUCCESS(Return) && NT_SUCCESS(IoStatus.Status ) && IoStatus.Information == Length)); 00588 FSRTL_TEST("FsRtlMdlRead() - Releasing the MDL",FsRtlMdlReadComplete(Pfo,MdlChain)); 00589 00590 00591 /* Testing read past the end of the file */ 00592 Offset.QuadPart = FileSize->QuadPart - (5 * _1KB); 00593 Length = 10 * _1KB; 00594 MdlChain = NULL; 00595 Return = FsRtlMdlRead(Pfo,&Offset,Length,0,&MdlChain,&IoStatus); 00596 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))); 00597 FSRTL_TEST("FsRtlMdlRead() - Releasing the MDL",FsRtlMdlReadComplete(Pfo,MdlChain)); 00598 00599 Offset.QuadPart = FileSize->QuadPart + 1; 00600 Length = 10 * _1KB; 00601 MdlChain = NULL; 00602 Return = FsRtlMdlRead(Pfo,&Offset,Length,0,&MdlChain,&IoStatus); 00603 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)); 00604 00605 /* Testing FastIoIsNotPossible */ 00606 Offset.LowPart = 0x0; 00607 Offset.HighPart = 0x0; 00608 MdlChain = NULL; 00609 Length = 0x10000; 00610 FcbHeader->IsFastIoPossible = FastIoIsNotPossible; 00611 FSRTL_TEST("FsRtlMdlRead() - FastIo is not possible flag. Wait = TRUE",!FsRtlMdlRead(Pfo,&Offset,Length,0,&MdlChain,&IoStatus)); 00612 00613 Return = TRUE; 00614 00615 if (Pfo) 00616 { 00617 ObDereferenceObject(Pfo); 00618 Pfo = NULL; 00619 } 00620 00621 if (Fh) 00622 { 00623 ZwClose(Fh); 00624 Fh = NULL; 00625 } 00626 00627 00628 00629 /* ------------------------------------------------------------------------------------------ 00630 TESTING: 00631 00632 FsRtlGetFileSize(IN PFILE_OBJECT FileObject, 00633 IN OUT PLARGE_INTEGER FileSize) 00634 00635 ------------------------------------------------------------------------------------------ 00636 */ 00637 FsRtlTest_OpenTestFile(&Fh, &Pfo); 00638 FSRTL_TEST("FsRtlGetFileSize() - Opening Test File.",((Pfo != NULL) && (Fh != NULL))); 00639 00640 FsRtlTest_OpenTestDirectory(&DirFh, &DirPfo); 00641 FSRTL_TEST("FsRtlGetFileSize() - Opening Test Directory.",((DirPfo != NULL) && (DirFh != NULL))); 00642 00643 Status = FsRtlGetFileSize(Pfo,&OldSize); 00644 FSRTL_TEST("FsRtlGetFileSize() - Get the size of a real file",NT_SUCCESS(Status)); 00645 00646 Status = FsRtlGetFileSize(DirPfo,&OldSize); 00647 FSRTL_TEST("FsRtlGetFileSize() - Get the size of a directory file",(Status == STATUS_FILE_IS_A_DIRECTORY)); 00648 00649 00650 /* The test if over. Do clean up */ 00651 00652 Cleanup: 00653 00654 if (DirPfo) 00655 { 00656 ObDereferenceObject(DirPfo); 00657 DirPfo = NULL; 00658 } 00659 00660 if (DirFh) 00661 { 00662 ZwClose(DirFh); 00663 DirFh = NULL; 00664 } 00665 if (Pfo) 00666 { 00667 ObDereferenceObject(Pfo); 00668 Pfo = NULL; 00669 } 00670 00671 if (Fh) 00672 { 00673 ZwClose(Fh); 00674 Fh = NULL; 00675 } 00676 00677 if (Buffer != NULL) { 00678 ExFreePool(Buffer); 00679 Buffer = NULL; 00680 } 00681 00682 return Return; 00683 00684 } 00685 00686 /* This function is just a wrapper around ZwWriteFile */ 00687 NTSTATUS FsRltTest_WritefileZw(HANDLE fh, PLARGE_INTEGER Offset, ULONG Length, PVOID Buffer, PIO_STATUS_BLOCK pIoStatus){ 00688 NTSTATUS Return; 00689 00690 Return = ZwWriteFile( 00691 fh, 00692 NULL, 00693 NULL, 00694 NULL, 00695 pIoStatus, 00696 Buffer, 00697 Length, 00698 Offset, 00699 NULL 00700 ); 00701 00702 return Return; 00703 } 00704 00705 /* This function fills the buffer with a test pattern */ 00706 void FsRtlTest_FillBuffer(LARGE_INTEGER Start, ULONG Length, PVOID Buffer) { 00707 ULONG i = 0; 00708 PULONGLONG Index = (PULONGLONG) Buffer; 00709 00710 for (i=0; i<Length/sizeof(ULONGLONG); i++) { 00711 Index[i] = Start.QuadPart + i; 00712 } 00713 00714 return; 00715 } 00716 00717 /* This function opens a test file with the FILE_DELETE_ON_CLOSE flag 00718 and reference the file object 00719 */ 00720 NTSTATUS FsRtlTest_OpenTestFile(PHANDLE Pfh, PFILE_OBJECT *Ppfo) { 00721 UNICODE_STRING FileName; 00722 OBJECT_ATTRIBUTES oa; 00723 IO_STATUS_BLOCK IoStatus; 00724 NTSTATUS Return; 00725 00726 RtlInitUnicodeString(&FileName,L"\\??\\C:\\fsrtl.bin"); 00727 00728 InitializeObjectAttributes( 00729 &oa, 00730 &FileName, 00731 OBJ_KERNEL_HANDLE, 00732 NULL, 00733 NULL; 00734 ); 00735 00736 Return = IoCreateFile(Pfh, 00737 GENERIC_WRITE, 00738 &oa, 00739 &IoStatus, 00740 0, 00741 FILE_ATTRIBUTE_NORMAL, 00742 0, 00743 FILE_OVERWRITE_IF , 00744 FILE_SYNCHRONOUS_IO_ALERT | FILE_DELETE_ON_CLOSE, 00745 NULL, 00746 0, 00747 CreateFileTypeNone, 00748 NULL, 00749 0); 00750 00751 Return = ObReferenceObjectByHandle( 00752 *Pfh, 00753 GENERIC_WRITE, 00754 NULL, 00755 KernelMode, 00756 Ppfo, 00757 NULL 00758 ); 00759 } 00760 00761 NTSTATUS FsRtlTest_OpenTestDirectory(PHANDLE Pfh, PFILE_OBJECT *Ppfo) { 00762 UNICODE_STRING FileName; 00763 OBJECT_ATTRIBUTES oa; 00764 IO_STATUS_BLOCK IoStatus; 00765 NTSTATUS Return; 00766 00767 RtlInitUnicodeString(&FileName,L"\\??\\C:\\testdir01"); 00768 00769 InitializeObjectAttributes( 00770 &oa, 00771 &FileName, 00772 OBJ_KERNEL_HANDLE, 00773 NULL, 00774 NULL; 00775 ); 00776 00777 Return = IoCreateFile(Pfh, 00778 GENERIC_WRITE, 00779 &oa, 00780 &IoStatus, 00781 0, 00782 FILE_ATTRIBUTE_NORMAL, 00783 0, 00784 FILE_OPEN_IF, 00785 FILE_DIRECTORY_FILE,FILE_SYNCHRONOUS_IO_ALERT | FILE_DELETE_ON_CLOSE, 00786 NULL, 00787 0, 00788 CreateFileTypeNone, 00789 NULL, 00790 0); 00791 00792 Return = ObReferenceObjectByHandle( 00793 *Pfh, 00794 GENERIC_WRITE, 00795 NULL, 00796 KernelMode, 00797 Ppfo, 00798 NULL 00799 ); 00800 } 00801 00802 /* All the testing is done from driver entry */ 00803 NTSTATUS DriverEntry( IN PDRIVER_OBJECT DriverObject, IN PUNICODE_STRING RegistryPath ) 00804 { 00805 PDEVICE_OBJECT DeviceObject; 00806 NTSTATUS mStatus; 00807 UNICODE_STRING uniName, uniDOSName; 00808 PDEVOBJ_EXTENSION x; 00809 00810 DbgPrint("Loading the FSRTL test driver.\n"); 00811 DbgBreakPoint(); 00812 00813 /* register device functions */ 00814 DriverObject->MajorFunction[IRP_MJ_CREATE] = FsRtlTest_DispatchCreateClose; 00815 DriverObject->MajorFunction[IRP_MJ_CLOSE] = FsRtlTest_DispatchCreateClose; 00816 DriverObject->DriverUnload = FsRtlTest_Unload; 00817 00818 if (!FsRtlTest_StartTest()) { 00819 DbgPrint("FsRtl test failed.\n"); 00820 } else { 00821 DbgPrint("FsRtl test OK.\n"); 00822 } 00823 00824 return STATUS_SUCCESS; 00825 } 00826 00827 00828 00829 00830 00831 00832 NTSTATUS FsRtlTest_DispatchCreateClose( IN PDEVICE_OBJECT devObj, IN PIRP Irp ) 00833 { 00834 DbgPrint(("FsRtl: Open / Close\n")); 00835 00836 Irp->IoStatus.Information = 0; 00837 Irp->IoStatus.Status = STATUS_SUCCESS; 00838 IoCompleteRequest( Irp, IO_NO_INCREMENT ); 00839 00840 return STATUS_SUCCESS; 00841 } 00842 00843 VOID FsRtlTest_Unload( IN PDRIVER_OBJECT DriverObject ) 00844 { 00845 DbgPrint(("FsRtl: Unloading.\n")); 00846 } 00847 00848 Generated on Wed May 23 2012 04:35:28 for ReactOS by
1.7.6.1
|