Author: ion
Date: Fri Jul 7 21:53:34 2006
New Revision: 22905
URL:
http://svn.reactos.org/svn/reactos?rev=22905&view=rev
Log:
- Add some more proper handling of ref/dereferencing in IopParseDevice.
Modified:
trunk/reactos/ntoskrnl/io/iomgr/file.c
Modified: trunk/reactos/ntoskrnl/io/iomgr/file.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/io/iomgr/file.c?r…
==============================================================================
--- trunk/reactos/ntoskrnl/io/iomgr/file.c (original)
+++ trunk/reactos/ntoskrnl/io/iomgr/file.c Fri Jul 7 21:53:34 2006
@@ -40,6 +40,7 @@
IO_STATUS_BLOCK IoStatusBlock;
BOOLEAN DirectOpen = FALSE;
OBJECT_ATTRIBUTES ObjectAttributes;
+ BOOLEAN OpenCancelled;
DPRINT("IopParseDevice:\n"
"DeviceObject : %p\n"
"RelatedFileObject : %p\n"
@@ -63,7 +64,8 @@
}
/* Reference the DO FIXME: Don't allow failure */
- Status = IopReferenceDeviceObject(OriginalDeviceObject);
+ //Status = IopReferenceDeviceObject(OriginalDeviceObject);
+ OriginalDeviceObject->ReferenceCount++;
/* Map the generic mask and set the new mapping in the access state */
RtlMapGenericMask(&AccessState->RemainingDesiredAccess,
@@ -192,7 +194,6 @@
SecurityContext.FullCreateOptions = OpenPacket->CreateOptions;
KeInitializeEvent(&FileObject->Lock, SynchronizationEvent, TRUE);
- KeInitializeEvent(&FileObject->Event, NotificationEvent, FALSE);
Irp = IoAllocateIrp(DeviceObject->StackSize, FALSE);
if (!Irp) return STATUS_UNSUCCESSFUL;
@@ -275,12 +276,16 @@
/* Reference the file object and call the driver */
ObReferenceObject(FileObject);
+
+ /* Initialize the File Object event and set the FO */
+ KeInitializeEvent(&FileObject->Event, NotificationEvent, FALSE);
OpenPacket->FileObject = FileObject;
- Status = IoCallDriver(FileObject->DeviceObject, Irp );
+
+ /* Queue the IRP and call the driver */
+ //IopQueueIrpToThread(Irp);
+ Status = IoCallDriver(DeviceObject, Irp);
/* Copy the status block */
- OpenPacket->Information = IoStatusBlock.Information;
- OpenPacket->FinalStatus = IoStatusBlock.Status;
if (Status == STATUS_PENDING)
{
KeWaitForSingleObject(&FileObject->Event,
@@ -309,6 +314,9 @@
}
#endif
+ /* Copy the I/O Status */
+ OpenPacket->Information = IoStatusBlock.Information;
+
/* The driver failed to create the file */
if (!NT_SUCCESS(Status))
{
@@ -323,11 +331,17 @@
/* Clear its device object */
FileObject->DeviceObject = NULL;
+ /* Save this now because the FO might go away */
+ OpenCancelled = FileObject->Flags & FO_FILE_OPEN_CANCELLED;
+
/* Clear the file object in the open packet */
OpenPacket->FileObject = NULL;
/* Dereference the file object */
ObDereferenceObject(FileObject);
+
+ /* Unless the driver canelled the open, dereference the VPB */
+ if (!(OpenCancelled) && (Vpb)) IopDereferenceVpb(Vpb);
/* Set the status and return */
OpenPacket->FinalStatus = Status;