Documentation
¶
Overview ¶
Package fusefs provides a read-only filesystem interface over pxar archives, compatible with hanwen/go-fuse's InodeEmbedder and Inode interfaces.
This package does NOT import go-fuse. It defines compatible interfaces (FileSystem, Attr, DirEntry) so callers can wrap them into a go-fuse FileSystem without the library requiring the dependency.
Basic Usage ¶
Open a pxar archive and create a Session:
f, err := os.Open("backup.pxar")
defer f.Close()
fi, _ := f.Stat()
sess, err := fusefs.NewSession(f, fi.Size())
if err != nil {
log.Fatal(err)
}
defer sess.Close()
Filesystem Operations ¶
Session implements the FileSystem interface:
// Look up a file in a directory inode, attr, err := sess.Lookup(fusefs.RootInode, "example.txt") // Read file data sess.Open(inode, 0) buf := make([]byte, attr.Size) n, err := sess.Read(inode, buf, 0) // List directory entries, err := sess.Readdir(fusefs.RootInode, 0) // Read symlink target target, err := sess.Readlink(symlinkInode)
Inode Model ¶
The root directory uses inode 1 (RootInode). Non-directory inodes have the NonDirBit (bit 63) set. Use IsDirInode to distinguish:
fusefs.IsDirInode(inode) // true if directory
Nodes track entry ranges and optional content ranges for file data access. Reference counting is handled automatically via Ref/Unref/Forget.
Package fusefs provides a read-only filesystem interface over pxar archives, compatible with hanwen/go-fuse's InodeEmbedder and Inode interfaces.
This package does NOT import go-fuse — it defines compatible interfaces so callers can wrap them into a go-fuse FileSystem without the library needing the dependency.
Index ¶
- Constants
- func IsDirInode(inode uint64) bool
- type Attr
- type ContentRange
- type DirEntry
- type DirEntryIndex
- type EntryRangeInfo
- type FileSystem
- type Node
- func (n *Node) Cache() (format.Stat, uint64, bool)
- func (n *Node) Content() (offset, size uint64, ok bool)
- func (n *Node) EntryRange() (start, end uint64)
- func (n *Node) Inode() uint64
- func (n *Node) Parent() uint64
- func (n *Node) Ref() bool
- func (n *Node) SetCache(stat format.Stat, fileSize uint64)
- func (n *Node) SetContent(offset, size uint64)
- func (n *Node) Unref(count uint64) bool
- type ReaderAt
- type Session
- func (s *Session) Access(inode uint64, mask uint32) error
- func (s *Session) Close() error
- func (s *Session) Forget(inode uint64, count uint64)
- func (s *Session) GetXAttr(inode uint64, attr string) ([]byte, error)
- func (s *Session) Getattr(inode uint64) (Attr, error)
- func (s *Session) ListXAttr(inode uint64) ([]string, error)
- func (s *Session) Lookup(parentInode uint64, name string) (uint64, Attr, error)
- func (s *Session) Open(inode uint64, flags uint32) error
- func (s *Session) Read(inode uint64, dest []byte, offset int64) (int, error)
- func (s *Session) Readdir(inode uint64, offset uint64) ([]DirEntryIndex, error)
- func (s *Session) Readlink(inode uint64) (string, error)
- func (s *Session) Release(inode uint64)
- func (s *Session) Statfs() (syscall.Statfs_t, error)
- type XAttr
Constants ¶
const ( // RootInode is the inode number for the root directory. RootInode = 1 // NonDirBit is set in the high bit of inodes for non-directory entries. NonDirBit uint64 = 1 << 63 )
Variables ¶
This section is empty.
Functions ¶
func IsDirInode ¶
IsDirInode returns true if the inode represents a directory.
Types ¶
type Attr ¶
type Attr struct {
Ino uint64
Size uint64
Blocks uint64
Atime uint64
Mtime uint64
Ctime uint64
Atimensec uint32
Mtimensec uint32
Ctimensec uint32
Mode uint32
Nlink uint32
Uid uint32
Gid uint32
Rdev uint32
Blksize uint32
}
Attr represents file metadata, compatible with go-fuse's fuse.Attr.
type ContentRange ¶
ContentRange describes where file content lives in the archive.
type DirEntryIndex ¶
DirEntryIndex adds an offset to DirEntry for readdir pagination.
type EntryRangeInfo ¶
EntryRangeInfo describes where an entry lives in the archive.
type FileSystem ¶
type FileSystem interface {
// Lookup finds a child entry by name in the given parent directory inode.
Lookup(parentInode uint64, name string) (inode uint64, attr Attr, err error)
// Getattr returns the attributes for the given inode.
Getattr(inode uint64) (Attr, error)
// Readdir returns directory entries starting at the given offset.
// Returns entries and the next offset. An empty slice signals end-of-directory.
Readdir(inode uint64, offset uint64) ([]DirEntryIndex, error)
// Open informs the kernel that the file is being opened.
Open(inode uint64, flags uint32) error
// Read reads data from a file inode at the given offset.
// FUSE requires no short reads (except at EOF).
Read(inode uint64, dest []byte, offset int64) (int, error)
// Readlink returns the symlink target for the given inode.
Readlink(inode uint64) (string, error)
// ListXAttr returns all extended attribute names for the given inode.
ListXAttr(inode uint64) ([]string, error)
// GetXAttr returns the value of a specific extended attribute.
GetXAttr(inode uint64, attr string) ([]byte, error)
// Forget decrements the reference count for an inode.
Forget(inode uint64, count uint64)
// Statfs returns filesystem statistics.
Statfs() (syscall.Statfs_t, error)
// Access checks file accessibility.
Access(inode uint64, mask uint32) error
// Release is called when a file is closed.
Release(inode uint64)
}
FileSystem is the interface that maps pxar archive entries to FUSE operations. It is compatible with hanwen/go-fuse's InodeEmbedder and RawFileSystem patterns.
type Node ¶
type Node struct {
// contains filtered or unexported fields
}
Node holds cached metadata for a filesystem entry.
func (*Node) EntryRange ¶
EntryRange returns the entry's byte range in the archive.
func (*Node) SetContent ¶
SetContent sets the file content location in the archive.
type Session ¶
type Session struct {
// contains filtered or unexported fields
}
Session implements FileSystem over a pxar archive, providing FUSE-compatible operations without importing go-fuse directly.
func NewSession ¶
func NewSession(r io.ReadSeeker, size int64) (*Session, error)
NewSession creates a new FUSE filesystem session over a pxar archive.
func (*Session) Readdir ¶
func (s *Session) Readdir(inode uint64, offset uint64) ([]DirEntryIndex, error)
Readdir returns directory entries starting at the given offset.