PiIrpQueryRemoveDevice

NTSTATUS __stdcall PiIrpQueryRemoveDevice(PDEVICE_OBJECT TargetDevice, PDRIVER_OBJECT *FailingDriver){
  int v4; 
  INT64 v5; 
  INT64 v6; 
  INT64 v7; 
  INT64 v8; 
  _DEVICE_OBJECT *v9; 
  INT64 v10; 
  NTSTATUS v11; 
  INT64 v12; 
  INT64 v14; 
  INT64 v15; 
  INT64 v16; 
  INT64 v17; 
  _ADAPTER_OBJECT *v18; 
  _DRIVER_OBJECT *v19; 
  __int128 Object; 
  __int64 v21; 
  NTSTATUS v22; 
  int v23; 
  _DEVICE_OBJECT *DeviceObject[2]; 
  char v25[72]; 

  v21 = 0i64;
  v23 = 0;
  v4 = 0;
  *(_OWORD *)DeviceObject = 0i64;
  Object = 0i64;
  memset(v25, 0i64, sizeof(v25));
  *(_WORD *)v25 = 283;
  if( PnpFindMountableDevice((__int64)TargetDevice, v5, v6) )
  {
    v4 = 1;
    PnpLockMountableDevice(TargetDevice, v7, v8);
    v9 = PnpMarkDeviceForRemove(TargetDevice, 1i64, DeviceObject);
    PnpUnlockMountableDevice((__int64)TargetDevice, v14, v15);
  }
  else
  {
    v9 = TargetDevice;
  }
  v19 = 0i64;
  v22 = -1073741823;
  KeInitializeEvent((INT64)&Object, 1, 0);
  v11 = PnpAsynchronousCall(
          v9,
          (__int128 *)v25,
          (int(__fastcall *)(_DEVICE_OBJECT *, _IRP *, void *))PnpDiagnosticCompletionRoutine,
          &v19);
  if( v11 == 259 )
  {
    KeWaitForSingleObject((UINT64)&Object, 0, 0, 0, 0i64);
    v11 = v22;
  }
  if( FailingDriver )
    *FailingDriver = v19;
  if( v4 )
  {
    PnpLockMountableDevice(TargetDevice, v10, v12);
    v18 = (_ADAPTER_OBJECT *)DeviceObject[1];
    if( DeviceObject[1] )
    {
      IopDecrementDeviceObjectHandleCount(DeviceObject[1]);
      HalPutDmaAdapter(v18);
    }
    PnpUnlockMountableDevice((__int64)TargetDevice, v16, v17);
    if( v11 >= 0 )
      return IopInvalidateVolumesForDevice(TargetDevice);
  }
  return v11;
}

Referenced by:

PnpDisableDevice
PnpQueryRemoveLockedDeviceNode