◈ Passerelle

Project

ADR-001 — lookup never follows a symbolic link, getattr does

Context

On QNX, path resolution is resumed by the <em>client</em>: when a path component is a symbolic link, the resource manager answers with a redirect (_RESMGR_REDIRECT) and the caller walks the target itself. For that to work, the layer-3 walk must <em>see</em> the link.

The backend interface of layer 3 exposes two attribute calls, lookup and getattr. The first draft of the interface did not say which one follows a final symbolic link, and the two sides of the tree answered differently: rmfs assumed one convention, the POSIX truth backend and the 9P adapter assumed the other. The observable result was that lstat on a link loop answered ELOOP while stat on the same path answered OK — inverted — and FS-08 (loop detection) was unreachable, because the walk never met a link to redirect on.

The defect was found by <em>running</em> the differential bench (0), not by reading the code.

Decision

The convention is written once, in the header both sides include, and it is this:

Call Semantics May fail with
lookup(impl, relpath, ...) attributes <strong>without</strong> following a final symbolic link — lstat(2) —
getattr(impl, relpath, ...) attributes <strong>following</strong> a final symbolic link — stat(2) PGW_ELOOP, PGW_ENOENT

The walk uses lookup, so a link component is seen and turned into a redirect answer for the caller. rmfs resolves links itself, through readlink, before asking for followed attributes.

An adapter whose protocol cannot distinguish the two — 9P2000.L: a Twalk ends on the link itself — may implement both callbacks with the same call, because rmfs does the resolution. What must never happen is lookup following links.

Consequences