erofs

package
v0.11.1 Latest Latest
Warning

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

Go to latest
Published: Sep 10, 2024 License: MPL-2.0 Imports: 15 Imported by: 1

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.

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

Index

Constants

View Source
const (
	FT_REG_FILE = 1
	FT_DIR      = 2
	FT_CHRDEV   = 3
	FT_BLKDEV   = 4
	FT_FIFO     = 5
	FT_SOCK     = 6
	FT_SYMLINK  = 7
)

Linux values for fs on-disk file types.

View Source
const (
	S_IFMT   = 0170000
	S_IFSOCK = 0140000
	S_IFLNK  = 0120000
	S_IFREG  = 0100000
	S_IFBLK  = 060000
	S_IFDIR  = 040000
	S_IFCHR  = 020000
	S_IFIFO  = 010000
	S_ISUID  = 04000
	S_ISGID  = 02000
	S_ISVTX  = 01000
)

Values for mode_t.

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 (
	BlockSize         = 4096
	BlockSizeBits     = 12
	InodeSlotSize     = 1 << InodeSlotBits
	MaxInlineDataSize = BlockSize / 4
)
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

View Source
var DirentSize = int64(binary.Size(Dirent{}))

Functions

func Create

func Create(dst io.WriterAt, src fs.FS) error

Create creates an EROFS filesystem image from the source filesystem and writes it to the destination writer.

Types

type Dirent

type Dirent struct {
	Nid      uint64 // Inode number
	NameOff  uint16 // Offset of file name
	FileType uint8  // File type
	Reserved uint8  // Reserved for future use
}

Dirent represents on-disk directory entry.

type Filesystem

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

func Open

func Open(src io.ReaderAt) (*Filesystem, error)

func (*Filesystem) Open

func (fsys *Filesystem) Open(name string) (fs.File, error)

func (*Filesystem) ReadDir

func (fsys *Filesystem) ReadDir(name string) ([]fs.DirEntry, error)
func (fsys *Filesystem) ReadLink(name string) (string, error)

ReadLink returns the destination of the named symbolic link. Experimental implementation of: https://github.com/golang/go/issues/49580

func (*Filesystem) Stat

func (fsys *Filesystem) Stat(name string) (fs.FileInfo, error)
func (fsys *Filesystem) StatLink(name string) (fs.FileInfo, error)

StatLink returns a FileInfo describing the file without following any symbolic links. Experimental implementation of: https://github.com/golang/go/issues/49580

type Image

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

Image represents an open EROFS image.

func OpenImage

func OpenImage(src io.ReaderAt) (*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) 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 an inode object.

func (*Inode) Data

func (ino *Inode) Data() (io.Reader, error)

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

func (*Inode) DataLayout

func (ino *Inode) DataLayout() uint16

DataLayout returns the inode data layout.

func (*Inode) GID

func (ino *Inode) GID() uint32

GID returns the group ID of the owner.

func (*Inode) IsBlockDev

func (ino *Inode) IsBlockDev() bool

IsBlockDev indicates whether i represents a block device.

func (*Inode) IsCharDev

func (ino *Inode) IsCharDev() bool

IsCharDev indicates whether i represents a character device.

func (*Inode) IsDir

func (ino *Inode) IsDir() bool

IsDir indicates whether i represents a directory.

func (*Inode) IsFIFO

func (ino *Inode) IsFIFO() bool

IsFIFO indicates whether i represents a named pipe.

func (*Inode) IsRegular

func (ino *Inode) IsRegular() bool

IsRegular indicates whether i represents a regular file.

func (*Inode) IsSocket

func (ino *Inode) IsSocket() bool

IsSocket indicates whether i represents a socket.

func (ino *Inode) IsSymlink() bool

IsSymlink indicates whether i represents a symbolic link.

func (*Inode) IterDirents

func (ino *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 (ino *Inode) Layout() uint16

Layout returns the inode layout.

func (*Inode) Lookup

func (ino *Inode) Lookup(name string) (Dirent, error)

Lookup looks up a child by the name.

func (*Inode) Mode

func (ino *Inode) Mode() fs.FileMode

Mode returns the file type and permissions.

func (*Inode) Mtime

func (ino *Inode) Mtime() uint64

Mtime returns the time of last modification.

func (*Inode) MtimeNsec

func (ino *Inode) MtimeNsec() uint32

MtimeNsec returns the nano second part of Mtime.

func (*Inode) Nid

func (ino *Inode) Nid() uint64

Nid returns the inode number.

func (ino *Inode) Nlink() uint32

Nlink returns the number of hard links.

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

Readlink reads the link target.

func (*Inode) Size

func (ino *Inode) Size() uint64

Size returns the data size.

func (*Inode) UID

func (ino *Inode) UID() uint32

UID returns the user ID of the owner.

type InodeCompact

type InodeCompact struct {
	Format       uint16 // Inode format hints
	XattrCount   uint16 // Xattr entry count
	Mode         uint16 // File mode
	Nlink        uint16 // Number of hard links
	Size         uint32 // File size in bytes
	Reserved     uint32 // Reserved for future use
	RawBlockAddr uint32 // Raw block address
	Ino          uint32 // Inode number
	UID          uint16 // User ID of owner
	GID          uint16 // Group ID of owner
	Reserved2    uint32 // Reserved for future use
}

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

type InodeExtended

type InodeExtended struct {
	Format       uint16    // Inode format hints
	XattrCount   uint16    // Xattr entry count
	Mode         uint16    // File mode
	Reserved     uint16    // Reserved for future use
	Size         uint64    // File size in bytes
	RawBlockAddr uint32    // Raw block address
	Ino          uint32    // Inode number
	UID          uint32    // User ID of owner
	GID          uint32    // Group ID of owner
	Mtime        uint64    // Last modification time
	MtimeNsec    uint32    // Nanoseconds part of Mtime
	Nlink        uint32    // Number of hard links
	Reserved2    [16]uint8 // Reserved for future use
}

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

type SuperBlock

type SuperBlock struct {
	Magic           uint32    // Filesystem magic number
	Checksum        uint32    // CRC32C checksum of the superblock
	FeatureCompat   uint32    // Compatible feature flags
	BlockSizeBits   uint8     // Filesystem block size in bit shift
	ExtSlots        uint8     // Superblock extension slots
	RootNid         uint16    // Root directory inode number
	Inodes          uint64    // Total valid inodes
	BuildTime       uint64    // Build time of the filesystem
	BuildTimeNsec   uint32    // Nanoseconds part of build time
	Blocks          uint32    // Total number of blocks
	MetaBlockAddr   uint32    // Start block address of metadata area
	XattrBlockAddr  uint32    // Start block address of shared xattr area
	UUID            [16]uint8 // UUID for volume
	VolumeName      [16]uint8 // Volume name
	FeatureIncompat uint32    // Incompatible feature flags
	Union1          uint16    // Union for additional features
	ExtraDevices    uint16    // Number of extra devices
	DevTableSlotOff uint16    // Device table slot offset
	Reserved        [38]uint8 // Reserved for future use
}

SuperBlock represents on-disk superblock.

func (*SuperBlock) BlockAddrToOffset

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

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

MetaOffset returns the offset of metadata area in image file.

func (*SuperBlock) NidToOffset

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

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