std1.0.0-beta-7 SafeC docs

Module fs::vfs

#include <std/fs/vfs.h> source

Virtual Filesystem (VFS) Layer Minimal inode-based VFS with driver registration. Freestanding-safe.

A filesystem driver is a context struct with methods; the traits below name them. Vfs::mount / mount_ro build the VfsOps table from those methods at compile time (one thunk per method, instantiated for the driver's type), so a driver writes no function table of its own:

FsRead      open, read, readdir                  FatCtx, Ext2Ctx
FsWrite     write, unlink, mkdir
FileSystem  FsRead + FsWrite                     TmpfsCtx

struct TmpfsCtx tmp; tmp.init();
vfs_init();
vfs_root.mount("/tmp", &tmp);       // read-write: needs a FileSystem
vfs_root.mount_ro("/sd", &fat);     // read-only: any FsRead

Paths a driver sees are relative to its mountpoint ("/" for the root). A driver need not set VfsNode.fs_ctx: the VFS fills it in.

Structs

VfsNode
VfsOpsThe mounted driver's entry points, type-erased so one Vfs holds drivers of different context types. Built by Vfs::mount / mount_ro; a null entry (a read-only mount's write/unlink/mkdir) makes that call fail. (See std/erased.h: ctx is the driver's &F.)
VfsMount
Vfs

Traits

FsRead
FsWrite
FileSystem

Functions

vfs_init

Macros

VFS_MAX_MOUNTS
VFS_MAX_PATH
VFS_MAX_NAME
VFS_TYPE_FILENode types
VFS_TYPE_DIR
VFS_O_READOpen flags
VFS_O_WRITE
VFS_O_CREATE
VFS_O_TRUNC
VFS_SEEK_SETSeek origins
VFS_SEEK_CUR
VFS_SEEK_END

Globals

vfs_rootGlobal VFS instance (single-root for embedded use).