NVMe Sanitize call returns unexpected error 0x13D

DawidW-5205 11 Reputation points
2022-11-03T14:24:56.677+00:00

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");  
}  
Windows API - Win32
Windows API - Win32
A core set of Windows application programming interfaces (APIs) for desktop and server applications. Previously known as Win32 API.
2,651 questions
C++
C++
A high-level, general-purpose programming language, created as an extension of the C programming language, that has object-oriented, generic, and functional features in addition to facilities for low-level memory manipulation.
3,758 questions
Windows Hardware Performance
Windows Hardware Performance
Windows: A family of Microsoft operating systems that run across personal computers, tablets, laptops, phones, internet of things devices, self-contained mixed reality headsets, large collaboration screens, and other devices.Hardware Performance: Delivering / providing hardware or hardware systems or adjusting / adapting hardware or hardware systems.
1,622 questions
{count} votes

6 answers

Sort by: Most helpful
  1. MaoliWolf 0 Reputation points
    2024-08-15T08:05:35.23+00:00

    I'm also getting the same error 13D, but something is weird:

    The program about sanitizing the NVMe device we built runs successfully once and the SSD was sanitized, then the program got the error 13D forever, if the sanitize command can only send in Win PE, how can that happen?

    Did I miss something?

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.