cpio

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Aug 15, 2018 License: BSD-3-Clause Imports: 12 Imported by: 302

Documentation

Index

Constants

View Source
const Trailer = "TRAILER!!!"

Trailer is the name of the trailer record.

Variables

View Source
var (
	Debug = func(string, ...interface{}) {}
)
View Source
var TrailerRecord = StaticRecord(nil, Info{Name: Trailer})

TrailerRecord is the last record in any CPIO archive.

Functions

func AllEqual

func AllEqual(r []Record, s []Record) bool

func Concat

func Concat(w RecordWriter, r RecordReader, transform func(Record) Record) error

Concat reads files from r one at a time, and writes them to w.

func CreateFile

func CreateFile(f Record) error

func CreateFileInRoot

func CreateFileInRoot(f Record, rootDir string) error

func Equal

func Equal(r Record, s Record) bool

func ForEachRecord

func ForEachRecord(rr RecordReader, fun func(Record) error) error

ForEachRecord reads every record from r and applies f.

func MakeAllReproducible

func MakeAllReproducible(files []Record)

MakeAllReproducible makes all given records reproducible as in MakeReproducible.

func NewLazyFile added in v0.2.0

func NewLazyFile(name string) io.ReaderAt

func Normalize

func Normalize(path string) string

Normalize normalizes path to be relative to /.

func Passthrough

func Passthrough(r RecordReader, w RecordWriter) error

Passthrough copies from a RecordReader to a RecordWriter It processes one record at a time to minimize the memory footprint.

func ReaderAtEqual added in v0.2.0

func ReaderAtEqual(r1, r2 io.ReaderAt) bool

func WriteRecords

func WriteRecords(w RecordWriter, files []Record) error

WriteRecords writes multiple records.

func WriteTrailer

func WriteTrailer(w RecordWriter) error

WriteTrailer writes the trailer record.

Types

type Archive

type Archive struct {
	// Files is a map of relative archive path -> record.
	Files map[string]Record

	// Order is a list of relative archive paths and represents the order
	// in which Files were added.
	Order []string
}

Archive implements RecordWriter and is an in-memory list of files.

Archive.Reader returns a RecordReader for this archive.

func InMemArchive

func InMemArchive() *Archive

InMemArchive returns an in-memory file archive.

func ReadArchive added in v0.2.0

func ReadArchive(rr RecordReader) (*Archive, error)

ReadArchive reads the entire archive in-memory and makes it accessible by paths.

func (*Archive) Contains

func (a *Archive) Contains(r Record) bool

Contains returns true if a record matching r is in the archive.

func (*Archive) Reader

func (a *Archive) Reader() RecordReader

Reader returns a RecordReader for the archive.

func (*Archive) WriteRecord

func (a *Archive) WriteRecord(r Record) error

WriteRecord implements RecordWriter and adds a record to the archive.

type DedupWriter

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

DedupWriter is a RecordWriter that does not write more than one record with the same path.

There seems to be no harm done in stripping duplicate names when the record is written, and lots of harm done if we don't do it.

func (*DedupWriter) WriteRecord

func (dw *DedupWriter) WriteRecord(rec Record) error

WriteRecord implements RecordWriter.

If rec.Name was already seen once before, it will not be written again and WriteRecord returns nil.

type EOFReader

type EOFReader struct {
	RecordReader
}

EOFReader is a RecordReader that converts the Trailer record to io.EOF.

func (EOFReader) ReadRecord

func (r EOFReader) ReadRecord() (Record, error)

ReadRecord implements RecordReader.

ReadRecord returns io.EOF when the record name is TRAILER!!!.

type Info

type Info struct {
	Ino      uint64
	Mode     uint64
	UID      uint64
	GID      uint64
	NLink    uint64
	MTime    uint64
	FileSize uint64
	Dev      uint64
	Major    uint64
	Minor    uint64
	Rmajor   uint64
	Rminor   uint64
	Name     string
}

Info holds metadata about files.

func (Info) String

func (i Info) String() string

type Record

type Record struct {
	// ReaderAt contains the content of this CPIO record.
	io.ReaderAt

	// Info is metadata describing the CPIO record.
	Info
}

Record represents a CPIO record, which represents a Unix file.

func CharDev

func CharDev(name string, perm uint64, rmajor, rminor uint64) Record

CharDev returns a character device record at name.

func Directory

func Directory(name string, mode uint64) Record

Directory returns a directory record at name.

func GetRecord added in v0.2.0

func GetRecord(path string) (Record, error)

func MakeReproducible

func MakeReproducible(r Record) Record

MakeReproducible changes any fields in a Record such that if we run cpio again, with the same files presented to it in the same order, and those files have unchanged contents, the cpio file it produces will be bit-for-bit identical. This is an essential property for firmware-embedded payloads.

func ReadAllRecords

func ReadAllRecords(rr RecordReader) ([]Record, error)

ReadAllRecords returns all records in `r` in the order in which they were read.

func StaticFile

func StaticFile(name string, content string, perm uint64) Record

func StaticRecord

func StaticRecord(contents []byte, info Info) Record
func Symlink(name string, target string) Record

Symlink returns a symlink record at name pointing to target.

type RecordFormat

type RecordFormat interface {
	Reader(r io.ReaderAt) RecordReader
	Writer(w io.Writer) RecordWriter
}

A RecordFormat gives readers and writers for dealing with archives.

var (
	// Newc is the newc CPIO record format.
	Newc RecordFormat = newc{/* contains filtered or unexported fields */}
)

func Format

func Format(name string) (RecordFormat, error)

Format returns the RecordFormat with that name, if it exists.

type RecordReader

type RecordReader interface {
	ReadRecord() (Record, error)
}

A RecordReader reads one record from an archive.

type RecordWriter

type RecordWriter interface {
	WriteRecord(Record) error
}

A RecordWriter writes on record to an archive.

func NewDedupWriter

func NewDedupWriter(rw RecordWriter) RecordWriter

NewDedupWriter returns a new deduplicating rw.

Jump to

Keyboard shortcuts

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