25#error "port/posix is host-only and must never be compiled or linked into target firmware."
95 const int saved_errno = errno;
104 struct stat meta = {};
105 if (fstat(opened, &meta) != 0) {
109 if (!S_ISREG(meta.st_mode)) {
119internal_read(
void* ctx,
void* file_state, uint8_t* dst, uint32_t cap, uint32_t* out_read)
126 got = read(fd, dst, (
size_t)cap);
129 saved = (got < 0) ? errno : 0;
130 }
while (saved == EINTR);
134 *out_read = (uint32_t)got;
143 uint32_t* out_written)
147 while (*out_written < len) {
148 const uint32_t remaining = len - *out_written;
149 const ssize_t wrote =
write(fd, &src[*out_written], (
size_t)remaining);
152 const int saved = (wrote < 0) ? errno : 0;
154 if (saved == EINTR) {
162 *out_written += (uint32_t)wrote;
171 if (offset > (uint64_t)INT64_MAX) {
175 if (lseek(fd, (off_t)offset, SEEK_SET) < 0) {
186 const off_t offset = lseek(fd, 0, SEEK_CUR);
190 *out_offset = (uint64_t)offset;
199 struct stat meta = {};
200 if (fstat(fd, &meta) != 0) {
203 *out_size = (uint64_t)meta.st_size;
212 if (fsync(fd) != 0) {
239 return &k_stream_iface;
static uint32_t internal_read(void)
Read current GPT counter ticks, or return UINT32_MAX on err.
Architecture-neutral filesystem namespace, stream, and transaction ports.
Backend-author interface for binding concrete filesystem ports.
ra8_err_t priv_fs_posix_parent_open(fw_fs_posix_state_t *state, const char *path, int *out_parent_fd, char *out_leaf)
Resolve a canonical path's parent without following any symlink.
#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.
ra8_err_t priv_fs_posix_close_fd(int *fd)
Close exactly once and invalidate the caller's descriptor.
ra8_err_t priv_fs_posix_close_fd_preserve(int *fd, ra8_err_t primary)
Close one owned descriptor while preserving a primary status.
ra8_err_t priv_fs_posix_errno(int value)
Map one captured errno value into ra8_err_t.
ra8_err_t priv_fs_posix_seek(void *ctx, void *file_state, uint64_t offset)
Seek a POSIX descriptor to an unsigned absolute offset.
ra8_err_t priv_fs_posix_close(void *ctx, void *file_state)
Close and consume one caller-owned POSIX file state.
ra8_err_t priv_fs_posix_sync(void *ctx, void *file_state)
Flush file contents and metadata through POSIX fsync.
ra8_err_t priv_fs_posix_write(void *ctx, void *file_state, const uint8_t *src, uint32_t len, uint32_t *out_written)
Complete POSIX short writes while reporting any accepted prefix.
ra8_err_t priv_fs_posix_size(void *ctx, void *file_state, uint64_t *out_size)
Report a POSIX descriptor's current file length.
@ k_posix_file_mode
Owner-only created-file mode.
@ k_posix_component_cap
Component buffer including NUL.
ra8_err_t priv_fs_posix_open(void *ctx, const char *path, fw_fs_open_mode_t mode, void *file_state, uint32_t state_bytes)
Open one confined regular file into caller workspace.
ra8_err_t priv_fs_posix_seek(void *ctx, void *file_state, uint64_t offset)
Seek a POSIX descriptor to an unsigned absolute offset.
ra8_err_t priv_fs_posix_close(void *ctx, void *file_state)
Close and consume one caller-owned POSIX file state.
ra8_err_t priv_fs_posix_sync(void *ctx, void *file_state)
Flush file contents and metadata through POSIX fsync.
ra8_err_t priv_fs_posix_write(void *ctx, void *file_state, const uint8_t *src, uint32_t len, uint32_t *out_written)
Complete POSIX short writes while reporting any accepted prefix.
ra8_err_t priv_fs_posix_size(void *ctx, void *file_state, uint64_t *out_size)
Report a POSIX descriptor's current file length.
const fw_fs_stream_iface_t * priv_fs_posix_stream_iface(void)
Borrow the immutable POSIX byte-stream operation table.
ra8_err_t priv_fs_posix_open(void *ctx, const char *path, fw_fs_open_mode_t mode, void *file_state, uint32_t state_bytes)
Open one confined regular file into caller workspace.
static ra8_err_t internal_tell(void *ctx, void *file_state, uint64_t *out_offset)
static ra8_err_t internal_open_flags(fw_fs_open_mode_t mode, int *out_flags)
File-local contracts for the hosted POSIX byte-stream operations.
static ra8_err_t internal_read(void *ctx, void *file_state, uint8_t *dst, uint32_t cap, uint32_t *out_read)
static ra8_err_t internal_tell(void *ctx, void *file_state, uint64_t *out_offset)
struct fw_fs_stream_iface fw_fs_stream_iface_t
fw_fs_open_mode_t
Open intent for fw_fs_open.
@ k_fw_fs_open_create_new
Create only when leaf is absent.
@ k_fw_fs_open_append
Create/append, write-only.
@ k_fw_fs_open_read
Existing file, read-only.
@ k_fw_fs_open_write_truncate
Create/truncate, write-only.
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).
Error Code Definitions for ra8-firmware.
@ 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_ok
Success – operation completed with all postconditions satisfied.
@ 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.
Caller-owned POSIX adapter state.
POSIX state placed in caller file workspace.