erofs

package
v0.0.0-...-c27c9a0 Latest Latest
Warning

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

Go to latest
Published: Dec 14, 2024 License: Apache-2.0, MIT Imports: 14 Imported by: 2

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) Nid

func (d *Dirent) Nid() uint64

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

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) 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) 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

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

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) 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.

Jump to

Keyboard shortcuts

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