initramfs

package
v0.0.0-...-899a47e Latest Latest
Warning

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

Go to latest
Published: Feb 28, 2024 License: BSD-3-Clause Imports: 9 Imported by: 0

Documentation

Overview

Package initramfs can write archives out to CPIO or directories.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNoPath = errors.New("invalid argument: must specify path")
)

Possible errors.

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 Archive

type Archive struct {
	*cpio.Archive
}

Archive opens a Reader that reads files from an in-memory archive.

func (*Archive) OpenReader

func (a *Archive) OpenReader() (cpio.RecordReader, error)

OpenReader opens the archive for reading.

func (*Archive) OpenWriter

func (a *Archive) OpenWriter() (Writer, error)

OpenWriter writes to the archive.

type CPIOFile

type CPIOFile struct {
	Path string
}

CPIOFile opens a Reader or Writer that reads/writes files from/to a CPIO archive at the given path.

func (*CPIOFile) OpenReader

func (c *CPIOFile) OpenReader() (cpio.RecordReader, error)

OpenReader opens c.Path for reading.

func (*CPIOFile) OpenWriter

func (c *CPIOFile) OpenWriter() (Writer, error)

OpenWriter opens c.Path for writing.

type Dir

type Dir struct {
	Path string
}

Dir opens a Writer that writes all archive files to the given directory.

func (*Dir) OpenWriter

func (d *Dir) OpenWriter() (Writer, error)

OpenWriter implements Archiver.OpenWriter.

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. It follows symlinks.

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

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

AddFileNoFollow adds a host file at src into the archive at dest. It does not follow symlinks.

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 WriteOpener

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

	// 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 ReadOpener

type ReadOpener interface {
	OpenReader() (cpio.RecordReader, error)
}

ReadOpener opens a cpio.RecordReader.

type WriteOpener

type WriteOpener interface {
	OpenWriter() (Writer, error)
}

WriteOpener opens a Writer.

type Writer

type Writer interface {
	cpio.RecordWriter

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

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

Directories

Path Synopsis
nolint
nolint

Jump to

Keyboard shortcuts

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