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
11 * 28/06/2004: Compile against the DDK, use PSEH where necessary
17 #include <rosrtl/string.h>
23 static const NULL_EXTENSION nxNull
= NullBitBucket
;
24 static const NULL_EXTENSION nxZero
= NullZeroStream
;
28 NullDispatch(PDEVICE_OBJECT DeviceObject
, PIRP Irp
)
30 PIO_STACK_LOCATION piosStack
= IoGetCurrentIrpStackLocation(Irp
);
33 nErrCode
= STATUS_SUCCESS
;
34 Irp
->IoStatus
.Information
= 0;
36 switch(piosStack
->MajorFunction
)
38 /* opening and closing handles to the device */
41 switch(NULL_DEVICE_TYPE(DeviceObject
))
56 switch(NULL_DEVICE_TYPE(DeviceObject
))
59 Irp
->IoStatus
.Information
= piosStack
->Parameters
.Write
.Length
;
63 nErrCode
= STATUS_INVALID_DEVICE_REQUEST
;
76 switch(NULL_DEVICE_TYPE(DeviceObject
))
79 nErrCode
= STATUS_END_OF_FILE
;
85 RtlZeroMemory(Irp
->AssociatedIrp
.SystemBuffer
, piosStack
->Parameters
.Read
.Length
);
86 Irp
->IoStatus
.Information
= piosStack
->Parameters
.Read
.Length
;
90 nErrCode
= _SEH_GetExceptionCode();
97 Irp
->IoStatus
.Information
= 0;
98 nErrCode
= STATUS_NOT_IMPLEMENTED
;
108 Irp
->IoStatus
.Status
= nErrCode
;
109 IoCompleteRequest(Irp
, IO_NO_INCREMENT
);
115 NullUnload(PDRIVER_OBJECT DriverObject
)
119 /* TODO: \Device\Zero should be memory-mappable */
121 DriverEntry(PDRIVER_OBJECT DriverObject
, PUNICODE_STRING RegistryPath
)
123 PDEVICE_OBJECT pdoNullDevice
;
124 PDEVICE_OBJECT pdoZeroDevice
;
125 UNICODE_STRING wstrDeviceName
;
128 /* register driver routines */
129 DriverObject
->MajorFunction
[IRP_MJ_CLOSE
] = NullDispatch
;
130 DriverObject
->MajorFunction
[IRP_MJ_CREATE
] = NullDispatch
;
131 DriverObject
->MajorFunction
[IRP_MJ_WRITE
] = NullDispatch
;
132 DriverObject
->MajorFunction
[IRP_MJ_READ
] = NullDispatch
;
133 DriverObject
->DriverUnload
= NullUnload
;
135 /* create null device */
136 RtlRosInitUnicodeStringFromLiteral(&wstrDeviceName
, L
"\\Device\\Null");
138 nErrCode
= IoCreateDevice
141 sizeof(NULL_EXTENSION
),
150 if(!NT_SUCCESS(nErrCode
))
155 pdoNullDevice
->DeviceExtension
= (PVOID
)&nxNull
;
157 /* create zero device */
158 RtlRosInitUnicodeStringFromLiteral(&wstrDeviceName
, L
"\\Device\\Zero");
160 nErrCode
= IoCreateDevice
163 sizeof(NULL_EXTENSION
),
166 FILE_READ_ONLY_DEVICE
, /* zero device is read-only */
172 if(!NT_SUCCESS(nErrCode
))
174 IoDeleteDevice(pdoNullDevice
);
178 pdoZeroDevice
->DeviceExtension
= (PVOID
)&nxZero
;
179 pdoZeroDevice
->Flags
|= DO_BUFFERED_IO
;