ReactOS 0.4.16-dev-297-gc569aee
null.c
Go to the documentation of this file.
1/*
2 * PROJECT: ReactOS Kernel
3 * LICENSE: GPL-2.0+ (https://spdx.org/licenses/GPL-2.0+)
4 * PURPOSE: Null Device Driver
5 * COPYRIGHT: Copyright 1998-2018 David Welch (welch@mcmail.com)
6 * Copyright 2007-2018 Alex Ionescu (alex.ionescu@reactos.org)
7 */
8
9/* INCLUDES ******************************************************************/
10
11#include <wdm.h>
12
13/* GLOBALS *******************************************************************/
14
16
17/* FUNCTIONS *****************************************************************/
18
24{
26
27 PAGED_CODE();
28
29 /* We only support one class */
31 {
32 /* Fail */
34 }
35
36 /* Fill out the information */
37 RtlZeroMemory(StandardInfo, sizeof(FILE_STANDARD_INFORMATION));
38 StandardInfo->NumberOfLinks = 1;
39
40 /* Return the length and success */
42 return STATUS_SUCCESS;
43}
44
55{
56 PAGED_CODE();
57
58 /* Complete successfully */
60 IoStatus->Information = 0;
61 return TRUE;
62}
63
74{
75 PAGED_CODE();
76
77 /* Complete successfully */
78 IoStatus->Status = STATUS_SUCCESS;
79 IoStatus->Information = Length;
80 return TRUE;
81}
82
86 IN PIRP Irp)
87{
92
93 PAGED_CODE();
94
95 /* Get the file object and check what kind of request this is */
96 FileObject = IoStack->FileObject;
97 switch (IoStack->MajorFunction)
98 {
99 case IRP_MJ_CREATE:
100 case IRP_MJ_CLOSE:
101
102 /* Check if this is synch I/O */
103 if (FileObject->Flags & FO_SYNCHRONOUS_IO)
104 {
105 /* Set distinguished value for Cc */
106 FileObject->PrivateCacheMap = (PVOID)1;
107 }
108
109 /* Complete successfully */
110 Irp->IoStatus.Status = STATUS_SUCCESS;
111 Irp->IoStatus.Information = 0;
112 break;
113
114 case IRP_MJ_READ:
115
116 /* Return as if we read the entire file */
117 Irp->IoStatus.Status = STATUS_END_OF_FILE;
118 Irp->IoStatus.Information = 0;
119 break;
120
121 case IRP_MJ_WRITE:
122
123 /* Return as if we wrote the entire request */
124 Irp->IoStatus.Status = STATUS_SUCCESS;
125 Irp->IoStatus.Information = IoStack->Parameters.Write.Length;
126 break;
127
129
130 /* Dummy */
131 Irp->IoStatus.Status = STATUS_SUCCESS;
132 Irp->IoStatus.Information = 0;
133 break;
134
136
137 /* Get the length inputted and do the request */
138 Length = IoStack->Parameters.QueryFile.Length;
139 Irp->IoStatus.Status = NullQueryFileInformation(Irp->AssociatedIrp.
140 SystemBuffer,
141 &Length,
142 IoStack->
144 QueryFile.
146
147 /* Return the actual length */
148 Irp->IoStatus.Information = Length;
149 break;
150 }
151
152 /* Complete the request */
153 Status = Irp->IoStatus.Status;
155 return Status;
156}
157
158VOID
159NTAPI
161{
163
164 /* Delete the Null device */
166}
167
169NTAPI
172{
176
177 PAGED_CODE();
178
180
181 /* Page the driver */
183
184 /* Create the Null device */
186 0,
187 &DeviceName,
190 FALSE,
191 &DeviceObject);
192 if (!NT_SUCCESS(Status))
193 return Status;
194
195 /* Register driver routines */
196 DriverObject->MajorFunction[IRP_MJ_CLOSE] = NullDispatch;
197 DriverObject->MajorFunction[IRP_MJ_CREATE] = NullDispatch;
198 DriverObject->MajorFunction[IRP_MJ_WRITE] = NullDispatch;
199 DriverObject->MajorFunction[IRP_MJ_READ] = NullDispatch;
202 DriverObject->DriverUnload = NullUnload;
203
204 /* Initialize the fast I/O dispatch table */
207
208 /* Setup our pointers */
211 DriverObject->FastIoDispatch = &FastIoDispatch;
212
213 /* Return success */
214 return STATUS_SUCCESS;
215}
216
217/* EOF */
static PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(PIRP Irp)
#define PAGED_CODE()
unsigned char BOOLEAN
LONG NTSTATUS
Definition: precomp.h:26
_In_ PFCB _In_ LONGLONG FileOffset
Definition: cdprocs.h:160
#define FILE_DEVICE_SECURE_OPEN
Definition: cdrw_usr.h:46
Definition: bufpool.h:45
_In_ PIRP Irp
Definition: csq.h:116
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:33
DRIVER_INITIALIZE DriverEntry
Definition: condrv.c:21
IN PLARGE_INTEGER IN ULONG IN BOOLEAN IN ULONG LockKey
Definition: fatprocs.h:2666
_In_ FILTER_INFORMATION_CLASS InformationClass
Definition: fltkernel.h:1713
enum _FILE_INFORMATION_CLASS FILE_INFORMATION_CLASS
Definition: directory.c:44
Status
Definition: gdiplustypes.h:25
#define FILE_STANDARD_INFORMATION
Definition: disk.h:54
static OUT PIO_STATUS_BLOCK OUT PVOID IN ULONG IN FILE_INFORMATION_CLASS FileInformationClass
Definition: pipe.c:75
__in UCHAR __in POWER_STATE __in_opt PVOID __in PIO_STATUS_BLOCK IoStatus
Definition: mxum.h:159
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:325
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:102
NTSTATUS NTAPI IoCreateDevice(IN PDRIVER_OBJECT DriverObject, IN ULONG DeviceExtensionSize, IN PUNICODE_STRING DeviceName, IN DEVICE_TYPE DeviceType, IN ULONG DeviceCharacteristics, IN BOOLEAN Exclusive, OUT PDEVICE_OBJECT *DeviceObject)
Definition: device.c:1031
VOID NTAPI IoDeleteDevice(IN PDEVICE_OBJECT DeviceObject)
Definition: device.c:1251
#define IoCompleteRequest
Definition: irp.c:1240
#define STATUS_INVALID_INFO_CLASS
Definition: ntstatus.h:240
#define L(x)
Definition: ntvdm.h:50
BOOLEAN NTAPI NullRead(IN PFILE_OBJECT FileObject, IN PLARGE_INTEGER FileOffset, IN ULONG Length, IN BOOLEAN Wait, IN ULONG LockKey, OUT PVOID Buffer, OUT PIO_STATUS_BLOCK IoStatus, IN PDEVICE_OBJECT DeviceObject)
Definition: null.c:47
VOID NTAPI NullUnload(IN PDRIVER_OBJECT DriverObject)
Definition: null.c:160
BOOLEAN NTAPI NullWrite(IN PFILE_OBJECT FileObject, IN PLARGE_INTEGER FileOffset, IN ULONG Length, IN BOOLEAN Wait, IN ULONG LockKey, IN PVOID Buffer, OUT PIO_STATUS_BLOCK IoStatus, IN PDEVICE_OBJECT DeviceObject)
Definition: null.c:66
FAST_IO_DISPATCH FastIoDispatch
Definition: null.c:15
NTSTATUS NTAPI NullQueryFileInformation(OUT PVOID Buffer, IN PULONG Length, IN FILE_INFORMATION_CLASS InformationClass)
Definition: null.c:21
NTSTATUS NTAPI NullDispatch(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: null.c:85
#define FileStandardInformation
Definition: propsheet.cpp:61
#define FILE_DEVICE_NULL
Definition: winioctl.h:66
#define IRP_MJ_CLOSE
Definition: rdpdr.c:45
#define IRP_MJ_READ
Definition: rdpdr.c:46
#define IRP_MJ_LOCK_CONTROL
Definition: rdpdr.c:53
#define IRP_MJ_WRITE
Definition: rdpdr.c:47
#define IRP_MJ_CREATE
Definition: rdpdr.c:44
#define IRP_MJ_QUERY_INFORMATION
Definition: rdpdr.c:48
#define STATUS_END_OF_FILE
Definition: shellext.h:67
#define STATUS_SUCCESS
Definition: shellext.h:65
PFAST_IO_WRITE FastIoWrite
Definition: iotypes.h:1736
ULONG SizeOfFastIoDispatch
Definition: iotypes.h:1733
PFAST_IO_READ FastIoRead
Definition: iotypes.h:1735
PFILE_OBJECT FileObject
Definition: iotypes.h:3169
union _IO_STACK_LOCATION::@1579 Parameters
struct _IO_STACK_LOCATION::@3978::@3983 Write
struct _IO_STACK_LOCATION::@3978::@3987 QueryFile
PVOID NTAPI MmPageEntireDriver(IN PVOID AddressWithinSection)
Definition: sysldr.c:3557
#define RTL_CONSTANT_STRING(s)
Definition: tunneltest.c:14
uint32_t * PULONG
Definition: typedefs.h:59
#define NTAPI
Definition: typedefs.h:36
void * PVOID
Definition: typedefs.h:50
#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
_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
_In_ WDFDPC _In_ BOOLEAN Wait
Definition: wdfdpc.h:170
_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
_Must_inspect_result_ _In_ WDFQUEUE _In_opt_ WDFREQUEST _In_opt_ WDFFILEOBJECT _Inout_opt_ PWDF_REQUEST_PARAMETERS Parameters
Definition: wdfio.h:869
#define IO_NO_INCREMENT
Definition: iotypes.h:598
* PFILE_OBJECT
Definition: iotypes.h:1998
#define FO_SYNCHRONOUS_IO
Definition: iotypes.h:1776