powerloss

package
v0.1.7 Latest Latest
Warning

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

Go to latest
Published: Nov 19, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package powerloss builds the files a power loss could leave in a directory, for the tests that play one. A Disk follows what a program does to the files of the directory, one call for each change, in the order the program made them. Crash then gives files a power loss at that moment could leave: what was synced is there, and of what was not, any part.

Index

Constants

View Source
const (
	None  = iota // none of it arrived
	All          // all of it did, as when the process is killed
	First        // what was done before some moment did
	Some         // any part: of each write all its sectors, none, the first ones or any of them
	Kinds
)

How a power loss treats what was not synced.

View Source
const NoDirSync = runtime.GOOS == "windows"

NoDirSync says the system has no directory to sync (Windows). A file made, deleted or renamed then counts as on disk at once: the tests check the syncs of the files there, not what the file system does with names.

Variables

View Source
var KindNames = [...]string{"nothing unsynced arrived", "all arrived", "the first part arrived", "some writes arrived"}

KindNames says each kind in words.

Functions

This section is empty.

Types

type Disk

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

Disk is the files of one directory, and the ones it held when it was last synced.

func Empty

func Empty() *Disk

Empty is the disk of a directory with no file.

func Start

func Start(dir string) (*Disk, error)

Start is the disk before the program runs: the files of dir, all of them synced. The directories in dir are left out.

func (*Disk) Apply

func (d *Disk) Apply(seq int, c vfs.Change) (err error)

Apply does c, a change the VFS told of (vfs.SetTrace), to the file of that name. seq is the place of c in the log. The VFS tells of no directory sync where the system has none (NoDirSync).

func (*Disk) Crash

func (d *Disk) Crash(kind int, garbage bool, rng *rand.Rand) map[string][]byte

Crash gives the files a power loss now could leave, by name. kind says what arrived of what was not synced. With garbage, where a write that makes a file longer did not arrive, the file may be longer all the same and hold anything there: SQLite assumes a file system may set the size of a file before it writes the data.

func (*Disk) Create

func (d *Disk) Create(name string)

Create makes the file name, empty, when it is not there.

func (*Disk) Delete

func (d *Disk) Delete(name string) error

Delete deletes the file name.

func (*Disk) Rename

func (d *Disk) Rename(from, to string) error

Rename gives the file from the name to, in place of the file that had it.

func (*Disk) Sync

func (d *Disk) Sync(name string) error

Sync syncs the file name: what was done to it is on disk.

func (*Disk) SyncDir

func (d *Disk) SyncDir()

SyncDir syncs the directory: its names are on disk.

func (*Disk) Truncate

func (d *Disk) Truncate(seq int, name string, size int64) error

Truncate sets the size of the file name. seq is as for Write.

func (*Disk) Write

func (d *Disk) Write(seq int, name string, off int64, data []byte) error

Write writes data at off of the file name. seq is the place of the write among the changes of the directory, for First.

Jump to

Keyboard shortcuts

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