|
ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
|
On-import EPUB -> .rabook compile-and-cache manager (#151). More...
Go to the source code of this file.
Data Structures | |
| struct | rabook_import_stamp_t |
| Body of the sidecar freshness marker (<name>.rabook.mrk). More... | |
| struct | rabook_import_cfg_t |
| Injected dependencies + versioning for rabook_import_open. More... | |
Typedefs | |
| typedef ra8_err_t(* | rabook_import_compile_fn) (void *compile_ctx, ra8_fs_mount_t *mount, const char *epub_path, const char *out_path) |
| Dependency-injection seam: compile one EPUB into a .rabook blob. | |
Enumerations | |
| enum | rabook_import_size_t : uint16_t { k_rabook_import_name_cap = 128U , k_rabook_import_stamp_bytes = 20U } |
| Fixed sizing constants for the cache-name layout. More... | |
| enum | rabook_import_magic_t : uint32_t { k_rabook_import_stamp_magic = 0x52424B31U } |
| Sentinel stamped into the freshness marker so a stray file is rejected. More... | |
| enum | rabook_import_outcome_t : uint8_t { k_rabook_import_hit = 0U , k_rabook_import_compiled = 1U } |
| How rabook_import_open satisfied the request. More... | |
Functions | |
| ra8_err_t | rabook_import_open (const rabook_import_cfg_t *cfg, const char *epub_path, char *out_cache_path, uint32_t cache_path_cap, rabook_import_outcome_t *out_outcome) |
| Resolve a source .epub to a fresh cached .rabook, compiling once. | |
On-import EPUB -> .rabook compile-and-cache manager (#151).
rabook_import makes the e-reader a self-contained appliance: drop a raw .epub on the SD card and the first open compiles it once into the flat, execute-in-place .rabook blob (via the injected compiler seam), caches the result on the card, and takes the fast cached path on every subsequent open.
This header is the cache manager + import state machine only. It owns:
[Ring 4 / EPUB Import] {World: NS}
Definition in file rabook_import.h.
| typedef ra8_err_t(* rabook_import_compile_fn) (void *compile_ctx, ra8_fs_mount_t *mount, const char *epub_path, const char *out_path) |
Dependency-injection seam: compile one EPUB into a .rabook blob.
The manager calls this on a cache miss to produce the bare RABOOK1 body at out_path. Production binds the real rabook_compile_from_epub (through the supplied adapter); host tests bind a spy that records the call count.
| [in] | compile_ctx | Opaque cookie supplied in the config; carries the EPUB handle + builder arenas in production. |
| [in,out] | mount | Mounted volume holding the source and the output. |
| [in] | epub_path | Root-level path of the source .epub. |
| [in] | out_path | Root-level path to write the .rabook body to (the manager passes a temp name, then renames it). |
Definition at line 143 of file rabook_import.h.
| enum rabook_import_magic_t : uint32_t |
Sentinel stamped into the freshness marker so a stray file is rejected.
A marker that does not start with this tag (e.g. a same-named file left by another tool, or a torn write) is treated as absent and the book is re-derived.
| Enumerator | |
|---|---|
| k_rabook_import_stamp_magic | Importer marker tag "RBK1". |
Definition at line 84 of file rabook_import.h.
| enum rabook_import_outcome_t : uint8_t |
How rabook_import_open satisfied the request.
| Enumerator | |
|---|---|
| k_rabook_import_hit | Fresh cache reused; the compiler was NOT invoked. |
| k_rabook_import_compiled | Miss/stale; the book was compiled and cached. |
Definition at line 93 of file rabook_import.h.
| enum rabook_import_size_t : uint16_t |
Fixed sizing constants for the cache-name layout.
The cache entry is named after the SOURCE'S OWN name – the .epub basename with .rabook (cache), .rabook.tmp (crash-safe temp) or .rabook.mrk (freshness marker) appended – now that ra8_fs writes VFAT long names (#600/#633). The CRC-32 still keys freshness inside the marker, but no longer names the file. k_rabook_import_name_cap bounds the derivation onto fixed buffers; a source whose derived name does not fit is refused rather than truncated.
| Enumerator | |
|---|---|
| k_rabook_import_name_cap | Cache/temp/marker name buffer bytes incl. NUL. |
| k_rabook_import_stamp_bytes | Pinned size of the freshness stamp. |
Definition at line 71 of file rabook_import.h.
|
nodiscard |
Resolve a source .epub to a fresh cached .rabook, compiling once.
State machine on "open `epub_path`":
compile.compile to <name>.rabook.tmp, atomically rename it over <name>.rabook, write the fresh marker, and emit the cache path.| [in] | cfg | Injected dependencies + versioning (see struct). |
| [in] | epub_path | Root-level path of the source .epub. |
| [out] | out_cache_path | Receives the NUL-terminated cache .rabook path the caller then opens with book_open. |
| [in] | cache_path_cap | Capacity of out_cache_path in bytes; must hold the derived <name>.rabook name and its terminator. |
| [out] | out_outcome | Receives k_rabook_import_hit or k_rabook_import_compiled on success. |
| k_ra8_ok | Cache is fresh (hit) or freshly written (compiled). |
| k_ra8_err_null_ptr | A required pointer (incl. an injected dependency) is NULL. |
| k_ra8_err_invalid_arg | epub_path has no usable basename. |
| k_ra8_err_invalid_size | cache_path_cap is too small for the derived name, the derived name overflows the fixed buffer, or scratch_cap is zero. |
| k_ra8_err_not_found | The source .epub does not exist. |
| k_ra8_err_* | Propagated filesystem or compiler error (on a compile error the cache is left untouched). |
Definition at line 806 of file rabook_import.c.
References rabook_import_cfg_t::format_version, rabook_import_cfg_t::importer_version, internal_cache_is_fresh(), internal_compile_and_cache(), internal_compute_source_key(), internal_copy_name(), internal_derive_names(), internal_derive_stem(), internal_file_exists(), internal_validate_open_args(), k_ra8_err_invalid_size, k_ra8_ok, k_rabook_import_compiled, k_rabook_import_hit, k_rabook_import_name_cap, k_rabook_import_stamp_magic, rabook_import_cfg_t::mount, rabook_import_cfg_t::scratch, rabook_import_cfg_t::scratch_cap, and strlen().
Referenced by imp_run().