vfs

package
v0.3.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 18, 2026 License: BSD-3-Clause, BSD-3-Clause Imports: 15 Imported by: 0

Documentation

Overview

codec.go — a read-write, os-backed SQLite VFS that encrypts every page with the SQLCipher-4 page format (github.com/hanzoai/sqlcipher), giving the pure-Go engine real at-rest encryption byte-compatible with C SQLCipher.

It is the write side the vendored engine's stock vfs package leaves null (it fills only xRead/xFileSize/xClose (read-only). Here codecio wires xWrite/xTruncate/ xSync too, backed by a real *os.File, and transforms page bytes with the codec on the way through.)

How it stays byte-compatible AND lets the engine's WAL round-trip

SQLCipher's codec is normally a pager hook; here it is a VFS shim UNDER the pager, so the engine computes WAL frame checksums over the PLAINTEXT page, reserve region included. The codec overwrites that reserve with a fresh IV+HMAC on every write, so a naive decrypt would not reproduce the bytes the engine checksummed and WAL recovery would reject every frame. The fix, proven empirically: the engine zeros the full page buffer of NEW pages, and codecRead ZEROS the reserve of every page it returns — so every page the engine ever checksums has a zero reserve, the checksum is always taken over [data‖zeros], and the read-back reproduces it exactly. (the main database file carries no checksums, so zeroing the (pager- ignored) reserve there is invisible and the on-disk ciphertext is byte-identical to what C SQLCipher writes.

Fail-closed

A wrong key or a tampered page fails Decrypt (HMAC) and is returned as an I/O error; plaintext is never produced. Rollback journals are refused (keyed databases run WAL-only); temp spill is kept in memory by the DSN. Plaintext never reaches disk.

Index

Constants

View Source
const (
	SIGEV_SIGNAL = 0
	SIGEV_NONE   = 1
	SIGEV_THREAD = 2

	SIGEV_THREAD_ID = 4
)
View Source
const (
	SEGV_MAPERR  = 1
	SEGV_ACCERR  = 2
	SEGV_BNDERR  = 3
	SEGV_PKUERR  = 4
	SEGV_ACCADI  = 5
	SEGV_ADIDERR = 6
	SEGV_ADIPERR = 7
)
View Source
const (
	BUS_ADRALN    = 1
	BUS_ADRERR    = 2
	BUS_OBJERR    = 3
	BUS_MCEERR_AR = 4
	BUS_MCEERR_AO = 5
)
View Source
const (
	CLD_EXITED    = 1
	CLD_KILLED    = 2
	CLD_DUMPED    = 3
	CLD_TRAPPED   = 4
	CLD_STOPPED   = 5
	CLD_CONTINUED = 6
)
View Source
const (
	POLL_IN  = 1
	POLL_OUT = 2
	POLL_MSG = 3
	POLL_ERR = 4
	POLL_PRI = 5
	POLL_HUP = 6
)
View Source
const (
	SI_ASYNCNL  = -60
	SI_DETHREAD = -7

	SI_TKILL   = -6
	SI_SIGIO   = -5
	SI_ASYNCIO = -4
	SI_MESGQ   = -3
	SI_TIMER   = -2
	SI_QUEUE   = -1
	SI_USER    = 0
	SI_KERNEL  = 128
)
View Source
const (
	ILL_ILLOPC   = 1
	ILL_ILLOPN   = 2
	ILL_ILLADR   = 3
	ILL_ILLTRP   = 4
	ILL_PRVOPC   = 5
	ILL_PRVREG   = 6
	ILL_COPROC   = 7
	ILL_BADSTK   = 8
	ILL_BADIADDR = 9
)
View Source
const (
	FPE_INTDIV   = 1
	FPE_INTOVF   = 2
	FPE_FLTDIV   = 3
	FPE_FLTOVF   = 4
	FPE_FLTUND   = 5
	FPE_FLTRES   = 6
	FPE_FLTINV   = 7
	FPE_FLTSUB   = 8
	FPE_FLTUNK   = 14
	FPE_CONDTRAP = 15
)
View Source
const (
	SS_ONSTACK = 1
	SS_DISABLE = 2
)

Variables

This section is empty.

Functions

func Register

func Register(dek []byte) (name string, closer func() error, err error)

Register creates and registers a VFS bound to dek and returns its name (for `?vfs=<name>`) and a closer that unregisters it and drops the key. dek must be a 32-byte raw SQLCipher key. One instance per open database.

func Xsqlite3_fsFS

func Xsqlite3_fsFS(tls *libc.TLS, zName uintptr, pAppData uintptr) uintptr

Types

type FS

type FS struct {
	// contains filtered or unexported fields
}

FS represents a SQLite read only file system backed by Go's fs.FS.

func New

func New(fs fs.FS) (name string, _ *FS, _ error)

New creates a new sqlite VFS and registers it. If successful, the file system can be used with the URI parameter `?vfs=<returned name>`.

func (*FS) Close

func (f *FS) Close() error

Close unregisters f and releases its resources.

type Fts5ExtensionApi

type Fts5ExtensionApi = Fts5ExtensionApi1

type Fts5ExtensionApi1

type Fts5ExtensionApi1 = struct {
	// contains filtered or unexported fields
}

type Fts5PhraseIter

type Fts5PhraseIter = Fts5PhraseIter1

type Fts5PhraseIter1

type Fts5PhraseIter1 = struct {
	// contains filtered or unexported fields
}

type VFSFile

type VFSFile = VFSFile1

type VFSFile1

type VFSFile1 = struct {
	// contains filtered or unexported fields
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL