1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
//! The [`Backend`] trait and the plain-data types that cross it.
//!
//! This is the contract a mount implements. It is **synchronous, path-addressed and stateless**: there is no file handle
//! anywhere in it, because a handle cannot cross a remote boundary and a stateless call can be replayed, logged and
//! served. (An async adapter is a later layer over this, not a change to it.)
//!
//! It is also deliberately *not* the engine's `backend` module: that one is a block transport under the
//! content-addressed store. This one is a file tree. The two share no types.
//!
//! Every path a `Backend` receives is **relative to its mount** (the mount root is `/`). A backend never sees, and never
//! returns, the namespace path it is mounted at; the [`Namespace`](super::Namespace) adds and strips that prefix.
use fmt;
use SystemTime;
use NsResult;
use NsPath;
use ;
/// An opaque token for "the state this entry was in when you looked".
///
/// Returned by every `read`, `stat` and `write`; handed back as `if_version` to say "only if nothing changed".
///
/// - **An opaque equality token.** Compare for equality, nothing else: the bytes mean different things per backend and
/// are not stable across versions of this crate. Do not order, parse or persist one across an upgrade.
/// - **Valid only against its own mount.** A version taken from one mount means nothing to another: `Memory` makes
/// every instance's versions distinct, and a `HostDir` version carries the file's device and inode. Offered to the
/// wrong mount it is a `VersionMismatch`, never a match.
/// - **A file's version** changes whenever its content is replaced (`HostDir` derives it from mtime in nanoseconds,
/// size, inode and device; `Memory` from a counter).
/// - **A directory's version** changes **at least whenever its set of entries changes** (an entry added, removed or
/// renamed in it). It may change more often (a backend is free to bump it for other reasons), so use it as "something
/// may have changed, re-list", never as "exactly these entries changed". It does *not* promise to change when an
/// entry's content changes.
;
/// What an entry is. The namespace has exactly two kinds; everything else on a host disk is refused or hidden.
/// One name in a directory listing.
/// The `manifest` verb: what is known about one entry.
///
/// `owner`, `mode` and `links` are `Some` only where the backend has them (see [`Caps::owner_mode`]); the caller's
/// policy decides what to do with them. The Kit reports, it does not judge: whether "owned by you and not writable by
/// group or others" is acceptable is the embedder's rule.
/// An argument of the namespace verb `write`: **not new verbs**. The set is closed per release (`non_exhaustive`).
///
/// `append` and `at_offset` are **reserved and not implemented**: partial writes need a position model that survives a
/// remote hop and a `Cas` commit, and that is not settled. Do not simulate them with read-modify-write.
///
/// Except where noted, every op takes its data from the `data` argument of [`Backend::write`] (empty for ops that take
/// none; non-empty data on those is `InvalidInput`).
/// What a watch is built from. Typed, so a caller can branch on it without parsing a string.
/// What a mount can and cannot do, and where it is weaker than it looks. A typed struct, not strings.
///
/// A capability that is `false` (or [`WatchKind::None`]) means the operation returns
/// [`NsErrorKind::Unsupported`](super::NsErrorKind::Unsupported), and the conformance suite checks that it does.
/// A mount's grant, enforced by the [`Namespace`](super::Namespace) on top of the backend's own [`Caps::writable`].
///
/// **The grant belongs to the mount, not to the data behind it.** `ReadOnly` means "nothing written *through this mount*
/// changes anything"; it does not make the host directory read-only. If the embedder also mounts the same directory, or
/// one inside it, read-write somewhere else, or another process writes it, what this mount reads changes. The Kit
/// enforces the grant per mount and the embedder chooses the host directories, so choose them to be disjoint. The one
/// overlap the Kit can see, the *same* directory mounted twice, is refused at `build()`
/// (`InvalidInput(DuplicateRoot)`); a directory mounted together with one of its ancestors or descendants is not
/// detected, because the Kit holds no host paths by design (see [`Backend::root_identity`]).
/// A mount: a file tree behind one root, addressed by path.
///
/// Implementations must enforce the portable name grammar (it comes for free from [`NsPath`], and any name read back
/// from the backing store goes through [`validate_name`](super::validate_name)), must refuse to create a name that
/// case-folds to an existing sibling (`CaseCollision`), and must return `Unsupported` for anything their [`Caps`] say
/// they cannot do. The [`conformance`](super::conformance) suite checks all of it.
///
/// **This trait is not frozen** (see the [module docs](super)). New methods arrive with a default body, so an existing
/// implementation keeps compiling and behaves as if the new capability were absent; [`Backend::root_identity`] was added
/// that way. A method without a default would be a breaking change and a minor bump while pre-1.0.