mco_open_file_rt

Open a file using a device-specific I/O implementation, with optional real-time deadline awareness.

Prototype

    mco_file_h mco_open_file_rt(
        /*IN*/ mco_db_h con,
        /*IN*/ const mco_device_t *dev
    );

Arguments

con
Database connection handle. If NULL (or zero), the file is opened in non-real-time mode without deadline enforcement. If valid, the file operations will respect the transaction’s real-time deadline.
dev
Pointer to a mco_device_t structure that describes the file or storage device. This structure may contain device-specific context such as:
  • A pointer to a global media descriptor,
  • Bus or driver context (e.g., SPI, I2C handle),
  • File path or memory buffer,
  • Custom media context (e.g., from a flash simulator).

Description

This function opens a file or storage device using an I/O backend that is determined by the dev->type field. It supports both standard file systems and custom embedded storage interfaces (e.g., raw flash, block devices, simulated media).

The con parameter controls real-time behavior:

This design allows the same API to work across diverse platforms (from desktop POSIX systems to bare-metal embedded targets) by encapsulating platform-specific context within the mco_device_t structure.

Common use cases include:

Return Value

mco_file_h
A handle to the opened file, or NULL if the operation failed (e.g., due to invalid device type, missing context, or I/O error).

Notes

For convenience, a macro is provided to open files in non-real-time mode without explicitly passing a null connection handle:

    #define mco_open_file(dev) mco_open_file_rt((mco_db_h)0, (dev))

This macro is intended for utility operations, initialization, or any scenario where real-time deadline guarantees are not required.

Example

    mco_device_t d = {0};
    char * backup_path = d.dev.file.name;
    ...
    d.type = MCO_MEMORY_FILE;
    d.assignment = MCO_MEMORY_ASSIGN_NONE;
    d.dev.file.flags = flags;
    // Set backup file name
    mco_strcpy(backup_path, db_name);
    mco_strcat(backup_path, "bck");
    ...
    f = mco_open_file(&d);
    if (f == NULL) {
        // Handle error
        ...
    }

Files

Header file:
mco.h
Source file:
Platform specific
Library:
libmcolib.a