erofs

package
v0.0.0-...-799fb6b Latest Latest
Warning

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

Go to latest
Published: Mar 15, 2024 License: Apache-2.0, MIT Imports: 19 Imported by: 0

Documentation

Overview

Package erofs provides the ability to access the contents in an EROFS [1] image.

The design principle of this package is that, it will just provide the ability to access the contents in the image, and it will never cache any objects internally. The whole disk image is mapped via a read-only/shared mapping, and it relies on host kernel to cache the blocks/pages transparently.

[1] https://docs.kernel.org/filesystems/erofs.html

Index

Constants

View Source
const (
	// Definitions for superblock.
	SuperBlockMagicV1 = 0xe0f5e1e2
	SuperBlockOffset  = 1024

	// Inode slot size in bit shift.
	InodeSlotBits = 5

	// Max file name length.
	MaxNameLen = 255
)
View Source
const (
	InodeLayoutBit  = 0
	InodeLayoutBits = 1

	InodeDataLayoutBit  = 1
	InodeDataLayoutBits = 3
)

Bit definitions for Inode*::Format.

View Source
const (
	InodeLayoutCompact  = 0
	InodeLayoutExtended = 1
)

Inode layouts.

View Source
const (
	InodeDataLayoutFlatPlain = iota
	InodeDataLayoutFlatCompressionLegacy
	InodeDataLayoutFlatInline
	InodeDataLayoutFlatCompression
	InodeDataLayoutChunkBased
	InodeDataLayoutMax
)

Inode data layouts.

View Source
const (
	SuperBlockSize    = 128
	InodeCompactSize  = 32
	InodeExtendedSize = 64
	DirentSize        = 12
)

Sizes of on-disk structures in bytes.

View Source
const (
	FeatureCompatSuperBlockChecksum = 0x00000001
)

Features w/ backward compatibility. This is not exhaustive, unused features are not listed.

View Source
const (
	FeatureIncompatSupported = 0x0
)

Features w/o backward compatibility.

Any features that aren't in FeatureIncompatSupported are incompatible with this implementation.

This is not exhaustive, unused features are not listed.

Variables

This section is empty.

Functions

This section is empty.

Types

type Dirent

type Dirent struct {
	NidLow   uint32
	NidHigh  uint32
	NameOff  uint16
	FileType uint8
	Reserved uint8
}

Dirent represents on-disk directory entry.

+marshal

func (*Dirent) CopyIn

func (d *Dirent) CopyIn(cc marshal.CopyContext, addr hostarch.Addr) (int, error)

CopyIn implements marshal.Marshallable.CopyIn.

func (*Dirent) CopyInN

func (d *Dirent) CopyInN(cc marshal.CopyContext, addr hostarch.Addr, limit int) (int, error)

CopyInN implements marshal.Marshallable.CopyInN.

func (*Dirent) CopyOut

func (d *Dirent) CopyOut(cc marshal.CopyContext, addr hostarch.Addr) (int, error)

CopyOut implements marshal.Marshallable.CopyOut.

func (*Dirent) CopyOutN

func (d *Dirent) CopyOutN(cc marshal.CopyContext, addr hostarch.Addr, limit int) (int, error)

CopyOutN implements marshal.Marshallable.CopyOutN.

func (*Dirent) MarshalBytes

func (d *Dirent) MarshalBytes(dst []byte) []byte

MarshalBytes implements marshal.Marshallable.MarshalBytes.

func (*Dirent) MarshalUnsafe

func (d *Dirent) MarshalUnsafe(dst []byte) []byte

MarshalUnsafe implements marshal.Marshallable.MarshalUnsafe.

func (*Dirent) Nid

func (d *Dirent) Nid() uint64

Nid returns the inode number of the inode referenced by this dirent.

func (*Dirent) Packed

func (d *Dirent) Packed() bool

Packed implements marshal.Marshallable.Packed.

func (*Dirent) SizeBytes

func (d *Dirent) SizeBytes() int

SizeBytes implements marshal.Marshallable.SizeBytes.

func (*Dirent) UnmarshalBytes

func (d *Dirent) UnmarshalBytes(src []byte) []byte

UnmarshalBytes implements marshal.Marshallable.UnmarshalBytes.

func (*Dirent) UnmarshalUnsafe

func (d *Dirent) UnmarshalUnsafe(src []byte) []byte

UnmarshalUnsafe implements marshal.Marshallable.UnmarshalUnsafe.

func (*Dirent) WriteTo

func (d *Dirent) WriteTo(writer io.Writer) (int64, error)

WriteTo implements io.WriterTo.WriteTo.

type Image

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

Image represents an open EROFS image.

+stateify savable

func OpenImage

func OpenImage(src *os.File) (*Image, error)

OpenImage returns an Image providing access to the contents in the image file src.

On success, the ownership of src is transferred to Image.

func (*Image) BlockSize

func (i *Image) BlockSize() uint32

BlockSize returns the block size of this image.

func (*Image) Blocks

func (i *Image) Blocks() uint32

Blocks returns the total blocks of this image.

func (*Image) BytesAt

func (i *Image) BytesAt(off, n uint64) ([]byte, error)

BytesAt returns the bytes at [off, off+n) of the image.

func (*Image) Close

func (i *Image) Close()

Close closes the image.

func (*Image) FD

func (i *Image) FD() int

FD returns the host FD of underlying image file.

func (*Image) Inode

func (i *Image) Inode(nid uint64) (Inode, error)

Inode returns the inode identified by nid.

func (*Image) RootNid

func (i *Image) RootNid() uint64

RootNid returns the root inode number of this image.

func (*Image) StateFields

func (i *Image) StateFields() []string

func (*Image) StateLoad

func (i *Image) StateLoad(ctx context.Context, stateSourceObject state.Source)

+checklocksignore

func (*Image) StateSave

func (i *Image) StateSave(stateSinkObject state.Sink)

+checklocksignore

func (*Image) StateTypeName

func (i *Image) StateTypeName() string

func (*Image) SuperBlock

func (i *Image) SuperBlock() SuperBlock

SuperBlock returns a copy of the image's superblock.

type Inode

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

Inode represents in-memory inode object.

+stateify savable

func (*Inode) Data

func (i *Inode) Data() (safemem.BlockSeq, error)

Data returns the read-only file data of this inode.

func (*Inode) DataLayout

func (i *Inode) DataLayout() uint16

DataLayout returns the inode data layout.

func (*Inode) DataOffset

func (i *Inode) DataOffset() (uint64, error)

DataOffset returns the data offset of this inode in image file.

func (*Inode) GID

func (i *Inode) GID() uint32

GID returns the group ID of the owner.

func (*Inode) IsBlockDev

func (i *Inode) IsBlockDev() bool

IsBlockDev indicates whether i represents a block device.

func (*Inode) IsCharDev

func (i *Inode) IsCharDev() bool

IsCharDev indicates whether i represents a character device.

func (*Inode) IsDir

func (i *Inode) IsDir() bool

IsDir indicates whether i represents a directory.

func (*Inode) IsFIFO

func (i *Inode) IsFIFO() bool

IsFIFO indicates whether i represents a named pipe.

func (*Inode) IsRegular

func (i *Inode) IsRegular() bool

IsRegular indicates whether i represents a regular file.

func (*Inode) IsSocket

func (i *Inode) IsSocket() bool

IsSocket indicates whether i represents a socket.

func (i *Inode) IsSymlink() bool

IsSymlink indicates whether i represents a symbolic link.

func (*Inode) IterDirents

func (i *Inode) IterDirents(cb func(name string, typ uint8, nid uint64) error) error

IterDirents invokes cb on each entry in the directory represented by this inode. The directory entries will be iterated in alphabetical order.

func (*Inode) Layout

func (i *Inode) Layout() uint16

Layout returns the inode layout.

func (*Inode) Lookup

func (i *Inode) Lookup(name string) (uint64, error)

Lookup looks up a child by the name. The child inode number will be returned on success.

func (*Inode) Mode

func (i *Inode) Mode() uint16

Mode returns the file type and permissions.

func (*Inode) Mtime

func (i *Inode) Mtime() uint64

Mtime returns the time of last modification.

func (*Inode) MtimeNsec

func (i *Inode) MtimeNsec() uint32

MtimeNsec returns the nano second part of Mtime.

func (*Inode) Nid

func (i *Inode) Nid() uint64

Nid returns the inode number.

func (i *Inode) Nlink() uint32

Nlink returns the number of hard links.

func (i *Inode) Readlink() (string, error)

Readlink reads the link target.

func (*Inode) Size

func (i *Inode) Size() uint64

Size returns the data size.

func (*Inode) StateFields

func (i *Inode) StateFields() []string

func (*Inode) StateLoad

func (i *Inode) StateLoad(ctx context.Context, stateSourceObject state.Source)

+checklocksignore

func (*Inode) StateSave

func (i *Inode) StateSave(stateSinkObject state.Sink)

+checklocksignore

func (*Inode) StateTypeName

func (i *Inode) StateTypeName() string

func (*Inode) UID

func (i *Inode) UID() uint32

UID returns the user ID of the owner.

type InodeCompact

type InodeCompact struct {
	Format       uint16
	XattrCount   uint16
	Mode         uint16
	Nlink        uint16
	Size         uint32
	Reserved     uint32
	RawBlockAddr uint32
	Ino          uint32
	UID          uint16
	GID          uint16
	Reserved2    uint32
}

InodeCompact represents 32-byte reduced form of on-disk inode.

+marshal

func (*InodeCompact) CopyIn

func (i *InodeCompact) CopyIn(cc marshal.CopyContext, addr hostarch.Addr) (int, error)

CopyIn implements marshal.Marshallable.CopyIn.

func (*InodeCompact) CopyInN

func (i *InodeCompact) CopyInN(cc marshal.CopyContext, addr hostarch.Addr, limit int) (int, error)

CopyInN implements marshal.Marshallable.CopyInN.

func (*InodeCompact) CopyOut

func (i *InodeCompact) CopyOut(cc marshal.CopyContext, addr hostarch.Addr) (int, error)

CopyOut implements marshal.Marshallable.CopyOut.

func (*InodeCompact) CopyOutN

func (i *InodeCompact) CopyOutN(cc marshal.CopyContext, addr hostarch.Addr, limit int) (int, error)

CopyOutN implements marshal.Marshallable.CopyOutN.

func (*InodeCompact) MarshalBytes

func (i *InodeCompact) MarshalBytes(dst []byte) []byte

MarshalBytes implements marshal.Marshallable.MarshalBytes.

func (*InodeCompact) MarshalUnsafe

func (i *InodeCompact) MarshalUnsafe(dst []byte) []byte

MarshalUnsafe implements marshal.Marshallable.MarshalUnsafe.

func (*InodeCompact) Packed

func (i *InodeCompact) Packed() bool

Packed implements marshal.Marshallable.Packed.

func (*InodeCompact) SizeBytes

func (i *InodeCompact) SizeBytes() int

SizeBytes implements marshal.Marshallable.SizeBytes.

func (*InodeCompact) UnmarshalBytes

func (i *InodeCompact) UnmarshalBytes(src []byte) []byte

UnmarshalBytes implements marshal.Marshallable.UnmarshalBytes.

func (*InodeCompact) UnmarshalUnsafe

func (i *InodeCompact) UnmarshalUnsafe(src []byte) []byte

UnmarshalUnsafe implements marshal.Marshallable.UnmarshalUnsafe.

func (*InodeCompact) WriteTo

func (i *InodeCompact) WriteTo(writer io.Writer) (int64, error)

WriteTo implements io.WriterTo.WriteTo.

type InodeExtended

type InodeExtended struct {
	Format       uint16
	XattrCount   uint16
	Mode         uint16
	Reserved     uint16
	Size         uint64
	RawBlockAddr uint32
	Ino          uint32
	UID          uint32
	GID          uint32
	Mtime        uint64
	MtimeNsec    uint32
	Nlink        uint32
	Reserved2    [16]uint8
}

InodeExtended represents 64-byte complete form of on-disk inode.

+marshal

func (*InodeExtended) CopyIn

func (i *InodeExtended) CopyIn(cc marshal.CopyContext, addr hostarch.Addr) (int, error)

CopyIn implements marshal.Marshallable.CopyIn.

func (*InodeExtended) CopyInN

func (i *InodeExtended) CopyInN(cc marshal.CopyContext, addr hostarch.Addr, limit int) (int, error)

CopyInN implements marshal.Marshallable.CopyInN.

func (*InodeExtended) CopyOut

func (i *InodeExtended) CopyOut(cc marshal.CopyContext, addr hostarch.Addr) (int, error)

CopyOut implements marshal.Marshallable.CopyOut.

func (*InodeExtended) CopyOutN

func (i *InodeExtended) CopyOutN(cc marshal.CopyContext, addr hostarch.Addr, limit int) (int, error)

CopyOutN implements marshal.Marshallable.CopyOutN.

func (*InodeExtended) MarshalBytes

func (i *InodeExtended) MarshalBytes(dst []byte) []byte

MarshalBytes implements marshal.Marshallable.MarshalBytes.

func (*InodeExtended) MarshalUnsafe

func (i *InodeExtended) MarshalUnsafe(dst []byte) []byte

MarshalUnsafe implements marshal.Marshallable.MarshalUnsafe.

func (*InodeExtended) Packed

func (i *InodeExtended) Packed() bool

Packed implements marshal.Marshallable.Packed.

func (*InodeExtended) SizeBytes

func (i *InodeExtended) SizeBytes() int

SizeBytes implements marshal.Marshallable.SizeBytes.

func (*InodeExtended) UnmarshalBytes

func (i *InodeExtended) UnmarshalBytes(src []byte) []byte

UnmarshalBytes implements marshal.Marshallable.UnmarshalBytes.

func (*InodeExtended) UnmarshalUnsafe

func (i *InodeExtended) UnmarshalUnsafe(src []byte) []byte

UnmarshalUnsafe implements marshal.Marshallable.UnmarshalUnsafe.

func (*InodeExtended) WriteTo

func (i *InodeExtended) WriteTo(writer io.Writer) (int64, error)

WriteTo implements io.WriterTo.WriteTo.

type SuperBlock

type SuperBlock struct {
	Magic           uint32
	Checksum        uint32
	FeatureCompat   uint32
	BlockSizeBits   uint8
	ExtSlots        uint8
	RootNid         uint16
	Inodes          uint64
	BuildTime       uint64
	BuildTimeNsec   uint32
	Blocks          uint32
	MetaBlockAddr   uint32
	XattrBlockAddr  uint32
	UUID            [16]uint8
	VolumeName      [16]uint8
	FeatureIncompat uint32
	Union1          uint16
	ExtraDevices    uint16
	DevTableSlotOff uint16
	Reserved        [38]uint8
}

SuperBlock represents on-disk superblock.

+marshal +stateify savable

func (*SuperBlock) BlockAddrToOffset

func (sb *SuperBlock) BlockAddrToOffset(addr uint32) uint64

BlockAddrToOffset converts block addr to the offset in image file.

func (*SuperBlock) BlockSize

func (sb *SuperBlock) BlockSize() uint32

BlockSize returns the block size.

func (*SuperBlock) CopyIn

func (sb *SuperBlock) CopyIn(cc marshal.CopyContext, addr hostarch.Addr) (int, error)

CopyIn implements marshal.Marshallable.CopyIn.

func (*SuperBlock) CopyInN

func (sb *SuperBlock) CopyInN(cc marshal.CopyContext, addr hostarch.Addr, limit int) (int, error)

CopyInN implements marshal.Marshallable.CopyInN.

func (*SuperBlock) CopyOut

func (sb *SuperBlock) CopyOut(cc marshal.CopyContext, addr hostarch.Addr) (int, error)

CopyOut implements marshal.Marshallable.CopyOut.

func (*SuperBlock) CopyOutN

func (sb *SuperBlock) CopyOutN(cc marshal.CopyContext, addr hostarch.Addr, limit int) (int, error)

CopyOutN implements marshal.Marshallable.CopyOutN.

func (*SuperBlock) MarshalBytes

func (sb *SuperBlock) MarshalBytes(dst []byte) []byte

MarshalBytes implements marshal.Marshallable.MarshalBytes.

func (*SuperBlock) MarshalUnsafe

func (sb *SuperBlock) MarshalUnsafe(dst []byte) []byte

MarshalUnsafe implements marshal.Marshallable.MarshalUnsafe.

func (*SuperBlock) MetaOffset

func (sb *SuperBlock) MetaOffset() uint64

MetaOffset returns the offset of metadata area in image file.

func (*SuperBlock) NidToOffset

func (sb *SuperBlock) NidToOffset(nid uint64) uint64

NidToOffset converts inode number to the offset in image file.

func (*SuperBlock) Packed

func (sb *SuperBlock) Packed() bool

Packed implements marshal.Marshallable.Packed.

func (*SuperBlock) SizeBytes

func (sb *SuperBlock) SizeBytes() int

SizeBytes implements marshal.Marshallable.SizeBytes.

func (*SuperBlock) StateFields

func (sb *SuperBlock) StateFields() []string

func (*SuperBlock) StateLoad

func (sb *SuperBlock) StateLoad(ctx context.Context, stateSourceObject state.Source)

+checklocksignore

func (*SuperBlock) StateSave

func (sb *SuperBlock) StateSave(stateSinkObject state.Sink)

+checklocksignore

func (*SuperBlock) StateTypeName

func (sb *SuperBlock) StateTypeName() string

func (*SuperBlock) UnmarshalBytes

func (sb *SuperBlock) UnmarshalBytes(src []byte) []byte

UnmarshalBytes implements marshal.Marshallable.UnmarshalBytes.

func (*SuperBlock) UnmarshalUnsafe

func (sb *SuperBlock) UnmarshalUnsafe(src []byte) []byte

UnmarshalUnsafe implements marshal.Marshallable.UnmarshalUnsafe.

func (*SuperBlock) WriteTo

func (sb *SuperBlock) WriteTo(writer io.Writer) (int64, error)

WriteTo implements io.WriterTo.WriteTo.

Jump to

Keyboard shortcuts

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