92 "one allocator state slot per mount slot, or a bind can fail");
333 if (cluster < st->next_free) {
505 if (free <= m->count_of_clusters) {
521 if (st->
dirty == 0U) {
Annotation-attribute framework macros for ra8-firmware.
#define RA8_INTERNAL
Marker that a function is intended to be static (file-local).
@ k_ra8_ok
Success – operation completed with all postconditions satisfied.
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).
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.
uint64_t priv_cluster_to_lba(const ra8_fs_mount_t *m, uint32_t cluster)
Convert a cluster number into its first data-region LBA.
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.
uint32_t priv_bps(const ra8_fs_mount_t *m)
One mounted volume's sector size in bytes.
void priv_wr32(uint8_t *p, uint32_t v)
Encode a little-endian uint32_t into a byte buffer.
void priv_byte_copy(uint8_t *dst, const uint8_t *src, uint32_t n)
Length-checked byte copy used in place of memcpy().
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.
ra8_err_t priv_fsinfo_seed(const ra8_fs_mount_t *m)
Validate FAT32's FSInfo sector and seed the hint and free count.
void priv_free_count_took(const ra8_fs_mount_t *m, uint32_t n)
Account n clusters as taken out of the volume's free space.
void priv_free_count_gave(const ra8_fs_mount_t *m, uint32_t n)
Account n clusters as returned to the volume's free space.
uint32_t priv_free_count_peek(const ra8_fs_mount_t *m)
Report the tracked free-cluster count, or k_fs_free_unknown.
void priv_alloc_hint_lower(const ra8_fs_mount_t *m, uint32_t cluster)
Pull the next-free hint back to cluster if it is further on.
static fat_alloc_state_t * internal_state_for(const ra8_fs_mount_t *m)
Find the allocator state slot bound to m.
static fat_alloc_state_t s_alloc[k_fs_alloc_slots]
One allocator state slot per mount slot.
void priv_alloc_state_bind(const ra8_fs_mount_t *m)
Claim and reset the allocator state slot for a freshly mounted volume.
static uint64_t s_fat_cache_lba
Volume-relative LBA held in s_fat_cache, or k_fs_cache_empty.
static ra8_err_t internal_fsinfo_locate(const ra8_fs_mount_t *m, uint32_t *out_lba)
Report the FSInfo sector number this volume declares, or absent.
static bool internal_lba_is_cacheable(const ra8_fs_mount_t *m, uint64_t lba)
True when lba lies inside the first FAT copy of m.
void priv_fat_sector_wrote(const ra8_fs_mount_t *m, const uint8_t *buf, uint64_t lba)
Tell the cache that lba has just been written with buf.
void priv_alloc_hint_set(const ra8_fs_mount_t *m, uint32_t cluster)
Move the next-free hint forward to cluster.
ra8_err_t priv_fsinfo_flush(const ra8_fs_mount_t *m)
Write the tracked free count and next-free hint back into FSInfo.
static uint8_t s_fat_cache[k_ra8_fs_sector_max]
The one cached FAT sector, shared by every mount.
ra8_err_t priv_fat_sector_read(const ra8_fs_mount_t *m, uint64_t lba, uint8_t *buf)
Read one FAT sector, through the shared one-sector cache.
static const ra8_fs_mount_t * s_fat_cache_owner
Mount whose volume s_fat_cache holds a sector of.
ra8_err_t priv_exfat_bitmap_lba(const ra8_fs_mount_t *m, uint64_t *out_lba)
Resolve the exFAT allocation bitmap's first LBA, once per mount.
void priv_alloc_state_release(const ra8_fs_mount_t *m)
Release the allocator state slot held by m.
static bool internal_fsinfo_signatures_ok(const uint8_t *sec)
Check the three FSInfo signatures in a candidate sector.
uint32_t priv_alloc_hint_get(const ra8_fs_mount_t *m)
Report the cluster a free-space scan should start from.
void priv_free_count_cache(const ra8_fs_mount_t *m, uint32_t n)
Cache a freshly counted free-cluster total in the allocator slot.
@ k_fs_fsinfo_absent
No usable FSInfo sector on this vol.
@ k_fs_alloc_slots
One state slot per mount slot.
@ k_fs_free_unknown
MS FAT spec sec 5: count not known.
@ k_fs_cache_empty
Cache holds no sector.
@ k_fs_bitmap_unknown
exFAT bitmap LBA not resolved yet.
uint8_t * priv_sec_walk(void)
The WALK-role sector buffer (directory scans and entry RMW).
ra8_err_t priv_exfat_find_bitmap(const ra8_fs_mount_t *m, uint32_t *out_clus, uint32_t *out_len)
Locate the allocation-bitmap entry in the exFAT root directory.
Cross-TU shared declarations for the FAT/exFAT ra8_fs adapter.
@ k_fmt_fsi_off_free
FSInfo FSI_Free_Count offset.
@ k_fmt_fsi_off_struct
FSInfo FSI_StrucSig offset.
@ k_fmt_off_f32_fsinfo
FAT32 BPB_FSInfo sector number.
@ k_fmt_fsi_off_nxtfree
FSInfo FSI_Nxt_Free offset.
@ k_fmt_fsi_off_lead
FSInfo FSI_LeadSig offset.
@ k_fmt_fsi_off_trail
FSInfo FSI_TrailSig offset.
@ k_fmt_fsi_lead_sig
FSInfo lead signature "RRaA".
@ k_fmt_fsi_trail_sig
FSInfo trailing signature.
@ k_fmt_fsi_struct_sig
FSInfo struct signature "rrAa".
@ k_cluster_first_data
Cluster numbers start at 2.
@ k_ra8_fs_type_fat32
count_of_clusters >= 65525.
@ k_ra8_fs_max_mounts
Max concurrent mount points.
@ k_ra8_fs_sector_max
Largest supported sector size (4Kn).
One mounted volume's answer to "where is the free space".
uint32_t fsinfo_lba
FSInfo sector, or k_fs_fsinfo_absent.
uint32_t free_count
Free clusters, or k_fs_free_unknown.
uint8_t dirty
1 = FSInfo needs a writeback.
uint64_t bitmap_lba
exFAT bitmap LBA, or unknown.
uint32_t next_free
Cluster the next scan starts at.
const ra8_fs_mount_t * owner
Mount this slot describes; NULL = free.
Cached parse of one mounted FAT volume.
uint32_t reserved_sectors
BPB BPB_RsvdSecCnt.
ra8_fs_type_t type
FAT12 / FAT16 / FAT32.
uint32_t fat_size_sectors
BPB BPB_FATSz16 / BPB_FATSz32.
uint32_t count_of_clusters
Per MS spec: data_sectors / SPC.
uint64_t first_fat_lba
Computed: first FAT sector.