34#ifndef PROTOCORE_WAL_FS_H
35#define PROTOCORE_WAL_FS_H
39#if PROTOCORE_ENABLE_WAL
43#include "memoria_operor/memoria_operor.h"
52} protocore_wal_fs_ctx;
54PROTOCORE_INLINE size_t protocore_wal_fs_read(
void *ctx, uint64_t off, uint8_t *buf,
size_t len)
56 protocore_wal_fs_ctx *c = (protocore_wal_fs_ctx *)ctx;
57 if (!c->fs->seek(c->handle, off))
61 int n = c->fs->
read(c->handle, buf, len);
62 return n < 0 ? 0 : (size_t)n;
65PROTOCORE_INLINE size_t protocore_wal_fs_write(
void *ctx, uint64_t off,
const uint8_t *buf,
size_t len)
67 protocore_wal_fs_ctx *c = (protocore_wal_fs_ctx *)ctx;
68 if (!c->fs->seek(c->handle, off))
72 int n = c->fs->write(c->handle, buf, len);
73 return n < 0 ? 0 : (size_t)n;
78 protocore_wal_fs_ctx *c = (protocore_wal_fs_ctx *)ctx;
79 return c->fs->sync(c->handle);
92 if (fs->
exists(path) && fs->
size(path) >= 0 && (uint64_t)fs->
size(path) >= size)
102 EMBED_CALL(memor.set, MemoriaCfg, .dst = z, .val = 0, .bytes =
sizeof z);
103 uint64_t left = size;
107 size_t n = left <
sizeof z ? (size_t)left : sizeof z;
108 if (fs->
write(h, z, n) != (
int)n)
132 const char *path, uint64_t size)
134 if (!c || !dev || !fs || !path || !fs->
sync)
145 dev->
read = protocore_wal_fs_read;
146 dev->write = protocore_wal_fs_write;
147 dev->sync = protocore_wal_fs_sync;
158 c->fs->close(c->handle);
#define PROTOCORE_INLINE
Linkage for a leaf primitive whose body is cheaper than the call that reaches it.
The mount: which store is behind the filesystem, and the vtable it answers through.
@ PROTOCORE_MNT_WRITE
Create/truncate for writing.
@ PROTOCORE_MNT_RDWR
Open existing for random read+write, no truncation (fails if absent).
A storage backend. Each open call returns a small handle (>= 0) or -1.
long(* size)(const char *path)
file size, or -1 if absent.
proto_bool(* exists)(const char *path)
true if the path exists.
int(* open)(const char *path, int mode)
-> handle (>=0) or -1.
int(* write)(int handle, const void *buf, size_t n)
bytes written, or -1.
void(* close)(int handle)
release a file OR directory handle.
proto_bool(* sync)(int handle)
Push everything written to handle past the backend's own buffering, and report whether it got there....
int(* read)(int handle, void *buf, size_t n)
bytes read, or -1.
#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