device

package
v0.0.0-...-c4ea246 Latest Latest
Warning

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

Go to latest
Published: Dec 19, 2025 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	SuperblockOffset  int64 = 0x10000      // 64KB
	SuperblockBackup1 int64 = 0x4000000    // 64MB
	SuperblockBackup2 int64 = 0x4000000000 // 256GB
)

Variables

This section is empty.

Functions

This section is empty.

Types

type BlockCache

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

BlockCache is an LRU block cache.

func NewBlockCache

func NewBlockCache(capacity int) *BlockCache

NewBlockCache creates a cache.

func (*BlockCache) Capacity

func (c *BlockCache) Capacity() int

Capacity returns the cache capacity.

func (*BlockCache) Clear

func (c *BlockCache) Clear()

Clear clears the cache.

func (*BlockCache) Get

func (c *BlockCache) Get(key uint64) ([]byte, bool)

Get retrieves a cached entry.

func (*BlockCache) Len

func (c *BlockCache) Len() int

Len returns the number of cached entries.

func (*BlockCache) Put

func (c *BlockCache) Put(key uint64, data []byte)

Put adds a cached entry.

func (*BlockCache) Stats

func (c *BlockCache) Stats() CacheStats

Stats returns cache statistics.

type BlockDevice

type BlockDevice interface {
	// ReadAt reads data at the specified offset.
	ReadAt(p []byte, off int64) (n int, err error)

	// Size returns the device size.
	Size() int64

	// DeviceID returns the unique device identifier.
	DeviceID() uint64

	// Close closes the device.
	Close() error
}

BlockDevice is the block device interface.

type CacheStats

type CacheStats struct {
	Size     int
	Capacity int
}

CacheStats holds cache statistics.

type FileDevice

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

FileDevice is a file-backed block device.

func NewFileDevice

func NewFileDevice(path string) (*FileDevice, error)

NewFileDevice creates a file device.

func (*FileDevice) Close

func (d *FileDevice) Close() error

Close closes the device.

func (*FileDevice) DeviceID

func (d *FileDevice) DeviceID() uint64

DeviceID returns the device ID.

func (*FileDevice) Path

func (d *FileDevice) Path() string

Path returns the device path.

func (*FileDevice) ReadAt

func (d *FileDevice) ReadAt(p []byte, off int64) (int, error)

ReadAt implements io.ReaderAt.

func (*FileDevice) SetDeviceID

func (d *FileDevice) SetDeviceID(id uint64)

SetDeviceID sets the device ID (after reading from the superblock).

func (*FileDevice) Size

func (d *FileDevice) Size() int64

Size returns the device size.

type SuperblockReader

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

SuperblockReader reads superblocks.

func NewSuperblockReader

func NewSuperblockReader(dev BlockDevice) *SuperblockReader

NewSuperblockReader creates a reader.

func (*SuperblockReader) ReadBackup

func (r *SuperblockReader) ReadBackup(index int) (*ondisk.Superblock, error)

ReadBackup reads a backup superblock at the given index. index: 0 = primary, 1 = backup1 (64MB), 2 = backup2 (256GB)

func (*SuperblockReader) ReadLatest

func (r *SuperblockReader) ReadLatest() (*ondisk.Superblock, error)

ReadLatest reads the newest valid superblock (primary then backups).

func (*SuperblockReader) ReadPrimary

func (r *SuperblockReader) ReadPrimary() (*ondisk.Superblock, error)

ReadPrimary reads the primary superblock.

Jump to

Keyboard shortcuts

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