WOW!!!
Thanks! You guys have cause me to revisit my reason for needing to
cancel a file open!
In my case, I needed the canonical filename of a create operations.
There is a problem with related file objects in that their names may be
lost. I was pre-opening the file by sending the request down and
allowing the open to occur. I would then get the canonical name and call
IoCancelFileOpen().
At this point, I would replace the filename in the file object with the
canonical name, NULL the related file object and return STATUS_REPARSE.
This would cause the request to be reissued; unless I wanted to fail the
request. So far, under much stress, I have seen no problems.
But Dooh!
I do not need to do this. I can change the code to get the canonical
name of the, already opened, related file object and then concatenate
the current file object name. I will still need to have a case for open
by ID, but it will probably be a very rare code path.
Jamey
-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Ken Galipeau
Sent: Thursday, December 13, 2001 11:12 PM
To: File Systems Developers
Subject: [ntfsd] Re: Create Sample Code
Jamey,
Here is something I noticed:
first irp sets UserIosb to the IoStatus in the Irp itself while the
second sets it to a local variable. Should they both use the local.
1st IRP does:
irp->UserEvent = &event;
irp->UserIosb = &irp->IoStatus;
2ns IRP does:
irp->UserIosb = &ioStatus;
irp->UserEvent = &event;
Ken
-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com]On Behalf Of Jamey Kirby
Sent: Friday, December 14, 2001 1:47 AM
To: File Systems Developers
Subject: [ntfsd] Re: Create Sample Code
Later?
Don’t keep me in suspense.
Jamey
-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Ravisankar
Pudipeddi
Sent: Thursday, December 13, 2001 6:53 PM
To: File Systems Developers
Subject: [ntfsd] Re: Create Sample Code
Of course, the one BIG problem with the code below is that you are not
checking for failure from IoAllocateIrp(), so the filter will blow up
under low resources conditions… There’s one more issue which I’ll touch
upon later.
Ravi
This posting is provided “AS IS” with no warranties, and confers no
rights. You assume all risk for your use.
-----Original Message-----
From: Jamey Kirby [mailto:xxxxx@storagecraft.com]
Sent: Thursday, December 13, 2001 2:02 AM
To: File Systems Developers
Subject: [ntfsd] Re: Create Sample Code
Here is how we did it:
VOID SciCancelFileOpen(PDEVICE_OBJECT DeviceObject, PFILE_OBJECT
FileObject)
{
PIRP irp;
PIO_STACK_LOCATION irpSp;
KEVENT event;
KIRQL irql;
IO_STATUS_BLOCK ioStatus;
PVPB vpb;
ASSERT(!(FileObject->Flags & FO_HANDLE_CREATED));
KeInitializeEvent(&event, NotificationEvent, FALSE);
KeClearEvent(&FileObject->Event);
irp = IoAllocateIrp(DeviceObject->StackSize, FALSE);
irp->Tail.Overlay.OriginalFileObject = FileObject;
irp->Tail.Overlay.Thread = PsGetCurrentThread();
irp->RequestorMode = KernelMode;
irp->UserEvent = &event;
irp->UserIosb = &irp->IoStatus;
irp->Overlay.AsynchronousParameters.UserApcRoutine =
(PIO_APC_ROUTINE)NULL;
irp->Flags = IRP_SYNCHRONOUS_API | IRP_CLOSE_OPERATION;
irpSp = IoGetNextIrpStackLocation(irp);
irpSp->MajorFunction = IRP_MJ_CLEANUP;
irpSp->FileObject = FileObject;
if (IoCallDriver(DeviceObject, irp) == STATUS_PENDING)
KeWaitForSingleObject(&event, UserRequest, KernelMode, FALSE,
NULL);
irp = IoAllocateIrp(DeviceObject->StackSize, FALSE);
KeClearEvent(&FileObject->Event);
KeClearEvent(&event);
irpSp = IoGetNextIrpStackLocation(irp);
irpSp->MajorFunction = IRP_MJ_CLOSE;
irpSp->FileObject = FileObject;
irp->UserIosb = &ioStatus;
irp->UserEvent = &event;
irp->Tail.Overlay.OriginalFileObject = FileObject;
irp->Tail.Overlay.Thread = PsGetCurrentThread();
irp->AssociatedIrp.SystemBuffer = NULL;
irp->Flags = IRP_CLOSE_OPERATION | IRP_SYNCHRONOUS_API;
vpb = FileObject->Vpb;
// Make sure the VPBs reference count ius adjusted properly;
if (vpb && !(FileObject->Flags & FO_DIRECT_DEVICE_OPEN))
{
IoAcquireVpbSpinLock(&irql);
vpb->ReferenceCount += 0xffffffff;
IoReleaseVpbSpinLock(irql);
}
if (IoCallDriver(DeviceObject, irp) == STATUS_PENDING)
KeWaitForSingleObject(&event, Executive, KernelMode, FALSE,
NULL); }
The only difference in this code and the code we saw in the debugger is
that the w2k version of IoCancelFileOpen() inserts each IRP into the
threads IRP queue. Since we do not have access to IopQueueThreadIrp()
and IopDequeueThreadIrp(), I think those are the names, I wouldhave to
load the checked build to verify, we simply left them out. Not sure if
there are any specific problems with this code that we have yet to find,
but it has been working for quite some time in numerous drivers.
Jamey
-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Peter Viscarola
Sent: Thursday, December 13, 2001 3:00 PM
To: File Systems Developers
Subject: [ntfsd] Re: Create Sample Code
Message"Maxim S. Shatskih" wrote in message
news:xxxxx@ntfsd…
>It is trivial to rev.eng. IoCancelFileOpen from w2k and port it to NT4.
>It just sends CLEANUP and CLOSE IRPs.
>
Gee, I remember writing equivalent code for NT V4, and I seem to
remember there were some tricks to it. And while sending a CLEANUP and
CLOSE is what you need to do, how those are sent so that they work all
the time wasn’t exactly “trivial”. At least not to me.
Then again, at OSR it’s Tony who know about file systems…
Peter
OSR
—
You are currently subscribed to ntfsd as: xxxxx@storagecraft.com To
unsubscribe send a blank email to leave-ntfsd-$subst(‘Recip.MemberIDChar’)@lists.osr.com
—
You are currently subscribed to ntfsd as: xxxxx@windows.microsoft.com
To unsubscribe send a blank email to leave-ntfsd-$subst(‘Recip.MemberIDChar’)@lists.osr.com
—
You are currently subscribed to ntfsd as: xxxxx@storagecraft.com To
unsubscribe send a blank email to leave-ntfsd-$subst(‘Recip.MemberIDChar’)@lists.osr.com
—
You are currently subscribed to ntfsd as: xxxxx@legato.com
To unsubscribe send a blank email to leave-ntfsd-$subst(‘Recip.MemberIDChar’)@lists.osr.com
—
You are currently subscribed to ntfsd as: xxxxx@storagecraft.com To
unsubscribe send a blank email to leave-ntfsd-$subst(‘Recip.MemberIDChar’)@lists.osr.com
—
You are currently subscribed to ntfsd as: $subst(‘Recip.EmailAddr’)
To unsubscribe send a blank email to leave-ntfsd-$subst(‘Recip.MemberIDChar’)@lists.osr.com