Skip to main content

resolve

Function resolve 

Source
pub fn resolve(
    fs: &Fs,
    pid: u32,
    guest: &[u8],
    deref_final: bool,
) -> Result<Resolved, i32>
Expand description

Resolves an absolute guest path inside the guest namespace to the pinned directory and name to act on.

Walks guest one component at a time. Each intermediate component is opened O_PATH relative to the directory walked so far; a symlink is read and its target re-entered into the walk as a guest path (absolute targets restart from guest /). The final component is dereferenced only when deref_final is true. A final component that does not exist is returned as a name in its parent, so the kernel produces the real error, or creates it, through the pinned parent; a missing or non-directory intermediate component fails here with the errno the kernel would give.

/proc magic links are special: /proc/self and /proc/thread-self become the tracee’s own entries (not the supervisor’s), the targets of /proc/<pid>/{exe,cwd,root,fd/N,map_files/*} are host paths, so they are detranslated instead of being re-walked as guest paths, and /proc/<pid>/ns/* name namespaces, which only the kernel resolves.

§Arguments

  • fs - Guest filesystem view.
  • pid - Tracee thread id the path belongs to (for /proc/self).
  • guest - Absolute guest path, may contain ./../double slashes.
  • deref_final - Follow a symlink in the last component.

§Errors

ELOOP after too many symlinks, or when a component kept changing under the walk; ENAMETOOLONG for an overlong result; ENOTDIR when an intermediate component is not a directory; ENOENT when one is missing; EINVAL for a relative input.