ReactOS  0.4.14-dev-98-gb0d4763
CcSetFileSizes_drv.c File Reference
#include <kmt_test.h>
#include <debug.h>
Include dependency graph for CcSetFileSizes_drv.c:

Go to the source code of this file.

Classes

struct  _TEST_FCB
 

Macros

#define NDEBUG
 
#define IOCTL_START_TEST   1
 
#define IOCTL_FINISH_TEST   2
 

Typedefs

typedef struct _TEST_FCB TEST_FCB
 
typedef struct _TEST_FCBPTEST_FCB
 

Functions

NTSTATUS TestEntry (_In_ PDRIVER_OBJECT DriverObject, _In_ PCUNICODE_STRING RegistryPath, _Out_ PCWSTR *DeviceName, _Inout_ INT *Flags)
 
VOID TestUnload (_In_ PDRIVER_OBJECT DriverObject)
 
BOOLEAN NTAPI AcquireForLazyWrite (_In_ PVOID Context, _In_ BOOLEAN Wait)
 
VOID NTAPI ReleaseFromLazyWrite (_In_ PVOID Context)
 
BOOLEAN NTAPI AcquireForReadAhead (_In_ PVOID Context, _In_ BOOLEAN Wait)
 
VOID NTAPI ReleaseFromReadAhead (_In_ PVOID Context)
 
static PVOID MapAndLockUserBuffer (_In_ _Out_ PIRP Irp, _In_ ULONG BufferLength)
 
static VOID PerformTest (ULONG TestId, PDEVICE_OBJECT DeviceObject)
 
static VOID CleanupTest (ULONG TestId, PDEVICE_OBJECT DeviceObject)
 
static NTSTATUS TestMessageHandler (_In_ PDEVICE_OBJECT DeviceObject, _In_ ULONG ControlCode, _In_opt_ PVOID Buffer, _In_ SIZE_T InLength, _Inout_ PSIZE_T OutLength)
 
static NTSTATUS TestIrpHandler (_In_ PDEVICE_OBJECT DeviceObject, _In_ PIRP Irp, _In_ PIO_STACK_LOCATION IoStack)
 

Variables

static ULONG TestTestId = -1
 
static PFILE_OBJECT TestFileObject
 
static PDEVICE_OBJECT TestDeviceObject
 
static KMT_IRP_HANDLER TestIrpHandler
 
static KMT_MESSAGE_HANDLER TestMessageHandler
 
static BOOLEAN TestUnpin = FALSE
 
static BOOLEAN TestSizing = FALSE
 
static BOOLEAN TestDirtying = FALSE
 
static BOOLEAN TestUncaching = FALSE
 
static BOOLEAN TestWritten = FALSE
 
static CACHE_MANAGER_CALLBACKS Callbacks
 
static CC_FILE_SIZES NewFileSizes
 

Macro Definition Documentation

◆ IOCTL_FINISH_TEST

#define IOCTL_FINISH_TEST   2

Definition at line 14 of file CcSetFileSizes_drv.c.

◆ IOCTL_START_TEST

#define IOCTL_START_TEST   1

Definition at line 13 of file CcSetFileSizes_drv.c.

◆ NDEBUG

#define NDEBUG

Definition at line 10 of file CcSetFileSizes_drv.c.

Typedef Documentation

◆ PTEST_FCB

◆ TEST_FCB

Function Documentation

◆ AcquireForLazyWrite()

BOOLEAN NTAPI AcquireForLazyWrite ( _In_ PVOID  Context,
_In_ BOOLEAN  Wait 
)

Definition at line 68 of file CcSetFileSizes_drv.c.

71 {
72  return TRUE;
73 }
#define TRUE
Definition: types.h:120

◆ AcquireForReadAhead()

BOOLEAN NTAPI AcquireForReadAhead ( _In_ PVOID  Context,
_In_ BOOLEAN  Wait 
)

Definition at line 85 of file CcSetFileSizes_drv.c.

88 {
89  return TRUE;
90 }
#define TRUE
Definition: types.h:120

◆ CleanupTest()

static VOID CleanupTest ( ULONG  TestId,
PDEVICE_OBJECT  DeviceObject 
)
static

Definition at line 326 of file CcSetFileSizes_drv.c.

329 {
331  CACHE_UNINITIALIZE_EVENT CacheUninitEvent;
332 
334  ok_eq_ulong(TestTestId, TestId);
335 
336  if (!skip(TestFileObject != NULL, "No test FO\n"))
337  {
339  {
341  KeInitializeEvent(&CacheUninitEvent.Event, NotificationEvent, FALSE);
342  CcUninitializeCacheMap(TestFileObject, &Zero, &CacheUninitEvent);
343  KeWaitForSingleObject(&CacheUninitEvent.Event, Executive, KernelMode, FALSE, NULL);
345  }
346 
347  if (TestFileObject->FsContext != NULL)
348  {
349  ExFreePool(TestFileObject->FsContext);
350  TestFileObject->FsContext = NULL;
351  TestFileObject->SectionObjectPointer = NULL;
352  }
353 
355  }
356 
359  TestTestId = -1;
360 }
#define ok_eq_ulong(value, expected)
#define TRUE
Definition: types.h:120
#define LL
Definition: tui.h:85
static ULONG TestTestId
#define ok_eq_pointer(value, expected)
VOID NTAPI ObDereferenceObject(IN PVOID Object)
Definition: obref.c:375
static BOOLEAN TestUncaching
NTSTATUS NTAPI KeWaitForSingleObject(IN PVOID Object, IN KWAIT_REASON WaitReason, IN KPROCESSOR_MODE WaitMode, IN BOOLEAN Alertable, IN PLARGE_INTEGER Timeout OPTIONAL)
Definition: wait.c:416
#define RTL_CONSTANT_LARGE_INTEGER(quad_part)
Definition: rtltypes.h:414
#define CcIsFileCached(FO)
smooth NULL
Definition: ftsmooth.c:416
static PFILE_OBJECT TestFileObject
static PDEVICE_OBJECT TestDeviceObject
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
#define KeInitializeEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:477
BOOLEAN NTAPI CcUninitializeCacheMap(IN PFILE_OBJECT FileObject, IN OPTIONAL PLARGE_INTEGER TruncateSize, IN OPTIONAL PCACHE_UNINITIALIZE_EVENT UninitializeEvent)
Definition: fssup.c:284
IN PVCB IN VBO IN ULONG OUT PBCB OUT PVOID IN BOOLEAN IN BOOLEAN Zero
Definition: fatprocs.h:402
#define skip(...)
Definition: atltest.h:64
#define ExFreePool(addr)
Definition: env_spec_w32.h:352

Referenced by TestMessageHandler().

◆ MapAndLockUserBuffer()

static PVOID MapAndLockUserBuffer ( _In_ _Out_ PIRP  Irp,
_In_ ULONG  BufferLength 
)
static

Definition at line 115 of file CcSetFileSizes_drv.c.

118 {
119  PMDL Mdl;
120 
121  if (Irp->MdlAddress == NULL)
122  {
123  Mdl = IoAllocateMdl(Irp->UserBuffer, BufferLength, FALSE, FALSE, Irp);
124  if (Mdl == NULL)
125  {
126  return NULL;
127  }
128 
129  _SEH2_TRY
130  {
131  MmProbeAndLockPages(Mdl, Irp->RequestorMode, IoWriteAccess);
132  }
134  {
135  IoFreeMdl(Mdl);
136  Irp->MdlAddress = NULL;
137  _SEH2_YIELD(return NULL);
138  }
139  _SEH2_END;
140  }
141 
143 }
_In_ PIRP Irp
Definition: csq.h:116
#define MmGetSystemAddressForMdlSafe(_Mdl, _Priority)
_SEH2_TRY
Definition: create.c:4250
_In_ ULONG BufferLength
Definition: usbdlib.h:225
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:85
smooth NULL
Definition: ftsmooth.c:416
#define _SEH2_YIELD(STMT_)
Definition: pseh2_64.h:8
VOID NTAPI IoFreeMdl(PMDL Mdl)
Definition: iomdl.c:146
PMDL NTAPI IoAllocateMdl(IN PVOID VirtualAddress, IN ULONG Length, IN BOOLEAN SecondaryBuffer, IN BOOLEAN ChargeQuota, IN PIRP Irp)
Definition: iomdl.c:22
_SEH2_END
Definition: create.c:4424
VOID NTAPI MmProbeAndLockPages(IN PMDL Mdl, IN KPROCESSOR_MODE AccessMode, IN LOCK_OPERATION Operation)
Definition: mdlsup.c:935
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:6

Referenced by TestIrpHandler().

◆ PerformTest()

static VOID PerformTest ( ULONG  TestId,
PDEVICE_OBJECT  DeviceObject 
)
static

Definition at line 147 of file CcSetFileSizes_drv.c.

150 {
151  PVOID Bcb;
152  BOOLEAN Ret;
153  PULONG Buffer;
154  PTEST_FCB Fcb;
157 
160  ok_eq_ulong(TestTestId, -1);
161 
162  TestWritten = FALSE;
164  TestTestId = TestId;
166  if (!skip(TestFileObject != NULL, "Failed to allocate FO\n"))
167  {
169  if (!skip(Fcb != NULL, "ExAllocatePool failed\n"))
170  {
171  RtlZeroMemory(Fcb, sizeof(TEST_FCB));
172  ExInitializeFastMutex(&Fcb->HeaderMutex);
173  FsRtlSetupAdvancedHeader(&Fcb->Header, &Fcb->HeaderMutex);
174 
175  TestFileObject->FsContext = Fcb;
176  TestFileObject->SectionObjectPointer = &Fcb->SectionObjectPointers;
177  Fcb->Header.AllocationSize.QuadPart = VACB_MAPPING_GRANULARITY;
178  Fcb->Header.FileSize.QuadPart = VACB_MAPPING_GRANULARITY - PAGE_SIZE;
179  Fcb->Header.ValidDataLength.QuadPart = VACB_MAPPING_GRANULARITY - PAGE_SIZE;
180 
181  if ((TestId > 1 && TestId < 4) || TestId == 5)
182  {
183  Fcb->Header.AllocationSize.QuadPart = VACB_MAPPING_GRANULARITY - PAGE_SIZE;
184  }
185 
186  KmtStartSeh();
189 
190  if (!skip(CcIsFileCached(TestFileObject) == TRUE, "CcInitializeCacheMap failed\n"))
191  {
192  trace("Starting test: %d\n", TestId);
193 
194  if (TestId == 0 || TestId == 2)
195  {
196  Offset.QuadPart = 0;
197  KmtStartSeh();
200 
201  if (!skip(Ret == TRUE, "CcMapData failed\n"))
202  {
203  ok_eq_ulong(Buffer[(VACB_MAPPING_GRANULARITY - PAGE_SIZE - sizeof(ULONG)) / sizeof(ULONG)], 0xBABABABA);
204  CcUnpinData(Bcb);
205  }
206 
207  KmtStartSeh();
210 
211  Fcb->Header.AllocationSize.QuadPart = VACB_MAPPING_GRANULARITY;
212  Fcb->Header.FileSize.QuadPart = VACB_MAPPING_GRANULARITY;
213 
214  Offset.QuadPart = 0;
215  KmtStartSeh();
218 
219  if (!skip(Ret == TRUE, "CcMapData failed\n"))
220  {
221  ok_eq_ulong(Buffer[(VACB_MAPPING_GRANULARITY - sizeof(ULONG)) / sizeof(ULONG)], 0xBABABABA);
222 
223  CcUnpinData(Bcb);
224  }
225  }
226  else if (TestId == 1 || TestId == 3)
227  {
229  if (!skip(Buffer != NULL, "ExAllocatePool failed\n"))
230  {
231  Ret = FALSE;
232  Offset.QuadPart = VACB_MAPPING_GRANULARITY - 2 * PAGE_SIZE;
233 
234  KmtStartSeh();
237 
238  ok_eq_ulong(Buffer[(PAGE_SIZE - sizeof(ULONG)) / sizeof(ULONG)], 0xBABABABA);
239 
240  KmtStartSeh();
243 
244  Fcb->Header.AllocationSize.QuadPart = VACB_MAPPING_GRANULARITY;
245  Fcb->Header.FileSize.QuadPart = VACB_MAPPING_GRANULARITY;
247 
249 
250  KmtStartSeh();
253 
254  ok_eq_ulong(Buffer[(PAGE_SIZE - sizeof(ULONG)) / sizeof(ULONG)], 0xBABABABA);
255 
257  }
258  }
259  else if (TestId == 4 || TestId == 5)
260  {
261  /* Kill lazy writer */
263 
264  Offset.QuadPart = 0;
265  KmtStartSeh();
268 
269  if (!skip(Ret == TRUE, "CcPinRead failed\n"))
270  {
271  LARGE_INTEGER Flushed;
272 
273  ok_eq_ulong(Buffer[(VACB_MAPPING_GRANULARITY - PAGE_SIZE - sizeof(ULONG)) / sizeof(ULONG)], 0xBABABABA);
274  Buffer[(VACB_MAPPING_GRANULARITY - PAGE_SIZE - sizeof(ULONG)) / sizeof(ULONG)] = 0xDADADADA;
275 
276  TestDirtying = TRUE;
279 
280  ok_bool_false(TestWritten, "Dirty VACB has been unexpectedly written!\n");
281 
282  TestSizing = TRUE;
283  KmtStartSeh();
286  TestSizing = FALSE;
287 
288  ok_bool_false(TestWritten, "Dirty VACB has been unexpectedly written!\n");
289 
290  Fcb->Header.AllocationSize.QuadPart = VACB_MAPPING_GRANULARITY;
291  Fcb->Header.FileSize.QuadPart = VACB_MAPPING_GRANULARITY;
292 
293  Flushed = CcGetFlushedValidData(TestFileObject->SectionObjectPointer, FALSE);
294  ok(Flushed.QuadPart == 0, "Flushed: %I64d\n", Flushed.QuadPart);
295 
296  TestUnpin = TRUE;
297  CcUnpinData(Bcb);
298  TestUnpin = FALSE;
299 
300  ok_bool_false(TestWritten, "Dirty VACB has been unexpectedly written!\n");
301 
302  Offset.QuadPart = 0;
303  KmtStartSeh();
306 
307  if (!skip(Ret == TRUE, "CcMapData failed\n"))
308  {
309  ok_eq_ulong(Buffer[(VACB_MAPPING_GRANULARITY - PAGE_SIZE - sizeof(ULONG)) / sizeof(ULONG)], 0xDADADADA);
310  ok_eq_ulong(Buffer[(VACB_MAPPING_GRANULARITY - sizeof(ULONG)) / sizeof(ULONG)], 0xBABABABA);
311 
312  CcUnpinData(Bcb);
313 
314  ok_bool_false(TestWritten, "Dirty VACB has been unexpectedly written!\n");
315  }
316  }
317  }
318  }
319  }
320  }
321 }
#define ok_eq_ulong(value, expected)
#define TRUE
Definition: types.h:120
IN PVCB IN VBO IN ULONG OUT PBCB * Bcb
Definition: fatprocs.h:402
FSRTL_ADVANCED_FCB_HEADER Header
Definition: cdstruc.h:931
static ULONG TestTestId
IN PLARGE_INTEGER IN ULONG IN BOOLEAN IN ULONG IN BOOLEAN OUT PIO_STATUS_BLOCK IoStatus
Definition: fatprocs.h:2650
VOID NTAPI CcSetDirtyPinnedData(IN PVOID BcbVoid, IN OPTIONAL PLARGE_INTEGER Lsn)
Definition: cachesub.c:121
#define ok_eq_pointer(value, expected)
#define KmtEndSeh(ExpectedStatus)
Definition: kmt_test.h:283
VOID NTAPI CcUnpinData(IN PVOID Bcb)
Definition: pinsup.c:955
#define MAP_WAIT
static CC_FILE_SIZES NewFileSizes
#define ok_bool_false(value, desc)
Definition: kmt_test.h:257
_In_ ULONG _In_ ULONG Offset
Definition: ntddpcm.h:101
#define CcIsFileCached(FO)
unsigned char BOOLEAN
smooth NULL
Definition: ftsmooth.c:416
VOID NTAPI CcSetAdditionalCacheAttributes(IN PFILE_OBJECT FileObject, IN BOOLEAN DisableReadAhead, IN BOOLEAN DisableWriteBehind)
Definition: logsup.c:22
Definition: bufpool.h:45
PFILE_OBJECT NTAPI IoCreateStreamFileObject(IN PFILE_OBJECT FileObject, IN PDEVICE_OBJECT DeviceObject)
Definition: file.c:3186
static PFILE_OBJECT TestFileObject
BOOLEAN NTAPI CcMapData(IN PFILE_OBJECT FileObject, IN PLARGE_INTEGER FileOffset, IN ULONG Length, IN ULONG Flags, OUT PVOID *BcbResult, OUT PVOID *Buffer)
Definition: pinsup.c:694
#define trace
Definition: atltest.h:70
VOID NTAPI CcInitializeCacheMap(IN PFILE_OBJECT FileObject, IN PCC_FILE_SIZES FileSizes, IN BOOLEAN PinAccess, IN PCACHE_MANAGER_CALLBACKS Callbacks, IN PVOID LazyWriteContext)
Definition: fssup.c:193
static BOOLEAN TestUnpin
FORCEINLINE VOID ExInitializeFastMutex(_Out_ PFAST_MUTEX FastMutex)
Definition: exfuncs.h:274
static BOOLEAN TestDirtying
static PDEVICE_OBJECT TestDeviceObject
BOOLEAN NTAPI CcPinRead(IN PFILE_OBJECT FileObject, IN PLARGE_INTEGER FileOffset, IN ULONG Length, IN ULONG Flags, OUT PVOID *Bcb, OUT PVOID *Buffer)
Definition: pinsup.c:802
BOOLEAN NTAPI CcCopyRead(IN PFILE_OBJECT FileObject, IN PLARGE_INTEGER FileOffset, IN ULONG Length, IN BOOLEAN Wait, OUT PVOID Buffer, OUT PIO_STATUS_BLOCK IoStatus)
Definition: copysup.c:43
#define ExAllocatePool(type, size)
Definition: fbtusb.h:44
#define PAGE_SIZE
Definition: env_spec_w32.h:49
#define KmtStartSeh()
Definition: kmt_test.h:277
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
VOID NTAPI CcSetFileSizes(IN PFILE_OBJECT FileObject, IN PCC_FILE_SIZES FileSizes)
Definition: fssup.c:354
#define ok(value,...)
Definition: atltest.h:57
unsigned int * PULONG
Definition: retypes.h:1
#define skip(...)
Definition: atltest.h:64
#define VACB_MAPPING_GRANULARITY
static BOOLEAN TestSizing
unsigned int ULONG
Definition: retypes.h:1
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:261
static CACHE_MANAGER_CALLBACKS Callbacks
_In_ PFCB Fcb
Definition: cdprocs.h:151
IN BOOLEAN OUT PSTR Buffer
Definition: progress.h:34
return STATUS_SUCCESS
Definition: btrfs.c:2966
static BOOLEAN TestWritten
SECTION_OBJECT_POINTERS SectionObjectPointers
Definition: ntfs.h:514
#define ExFreePool(addr)
Definition: env_spec_w32.h:352
LONGLONG QuadPart
Definition: typedefs.h:112
LARGE_INTEGER NTAPI CcGetFlushedValidData(IN PSECTION_OBJECT_POINTERS SectionObjectPointer, IN BOOLEAN CcInternalCaller)
Definition: cachesub.c:130

Referenced by TestMessageHandler().

◆ ReleaseFromLazyWrite()

VOID NTAPI ReleaseFromLazyWrite ( _In_ PVOID  Context)

Definition at line 77 of file CcSetFileSizes_drv.c.

79 {
80  return;
81 }

◆ ReleaseFromReadAhead()

VOID NTAPI ReleaseFromReadAhead ( _In_ PVOID  Context)

Definition at line 94 of file CcSetFileSizes_drv.c.

96 {
97  return;
98 }

◆ TestEntry()

NTSTATUS TestEntry ( _In_ PDRIVER_OBJECT  DriverObject,
_In_ PCUNICODE_STRING  RegistryPath,
_Out_ PCWSTR DeviceName,
_Inout_ INT Flags 
)

Definition at line 35 of file CcSetFileSizes_drv.c.

40 {
42 
43  PAGED_CODE();
44 
46 
47  *DeviceName = L"CcSetFileSizes";
48  *Flags = TESTENTRY_NO_EXCLUSIVE_DEVICE |
49  TESTENTRY_BUFFERED_IO_DEVICE |
50  TESTENTRY_NO_READONLY_DEVICE;
51 
55 
56  return Status;
57 }
static KMT_MESSAGE_HANDLER TestMessageHandler
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:323
LONG NTSTATUS
Definition: precomp.h:26
WCHAR DeviceName[]
Definition: adapter.cpp:21
#define PAGED_CODE()
Definition: video.h:57
_Must_inspect_result_ _In_ ULONG Flags
Definition: wsk.h:170
smooth NULL
Definition: ftsmooth.c:416
NTSTATUS KmtRegisterIrpHandler(IN UCHAR MajorFunction, IN PDEVICE_OBJECT DeviceObject OPTIONAL, IN PKMT_IRP_HANDLER IrpHandler)
NTSTATUS KmtRegisterMessageHandler(IN ULONG ControlCode OPTIONAL, IN PDEVICE_OBJECT DeviceObject OPTIONAL, IN PKMT_MESSAGE_HANDLER MessageHandler)
static const WCHAR L[]
Definition: oid.c:1250
Status
Definition: gdiplustypes.h:24
static KMT_IRP_HANDLER TestIrpHandler
#define IRP_MJ_READ
Definition: rdpdr.c:46
_In_ PUNICODE_STRING RegistryPath
Definition: wmip.h:27
#define IRP_MJ_WRITE
Definition: rdpdr.c:47
return STATUS_SUCCESS
Definition: btrfs.c:2966

◆ TestIrpHandler()

static NTSTATUS TestIrpHandler ( _In_ PDEVICE_OBJECT  DeviceObject,
_In_ PIRP  Irp,
_In_ PIO_STACK_LOCATION  IoStack 
)
static

Definition at line 400 of file CcSetFileSizes_drv.c.

404 {
406 
407  PAGED_CODE();
408 
409  DPRINT("IRP %x/%x\n", IoStack->MajorFunction, IoStack->MinorFunction);
410  ASSERT(IoStack->MajorFunction == IRP_MJ_READ ||
411  IoStack->MajorFunction == IRP_MJ_WRITE);
412 
414 
416  Irp->IoStatus.Information = 0;
417 
418  if (IoStack->MajorFunction == IRP_MJ_READ)
419  {
420  PMDL Mdl;
421  ULONG Length;
422  PTEST_FCB Fcb;
424  PVOID Buffer, OrigBuffer;
425 
426  Offset = IoStack->Parameters.Read.ByteOffset;
427  Length = IoStack->Parameters.Read.Length;
428  Fcb = IoStack->FileObject->FsContext;
429 
431  ok_eq_pointer(IoStack->FileObject, TestFileObject);
432  ok(Fcb != NULL, "Null FCB\n");
433 
434  ok(FlagOn(Irp->Flags, IRP_NOCACHE), "Not coming from Cc\n");
435 
436  ok_irql(APC_LEVEL);
437  ok((Offset.QuadPart % PAGE_SIZE == 0 || Offset.QuadPart == 0), "Offset is not aligned: %I64i\n", Offset.QuadPart);
438  ok(Length % PAGE_SIZE == 0, "Length is not aligned: %I64i\n", Length);
439 
440  ok(Irp->AssociatedIrp.SystemBuffer == NULL, "A SystemBuffer was allocated!\n");
441  OrigBuffer = Buffer = MapAndLockUserBuffer(Irp, Length);
442  ok(Buffer != NULL, "Null pointer!\n");
443 
444  if (Offset.QuadPart < Fcb->Header.FileSize.QuadPart)
445  {
446  RtlFillMemory(Buffer, min(Length, Fcb->Header.FileSize.QuadPart - Offset.QuadPart), 0xBA);
447  Buffer = (PVOID)((ULONG_PTR)Buffer + (ULONG_PTR)min(Length, Fcb->Header.FileSize.QuadPart - Offset.QuadPart));
448 
449  if (Length > (Fcb->Header.FileSize.QuadPart - Offset.QuadPart))
450  {
451  RtlFillMemory(Buffer, Length - Fcb->Header.FileSize.QuadPart, 0xBD);
452  }
453  }
454  else
455  {
456  RtlFillMemory(Buffer, Length, 0xBD);
457  }
458 
459  if ((TestTestId == 4 || TestTestId == 5) && TestWritten &&
460  Offset.QuadPart <= VACB_MAPPING_GRANULARITY - PAGE_SIZE - sizeof(ULONG) &&
462  {
463  Buffer = (PVOID)((ULONG_PTR)OrigBuffer + (VACB_MAPPING_GRANULARITY - PAGE_SIZE - sizeof(ULONG)));
464  RtlFillMemory(Buffer, sizeof(ULONG), 0xDA);
465  }
466 
468 
469  Mdl = Irp->MdlAddress;
470  ok(Mdl != NULL, "Null pointer for MDL!\n");
471  ok((Mdl->MdlFlags & MDL_PAGES_LOCKED) != 0, "MDL not locked\n");
472  ok((Mdl->MdlFlags & MDL_SOURCE_IS_NONPAGED_POOL) == 0, "MDL from non paged\n");
473  ok((Mdl->MdlFlags & MDL_IO_PAGE_READ) != 0, "Non paging IO\n");
474  ok((Irp->Flags & IRP_PAGING_IO) != 0, "Non paging IO\n");
475 
476  Irp->IoStatus.Information = Length;
477  }
478  else if (IoStack->MajorFunction == IRP_MJ_WRITE)
479  {
480  PMDL Mdl;
481  ULONG Length;
482  PVOID Buffer;
484 
485  Offset = IoStack->Parameters.Write.ByteOffset;
486  Length = IoStack->Parameters.Write.Length;
487 
488  ok((TestTestId == 4 || TestTestId == 5), "Unexpected test id: %d\n", TestTestId);
490  ok_eq_pointer(IoStack->FileObject, TestFileObject);
491 
492  ok_bool_false(TestUnpin, "Write triggered while unpinning!\n");
493  ok_bool_false(TestSizing, "Write triggered while sizing!\n");
494  ok_bool_false(TestDirtying, "Write triggered while dirtying!\n");
495  ok_bool_true(TestUncaching, "Write not triggered while uncaching!\n");
496 
497  ok(FlagOn(Irp->Flags, IRP_NOCACHE), "Not coming from Cc\n");
498 
499  ok_irql(PASSIVE_LEVEL);
500  ok((Offset.QuadPart % PAGE_SIZE == 0 || Offset.QuadPart == 0), "Offset is not aligned: %I64i\n", Offset.QuadPart);
501  ok(Length % PAGE_SIZE == 0, "Length is not aligned: %I64i\n", Length);
502 
504  ok(Buffer != NULL, "Null pointer!\n");
505 
506  Mdl = Irp->MdlAddress;
507  ok(Mdl != NULL, "Null pointer for MDL!\n");
508  ok((Mdl->MdlFlags & MDL_PAGES_LOCKED) != 0, "MDL not locked\n");
509  ok((Mdl->MdlFlags & MDL_SOURCE_IS_NONPAGED_POOL) == 0, "MDL from non paged\n");
510  ok((Irp->Flags & IRP_PAGING_IO) != 0, "Non paging IO\n");
511 
512  TestWritten = TRUE;
514  Irp->IoStatus.Information = Length;
515  }
516 
517  if (Status == STATUS_PENDING)
518  {
522  }
523  else
524  {
525  Irp->IoStatus.Status = Status;
527  }
528 
530 
531  return Status;
532 }
#define MDL_IO_PAGE_READ
Definition: mmtypes.h:24
#define TRUE
Definition: types.h:120
#define FsRtlEnterFileSystem
#define FsRtlExitFileSystem
FSRTL_ADVANCED_FCB_HEADER Header
Definition: cdstruc.h:931
static ULONG TestTestId
PFILE_OBJECT FileObject
Definition: ntfs.h:516
_In_ PIRP Irp
Definition: csq.h:116
#define ok_eq_pointer(value, expected)
LONG NTSTATUS
Definition: precomp.h:26
#define IRP_NOCACHE
static BOOLEAN TestUncaching
#define PAGED_CODE()
Definition: video.h:57
uint32_t ULONG_PTR
Definition: typedefs.h:63
#define ok_bool_false(value, desc)
Definition: kmt_test.h:257
#define ok_bool_true(value, desc)
Definition: kmt_test.h:256
_In_ ULONG _In_ ULONG Offset
Definition: ntddpcm.h:101
smooth NULL
Definition: ftsmooth.c:416
#define MDL_SOURCE_IS_NONPAGED_POOL
Definition: mmtypes.h:20
#define IoCompleteRequest
Definition: irp.c:1240
void DPRINT(...)
Definition: polytest.cpp:61
Definition: bufpool.h:45
void * PVOID
Definition: retypes.h:9
static PFILE_OBJECT TestFileObject
#define MDL_PAGES_LOCKED
Definition: mmtypes.h:19
#define STATUS_PENDING
Definition: ntstatus.h:82
static BOOLEAN TestUnpin
static BOOLEAN TestDirtying
static PDEVICE_OBJECT TestDeviceObject
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#define PAGE_SIZE
Definition: env_spec_w32.h:49
#define FlagOn(_F, _SF)
Definition: ext2fs.h:179
#define PASSIVE_LEVEL
Definition: env_spec_w32.h:693
Status
Definition: gdiplustypes.h:24
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
static PVOID MapAndLockUserBuffer(_In_ _Out_ PIRP Irp, _In_ ULONG BufferLength)
#define ok(value,...)
Definition: atltest.h:57
#define min(a, b)
Definition: monoChain.cc:55
#define IRP_PAGING_IO
#define IRP_MJ_READ
Definition: rdpdr.c:46
#define VACB_MAPPING_GRANULARITY
static BOOLEAN TestSizing
#define STATUS_NOT_SUPPORTED
Definition: ntstatus.h:409
unsigned int ULONG
Definition: retypes.h:1
#define IO_NO_INCREMENT
Definition: iotypes.h:566
#define ULONG_PTR
Definition: config.h:101
#define IRP_MJ_WRITE
Definition: rdpdr.c:47
_In_ PFCB Fcb
Definition: cdprocs.h:151
IN BOOLEAN OUT PSTR Buffer
Definition: progress.h:34
return STATUS_SUCCESS
Definition: btrfs.c:2966
IoMarkIrpPending(Irp)
#define RtlFillMemory(Dest, Length, Fill)
Definition: winternl.h:593
static BOOLEAN TestWritten
#define APC_LEVEL
Definition: env_spec_w32.h:695

◆ TestMessageHandler()

static NTSTATUS TestMessageHandler ( _In_ PDEVICE_OBJECT  DeviceObject,
_In_ ULONG  ControlCode,
_In_opt_ PVOID Buffer  ,
_In_ SIZE_T  InLength,
_Inout_ PSIZE_T  OutLength 
)
static

Definition at line 365 of file CcSetFileSizes_drv.c.

371 {
373 
375 
376  switch (ControlCode)
377  {
378  case IOCTL_START_TEST:
379  ok_eq_ulong((ULONG)InLength, sizeof(ULONG));
381  break;
382 
383  case IOCTL_FINISH_TEST:
384  ok_eq_ulong((ULONG)InLength, sizeof(ULONG));
386  break;
387 
388  default:
390  break;
391  }
392 
394 
395  return Status;
396 }
#define ok_eq_ulong(value, expected)
#define FsRtlEnterFileSystem
#define FsRtlExitFileSystem
#define STATUS_NOT_IMPLEMENTED
Definition: ntstatus.h:225
LONG NTSTATUS
Definition: precomp.h:26
_IRQL_requires_same_ typedef _In_ ULONG ControlCode
Definition: wmitypes.h:55
Definition: bufpool.h:45
#define IOCTL_START_TEST
Status
Definition: gdiplustypes.h:24
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
unsigned int * PULONG
Definition: retypes.h:1
#define IOCTL_FINISH_TEST
static VOID PerformTest(ULONG TestId, PDEVICE_OBJECT DeviceObject)
unsigned int ULONG
Definition: retypes.h:1
return STATUS_SUCCESS
Definition: btrfs.c:2966
static VOID CleanupTest(ULONG TestId, PDEVICE_OBJECT DeviceObject)

◆ TestUnload()

VOID TestUnload ( _In_ PDRIVER_OBJECT  DriverObject)

Definition at line 60 of file CcSetFileSizes_drv.c.

62 {
63  PAGED_CODE();
64 }
#define PAGED_CODE()
Definition: video.h:57

Variable Documentation

◆ Callbacks

CACHE_MANAGER_CALLBACKS Callbacks
static
Initial value:
= {
}
BOOLEAN NTAPI AcquireForLazyWrite(_In_ PVOID Context, _In_ BOOLEAN Wait)
VOID NTAPI ReleaseFromReadAhead(_In_ PVOID Context)
BOOLEAN NTAPI AcquireForReadAhead(_In_ PVOID Context, _In_ BOOLEAN Wait)
VOID NTAPI ReleaseFromLazyWrite(_In_ PVOID Context)

Definition at line 100 of file CcSetFileSizes_drv.c.

Referenced by PerformTest().

◆ NewFileSizes

CC_FILE_SIZES NewFileSizes
static
Initial value:

Definition at line 107 of file CcSetFileSizes_drv.c.

Referenced by PerformTest().

◆ TestDeviceObject

PDEVICE_OBJECT TestDeviceObject
static

Definition at line 25 of file CcSetFileSizes_drv.c.

Referenced by CleanupTest(), PerformTest(), and TestIrpHandler().

◆ TestDirtying

BOOLEAN TestDirtying = FALSE
static

Definition at line 30 of file CcSetFileSizes_drv.c.

Referenced by PerformTest(), and TestIrpHandler().

◆ TestFileObject

PFILE_OBJECT TestFileObject
static

Definition at line 24 of file CcSetFileSizes_drv.c.

Referenced by CleanupTest(), PerformTest(), and TestIrpHandler().

◆ TestIrpHandler

KMT_IRP_HANDLER TestIrpHandler
static

Definition at line 26 of file CcSetFileSizes_drv.c.

Referenced by TestEntry().

◆ TestMessageHandler

KMT_MESSAGE_HANDLER TestMessageHandler
static

Definition at line 27 of file CcSetFileSizes_drv.c.

Referenced by TestEntry().

◆ TestSizing

BOOLEAN TestSizing = FALSE
static

Definition at line 29 of file CcSetFileSizes_drv.c.

Referenced by PerformTest(), and TestIrpHandler().

◆ TestTestId

ULONG TestTestId = -1
static

Definition at line 23 of file CcSetFileSizes_drv.c.

Referenced by CleanupTest(), PerformTest(), and TestIrpHandler().

◆ TestUncaching

BOOLEAN TestUncaching = FALSE
static

Definition at line 31 of file CcSetFileSizes_drv.c.

Referenced by CleanupTest(), and TestIrpHandler().

◆ TestUnpin

BOOLEAN TestUnpin = FALSE
static

Definition at line 28 of file CcSetFileSizes_drv.c.

Referenced by PerformTest(), and TestIrpHandler().

◆ TestWritten

BOOLEAN TestWritten = FALSE
static

Definition at line 32 of file CcSetFileSizes_drv.c.

Referenced by PerformTest(), and TestIrpHandler().