[ros-diffs] [ion] 26258: - Refactor device attachment into a private routine. - We shouldn't allow attaching to a device that's still initlizaing, but ROS currently does because of some device that tries to do this, in the PnP manager or early boot-phase drivers (it has an auto-generated name). Please fix this!

ion at svn.reactos.org ion at svn.reactos.org
Wed Apr 4 05:19:27 CEST 2007


Author: ion
Date: Wed Apr  4 07:19:27 2007
New Revision: 26258

URL: http://svn.reactos.org/svn/reactos?rev=26258&view=rev
Log:
- Refactor device attachment into a private routine.
- We shouldn't allow attaching to a device that's still initlizaing, but ROS currently does because of some device that tries to do this, in the PnP manager or early boot-phase drivers (it has an auto-generated name). Please fix this!

Modified:
    trunk/reactos/ntoskrnl/io/iomgr/device.c

Modified: trunk/reactos/ntoskrnl/io/iomgr/device.c
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/io/iomgr/device.c?rev=26258&r1=26257&r2=26258&view=diff
==============================================================================
--- trunk/reactos/ntoskrnl/io/iomgr/device.c (original)
+++ trunk/reactos/ntoskrnl/io/iomgr/device.c Wed Apr  4 07:19:27 2007
@@ -37,9 +37,18 @@
     SourceDeviceExtension = IoGetDevObjExtension(SourceDevice);
     ASSERT(SourceDeviceExtension->AttachedTo == NULL);
 
+    /* FIXME: ROS HACK */
+    if (AttachedDevice->Flags & DO_DEVICE_INITIALIZING)
+    {
+        DPRINT1("Io: CRITICAL: Allowing attach to device which hasn't "
+                "cleared its DO_DEVICE_INITIALIZING flag. Fix the damn "
+                "thing: %p %wZ\n",
+                AttachedDevice,
+                &AttachedDevice->DriverObject->DriverName);
+    }
+
     /* Make sure that it's in a correct state */
-    if ((AttachedDevice->Flags & DO_DEVICE_INITIALIZING) ||
-        (IoGetDevObjExtension(AttachedDevice)->ExtensionFlags &
+    if ((IoGetDevObjExtension(AttachedDevice)->ExtensionFlags &
          (DOE_UNLOAD_PENDING |
           DOE_DELETE_PENDING |
           DOE_REMOVE_PENDING |
@@ -629,16 +638,10 @@
 IoAttachDeviceToDeviceStack(IN PDEVICE_OBJECT SourceDevice,
                             IN PDEVICE_OBJECT TargetDevice)
 {
-    NTSTATUS Status;
-    PDEVICE_OBJECT LocalAttach;
-
     /* Attach it safely */
-    Status = IoAttachDeviceToDeviceStackSafe(SourceDevice,
-                                             TargetDevice,
-                                             &LocalAttach);
-
-    /* Return it */
-    return LocalAttach;
+    return IopAttachDeviceToDeviceStackSafe(SourceDevice,
+                                            TargetDevice,
+                                            NULL);
 }
 
 /*
@@ -650,41 +653,16 @@
                                 IN PDEVICE_OBJECT TargetDevice,
                                 IN OUT PDEVICE_OBJECT *AttachedToDeviceObject)
 {
-    PDEVICE_OBJECT AttachedDevice;
-    PEXTENDED_DEVOBJ_EXTENSION SourceDeviceExtension;
-
-    /* Get the Attached Device and source extension */
-    AttachedDevice = IoGetAttachedDevice(TargetDevice);
-    SourceDeviceExtension = IoGetDevObjExtension(SourceDevice);
-
-    /* Make sure that it's in a correct state */
-    if (!IoGetDevObjExtension(AttachedDevice)->ExtensionFlags &
-        (DOE_UNLOAD_PENDING |
-         DOE_DELETE_PENDING |
-         DOE_REMOVE_PENDING |
-         DOE_REMOVE_PROCESSED))
-    {
-        /* Update atached device fields */
-        AttachedDevice->AttachedDevice = SourceDevice;
-        AttachedDevice->Spare1++;
-
-        /* Update the source with the attached data */
-        SourceDevice->StackSize = AttachedDevice->StackSize + 1;
-        SourceDevice->AlignmentRequirement = AttachedDevice->
-                                             AlignmentRequirement;
-        SourceDevice->SectorSize = AttachedDevice->SectorSize;
-
-        /* Set the attachment in the device extension */
-        SourceDeviceExtension->AttachedTo = AttachedDevice;
-    }
-    else
-    {
-        /* Device was unloading or being removed */
-        AttachedDevice = NULL;
-    }
-
-    /* Return the attached device */
-    *AttachedToDeviceObject = AttachedDevice;
+    /* Call the internal function */
+    if (!IopAttachDeviceToDeviceStackSafe(SourceDevice,
+                                          TargetDevice,
+                                          AttachedToDeviceObject))
+    {
+        /* Nothing found */
+        return STATUS_NO_SUCH_DEVICE;
+    }
+
+    /* Success! */
     return STATUS_SUCCESS;
 }
 




More information about the Ros-diffs mailing list