Hello, Stefano,
I am not sure I understand your situation. Please allow me to guess,
and throw in some random things I’ve learned regarding Create/Close, and
perhaps with your response we can make progress on your issue?
Create() and Close() are irp functions with semantics that look easy at
first, but really have some things that must be done or things will not
work properly. For example, it would seem that this is a “good” create
handler:
NTSTATUS DispatchCreate(…)
{
NTSTATUS status = DoMyCreateHandling();
if (SUCCEEDED(status))
{
status = ForwardIrpToNextLowerDriver();
}
else
{
Irp->IoStatus.Status = status;
Irp->IoStatus.Information = 0;
}
return status;
}
However, the problem with the above code is that, if a lower level
driver fails the Create(), then you have kept state for a non-existant
handle. Similiarly, you cannot simply forward the Create() and handle
the Irp after all the lower level drivers, unless you can guarantee
success (i.e. no memory allocation, etc.). This is because The IO
system does not send a Close() for Create() irps that failed (for good
reason).
So, the only “correct” manner to handle a create irp is as follows:
DispatchCreate()
{
Validate Parameters (failure point)
Allocate all resources required for this request (failure point)
Synchronously forward to lower level drivers (failure point)
<<< IF SUCCESS AT THIS POINT, NOT ALLOWED TO FAIL THE IRP >>>
Finish handling the irp
}
When this general logic is applied at all levels of the stack, there is
never a possibility of having one driver think the create succeeded when
it really failed.
If you are already following these rules, can you describe another way
to end up with a succeeded Create irp where the caller gets a failure?
Hope that helps,
.
-----Original Message-----
From: Stefano Mora - EOS S.r.l. [mailto:xxxxx@eos.pr.it]
Sent: Wednesday, April 13, 2005 7:53 AM
Subject: Closing an erroneous DispatchCreate()
Hi all,
i need to handle correctly a post-DispatchCreate() call that returned an
error.
Tha CreateFile had received an INVALID_HANDLE_VALUE value, so it doesn’t
have sense to call the CloseHandle() function.
Do i need to call ‘manually’ claenup and close functions to clean the
driver
?
I don’t think to call DispatchCleanup and DispatchClose, right ?
Thanks
Ing. Stefano Mora