Building IRP failed ...

Hi all , i have written a function to find out if a file object is related to a
directory or to a file . here’s my code :

BOOLEAN FuncQueryFileInformation( PDEVICE_OBJECT DeviceObject,
PFILE_OBJECT FileObject,
PFILE_STANDARD_INFORMATION FileInformation, ULONG
FileInformationLength )
{
PIRP irp;
KEVENT event;
IO_STATUS_BLOCK IoStatusBlock;
PIO_STACK_LOCATION ioStackLocation;

DbgPrint((“Getting file information for (%x)\n”, FileObject));

KeInitializeEvent(&event, SynchronizationEvent, FALSE);

irp = IoAllocateIrp(DeviceObject->StackSize, FALSE);

if (!irp) {

return FALSE;
}

irp->AssociatedIrp.SystemBuffer = FileInformation;
irp->UserEvent = &event;
irp->UserIosb = &IoStatusBlock;
irp->Tail.Overlay.Thread = PsGetCurrentThread();
irp->Tail.Overlay.OriginalFileObject = FileObject;
irp->RequestorMode = KernelMode;
irp->Flags = 0;

ioStackLocation = IoGetNextIrpStackLocation(irp);
ioStackLocation->MajorFunction = IRP_MJ_QUERY_INFORMATION;
ioStackLocation->DeviceObject = DeviceObject;
ioStackLocation->FileObject = FileObject;
ioStackLocation->Parameters.QueryFile.Length = FileInformationLength;
ioStackLocation->Parameters.QueryFile.FileInformationClass =
FileStandardInformation ;

IoSetCompletionRoutine(irp, FuncQueryFileInformationComplete, 0, TRUE, TRUE,
TRUE);

(void) IoCallDriver(DeviceObject, irp);

KeWaitForSingleObject(&event, Executive, KernelMode, TRUE, 0);

return NT_SUCCESS( IoStatusBlock.Status );
}

NTSTATUS FuncQueryFileInformationComplete(PDEVICE_OBJECT DeviceObject,
PIRP Irp,
PVOID Context)
{
*Irp->UserIosb = Irp->IoStatus;

if( !NT_SUCCESS(Irp->IoStatus.Status) ) {

DbgPrint((" ERROR ON IRP: %x\n", Irp->IoStatus.Status ));
}

KeSetEvent(Irp->UserEvent, 0, FALSE);

IoFreeIrp(Irp);

return STATUS_MORE_PROCESSING_REQUIRED;
}

what’s wrong with these routines ? why they allways returns
“STATUS_INVALID_PARAMETER” ?

thanks.

You do not initialize the following fields in the irp, the are private to the io manager

********
irp->UserEvent = &event;
irp->UserIosb = &IoStatusBlock;
irp->Tail.Overlay.Thread = PsGetCurrentThread();
irp->Tail.Overlay.OriginalFileObject = FileObject;
irp->RequestorMode = KernelMode;
irp->Flags = 0;
**********
Instead, use one of the IoBuildXxx apis to allocate a threaded irp and then format the next stack location as needed.

d

Sent from my phone with no t9, all spilling mistakes are not intentional.

-----Original Message-----
From: xxxxx@yahoo.com
Sent: Saturday, December 20, 2008 4:49 AM
To: Windows System Software Devs Interest List
Subject: [ntdev] Building IRP failed …

Hi all , i have written a function to find out if a file object is related to a
directory or to a file . here’s my code :

BOOLEAN FuncQueryFileInformation( PDEVICE_OBJECT DeviceObject,
PFILE_OBJECT FileObject,
PFILE_STANDARD_INFORMATION FileInformation, ULONG
FileInformationLength )
{
PIRP irp;
KEVENT event;
IO_STATUS_BLOCK IoStatusBlock;
PIO_STACK_LOCATION ioStackLocation;

DbgPrint((“Getting file information for (%x)\n”, FileObject));

KeInitializeEvent(&event, SynchronizationEvent, FALSE);

irp = IoAllocateIrp(DeviceObject->StackSize, FALSE);

if (!irp) {

return FALSE;
}

irp->AssociatedIrp.SystemBuffer = FileInformation;
irp->UserEvent = &event;
irp->UserIosb = &IoStatusBlock;
irp->Tail.Overlay.Thread = PsGetCurrentThread();
irp->Tail.Overlay.OriginalFileObject = FileObject;
irp->RequestorMode = KernelMode;
irp->Flags = 0;

ioStackLocation = IoGetNextIrpStackLocation(irp);
ioStackLocation->MajorFunction = IRP_MJ_QUERY_INFORMATION;
ioStackLocation->DeviceObject = DeviceObject;
ioStackLocation->FileObject = FileObject;
ioStackLocation->Parameters.QueryFile.Length = FileInformationLength;
ioStackLocation->Parameters.QueryFile.FileInformationClass =
FileStandardInformation ;

IoSetCompletionRoutine(irp, FuncQueryFileInformationComplete, 0, TRUE, TRUE,
TRUE);

(void) IoCallDriver(DeviceObject, irp);

KeWaitForSingleObject(&event, Executive, KernelMode, TRUE, 0);

return NT_SUCCESS( IoStatusBlock.Status );
}

NTSTATUS FuncQueryFileInformationComplete(PDEVICE_OBJECT DeviceObject,
PIRP Irp,
PVOID Context)
{
*Irp->UserIosb = Irp->IoStatus;

if( !NT_SUCCESS(Irp->IoStatus.Status) ) {

DbgPrint((" ERROR ON IRP: %x\n", Irp->IoStatus.Status ));
}

KeSetEvent(Irp->UserEvent, 0, FALSE);

IoFreeIrp(Irp);

return STATUS_MORE_PROCESSING_REQUIRED;
}

what’s wrong with these routines ? why they allways returns
“STATUS_INVALID_PARAMETER” ?

thanks.


NTDEV is sponsored by OSR

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

To unsubscribe, visit the List Server section of OSR Online at http://www.osronline.com/page.cfm?name=ListServer