Hi,
I'm trying to send NVME Sanitize/BlockErase command to NVMe disk which supports that. This shall be available on regular Win11 OS and I'm running 10.0.22000.1098 (10.0.22000.1042 StorNvm driver). I'm receiving absurd last error after DeviceIoControl call: 0x013D which normally would be ERROR_MR_MID_NOT_FOUND ("The system cannot find message text for message number 0x%1 in the message file for %2."). How to understand such error code, what am I doing incorrectly? Example code:
void Msft_StorageProtocolCommand_Sanitize_Nvme(HANDLE devHandle)
{
printf("\n*** STORAGE PROTOCOL COMMAND - SANITIZE (block erase) NVMe ***\n");
const size_t bufSize = offsetof(STORAGE_PROTOCOL_COMMAND, Command) + STORAGE_PROTOCOL_COMMAND_LENGTH_NVME;
unsigned char inBuffer[bufSize] = { 0 };
STORAGE_PROTOCOL_COMMAND* header = (STORAGE_PROTOCOL_COMMAND*)inBuffer;
header->Version = STORAGE_PROTOCOL_STRUCTURE_VERSION;
header->Length = sizeof(STORAGE_PROTOCOL_COMMAND);
header->ProtocolType = STORAGE_PROTOCOL_TYPE::ProtocolTypeNvme;
header->CommandLength = STORAGE_PROTOCOL_COMMAND_LENGTH_NVME;
header->CommandSpecific = STORAGE_PROTOCOL_SPECIFIC_NVME_ADMIN_COMMAND;
header->TimeOutValue = 10;
ADMIN_COMMAND* formatCommand = (ADMIN_COMMAND*)(header->Command);
formatCommand->CDW0.OPC.Raw = ADMIN_COMMAND_SANITIZE;
formatCommand->NSID = 0; // or 0
formatCommand->SanitizeCommand.AUSE = 0;
formatCommand->SanitizeCommand.NDAS = 0;
formatCommand->SanitizeCommand.OIPBP = 0;
formatCommand->SanitizeCommand.OWPASS = 0;
formatCommand->SanitizeCommand.SANACT = 2;
DWORD recievedLen = 0;
if (!DeviceIoControl(devHandle, IOCTL_STORAGE_PROTOCOL_COMMAND, inBuffer, sizeof(inBuffer), inBuffer, sizeof(inBuffer), &recievedLen, NULL))
{
DWORD err = GetLastError();
printf("DeviceIo err: %d\n", err);
return;
}
printf("Executed.\n");
printf("Return status: 0x%X\n", header->ReturnStatus);
printf("Error code: 0x%X\n", header->ErrorCode);
printf("Protocol return data: 0x%X\n", header->FixedProtocolReturnData);
printf("\n");
}