2 * PROJECT: ReactOS Kernel
3 * LICENSE: GPL - See COPYING in the top level directory
4 * FILE: drivers/base/null/null.c
5 * PURPOSE: Null Device Driver
6 * PROGRAMMERS: Alex Ionescu (alex.ionescu@reactos.org)
7 * David Welch (welch@mcmail.com)
10 /* INCLUDES ******************************************************************/
14 /* FUNCTIONS *****************************************************************/
18 NullQueryFileInformation(OUT PVOID Buffer
,
20 IN FILE_INFORMATION_CLASS InformationClass
)
22 PFILE_STANDARD_INFORMATION StandardInfo
= Buffer
;
25 /* We only support one class */
26 if (InformationClass
!= FileStandardInformation
)
29 return STATUS_INVALID_INFO_CLASS
;
32 /* Fill out the information */
33 RtlZeroMemory(StandardInfo
, sizeof(FILE_STANDARD_INFORMATION
));
34 StandardInfo
->NumberOfLinks
= 1;
36 /* Return the length and success */
37 *Length
= sizeof(FILE_STANDARD_INFORMATION
);
38 return STATUS_SUCCESS
;
43 NullRead(IN PFILE_OBJECT FileObject
,
44 IN PLARGE_INTEGER FileOffset
,
49 OUT PIO_STATUS_BLOCK IoStatus
,
50 IN PDEVICE_OBJECT DeviceObject
)
54 /* Complete successfully */
55 IoStatus
->Status
= STATUS_END_OF_FILE
;
56 IoStatus
->Information
= 0;
62 NullWrite(IN PFILE_OBJECT FileObject
,
63 IN PLARGE_INTEGER FileOffset
,
68 OUT PIO_STATUS_BLOCK IoStatus
,
69 IN PDEVICE_OBJECT DeviceObject
)
73 /* Complete successfully */
74 IoStatus
->Status
= STATUS_SUCCESS
;
75 IoStatus
->Information
= Length
;
81 NullDispatch(IN PDEVICE_OBJECT DeviceObject
,
84 PIO_STACK_LOCATION IoStack
= IoGetCurrentIrpStackLocation(Irp
);
86 PFILE_OBJECT FileObject
;
90 /* Get the file object and check what kind of request this is */
91 FileObject
= IoStack
->FileObject
;
92 switch (IoStack
->MajorFunction
)
97 /* Check if this is synch I/O */
98 if (FileObject
->Flags
& FO_SYNCHRONOUS_IO
)
100 /* Set distinguished value for Cc */
101 FileObject
->PrivateCacheMap
= (PVOID
)1;
104 /* Complete successfully */
105 Irp
->IoStatus
.Status
= STATUS_SUCCESS
;
106 Irp
->IoStatus
.Information
= 0;
111 /* Return as if we read the entire file */
112 Irp
->IoStatus
.Status
= STATUS_END_OF_FILE
;
113 Irp
->IoStatus
.Information
= 0;
118 /* Return as if we wrote the entire request */
119 Irp
->IoStatus
.Status
= STATUS_SUCCESS
;
120 Irp
->IoStatus
.Information
= IoStack
->Parameters
.Write
.Length
;
123 case IRP_MJ_LOCK_CONTROL
:
126 Irp
->IoStatus
.Status
= STATUS_SUCCESS
;
127 Irp
->IoStatus
.Information
= 0;
130 case IRP_MJ_QUERY_INFORMATION
:
132 /* Get the length inputted and do the request */
133 Length
= IoStack
->Parameters
.QueryFile
.Length
;
134 Irp
->IoStatus
.Status
= NullQueryFileInformation(Irp
->AssociatedIrp
.
140 FileInformationClass
);
142 /* Return the actual length */
143 Irp
->IoStatus
.Information
= Length
;
147 /* Complete the request */
148 Status
= Irp
->IoStatus
.Status
;
149 IoCompleteRequest(Irp
, IO_NO_INCREMENT
);
155 DriverEntry(IN PDRIVER_OBJECT DriverObject
,
156 IN PUNICODE_STRING RegistryPath
)
158 PDEVICE_OBJECT DeviceObject
;
159 UNICODE_STRING DeviceName
= RTL_CONSTANT_STRING(L
"\\Device\\Null");
161 PFAST_IO_DISPATCH FastIoDispatch
;
164 /* Page the driver */
165 MmPageEntireDriver(DriverEntry
);
167 /* Create null device */
168 Status
= IoCreateDevice(DriverObject
,
175 if (!NT_SUCCESS(Status
)) return Status
;
177 /* Register driver routines */
178 DriverObject
->MajorFunction
[IRP_MJ_CLOSE
] = NullDispatch
;
179 DriverObject
->MajorFunction
[IRP_MJ_CREATE
] = NullDispatch
;
180 DriverObject
->MajorFunction
[IRP_MJ_WRITE
] = NullDispatch
;
181 DriverObject
->MajorFunction
[IRP_MJ_READ
] = NullDispatch
;
182 DriverObject
->MajorFunction
[IRP_MJ_LOCK_CONTROL
] = NullDispatch
;
183 DriverObject
->MajorFunction
[IRP_MJ_QUERY_INFORMATION
] = NullDispatch
;
185 /* Allocate the fast I/O dispatch table */
186 FastIoDispatch
= ExAllocatePool(NonPagedPool
, sizeof(FAST_IO_DISPATCH
));
189 /* Failed, cleanup */
190 IoDeleteDevice(DeviceObject
);
191 return STATUS_INSUFFICIENT_RESOURCES
;
195 RtlZeroMemory(FastIoDispatch
, sizeof(FAST_IO_DISPATCH
));
196 FastIoDispatch
->SizeOfFastIoDispatch
= sizeof(FAST_IO_DISPATCH
);
198 /* Setup our pointers */
199 FastIoDispatch
->FastIoRead
= NullRead
;
200 FastIoDispatch
->FastIoWrite
= NullWrite
;
201 DriverObject
->FastIoDispatch
= FastIoDispatch
;
204 return STATUS_SUCCESS
;