rcbench
Servo and ESC test bench: panel, IOmcu and shared C
Loading...
Searching...
No Matches
storage.h
Go to the documentation of this file.
1
18
19#pragma once
20
21#include <stdbool.h>
22#include <stddef.h>
23#include <stdint.h>
24#include <stdio.h>
25
26#include "card_state.h"
27#include "esp_err.h"
28
29#ifdef __cplusplus
30extern "C" {
31#endif
32
33#define STORAGE_MOUNT_POINT "/sdcard"
34#define STORAGE_NAME_MAX 64
35
36/*
37 * A file's size is 64-bit: an exFAT (extended File Allocation Table) volume
38 * holds files of 4GiB and more. FAT12, FAT16 and FAT32 stop at
39 * 4GiB less 1 byte.
40 */
41typedef struct {
42 char name[STORAGE_NAME_MAX];
43 uint64_t size;
44 bool is_dir;
50 uint32_t stamp;
52
54typedef struct {
55 uint64_t size;
56 bool is_dir;
57 int64_t mtime;
59
76esp_err_t storage_init(void);
77
95
105bool storage_hold(void);
106
110bool storage_hold_mount(unsigned mount);
111
114void storage_release(void);
115
118FILE *storage_fopen(const char *path, const char *mode);
119
123int storage_fclose(FILE *f);
124
129void storage_deinit(void);
130
132bool storage_mounted(void);
133
137unsigned storage_mount_count(void);
138
140uint64_t storage_total_bytes(void);
141uint64_t storage_free_bytes(void);
142
150void storage_card_name(char *out, size_t n);
151
158const char *storage_status(void);
159
168
170typedef void (*storage_visit_fn)(const storage_entry_t *entry, void *ctx);
171
172typedef void (*storage_tick_fn)(void);
173
175#define STORAGE_WALK_NO_DIR (-2)
179#define STORAGE_WALK_REMOUNTED (-3)
180
224int storage_walk(const char *dir, const char *suffixes, storage_visit_fn visit,
225 void *ctx, storage_tick_fn tick);
226
245int storage_walk_counted(const char *dir, const char *suffixes,
246 storage_visit_fn visit, void *ctx,
247 storage_tick_fn tick, unsigned *left_out);
248
266esp_err_t storage_stat(const char *path, storage_stat_t *out);
267
279int64_t storage_stamp_mtime(uint32_t stamp);
280
283
298storage_dir_t *storage_dir_open(const char *path);
299
309int storage_dir_read(storage_dir_t *d, char *name, size_t cap,
310 storage_stat_t *out);
311
318
320void storage_path(const char *dir, const char *name, char *out, size_t out_size);
321
322#ifdef __cplusplus
323}
324#endif
What the panel's SD (Secure Digital) card slot holds, as the last mount found it: no card,...
card_state_t
Mount state of the SD card.
Definition card_state.h:17
card_state_t storage_check(void)
Definition storage.c:531
uint64_t storage_total_bytes(void)
Definition storage.c:673
bool storage_hold(void)
Definition storage.c:556
void storage_card_name(char *out, size_t n)
Definition storage.c:652
void(*) storage_visit_fn(const storage_entry_t *entry, void *ctx)
Definition storage.h:170
unsigned storage_mount_count(void)
Definition storage.c:642
int storage_walk_counted(const char *dir, const char *suffixes, storage_visit_fn visit, void *ctx, storage_tick_fn tick, unsigned *left_out)
storage_walk(), and the count of the entries its name filters left out: names starting with "....
Definition storage_list.c:221
int storage_walk(const char *dir, const char *suffixes, storage_visit_fn visit, void *ctx, storage_tick_fn tick)
Walk a directory, handing every matching entry to visit, with its size (0 for a directory) and its FA...
Definition storage_list.c:215
int64_t storage_stamp_mtime(uint32_t stamp)
A storage_entry_t stamp as the time storage_stat() gives the same file: FAT's local date and time thr...
Definition storage_list.c:266
void storage_deinit(void)
Unmount and switch the card's supply off. Safe to call when nothing was mounted. Clears storage_statu...
Definition storage.c:622
int storage_dir_read(storage_dir_t *d, char *name, size_t cap, storage_stat_t *out)
The next entry of d.
Definition storage_list.c:382
void storage_release(void)
Definition storage.c:585
card_state_t storage_card_state(void)
Definition storage.c:667
esp_err_t storage_init(void)
Switch the card's supply on and mount the card at /sdcard.
Definition storage.c:512
esp_err_t storage_stat(const char *path, storage_stat_t *out)
The size, kind and time of one file or folder, by its full path under STORAGE_MOUNT_POINT,...
Definition storage_list.c:322
const char * storage_status(void)
What went wrong, in a few words for the console and the start-up line: "no card", "no FAT volume",...
Definition storage.c:662
void storage_dir_close(storage_dir_t *d)
Close d and give its hold back. A failed read is weighed as storage_walk() weighs one,...
Definition storage_list.c:404
FILE * storage_fopen(const char *path, const char *mode)
Definition storage.c:600
void storage_path(const char *dir, const char *name, char *out, size_t out_size)
Definition storage_list.c:30
bool storage_mounted(void)
Definition storage.c:647
int storage_fclose(FILE *f)
Definition storage.c:612
bool storage_hold_mount(unsigned mount)
Definition storage.c:570
storage_dir_t * storage_dir_open(const char *path)
Open a folder by its full path under STORAGE_MOUNT_POINT, "/sdcard" for the root, to read it one entr...
Definition storage_list.c:349
struct storage_dir storage_dir_t
A folder open for storage_dir_read().
Definition storage.h:282
An open folder: FatFs's handle, its entry, and the last read's answer for the close.
Definition storage_list.c:343
FF_DIR dir
Definition storage_list.c:344
Definition storage.h:41
uint32_t stamp
FAT's date stamp in bits 31..16 and its time stamp in bits 15..0, as the directory read returns them ...
Definition storage.h:50
Definition storage.h:54
int64_t mtime
Definition storage.h:57
uint64_t size
Definition storage.h:55