ReactOS 0.4.15-dev-7089-gea8a49d
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
15static KMT_MESSAGE_HANDLER TestMessageHandler;
16static KMT_IRP_HANDLER TestDirectoryControl;
17static KMT_IRP_HANDLER TestQueryInformation;
18static 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
51VOID
54{
55 PAGED_CODE();
56}
57
58static
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));
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:
114 }
115
116 return Status;
117}
118
119static
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
155static
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
195static
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;
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 PAGED_CODE()
unsigned char BOOLEAN
#define ok_eq_ulong(value, expected)
Definition: apitest.h:62
#define ok_eq_longlong(value, expected)
Definition: apitest.h:63
#define ok(value,...)
Definition: atltest.h:57
LONG NTSTATUS
Definition: precomp.h:26
Definition: bufpool.h:45
_In_ PIRP Irp
Definition: csq.h:116
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define MAX_PATH
Definition: compat.h:34
@ FileBasicInformation
Definition: from_kernel.h:65
@ FileBothDirectoryInformation
Definition: from_kernel.h:64
Status
Definition: gdiplustypes.h:25
#define C_ASSERT(e)
Definition: intsafe.h:73
static BOOLEAN ExpectingSetAttributes
Definition: kernel32_drv.c:22
static UNICODE_STRING ExpectedExpression
Definition: kernel32_drv.c:20
static ULONG ReturnQueryAttributes
Definition: kernel32_drv.c:25
static BOOLEAN ExpectingQueryAttributes
Definition: kernel32_drv.c:24
static WCHAR ExpressionBuffer[MAX_PATH]
Definition: kernel32_drv.c:21
static ULONG ExpectedSetAttributes
Definition: kernel32_drv.c:23
static KMT_IRP_HANDLER TestDirectoryControl
Definition: kernel32_drv.c:16
static KMT_IRP_HANDLER TestSetInformation
Definition: kernel32_drv.c:18
static KMT_MESSAGE_HANDLER TestMessageHandler
Definition: kernel32_drv.c:15
VOID TestUnload(IN PDRIVER_OBJECT DriverObject)
Definition: kernel32_drv.c:52
NTSTATUS TestEntry(IN PDRIVER_OBJECT DriverObject, IN PCUNICODE_STRING RegistryPath, OUT PCWSTR *DeviceName, IN OUT INT *Flags)
Definition: kernel32_drv.c:28
static KMT_IRP_HANDLER TestQueryInformation
Definition: kernel32_drv.c:17
#define IOCTL_RETURN_QUERY_ATTRIBUTES
Definition: kernel32_test.h:12
#define IOCTL_EXPECT_EXPRESSION
Definition: kernel32_test.h:11
#define IOCTL_EXPECT_SET_ATTRIBUTES
Definition: kernel32_test.h:13
NTSTATUS KmtRegisterMessageHandler(IN ULONG ControlCode OPTIONAL, IN PDEVICE_OBJECT DeviceObject OPTIONAL, IN PKMT_MESSAGE_HANDLER MessageHandler)
NTSTATUS KmtRegisterIrpHandler(IN UCHAR MajorFunction, IN PDEVICE_OBJECT DeviceObject OPTIONAL, IN PKMT_IRP_HANDLER IrpHandler)
#define ASSERT(a)
Definition: mode.c:44
NTSYSAPI BOOLEAN NTAPI RtlEqualUnicodeString(PUNICODE_STRING String1, PUNICODE_STRING String2, BOOLEAN CaseInSensitive)
#define UNICODE_STRING_MAX_BYTES
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:317
#define IoCompleteRequest
Definition: irp.c:1240
#define STATUS_NOT_SUPPORTED
Definition: ntstatus.h:423
#define L(x)
Definition: ntvdm.h:50
unsigned short USHORT
Definition: pedump.c:61
#define IRP_MJ_DIRECTORY_CONTROL
Definition: rdpdr.c:51
#define IRP_MN_QUERY_DIRECTORY
Definition: rdpdr.c:55
#define IRP_MJ_SET_INFORMATION
Definition: rdpdr.c:49
#define IRP_MJ_QUERY_INFORMATION
Definition: rdpdr.c:48
#define STATUS_SUCCESS
Definition: shellext.h:65
#define STATUS_BUFFER_OVERFLOW
Definition: shellext.h:66
#define DPRINT
Definition: sndvol32.h:71
PULONG MinorVersion OPTIONAL
Definition: CrossNt.h:68
LARGE_INTEGER LastWriteTime
Definition: nt_native.h:941
LARGE_INTEGER CreationTime
Definition: nt_native.h:939
LARGE_INTEGER ChangeTime
Definition: nt_native.h:942
LARGE_INTEGER LastAccessTime
Definition: nt_native.h:940
#define LL
Definition: tui.h:150
#define RTL_CONSTANT_STRING(s)
Definition: tunneltest.c:14
ULONG_PTR * PSIZE_T
Definition: typedefs.h:80
uint32_t * PULONG
Definition: typedefs.h:59
const uint16_t * PCWSTR
Definition: typedefs.h:57
ULONG_PTR SIZE_T
Definition: typedefs.h:80
int32_t INT
Definition: typedefs.h:58
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
#define IN
Definition: typedefs.h:39
uint32_t ULONG
Definition: typedefs.h:59
#define OUT
Definition: typedefs.h:40
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
LONGLONG QuadPart
Definition: typedefs.h:114
_In_ PDEVICE_OBJECT DeviceObject
Definition: wdfdevice.h:2055
_Must_inspect_result_ _In_ PWDFDEVICE_INIT _In_opt_ PCUNICODE_STRING DeviceName
Definition: wdfdevice.h:3275
_Must_inspect_result_ _In_ PDRIVER_OBJECT _In_ PCUNICODE_STRING RegistryPath
Definition: wdfdriver.h:215
_Must_inspect_result_ _In_ PDRIVER_OBJECT DriverObject
Definition: wdfdriver.h:213
_IRQL_requires_same_ typedef _In_ ULONG ControlCode
Definition: wmitypes.h:55
_Must_inspect_result_ _In_ ULONG Flags
Definition: wsk.h:170
#define IO_NO_INCREMENT
Definition: iotypes.h:598
__wchar_t WCHAR
Definition: xmlstorage.h:180