Nikita Nikita - 2 months ago 14
C# Question

How to get hdd transfer mode?

I need to get hdd transfer mode(dma or pio) and print it, you can find it in device manager(in red circle in the screenshot).AtaScreen

So I need to get the info in red circle from programm. I've tried to use wmi classes, but Win32_DiskDrive, Win32_IDEController and others dont't provide the information I need. The closest to the property window from device manager was Win32_IDEController, field Win32_IDEController["Name"] returns string

ATA Channel 1
.

Also I've found this https://msdn.microsoft.com/en-us/library/windows/hardware/ff550142(v=vs.85).aspx , but it use
irb.h
, that is part of ddk(wdk) and I've never used it before, so I don't even know how to use this function.

Now I'm learning the WDK) Any solution in any language will good, in project I'm using C#, but if the solution will be in another language I can write "DMA" or "PIO" to a file in this solution, execute it .exe from C# and read from file. OFC solution in C# will be appreciated more.

Answer

You can use the AdapterUsesPio member from the STORAGE_ADAPTER_DESCRIPTOR structure. Here is a C++ example that demonstrates how to query a disk for it:

#include "stdafx.h"

int main()
{
    wchar_t path[1024];
    wsprintf(path, L"\\\\?\\C:"); // or L"\\\\.\\PhysicalDrive0"

    // note we use 0, not GENERIC_READ to avoid the need for admin rights
    // 0 is ok if you only need to query for characteristics
    HANDLE device = CreateFile(path, 0, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, NULL, NULL);
    if (device == INVALID_HANDLE_VALUE)
        return 0;

    STORAGE_PROPERTY_QUERY query = {};
    query.PropertyId = StorageAdapterProperty;
    query.QueryType = PropertyStandardQuery;

    STORAGE_ADAPTER_DESCRIPTOR descriptor = {};

    DWORD read;
    if (!DeviceIoControl(device, IOCTL_STORAGE_QUERY_PROPERTY,
        &query,
        sizeof(query),
        &descriptor,
        sizeof(descriptor),
        &read,
        NULL
        ))
    {
        wprintf(L"DeviceIoControl error: %i\n", GetLastError());
    }
    else
    {
        wprintf(L"AdapterUsesPio: %i\n", descriptor.AdapterUsesPio);
    }

    CloseHandle(device);
    return 0;
}