Expand description
Component-wise canonicalization of guest paths (port of PRoot’s canon.c),
walked on descriptors.
Every component of a guest path is looked up on the host side of its
binding, relative to an O_PATH descriptor of the directory walked so
far, never through a textual host path: a symlink found there is read and
re-interpreted in the guest namespace, so a link to /usr/lib inside
the rootfs lands in the rootfs’s /usr/lib, never the host’s. The walk
starts from the descriptors Fs holds open on the root and on every
binding, and ends on a Resolved: the pinned parent directory and the
final name, which the handlers act on with the *at syscalls and
O_NOFOLLOW. A directory the guest renames away and replaces by a
symlink while a call is in flight is then seen as the symlink it is, and
resolved inside the guest on a retry, instead of followed on the host by
the kernel’s own walk of a stale string. Directories already resolved are
kept in Fs’s cache to skip the openat next time.
Structs§
- Resolved
- A guest path resolved inside the guest namespace.
Enums§
- At
- Where the object a guest path names is, for the
*atsyscalls. - Missing 🔒
- What becomes of the components after a missing intermediate one.
Constants§
- MAX_
RESTARTS 🔒 - Walks started over, after a component changed under the walk, before
giving up with
ELOOP. - MAX_
SYMLINKS 🔒 - Symlink hops allowed before giving up with
ELOOP(Linux’sMAXSYMLINKS). - RETRY
- Sentinel errno: the object changed between two steps of a lookup or
between the lookup and the call; start over from the guest path. Never
reaches a tracee:
resolveand the handlers turn it intoELOOPonce the restarts are used up.
Functions§
- append_
rest 🔒 - Appends the remaining components to a path without touching the host.
- canonicalize
- Canonicalizes an absolute guest path inside the guest namespace.
- child 🔒
- A
Resolvedfornameinside the pinned directoryparent. - components 🔒
- The non-empty components of a path, in order.
- cstr 🔒
- Builds a C string from path bytes.
- fd_path
/proc/self/fd/<n>of a descriptor, as a C string.- follow 🔒
- Re-enters a symlink target into the walk, interpreted in the guest namespace relative to the canonical directory that holds the link.
- fstat_
mode 🔒 st_modeof an open descriptor.- fstatat_
mode 🔒 st_modeofnameinsidedirwithout following a final symlink.- is_
proc_ 🔒fd_ link - Whether a canonical guest path is a
/proc/<pid>[/task/<tid>]/fd/Normap_files/Xlink. - is_
proc_ 🔒magic_ link - Whether a canonical guest path names a
/proc/<pid>[/task/<tid>]/{exe,cwd,root,fd/N,map_files/X,ns/X}link. - join 🔒
- Joins a canonical directory and one component.
- lexical_
clean - Removes
.components, resolves..lexically and collapses slashes. - lstat_
mode 🔒 st_modeof a host path without following a final symlink.- object 🔒
- A
Resolvedfor a pinned mount point itself. - open_at 🔒
- Opens
nameinsidediras anO_PATH|O_CLOEXECdescriptor with extraflags. - open_
dir 🔒 - Opens the canonical guest directory
guestfrom the mount point it lies under. - open_
dir_ 🔒component - Opens the directory
compinsidediras anO_PATHdescriptor. - pop_
component 🔒 - Removes the last component of a canonical path;
/stays/. - proc_
pid 🔒 - The
<n>of a/proc/<n>/...path, or of/proc/<n>/task/<t>/...(thent). - read_
link 🔒 readlink(2)on a host path, as bytes.- readlinkat
readlinkat(2)ofnameinsidedir, as bytes.- resolve
- Resolves an absolute guest path inside the guest namespace to the pinned directory and name to act on.
- resolve_
with 🔒 - textual 🔒
- A
Resolvedthe kernel resolves from the textual host path. - walk 🔒
- One pass of
resolve;Err(RETRY)when a component changed under it.