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.
Index ¶
- Constants
- type Dirent
- func (d *Dirent) CopyIn(cc marshal.CopyContext, addr hostarch.Addr) (int, error)
- func (d *Dirent) CopyInN(cc marshal.CopyContext, addr hostarch.Addr, limit int) (int, error)
- func (d *Dirent) CopyOut(cc marshal.CopyContext, addr hostarch.Addr) (int, error)
- func (d *Dirent) CopyOutN(cc marshal.CopyContext, addr hostarch.Addr, limit int) (int, error)
- func (d *Dirent) MarshalBytes(dst []byte) []byte
- func (d *Dirent) MarshalUnsafe(dst []byte) []byte
- func (d *Dirent) Packed() bool
- func (d *Dirent) SizeBytes() int
- func (d *Dirent) UnmarshalBytes(src []byte) []byte
- func (d *Dirent) UnmarshalUnsafe(src []byte) []byte
- func (d *Dirent) WriteTo(writer io.Writer) (int64, error)
- type Image
- func (i *Image) BlockSize() uint32
- func (i *Image) Blocks() uint32
- func (i *Image) BytesAt(off, n uint64) ([]byte, error)
- func (i *Image) Close()
- func (i *Image) FD() int
- func (i *Image) Inode(nid uint64) (Inode, error)
- func (i *Image) RootNid() uint64
- func (i *Image) StateFields() []string
- func (i *Image) StateLoad(stateSourceObject state.Source)
- func (i *Image) StateSave(stateSinkObject state.Sink)
- func (i *Image) StateTypeName() string
- func (i *Image) UnmarshalAt(data marshal.Marshallable, off uint64) error
- type Inode
- func (i *Inode) Data() (safemem.BlockSeq, error)
- func (i *Inode) DataLayout() uint16
- func (i *Inode) DataOffset() (uint64, error)
- func (i *Inode) GID() uint32
- func (i *Inode) IsBlockDev() bool
- func (i *Inode) IsCharDev() bool
- func (i *Inode) IsDir() bool
- func (i *Inode) IsFIFO() bool
- func (i *Inode) IsRegular() bool
- func (i *Inode) IsSocket() bool
- func (i *Inode) IsSymlink() bool
- func (i *Inode) IterDirents(cb func(name string, typ uint8, nid uint64) error) error
- func (i *Inode) Layout() uint16
- func (i *Inode) Mode() uint16
- func (i *Inode) Mtime() uint64
- func (i *Inode) MtimeNsec() uint32
- func (i *Inode) Nid() uint64
- func (i *Inode) Nlink() uint32
- func (i *Inode) Readlink() (string, error)
- func (i *Inode) Size() uint64
- func (i *Inode) StateFields() []string
- func (i *Inode) StateLoad(stateSourceObject state.Source)
- func (i *Inode) StateSave(stateSinkObject state.Sink)
- func (i *Inode) StateTypeName() string
- func (i *Inode) UID() uint32
- type InodeCompact
- func (i *InodeCompact) CopyIn(cc marshal.CopyContext, addr hostarch.Addr) (int, error)
- func (i *InodeCompact) CopyInN(cc marshal.CopyContext, addr hostarch.Addr, limit int) (int, error)
- func (i *InodeCompact) CopyOut(cc marshal.CopyContext, addr hostarch.Addr) (int, error)
- func (i *InodeCompact) CopyOutN(cc marshal.CopyContext, addr hostarch.Addr, limit int) (int, error)
- func (i *InodeCompact) MarshalBytes(dst []byte) []byte
- func (i *InodeCompact) MarshalUnsafe(dst []byte) []byte
- func (i *InodeCompact) Packed() bool
- func (i *InodeCompact) SizeBytes() int
- func (i *InodeCompact) UnmarshalBytes(src []byte) []byte
- func (i *InodeCompact) UnmarshalUnsafe(src []byte) []byte
- func (i *InodeCompact) WriteTo(writer io.Writer) (int64, error)
- type InodeExtended
- func (i *InodeExtended) CopyIn(cc marshal.CopyContext, addr hostarch.Addr) (int, error)
- func (i *InodeExtended) CopyInN(cc marshal.CopyContext, addr hostarch.Addr, limit int) (int, error)
- func (i *InodeExtended) CopyOut(cc marshal.CopyContext, addr hostarch.Addr) (int, error)
- func (i *InodeExtended) CopyOutN(cc marshal.CopyContext, addr hostarch.Addr, limit int) (int, error)
- func (i *InodeExtended) MarshalBytes(dst []byte) []byte
- func (i *InodeExtended) MarshalUnsafe(dst []byte) []byte
- func (i *InodeExtended) Packed() bool
- func (i *InodeExtended) SizeBytes() int
- func (i *InodeExtended) UnmarshalBytes(src []byte) []byte
- func (i *InodeExtended) UnmarshalUnsafe(src []byte) []byte
- func (i *InodeExtended) WriteTo(writer io.Writer) (int64, error)
- type SuperBlock
- func (sb *SuperBlock) BlockAddrToOffset(addr uint32) uint64
- func (sb *SuperBlock) BlockSize() uint32
- func (sb *SuperBlock) CopyIn(cc marshal.CopyContext, addr hostarch.Addr) (int, error)
- func (sb *SuperBlock) CopyInN(cc marshal.CopyContext, addr hostarch.Addr, limit int) (int, error)
- func (sb *SuperBlock) CopyOut(cc marshal.CopyContext, addr hostarch.Addr) (int, error)
- func (sb *SuperBlock) CopyOutN(cc marshal.CopyContext, addr hostarch.Addr, limit int) (int, error)
- func (sb *SuperBlock) MarshalBytes(dst []byte) []byte
- func (sb *SuperBlock) MarshalUnsafe(dst []byte) []byte
- func (sb *SuperBlock) MetaOffset() uint64
- func (sb *SuperBlock) NidToOffset(nid uint64) uint64
- func (sb *SuperBlock) Packed() bool
- func (sb *SuperBlock) SizeBytes() int
- func (sb *SuperBlock) StateFields() []string
- func (sb *SuperBlock) StateLoad(stateSourceObject state.Source)
- func (sb *SuperBlock) StateSave(stateSinkObject state.Sink)
- func (sb *SuperBlock) StateTypeName() string
- func (sb *SuperBlock) UnmarshalBytes(src []byte) []byte
- func (sb *SuperBlock) UnmarshalUnsafe(src []byte) []byte
- func (sb *SuperBlock) WriteTo(writer io.Writer) (int64, error)
Constants ¶
const ( // Definitions for super block. SuperBlockMagicV1 = 0xe0f5e1e2 SuperBlockOffset = 1024 // Inode slot size in bit shift. InodeSlotBits = 5 // Max file name length. MaxNameLen = 255 )
const ( InodeLayoutBit = 0 InodeLayoutBits = 1 InodeDataLayoutBit = 1 InodeDataLayoutBits = 3 )
Bit definitions for Inode*::Format.
const ( InodeLayoutCompact = 0 InodeLayoutExtended = 1 )
Inode layouts.
const ( InodeDataLayoutFlatPlain = iota InodeDataLayoutFlatCompressionLegacy InodeDataLayoutFlatInline InodeDataLayoutFlatCompression InodeDataLayoutChunkBased InodeDataLayoutMax )
Inode data layouts.
const (
FeatureCompatSuperBlockChecksum = 0x00000001
)
Features w/ backward compatibility. This is not exhaustive, unused features are not listed.
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 {
Nid uint64
NameOff uint16
FileType uint8
Reserved uint8 `marshal:"unaligned"`
}
Dirent represents on-disk directory entry.
This struct is misaligned according to go_marshal, as it is only 12 bytes in size. The last field needs to be marked unaligned so the struct is marked unpacked and the generated methods behave correctly.
+marshal
func (*Dirent) MarshalBytes ¶
MarshalBytes implements marshal.Marshallable.MarshalBytes.
func (*Dirent) MarshalUnsafe ¶
MarshalUnsafe implements marshal.Marshallable.MarshalUnsafe.
func (*Dirent) UnmarshalBytes ¶
UnmarshalBytes implements marshal.Marshallable.UnmarshalBytes.
func (*Dirent) UnmarshalUnsafe ¶
UnmarshalUnsafe implements marshal.Marshallable.UnmarshalUnsafe.
type Image ¶
type Image struct {
// contains filtered or unexported fields
}
Image represents an open EROFS image.
+stateify savable
func OpenImage ¶
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) Inode ¶
Inode returns the inode identified by nid.
TODO: Ideally, we should avoid escaping objects to heap when constructing objects from the image.
func (*Image) StateFields ¶
func (*Image) StateTypeName ¶
func (*Image) UnmarshalAt ¶
func (i *Image) UnmarshalAt(data marshal.Marshallable, off uint64) error
UnmarshalAt deserializes data from the bytes at [off, off+n) of the image.
type Inode ¶
type Inode struct {
// contains filtered or unexported fields
}
Inode represents in-memory inode object.
+stateify savable
func (*Inode) DataLayout ¶
DataLayout returns the inode data layout.
func (*Inode) DataOffset ¶
DataOffset returns the data offset of this inode in image file.
func (*Inode) IsBlockDev ¶
IsBlockDev indicates whether i represents a block device.
func (*Inode) IterDirents ¶
IterDirents invokes cb on each entry in the directory represented by this inode. The directory entries will be iterated in alphabetical order.
https://docs.kernel.org/filesystems/erofs.html#directories
The on-disk format of one block looks like this:
___________________________
/ |
/ ______________|________________
/ / | nameoff1 | nameoffN-1
____________.______________._______________v________________v__________
| dirent | dirent | ... | dirent | filename | filename | ... | filename |
|___.0___|____1___|_____|___N-1__|____0_____|____1_____|_____|___N-1____|
\ ^
\ | * could have
\ | trailing '\0'
\________________________| nameoff0
Directory block
The on-disk format of one directory looks like this:
[ (block 1) dirent 1 | dirent 2 | dirent 3 | name 1 | name 2 | name 3 | optional padding ] [ (block 2) dirent 4 | dirent 5 | name 4 | name 5 | optional padding ] ... [ (block N) dirent M | dirent M+1 | name M | name M+1 | optional padding ]
[ (metadata block) inode | optional fields | dirent M+2 | dirent M+3 | name M+2 | name M+3 | optional padding ]
All directory entries are _strictly_ recorded in alphabetical order.
func (*Inode) StateFields ¶
func (*Inode) StateTypeName ¶
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.
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.
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 super block.
+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(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.