mco_flashsim_save_image

Save the current state of a flash memory simulator to a persistent image file.

Prototype

    MCO_RET mco_flashsim_save_image(
        /*IN*/ mco_flashsim_h fs,
        /*IN*/ const char *image_name
    );

Arguments

fs
Handle to an open flash simulator instance.
image_name
Path to the output image file. If NULL, the function uses the filename specified in the original mco_flashsim_params_t::image_filename during initialization.

Description

This function persists the entire state of the flash simulator (including flash data, page states, and block wear/health information) to a binary image file.

The image file format includes:

Note: This function is only available when file system support is enabled at build time.

Return Codes

MCO_S_OK
Image successfully saved to disk.
MCO_E_INVALID_HANDLE
The provided simulator handle is invalid.
MCO_E_ILLEGAL_PARAM
Both image_name and the internal filename are NULL.
MCO_E_DISK_WRITE
Failed to write the image file (e.g., due to insufficient permissions or disk space).
MCO_E_UNSUPPORTED
File system support is disabled in the current build configuration.

Example

    // Save simulator state to a custom file
    MCO_RET rc = mco_flashsim_save_image(fs, "flash_checkpoint.img");
    if (rc == MCO_S_OK) {
        printf("Flash state saved successfully.\n");
    }

Files

Header file:
mcoflashsim.h
Source file:
mcoflashsim.c
Library:
libmcoflashsim.a