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
105EMBED_INLINE
size_t protocore_fs_join(
const char *root,
const char *dir,
const char *name,
char *out,
size_t cap)
111 return EMBED_CALL(numer.build, NumerosCfg, .out = out, .cap = cap, .spec = FILESYSTEM_JOIN,
112 .vals = (
const mmgr_fval[]){MMGR_VSTR(root), MMGR_VSTR(dir), MMGR_VSTR(name)}, .nvals = 3);
126 for (
const char *p = s; p[0] !=
'\0' && p[1] !=
'\0'; p++)
128 if (p[0] ==
'.' && p[1] ==
'.')
136EMBED_INLINE
int protocore_fs_resolve(
const char *root,
const char *dir,
const char *name,
char *out,
size_t cap)
148 if (fpl > 1 && out[fpl - 1] ==
'/')
176#define PROTOCORE_FS_OK 0u
177#define PROTOCORE_FS_STORAGE_EXHAUSTED (1u << 0)
178#define PROTOCORE_FS_BAD_ROOT (1u << 1)
179#define PROTOCORE_FS_TRAVERSAL (1u << 2)
180#define PROTOCORE_FS_TOO_LONG (1u << 3)
270 void (*
const open)(uint8_t *work);
271 void (*
const read)(uint8_t *work);
274 void (*
const seek)(uint8_t *work);
275 void (*
const size)(uint8_t *work);
277 void (*
const stat)(uint8_t *work);
280 void (*
const copy)(uint8_t *work);
uint8_t * protocore_filesystem_span(void)
The PROTOCORE_FILESYSTEM_BORROW bytes this module's state lives in.
EMBED_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.
EMBED_INLINE int protocore_fs_resolve(const char *root, const char *dir, const char *name, char *out, size_t cap)
EMBED_INLINE embed_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 ....
FilesystemNs Fs
The one symbol this module exports.
The mount: which store is behind the filesystem, and the vtable it answers through.
void(*const readdir)(uint8_t *work)
void(*const copy)(uint8_t *work)
void(*const open)(uint8_t *work)
void(*const remove)(uint8_t *work)
void(*const opendir)(uint8_t *work)
void(*const size)(uint8_t *work)
void(*const rmdir)(uint8_t *work)
void(*const close)(uint8_t *work)
void(*const begin)(uint8_t *work)
void(*const clear)(uint8_t *work)
void(*const present)(const uint8_t *work)
void(*const exists)(uint8_t *work)
void(*const read_file)(uint8_t *work)
void(*const rename)(uint8_t *work)
void(*const status)(uint8_t *work)
void(*const mkdir)(uint8_t *work)
void(*const resolve)(uint8_t *work)
void(*const write_file)(uint8_t *work)
void(*const seek)(uint8_t *work)
void(*const read)(uint8_t *work)
void(*const stat)(uint8_t *work)
void(*const write)(uint8_t *work)
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.