27#ifndef PROTOCORE_WAL_FS_H
28#define PROTOCORE_WAL_FS_H
32#if PC_ENABLE_WAL && defined(ARDUINO)
38namespace pc_wal_fs_detail
40inline size_t fs_read(
void *ctx, uint64_t off, uint8_t *buf,
size_t len)
42 fs::File *f = (fs::File *)ctx;
43 if (!f->seek((uint32_t)off))
47 return f->read(buf, len);
49inline size_t fs_write(
void *ctx, uint64_t off,
const uint8_t *buf,
size_t len)
51 fs::File *f = (fs::File *)ctx;
52 if (!f->seek((uint32_t)off))
56 return f->write(buf, len);
58inline bool fs_sync(
void *ctx)
60 ((fs::File *)ctx)->flush();
69inline bool pc_wal_fs_prealloc(fs::FS &fsys,
const char *path, uint64_t size)
71 if (fsys.exists(path))
73 fs::File ex = fsys.open(path,
"r");
74 uint64_t have = ex ? (uint64_t)ex.size() : 0;
84 fs::File f = fsys.open(path,
"w");
90 memset(z, 0,
sizeof(z));
95 size_t n = left <
sizeof(z) ? (
size_t)left :
sizeof(z);
96 if (f.write(z, n) != n)
112inline WalDev pc_wal_fs_dev(fs::File *f, uint64_t size)
115 d.read = pc_wal_fs_detail::fs_read;
116 d.write = pc_wal_fs_detail::fs_write;
117 d.sync = pc_wal_fs_detail::fs_sync;
User-facing configuration for ProtoCore.