Fix sublanguage IDs in .rc files:
[reactos.git] / reactos / drivers / dd / debugout / debugout.c
1 /* $Id$
2 *
3 * COPYRIGHT: See COPYING in the top level directory
4 * PROJECT: ReactOS kernel
5 * FILE: drivers/dd/debugout.c
6 * PURPOSE: Debug output device driver
7 * PROGRAMMER: Ge van Geldorp (ge@gse.nl)
8 * UPDATE HISTORY:
9 * 2003/05/22: Created
10 * NOTES:
11 * In your usermode application, do something like this:
12 *
13 * DebugHandle = CreateFile("\\\\.\\DebugOut",
14 * GENERIC_WRITE,
15 * 0,
16 * NULL,
17 * OPEN_EXISTING,
18 * FILE_ATTRIBUTE_NORMAL,
19 * NULL);
20 *
21 * and write to your hearts content to DebugHandle.
22 */
23
24 /* INCLUDES */
25 #include <ddk/ntddk.h>
26
27 NTSTATUS STDCALL
28 DriverEntry(PDRIVER_OBJECT DriverObject, PUNICODE_STRING RegistryPath);
29
30 /* FUNCTIONS */
31 static NTSTATUS STDCALL
32 DebugOutDispatch(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
33 {
34 PIO_STACK_LOCATION piosStack = IoGetCurrentIrpStackLocation(Irp);
35 NTSTATUS nErrCode;
36 char *Start;
37 char Buf[513];
38 unsigned Remaining;
39 unsigned Length;
40
41 nErrCode = STATUS_SUCCESS;
42
43 switch(piosStack->MajorFunction)
44 {
45 /* opening and closing handles to the device */
46 case IRP_MJ_CREATE:
47 case IRP_MJ_CLOSE:
48 break;
49
50 /* write data */
51 case IRP_MJ_WRITE:
52 Remaining = piosStack->Parameters.Write.Length;
53 Start = Irp->AssociatedIrp.SystemBuffer;
54 while (0 < Remaining)
55 {
56 Length = Remaining;
57 if (sizeof(Buf) - 1 < Length)
58 {
59 Length = sizeof(Buf) - 1;
60 }
61 RtlCopyMemory(Buf, Start, Length);
62 Buf[Length] = '\0';
63 DbgPrint("%s", Buf);
64 Remaining -= Length;
65 Start += Length;
66 }
67
68 Irp->IoStatus.Information = piosStack->Parameters.Write.Length;
69 break;
70
71 /* read data */
72 case IRP_MJ_READ:
73 Irp->IoStatus.Information = 0;
74 nErrCode = STATUS_END_OF_FILE;
75 break;
76
77 /* unsupported operations */
78 default:
79 nErrCode = STATUS_NOT_IMPLEMENTED;
80 }
81
82 Irp->IoStatus.Status = nErrCode;
83 IoCompleteRequest(Irp, IO_NO_INCREMENT);
84
85 return nErrCode;
86 }
87
88 static VOID STDCALL
89 DebugOutUnload(PDRIVER_OBJECT DriverObject)
90 {
91 }
92
93 NTSTATUS STDCALL
94 DriverEntry(PDRIVER_OBJECT DriverObject, PUNICODE_STRING RegistryPath)
95 {
96 PDEVICE_OBJECT DebugOutDevice;
97 UNICODE_STRING DeviceName = RTL_CONSTANT_STRING(L"\\Device\\DebugOut");
98 UNICODE_STRING DosName = RTL_CONSTANT_STRING(L"\\DosDevices\\DebugOut");
99 NTSTATUS Status;
100
101 /* register driver routines */
102 DriverObject->MajorFunction[IRP_MJ_CLOSE] = DebugOutDispatch;
103 DriverObject->MajorFunction[IRP_MJ_CREATE] = DebugOutDispatch;
104 DriverObject->MajorFunction[IRP_MJ_WRITE] = DebugOutDispatch;
105 DriverObject->MajorFunction[IRP_MJ_READ] = DebugOutDispatch;
106 /* DriverObject->MajorFunction[IRP_MJ_QUERY_INFORMATION] = DebugOutDispatch; */
107 DriverObject->DriverUnload = DebugOutUnload;
108
109 /* create device */
110 Status = IoCreateDevice(DriverObject, 0, &DeviceName, FILE_DEVICE_NULL,
111 0, FALSE, &DebugOutDevice);
112 if (! NT_SUCCESS(Status))
113 {
114 return Status;
115 }
116
117 Status = IoCreateSymbolicLink(&DosName, &DeviceName);
118 if (! NT_SUCCESS(Status))
119 {
120 IoDeleteDevice(DebugOutDevice);
121 return Status;
122 }
123
124 DebugOutDevice->Flags |= DO_BUFFERED_IO;
125
126 return Status;
127 }
128
129 /* EOF */