Expand description
§The namespace layer: one tree for the app, many mounted backends underneath
To a caller there is a single file structure rooted at / (NsPath). Under it is a mount table
(Namespace); each mount is a Backend. Today the backends are HostDir (an OS directory, confined with
cap-std) and Memory (tests and scratch). The five verbs are the studio’s namespace verbs: walk, read,
write, watch, and manifest (here Stat).
Status: new, and not frozen. Unlike the engine’s locked surface, the Backend trait and the ns types may still change
(pre-1.0, a break is a minor bump). The trait stays unfrozen until a read-only content-addressed backend has been written
against it, because a trait shaped by two simple backends can bend when a third arrives.
This layer is independent of the content-addressed engine in the rest of this crate. It uses only std,
cap-std (with its companions cap-fs-ext, and cap-primitives on Windows), unicode-normalization and its own
NsError; none of the engine’s types or dependencies appear in it
(a test checks the source). It is built by the ns feature.
The design in brief:
- Sync, path-addressed, stateless. No file handle appears in any public trait, so a mount can later be served across a wire. An async adapter is a later layer.
- A portable name grammar, checked by one validator for every backend (
path): NFC only, no./.., no Windows reserved names, no case-colliding siblings. A name that is legal on Linux but breaks on a Mac or Windows is refused here, not discovered later. - Every read and
statreturns aVersion, andwritetakesif_version: optimistic concurrency from the first release, because adding it later would change what a call means. It is exact onMemoryand best effort onHostDir, andCapssays which. writehas a closed set of ops (WriteOp):CreateExclusive,Replace(atomic),Remove,RenameWithinMount,MakeDir. These are arguments towrite, not new verbs.appendandat_offsetare reserved.- Confinement is the Kit’s; policy is the embedder’s. The Kit refuses
.., symlinks, reparse points and devices inside the root it is given, andReplaceof a file with more than one hard link is refused (HardLinked;RemoveandRenameWithinMountact on the name and are allowed, and no operation opens an existing file for writing, so the contents of a file reachable by another name are never changed). It does not refuse to read such a file: a hard link to a file elsewhere on the same filesystem, made by anyone who can write the directory, is served like any other file (Stat::linksreports the count, but a check before the read is racy; seeHostDir). It has no notion of which host directories may be mounted, or by whom: the embedder supplies the resolver and the grants. - Watching is a hint to re-read (
Watch,WatchBatch): a polling source in the Kit (std only), batches numbered by(epoch, generation)so a gap is a rescan, namespace paths only. - Errors never carry a host path (
NsError). - Backends say what they cannot do (
Caps, a typed struct) and theconformancesuite (featureconformance) runs the same cases against every backend, skipping and reporting what a backend declares missing.
use std::sync::Arc;
use storage_kit::ns::{Access, Memory, Namespace, NsPath, WriteOp};
let scratch = Arc::new(Memory::new());
let ns = Namespace::builder()
.mount(NsPath::parse("/scratch")?, scratch, Access::ReadWrite)
.build()?;
let file = NsPath::parse("/scratch/hello.txt")?;
let v1 = ns.write(&file, WriteOp::Replace, b"hello", None)?;
let (bytes, version) = ns.read(&file, 1024)?;
assert_eq!(bytes, b"hello");
assert_eq!(v1, version);
// Optimistic concurrency: this succeeds only if nobody changed the file since `version`.
ns.write(&file, WriteOp::Replace, b"hello, world", Some(&version))?;
assert!(ns.write(&file, WriteOp::Replace, b"stale", Some(&version)).is_err());§What is not here yet
A native (inotify, FSEvents, ReadDirectoryChangesW) watcher, a content-addressed (Cas) mount, remote mounts,
attributes and queries, and a handle-based or streaming read. Each is additive behind the same traits; none is
promised by this release.
Re-exports§
pub use backend::Access;pub use backend::Backend;pub use backend::Caps;pub use backend::Entry;pub use backend::Kind;pub use backend::Stat;pub use backend::Version;pub use backend::WatchKind;pub use backend::WriteOp;pub use error::Feature;pub use error::InputReason;pub use error::NsError;pub use error::NsErrorKind;pub use error::NsResult;pub use hostdir::HostDir;pub use memory::Memory;pub use memory::MemoryOptions;pub use namespace::Namespace;pub use namespace::NamespaceBuilder;pub use path::case_fold_key;pub use path::is_format_character;pub use path::validate_name;pub use path::NsPath;pub use path::PathReason;pub use path::MAX_NAME_BYTES;pub use path::MAX_PATH_BYTES;pub use path::TEMP_PREFIX;pub use watch::Watch;pub use watch::WatchBatch;pub use watch::WatchCursor;pub use watch::WatchOpts;pub use watch::DEFAULT_INTERVAL;pub use watch::DEFAULT_MAX_DEPTH;pub use watch::DEFAULT_MAX_ENTRIES;pub use watch::DEFAULT_MAX_TRACKED;pub use watch::MAX_INTERVAL;pub use watch::MIN_INTERVAL;pub use watch::QUEUE_DEPTH;
Modules§
- backend
- The
Backendtrait and the plain-data types that cross it. - conformance
- The conformance suite: the same cases against every backend.
- error
NsError: the one error type of the namespace layer.- hostdir
HostDir: a mount over an operating-system directory, confined withcap-std.- memory
Memory: an in-memory mount with exact versions, for tests and scratch trees.- namespace
Namespace: one tree for the app, a table of mounts underneath.- path
NsPath: a validated namespace path, and the portable name grammar every backend enforces through it.- watch
- Watching a directory:
Watch,WatchBatch,WatchOpts, and the std-only polling engineHostDiruses.