45 return (uint16_t)(hi + (uint16_t)(cs >> 1) + (uint16_t)b);
52 for (uint32_t i = 0U; i < nlen; i++) {
68 for (uint32_t i = 0U; i < bytes; i++) {
139 uint64_t loaded = UINT64_MAX;
152 if ((((uint32_t)sec[
byte] >> bit) & 1U) != 0U) {
194 if (lba == *loaded) {
197 if (*loaded != UINT64_MAX) {
215 uint64_t loaded = UINT64_MAX;
217 for (uint32_t k = 0U; k < count; k++) {
226 sec[byte] = (uint8_t)(sec[
byte] | (uint8_t)(1U << bit));
245 *out_free = (uint8_t)(((((uint32_t)sec[
byte] >> bit) & 1U) != 0U) ? 0U : 1U);
340 for (uint32_t i = 0U; i < per_cluster; i++) {
396 uint32_t cluster = dir->
cluster;
478 const uint32_t name_entries =
480 const uint32_t sec_count = 1U + name_entries;
482 for (uint32_t i = 0U; i < total; i++) {
498 for (uint32_t n = 0U; n < name_entries; n++) {
524 for (uint32_t k = 0U; k < count; k++) {
546 const uint16_t* name,
551 const uint32_t name_entries =
553 const uint32_t need = 2U + name_entries;
567 out_head->
index = didx;
Annotation-attribute framework macros for ra8-firmware.
#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_ok
Success – operation completed with all postconditions satisfied.
@ 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).
uint32_t priv_rd32(const uint8_t *p)
Decode a little-endian uint32_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_byte_copy(uint8_t *dst, const uint8_t *src, uint32_t n)
Length-checked byte copy used in place of memcpy().
uint32_t priv_cluster_bytes(const ra8_fs_mount_t *m)
One mounted volume's cluster size in bytes.
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.
uint32_t priv_alloc_hint_get(const ra8_fs_mount_t *m)
Report the cluster a free-space scan should start from.
uint8_t * priv_sec_io(void)
The IO-role sector buffer (leaf data / bitmap sector transfers).
void priv_exfat_dir_root(const ra8_fs_mount_t *m, exfat_dir_t *out)
Fill out with the volume root's directory location.
ra8_err_t priv_exfat_step_cluster(const ra8_fs_mount_t *m, uint32_t cluster, uint32_t contig_end, uint32_t *out_next)
Compute the cluster that follows cluster in a directory.
void priv_exfat_cursor_init(const exfat_dir_t *dir, exfat_cursor_t *out)
Aim a fresh cursor at the start of dir.
ra8_err_t priv_exfat_next_entry(const ra8_fs_mount_t *m, exfat_cursor_t *cur, uint8_t *out)
Fetch the next 32-byte directory entry, following the cluster chain.
ra8_err_t priv_exfat_grow_dir(const ra8_fs_mount_t *m, exfat_dir_t *dir)
Append one zeroed cluster to a directory, keeping its entry set true.
uint16_t priv_exfat_upcase_unit(uint16_t unit)
Fold a UTF-16 code unit through the canonical exFAT up-case table.
static uint32_t internal_exfat_build_set(uint8_t *set, const uint16_t *name, uint32_t nlen)
Build a zero-length File + Stream + Name entry set into set.
ra8_err_t priv_exfat_bitmap_mark(const ra8_fs_mount_t *m, uint64_t bmp_lba, uint32_t clus, uint32_t count)
Implementation of priv_exfat_bitmap_mark() – one read-modify-write per sector.
ra8_err_t priv_exfat_bitmap_test(const ra8_fs_mount_t *m, uint64_t bmp_lba, uint32_t clus, uint8_t *out_free)
Implementation of priv_exfat_bitmap_test() – one sector read, one bit.
static uint16_t internal_exfat_csum_add(uint16_t cs, uint8_t b)
One step of exFAT's rotate-right-then-add 16-bit checksum.
uint16_t priv_exfat_set_checksum(const uint8_t *set, uint32_t bytes)
Compute the SetChecksum over a built directory entry set.
static ra8_err_t internal_exfat_bitmap_window(const ra8_fs_mount_t *m, uint64_t bmp_lba, uint32_t from, uint32_t need, uint32_t *out_clus)
Scan a window of the allocation bitmap for a contiguous free run.
uint16_t priv_exfat_name_hash(const uint16_t *name, uint32_t nlen)
Compute the exFAT NameHash for a name in UTF-16 code units.
ra8_err_t priv_exfat_bitmap_scan(const ra8_fs_mount_t *m, uint64_t bmp_lba, uint32_t need, uint32_t *out_clus)
Implementation of priv_exfat_bitmap_scan() – hinted pass, then a full rescan.
ra8_err_t priv_exfat_write_dir_set(const ra8_fs_mount_t *m, uint32_t cluster, uint32_t idx, const uint8_t *set, uint32_t bytes)
Write a pre-built entry set into consecutive directory entries.
ra8_err_t priv_exfat_bmp_switch(const ra8_fs_mount_t *m, uint64_t lba, uint64_t *loaded, uint8_t *sec)
Flush the cached bitmap sector and load lba if it changed.
static ra8_err_t internal_exfat_read_entry(const ra8_fs_mount_t *m, uint32_t cluster, uint32_t idx, uint8_t *out)
Read one 32-byte directory entry by index within a cluster.
static ra8_err_t internal_exfat_space_in_cluster(const ra8_fs_mount_t *m, uint32_t cluster, uint32_t need, uint32_t *out_idx)
Scan one directory cluster for need consecutive free entries.
ra8_err_t priv_exfat_find_dir_space(const ra8_fs_mount_t *m, const exfat_dir_t *dir, uint32_t need, uint32_t *out_clus, uint32_t *out_idx)
Find need consecutive free entry slots inside one directory cluster.
static uint8_t internal_exfat_slot_free(uint8_t type_byte)
True if a directory entry slot is free (end-of-dir or deleted).
static ra8_err_t internal_exfat_scan_dir_space(const ra8_fs_mount_t *m, const exfat_dir_t *dir, uint32_t need, uint32_t *out_clus, uint32_t *out_idx)
Scan a directory's existing clusters for need consecutive free slots.
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.
ra8_err_t priv_exfat_link(const ra8_fs_mount_t *m, const exfat_dir_t *dir, const uint16_t *name, uint32_t nlen, exfat_setpos_t *out_head, uint32_t *out_count)
Implementation of priv_exfat_link() – one directory-slot scan, one set write.
Cross-TU shared declarations for the FAT/exFAT ra8_fs adapter.
void priv_exfat_file_stamp_create(uint8_t *file_entry)
Stamp a fresh exFAT File entry's create, modify, and access fields.
@ k_exfat_name_off
File-name entry character offset.
@ k_exfat_strm_off_dlen
Stream-ext DataLength (low 32 used).
@ k_exfat_strm_off_nlen
Stream-ext NameLength (UTF-16 units).
@ k_exfat_strm_off_clus
Stream-ext FirstCluster.
@ k_exfat_strm_off_flags
Stream-ext GeneralSecondaryFlags.
@ k_exfat_entry_bitmap
Allocation-bitmap directory entry.
@ k_exfat_off_file_csum
File entry: SetChecksum (2 bytes).
@ k_exfat_name_per_entry
UTF-16 units per file-name entry.
@ k_exfat_entry_bytes
Directory entry size.
@ k_exfat_csum_hi_bit
Wrap bit for the rotate-add checksum.
@ k_exfat_off_strm_hash
Stream entry: NameHash (2 bytes).
@ k_exfat_secflag_poss
GeneralSecondaryFlags: AllocationPossible.
@ k_exfat_entry_eod
End-of-directory marker.
@ k_exfat_bit_shift
log2(8): cluster index -> byte.
@ k_exfat_entry_stream
Stream-extension entry.
@ k_exfat_off_file_attr
File entry: FileAttributes (2 bytes).
@ k_exfat_off_file_secnt
File entry: SecondaryCount.
@ k_exfat_max_set_bytes
(2 + ceil(64/15)) * 32 = 7 entries.
@ k_exfat_attr_archive
FileAttributes: archive.
@ k_exfat_scan_limit
Max dir entries scanned (P10 bound).
@ k_exfat_dir_grow_max
Max clusters one find-space call appends.
@ k_exfat_bit_mask
Bit index within a bitmap byte.
@ k_exfat_entry_name
File-name entry.
@ k_exfat_inuse_bit
Directory entry type bit 7 = in use.
@ k_exfat_entry_file
File directory entry.
@ k_cluster_first_data
Cluster numbers start at 2.
@ k_utf_byte_mask
Mask isolating a unit's low byte.
@ k_utf_byte_shift
Shift bringing a unit's high byte down.
Linear cursor over a directory's 32-byte entries.
uint32_t scanned
Total entries read (P10 bound).
Identifies the exFAT directory a lookup, scan or link operates in.
uint32_t cluster
First cluster of the directory.
uint32_t contig_end
One past the run's last cluster; 0 => FAT-chained.
Directory position (cluster + entry index) of one 32-byte entry.
uint32_t index
Entry index within that cluster (0-based).
uint32_t cluster
Directory cluster holding the entry.
Cached parse of one mounted FAT volume.
uint32_t count_of_clusters
Per MS spec: data_sectors / SPC.