Reference

API Reference

Complete C API reference for libdriveinfo — the native backend library.

Device Enumeration

int di_enumerate_drives(drive_info_t **drives, int *count)

Discovers all physical storage devices connected to the system. Populates an array of drive_info_t structs.

Parameters

drivesdrive_info_t**Output pointer to allocated drive array
countint*Output number of drives found

Returns

DI_SUCCESS (0) on success, negative error code on failure.

void di_free_drives(drive_info_t *drives, int count)

Frees memory allocated by di_enumerate_drives().

Device Details

int di_get_drive_details(drive_info_t *drive)

Fills in detailed metadata for a drive: model, serial number, firmware version, capacity, and security state.

Populated Fields

modelchar[256]Drive model name
serialchar[256]Serial number
firmwarechar[256]Firmware revision
capacity_bytesuint64_tTotal capacity in bytes
protocoldi_protocol_tATA, NVMe, or SAT

Wipe Operations

int di_wipe_start(drive_info_t *drive, di_wipe_method_t method)

Starts an asynchronous wipe operation in a new thread. Returns immediately.

Methods (di_wipe_method_t)

DI_WIPE_ZERO DI_WIPE_ONE DI_WIPE_RANDOM DI_WIPE_DOD_3 DI_WIPE_DOD_7 DI_WIPE_GUTMANN DI_WIPE_NIST_CLEAR DI_WIPE_NIST_PURGE
int di_wipe_get_progress(drive_info_t *drive, di_wipe_progress_t *progress)

Queries the current progress of a running wipe operation.

Progress Fields

percentagedouble0.0 to 100.0
bytes_writtenuint64_tTotal bytes written so far
speed_bpsuint64_tCurrent speed in bytes/second
current_passintCurrent pass number
total_passesintTotal number of passes
statusdi_wipe_status_tRUNNING, COMPLETED, FAILED, CANCELLED
int di_wipe_cancel(drive_info_t *drive)

Signals the wipe thread to stop. The thread will finish the current sector write and exit cleanly.

Purge Operations

int di_secure_erase(drive_info_t *drive, const char *password)

Performs ATA Security Erase. Sets password, prepares drive, and sends SECURITY ERASE UNIT command.

Error Codes

DI_ERR_FROZEN-4Drive is frozen by BIOS
DI_ERR_NOT_SUPPORTED-3Drive doesn't support security feature set
DI_ERR_PERMISSION-2Not running as root
int di_nvme_sanitize(drive_info_t *drive, di_purge_method_t method)

Sends NVMe Sanitize command. Methods: DI_PURGE_NVME_SANITIZE_CRYPTO, DI_PURGE_NVME_SANITIZE_BLOCK.

Error Codes

Code Constant Description
0 DI_SUCCESS Operation completed successfully
-1 DI_ERR_GENERAL General / unspecified error
-2 DI_ERR_PERMISSION Insufficient permissions (not root)
-3 DI_ERR_NOT_SUPPORTED Feature not supported by device
-4 DI_ERR_FROZEN ATA security is frozen
-5 DI_ERR_LOCKED Drive is locked
-6 DI_ERR_IO I/O error during operation
-7 DI_ERR_BUSY Device is busy