IoSetInformation

INT64 __stdcall IoSetInformation(
        FILE_OBJECT *FileObject,
        FILE_INFORMATION_CLASS FileInformationClass,
        UINT64 Length,
        VOID *FileInformation){
  char v4; 
  char v5; 
  _ETHREAD *CurrentThread; 
  __int64 v10; 
  UINT64 v11; 
  UINT8 v12; 
  UINT8 v13; 
  _DEVICE_OBJECT *RelatedDeviceObject; 
  IRP *Irp; 
  IRP *v16; 
  struct _KEVENT *p_Event; 
  __int64 v18; 
  int v19; 
  unsigned __int64 v20; 
  __int64 v21; 
  int FinalStatus; 
  unsigned int v24; 
  unsigned int Flags; 
  unsigned int v26; 
  int v27; 
  unsigned int v28; 
  CHAR v29; 
  char v30; 
  PLARGE_INTEGER Timeout; 
  char v32; 
  char v33; 
  _DEVICE_OBJECT *DeviceObject; 
  HANDLE Handle; 
  __int128 v36; 
  struct _KEVENT Event; 
  VOID *retaddr; 
  __int64 v39; 
  UINT64 a3; 
  LODWORD(a3) = Length;
  v4 = 0;
  Handle = 0i64;
  memset(&Event, 0, sizeof(Event));
  v5 = 0;
  v36 = 0i64;
  v32 = 0;
  ObfReferenceObject(FileObject);
  if( (FileObject->Flags & 2) != 0 )
  {
    CurrentThread = (_ETHREAD *)KeGetCurrentThread();
    --*((_WORD *)CurrentThread + 242);
    LODWORD(v10) = KeAbPreAcquire(&FileObject->Lock, 0i64, 0i64);
    LOBYTE(v39) = 0;
    if( _InterlockedExchange((volatile __int32 *)&FileObject->Busy, 1) )
    {
      Timeout = (PLARGE_INTEGER)&v39;
      v24 = IopWaitAndAcquireFileObjectLock(FileObject, 0i64);
      if( (_BYTE)v39 )
      {
        HalPutDmaAdapter((PADAPTER_OBJECT)FileObject);
        return v24;
      }
    }
    else
    {
      if( v10 )
        *(_BYTE *)(v10 + 26) |= 1u;
      ObfReferenceObject(FileObject);
    }
    KeResetEvent(&FileObject->Event, v11, v12, v13, (IRP *)Timeout);
    v4 = 1;
  }
  else
  {
    KeInitializeEvent(&Event, SynchronizationEvent, 0);
  }
  v33 = v4;
  RelatedDeviceObject = IoGetRelatedDeviceObject(FileObject);
  DeviceObject = RelatedDeviceObject;
  switch( FileInformationClass )
  {
    case FileRenameInformationBypassAccessCheck:
      FileInformationClass = FileRenameInformation;
LABEL_38:
      v5 = 1;
      break;
    case FileRenameInformationExBypassAccessCheck:
      FileInformationClass = FileRenameInformationEx;
      goto LABEL_38;
    case FileLinkInformationBypassAccessCheck:
      FileInformationClass = FileLinkInformation;
      goto LABEL_38;
    case FileLinkInformationExBypassAccessCheck:
      FileInformationClass = FileLinkInformationEx;
      goto LABEL_38;
    case FileCaseSensitiveInformationForceAccessCheck:
      FileInformationClass = FileCaseSensitiveInformation;
      v32 = 1;
      break;
  }
  Irp = IopAllocateIrpExReturn(RelatedDeviceObject, *((_BYTE *)RelatedDeviceObject + 76), v4 ^ 1u, retaddr);
  v16 = Irp;
  if( !Irp )
  {
    IopAllocateIrpCleanup((PUNICODE_STRING)FileObject);
    return 3221225626i64;
  }
  *((_QWORD *)Irp + 24) = FileObject;
  *((_QWORD *)Irp + 19) = KeGetCurrentThread();
  *((_BYTE *)Irp + 64) = 0;
  if( v4 )
  {
    *((_BYTE *)Irp + 71) |= 2u;
    p_Event = 0i64;
  }
  else
  {
    *((_DWORD *)Irp + 4) = 4;
    p_Event = &Event;
  }
  *((_QWORD *)v16 + 10) = p_Event;
  v18 = *((_QWORD *)v16 + 23);
  *((_QWORD *)v16 + 9) = &v36;
  v19 = a3;
  *(_BYTE *)(v18 - 72) = 6;
  *(_QWORD *)(v18 - 24) = FileObject;
  *((_DWORD *)v16 + 4) |= 0x10u;
  *((_QWORD *)v16 + 3) = FileInformation;
  *(_DWORD *)(v18 - 64) = v19;
  *(_DWORD *)(v18 - 56) = FileInformationClass;
  if( v5 )
  {
    *(_BYTE *)(v18 - 70) |= 1u;
  }
  else if( v32 )
  {
    *(_BYTE *)(v18 - 70) |= 1u;
  }
  IopQueueThreadIrp(v16);
  if( FileInformationClass == FileModeInformation )
  {
    Flags = FileObject->Flags;
    if( (Flags & 8) == 0 )
    {
      if( (*(_DWORD *)FileInformation & 2) != 0 )
        Flags |= 0x10u;
      else
        Flags &= ~0x10u;
      FileObject->Flags = Flags;
    }
    v26 = Flags & 0xFFFFFFDF;
    v27 = Flags | 0x20;
    if( (*(_DWORD *)FileInformation & 4) == 0 )
      v27 = v26;
    FileObject->Flags = v27;
    if( (*(_DWORD *)FileInformation & 2) != 0 )
    {
      if( (*(_DWORD *)FileInformation & 0x10) != 0 )
        v28 = v27 | 4;
      else
        v28 = v27 & 0xFFFFFFFB;
      FileObject->Flags = v28;
    }
    --*((_BYTE *)v16 + 67);
    FinalStatus = 0;
    *((_QWORD *)v16 + 23) -= 72i64;
    v29 = 0;
    *((_DWORD *)v16 + 12) = 0;
    *((_QWORD *)v16 + 7) = 0i64;
    goto LABEL_68;
  }
  v20 = (unsigned int)(FileInformationClass - 10);
  if( (unsigned int)v20 <= 0x3E )
  {
    v21 = 0x4080000000000003i64;
    if( _bittest64(&v21, v20) )
    {
      if( FileInformationClass != FileMoveClusterInformation )
      {
        if( FileInformationClass == FileRenameInformationEx || FileInformationClass == FileLinkInformationEx )
          v30 = *(_BYTE *)FileInformation & 1;
        else
          v30 = *(_BYTE *)FileInformation;
        *(_BYTE *)(v18 - 40) = v30;
        goto LABEL_63;
      }
LABEL_62:
      *(_DWORD *)(v18 - 40) = *(_DWORD *)FileInformation;
LABEL_63:
      if( *((_WORD *)FileInformation + 10) != 92 && !*((_QWORD *)FileInformation + 1) )
        goto LABEL_24;
      FinalStatus = IopOpenLinkOrRenameTarget(&Handle, v16, FileInformation, FileObject);
      if( FinalStatus >= 0 )
        goto LABEL_24;
      v29 = 2;
      goto LABEL_67;
    }
  }
  if( FileInformationClass == FileMoveClusterInformation )
    goto LABEL_62;
  if( FileInformationClass == FileMemoryPartitionInformation )
  {
    FinalStatus = IopSetFileMemoryPartitionInformation(FileObject, (INT64)FileInformation, (unsigned int)a3);
    *((_DWORD *)v16 + 12) = FinalStatus;
    v29 = 0;
    *((_QWORD *)v16 + 7) = 0i64;
LABEL_67:
    --*((_BYTE *)v16 + 67);
    *((_QWORD *)v16 + 23) -= 72i64;
LABEL_68:
    IofCompleteRequest(v16, v29);
    goto LABEL_25;
  }
LABEL_24:
  FinalStatus = IofCallDriver(DeviceObject, v16);
LABEL_25:
  if( v33 )
  {
    if( FinalStatus == 259 )
    {
      if( KeWaitForSingleObject(&FileObject->Event, Executive, 0, (FileObject->Flags & 4) != 0, 0i64) == 257 )
        IopCancelAlertedRequest(&FileObject->Event, v16);
      FinalStatus = FileObject->FinalStatus;
    }
    IopReleaseFileObjectLock((PADAPTER_OBJECT)FileObject);
  }
  else if( FinalStatus == 259 )
  {
    KeWaitForSingleObject(&Event, Executive, 0, 0, 0i64);
    FinalStatus = v36;
  }
  if( Handle )
    ObCloseHandle(Handle, 0);
  return(unsigned int)FinalStatus;
}

Referenced by:

MiAttemptPageFileExtension
MiAttemptPageFileReduction