Nikita
Nikita

Reputation: 1082

How to get what ATA Standards are supported by HDD?

How to get ATA Standards that are supported by HDD? I'm using C++, WINAPI. I can't use WMI.

I meen these ATA Standards: http://www.quepublishing.com/articles/article.aspx?p=2028834&seqNum=2

I'm already using this struct in my project: https://msdn.microsoft.com/en-us/library/windows/hardware/ff559006(v=vs.85).aspx , but there no information about supported ATA standards.

I'm looking for any programm solution, I think that if need I can write to a file supported standards with other language and then read them with c++.

Upvotes: 0

Views: 673

Answers (1)

johnbrovi
johnbrovi

Reputation: 92

You can send 0xEC ATA command to HDD and retrieve IDENTIFY_DEVICE_DATA structure, which contain information about your HDD. It requires irb.h library include from WDK (Windows Driver Kit).

BOOL getAtaCompliance() { 
  DWORD dwBytes;
  BOOL  bResult;

  CONST UINT bufferSize = 512;
  CONST BYTE identifyDataCommandId =  0xEC;

  UCHAR identifyDataBuffer[bufferSize
        + sizeof(ATA_PASS_THROUGH_EX)] = { 0 };

  ATA_PASS_THROUGH_EX & PTE = *(ATA_PASS_THROUGH_EX *) identifyDataBuffer;
  PTE.Length = sizeof(PTE);
  PTE.TimeOutValue = 10;
  PTE.DataTransferLength = 512;
  PTE.DataBufferOffset = sizeof(ATA_PASS_THROUGH_EX);

  IDEREGS * ideRegs = (IDEREGS *) PTE.CurrentTaskFile;
  ideRegs->bCommandReg = identifyDataCommandId;
  ideRegs->bSectorCountReg = 1;

  PTE.AtaFlags = ATA_FLAGS_DATA_IN | ATA_FLAGS_DRDY_REQUIRED;

  bResult = DeviceIoControl(hDevice, IOCTL_ATA_PASS_THROUGH, &PTE,
                      sizeof(identifyDataBuffer), &PTE,
                      sizeof(identifyDataBuffer), &dwBytes, 0);

  if (bResult == FALSE) {
    std::cout << "Oops, something went wrong, error code: "
              << GetLastError() << std::endl;
    return bResult;
  }

  WORD *data = (WORD *)(identifyDataBuffer + sizeof(ATA_PASS_THROUGH_EX));

  int16_t ataSupportBits = data[80];

  return bResult;
}

ataSupportBits will contain 16 bits about supported ATA standarts. From Information technology - AT Attachment 8 - ATA/ATAPI Command Set (ATA8-ACS)

word #80, ATA/ATAPI Compliance bitmap

Upvotes: 1

Related Questions