1 /* $Id: null.c,v 1.10 2002/09/08 10:22:05 chorns Exp $
3 * COPYRIGHT: See COPYING in the top level directory
4 * PROJECT: ReactOS kernel
5 * FILE: services/null/null.c
6 * PURPOSE: NULL device driver
7 * PROGRAMMER: David Welch (welch@mcmail.com)
10 * 29/04/2002: Fixed bugs, added zero-stream device
14 #include <ddk/ntddk.h>
18 static const NULL_EXTENSION nxNull
= NullBitBucket
;
19 static const NULL_EXTENSION nxZero
= NullZeroStream
;
23 NullDispatch(PDEVICE_OBJECT DeviceObject
, PIRP Irp
)
25 PIO_STACK_LOCATION piosStack
= IoGetCurrentIrpStackLocation(Irp
);
28 nErrCode
= STATUS_SUCCESS
;
30 switch(piosStack
->MajorFunction
)
32 /* opening and closing handles to the device */
42 switch(NULL_DEVICE_TYPE(DeviceObject
))
45 Irp
->IoStatus
.Information
= piosStack
->Parameters
.Write
.Length
;
50 Irp
->IoStatus
.Information
= 0;
51 nErrCode
= STATUS_NOT_IMPLEMENTED
;
60 switch(NULL_DEVICE_TYPE(DeviceObject
))
63 Irp
->IoStatus
.Information
= 0;
64 nErrCode
= STATUS_END_OF_FILE
;
68 RtlZeroMemory(Irp
->AssociatedIrp
.SystemBuffer
, piosStack
->Parameters
.Read
.Length
);
69 Irp
->IoStatus
.Information
= piosStack
->Parameters
.Read
.Length
;
73 Irp
->IoStatus
.Information
= 0;
74 nErrCode
= STATUS_NOT_IMPLEMENTED
;
80 /* unsupported operations */
83 nErrCode
= STATUS_NOT_IMPLEMENTED
;
87 Irp
->IoStatus
.Status
= nErrCode
;
88 IoCompleteRequest(Irp
, IO_NO_INCREMENT
);
94 NullUnload(PDRIVER_OBJECT DriverObject
)
96 return(STATUS_SUCCESS
);
100 DriverEntry(PDRIVER_OBJECT DriverObject
, PUNICODE_STRING RegistryPath
)
102 PDEVICE_OBJECT pdoNullDevice
;
103 PDEVICE_OBJECT pdoZeroDevice
;
104 UNICODE_STRING wstrDeviceName
;
107 /* register driver routines */
108 DriverObject
->MajorFunction
[IRP_MJ_CLOSE
] = NullDispatch
;
109 DriverObject
->MajorFunction
[IRP_MJ_CREATE
] = NullDispatch
;
110 DriverObject
->MajorFunction
[IRP_MJ_WRITE
] = NullDispatch
;
111 DriverObject
->MajorFunction
[IRP_MJ_READ
] = NullDispatch
;
112 /* DriverObject->MajorFunction[IRP_MJ_QUERY_INFORMATION] = NullDispatch; */
113 DriverObject
->DriverUnload
= NullUnload
;
115 /* create null device */
116 RtlInitUnicodeStringFromLiteral(&wstrDeviceName
, L
"\\Device\\Null");
118 nErrCode
= IoCreateDevice
121 sizeof(NULL_EXTENSION
),
130 if(!NT_SUCCESS(nErrCode
))
135 pdoNullDevice
->DeviceExtension
= (PVOID
)&nxNull
;
137 /* create zero device */
138 RtlInitUnicodeStringFromLiteral(&wstrDeviceName
, L
"\\Device\\Zero");
140 nErrCode
= IoCreateDevice
143 sizeof(NULL_EXTENSION
),
146 FILE_READ_ONLY_DEVICE
, /* zero device is read-only */
152 if(!NT_SUCCESS(nErrCode
))
154 IoDeleteDevice(pdoNullDevice
);
158 pdoZeroDevice
->DeviceExtension
= (PVOID
)&nxZero
;
159 pdoZeroDevice
->Flags
|= DO_BUFFERED_IO
;