753c55c87211a2a667d0a564bfbfb2a2e4ec8650
[reactos.git] / reactos / drivers / dd / null / null.c
1 /*
2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS kernel
4 * FILE: services/null/null.c
5 * PURPOSE: NULL device driver
6 * PROGRAMMER: David Welch (welch@mcmail.com)
7 * UPDATE HISTORY:
8 * 13/08/98: Created
9 */
10
11 /* INCLUDES ****************************************************************/
12
13 #include <ddk/ntddk.h>
14
15 /* FUNCTIONS **************************************************************/
16
17 NTSTATUS NullWrite(PIRP Irp, PIO_STACK_LOCATION stk)
18 {
19 Irp->IoStatus.Information = stk->Parameters.Write.Length;
20 return(STATUS_SUCCESS);
21 }
22
23 NTSTATUS NullRead(PIRP Irp, PIO_STACK_LOCATION stk)
24 {
25 Irp->IoStatus.Information = 0;
26 return(STATUS_END_OF_FILE);
27 }
28
29 NTSTATUS NullDispatch(PDEVICE_OBJECT DeviceObject, PIRP Irp)
30 /*
31 * FUNCTION: Handles user mode requests
32 * ARGUMENTS:
33 * DeviceObject = Device for request
34 * Irp = I/O request packet describing request
35 * RETURNS: Success or failure
36 */
37 {
38 PIO_STACK_LOCATION Stack = IoGetCurrentIrpStackLocation(Irp);
39 NTSTATUS status;
40
41 switch (Stack->MajorFunction)
42 {
43 case IRP_MJ_CREATE:
44 case IRP_MJ_CLOSE:
45 status = STATUS_SUCCESS;
46 break;
47
48 case IRP_MJ_WRITE:
49 status = NullWrite(Irp,Stack);
50 break;
51
52 case IRP_MJ_READ:
53 status = NullRead(Irp,Stack);
54 break;
55
56 default:
57 status = STATUS_NOT_IMPLEMENTED;
58 }
59
60 Irp->IoStatus.Status = status;
61 IoCompleteRequest(Irp,IO_NO_INCREMENT);
62 return(status);
63 }
64
65 NTSTATUS NullUnload(PDRIVER_OBJECT DriverObject)
66 {
67 return(STATUS_SUCCESS);
68 }
69
70 NTSTATUS STDCALL
71 DriverEntry(PDRIVER_OBJECT DriverObject, PUNICODE_STRING RegistryPath)
72 /*
73 * FUNCTION: Called by the system to initalize the driver
74 * ARGUMENTS:
75 * DriverObject = object describing this driver
76 * RegistryPath = path to our configuration entries
77 * RETURNS: Success or failure
78 */
79 {
80 PDEVICE_OBJECT DeviceObject;
81 NTSTATUS ret;
82 ANSI_STRING ansi_device_name;
83 UNICODE_STRING device_name;
84
85 DbgPrint("Null Device Driver 0.0.2\n");
86
87 RtlInitAnsiString(&ansi_device_name,"\\Device\\NUL");
88 RtlAnsiStringToUnicodeString(&device_name,&ansi_device_name,TRUE);
89 ret = IoCreateDevice(DriverObject,0,&device_name,
90 FILE_DEVICE_NULL,0,FALSE,&DeviceObject);
91 if (ret!=STATUS_SUCCESS)
92 {
93 return(ret);
94 }
95
96 DeviceObject->Flags=0;
97 DriverObject->MajorFunction[IRP_MJ_CLOSE] = NullDispatch;
98 DriverObject->MajorFunction[IRP_MJ_CREATE] = NullDispatch;
99 DriverObject->MajorFunction[IRP_MJ_WRITE] = NullDispatch;
100 DriverObject->MajorFunction[IRP_MJ_READ] = NullDispatch;
101 DriverObject->DriverUnload = NullUnload;
102
103 return(STATUS_SUCCESS);
104 }
105