|
ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
|
Private portable byte-stream contracts for media exporters. More...
#include <stddef.h>#include <stdint.h>#include "mdl_export.h"#include "mdl_storage.h"#include "miniz.h"#include "ra8_attributes.h"#include "ra8_err.h"Go to the source code of this file.
Data Structures | |
| struct | mdl_export_source_t |
| One open regular source with a snapshotted identity. More... | |
| struct | mdl_export_output_t |
| One validated staged publication, including random ZIP backfill. More... | |
Typedefs | |
| typedef ra8_err_t(* | mdl_export_sink_fn_t) (void *ctx, const uint8_t *bytes, uint32_t length) |
| Portable archive-output sink signature. | |
Functions | |
| ra8_err_t | priv_mdl_export_output_begin (mdl_export_output_t *output, mdl_storage_t *storage, const char *destination, mdl_format_t format) |
| Bind a validated publication transaction to one destination. | |
| ra8_err_t | priv_mdl_export_output_begin_new (mdl_export_output_t *output, mdl_storage_t *storage, const char *destination, mdl_format_t format) |
| Bind a create-new validated publication transaction. | |
| ra8_err_t | priv_mdl_export_output_write (mdl_export_output_t *output, const uint8_t *bytes, uint32_t length) |
| Append one complete byte span to an active export stage. | |
| ra8_err_t | priv_mdl_export_output_write_at (void *opaque, uint64_t offset, const uint8_t *bytes, uint32_t length, uint32_t *out_written) |
| Write one complete span at an absolute active-stage offset. | |
| size_t | priv_mdl_export_zip_write (void *opaque, mz_uint64 file_offset, const void *bytes, size_t length) |
| Adapt random-offset miniz output to the active export stage. | |
| ra8_err_t | priv_mdl_export_output_commit (mdl_export_output_t *output, mdl_export_workspace_t *workspace, bool *out_published) |
| Structurally validate and publish one completed export stage. | |
| ra8_err_t | priv_mdl_export_output_abort (mdl_export_output_t *output) |
| Abort one unpublished export stage, retaining cleanup failure. | |
| ra8_err_t | priv_mdl_export_source_open (mdl_export_source_t *source, mdl_storage_t *storage, const char *path) |
| Open one regular source and snapshot its exact nonempty extent. | |
| ra8_err_t | priv_mdl_export_source_close (mdl_export_source_t *source) |
| Close one open source and clear its retained binding. | |
| size_t | priv_mdl_export_zip_read (void *opaque, mz_uint64 file_offset, void *destination, size_t capacity) |
| Adapt one sequential miniz source read to a portable file stream. | |
| ra8_err_t | priv_mdl_export_source_verify_close (mdl_export_source_t *source) |
| Verify the first source pass against an independent reread. | |
| ra8_err_t | priv_mdl_export_zip_add_file (mz_zip_archive *zip, mdl_storage_t *storage, const char *member, const char *path, mz_uint flags) |
| Add one portable source file through miniz callbacks. | |
| ra8_err_t | priv_mdl_export_zip_add_memory (mz_zip_archive *zip, const char *member, const uint8_t *bytes, size_t length, mz_uint flags) |
| Add caller-owned memory through the deterministic ZIP read seam. | |
| ra8_err_t | priv_mdl_export_source_copy (mdl_export_source_t *source, mdl_export_sink_fn_t sink, void *sink_ctx) |
| Stream one portable source into a bounded caller sink. | |
| ra8_err_t | priv_mdl_export_source_slurp (mdl_storage_t *storage, const char *path, uint8_t *destination, size_t capacity, size_t *out_length) |
| Read one complete bounded portable source into caller storage. | |
| ra8_err_t | priv_mdl_export_path_join (char *out, size_t capacity, const char *directory, const char *leaf) |
| Join a canonical directory and leaf without truncation. | |
Private portable byte-stream contracts for media exporters.
Binds archive sources and validated publication transactions to the existing downloader storage dependency. The contract owns no allocation, host descriptor, or device-specific path operation.
[Ring 4 / Domain] {World: NS}
Definition in file mdl_export_io_internal.h.
| typedef ra8_err_t(* mdl_export_sink_fn_t) (void *ctx, const uint8_t *bytes, uint32_t length) |
Portable archive-output sink signature.
Definition at line 47 of file mdl_export_io_internal.h.
| ra8_err_t priv_mdl_export_output_abort | ( | mdl_export_output_t * | output | ) |
Abort one unpublished export stage, retaining cleanup failure.
Delegates stage removal once and clears the exporter binding only after capturing the transaction's cleanup result.
| [in,out] | output | Active caller-owned staged output. |
| k_ra8_ok | The unpublished stage was removed. |
| k_ra8_fail | The injected transaction could not clean its stage. |
output is non-NULL and owns an active transaction. Definition at line 217 of file mdl_export_io.c.
References k_ra8_err_invalid_arg, k_ra8_ok, mdl_storage_txn_abort(), and mdl_export_output_t::writer.
Referenced by internal_direct_artifact_reset(), internal_emit_container(), internal_export_transaction(), internal_finish_artifact_fetch(), internal_jof_one(), internal_write_temp_epub(), and priv_mdl_export_output_commit().
| ra8_err_t priv_mdl_export_output_begin | ( | mdl_export_output_t * | output, |
| mdl_storage_t * | storage, | ||
| const char * | destination, | ||
| mdl_format_t | format ) |
Bind a validated publication transaction to one destination.
Initializes the output cursor only after the injected storage transaction accepts the canonical destination.
| [out] | output | Caller-owned output state to initialize. |
| [in,out] | storage | Exclusive portable storage transaction provider. |
| [in] | destination | Canonical NUL-terminated destination path. |
| [in] | format | Exact format used by the canonical staged verifier. |
| k_ra8_ok | A new unpublished stage is active. |
| k_ra8_err_invalid_arg | An argument or format is invalid. |
destination is stable for the call. output is not already bound to an active transaction. output inactive and publishes no destination bytes. Definition at line 129 of file mdl_export_io.c.
References k_ra8_err_invalid_arg, k_ra8_ok, mdl_format_is_verifiable(), mdl_storage_txn_begin(), and mdl_export_output_t::writer.
Referenced by internal_direct_artifact_reset(), internal_emit_container(), internal_export_transaction(), and internal_jof_one().
| ra8_err_t priv_mdl_export_output_begin_new | ( | mdl_export_output_t * | output, |
| mdl_storage_t * | storage, | ||
| const char * | destination, | ||
| mdl_format_t | format ) |
Bind a create-new validated publication transaction.
Mirrors priv_mdl_export_output_begin but refuses an existing destination, which is required for private intermediate artifacts.
| [out] | output | Caller-owned output state to initialize. |
| [in,out] | storage | Exclusive portable storage transaction provider. |
| [in] | destination | Canonical absent destination path. |
| [in] | format | Exact format used by the staged verifier. |
| k_ra8_ok | A new unpublished stage is active. |
| k_ra8_err_exists | The destination already exists. |
| k_ra8_err_invalid_arg | An argument or format is invalid. |
destination is stable for the call. output is not already bound to an active transaction. output inactive and changes no named file. Definition at line 146 of file mdl_export_io.c.
References k_ra8_err_invalid_arg, k_ra8_ok, mdl_format_is_verifiable(), mdl_storage_txn_begin_new(), RA8_PRIV, and mdl_export_output_t::writer.
Referenced by priv_mdl_rabook_temp_begin().
| ra8_err_t priv_mdl_export_output_commit | ( | mdl_export_output_t * | output, |
| mdl_export_workspace_t * | workspace, | ||
| bool * | out_published ) |
Structurally validate and publish one completed export stage.
Runs the canonical format verifier against the borrowed staged file, then asks the injected transaction to publish it once.
| [in,out] | output | Completed caller-owned staged output. |
| [in,out] | workspace | Exclusive caller arena used by the verifier. |
| [out] | out_published | Whether the transaction reports destination visibility. |
| k_ra8_ok | Validation and publication completed. |
| k_ra8_err_validation_failed | Canonical structural validation failed. |
output owns an active transaction with no retained writer error. workspace and out_published are writable and caller-owned. out_published true. Definition at line 229 of file mdl_export_io.c.
References fw_fs_transaction_t::active, mdl_export_output_t::error, mdl_export_output_t::extent, mdl_export_output_t::format, fw_fs_transaction_abort(), fw_fs_transaction_commit(), fw_fs_transaction_validate(), mdl_export_workspace::high_water, internal_validate_stage(), k_ra8_err_invalid_arg, k_ra8_err_invalid_state, k_ra8_ok, priv_mdl_export_output_abort(), mdl_storage_txn_t::storage, mdl_storage_txn_t::transaction, and mdl_export_output_t::writer.
Referenced by internal_emit_container(), internal_export_transaction(), internal_fetch_artifact(), internal_jof_one(), and internal_write_temp_epub().
| ra8_err_t priv_mdl_export_output_write | ( | mdl_export_output_t * | output, |
| const uint8_t * | bytes, | ||
| uint32_t | length ) |
Append one complete byte span to an active export stage.
Retries bounded short writes, advances the sequential cursor, and retains the first storage failure in the output state.
| [in,out] | output | Active caller-owned staged output. |
| [in] | bytes | Readable bytes to append. |
| [in] | length | Exact byte count to append. |
| k_ra8_ok | Every requested byte was written. |
| k_ra8_fail | The sink failed or made zero progress. |
output owns an active transaction and has no retained error. bytes addresses length readable bytes when length is nonzero. length. Definition at line 164 of file mdl_export_io.c.
References fw_fs_transaction_t::active, mdl_export_output_t::error, internal_output_write_at(), k_ra8_err_invalid_arg, k_ra8_ok, mdl_export_output_t::offset, mdl_storage_txn_t::transaction, and mdl_export_output_t::writer.
Referenced by internal_direct_artifact_write(), internal_direct_sink(), internal_gzip_put(), internal_jof_sink(), and priv_mdl_export_tar_gzip().
| ra8_err_t priv_mdl_export_output_write_at | ( | void * | opaque, |
| uint64_t | offset, | ||
| const uint8_t * | bytes, | ||
| uint32_t | length, | ||
| uint32_t * | out_written ) |
Write one complete span at an absolute active-stage offset.
Adapts the export transaction to the RABOOK container writer's random-write contract while retaining the first output error.
| [in,out] | opaque | Bound mdl_export_output_t. |
| [in] | offset | Absolute stage offset; holes are rejected. |
| [in] | bytes | Readable source bytes. |
| [in] | length | Exact requested byte count. |
| [out] | out_written | Exact written byte count on success. |
| k_ra8_ok | Every requested byte was staged. |
| k_ra8_err_invalid_arg | A pointer or output lifecycle is invalid. |
| k_ra8_err_invalid_size | The write would create a hole or overflow. |
opaque owns one active transaction and bytes spans length bytes. out_written is non-NULL and exclusively writable. out_written to length and updates the staged extent. out_written to zero and retains the first output error. Definition at line 177 of file mdl_export_io.c.
References fw_fs_transaction_t::active, mdl_export_output_t::error, internal_output_write_at(), k_ra8_err_invalid_arg, k_ra8_ok, RA8_PRIV, mdl_storage_txn_t::transaction, and mdl_export_output_t::writer.
Referenced by internal_emit_container().
| ra8_err_t priv_mdl_export_path_join | ( | char * | out, |
| size_t | capacity, | ||
| const char * | directory, | ||
| const char * | leaf ) |
Join a canonical directory and leaf without truncation.
Inserts one separator only when required and rejects arithmetic or capacity overflow before copying either component.
| [out] | out | Caller-owned destination string. |
| [in] | capacity | Total writable bytes including the terminator. |
| [in] | directory | Canonical NUL-terminated directory. |
| [in] | leaf | Canonical NUL-terminated leaf. |
| k_ra8_ok | The complete joined path fits. |
| k_ra8_err_invalid_size | The complete path exceeds capacity. |
out is writable for capacity bytes and does not overlap inputs. out as an empty string when capacity is nonzero. Definition at line 551 of file mdl_export_io.c.
References k_ra8_err_invalid_arg, k_ra8_err_invalid_size, k_ra8_ok, and strcmp().
Referenced by internal_build_tar(), internal_cbz_add_pages(), internal_epub_add_page(), internal_epub_media_type_from_sniff(), internal_meta_candidate_path(), internal_metadata_set_page_timestamp(), priv_mdl_export_jof(), and priv_mdl_rabook_temp_begin().
| ra8_err_t priv_mdl_export_source_close | ( | mdl_export_source_t * | source | ) |
Close one open source and clear its retained binding.
Closes the injected stream exactly once and clears all borrowed storage and cursor state regardless of close status.
| [in,out] | source | Open caller-owned source state. |
| k_ra8_ok | The source closed cleanly. |
| k_ra8_fail | The injected close operation failed. |
source is non-NULL and owns an open portable stream. Definition at line 315 of file mdl_export_io.c.
References mdl_export_source_t::file, fw_fs_close(), fw_fs_file_t::is_open, k_ra8_err_invalid_arg, and k_ra8_ok.
Referenced by internal_tar_write_source(), priv_mdl_export_source_slurp(), and priv_mdl_export_zip_add_file().
| ra8_err_t priv_mdl_export_source_copy | ( | mdl_export_source_t * | source, |
| mdl_export_sink_fn_t | sink, | ||
| void * | sink_ctx ) |
Stream one portable source into a bounded caller sink.
Reads the exact snapshotted extent through storage scratch, offers each bounded span to the sink, then performs an independent reread.
| [in,out] | source | Open caller-owned source. |
| [in] | sink | Non-NULL bounded output callback. |
| [in,out] | sink_ctx | Opaque sink context retained by the caller. |
| k_ra8_ok | The whole stable source reached the sink. |
| k_ra8_err_validation_failed | The source changed during the copy. |
source owns an open stream and sink is callable. Definition at line 499 of file mdl_export_io.c.
References mdl_export_source_t::error, mdl_export_source_t::file, mdl_storage_t::io_buffer, mdl_storage_t::io_buffer_bytes, fw_fs_file_t::is_open, k_ra8_err_invalid_arg, k_ra8_ok, mdl_export_source_t::offset, priv_mdl_export_source_verify_close(), priv_mdl_export_zip_read(), mdl_export_source_t::size, and mdl_export_source_t::storage.
Referenced by internal_tar_write_source().
| ra8_err_t priv_mdl_export_source_open | ( | mdl_export_source_t * | source, |
| mdl_storage_t * | storage, | ||
| const char * | path ) |
Open one regular source and snapshot its exact nonempty extent.
Rejects missing, empty, symlink, and nonregular nodes before opening the stream through the injected portable filesystem.
| [out] | source | Caller-owned source state to initialize. |
| [in,out] | storage | Exclusive portable stream provider. |
| [in] | path | Canonical NUL-terminated source path. |
| k_ra8_ok | A regular nonempty source is open. |
| k_ra8_err_invalid_arg | The node is symlinked or nonregular. |
path remains stable for the call. source does not own an open stream. source clear and owns no stream. Definition at line 270 of file mdl_export_io.c.
References fw_fs_stat_t::exists, mdl_export_source_t::file, mdl_storage_t::file_workspace, mdl_storage_t::file_workspace_bytes, mdl_storage_t::fs, fw_fs_close(), fw_fs_file_size(), fw_fs_open(), fw_fs_stat(), fw_fs_file_t::is_open, k_fw_fs_node_file, k_fw_fs_open_read, k_mdl_fnv_offset, k_mdl_hash_max_file_bytes, k_ra8_err_invalid_arg, k_ra8_err_invalid_size, k_ra8_err_not_found, k_ra8_err_protocol_error, k_ra8_ok, fw_fs_t::names, mdl_export_source_t::size, fw_fs_stat_t::size_bytes, fw_fs_t::streams, and fw_fs_stat_t::type.
Referenced by internal_tar_write_source(), priv_mdl_export_source_slurp(), and priv_mdl_export_zip_add_file().
| ra8_err_t priv_mdl_export_source_slurp | ( | mdl_storage_t * | storage, |
| const char * | path, | ||
| uint8_t * | destination, | ||
| size_t | capacity, | ||
| size_t * | out_length ) |
Read one complete bounded portable source into caller storage.
Opens and consumes one stable regular file without truncation, verifies it through an independent reread, and returns exact length.
| [in,out] | storage | Exclusive portable source storage. |
| [in] | path | Canonical source path. |
| [out] | destination | Caller-owned byte buffer. |
| [in] | capacity | Writable destination capacity. |
| [out] | out_length | Exact copied extent on success. |
| k_ra8_ok | A stable complete source was copied. |
| k_ra8_err_invalid_size | The snapshot exceeds capacity. |
destination is writable for capacity. storage is initialized and exclusive to this read. out_length and fills exactly that many bytes. out_length to zero and closes any opened stream. Definition at line 520 of file mdl_export_io.c.
References k_ra8_err_invalid_arg, k_ra8_err_invalid_size, k_ra8_err_protocol_error, k_ra8_ok, priv_mdl_export_source_close(), priv_mdl_export_source_open(), priv_mdl_export_source_verify_close(), priv_mdl_export_zip_read(), and mdl_export_source_t::size.
Referenced by internal_jof_load_source(), and internal_meta_load_candidate().
| ra8_err_t priv_mdl_export_source_verify_close | ( | mdl_export_source_t * | source | ) |
Verify the first source pass against an independent reread.
Requires complete first-pass consumption, seeks to the beginning, hashes an independent bounded reread, checks size stability, and closes.
| [in,out] | source | Open source after a complete first pass. |
| k_ra8_ok | Both passes and the final size snapshot match. |
| k_ra8_err_validation_failed | The source changed between passes. |
source owns an open regular stream. Definition at line 368 of file mdl_export_io.c.
References mdl_export_source_t::error, mdl_export_source_t::file, fw_fs_close(), fw_fs_seek(), mdl_export_source_t::hash, mdl_storage_t::io_buffer, mdl_storage_t::io_buffer_bytes, fw_fs_file_t::is_open, k_ra8_err_invalid_arg, k_ra8_err_protocol_error, k_ra8_ok, mdl_hash_stream(), mdl_export_source_t::offset, mdl_export_source_t::size, and mdl_export_source_t::storage.
Referenced by priv_mdl_export_source_copy(), priv_mdl_export_source_slurp(), and priv_mdl_export_zip_add_file().
| ra8_err_t priv_mdl_export_zip_add_file | ( | mz_zip_archive * | zip, |
| mdl_storage_t * | storage, | ||
| const char * | member, | ||
| const char * | path, | ||
| mz_uint | flags ) |
Add one portable source file through miniz callbacks.
Opens the source through injected storage, supplies deterministic callback metadata to miniz, then independently rereads before success.
| [in,out] | zip | Initialized caller-arena miniz writer. |
| [in,out] | storage | Exclusive portable source storage. |
| [in] | member | Canonical archive member name. |
| [in] | path | Canonical source path. |
| [in] | flags | Miniz compression flags. |
| k_ra8_ok | The complete stable source was added. |
| k_ra8_err_validation_failed | The source changed during export. |
zip is initialized with caller-owned allocator and output callbacks. Definition at line 399 of file mdl_export_io.c.
References mdl_export_source_t::error, k_ra8_fail, k_ra8_ok, priv_mdl_export_source_close(), priv_mdl_export_source_open(), priv_mdl_export_source_verify_close(), priv_mdl_export_zip_read(), and mdl_export_source_t::size.
Referenced by internal_cbz_add_pages(), internal_epub_add_external_cover(), internal_epub_add_page(), and priv_mdl_export_cbz().
| ra8_err_t priv_mdl_export_zip_add_memory | ( | mz_zip_archive * | zip, |
| const char * | member, | ||
| const uint8_t * | bytes, | ||
| size_t | length, | ||
| mz_uint | flags ) |
Add caller-owned memory through the deterministic ZIP read seam.
Binds an immutable bounded cursor to miniz's read-callback API so generated metadata uses the same deterministic member path.
| [in,out] | zip | Initialized caller-arena miniz writer. |
| [in] | member | Canonical archive member name. |
| [in] | bytes | Immutable caller-owned member bytes. |
| [in] | length | Exact member extent. |
| [in] | flags | Miniz compression flags. |
| k_ra8_ok | The memory member was added completely. |
| k_ra8_fail | Miniz rejected or incompletely consumed the member. |
bytes remains readable for length. zip is initialized and its caller arena remains live. Definition at line 472 of file mdl_export_io.c.
References internal_memory_read(), k_ra8_err_invalid_arg, k_ra8_fail, k_ra8_ok, internal_export_memory_t::length, and internal_export_memory_t::offset.
Referenced by internal_cbz_add_metadata(), and priv_mdl_epub_add_str().
| size_t priv_mdl_export_zip_read | ( | void * | opaque, |
| mz_uint64 | file_offset, | ||
| void * | destination, | ||
| size_t | capacity ) |
Adapt one sequential miniz source read to a portable file stream.
Enforces exact sequential offsets, bounded progress, snapshotted extent, and a running first-pass identity hash for later reread.
| [in,out] | opaque | Borrowed mdl_export_source_t callback context. |
| [in] | file_offset | Absolute source offset requested by miniz. |
| [out] | destination | Writable callback destination. |
| [in] | capacity | Maximum bytes requested. |
| 0 | End of the snapshot or a retained protocol/storage failure. |
opaque owns an open source and destination is writable. Definition at line 331 of file mdl_export_io.c.
References mdl_export_source_t::calls, mdl_export_source_t::error, mdl_export_source_t::file, fw_fs_read(), mdl_export_source_t::hash, fw_fs_file_t::is_open, k_export_io_calls, k_ra8_err_invalid_size, k_ra8_err_invalid_state, k_ra8_err_protocol_error, k_ra8_ok, mdl_hash_bytes_seed(), mdl_export_source_t::offset, and mdl_export_source_t::size.
Referenced by priv_mdl_export_source_copy(), priv_mdl_export_source_slurp(), and priv_mdl_export_zip_add_file().
| size_t priv_mdl_export_zip_write | ( | void * | opaque, |
| mz_uint64 | file_offset, | ||
| const void * | bytes, | ||
| size_t | length ) |
Adapt random-offset miniz output to the active export stage.
Seeks the injected transaction for ZIP backfill, writes the whole span with bounded progress, and returns miniz-compatible byte count.
| [in,out] | opaque | Borrowed mdl_export_output_t callback context. |
| [in] | file_offset | Absolute staged-file offset selected by miniz. |
| [in] | bytes | Readable archive bytes. |
| [in] | length | Requested byte count. |
length on complete success, otherwise zero. | 0 | Seek, size, or write failure occurred. |
opaque is a live output and bytes is readable for length. file_offset and length admit a uint64 extent without overflow. Definition at line 201 of file mdl_export_io.c.
References fw_fs_transaction_t::active, mdl_export_output_t::error, internal_output_write_at(), k_ra8_ok, mdl_storage_txn_t::transaction, and mdl_export_output_t::writer.
Referenced by priv_mdl_export_cbz(), and priv_mdl_export_epub().