Dear Sir,
I have a program which sends “some data” to its kernel level program
through DeviceIoCrontrol function.
I want to make the kernel program independent of the user level code. Can
we make our own IRP having input as the data that we were sending from
user mode (ie.
ioStackLocation->Parameters.DeviceIoControl.InputBufferLength ) and send
it to the code where this data is required ?
How can we provide the functionality of DeviceIoControl in the kernel
level code ?
Please suggest a way out.
Rohit
You can create Irps, fill them in (including stack location) and send them
to any driver. As for sending it to yourself? Yes, you certainly can. I
did that by mistake once! Lots of fun with that one :-).
There must be some PnP examples in the DDK showing how to build and send
an Irp (they’ll be PnP Irps but they show the principles), but here are
the key steps to follow anyway…
(beware, there are other valid variations on this, and there’s plenty
missing between the lines!)
PDEVICE_OBJECT TargetDeviceObject = ;
CCHAR NumberOfStackLocations = TargetDeviceObject->StackSize;
USHORT IrpSize = IoSizeOfIrp(NumberOfStackLocations);
Irp = ExAllocatePool(NonPagedPool, IrpSize);
RtlZeroMemory(Irp, IrpSize);
IoInitializeIrp(Irp, IrpSize, NumberOfStackLocations);
// set up the Irp here
PIO_STACK_LOCATION Stack = IoGetNextIrpStackLocation(Irp);
// set up the stack location here
IoCallDriver(TargetDeviceObject);
To be independent of user mode, I guess you will want to create and start
a system thread to issue this Irp (every so often). Last time I did that I
used PsCreateSystemThread() but that was a while back…
You can launch that thread from addDevice() or any convenient point after
you have a device object to use.
Surely, by IoBuildDeviceIoControlRequest and IoCallDriver.
----- Original Message -----
From: “Rohit”
To: “File Systems Developers”
Sent: Friday, July 25, 2003 3:51 PM
Subject: [ntfsd] Create your own IRP ??
> Dear Sir,
>
> I have a program which sends “some data” to its kernel level program
> through DeviceIoCrontrol function.
>
> I want to make the kernel program independent of the user level code. Can
> we make our own IRP having input as the data that we were sending from
> user mode (ie.
> ioStackLocation->Parameters.DeviceIoControl.InputBufferLength ) and send
> it to the code where this data is required ?
>
> How can we provide the functionality of DeviceIoControl in the kernel
> level code ?
>
> Please suggest a way out.
>
> Rohit
>
> —
> You are currently subscribed to ntfsd as: xxxxx@storagecraft.com
> To unsubscribe send a blank email to xxxxx@lists.osr.com
Yes that’s much easier, but it isn’t robust programming.
(I’ve gotta admit I missed that, and am wriggling out of it!)
I’m fairly sure that IoBuildDeviceIoControlRequest() builds an Irp to pass
down to the next driver. In this case that Irp will have one too few stack
locations (since you send the Irp to yourself).
That shouldn’t matter so long as you can be sure your driver will never
fail to recognise it, and won’t ever pass it down. Fair assumption? I
don’t know.
Jack.
No, IoBuildDeviceIoControlRequest will create the IRP to be passed from top of
stack, and thus having enough stack locations.
Max
----- Original Message -----
From: “Jack Heeley”
To: “File Systems Developers”
Sent: Sunday, July 27, 2003 7:17 PM
Subject: [ntfsd] Re: Create your own IRP ??
> Yes that’s much easier, but it isn’t robust programming.
>
> (I’ve gotta admit I missed that, and am wriggling out of it!)
>
> I’m fairly sure that IoBuildDeviceIoControlRequest() builds an Irp to pass
> down to the next driver. In this case that Irp will have one too few stack
> locations (since you send the Irp to yourself).
>
> That shouldn’t matter so long as you can be sure your driver will never
> fail to recognise it, and won’t ever pass it down. Fair assumption? I
> don’t know.
>
> Jack.
>
> —
> You are currently subscribed to ntfsd as: xxxxx@storagecraft.com
> To unsubscribe send a blank email to xxxxx@lists.osr.com
I stand corrected, thanks.
Jack.