initramfs

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Oct 1, 2018 License: BSD-3-Clause Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	CPIO = CPIOArchiver{
		RecordFormat: cpio.Newc,
	}

	Dir = DirArchiver{}

	// Archivers are the supported initramfs archivers at the moment.
	//
	// - cpio: writes the initramfs to a cpio.
	// - dir:  writes the initramfs relative to a specified directory.
	Archivers = map[string]Archiver{
		"cpio": CPIO,
		"dir":  Dir,
	}
)

Functions

func Write

func Write(opts *Opts) error

Write uses the given options to determine which files to write to the output initramfs.

Types

type Archiver

type Archiver interface {
	// OpenWriter opens an archive writer at `path`.
	//
	// If `path` is unspecified, implementations may choose an arbitrary
	// default location, potentially based on `goos` and `goarch`.
	OpenWriter(path, goos, goarch string) (Writer, error)

	// Reader returns a Reader that allows reading files from a file.
	Reader(file io.ReaderAt) Reader
}

Archiver is an archive format that builds an archive using a given set of files.

func GetArchiver

func GetArchiver(name string) (Archiver, error)

GetArchiver finds a registered initramfs archiver by name.

Good to use with command-line arguments.

type CPIOArchiver

type CPIOArchiver struct {
	cpio.RecordFormat
}

CPIOArchiver is an implementation of Archiver for the cpio format.

func (CPIOArchiver) OpenWriter

func (ca CPIOArchiver) OpenWriter(path, goos, goarch string) (Writer, error)

OpenWriter opens `path` as the correct file type and returns an Writer pointing to `path`.

If `path` is empty, a default path of /tmp/initramfs.GOOS_GOARCH.cpio is used.

func (CPIOArchiver) Reader

func (ca CPIOArchiver) Reader(r io.ReaderAt) Reader

Reader implements Archiver.Reader.

type DirArchiver

type DirArchiver struct{}

DirArchiver implements Archiver for a directory.

func (DirArchiver) OpenWriter

func (da DirArchiver) OpenWriter(path, goos, goarch string) (Writer, error)

OpenWriter implements Archiver.OpenWriter.

func (DirArchiver) Reader

func (da DirArchiver) Reader(io.ReaderAt) Reader

Reader implements Archiver.Reader.

Currently unsupported for directories.

type Files

type Files struct {
	// Files is a map of relative archive path -> absolute host file path.
	Files map[string]string

	// Records is a map of relative archive path -> Record to use.
	//
	// TODO: While the only archive mode is cpio, this will be a
	// cpio.Record. If or when there is another archival mode, we can add a
	// similar uroot.Record type.
	Records map[string]cpio.Record
}

Files are host files and records to add to the resulting initramfs.

func NewFiles

func NewFiles() *Files

NewFiles returns a new archive files map.

func (*Files) AddFile

func (af *Files) AddFile(src string, dest string) error

AddFile adds a host file at src into the archive at dest.

If src is a directory, it and its children will be added to the archive relative to dest.

Duplicate files with identical content will be silently ignored.

func (*Files) AddRecord

func (af *Files) AddRecord(r cpio.Record) error

AddRecord adds a cpio.Record into the archive at `r.Name`.

func (*Files) Contains

func (af *Files) Contains(dest string) bool

Contains returns whether path `dest` is already contained in the archive.

func (*Files) Rename

func (af *Files) Rename(name string, newname string)

Rename renames a file in the archive.

func (*Files) WriteTo

func (af *Files) WriteTo(w Writer) error

WriteTo writes all records and files in `af` to `w`.

type Opts

type Opts struct {
	// Files are the files to be included.
	//
	// Files here generally have priority over files in DefaultRecords or
	// BaseArchive.
	*Files

	// OutputFile is the file to write to.
	OutputFile Writer

	// BaseArchive is an existing archive to add files to.
	//
	// BaseArchive may be nil.
	BaseArchive Reader

	// UseExistingInit determines whether the init from BaseArchive is used
	// or not, if BaseArchive is specified.
	//
	// If this is false, the "init" file in BaseArchive will be renamed
	// "inito" (for init-original) in the output archive.
	UseExistingInit bool
}

Opts are options for building an initramfs archive.

type Reader

type Reader cpio.RecordReader

Reader is an object that files can be read from.

type Writer

type Writer interface {
	cpio.RecordWriter

	// Finish finishes the archive.
	Finish() error
}

Writer is an initramfs archive that files can be written to.

Jump to

Keyboard shortcuts

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