volume

package
v0.2.9 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SourceSize

func SourceSize(f *os.File) (int64, error)

SourceSize sizes an opened capture source; Seek(END) covers regular files and Unix block devices alike. See sourcesize_windows.go for why this is the ONE shared derivation (#309).

func VolumeSize

func VolumeSize(_ string) (int64, error)

VolumeSize is a no-op on non-Windows platforms.

Types

type Disk added in v0.2.8

type Disk struct {
	Path  string `json:"path"`
	Bytes int64  `json:"bytes"`
	// Serial and Removable as the OS reports them: the storage descriptor
	// on Windows (a USB, SD or MMC bus counts as removable whatever the
	// media bit says), sysfs on Linux (the removable flag, or a device
	// path through a USB controller), diskutil on macOS.
	Serial    string `json:"serial,omitempty"`
	Removable bool   `json:"removable"`
}

Disk is a physical disk in capture form: \\.\PhysicalDriveN on Windows, /dev/sdX or /dev/nvme0n1 on Linux, /dev/diskN on macOS.

type Enumerator added in v0.2.8

type Enumerator struct {
	// Linux: the mount table (/proc/self/mounts), the mountinfo table
	// (/proc/self/mountinfo), the sysfs block tree (/sys/block) and the
	// directory device nodes live in (/dev). Empty = the real ones.
	Mounts, Mountinfo, SysBlock, DevRoot string
	// Diskutil runs macOS's diskutil with args; nil = exec it.
	Diskutil func(args ...string) ([]byte, error)
}

Enumerator reads the machine. The zero value reads the real OS; the fields are the seams tests feed fixtures through.

func DefaultEnumerator added in v0.2.8

func DefaultEnumerator() Enumerator

DefaultEnumerator honors the fixture environment the product's tests use: DISKNEXUS_SYS_BLOCK, DISKNEXUS_PROC_MOUNTS, DISKNEXUS_DEV_ROOT.

func (Enumerator) Disks added in v0.2.8

func (e Enumerator) Disks() ([]Disk, error)

Disks lists the physical disks a capture can name. Loop, RAM and zram devices are not disks.

func (Enumerator) SystemDisk added in v0.2.8

func (e Enumerator) SystemDisk() (string, error)

SystemDisk is the disk the running OS boots from, in Disk.Path form; an error when it cannot be resolved.

func (Enumerator) Volumes added in v0.2.8

func (e Enumerator) Volumes() ([]VolumeInfo, error)

Volumes lists the filesystems the OS knows, mounted or not where the OS can say. A volume the OS lists but cannot describe is still returned; the caller decides what an unreadable one means.

type ExcludedReader

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

ExcludedReader wraps a reader and zeros out excluded regions.

func NewExcludedReader

func NewExcludedReader(r io.Reader, exclusions *ExclusionMap) *ExcludedReader

NewExcludedReader wraps a reader with an exclusion map.

func NewExcludedReaderAt

func NewExcludedReaderAt(r io.Reader, exclusions *ExclusionMap, startOffset int64) *ExcludedReader

NewExcludedReaderAt wraps a reader whose next byte is at startOffset on the source volume. Used to resume a volatile-exclusion backup (#54): the inner reader has been seeked to the resume offset, so the exclusion bookkeeping must start there rather than at 0.

func (*ExcludedReader) Read

func (r *ExcludedReader) Read(p []byte) (int, error)

Read reads from the inner reader, zeroing excluded regions.

type ExclusionMap

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

ExclusionMap marks byte ranges to skip (write as zeros). Used for volatile files like pagefile.sys.

func NewExclusionMap

func NewExclusionMap() *ExclusionMap

NewExclusionMap creates an empty exclusion map.

func (*ExclusionMap) AddRange

func (m *ExclusionMap) AddRange(start, length int64)

AddRange marks a byte range as excluded.

func (*ExclusionMap) CoveredBytes

func (m *ExclusionMap) CoveredBytes() int64

CoveredBytes is the number of distinct bytes the map excludes — overlaps between passes (volatile, subtree, live-extent) counted once. It is what an operator-facing "excluding X (N MB)" line reports (#468).

func (*ExclusionMap) IsExcluded

func (m *ExclusionMap) IsExcluded(offset, length int64) bool

IsExcluded returns true if any byte in the range [offset, offset+length) is excluded. Binary search over the sorted ranges: catalog marking (#94) calls this once per extent across whole-volume catalogs, where a linear scan of a large repo-subtree map would be O(files × ranges).

func (*ExclusionMap) Len

func (m *ExclusionMap) Len() int

Len returns the number of excluded ranges.

func (*ExclusionMap) ZeroExcluded

func (m *ExclusionMap) ZeroExcluded(p []byte, bufStart int64)

ZeroExcluded zeros the bytes of p that fall in an excluded range, where p represents the source bytes starting at bufStart. This is the same masking ExcludedReader applies to the stream, exposed so the resume boundary probe can reproduce the exact bytes the pipeline hashed (#54).

type Reader

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

Reader provides sequential reading of a volume or file for the backup pipeline.

func NewReader

func NewReader(path string, bufferSize int) (*Reader, error)

NewReader opens a volume device path or file for reading. bufferSize controls the read chunk size (default 1 MB).

func (*Reader) Close

func (r *Reader) Close() error

Close closes the underlying file.

func (*Reader) Offset

func (r *Reader) Offset() int64

Offset returns the current read position.

func (*Reader) Read

func (r *Reader) Read(p []byte) (int, error)

Read implements io.Reader.

func (*Reader) SeekTo

func (r *Reader) SeekTo(off int64) error

SeekTo repositions the reader so the next Read returns the byte at off. It is used to resume an interrupted backup from a checkpoint offset (#42). For a buffered file it is a plain seek. For a direct-I/O device it seeks to the sector floor (O_DIRECT requires sector-aligned reads) and discards the sub-sector remainder, so the next Read still delivers byte off exactly.

func (*Reader) SetSize

func (r *Reader) SetSize(size int64)

SetSize explicitly sets the volume size (needed for raw device reads where stat returns 0).

func (*Reader) Size

func (r *Reader) Size() int64

Size returns the total size in bytes.

type VolumeInfo added in v0.2.8

type VolumeInfo struct {
	Device     string `json:"device"`
	MountPoint string `json:"mount_point,omitempty"` // "" when unmounted
	Filesystem string `json:"filesystem,omitempty"`
	Label      string `json:"label,omitempty"`
	Bytes      int64  `json:"bytes"`
	Disk       string `json:"disk,omitempty"` // the whole disk, in Disk.Path form
	DiskSerial string `json:"disk_serial,omitempty"`
	Removable  bool   `json:"removable"`
}

VolumeInfo is a filesystem the OS knows about, with the disk it sits on. Device is the raw node a capture opens; Filesystem and Label are what the OS reported (empty when it reported nothing; the boot sector is the authority and the caller reads it through volumefs.IdentityAuto).

type Writer

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

Writer provides random-access writing to a file or device for restoring backups.

func NewWriter

func NewWriter(path string) (*Writer, error)

NewWriter opens or creates a file for writing at arbitrary offsets. For device paths (e.g., \\.\PhysicalDrive0), platform-specific opening is used.

func (*Writer) Close

func (w *Writer) Close() error

Close closes the writer.

func (*Writer) Sync

func (w *Writer) Sync() error

Sync flushes writes to stable storage.

func (*Writer) Truncate

func (w *Writer) Truncate(size int64) error

Truncate sets the file to the given size. For device paths, truncate is a no-op since devices have a fixed size.

func (*Writer) WriteAt

func (w *Writer) WriteAt(data []byte, offset int64) (int, error)

WriteAt writes data at the given byte offset. For device paths on Windows, writes are sector-aligned automatically.

Jump to

Keyboard shortcuts

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