55typedef enum : uint32_t {
88 n += ((uint32_t)b >> i) & 1U;
168 uint32_t bmp_clus = 0U;
169 uint32_t bmp_len = 0U;
181 const uint32_t nbytes = full_bytes + ((rem_bits != 0U) ? 1U : 0U);
183 uint64_t loaded = UINT64_MAX;
185 for (uint32_t bi = 0U; bi < nbytes; bi++) {
186 const uint64_t lba = bmp_lba + (bi /
priv_bps(m));
198 if (bi == full_bytes) {
199 b = (uint8_t)(b & (uint8_t)((1U << rem_bits) - 1U));
205 *out_free = total - used;
292 if (handle ==
nullptr || out ==
nullptr) {
295 if (handle->in_use == 0U) {
296 return k_ra8_err_invalid_state;
298 uint32_t free_clusters = 0U;
307 const uint32_t total = handle->count_of_clusters;
309 const uint32_t used = total - free_clusters;
311 out->bytes_per_cluster = bytes_per_cluster;
312 out->total_clusters = total;
313 out->free_clusters = free_clusters;
314 out->used_clusters = used;
315 out->total_bytes = (uint64_t)total * (uint64_t)bytes_per_cluster;
316 out->free_bytes = (uint64_t)free_clusters * (uint64_t)bytes_per_cluster;
317 out->used_bytes = (uint64_t)used * (uint64_t)bytes_per_cluster;
Annotation-attribute framework macros for ra8-firmware.
#define RA8_OWNS_RESOURCE(kind)
RAII-style resource ownership contract.
#define RA8_EXPECTS_LOCK(name)
The function expects the named thread/IRQ lock to be held on entry.
#define RA8_INTERNAL
Marker that a function is intended to be static (file-local).
@ k_ra8_ok
Success – operation completed with all postconditions satisfied.
@ k_ra8_err_null_ptr
Pointer was NULL where a valid pointer was required.
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 priv_fat_get(const ra8_fs_mount_t *m, uint32_t cluster, uint32_t *out_value)
Fetch the FAT entry for cluster, returning the next-cluster value.
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.
uint32_t priv_cluster_bytes(const ra8_fs_mount_t *m)
One mounted volume's cluster size in bytes.
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_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_free_unknown
MS FAT spec sec 5: count not known.
uint8_t * priv_sec_io(void)
The IO-role sector buffer (leaf data / bitmap sector transfers).
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.
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.
static ra8_err_t internal_space_free_clusters(const ra8_fs_mount_t *m, uint32_t *out_free)
Resolve the free-cluster count: cached, or freshly walked and cached.
static ra8_err_t internal_space_exfat_free(const ra8_fs_mount_t *m, uint32_t *out_free)
Count free clusters on an exFAT volume by population-counting the bitmap.
ra8_fs_space_const_t
Bit-arithmetic constants for the free-space walkers.
@ k_space_bit_mask
Cluster index -> bit within its byte.
@ k_space_byte_shift
log2(8): cluster index -> bitmap byte.
@ k_space_bits_per_byte
Bits in one allocation-bitmap byte.
static ra8_err_t internal_space_fat_free(const ra8_fs_mount_t *m, uint32_t *out_free)
Count free clusters on a FAT12/16/32 volume by scanning the FAT.
static ra8_err_t internal_space_locked(const ra8_fs_mount_t *handle, ra8_fs_space_t *out)
Report free/used/total space – the guarded body of ra8_fs_free_space().
static uint32_t internal_popcount8(uint8_t b)
Count the set bits in one byte.
@ k_cluster_free
Cluster free.
@ k_cluster_first_data
Cluster numbers start at 2.
@ k_ra8_fs_type_exfat
exFAT (read + streaming write + format).
Cached parse of one mounted FAT volume.
ra8_fs_type_t type
FAT12 / FAT16 / FAT32.
uint32_t count_of_clusters
Per MS spec: data_sectors / SPC.
A mounted volume's capacity, free space, and cluster geometry.