ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
Loading...
Searching...
No Matches
comic_cbt.c
Go to the documentation of this file.
1
26#include <stddef.h>
27#include <stdint.h>
28
29#include "comic.h"
30#include "comic_internal.h"
31#include "ra8_attributes.h"
32#include "ra8_check.h"
33#include "unarch_tar.h"
34
36static const char* const s_tag_cbt = "comic_cbt";
37
43typedef enum : uint32_t {
47
68internal_add_member(comic_t* c, const unarch_tar_entry_t* ent, const char* name, uint16_t nlen)
69{
70 if (ent->is_file == 0U) {
71 return k_ra8_ok;
72 }
73 if (!priv_comic_is_page_name(name, nlen)) {
74 return k_ra8_ok;
75 }
76 return priv_comic_page_add(c,
77 name,
78 nlen,
79 ent->size,
80 1U,
81 (uint8_t)k_ra8_rar_method_store, /* stored verbatim */
82 0U,
83 ent->data_off,
84 ent->size);
85}
86
88{
89 RA8_CHECK_NULL_PTR(c, s_tag_cbt, "cbt open: null c");
90 if (!c->tar.live) {
92 }
93 uint64_t off = 0U;
94 for (uint32_t n = 0U; n < (uint32_t)k_cbt_max_members; ++n) { /* bound: static member cap */
95 char nb[k_cbt_name_max] = {};
96 unarch_tar_entry_t ent = {};
97 const ra8_err_t nerr = unarch_tar_next(&c->tar, off, nb, (uint16_t)sizeof(nb), &ent);
98 if (nerr == k_ra8_err_not_found) {
99 return k_ra8_ok; /* clean end of archive */
100 }
101 if (nerr != k_ra8_ok) {
102 return nerr; /* malformed / lying / over-policy member: reject */
103 }
104 const ra8_err_t ae = internal_add_member(c, &ent, nb, ent.name_len);
105 if (ae != k_ra8_ok) {
106 return ae; /* index / arena full -- a real capacity error, propagate */
107 }
108 off = ent.next_off;
109 }
110 return k_ra8_err_validation_failed; /* GCOVR_EXCL_LINE -- the walker's policy
111 * entry cap (4096) fires inside tar_next
112 * far below the static member cap */
113}
114
116priv_comic_cbt_extract(comic_t* c, const comic_page_t* p, uint8_t* buf, size_t cap, size_t* got)
117{
118 RA8_CHECK_NULL_PTR(c, s_tag_cbt, "cbt extract: null c");
119 RA8_CHECK_NULL_PTR(p, s_tag_cbt, "cbt extract: null p");
120 RA8_CHECK_NULL_PTR(buf, s_tag_cbt, "cbt extract: null buf");
121 RA8_CHECK_NULL_PTR(got, s_tag_cbt, "cbt extract: null got");
122 *got = 0U;
123 if (!c->tar.live) {
125 }
126 unarch_tar_entry_t ent = {};
127 ent.is_file = 1U;
128 ent.data_off = p->data_off;
129 ent.size = p->raw_size;
130 return unarch_tar_read(&c->tar, &ent, buf, cap, got);
131}
bool priv_comic_is_page_name(const char *name, uint16_t len)
Whether an archive entry name is a decodable comic page image.
Definition comic.c:152
ra8_err_t priv_comic_page_add(comic_t *c, const char *name, uint16_t name_len, uint64_t raw_size, uint8_t extractable, uint8_t method, uint32_t zip_index, uint64_t data_off, uint64_t pack_size)
Append one image member to the resident page index.
Definition comic.c:177
Unified demand-paged reader for comic-book archives – CBZ (ZIP) and CBR (RAR).
cbt_limits_t
Name scratch size for the tar member walk.
Definition comic_cbt.c:43
@ k_cbt_max_members
Static upper bound on members walked.
Definition comic_cbt.c:45
@ k_cbt_name_max
Longest member name indexed (bytes, incl.
Definition comic_cbt.c:44
ra8_err_t priv_comic_cbt_open(comic_t *c)
Open the CBT (tar) backend: walk the archive + build the page index.
Definition comic_cbt.c:87
static ra8_err_t internal_add_member(comic_t *c, const unarch_tar_entry_t *ent, const char *name, uint16_t nlen)
Index one tar member if it is a decodable page-image file.
Definition comic_cbt.c:68
ra8_err_t priv_comic_cbt_extract(comic_t *c, const comic_page_t *p, uint8_t *buf, size_t cap, size_t *got)
Extract one CBT page's encoded image (verbatim tar member copy).
Definition comic_cbt.c:116
static const char *const s_tag_cbt
Log tag for CBT-backend diagnostics.
Definition comic_cbt.c:36
Cross-TU seams between the comic facade and its CBZ / CBR backends.
Annotation-attribute framework macros for ra8-firmware.
#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).
Validation and Error-Checking Macros for ra8-firmware.
#define RA8_CHECK_NULL_PTR(ptr, tag, message)
Reject nullptr pointer, returning k_ra8_err_null_ptr.
Definition ra8_check.h:243
@ k_ra8_err_invalid_state
Module in wrong state for requested operation.
Definition ra8_err.h:161
@ k_ra8_err_validation_failed
Validation rule failed (caller-supplied invariant not satisfied).
Definition ra8_err.h:459
@ k_ra8_ok
Success – operation completed with all postconditions satisfied.
Definition ra8_err.h:119
@ k_ra8_err_not_found
Requested item not found (lookup / search missed).
Definition ra8_err.h:173
ra8_err_codes_t ra8_err_t
Canonical error-return type used by every ra8-firmware API.
Definition ra8_err.h:546
@ k_ra8_rar_method_store
Uncompressed: data area is the file bytes.
Definition ra8_rar.h:112
One entry in the resident, sorted page index.
Definition comic.h:140
uint64_t raw_size
Encoded image length in bytes (decoder input).
Definition comic.h:148
uint64_t data_off
CBR: absolute offset of the member data area.
Definition comic.h:146
One open comic archive: backing, kind, page index, and backend state.
Definition comic.h:179
unarch_tar_t tar
CBT tar walker state.
Definition comic.h:192
One decoded tar member: a file, a directory, or a skipped block.
Definition unarch_tar.h:122
uint64_t data_off
Absolute offset of the member's data area.
Definition unarch_tar.h:123
uint64_t size
Member data length in bytes (stored verbatim).
Definition unarch_tar.h:124
uint64_t next_off
Absolute offset of the next member's first block.
Definition unarch_tar.h:125
uint8_t is_file
1 if this member is a regular file.
Definition unarch_tar.h:127
uint16_t name_len
Name bytes copied into the caller buffer (clamped).
Definition unarch_tar.h:126
bool live
Open succeeded and not superseded.
Definition unarch_tar.h:102
Clean-room, read-only streaming tar walker (POSIX ustar + pax + GNU).
ra8_err_t unarch_tar_next(unarch_tar_t *t, uint64_t off, char *name_buf, uint16_t name_cap, unarch_tar_entry_t *out)
Decode the member at off and advance to the next member.
Definition unarch_tar.c:419
ra8_err_t unarch_tar_read(const unarch_tar_t *t, const unarch_tar_entry_t *ent, uint8_t *buf, size_t cap, size_t *got)
Copy a file member's data area into the caller buffer.
Definition unarch_tar.c:486