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,660 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,772 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,629 questions
{count} votes

6 answers

Sort by: Most helpful
  1. DawidW-5205 11 Reputation points
    2023-03-31T14:11:08.9233333+00:00

    We filed an issue and Microsoft answered us that SANITIZE through storage protocol command is only supported on WinPE and documentation on their web page is wrong. Their answer:

    Hello Dawid, Thanks for pointing this out. This is a documentation bug. NVMe admin command sanitize is allowed only in WinPE if user uses IOCTL_STORAGE_PROTOCOL_COMMAND. I will open up a documentation bug to get it corrected. Regards, Ashwini

    1 person found this answer helpful.
    0 comments No comments

  2. DawidW-5205 11 Reputation points
    2023-03-31T14:39:21.0666667+00:00

    Duplicated message. Deleted.

    1 person found this answer helpful.
    0 comments No comments

  3. Xiaopo Yang - MSFT 12,726 Reputation points Microsoft Vendor
    2022-11-11T05:52:53.723+00:00

    You need Retrieving the Last-Error Code to get the complete error message. And according to Pass-through mechanism, the submitted command mightn't be reported as supported in the Command Effects Log. StorNVMe.sys and Storport.sys will block any command to a device if it is not described in the Command Effects Log. You may refer to vendor manual for using vendor-specific command correctly.
    There is an Example: sending a vendor-specific command.


  4. alsc01 0 Reputation points
    2023-03-31T13:35:54.57+00:00

    I'm also getting the same error, 0x013D, when trying to send a sanitize command on Win11.

    When running the application in debug mode, I get the following additional console output:
    RTL: RtlNtStatusToDosError(0xc1000006): No Valid Win32 Error Mapping

    RTL: Edit ntos\rtl\generr.c to correct the problem

    RTL: ERROR_MR_MID_NOT_FOUND is being returned

    Any idea how I can get more information about the root cause?

    0 comments No comments

  5. Winson.Loh 0 Reputation points
    2024-04-16T10:14:05.1366667+00:00

    I also getting same error 13D.

    When the NVMe Sanitize going to fully support under Window 11?

    Thanks


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.