PWDM1_DEVICE_EXTENSION dx=(PWDMl_DEVICE_EXTENSION)fdo->DeviceExtension;
// Remember minor function
PIO_STACK_LOCATION IrpStack = IoGetCurrentIrpStackLocation(Irp);
ULONG MinorFunction = IrpStack->MinorFunction;
// Just pass to lower driver
IoSkipCurrentIrpStackLocation(Irp);
NTSTATUS status = IoCallDriver(dx->NextStackDevice, Irp);
// Device removed
if (MinorFunction==IRP_MN_REMOVE_DEVICE) {
DebugPrint('PnP RemoveDevice');
// disable device interface
IoSetDeviceInterfaceState(&dx->ifSymLinkName, FALSE);
RtlFreeUnicodeString(&dx->ifSymLinkName);
// unattach from stack
if (dx->NextStackDevice) IoDetachDevice(dx->NextStackDevice);
// delete our fdo IoDeleteDevice(fdo);
}
return status;
}
///////////////////////////////////////////////////////////////////////
//Wdm1Power:
//
//Description:
//Handle IRP_MJ_POWER requests
//
//Arguments:
//Pointer to the FDO
//Pointer to the IRP
//IRP_MN_WAIT_WAKE:IrpStack->Parameters.WaitWake.Xxx
//IRP_MN_POWER_SEOUENCE:IrpStack->Parameters.PowerSequence.Xxx
//IRP_MN_SET_POWER:
//IRP_MN_QUERY_POWER:IrpStack->Parameters.Power.Xxx
//
//Return Value:
//This function returns STATUS_XXX
NTSTATUS Wdm1Power(IN PDEVICE_OBJECT fdo, IN PIRP Irp) {
DebugPrint('Power %I',Irp);
PWDM1_DEVICE_EXTENSION dx = (PWDM1_DEVICE_EXTENSION)fdo->DeviceExtension;
// Just pass to lower driver
PoStartNextPowerIrp(Irp);
IoSkipCurrentIrpStackLocation(Irp);
return PoCallDriver(dx->NextStackDevice, Irp);
}
#pragma code_seg()// end PAGE section
Listing 4.10 Dispatch.cpp
///////////////////////////////////////////////////////////////////////
//Copyright © 1998 Chris Cant, PHD Computer Consultants Ltd
//WDM Book for R&D Books, Miller Freeman Inc
//
//Wdm1 example
///////////////////////////////////////////////////////////////////////
//dispatch.cpp:Other IRP handlers
///////////////////////////////////////////////////////////////////////
//Wdm1CreateHandle Create/Open file IRP
//Wdm1CloseHandle Close file IRPs
//Wdm1ReadHandle Read IRPs
//Wdm1WriteHandle Write IRPs
//Wdm1DeviceControlHandle DeviceIoControl IRPs
//Wdm1SystemControlHandle WMI IRPs
///////////////////////////////////////////////////////////////////////
//Version history
//27-Apr-991.0.0CCcreation
///////////////////////////////////////////////////////////////////////
#include 'wdm1.h'
#include 'Ioctl.h'
///////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////
//Buffer and BufferSize and guarding spin lock globals (in unpaged memory)
KSPIN_LOCK BufferLock;
PUCHARBuffer = NULL;
ULONGBufferSize = 0;
///////////////////////////////////////////////////////////////////////
//Wdm1Create:
//
//Description:
//Handle IRP_MJ_CREATE requests
//
//Arguments:
//Pointer to our FDO
//Pointer to the IRP
//IrpStack->Parameters.Create.xxx has create parameters
//IrpStack->FileObject->FileName has file name of device
//
//Return Value:
//This function returns STATUS_XXX
NTSTATUS Wdm1Create(IN PDEVICE_OBJECT fdo, IN PIRP Irp) {
PIO_STACK_LOCATION IrpStack = IoGetCurrentIrpStackLocation(Irp);
DebugPrint('Create File is %T', &(IrpStack->FileObject->FileName);