clear

package module
v0.0.0-...-a9b61d9 Latest Latest
Warning

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

Go to latest
Published: Oct 31, 2026 License: BSD-3-Clause Imports: 3 Imported by: 1

README

go-fde/clear

clear

ci Go Reference

Pure-Go passthrough block device with no encryption.

Overview

The clear package exposes a Device that forwards all I/O directly to the underlying file or block device without any encryption or decryption. It satisfies the same interface as the luks and apfs backends so that the fde dispatcher can treat plaintext devices uniformly.

Usage

Open a plaintext file as a block device
import "github.com/go-fde/clear"

dev, err := clear.Open("/path/to/disk.raw")
if err != nil {
    log.Fatal(err)
}
defer dev.Close()

buf := make([]byte, 512)
_, err = dev.ReadAt(buf, 0)

_, err = dev.WriteAt(buf, 0)

fmt.Println("device size:", dev.Size())
Layer on top of another block device

OpenFrom accepts any value satisfying:

interface {
    io.ReaderAt
    WriteAt([]byte, int64) (int, error)
    io.Closer
}
dev, err := clear.OpenFrom(someRW)
if err != nil {
    log.Fatal(err)
}
defer dev.Close()

Size() returns the file size when the underlying value is an *os.File, and 0 for all other backends.

Device interface

Method Description
ReadAt(p, off) Forward read to the underlying device
WriteAt(p, off) Forward write to the underlying device
Size() int64 File size at open time (0 for non-file backends)
Close() Close the underlying device

Documentation

Overview

Package clear provides a passthrough Device implementation for unencrypted block devices. It satisfies the same interface as the LUKS and APFS backends, allowing the fde dispatcher to treat plaintext devices uniformly.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Device

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

Device is a passthrough block device that applies no encryption or decryption. ReadAt and WriteAt forward directly to the underlying device.

func Open

func Open(path string) (*Device, error)

Open opens the file at path as a passthrough block device. The file must already exist; it is opened for reading and writing.

func OpenFrom

func OpenFrom(rw RW) (*Device, error)

OpenFrom wraps rw as a passthrough Device. If rw is an *os.File its current size is recorded for Size(); otherwise Size returns 0.

func (*Device) Close

func (d *Device) Close() error

Close releases all resources held by the device.

func (*Device) ReadAt

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

ReadAt reads from the underlying device at byte offset off.

func (*Device) Size

func (d *Device) Size() int64

Size returns the byte length of the device as recorded at open time. Returns 0 when the size is not known (e.g. OpenFrom with a non-file backend).

func (*Device) WriteAt

func (d *Device) WriteAt(p []byte, off int64) (int, error)

WriteAt writes to the underlying device at byte offset off.

type RW

type RW interface {
	io.ReaderAt
	WriteAt(p []byte, off int64) (int, error)
	io.Closer
}

RW is the minimal read-write-close interface accepted by OpenFrom.

Jump to

Keyboard shortcuts

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