skip to content
==> include/mesh/blobs/durable.h <==
1/* @ajax/mesh-blobs-durable: a blob made durable under dir/name (blobs.rs `make_durable`,
2 * `write_durable`, `sync_dir`, `fsync`): written to `name.tmp`, fsynced, renamed, so it is either
3 * whole under its name or absent (a crash leaves at most a .tmp). The rename is durable once the
4 * directory is fsynced, which the caller batches. A job's copy of bytes another job already holds is a
5 * hard link of that file (the bytes are on disk once). fsync(2), not a drive cache flush (macOS's
6 * F_FULLFSYNC): the job log's guarantee too. */
7#ifndef MESH_BLOBS_DURABLE_H
8#define MESH_BLOBS_DURABLE_H
9
10#include <stdbool.h>
11#include <stddef.h>
12
13/* mkdir -p. False with *err. */
14bool mb_mkdirs(const char *dir, char **err);
15/* The bytes under dir/name, durably: written to name.tmp, fsynced, renamed. */
16bool mb_write_durable(const char *dir, const char *name, const void *bytes, size_t n, char **err);
17/* A hard link of `link` (another job's whole file of the same bytes) as dir/name when link is not
18 * NULL, else (or if that file went meanwhile) the bytes written (mb_write_durable). */
19bool mb_make_durable(const char *dir, const char *name, const char *link, const void *bytes, size_t n, char **err);
20/* fsync(2) a directory (its entries: the renames into it). */
21bool mb_sync_dir(const char *dir, char **err);
22/* rm -rf of a directory tree (missing is fine). */
23void mb_remove_tree(const char *dir);
24
25#endif