FastIoDispatch example
X-NEWS: cmkrnl comp.os.ms-windows.programmer.nt.kernel-mode: 6795
Relay-Version: ANU News - V6.1B10 10/08/94 OpenVMS VAX V5.5-2; site cmkrnl
Path: cmkrnl!newsfeed.cts.com!newshub.cts.com!news.aloha.net!
svr1.gstis.net!news-chi-8.sprintlink.net!
news-pull.sprintlink.net!news.sprintlink.net!
news-peer.sprintlink.net!howland.erols.net!
newsfeed.internetmci.com!eanews1!trsvr!news
Newsgroups: comp.os.ms-windows.programmer.nt.kernel-mode
Subject: FastIoDispatch, example code
Message-ID: <01bc23ed$36cc47f0$d0e43fc0@djm8>
From: "Duane J. McCrory"
Date: Wed, 26 Feb 1997 13:48:28 GMT
Sender:
news@tr.unisys.com (cnews news id.)
Organization: Unisys Corporation
X-Nntp-Posting-Host: djm8.tr.unisys.com
X-Newsreader: Microsoft Internet News 4.70.1155
Lines: 93
I got a request for sample FastIoDispatch code. Here's an example for Ioctls.
static FAST_IO_DISPATCH fast_io_dispatch;
static NTSTATUS driver_dispatch_device_control(IN DEVICE_OBJECT *
dev, IN
IRP *irp) {
PIO_STACK_LOCATION irp_stk;
NTSTATUS status;
// in my case, I never need an IRP for a device_control opera
// tion
// so if my IRP_MJ_DEVICE_CONTROL function happens to get cal
// led
// I can make use of the fast procedure that I've implemented
irp_stk = IoGetCurrentIrpStackLocation(irp);
driver_dispatch_device_control_fast(irp_stk->FileObject, TRUE
,
irp_stk->Parameters.DeviceIoControl.Type3InputBuffer,
irp_stk->Parameters.DeviceIoControl.InputBufferLength,
irp->UserBuffer,
irp_stk->Parameters.DeviceIoControl.OutputBufferLength,
irp_stk->Parameters.DeviceIoControl.IoControlCode,
&irp->IoStatus, dev);
status = irp->IoStatus.Status;
IoCompleteRequest(irp, IO_NO_INCREMENT);
return status;
}
static BOOLEAN driver_dispatch_device_control_fast(IN FILE_OBJECT
*FileObject,
IN BOOLEAN Wait, IN PVOID InputBuffer OPTIONAL, IN ULONG
InputBufferLength,
OUT PVOID OutputBuffer OPTIONAL, IN ULONG OutputBufferLen
gth,
IN ULONG IoControlCode, OUT PIO_STATUS_BLOCK IoStatus, IN
DEVICE_OBJECT *dev) {
// setup default result
IoStatus->Status = STATUS_SUCCESS;
IoStatus->Information = 0;
switch (IoControlCode) {
case IOCTL_OUTPUT_TO_APPLICATION:
// this is an example for sending data to an application
if (OutputBufferLength >= sizeof(YOUR_OUTPUT_AREA)) {
__try {
*(YOUR_OUTPUT_AREA *)OutputBuffer = d>
IoStatus->Information = sizeof(YOUR_OUTPUT_AREA);
} __except(EXCEPTION_EXECUTE_HANDLER) {
IoStatus->Status = GetExceptionCode();
}
} else
IoStatus->Status = STATUS_INVALID_PARAMETER;
return TRUE;
default:
// Set default return information
IoStatus->Status = STATUS_NOT_IMPLEMENTED;
return TRUE;
}
// note that you would return FALSE if you want the standard
IRP_MJ_DEVICE_CONTROL
// dispatch routine called, in my case I always return TRUE
}
NTSTATUS PROCEDURE DriverEntry(IN DRIVER_OBJECT *drv, IN PUNICODE
_STRING
RegistryPath) {
.
.
.
RtlZeroMemory(&fast_io_dispatch, sizeof(fast_io_dispatch));
fast_io_dispatch.SizeOfFastIoDispatch = sizeof(fast_io_dispat
ch);
fast_io_dispatch.FastIoDeviceControl =
driver_dispatch_device_control_fast;
drv->FastIoDispatch = &fast_io_dispatch;
drv->MajorFunction[IRP_MJ_CREATE] = driver_dispatch;
drv->MajorFunction[IRP_MJ_CLOSE] = driver_dispatch;
drv->MajorFunction[IRP_MJ_DEVICE_CONTROL] =
driver_dispatch_device_control;
drv->MajorFunction[IRP_MJ_READ] = driver_dispatch;
drv->MajorFunction[IRP_MJ_WRITE] = driver_dispatch;
drv->MajorFunction[IRP_MJ_CLEANUP] = driver_dispatch;
drv->MajorFunction[IRP_MJ_SHUTDOWN] = driver_dispatch;
drv->DriverUnload = driver_unload;
.
.
.
}
--
Duane.