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