Fix IopCloseFile: Use IRP_SYNC_API flag, use local stack event, get the right deviceobject if FO_DIRECT_DEVICE_OPEN is set, set IRP_CLOSE_OPERATION flag.

svn path=/trunk/; revision=14921
This commit is contained in:
Alex Ionescu 2005-05-01 19:46:51 +00:00
parent f7695b0f53
commit aa1fd35178

View file

@ -183,7 +183,6 @@ IopDeleteFile(PVOID ObjectBody)
NTSTATUS Status; NTSTATUS Status;
KEVENT Event; KEVENT Event;
PDEVICE_OBJECT DeviceObject; PDEVICE_OBJECT DeviceObject;
IO_STATUS_BLOCK IoStatusBlock;
DPRINT("IopDeleteFile()\n"); DPRINT("IopDeleteFile()\n");
@ -208,9 +207,9 @@ IopDeleteFile(PVOID ObjectBody)
/* Set it up */ /* Set it up */
Irp->UserEvent = &Event; Irp->UserEvent = &Event;
Irp->UserIosb = &IoStatusBlock; Irp->UserIosb = &Irp->IoStatus;
Irp->Tail.Overlay.Thread = PsGetCurrentThread(); Irp->Tail.Overlay.Thread = PsGetCurrentThread();
Irp->Tail.Overlay.OriginalFileObject= FileObject; Irp->Tail.Overlay.OriginalFileObject = FileObject;
Irp->Flags = IRP_CLOSE_OPERATION | IRP_SYNCHRONOUS_API; Irp->Flags = IRP_CLOSE_OPERATION | IRP_SYNCHRONOUS_API;
/* Set up Stack Pointer Data */ /* Set up Stack Pointer Data */
@ -494,46 +493,52 @@ IopCloseFile(PVOID ObjectBody,
ULONG HandleCount) ULONG HandleCount)
{ {
PFILE_OBJECT FileObject = (PFILE_OBJECT)ObjectBody; PFILE_OBJECT FileObject = (PFILE_OBJECT)ObjectBody;
KEVENT Event;
PIRP Irp; PIRP Irp;
PIO_STACK_LOCATION StackPtr; PIO_STACK_LOCATION StackPtr;
NTSTATUS Status; NTSTATUS Status;
PDEVICE_OBJECT DeviceObject;
DPRINT("IopCloseFile()\n"); DPRINT("IopCloseFile()\n");
if (HandleCount > 1 || FileObject->DeviceObject == NULL) if (HandleCount > 1 || FileObject->DeviceObject == NULL) return;
/* Check if this is a direct open or not */
if (FileObject->Flags & FO_DIRECT_DEVICE_OPEN)
{ {
return; DeviceObject = IoGetAttachedDevice(FileObject->DeviceObject);
}
else
{
DeviceObject = IoGetRelatedDeviceObject(FileObject);
} }
#if 0 /* Clear and set up Events */
//NOTE: Allmost certain that the latest changes to I/O Mgr makes this redundant (OriginalFileObject case) KeClearEvent(&FileObject->Event);
ObReferenceObjectByPointer(FileObject, KeInitializeEvent(&Event, SynchronizationEvent, FALSE);
STANDARD_RIGHTS_REQUIRED,
IoFileObjectType,
UserMode);
#endif
KeResetEvent( &FileObject->Event ); /* Allocate an IRP */
Irp = IoAllocateIrp(DeviceObject->StackSize, TRUE);
IO_STATUS_BLOCK Dummy; /* Set it up */
/* WRONG WRONG WRONG WRONG!!!!!! */ Irp->UserEvent = &Event;
Irp = IoBuildSynchronousFsdRequest(IRP_MJ_CLEANUP,
FileObject->DeviceObject,
NULL,
0,
NULL,
&FileObject->Event,
&Dummy);
/* Hack to fix the above WRONG WRONG WRONG WRONG CODE!!! */
Irp->UserIosb = &Irp->IoStatus; Irp->UserIosb = &Irp->IoStatus;
Irp->Tail.Overlay.Thread = PsGetCurrentThread();
Irp->Tail.Overlay.OriginalFileObject = FileObject;
Irp->Flags = IRP_CLOSE_OPERATION | IRP_SYNCHRONOUS_API;
/* Set up Stack Pointer Data */
StackPtr = IoGetNextIrpStackLocation(Irp); StackPtr = IoGetNextIrpStackLocation(Irp);
StackPtr->MajorFunction = IRP_MJ_CLEANUP;
StackPtr->FileObject = FileObject; StackPtr->FileObject = FileObject;
Status = IoCallDriver(FileObject->DeviceObject, Irp); /* Call the FS Driver */
Status = IoCallDriver(DeviceObject, Irp);
/* Wait for completion */
if (Status == STATUS_PENDING) if (Status == STATUS_PENDING)
{ {
KeWaitForSingleObject(&FileObject->Event, Executive, KernelMode, FALSE, NULL); KeWaitForSingleObject(&Event, Executive, KernelMode, FALSE, NULL);
} }
} }