c

package
v0.5.2 Latest Latest
Warning

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

Go to latest
Published: Feb 27, 2024 License: MIT Imports: 19 Imported by: 1

Documentation

Overview

Package c provides common interfaces and functionality for all supported read-only filesystems.

Index

Constants

View Source
const MTATag = "user.drpetag"
View Source
const SignTag = "user.drpsign"

Variables

View Source
var Zeroes io.ReaderAt = z{}

Zeroes is an io.Reader and an io.ReaderAt that returns an endless stream of zeroes.

Zstd is our preallocated zstd decoder. It is intended to be used for zstd.DecodeAll operations.

Functions

func CheckSignatures added in v0.5.1

func CheckSignatures(fi fs.File, keys ...ed25519.PublicKey) (err error)

CheckSignatures checks to see if the SHA256sum of fi (as recorded in the MTATag extended attribute) has been signed with one of the provided keys. It returns fs.ErrNotExist if neither the MTATag nor the SignTag extended attributes are valid, fs.ErrInvalid if the MTATag is out of date or the SignTag fails validation with any of the provided keys. If the file is signed appropriately, then it returns nil.

func ProcessSymlink(parts []string, offset int, sl string) ([]string, error)

ProcessSymlink handles generating a new target path given a source path , the offset in the source path, that the symbolic link was found at, and a symbolic link.

func ReadXattr added in v0.5.2

func ReadXattr(fi fs.File, k string) (string, error)

func SaveXattr added in v0.5.2

func SaveXattr(fi *os.File, k, v string) (err error)

func SignFile added in v0.5.1

func SignFile(key ed25519.PrivateKey, fi *os.File) (err error)

SignFile signs the SHA256sum of the provided fi with the provided signature. The signature is stored in the SignTag extended attribute upon success.

func SignHash added in v0.5.1

func SignHash(key ed25519.PrivateKey, sum []byte) (signature []byte, err error)

Types

type Buffer

type Buffer struct {
	SimpleBuffer
	// contains filtered or unexported fields
}

Buffer is an exact sized buffer. Unlike a bytes.Buffer, it never grows beyond the capacity of the slice. it is used where we know there is a fixed upper bound to the amount of data we are going to have it hold.

func NewBuffer

func NewBuffer(b []byte) *Buffer

NewBuffer creates a new Buffer. The total size is fixed to the size of the byte slice that is passed in.

func (*Buffer) Len

func (b *Buffer) Len() int

Len returns the length of the unread part of the Buffer.

func (*Buffer) Read

func (b *Buffer) Read(buf []byte) (int, error)

Read implements io.Reader

func (*Buffer) ReadByte

func (b *Buffer) ReadByte() (byte, error)

ReadByte returns the next byte in the Buffer.

func (*Buffer) Seek

func (b *Buffer) Seek(offset int64, whence int) (n int64, err error)

Seek changes the read and write offset in the Buffer. It implements io.Seeker

func (*Buffer) WriteTo

func (b *Buffer) WriteTo(w io.Writer) (int64, error)

WriteTo implements io.WriterTo.

type ByteFetcher

type ByteFetcher interface {
	io.ReaderAt
	WithBytesAt(offset int64, size uint, f func([]byte) error) error
}

ByteFetcher is satisfied by anything that can directly return a byte slice from an io.ReaderAt without needing to perform extra IO or byte copies. The intent is to eventually use this and mmap to optimize IO.

type Extents added in v0.4.1

type Extents []extent

Extents keep track of byte ranges and offsets in underlying Filesystems.

func AllocExtents added in v0.4.1

func AllocExtents(size int) Extents

AllocExtents allocates Extents. The passed size is used to separate requested extent sizes into buckets and allow different sizes of Extents to have their own pools. Extents allocated using this function will be released internally as part of Reader.ReadAt and Reader.WriteTo.

Extents returned from this function will have 0 length.

func (Extents) Append added in v0.4.1

func (ex Extents) Append(src io.ReaderAt, offset int64, size int64) Extents

Append a range to the passed-in Extents.

type File

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

File implements fs.File and Src.

func (*File) Close

func (f *File) Close() error

Close closes a File.

func (*File) ReadDir

func (f *File) ReadDir(count int) (dents []fs.DirEntry, err error)

ReadDir returns the requested directory entries, or an error if the File is not a directory.

func (*File) Stat

func (f *File) Stat() (fs.FileInfo, error)

Stat gets the fs.FileInfo for an open File. We just return the Inode, which satisfies the fs.FileInfo interface.

type Filesystem

type Filesystem struct {
	InodeProvider
}

Filesystem provides common functionality needed to implement fs.FS and associated interfaces in a standard way for all supported read-only filesystems.

func (Filesystem) Lookup

func (f Filesystem) Lookup(name string, followSymlinks bool) (ent Inode, err error)

Lookup returns the inode for a given path. If followSymlink is false and a symlink is found in the path, it will be followed anyway. If however the target file is a symlink, then its inode will be returned. There are caching opportunities here.

func (Filesystem) Lstat

func (f Filesystem) Lstat(path string) (fi fs.FileInfo, err error)

Lstat returns the fs.FileInfo for the File at path. If the final target is a symbolic link, the stat information for the link will be returned instead of following the symbolic link.

func (Filesystem) Open

func (f Filesystem) Open(p string) (res fs.File, err error)

Open opens the fs.File at a p.

func (Filesystem) ReadDir

func (f Filesystem) ReadDir(p string) (res []fs.DirEntry, err error)

ReadDir returns the directory listings at p, or returns an error if p is not a directory.

func (f Filesystem) ReadLink(p string) (link string, err error)

ReadLink reads the symbolic link target at p. If p does not resolve to a link, an error will be returned.

func (Filesystem) ReadXattrs added in v0.5.0

func (f Filesystem) ReadXattrs(p string) (map[string]string, error)

ReadXattrs returns the extended attributes associated with p, or return nil if there are no extended attributes or if we cannot read extended attributes from the underlying archive.

func (Filesystem) Stat

func (f Filesystem) Stat(path string) (fi fs.FileInfo, err error)

Stat returns the fs.FileInfo for the File at path. It will follow all symbolic links.

type GetExtents

type GetExtents func(offset, size int64) Extents

GetExtents is a function that fetches a sufficient number of Extents to satisfy the Read or ReadAt request. There must be no gaps in the Extents returned -- the Offset of extent n+1 must equal Offset + Size of extent n. If no Extents are returned, the Reader functions will interpret that as io.EOF, and if the aggregate size of the Extents is not equal to size, the Reader functions will interpret that as trying to read past the end of the File and handle that appropriately.

func (GetExtents) Reader

func (e GetExtents) Reader() *Reader

Reader creates a *Reader from the GetExtents iterator.

type Inode

type Inode interface {
	fs.DirEntry
	fs.FileInfo
	Open() *Reader
	IsSymlink() bool
	ReadLink() (string, error)
	ReadDir() ([]fs.DirEntry, error)
	ReadXattrs() map[string]string
}

Inode is what filesystems in this package must provide when the common routines want to access a file in a filesystem.

type InodeProvider

type InodeProvider interface {
	Root() Inode
	Close() error
}

InodeProvider is the interface that all filesystems using these common routines must satisfy file lookup requests. The common code handles looking up inodes to properly handle symlink resolution, which can get tricky.

type MmappedSrc added in v0.4.0

type MmappedSrc interface {
	io.Closer
	Src
}

func Mmap added in v0.4.0

func Mmap(src Src) MmappedSrc

Mmap will return an open memory-mapped version of src if src is really an *os.File, otherwise it will return nil. The caller is responsible for making sure that the resulting object is Closed when you are finished with it. When the returned MmapedSrc is used as an argument to rofs.Open or the individual package Open functions, the common routines in c will recognize that the backing file is memory-mapped and optimize handling to reduce the number of data copies that are required as part of extent handling, and using io.Copy and friends will default to zero copy behaviour to the extent possible. Use of Mmap is optional.

type ModTimeSha added in v0.5.0

type ModTimeSha struct {
	ModTime time.Time
	ShaSum  []byte
}

func ReadMTA added in v0.5.0

func ReadMTA(s fs.FS, p string) (res *ModTimeSha, upToDate bool, err error)

func (*ModTimeSha) Generate added in v0.5.0

func (m *ModTimeSha) Generate(fi fs.File) error

func (*ModTimeSha) GenerateStat added in v0.5.0

func (m *ModTimeSha) GenerateStat(fi fs.File, stat fs.FileInfo) error

func (*ModTimeSha) MarshalBinary added in v0.5.0

func (m *ModTimeSha) MarshalBinary() ([]byte, error)

func (*ModTimeSha) ReadFromXattr added in v0.5.0

func (m *ModTimeSha) ReadFromXattr(fi fs.File) error

func (*ModTimeSha) Regenerate added in v0.5.0

func (m *ModTimeSha) Regenerate(fi *os.File) (bool, error)

func (*ModTimeSha) SaveToXattr added in v0.5.0

func (m *ModTimeSha) SaveToXattr(fi *os.File) error

func (*ModTimeSha) String added in v0.5.0

func (m *ModTimeSha) String() string

func (*ModTimeSha) UnmarshalBinary added in v0.5.0

func (m *ModTimeSha) UnmarshalBinary(buf []byte) error

func (*ModTimeSha) UpToDate added in v0.5.0

func (m *ModTimeSha) UpToDate(fi fs.File) bool

type NoData

type NoData struct{ Err error }

NoData is a basic Src used when a File doesn't have data backing it. All file-ish functions will return the specified error instead.

func (NoData) Read

func (n NoData) Read([]byte) (int, error)

func (NoData) ReadAt

func (n NoData) ReadAt([]byte, int64) (int, error)

func (NoData) Seek

func (n NoData) Seek(int64, int) (int64, error)

func (NoData) WriteTo

func (n NoData) WriteTo(io.Writer) (int64, error)

type Reader

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

Reader implements Src methods for the *File structs returned from this package. As a bonus, it also implements io.WriterTo.

func (*Reader) Read

func (e *Reader) Read(buf []byte) (int, error)

Read implements io.Reader for a Reader.

func (*Reader) ReadAt

func (e *Reader) ReadAt(buf []byte, offset int64) (readsize int, err error)

ReadAt implements io.ReaderAt for a Reader. It is responsible for handling the case where a single ReadAt call may cross multiple Extents.

func (*Reader) Seek

func (e *Reader) Seek(offset int64, whence int) (int64, error)

Seek implements io.Seeker for a Reader

func (*Reader) WriteTo

func (e *Reader) WriteTo(w io.Writer) (written int64, err error)

WriteTo implements io.WriterTo for a Reader.

type SimpleBuffer

type SimpleBuffer []byte

SimpleBuffer is a very basic wrapper around a mostly static byte buffer

func (SimpleBuffer) BytesAt

func (s SimpleBuffer) BytesAt(offset int64, size uint) (buf []byte, err error)

BytesAt returns a slice covering the requested byte range in the buffer.

func (SimpleBuffer) Clear

func (s SimpleBuffer) Clear()

Clear zeros out the buffer.

func (SimpleBuffer) ReadAt

func (s SimpleBuffer) ReadAt(buf []byte, offset int64) (n int, err error)

ReaAt implements io.ReaderAt

func (SimpleBuffer) Size

func (s SimpleBuffer) Size() int64

Size returns the size of the buffer.

func (SimpleBuffer) WithBytesAt

func (s SimpleBuffer) WithBytesAt(offset int64, size uint, f func([]byte) error) error

WithBytesAt call f with a slice covering the requested byte range.

type Src

type Src interface {
	io.ReadSeeker
	io.ReaderAt
}

Src is anything we can use to provide a filesystem. All filesystems using the common routines in this package also provide fs.Files that satisfy this interface.

type WriteBuffer

type WriteBuffer struct {
	Buffer
}

func NewWriteBuffer

func NewWriteBuffer(b []byte) *WriteBuffer

NewBuffer creates a new Buffer. The total size is fixed to the size of the byte slice that is passed in.

func (*WriteBuffer) Bytes

func (w *WriteBuffer) Bytes() []byte

Bytes returns the written bytes in the buffer.

func (*WriteBuffer) Write

func (w *WriteBuffer) Write(buf []byte) (int, error)

Write implements io.Writer

Jump to

Keyboard shortcuts

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