[NTOSKRNL]
authorCameron Gutman <aicommander@gmail.com>
Wed, 9 Jun 2010 20:04:39 +0000 (20:04 +0000)
committerCameron Gutman <aicommander@gmail.com>
Wed, 9 Jun 2010 20:04:39 +0000 (20:04 +0000)
- Implement IRP_MN_REMOVE_DEVICE handling for PnP root PDOs

svn path=/trunk/; revision=47722

reactos/ntoskrnl/io/pnpmgr/pnproot.c

index fb05da9..42d9421 100644 (file)
@@ -1027,10 +1027,12 @@ PnpRootPdoPnpControl(
   IN PIRP Irp)
 {
   PPNPROOT_PDO_DEVICE_EXTENSION DeviceExtension;
+  PPNPROOT_FDO_DEVICE_EXTENSION FdoDeviceExtension;
   PIO_STACK_LOCATION IrpSp;
   NTSTATUS Status;
 
   DeviceExtension = (PPNPROOT_PDO_DEVICE_EXTENSION)DeviceObject->DeviceExtension;
+  FdoDeviceExtension = (PPNPROOT_FDO_DEVICE_EXTENSION)PnpRootDeviceObject->DeviceExtension;
   Status = Irp->IoStatus.Status;
   IrpSp = IoGetCurrentIrpStackLocation(Irp);
 
@@ -1070,7 +1072,32 @@ PnpRootPdoPnpControl(
         break;
 
     case IRP_MN_REMOVE_DEVICE:
-        DPRINT1("IRP_MN_REMOVE_DEVICE is UNIMPLEMENTED!\n");
+        /* Remove the device from the device list and decrement the device count*/
+        KeAcquireGuardedMutex(&FdoDeviceExtension->DeviceListLock);
+        RemoveEntryList(&DeviceExtension->DeviceInfo->ListEntry);
+        FdoDeviceExtension->DeviceListCount--;
+        KeReleaseGuardedMutex(&FdoDeviceExtension->DeviceListLock);
+
+        /* Free some strings we created */
+        RtlFreeUnicodeString(&DeviceExtension->DeviceInfo->DeviceDescription);
+        RtlFreeUnicodeString(&DeviceExtension->DeviceInfo->DeviceID);
+        RtlFreeUnicodeString(&DeviceExtension->DeviceInfo->InstanceID);
+
+        /* Free the resource requirements list */
+        if (DeviceExtension->DeviceInfo->ResourceRequirementsList != NULL)
+            ExFreePool(DeviceExtension->DeviceInfo->ResourceRequirementsList);
+
+        /* Free the boot resources list */
+        if (DeviceExtension->DeviceInfo->ResourceList != NULL)
+            ExFreePool(DeviceExtension->DeviceInfo->ResourceList);
+
+        /* Free the device info */
+        ExFreePool(DeviceExtension->DeviceInfo);
+
+        /* Finally, delete the device object */
+        IoDeleteDevice(DeviceObject);
+
+        /* Return success */
         Status = STATUS_SUCCESS;
         break;