vfs

package
v0.1.23 Latest Latest
Warning

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

Go to latest
Published: Feb 21, 2026 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AfterHookCallback added in v0.1.19

type AfterHookCallback interface {
	After(ctx context.Context, req HookRequest, result HookResult)
}

AfterHookCallback runs after the target VFS operation.

type AfterHookFunc added in v0.1.19

type AfterHookFunc func(ctx context.Context, req HookRequest, result HookResult)

AfterHookFunc adapts a function into AfterHookCallback.

func (AfterHookFunc) After added in v0.1.19

func (f AfterHookFunc) After(ctx context.Context, req HookRequest, result HookResult)

type BeforeHookCallback added in v0.1.19

type BeforeHookCallback interface {
	Before(ctx context.Context, req *HookRequest) error
}

BeforeHookCallback runs inline before the target VFS operation.

type BeforeHookFunc added in v0.1.19

type BeforeHookFunc func(ctx context.Context, req *HookRequest) error

BeforeHookFunc adapts a function into BeforeHookCallback.

func (BeforeHookFunc) Before added in v0.1.19

func (f BeforeHookFunc) Before(ctx context.Context, req *HookRequest) error

type DirEntry

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

func NewDirEntry

func NewDirEntry(name string, isDir bool, mode os.FileMode, info FileInfo) DirEntry

func (DirEntry) Info

func (de DirEntry) Info() (fs.FileInfo, error)

func (DirEntry) IsDir

func (de DirEntry) IsDir() bool

func (DirEntry) Name

func (de DirEntry) Name() string

func (DirEntry) Type

func (de DirEntry) Type() fs.FileMode

type FileInfo

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

func NewFileInfo

func NewFileInfo(name string, size int64, mode os.FileMode, modTime time.Time, isDir bool) FileInfo

func NewFileInfoWithSys added in v0.1.19

func NewFileInfoWithSys(name string, size int64, mode os.FileMode, modTime time.Time, isDir bool, sys any) FileInfo

func (FileInfo) IsDir

func (fi FileInfo) IsDir() bool

func (FileInfo) ModTime

func (fi FileInfo) ModTime() time.Time

func (FileInfo) Mode

func (fi FileInfo) Mode() os.FileMode

func (FileInfo) Name

func (fi FileInfo) Name() string

func (FileInfo) Size

func (fi FileInfo) Size() int64

func (FileInfo) Sys

func (fi FileInfo) Sys() any

type Handle

type Handle interface {
	io.Reader
	io.Writer
	io.Seeker
	io.Closer
	ReadAt(p []byte, off int64) (int, error)
	WriteAt(p []byte, off int64) (int, error)
	Stat() (FileInfo, error)
	Sync() error
	Truncate(size int64) error
}

type Hook added in v0.1.19

type Hook struct {
	Name    string
	Phase   HookPhase
	Matcher HookMatcher

	Before BeforeHookCallback
	After  AfterHookCallback

	// Async enqueues after-callback execution on the hook worker.
	Async bool
	// SideEffect marks callbacks that should be suppressed while hook-triggered
	// side effects are in-flight.
	SideEffect bool
}

Hook represents a callback-driven interception hook.

type HookAction added in v0.1.19

type HookAction string
const (
	HookActionAllow       HookAction = "allow"
	HookActionBlock       HookAction = "block"
	HookActionMutateWrite HookAction = "mutate_write"
)

type HookEngine added in v0.1.19

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

func NewHookEngine added in v0.1.19

func NewHookEngine(rules []HookRule) *HookEngine

NewHookEngine constructs a hook engine from declarative rules. Rules are compiled into callback hooks internally.

func NewHookEngineWithCallbacks added in v0.1.19

func NewHookEngineWithCallbacks(hooks []Hook) *HookEngine

NewHookEngineWithCallbacks constructs a hook engine from callback hooks.

func (*HookEngine) After added in v0.1.19

func (h *HookEngine) After(req HookRequest, result HookResult)

func (*HookEngine) Before added in v0.1.19

func (h *HookEngine) Before(req *HookRequest) error

func (*HookEngine) Close added in v0.1.19

func (h *HookEngine) Close()

func (*HookEngine) SetEventFunc added in v0.1.19

func (h *HookEngine) SetEventFunc(fn func(req HookRequest, result HookResult))

func (*HookEngine) Wait added in v0.1.19

func (h *HookEngine) Wait()

type HookFileMeta added in v0.1.19

type HookFileMeta struct {
	Size         int64
	Mode         os.FileMode
	UID          int
	GID          int
	HasOwnership bool
}

type HookMatcher added in v0.1.19

type HookMatcher interface {
	Match(req *HookRequest) bool
}

HookMatcher decides whether a hook should apply for a request.

type HookMatcherFunc added in v0.1.19

type HookMatcherFunc func(req *HookRequest) bool

HookMatcherFunc adapts a function into HookMatcher.

func (HookMatcherFunc) Match added in v0.1.19

func (f HookMatcherFunc) Match(req *HookRequest) bool

type HookOp added in v0.1.19

type HookOp string
const (
	HookOpStat      HookOp = "stat"
	HookOpReadDir   HookOp = "readdir"
	HookOpOpen      HookOp = "open"
	HookOpCreate    HookOp = "create"
	HookOpMkdir     HookOp = "mkdir"
	HookOpChmod     HookOp = "chmod"
	HookOpRemove    HookOp = "remove"
	HookOpRemoveAll HookOp = "remove_all"
	HookOpRename    HookOp = "rename"
	HookOpSymlink   HookOp = "symlink"
	HookOpReadlink  HookOp = "readlink"
	HookOpRead      HookOp = "read"
	HookOpWrite     HookOp = "write"
	HookOpClose     HookOp = "close"
	HookOpSync      HookOp = "sync"
	HookOpTruncate  HookOp = "truncate"
)

type HookPhase added in v0.1.19

type HookPhase string
const (
	HookPhaseBefore HookPhase = "before"
	HookPhaseAfter  HookPhase = "after"
)

type HookRequest added in v0.1.19

type HookRequest struct {
	Op      HookOp
	Path    string
	NewPath string
	Flags   int
	Mode    os.FileMode
	UID     int
	GID     int
	Offset  int64
	Data    []byte
}

type HookResult added in v0.1.19

type HookResult struct {
	Err   error
	Bytes int
	Meta  *HookFileMeta
}

type HookRule added in v0.1.19

type HookRule struct {
	Name        string
	Phase       HookPhase
	Ops         []HookOp
	PathPattern string
	Action      HookAction
	ActionFunc  func(ctx context.Context, req HookRequest) HookAction

	MutateWriteFunc MutateWriteFunc
	MutateWrite     []byte
}

type MemoryProvider

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

func NewMemoryProvider

func NewMemoryProvider() *MemoryProvider

func (*MemoryProvider) Chmod added in v0.1.10

func (p *MemoryProvider) Chmod(path string, mode os.FileMode) error

func (*MemoryProvider) Create

func (p *MemoryProvider) Create(path string, mode os.FileMode) (Handle, error)

func (*MemoryProvider) Mkdir

func (p *MemoryProvider) Mkdir(path string, mode os.FileMode) error

func (*MemoryProvider) MkdirAll

func (p *MemoryProvider) MkdirAll(path string, mode os.FileMode) error

func (*MemoryProvider) Open

func (p *MemoryProvider) Open(path string, flags int, mode os.FileMode) (Handle, error)

func (*MemoryProvider) ReadDir

func (p *MemoryProvider) ReadDir(path string) ([]DirEntry, error)

func (*MemoryProvider) ReadFile

func (p *MemoryProvider) ReadFile(path string) ([]byte, error)
func (p *MemoryProvider) Readlink(path string) (string, error)

func (*MemoryProvider) Readonly

func (p *MemoryProvider) Readonly() bool

func (*MemoryProvider) Remove

func (p *MemoryProvider) Remove(path string) error

func (*MemoryProvider) RemoveAll

func (p *MemoryProvider) RemoveAll(path string) error

func (*MemoryProvider) Rename

func (p *MemoryProvider) Rename(oldPath, newPath string) error

func (*MemoryProvider) Stat

func (p *MemoryProvider) Stat(path string) (FileInfo, error)
func (p *MemoryProvider) Symlink(target, link string) error

func (*MemoryProvider) WriteFile

func (p *MemoryProvider) WriteFile(path string, data []byte, mode os.FileMode) error

type MountRouter

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

func NewMountRouter

func NewMountRouter(mounts map[string]Provider) *MountRouter

func (*MountRouter) AddMount

func (r *MountRouter) AddMount(path string, provider Provider)

func (*MountRouter) Chmod added in v0.1.10

func (r *MountRouter) Chmod(path string, mode os.FileMode) error

func (*MountRouter) Create

func (r *MountRouter) Create(path string, mode os.FileMode) (Handle, error)

func (*MountRouter) Mkdir

func (r *MountRouter) Mkdir(path string, mode os.FileMode) error

func (*MountRouter) Open

func (r *MountRouter) Open(path string, flags int, mode os.FileMode) (Handle, error)

func (*MountRouter) ReadDir

func (r *MountRouter) ReadDir(path string) ([]DirEntry, error)
func (r *MountRouter) Readlink(path string) (string, error)

func (*MountRouter) Readonly

func (r *MountRouter) Readonly() bool

func (*MountRouter) Remove

func (r *MountRouter) Remove(path string) error

func (*MountRouter) RemoveAll

func (r *MountRouter) RemoveAll(path string) error

func (*MountRouter) RemoveMount

func (r *MountRouter) RemoveMount(path string)

func (*MountRouter) Rename

func (r *MountRouter) Rename(oldPath, newPath string) error

func (*MountRouter) Stat

func (r *MountRouter) Stat(path string) (FileInfo, error)
func (r *MountRouter) Symlink(target, link string) error

type MutateWriteFunc added in v0.1.19

type MutateWriteFunc func(ctx context.Context, req MutateWriteRequest) ([]byte, error)

MutateWriteFunc computes replacement bytes for a write operation. Returning an error fails the intercepted write.

type MutateWriteRequest added in v0.1.19

type MutateWriteRequest struct {
	Path   string
	Offset int64
	Size   int
	Mode   os.FileMode
	UID    int
	GID    int
}

MutateWriteRequest contains metadata for write mutation decisions.

type OpCode

type OpCode uint8
const (
	OpLookup OpCode = iota
	OpGetattr
	OpSetattr
	OpRead
	OpWrite
	OpCreate
	OpMkdir
	OpUnlink
	OpRmdir
	OpRename
	OpOpen
	OpRelease
	OpReaddir
	OpFsync
	OpMkdirAll
	OpTruncate
	OpSymlink
	OpReadlink
	OpLink
)

type OpPathMatcher added in v0.1.19

type OpPathMatcher struct {
	Ops         []HookOp
	PathPattern string
}

OpPathMatcher matches by operation and filepath-style glob pattern.

func (OpPathMatcher) Match added in v0.1.19

func (m OpPathMatcher) Match(req *HookRequest) bool

type Provider

type Provider interface {
	Readonly() bool
	Stat(path string) (FileInfo, error)
	ReadDir(path string) ([]DirEntry, error)
	Open(path string, flags int, mode os.FileMode) (Handle, error)
	Create(path string, mode os.FileMode) (Handle, error)
	Mkdir(path string, mode os.FileMode) error
	Chmod(path string, mode os.FileMode) error
	Remove(path string) error
	RemoveAll(path string) error
	Rename(oldPath, newPath string) error
	Symlink(target, link string) error
	Readlink(path string) (string, error)
}

func NewInterceptProvider added in v0.1.19

func NewInterceptProvider(inner Provider, hooks *HookEngine) Provider

type ReadonlyProvider

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

func NewReadonlyProvider

func NewReadonlyProvider(inner Provider) *ReadonlyProvider

func (*ReadonlyProvider) Chmod added in v0.1.10

func (p *ReadonlyProvider) Chmod(path string, mode os.FileMode) error

func (*ReadonlyProvider) Create

func (p *ReadonlyProvider) Create(path string, mode os.FileMode) (Handle, error)

func (*ReadonlyProvider) Mkdir

func (p *ReadonlyProvider) Mkdir(path string, mode os.FileMode) error

func (*ReadonlyProvider) Open

func (p *ReadonlyProvider) Open(path string, flags int, mode os.FileMode) (Handle, error)

func (*ReadonlyProvider) ReadDir

func (p *ReadonlyProvider) ReadDir(path string) ([]DirEntry, error)
func (p *ReadonlyProvider) Readlink(path string) (string, error)

func (*ReadonlyProvider) Readonly

func (p *ReadonlyProvider) Readonly() bool

func (*ReadonlyProvider) Remove

func (p *ReadonlyProvider) Remove(path string) error

func (*ReadonlyProvider) RemoveAll

func (p *ReadonlyProvider) RemoveAll(path string) error

func (*ReadonlyProvider) Rename

func (p *ReadonlyProvider) Rename(oldPath, newPath string) error

func (*ReadonlyProvider) Stat

func (p *ReadonlyProvider) Stat(path string) (FileInfo, error)
func (p *ReadonlyProvider) Symlink(target, link string) error

type RealFSProvider

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

func NewRealFSProvider

func NewRealFSProvider(root string) *RealFSProvider

func (*RealFSProvider) Chmod added in v0.1.10

func (p *RealFSProvider) Chmod(path string, mode os.FileMode) error

func (*RealFSProvider) Create

func (p *RealFSProvider) Create(path string, mode os.FileMode) (Handle, error)

func (*RealFSProvider) Mkdir

func (p *RealFSProvider) Mkdir(path string, mode os.FileMode) error

func (*RealFSProvider) Open

func (p *RealFSProvider) Open(path string, flags int, mode os.FileMode) (Handle, error)

func (*RealFSProvider) ReadDir

func (p *RealFSProvider) ReadDir(path string) ([]DirEntry, error)
func (p *RealFSProvider) Readlink(path string) (string, error)

func (*RealFSProvider) Readonly

func (p *RealFSProvider) Readonly() bool

func (*RealFSProvider) Remove

func (p *RealFSProvider) Remove(path string) error

func (*RealFSProvider) RemoveAll

func (p *RealFSProvider) RemoveAll(path string) error

func (*RealFSProvider) Rename

func (p *RealFSProvider) Rename(oldPath, newPath string) error

func (*RealFSProvider) Stat

func (p *RealFSProvider) Stat(path string) (FileInfo, error)
func (p *RealFSProvider) Symlink(target, link string) error

type VFSDirEntry

type VFSDirEntry struct {
	Name  string `cbor:"name"`
	IsDir bool   `cbor:"is_dir"`
	Mode  uint32 `cbor:"mode"`
	Size  int64  `cbor:"size"`
	Ino   uint64 `cbor:"ino,omitempty"`
}

type VFSRequest

type VFSRequest struct {
	Op      OpCode `cbor:"op"`
	Path    string `cbor:"path,omitempty"`
	NewPath string `cbor:"new_path,omitempty"`
	Handle  uint64 `cbor:"fh,omitempty"`
	Offset  int64  `cbor:"off,omitempty"`
	Size    uint32 `cbor:"sz,omitempty"`
	Data    []byte `cbor:"data,omitempty"`
	Flags   uint32 `cbor:"flags,omitempty"`
	Mode    uint32 `cbor:"mode,omitempty"`
	UID     uint32 `cbor:"uid,omitempty"`
	GID     uint32 `cbor:"gid,omitempty"`
}

type VFSResponse

type VFSResponse struct {
	Err     int32         `cbor:"err"`
	Stat    *VFSStat      `cbor:"stat,omitempty"`
	Data    []byte        `cbor:"data,omitempty"`
	Written uint32        `cbor:"written,omitempty"`
	Handle  uint64        `cbor:"fh,omitempty"`
	Entries []VFSDirEntry `cbor:"entries,omitempty"`
}

type VFSServer

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

func NewVFSServer

func NewVFSServer(provider Provider) *VFSServer

func (*VFSServer) HandleConnection

func (s *VFSServer) HandleConnection(conn net.Conn)

HandleConnection handles a single VFS connection. Exported for use by platform-specific backends.

func (*VFSServer) Serve

func (s *VFSServer) Serve(listener net.Listener) error

func (*VFSServer) ServeUDS

func (s *VFSServer) ServeUDS(socketPath string) error

ServeUDS starts the VFS server on a Unix domain socket This is used by Firecracker vsock which exposes guest vsock ports as UDS

func (*VFSServer) ServeUDSBackground

func (s *VFSServer) ServeUDSBackground(socketPath string) (stop func(), err error)

ServeUDSBackground starts the VFS server on a Unix domain socket in a goroutine Returns a function to stop the server

type VFSStat

type VFSStat struct {
	Size    int64  `cbor:"size"`
	Mode    uint32 `cbor:"mode"`
	ModTime int64  `cbor:"mtime"`
	IsDir   bool   `cbor:"is_dir"`
	Ino     uint64 `cbor:"ino,omitempty"`
}

Jump to

Keyboard shortcuts

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