0

I'm trying to set flags/attributes of UFS device with IOCTL_STORAGE_SET_PROPERTY

based on the guide for NVMe here: https://learn.microsoft.com/en-us/windows/win32/fileio/working-with-nvme-devices

see below the code that I'm executing.

the GetLastError shows "incorrect function" error

I did manage to read the flags/attributes using the guide from the NVMe examples there (IOCTL_STORAGE_QUERY_PROPERTY)

any ideas for making this IOCTL work?

thanks,

PVOID   buffer = NULL;
ULONG   bufferLength = 0;
ULONG   returnedLength = 0;

PSTORAGE_PROPERTY_SET                   setProperty = NULL;
PSTORAGE_PROTOCOL_SPECIFIC_DATA_EXT     protocolData = NULL;
PSTORAGE_PROTOCOL_DATA_DESCRIPTOR_EXT   protocolDataDescr = NULL;

bufferLength = FIELD_OFFSET(STORAGE_PROPERTY_SET, AdditionalParameters) + sizeof(STORAGE_PROTOCOL_SPECIFIC_DATA_EXT);
bufferLength += 1024;

buffer = new UCHAR[bufferLength];

//
// Initialize query data structure to get the desired log page.
//
ZeroMemory(buffer, bufferLength);

setProperty = (PSTORAGE_PROPERTY_SET)buffer;

setProperty->PropertyId = StorageAdapterProtocolSpecificProperty;
setProperty->SetType = PropertyStandardSet;

protocolData = (PSTORAGE_PROTOCOL_SPECIFIC_DATA_EXT)setProperty->AdditionalParameters;

protocolData->ProtocolType = ProtocolTypeUfs;
protocolData->DataType = UfsDataTypeQueryFlag;
protocolData->ProtocolDataValue = UFS_fPurgeEnable;

protocolData->ProtocolDataSubValue = 1; // This will pass to CDW11.
protocolData->ProtocolDataSubValue2 = 0; // This will pass to CDW12.
protocolData->ProtocolDataSubValue3 = 0; // This will pass to CDW13.
protocolData->ProtocolDataSubValue4 = 0; // This will pass to CDW14.
protocolData->ProtocolDataSubValue5 = 0; // This will pass to CDW15.

protocolData->ProtocolDataOffset = 0;
protocolData->ProtocolDataLength = 0;

//
// Send request down.
//
auto retval = DeviceIoControl(IOCTL_STORAGE_SET_PROPERTY,
    buffer,
    bufferLength,
    buffer,
    bufferLength,
    &returnedLength
);


if (!retval)
{
        auto error{ ::GetLastError() };
        throw Windows::Win32Error(error);
}

0 Answers0