# Start here

---

# Overview

_Peios Kernel / Internals / StrataFS / Start here_

> stratafs presents an ordered set of existing directories as one tree — where it sits, the model it follows, and what it delegates.

<a id="trm-4-1"></a>

stratafs presents an ordered set of existing directories — its
**strata**, or layers, which give it its name — as one merged
directory tree. Each stratum is an ordinary
directory on an ordinary filesystem, owned and written by whatever
agent owns it, with no coordination with stratafs and no notification
to it. The merged view reflects changes to any stratum without a
remount. <a id="cite-mount.reflects-stratum-changes"></a>

It is a stacking filesystem in the strict sense: it stores no file
data, no directory entries, and no security descriptors. Every object
reachable through a stratafs mount is a real object on a real stratum,
and every data and metadata operation is performed against that object. <a id="cite-model.every-object-is-real"></a>
stratafs inodes carry no address-space operations, so there is no
second page cache to keep coherent; reads, writes, mappings and splices
are forwarded to a backing file opened on the provider.

Unlike overlayfs, stratafs has **no whiteouts and no opaque-directory
markers**. There is no mechanism anywhere in the filesystem for
recording that a name should be absent. That single omission accounts
for most of what is unusual about it: removing a name can leave the
name visible, some names cannot be removed at all, and several
operations that succeed on an ordinary filesystem are refused here
rather than faked. [Failure Modes](</kernel/internals/stratafs/start-here/failure-modes.md#trm-4-8>) collects the consequences.

<a id="trm-4-1-1"></a>

## Where it sits <a id="cite-mount.superblock-identity"></a>

stratafs lives in `fs/stratafs`, alongside PKM. It is built by `CONFIG_STRATAFS_FS` — a boolean option, so it
is linked into `vmlinux` — and registered by an `fs_initcall`. The
option depends on `CONFIG_SECURITY_PKM`, because stratafs reaches KACS
for every access decision and for the whole of the copy-up context.
That reach is through `<linux/kacs_stratafs.h>`, a kernel-private
header in `include/linux` whose symbols are deliberately not exported
to modules. This is a private in-kernel integration interface, not a
userspace API.

The filesystem type registers under the name `stratafs`, with the
superblock magic `0x53545241` — ASCII `STRA` — and the flags
`FS_USERNS_MOUNT` and `FS_RENAME_DOES_D_MOVE`. It takes no device;
superblocks come from `get_tree_nodev`, so the device identifier
reported for every object in a mount is an anonymous one belonging to
the mount rather than to any stratum.

A small part of the filesystem is written in Rust. The crate
`stratafs-core` compiles the sources in `security/pkm/stratafs_core`
and holds three pure, allocation-free decisions: validating the
stack-wide flag rules, selecting the provider from a presence bitmap,
and routing one modifying operation. Everything else — the VFS glue,
resolution, enumeration, copy-up — is C.

<a id="trm-4-1-2"></a>

## The model <a id="cite-strata.identified-by-path"></a>

A mount is defined by its **stratum stack**: an ordered list of strata,
highest-precedence first, fixed for the life of the mount. A stratum is
identified by its **path**, not by the directory that path resolved to
at mount time, which is what allows a package transaction to replace a
whole stratum by renaming trees around underneath a live mount.

For a given name in a given directory, the **provider** is the
highest-precedence stratum that holds it. A name whose provider is a
directory, and which lower strata also hold as a directory, resolves to
a **merged directory** whose entries are the union of theirs. A name
whose provider is anything else masks every lower entry of that name
completely, subtree and all.

At most one stratum carries the `create` flag. That **create stratum**
receives newly created objects and is the destination of **copy-up** —
the replication of an object into the create stratum so that a
modification can be applied without touching the stratum that provides
it. A stack may have no create stratum, in which case nothing can be
created and nothing copied up.

Routing a modification is a decision about strata alone. It happens
when the modifying operation is performed, never at open, and it never
consults the caller: by the time an operation reaches stratafs, KACS
has already decided the caller was entitled to perform it. [Write Routing](</kernel/internals/stratafs/mutation/write-routing.md#trm-4-5-1>) sets
out why no other formulation is implementable.

<a id="trm-4-1-3"></a>

## What it delegates

stratafs holds no security descriptors, so it makes no access
decisions of its own about the objects it presents. The descriptor
evaluated for an operation is the one on the object the operation will
be performed against, and KACS reads it through the ordinary
extended-attribute path, which the stacking layer forwards down to the
provider. A stratafs mount cannot grant access its provider stratum
would refuse.

A merged directory is the exception, because it stands for several
real directories with several descriptors and forwarding yields only
the provider's. Those checks stratafs performs itself, against every
participating directory, requiring all of them to succeed ([Checks on Merged Directories](</kernel/internals/stratafs/security/checks-on-merged-directories.md#trm-4-6-2>)).

Copy-up is the other exception, in the opposite direction. It is
machinery serving an operation that was already authorised, not an
operation a caller requests, so it must introduce no new checks against
whichever task happens to execute it. KACS provides a kernel-internal
copy-up context for exactly this, described in full at [The StrataFS Copy-Up Context](</kernel/internals/stratafs/security/kacs-admission-and-object-phases.md#trm-3-9-7>); [Descriptors on Copy-Up](</kernel/internals/stratafs/security/copy-up-descriptors.md#trm-4-6-3>)
covers the stratafs half.

<a id="trm-4-1-4"></a>

## This chapter

[The Stratum Stack](</kernel/internals/stratafs/strata-and-mounting/the-stratum-stack.md#trm-4-2-1>) covers the stack, the mount options that define it, what a
mounter must be entitled to, and absent strata. [Lookup](</kernel/internals/stratafs/name-resolution/lookup-and-type-conflicts.md#trm-4-3-1>) covers resolution:
providers, merging, type conflicts, and enumeration. [The Coherency Model](</kernel/internals/stratafs/coherency/model-and-revalidation.md#trm-4-4-1>) covers
coherency — how uncoordinated change is observed, and the inode
identity presented over it. [Write Routing](</kernel/internals/stratafs/mutation/write-routing.md#trm-4-5-1>) covers mutation: routing, copy-up,
creation, removal, rename, links, locking and durability. [Access Check Delegation](</kernel/internals/stratafs/security/access-check-delegation.md#trm-4-6-1>) covers
the security seam with KACS, and [The Origin Attribute](</kernel/internals/stratafs/start-here/the-origin-attribute.md#trm-4-7>) the one interface stratafs
synthesises for userspace. [Failure Modes](</kernel/internals/stratafs/start-here/failure-modes.md#trm-4-8>) collects the failure modes, including
the divergences from ordinary filesystem behaviour that follow from
having no whiteouts, and [Constants](</kernel/internals/stratafs/start-here/generated-constants.md#trm-4-a>) the constants.

## Mounting and testing

See [StrataFS mount options](</kernel/administration/stratafs/mount-options.md>) for operation, and [StrataFS test hooks](</kernel/development/native-subsystems/stratafs-test-hooks.md>) for development.

## Topics

- [Security](</kernel/internals/stratafs/security/overview.md>)
- [Mutation](</kernel/internals/stratafs/mutation/overview.md>)
- [Strata and mounting](</kernel/internals/stratafs/strata-and-mounting/overview.md>)
- [Name resolution](</kernel/internals/stratafs/name-resolution/overview.md>)
- [Coherency](</kernel/internals/stratafs/coherency/overview.md>)

---

# The Origin Attribute

_Peios Kernel / Internals / StrataFS / Start here_

> The one synthetic extended attribute that reveals which stratum provided a merged path — its value, constraints and access rules.

<a id="trm-4-7"></a>

A merged path does not reveal which stratum provided it. stratafs
exposes that through one synthetic extended attribute,
`system.stratafs.origin`, and deliberately through nothing else — a
tool that instead re-implemented [Lookup](</kernel/internals/stratafs/name-resolution/lookup-and-type-conflicts.md#trm-4-3-1>)'s resolution rules against the
strata would be a second implementation of them, and would eventually
disagree with the first.

Together with the mount table ([Mount Options](</kernel/administration/stratafs/mount-options.md#trm-4-2-2>)), which gives the stratum stack,
it is enough to explain any path in a mount without privilege beyond
what reading the path itself requires.

<a id="trm-4-7-1"></a>

## The value

Reading the attribute returns the absolute path of the object that
provides it:

- For a **non-directory**, the provider's path in its stratum. <a id="cite-origin.value.non-directory"></a>
- For a **merged directory**, the paths of every participating
  directory in precedence order, separated by newlines. <a id="cite-origin.value.merged-directory"></a>

Each element is the stratum's own path, then a `/` where the relative
part is non-empty and the base does not already end in one, then the
relative path. <a id="cite-origin.value.element-format"></a> Within a path, a newline or a backslash is escaped by a
preceding backslash; those two are the whole escape set, and the `/`
stratafs itself inserts is not escaped. <a id="cite-origin.value.escaping"></a> Stratum paths are absolute
because the mount parser required them to be ([Mount Options](</kernel/administration/stratafs/mount-options.md#trm-4-2-2>)).

There is no trailing newline and no trailing NUL. <a id="cite-origin.value.no-trailing-terminator"></a> A null buffer returns
the length required; an undersized one returns `ERANGE`. <a id="cite-origin.value.sizing"></a>

The value is synthesised at each read from the current resolution. It
is not stored, and it is not the value of any attribute on any stratum. <a id="cite-origin.value.synthesised-per-read"></a>
Because non-root dentries are always invalidated ([Revalidation](</kernel/internals/stratafs/coherency/model-and-revalidation.md#trm-4-4-2>)), a read by
path always reflects a fresh resolution.

<a id="trm-4-7-2"></a>

## Constraints

The attribute is not settable. Any set or removal in the reserved
namespace fails with `EPERM`, before the provider is reached at all. <a id="cite-origin.not-settable"></a>

It is not reported by an attribute listing. The listing handler filters
reserved names out of both its sizing pass and its copy pass, and the
synthetic name is never added to any listing. <a id="cite-origin.hidden-from-listing"></a> Hiding it keeps
archivers, copy tools and backup software from discovering it,
attempting to preserve it, and failing.

The whole `system.stratafs.` namespace is reserved. No read, write or
removal of any name in it is forwarded to the provider: a read of any
name other than `origin` returns `ENODATA`, and a write or removal
returns `EPERM`. <a id="cite-origin.namespace-reserved"></a> Where a provider object carries a real attribute of
one of these names, it is masked — the synthesised value is returned
instead, and the provider's attribute is absent from listings through
the mount. <a id="cite-origin.masks-provider-attribute"></a>

Two details of the implementation are worth stating exactly. The
namespace test is a fixed-length prefix comparison against
`system.stratafs.` including the trailing dot, so the bare name
`system.stratafs` is *not* reserved and would be forwarded to the
provider. <a id="cite-origin.bare-name-not-reserved"></a> And the reserved set is one name wider than the namespace
suggests: the staging marker attribute,
`security.peios.stratafs_staging`, receives the same treatment —
`EPERM` to write, `ENODATA` to read, hidden from listings, masked from
providers — despite lying outside the `system.stratafs.` namespace. <a id="cite-origin.staging-marker-reserved"></a>

<a id="trm-4-7-3"></a>

## Access

Reading the attribute requires the access that reading an extended
attribute of the object requires, and is refused where that would be
refused. <a id="cite-origin.requires-read-ea"></a> The right to read the object's stat attributes is not
sufficient: the request is for the read-EA right, which KACS's
`getxattr` hook demands on the stratafs dentry before stratafs's own
handler runs.

For a merged directory the value names every participating directory,
so it discloses more than any one of them. Reading it requires that
access on **every** participating directory and is refused where any
refuses — the same intersection [Checks on Merged Directories](</kernel/internals/stratafs/security/checks-on-merged-directories.md#trm-4-6-2>) applies to enumeration, and for
the same reason: a caller who may not know a restricted directory
participates must not learn it from this attribute. <a id="cite-origin.merged-requires-all-participants"></a>

Where the attribute is read **through a directory descriptor**, the
participating set is the one settled when that descriptor was opened
([Enumeration](</kernel/internals/stratafs/name-resolution/enumeration.md#trm-4-3-4>)), and the value names that set rather than the current one. <a id="cite-origin.fd.settled-participant-set"></a> The
access decision was likewise made at open and is recorded on the
dentry, so the read consults a stored verdict rather than re-checking. <a id="cite-origin.fd.access-decided-at-open"></a>
A stratum that has joined since is not disclosed, because the check
that would have covered it was never run; a settled participant that
has since ceased to hold the directory is still named, for the same
reason.

Where it is read **by path**, the participating set is the current one,
resolved afresh, and the read-EA right is required against each of its
members at that moment. <a id="cite-origin.by-path.current-participant-set"></a>

---

# Failure Modes

_Peios Kernel / Internals / StrataFS / Start here_

> Every condition under which a stratafs operation fails and the error it produces, from mount time through resolution and mutation.

<a id="trm-4-8"></a>

This section consolidates the conditions under which a stratafs
operation fails and the error each produces. The sections above remain
authoritative for the conditions themselves.

<a id="trm-4-8-1"></a>

## Mount-time

| Condition | Error |
|---|---|
| Caller lacks the access to resolve a stratum path or read its attributes | `EACCES` |
| Empty stratum stack, or `strata=` absent | `EINVAL` |
| Stack longer than 16 strata | `EINVAL` |
| More than one stratum carries `create` | `EINVAL` |
| A stratum carries both `create` and `ro` | `EINVAL` |
| The same directory appears twice in the stack | `EINVAL` |
| Any malformed `strata=` value ([Mount Options](</kernel/administration/stratafs/mount-options.md#trm-4-2-2>)) | `EINVAL` |
| A remount's `strata=` differs from the mounted stack ([Mount Options](</kernel/administration/stratafs/mount-options.md#trm-4-2-2>)) | `EINVAL` |
| An allocation failure while parsing | `ENOMEM` |
| A create-bearing stack established outside the initial user namespace, or without `CAP_SYS_ADMIN` there | `EPERM` |
| A stratum path names a non-directory | `ENOTDIR` |
| A stratum is absent without `am` | `ENOENT` |
| A stratum lies within the mount point, or within another stratafs mount whose strata include this mount point | `ELOOP` |
| The composed stack reaches the kernel's maximum stacking depth | `ELOOP` |
| Sixteen consecutive collisions allocating a mount cookie | `EAGAIN` |

The option-only conditions are decided before any path is touched, and
the `EPERM` admission test before any path is resolved. <a id="cite-failure.mount.option-checks-precede-path-checks"></a> The per-path
conditions follow. [Mount Admission](</kernel/internals/stratafs/strata-and-mounting/mount-admission.md#trm-4-2-3>) records the one place the specified ordering
is not achieved.

<a id="trm-4-8-2"></a>

## Resolution

| Condition | Error |
|---|---|
| No participating stratum holds the name | `ENOENT` |
| An ancestor of the path is masked by a non-directory provider | `ENOTDIR` |
| Operation requires a non-directory; provider is a directory | `EISDIR` |
| Traverse or list refused on any participating directory | `EACCES` |
| A stratum walk fails for a reason other than absence | that error |
| A joined stratum path or child relative path exceeds `PATH_MAX` | `ENAMETOOLONG` |
| A task re-enters the same superblock while resolving | `ELOOP` |

<a id="trm-4-8-3"></a>

## Mutation

| Condition | Error |
|---|---|
| Provider will not accept modification, and no create stratum has higher precedence | `EROFS` |
| Any mutation on a read-only-mounted stratafs | `EROFS` |
| Creation, unnamed-file creation, or unnamed-file link with no create stratum, or it absent | `EROFS` |
| Create stratum holds a path component as a non-directory | `ENOTDIR` |
| Exclusive creation where any stratum holds the name | `EEXIST` |
| Copy-up cannot preserve an extended attribute | `EIO` |
| Copy-up cannot preserve the descriptor | `EACCES`, `EOPNOTSUPP`, `EINVAL`, `ESTALE` or `ENOMEM`, as KACS reported it |
| Copy-up for a descriptor whose object is no longer the provider, or whose target name is taken at publication | `ESTALE` |
| Copy-up of a device node, FIFO or socket | `EROFS` |
| Unlink where the provider will not accept modification | `EROFS`, or `EPERM` where the provider inode is immutable |
| Rmdir where another stratum holds entries within | `ENOTEMPTY` |
| Rmdir or directory rename where list is refused on a participant | `EACCES` |
| Modifying a special file's mode, descriptor or extended attributes where its provider will not accept modification | `EROFS` |
| Establishing a shared write-capable mapping where routing yields read-only | `EROFS` |
| A route change after shared mapping preparation could require another copy-up | `EAGAIN`; retry the whole `mmap` call |
| StrataFS or FUSE passthrough layers exceed the supported stacking depth during shared mapping preparation | `ELOOP` |
| Replacing disposition where [Removal](</kernel/internals/stratafs/mutation/removal.md#trm-4-5-4>) would refuse the removal, or where a stratum above the create stratum would still hold the name | `EROFS` |
| Replacing disposition on anything but a regular file | `EOPNOTSUPP` |
| Rename where the source's provider will not accept modification | `EROFS` |
| Rename where a stratum above the source's provider provides the destination | `EROFS` |
| Rename where the source's provider does not hold the destination's directory | `EXDEV` |
| Rename of a directory containing entries from other strata | `EXDEV` |
| Rename of a non-directory onto a directory provider | `EISDIR` |
| Rename of a directory onto a non-directory provider | `ENOTDIR` |
| Rename onto a destination directory not empty across every stratum | `ENOTEMPTY` |
| `RENAME_NOREPLACE` where any stratum holds the destination | `EEXIST` |
| `RENAME_EXCHANGE` where the two names are not provided by one stratum that accepts modification | `EROFS` |
| `RENAME_EXCHANGE` where another stratum holds entries under either directory name | `EXDEV` |
| `RENAME_WHITEOUT` | `EINVAL` |
| Hard link whose source's provider will not accept modification, or does not hold the destination's directory | `EXDEV` |
| Hard link where any stratum holds the destination | `EEXIST` |
| Linking an unnamed file into a different mount | `EXDEV` |
| A dentry whose private state is missing, or whose provider identity no longer matches | `ESTALE` |
| `ioctl` on a regular file | `ENOTTY`, or `ENOIOCTLCMD` for the compat form |
| `remap_file_range` with flags outside dedupe and advisory | `EINVAL` |

Shared mapping preparation can publish a copy-up before a later mapping
check fails. That copy remains published; the mapping failure does not
restore the earlier provider. Copies completed by earlier layers also
remain if preparation fails deeper in the backing chain.

<a id="trm-4-8-4"></a>

## Interface

| Condition | Error |
|---|---|
| Set or remove of any reserved attribute | `EPERM` |
| Read of a reserved attribute other than `origin` | `ENODATA` |
| Origin read where read-EA is refused on any participant | `EACCES` |
| Origin read into an undersized buffer | `ERANGE` |
| Freezing the filesystem | `EOPNOTSUPP` |
| Reading a mount's policy without TCB privilege | refused by KACS |

<a id="trm-4-8-5"></a>

## Intended divergences

None of the following is a defect. Each is described above, and each
follows from stratafs having no way to record that a name should be
absent, or from a merged path standing for objects in more than one
stratum.

- **Removing a name may not remove it from the view.** Where a lower
  stratum also holds the name, it becomes the provider and the name
  remains, now resolving to different content ([Removal](</kernel/internals/stratafs/mutation/removal.md#trm-4-5-4>)).
- **A name may be unremovable.** Where the provider will not accept
  modification, removal fails however the caller is privileged
  ([Removal](</kernel/internals/stratafs/mutation/removal.md#trm-4-5-4>)).
- **Rename may be refused for an unmodified file.** Where the source's
  provider will not accept modification, rename fails rather than
  silently copying ([Rename](</kernel/internals/stratafs/mutation/rename.md#trm-4-5-5>)).
- **Hard links may be refused within one directory.** Where the
  source's provider will not accept modification, linking fails with
  `EXDEV` ([Links](</kernel/internals/stratafs/mutation/links.md#trm-4-5-6>)).
- **An object's inode number may change.** Where the provider for a
  path changes, a new inode is presented ([Inode Identity and Lifecycle](</kernel/internals/stratafs/coherency/inode-identity-and-lifecycle.md#trm-4-4-3>)).
- **Two callers may hold non-contending locks on one path.** Locks are
  held on the object a descriptor resolved to, so callers who opened
  either side of a change of provider — including one caused by a
  copy-up neither of them performed — have locked different objects
  ([Locking](</kernel/internals/stratafs/mutation/locking.md#trm-4-5-7>)).
- **Copy-up severs hard links.** Two names that shared an object in a
  lower stratum, and compared equal by inode number, refer to different
  objects once one of them is written through the mount; only the
  written one is copied up ([Copy-Up](</kernel/internals/stratafs/mutation/copy-up.md#trm-4-5-2>)).
- **An open may succeed where the first write then fails.** Routing
  happens when a modifying operation is performed, not at open, so an
  open for writing against a provider that will not accept modification
  succeeds and the `EROFS` arrives at the write, the truncate, or the
  attempt to establish a shared writable mapping ([Write Routing](</kernel/internals/stratafs/mutation/write-routing.md#trm-4-5-1>)).
- **A copy-up moves an object out from under descriptors already open
  on it.** Only the descriptor whose operation caused the copy-up refers
  to the copy; others continue to refer to the original, and locks held
  on it stay there ([Write Routing](</kernel/internals/stratafs/mutation/write-routing.md#trm-4-5-1>), [Locking](</kernel/internals/stratafs/mutation/locking.md#trm-4-5-7>)).
- **A write may fail `ESTALE` on a descriptor that was valid when
  opened.** Where another descriptor, another mount, or a direct writer
  has since caused that name to be provided by a different object, a
  copy-up cannot proceed and the caller must reopen ([Copy-Up](</kernel/internals/stratafs/mutation/copy-up.md#trm-4-5-2>)).
- **`fstat` and `stat` may report different inode numbers for one
  file.** After a copy-up, the descriptor that caused it keeps the inode
  it was opened against while a fresh resolution of the path yields a
  new one, so the two disagree for as long as that descriptor lives —
  though both name the copy ([Inode Identity and Lifecycle](</kernel/internals/stratafs/coherency/inode-identity-and-lifecycle.md#trm-4-4-3>)).
- **A directory's link count is always 1.** The true count of
  subdirectories spans strata and cannot be maintained ([Inode Identity and Lifecycle](</kernel/internals/stratafs/coherency/inode-identity-and-lifecycle.md#trm-4-4-3>)).
- **Directory positions do not survive a reopen.** A `readdir` offset
  is an ordinal into a per-descriptor capture, carrying no provider
  cookie ([Enumeration](</kernel/internals/stratafs/name-resolution/enumeration.md#trm-4-3-4>)).

Every one of the first four is the result of refusing to invent a
hidden record — a whiteout — that would make an entry in someone else's
directory unreachable without their knowledge. The alternative buys
POSIX fidelity at the cost of a stratum no longer meaning what its
owner wrote in it, which is the property [The Stratum Stack](</kernel/internals/stratafs/strata-and-mounting/the-stratum-stack.md#trm-4-2-1>) exists to protect.

---

# Generated constants

_Peios Kernel / Internals / StrataFS / Start here_

> Every stratafs constant — filesystem identity, stratum flags, extended attributes, copy-up and staging markers — generated from the source.

<a id="trm-4-a"></a>

Every value below is generated from the source by
`tools/docs/peios-reference/generators/gen-stratafs-constants.py`. Nothing here is transcribed by
hand, and the generator's `--check` mode fails if the two drift apart. <a id="cite-const.generated-from-source"></a>

<a id="trm-4-a-1"></a>

## Filesystem identity <a id="cite-const.magic-alias-shared-with-kacs"></a>

| Constant              | Value        | Meaning                                         |
|-----------------------|--------------|-------------------------------------------------|
| `STRATAFS_MAGIC`      | `0x53545241` | Superblock magic, reported by `statfs` ([Mount Options](</kernel/administration/stratafs/mount-options.md#trm-4-2-2>)) |
| `STRATAFS_NAME`       | `"stratafs"` | The name the filesystem registers under         |
| `STRATAFS_MAX_STRATA` | `16`         | Longest stratum stack accepted ([The Stratum Stack](</kernel/internals/stratafs/strata-and-mounting/the-stratum-stack.md#trm-4-2-1>))         |

`STRATAFS_MAGIC` is an alias for `STRATAFS_SUPER_MAGIC`, which is
declared in the header stratafs shares with KACS so that the mount
policy class keyed on it cannot drift ([Mount Policy](</kernel/internals/stratafs/security/mount-policy.md#trm-4-6-4>)).

<a id="trm-4-a-2"></a>

## Stratum flags

| Constant            | Value | Meaning                    |
|---------------------|-------|----------------------------|
| `STRATAFS_F_CREATE` | `0x1` | The `create` flag ([The Stratum Stack](</kernel/internals/stratafs/strata-and-mounting/the-stratum-stack.md#trm-4-2-1>)) |
| `STRATAFS_F_RO`     | `0x2` | The `ro` flag              |
| `STRATAFS_F_AM`     | `0x4` | The `am` flag              |

<a id="trm-4-a-3"></a>

## Extended attributes

| Constant                 | Value                               | Meaning                                                  |
|--------------------------|-------------------------------------|----------------------------------------------------------|
| `STRATAFS_XATTR_PREFIX`  | `"system.stratafs."`                | Reserved namespace; never forwarded to a provider ([The Origin Attribute](</kernel/internals/stratafs/start-here/the-origin-attribute.md#trm-4-7>)) |
| `STRATAFS_XATTR_ORIGIN`  | `"system.stratafs.origin"`          | Synthetic, read-only, hidden from listings ([The Origin Attribute](</kernel/internals/stratafs/start-here/the-origin-attribute.md#trm-4-7>))        |
| `STRATAFS_XATTR_STAGING` | `"security.peios.stratafs_staging"` | Copy-up staging marker; also reserved ([Copy-Up](</kernel/internals/stratafs/mutation/copy-up.md#trm-4-5-2>))           |

`STRATAFS_XATTR_STAGING` is an alias for `STRATAFS_STAGING_XATTR`,
declared in the shared header. Note the name it resolves to lies
outside the reserved `system.stratafs.` namespace, yet receives the
same treatment ([The Origin Attribute](</kernel/internals/stratafs/start-here/the-origin-attribute.md#trm-4-7>)).

The canonical security-descriptor attribute is KACS's, not
stratafs's; stratafs only detects it in order to exclude it from
copy-up replication ([Descriptors on Copy-Up](</kernel/internals/stratafs/security/copy-up-descriptors.md#trm-4-6-3>)).

<a id="trm-4-a-4"></a>

## Copy-up and staging

| Constant                        | Value                | Meaning                                     |
|---------------------------------|----------------------|---------------------------------------------|
| `STRATAFS_STAGE_MARKER_MAGIC`   | `0x53544731`         | Marker magic                                |
| `STRATAFS_STAGE_MARKER_VERSION` | `1`                  | Marker version                              |
| `STRATAFS_COPY_BUFFER_SIZE`     | `65536`              | Copy-up read/write chunk, in bytes ([Copy-Up](</kernel/internals/stratafs/mutation/copy-up.md#trm-4-5-2>)) |
| `STRATAFS_STAGE_PREFIX`         | `".stratafs-stage-"` | Staged-name prefix                          |
| `STRATAFS_RECOVERY_BATCH`       | `128`                | Names scanned per staging-recovery pass     |

<a id="trm-4-a-4-1"></a>

### The staging marker <a id="cite-const.stage-marker-layout"></a>

`struct stratafs_stage_marker` is packed and 24 bytes, all fields
little-endian. It is the value of the staging attribute above.

| Offset | Size | Field          | Type     |
|--------|------|----------------|----------|
| 0      | 4    | `magic`        | `__le32` |
| 4      | 2    | `version`      | `__le16` |
| 6      | 2    | `size`         | `__le16` |
| 8      | 8    | `boot_cookie`  | `__le64` |
| 16     | 8    | `mount_cookie` | `__le64` |

<a id="trm-4-a-5"></a>

## Routing <a id="cite-const.route-discriminants-match-rust"></a>

The value `route_existing` returns ([Write Routing](</kernel/internals/stratafs/mutation/write-routing.md#trm-4-5-1>)), as the Rust decision
core names it and as the C glue mirrors it. The discriminants match.

| C enumerator               | Value | Rust       |
|----------------------------|-------|------------|
| `STRATAFS_ROUTE_IN_PLACE`  | `0`   | `InPlace`  |
| `STRATAFS_ROUTE_COPY_UP`   | `1`   | `CopyUp`   |
| `STRATAFS_ROUTE_READ_ONLY` | `2`   | `ReadOnly` |

<a id="trm-4-a-6"></a>

## The decision core

`stratafs-core` holds the stack-wide flag rules, provider selection,
and routing. Its flag bits match the C ones above exactly. <a id="cite-const.core-flag-bits-match-c"></a>

| Constant          | Value |
|-------------------|-------|
| `MAX_STRATA`      | `16`  |
| `FLAG_CREATE`     | `0x1` |
| `FLAG_READ_ONLY`  | `0x2` |
| `FLAG_ABSENT_MAY` | `0x4` |
| `FLAG_MASK`       | `0x7` |

The crate distinguishes these configuration errors. The C boundary
collapses all of them to `EINVAL`, so the distinction is not
observable to a caller ([The Stratum Stack](</kernel/internals/stratafs/strata-and-mounting/the-stratum-stack.md#trm-4-2-1>)). <a id="cite-const.config-errors-collapse-to-einval"></a>

| Error            | Discriminant |
|------------------|--------------|
| `Empty`          | `1`          |
| `TooMany`        | `2`          |
| `UnknownFlag`    | `3`          |
| `RepeatedCreate` | `4`          |
| `CreateReadOnly` | `5`          |

<a id="trm-4-a-7"></a>

## Build configuration <a id="cite-const.build-kconfig-option"></a>

stratafs is built by `CONFIG_STRATAFS_FS`, a boolean option, so what it
builds is linked into `vmlinux` rather than loaded. It depends on
`CONFIG_SECURITY_PKM` and selects `FS_STACK`. Its sources are staged
into the kernel tree as `fs/stratafs`, separate from PKM's own
`security/pkm`. `CONFIG_STRATAFS_FS_TEST_HOOKS` compiles the test rendezvous and fail points ([Stratum flags](</kernel/internals/stratafs/start-here/generated-constants.md#trm-4-a-2>)),
inert unless the kernel is booted with `stratafs.test_hooks=1`. `CONFIG_STRATAFS_KUNIT_TEST` builds the in-kernel unit tests.

The translation units are:

- `super.o`
- `lookup.o`
- `inode.o`
- `file.o`
- `dir.o`
- `dir_cache.o`
- `xattr.o`
- `copy_up.o`
