vimg

package
Version: v0.0.0-...-cd5610b Latest Latest
Warning

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

Go to latest
Published: Jun 9, 2021 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	SemverMajor    = 3
	SemverMinor    = 0
	SemverRevision = 0
)

Compiler version constants.

View Source
const (
	OSReservedSectors        = 32
	KernelConfigSpaceSectors = 32
)

Various build constants.

View Source
const (
	SectorSize              = 512
	GPTSignature            = 0x5452415020494645 // "EFI PART" (little-endian)
	GPTHeaderSize           = 92
	MaximumGPTEntries       = 128
	GPTEntrySize            = 128
	GPTEntriesSectors       = MaximumGPTEntries * GPTEntrySize / SectorSize
	PrimaryGPTHeaderLBA     = 1
	PrimaryGPTHeaderOffset  = SectorSize * PrimaryGPTHeaderLBA
	PrimaryGPTEntriesLBA    = PrimaryGPTHeaderLBA + 1
	PrimaryGPTEntriesOffset = SectorSize * PrimaryGPTEntriesLBA
	P0FirstLBA              = PrimaryGPTEntriesLBA + GPTEntriesSectors
	P0Offset                = P0FirstLBA * SectorSize
)

Various build constants.

Variables

View Source
var (
	// OSPartitionName is the hardcoded name for the Vorteil OS partition in the GPT.
	OSPartitionName = []byte{0x76, 0x0, 0x6f, 0x0, 0x72, 0x0, 0x74, 0x0, 0x65, 0x0,
		0x69, 0x0, 0x6c, 0x0, 0x2d, 0x0, 0x6f, 0x0, 0x73, 0x0} // "vorteil-os" in utf16

	// RootPartitionName is the hardcoded name for the Vorteil root file-system partition in the GPT.
	RootPartitionName = []byte{0x76, 0x0, 0x6f, 0x0, 0x72, 0x0, 0x74, 0x0, 0x65, 0x0, 0x69, 0x0,
		0x6c, 0x0, 0x2d, 0x0, 0x72, 0x0, 0x6f, 0x0, 0x6f, 0x0, 0x74, 0x0} // "vorteil-root" in utf16

	// Part2UUID for second partition. used to define rooot partition in kernel args
	Part2UUID = []byte{
		0x7d, 0x44, 0x48, 0x40,
		0x9d, 0xc0, 0x11, 0xd1,
		0xb2, 0x45, 0x5f, 0xfd,
		0xce, 0x74, 0xfa, 0xd2,
	}

	// Part2UUIDString string value of Part2UUID
	Part2UUIDString = "4048447D-C09D-D111-B245-5FFDCE74FAD2"
)
View Source
var (
	// Bootloader contains all of the bytes that will be written as the image's bootloader.
	Bootloader = []byte{}/* 410 elements not displayed */

)
View Source
var GetKernel func(ctx context.Context, version vkern.CalVer) (*vkern.ManagedBundle, error)

GetKernel is the function a Builder will use to load a kernel bundle. It must be set externally.

View Source
var GetLatestKernel func(ctx context.Context) (vkern.CalVer, error)

GetLatestKernel is the function a Builder will use to determine what kernel to use if none is specified. It must be set externally.

Functions

This section is empty.

Types

type BootloaderConfig

type BootloaderConfig struct {
	Version [16]byte // 0

	LinuxArgsLen uint16 // 32

	ConfigOffset   uint64 // 40
	ConfigLen      uint64 // 48
	ConfigCapacity uint64 // 56

	LinuxArgs [0x2000]byte // 256
	// contains filtered or unexported fields
}

BootloaderConfig is the structure of the bootloader config as it appears on the disk.

type Builder

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

Builder is used for building a raw Vorteil image. Building happens in several stages to make the logic play nicely with potential external logic that needs some back-and-forth control over the build process.

func NewBuilder

func NewBuilder(ctx context.Context, args *BuilderArgs) (*Builder, error)

NewBuilder returns a new Builder object configured according to the provided args. In this state it can calculate the minimum possible image size and accept some minor further configuration. Once this configuration is complete you should call Prebuild on it to proceed.

func (*Builder) Build

func (b *Builder) Build(ctx context.Context, w io.WriteSeeker) error

Build is the final operation performed by the Builder, and should only be called after a successful call to the Prebuild function. It writes the file-system to the provided io.WriteSeeker, w. Despite using io.Seeker functionality to improve performance, the Builder has been written in a way such that it never needs to seek "backwards", which means you can wrap any io.Writer with a vio.WriteSeeker and it will work.

func (*Builder) Close

func (b *Builder) Close() error

Close frees up any resources kept open by the Builder.

func (*Builder) KernelUsed

func (b *Builder) KernelUsed() vkern.CalVer

KernelUsed returns the calver the disk was built with

func (*Builder) MinimumSize

func (b *Builder) MinimumSize() int64

MinimumSize returns the minimum number of bytes that are needed to build the image.

func (*Builder) Prebuild

func (b *Builder) Prebuild(ctx context.Context, size int64) error

Prebuild locks in a final raw image size (in bytes) and performs some preflight calculations to determine the final disk layout and to make the RegionIsHole function usable by external logic that wants to wrap the image in some sort of sparse virtual disk image format. Prebuild must be called before calling Build.

func (*Builder) RegionIsHole

func (b *Builder) RegionIsHole(begin, size int64) bool

RegionIsHole can be called after a successful Prebuild. Its purpose is to provide advance notice to sparse disk image formatting logic on regions within the image that will be completely empty. The two args are measured in bytes, and the function returns true if every byte starting at begin and continuing for the full size is zeroed.

func (*Builder) SetDefaultMTU

func (b *Builder) SetDefaultMTU(mtu uint)

SetDefaultMTU can be called before calling Prebuild in order to change the default MTU that will be applied to each NIC configuration (if not explicitly set in the VCFG).

func (*Builder) Size

func (b *Builder) Size() int64

Size returns the full final size of the raw disk image.

type BuilderArgs

type BuilderArgs struct {
	Seed       int64
	Kernel     KernelOptions
	FSCompiler FSCompiler
	VCFG       *vcfg.VCFG
	Logger     elog.View
}

BuilderArgs collects all of the arguments needed to call NewBuilder into one place.

type FSCompiler

type FSCompiler interface {
	Mkdir(path string) error
	AddFile(path string, r io.ReadCloser, size int64, force bool) error
	IncreaseMinimumFreeSpace(space int64)
	SetMinimumInodes(inodes int64)
	SetMinimumInodesPer64MiB(inodes int64)
	IncreaseMinimumInodes(inodes int64)
	Commit(ctx context.Context) error
	MinimumSize() int64
	Precompile(ctx context.Context, size int64) error
	Compile(ctx context.Context, w io.WriteSeeker) error
	RegionIsHole(begin, size int64) bool
}

FSCompiler is an interface that must be satisfied for a file-system compipler to be usable in this logic.

type GPTEntry

type GPTEntry struct {
	TypeGUID      [16]byte
	PartitionGUID [16]byte
	FirstLBA      uint64
	LastLBA       uint64

	Name [72]byte
	// contains filtered or unexported fields
}

GPTEntry is the structure of a GUID Partition Table entry as it appears on disk.

type GPTHeader

type GPTHeader struct {
	Signature  uint64
	Revision   [4]byte
	HeaderSize uint32
	CRC        uint32

	CurrentLBA     uint64
	BackupLBA      uint64
	FirstUsableLBA uint64
	LastUsableLBA  uint64
	GUID           [16]byte
	StartLBAParts  uint64
	NoOfParts      uint32
	SizePartEntry  uint32
	CRCParts       uint32
	// contains filtered or unexported fields
}

GPTHeader is the structure of a GUID Partition Table Header as it appears on disk.

type KernelOptions

type KernelOptions struct {
	Record bool
	Shell  bool
}

KernelOptions for settings that change kernel behaviour.

type ProtectiveMBR

type ProtectiveMBR struct {
	Bootloader [446]byte
	Status     byte

	PartitionType byte

	FirstLBA     uint32
	TotalSectors uint32

	MagicNumber [2]byte
	// contains filtered or unexported fields
}

ProtectiveMBR is the structure of a protective master boot record as it appears on disk.

Jump to

Keyboard shortcuts

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