ReactOS  0.4.13-dev-259-g5ca9c9c
kernel32_drv.c
Go to the documentation of this file.
1 /*
2  * PROJECT: ReactOS kernel-mode tests
3  * LICENSE: LGPL-2.1+ (https://spdx.org/licenses/LGPL-2.1+)
4  * PURPOSE: Test driver for kernel32 filesystem tests
5  * COPYRIGHT: Copyright 2013-2017 Thomas Faber <thomas.faber@reactos.org>
6  */
7 
8 #include <kmt_test.h>
9 
10 #define NDEBUG
11 #include <debug.h>
12 
13 #include "kernel32_test.h"
14 
15 static KMT_MESSAGE_HANDLER TestMessageHandler;
16 static KMT_IRP_HANDLER TestDirectoryControl;
17 static KMT_IRP_HANDLER TestQueryInformation;
18 static KMT_IRP_HANDLER TestSetInformation;
19 
26 
32  IN OUT INT *Flags)
33 {
35 
36  PAGED_CODE();
37 
39 
40  *DeviceName = L"kernel32";
41  *Flags = TESTENTRY_NO_EXCLUSIVE_DEVICE;
42 
47 
48  return Status;
49 }
50 
51 VOID
54 {
55  PAGED_CODE();
56 }
57 
58 static
64  IN SIZE_T InLength,
65  IN OUT PSIZE_T OutLength)
66 {
68 
69  PAGED_CODE();
70 
71  switch (ControlCode)
72  {
74  {
76  DPRINT("IOCTL_EXPECT_EXPRESSION, InLength = %lu\n", InLength);
77  if (InLength > sizeof(ExpressionBuffer))
79 
80  if (InLength % sizeof(WCHAR) != 0)
82 
83  RtlInitEmptyUnicodeString(&ExpectedExpression, ExpressionBuffer, sizeof(ExpressionBuffer));
85  ExpectedExpression.Length = (USHORT)InLength;
86  DPRINT("IOCTL_EXPECT_EXPRESSION: %wZ\n", &ExpectedExpression);
87 
88  break;
89  }
91  {
92  DPRINT("IOCTL_RETURN_QUERY_ATTRIBUTES, InLength = %lu\n", InLength);
93  if (InLength != sizeof(ULONG))
95 
98  DPRINT("IOCTL_RETURN_QUERY_ATTRIBUTES: %lu\n", ReturnQueryAttributes);
99  break;
100  }
102  {
103  DPRINT("IOCTL_EXPECT_SET_ATTRIBUTES, InLength = %lu\n", InLength);
104  if (InLength != sizeof(ULONG))
106 
109  DPRINT("IOCTL_EXPECT_SET_ATTRIBUTES: %lu\n", ExpectedSetAttributes);
110  break;
111  }
112  default:
113  return STATUS_NOT_SUPPORTED;
114  }
115 
116  return Status;
117 }
118 
119 static
120 NTSTATUS
123  IN PIRP Irp,
124  IN PIO_STACK_LOCATION IoStackLocation)
125 {
127 
128  PAGED_CODE();
129 
130  DPRINT("IRP %x/%x\n", IoStackLocation->MajorFunction, IoStackLocation->MinorFunction);
131  ASSERT(IoStackLocation->MajorFunction == IRP_MJ_DIRECTORY_CONTROL);
132 
133  ok(IoStackLocation->MinorFunction == IRP_MN_QUERY_DIRECTORY, "Minor function: %u\n", IoStackLocation->MinorFunction);
134  if (IoStackLocation->MinorFunction == IRP_MN_QUERY_DIRECTORY)
135  {
136  ok(IoStackLocation->Parameters.QueryDirectory.FileInformationClass == FileBothDirectoryInformation,
137  "FileInformationClass: %d\n", IoStackLocation->Parameters.QueryDirectory.FileInformationClass);
138  if (IoStackLocation->Parameters.QueryDirectory.FileInformationClass == FileBothDirectoryInformation)
139  {
140  ok(RtlEqualUnicodeString(IoStackLocation->Parameters.QueryDirectory.FileName, &ExpectedExpression, FALSE),
141  "Expression is '%wZ', expected '%wZ'\n", IoStackLocation->Parameters.QueryDirectory.FileName, &ExpectedExpression);
142  RtlZeroMemory(Irp->UserBuffer, IoStackLocation->Parameters.QueryDirectory.Length);
144  }
145  }
146 
147  Irp->IoStatus.Status = Status;
148  Irp->IoStatus.Information = 0;
149 
151 
152  return Status;
153 }
154 
155 static
156 NTSTATUS
159  IN PIRP Irp,
160  IN PIO_STACK_LOCATION IoStackLocation)
161 {
163  PFILE_BASIC_INFORMATION BasicInfo;
164 
165  PAGED_CODE();
166 
167  DPRINT("IRP %x/%x\n", IoStackLocation->MajorFunction, IoStackLocation->MinorFunction);
168  ASSERT(IoStackLocation->MajorFunction == IRP_MJ_QUERY_INFORMATION);
169 
170  Irp->IoStatus.Information = 0;
171 
172  ok_eq_ulong(IoStackLocation->Parameters.QueryFile.FileInformationClass, FileBasicInformation);
173  if (IoStackLocation->Parameters.QueryFile.FileInformationClass == FileBasicInformation)
174  {
175  ok(ExpectingQueryAttributes, "Unexpected QUERY_INFORMATION call\n");
176  BasicInfo = Irp->AssociatedIrp.SystemBuffer;
177  BasicInfo->CreationTime.QuadPart = 126011664000000000;
178  BasicInfo->LastAccessTime.QuadPart = 130899112800000000;
179  BasicInfo->LastWriteTime.QuadPart = 130899112800000000;
180  BasicInfo->ChangeTime.QuadPart = 130899112800000000;
185  Irp->IoStatus.Information = sizeof(*BasicInfo);
186  }
187 
188  Irp->IoStatus.Status = Status;
189 
191 
192  return Status;
193 }
194 
195 static
196 NTSTATUS
199  IN PIRP Irp,
200  IN PIO_STACK_LOCATION IoStackLocation)
201 {
203  PFILE_BASIC_INFORMATION BasicInfo;
204 
205  PAGED_CODE();
206 
207  DPRINT("IRP %x/%x\n", IoStackLocation->MajorFunction, IoStackLocation->MinorFunction);
208  ASSERT(IoStackLocation->MajorFunction == IRP_MJ_SET_INFORMATION);
209 
210  ok_eq_ulong(IoStackLocation->Parameters.SetFile.FileInformationClass, FileBasicInformation);
211  if (IoStackLocation->Parameters.SetFile.FileInformationClass == FileBasicInformation)
212  {
213  ok(ExpectingSetAttributes, "Unexpected SET_INFORMATION call\n");
214  BasicInfo = Irp->AssociatedIrp.SystemBuffer;
215  ok_eq_longlong(BasicInfo->CreationTime.QuadPart, 0LL);
217  ok_eq_longlong(BasicInfo->LastWriteTime.QuadPart, 0LL);
218  ok_eq_longlong(BasicInfo->ChangeTime.QuadPart, 0LL);
223  }
224 
225  Irp->IoStatus.Status = Status;
226  Irp->IoStatus.Information = 0;
227 
229 
230  return Status;
231 }
#define ok_eq_ulong(value, expected)
VOID TestUnload(IN PDRIVER_OBJECT DriverObject)
Definition: kernel32_drv.c:52
const uint16_t * PCWSTR
Definition: typedefs.h:55
#define IN
Definition: typedefs.h:38
#define TRUE
Definition: types.h:120
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
#define LL
Definition: tui.h:72
#define ok_eq_longlong(value, expected)
Definition: kmt_test.h:242
LARGE_INTEGER LastAccessTime
Definition: nt_native.h:940
_In_ PIRP Irp
Definition: csq.h:116
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:323
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
static KMT_IRP_HANDLER TestSetInformation
Definition: kernel32_drv.c:18
LONG NTSTATUS
Definition: precomp.h:26
#define IOCTL_EXPECT_EXPRESSION
Definition: kernel32_test.h:11
#define IRP_MN_QUERY_DIRECTORY
Definition: rdpdr.c:55
WCHAR DeviceName[]
Definition: adapter.cpp:21
static KMT_IRP_HANDLER TestDirectoryControl
Definition: kernel32_drv.c:16
#define UNICODE_STRING_MAX_BYTES
int32_t INT
Definition: typedefs.h:56
#define PAGED_CODE()
Definition: video.h:57
_Must_inspect_result_ _In_ ULONG Flags
Definition: wsk.h:170
ULONG_PTR * PSIZE_T
Definition: typedefs.h:78
#define ok(value,...)
unsigned char BOOLEAN
smooth NULL
Definition: ftsmooth.c:416
static PDRIVER_OBJECT DriverObject
Definition: template.c:42
#define IoCompleteRequest
Definition: irp.c:1240
void DPRINT(...)
Definition: polytest.cpp:61
_IRQL_requires_same_ typedef _In_ ULONG ControlCode
Definition: wmitypes.h:55
Definition: bufpool.h:45
#define IRP_MJ_DIRECTORY_CONTROL
Definition: rdpdr.c:51
NTSTATUS KmtRegisterIrpHandler(IN UCHAR MajorFunction, IN PDEVICE_OBJECT DeviceObject OPTIONAL, IN PKMT_IRP_HANDLER IrpHandler)
static BOOLEAN ExpectingQueryAttributes
Definition: kernel32_drv.c:24
static UNICODE_STRING ExpectedExpression
Definition: kernel32_drv.c:20
#define IOCTL_RETURN_QUERY_ATTRIBUTES
Definition: kernel32_test.h:12
LARGE_INTEGER LastWriteTime
Definition: nt_native.h:941
NTSTATUS KmtRegisterMessageHandler(IN ULONG ControlCode OPTIONAL, IN PDEVICE_OBJECT DeviceObject OPTIONAL, IN PKMT_MESSAGE_HANDLER MessageHandler)
__wchar_t WCHAR
Definition: xmlstorage.h:180
static BOOLEAN ExpectingSetAttributes
Definition: kernel32_drv.c:22
#define MAX_PATH
Definition: compat.h:26
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
LARGE_INTEGER CreationTime
Definition: nt_native.h:939
static const WCHAR L[]
Definition: oid.c:1250
NTSTATUS TestEntry(IN PDRIVER_OBJECT DriverObject, IN PCUNICODE_STRING RegistryPath, OUT PCWSTR *DeviceName, IN OUT INT *Flags)
Definition: kernel32_drv.c:28
LARGE_INTEGER ChangeTime
Definition: nt_native.h:942
Status
Definition: gdiplustypes.h:24
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
ULONG_PTR SIZE_T
Definition: typedefs.h:78
#define STATUS_BUFFER_OVERFLOW
Definition: shellext.h:61
#define C_ASSERT(e)
Definition: ntstrsafe.h:22
unsigned short USHORT
Definition: pedump.c:61
static WCHAR ExpressionBuffer[MAX_PATH]
Definition: kernel32_drv.c:21
unsigned int * PULONG
Definition: retypes.h:1
static ULONG ReturnQueryAttributes
Definition: kernel32_drv.c:25
#define OUT
Definition: typedefs.h:39
#define STATUS_NOT_SUPPORTED
Definition: ntstatus.h:409
#define IRP_MJ_SET_INFORMATION
Definition: rdpdr.c:49
unsigned int ULONG
Definition: retypes.h:1
static KMT_MESSAGE_HANDLER TestMessageHandler
Definition: kernel32_drv.c:15
#define IO_NO_INCREMENT
Definition: iotypes.h:565
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:261
_In_ PUNICODE_STRING RegistryPath
Definition: wmip.h:27
#define IRP_MJ_QUERY_INFORMATION
Definition: rdpdr.c:48
return STATUS_SUCCESS
Definition: btrfs.c:2745
static ULONG ExpectedSetAttributes
Definition: kernel32_drv.c:23
NTSYSAPI BOOLEAN NTAPI RtlEqualUnicodeString(PUNICODE_STRING String1, PUNICODE_STRING String2, BOOLEAN CaseInSensitive)
static KMT_IRP_HANDLER TestQueryInformation
Definition: kernel32_drv.c:17
#define IOCTL_EXPECT_SET_ATTRIBUTES
Definition: kernel32_test.h:13
LONGLONG QuadPart
Definition: typedefs.h:112
#define RTL_CONSTANT_STRING(s)
Definition: tunneltest.c:14
PULONG MinorVersion OPTIONAL
Definition: CrossNt.h:68