Open a file using a device-specific I/O implementation, with optional real-time deadline awareness.
mco_file_h mco_open_file_rt(
/*IN*/ mco_db_h con,
/*IN*/ const mco_device_t *dev
);
con
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
mco_device_t structure that describes the file or storage device. This structure may contain device-specific context such as:
This function opens a file or storage device using an I/O backend that is determined by the
dev->typefield. It supports both standard file systems and custom embedded storage interfaces (e.g., raw flash, block devices, simulated media).The
conparameter controls real-time behavior:
- If
con == NULL, the file is opened in non-real-time mode - no deadline checks are performed during I/O.- If
conis a valid database connection, all subsequent I/O operations on this file will be subject to the transaction’s real-time deadline (if enabled in the runtime configuration).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_tstructure.Common use cases include:
- Opening a persistent database file on a host OS,
- Accessing raw flash via a flash translation layer,
- Using a flash simulator (
mco_flashsim) for testing,- Interfacing with custom hardware through a user-provided media context.
mco_file_h
NULL if the operation failed (e.g., due to invalid device type, missing context, or I/O error).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.
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
...
}