Peios Learn
Documentation

Peios

Peios Peios Kernel Universal Directory Project

Developer Tools

Trail Acta Provium clackatoo CAF GCSL Pekit

Applications

Framewright

Standards and Conventions

Standards and Conventions Peios Specifications
Peios Kernel

Strata and mounting

Single-page view · as markdown

Strata and mounting

Peios Kernel / Internals / StrataFS / Strata and mounting

Use these articles to understand strata and mounting in the Peios kernel.

  • The Stratum Stack
  • Mount Admission
  • Absent Strata

The Stratum Stack

Peios Kernel / Internals / StrataFS / Strata and mounting

A mount is defined by its stratum stack: an ordered, non-empty list of strata, highest-precedence first. The stack is fixed for the life of the mount. Nothing reorders it, and precedence never varies by path, by caller, or by operation.

Index 0 is the highest-precedence stratum. That convention runs all the way through: strata are stored in a fixed array in mount-option order, presence across the stack is a u64 bitmap indexed by the same position, and selecting the provider is the trailing-zero count of that bitmap — the lowest set index, which is the highest-precedence stratum that holds the name.

The array is STRATAFS_MAX_STRATA entries, which is 16. A stack longer than that is refused at parse time. Absence never renumbers anything: an absent stratum simply has its bit clear, keeping its slot and its precedence.

A stratum is a path #

What is stored for each stratum is a string and a flag word — nothing else. No reference is held on a stratum's directory, and no resolution result is retained across operations. Every time a name is resolved, the stratum's path string is joined with the relative path of the name and walked from scratch.

This is what makes a stratum follow a wholesale replacement. A package transaction that renames the old tree aside and the new tree into place leaves the original directory object intact and referenced by anything that held it; a stratum defined as that object would go on serving the replaced tree. Defined as a path, it follows.

The cost is that every lookup does the walk. Revalidation covers what that means in practice, because the implementation does not cache resolutions at all.

The resolution context #

Stratum paths are joined absolute and walked from a root captured when the mount was created — the creating process's own filesystem root — under credentials captured at the same moment. Both are pinned for the life of the mount and released only when the superblock is freed.

The credential override matters as much as the root. A stratum path is resolved with the mounter's credentials, not with those of whatever process later touches the mount, so a caller in a different mount namespace cannot shift what a stratum denotes, and the paths reported by the origin attribute (The Origin Attribute) always name the same things.

Symbolic links and mounts along a stratum's path are followed as they stand at the moment of resolution, since the walk is an ordinary filename_lookup with no restricting flags. A mount established inside a stratum is therefore part of that stratum's tree, and one stratum can span several filesystems — which Inode Identity and Lifecycle has to account for when deriving inode numbers.

What a stratum's filesystem must provide #

Nothing beyond ordinary directory and file operations. stratafs probes no capability at mount time: it checks only that each stratum path resolves, names a directory, is not a duplicate of another stratum, and does not push the composed stack past the kernel's maximum stacking depth. There is no test for a usable directory version value, because nothing in the implementation would use one.

Flags #

Each stratum carries zero or more flags, declared with it in the mount options and stored as a bit field.

FlagBitMeaning
createSTRATAFS_F_CREATEThis stratum receives newly created objects and is the destination of copy-up.
roSTRATAFS_F_ROstratafs does not modify this stratum.
amSTRATAFS_F_AMThis stratum's directory may be absent.

The stack-wide rules are decided in Rust, in stratafs-core: the stack must be non-empty, must not exceed 16 strata, must contain no unrecognised flag bit, must not carry create twice, and must not carry create and ro on one stratum. The crate distinguishes five error cases, but the C boundary collapses all of them to EINVAL, so the distinction is not observable to a caller.

create #

At most one stratum carries create, and a stack may carry none, in which case create_index is -1 and every creation and every copy-up is refused with EROFS. Modification of an object provided by a stratum that accepts modification is unaffected, because routing tests the provider before it consults the create stratum at all (Write Routing).

create does not mean "writable", and it is not the only stratum stratafs writes to. It designates where objects that do not yet exist in any stratum are created, and where an object is copied when its provider will not accept a modification. A stratum carrying neither create nor ro is modified in place, and any number of such strata may sit above the create stratum, below it, or both.

ro #

ro is a stratafs-level assertion, independent of whether the stratum's filesystem is itself read-only. It is one of three terms in the predicate that decides whether a stratum accepts modification of an object it provides:

  • the stratum does not carry ro;
  • the provider's mount is not read-only;
  • the provider's inode is not marked immutable.

The predicate takes only the superblock, the stratum index, and the provider path. It reads no credentials, consults no security descriptor, and calls into KACS not at all — which is what stops a caller who has been refused write access from provoking a copy-up (Write Routing).

Note the third term is specifically the immutable inode flag. A file that is unwritable by its mode bits is not excluded by this predicate; the write is routed in place and the underlying filesystem refuses it.

am #

Without am, a stratum's directory must exist when the mount is created, and a mount whose stratum directory is absent fails with ENOENT. With am, an absent directory is accepted at mount time.

The flag governs mount time only. At runtime the resolver never consults it: a stratum whose directory has gone is skipped exactly the same way whether or not it carries am. Absent Strata covers what absence means once the mount is live.

Mount Admission

Peios Kernel / Internals / StrataFS / Strata and mounting

A stratafs mount is configured entirely at mount time. This section covers what the caller must be entitled to, the conditions a configuration has to satisfy, and the order in which those conditions are evaluated.

Entitlement #

Establishing a mount with no create stratum takes no privilege of its own. The filesystem type carries FS_USERNS_MOUNT, and stratafs is on the allowlist of types a mount namespace's descriptor may admit (A Private Mount Table), so a caller may establish one in a mount namespace it created without the mount privilege; what the caller needs beyond that is only the access that resolving the stratum paths already requires, which falls out of the resolution itself. A user namespace by itself confers nothing here, as everywhere under KACS.

A stack that carries create is different. Copy-up is authorised by the outer handle and deliberately requires no add-entry right on the create stratum (Checks on Merged Directories), so the mount configuration carries authority to materialise names in a real directory outside the mount. The caller establishing such a stack must be operating in the initial user namespace and hold CAP_SYS_ADMIN there; anything else fails with EPERM.

The test is made in get_tree, before the tree is built and therefore before any stratum path is resolved, and it is stricter than requiring the capability alone: the credential's own user namespace must be the initial one, not merely a namespace in which the capability resolves. This is the closure the KACS copy-up context depends on. The check is made once, when the immutable stack is established, rather than at each copy-up, so descriptor delegation cannot reintroduce authorisation against the acting task, and no reconfiguration can re-supply the strata list.

There is no explicit per-stratum entitlement check in the mount path. Both halves come out of the ordinary machinery: traverse rights are enforced by the path walk, which runs under the mounting caller's credentials, and the right to read a stratum directory's attributes is enforced by using the security-checking vfs_getattr rather than its unchecked variant, which reaches KACS's getattr hook and demands FILE_READ_ATTRIBUTES.

One seam is worth recording: the path walk uses the credentials captured on the filesystem context, while vfs_getattr runs outside that override and so uses the acting task's. For a mount established the ordinary way the two are the same task. For one established with fsopen and fsconfig from different tasks they need not be.

Nothing re-checks entitlement if a stratum directory later appears. That is sound because every access through the mount is checked against the providing object in any case (Access Check Delegation), so a caller who mounts a stratum they cannot read still cannot read it.

Validity #

ConditionError
The stratum stack is emptyEINVAL
The stack exceeds 16 strataEINVAL
More than one stratum carries createEINVAL
A stratum carries both create and roEINVAL
The same directory appears as more than one stratumEINVAL
A malformed strata= value (Mount Options)EINVAL
A create-bearing stack from outside the initial user namespace, or without CAP_SYS_ADMIN thereEPERM
A stratum's path names something other than a directoryENOTDIR
A stratum's directory is absent and the stratum does not carry amENOENT
The composed stack reaches the kernel's maximum stacking depthELOOP
A stratum lies within the mount point, or within another stratafs mount whose strata include this mount pointELOOP
Sixteen consecutive collisions allocating a mount cookieEAGAIN

Two strata are the same directory when they resolve to the same directory object, not merely when their paths are equal as strings: the comparison is on resolved inodes, so two paths reaching one directory through different symbolic links or bind mounts are caught. Absent strata are skipped and never compared.

Evaluation order #

The conditions that depend on nothing but the option string are decided first, during parsing and stack-wide validation, and are reported whatever the caller's access. The EPERM admission test comes next, in get_tree, still before any path is touched. Only then are the strata resolved.

The purpose of that ordering is to stop the validity conditions being an oracle: a caller with no right to traverse a directory should not be able to name it as a stratum and learn from the errno whether it exists and whether it is a directory.

The path walk and the attribute read both run under the caller's credentials, so a path the caller cannot resolve returns EACCES from the walk itself, and the EACCES is propagated unchanged.

The check is stack-wide because it runs in two passes. The first resolves and stats every stratum; an EACCES from any of them is the answer, whatever an earlier stratum reported. Only when every stratum has passed entitlement does the second pass apply the type, duplicate and depth conditions. A caller who names a readable non-directory first and an unreadable path second is told EACCES, not ENOTDIR.

The mount-point loop condition is evaluated in a different call entirely, after the tree has been built, and so always follows every entitlement check.

Loops #

A stratum inside the mount point is detected directly. The indirect case — a stratum inside another stratafs mount whose own strata include this mount point — is detected by recursing into any stratum whose superblock carries the stratafs magic, bounded by a visited- superblock set and by the kernel's maximum stacking depth. This runs through a Peios-added super_operations hook, validate_mountpoint, wired into the new-mount, bind and move-mount paths by the patch series; it is not an upstream interface.

That check cannot bind after the fact: a mount established within a stratum, or a bind mount of this mount into one of its own strata, can create a cycle later. Resolution is guarded separately, and differently — not by a depth counter but by a per-task, per-superblock re-entrancy list. A task that is already resolving in a superblock and re-enters it gets ELOOP immediately, so a cycle spanning any number of stratafs mounts terminates the moment it returns to one it is already inside.

Immutability and mount identity #

The stack is fixed for the life of the mount; changing one is expressed by unmounting and mounting again (Mount Options).

Two stratafs mounts may name the same directory as a stratum. Each resolves independently and neither is aware of the other; where both have a create stratum in common they mutate the same objects, with the same result as any two writers of one directory. There is no registry of stratum paths to make them aware of each other.

There is a registry of mounts, but it exists for a different purpose. Each mount draws a random non-zero cookie and inserts itself into a global table, retrying up to sixteen times on collision; a second random non-zero cookie is drawn once per boot. The pair identifies which live mount owns a staging entry, so that a mount sharing a create stratum can distinguish another mount's copy-up in flight from an orphan left by a crash (Copy-Up).

An all-absent stack #

A mount succeeds even when no stratum root is present at all — a stack whose only strata are absent am strata is legal. The root inode is constructed with no provider, and reports mode S_IFDIR with no permission bits.

Such a root still carries a security descriptor, since an object with none would refuse every access check made on the mount root and the provider-less root could never be observed. stratafs synthesises it: owned by the mounter, with read and traverse for everyone, and nothing more — there is nothing beneath such a root to write. The moment a stratum root appears the root's descriptor is that root's own, and when it goes again the synthesised one returns; KACS never caches a StrataFS root's descriptor, so no access is decided against a root that has since gained or lost its provider.

Absent Strata

Peios Kernel / Internals / StrataFS / Strata and mounting

A stratum's directory may not exist. It may be absent when the mount is created — which requires am (Mount Admission) — or exist at mount time and be removed while the mount is live, which nothing prevents for any stratum.

While absent #

An absent stratum holds no names, participates in no merged directory, and contributes no entries to any enumeration. It keeps its position and its precedence; only its presence bit is clear.

The mechanism is a single test in the resolver. Resolving one stratum either succeeds, or fails with ENOENT or ENOTDIR, in which case the stratum is skipped and its bit is left clear. Any other error — EACCES, EIO, ELOOP, ENAMETOOLONG, ESTALE — is not treated as absence and fails the whole resolution instead. So a stratum that is unreadable for a reason other than not being there masks the name for every stratum, rather than being passed over.

An absent create stratum additionally causes every operation that would create or copy up to fail with EROFS. The create stratum's root is re-resolved at the point of use and its ENOENT is mapped to EROFS by each of the paths that needs it — the copy-up parent walk, the creation authorisation pre-check, and the routing decision, which computes create-stratum presence live and requires the result to be a directory. stratafs does not create the stratum's own directory to satisfy such an operation: establishing that directory, with the security descriptor it should have, belongs to whatever provisions the system, and a mount that minted it would be choosing that descriptor.

Appearing and disappearing #

Neither event is detected. Both are simply observed, because there is nothing to invalidate.

A stratum's directory is never held; only its path string is. Every resolution walks that string afresh, so a directory that comes into existence is picked up by the very next lookup, and one that is removed, renamed away, or replaced by another directory is picked up just as immediately — the walk finds nothing, or finds the replacement.

The specification describes this in terms of a version tuple recorded over the nearest existing ancestor of an absent stratum's path, and an identity comparison for a stratum that disappears. Neither exists in the implementation, and neither is needed: they are the machinery for knowing when a cached resolution has gone stale, and nothing is cached. Revalidation covers the trade that represents.

The am flag is not consulted at runtime at all. It governs whether the mount is allowed to be established with the directory missing, and nothing more; a stratum without it that vanishes afterwards behaves exactly like one with it.

Reappearance #

A stratum that disappears and reappears is the same stratum in the same stack position, and nothing about the old directory is remembered. Resolutions are recomputed against whatever the new directory holds.

Provider identity does survive the gap, though it is not resolution memory. The derived inode number (Inode Identity and Lifecycle) identifies the provider's filesystem and inode number. If the same underlying object is reached again — because the directory was renamed away and back rather than replaced — it receives the same number it had before, without a mount-lifetime pin on ordinary provider inodes. Only identities that cannot be derived use the pinned fallback map. That is exactly what the identity rule requires: equal numbers for one provider object, whatever path reached it.

Peios Learn — documentation for Peios software.

Built with Trail.