1 /* $Id: debugout.c,v 1.2 2003/11/17 02:12:49 hyperion Exp $
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)
11 * In your usermode application, do something like this:
13 * DebugHandle = CreateFile("\\\\.\\DebugOut",
18 * FILE_ATTRIBUTE_NORMAL,
21 * and write to your hearts content to DebugHandle.
25 #include <ddk/ntddk.h>
26 #include <rosrtl/string.h>
30 DebugOutDispatch(IN PDEVICE_OBJECT DeviceObject
, IN PIRP Irp
)
32 PIO_STACK_LOCATION piosStack
= IoGetCurrentIrpStackLocation(Irp
);
39 nErrCode
= STATUS_SUCCESS
;
41 switch(piosStack
->MajorFunction
)
43 /* opening and closing handles to the device */
50 Remaining
= piosStack
->Parameters
.Write
.Length
;
51 Start
= Irp
->AssociatedIrp
.SystemBuffer
;
55 if (sizeof(Buf
) - 1 < Length
)
57 Length
= sizeof(Buf
) - 1;
59 RtlCopyMemory(Buf
, Start
, Length
);
66 Irp
->IoStatus
.Information
= piosStack
->Parameters
.Write
.Length
;
71 Irp
->IoStatus
.Information
= 0;
72 nErrCode
= STATUS_END_OF_FILE
;
75 /* unsupported operations */
77 nErrCode
= STATUS_NOT_IMPLEMENTED
;
80 Irp
->IoStatus
.Status
= nErrCode
;
81 IoCompleteRequest(Irp
, IO_NO_INCREMENT
);
87 DebugOutUnload(PDRIVER_OBJECT DriverObject
)
89 return STATUS_SUCCESS
;
93 DriverEntry(PDRIVER_OBJECT DriverObject
, PUNICODE_STRING RegistryPath
)
95 PDEVICE_OBJECT DebugOutDevice
;
96 UNICODE_STRING DeviceName
;
97 UNICODE_STRING DosName
;
100 /* register driver routines */
101 DriverObject
->MajorFunction
[IRP_MJ_CLOSE
] = (PDRIVER_DISPATCH
) DebugOutDispatch
;
102 DriverObject
->MajorFunction
[IRP_MJ_CREATE
] = (PDRIVER_DISPATCH
) DebugOutDispatch
;
103 DriverObject
->MajorFunction
[IRP_MJ_WRITE
] = (PDRIVER_DISPATCH
) DebugOutDispatch
;
104 DriverObject
->MajorFunction
[IRP_MJ_READ
] = (PDRIVER_DISPATCH
) DebugOutDispatch
;
105 /* DriverObject->MajorFunction[IRP_MJ_QUERY_INFORMATION] = (PDRIVER_DISPATCH) DebugOutDispatch; */
106 DriverObject
->DriverUnload
= (PDRIVER_UNLOAD
) DebugOutUnload
;
109 RtlRosInitUnicodeStringFromLiteral(&DeviceName
, L
"\\Device\\DebugOut");
111 Status
= IoCreateDevice(DriverObject
, 0, &DeviceName
, FILE_DEVICE_NULL
,
112 0, FALSE
, &DebugOutDevice
);
113 if (! NT_SUCCESS(Status
))
118 RtlRosInitUnicodeStringFromLiteral(&DosName
, L
"\\DosDevices\\DebugOut");
119 Status
= IoCreateSymbolicLink(&DosName
, &DeviceName
);
120 if (! NT_SUCCESS(Status
))
122 IoDeleteDevice(DebugOutDevice
);
126 DebugOutDevice
->Flags
|= DO_BUFFERED_IO
;