Fixed bugs in null device drivers, added zero stream device

svn path=/trunk/; revision=2897
This commit is contained in:
KJK::Hyperion 2002-04-29 23:06:42 +00:00
parent bceb83614d
commit 488ec274f1
3 changed files with 159 additions and 79 deletions

View file

@ -1,4 +1,4 @@
# $Id: makefile,v 1.14 2001/08/21 20:13:11 chorns Exp $ # $Id: makefile,v 1.15 2002/04/29 23:06:42 hyperion Exp $
PATH_TO_TOP = ../../.. PATH_TO_TOP = ../../..
@ -8,6 +8,8 @@ TARGET_NAME = null
TARGET_OBJECTS = null.o TARGET_OBJECTS = null.o
TARGET_LFLAGS = -Wl,--file-alignment,0x20 -Wl,--section-alignment,0x20
include $(PATH_TO_TOP)/rules.mak include $(PATH_TO_TOP)/rules.mak
include $(TOOLS_PATH)/helper.mk include $(TOOLS_PATH)/helper.mk

View file

@ -1,4 +1,4 @@
/* $Id: null.c,v 1.6 2002/02/08 02:57:08 chorns Exp $ /* $Id: null.c,v 1.7 2002/04/29 23:06:42 hyperion Exp $
* *
* COPYRIGHT: See COPYING in the top level directory * COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel * PROJECT: ReactOS kernel
@ -6,62 +6,88 @@
* PURPOSE: NULL device driver * PURPOSE: NULL device driver
* PROGRAMMER: David Welch (welch@mcmail.com) * PROGRAMMER: David Welch (welch@mcmail.com)
* UPDATE HISTORY: * UPDATE HISTORY:
* 13/08/98: Created * 13/08/1998: Created
* 29/04/2002: Fixed bugs, added zero-stream device
*/ */
/* INCLUDES ****************************************************************/ /* INCLUDES */
#include <ddk/ntddk.h> #include <ddk/ntddk.h>
#include "null.h"
/* FUNCTIONS **************************************************************/ /* OBJECTS */
static const NULL_EXTENSION nxNull = NullBitBucket;
NTSTATUS NullWrite(PIRP Irp, PIO_STACK_LOCATION stk) static const NULL_EXTENSION nxZero = NullZeroStream;
{
Irp->IoStatus.Information = stk->Parameters.Write.Length;
return(STATUS_SUCCESS);
}
NTSTATUS NullRead(PIRP Irp, PIO_STACK_LOCATION stk)
{
Irp->IoStatus.Information = 0;
return(STATUS_END_OF_FILE);
}
/* FUNCTIONS */
NTSTATUS STDCALL NTSTATUS STDCALL
NullDispatch(PDEVICE_OBJECT DeviceObject, PIRP Irp) NullDispatch(PDEVICE_OBJECT DeviceObject, PIRP Irp)
/*
* FUNCTION: Handles user mode requests
* ARGUMENTS:
* DeviceObject = Device for request
* Irp = I/O request packet describing request
* RETURNS: Success or failure
*/
{ {
PIO_STACK_LOCATION Stack = IoGetCurrentIrpStackLocation(Irp); PIO_STACK_LOCATION piosStack = IoGetCurrentIrpStackLocation(Irp);
NTSTATUS status; NTSTATUS nErrCode;
switch (Stack->MajorFunction) nErrCode = STATUS_SUCCESS;
switch(piosStack->MajorFunction)
{ {
/* opening and closing handles to the device */
case IRP_MJ_CREATE: case IRP_MJ_CREATE:
case IRP_MJ_CLOSE: case IRP_MJ_CLOSE:
status = STATUS_SUCCESS; {
break; break;
}
/* write data */
case IRP_MJ_WRITE: case IRP_MJ_WRITE:
status = NullWrite(Irp,Stack); {
switch(NULL_DEVICE_TYPE(DeviceObject))
{
case NullBitBucket:
Irp->IoStatus.Information = piosStack->Parameters.Write.Length;
break; break;
case NullZeroStream:
default:
Irp->IoStatus.Information = 0;
nErrCode = STATUS_NOT_IMPLEMENTED;
}
break;
}
/* read data */
case IRP_MJ_READ: case IRP_MJ_READ:
status = NullRead(Irp,Stack); {
switch(NULL_DEVICE_TYPE(DeviceObject))
{
case NullBitBucket:
Irp->IoStatus.Information = 0;
nErrCode = STATUS_END_OF_FILE;
break;
case NullZeroStream:
RtlZeroMemory(Irp->AssociatedIrp.SystemBuffer, piosStack->Parameters.Read.Length);
Irp->IoStatus.Information = piosStack->Parameters.Read.Length;
break; break;
default: default:
status = STATUS_NOT_IMPLEMENTED; Irp->IoStatus.Information = 0;
nErrCode = STATUS_NOT_IMPLEMENTED;
} }
Irp->IoStatus.Status = status; break;
IoCompleteRequest(Irp,IO_NO_INCREMENT); }
return(status);
/* unsupported operations */
default:
{
nErrCode = STATUS_NOT_IMPLEMENTED;
}
}
Irp->IoStatus.Status = nErrCode;
IoCompleteRequest(Irp, IO_NO_INCREMENT);
return (nErrCode);
} }
NTSTATUS STDCALL NTSTATUS STDCALL
@ -72,34 +98,67 @@ NullUnload(PDRIVER_OBJECT DriverObject)
NTSTATUS STDCALL NTSTATUS STDCALL
DriverEntry(PDRIVER_OBJECT DriverObject, PUNICODE_STRING RegistryPath) DriverEntry(PDRIVER_OBJECT DriverObject, PUNICODE_STRING RegistryPath)
/*
* FUNCTION: Called by the system to initalize the driver
* ARGUMENTS:
* DriverObject = object describing this driver
* RegistryPath = path to our configuration entries
* RETURNS: Success or failure
*/
{ {
PDEVICE_OBJECT DeviceObject; PDEVICE_OBJECT pdoNullDevice;
UNICODE_STRING DeviceName; PDEVICE_OBJECT pdoZeroDevice;
NTSTATUS Status; UNICODE_STRING wstrDeviceName;
NTSTATUS nErrCode;
DeviceObject->Flags=0; /* register driver routines */
DriverObject->MajorFunction[IRP_MJ_CLOSE] = NullDispatch; DriverObject->MajorFunction[IRP_MJ_CLOSE] = NullDispatch;
DriverObject->MajorFunction[IRP_MJ_CREATE] = NullDispatch; DriverObject->MajorFunction[IRP_MJ_CREATE] = NullDispatch;
DriverObject->MajorFunction[IRP_MJ_WRITE] = NullDispatch; DriverObject->MajorFunction[IRP_MJ_WRITE] = NullDispatch;
DriverObject->MajorFunction[IRP_MJ_READ] = NullDispatch; DriverObject->MajorFunction[IRP_MJ_READ] = NullDispatch;
/* DriverObject->MajorFunction[IRP_MJ_QUERY_INFORMATION] = NullDispatch; */
DriverObject->DriverUnload = NullUnload; DriverObject->DriverUnload = NullUnload;
RtlInitUnicodeString(&DeviceName, /* create null device */
L"\\Device\\Null"); RtlInitUnicodeString(&wstrDeviceName, L"\\Device\\Null");
Status = IoCreateDevice(DriverObject,
0, nErrCode = IoCreateDevice
&DeviceName, (
DriverObject,
sizeof(NULL_EXTENSION),
&wstrDeviceName,
FILE_DEVICE_NULL, FILE_DEVICE_NULL,
0, 0,
FALSE, FALSE,
&DeviceObject); &pdoNullDevice
return (Status); );
/* failure */
if(!NT_SUCCESS(nErrCode))
{
return (nErrCode);
}
pdoNullDevice->DeviceExtension = (PVOID)&nxNull;
/* create zero device */
RtlInitUnicodeString(&wstrDeviceName, L"\\Device\\Zero");
nErrCode = IoCreateDevice
(
DriverObject,
sizeof(NULL_EXTENSION),
&wstrDeviceName,
FILE_DEVICE_NULL,
FILE_READ_ONLY_DEVICE, /* zero device is read-only */
FALSE,
&pdoZeroDevice
);
/* failure */
if(!NT_SUCCESS(nErrCode))
{
IoDeleteDevice(pdoNullDevice);
return (nErrCode);
}
pdoZeroDevice->DeviceExtension = (PVOID)&nxZero;
pdoZeroDevice->Flags |= DO_BUFFERED_IO;
return (nErrCode);
} }
/* EOF */

View file

@ -0,0 +1,19 @@
/* $Id: null.h,v 1.1 2002/04/29 23:06:42 hyperion Exp $
*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
* FILE: services/dd/null/null.h
* PURPOSE: NULL device driver internal definitions
* PROGRAMMER: KJK::Hyperion <noog@libero.it>
* UPDATE HISTORY:
* 29/04/2002: Created
*/
typedef enum __tagNULL_EXTENSION{
NullBitBucket,
NullZeroStream,
} NULL_EXTENSION, *PNULL_EXTENSION;
#define NULL_DEVICE_TYPE(__DEVICE__) (*((PNULL_EXTENSION)((__DEVICE__)->DeviceExtension)))
/* EOF */