PnpQueryRemoveLockedDeviceNode

__int64 __fastcall PnpQueryRemoveLockedDeviceNode(_DEVICE_NODE *DeviceNode, int a2, _DWORD *a3, _UNICODE_STRING *a4){
  _DEVICE_OBJECT *PhysicalDeviceObject; 
  NTSTATUS v9; 
  unsigned int v10; 
  __int64 result; 
  _DRIVER_OBJECT *FailingDriver; 

  switch( DeviceNode->State )
  {
    case DeviceNodeDriversAdded:
    case DeviceNodeResourcesAssigned:
    case DeviceNodeStartCompletion:
    case DeviceNodeStartPostWork:
    case DeviceNodeStarted:
      PipSetDevNodeUserFlags(DeviceNode, 0x200ui64);
      PhysicalDeviceObject = DeviceNode->PhysicalDeviceObject;
      FailingDriver = 0i64;
      v9 = PiIrpQueryRemoveDevice(PhysicalDeviceObject, &FailingDriver);
      v10 = v9;
      if( v9 < 0 )
      {
        if( a2 == 54 && v9 == -1073740537 )
        {
          PipSetDevNodeState(DeviceNode, DeviceNodeQueryRemoved);
          DeviceNode->StateFlags |= 2u;
        }
        else
        {
          IopRemoveDevice(PhysicalDeviceObject, 3ui64);
          *a3 = 6;
          RtlCopyUnicodeString(a4, &DeviceNode->InstancePath);
          if( FailingDriver && a4->MaximumLength - a4->Length >= FailingDriver->DriverName.Length + 4 )
            RtlAppendUnicodeStringToString(a4, &FailingDriver->DriverName);
        }
      }
      else
      {
        PipSetDevNodeState(DeviceNode, DeviceNodeQueryRemoved);
        if( a2 == 54 && (DeviceNode->StateFlags & 2) != 0 )
          v10 = -1073740537;
      }
      PipClearDevNodeUserFlags(DeviceNode, 0x200ui64);
      result = v10;
      break;
    default:
      result = 0i64;
      break;
  }
  return result;
}

Referenced by:

PnpDeleteLockedDeviceNode