slots

package
v0.3.5 Latest Latest
Warning

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

Go to latest
Published: Jan 14, 2025 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package slots provides a simple "postbox" type filesystem.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BlockReaderWriter

type BlockReaderWriter interface {
	// BlockSize returns the block size of the underlying storage system.
	BlockSize() uint

	// ReadBlocks reads len(b) bytes into b from contiguous storage blocks starting
	// at the given block address.
	// b must be an integer multiple of the device's block size.
	ReadBlocks(lba uint, b []byte) error

	// WriteBlocks writes len(b) bytes from b to contiguous storage blocks starting
	// at the given block address.
	// b must be an integer multiple of the device's block size.
	// Returns the number of blocks written, or an error.
	WriteBlocks(lba uint, b []byte) (uint, error)
}

BlockReaderWriter describes a type which knows how to read and write whole blocks to some backing storage.

type Geometry

type Geometry struct {
	// Start identifies the address of first block which is part of a partition.
	Start uint
	// Length is the number of blocks covered by this partition.
	// i.e. [Start, Start+Length) is the range of blocks covered by this partition.
	Length uint
	// SlotLengths is an ordered list containing the lengths of the slot(s)
	// allocated within this partition.
	// For obvious reasons, great care must be taken if, once data has been written
	// to one or more slots, the values specified in this list at the time the data
	// was written are changed.
	SlotLengths []uint
}

Geometry describes the physical layout of a Partition and its slots on the underlying storage.

func (Geometry) Validate

func (g Geometry) Validate() error

Validate checks that the geometry is self-consistent.

type Journal

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

Journal implements a record-based format which provides a resilient storage. This structure is not thread-safe, so concurrent access must be enforced at a higher level.

func OpenJournal

func OpenJournal(dev BlockReaderWriter, start, length uint) (*Journal, error)

OpenJournal returns a new journal structure for interacting with a journal stored in the [start, start+length) range of blocks accessible via dev. Journal ranges should not overlap with one another, or corruption will almost certainly occur.

func (*Journal) Data

func (j *Journal) Data() ([]byte, uint32)

Data returns the application data from the most recent valid entry in the journal, along with the entry's revision number. If the returned revision is zero, then no successful writes have taken place on this journal.

func (*Journal) Update

func (j *Journal) Update(data []byte) error

Update creates a new entry record in the journal for the provided data. The new record's revision will be one greater than the previous record (or 1 if no previous record exists).

type Partition

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

Partition describes the extent and layout of a single contiguous region of underlying block storage.

func OpenPartition

func OpenPartition(rw BlockReaderWriter, geo Geometry) (*Partition, error)

OpenPartition returns a partition struct for accessing the slots described by the given geometry using the provided read/write methods.

func (*Partition) Erase

func (p *Partition) Erase() error

Erase destroys the data stored in all slots configured in this partition. WARNING: Data Loss!

func (*Partition) NumSlots

func (p *Partition) NumSlots() int

NumSlots returns the number of slots configured in this partition.

func (*Partition) Open

func (p *Partition) Open(slot uint) (*Slot, error)

Open opens the specified slot, returns an error if the slot is out of bounds.

type Slot

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

Slot represents the current data in a slot.

func (*Slot) CheckAndWrite

func (s *Slot) CheckAndWrite(token uint32, p []byte) error

CheckAndWrite behaves like Write, with the exception that it will immediately return an error if the slot has been successfully written to since the Read call which produced the passed-in token.

func (*Slot) Open

func (s *Slot) Open(dev BlockReaderWriter) error

Open prepares the slot for use. This method is idempotent and will not return an error if called multiple times.

func (*Slot) Read

func (s *Slot) Read() ([]byte, uint32, error)

Read returns the last data successfully written to the slot, along with a token which can be used with CheckAndWrite.

func (*Slot) Write

func (s *Slot) Write(p []byte) error

Write writes the provided data to the slot. Upon successful completion, this data will be returned by future calls to Read until another successful Write call is mode. If the call to Write fails, future calls to Read will return the previous successfully written data, if any.

Jump to

Keyboard shortcuts

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