ProtoCore v1.0.16
Deterministic, zero-heap network stack for embedded targets
Loading...
Searching...
No Matches
wal_fs.h File Reference

Bind the WAL store's ::WalDev block-device seam to a file on a mounted store (PROTOCORE_ENABLE_WAL). More...

#include "protocore_config.h"

Go to the source code of this file.

Detailed Description

Bind the WAL store's ::WalDev block-device seam to a file on a mounted store (PROTOCORE_ENABLE_WAL).

The store in wal_store.h does all I/O through three function pointers so its logic stays pure and host-testable; this header is the thin adapter that points those pointers at a preallocated file on any protocore_mnt_backend. Random access is the backend's seek, and the durability barrier is its sync.

Usage:

protocore_wal_fs_prealloc(store, "/wal.bin", 256 * 1024); // once: fixed-size, zero-filled backing file
protocore_wal_fs_ctx c;
WalDev dev;
if (protocore_wal_fs_open(&c, &dev, store, "/wal.bin", 256 * 1024))
{
WalStore s;
protocore_wal_store_mount(&s, &dev) || protocore_wal_store_format(&s, &dev); // recover, or initialize
}
void protocore_mnt_active(uint8_t *work)
A storage backend. Each open call returns a small handle (>= 0) or -1.
Definition mnt.h:88

The backing file is preallocated to a fixed size so every store offset lands inside it and seek+write overwrites in place, rather than depending on past-EOF behavior that differs between FAT and littlefs. The ::protocore_wal_fs_ctx must outlive any ::WalDev bound to it.

A backend with no sync is refused at open. The WAL's checkpoint is an ordering guarantee built on that barrier, so a store that cannot promise it cannot carry a power-loss-safe log, and saying so at mount is the only honest answer: a barrier that returns true having done nothing makes an unsafe store look safe.

Definition in file wal_fs.h.