rcbench
Servo and ESC test bench: panel, IOmcu and shared C
Loading...
Searching...
No Matches
kst_store.h
Go to the documentation of this file.
1
30
31#pragma once
32
33#include <stdbool.h>
34#include <stddef.h>
35#include <stdint.h>
36
37#include "card_tree.h"
38
39#ifdef __cplusplus
40extern "C" {
41#endif
42
47#define KST_STORE_DIR CARD_KST_CONF
48
52#define KST_STORE_EXT ".TXT"
53
57#define KST_STORE_BASE_MAX 32
58
62#define KST_STORE_NAME_MAX (KST_STORE_BASE_MAX + 4 + 1)
63
67#define KST_STORE_FIRST 1
68#define KST_STORE_LAST 999
69
73#define KST_STORE_PRESET_MAX 7
74
84#define KST_STORE_RECORD "KST"
85
105
111typedef enum {
112 KST_STORE_OK = 0,
119 KST_STORE_CARD_FULL = 7,
120 KST_STORE_WRITE_ERROR = 8,
123 KST_STORE_READ_ERROR = 11,
128
142
146typedef void (*kst_store_visit_fn)(const char *name, bool is_dir,
147 void *visit_ctx);
148
154typedef struct {
155 void *ctx;
159 bool (*mounted)(void *ctx);
167 bool (*walk)(void *ctx, kst_store_visit_fn visit, void *visit_ctx);
171 int32_t (*size)(void *ctx, const char *name);
177 int32_t (*read)(void *ctx, const char *name, char *buf, size_t cap);
183 kst_store_io_result_t (*create)(void *ctx, const char *name,
184 const char *data, size_t len);
186
190typedef struct {
193
200kst_store_name_t kst_store_name_check(const char *base);
201
213bool kst_store_file_name(const char *base, char *out, size_t out_size);
214
230kst_store_t kst_store_preset(const kst_store_io_t *io, char *base,
231 size_t base_size);
232
247kst_store_t kst_store_save(const kst_store_io_t *io, const char *base,
248 const char *text, size_t len,
249 kst_store_name_t *why);
250
276 kst_store_entry_t *entries, size_t cap,
277 size_t *count, size_t *total, size_t *skipped);
278
300kst_store_t kst_store_list_after(const kst_store_io_t *io, const char *after,
301 kst_store_entry_t *entries, size_t cap,
302 size_t *count, size_t *total,
303 size_t *skipped);
304
318kst_store_t kst_store_load(const kst_store_io_t *io, const char *name,
319 char *buf, size_t cap, size_t *len);
320
321#ifdef __cplusplus
322}
323#endif
The folders of the panel's SD (Secure Digital) card, and the files in them with a fixed name.
void(*) kst_store_visit_fn(const char *name, bool is_dir, void *visit_ctx)
Receives one directory entry. name does not outlive the call.
Definition kst_store.h:146
kst_store_t kst_store_load(const kst_store_io_t *io, const char *name, char *buf, size_t cap, size_t *len)
Read the file name, a name as kst_store_list() gives it, into buf. len receives the number of bytes.
Definition kst_store.c:465
kst_store_t kst_store_save(const kst_store_io_t *io, const char *base, const char *text, size_t len, kst_store_name_t *why)
Write len bytes of text as the file of base.
Definition kst_store.c:293
kst_store_t kst_store_preset(const kst_store_io_t *io, char *base, size_t base_size)
Propose a base name: "KST" and 3 digits, one above the highest number the directory holds.
Definition kst_store.c:231
kst_store_t kst_store_list(const kst_store_io_t *io, kst_store_entry_t *entries, size_t cap, size_t *count, size_t *total, size_t *skipped)
List the files with KST_STORE_EXT.
Definition kst_store.c:430
kst_store_io_result_t
What the create function reports.
Definition kst_store.h:132
@ KST_STORE_IO_EXISTS
Definition kst_store.h:134
@ KST_STORE_IO_ERROR
Definition kst_store.h:136
@ KST_STORE_IO_FULL
Definition kst_store.h:135
@ KST_STORE_IO_DENIED
Definition kst_store.h:137
kst_store_name_t kst_store_name_check(const char *base)
Whether base is a base name this layer writes.
Definition kst_store.c:151
kst_store_t
The result of a call.
Definition kst_store.h:111
@ KST_STORE_BAD_NAME
Definition kst_store.h:117
@ KST_STORE_NO_CARD
Definition kst_store.h:114
@ KST_STORE_TOO_LARGE
Definition kst_store.h:122
@ KST_STORE_EXISTS
Definition kst_store.h:118
@ KST_STORE_NOT_FOUND
Definition kst_store.h:121
@ KST_STORE_NO_NUMBER
Definition kst_store.h:116
@ KST_STORE_LIST_ERROR
Definition kst_store.h:115
@ KST_STORE_ARG
Definition kst_store.h:113
@ KST_STORE_DENIED
Definition kst_store.h:124
kst_store_name_t
Whether a base name is taken.
Definition kst_store.h:91
@ KST_STORE_NAME_RESERVED
Definition kst_store.h:97
@ KST_STORE_NAME_TOO_LONG
Definition kst_store.h:94
@ KST_STORE_NAME_BAD_CHAR
Definition kst_store.h:95
@ KST_STORE_NAME_EMPTY
Definition kst_store.h:93
@ KST_STORE_NAME_EDGE
Definition kst_store.h:102
bool kst_store_file_name(const char *base, char *out, size_t out_size)
The file name of base: the base name and KST_STORE_EXT.
Definition kst_store.c:156
kst_store_t kst_store_list_after(const kst_store_io_t *io, const char *after, kst_store_entry_t *entries, size_t cap, size_t *count, size_t *total, size_t *skipped)
kst_store_list() from the file behind after on: entries receives the first cap files the order has be...
Definition kst_store.c:438
#define KST_STORE_NAME_MAX
Room for a file name: base name, extension and terminator.
Definition kst_store.h:62
One row of a list.
Definition kst_store.h:190
char name[KST_STORE_NAME_MAX]
Definition kst_store.h:191
The card.
Definition kst_store.h:154
int32_t(*) read(void *ctx, const char *name, char *buf, size_t cap)
Up to cap bytes from the start of the file.
Definition kst_store.h:177
kst_store_io_result_t(*) create(void *ctx, const char *name, const char *data, size_t len)
Create the directory when it is missing, create the file and fail when the name exists,...
Definition kst_store.h:183
bool(*) walk(void *ctx, kst_store_visit_fn visit, void *visit_ctx)
Call visit for every entry of the directory, files and directories, once each.
Definition kst_store.h:167
bool(*) mounted(void *ctx)
Whether a card is mounted.
Definition kst_store.h:159
void * ctx
Definition kst_store.h:155
int32_t(*) size(void *ctx, const char *name)
Size of a file in bytes; -1 when no file has that name.
Definition kst_store.h:171