1 /* $Id: null.c,v 1.12 2003/11/17 02:12:49 hyperion 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>
15 #include <rosrtl/string.h>
19 static const NULL_EXTENSION nxNull
= NullBitBucket
;
20 static const NULL_EXTENSION nxZero
= NullZeroStream
;
24 NullDispatch(PDEVICE_OBJECT DeviceObject
, PIRP Irp
)
26 PIO_STACK_LOCATION piosStack
= IoGetCurrentIrpStackLocation(Irp
);
29 nErrCode
= STATUS_SUCCESS
;
31 switch(piosStack
->MajorFunction
)
33 /* opening and closing handles to the device */
43 switch(NULL_DEVICE_TYPE(DeviceObject
))
46 Irp
->IoStatus
.Information
= piosStack
->Parameters
.Write
.Length
;
51 Irp
->IoStatus
.Information
= 0;
52 nErrCode
= STATUS_NOT_IMPLEMENTED
;
61 switch(NULL_DEVICE_TYPE(DeviceObject
))
64 Irp
->IoStatus
.Information
= 0;
65 nErrCode
= STATUS_END_OF_FILE
;
69 RtlZeroMemory(Irp
->AssociatedIrp
.SystemBuffer
, piosStack
->Parameters
.Read
.Length
);
70 Irp
->IoStatus
.Information
= piosStack
->Parameters
.Read
.Length
;
74 Irp
->IoStatus
.Information
= 0;
75 nErrCode
= STATUS_NOT_IMPLEMENTED
;
81 /* unsupported operations */
84 nErrCode
= STATUS_NOT_IMPLEMENTED
;
88 Irp
->IoStatus
.Status
= nErrCode
;
89 IoCompleteRequest(Irp
, IO_NO_INCREMENT
);
95 NullUnload(PDRIVER_OBJECT DriverObject
)
97 return(STATUS_SUCCESS
);
101 DriverEntry(PDRIVER_OBJECT DriverObject
, PUNICODE_STRING RegistryPath
)
103 PDEVICE_OBJECT pdoNullDevice
;
104 PDEVICE_OBJECT pdoZeroDevice
;
105 UNICODE_STRING wstrDeviceName
;
108 /* register driver routines */
109 DriverObject
->MajorFunction
[IRP_MJ_CLOSE
] = (PDRIVER_DISPATCH
)NullDispatch
;
110 DriverObject
->MajorFunction
[IRP_MJ_CREATE
] = (PDRIVER_DISPATCH
)NullDispatch
;
111 DriverObject
->MajorFunction
[IRP_MJ_WRITE
] = (PDRIVER_DISPATCH
)NullDispatch
;
112 DriverObject
->MajorFunction
[IRP_MJ_READ
] = (PDRIVER_DISPATCH
)NullDispatch
;
113 /* DriverObject->MajorFunction[IRP_MJ_QUERY_INFORMATION] = (PDRIVER_DISPATCH)NullDispatch; */
114 DriverObject
->DriverUnload
= (PDRIVER_UNLOAD
)NullUnload
;
116 /* create null device */
117 RtlRosInitUnicodeStringFromLiteral(&wstrDeviceName
, L
"\\Device\\Null");
119 nErrCode
= IoCreateDevice
122 sizeof(NULL_EXTENSION
),
131 if(!NT_SUCCESS(nErrCode
))
136 pdoNullDevice
->DeviceExtension
= (PVOID
)&nxNull
;
138 /* create zero device */
139 RtlRosInitUnicodeStringFromLiteral(&wstrDeviceName
, L
"\\Device\\Zero");
141 nErrCode
= IoCreateDevice
144 sizeof(NULL_EXTENSION
),
147 FILE_READ_ONLY_DEVICE
, /* zero device is read-only */
153 if(!NT_SUCCESS(nErrCode
))
155 IoDeleteDevice(pdoNullDevice
);
159 pdoZeroDevice
->DeviceExtension
= (PVOID
)&nxZero
;
160 pdoZeroDevice
->Flags
|= DO_BUFFERED_IO
;