ReactOS 0.4.15-dev-8241-g63935f8
IoCreateFile_drv.c
Go to the documentation of this file.
1/*
2 * PROJECT: ReactOS kernel-mode tests
3 * LICENSE: LGPLv2.1+ - See COPYING.LIB in the top level directory
4 * PURPOSE: Test driver for reparse point operations
5 * PROGRAMMER: Pierre Schweitzer <pierre@reactos.org>
6 */
7
8#include <kmt_test.h>
9
10#define NDEBUG
11#include <debug.h>
12
13#include "IoCreateFile.h"
14
15typedef struct _TEST_FCB
16{
21
22static KMT_IRP_HANDLER TestIrpHandler;
23static KMT_MESSAGE_HANDLER TestMessageHandler;
24
27
34{
36
37 PAGED_CODE();
38
40
41 *DeviceName = L"IoCreateFile";
42 *Flags = TESTENTRY_NO_EXCLUSIVE_DEVICE |
43 TESTENTRY_BUFFERED_IO_DEVICE |
44 TESTENTRY_NO_READONLY_DEVICE;
45
49
50 return Status;
51}
52
53VOID
56{
57 PAGED_CODE();
58}
59
60static volatile long gNoLinks = FALSE;
61
62static
68{
71 CACHE_UNINITIALIZE_EVENT CacheUninitEvent;
72
73 PAGED_CODE();
74
75 DPRINT("IRP %x/%x\n", IoStack->MajorFunction, IoStack->MinorFunction);
76 ASSERT(IoStack->MajorFunction == IRP_MJ_CREATE ||
77 IoStack->MajorFunction == IRP_MJ_CLEANUP);
78
80 Irp->IoStatus.Information = 0;
81
82 if (IoStack->MajorFunction == IRP_MJ_CREATE)
83 {
84 ok((IoStack->Parameters.Create.Options & FILE_OPEN_REPARSE_POINT) == 0, "FILE_OPEN_REPARSE_POINT set\n");
85 ok((IoStack->Flags == 0 && !gNoLinks) || (IoStack->Flags == SL_STOP_ON_SYMLINK && gNoLinks), "IoStack->Flags = %lx\n", IoStack->Flags);
86
87 if (IoStack->FileObject->FileName.Length >= 2 * sizeof(WCHAR))
88 {
90 TestFileObject = IoStack->FileObject;
91 }
92 if (IoStack->FileObject->FileName.Length >= 2 * sizeof(WCHAR) &&
93 IoStack->FileObject->FileName.Buffer[1] == 'M')
94 {
96
97 Irp->Tail.Overlay.AuxiliaryBuffer = ExAllocatePoolZero(NonPagedPool, MAXIMUM_REPARSE_DATA_BUFFER_SIZE, 'FwrI');
98 Reparse = (PREPARSE_DATA_BUFFER)Irp->Tail.Overlay.AuxiliaryBuffer;
99
100 if (!Reparse)
101 {
103 goto Finish;
104 }
105
107 Reparse->ReparseDataLength = 12 + sizeof(L"\\??\\C:\\Documents and Settings");
108 Reparse->MountPointReparseBuffer.SubstituteNameLength = sizeof(L"\\??\\C:\\Documents and Settings") - sizeof(UNICODE_NULL);
109 Reparse->MountPointReparseBuffer.PrintNameOffset = sizeof(L"\\??\\C:\\Documents and Settings");
110 RtlCopyMemory(Reparse->MountPointReparseBuffer.PathBuffer, L"\\??\\C:\\Documents and Settings", sizeof(L"\\??\\C:\\Documents and Settings"));
111 Irp->IoStatus.Information = IO_REPARSE_TAG_MOUNT_POINT;
113 }
114 else if (IoStack->FileObject->FileName.Length >= 2 * sizeof(WCHAR) &&
115 IoStack->FileObject->FileName.Buffer[1] == 'S')
116 {
117 PREPARSE_DATA_BUFFER Reparse;
118
119 if (IoStack->Flags & SL_STOP_ON_SYMLINK)
120 {
122 goto Finish;
123 }
124
125 Irp->Tail.Overlay.AuxiliaryBuffer = ExAllocatePoolZero(NonPagedPool, MAXIMUM_REPARSE_DATA_BUFFER_SIZE, 'FwrI');
126 Reparse = (PREPARSE_DATA_BUFFER)Irp->Tail.Overlay.AuxiliaryBuffer;
127
128 if (!Reparse)
129 {
131 goto Finish;
132 }
133
135 Reparse->ReparseDataLength = 12 + sizeof(L"\\??\\C:\\Documents and Settings");
136 Reparse->SymbolicLinkReparseBuffer.SubstituteNameLength = sizeof(L"\\??\\C:\\Documents and Settings") - sizeof(UNICODE_NULL);
137 Reparse->SymbolicLinkReparseBuffer.PrintNameOffset = sizeof(L"\\??\\C:\\Documents and Settings");
138 RtlCopyMemory(Reparse->SymbolicLinkReparseBuffer.PathBuffer, L"\\??\\C:\\Documents and Settings", sizeof(L"\\??\\C:\\Documents and Settings"));
139 Irp->IoStatus.Information = IO_REPARSE_TAG_SYMLINK;
141 }
142 else
143 {
144 Fcb = ExAllocatePoolZero(NonPagedPool, sizeof(*Fcb), 'FwrI');
145
146 if (!Fcb)
147 {
149 goto Finish;
150 }
151
152 ExInitializeFastMutex(&Fcb->HeaderMutex);
153 FsRtlSetupAdvancedHeader(&Fcb->Header, &Fcb->HeaderMutex);
154 Fcb->Header.AllocationSize.QuadPart = 0;
155 Fcb->Header.FileSize.QuadPart = 0;
156 Fcb->Header.ValidDataLength.QuadPart = 0;
157 IoStack->FileObject->FsContext = Fcb;
158 IoStack->FileObject->SectionObjectPointer = &Fcb->SectionObjectPointers;
159
160 Irp->IoStatus.Information = FILE_OPENED;
162 }
163 }
164 else if (IoStack->MajorFunction == IRP_MJ_CLEANUP)
165 {
166 KeInitializeEvent(&CacheUninitEvent.Event, NotificationEvent, FALSE);
167 CcUninitializeCacheMap(IoStack->FileObject, NULL, &CacheUninitEvent);
169 Fcb = IoStack->FileObject->FsContext;
170 ExFreePoolWithTag(Fcb, 'FwrI');
171 IoStack->FileObject->FsContext = NULL;
173 }
174
175Finish:
176 Irp->IoStatus.Status = Status;
178
179 return Status;
180}
181
183static UNICODE_STRING DocumentsAndSettings = RTL_CONSTANT_STRING(L"\\Documents and Settings");
184
185static
189{
195
197 Path,
199 NULL,
200 NULL);
205 NULL,
208 FILE_OPEN,
210 NULL,
211 0,
213 NULL,
215 if (NT_SUCCESS(Status))
216 {
217 NTSTATUS IntStatus;
218
223 (PVOID *)&FileObject,
224 NULL);
225 ok_eq_hex(IntStatus, STATUS_SUCCESS);
226 if (NT_SUCCESS(IntStatus))
227 {
230 "Expected: %wZ or %wZ. Opened: %wZ\n", &FileObjectFileName, &DocumentsAndSettings, &FileObject->FileName);
232 }
233
234 IntStatus = ObCloseHandle(Handle, KernelMode);
235 ok_eq_hex(IntStatus, STATUS_SUCCESS);
236 }
237
238 return Status;
239}
240
241static
247 IN SIZE_T InLength,
248 IN OUT PSIZE_T OutLength)
249{
251
252 PAGED_CODE();
253
254 switch (ControlCode)
255 {
257 {
259 {
261 }
262
263 break;
264 }
266 {
268 UNICODE_STRING PathW;
269
270 ok(Buffer != NULL, "Buffer is NULL\n");
271 Path.Length = Path.MaximumLength = (USHORT)InLength;
272 Path.Buffer = Buffer;
273
276
277 Status = TestIoCreateFile(&PathW);
278
279 RtlFreeUnicodeString(&PathW);
280
281 break;
282 }
283 default:
285 }
286
287 return Status;
288}
#define PAGED_CODE()
#define IOCTL_DISABLE_SYMLINK
Definition: IoCreateFile.h:12
#define IOCTL_CALL_CREATE
Definition: IoCreateFile.h:11
static PDEVICE_OBJECT TestDeviceObject
static PFILE_OBJECT TestFileObject
static volatile long gNoLinks
struct _TEST_FCB TEST_FCB
struct _TEST_FCB * PTEST_FCB
VOID TestUnload(_In_ PDRIVER_OBJECT DriverObject)
static KMT_MESSAGE_HANDLER TestMessageHandler
static UNICODE_STRING FileObjectFileName
NTSTATUS TestEntry(_In_ PDRIVER_OBJECT DriverObject, _In_ PCUNICODE_STRING RegistryPath, _Out_ PCWSTR *DeviceName, _Inout_ INT *Flags)
static NTSTATUS TestIoCreateFile(IN PUNICODE_STRING Path)
static KMT_IRP_HANDLER TestIrpHandler
static UNICODE_STRING DocumentsAndSettings
PRTL_UNICODE_STRING_BUFFER Path
#define ok_eq_hex(value, expected)
Definition: apitest.h:77
#define InterlockedExchange
Definition: armddk.h:54
#define ok(value,...)
Definition: atltest.h:57
LONG NTSTATUS
Definition: precomp.h:26
#define FILE_DIRECTORY_FILE
Definition: constants.h:491
_In_ PFCB Fcb
Definition: cdprocs.h:159
Definition: bufpool.h:45
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
Definition: conport.c:36
_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 NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define GENERIC_READ
Definition: compat.h:135
#define FILE_ATTRIBUTE_NORMAL
Definition: compat.h:137
#define FILE_SHARE_READ
Definition: compat.h:136
ULONG RtlCompareUnicodeString(PUNICODE_STRING s1, PUNICODE_STRING s2, BOOLEAN UpCase)
Definition: string_lib.cpp:31
#define KeWaitForSingleObject(pEvt, foo, a, b, c)
Definition: env_spec_w32.h:478
#define KeInitializeEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:477
#define NonPagedPool
Definition: env_spec_w32.h:307
#define FILE_OPEN
Definition: from_kernel.h:54
#define FILE_OPEN_REPARSE_POINT
Definition: from_kernel.h:46
#define FILE_SYNCHRONOUS_IO_ALERT
Definition: from_kernel.h:30
BOOLEAN NTAPI CcUninitializeCacheMap(IN PFILE_OBJECT FileObject, IN OPTIONAL PLARGE_INTEGER TruncateSize, IN OPTIONAL PCACHE_UNINITIALIZE_EVENT UninitializeEvent)
Definition: fssup.c:286
ULONG Handle
Definition: gdb_input.c:15
Status
Definition: gdiplustypes.h:25
#define OBJ_KERNEL_HANDLE
Definition: winternl.h:231
#define OBJ_CASE_INSENSITIVE
Definition: winternl.h:228
POBJECT_TYPE IoFileObjectType
Definition: iomgr.c:36
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)
if(dx< 0)
Definition: linetemp.h:194
#define ASSERT(a)
Definition: mode.c:44
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1109
static OUT PIO_STATUS_BLOCK IoStatusBlock
Definition: pipe.c:75
#define InitializeObjectAttributes(p, n, a, r, s)
Definition: reg.c:106
#define _Inout_
Definition: ms_sal.h:378
#define _Out_
Definition: ms_sal.h:345
#define _In_
Definition: ms_sal.h:308
#define KernelMode
Definition: asm.h:34
#define FILE_SHARE_WRITE
Definition: nt_native.h:681
#define FILE_READ_DATA
Definition: nt_native.h:628
NTSYSAPI NTSTATUS NTAPI RtlAnsiStringToUnicodeString(PUNICODE_STRING DestinationString, PANSI_STRING SourceString, BOOLEAN AllocateDestinationString)
NTSYSAPI VOID NTAPI RtlFreeUnicodeString(PUNICODE_STRING UnicodeString)
#define FILE_OPENED
Definition: nt_native.h:769
#define UNICODE_NULL
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:317
@ NotificationEvent
NTSTATUS NTAPI IoCreateFile(OUT PHANDLE FileHandle, IN ACCESS_MASK DesiredAccess, IN POBJECT_ATTRIBUTES ObjectAttributes, OUT PIO_STATUS_BLOCK IoStatusBlock, IN PLARGE_INTEGER AllocationSize OPTIONAL, IN ULONG FileAttributes, IN ULONG ShareAccess, IN ULONG Disposition, IN ULONG CreateOptions, IN PVOID EaBuffer OPTIONAL, IN ULONG EaLength, IN CREATE_FILE_TYPE CreateFileType, IN PVOID ExtraCreateParameters OPTIONAL, IN ULONG Options)
Definition: file.c:3010
#define IoCompleteRequest
Definition: irp.c:1240
#define STATUS_REPARSE
Definition: ntstatus.h:83
#define STATUS_NOT_SUPPORTED
Definition: ntstatus.h:423
#define STATUS_STOPPED_ON_SYMLINK
Definition: ntstatus.h:224
#define L(x)
Definition: ntvdm.h:50
NTSTATUS NTAPI ObCloseHandle(IN HANDLE Handle, IN KPROCESSOR_MODE AccessMode)
Definition: obhandle.c:3379
NTSTATUS NTAPI ObReferenceObjectByHandle(IN HANDLE Handle, IN ACCESS_MASK DesiredAccess, IN POBJECT_TYPE ObjectType, IN KPROCESSOR_MODE AccessMode, OUT PVOID *Object, OUT POBJECT_HANDLE_INFORMATION HandleInformation OPTIONAL)
Definition: obref.c:494
unsigned short USHORT
Definition: pedump.c:61
#define IRP_MJ_CREATE
Definition: rdpdr.c:44
#define STATUS_SUCCESS
Definition: shellext.h:65
struct _REPARSE_DATA_BUFFER * PREPARSE_DATA_BUFFER
#define DPRINT
Definition: sndvol32.h:73
PULONG MinorVersion OPTIONAL
Definition: CrossNt.h:68
SECTION_OBJECT_POINTERS SectionObjectPointers
Definition: ntfs.h:518
FSRTL_ADVANCED_FCB_HEADER Header
Definition: cdstruc.h:925
PFILE_OBJECT FileObject
Definition: ntfs.h:520
struct _REPARSE_DATA_BUFFER::@321::@323 SymbolicLinkReparseBuffer
struct _REPARSE_DATA_BUFFER::@321::@324 MountPointReparseBuffer
USHORT ReparseDataLength
Definition: shellext.h:166
SECTION_OBJECT_POINTERS SectionObjectPointers
FAST_MUTEX HeaderMutex
FSRTL_ADVANCED_FCB_HEADER Header
#define RTL_CONSTANT_STRING(s)
Definition: tunneltest.c:14
ULONG_PTR * PSIZE_T
Definition: typedefs.h:80
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 IN
Definition: typedefs.h:39
uint32_t ULONG
Definition: typedefs.h:59
#define OUT
Definition: typedefs.h:40
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
_In_ PDEVICE_OBJECT DeviceObject
Definition: wdfdevice.h:2055
_In_ WDFREQUEST _In_ WDFFILEOBJECT FileObject
Definition: wdfdevice.h:550
_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
FORCEINLINE VOID ExInitializeFastMutex(_Out_ PFAST_MUTEX FastMutex)
Definition: exfuncs.h:274
FAST_MUTEX
Definition: extypes.h:17
#define IO_NO_PARAMETER_CHECKING
Definition: iotypes.h:541
#define IO_NO_INCREMENT
Definition: iotypes.h:598
* PFILE_OBJECT
Definition: iotypes.h:1998
#define MAXIMUM_REPARSE_DATA_BUFFER_SIZE
Definition: iotypes.h:7213
#define SL_STOP_ON_SYMLINK
Definition: iotypes.h:1819
@ CreateFileTypeNone
Definition: iotypes.h:535
#define IO_STOP_ON_SYMLINK
Definition: iotypes.h:7353
#define IO_REPARSE_TAG_SYMLINK
Definition: iotypes.h:7240
#define IO_REPARSE_TAG_MOUNT_POINT
Definition: iotypes.h:7231
#define IRP_MJ_CLEANUP
@ Executive
Definition: ketypes.h:415
#define ObDereferenceObject
Definition: obfuncs.h:203
__wchar_t WCHAR
Definition: xmlstorage.h:180