|
ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
|
Coordinate bounded chapter export and validated publication. More...
#include "mdl_export.h"#include <ctype.h>#include <stdio.h>#include <string.h>#include "mdl_export_internal.h"#include "ra8_attributes.h"Go to the source code of this file.
Enumerations | |
| enum | mdl_export_time_radix_t : uint8_t { k_export_month_radix = 13U , k_export_hours_per_day = 24U , k_export_minutes_per_hour = 60U , k_export_seconds_per_minute = 60U } |
| Mixed-radix civil timestamp geometry used for stable ordering. More... | |
Functions | |
| mdl_format_t | mdl_format_from_str (const char *s) |
| Map a --format string to a container kind. | |
| const char * | mdl_format_ext (mdl_format_t fmt) |
| File extension (without dot) for a format, e.g. | |
| bool | mdl_format_is_dir_output (mdl_format_t fmt) |
| Whether fmt writes per-page sibling files rather than one container. | |
| static bool | internal_ends_with_ci (const char *name, const char *suffix) |
| Test a filename suffix without ASCII case sensitivity. | |
| static bool | internal_is_page_image (const char *name) |
| True if name is a raster page image a reader engine can decode. | |
| static void | internal_sort_pages (char names[][k_name_max], size_t count) |
| Sort a bounded page-name table lexically in place. | |
| static ra8_err_t | internal_list_pages_open_dir (mdl_storage_t *storage, const char *dir, mdl_export_workspace_t *ws, fw_fs_dir_t *directory) |
| Open the chapter directory cursor into workspace-backed state. | |
| static ra8_err_t | internal_list_pages (mdl_storage_t *storage, const char *dir, char names[][k_name_max], size_t cap, mdl_export_workspace_t *ws, size_t *out_count) |
| List and sort regular chapter image entries through a portable cursor. | |
| static uint64_t | internal_timestamp_key (const fw_fs_datetime_t *value) |
| Map one civil timestamp to a stable ordering key. | |
| static bool | internal_metadata_set_page_timestamp (mdl_storage_t *storage, mdl_export_meta_t *meta, const char *dir, const char names[][k_name_max], size_t count) |
| Derive a deterministic UTC modified timestamp from source pages. | |
| static ra8_err_t | internal_export_dispatch (mdl_storage_t *storage, mdl_format_t fmt, const char *dir, char names[][k_name_max], size_t count, mdl_export_output_t *output, const mdl_export_meta_t *meta, mdl_export_workspace_t *ws) |
| Dispatch one selected container writer. | |
| static ra8_err_t | internal_export_transaction (mdl_storage_t *storage, mdl_format_t fmt, const char *dir, char names[][k_name_max], size_t count, const char *out_path, const mdl_export_meta_t *meta, mdl_export_workspace_t *ws) |
| Build out_path through one storage transaction. | |
| static ra8_err_t | internal_resolve_export_metadata (mdl_storage_t *storage, const char *chapter_dir, char names[][k_name_max], size_t count, const mdl_export_meta_t *meta, mdl_export_meta_t *resolved) |
| Resolve and validate metadata for one chapter export. | |
| ra8_err_t | mdl_export_chapter_meta_ws (mdl_storage_t *storage, mdl_format_t fmt, const char *chapter_dir, const char *out_path, const mdl_export_meta_t *meta, mdl_export_workspace_t *ws) |
| Package a chapter with explicit metadata and caller-owned workspace. | |
| ra8_err_t | mdl_export_chapter_ws (mdl_storage_t *storage, mdl_format_t fmt, const char *chapter_dir, const char *out_path, mdl_export_workspace_t *ws) |
| Package a chapter after auto-loading bounded local metadata. | |
Coordinate bounded chapter export and validated publication.
Owns format selection, page discovery, workspace accounting, and dispatch to the format-specific writer translation units. Each writer keeps its own format rules while this unit preserves one publication policy.
[Ring 4 / Domain] {World: NS}
Definition in file mdl_export.c.
| enum mdl_export_time_radix_t : uint8_t |
Mixed-radix civil timestamp geometry used for stable ordering.
Definition at line 25 of file mdl_export.c.
|
static |
Test a filename suffix without ASCII case sensitivity.
Compares only the tail and rejects a suffix longer than the name.
| [in] | name | NUL-terminated filename. |
| [in] | suffix | NUL-terminated suffix. |
| true | The suffix matches ignoring ASCII case. |
| false | Length or bytes differ. |
Definition at line 108 of file mdl_export.c.
References RA8_INTERNAL, and strlen().
Referenced by internal_is_page_image().
|
static |
Dispatch one selected container writer.
Centralizes format-to-writer mapping while preserving the shared metadata and caller-workspace contract.
| [in,out] | storage | Injected portable file reader. |
| [in] | fmt | Selected output format. |
| [in] | dir | Chapter directory. |
| [in] | names | Sorted page-name rows. |
| [in] | count | Page count. |
| [in,out] | output | Active validated-publication output. |
| [in] | meta | Metadata to embed, or NULL. |
| [in,out] | ws | Exclusive caller-owned workspace. |
| k_ra8_ok | The selected writer completed. |
| k_ra8_err_invalid_arg | The format has no container writer here. |
| k_ra8_err_not_supported | An optional writer is unavailable. |
| k_ra8_fail | The selected writer failed. |
ws is exclusive and owns writable arena bytes. Definition at line 408 of file mdl_export.c.
References k_mdl_format_cbr, k_mdl_format_cbt, k_mdl_format_cbt_gz, k_mdl_format_cbt_xz, k_mdl_format_cbz, k_mdl_format_epub, k_mdl_format_invalid, k_mdl_format_jof, k_mdl_format_loose, k_mdl_format_rabook, k_name_max, k_ra8_err_invalid_arg, k_ra8_err_not_supported, priv_mdl_export_cbz(), priv_mdl_export_epub(), priv_mdl_export_tar(), priv_mdl_export_tar_gzip(), and RA8_INTERNAL.
Referenced by internal_export_transaction().
|
static |
Build out_path through one storage transaction.
The single publication seam for every container format, rather than making each writer remember it. A re-export that fails part-way because caller storage is exhausted, metadata is invalid, or output I/O fails cannot truncate the previously-good archive: the destination is untouched until a complete, independently verified stage exists.
| [in,out] | storage | Injected portable file reader. |
| [in] | fmt | Selected output format. |
| [in] | dir | Chapter directory. |
| [in] | names | Sorted page-name rows. |
| [in] | count | Page count. |
| [in] | out_path | Final destination path. |
| [in] | meta | Metadata to embed, or NULL. |
| [in,out] | ws | Exclusive caller-owned workspace. |
| k_ra8_ok | The completed stage was published. |
| k_ra8_fail | Stage reservation, writer, verification, or commit failed. |
| k_ra8_err_invalid_size | A selected writer exceeded a bound. |
| k_ra8_err_validation_failed | Cover or container validation failed. |
ws is exclusive and remains alive through commit. Definition at line 466 of file mdl_export.c.
References fw_fs_transaction_t::active, internal_export_dispatch(), k_name_max, k_ra8_ok, priv_mdl_export_output_abort(), priv_mdl_export_output_begin(), priv_mdl_export_output_commit(), RA8_INTERNAL, mdl_storage_txn_t::transaction, and mdl_export_output_t::writer.
Referenced by mdl_export_chapter_meta_ws().
|
static |
True if name is a raster page image a reader engine can decode.
Packaging must include ONLY page images. A chapter folder often also holds this tool's own prior output (a sibling .jof/.cbz, a .tar.tmp) or OS junk; folding those into an archive makes the reader choke when it decodes a non-image "page" (the 0x107 that bit re-runs). Filtering by extension keeps packaging idempotent – re-running any format on a folder is safe.
| [in] | name | NUL-terminated directory-entry name. |
| true | A supported raster suffix matched. |
| false | The entry is not a page image. |
name is non-NULL and NUL-terminated. name is unchanged. Definition at line 144 of file mdl_export.c.
References internal_ends_with_ci(), and RA8_INTERNAL.
Referenced by internal_list_pages().
|
static |
List and sort regular chapter image entries through a portable cursor.
Uses the injected directory cursor and caller arena, rejects symlink/nonregular qualifying entries, and closes before sorting.
| [in,out] | storage | Bound portable filesystem. |
| [in] | dir | Canonical chapter directory. |
| [out] | names | Fixed-width page table. |
| [in] | cap | Available page rows. |
| [in,out] | ws | Export workspace providing the directory backend state. |
| [out] | out_count | Number of page rows written. |
| k_ra8_ok | A complete sorted page table was produced. |
| k_ra8_err_invalid_size | A name, count, or workspace bound was exceeded. |
ws is exclusively owned. names has cap writable rows of k_name_max bytes. Definition at line 246 of file mdl_export.c.
References fw_fs_dir_close(), fw_fs_dir_next(), internal_is_page_image(), internal_list_pages_open_dir(), internal_sort_pages(), fw_fs_dir_t::is_open, k_fw_fs_node_file, k_name_max, k_ra8_err_invalid_arg, k_ra8_err_invalid_size, k_ra8_ok, memcpy(), fw_fs_dirent_value_t::name, fw_fs_dirent_value_t::name_bytes, RA8_INTERNAL, fw_fs_dirent_value_t::type, and mdl_export_workspace::used.
Referenced by mdl_export_chapter_meta_ws().
|
static |
Open the chapter directory cursor into workspace-backed state.
Queries filesystem capabilities, reserves the directory cursor's backend workspace, and opens the cursor at dir.
| [in,out] | storage | Bound portable filesystem. |
| [in] | dir | Canonical chapter directory. |
| [in,out] | ws | Export workspace providing the directory backend state. |
| [out] | directory | Receives the opened directory cursor. |
| k_ra8_ok | The directory cursor is open and ready to enumerate. |
| k_ra8_err_invalid_size | The directory workspace reservation failed. |
| other | A capability query or directory open failure propagated. |
storage, dir, ws, and directory are non-NULL. ws was initialized by mdl_export_workspace_init. directory->is_open is true. directory is not open and must not be closed. Definition at line 201 of file mdl_export.c.
References fw_fs_caps_t::directory_workspace_align, fw_fs_caps_t::directory_workspace_bytes, mdl_storage_t::fs, fw_fs_dir_open(), fw_fs_get_caps(), k_ra8_err_invalid_size, k_ra8_ok, mdl_export_workspace_take(), fw_fs_t::names, and RA8_INTERNAL.
Referenced by internal_list_pages().
|
static |
Derive a deterministic UTC modified timestamp from source pages.
Stats every selected page and formats the newest mtime as ISO-8601 UTC.
| [in,out] | storage | Injected portable metadata reader. |
| [in,out] | meta | Metadata object receiving the timestamp. |
| [in] | dir | NUL-terminated chapter directory. |
| [in] | names | Sorted page-name table. |
| [in] | count | Number of readable name rows. |
| true | meta->modified contains the derived timestamp. |
| false | A path, stat, clock conversion, or formatting step failed. |
meta is exclusively owned during the call. Definition at line 328 of file mdl_export.c.
References fw_fs_datetime_t::day, fw_fs_stat_t::exists, mdl_storage_t::fs, fw_fs_stat(), fw_fs_datetime_t::hour, internal_timestamp_key(), k_export_minutes_per_hour, k_fw_fs_node_file, k_fw_fs_path_cap, k_name_max, k_ra8_ok, fw_fs_datetime_t::minute, fw_fs_stat_t::modified, mdl_export_meta_t::modified, fw_fs_datetime_t::month, fw_fs_t::names, priv_mdl_export_path_join(), RA8_INTERNAL, fw_fs_datetime_t::second, fw_fs_stat_t::type, fw_fs_datetime_t::utc_offset_min, fw_fs_timestamp_t::utc_offset_valid, fw_fs_timestamp_t::valid, fw_fs_timestamp_t::value, and fw_fs_datetime_t::year.
Referenced by internal_resolve_export_metadata().
|
static |
Resolve and validate metadata for one chapter export.
Copies explicit metadata or initializes defaults, validates the source URL, and derives a missing modified time from the first page.
| [in,out] | storage | Injected portable storage binding. |
| [in] | chapter_dir | Canonical source chapter directory. |
| [in] | names | Sorted page-name rows. |
| [in] | count | Page count. |
| [in] | meta | Optional caller metadata. |
| [out] | resolved | Complete validated metadata. |
| k_ra8_ok | Metadata is ready for a writer. |
| k_ra8_fail | The first page timestamp could not be read. |
| k_ra8_err_invalid_arg | The source URL is invalid. |
resolved is exclusively writable. resolved. Definition at line 509 of file mdl_export.c.
References internal_metadata_set_page_timestamp(), k_name_max, k_ra8_fail, k_ra8_ok, mdl_meta_init(), mdl_export_meta_t::modified, priv_mdl_export_validate_source_url(), RA8_INTERNAL, and mdl_export_meta_t::source_url.
Referenced by mdl_export_chapter_meta_ws().
|
static |
Sort a bounded page-name table lexically in place.
Uses stable insertion sort so the caller needs no allocator, comparator callback, or hidden global sort context.
| [in,out] | names | Fixed-width table of terminated page filenames. |
| [in] | count | Number of readable and writable rows. |
names is non-NULL and contains count complete rows. Definition at line 168 of file mdl_export.c.
References k_name_max, memcpy(), RA8_INTERNAL, and strcmp().
Referenced by internal_list_pages().
|
static |
Map one civil timestamp to a stable ordering key.
Packs validated calendar fields with mixed-radix multiplication so lexical civil-time order becomes unsigned integer order.
| [in] | value | Portable civil-time value. |
| uint64_t | Packed within-volume civil timestamp key. |
value comes from a valid filesystem timestamp. Definition at line 301 of file mdl_export.c.
References fw_fs_datetime_t::day, fw_fs_datetime_t::hour, k_export_hours_per_day, k_export_minutes_per_hour, k_export_month_radix, k_export_seconds_per_minute, fw_fs_datetime_t::minute, fw_fs_datetime_t::month, RA8_INTERNAL, fw_fs_datetime_t::second, and fw_fs_datetime_t::year.
Referenced by internal_metadata_set_page_timestamp().
| ra8_err_t mdl_export_chapter_meta_ws | ( | mdl_storage_t * | storage, |
| mdl_format_t | fmt, | ||
| const char * | chapter_dir, | ||
| const char * | out_path, | ||
| const mdl_export_meta_t * | meta, | ||
| mdl_export_workspace_t * | ws ) |
Package a chapter with explicit metadata and caller-owned workspace.
Enumerates bounded page names, derives deterministic timestamps, validates any external cover, independently verifies a borrowed transaction stage, and publishes out_path only after the selected writer succeeds. JOF publishes one validated sibling per page and therefore reports partial progress on a later-page failure.
| [in,out] | storage | Injected portable storage used for image classification. |
| [in] | fmt | Target output format. |
| [in] | chapter_dir | Directory containing verified page images. |
| [in] | out_path | Container path, or chapter directory for JOF output. |
| [in] | meta | Metadata to embed, or NULL for deterministic defaults. |
| [in,out] | ws | Exclusive bounded exporter workspace. |
| k_ra8_ok | All requested output was completed. |
| k_ra8_err_invalid_arg | A pointer, workspace, or format is invalid. |
| k_ra8_err_invalid_size | A bound or workspace capacity was exceeded. |
| k_ra8_err_empty | No qualifying page image exists. |
| k_ra8_err_validation_failed | An external cover is not a recognized image. |
| k_ra8_err_not_supported | The reserved writer is unavailable. |
| k_ra8_fail | File or container writing failed. |
storage is initialized, exclusive, and all paths are canonical beneath it. ws owns writable storage and is not shared concurrently. Definition at line 532 of file mdl_export.c.
References mdl_export_workspace::data, mdl_export_workspace::high_water, internal_export_transaction(), internal_list_pages(), internal_resolve_export_metadata(), k_max_pages, k_mdl_format_cbr, k_mdl_format_cbt_xz, k_mdl_format_invalid, k_mdl_format_jof, k_mdl_format_loose, k_mdl_format_rabook, k_name_max, k_ra8_err_empty, k_ra8_err_invalid_arg, k_ra8_err_invalid_size, k_ra8_err_not_supported, k_ra8_ok, mdl_export_workspace_take(), priv_mdl_export_jof(), priv_mdl_export_rabook(), and mdl_export_workspace::used.
Referenced by internal_pack_combined_dir(), internal_pack_combined_dir_output(), internal_pack_dir_output(), mdl_export_chapter_ws(), and mdl_pack_one_meta().
| ra8_err_t mdl_export_chapter_ws | ( | mdl_storage_t * | storage, |
| mdl_format_t | fmt, | ||
| const char * | chapter_dir, | ||
| const char * | out_path, | ||
| mdl_export_workspace_t * | ws ) |
Package a chapter after auto-loading bounded local metadata.
Loads the supported metadata files from chapter_dir and delegates to mdl_export_chapter_meta_ws with the same publication guarantees.
| [in,out] | storage | Injected portable storage used for image classification. |
| [in] | fmt | Target output format. |
| [in] | chapter_dir | Directory containing pages and optional metadata. |
| [in] | out_path | Container path, or chapter directory for JOF output. |
| [in,out] | ws | Exclusive bounded exporter workspace. |
| k_ra8_ok | Output was completed. |
| k_ra8_err_invalid_arg | A pointer, workspace, or format is invalid. |
| k_ra8_err_invalid_size | Metadata or exporter bounds were exceeded. |
| k_ra8_err_empty | No qualifying pages exist. |
| k_ra8_fail | File or container writing failed. |
storage is initialized, exclusive, and all paths are canonical beneath it. ws owns writable storage and is not shared concurrently. Definition at line 592 of file mdl_export.c.
References mdl_export_chapter_meta_ws(), mdl_meta_init(), and mdl_meta_load_dir().
Referenced by internal_pack_directory_output(), and internal_pack_file_output().
| const char * mdl_format_ext | ( | mdl_format_t | fmt | ) |
File extension (without dot) for a format, e.g.
"cbz" / "cbt.xz".
Definition at line 58 of file mdl_export.c.
References k_mdl_format_cbr, k_mdl_format_cbt, k_mdl_format_cbt_gz, k_mdl_format_cbt_xz, k_mdl_format_cbz, k_mdl_format_epub, k_mdl_format_invalid, k_mdl_format_jof, k_mdl_format_loose, and k_mdl_format_rabook.
Referenced by internal_pack_combined_dir(), mdl_app_run_pack(), and mdl_pack_one_meta().
| mdl_format_t mdl_format_from_str | ( | const char * | s | ) |
Map a --format string to a container kind.
Recognizes only formats the CLI may currently emit; NULL and the explicit loose token select loose pages, while reserved formats remain invalid until their writer and validator are available.
| [in] | s | Format name, or NULL (treated as "loose"). |
| k_mdl_format_loose | s is NULL or names loose output. |
| k_mdl_format_rabook | s names the strict reader-native container. |
| k_mdl_format_invalid | s is an unknown or reserved format name. |
s is NULL or points to a NUL-terminated string. Definition at line 32 of file mdl_export.c.
References k_mdl_format_cbt, k_mdl_format_cbt_gz, k_mdl_format_cbz, k_mdl_format_epub, k_mdl_format_invalid, k_mdl_format_jof, k_mdl_format_loose, k_mdl_format_rabook, and strcmp().
Referenced by internal_prepare_run_policy().
| bool mdl_format_is_dir_output | ( | mdl_format_t | fmt | ) |
Whether fmt writes per-page sibling files rather than one container.
JOF is inherently per-page: ::mdl_export_chapter writes one .jof band atlas beside each source image inside the chapter directory, so a JOF "chapter" is a directory of atlases, not a single archive at out_path. Every other archive format produces exactly one file at out_path. Callers use this to report what was actually written – a success message must never name a container file that a directory-output format did not create.
| [in] | fmt | Format to classify. |
fmt produces per-page sibling files in the chapter dir. | true | fmt is k_mdl_format_jof (per-page .jof siblings). |
| false | fmt produces a single container file at out_path. |
fmt is a value of mdl_format_t. Definition at line 84 of file mdl_export.c.
References k_mdl_format_jof.
Referenced by internal_pack_combined_dir(), mdl_app_run_pack(), and mdl_pack_one_meta().