22typedef enum : uint32_t {
60 if ((ctx ==
nullptr) || (staged ==
nullptr)) {
100 if ((offset > output->
extent) || (length > (UINT64_MAX - offset))) {
104 if (offset != output->
offset) {
108 while ((err ==
k_ra8_ok) && (done < length)) {
112 const size_t remaining = length - done;
113 const uint32_t request = (remaining > UINT32_MAX) ? UINT32_MAX : (uint32_t)remaining;
114 uint32_t written = 0U;
117 if ((err ==
k_ra8_ok) && (written == 0U)) {
122 output->
offset = offset + done;
131 const char* destination,
134 if ((output ==
nullptr) || (storage ==
nullptr) || (destination ==
nullptr) ||
148 const char* destination,
151 if ((output ==
nullptr) || (storage ==
nullptr) || (destination ==
nullptr) ||
166 if ((output ==
nullptr) || ((bytes ==
nullptr) && (length != 0U)) ||
179 const uint8_t* bytes,
181 uint32_t* out_written)
184 if (out_written !=
nullptr) {
187 if ((output ==
nullptr) || (out_written ==
nullptr) || ((bytes ==
nullptr) && (length != 0U)) ||
196 *out_written = length;
204 if ((output ==
nullptr) || ((bytes ==
nullptr) && (length != 0U)) ||
219 if (output ==
nullptr) {
233 if ((output ==
nullptr) || (workspace ==
nullptr) || (out_published ==
nullptr) ||
237 *out_published =
false;
241 return (aborted ==
k_ra8_ok) ? primary : aborted;
244 .workspace = workspace,
254 if ((err ==
k_ra8_ok) && !*out_published) {
272 if ((source ==
nullptr) || (storage ==
nullptr) || (storage->
fs ==
nullptr) ||
299 uint64_t open_size = 0U;
317 if (source ==
nullptr) {
334 if ((source ==
nullptr) || (destination ==
nullptr) || !source->
file.
is_open ||
342 const uint64_t remaining = source->
size - source->
offset;
343 size_t target = capacity;
344 if ((uint64_t)target > remaining) {
345 target = (size_t)remaining;
353 const size_t left = target - done;
354 const uint32_t request = (left > UINT32_MAX) ? UINT32_MAX : (uint32_t)left;
377 uint64_t digest = 0U;
410 const mz_bool added = mz_zip_writer_add_read_buf_callback(zip,
423 if (added == MZ_FALSE) {
459 if ((memory ==
nullptr) || (destination ==
nullptr) || (offset != memory->
offset) ||
464 if (amount > capacity) {
474 const uint8_t* bytes,
478 if ((zip ==
nullptr) || (member ==
nullptr) || ((bytes ==
nullptr) && (length != 0U))) {
482 const mz_bool added = mz_zip_writer_add_read_buf_callback(zip,
501 if ((source ==
nullptr) || (sink ==
nullptr) || !source->
file.
is_open ||
502 (source->
storage ==
nullptr)) {
506 const uint64_t remaining = source->
size - source->
offset;
508 if ((uint64_t)request > remaining) {
509 request = (uint32_t)remaining;
522 uint8_t* destination,
526 if ((destination ==
nullptr) || (out_length ==
nullptr)) {
534 if ((source.
size > capacity) || (source.
size > SIZE_MAX)) {
538 const uint64_t expected = source.
size;
541 if ((err ==
k_ra8_ok) && (got != (
size_t)expected)) {
553 if ((out ==
nullptr) || (capacity == 0U) || (directory ==
nullptr) || (leaf ==
nullptr)) {
556 const char* separator = (
strcmp(directory,
"/") == 0) ?
"" :
"/";
557 const int written = snprintf(out, capacity,
"%s%s%s", directory, separator, leaf);
ra8_err_t fw_fs_open(const fw_fs_stream_port_t *streams, const char *path, fw_fs_open_mode_t mode, fw_fs_file_t *file, void *workspace, uint32_t workspace_size)
Open a file into a caller-owned handle and backend workspace.
ra8_err_t fw_fs_transaction_seek(fw_fs_transaction_t *transaction, uint64_t absolute_offset)
Seek the staging writer to an absolute byte offset for bounded backfill.
ra8_err_t fw_fs_transaction_abort(fw_fs_transaction_t *transaction)
Close and remove an unpublished staging artifact.
ra8_err_t fw_fs_stat(const fw_fs_namespace_t *names, const char *path, fw_fs_stat_t *out)
Query a path; a miss is success with out->exists == false.
ra8_err_t fw_fs_transaction_validate(fw_fs_transaction_t *transaction, fw_fs_validate_fn_t validator, void *validator_ctx)
Flush/reopen the stage and ask validator to inspect it read-only.
ra8_err_t fw_fs_read(fw_fs_file_t *file, uint8_t *dst, uint32_t cap, uint32_t *out_read)
Read up to cap bytes; zero bytes is EOF.
ra8_err_t fw_fs_transaction_write(fw_fs_transaction_t *transaction, const uint8_t *source, uint32_t length, uint32_t *out_written)
Append bytes to the private staging artifact.
ra8_err_t fw_fs_close(fw_fs_file_t *file)
Close and consume an open handle.
ra8_err_t fw_fs_seek(fw_fs_file_t *file, uint64_t absolute_offset)
Seek to an absolute byte offset from the beginning.
ra8_err_t fw_fs_transaction_commit(fw_fs_transaction_t *transaction, bool *out_published)
Publish a validated stage.
ra8_err_t fw_fs_file_size(fw_fs_file_t *file, uint64_t *out_size)
Report the open file's current length.
@ k_fw_fs_node_file
Regular byte stream.
@ k_fw_fs_open_read
Existing file, read-only.
struct mdl_export_workspace mdl_export_workspace_t
Caller-owned bounded arena for all exporter scratch state.
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_path_join(char *out, size_t capacity, const char *directory, const char *leaf)
Join a canonical directory and leaf without truncation.
ra8_err_t priv_mdl_export_output_abort(mdl_export_output_t *output)
Abort one unpublished export stage, retaining cleanup failure.
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.
static ra8_err_t internal_output_write_at(mdl_export_output_t *output, uint64_t offset, const uint8_t *bytes, size_t length)
Write a complete byte span at one staged offset.
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_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_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_source_close(mdl_export_source_t *source)
Close one open source and clear its retained binding.
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.
mdl_export_io_limit_t
Bounded callback call count shared by archive stream adapters.
@ k_export_io_calls
Short-I/O progress ceiling.
static ra8_err_t internal_validate_stage(void *ctx, fw_fs_file_t *staged)
Dispatch structural validation for one staged artifact.
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_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_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_source_verify_close(mdl_export_source_t *source)
Verify the first source pass against an independent reread.
static size_t internal_memory_read(void *opaque, mz_uint64 offset, void *destination, size_t capacity)
Serve a sequential ZIP read from immutable caller memory.
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.
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.
Private portable byte-stream contracts for media exporters.
ra8_err_t(* mdl_export_sink_fn_t)(void *ctx, const uint8_t *bytes, uint32_t length)
Portable archive-output sink signature.
Content-identity hashing (FNV-1a 64) for the media downloader's persistent library state.
@ k_mdl_hash_max_file_bytes
Exact file hash bound.
@ k_mdl_fnv_offset
FNV-1a 64 offset basis.
ra8_err_t mdl_hash_stream(fw_fs_file_t *file, uint64_t file_size, uint8_t *buffer, uint32_t buffer_bytes, uint64_t *out)
Hash exactly one snapshotted extent from an already-open stream.
uint64_t mdl_hash_bytes_seed(const void *data, size_t len, uint64_t seed)
Continue an FNV-1a 64 fold over a byte range from a running state.
ra8_err_t mdl_storage_txn_begin_new(mdl_storage_txn_t *writer, mdl_storage_t *storage, const char *destination)
Begin one streamed create-new publication without replacement.
ra8_err_t mdl_storage_txn_abort(mdl_storage_txn_t *writer)
Abort and clear one streamed transaction.
ra8_err_t mdl_storage_txn_begin(mdl_storage_txn_t *writer, mdl_storage_t *storage, const char *destination)
Begin one streamed create or truthful atomic replacement.
Bounded, no-heap structural validation of mdl artifacts.
ra8_err_t mdl_verify_open_file(mdl_storage_t *storage, mdl_format_t format, fw_fs_file_t *file, uint64_t size_bytes, mdl_export_workspace_t *workspace, mdl_verify_report_t *report)
Validate an artifact through a borrowed open filesystem handle.
bool mdl_format_is_verifiable(mdl_format_t format)
Report whether a format has an in-process structural validator.
#define RA8_PRIV
Module-private helper: shared across TUs but only inside one library.
#define RA8_INTERNAL
Marker that a function is intended to be static (file-local).
@ k_ra8_fail
Generic unspecified failure.
@ k_ra8_err_invalid_arg
Invalid function argument.
@ k_ra8_err_invalid_state
Module in wrong state for requested operation.
@ k_ra8_ok
Success – operation completed with all postconditions satisfied.
@ k_ra8_err_protocol_error
Protocol-level error (e.g.
@ k_ra8_err_not_found
Requested item not found (lookup / search missed).
@ k_ra8_err_invalid_size
Invalid size parameter (too large, too small, or misaligned).
ra8_err_codes_t ra8_err_t
Canonical error-return type used by every ra8-firmware API.
int strcmp(const char *s1, const char *s2)
Compare two null-terminated strings.
void * memcpy(void *dst, const void *src, size_t n)
Copy memory area between non-overlapping regions.
Caller-owned open file; fields are private to the facade.
bool is_open
Facade lifecycle guard.
Result of a portable metadata query.
uint64_t size_bytes
File length; zero for a directory.
bool exists
False means a clean lookup miss.
fw_fs_node_type_t type
Kind of node at the path.
fw_fs_stream_port_t streams
Byte-stream operations.
fw_fs_namespace_t names
Namespace operations.
bool active
Begin succeeded.
Sequential view over one caller-owned ZIP memory member.
const uint8_t * bytes
Borrowed immutable payload.
size_t length
Complete payload extent.
size_t offset
Sequential read cursor.
Context retained while a staged artifact is structurally checked.
uint64_t extent
Exact staged extent.
mdl_format_t format
Exact artifact format.
mdl_export_workspace_t * workspace
Borrowed verifier arena.
size_t export_high_water
Pre-validation high-water.
mdl_storage_t * storage
Borrowed storage scratch.
One validated staged publication, including random ZIP backfill.
uint64_t extent
Greatest written byte edge.
uint64_t offset
Current staged write position.
mdl_storage_txn_t writer
Active storage transaction.
ra8_err_t error
First callback error, if any.
mdl_format_t format
Canonical verifier selection.
One open regular source with a snapshotted identity.
mdl_storage_t * storage
Borrowed exclusive storage binding.
uint32_t calls
Bounded read-call tally.
ra8_err_t error
First callback error, if any.
fw_fs_file_t file
Open portable source stream.
uint64_t hash
First-pass FNV identity.
uint64_t offset
Sequential callback cursor.
uint64_t size
Snapshotted source extent.
size_t high_water
Largest used value observed.
One non-reentrant downloader filesystem dependency bundle.
uint32_t file_workspace_bytes
File workspace extent.
uint8_t * io_buffer
Caller-owned stream scratch.
const fw_fs_t * fs
Injected portable filesystem.
void * file_workspace
Open-file backend state.
uint32_t io_buffer_bytes
Stream scratch extent.
mdl_storage_t * storage
Exclusively borrowed storage binding.
fw_fs_transaction_t transaction
Active private filesystem stage.
uint32_t write_calls
Bounded backend write-call tally.