61 const long modified_nsec = metadata->st_mtimespec.tv_nsec;
62 const long changed_nsec = metadata->st_ctimespec.tv_nsec;
64 const long modified_nsec = metadata->st_mtim.tv_nsec;
65 const long changed_nsec = metadata->st_ctim.tv_nsec;
68 .inode = metadata->st_ino,
69 .size = (uint64_t)metadata->st_size,
70 .modified_sec = metadata->st_mtime,
71 .modified_nsec = modified_nsec,
72 .changed_sec = metadata->st_ctime,
73 .changed_nsec = changed_nsec};
92 const struct stat* actual)
94 if (actual->st_size < 0) {
152 struct stat metadata = {};
153 if (fstat(fd, &metadata) != 0 || !S_ISREG(metadata.st_mode) || metadata.st_size <= 0 ||
154 (uint64_t)metadata.st_size > UINT32_MAX) {
191 (void)close(input_fd);
195 uint64_t offset = 0U;
197 while (ok && offset < identity->size) {
198 size_t take = (size_t)(identity->
size - offset);
199 if (take >
sizeof(chunk)) {
200 take =
sizeof(chunk);
206 struct stat after = {};
210 if (close(input_fd) != 0) {
251 (void)close(input_fd);
256 (void)close(input_fd);
263 if (card !=
nullptr) {
266 (void)close(input_fd);
269 *out_input_fd = input_fd;
303 uint64_t offset = 0U;
305 while (ok && offset < identity->size) {
306 uint32_t take = (uint32_t)(identity->
size - offset);
307 if (take > (uint32_t)
sizeof(source)) {
308 take = (uint32_t)
sizeof(source);
313 memcmp(source, copied, take) == 0;
316 struct stat after = {};
344 for (
int prior = 0; prior < index; ++prior) {
401 for (
int index = 0; index < book_count; ++index) {
#define O_NOFOLLOW
Zero fallback paired with explicit no-follow metadata validation.
#define O_CLOEXEC
Zero fallback when the host lacks close-on-exec open flags.
static bool internal_verify_book_reopen(ra8_fs_mount_t *mount, const char *name, const char *path, const mkbookimg_input_identity_t *identity, int *out_input_fd, ra8_fs_file_t **out_card)
Reopen host and card handles and confirm identity and size.
static bool internal_duplicate_name(char **arguments, int index)
Detect whether one input would overwrite an earlier basename.
static bool internal_identity_equal(const mkbookimg_input_identity_t *left, const mkbookimg_input_identity_t *right)
Compare two captured host-input identities field by field.
static mkbookimg_input_identity_t internal_input_identity(const struct stat *metadata)
Extract nanosecond-resolution identity fields portably.
static bool internal_format_mount(const ra8_fs_backend_t *backend, ra8_fs_mount_t **mount)
Format and mount the descriptor-backed FAT32 image.
static bool internal_stream_book(ra8_fs_mount_t *mount, const char *name, const char *path, mkbookimg_input_identity_t *identity)
Stream one host input into a newly truncated filesystem file.
static bool internal_input_same(const mkbookimg_input_identity_t *expected, const struct stat *actual)
Compare a captured identity with a fresh fstat result.
static bool internal_input_open(const char *path, int *out_fd, mkbookimg_input_identity_t *identity)
Open and identify one immutable regular input without following its leaf.
bool priv_mkbookimg_build_image(const ra8_fs_backend_t *backend, char **argv, int book_count, const mkbookimg_disk_t *disk)
Format, populate, and unmount the destination image.
static bool internal_write_books(ra8_fs_mount_t *mount, char **arguments, int book_count)
Stream and verify every requested book through the mounted filesystem.
static bool internal_verify_book(ra8_fs_mount_t *mount, const char *name, const char *path, const mkbookimg_input_identity_t *identity)
Re-read host and card bytes to prove the streamed copy and input stability.
Module-private seams shared by the two mkbookimg translation units.
bool priv_mkbookimg_pread_exact(int fd, uint64_t offset, uint8_t *bytes, size_t length)
Read exactly one bounded positioned byte range.
void priv_mkbookimg_diag(const char *text)
Write a complete diagnostic fragment to the standard-error descriptor.
void priv_mkbookimg_diag_u64(uint64_t value)
Emit an unsigned decimal value without a formatting runtime.
@ k_stream_chunk_bytes
Bounded copy chunk bytes.
Derive an on-card file name from a source book path (long-name capable).
static bool mkbookimg_dest_name(const char *path, char *out, size_t cap)
Derive the on-card destination name for a source book path.
@ k_mkbookimg_name_cap
Destination-name buffer bytes incl.
static const char * mkbookimg_basename(const char *path)
Return the basename of path: the run after its last '/'.
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).
@ k_ra8_ok
Success – operation completed with all postconditions satisfied.
int strcmp(const char *s1, const char *s2)
Compare two null-terminated strings.
int memcmp(const void *a, const void *b, size_t n)
Compare bytes in two memory areas.
Minimal FAT12/FAT16/FAT32 filesystem adapter (read + write).
ra8_err_t ra8_fs_format(const ra8_fs_backend_t *backend, const ra8_fs_format_opts_t *opts)
Format a block device as a fresh, empty FAT12/FAT16/FAT32/exFAT volume.
ra8_err_t ra8_fs_write(ra8_fs_file_t *file, const uint8_t *buf, uint32_t len)
Write len bytes; allocate new clusters from FAT free-space scan as needed.
ra8_err_t ra8_fs_mount(const ra8_fs_backend_t *backend, ra8_fs_mount_t **out_handle)
Mount a FAT volume from a block-device backend, auto-selecting the first partition.
ra8_err_t ra8_fs_size(const ra8_fs_file_t *file, uint64_t *out_bytes)
Report the file's size in bytes (64-bit on exFAT, #676).
ra8_err_t ra8_fs_read(ra8_fs_file_t *file, uint8_t *buf, uint32_t max_len, uint32_t *got_len)
Read up to max_len bytes; advance the cluster chain on cluster crossings.
ra8_err_t ra8_fs_open(ra8_fs_mount_t *handle, const char *path, ra8_fs_mode_t mode, ra8_fs_file_t **out_file)
Open or create a file by path, 8.3 or long.
ra8_err_t ra8_fs_unmount(ra8_fs_mount_t *handle)
Unmount a previously mounted volume and release its slot.
ra8_err_t ra8_fs_close(ra8_fs_file_t *file)
Close an open file, stamping its final modification time.
@ k_ra8_fs_type_fat32
count_of_clusters >= 65525.
@ k_ra8_fs_mode_read
Read-only, must exist.
@ k_ra8_fs_mode_write
Truncate (or create) for writing.
Host descriptor-backed block device bound into ra8_fs.
bool io_failed
Sticky positioned-I/O failure.
Block-device interface that ra8_fs runs on top of.
Cached parse of one mounted FAT volume.