IopCreateArcName

NTSTATUS __stdcall IopCreateArcName(_DEVICE_OBJECT *DeviceObject, UINT64 DeviceNumber){
  VOID **v3; 
  int v4; 
  VOID **PoolWithTag; 
  _DEVICE_OBJECT *v6; 
  UINT64 OutputBufferLength; 
  PIRP *v8; 
  int Status; 
  PIRP *v10; 
  unsigned int v11; 
  UINT64 i; 
  PIRP *v13; 
  char v14; 
  PVOID *v15; 
  PVOID *v16; 
  bool v18; 
  WCHAR *v19; 
  int v20; 
  VOID **Pool_1; 
  _IRP *v22; 
  UINT64 v23; 
  unsigned __int64 v24; 
  unsigned __int64 v25; 
  UINT8 v26; 
  char *v27; 
  char *v28; 
  int v29; 
  int v30; 
  __int128 Object; 
  __int64 v32; 
  _IO_STATUS_BLOCK IoStatusBlock; 
  _UNICODE_STRING UnicodeString; 
  UINT64 DiskSignature; 
  _UNICODE_STRING DestinationString; 
  __int128 v37; 
  UINT64 Length; 
  __int64 OutputBuffer; 
  int v40; 
  INT8 AnsiBuffer[64]; 
  WCHAR pszDest[64]; 
  VOID *retaddr; 

  OutputBuffer = 0i64;
  v40 = 0;
  v3 = 0i64;
  Length = 0i64;
  v4 = 0;
  v32 = 0i64;
  PoolWithTag = 0i64;
  v6 = (_DEVICE_OBJECT *)IoArcTableListHead;
  LODWORD(OutputBufferLength) = 4096;
  UnicodeString = 0i64;
  DestinationString = 0i64;
  v37 = 0i64;
  Object = 0i64;
  IoStatusBlock = 0i64;
  while( 1 )
  {
    if( v6 == (_DEVICE_OBJECT *)&IoArcTableListHead )
    {
      if( (_DWORD)DeviceNumber == -1 )
      {
        v8 = IoBuildDeviceIoControlRequest(
               0x2D1080u,
               DeviceObject,
               0i64,
               0,
               &OutputBuffer,
               0xCu,
               0,
               (PKEVENT)&Object,
               &IoStatusBlock);
        if( !v8 )
          return -1073741670;
        KeInitializeEvent((INT64)&Object, 0, 0);
        Status = IofCallDriver((UINT64)DeviceObject, (UINT64)v8);
        if( Status == 259 )
        {
          KeWaitForSingleObject((UINT64)&Object, 0, 0, 0, 0i64);
          Status = IoStatusBlock.Status;
        }
        if( Status < 0 )
          return Status;
      }
      else
      {
        HIDWORD(OutputBuffer) = DeviceNumber;
      }
      v10 = IoBuildDeviceIoControlRequest(
              0x70000u,
              DeviceObject,
              0i64,
              0,
              &v37,
              0x18u,
              0,
              (PKEVENT)&Object,
              &IoStatusBlock);
      if( v10 )
      {
        KeInitializeEvent((INT64)&Object, 0, 0);
        Status = IofCallDriver((UINT64)DeviceObject, (UINT64)v10);
        if( Status == 259 )
        {
          KeWaitForSingleObject((UINT64)&Object, 0, 0, 0, 0i64);
          Status = IoStatusBlock.Status;
        }
        if( Status < 0 )
          return Status;
        v11 = HIDWORD(Length);
        if( HIDWORD(Length) < 0x200 )
          v11 = 512;
        v18 = DeviceObject->DeviceType == 2;
        HIDWORD(Length) = v11;
        if( !v18 )
        {
          for( i = 4096i64; ; i = OutputBufferLength )
          {
            PoolWithTag = ExAllocatePoolWithTag(0x200ui64, i, 1866624841i64);
            if( !PoolWithTag )
            {
              Status = -1073741670;
              goto LABEL_36;
            }
            v13 = IoBuildDeviceIoControlRequest(
                    0x70050u,
                    DeviceObject,
                    0i64,
                    0,
                    PoolWithTag,
                    OutputBufferLength,
                    0,
                    (PKEVENT)&Object,
                    &IoStatusBlock);
            if( !v13 )
              break;
            KeResetEvent((_KEVENT *)&Object);
            Status = IofCallDriver((UINT64)DeviceObject, (UINT64)v13);
            if( Status == 259 )
            {
              KeWaitForSingleObject((UINT64)&Object, 5, 0, 0, 0i64);
              Status = IoStatusBlock.Status;
            }
            if( Status != -1073741789 )
              goto LABEL_23;
            ExFreePoolWithTag(PoolWithTag, 0);
            OutputBufferLength = (unsigned int)(2 * OutputBufferLength);
          }
          Status = -1073741670;
LABEL_23:
          if( Status < 0 )
            goto LABEL_36;
          if( *(_DWORD *)PoolWithTag != 2
            && (*(_DWORD *)PoolWithTag || *((_DWORD *)PoolWithTag + 1) || *((_DWORD *)PoolWithTag + 2)) )
          {
            v14 = 0;
            goto LABEL_30;
          }
          v4 = *((_DWORD *)PoolWithTag + 3);
LABEL_29:
          v14 = 1;
LABEL_30:
          v15 = (PVOID *)IoArcTableListHead;
          v16 = &IoArcTableListHead;
          while( 1 )
          {
            if( v15 == v16 )
            {
              Status = -1073741637;
              goto LABEL_36;
            }
            if( !*((_BYTE *)v15 + 72) && !v15[8] )
            {
              if( v14 )
              {
                if( *((_BYTE *)v15 + 36) )
                  goto LABEL_34;
                v18 = *((_DWORD *)v15 + 8) == v4;
              }
              else
              {
                if( !IopVerifyDiskSignature(
                        (_DRIVE_LAYOUT_INFORMATION_EX *)PoolWithTag,
                        (_ARC_DISK_SIGNATURE *)v15,
                        &DiskSignature) )
                  goto LABEL_34;
                if( v15[7] )
                {
                  v26 = VhdiVerifyBootDisk(DeviceObject);
                  v16 = &IoArcTableListHead;
                  if( !v26 )
                    goto LABEL_34;
                }
                if( *(_DWORD *)PoolWithTag )
                  goto LABEL_47;
                v18 = *((_DWORD *)v15 + 8) == *((_DWORD *)PoolWithTag + 3);
              }
              if( v18 )
              {
LABEL_47:
                v15[8] = DeviceObject;
                v19 = L"\\Device\\CdRom%d";
                if( DeviceObject->DeviceType != 2 )
                  v19 = (WCHAR *)L"\\Device\\Harddisk%d\\Partition0";
                RtlStringCchPrintfW(pszDest, 0x40ui64, v19);
                RtlInitUnicodeString(&DestinationString, pszDest);
                RtlStringCchPrintfA(AnsiBuffer, 0x40ui64, (INT8 *)"\\ArcName\\%s");
                Status = IopCreateUnicodeFromAnsiBuffer(&UnicodeString, AnsiBuffer);
                if( Status >= 0 )
                {
                  IoCreateSymbolicLink(&UnicodeString, &DestinationString);
                  RtlFreeAnsiString(&UnicodeString);
                  if( DeviceObject->DeviceType == 2 )
                  {
                    if( (unsigned int)InitializationPhase < 2 )
                    {
                      v27 = (char *)v15[3];
                      v28 = (char *)(KeLoaderBlock_0->ArcBootDeviceName - v27);
                      do
                      {
                        v29 = (unsigned __int8)v28[(_QWORD)v27];
                        v30 = (unsigned __int8)*v27 - v29;
                        if( v30 )
                          break;
                        ++v27;
                      }
                      while( v29 );
                      if( !v30 )
                        DeviceObject->Flags |= 0x100u;
                    }
                  }
                  else if( *((_DWORD *)PoolWithTag + 1) )
                  {
                    Status = 0;
                    v20 = 1;
                    do
                    {
                      RtlStringCchPrintfW(pszDest, 0x40ui64, (WCHAR *)L"\\Device\\Harddisk%d\\Partition%d");
                      RtlInitUnicodeString(&DestinationString, pszDest);
                      RtlStringCchPrintfA(AnsiBuffer, 0x40ui64, (INT8 *)"\\ArcName\\%spartition(%d)");
                      if( IopCreateUnicodeFromAnsiBuffer(&UnicodeString, AnsiBuffer) >= 0 )
                      {
                        IoCreateSymbolicLink(&UnicodeString, &DestinationString);
                        RtlFreeAnsiString(&UnicodeString);
                      }
                      ++v20;
                    }
                    while( (unsigned int)(v20 - 1) < *((_DWORD *)PoolWithTag + 1) );
                  }
                }
LABEL_36:
                if( PoolWithTag )
                  ExFreePoolWithTag(PoolWithTag, 0);
                goto LABEL_38;
              }
            }
LABEL_34:
            v15 = (PVOID *)*v15;
          }
        }
        DiskSignature = 0x8000i64;
        Pool_1 = IopVerifierExAllocatePool_1(0x204ui64, v11);
        v3 = Pool_1;
        if( Pool_1 )
        {
          v22 = IopBuildSynchronousFsdRequest(
                  3ui64,
                  DeviceObject,
                  Pool_1,
                  HIDWORD(Length),
                  (_LARGE_INTEGER *)&DiskSignature,
                  (_KEVENT *)&Object,
                  &IoStatusBlock,
                  retaddr);
          v23 = (UINT64)v22;
          if( !v22 )
          {
            Status = -1073741670;
            goto LABEL_38;
          }
          v22->Tail.CurrentStackLocation[-1].Flags |= 2u;
          KeInitializeEvent((INT64)&Object, 0, 0);
          Status = IofCallDriver((UINT64)DeviceObject, v23);
          if( Status == 259 )
          {
            KeWaitForSingleObject((UINT64)&Object, 0, 0, 0, 0i64);
            Status = IoStatusBlock.Status;
          }
          if( Status >= 0 )
          {
            v24 = 0i64;
            v25 = (unsigned __int64)HIDWORD(Length) >> 2;
            if( v25 )
            {
              do
                v4 += *((_DWORD *)v3 + v24++);
              while( v24 < v25 );
            }
            v4 = -v4;
            goto LABEL_29;
          }
LABEL_38:
          if( v3 )
            ExFreePoolWithTag(v3, 0);
          return Status;
        }
      }
      return -1073741670;
    }
    if( v6->DeviceExtension == DeviceObject )
      return 0;
    v6 = *(_DEVICE_OBJECT **)&v6->Type;
  }
}

Referenced by:

IoCreateArcName
IopCreateArcNamesDisk