Author: cgutman
Date: Mon May 30 04:15:27 2011
New Revision: 52003
URL: 
http://svn.reactos.org/svn/reactos?rev=52003&view=rev
Log:
[NTOSKRNL]
- Implement sending GUID_TARGET_DEVICE_QUERY_REMOVE and GUID_TARGET_DEVICE_REMOVE_COMPLETE
notifications
- Fix sending EventCategoryTargetDeviceChange notifications
- Remove some incorrect checks (IRP_MN_START_DEVICE CAN be called for a device that is
already "started")
- Check the final status of the IRP_MN_START_DEVICE request sent after resource
rebalancing and send IRP_MN_REMOVE_DEVICE if it fails
Modified:
    trunk/reactos/ntoskrnl/io/pnpmgr/pnpmgr.c
    trunk/reactos/ntoskrnl/io/pnpmgr/pnpnotify.c
Modified: trunk/reactos/ntoskrnl/io/pnpmgr/pnpmgr.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/io/pnpmgr/pnpmgr.…
==============================================================================
--- trunk/reactos/ntoskrnl/io/pnpmgr/pnpmgr.c [iso-8859-1] (original)
+++ trunk/reactos/ntoskrnl/io/pnpmgr/pnpmgr.c [iso-8859-1] Mon May 30 04:15:27 2011
@@ -160,12 +160,21 @@
 {
     IO_STACK_LOCATION Stack;
     PVOID Dummy;
+    NTSTATUS Status;
     RtlZeroMemory(&Stack, sizeof(IO_STACK_LOCATION));
     Stack.MajorFunction = IRP_MJ_PNP;
     Stack.MinorFunction = IRP_MN_QUERY_REMOVE_DEVICE;
-
-    return IopSynchronousCall(DeviceObject, &Stack, &Dummy);
+
+    Status = IopSynchronousCall(DeviceObject, &Stack, &Dummy);
+
+    IopNotifyPlugPlayNotification(DeviceObject,
+                                  EventCategoryTargetDeviceChange,
+                                  &GUID_TARGET_DEVICE_QUERY_REMOVE,
+                                  NULL,
+                                  NULL);
+
+    return Status;
 }
 NTSTATUS
@@ -195,6 +204,12 @@
     /* Drivers should never fail a IRP_MN_REMOVE_DEVICE request */
     IopSynchronousCall(DeviceObject, &Stack, &Dummy);
+
+    IopNotifyPlugPlayNotification(DeviceObject,
+                                  EventCategoryTargetDeviceChange,
+                                  &GUID_TARGET_DEVICE_REMOVE_COMPLETE,
+                                  NULL,
+                                  NULL);
 }
 VOID
@@ -239,9 +254,6 @@
             DeviceNode->ResourceListTranslated;
     }
-    /* I don't think we set this flag yet */
-    ASSERT(!(DeviceNode->Flags & DNF_STOPPED));
-
     /* Do the call */
     Status = IopSynchronousCall(DeviceObject, &Stack, &Dummy);
     if (!NT_SUCCESS(Status))
@@ -258,6 +270,7 @@
     /* Otherwise, mark us as started */
     DeviceNode->Flags |= DNF_STARTED;
+    DeviceNode->Flags &= ~DNF_STOPPED;
     /* We now need enumeration */
     DeviceNode->Flags |= DNF_NEED_ENUMERATION_ONLY;
@@ -276,9 +289,6 @@
     ASSERT((DeviceNode->Flags & (DNF_RESOURCE_ASSIGNED |
                                  DNF_RESOURCE_REPORTED |
                                  DNF_NO_RESOURCE_REQUIRED)));
-    ASSERT((!(DeviceNode->Flags & (DNF_HAS_PROBLEM |
-                                   DNF_STARTED |
-                                   DNF_START_REQUEST_PENDING))));
     /* Get the device object */
     DeviceObject = DeviceNode->PhysicalDeviceObject;
@@ -327,12 +337,6 @@
    HANDLE InstanceHandle = INVALID_HANDLE_VALUE, ControlHandle = INVALID_HANDLE_VALUE;
    UNICODE_STRING KeyName;
    OBJECT_ATTRIBUTES ObjectAttributes;
-
-   if (((DeviceNode->Flags & DNF_STARTED) && !(DeviceNode->Flags &
DNF_HAS_PROBLEM)) ||
-       (DeviceNode->Flags & DNF_START_REQUEST_PENDING))
-   {
-       return STATUS_SUCCESS;
-   }
    Status = IopAssignDeviceResources(DeviceNode);
    if (!NT_SUCCESS(Status))
@@ -3623,6 +3627,9 @@
         if (NT_SUCCESS(IopQueryStopDevice(PhysicalDeviceObject)))
         {
             IopSendStopDevice(PhysicalDeviceObject);
+
+            DeviceNode->Flags &= ~(DNF_STARTED | DNF_START_REQUEST_PENDING);
+            DeviceNode->Flags |= DNF_STOPPED;
         }
     }
@@ -3665,7 +3672,15 @@
         }
         /* IRP_MN_FILTER_RESOURCE_REQUIREMENTS is called indirectly by IopStartDevice */
-        IopStartDevice(DeviceNode);
+        if (IopStartDevice(DeviceNode) != STATUS_SUCCESS)
+        {
+            DPRINT1("Restart after resource rebalance failed\n");
+
+            DeviceNode->Flags &= ~(DNF_STARTED | DNF_START_REQUEST_PENDING);
+            DeviceNode->Flags |= DNF_START_FAILED;
+
+            IopSendRemoveDevice(PhysicalDeviceObject);
+        }
     }
 }
Modified: trunk/reactos/ntoskrnl/io/pnpmgr/pnpnotify.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/io/pnpmgr/pnpnoti…
==============================================================================
--- trunk/reactos/ntoskrnl/io/pnpmgr/pnpnotify.c [iso-8859-1] (original)
+++ trunk/reactos/ntoskrnl/io/pnpmgr/pnpnotify.c [iso-8859-1] Mon May 30 04:15:27 2011
@@ -119,7 +119,6 @@
                                NotificationInfos->Version = 1;
                                NotificationInfos->Size =
sizeof(TARGET_DEVICE_REMOVAL_NOTIFICATION);
                                RtlCopyMemory(&NotificationInfos->Event, Event,
sizeof(GUID));
-                               NotificationInfos->FileObject =
(PFILE_OBJECT)EventCategoryData1;
                        }
                        else
                        {
@@ -177,22 +176,21 @@
                        }
                        case EventCategoryTargetDeviceChange:
                        {
-                               if (Event != &GUID_PNP_CUSTOM_NOTIFICATION)
-                               {
-                                       if (ChangeEntry->FileObject ==
(PFILE_OBJECT)EventCategoryData1)
-                                               CallCurrentEntry = TRUE;
-                               }
-                               else
-                               {
-                                       Status =
IoGetRelatedTargetDevice(ChangeEntry->FileObject, &EntryDeviceObject);
-                               if (NT_SUCCESS(Status))
-                               {
-                                               if (DeviceObject == EntryDeviceObject)
-                                               {
-
((PTARGET_DEVICE_CUSTOM_NOTIFICATION)NotificationStructure)->FileObject =
ChangeEntry->FileObject;
-                                                       CallCurrentEntry = TRUE;
-                                               }
-                                       }
+                               Status =
IoGetRelatedTargetDevice(ChangeEntry->FileObject, &EntryDeviceObject);
+                       if (NT_SUCCESS(Status))
+                {
+                    if (DeviceObject == EntryDeviceObject)
+                    {
+                        if (Event == &GUID_PNP_CUSTOM_NOTIFICATION)
+                        {
+
((PTARGET_DEVICE_CUSTOM_NOTIFICATION)NotificationStructure)->FileObject =
ChangeEntry->FileObject;
+                        }
+                        else
+                        {
+
((PTARGET_DEVICE_REMOVAL_NOTIFICATION)NotificationStructure)->FileObject =
ChangeEntry->FileObject;
+                        }
+                        CallCurrentEntry = TRUE;
+                    }
                                }
                        }
                        default: