ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
Loading...
Searching...
No Matches
ra8_fs_fat_utime.c
Go to the documentation of this file.
1
34
35#include <stddef.h>
36#include <stdint.h>
37
38#include "ra8_attributes.h"
39#include "ra8_fs.h"
40#include "ra8_fs_fat_internal.h"
41#include "ra8_fs_meta.h"
42
76 const char* path,
77 const ra8_fs_datetime_t* create,
78 const ra8_fs_datetime_t* modify,
79 const ra8_fs_datetime_t* access)
80{
81 dir_loc_t parent = {};
82 const char* leaf = nullptr;
83 const ra8_err_t rerr = priv_resolve_parent(m, path, &parent, &leaf);
84 if (rerr != k_ra8_ok) {
85 return rerr;
86 }
87 uint8_t name83[k_max_8_3_name] = {};
88 const uint8_t have83 = priv_path_to_83(leaf, name83);
89 uint64_t lba = 0U;
90 uint32_t off = 0U;
91 uint8_t entry[k_ra8_fs_dir_entry_bytes] = {};
93 if (have83 != 0U) {
94 err = priv_dir_find(m, &parent, name83, &lba, &off, entry);
95 }
96 if (err == k_ra8_err_not_found) {
97 err = priv_dir_find_long(m, &parent, leaf, &lba, &off, entry);
98 }
99 if (err != k_ra8_ok) {
100 return err;
101 }
102 uint8_t* const sec = priv_sec_walk();
103 err = priv_read_sector(m, lba, sec);
104 if (err != k_ra8_ok) {
105 return err;
106 }
107 priv_fat_entry_set_times(&sec[off], create, modify, access);
108 return priv_write_sector(m, lba, sec);
109}
110
146 const char* path,
147 const ra8_fs_datetime_t* create,
148 const ra8_fs_datetime_t* modify,
149 const ra8_fs_datetime_t* access)
150{
151 exfat_dir_t root = {};
152 priv_exfat_dir_root(m, &root);
154 uint32_t count = 0U;
155 uint8_t file_e[k_exfat_entry_bytes] = {};
156 uint8_t strm_e[k_exfat_entry_bytes] = {};
158 &root,
159 path,
160 pos,
161 (uint32_t)k_exfat_set_max_entries,
162 &count,
163 file_e,
164 strm_e);
165 if (err != k_ra8_ok) {
166 return err;
167 }
168 uint8_t set[(uint32_t)k_exfat_set_max_entries * (uint32_t)k_exfat_entry_bytes] = {};
169 for (uint32_t k = 0U; k < count; k++) {
170 exfat_cursor_t one = {.cluster = pos[k].cluster,
171 .entry_in_cluster = pos[k].index,
172 .scanned = 0U,
173 .contig_end = 0U};
174 err = priv_exfat_next_entry(m, &one, &set[(size_t)k * (size_t)k_exfat_entry_bytes]);
175 if (err != k_ra8_ok) {
176 return err;
177 }
178 }
179 priv_exfat_file_set_times(&set[0], create, modify, access);
181 priv_exfat_set_checksum(set, count * (uint32_t)k_exfat_entry_bytes));
183 pos[0].cluster,
184 pos[0].index,
185 &set[0],
186 (uint32_t)k_exfat_entry_bytes);
187}
188
223RA8_EXPECTS_LOCK("ra8_fs_lock")
225 const char* path,
226 const ra8_fs_datetime_t* create,
227 const ra8_fs_datetime_t* modify,
228 const ra8_fs_datetime_t* access)
229{
230 if (handle == nullptr || path == nullptr) {
231 return k_ra8_err_null_ptr;
232 }
233 if (handle->in_use == 0U) {
234 return k_ra8_err_invalid_state;
235 }
236 const char* p = path;
237 while (*p == '/') {
238 p++;
239 }
240 if (*p == '\0') {
241 return k_ra8_err_invalid_arg; /* the volume root has no entry to stamp */
242 }
243 if (handle->type == k_ra8_fs_type_exfat) {
244 return internal_utime_exfat(handle, path, create, modify, access);
245 }
246 return internal_utime_fat(handle, path, create, modify, access);
247}
248
249/* =============================================================================
250 * Public entry point -- the lock bracket
251 * =============================================================================
252 */
253
254RA8_OWNS_RESOURCE("ra8_fs_lock")
256 const char* path,
257 const ra8_fs_datetime_t* create,
258 const ra8_fs_datetime_t* modify,
259 const ra8_fs_datetime_t* access)
260{
262 const ra8_err_t err = internal_utime_locked(handle, path, create, modify, access);
264 return err;
265}
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_err_invalid_arg
Invalid function argument.
Definition ra8_err.h:152
@ k_ra8_ok
Success – operation completed with all postconditions satisfied.
Definition ra8_err.h:119
@ k_ra8_err_null_ptr
Pointer was NULL where a valid pointer was required.
Definition ra8_err.h:478
@ k_ra8_err_not_found
Requested item not found (lookup / search missed).
Definition ra8_err.h:173
ra8_err_codes_t ra8_err_t
Canonical error-return type used by every ra8-firmware API.
Definition ra8_err.h:546
Minimal FAT12/FAT16/FAT32 filesystem adapter (read + write).
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.
Definition ra8_fs_fat.c:134
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.
Definition ra8_fs_fat.c:140
void priv_wr16(uint8_t *p, uint16_t v)
Encode a little-endian uint16_t into a byte buffer.
Definition ra8_fs_fat.c:61
uint8_t * priv_sec_walk(void)
The WALK-role sector buffer (directory scans and entry RMW).
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_find_set(const ra8_fs_mount_t *m, const exfat_dir_t *dir, const char *path, exfat_setpos_t *pos, uint32_t max_pos, uint32_t *out_count, uint8_t *file_copy, uint8_t *strm_copy)
Implementation of priv_exfat_find_set() – one aligned walk of a directory.
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.
uint16_t priv_exfat_set_checksum(const uint8_t *set, uint32_t bytes)
Compute the SetChecksum over a built directory entry set.
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_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_dir_find_long(const ra8_fs_mount_t *m, const dir_loc_t *loc, const char *want, uint64_t *out_lba, uint32_t *out_entry_off, uint8_t out_entry[k_ra8_fs_dir_entry_bytes])
Find a directory entry by its VFAT long name (case-insensitive).
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.
uint8_t priv_path_to_83(const char *path, uint8_t *out11)
Convert a "/FILE.TXT"-style path to packed 11-byte 8.3 form.
ra8_err_t priv_dir_find(const ra8_fs_mount_t *m, const dir_loc_t *loc, const uint8_t *name83, uint64_t *out_lba, uint32_t *out_entry_off, uint8_t out_entry[k_ra8_fs_dir_entry_bytes])
Find a directory entry by 8.3 name within a given directory.
void priv_fat_entry_set_times(uint8_t *entry, const ra8_fs_datetime_t *create, const ra8_fs_datetime_t *modify, const ra8_fs_datetime_t *access)
Set chosen FAT directory-entry timestamps from caller-supplied readings.
void priv_exfat_file_set_times(uint8_t *file_entry, const ra8_fs_datetime_t *create, const ra8_fs_datetime_t *modify, const ra8_fs_datetime_t *access)
Set chosen exFAT File-entry timestamps from caller-supplied readings.
@ k_exfat_off_file_csum
File entry: SetChecksum (2 bytes).
@ k_exfat_entry_bytes
Directory entry size.
@ k_exfat_set_max_entries
1 File + 1 Stream + 17 Name entries.
@ k_max_8_3_name
8.3 packed length without dot.
static ra8_err_t internal_utime_locked(const ra8_fs_mount_t *handle, const char *path, const ra8_fs_datetime_t *create, const ra8_fs_datetime_t *modify, const ra8_fs_datetime_t *access)
Set entry timestamps – the guarded body of ra8_fs_utime().
static ra8_err_t internal_utime_exfat(const ra8_fs_mount_t *m, const char *path, const ra8_fs_datetime_t *create, const ra8_fs_datetime_t *modify, const ra8_fs_datetime_t *access)
Set chosen timestamps on an exFAT root-level entry.
static ra8_err_t internal_utime_fat(const ra8_fs_mount_t *m, const char *path, const ra8_fs_datetime_t *create, const ra8_fs_datetime_t *modify, const ra8_fs_datetime_t *access)
Set chosen timestamps on a FAT12/16/32 entry.
Volume-level metadata: free space, volume label, and per-entry utime.
ra8_err_t ra8_fs_utime(const ra8_fs_mount_t *handle, const char *path, const ra8_fs_datetime_t *create, const ra8_fs_datetime_t *modify, const ra8_fs_datetime_t *access)
Set a named entry's create / modify / access timestamps.
@ k_ra8_fs_type_exfat
exFAT (read + streaming write + format).
@ k_ra8_fs_dir_entry_bytes
MS FAT spec sec 6 "Directory Entry".
Identifies the directory a lookup/scan should operate in.
Linear cursor over a directory's 32-byte entries.
Identifies the exFAT directory a lookup, scan or link operates in.
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.
Broken-down civil date and time used at the filesystem boundary.
Cached parse of one mounted FAT volume.