6230abe114e1826577398a6b5ea863d1734015c7
[reactos.git] / reactos / drivers / dd / null / null.c
1 /* $Id: null.c,v 1.6 2002/02/08 02:57:08 chorns Exp $
2 *
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)
8 * UPDATE HISTORY:
9 * 13/08/98: Created
10 */
11
12 /* INCLUDES ****************************************************************/
13
14 #include <ddk/ntddk.h>
15
16 /* FUNCTIONS **************************************************************/
17
18 NTSTATUS NullWrite(PIRP Irp, PIO_STACK_LOCATION stk)
19 {
20 Irp->IoStatus.Information = stk->Parameters.Write.Length;
21 return(STATUS_SUCCESS);
22 }
23
24 NTSTATUS NullRead(PIRP Irp, PIO_STACK_LOCATION stk)
25 {
26 Irp->IoStatus.Information = 0;
27 return(STATUS_END_OF_FILE);
28 }
29
30 NTSTATUS STDCALL
31 NullDispatch(PDEVICE_OBJECT DeviceObject, PIRP Irp)
32 /*
33 * FUNCTION: Handles user mode requests
34 * ARGUMENTS:
35 * DeviceObject = Device for request
36 * Irp = I/O request packet describing request
37 * RETURNS: Success or failure
38 */
39 {
40 PIO_STACK_LOCATION Stack = IoGetCurrentIrpStackLocation(Irp);
41 NTSTATUS status;
42
43 switch (Stack->MajorFunction)
44 {
45 case IRP_MJ_CREATE:
46 case IRP_MJ_CLOSE:
47 status = STATUS_SUCCESS;
48 break;
49
50 case IRP_MJ_WRITE:
51 status = NullWrite(Irp,Stack);
52 break;
53
54 case IRP_MJ_READ:
55 status = NullRead(Irp,Stack);
56 break;
57
58 default:
59 status = STATUS_NOT_IMPLEMENTED;
60 }
61
62 Irp->IoStatus.Status = status;
63 IoCompleteRequest(Irp,IO_NO_INCREMENT);
64 return(status);
65 }
66
67 NTSTATUS STDCALL
68 NullUnload(PDRIVER_OBJECT DriverObject)
69 {
70 return(STATUS_SUCCESS);
71 }
72
73 NTSTATUS STDCALL
74 DriverEntry(PDRIVER_OBJECT DriverObject, PUNICODE_STRING RegistryPath)
75 /*
76 * FUNCTION: Called by the system to initalize the driver
77 * ARGUMENTS:
78 * DriverObject = object describing this driver
79 * RegistryPath = path to our configuration entries
80 * RETURNS: Success or failure
81 */
82 {
83 PDEVICE_OBJECT DeviceObject;
84 UNICODE_STRING DeviceName;
85 NTSTATUS Status;
86
87 DeviceObject->Flags=0;
88 DriverObject->MajorFunction[IRP_MJ_CLOSE] = NullDispatch;
89 DriverObject->MajorFunction[IRP_MJ_CREATE] = NullDispatch;
90 DriverObject->MajorFunction[IRP_MJ_WRITE] = NullDispatch;
91 DriverObject->MajorFunction[IRP_MJ_READ] = NullDispatch;
92 DriverObject->DriverUnload = NullUnload;
93
94 RtlInitUnicodeString(&DeviceName,
95 L"\\Device\\Null");
96 Status = IoCreateDevice(DriverObject,
97 0,
98 &DeviceName,
99 FILE_DEVICE_NULL,
100 0,
101 FALSE,
102 &DeviceObject);
103 return (Status);
104 }
105