disk

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Aug 29, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultSectorSize = 512

Variables

View Source
var ErrReadOnly = errors.New("hfsgo/disk: content is read-only")

ErrReadOnly is returned when writing to a read-only Content.

Functions

func ReadExactly

func ReadExactly(c Content, off int64, p []byte) error

ReadExactly reads len(p) bytes at off, or returns an error.

func Register

func Register(f Factory)

Register adds a disk factory. Typically called from a plugin package init().

func WriteExactly

func WriteExactly(c Content, off int64, p []byte) error

WriteExactly writes len(p) bytes at off, or returns an error.

Types

type Access

type Access int

Access is open mode.

const (
	Read Access = iota
	ReadWrite
)

type BasicDisk

type BasicDisk struct {
	C        Content
	Geom     Geometry
	Writable bool
	Sect     int
}

BasicDisk is a Disk wrapping a Content.

func (*BasicDisk) CanWrite

func (d *BasicDisk) CanWrite() bool

func (*BasicDisk) Capacity

func (d *BasicDisk) Capacity() int64

func (*BasicDisk) Close

func (d *BasicDisk) Close() error

func (*BasicDisk) Content

func (d *BasicDisk) Content() Content

func (*BasicDisk) Geometry

func (d *BasicDisk) Geometry() Geometry

func (*BasicDisk) SectorSize

func (d *BasicDisk) SectorSize() int

type Content

type Content interface {
	io.ReaderAt
	io.WriterAt
	io.Closer
	Size() int64
	Extents() []Extent
}

Content is a sparse, random-access byte view of a disk or volume. It is the Go equivalent of DiscUtils SparseStream.

type Disk

type Disk interface {
	io.Closer
	Content() Content
	Capacity() int64
	SectorSize() int
	Geometry() Geometry
	CanWrite() bool
}

Disk is a virtual disk. Equivalent to DiscUtils VirtualDisk.

func Create

func Create(path, typ string, capacity int64) (Disk, error)

Create creates a new disk image of the given type at path.

func CreateMemory

func CreateMemory(typ string, capacity int64) (Disk, error)

CreateMemory creates an in-memory disk of the given type.

func Open

func Open(path string) (Disk, error)

Open opens a disk image by path. Extension selects a factory; remaining factories are probed; raw is the fallback.

func OpenContent

func OpenContent(c Content, writable bool, ext string) (Disk, error)

OpenContent selects a factory by extension then probe.

func OpenFileAccess

func OpenFileAccess(path string, access Access) (Disk, error)

OpenFileAccess opens a disk image with the given access.

type Extent

type Extent struct {
	Start  int64
	Length int64
}

Extent is a stored (non-hole) byte range. Holes read as zeros.

func (Extent) End

func (e Extent) End() int64

type Factory

type Factory interface {
	Type() string
	Extensions() []string
	Detect(c Content) bool
	Open(c Content, writable bool) (Disk, error)
	Create(c Content, capacity int64) (Disk, error)
}

Factory opens or creates a disk format. Equivalent to DiscUtils VirtualDiskFactory.

type FileContent

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

FileContent wraps an os.File as Content.

func CreateFile

func CreateFile(path string, size int64) (*FileContent, error)

func OpenFile

func OpenFile(path string, write bool) (*FileContent, error)

func (*FileContent) Close

func (c *FileContent) Close() error

func (*FileContent) Extents

func (c *FileContent) Extents() []Extent

func (*FileContent) ReadAt

func (c *FileContent) ReadAt(p []byte, off int64) (int, error)

func (*FileContent) Size

func (c *FileContent) Size() int64

func (*FileContent) WriteAt

func (c *FileContent) WriteAt(p []byte, off int64) (int, error)

type Geometry

type Geometry struct {
	Cylinders        int
	HeadsPerCylinder int
	SectorsPerTrack  int
	BytesPerSector   int
}

Geometry is CHS disk geometry (DiscUtils Geometry).

func FromCapacity

func FromCapacity(capacity int64) Geometry

FromCapacity guesses a BIOS-safe geometry for a given capacity.

func (Geometry) Capacity

func (g Geometry) Capacity() int64

type MemoryContent

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

MemoryContent is an in-memory sparse Content.

func MemoryFromBytes

func MemoryFromBytes(b []byte) *MemoryContent

func NewMemory

func NewMemory(size int64) *MemoryContent

func (*MemoryContent) Bytes

func (c *MemoryContent) Bytes() []byte

func (*MemoryContent) Close

func (c *MemoryContent) Close() error

func (*MemoryContent) Extents

func (c *MemoryContent) Extents() []Extent

func (*MemoryContent) ReadAt

func (c *MemoryContent) ReadAt(p []byte, off int64) (int, error)

func (*MemoryContent) Size

func (c *MemoryContent) Size() int64

func (*MemoryContent) WriteAt

func (c *MemoryContent) WriteAt(p []byte, off int64) (int, error)

type ReadOnly

type ReadOnly struct{ Content }

ReadOnly wraps Content and rejects writes.

func (ReadOnly) WriteAt

func (c ReadOnly) WriteAt([]byte, int64) (int, error)

type SubContent

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

SubContent is a window into parent, equivalent to DiscUtils SubStream.

func NewSub

func NewSub(parent Content, off, length int64) *SubContent

func (*SubContent) Close

func (c *SubContent) Close() error

func (*SubContent) Extents

func (c *SubContent) Extents() []Extent

func (*SubContent) ReadAt

func (c *SubContent) ReadAt(p []byte, off int64) (int, error)

func (*SubContent) Size

func (c *SubContent) Size() int64

func (*SubContent) WriteAt

func (c *SubContent) WriteAt(p []byte, off int64) (int, error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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