Hello all,
I am a beginner.Recently,I am trying to write a filter driver,but there is a BSOD issue in my dispatch routine that process IRP_MJ_READ irp.I don’t know how to deal with it. The following is my simple sample code.Could you help me?Thanks in advance!Sorry my poor English!!!
NTSTATUS SfRead(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
{
PIO_STACK_LOCATION pIrpSp;
PFILE_OBJECT pFileObject;
PSFILTER_DEVICE_EXTENSION devExt;
pIrpSp = IoGetCurrentIrpStackLocation(Irp);
pFileObject = pIrpSp->FileObject;
devExt = DeviceObject->DeviceExtension;
////////////////////////////////////////////////////////////////////////
// Is my control device object
if (IS_MY_CONTROL_DEVICE_OBJECT(DeviceObject))
{
Irp->IoStatus.Status = STATUS_INVALID_DEVICE_REQUEST;
Irp->IoStatus.Information = 0;
IoCompleteRequest(Irp, IO_NO_INCREMENT);
return STATUS_INVALID_DEVICE_REQUEST;
}
////////////////////////////////////////////////////////////////////////
//Is storage stack device object
if (NULL == devExt->StorageStackDeviceObject)
{
return SfPassThrough(DeviceObject,Irp);
}
////////////////////////////////////////////////////////////////////////
//Is my filter device object
{
UNICODE_STRING fullName;
UNICODE_STRING extName;
WCHAR fullNameBuffer[512];
WCHAR extNameBuffer[256];
USHORT i;
//////////////////////////////////////////////////////////////////////
//Get file name from file object
fullUniName.Length = pFileObject->FileName.Length;
fullUniName.MaximumLength = pFileObject->FileName.MaximumLength;
RtlInitEmptyUnicodeString(&fullName, fullNameBuffer, 512*sizeof(WCHAR));
RtlCopyUnicodeString(&fullUniName, &(pFileObject->FileName));
////////////////////////////////////////////////////////////////////////
//Get extension name
RtlInitEmptyUnicodeString(&extName, extNameBuffer, 256*sizeof(WCHAR));
for (i = 0; i < fullName.Length; i++)
{
if (L’.’ == fullName.Buffer[i])
{
USHORT nIndex = 0;
USHORT j;
extName.Length = fullName.Length - i - 1;
for (j = i+1; j < fullName.Length; j++,nIndex++)
{
//extName.Buffer[nIndex] = fullName.Buffer[j]; // If add, BSOD
;//not BSOD
}
break;
}
}
return SfPassThrough(DeviceObject,Irp);
}
}