superlp

package
v0.7.4 Latest Latest
Warning

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

Go to latest
Published: Sep 28, 2026 License: MIT Imports: 5 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package superlp reads Android "super" partitions: the LP metadata that describes dynamic partitions (system, vendor, product, …) as an extent list over one block device.

A super partition starts with two copies of a geometry block, then the metadata slots (two by default, plus backups), then the partitions' data. Every logical partition is a list of extents — each either a range of the super partition or a run of zeroes — so reading one means stitching those ranges together, which is what Mapping does.

The layout is the one liblp writes; Open validates it against the geometry rather than trusting the numbers, because a corrupt super should be reported as unreadable, not read as garbage.

Index

Constants

View Source
const (
	// GeometryMagic ("gDla") and HeaderMagic ("0PLA") are the two magics liblp
	// writes; the geometry sits at GeometryOffset and is written twice.
	GeometryMagic  = 0x616c4467
	HeaderMagic    = 0x414c5030
	GeometryOffset = 4096
	GeometrySize   = 4096
	SectorSize     = 512

	// Target types of an extent.
	TargetLinear = 0
	TargetZero   = 1
)

Variables

This section is empty.

Functions

func Detect

func Detect(ra io.ReaderAt, origin int64) bool

Detect reports whether ra holds LP metadata at origin: the geometry magic is present where liblp writes it. It reads one block.

Types

type Extent

type Extent struct {
	NumSectors   uint64
	TargetType   uint32
	TargetData   uint64
	TargetSource uint32
}

Extent is one range of a logical partition: NumSectors sectors starting at TargetData on block device TargetSource, or—when TargetType is TargetZero— NumSectors sectors that read as zeroes.

type Geometry

type Geometry struct {
	MaxMetadataSize uint32
	SlotCount       uint32
	LogicalBlockSz  uint32
}

Geometry is the metadata geometry block.

type Mapping

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

Mapping exposes one logical partition as a byte range: reads are served from the extents that make it up, and zero-type extents read as zeroes.

func (*Mapping) ReadAt

func (mp *Mapping) ReadAt(p []byte, off int64) (int, error)

ReadAt reads from the partition, gathering the extents that cover the range.

func (*Mapping) Size

func (mp *Mapping) Size() int64

Size is the partition's size in bytes.

type Metadata

type Metadata struct {
	Geometry   Geometry
	Partitions []Partition
}

Metadata is a parsed super partition.

func Open

func Open(ra io.ReaderAt, origin int64) (*Metadata, error)

Open parses the metadata at origin. The primary slot is used, falling back to the other slots (and their backups) when a copy does not validate, so a super with one damaged slot still opens.

func (*Metadata) Find

func (m *Metadata) Find(name string) (Partition, bool)

Find returns the named logical partition.

func (*Metadata) Mapping

func (m *Metadata) Mapping(ra io.ReaderAt, origin int64, p Partition) (*Mapping, error)

Mapping builds a reader for a partition held in the super at origin.

type Partition

type Partition struct {
	Name       string
	Attributes uint32
	Extents    []Extent
}

Partition is one logical partition: a name and the extents that hold it.

func (Partition) Contiguous

func (p Partition) Contiguous() (offset, size int64, ok bool)

Contiguous reports whether the partition is a single uninterrupted run of the super partition, and returns the run's byte offset and size when it is.

func (Partition) Size

func (p Partition) Size() int64

Size is the partition's size in bytes.

Jump to

Keyboard shortcuts

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