ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
Loading...
Searching...
No Matches
ra8_fs_fat_exfat_label.c File Reference

exFAT volume-label read/write (the exFAT half of ra8_fs_{get,set}_label). More...

#include <stddef.h>
#include <stdint.h>
#include "ra8_attributes.h"
#include "ra8_fs.h"
#include "ra8_fs_fat_internal.h"
#include "ra8_fs_meta.h"
Include dependency graph for ra8_fs_fat_exfat_label.c:

Go to the source code of this file.

Functions

static ra8_err_t internal_exfat_locate_label (const ra8_fs_mount_t *m, exfat_setpos_t *out_pos, uint8_t *out_entry, bool *out_present)
 Locate the exFAT Volume Label entry (or the slot to create one at).
static void internal_exfat_label_decode (const uint8_t *entry, char *out, uint32_t out_len)
 Decode an exFAT Volume Label entry's UTF-16LE label into ASCII.
ra8_err_t priv_exfat_get_label (const ra8_fs_mount_t *m, char *out, uint32_t out_len)
 Read an exFAT volume's label into an ASCII buffer.
ra8_err_t priv_exfat_set_label (const ra8_fs_mount_t *m, const char *label)
 Set (or clear) an exFAT volume's label in place.

Detailed Description

exFAT volume-label read/write (the exFAT half of ra8_fs_{get,set}_label).

exFAT keeps the volume label in a single root-directory entry – the Volume Label entry, type 0x83 when a label is present, 0x03 (in-use bit clear) when it is not (exFAT spec sec 7.7). Unlike a File entry set, it stands alone with no secondary entries and no SetChecksum spanning several entries, so reading and rewriting it is a single-entry operation. The FAT half, and the public lock-bracketed entry points that dispatch here, live in ra8_fs_fat_label.c.

References (every shorthand citation in this file):

  • "exFAT spec" = Microsoft Corp., "exFAT file system specification", revision 1.00, section 7.7 "Volume Label Directory Entry".

NASA Power-of-Ten compliance:

  • Rule 2: the root scan is bounded by k_exfat_scan_limit; the decode / encode loops by k_exfat_fmt_label_max (11).
  • Rule 3: zero malloc; one 32-byte entry buffer on the stack.
  • Rule 7: every backend call is checked.
Since
0.1.0

Definition in file ra8_fs_fat_exfat_label.c.

Function Documentation

◆ internal_exfat_label_decode()

void internal_exfat_label_decode ( const uint8_t * entry,
char * out,
uint32_t out_len )
static

Decode an exFAT Volume Label entry's UTF-16LE label into ASCII.

Reads the CharacterCount and copies the low byte of each UTF-16 code unit – the ASCII character for a Latin-1 label – into out, truncated to the entry's cap and to out_len, and NUL-terminated.

Parameters
[in]entryA 32-byte Volume Label entry (type 0x83).
[out]outBuffer receiving the NUL-terminated label.
[in]out_lenCapacity of out in bytes (at least 1).
Returns
Nothing.
Precondition
entry and out are non-NULL; out_len >= 1.
entry is an in-use Volume Label entry.
Postcondition
out is NUL-terminated (possibly truncated).
No byte past out[out_len-1] is written.
Note
Bounded loop (NASA Rule 2): k_exfat_fmt_label_max iterations.
Since
0.1.0

Definition at line 123 of file ra8_fs_fat_exfat_label.c.

References k_exfat_de_lbl_cnt, k_exfat_de_lbl_name, and k_exfat_fmt_label_max.

Referenced by priv_exfat_get_label().

◆ internal_exfat_locate_label()

ra8_err_t internal_exfat_locate_label ( const ra8_fs_mount_t * m,
exfat_setpos_t * out_pos,
uint8_t * out_entry,
bool * out_present )
static

Locate the exFAT Volume Label entry (or the slot to create one at).

Scans the root directory. On the first entry whose type – ignoring the in-use bit – is the Volume Label type (0x83 present, or 0x03 cleared), reports it: out_pos its position, out_entry its 32 bytes, out_present true. If end-of-directory is reached first the volume carries no label entry: out_pos is the EOD slot a new one would go in and out_present is false.

Parameters
[in]mMounted exFAT volume.
[out]out_posPosition of the label entry, or of the EOD slot.
[out]out_entryThe 32-byte label entry (only meaningful when present).
[out]out_presentReceives true when a label entry exists.
Returns
Error code.
Return values
k_ra8_okout_pos / out_present populated.
k_ra8_err_not_foundThe scan limit was hit without an entry or EOD.
k_ra8_err_*Backend read failure.
Precondition
All pointers are non-NULL; m->type is exFAT.
The mount is in use.
Postcondition
On k_ra8_ok out_pos addresses a writable root-directory slot.
No volume state is modified.
Note
Bounded loop (NASA Rule 2): k_exfat_scan_limit entries.
Not thread-safe; callers serialise filesystem operations.
Since
0.1.0

Definition at line 67 of file ra8_fs_fat_exfat_label.c.

References exfat_cursor_t::cluster, exfat_cursor_t::entry_in_cluster, k_exfat_entry_bytes, k_exfat_entry_eod, k_exfat_entry_label, k_exfat_inuse_bit, k_exfat_scan_limit, k_ra8_err_not_found, k_ra8_ok, priv_byte_copy(), priv_exfat_cursor_init(), priv_exfat_dir_root(), priv_exfat_next_entry(), and exfat_cursor_t::scanned.

Referenced by priv_exfat_get_label(), and priv_exfat_set_label().

◆ priv_exfat_get_label()

ra8_err_t priv_exfat_get_label ( const ra8_fs_mount_t * m,
char * out,
uint32_t out_len )

Read an exFAT volume's label into an ASCII buffer.

Scans the root directory for the Volume Label directory entry (exFAT spec sec 7.7): an in-use entry (type 0x83) yields its UTF-16LE label decoded to ASCII (low byte of each code unit), truncated to out_len; a cleared entry (type 0x03) or no entry at all yields the empty string. The exFAT half of ra8_fs_get_label.

Parameters
[in]mMounted exFAT volume.
[out]outBuffer receiving the NUL-terminated label.
[in]out_lenCapacity of out in bytes (at least 1).
Returns
Error code.
Return values
k_ra8_okout holds the label (possibly empty).
k_ra8_err_*Backend read failure, or a volume with no directory.
Precondition
m and out are non-NULL; m->type is exFAT; out_len >= 1.
The mount is in use.
Postcondition
out is NUL-terminated.
No volume state is modified.
Note
Not thread-safe; callers serialise filesystem operations.
Since
0.1.0

Definition at line 141 of file ra8_fs_fat_exfat_label.c.

References internal_exfat_label_decode(), internal_exfat_locate_label(), k_exfat_entry_bytes, k_exfat_entry_label, and k_ra8_ok.

◆ priv_exfat_set_label()

ra8_err_t priv_exfat_set_label ( const ra8_fs_mount_t * m,
const char * label )

Set (or clear) an exFAT volume's label in place.

Rewrites the root Volume Label directory entry (exFAT spec sec 7.7) with the new UTF-16LE label and character count, creating one at the end-of-directory position when the volume carries none. A NULL or empty label writes a zero-length label entry (the unlabelled form). The exFAT half of ra8_fs_set_label.

Parameters
[in]mMounted exFAT volume.
[in]labelNew label (<= 11 characters), or NULL / "" to clear it.
Returns
Error code.
Return values
k_ra8_okLabel written.
k_ra8_err_not_foundThe root directory could not be scanned.
k_ra8_err_*Backend read/write failure.
Precondition
m is non-NULL; m->type is exFAT; the mount is in use.
label, when non-NULL, is at most 11 characters.
Postcondition
On success a later priv_exfat_get_label reports label.
Only the Volume Label entry is modified.
Note
Not thread-safe; callers serialise filesystem operations.
Since
0.1.0

Definition at line 159 of file ra8_fs_fat_exfat_label.c.

References exfat_setpos_t::cluster, exfat_setpos_t::index, internal_exfat_locate_label(), k_exfat_de_lbl_cnt, k_exfat_de_lbl_name, k_exfat_entry_bytes, k_exfat_entry_label, k_exfat_fmt_label_max, k_ra8_ok, and priv_exfat_write_dir_set().