Documentation
¶
Overview ¶
Package c provides common interfaces and functionality for all supported read-only filesystems.
Index ¶
- Constants
- Variables
- func CheckSignatures(fi fs.File, keys ...ed25519.PublicKey) (err error)
- func ProcessSymlink(parts []string, offset int, sl string) ([]string, error)
- func ReadXattr(fi fs.File, k string) (string, error)
- func SaveXattr(fi *os.File, k, v string) (err error)
- func SignFile(key ed25519.PrivateKey, fi *os.File) (err error)
- func SignHash(key ed25519.PrivateKey, sum []byte) (signature []byte, err error)
- type Buffer
- type ByteFetcher
- type Extents
- type File
- type Filesystem
- func (f Filesystem) Lookup(name string, followSymlinks bool) (ent Inode, err error)
- func (f Filesystem) Lstat(path string) (fi fs.FileInfo, err error)
- func (f Filesystem) Open(p string) (res fs.File, err error)
- func (f Filesystem) ReadDir(p string) (res []fs.DirEntry, err error)
- func (f Filesystem) ReadLink(p string) (link string, err error)
- func (f Filesystem) ReadXattrs(p string) (map[string]string, error)
- func (f Filesystem) Stat(path string) (fi fs.FileInfo, err error)
- type GetExtents
- type Inode
- type InodeProvider
- type MmappedSrc
- type ModTimeSha
- func (m *ModTimeSha) Generate(fi fs.File) error
- func (m *ModTimeSha) GenerateStat(fi fs.File, stat fs.FileInfo) error
- func (m *ModTimeSha) MarshalBinary() ([]byte, error)
- func (m *ModTimeSha) ReadFromXattr(fi fs.File) error
- func (m *ModTimeSha) Regenerate(fi *os.File) (bool, error)
- func (m *ModTimeSha) SaveToXattr(fi *os.File) error
- func (m *ModTimeSha) String() string
- func (m *ModTimeSha) UnmarshalBinary(buf []byte) error
- func (m *ModTimeSha) UpToDate(fi fs.File) bool
- type NoData
- type Reader
- type SimpleBuffer
- func (s SimpleBuffer) BytesAt(offset int64, size uint) (buf []byte, err error)
- func (s SimpleBuffer) Clear()
- func (s SimpleBuffer) ReadAt(buf []byte, offset int64) (n int, err error)
- func (s SimpleBuffer) Size() int64
- func (s SimpleBuffer) WithBytesAt(offset int64, size uint, f func([]byte) error) error
- type Src
- type WriteBuffer
Constants ¶
const MTATag = "user.drpetag"
const SignTag = "user.drpsign"
Variables ¶
var Zeroes io.ReaderAt = z{}
Zeroes is an io.Reader and an io.ReaderAt that returns an endless stream of zeroes.
var Zstd *zstd.Decoder
Zstd is our preallocated zstd decoder. It is intended to be used for zstd.DecodeAll operations.
Functions ¶
func CheckSignatures ¶ added in v0.5.1
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 ¶
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.
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 ¶
NewBuffer creates a new Buffer. The total size is fixed to the size of the byte slice that is passed in.
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
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.
type File ¶
type File struct {
// contains filtered or unexported fields
}
File implements fs.File and Src.
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 (Filesystem) ReadLink ¶
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.
type GetExtents ¶
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 ¶
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
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
func (*ModTimeSha) GenerateStat ¶ added in v0.5.0
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
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.
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) ReadAt ¶
ReadAt implements io.ReaderAt for a Reader. It is responsible for handling the case where a single ReadAt call may cross multiple Extents.
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) ReadAt ¶
func (s SimpleBuffer) ReadAt(buf []byte, offset int64) (n int, err error)
ReaAt implements io.ReaderAt
func (SimpleBuffer) WithBytesAt ¶
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.