|
ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
|
Hosted POSIX byte-stream operations for the portable filesystem port. More...
#include <errno.h>#include <fcntl.h>#include <stdint.h>#include <sys/stat.h>#include <unistd.h>#include "fw_if_fs.h"#include "fw_if_fs_backend.h"#include "fw_if_fs_posix_stream_contracts_internal.h"#include "ra8_attributes.h"#include "ra8_err.h"Go to the source code of this file.
Macros | |
| #define | O_CLOEXEC (0) |
| Zero fallback when the host lacks close-on-exec open flags. | |
| #define | O_NOFOLLOW (0) |
| Zero fallback paired with explicit no-follow metadata validation. | |
Functions | |
| static ra8_err_t | internal_open_flags (fw_fs_open_mode_t mode, int *out_flags) |
| 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_read (void *ctx, void *file_state, uint8_t *dst, uint32_t cap, uint32_t *out_read) |
| 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_seek (void *ctx, void *file_state, uint64_t offset) |
| Seek a POSIX descriptor to an unsigned absolute offset. | |
| static ra8_err_t | internal_tell (void *ctx, void *file_state, uint64_t *out_offset) |
| ra8_err_t | priv_fs_posix_size (void *ctx, void *file_state, uint64_t *out_size) |
| Report a POSIX descriptor's current file length. | |
| 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_close (void *ctx, void *file_state) |
| Close and consume one caller-owned POSIX file state. | |
| const fw_fs_stream_iface_t * | priv_fs_posix_stream_iface (void) |
| Borrow the immutable POSIX byte-stream operation table. | |
Hosted POSIX byte-stream operations for the portable filesystem port.
Owns the adapter's complete fw_fs_stream_iface_t implementation: portable open-mode to no-follow openat flag mapping, interrupt-safe read and write loops, absolute seek and position queries, length queries, durability, and close. Every operation drives a caller-owned posix_file_state_t, so this unit holds no mutable state and resolves no path beyond the confined parent the shared no-follow resolver hands it. Namespace policy and staged publication live in fw_if_fs_posix.c, which drives these same operations for its transaction stage through the widened RA8_PRIV entry points.
Definition in file fw_if_fs_posix_stream.c.
| #define O_CLOEXEC (0) |
Zero fallback when the host lacks close-on-exec open flags.
Definition at line 42 of file fw_if_fs_posix_stream.c.
| #define O_NOFOLLOW (0) |
Zero fallback paired with explicit no-follow metadata validation.
Definition at line 47 of file fw_if_fs_posix_stream.c.
|
static |
Definition at line 51 of file fw_if_fs_posix_stream.c.
References k_fw_fs_open_append, k_fw_fs_open_create_new, k_fw_fs_open_read, k_fw_fs_open_write_truncate, k_ra8_err_invalid_arg, k_ra8_ok, O_CLOEXEC, O_NOFOLLOW, and RA8_INTERNAL.
Referenced by priv_fs_posix_open().
|
static |
Definition at line 119 of file fw_if_fs_posix_stream.c.
References k_ra8_ok, and priv_fs_posix_errno().
|
static |
Definition at line 182 of file fw_if_fs_posix_stream.c.
References k_ra8_ok, priv_fs_posix_errno(), and RA8_INTERNAL.
| ra8_err_t priv_fs_posix_close | ( | void * | ctx, |
| void * | file_state ) |
Close and consume one caller-owned POSIX file state.
Delegates to the shared EINTR-safe descriptor close helper, which invalidates the stored descriptor to prevent unsafe retries.
| [in] | ctx | Unused confined-root context. |
| [in,out] | file_state | Open posix_file_state_t to consume. |
| k_ra8_ok | The descriptor closed successfully. |
| k_ra8_err_* | Mapped close failure. |
file_state owns one open descriptor. Definition at line 219 of file fw_if_fs_posix_stream.c.
References priv_fs_posix_close_fd(), and RA8_PRIV.
Referenced by internal_txn_abort(), internal_txn_validate(), and priv_fs_posix_stream_iface().
| 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.
Maps safe flags, resolves the no-follow parent, opens relative to it, closes the parent, then rejects any resulting non-regular object.
| [in,out] | ctx | Initialized confined-root adapter context. |
| [in] | path | Validated portable file path. |
| [in] | mode | Portable open mode. |
| [out] | file_state | Caller workspace receiving posix_file_state_t. |
| [in] | state_bytes | Writable workspace size. |
| k_ra8_ok | file_state owns one open regular-file descriptor. |
| k_ra8_err_no_mem | The workspace is undersized. |
| k_ra8_err_invalid_arg | The mode or opened object type is invalid. |
| k_ra8_err_* | Mapped resolution, open, stat, or close failure. |
ctx owns a live confined root descriptor. file_state. Definition at line 73 of file fw_if_fs_posix_stream.c.
References internal_open_flags(), k_posix_component_cap, k_posix_file_mode, k_ra8_err_invalid_arg, k_ra8_err_no_mem, k_ra8_ok, priv_fs_posix_close_fd(), priv_fs_posix_close_fd_preserve(), priv_fs_posix_errno(), priv_fs_posix_parent_open(), and RA8_PRIV.
Referenced by internal_stage_open(), internal_txn_validate(), and priv_fs_posix_stream_iface().
| ra8_err_t priv_fs_posix_seek | ( | void * | ctx, |
| void * | file_state, | ||
| uint64_t | offset ) |
Seek a POSIX descriptor to an unsigned absolute offset.
Rejects values not representable by signed 64-bit host offsets before issuing one lseek(SEEK_SET).
| [in] | ctx | Unused confined-root context. |
| [in,out] | file_state | Open posix_file_state_t. |
| [in] | offset | Absolute byte offset. |
| k_ra8_ok | The descriptor position is offset. |
| k_ra8_err_invalid_size | offset exceeds INT64_MAX. |
| k_ra8_err_* | Mapped lseek failure. |
file_state owns an open seekable descriptor. offset. Definition at line 168 of file fw_if_fs_posix_stream.c.
References k_ra8_err_invalid_size, k_ra8_ok, priv_fs_posix_errno(), and RA8_PRIV.
Referenced by internal_txn_seek(), and priv_fs_posix_stream_iface().
| ra8_err_t priv_fs_posix_size | ( | void * | ctx, |
| void * | file_state, | ||
| uint64_t * | out_size ) |
Report a POSIX descriptor's current file length.
Queries descriptor metadata with fstat and widens the non-negative regular-file size to the portable uint64_t result.
| [in] | ctx | Unused confined-root context. |
| [in] | file_state | Open posix_file_state_t. |
| [out] | out_size | Receives current file length in bytes. |
| k_ra8_ok | out_size contains the current length. |
| k_ra8_err_* | Mapped fstat failure. |
file_state owns an open regular-file descriptor. out_size addresses one writable uint64_t object. Definition at line 195 of file fw_if_fs_posix_stream.c.
References k_ra8_ok, priv_fs_posix_errno(), and RA8_PRIV.
Referenced by internal_txn_seek(), and priv_fs_posix_stream_iface().
| const fw_fs_stream_iface_t * priv_fs_posix_stream_iface | ( | void | ) |
Borrow the immutable POSIX byte-stream operation table.
Hands back the single translation-unit-scoped vtable so the adapter's namespace and transaction units can bind or borrow the same stream implementation without a second copy of the table.
| non-NULL | The one stream vtable, valid for the program lifetime. |
Immutable POSIX stream vtable.
Definition at line 226 of file fw_if_fs_posix_stream.c.
References internal_read(), internal_tell(), priv_fs_posix_close(), priv_fs_posix_open(), priv_fs_posix_seek(), priv_fs_posix_size(), priv_fs_posix_sync(), priv_fs_posix_write(), and RA8_PRIV.
Referenced by internal_txn_validate(), and priv_fs_posix_bind_interfaces().
| ra8_err_t priv_fs_posix_sync | ( | void * | ctx, |
| void * | file_state ) |
Flush file contents and metadata through POSIX fsync.
Delegates durability to the host descriptor and maps any failure.
| [in] | ctx | Unused confined-root context. |
| [in,out] | file_state | Open posix_file_state_t. |
| k_ra8_ok | The host accepted the durability request. |
| k_ra8_err_* | Mapped fsync failure. |
file_state owns an open descriptor valid for synchronization. Definition at line 208 of file fw_if_fs_posix_stream.c.
References k_ra8_ok, priv_fs_posix_errno(), and RA8_PRIV.
Referenced by internal_txn_validate(), and priv_fs_posix_stream_iface().
| 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.
Retries interrupts, advances over positive short writes, maps host errors, and treats a zero-byte write before completion as failure.
| [in] | ctx | Unused confined-root context. |
| [in,out] | file_state | Open posix_file_state_t. |
| [in] | src | Source bytes. |
| [in] | len | Exact requested byte count. |
| [in,out] | out_written | Running accepted count initialized by public dispatch. |
| k_ra8_ok | Exactly len bytes were accepted. |
| k_ra8_fail | The host returned zero before completion. |
| k_ra8_err_* | Mapped non-interrupt write failure. |
file_state owns an open writable descriptor. src addresses len readable bytes when non-zero. out_written to len. Definition at line 139 of file fw_if_fs_posix_stream.c.
References k_ra8_fail, k_ra8_ok, priv_fs_posix_errno(), and RA8_PRIV.
Referenced by internal_txn_write(), and priv_fs_posix_stream_iface().