ReactOS 0.4.15-dev-7907-g95bf896
IoCreateFile_drv.c File Reference
#include <kmt_test.h>
#include <debug.h>
#include "IoCreateFile.h"
Include dependency graph for IoCreateFile_drv.c:

Go to the source code of this file.

Classes

struct  _TEST_FCB
 

Macros

#define NDEBUG
 

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)
 
static NTSTATUS TestIrpHandler (_In_ PDEVICE_OBJECT DeviceObject, _In_ PIRP Irp, _In_ PIO_STACK_LOCATION IoStack)
 
static NTSTATUS TestIoCreateFile (IN PUNICODE_STRING Path)
 
static NTSTATUS TestMessageHandler (IN PDEVICE_OBJECT DeviceObject, IN ULONG ControlCode, IN PVOID Buffer OPTIONAL, IN SIZE_T InLength, IN OUT PSIZE_T OutLength)
 

Variables

static KMT_IRP_HANDLER TestIrpHandler
 
static KMT_MESSAGE_HANDLER TestMessageHandler
 
static PFILE_OBJECT TestFileObject
 
static PDEVICE_OBJECT TestDeviceObject
 
static volatile long gNoLinks = FALSE
 
static UNICODE_STRING FileObjectFileName = RTL_CONSTANT_STRING(L"\\NonSymlinked")
 
static UNICODE_STRING DocumentsAndSettings = RTL_CONSTANT_STRING(L"\\Documents and Settings")
 

Macro Definition Documentation

◆ NDEBUG

#define NDEBUG

Definition at line 10 of file IoCreateFile_drv.c.

Typedef Documentation

◆ PTEST_FCB

◆ TEST_FCB

Function Documentation

◆ TestEntry()

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

Definition at line 29 of file IoCreateFile_drv.c.

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}
#define PAGED_CODE()
static KMT_MESSAGE_HANDLER TestMessageHandler
static KMT_IRP_HANDLER TestIrpHandler
LONG NTSTATUS
Definition: precomp.h:26
#define NULL
Definition: types.h:112
Status
Definition: gdiplustypes.h:25
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 UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:317
#define L(x)
Definition: ntvdm.h:50
#define IRP_MJ_CREATE
Definition: rdpdr.c:44
#define STATUS_SUCCESS
Definition: shellext.h:65
_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_ ULONG Flags
Definition: wsk.h:170
#define IRP_MJ_CLEANUP

◆ TestIoCreateFile()

static NTSTATUS TestIoCreateFile ( IN PUNICODE_STRING  Path)
static

Definition at line 187 of file IoCreateFile_drv.c.

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}
static volatile long gNoLinks
static UNICODE_STRING FileObjectFileName
static UNICODE_STRING DocumentsAndSettings
PRTL_UNICODE_STRING_BUFFER Path
#define ok_eq_hex(value, expected)
Definition: apitest.h:77
#define ok(value,...)
Definition: atltest.h:57
#define FILE_DIRECTORY_FILE
Definition: constants.h:491
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
Definition: conport.c:36
#define TRUE
Definition: types.h:120
#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 FILE_OPEN
Definition: from_kernel.h:54
#define FILE_SYNCHRONOUS_IO_ALERT
Definition: from_kernel.h:30
ULONG Handle
Definition: gdb_input.c:15
#define OBJ_KERNEL_HANDLE
Definition: winternl.h:231
#define OBJ_CASE_INSENSITIVE
Definition: winternl.h:228
POBJECT_TYPE IoFileObjectType
Definition: iomgr.c:36
static OUT PIO_STATUS_BLOCK IoStatusBlock
Definition: pipe.c:75
#define InitializeObjectAttributes(p, n, a, r, s)
Definition: reg.c:106
#define KernelMode
Definition: asm.h:34
#define FILE_SHARE_WRITE
Definition: nt_native.h:681
#define FILE_READ_DATA
Definition: nt_native.h:628
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
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
_In_ WDFREQUEST _In_ WDFFILEOBJECT FileObject
Definition: wdfdevice.h:550
#define IO_NO_PARAMETER_CHECKING
Definition: iotypes.h:541
* PFILE_OBJECT
Definition: iotypes.h:1998
@ CreateFileTypeNone
Definition: iotypes.h:535
#define IO_STOP_ON_SYMLINK
Definition: iotypes.h:7353
#define ObDereferenceObject
Definition: obfuncs.h:203

Referenced by TestMessageHandler().

◆ TestIrpHandler()

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

Definition at line 64 of file IoCreateFile_drv.c.

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}
static PDEVICE_OBJECT TestDeviceObject
static PFILE_OBJECT TestFileObject
_In_ PFCB Fcb
Definition: cdprocs.h:159
_In_ PIRP Irp
Definition: csq.h:116
#define FALSE
Definition: types.h:117
#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_REPARSE_POINT
Definition: from_kernel.h:46
BOOLEAN NTAPI CcUninitializeCacheMap(IN PFILE_OBJECT FileObject, IN OPTIONAL PLARGE_INTEGER TruncateSize, IN OPTIONAL PCACHE_UNINITIALIZE_EVENT UninitializeEvent)
Definition: fssup.c:286
if(dx< 0)
Definition: linetemp.h:194
#define ASSERT(a)
Definition: mode.c:44
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1109
#define FILE_OPENED
Definition: nt_native.h:769
#define UNICODE_NULL
@ NotificationEvent
#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
struct _REPARSE_DATA_BUFFER * PREPARSE_DATA_BUFFER
#define DPRINT
Definition: sndvol32.h:71
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::@318::@321 MountPointReparseBuffer
struct _REPARSE_DATA_BUFFER::@318::@320 SymbolicLinkReparseBuffer
USHORT ReparseDataLength
Definition: shellext.h:166
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
_In_ PDEVICE_OBJECT DeviceObject
Definition: wdfdevice.h:2055
FORCEINLINE VOID ExInitializeFastMutex(_Out_ PFAST_MUTEX FastMutex)
Definition: exfuncs.h:274
#define IO_NO_INCREMENT
Definition: iotypes.h:598
#define MAXIMUM_REPARSE_DATA_BUFFER_SIZE
Definition: iotypes.h:7213
#define SL_STOP_ON_SYMLINK
Definition: iotypes.h:1819
#define IO_REPARSE_TAG_SYMLINK
Definition: iotypes.h:7240
#define IO_REPARSE_TAG_MOUNT_POINT
Definition: iotypes.h:7231
@ Executive
Definition: ketypes.h:415
__wchar_t WCHAR
Definition: xmlstorage.h:180

◆ TestMessageHandler()

static NTSTATUS TestMessageHandler ( IN PDEVICE_OBJECT  DeviceObject,
IN ULONG  ControlCode,
IN PVOID Buffer  OPTIONAL,
IN SIZE_T  InLength,
IN OUT PSIZE_T  OutLength 
)
static

Definition at line 243 of file IoCreateFile_drv.c.

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 IOCTL_DISABLE_SYMLINK
Definition: IoCreateFile.h:12
#define IOCTL_CALL_CREATE
Definition: IoCreateFile.h:11
static NTSTATUS TestIoCreateFile(IN PUNICODE_STRING Path)
#define InterlockedExchange
Definition: armddk.h:54
Definition: bufpool.h:45
NTSYSAPI NTSTATUS NTAPI RtlAnsiStringToUnicodeString(PUNICODE_STRING DestinationString, PANSI_STRING SourceString, BOOLEAN AllocateDestinationString)
NTSYSAPI VOID NTAPI RtlFreeUnicodeString(PUNICODE_STRING UnicodeString)
unsigned short USHORT
Definition: pedump.c:61
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
_IRQL_requires_same_ typedef _In_ ULONG ControlCode
Definition: wmitypes.h:55

◆ TestUnload()

VOID TestUnload ( _In_ PDRIVER_OBJECT  DriverObject)

Definition at line 54 of file IoCreateFile_drv.c.

56{
57 PAGED_CODE();
58}

Variable Documentation

◆ DocumentsAndSettings

UNICODE_STRING DocumentsAndSettings = RTL_CONSTANT_STRING(L"\\Documents and Settings")
static

Definition at line 183 of file IoCreateFile_drv.c.

Referenced by TestIoCreateFile().

◆ FileObjectFileName

UNICODE_STRING FileObjectFileName = RTL_CONSTANT_STRING(L"\\NonSymlinked")
static

Definition at line 182 of file IoCreateFile_drv.c.

Referenced by TestIoCreateFile().

◆ gNoLinks

volatile long gNoLinks = FALSE
static

Definition at line 60 of file IoCreateFile_drv.c.

Referenced by TestIoCreateFile(), TestIrpHandler(), and TestMessageHandler().

◆ TestDeviceObject

PDEVICE_OBJECT TestDeviceObject
static

Definition at line 26 of file IoCreateFile_drv.c.

Referenced by TestIrpHandler().

◆ TestFileObject

PFILE_OBJECT TestFileObject
static

Definition at line 25 of file IoCreateFile_drv.c.

Referenced by TestIrpHandler().

◆ TestIrpHandler

KMT_IRP_HANDLER TestIrpHandler
static

Definition at line 22 of file IoCreateFile_drv.c.

Referenced by TestEntry().

◆ TestMessageHandler

KMT_MESSAGE_HANDLER TestMessageHandler
static

Definition at line 23 of file IoCreateFile_drv.c.

Referenced by TestEntry().