[MOUNTMGR] Avoid an endless loop while sending GUID_IO_VOLUME_NAME_CHANGE notification
[reactos.git] / drivers / filters / mountmgr / notify.c
index de1e573..2c7a05d 100644 (file)
@@ -119,11 +119,11 @@ SendOnlineNotificationWorker(IN PVOID Parameter)
     {
         /* Queue a new one for execution */
         Head = RemoveHeadList(&(DeviceExtension->OnlineNotificationListHead));
-        NewWorkItem = CONTAINING_RECORD(Head, ONLINE_NOTIFICATION_WORK_ITEM, List);
+        NewWorkItem = CONTAINING_RECORD(Head, ONLINE_NOTIFICATION_WORK_ITEM, WorkItem.List);
         KeReleaseSpinLock(&(DeviceExtension->WorkerLock), OldIrql);
-        NewWorkItem->List.Blink = NULL;
-        NewWorkItem->List.Flink = NULL;
-        ExQueueWorkItem((PWORK_QUEUE_ITEM)NewWorkItem, DelayedWorkQueue);
+        NewWorkItem->WorkItem.List.Blink = NULL;
+        NewWorkItem->WorkItem.List.Flink = NULL;
+        ExQueueWorkItem(&NewWorkItem->WorkItem, DelayedWorkQueue);
     }
     else
     {
@@ -155,10 +155,8 @@ PostOnlineNotification(IN PDEVICE_EXTENSION DeviceExtension,
         return;
     }
 
-    WorkItem->List.Flink = NULL;
+    ExInitializeWorkItem(&WorkItem->WorkItem, SendOnlineNotificationWorker, WorkItem);
     WorkItem->DeviceExtension = DeviceExtension;
-    WorkItem->WorkerRoutine = SendOnlineNotificationWorker;
-    WorkItem->Parameter = WorkItem;
     WorkItem->SymbolicName.Length = SymbolicName->Length;
     WorkItem->SymbolicName.MaximumLength = SymbolicName->Length + sizeof(WCHAR);
     WorkItem->SymbolicName.Buffer = AllocatePool(WorkItem->SymbolicName.MaximumLength);
@@ -179,12 +177,12 @@ PostOnlineNotification(IN PDEVICE_EXTENSION DeviceExtension,
     {
         /* Queue that one for execution */
         DeviceExtension->OnlineNotificationWorkerActive = 1;
-        ExQueueWorkItem((PWORK_QUEUE_ITEM)WorkItem, DelayedWorkQueue);
+        ExQueueWorkItem(&WorkItem->WorkItem, DelayedWorkQueue);
     }
     else
     {
         /* Otherwise, just put it in the queue list */
-        InsertTailList(&(DeviceExtension->OnlineNotificationListHead), &(WorkItem->List));
+        InsertTailList(&(DeviceExtension->OnlineNotificationListHead), &(WorkItem->WorkItem.List));
     }
 
     KeReleaseSpinLock(&(DeviceExtension->WorkerLock), OldIrql);
@@ -249,12 +247,14 @@ MountMgrTargetDeviceNotification(IN PVOID NotificationStructure,
      */
     else if (IsEqualGUID(&(Notification->Event), &GUID_IO_VOLUME_MOUNT))
     {
+        /* If we were already mounted, then mark us unmounted */
         if (InterlockedCompareExchange(&(DeviceInformation->MountState),
                                        FALSE,
-                                       TRUE) == TRUE)
+                                       FALSE) == TRUE)
         {
             InterlockedDecrement(&(DeviceInformation->MountState));
         }
+        /* Otherwise, start mounting the device and first, reconcile its DB if required */
         else
         {
             if (DeviceInformation->NeedsReconcile)
@@ -328,11 +328,12 @@ MountMgrNotify(IN PDEVICE_EXTENSION DeviceExtension)
     {
         NextEntry = RemoveHeadList(&(DeviceExtension->IrpListHead));
         Irp = CONTAINING_RECORD(NextEntry, IRP, Tail.Overlay.ListEntry);
+        IoSetCancelRoutine(Irp, NULL);
         InsertTailList(&CopyList, &(Irp->Tail.Overlay.ListEntry));
     }
     IoReleaseCancelSpinLock(OldIrql);
 
-    /* Then, notifiy them one by one */
+    /* Then, notify them one by one */
     while (!IsListEmpty(&CopyList))
     {
         NextEntry = RemoveHeadList(&CopyList);
@@ -369,8 +370,9 @@ MountMgrNotifyNameChange(IN PDEVICE_EXTENSION DeviceExtension,
     if (ValidateVolume)
     {
         /* Then, ensure we can find the device */
-        NextEntry = DeviceExtension->DeviceListHead.Flink;
-        while (NextEntry != &(DeviceExtension->DeviceListHead))
+        for (NextEntry = DeviceExtension->DeviceListHead.Flink;
+             NextEntry != &DeviceExtension->DeviceListHead;
+             NextEntry = NextEntry->Flink)
         {
             DeviceInformation = CONTAINING_RECORD(NextEntry, DEVICE_INFORMATION, DeviceListEntry);
             if (RtlCompareUnicodeString(DeviceName, &(DeviceInformation->DeviceName), TRUE) == 0)
@@ -379,8 +381,9 @@ MountMgrNotifyNameChange(IN PDEVICE_EXTENSION DeviceExtension,
             }
         }
 
+        /* No need to notify for a PnP device or if we didn't find the device */
         if (NextEntry == &(DeviceExtension->DeviceListHead) ||
-            !DeviceInformation->Volume)
+            !DeviceInformation->ManuallyRegistered)
         {
             return;
         }