NTSTATUS DiskRemoveDevice( IN PDEVICE_OBJECT DeviceObject, IN UCHAR Type ) /*++ Routine Description: This routine will release any resources the device may have allocated for this device object and return. Arguments: DeviceObject - the device object being removed Return Value: status --*/ { PCOMMON_DEVICE_EXTENSION commonExtension = DeviceObject->DeviceExtension; PFUNCTIONAL_DEVICE_EXTENSION fdoExtension = DeviceObject->DeviceExtension; PAGED_CODE(); // // Handle query and cancel // if((Type == IRP_MN_QUERY_REMOVE_DEVICE) || (Type == IRP_MN_CANCEL_REMOVE_DEVICE)) { return STATUS_SUCCESS; } // // Delete our object directory. // if(fdoExtension->DeviceDirectory != NULL) { ZwMakeTemporaryObject(fdoExtension->DeviceDirectory); ZwClose(fdoExtension->DeviceDirectory); fdoExtension->DeviceDirectory = NULL; } if(Type == IRP_MN_REMOVE_DEVICE) { FREE_POOL(fdoExtension->SenseData); IoGetConfigurationInformation()->DiskCount--; } DiskDeleteSymbolicLinks(DeviceObject); if (Type == IRP_MN_REMOVE_DEVICE) { ClassDeleteSrbLookasideList(commonExtension); } return STATUS_SUCCESS; }
NTSTATUS NTAPI DiskRemoveDevice( IN PDEVICE_OBJECT DeviceObject, IN UCHAR Type ) /*++ Routine Description: This routine will release any resources the device may have allocated for this device object and return. Arguments: DeviceObject - the device object being removed Return Value: status --*/ { PCOMMON_DEVICE_EXTENSION commonExtension = DeviceObject->DeviceExtension; PDISK_DATA diskData = commonExtension->DriverData; PAGED_CODE(); // // Handle query and cancel // if((Type == IRP_MN_QUERY_REMOVE_DEVICE) || (Type == IRP_MN_CANCEL_REMOVE_DEVICE)) { return STATUS_SUCCESS; } if(commonExtension->IsFdo) { PFUNCTIONAL_DEVICE_EXTENSION fdoExtension = DeviceObject->DeviceExtension; // // Purge the cached partition table (if any). // DiskAcquirePartitioningLock(fdoExtension); DiskInvalidatePartitionTable(fdoExtension, TRUE); DiskReleasePartitioningLock(fdoExtension); // // Delete our object directory. // if(fdoExtension->AdapterDescriptor) { ExFreePool(fdoExtension->AdapterDescriptor); fdoExtension->AdapterDescriptor = NULL; } if(fdoExtension->DeviceDescriptor) { ExFreePool(fdoExtension->DeviceDescriptor); fdoExtension->DeviceDescriptor = NULL; } if(fdoExtension->SenseData) { ExFreePool(fdoExtension->SenseData); fdoExtension->SenseData = NULL; } if(fdoExtension->DeviceDirectory != NULL) { ZwMakeTemporaryObject(fdoExtension->DeviceDirectory); ZwClose(fdoExtension->DeviceDirectory); fdoExtension->DeviceDirectory = NULL; } if(Type == IRP_MN_REMOVE_DEVICE) { IoGetConfigurationInformation()->DiskCount--; } } else { //PPHYSICAL_DEVICE_EXTENSION pdoExtension = DeviceObject->DeviceExtension; } DiskDeleteSymbolicLinks(DeviceObject); // // Release the mounted device interface if we've set it. // if(diskData->PartitionInterfaceString.Buffer != NULL) { IoSetDeviceInterfaceState(&(diskData->PartitionInterfaceString), FALSE); RtlFreeUnicodeString(&(diskData->PartitionInterfaceString)); RtlInitUnicodeString(&(diskData->PartitionInterfaceString), NULL); } if(diskData->DiskInterfaceString.Buffer != NULL) { IoSetDeviceInterfaceState(&(diskData->DiskInterfaceString), FALSE); RtlFreeUnicodeString(&(diskData->DiskInterfaceString)); RtlInitUnicodeString(&(diskData->DiskInterfaceString), NULL); } ClassDeleteSrbLookasideList(commonExtension); return STATUS_SUCCESS; }