fsqlite-vfs
Virtual filesystem abstraction layer for the fsqlite storage engine. This crate defines the traits and implementations that isolate all file I/O behind a pluggable interface, mirroring SQLite's sqlite3_vfs architecture.
Overview
fsqlite-vfs is the lowest layer in the fsqlite storage stack. Every byte that reaches disk (or memory, or io_uring) passes through the Vfs and VfsFile traits defined here. The pager, WAL, and all higher layers depend on this crate but never call std::fs directly -- an ambient-authority audit gate enforces this boundary.
Position in the dependency graph:
fsqlite-types, fsqlite-error
|
fsqlite-vfs <-- you are here
|
fsqlite-pager
/ \
fsqlite-wal fsqlite-btree
\ /
fsqlite-mvcc
Key Types
Vfs(trait) -- A virtual filesystem implementation. Providesopen,delete,access,full_pathname,randomness, andcurrent_time. Generic over its associatedFiletype.VfsFile(trait) -- A file handle opened by a VFS. Supportsread,write,truncate,sync,file_size, five-level locking (lock/unlock/check_reserved_lock), and shared-memory operations (shm_map,shm_lock,shm_barrier,shm_unmap) required for WAL mode.UnixVfs/UnixFile-- Production VFS for Unix systems using POSIX file I/O andfcntllocking.IoUringVfs/IoUringFile-- Linux-only VFS backed byio_uringfor asynchronous I/O.WindowsVfs/WindowsFile-- Windows VFS using native file APIs and advisory locks.MemoryVfs/MemoryFile-- Fully in-memory VFS for testing. No disk I/O.ShmRegion-- Safe handle for shared-memory regions with bounds-checked accessors.TracingFile/VfsMetrics/GLOBAL_VFS_METRICS-- Instrumentation wrapper that records read/write/sync counts and latencies.host_fs(module) -- Audited helpers (read,write,create_dir_all, etc.) that are the only code permitted to callstd::fsoutside of VFS implementations.
Usage
use ;
use Cx;
use VfsOpenFlags;
let cx = new;
let vfs = new;
// Open a database file in memory.
let flags = READWRITE | CREATE | MAIN_DB;
let = vfs.open.unwrap;
// Write a page.
let page = ;
file.write.unwrap;
// Read it back.
let mut buf = ;
file.read.unwrap;
assert_eq!;
file.close.unwrap;
Dependencies
fsqlite-types-- Shared type definitions (LockLevel,VfsOpenFlags,SyncFlags,Cx).fsqlite-error-- Unified error/result types.nix,libc-- POSIX syscall bindings (Unix builds).asupersync,pollster-- homegrown io_uring runtime integration (Linux builds).advisory-lock-- File locking (Windows builds).
License
MIT