vfs

package
v0.31.0 Latest Latest
Warning

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

Go to latest
Published: Jun 19, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MethodRoot       = "pxar.Root"
	MethodLookup     = "pxar.Lookup"
	MethodReadDir    = "pxar.ReadDir"
	MethodGetAttr    = "pxar.GetAttr"
	MethodRead       = "pxar.Read"
	MethodReadStream = "pxar.ReadStream"
	MethodReadLink   = "pxar.ReadLink"
	MethodListXAttrs = "pxar.ListXAttrs"
	MethodError      = "pxar.Error"
	MethodDone       = "pxar.Done"
)

Offset method constants for RPC routing.

Variables

This section is empty.

Functions

This section is empty.

Types

type FileSystem

type FileSystem interface {
	// Root returns the root directory entry.
	Root() (*pxar.FileInfo, error)

	// Lookup finds an entry by archive-internal path.
	Lookup(path string) (*pxar.FileInfo, error)

	// ReadDir lists entries in a directory identified by content offset
	// or entry range end. The offset is resolved to content offset
	// internally via the cache.
	ReadDir(offset uint64) ([]pxar.FileInfo, error)

	// GetAttr returns attributes for an entry identified by its
	// file offset (pxar.Entry.FileOffset).
	GetAttr(entryStart uint64) (*pxar.FileInfo, error)

	// Read reads raw file content from a content range.
	// contentStart is the ContentOffset, offset is the byte offset
	// within the content, size is the number of bytes to read.
	Read(contentStart, contentEnd, offset uint64, size uint) ([]byte, error)

	// ReadContentReader returns a streaming reader for an entire file,
	// looked up by content start offset. The caller must close the reader.
	ReadContentReader(contentStart, contentEnd uint64) (io.ReadCloser, error)

	// ReadLink returns the target of a symlink identified by entry offset.
	ReadLink(entryStart uint64) ([]byte, error)

	// ListXAttrs returns extended attributes for an entry identified
	// by entry offset. Re-reads full metadata if the cached entry was
	// decoded with minimal mode.
	ListXAttrs(entryStart uint64) (map[string][]byte, error)

	// Close releases all resources.
	Close() error
}

FileSystem provides offset-based access to a pxar archive. Operations use byte offsets from the archive structure (entry offsets, content offsets). This mirrors the wire protocol used by PBS agents for restore operations.

Thread safety: all methods are safe for concurrent use.

type LocalFS added in v0.24.0

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

LocalFS implements FileSystem backed by a transfer.ArchiveReader. It maintains offset-based caches for entry lookup, content lookup, and directory range resolution — matching the PBS wire protocol patterns.

func NewLocalFS

func NewLocalFS(reader transfer.ArchiveReader) *LocalFS

NewLocalFS creates an offset-based filesystem backed by an ArchiveReader.

func (*LocalFS) Close added in v0.24.0

func (fs *LocalFS) Close() error

Close releases all resources.

func (*LocalFS) GetAttr added in v0.24.0

func (fs *LocalFS) GetAttr(entryStart uint64) (*pxar.FileInfo, error)

GetAttr returns attributes for an entry by file offset.

func (*LocalFS) ListXAttrs added in v0.24.0

func (fs *LocalFS) ListXAttrs(entryStart uint64) (map[string][]byte, error)

ListXAttrs returns extended attributes for an entry by offset.

func (*LocalFS) Lookup added in v0.24.0

func (fs *LocalFS) Lookup(path string) (*pxar.FileInfo, error)

Lookup finds an entry by archive-internal path.

func (*LocalFS) Read added in v0.24.0

func (fs *LocalFS) Read(contentStart, contentEnd, offset uint64, size uint) ([]byte, error)

Read reads raw file content from a content range.

func (*LocalFS) ReadContentReader added in v0.24.0

func (fs *LocalFS) ReadContentReader(contentStart, contentEnd uint64) (io.ReadCloser, error)

ReadContentReader returns a streaming reader for file content by offset.

func (*LocalFS) ReadDir added in v0.24.0

func (fs *LocalFS) ReadDir(offset uint64) ([]pxar.FileInfo, error)

ReadDir lists entries in a directory identified by offset. The offset may be a ContentOffset or a legacy EntryRangeEnd — it is resolved to ContentOffset via the internal cache.

func (fs *LocalFS) ReadLink(entryStart uint64) ([]byte, error)

ReadLink returns the symlink target by entry offset.

func (*LocalFS) Reader added in v0.24.0

func (fs *LocalFS) Reader() transfer.ArchiveReader

Reader returns the underlying ArchiveReader for advanced operations.

func (*LocalFS) Root added in v0.24.0

func (fs *LocalFS) Root() (*pxar.FileInfo, error)

Root returns the root directory entry.

func (*LocalFS) Stats added in v0.24.0

func (fs *LocalFS) Stats() Stats

Stats returns current read progress statistics.

type RPCTransport

type RPCTransport interface {
	// Call invokes a remote method with a typed request/response.
	Call(ctx context.Context, method string, req, resp any) error

	// CallBinary invokes a remote method that returns raw bytes.
	// Copies into dst and returns the number of bytes written.
	CallBinary(ctx context.Context, method string, req any, dst []byte) (int, error)

	// CallStream invokes a remote method that returns a stream.
	CallStream(ctx context.Context, method string, req any) (io.ReadCloser, error)

	// Close releases transport resources.
	Close() error
}

RPCTransport is the transport interface for offset-based remote FS. Implement this to bridge to any wire format or transport (arpc, gRPC, etc.).

type RemoteFS

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

RemoteFS implements FileSystem over an RPCTransport.

func NewRemoteFS

func NewRemoteFS(transport RPCTransport) *RemoteFS

NewRemoteFS creates an FileSystem backed by an RPCTransport.

func (*RemoteFS) Close added in v0.24.0

func (fs *RemoteFS) Close() error

func (*RemoteFS) GetAttr added in v0.24.0

func (fs *RemoteFS) GetAttr(entryStart uint64) (*pxar.FileInfo, error)

func (*RemoteFS) ListXAttrs added in v0.24.0

func (fs *RemoteFS) ListXAttrs(entryStart uint64) (map[string][]byte, error)

func (*RemoteFS) Lookup added in v0.24.0

func (fs *RemoteFS) Lookup(path string) (*pxar.FileInfo, error)

func (*RemoteFS) Read added in v0.24.0

func (fs *RemoteFS) Read(contentStart, contentEnd, offset uint64, size uint) ([]byte, error)

func (*RemoteFS) ReadContentReader added in v0.24.0

func (fs *RemoteFS) ReadContentReader(contentStart, contentEnd uint64) (io.ReadCloser, error)

func (*RemoteFS) ReadDir added in v0.24.0

func (fs *RemoteFS) ReadDir(offset uint64) ([]pxar.FileInfo, error)
func (fs *RemoteFS) ReadLink(entryStart uint64) ([]byte, error)

func (*RemoteFS) Root added in v0.24.0

func (fs *RemoteFS) Root() (*pxar.FileInfo, error)

type RemoteServer

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

RemoteServer serves FileSystem operations as typed handler methods. Register each handler with your RPC framework using the Method* constants.

Example with arpc:

srv := vfs.NewRemoteServer(offsetFS)
router.Handle("pxar.Root", func(req *arpc.Request) (arpc.Response, error) {
    fi, err := srv.HandleRoot()
    data, _ := cbor.Marshal(fi)
    return arpc.Response{Status: 200, Data: data}, err
})

func NewRemoteServer

func NewRemoteServer(fs FileSystem) *RemoteServer

NewRemoteServer creates a server that dispatches to the given FileSystem.

func (*RemoteServer) HandleDone

func (s *RemoteServer) HandleDone() error

HandleDone signals session completion.

func (*RemoteServer) HandleError

func (s *RemoteServer) HandleError(errMsg string) error

HandleError receives a client-reported error.

func (*RemoteServer) HandleGetAttr added in v0.24.0

func (s *RemoteServer) HandleGetAttr(entryStart uint64) (*pxar.FileInfo, error)

HandleGetAttr returns entry attributes by file offset.

func (*RemoteServer) HandleListXAttrs

func (s *RemoteServer) HandleListXAttrs(entryStart uint64) (map[string][]byte, error)

HandleListXAttrs returns extended attributes.

func (*RemoteServer) HandleLookup added in v0.24.0

func (s *RemoteServer) HandleLookup(path string) (*pxar.FileInfo, error)

HandleLookup finds an entry by path.

func (*RemoteServer) HandleRead

func (s *RemoteServer) HandleRead(contentStart, contentEnd, offset uint64, size uint) ([]byte, error)

HandleRead reads raw file content.

func (*RemoteServer) HandleReadDir

func (s *RemoteServer) HandleReadDir(offset uint64) ([]pxar.FileInfo, error)

HandleReadDir lists directory entries by offset.

func (s *RemoteServer) HandleReadLink(entryStart uint64) ([]byte, error)

HandleReadLink returns symlink target.

func (*RemoteServer) HandleReadStream added in v0.24.0

func (s *RemoteServer) HandleReadStream(contentStart, contentEnd uint64) (io.ReadCloser, error)

HandleReadStream returns a streaming reader for file content.

func (*RemoteServer) HandleRoot added in v0.24.0

func (s *RemoteServer) HandleRoot() (*pxar.FileInfo, error)

HandleRoot returns the root entry.

type Stats added in v0.24.0

type Stats struct {
	FilesAccessed   int64
	FoldersAccessed int64
	TotalBytes      int64
}

Stats holds read progress statistics.

type StatsProvider added in v0.22.0

type StatsProvider interface {
	Stats() Stats
}

StatsProvider is an optional interface that offset filesystems can implement to expose read progress statistics.

Jump to

Keyboard shortcuts

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