ReactOS  0.4.13-dev-52-g0efcfec
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 
20 NTAPI
24 {
25  PFILE_STANDARD_INFORMATION StandardInfo = Buffer;
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 
45 BOOLEAN
46 NTAPI
49  IN ULONG Length,
50  IN BOOLEAN Wait,
55 {
56  PAGED_CODE();
57 
58  /* Complete successfully */
59  IoStatus->Status = STATUS_END_OF_FILE;
60  IoStatus->Information = 0;
61  return TRUE;
62 }
63 
64 BOOLEAN
65 NTAPI
68  IN ULONG Length,
69  IN BOOLEAN Wait,
71  IN PVOID Buffer,
74 {
75  PAGED_CODE();
76 
77  /* Complete successfully */
78  IoStatus->Status = STATUS_SUCCESS;
79  IoStatus->Information = Length;
80  return TRUE;
81 }
82 
84 NTAPI
86  IN PIRP Irp)
87 {
91  ULONG Length;
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 
128  case IRP_MJ_LOCK_CONTROL:
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->
143  Parameters.
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 
158 VOID
159 NTAPI
161 {
163 
164  /* Delete the Null device */
166 }
167 
168 NTSTATUS
169 NTAPI
172 {
175  UNICODE_STRING DeviceName = RTL_CONSTANT_STRING(L"\\Device\\Null");
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 */
203 
204  /* Initialize the fast I/O dispatch table */
207 
208  /* Setup our pointers */
212 
213  /* Return success */
214  return STATUS_SUCCESS;
215 }
216 
217 /* EOF */
#define IN
Definition: typedefs.h:38
#define TRUE
Definition: types.h:120
#define IRP_MJ_CREATE
Definition: rdpdr.c:44
IN PLARGE_INTEGER IN ULONG IN BOOLEAN IN ULONG IN BOOLEAN OUT PIO_STATUS_BLOCK IoStatus
Definition: fatprocs.h:2650
_In_ PIRP Irp
Definition: csq.h:116
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:323
LONG NTSTATUS
Definition: precomp.h:26
NTSTATUS NTAPI NullQueryFileInformation(OUT PVOID Buffer, IN PULONG Length, IN FILE_INFORMATION_CLASS InformationClass)
Definition: null.c:21
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
static OUT PIO_STATUS_BLOCK OUT PVOID IN ULONG IN FILE_INFORMATION_CLASS FileInformationClass
Definition: pipe.c:75
NTSTATUS NTAPI NullDispatch(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: null.c:85
WCHAR DeviceName[]
Definition: adapter.cpp:21
#define FILE_DEVICE_NULL
Definition: winioctl.h:126
#define PAGED_CODE()
Definition: video.h:57
#define STATUS_END_OF_FILE
Definition: shellext.h:62
#define FO_SYNCHRONOUS_IO
Definition: iotypes.h:1732
NTSTATUS(* NTAPI)(IN PFILE_FULL_EA_INFORMATION EaBuffer, IN ULONG EaLength, OUT PULONG ErrorOffset)
Definition: IoEaTest.cpp:117
unsigned char BOOLEAN
static PDRIVER_OBJECT DriverObject
Definition: template.c:42
#define IoCompleteRequest
Definition: irp.c:1240
Definition: bufpool.h:45
void * PVOID
Definition: retypes.h:9
_Inout_ PFILE_OBJECT FileObject
Definition: cdprocs.h:593
NTSTATUS NTAPI DriverEntry(IN PDRIVER_OBJECT DriverObject, IN PUNICODE_STRING RegistryPath)
Definition: null.c:170
IN PLARGE_INTEGER IN ULONG IN BOOLEAN IN ULONG LockKey
Definition: fatprocs.h:2650
enum _FILE_INFORMATION_CLASS FILE_INFORMATION_CLASS
Definition: directory.c:44
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
PVOID NTAPI MmPageEntireDriver(IN PVOID AddressWithinSection)
Definition: sysldr.c:3320
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
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
* PFILE_OBJECT
Definition: iotypes.h:1954
#define IRP_MJ_CLOSE
Definition: rdpdr.c:45
_In_ PPCI_DEVICE_PRESENCE_PARAMETERS Parameters
Definition: iotypes.h:871
#define STATUS_INVALID_INFO_CLASS
Definition: ntstatus.h:226
static const WCHAR L[]
Definition: oid.c:1250
PDRIVER_UNLOAD DriverUnload
Definition: iotypes.h:2179
#define FILE_STANDARD_INFORMATION
Definition: disk.h:54
Status
Definition: gdiplustypes.h:24
PFAST_IO_READ FastIoRead
Definition: iotypes.h:1691
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2745
VOID NTAPI IoDeleteDevice(IN PDEVICE_OBJECT DeviceObject)
Definition: device.c:1250
PFILE_OBJECT FileObject
Definition: iotypes.h:2812
PFAST_IO_WRITE FastIoWrite
Definition: iotypes.h:1692
_In_ PFCB _In_ LONGLONG FileOffset
Definition: cdprocs.h:151
unsigned int * PULONG
Definition: retypes.h:1
FAST_IO_DISPATCH FastIoDispatch
Definition: null.c:15
#define IRP_MJ_LOCK_CONTROL
Definition: rdpdr.c:53
#define FileStandardInformation
Definition: propsheet.cpp:61
#define IRP_MJ_READ
Definition: rdpdr.c:46
struct _FAST_IO_DISPATCH * FastIoDispatch
Definition: iotypes.h:2176
#define OUT
Definition: typedefs.h:39
PDRIVER_DISPATCH MajorFunction[IRP_MJ_MAXIMUM_FUNCTION+1]
Definition: iotypes.h:2180
unsigned int ULONG
Definition: retypes.h:1
#define IO_NO_INCREMENT
Definition: iotypes.h:565
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
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:261
_In_ PUNICODE_STRING RegistryPath
Definition: wmip.h:27
#define IRP_MJ_WRITE
Definition: rdpdr.c:47
#define IRP_MJ_QUERY_INFORMATION
Definition: rdpdr.c:48
#define FILE_DEVICE_SECURE_OPEN
Definition: cdrw_usr.h:46
_In_ FILTER_INFORMATION_CLASS InformationClass
Definition: fltkernel.h:1714
struct _NAMED_PIPE_CREATE_PARAMETERS * Parameters
Definition: iotypes.h:2771
IN BOOLEAN OUT PSTR Buffer
Definition: progress.h:34
return STATUS_SUCCESS
Definition: btrfs.c:2725
VOID NTAPI NullUnload(IN PDRIVER_OBJECT DriverObject)
Definition: null.c:160
PDEVICE_OBJECT DeviceObject
Definition: iotypes.h:2168
ULONG SizeOfFastIoDispatch
Definition: iotypes.h:1689
IN BOOLEAN Wait
Definition: fatprocs.h:1529
#define RTL_CONSTANT_STRING(s)
Definition: tunneltest.c:14