1

I am using DeviceIoControl with IOCTL_STORAGE_QUERY_PROPERTY to retrieve StorageAdapterPhysicalTopologyProperty. When i try this i get an 1117 error, "The request could not be performed because of an I/O device error".

I have determined that the request succeeds if i use a return buffer defined to be the sizeof(STORAGE_DESCRIPTOR_HEADER) (=8), but it fails when i use the proper (to me) buffer size of sizeof(STORAGE_PHYSICAL_TOPOLOGY_DESCRIPTOR). When i use the STORAGE_DESCRIPTOR_HEADER, the returned Size and Version is 56 which is the size of the STORAGE_PHYSICAL_TOPOLOGY_DESCRIPTOR.

I have successfully done other Storage Property Queries, but no example usage seems to exist for this property.

Does anyone have any experience with this and can you point out any problems with my code?

bool GetAdapterPhysicalTopology()
{
    bool   result = false;
    HANDLE hDevice = CreateFileA(_T("\\\\.\\PhysicalDrive0"),
        0,
        FILE_SHARE_READ | FILE_SHARE_WRITE,
        0,
        OPEN_EXISTING,
        0,
        0);

    if (hDevice != INVALID_HANDLE_VALUE)
    {
        DWORD bytesReturned = 0;
        STORAGE_PROPERTY_QUERY query = {};
        STORAGE_PHYSICAL_TOPOLOGY_DESCRIPTOR sptd = {};

        query.PropertyId = StorageAdapterPhysicalTopologyProperty;
        query.QueryType = PropertyStandardQuery;

        if ((result=DeviceIoControl(hDevice, 
                                    IOCTL_STORAGE_QUERY_PROPERTY,
                                    &query, sizeof(query),    // input buffer, size
                                    &sptd, sizeof(sptd),      // output buffer, size
                                    &bytesReturned, NULL)))
        {
            // Doesn't get here unless i use 8 as the output buffer size
            // And even then, the next DeviceIoControl fails with 1117
            if (bytesReturned)
            {
                // STORAGE_PHYSICAL_TOPOLOGY_DESCRIPTOR
                std::vector<byte> buff(sptd.Size);
                if ((result=DeviceIoControl(hDevice,  
                                        IOCTL_STORAGE_QUERY_PROPERTY,
                                        &query, sizeof(query),
                                        buff.data(), buff.size(),
                                        &bytesReturned, NULL)))
                {
                    // Get the data...
                    PSTORAGE_PHYSICAL_TOPOLOGY_DESCRIPTOR psptd = (PSTORAGE_PHYSICAL_TOPOLOGY_DESCRIPTOR)buff.data();
                    wprintf(L"NodeCount: %d", psptd->NodeCount);
                    // etc
                }
                else
                {
                    printf("DeviceIoControl(2) failed. Error Code %d.\n", GetLastError());
                }
            }
        }
        else
        {
            // Gives me error code: 1117
            printf("DeviceIoControl(1) failed. Error Code %d.\n", GetLastError());  
        }

        CloseHandle(hDevice);
    }

    return result;
}

Mark Welo
  • 11
  • 3

0 Answers0