47 entry[
k_dir_off_attr] = (uint8_t)((uint8_t)(attr & (uint8_t)~clear_mask) | (uint8_t)set_mask);
141 const uint8_t* entry,
244typedef enum : uint32_t {
295 for (uint32_t i = 0; i < len; i++) {
296 namebuf[i] = comp[i];
322 const char** out_leaf)
324 const char* p = path;
328 dir_loc_t cur = {.is_root = 1U, .cluster = 0U};
331 while (*end !=
'\0') {
359 const char* p = path;
369 const char* leaf =
nullptr;
375 while (leaf[len] !=
'\0') {
460 if (handle ==
nullptr || path ==
nullptr || out_file ==
nullptr) {
463 if (handle->
in_use == 0U) {
470 const char* leaf =
nullptr;
545 if (file ==
nullptr) {
552 if ((file->dirty != 0U) && (file->in_use != 0U) && (file->mount !=
nullptr) &&
553 (file->mount->in_use != 0U)) {
558 file->mount =
nullptr;
Annotation-attribute framework macros for ra8-firmware.
#define RA8_OWNS_RESOURCE(kind)
RAII-style resource ownership contract.
#define RA8_INTERNAL
Marker that a function is intended to be static (file-local).
@ k_ra8_err_no_mem
Static buffer exhausted (no dynamic memory on this project).
@ k_ra8_err_invalid_arg
Invalid function argument.
@ k_ra8_err_invalid_state
Module in wrong state for requested operation.
@ k_ra8_ok
Success – operation completed with all postconditions satisfied.
@ k_ra8_err_null_ptr
Pointer was NULL where a valid pointer was required.
@ k_ra8_err_access_denied
Operation refused because the target is protected against it.
@ k_ra8_err_protocol_error
Protocol-level error (e.g.
@ k_ra8_err_not_found
Requested item not found (lookup / search missed).
ra8_err_codes_t ra8_err_t
Canonical error-return type used by every ra8-firmware API.
Minimal FAT12/FAT16/FAT32 filesystem adapter (read + write).
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_close(ra8_fs_file_t *file)
Close an open file, stamping its final modification time.
uint32_t priv_rd32(const uint8_t *p)
Decode a little-endian uint32_t from a byte buffer.
uint16_t priv_rd16(const uint8_t *p)
Decode a little-endian uint16_t from a byte buffer.
ra8_err_t priv_read_sector(const ra8_fs_mount_t *m, uint64_t lba, uint8_t *buf)
Read a single sector into the module scratch buffer.
void priv_wr32(uint8_t *p, uint32_t v)
Encode a little-endian uint32_t into a byte buffer.
ra8_err_t priv_write_sector(const ra8_fs_mount_t *m, uint64_t lba, const uint8_t *buf)
Write a single sector from a caller-provided buffer.
void priv_wr16(uint8_t *p, uint16_t v)
Encode a little-endian uint16_t into a byte buffer.
ra8_err_t priv_fsinfo_flush(const ra8_fs_mount_t *m)
Write the tracked free count and next-free hint back into FSInfo.
uint8_t * priv_sec_walk(void)
The WALK-role sector buffer (directory scans and entry RMW).
ra8_err_t priv_exfat_open(ra8_fs_mount_t *handle, const char *path, ra8_fs_mode_t mode, ra8_fs_file_t **out_file)
Open a file (read-only) on a mounted exFAT volume.
ra8_err_t priv_exfat_flush_set(ra8_fs_file_t *file)
Rewrite a file's entry set from the handle, checksum last.
ra8_err_t priv_close_locked(ra8_fs_file_t *file)
Close an open file – the guarded body of ra8_fs_close().
static void internal_init_new_file(ra8_fs_file_t *f, ra8_fs_mount_t *handle, ra8_fs_mode_t mode, uint64_t free_lba, uint32_t free_off)
Populate a freshly allocated file slot for an empty new file.
ra8_err_t priv_resolve_dir(const ra8_fs_mount_t *m, const char *path, dir_loc_t *out)
Resolve a whole path to the directory it names.
uint32_t priv_entry_first_cluster(const uint8_t *entry)
Read the first cluster from a 32-byte directory entry.
void priv_entry_set_cluster_size(uint8_t *entry, uint32_t cluster, uint32_t size)
Patch first-cluster + size back into a 32-byte directory entry.
static ra8_err_t internal_close_stamp(ra8_fs_file_t *file)
Stamp the final modification time of a file that was written.
static ra8_err_t internal_truncate_existing(const ra8_fs_mount_t *handle, ra8_fs_file_t *f, uint64_t lba, uint32_t off)
Truncate an existing file's chain and zero its dir-entry size.
static ra8_err_t internal_open_existing(ra8_fs_mount_t *handle, const uint8_t *entry, uint64_t lba, uint32_t off, ra8_fs_mode_t mode, ra8_fs_file_t **out_file)
Populate a fresh file handle from an existing on-disk dir entry.
static ra8_err_t internal_enter_subdir(const ra8_fs_mount_t *m, const dir_loc_t *cur, const char *comp, uint32_t len, dir_loc_t *out)
Descend into the named directory component within cur.
ra8_fs_path_cap_t
Path-resolution caps (statically bound the component walk).
@ k_path_max_depth
Max nested directory components per path.
static ra8_err_t internal_create_new(ra8_fs_mount_t *handle, const dir_loc_t *parent, const char *leaf, ra8_fs_mode_t mode, ra8_fs_file_t **out_file)
Carve a fresh directory entry for leaf and populate a file handle.
void priv_fat_entry_apply_attr(uint8_t *entry, uint8_t set_mask, uint8_t clear_mask)
Clear then set attribute bits in a 32-byte FAT directory entry.
ra8_err_t priv_open_locked(ra8_fs_mount_t *handle, const char *path, ra8_fs_mode_t mode, ra8_fs_file_t **out_file)
Open a file by path – the guarded body of ra8_fs_open().
ra8_err_t priv_resolve_parent(const ra8_fs_mount_t *m, const char *path, dir_loc_t *out_parent, const char **out_leaf)
Resolve all-but-the-last path component to a parent directory.
Cross-TU shared declarations for the FAT/exFAT ra8_fs adapter.
ra8_err_t priv_free_chain(const ra8_fs_mount_t *m, uint32_t start)
Free an entire cluster chain starting at start.
ra8_err_t priv_dir_reserve(const ra8_fs_mount_t *m, const dir_loc_t *loc, const char *leaf, dir_insert_t *out)
Decide how a name will be stored and set aside the slots for it.
ra8_err_t priv_dir_lookup_any(const ra8_fs_mount_t *m, const dir_loc_t *loc, const char *leaf, uint64_t *out_lba, uint32_t *out_off, uint8_t out_entry[k_ra8_fs_dir_entry_bytes])
Resolve one leaf name by 8.3 first and by long name second.
ra8_err_t priv_dir_commit(const ra8_fs_mount_t *m, const dir_insert_t *plan, const uint8_t *tmpl, uint64_t *out_lba, uint32_t *out_off)
Write a reserved run: the long-name chain, then the 8.3 entry.
void priv_lock_release(void)
Drop the library lock taken by priv_lock_acquire.
void priv_lock_acquire(void)
Take the library lock, if the caller installed one.
ra8_fs_file_t * priv_alloc_file_slot(void)
Allocate a free entry from the file table; returns NULL if full.
void priv_fat_entry_stamp_write(uint8_t *entry)
Advance a FAT directory entry's modification time and access date.
void priv_fat_entry_stamp_create(uint8_t *entry)
Stamp a fresh FAT directory entry's create, write, and access fields.
@ k_dir_off_fst_clus_lo
MS FAT spec sec 6 "DIR_FstClusLO".
@ k_dir_off_attr
MS FAT spec sec 6 "DIR_Attr".
@ k_dir_off_file_size
MS FAT spec sec 6 "DIR_FileSize".
@ k_dir_off_fst_clus_hi
MS FAT spec sec 6 "DIR_FstClusHI".
@ k_cluster_first_data
Cluster numbers start at 2.
@ k_shift_two_bytes
Shift two bytes.
@ k_lfn_utf8_cap
A 247-unit name in UTF-8: 3 * 247, + NUL.
@ k_ra8_fs_type_exfat
exFAT (read + streaming write + format).
@ k_ra8_fs_attr_directory
MS FAT spec sec 6 "ATTR_DIRECTORY".
@ k_ra8_fs_attr_archive
MS FAT spec sec 6 "ATTR_ARCHIVE".
@ k_ra8_fs_attr_read_only
MS FAT spec sec 6 "ATTR_READ_ONLY".
ra8_fs_mode_t
File-open modes accepted by ra8_fs_open().
@ k_ra8_fs_mode_append
Open at EOF for writing.
@ k_ra8_fs_mode_read
Read-only, must exist.
@ k_ra8_fs_mode_write
Truncate (or create) for writing.
@ k_ra8_fs_dir_entry_bytes
MS FAT spec sec 6 "Directory Entry".
Everything decided about a new directory entry before anything is written.
Identifies the directory a lookup/scan should operate in.
uint8_t is_root
1 => the volume root; 0 => the subdirectory at cluster.
uint32_t cluster
First cluster of the subdirectory (ignored when root).
uint64_t size_bytes
File size (DIR_FileSize / DataLength).
uint64_t offset
Current read/write offset.
uint32_t first_cluster
Head of the file's cluster chain.
uint8_t in_use
0 = slot free, 1 = open.
uint32_t dir_entry_idx
FAT: byte offset of the entry in it.
uint32_t walk_cache_cluster
Cluster at walk_cache_idx; < 2 = no cache.
ra8_fs_mode_t mode
Open mode.
uint8_t no_fat_chain
exFAT contiguous file (no FAT walk).
uint32_t cur_cluster
Cluster the offset currently points into.
uint8_t dirty
1 once written; drives the close mtime.
uint64_t dir_entry_lba
FAT: sector containing the dir entry.
ra8_fs_mount_t * mount
Owning mount point.
uint32_t walk_cache_idx
Chain index whose cluster is cached below.
Cached parse of one mounted FAT volume.
ra8_fs_type_t type
FAT12 / FAT16 / FAT32.
uint8_t in_use
0 = slot free, 1 = mounted.