upperdir

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2026 License: Apache-2.0 Imports: 12 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package upperdir reads the upper directory of the kernel overlay that serves a mount-mode workspace and reports which paths differ from the base tree that the read-only lower layer serves. It knows the trusted.overlay.* markers (whiteout, opaque, redirect, metacopy) and holds no state.

Index

Constants

View Source
const (
	KindFile    = "file"
	KindSymlink = "symlink"
	KindDir     = "dir"
	KindDeleted = "deleted"
)
View Source
const (
	XattrOpaque   = "trusted.overlay.opaque"
	XattrRedirect = "trusted.overlay.redirect"
	XattrMetacopy = "trusted.overlay.metacopy"
)
View Source
const SettleWindow = 50 * time.Millisecond

SettleWindow is how long the newest change time must lie before the start of a walk for the walk to be settled. Kernel timestamps are coarse, so a change that lands in the same tick as the walk can leave the fingerprint unchanged.

Variables

This section is empty.

Functions

func ProbeTrusted

func ProbeTrusted(dir string) error

ProbeTrusted checks that the process can set and read a trusted.* attribute on the file system of dir, a directory that no overlay references. Without CAP_SYS_ADMIN in the initial user namespace a read of trusted.overlay.* answers no data, and Scan would report a wrong dirty set.

func ProbeTrustedBeside

func ProbeTrustedBeside(upper string) error

ProbeTrustedBeside runs ProbeTrusted on a new directory next to the upper directory, on its file system, and removes it. It never writes into the upper directory, which a live overlay can reference. It checks the file system of the parent of upper, which is the file system of upper when no mount point lies at upper.

func ScanStable

func ScanStable(ctx context.Context, fsys FS, root string, base BaseTree, now func() time.Time) ([]Entry, Token, error)

ScanStable reads the token, scans, and reads the token again, and retries when the two differ. An unsettled first token ends it after one scan, because the consumer treats that token as a change. It returns the token read before the winning scan, so an edit made during the scan shows in the next token. After the last try it returns the last scan with an unsettled token, which no other token equals.

Types

type BaseEntry

type BaseEntry struct {
	Name    string
	Dir     bool
	Symlink bool
	Exec    bool
}

BaseEntry is one entry of a base directory.

type BaseTree

type BaseTree interface {
	Lookup(ctx context.Context, path string) (BaseEntry, bool, error)
	List(ctx context.Context, dir string) ([]BaseEntry, error)
}

BaseTree reads the base tree. Paths use "/" and the empty path is the root. A submodule is a directory with no entries, as the mount shows it.

type Blob

type Blob struct {
	Mode    fs.FileMode
	Size    int64
	Data    []byte
	HasData bool
	// Read counts the bytes read from the file, also when Read discards them.
	Read int64
}

Blob is one regular file or symlink of a directory, from one inode. Data is the file bytes or the symlink target; a regular file past the limit has none. Size is len(Data) when Data is set.

type Dir

type Dir interface {
	// Entries lists the entries with their lstat.
	Entries() ([]Dirent, error)
	// Stat is the lstat of the directory itself.
	Stat() (Dirent, error)
	Lstat(name string) (Dirent, error)
	// Attr reads an attribute of the directory itself.
	Attr(attr string) (value string, ok bool, err error)
	// Xattr reads an attribute of a regular file of the directory.
	Xattr(name, attr string) (value string, ok bool, err error)
	Read(name string, limit int64) (Blob, error)
	// Open opens a child directory.
	Open(name string) (Dir, error)
	Close() error
}

Dir is an open directory. A name is one entry of the directory, never a path.

type Dirent

type Dirent struct {
	Name     string
	Mode     fs.FileMode
	Whiteout bool
	Size     int64
	Ctime    int64
	Ino      uint64
}

Dirent is the lstat of one upper entry. Ctime is in nanoseconds.

type Entry

type Entry struct {
	Path      string
	Kind      string
	Exec      bool
	Opaque    bool
	Origin    string // base path whose blob is the content, when the upper entry holds none
	NoContent bool
}

Entry is one path of the merged view that differs from the base tree.

func Scan

func Scan(ctx context.Context, fsys FS, root string, base BaseTree) ([]Entry, error)

Scan lists the paths of the merged view that differ from the base tree, sorted by path. root is the upper directory in fsys.

type FS

type FS interface {
	Open(path string) (Dir, error)
}

FS opens the directories of an upper directory. The empty path is the root, and a missing path answers an error that matches fs.ErrNotExist.

type MemFS

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

MemFS is an in-memory FS. The root exists and has no entry of its own in the map.

func NewMemFS

func NewMemFS() *MemFS

func (*MemFS) Delete

func (m *MemFS) Delete(p string)

func (*MemFS) Get

func (m *MemFS) Get(p string) (MemNode, bool)

func (*MemFS) Lstat

func (m *MemFS) Lstat(p string) (Dirent, error)

func (*MemFS) Open

func (m *MemFS) Open(p string) (Dir, error)

func (*MemFS) Paths

func (m *MemFS) Paths() []string

Paths lists every path in order.

func (*MemFS) Put

func (m *MemFS) Put(p string, n MemNode)

type MemNode

type MemNode struct {
	Mode     fs.FileMode
	Whiteout bool
	Size     int64
	Ctime    int64
	Ino      uint64
	Xattr    map[string]string
	// Data is the content of a regular file, or the target of a symlink.
	Data []byte
}

MemNode is one entry of a MemFS.

type OSFS

type OSFS struct {
	Dir string
	// contains filtered or unexported fields
}

OSFS reads an upper directory on a local file system. The sandbox can change the tree while the walk runs, so OSFS opens the root once and every directory below it one component at a time, and requires the opened inode to be the directory that fstatat found: no read goes through a symlink. A component that turns into a file or a symlink is gone. Attributes are read through a descriptor of the entry, so the walk needs no /proc. Reading the trusted.overlay.* attributes needs CAP_SYS_ADMIN in the initial user namespace.

func (*OSFS) Open

func (o *OSFS) Open(rel string) (Dir, error)

type Token

type Token struct {
	Entries  int64
	Ctime    int64
	Bytes    int64
	SumCtime uint64
	SumIno   uint64
	Settled  bool
	// contains filtered or unexported fields
}

Token is the fingerprint of an upper directory. The sums of the change times and of the inode numbers catch what the maximum alone misses: a clock that steps back, and a file replaced by another of the same size. An unsettled token carries a number that no other token has.

func Fingerprint

func Fingerprint(fsys FS, root string, now time.Time) (Token, error)

Fingerprint walks the upper directory with lstat only. now is the start of the walk. The root entries that Scan skips do not count. The token does not see a second store through a mapping that is already dirty: the change time moves at the first write fault only.

func (Token) Same

func (t Token) Same(o Token) bool

Same reports whether two tokens show the same upper directory. An unsettled token is never the same.

func (Token) String

func (t Token) String(boot string) string

String formats the token for the wire, behind the boot ID of the daemon process.

Jump to

Keyboard shortcuts

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