volume

package
v0.2.7 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: 7 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 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 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