From: Maxim S. Shatskih on
What is the crash?

--
Maxim S. Shatskih
Windows DDK MVP
maxim(a)storagecraft.com
http://www.storagecraft.com

"Daniel Zhang" <fanzier(a)gmail.com> wrote in message news:71ffe7d2-7a0a-491a-a89c-d4a62ebd0123(a)t39g2000prh.googlegroups.com...
I just return STATUS_SUCCESS without attaching,but the system also
crashed.

On Jan 21, 7:28 am, "Doron Holan [MSFT]" <dor...(a)online.microsoft.com>
wrote:
> return STATUS_SUCCESS without attaching
From: sharrajesh_at_g_mail_com on
Hi Daniel,

I am not sure if you got your responce. But what I wanted to ask you is that
when is your filter driver is configured to start at i..e
hklm\system\ccs\servies\<your filter> "start". Please make sure that it is
set to 0 instead of 3.

The reason being you may be filtering some boot time load driver.

Rajesh

"Daniel Zhang" wrote:

> On Jan 17, 2:21 am, "Doron Holan [MSFT]" <dor...(a)online.microsoft.com>
> wrote:
> > instead of looking at the driver name (in USB_Disk) of the PDO to determine
> > if it is a usb disk, get the enumerator name by calling
> > IoGetDeviceProperty(DevicePropertyEnumeratorName) and looks for "USBSTOR" or
> > "USB" depending on which usbstor devobj you are filtering
> >
> > http://msdn.microsoft.com/en-us/library/ms801223.aspx
> >
> > d
> >
> > --
> > Please do not send e-mail directly to this alias. this alias is for
> > newsgroup purposes only.
> > This posting is provided "AS IS" with no warranties, and confers no rights.
> >
> > "Daniel Zhang" <fanz...(a)gmail.com> wrote in message
> >
> > news:5240f735-2ee7-4979-91a8-0e31fd94e7e8(a)p2g2000prf.googlegroups.com...
> >
> > > Wayne,Thank you for your help. But I think I have already passed all
> > > the irp to the lower driver. Through the infomation from the core dump
> > > file, I felt that the system was not crashed at my filter driver.
> > > Below is my code,could you please find some error for me?
> >
> > > #include "stddcls.h"
> > > #include "driver.h"
> >
> > > #include <srb.h>
> > > #include <scsi.h>
> >
> > > NTSTATUS AddDevice(IN PDRIVER_OBJECT DriverObject, IN PDEVICE_OBJECT
> > > pdo);
> > > VOID DriverUnload(IN PDRIVER_OBJECT fido);
> > > NTSTATUS DispatchAny(IN PDEVICE_OBJECT fido, IN PIRP Irp);
> > > NTSTATUS DispatchPower(IN PDEVICE_OBJECT fido, IN PIRP Irp);
> > > NTSTATUS DispatchPnp(IN PDEVICE_OBJECT fido, IN PIRP Irp);
> > > NTSTATUS DispatchWmi(IN PDEVICE_OBJECT fido, IN PIRP Irp);
> > > ULONG GetDeviceTypeToUse(PDEVICE_OBJECT pdo);
> > > NTSTATUS StartDeviceCompletionRoutine(PDEVICE_OBJECT fido, PIRP Irp,
> > > PDEVICE_EXTENSION pdx);
> > > NTSTATUS UsageNotificationCompletionRoutine(PDEVICE_OBJECT fido, PIRP
> > > Irp, PDEVICE_EXTENSION pdx);
> >
> > > ///////////////////////////////////////////////////////////////////////////////
> > > #pragma INITCODE
> > > extern "C" NTSTATUS DriverEntry(IN PDRIVER_OBJECT DriverObject,
> > > IN PUNICODE_STRING RegistryPath)
> > > { // DriverEntry
> > > KdPrint((DRIVERNAME " - Entering DriverEntry: DriverObject %8.8lX\n",
> > > DriverObject));
> >
> > > // Initialize function pointers
> > > DriverObject->DriverUnload = DriverUnload;
> > > DriverObject->DriverExtension->AddDevice = AddDevice;
> > > for (int i = 0; i < arraysize(DriverObject->MajorFunction); ++i)
> > > DriverObject->MajorFunction[i] = DispatchAny;
> > > DriverObject->MajorFunction[IRP_MJ_POWER] = DispatchPower;
> > > DriverObject->MajorFunction[IRP_MJ_PNP] = DispatchPnp;
> > > DriverObject->MajorFunction[IRP_MJ_SCSI] = DispatchForSCSI;
> >
> > > return STATUS_SUCCESS;
> > > } // DriverEntry
> >
> > > #pragma PAGEDCODE
> > > VOID DriverUnload(IN PDRIVER_OBJECT DriverObject)
> > > { // DriverUnload
> > > PAGED_CODE();
> > > KdPrint((DRIVERNAME " - Entering DriverUnload: DriverObject %8.8lX
> > > \n", DriverObject));
> > > } // DriverUnload
> >
> > > BOOLEAN USB_Disk(IN PDEVICE_OBJECT pDevice)
> > > {
> > > UNICODE_STRING usb_disk_name;
> > > RtlInitUnicodeString(&usb_disk_name,L"\\driver\\usbstor");
> >
> > > PDRIVER_OBJECT pDriver = pDevice->DriverObject;
> > > KdPrint(("driver name:%wZ\n",&pDriver->DriverName));
> > > if (!RtlCompareUnicodeString(&pDriver-
> > >>DriverName,&usb_disk_name,TRUE))
> > > {
> > > KdPrint(("Find a USB disk device!\n"));
> > > return TRUE;
> > > }
> > > KdPrint(("This is not a USB disk device!"));
> > > return FALSE;
> > > }
> >
> > > NTSTATUS AddDevice(IN PDRIVER_OBJECT DriverObject, IN PDEVICE_OBJECT
> > > pdo)
> > > { // AddDevice
> > > PAGED_CODE();
> > > NTSTATUS status;
> >
> > > PDEVICE_OBJECT fido;
> >
> > > if (!USB_Disk(pdo))
> > > {
> > > return STATUS_SUCCESS;
> > > }
> >
> > > status = IoCreateDevice(DriverObject, sizeof(DEVICE_EXTENSION), NULL,
> > > GetDeviceTypeToUse(pdo), 0, FALSE, &fido);
> > > if (!NT_SUCCESS(status))
> > > { // can't create device object
> > > KdPrint((DRIVERNAME " - IoCreateDevice failed - %X\n", status));
> > > return status;
> > > } // can't create device object
> > > PDEVICE_EXTENSION pdx = (PDEVICE_EXTENSION) fido->DeviceExtension;
> >
> > > do
> > > { // finish initialization
> > > IoInitializeRemoveLock(&pdx->RemoveLock, 0, 0, 0);
> > > pdx->DeviceObject = fido;
> > > pdx->Pdo = pdo;
> > > //将过滤驱动附加在底层驱动之上
> > > PDEVICE_OBJECT fdo = IoAttachDeviceToDeviceStack(fido, pdo);
> > > if (!fdo)
> > > { // can't attach
> > > KdPrint((DRIVERNAME " - IoAttachDeviceToDeviceStack failed\n"));
> > > status = STATUS_DEVICE_REMOVED;
> > > break;
> > > } // can't attach
> > > //记录底层驱动
> > > pdx->LowerDeviceObject = fdo;
> > > //由于不知道底层驱动是直接IO还是BufferIO,因此将标志都置上
> > > fido->Flags |= fdo->Flags & (DO_DIRECT_IO | DO_BUFFERED_IO |
> > > DO_POWER_PAGABLE);
> > > // Clear the "initializing" flag so that we can get IRPs
> > > fido->Flags &= ~DO_DEVICE_INITIALIZING;
> > > } while (FALSE); // finish initialization
> >
> > > if (!NT_SUCCESS(status))
> > > { // need to cleanup
> > > if (pdx->LowerDeviceObject)
> > > IoDetachDevice(pdx->LowerDeviceObject);
> > > IoDeleteDevice(fido);
> > > } // need to cleanup
> >
> > > return status;
> > > } // AddDevice
> >
> > > ///////////////////////////////////////////////////////////////////////////////
> > > #pragma LOCKEDCODE
> > > NTSTATUS CompleteRequest(IN PIRP Irp, IN NTSTATUS status, IN ULONG_PTR
> > > info)
> > > { // CompleteRequest
> > > Irp->IoStatus.Status = status;
> > > Irp->IoStatus.Information = info;
> > > IoCompleteRequest(Irp, IO_NO_INCREMENT);
> > > return status;
> > > } // CompleteRequest
> >
> > > NTSTATUS
> > > USBSCSICompletion( IN PDEVICE_OBJECT DeviceObject,
> > > IN PIRP Irp,
> > > IN PVOID Context )
> > > {
> > > PDEVICE_EXTENSION pdx = ( PDEVICE_EXTENSION )
> > > DeviceObject->DeviceExtension;
> >
> > > IoAcquireRemoveLock(&pdx->RemoveLock,Irp);
> >
> > > PIO_STACK_LOCATION irpStack = IoGetCurrentIrpStackLocation( Irp );
> >
> > > PSCSI_REQUEST_BLOCK CurSrb=irpStack->Parameters.Scsi.Srb;
> > > PCDB cdb = (PCDB)CurSrb->Cdb;
> > > UCHAR opCode=cdb->CDB6GENERIC.OperationCode;
> >
> > > if(opCode==SCSIOP_MODE_SENSE && CurSrb->DataBuffer
> > > && CurSrb->DataTransferLength >=
> > > sizeof(MODE_PARAMETER_HEADER))
> > > {
> > > KdPrint(("SCSIOP_MODE_SENSE comming!\n"));
> >
> > > PMODE_PARAMETER_HEADER modeData = (PMODE_PARAMETER_HEADER)CurSrb-
> > >>DataBuffer;
> >
> > > modeData->DeviceSpecificParameter |= MODE_DSP_WRITE_PROTECT;
> > > }
> >
> > > if ( Irp->PendingReturned )
> > > {
> > > IoMarkIrpPending( Irp );
> > > }
> >
> > > IoReleaseRemoveLock(&pdx->RemoveLock,Irp);
> >
> > > return Irp->IoStatus.Status ;
> > > }
> >
> > > #pragma LOCKEDCODE
> > > NTSTATUS DispatchForSCSI(IN PDEVICE_OBJECT fido, IN PIRP Irp)
> > > {
> > > // KdPrint((DRIVERNAME " - Enter DispatchForSCSI \n"));
> >
> > > PDEVICE_EXTENSION pdx = (PDEVICE_EXTENSION) fido->DeviceExtension;
> >
> > > PIO_STACK_LOCATION irpStack = IoGetCurrentIrpStackLocation(Irp);
> >
> > > ULONG IoControlCode = irpStack-
> > >>Parameters.DeviceIoControl.IoControlCode;
> >
> > > KdPrint((DRIVERNAME " - Enter DispatchForSCSI :%x\n",IoControlCode));
> >
> > > // Pass request down without additional processing
> > > NTSTATUS status;
> > > status = IoAcquireRemoveLock(&pdx->RemoveLock, Irp);
> > > if (!NT_SUCCESS(status))
> > > return CompleteRequest(Irp, status, 0);
> >
> > > IoCopyCurrentIrpStackLocationToNext(Irp);
> >
> > > IoSetCompletionRoutine( Irp,
> > > USBSCSICompletion,
> > > NULL,
> > > TRUE,
> > > TRUE,
> > > TRUE );
> > > status = IoCallDriver(pdx->LowerDeviceObject, Irp);
> > > IoReleaseRemoveLock(&pdx->RemoveLock, Irp);
> > > return status;
> > > }
> > > ///////////////////////////////////////////////////////////////////////////////
> > > #pragma LOCKEDCODE // make no assumptions about pageability of
> > > dispatch fcns
> > > NTSTATUS DispatchAny(IN PDEVICE_OBJECT fido, IN PIRP Irp)
> > > { // DispatchAny
> > > PDEVICE_EXTENSION pdx = (PDEVICE_EXTENSION) fido->DeviceExtension;
> > > PIO_STACK_LOCATION stack = IoGetCurrentIrpStackLocation(Irp);
> > > #if DBG
> > > static char* irpname[] =
> > > {
> > > "IRP_MJ_CREATE",
> > > "IRP_MJ_CREATE_NAMED_PIPE",
> > > "IRP_MJ_CLOSE",
> > > "IRP_MJ_READ",
> > > "IRP_MJ_WRITE",
> > > "IRP_MJ_QUERY_INFORMATION",
> > > "IRP_MJ_SET_INFORMATION",
> > > "IRP_MJ_QUERY_EA",
> > > "IRP_MJ_SET_EA",
> > > "IRP_MJ_FLUSH_BUFFERS",
> > > "IRP_MJ_QUERY_VOLUME_INFORMATION",
> > > "IRP_MJ_SET_VOLUME_INFORMATION",
> > > "IRP_MJ_DIRECTORY_CONTROL",
> > > "IRP_MJ_FILE_SYSTEM_CONTROL",
> > > "IRP_MJ_DEVICE_CONTROL",
> > > "IRP_MJ_INTERNAL_DEVICE_CONTROL",
> > > "IRP_MJ_SHUTDOWN",
> > > "IRP_MJ_LOCK_CONTROL",
> > > "IRP_MJ_CLEANUP",
> > > "IRP_MJ_CREATE_MAILSLOT",
> > > "IRP_MJ_QUERY_SECURITY",
> > > "IRP_MJ_SET_SECURITY",
> > > "IRP_MJ_POWER",
> > > "IRP_MJ_SYSTEM_CONTROL",
> > > "IRP_MJ_DEVICE_CHANGE",
> > > "IRP_MJ_QUERY_QUOTA",
> > > "IRP_MJ_SET_QUOTA",
> > > "IRP_MJ_PNP",
> > > };
> >
> > > UCHAR type = stack->MajorFunction;
> > > // if (type >= arraysize(irpname))
> > > // KdPrint((DRIVERNAME " - Unknown IRP, major type %X\n", type));
> > > // else
> > > // KdPrint((DRIVERNAME " - %s\n", irpname[type]));
> >
> > > #endif
> >
> > > // Pass request down without additional processing
> > > NTSTATUS status;
> > > status = IoAcquireRemoveLock(&pdx->RemoveLock, Irp);
> > > if (!NT_SUCCESS(status))
> > > return CompleteRequest(Irp, status, 0);
> > > IoSkipCurrentIrpStackLocation(Irp);
> > > status = IoCallDriver(pdx->LowerDeviceObject, Irp);
> > > IoReleaseRemoveLock(&pdx->RemoveLock, Irp);
> > > return status;
> > > } // DispatchAny
> >
> > > ///////////////////////////////////////////////////////////////////////////////
> > > NTSTATUS DispatchPower(IN PDEVICE_OBJECT fido, IN PIRP Irp)
> > > { // DispatchPower
> > > #if DBG
> > > PIO_STACK_LOCATION stack = IoGetCurrentIrpStackLocation(Irp);
> > > ULONG fcn = stack->MinorFunction;
> > > static char* fcnname[] =
> > > {
> > > "IRP_MN_WAIT_WAKE",
> > > "IRP_MN_POWER_SEQUENCE",
> > > "IRP_MN_SET_POWER",
> > > "IRP_MN_QUERY_POWER",
> > > };
> >
> > > if (fcn == IRP_MN_SET_POWER || fcn == IRP_MN_QUERY_POWER)
> > > {
> > > static char* sysstate[] =