2007-04-03 16:22:44 +00:00
|
|
|
/*
|
2018-04-22 20:13:52 +00:00
|
|
|
* PROJECT: ReactOS Kernel
|
|
|
|
* LICENSE: GPL-2.0+ (https://spdx.org/licenses/GPL-2.0+)
|
|
|
|
* PURPOSE: Null Device Driver
|
|
|
|
* COPYRIGHT: Copyright 1998-2018 David Welch (welch@mcmail.com)
|
|
|
|
* Copyright 2007-2018 Alex Ionescu (alex.ionescu@reactos.org)
|
1998-10-05 04:00:59 +00:00
|
|
|
*/
|
|
|
|
|
2007-04-03 16:22:44 +00:00
|
|
|
/* INCLUDES ******************************************************************/
|
|
|
|
|
2015-03-27 17:20:03 +00:00
|
|
|
#include <wdm.h>
|
2004-07-01 02:40:23 +00:00
|
|
|
|
2018-04-22 20:13:52 +00:00
|
|
|
/* GLOBALS *******************************************************************/
|
|
|
|
|
|
|
|
FAST_IO_DISPATCH FastIoDispatch;
|
|
|
|
|
2007-04-03 16:22:44 +00:00
|
|
|
/* FUNCTIONS *****************************************************************/
|
|
|
|
|
|
|
|
NTSTATUS
|
|
|
|
NTAPI
|
|
|
|
NullQueryFileInformation(OUT PVOID Buffer,
|
|
|
|
IN PULONG Length,
|
|
|
|
IN FILE_INFORMATION_CLASS InformationClass)
|
|
|
|
{
|
|
|
|
PFILE_STANDARD_INFORMATION StandardInfo = Buffer;
|
2018-04-22 20:13:52 +00:00
|
|
|
|
2007-04-03 16:22:44 +00:00
|
|
|
PAGED_CODE();
|
2004-07-01 02:40:23 +00:00
|
|
|
|
2007-04-03 16:22:44 +00:00
|
|
|
/* We only support one class */
|
|
|
|
if (InformationClass != FileStandardInformation)
|
|
|
|
{
|
|
|
|
/* Fail */
|
|
|
|
return STATUS_INVALID_INFO_CLASS;
|
|
|
|
}
|
1998-10-05 04:00:59 +00:00
|
|
|
|
2007-04-03 16:22:44 +00:00
|
|
|
/* Fill out the information */
|
|
|
|
RtlZeroMemory(StandardInfo, sizeof(FILE_STANDARD_INFORMATION));
|
|
|
|
StandardInfo->NumberOfLinks = 1;
|
1998-10-05 04:00:59 +00:00
|
|
|
|
2007-04-03 16:22:44 +00:00
|
|
|
/* Return the length and success */
|
|
|
|
*Length = sizeof(FILE_STANDARD_INFORMATION);
|
|
|
|
return STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
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)
|
1998-10-05 04:00:59 +00:00
|
|
|
{
|
2007-04-03 16:22:44 +00:00
|
|
|
PAGED_CODE();
|
2005-08-11 19:07:11 +00:00
|
|
|
|
2007-04-03 16:22:44 +00:00
|
|
|
/* Complete successfully */
|
|
|
|
IoStatus->Status = STATUS_END_OF_FILE;
|
|
|
|
IoStatus->Information = 0;
|
|
|
|
return TRUE;
|
|
|
|
}
|
2005-08-11 19:07:11 +00:00
|
|
|
|
2007-04-03 16:22:44 +00:00
|
|
|
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)
|
|
|
|
{
|
|
|
|
PAGED_CODE();
|
|
|
|
|
|
|
|
/* Complete successfully */
|
|
|
|
IoStatus->Status = STATUS_SUCCESS;
|
|
|
|
IoStatus->Information = Length;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
NTSTATUS
|
2008-11-30 11:16:55 +00:00
|
|
|
NTAPI
|
2007-04-03 16:22:44 +00:00
|
|
|
NullDispatch(IN PDEVICE_OBJECT DeviceObject,
|
|
|
|
IN PIRP Irp)
|
|
|
|
{
|
|
|
|
NTSTATUS Status;
|
2018-04-22 20:13:52 +00:00
|
|
|
PIO_STACK_LOCATION IoStack = IoGetCurrentIrpStackLocation(Irp);
|
2007-04-03 16:22:44 +00:00
|
|
|
PFILE_OBJECT FileObject;
|
|
|
|
ULONG Length;
|
2018-04-22 20:13:52 +00:00
|
|
|
|
2007-04-03 16:22:44 +00:00
|
|
|
PAGED_CODE();
|
|
|
|
|
|
|
|
/* Get the file object and check what kind of request this is */
|
|
|
|
FileObject = IoStack->FileObject;
|
|
|
|
switch (IoStack->MajorFunction)
|
2005-08-11 19:07:11 +00:00
|
|
|
{
|
|
|
|
case IRP_MJ_CREATE:
|
|
|
|
case IRP_MJ_CLOSE:
|
|
|
|
|
2007-04-03 16:22:44 +00:00
|
|
|
/* Check if this is synch I/O */
|
|
|
|
if (FileObject->Flags & FO_SYNCHRONOUS_IO)
|
|
|
|
{
|
|
|
|
/* Set distinguished value for Cc */
|
|
|
|
FileObject->PrivateCacheMap = (PVOID)1;
|
2005-08-11 19:07:11 +00:00
|
|
|
}
|
|
|
|
|
2007-04-03 16:22:44 +00:00
|
|
|
/* Complete successfully */
|
|
|
|
Irp->IoStatus.Status = STATUS_SUCCESS;
|
|
|
|
Irp->IoStatus.Information = 0;
|
2005-08-11 19:07:11 +00:00
|
|
|
break;
|
|
|
|
|
2007-04-03 16:22:44 +00:00
|
|
|
case IRP_MJ_READ:
|
2005-08-11 19:07:11 +00:00
|
|
|
|
2007-04-03 16:22:44 +00:00
|
|
|
/* Return as if we read the entire file */
|
|
|
|
Irp->IoStatus.Status = STATUS_END_OF_FILE;
|
|
|
|
Irp->IoStatus.Information = 0;
|
|
|
|
break;
|
2005-08-11 19:07:11 +00:00
|
|
|
|
2007-04-03 16:22:44 +00:00
|
|
|
case IRP_MJ_WRITE:
|
2005-08-11 19:07:11 +00:00
|
|
|
|
2007-04-03 16:22:44 +00:00
|
|
|
/* Return as if we wrote the entire request */
|
|
|
|
Irp->IoStatus.Status = STATUS_SUCCESS;
|
|
|
|
Irp->IoStatus.Information = IoStack->Parameters.Write.Length;
|
|
|
|
break;
|
2005-08-11 19:07:11 +00:00
|
|
|
|
2007-04-03 16:22:44 +00:00
|
|
|
case IRP_MJ_LOCK_CONTROL:
|
2005-08-11 19:07:11 +00:00
|
|
|
|
2007-04-03 16:22:44 +00:00
|
|
|
/* Dummy */
|
|
|
|
Irp->IoStatus.Status = STATUS_SUCCESS;
|
|
|
|
Irp->IoStatus.Information = 0;
|
2005-08-11 19:07:11 +00:00
|
|
|
break;
|
|
|
|
|
2007-04-03 16:22:44 +00:00
|
|
|
case IRP_MJ_QUERY_INFORMATION:
|
2005-08-11 19:07:11 +00:00
|
|
|
|
2007-04-03 16:22:44 +00:00
|
|
|
/* Get the length inputted and do the request */
|
|
|
|
Length = IoStack->Parameters.QueryFile.Length;
|
|
|
|
Irp->IoStatus.Status = NullQueryFileInformation(Irp->AssociatedIrp.
|
|
|
|
SystemBuffer,
|
|
|
|
&Length,
|
|
|
|
IoStack->
|
|
|
|
Parameters.
|
|
|
|
QueryFile.
|
|
|
|
FileInformationClass);
|
|
|
|
|
|
|
|
/* Return the actual length */
|
|
|
|
Irp->IoStatus.Information = Length;
|
|
|
|
break;
|
2005-08-11 19:07:11 +00:00
|
|
|
}
|
|
|
|
|
2007-04-03 16:22:44 +00:00
|
|
|
/* Complete the request */
|
|
|
|
Status = Irp->IoStatus.Status;
|
2005-08-11 19:07:11 +00:00
|
|
|
IoCompleteRequest(Irp, IO_NO_INCREMENT);
|
2007-04-03 16:22:44 +00:00
|
|
|
return Status;
|
1998-10-05 04:00:59 +00:00
|
|
|
}
|
|
|
|
|
2018-04-22 20:13:52 +00:00
|
|
|
VOID
|
|
|
|
NTAPI
|
|
|
|
NullUnload(IN PDRIVER_OBJECT DriverObject)
|
|
|
|
{
|
|
|
|
PDEVICE_OBJECT DeviceObject = DriverObject->DeviceObject;
|
|
|
|
|
|
|
|
/* Delete the Null device */
|
|
|
|
IoDeleteDevice(DeviceObject);
|
|
|
|
}
|
|
|
|
|
2007-04-03 16:22:44 +00:00
|
|
|
NTSTATUS
|
2008-11-30 11:16:55 +00:00
|
|
|
NTAPI
|
2007-04-03 16:22:44 +00:00
|
|
|
DriverEntry(IN PDRIVER_OBJECT DriverObject,
|
|
|
|
IN PUNICODE_STRING RegistryPath)
|
1998-10-05 04:00:59 +00:00
|
|
|
{
|
2018-04-22 20:13:52 +00:00
|
|
|
NTSTATUS Status;
|
2007-04-03 16:22:44 +00:00
|
|
|
PDEVICE_OBJECT DeviceObject;
|
|
|
|
UNICODE_STRING DeviceName = RTL_CONSTANT_STRING(L"\\Device\\Null");
|
2018-04-22 20:13:52 +00:00
|
|
|
|
2007-04-03 16:22:44 +00:00
|
|
|
PAGED_CODE();
|
|
|
|
|
2018-04-22 20:13:52 +00:00
|
|
|
UNREFERENCED_PARAMETER(RegistryPath);
|
|
|
|
|
2007-04-03 16:22:44 +00:00
|
|
|
/* Page the driver */
|
|
|
|
MmPageEntireDriver(DriverEntry);
|
|
|
|
|
2018-04-22 20:13:52 +00:00
|
|
|
/* Create the Null device */
|
2007-04-03 16:22:44 +00:00
|
|
|
Status = IoCreateDevice(DriverObject,
|
|
|
|
0,
|
|
|
|
&DeviceName,
|
|
|
|
FILE_DEVICE_NULL,
|
2019-03-27 01:23:21 +00:00
|
|
|
FILE_DEVICE_SECURE_OPEN,
|
2007-04-03 16:22:44 +00:00
|
|
|
FALSE,
|
|
|
|
&DeviceObject);
|
2018-04-22 20:13:52 +00:00
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
return Status;
|
2007-04-03 16:22:44 +00:00
|
|
|
|
|
|
|
/* Register driver routines */
|
2005-08-11 19:07:11 +00:00
|
|
|
DriverObject->MajorFunction[IRP_MJ_CLOSE] = NullDispatch;
|
|
|
|
DriverObject->MajorFunction[IRP_MJ_CREATE] = NullDispatch;
|
|
|
|
DriverObject->MajorFunction[IRP_MJ_WRITE] = NullDispatch;
|
|
|
|
DriverObject->MajorFunction[IRP_MJ_READ] = NullDispatch;
|
2007-04-03 16:22:44 +00:00
|
|
|
DriverObject->MajorFunction[IRP_MJ_LOCK_CONTROL] = NullDispatch;
|
|
|
|
DriverObject->MajorFunction[IRP_MJ_QUERY_INFORMATION] = NullDispatch;
|
2018-04-22 20:13:52 +00:00
|
|
|
DriverObject->DriverUnload = NullUnload;
|
2005-08-11 19:07:11 +00:00
|
|
|
|
2018-04-22 20:13:52 +00:00
|
|
|
/* Initialize the fast I/O dispatch table */
|
|
|
|
RtlZeroMemory(&FastIoDispatch, sizeof(FastIoDispatch));
|
|
|
|
FastIoDispatch.SizeOfFastIoDispatch = sizeof(FastIoDispatch);
|
2007-04-03 16:22:44 +00:00
|
|
|
|
|
|
|
/* Setup our pointers */
|
2018-04-22 20:13:52 +00:00
|
|
|
FastIoDispatch.FastIoRead = NullRead;
|
|
|
|
FastIoDispatch.FastIoWrite = NullWrite;
|
|
|
|
DriverObject->FastIoDispatch = &FastIoDispatch;
|
2005-08-11 19:07:11 +00:00
|
|
|
|
2007-04-03 16:22:44 +00:00
|
|
|
/* Return success */
|
|
|
|
return STATUS_SUCCESS;
|
1998-10-05 04:00:59 +00:00
|
|
|
}
|
|
|
|
|
2002-04-29 23:06:42 +00:00
|
|
|
/* EOF */
|