|
ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
|
Bounded descriptor-backed storage composition for mkfontimg. More...
#include <errno.h>#include <fcntl.h>#include <limits.h>#include <stddef.h>#include <stdint.h>#include <stdio.h>#include <string.h>#include <sys/stat.h>#include <sys/types.h>#include <unistd.h>#include "mkfontimg_internal.h"#include "ra8_attributes.h"#include "ra8_err.h"#include "ra8_fs.h"Go to the source code of this file.
Data Structures | |
| struct | host_input_identity_t |
| Mutation-sensitive identity for one open regular input. More... | |
Macros | |
| #define | O_CLOEXEC (0) |
| No-op close-on-exec fallback for hosts lacking the flag. | |
| #define | O_DIRECTORY (0) |
| No-op directory-open fallback for hosts lacking the flag. | |
| #define | O_NOFOLLOW (0) |
| No-op no-follow fallback for hosts lacking the flag. | |
Enumerations | |
| enum | host_limit_t : uint32_t { k_host_stream_chunk = 16U * 1024U , k_host_temp_attempts = 128U , k_host_decimal_digits = 20U , k_host_decimal_base = 10U , k_host_create_mode = 0666U } |
| Fixed I/O, naming, and formatting bounds. More... | |
Functions | |
| void | priv_mkfontimg_diag (const char *text) |
| Write one complete best-effort diagnostic fragment to standard error. | |
| void | priv_mkfontimg_diag_u64 (uint64_t value) |
| Write one unsigned decimal value to standard error without stdio. | |
| static bool | internal_pread_exact (int fd, uint64_t offset, uint8_t *bytes, size_t length) |
| Read an exact positioned byte range with bounded retries. | |
| static bool | internal_pwrite_exact (int fd, uint64_t offset, const uint8_t *bytes, size_t length) |
| Write an exact positioned byte range with bounded retries. | |
| static bool | internal_block_range (const mkfontimg_disk_t *disk, uint64_t lba, uint32_t count, uint64_t *out_offset, size_t *out_bytes) |
| Translate one sector range to a representable byte range. | |
| static ra8_err_t | internal_disk_read (void *ctx, uint64_t lba, uint32_t count, uint8_t *buffer) |
| Read sectors from the sparse unpublished image. | |
| static ra8_err_t | internal_disk_write (void *ctx, uint64_t lba, uint32_t count, const uint8_t *buffer) |
| Write sectors into the sparse unpublished image. | |
| static ra8_err_t | internal_disk_capacity (void *ctx, uint64_t *block_count, uint32_t *block_size) |
| Report the fixed sparse-image geometry. | |
| static bool | internal_split_output (const char *path, char parent[k_mkfontimg_host_path_cap], char leaf[k_mkfontimg_host_name_cap]) |
| Split one output path into bounded parent and leaf components. | |
| static bool | internal_temp_name (char out[k_mkfontimg_host_name_cap], uint64_t process, uint32_t attempt) |
| Build one collision-resistant hidden temporary leaf. | |
| bool | priv_mkfontimg_host_begin (const char *final_path, uint64_t block_count, uint32_t block_size, mkfontimg_host_t *host) |
| Create, size, and bind one private sibling-temporary image. | |
| bool | priv_mkfontimg_host_seed (mkfontimg_host_t *host, const uint8_t *bytes, uint32_t length) |
| Seed exact bytes at the beginning of the temporary image. | |
| static host_input_identity_t | internal_identity (const struct stat *metadata) |
| Capture all mutation-sensitive fields from one successful fstat. | |
| static bool | internal_identity_equal (const host_input_identity_t *left, const host_input_identity_t *right) |
| Compare two initialized input identities without inspecting padding. | |
| static bool | internal_input_open (const char *path, uint64_t minimum_bytes, uint64_t maximum_bytes, int *out_fd, host_input_identity_t *identity) |
| Open and validate one non-symlink regular input. | |
| static bool | internal_stream (int input_fd, const host_input_identity_t *identity, ra8_fs_file_t *card) |
| Stream the first pass from host input to one new card file. | |
| static bool | internal_compare (int input_fd, const host_input_identity_t *identity, ra8_fs_file_t *card) |
| Compare a second host-input pass with the generated card file. | |
| static bool | internal_mkfontimg_write (ra8_fs_mount_t *mount, const char *input_path, const char *card_name, uint64_t minimum_bytes, uint64_t maximum_bytes, host_input_identity_t *out_identity) |
| Open the host input and stream it into a fresh card file. | |
| static bool | internal_mkfontimg_verify (ra8_fs_mount_t *mount, const char *input_path, const char *card_name, uint64_t minimum_bytes, uint64_t maximum_bytes, const host_input_identity_t *identity) |
| Reopen the host input and card file and verify byte-for-byte identity. | |
| bool | priv_mkfontimg_host_copy (const mkfontimg_host_t *host, ra8_fs_mount_t *mount, const char *input_path, const char *card_name, uint64_t minimum_bytes, uint64_t maximum_bytes, uint64_t *out_bytes) |
| Stream one stable host input into a card file and verify it by reread. | |
| bool | priv_mkfontimg_host_commit (mkfontimg_host_t *host) |
| Sync and atomically publish a complete temporary image. | |
| void | priv_mkfontimg_host_abort (mkfontimg_host_t *host) |
| Close and unlink an unpublished temporary image. | |
Bounded descriptor-backed storage composition for mkfontimg.
Implements exact positioned block I/O, immutable input streaming, card-file reread verification, and durable same-directory atomic publication. This is deliberately tool-private POSIX code; reusable filesystem code depends only on the ra8_fs_backend_t callbacks bound here.
Definition in file mkfontimg_host.c.
| #define O_CLOEXEC (0) |
No-op close-on-exec fallback for hosts lacking the flag.
Definition at line 34 of file mkfontimg_host.c.
| #define O_DIRECTORY (0) |
No-op directory-open fallback for hosts lacking the flag.
Definition at line 39 of file mkfontimg_host.c.
| #define O_NOFOLLOW (0) |
No-op no-follow fallback for hosts lacking the flag.
Definition at line 44 of file mkfontimg_host.c.
| enum host_limit_t : uint32_t |
Fixed I/O, naming, and formatting bounds.
Definition at line 48 of file mkfontimg_host.c.
|
static |
Translate one sector range to a representable byte range.
Checks device geometry and every host integer conversion before I/O.
| [in] | disk | Bound image geometry. |
| [in] | lba | First sector. |
| [in] | count | Sector count. |
| [out] | out_offset | Host byte offset. |
| [out] | out_bytes | Host byte count. |
| true | Both outputs describe the requested range. |
| false | Geometry or integer bounds reject it. |
Definition at line 199 of file mkfontimg_host.c.
References mkfontimg_disk_t::block_count, mkfontimg_disk_t::block_size, and RA8_INTERNAL.
|
static |
Compare a second host-input pass with the generated card file.
Verifies every byte and repeats the mutation-sensitive metadata check.
| [in] | input_fd | Open stable input. |
| [in] | identity | Original identity. |
| [in,out] | card | Open card file in read mode. |
| true | Every byte and final metadata match. |
| false | Read, size, content, or mutation validation failed. |
Definition at line 628 of file mkfontimg_host.c.
References internal_identity(), internal_identity_equal(), internal_pread_exact(), k_host_stream_chunk, k_ra8_ok, memcmp(), ra8_fs_read(), and host_input_identity_t::size.
Referenced by internal_mkfontimg_verify().
|
static |
Report the fixed sparse-image geometry.
Copies immutable sector count and size fields into caller outputs.
| [in] | ctx | Bound mkfontimg_disk_t context. |
| [out] | block_count | Receives the number of sectors. |
| [out] | block_size | Receives bytes per sector. |
| k_ra8_ok | Both geometry outputs were initialized. |
| k_ra8_err_null_ptr | A required pointer was null. |
Definition at line 308 of file mkfontimg_host.c.
References mkfontimg_disk_t::block_count, mkfontimg_disk_t::block_size, k_ra8_err_null_ptr, and k_ra8_ok.
|
static |
Read sectors from the sparse unpublished image.
Validates the complete block range, performs exact positioned I/O, and makes the first host failure sticky for the transaction.
| [in,out] | ctx | Bound mkfontimg_disk_t context. |
| [in] | lba | First sector to read. |
| [in] | count | Number of sectors to read. |
| [out] | buffer | Destination spanning count * block_size bytes. |
| k_ra8_ok | Every requested sector was read. |
| k_ra8_err_out_of_range | State, pointer, or geometry was invalid. |
| k_ra8_fail | Exact host I/O failed. |
ctx and buffer are non-null. Definition at line 239 of file mkfontimg_host.c.
References mkfontimg_disk_t::fd, internal_block_range(), internal_pread_exact(), mkfontimg_disk_t::io_failed, k_ra8_err_out_of_range, k_ra8_fail, and k_ra8_ok.
|
static |
Write sectors into the sparse unpublished image.
Validates the complete block range, performs exact positioned I/O, and makes the first host failure sticky for the transaction.
| [in,out] | ctx | Bound mkfontimg_disk_t context. |
| [in] | lba | First sector to write. |
| [in] | count | Number of sectors to write. |
| [in] | buffer | Source spanning count * block_size bytes. |
| k_ra8_ok | Every requested sector was written. |
| k_ra8_err_out_of_range | State, pointer, or geometry was invalid. |
| k_ra8_fail | Exact host I/O failed. |
ctx and buffer are non-null. Definition at line 275 of file mkfontimg_host.c.
References mkfontimg_disk_t::fd, internal_block_range(), internal_pwrite_exact(), mkfontimg_disk_t::io_failed, k_ra8_err_out_of_range, k_ra8_fail, and k_ra8_ok.
|
static |
Capture all mutation-sensitive fields from one successful fstat.
Normalizes Darwin and POSIX timestamp layouts into an owned value.
| [in] | metadata | Successful metadata for a regular file. |
| all-fields | A complete identity value with no borrowed storage. |
metadata is non-null and has a non-negative size. Definition at line 487 of file mkfontimg_host.c.
References RA8_INTERNAL.
Referenced by internal_compare(), internal_input_open(), and internal_stream().
|
static |
Compare two initialized input identities without inspecting padding.
Checks every mutation-sensitive value explicitly.
| [in] | left | First captured identity. |
| [in] | right | Second captured identity. |
| true | Every represented field is equal. |
| false | At least one identity, size, or timestamp differs. |
Definition at line 520 of file mkfontimg_host.c.
References host_input_identity_t::changed_nsec, host_input_identity_t::changed_sec, host_input_identity_t::device, host_input_identity_t::inode, host_input_identity_t::modified_nsec, host_input_identity_t::modified_sec, RA8_INTERNAL, and host_input_identity_t::size.
Referenced by internal_compare(), internal_mkfontimg_verify(), and internal_stream().
|
static |
Open and validate one non-symlink regular input.
Captures identity through the opened no-follow descriptor.
| [in] | path | Input path. |
| [in] | minimum_bytes | Inclusive lower size bound. |
| [in] | maximum_bytes | Inclusive upper size bound. |
| [out] | out_fd | Receives owned descriptor. |
| [out] | identity | Receives stable metadata. |
| true | Both outputs are populated. |
| false | Open, type, or size validation failed. |
out_fd. Definition at line 547 of file mkfontimg_host.c.
References internal_identity(), O_CLOEXEC, O_NOFOLLOW, and RA8_INTERNAL.
Referenced by internal_mkfontimg_verify(), and internal_mkfontimg_write().
|
static |
Reopen the host input and card file and verify byte-for-byte identity.
Reopens the host input, confirms it is unchanged since the write pass, then opens the card copy, confirms its size, and compares every byte.
| [in,out] | mount | Mounted card filesystem holding the written copy. |
| [in] | input_path | Host source path. |
| [in] | card_name | Card basename written by internal_mkfontimg_write. |
| [in] | minimum_bytes | Smallest accepted host input size. |
| [in] | maximum_bytes | Largest accepted host input size. |
| [in] | identity | Identity observed during the write pass. |
| true | Host and card contents match and the host input is unchanged. |
| false | Reopen, identity, open, size, or byte comparison failed. |
identity was populated by a prior internal_mkfontimg_write call. mount still holds card_name. Definition at line 724 of file mkfontimg_host.c.
References internal_compare(), internal_identity_equal(), internal_input_open(), k_ra8_fs_mode_read, k_ra8_ok, ra8_fs_close(), ra8_fs_open(), ra8_fs_size(), RA8_INTERNAL, and host_input_identity_t::size.
Referenced by priv_mkfontimg_host_copy().
|
static |
Open the host input and stream it into a fresh card file.
Opens and size-validates the host input, then streams every byte into a newly created card file, closing both handles regardless of outcome.
| [in,out] | mount | Mounted destination card filesystem. |
| [in] | input_path | Host source path. |
| [in] | card_name | Card basename to create. |
| [in] | minimum_bytes | Smallest accepted host input size. |
| [in] | maximum_bytes | Largest accepted host input size. |
| [out] | out_identity | Receives the host input's observed identity. |
| true | out_identity is populated and the card file is written. |
| false | Open, size validation, streaming, or close failed. |
mount is mounted. minimum_bytes does not exceed maximum_bytes. Definition at line 678 of file mkfontimg_host.c.
References internal_input_open(), internal_stream(), k_ra8_fs_mode_write, k_ra8_ok, ra8_fs_close(), ra8_fs_open(), and RA8_INTERNAL.
Referenced by priv_mkfontimg_host_copy().
|
static |
Read an exact positioned byte range with bounded retries.
Retries interruptions and rejects EOF before the requested length.
| [in] | fd | Open regular-file descriptor. |
| [in] | offset | Absolute byte offset. |
| [out] | bytes | Exact-size destination. |
| [in] | length | Required byte count. |
| true | The destination is complete. |
| false | Overflow, EOF, or host I/O failure occurred. |
bytes spans length writable bytes. fd remains open. Definition at line 117 of file mkfontimg_host.c.
Referenced by internal_compare(), internal_disk_read(), and internal_stream().
|
static |
Write an exact positioned byte range with bounded retries.
Retries interruptions and treats a zero write as terminal failure.
| [in] | fd | Open regular-file descriptor. |
| [in] | offset | Absolute byte offset. |
| [in] | bytes | Exact-size source. |
| [in] | length | Required byte count. |
| true | The complete range reached the page cache. |
| false | Overflow or host I/O failure occurred. |
bytes spans length readable bytes. fd remains open. Definition at line 158 of file mkfontimg_host.c.
Referenced by internal_disk_write(), and priv_mkfontimg_host_seed().
|
static |
Split one output path into bounded parent and leaf components.
Rejects truncation, empty leaves, and dot traversal components.
| [in] | path | Requested output. |
| [out] | parent | Parent path. |
| [out] | leaf | Destination leaf. |
| true | Outputs are populated. |
| false | Path is empty, overlong, or names ./../a directory. |
path. Definition at line 335 of file mkfontimg_host.c.
References k_mkfontimg_host_name_cap, k_mkfontimg_host_path_cap, memcpy(), RA8_INTERNAL, strcmp(), and strlen().
Referenced by priv_mkfontimg_host_begin().
|
static |
Stream the first pass from host input to one new card file.
Copies bounded chunks and rechecks metadata before returning success.
| [in] | input_fd | Open host input. |
| [in] | identity | Initial stable metadata. |
| [in,out] | card | Open card file in write mode. |
| true | Card file received exactly identity->size bytes. |
| false | Read, write, or mutation validation failed. |
Definition at line 585 of file mkfontimg_host.c.
References internal_identity(), internal_identity_equal(), internal_pread_exact(), k_host_stream_chunk, k_ra8_ok, ra8_fs_write(), and host_input_identity_t::size.
Referenced by internal_mkfontimg_write().
|
static |
Build one collision-resistant hidden temporary leaf.
Uses fixed decimal conversion buffers and no process-global state.
| [out] | out | Temporary-name buffer. |
| [in] | process | Process identifier. |
| [in] | attempt | Collision retry index. |
| true | A NUL-terminated slash-free leaf was built. |
| false | Capacity was insufficient. |
out has k_mkfontimg_host_name_cap bytes. Definition at line 387 of file mkfontimg_host.c.
References k_host_decimal_base, k_host_decimal_digits, k_mkfontimg_host_name_cap, memcpy(), and s_prefix.
Referenced by priv_mkfontimg_host_begin().
| void priv_mkfontimg_diag | ( | const char * | text | ) |
Write one complete best-effort diagnostic fragment to standard error.
Retries interrupted and short raw-descriptor writes without stdio.
| [in] | text | NUL-terminated diagnostic fragment. |
text is non-null and NUL-terminated. Definition at line 67 of file mkfontimg_host.c.
References RA8_PRIV, and strlen().
Referenced by internal_run_blank(), internal_run_font(), main(), and priv_mkfontimg_diag_u64().
| void priv_mkfontimg_diag_u64 | ( | uint64_t | value | ) |
Write one unsigned decimal value to standard error without stdio.
Converts through fixed local buffers and delegates one bounded string.
| [in] | value | Unsigned value to render in base ten. |
Definition at line 83 of file mkfontimg_host.c.
References k_host_decimal_base, k_host_decimal_digits, priv_mkfontimg_diag(), and RA8_PRIV.
Referenced by internal_run_font().
| void priv_mkfontimg_host_abort | ( | mkfontimg_host_t * | host | ) |
Close and unlink an unpublished temporary image.
Idempotently releases every partially acquired host resource.
| [in,out] | host | Publication state returned by the begin operation. |
host is non-null and may be only partially initialized. Definition at line 815 of file mkfontimg_host.c.
References mkfontimg_host_t::directory_fd, mkfontimg_host_t::image_fd, RA8_PRIV, mkfontimg_host_t::temp_exists, and mkfontimg_host_t::temp_name.
Referenced by internal_finish_image(), internal_mount_image(), internal_run_font(), and priv_mkfontimg_host_begin().
|
nodiscard |
Create, size, and bind one private sibling-temporary image.
Definition at line 411 of file mkfontimg_host.c.
References mkfontimg_host_t::backend, mkfontimg_host_t::directory_fd, mkfontimg_host_t::disk, mkfontimg_host_t::final_name, mkfontimg_host_t::image_fd, internal_disk_capacity(), internal_disk_read(), internal_disk_write(), internal_split_output(), internal_temp_name(), k_host_create_mode, k_host_temp_attempts, k_mkfontimg_host_path_cap, O_CLOEXEC, O_DIRECTORY, O_NOFOLLOW, priv_mkfontimg_host_abort(), RA8_PRIV, mkfontimg_host_t::temp_exists, and mkfontimg_host_t::temp_name.
Referenced by internal_mount_image().
|
nodiscard |
Sync and atomically publish a complete temporary image.
Definition at line 788 of file mkfontimg_host.c.
References mkfontimg_host_t::directory_fd, mkfontimg_host_t::disk, mkfontimg_host_t::final_name, mkfontimg_host_t::image_fd, mkfontimg_disk_t::io_failed, RA8_PRIV, renameat(), mkfontimg_host_t::temp_exists, and mkfontimg_host_t::temp_name.
Referenced by internal_finish_image().
|
nodiscard |
Stream one stable host input into a card file and verify it by reread.
Definition at line 756 of file mkfontimg_host.c.
References mkfontimg_host_t::disk, internal_mkfontimg_verify(), internal_mkfontimg_write(), mkfontimg_disk_t::io_failed, RA8_PRIV, and host_input_identity_t::size.
Referenced by internal_run_font().
|
nodiscard |
Seed exact bytes at the beginning of the temporary image.
Definition at line 461 of file mkfontimg_host.c.
References mkfontimg_disk_t::block_count, mkfontimg_disk_t::block_size, mkfontimg_host_t::disk, mkfontimg_host_t::image_fd, internal_pwrite_exact(), and mkfontimg_disk_t::io_failed.
Referenced by internal_mount_image().