25typedef enum : uint32_t {
65 if ((pointer ==
nullptr) || (bytes == 0U)) {
68 const uintptr_t begin = (uintptr_t)pointer;
69 if ((uintptr_t)bytes > (UINTPTR_MAX - begin)) {
120 void* file_workspace,
121 uint32_t file_workspace_bytes,
122 void* transaction_workspace,
123 uint32_t transaction_workspace_bytes,
125 uint32_t io_buffer_bytes)
133 err =
internal_make_span(transaction_workspace, transaction_workspace_bytes, &spans[2]);
170 if ((pointer ==
nullptr) || (alignment == 0U)) {
173 return ((uintptr_t)pointer & ((uintptr_t)alignment - 1U)) == 0U;
178 void* file_workspace,
179 uint32_t file_workspace_bytes,
180 void* transaction_workspace,
181 uint32_t transaction_workspace_bytes,
183 uint32_t io_buffer_bytes)
185 if (storage ==
nullptr) {
188 if ((fs ==
nullptr) || (file_workspace ==
nullptr) || (transaction_workspace ==
nullptr) ||
189 (io_buffer ==
nullptr) || (io_buffer_bytes == 0U)) {
194 file_workspace_bytes,
195 transaction_workspace,
196 transaction_workspace_bytes,
209 if ((caps.
flags & required) != required) {
221 .file_workspace = file_workspace,
222 .transaction_workspace = transaction_workspace,
223 .io_buffer = io_buffer,
224 .file_workspace_bytes = file_workspace_bytes,
225 .transaction_workspace_bytes = transaction_workspace_bytes,
226 .io_buffer_bytes = io_buffer_bytes};
227 *storage = candidate;
251 if (transaction->
active) {
281 const uint8_t* source,
285 uint32_t offset = 0U;
286 while (offset < length) {
290 uint32_t written = 0U;
326 if ((ctx ==
nullptr) || (staged ==
nullptr)) {
367 const char* destination,
446 const char* destination,
505 uint64_t remaining = size;
507 uint32_t read_calls = 0U;
508 uint32_t write_calls = 0U;
511 const uint32_t wanted = (remaining < (uint64_t)storage->
io_buffer_bytes)
512 ? (uint32_t)remaining
517 if ((err !=
k_ra8_ok) || (read == 0U) || ((uint64_t)read > remaining)) {
528 if ((err ==
k_ra8_ok) && (remaining != 0U)) {
531 uint32_t trailing = 0U;
535 if ((err ==
k_ra8_ok) && (trailing != 0U)) {
545 if ((storage ==
nullptr) || (storage->
fs ==
nullptr) || (source ==
nullptr) ||
546 (destination ==
nullptr)) {
549 if (
strcmp(source, destination) == 0) {
578 bool published =
false;
580 if ((err ==
k_ra8_ok) && !published) {
607 const char* destination,
610 if ((writer ==
nullptr) || (storage ==
nullptr) || (storage->
fs ==
nullptr) ||
626 .transaction = transaction,
636 if ((writer ==
nullptr) || (storage ==
nullptr) || (storage->
fs ==
nullptr) ||
647 const char* destination)
655 ((bytes ==
nullptr) && (length != 0U))) {
661 uint32_t offset = 0U;
662 while (offset < length) {
666 uint32_t written = 0U;
685 if (writer ==
nullptr) {
704 .hash = writer->
hash,
710 bool published =
false;
712 if ((err ==
k_ra8_ok) && !published) {
718 return (aborted ==
k_ra8_ok) ? err : aborted;
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_get_caps(const fw_fs_t *fs, fw_fs_caps_t *out)
Copy the immutable capability snapshot from a complete binding.
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_begin(const fw_fs_transaction_port_t *port, const char *destination, fw_fs_transaction_policy_t policy, fw_fs_transaction_t *transaction, void *workspace, uint32_t workspace_size)
Create a hidden sibling staging file for one destination.
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_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.
fw_fs_transaction_policy_t
Destination policy for a staged transaction.
@ k_fw_fs_txn_create_new
Commit only when destination is absent.
@ k_fw_fs_txn_replace_atomic
Atomically replace an existing file.
@ k_fw_fs_cap_stream
Regular-file stream operations are available.
@ k_fw_fs_cap_namespace
Metadata and namespace operations are available.
@ k_fw_fs_cap_transactions
Staged publication operations are available.
static ra8_err_t internal_validate_stage(void *ctx, fw_fs_file_t *staged)
Dispatch structural validation for one staged artifact.
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_write(mdl_storage_txn_t *writer, const uint8_t *bytes, uint32_t length)
Append one complete caller chunk, tolerating bounded short writes.
static ra8_err_t internal_abort(fw_fs_transaction_t *transaction, ra8_err_t primary)
Abort an active transaction and preserve cleanup failure visibility.
static ra8_err_t internal_copy_payload(mdl_storage_t *storage, fw_fs_file_t *source, fw_fs_transaction_t *transaction, uint64_t size, uint64_t *hash)
Copy and hash one exact source payload into a transaction.
mdl_storage_limits_t
Bounded I/O progress limits for a complete copy.
@ k_storage_io_calls
Short-I/O and EOF call ceiling.
@ k_storage_span_count
Output plus workspace span count.
static ra8_err_t internal_policy(const mdl_storage_t *storage, const char *destination, fw_fs_transaction_policy_t *out)
Select create-new or truthful atomic replacement policy.
static ra8_err_t internal_txn_begin(mdl_storage_txn_t *writer, mdl_storage_t *storage, const char *destination, fw_fs_transaction_policy_t policy)
Begin a streaming writer with one explicit publication policy.
static ra8_err_t internal_source_size(const mdl_storage_t *storage, const char *source, uint64_t *size)
Resolve and validate one regular bounded source file.
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.
static ra8_err_t internal_validate_stage(void *ctx, fw_fs_file_t *staged)
Validate staged size and identity through its generic read handle.
static bool internal_aligned(const void *pointer, uint8_t alignment)
Return whether one pointer satisfies a backend alignment contract.
ra8_err_t mdl_storage_txn_abort(mdl_storage_txn_t *writer)
Abort and clear one streamed transaction.
ra8_err_t mdl_storage_copy_atomic(mdl_storage_t *storage, const char *source, const char *destination)
Copy a regular file through a validated atomic transaction.
static ra8_err_t internal_begin_copy(mdl_storage_t *storage, const char *source, const char *destination, fw_fs_file_t *source_file, fw_fs_transaction_t *transaction, uint64_t *size)
Open the copy source and begin its publication transaction.
ra8_err_t mdl_storage_txn_commit(mdl_storage_txn_t *writer)
Independently validate and publish a completed streamed transaction.
static ra8_err_t internal_write_all(fw_fs_transaction_t *transaction, const uint8_t *source, uint32_t length, uint32_t *calls)
Write all of one buffer while rejecting zero-progress success.
ra8_err_t mdl_storage_init(mdl_storage_t *storage, const fw_fs_t *fs, void *file_workspace, uint32_t file_workspace_bytes, void *transaction_workspace, uint32_t transaction_workspace_bytes, uint8_t *io_buffer, uint32_t io_buffer_bytes)
Validate and retain one filesystem plus caller-owned workspaces.
static ra8_err_t internal_make_span(const void *pointer, uint32_t bytes, internal_storage_span_t *out)
Convert one non-empty caller region into an address interval.
static ra8_err_t internal_validate_spans(mdl_storage_t *storage, void *file_workspace, uint32_t file_workspace_bytes, void *transaction_workspace, uint32_t transaction_workspace_bytes, uint8_t *io_buffer, uint32_t io_buffer_bytes)
Validate that output and operational workspaces are pairwise disjoint.
static bool internal_overlap(const internal_storage_span_t *left, const internal_storage_span_t *right)
Return whether two validated half-open intervals share a byte.
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.
Injected portable storage resources for downloader domain code.
Annotation-attribute framework macros for ra8-firmware.
#define RA8_INTERNAL
Marker that a function is intended to be static (file-local).
@ k_ra8_err_not_supported
Requested feature not compiled in, not wired, or not supported by this MCU variant.
@ k_ra8_err_no_mem
Static buffer exhausted (no dynamic memory on this project).
@ 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.
Static properties and workspace requirements of one bound port.
uint32_t file_workspace_bytes
State bytes required by open.
uint8_t transaction_workspace_align
Required transaction alignment.
uint8_t file_workspace_align
Required file-state alignment.
uint32_t flags
OR of fw_fs_capability_t.
uint32_t transaction_workspace_bytes
State bytes required by begin.
Caller-owned open file; fields are private to the facade.
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.
One complete composition-root filesystem binding.
fw_fs_stream_port_t streams
Byte-stream operations.
fw_fs_namespace_t names
Namespace operations.
fw_fs_transaction_port_t transactions
Staged publication.
Caller-owned transaction; fields are private to the facade.
bool active
Begin succeeded.
One overflow-checked half-open caller-storage interval.
uintptr_t end
One-past-last byte address.
uintptr_t begin
First byte address.
One non-reentrant downloader filesystem dependency bundle.
uint32_t transaction_workspace_bytes
Transaction workspace extent.
uint32_t file_workspace_bytes
File workspace extent.
void * transaction_workspace
Transaction backend state.
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.
Caller-owned streaming publication transaction with running identity.
uint64_t hash
Running FNV-1a identity.
mdl_storage_t * storage
Exclusively borrowed storage binding.
fw_fs_transaction_t transaction
Active private filesystem stage.
uint64_t size_bytes
Exact bytes accepted into the stage.
uint32_t write_calls
Bounded backend write-call tally.
Expected staged identity retained during validation.
uint64_t hash
FNV identity.
uint32_t buffer_bytes
Scratch extent.
uint64_t size_bytes
Exact staged length.
uint8_t * buffer
Caller-owned scratch.