Hi,
I’m currently working on a project to sanitize data (Remove customer data) on MacBook storage devices (Refurbish). The NVMe SSD is embedded on the motherboard. I’ve created a simple proof-of-concept code (Running in terminal) with the following steps:
Check and Match the NVMe Device: Verify that the physical drive (disk0) exists on the system.
Open the Connection: Establish a connection to the device (disk0).
Send NVMe Admin Commands: For testing, I sent the IDENTIFY (0x06) command to confirm that the connection to the device works.
Close the Service and Connection: Terminate the connection after the test.
However, during runtime, I encountered an error when sending the command:
Error: Failed to send NVMe Admin Command with error: -536870206 ((iokit/common) invalid argument)
I’m unsure why this results in an "Invalid argument" error. Is the method I’m using to send the Admin Command incorrect? If so, what is the proper function call to use in the IOKit framework? Alternatively, are there any other recommended methods to achieve this?
In the future, I also need to send commands like ‘Sanitize (84h)’ and ‘Format NVM (80h).’ Since I’m new to macOS development, I’d greatly appreciate any advice or guidance from experts in this area.
I have attached the source code and related ioreg file for 'IOMedia' and 'IONVMeController' for you guy reference.
IOMedia
IONVMeController
sendAdminCommands.cpp
Thank you so much for your help!
Regards,
Winson