Hi,
Using sfilter as my "skeleton" code, I tried to get the deviceobject using
IoGetDeviceObjectPointer in SfCreate routine.
But it somehow always give be a blue screen at IoGetDeviceObjectPointer
routine.
Did I did anything wrong?
or I cannot use this routine in SfCreate?
hope you can help.
thank you
cheers,
vincent
=================================================
NTSTATUS
SfCreate (
IN PDEVICE_OBJECT DeviceObject,
IN PIRP Irp
)
{
NTSTATUS status;
PAGED_CODE();
if (DeviceObject == FsDeviceObject) {
Irp->IoStatus.Status = STATUS_SUCCESS;
Irp->IoStatus.Information = FILE_OPENED;
IoCompleteRequest( Irp, IO_NO_INCREMENT );
return STATUS_SUCCESS;
}
ASSERT(IS_MY_DEVICE_EXTENSION( DeviceObject->DeviceExtension ));
if (!SfDebug) {
//
// Don't put us on the stack then call the next driver
//
POBJECT_NAME_INFORMATION nameInfo;
PIO_STACK_LOCATION myIrpSp;
ULONG size;
#define BUFFER_SIZE 2048
UNICODE_STRING VolName;
ULONG BufLen;
PDEVICE_OBJECT DeviceObj;
PFILE_OBJECT FileObj;
myIrpSp = IoGetCurrentIrpStackLocation( Irp );
if (nameInfo = ExAllocatePool( NonPagedPool, BUFFER_SIZE ))
{
if (myIrpSp->FileObject->FileName.Length) {
ObQueryNameString(
myIrpSp->FileObject,
nameInfo,
BUFFER_SIZE,
&size );
} else {
ObQueryNameString(
myIrpSp->FileObject->DeviceObject,
nameInfo,
BUFFER_SIZE,
&size );
}
}
if (wcscmp (nameInfo->Name.Buffer, L"\Device\HarddiskVolume1") != 0)
{
DbgPrint( "SFILTER: Opened %ws\n", nameInfo->Name.Buffer );
RtlInitUnicodeString(&VolName, nameInfo->Name.Buffer);
BufLen = sizeof (FILE_OBJECT);
FileObj =(PFILE_OBJECT) ExAllocatePool( NonPagedPool, BufLen);
BufLen = sizeof (DEVICE_OBJECT);
DeviceObj = (PDEVICE_OBJECT)ExAllocatePool( NonPagedPool, BufLen);
IoGetDeviceObjectPointer (&VolName, FILE_READ_DATA, &FileObj, &DeviceObj);
ExFreePool (FileObj);
ExFreePool (DeviceObj);
}
ExFreePool( nameInfo );
} else {
KEVENT waitEvent;
POBJECT_NAME_INFORMATION nameInfo;
PFILE_OBJECT savedFileObject;
PIO_STACK_LOCATION myIrpSp;
ULONG savedCreateOptions;
ULONG size;
NTSTATUS localStatus;
define BUFFER_SIZE 2048
//
// Get the current IRP stack and save some information we will need
// after the create has completed.
//
myIrpSp = IoGetCurrentIrpStackLocation( Irp );
savedFileObject = myIrpSp->FileObject;
savedCreateOptions = myIrpSp->Parameters.Create.Options;
ASSERT(savedFileObject);
//
// Initialize an event to wait for the completion routine to occur
//
KeInitializeEvent( &waitEvent, SynchronizationEvent, FALSE );
//
// Copy the stack and set our Completion routine
//
IoCopyCurrentIrpStackLocationToNext( Irp );
IoSetCompletionRoutine(
Irp,
SfCreateCompletion,
&waitEvent,
TRUE,
FALSE,
FALSE );
//
// Call the next driver in the stack.
//
status = IoCallDriver(
((PDEVICE_EXTENSION)DeviceObject->DeviceExtension)->NextDeviceObject, Irp );
//
// Wait for the completion routine to be called
//
if (STATUS_PENDING == status) {
localStatus = KeWaitForSingleObject(&waitEvent, Executive, KernelMode,
FALSE, NULL);
ASSERT(NT_SUCCESS(localStatus));
}
//
// Retrieve and display the filename
//
if (SfDebug & (SFDEBUG_GET_NAME | SFDEBUG_DISPLAY_NAME)) {
if (nameInfo = ExAllocatePool( NonPagedPool, BUFFER_SIZE )) {
//
// A buffer was successfully allocated. Attempt to
determine
// whether this was a volume or a file open, based on the
length
// of the file's name. If it was a volume open, then
simply
// query the name of the device. Note that it is not legal
to
// perform a relative file open using a NULL name to obtain
another
// handle to the same file, so checking the
RelatedFileObject field
// is unnecessary.
//
if (savedFileObject->FileName.Length) {
localStatus = ObQueryNameString(
savedFileObject,
nameInfo,
BUFFER_SIZE,
&size );
} else {
localStatus = ObQueryNameString(
savedFileObject->DeviceObject,
nameInfo,
BUFFER_SIZE,
&size );
}
//
// If querying the name was successful, actually print the
name
// on the debug terminal.
//
if (NT_SUCCESS( localStatus )) {
if (SfDebug & SFDEBUG_DISPLAY_NAME) {
if (savedCreateOptions & FILE_OPEN_BY_FILE_ID) {
DbgPrint( "SFILTER: Opened %ws\(FID)\n",
nameInfo->Name.Buffer );
} else {
DbgPrint( "SFILTER: Opened %ws\n",
nameInfo->Name.Buffer );
}
}
} else {
DbgPrint( "SFILTER: Could not get the name for %p,
status=%08x\n",
savedFileObject,
localStatus );
if ((SfDebug & SFDEBUG_BREAK_IF_NO_NAME)) {
DbgBreakPoint();
}
}
ExFreePool( nameInfo );
}
}
}
return status;
}
Get 10mb of inbox space with MSN Hotmail Extra Storage
http://join.msn.com/?pgmarket=en-sg