31#ifndef PROTOCORE_FILESYSTEM_H
32#define PROTOCORE_FILESYSTEM_H
34#include "numeros_scribo/numeros_scribo.h"
45static const mmgr_field FILESYSTEM_JOIN[] = {MMGR_STR, MMGR_STR, MMGR_STR, MMGR_END};
48static const mmgr_field FILESYSTEM_ROOT[] = {MMGR_STR, MMGR_END};
57#ifndef PROTOCORE_FS_MAX_ROOTS
58#define PROTOCORE_FS_MAX_ROOTS 4
62#ifndef PROTOCORE_FS_ROOT_NAME_MAX
63#define PROTOCORE_FS_ROOT_NAME_MAX 24
74#ifndef PROTOCORE_FS_MAX_DEPTH
75#define PROTOCORE_FS_MAX_DEPTH 8
91#ifndef PROTOCORE_FS_BLOCK
92#define PROTOCORE_FS_BLOCK 512
108 return EMBED_CALL(numer.build, NumerosCfg, .out = out, .cap = cap, .spec = FILESYSTEM_JOIN,
109 .vals = (
const mmgr_fval[]){MMGR_VSTR(root), MMGR_VSTR(dir), MMGR_VSTR(name)}, .nvals = 3);
123 for (
const char *p = s; p[0] !=
'\0' && p[1] !=
'\0'; p++)
125 if (p[0] ==
'.' && p[1] ==
'.')
145 if (fpl > 1 && out[fpl - 1] ==
'/')
172#define PROTOCORE_FS_OK 0u
173#define PROTOCORE_FS_STORAGE_EXHAUSTED (1u << 0)
174#define PROTOCORE_FS_BAD_ROOT (1u << 1)
175#define PROTOCORE_FS_TRAVERSAL (1u << 2)
176#define PROTOCORE_FS_TOO_LONG (1u << 3)
261 void (*
const status)(uint8_t *work);
262 void (*
const clear)(uint8_t *work);
263 void (*
const present)(uint8_t *work);
264 void (*
const begin)(uint8_t *work);
265 void (*
const resolve)(uint8_t *work);
266 void (*
const open)(uint8_t *work);
267 void (*
const read)(uint8_t *work);
268 void (*
const write)(uint8_t *work);
269 void (*
const close)(uint8_t *work);
270 void (*
const seek)(uint8_t *work);
271 void (*
const size)(uint8_t *work);
272 void (*
const exists)(uint8_t *work);
273 void (*
const stat)(uint8_t *work);
274 void (*
const remove)(uint8_t *work);
275 void (*
const rename)(uint8_t *work);
276 void (*
const copy)(uint8_t *work);
277 void (*
const mkdir)(uint8_t *work);
278 void (*
const rmdir)(uint8_t *work);
279 void (*
const opendir)(uint8_t *work);
280 void (*
const readdir)(uint8_t *work);
281 void (*
const read_file)(uint8_t *work);
282 void (*
const write_file)(uint8_t *work);
#define PROTOCORE_INLINE
Linkage for a leaf primitive whose body is cheaper than the call that reaches it.
PROTOCORE_INLINE proto_bool protocore_fs_has_dotdot(const char *s)
Resolve a mount root + a request dir + a leaf name to an on-disk path in out: reject any ....
uint8_t * protocore_filesystem_span(void)
The PROTOCORE_FILESYSTEM_BORROW bytes this module's state lives in.
PROTOCORE_INLINE int protocore_fs_resolve(const char *root, const char *dir, const char *name, char *out, size_t cap)
PROTOCORE_INLINE size_t protocore_fs_join(const char *root, const char *dir, const char *name, char *out, size_t cap)
Join a mount root, a request dir, and a leaf name into out.
FilesystemNs Fs
The one symbol this module exports.
The mount: which store is behind the filesystem, and the vtable it answers through.
PROTOCORE_BEGIN_DECLS enum PROTO_ENUM_PACKED protocore_mnt_mode
Open modes.
The second path a rename or a copy needs.
const char * name
the destination entry
const char * dir
the destination directory
The open file a call acts on, and the bytes it moves.
uint64_t off
where a seek moves to
char * name_out
where a directory read writes the entry name
void * buf
where a read lands, or what a write sends
protocore_mnt_mode mode
how an open asks for it
size_t name_cap
how much room that has
int handle
the open file or directory a call acts on
const void * wbuf
the bytes a write sends, when they are const
protocore_mnt_stat * stat
where a stat or a directory read lands its entry
The file one call names: which mount, which directory, which entry.
int root
the mount point the path is resolved against
const char * dir
the directory within it
const char * name
the entry within that
What a stat and a directory entry both answer: the facts about one file, and no name.
#define PROTO_FALSE
the false value
#define PROTOCORE_BEGIN_DECLS
Give a header's declarations C linkage, so their symbol names carry no parameter types.
_Bool proto_bool
The truth value.
#define PROTO_TRUE
the true value, spelled so a caller never writes a bare 1
#define PROTOCORE_END_DECLS