Overview / Data & formats

storage

Embedded transactional key-value store with a page-based B+ tree and a full-page WAL. One writer and many readers that never wait for it. It creates no threads and is not SQL.

Always compiled: part of the core build.Include #include <ethereal/cpp/storage/storage_inc.hpp>C layer

storage_inc.hpp

#include <ethereal/cpp/storage/storage_inc.hpp>

Aggregate entry point of the Storage module.

An embedded transactional key-value store (a B+ tree with a WAL) and its I/O seam. The typed layer lives apart, in storage_typed.hpp.

storage.hpp

#include <ethereal/cpp/storage/storage.hpp>

Embedded transactional key-value store. It is not SQL.

A B+ tree over pages, with a write-ahead log (WAL) of whole pages, named tables, ordered iteration, snapshot isolation, one writer and many readers that never wait for it. It is what the TorreSync block index, the Updater queue and the CrashReport queue need, and what would make an integrator reach for SQLite.

What it is not: SQL, a planner, joins, a server, replication, background compaction. No thread is created. The checkpoint, the compaction and the TTL cleanup run when the integrator calls them, or at the end of a Commit.

Keys sort by bytes ('memcmp'). An integer stored little-endian does not sort as a number: 256 comes before 1. Store integers big-endian, with the sign bit flipped when they are signed. Everyone trips on this once. The typed layer (storage_typed.hpp) does the right encoding by itself.

Durability, for the whole module (the README has the protocol):

  • eFull: each Commit returns only after the WAL reaches the disk ('fsync', F_FULLFSYNC on macOS). A committed transaction survives a power failure. This is the default.
  • eBatched: Commit writes the WAL but syncs only when the interval (uBatchIntervalMs) has passed since the last sync. A power failure loses the commits of that interval, and those at the end if the database went quiet: with no thread, nobody syncs on its own, so call Sync or Checkpoint at a pace of your own. The file is never corrupt, it goes back to a prefix of the committed transactions.
  • eNone: syncs only in Checkpoint, Sync and Close. For caches and data that can be rebuilt. Same no corruption guarantee. A process that dies without a power failure loses nothing committed in any of the three: the WAL was already handed to the system.

Concurrency: one writer at a time (a second Begin( eReadWrite ) waits up to uWriteLockTimeoutMs and then returns eBusy). Readers have no limit, each one sees the database as it was when it started, and none waits for a writer. With a single writer a deadlock cannot happen.

Between processes: an exclusive lock on '<path>.lock'. One process at a time opens the database, the second gets eLocked. There are no readers in another process, and it does not work on a network file system (the locks and the 'fsync' there do not give the guarantees this depends on).

enum

EStorageStatus

Ethereal::Storage#
C++
enum class   EStorageStatus : std::uint8_t
{
    /// @brief  Success.
    eOk = 0,

    /// @brief  The key (or the table) does not exist.
    eNotFound,

    /// @brief  The cursor went past the end (or the start).
    eEnd,

    /// @brief  Invalid argument from the caller.
    eInvalidArgument,

    /// @brief  The VFS failed.
    eIo,

    /// @brief  A checksum or a structure does not match. A hard error, never used data.
    eCorrupt,

    /// @brief  Another writer, or there are open transactions for what was asked.
    eBusy,

    /// @brief  The database is open in another process.
    eLocked,

    /// @brief  Write in a read transaction.
    eReadOnly,

    /// @brief  The transaction was already committed or rolled back.
    eTxDone,

    /// @brief  The key is longer than MaxKeySize.
    eKeyTooLarge,

    /// @brief  The value is longer than uMaxValueBytes.
    eValueTooLarge,

    /// @brief  It would go past uMaxDatabaseBytes.
    eDatabaseFull,

    /// @brief  The bounded cache is not enough (transaction too large for it).
    eCacheFull,

    /// @brief  Get reports in *pWritten how much it needed.
    eBufferTooSmall,

    /// @brief  File format this version does not know.
    eVersion,

    /// @brief  A Sync failed before. The database refuses writes until reopened.
    eFailed,

    /// @brief  Operation not supported.
    eUnsupported,

    /// @brief  The ICompressor failed.
    eCompression,

    /// @brief  The page does not decrypt (wrong key, or corruption).
    eCipher,

    /// @brief  Refused: no license was accepted and the evaluation of this machine has
    ///          ended, or the license passed was refused (see Bundle::UnlockBundle).
    eNotLicensed,
};

Result of a Storage operation.

function

StatusName

Ethereal::Storage#
const char * StatusName( EStorageStatus e ) noexcept;

Static name of a result.

enum

EDurability

Ethereal::Storage#
C++
enum class   EDurability : std::uint8_t    { eFull = 0, eBatched, eNone };

Durability of a Commit. See the file description.

enum

ETxMode

Ethereal::Storage#
C++
enum class   ETxMode : std::uint8_t        { eReadOnly = 0, eReadWrite };

Mode of a transaction.

struct

ICompressor

Ethereal::Storage#
C++
struct   ICompressor
{
    /// @brief  Largest compressed size for uRaw input bytes.
    ///
    virtual std::size_t MaxCompressedSize( std::size_t uRaw ) const noexcept = 0;


    /// @brief  Compresses In into Out. false on failure.
    ///
    virtual bool Compress( std::span< const std::uint8_t > In, std::span< std::uint8_t > Out, std::size_t * pWritten ) noexcept = 0;


    /// @brief  Decompresses In into Out. false on failure.
    ///
    virtual bool Decompress( std::span< const std::uint8_t > In, std::span< std::uint8_t > Out, std::size_t * pWritten ) noexcept = 0;


    /// @brief  Destructor.
    ///
    virtual ~ICompressor() = default;
};

Compression of the values above uCompressMinBytes (the Compression glue implements this).

A compressed value cannot be read without a copy: GetRef and the cursor decompress it into memory owned by the transaction.

struct

IPageCipher

Ethereal::Storage#
C++
struct   IPageCipher
{
    /// @brief  Encrypts page uPage from In into Out.
    ///
    virtual void Encrypt( std::uint32_t uPage, std::span< const std::uint8_t > In, std::span< std::uint8_t > Out ) noexcept = 0;


    /// @brief  Decrypts page uPage from In into Out.
    ///
    virtual void Decrypt( std::uint32_t uPage, std::span< const std::uint8_t > In, std::span< std::uint8_t > Out ) noexcept = 0;


    /// @brief  Destructor.
    ///
    virtual ~IPageCipher() = default;
};

Encryption of pages at rest.

It must preserve the size and be tweakable by the page number (like AES-XTS): the number is the tweak. The key belongs to the integrator, never to this module. The file header stays in clear. In and Out may be the same block (the engine decrypts in place).

alias

bool

Ethereal::Storage#
using FIndexExtract = bool ( * )( void * pContext, std::span< const std::uint8_t > Value, std::span< std::uint8_t > KeyOut, std::size_t * pKeyLen ) noexcept;

Extracts the key of a secondary index from a value.

Returns false when the value does not enter the index. pKeyLen receives the length (up to KeyOut.size()).

struct

SIndexDef

Ethereal::Storage#
C++
struct   SIndexDef
{
    /// @brief  Table the index belongs to.
    std::string_view    sTable;

    /// @brief  Name of the index.
    std::string_view    sName;

    /// @brief  Extracts the index key from a value.
    FIndexExtract        pExtract = nullptr;

    /// @brief  Context passed to pExtract.
    void *                pContext = nullptr;
};

A secondary index, kept in the same transaction as its table.

struct

SOpenOptions

Ethereal::Storage#
C++
struct   SOpenOptions
{
    /// @brief  Size of this struct, checked by Open.
    std::uint32_t        uStructSize = sizeof( SOpenOptions );

    /// @brief  File system. Null uses OsVfs().
    IStorageVfs *        pVfs = nullptr;

    /// @brief  Creates the database when it does not exist.
    bool                bCreate = true;

    /// @brief  Page size, only on creation: a power of 2 from 4096 to 65536.
    std::uint32_t        uPageSize = 16384;

    /// @brief  Cache ceiling (clean and dirty pages).
    std::size_t            uCacheBytes = 64u << 20;

    /// @brief  Durability of each Commit.
    EDurability            eDurability = EDurability::eFull;

    /// @brief  Sync interval, only for eBatched.
    std::uint32_t        uBatchIntervalMs = 100;

    /// @brief  Checkpoint at the end of a Commit after this many WAL frames. 0 = manual only.
    std::uint32_t        uAutoCheckpointFrames = 2000;

    /// @brief  0 = only the format limit (2^32 pages).
    std::uint64_t        uMaxDatabaseBytes = 0;

    /// @brief  Up to 1 GiB, and never more than half the cache (the whole value goes through it).
    std::uint32_t        uMaxValueBytes = 16u << 20;

    /// @brief  How long a second writer waits for the lock before eBusy.
    std::uint32_t        uWriteLockTimeoutMs = 10000;

    /// @brief  Value compressor. Null disables compression.
    ICompressor *        pCompressor = nullptr;

    /// @brief  Values below this size are not compressed.
    std::uint32_t        uCompressMinBytes = 1024;

    /// @brief  Page cipher. Null keeps the pages in clear.
    IPageCipher *        pCipher = nullptr;

    /// @brief  Wall clock of the TTL. Null uses the system clock.
    Time::IClock *        pClock = nullptr;

    /// @brief  Secondary indexes.
    const SIndexDef *    pIndexes = nullptr;

    /// @brief  Number of entries in pIndexes.
    std::size_t            uIndexCount = 0;
};

Options of CDatabase::Open.

struct

SPutOptions

Ethereal::Storage#
C++
struct   SPutOptions
{
    /// @brief  Time to live. 0 keeps the key forever.
    Time::SDuration        Ttl{};

    /// @brief  Stores the value uncompressed even with a compressor.
    bool                bNoCompress = false;
};

Options of CTransaction::Put.

struct

SDbStats

Ethereal::Storage#
C++
struct   SDbStats
{
    /// @brief  Page size, in bytes.
    std::uint32_t        uPageSize = 0;

    /// @brief  Depth of the tree.
    std::uint32_t        uTreeDepth = 0;

    /// @brief  Pages in the database.
    std::uint64_t        uPageCount = 0;

    /// @brief  Pages in the free list.
    std::uint64_t        uFreePages = 0;

    /// @brief  Committed frames in the WAL.
    std::uint64_t        uWalFrames = 0;

    /// @brief  Bytes in the cache now.
    std::uint64_t        uCacheBytes = 0;

    /// @brief  Highest value ever reached by uCacheBytes.
    std::uint64_t        uCacheBytesMax = 0;

    /// @brief  Cache hits.
    std::uint64_t        uCacheHits = 0;

    /// @brief  Cache misses.
    std::uint64_t        uCacheMisses = 0;

    /// @brief  Commits that wrote something.
    std::uint64_t        uCommits = 0;

    /// @brief  Checkpoints.
    std::uint64_t        uCheckpoints = 0;

    /// @brief  WAL syncs.
    std::uint64_t        uSyncs = 0;

    /// @brief  Bytes copied by Get and by compressed values.
    std::uint64_t        uValueBytesCopied = 0;

    /// @brief  Open read transactions.
    std::uint64_t        uActiveReaders = 0;
};

Statistics of an open database.

struct

SVerifyReport

Ethereal::Storage#
C++
struct   SVerifyReport
{
    /// @brief  true when the whole database checked out.
    bool                bOk = false;

    /// @brief  Pages read and checked.
    std::uint64_t        uPagesChecked = 0;

    /// @brief  Entries in the tree.
    std::uint64_t        uEntries = 0;

    /// @brief  Pages in the free list.
    std::uint64_t        uFreePages = 0;

    /// @brief  Pages neither in the tree nor free (only space, not corruption).
    std::uint64_t        uLeakedPages = 0;

    /// @brief  Page of the first problem found.
    std::uint32_t        uBadPage = 0;

    /// @brief  Text of the first problem found.
    char                sError[ 160 ] = {};
};

Result of CDatabase::Verify.

class

CCursor

Ethereal::Storage#

A cursor over a table (or over an index). It does not outlive the transaction.

class CCursor

What Current returns points to the page in the cache (no copy) and is valid until the cursor moves or dies. This is shorter than GetRef (valid for the whole transaction) on purpose: a scan that held every page it went through would break the cache ceiling.

constructor

CCursor

#
CCursor() noexcept = default;

Empty cursor. Filled by CTransaction::Cursor or IndexCursor.

constructor

CCursor

#
CCursor( CCursor && o ) noexcept;

Move constructor.

operator

operator=

#
CCursor & operator=( CCursor && o ) noexcept;

Move assignment.

function

SeekFirst

#
EStorageStatus SeekFirst() noexcept;

Goes to the first entry of the table.

function

SeekLast

#
EStorageStatus SeekLast() noexcept;

Goes to the last entry of the table.

function

Seek

#
EStorageStatus Seek( std::span< const std::uint8_t > Key ) noexcept;

Goes to the first key >= Key.

function

SeekPrefix

#
EStorageStatus SeekPrefix( std::span< const std::uint8_t > Prefix ) noexcept;

Limits the cursor to the keys that start with Prefix, and goes to the first.

The limit holds for Next and Prev. SeekFirst, SeekLast and Seek remove it.

function

Next

#
EStorageStatus Next() noexcept;

Goes to the next entry.

function

Prev

#
EStorageStatus Prev() noexcept;

Goes to the previous entry.

function

Current

#
EStorageStatus Current( std::span< const std::uint8_t > * pKey, std::span< const std::uint8_t > * pValue ) noexcept;

The key and the value under the cursor.

On an index cursor these are the primary key and value.

pKey
Receives the key.
pValue
Receives the value.
eOk, or eEnd when the cursor is not on an entry.
class

CTransaction

Ethereal::Storage#

A transaction: the only access path.

class CTransaction

The destructor always rolls back what was not committed, also when an exception crosses the scope.

constructor

CTransaction

#
CTransaction() noexcept = default;

Inactive transaction. Filled by CDatabase::Begin.

constructor

CTransaction

#
CTransaction( CTransaction && o ) noexcept;

Move constructor.

operator

operator=

#
CTransaction & operator=( CTransaction && o ) noexcept;

Move assignment. Rolls back the current transaction first.

function

Get

#
EStorageStatus Get( std::string_view sTable, std::span< const std::uint8_t > Key, std::span< std::uint8_t > Out, std::size_t * pWritten ) noexcept;

Copies the value into Out.

sTable
Table name.
Key
Key.
Out
Destination buffer.
pWritten
Receives the value size. With eBufferTooSmall, the size needed.
eOk, eNotFound, eBufferTooSmall or an error.
function

GetRef

#
EStorageStatus GetRef( std::string_view sTable, std::span< const std::uint8_t > Key, std::span< const std::uint8_t > * pOut ) noexcept;

The value without a copy: a pointer to the page in the cache, valid until the end of this transaction.

A compressed value is decompressed once into memory of the transaction. There is a copy then, and it counts in uValueBytesCopied.

sTable
Table name.
Key
Key.
pOut
Receives the value.
eOk, eNotFound or an error.
function

Put

#
EStorageStatus Put( std::string_view sTable, std::span< const std::uint8_t > Key, std::span< const std::uint8_t > Value, const SPutOptions & Options = SPutOptions{} ) noexcept;

Writes or replaces a value. Creates the table on first use.

sTable
Table name.
Key
Key.
Value
Value.
Options
TTL and compression.
eOk or an error.
function

Delete

#
EStorageStatus Delete( std::string_view sTable, std::span< const std::uint8_t > Key ) noexcept;

Deletes a key. eNotFound when it did not exist.

function

Cursor

#
EStorageStatus Cursor( std::string_view sTable, CCursor * pOut ) noexcept;

Opens a cursor over a table, in key order.

function

IndexCursor

#
EStorageStatus IndexCursor( std::string_view sTable, std::string_view sIndex, CCursor * pOut ) noexcept;

A cursor over the keys of a secondary index.

The order is the order of the index, and Current returns the primary key and value.

sTable
Table name.
sIndex
Index name.
pOut
Receives the cursor.
eOk, eNotFound or an error.
function

Commit

#
EStorageStatus Commit() noexcept;

Commits the transaction.

function

Rollback

#
void Rollback() noexcept;

Rolls back the transaction. Does nothing when it is inactive.

function

IsActive

#
bool IsActive() const noexcept

true while the transaction is open.

class

CDatabase

Ethereal::Storage#

A database: one file, its WAL and its lock.

class CDatabase
constructor

CDatabase

#
CDatabase() noexcept = default;

Closed database. Filled by Open.

function

Open

#
static EStorageStatus Open( std::string_view sPath, const SOpenOptions & Options, CDatabase * pOut ) noexcept;

Opens (or creates) and recovers.

Rereads the WAL since the last checkpoint, drops the incomplete record at the end and checks. It gives either a consistent database or a clean error, never a tree corrupted in silence.

sPath
Database path.
Options
Open options.
pOut
Receives the open database. Must be closed.
eOk or an error. Opens without a license too: the database can always be read, and only a write transaction is refused (see Begin).
function

Close

#
EStorageStatus Close() noexcept;

Closes the database. eBusy when there are open transactions.

function

Begin

#
EStorageStatus Begin( ETxMode eMode, CTransaction * pOut ) noexcept;

Begins a transaction in eMode.

eOk or an error. A read-write transaction returns eNotLicensed when the library is not licensed (see Bundle::UnlockBundle). Read-only transactions always work, so the data stays readable.
function

Checkpoint

#
EStorageStatus Checkpoint() noexcept;

Copies the WAL pages into the main file, and restarts the WAL when no reader is using it. Also removes the keys with an expired TTL.

function

Sync

#
EStorageStatus Sync() noexcept;

Makes durable everything committed (for eBatched and eNone).

function

Compact

#
EStorageStatus Compact() noexcept;

Rewrites the database with only the live pages and gives the space back to the system.

Explicit, never in the background. eBusy when there are open transactions.

function

Backup

#
EStorageStatus Backup( std::string_view sPath ) noexcept;

Consistent copy to sPath, while writes go on.

function

Verify

#
EStorageStatus Verify( SVerifyReport * pOut ) noexcept;

Checks the whole database: checksums, order, bounds, pages.

function

Stats

#
EStorageStatus Stats( SDbStats * pOut ) noexcept;

Fills the statistics.

function

MaxKeySize

#
std::size_t MaxKeySize() const noexcept;

Largest user key size (depends on the page size).

function

IsOpen

#
bool IsOpen() const noexcept

true while the database is open.

storage_typed.hpp

#include <ethereal/cpp/storage/storage_typed.hpp>

Typed records over the Storage core: a described struct is a table.

A layer on top of the core. The core does not know it exists.

struct SUser { std::uint64_t uId; std::string sName; std::int32_t iAge; }; ETL_META_DESCRIBE( SUser, ETL_META_FIELD( uId, Storage::Key() ), ETL_META_FIELD( sName ), ETL_META_FIELD( iAge ) );

Storage::TTable< SUser > Users( "users" ); Users.Put( Tx, SUser{ 42, "Ana", 31 } ); SUser U; Users.Get( Tx, std::uint64_t( 42 ), &U );

The key sorts like the value by itself: integers big-endian with the sign flipped (-1 before 0, 255 before 256), floats in the IEEE total order, text by its bytes. It is the trap the core warns about, done right once here.

The value carries the other fields in the order of the description: numbers little-endian with a fixed width, text with its length in front. Supported fields: integers, bool, enums, floats, std::string and std::string_view. A std::string_view that was read points to the page (no copy) and is valid while the transaction lasts.

This layer allocates (it builds the key and the value in a std::vector). The core does not.

struct

Key

Ethereal::Storage#
C++
struct   Key : Meta::SAttribute
{
};

Attribute that marks the key field (exactly one per struct).

class

TTable

Ethereal::Storage#
template < typename T > class TTable
constructor

TTable

#
explicit TTable( const std::string_view sTable ) : m_sTable( sTable )

Binds the layer to the table sTable.

function

Put

#
EStorageStatus Put( CTransaction & Tx, const T & Obj, const SPutOptions & O = SPutOptions{} ) const

Writes (or replaces) the record under its key.

Tx
Write transaction.
Obj
The record.
O
TTL and compression.
The result of CTransaction::Put.
function

Get

#
template < typename TKey > EStorageStatus Get( CTransaction & Tx, const TKey & KeyValue, T * pOut ) const

Reads the record of a key.

Tx
Transaction.
KeyValue
The key, of the type of the key field.
pOut
Receives the record.
eOk, eNotFound, eCorrupt or an error.
function

Delete

#
template < typename TKey > EStorageStatus Delete( CTransaction & Tx, const TKey & KeyValue ) const

Deletes the record of a key. eNotFound when it did not exist.

function

Cursor

#
EStorageStatus Cursor( CTransaction & Tx, CCursor * pOut ) const

A cursor over the table, in key order. Decode reads each entry.

function

Decode

#
static EStorageStatus Decode( const std::span< const std::uint8_t > KeyBytes, const std::span< const std::uint8_t > ValueBytes, T * pOut )

A record from the raw key and value (of a cursor).

KeyBytes
Raw key.
ValueBytes
Raw value.
pOut
Receives the record.
eOk, or eCorrupt when the bytes do not match the type.
function

EncodeKey

#
template < typename TKey > static std::vector< std::uint8_t > EncodeKey( const TKey & KeyValue )

The encoded key of a value (for CCursor::Seek).

storage_vfs.hpp

#include <ethereal/cpp/storage/storage_vfs.hpp>

I/O seam of the Storage module.

Every byte the engine reads or writes goes through here. The engine never calls the operating system directly, it calls an IStorageVfs. The normal implementation (OsVfs) is the real file system. The test suite uses another one, in memory, that models what a disk does on a power failure (writes that are lost, that land half way, or out of order) and "kills" the process at any write boundary. That is why the engine reads through a cache of its own and not through 'mmap': a mapping cannot be interleaved that way.

The contract the engine assumes, which an alternative VFS must honor:

  • Write may stay in system memory. Only Sync makes it durable. Between two Syncs, writes may land in any order, or half way.
  • Sync is a barrier: what was written before it is on disk when it returns. On macOS this is F_FULLFSYNC (the 'fsync' there does not reach the disk).
  • Creating, deleting or renaming a file is durable only after SyncDir on the folder. Without it a new file can vanish on a power failure even with its content synced. On Windows this is a no-op: NTFS logs the metadata in its journal, and Windows does not allow syncing a folder.
  • A failed Sync leaves the state unknown. The engine then refuses writes until it is reopened (the lesson of the PostgreSQL "fsyncgate").
enum

EVfsStatus

Ethereal::Storage#
C++
enum class   EVfsStatus : std::uint8_t
{
    /// @brief  Success.
    eOk = 0,

    /// @brief  The file does not exist.
    eNotFound,

    /// @brief  Exclusive creation of a file that already exists.
    eExists,

    /// @brief  The lock is held by another process.
    eLocked,

    /// @brief  Any other failure.
    eIo,
};

Result of an I/O operation (a subset of the engine status).

struct

IStorageFile

Ethereal::Storage#
C++
struct   IStorageFile
{
    ///
    /// Read
    ///
    /// @brief  Reads up to uSize bytes starting at uOffset.
    ///
    /// @details  Near the end it reads less.
    ///
    /// @param uOffset        Offset in the file.
    /// @param pDst            Destination buffer.
    /// @param uSize        Bytes to read.
    /// @param pRead        Receives how many were read (0 past the end).
    ///
    /// @return  eOk or eIo.
    ///
    virtual EVfsStatus Read( std::uint64_t uOffset, void * pDst, std::size_t uSize, std::size_t * pRead ) noexcept = 0;


    ///
    /// Write
    ///
    /// @brief  Writes everything or fails. May stay in memory until Sync.
    ///
    /// @param uOffset        Offset in the file.
    /// @param pSrc            Source buffer.
    /// @param uSize        Bytes to write.
    ///
    /// @return  eOk or eIo.
    ///
    virtual EVfsStatus Write( std::uint64_t uOffset, const void * pSrc, std::size_t uSize ) noexcept = 0;


    /// @brief  Durability barrier.
    ///
    virtual EVfsStatus Sync() noexcept = 0;


    /// @brief  Current size of the file, in bytes.
    ///
    virtual EVfsStatus Size( std::uint64_t * pSize ) noexcept = 0;


    /// @brief  Cuts or extends the file to uSize bytes.
    ///
    virtual EVfsStatus Truncate( std::uint64_t uSize ) noexcept = 0;


    /// @brief  Closes the file.
    ///
    virtual ~IStorageFile() = default;
};

An open file. Owned by whoever opened it (std::unique_ptr).

struct

IStorageLock

Ethereal::Storage#
C++
struct   IStorageLock
{
    /// @brief  Releases the lock.
    ///
    virtual ~IStorageLock() = default;
};

An exclusive lock between processes, released by the destructor.

struct

IStorageVfs

Ethereal::Storage#
C++
struct   IStorageVfs
{
    ///
    /// Open
    ///
    /// @brief  Opens a file for reading and writing.
    ///
    /// @param sPath        File path.
    /// @param bCreate        Creates the file when it does not exist.
    /// @param bExclusive    Fails with eExists when the file already exists.
    /// @param pOut            Receives the open file.
    ///
    /// @return  eOk, eNotFound, eExists or eIo.
    ///
    virtual EVfsStatus Open( std::string_view sPath, bool bCreate, bool bExclusive,
                             std::unique_ptr< IStorageFile > * pOut ) noexcept = 0;


    /// @brief  Tells whether sPath exists.
    ///
    virtual EVfsStatus Exists( std::string_view sPath, bool * pExists ) noexcept = 0;


    /// @brief  Deletes the file. eNotFound when it does not exist.
    ///
    virtual EVfsStatus Delete( std::string_view sPath ) noexcept = 0;


    ///
    /// Rename
    ///
    /// @brief  Replaces sTo with sFrom atomically (the POSIX 'rename').
    ///
    /// @param sFrom    Current path.
    /// @param sTo        New path. Replaced when it exists.
    ///
    /// @return  eOk or eIo.
    ///
    virtual EVfsStatus Rename( std::string_view sFrom, std::string_view sTo ) noexcept = 0;


    /// @brief  Makes durable the entries of the folder that holds sPath.
    ///
    virtual EVfsStatus SyncDir( std::string_view sPath ) noexcept = 0;


    ///
    /// LockExclusive
    ///
    /// @brief  Takes an exclusive lock between processes, on an auxiliary file.
    ///
    /// @param sPath    Path of the lock file.
    /// @param pOut        Receives the lock. Released when destroyed.
    ///
    /// @return  eOk, eLocked or eIo.
    ///
    virtual EVfsStatus LockExclusive( std::string_view sPath, std::unique_ptr< IStorageLock > * pOut ) noexcept = 0;


    /// @brief  Destructor.
    ///
    virtual ~IStorageVfs() = default;
};

The file system.

function

OsVfs

Ethereal::Storage#
IStorageVfs & OsVfs() noexcept;

The real file system (POSIX or Windows). Stateless, lives forever.