@effect-vfs/nfs 0.5.0 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -20,7 +20,7 @@ The package describes what it does with a capability profile and how well that i
20
20
  | `read-only-local` | complete read path, `NFS4ERR_ROFS` on mutation, loopback binding, `AUTH_SYS` accepted as untrusted, backchannel and connection binding | preview |
21
21
  | `read-only-networked` | `AUTH_SYS` identity mapped to VFS callers by application policy, non-loopback binding behind that policy and an explicit opt-in | experimental |
22
22
  | `writable` | create, write, rename, remove, durable `WRITE` and `COMMIT`, share reservations, and advisory byte-range locks | experimental |
23
- | `stateful` | grace and reclaim, restart recovery, persistent filehandles | not public |
23
+ | `stateful` | grace and reclaim, restart recovery of sessions, opens, and locks | not public |
24
24
 
25
25
  The current read-only export tracks advisory byte-range read locks between NFS clients. `LOCK` requires an open stateid; `LOCKU` releases an exact range. Write locks still return `NFS4ERR_ROFS`. `maxLockOwners` and `maxLocks` bound the in-memory state, which is removed on lease expiry or client revocation. Direct VFS callers do not participate in NFS locks.
26
26
 
@@ -32,8 +32,10 @@ The optional `writable: true` profile is limited to one gateway owning one quali
32
32
  must prevent another gateway from opening the same storage image; the server does not provide a distributed lease.
33
33
  Successful mutations rely on the live provider's synchronous commit guarantee. The [R2 writable test app](../../apps/demo-r2-nfs/README.md)
34
34
  shows the public API with a bounded R2 image, a trusted-client policy, mounted Debian and macOS checks, restart
35
- recovery, and an injected lost R2 HTTP response. Remount clients after gateway restart; this is not the `stateful`
36
- recovery profile. Do not set a stronger `Volume.durability` for an unqualified storage provider.
35
+ recovery, and an injected lost R2 HTTP response. Filehandles carry the object's core reference key, so over a volume
36
+ whose commits survive at least a process crash they persist across a restart and `fh_expire_type` reports
37
+ `FH4_PERSISTENT`. The key's tag keeps a client from forging a handle for an object by guessing its inode number. Sessions, opens, and locks do not survive, so remount clients after gateway restart; this is not
38
+ the `stateful` recovery profile. Do not set a stronger `Volume.durability` for an unqualified storage provider.
37
39
 
38
40
  In local mode, one application-supplied caller performs every read. Decoded `AUTH_SYS` fields never grant VFS authority, and ACCESS answers derived from them are advisory. In networked mode, the application supplies a peer resolver evaluated for each accepted socket and a policy that maps the decoded credential and peer to a VFS identity or denies it. The server creates and caches callers per distinct identity, bounded by `maxIdentities`. Policy denials and cache exhaustion answer RPC `AUTH_FAILED` before the compound executes. A resolver returning `null` closes the connection. UNIX peers have `address: null` and `port: null`; `path` is the server socket path, not a client address. Applications must enforce their trusted-client boundary in the policy. This profile is experimental: protocol and socket tests pass, but a networked kernel-client gate has not been recorded. See the [authentication and export policy decision](https://github.com/lloydrichards/effect-virtual-fs/blob/main/.okf/decisions/nfs/nfs-authentication-and-export-policy.md).
39
41
 
@@ -99,7 +101,8 @@ bun run --filter @repo/nfs-preview start
99
101
  ```
100
102
 
101
103
  Applications continue writing through the VFS API while native clients read the mounted view. Stop the server,
102
- unmount, and mount again after a restart because filehandles and sessions are intentionally volatile.
104
+ unmount, and mount again after a restart because its memory volume's filehandles and every session are intentionally
105
+ volatile.
103
106
 
104
107
  Run the focused checks from this directory:
105
108
 
@@ -74,7 +74,6 @@ declare const NfsServerLimitsSchema: Schema.Struct<{
74
74
  readonly maxReaddirEntries: Schema.Finite;
75
75
  readonly maxReaddirReplyBytes: Schema.ByteSize;
76
76
  readonly maxNameBytes: Schema.ByteSize;
77
- readonly maxFilehandles: Schema.Finite;
78
77
  }>;
79
78
  /**
80
79
  * Every resource bound enforced by the preview server.
@@ -118,7 +117,6 @@ export declare const NfsServerLimits: Schema.Struct<{
118
117
  readonly maxReaddirEntries: Schema.Finite;
119
118
  readonly maxReaddirReplyBytes: Schema.ByteSize;
120
119
  readonly maxNameBytes: Schema.ByteSize;
121
- readonly maxFilehandles: Schema.Finite;
122
120
  }> & {
123
121
  constrained: {
124
122
  readonly maxConnections: number;
@@ -149,7 +147,6 @@ export declare const NfsServerLimits: Schema.Struct<{
149
147
  readonly maxReaddirEntries: number;
150
148
  readonly maxReaddirReplyBytes: ByteSize.ByteSize;
151
149
  readonly maxNameBytes: ByteSize.ByteSize;
152
- readonly maxFilehandles: number;
153
150
  };
154
151
  default: {
155
152
  readonly maxConnections: number;
@@ -180,7 +177,6 @@ export declare const NfsServerLimits: Schema.Struct<{
180
177
  readonly maxReaddirEntries: number;
181
178
  readonly maxReaddirReplyBytes: ByteSize.ByteSize;
182
179
  readonly maxNameBytes: ByteSize.ByteSize;
183
- readonly maxFilehandles: number;
184
180
  };
185
181
  };
186
182
  /**
@@ -218,7 +214,6 @@ export declare const NfsServerLimitOverrides: Schema.Struct<{
218
214
  readonly maxReaddirEntries: Schema.optionalKey<Schema.Finite>;
219
215
  readonly maxReaddirReplyBytes: Schema.optionalKey<Schema.ByteSize>;
220
216
  readonly maxNameBytes: Schema.optionalKey<Schema.ByteSize>;
221
- readonly maxFilehandles: Schema.optionalKey<Schema.Finite>;
222
217
  }>;
223
218
  /**
224
219
  * A selective override of the default NFS server resource policy.
@@ -261,7 +256,6 @@ declare const NfsServerConfigSchema: Schema.Struct<{
261
256
  readonly maxReaddirEntries: Schema.Finite;
262
257
  readonly maxReaddirReplyBytes: Schema.ByteSize;
263
258
  readonly maxNameBytes: Schema.ByteSize;
264
- readonly maxFilehandles: Schema.Finite;
265
259
  }> & {
266
260
  constrained: {
267
261
  readonly maxConnections: number;
@@ -292,7 +286,6 @@ declare const NfsServerConfigSchema: Schema.Struct<{
292
286
  readonly maxReaddirEntries: number;
293
287
  readonly maxReaddirReplyBytes: ByteSize.ByteSize;
294
288
  readonly maxNameBytes: ByteSize.ByteSize;
295
- readonly maxFilehandles: number;
296
289
  };
297
290
  default: {
298
291
  readonly maxConnections: number;
@@ -323,7 +316,6 @@ declare const NfsServerConfigSchema: Schema.Struct<{
323
316
  readonly maxReaddirEntries: number;
324
317
  readonly maxReaddirReplyBytes: ByteSize.ByteSize;
325
318
  readonly maxNameBytes: ByteSize.ByteSize;
326
- readonly maxFilehandles: number;
327
319
  };
328
320
  };
329
321
  }>;
@@ -373,7 +365,6 @@ export declare const NfsServerConfig: Schema.Struct<{
373
365
  readonly maxReaddirEntries: Schema.Finite;
374
366
  readonly maxReaddirReplyBytes: Schema.ByteSize;
375
367
  readonly maxNameBytes: Schema.ByteSize;
376
- readonly maxFilehandles: Schema.Finite;
377
368
  }> & {
378
369
  constrained: {
379
370
  readonly maxConnections: number;
@@ -404,7 +395,6 @@ export declare const NfsServerConfig: Schema.Struct<{
404
395
  readonly maxReaddirEntries: number;
405
396
  readonly maxReaddirReplyBytes: ByteSize.ByteSize;
406
397
  readonly maxNameBytes: ByteSize.ByteSize;
407
- readonly maxFilehandles: number;
408
398
  };
409
399
  default: {
410
400
  readonly maxConnections: number;
@@ -435,7 +425,6 @@ export declare const NfsServerConfig: Schema.Struct<{
435
425
  readonly maxReaddirEntries: number;
436
426
  readonly maxReaddirReplyBytes: ByteSize.ByteSize;
437
427
  readonly maxNameBytes: ByteSize.ByteSize;
438
- readonly maxFilehandles: number;
439
428
  };
440
429
  };
441
430
  }> & {
@@ -471,7 +460,6 @@ export declare const NfsServerConfig: Schema.Struct<{
471
460
  readonly maxReaddirEntries: number;
472
461
  readonly maxReaddirReplyBytes: ByteSize.ByteSize;
473
462
  readonly maxNameBytes: ByteSize.ByteSize;
474
- readonly maxFilehandles: number;
475
463
  };
476
464
  };
477
465
  };
@@ -513,7 +501,6 @@ export declare const NfsServerConfigOverrides: Schema.Struct<{
513
501
  readonly maxReaddirEntries: Schema.optionalKey<Schema.Finite>;
514
502
  readonly maxReaddirReplyBytes: Schema.optionalKey<Schema.ByteSize>;
515
503
  readonly maxNameBytes: Schema.optionalKey<Schema.ByteSize>;
516
- readonly maxFilehandles: Schema.optionalKey<Schema.Finite>;
517
504
  }>>;
518
505
  }>;
519
506
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"NfsServer.d.ts","sourceRoot":"","sources":["../src/NfsServer.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,OAAO,EAAE,i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MAAM,CAAA;IACvB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAA;CACzB,CAAC;CAAG;;;;AAEL;;;;;GAKG;AACH,qBAAa,cAAe,SAAQ,oBAAmC;IACrE,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAA;CACxB,CAAC;IACA,IAAa,OAAO,IAAI,MAAM,CAE7B;CACF;AA4ED,QAAA,MAAM,IAAI,YACC,gBAAgB,KACxB,MAAM,CAAC,MAAM,CACd,SAAS,CAAC,SAAS,CAAC,EACpB,kBAAkB,GAAG,cAAc,EACnC,KAAK,CAAC,KAAK,GAAG,YAAY,CAAC,YAAY,GAAG,MAAM,CAAC,MAAM,CAkMrD,CAAA;;sBASgB,gBAAgB;;AAPpC;;;;;GAKG;AACH,qBAAa,SAAU,SAAQ,cAI9B;IACC,MAAM,CAAC,QAAQ,CAAC,IAAI,cAAO;IAC3B,MAAM,CAAC,QAAQ,CAAC,KAAK,YACV,gBAAgB,KACxB,KAAK,CAAC,KAAK,CACZ,SAAS,EACT,kBAAkB,GAAG,cAAc,EACnC,YAAY,CAAC,YAAY,GAAG,MAAM,CAAC,MAAM,CAC1C,CAAqC;CACvC"}
package/dist/NfsServer.js CHANGED
@@ -72,8 +72,7 @@ const NfsServerLimitsSchema = Schema.Struct({
72
72
  maxWriteBytes: PositiveByteSize,
73
73
  maxReaddirEntries: PositiveSafeInteger,
74
74
  maxReaddirReplyBytes: PositiveByteSize,
75
- maxNameBytes: NameByteSize,
76
- maxFilehandles: PositiveSafeInteger
75
+ maxNameBytes: NameByteSize
77
76
  });
78
77
  const makeNfsServerLimits = (limits) => Object.freeze({ ...limits });
79
78
  const constrained = makeNfsServerLimits({
@@ -104,8 +103,7 @@ const constrained = makeNfsServerLimits({
104
103
  maxWriteBytes: ByteSize.kibibytes(64),
105
104
  maxReaddirEntries: 64,
106
105
  maxReaddirReplyBytes: ByteSize.kibibytes(64),
107
- maxNameBytes: ByteSize.bytes(255),
108
- maxFilehandles: 512
106
+ maxNameBytes: ByteSize.bytes(255)
109
107
  });
110
108
  const defaultLimits = makeNfsServerLimits({
111
109
  maxConnections: 16,
@@ -135,8 +133,7 @@ const defaultLimits = makeNfsServerLimits({
135
133
  maxWriteBytes: ByteSize.mebibytes(1),
136
134
  maxReaddirEntries: 1_024,
137
135
  maxReaddirReplyBytes: ByteSize.mebibytes(1),
138
- maxNameBytes: ByteSize.bytes(255),
139
- maxFilehandles: 8_192
136
+ maxNameBytes: ByteSize.bytes(255)
140
137
  });
141
138
  /**
142
139
  * Schema for every resource bound enforced by the preview server, with frozen presets.
@@ -182,8 +179,7 @@ export const NfsServerLimitOverrides = Schema.Struct({
182
179
  maxWriteBytes: Schema.optionalKey(NfsServerLimits.fields.maxWriteBytes),
183
180
  maxReaddirEntries: Schema.optionalKey(NfsServerLimits.fields.maxReaddirEntries),
184
181
  maxReaddirReplyBytes: Schema.optionalKey(NfsServerLimits.fields.maxReaddirReplyBytes),
185
- maxNameBytes: Schema.optionalKey(NfsServerLimits.fields.maxNameBytes),
186
- maxFilehandles: Schema.optionalKey(NfsServerLimits.fields.maxFilehandles)
182
+ maxNameBytes: Schema.optionalKey(NfsServerLimits.fields.maxNameBytes)
187
183
  });
188
184
  /** Schema for configuration that can be validated without opening runtime capabilities. */
189
185
  const NfsServerConfigSchema = Schema.Struct({
@@ -367,8 +363,8 @@ const make = (options) => Effect.gen(function* () {
367
363
  .pipe(Effect.mapError(() => configurationError("volume", "volume could not create a caller")));
368
364
  if (options.caller !== undefined) {
369
365
  const [volumeRoot, callerRoot] = yield* Effect.all([
370
- volumeCaller.rootReference,
371
- options.caller.rootReference
366
+ volumeCaller.root,
367
+ options.caller.root
372
368
  ]).pipe(Effect.mapError(() => configurationError("caller", "caller must be open and belong to volume")));
373
369
  if (volumeRoot !== callerRoot) {
374
370
  return yield* configurationError("caller", "caller must belong to volume");
@@ -376,9 +372,8 @@ const make = (options) => Effect.gen(function* () {
376
372
  }
377
373
  const crypto = yield* Crypto.Crypto;
378
374
  const generation = yield* crypto.randomBytes(16).pipe(Effect.mapError((cause) => new NfsServerError({ cause })));
379
- const identity = Result.getOrThrow(Encoding.decodeHex(options.volume.identity));
380
375
  const storageGeneration = Result.getOrThrow(Encoding.decodeHex(options.volume.incarnation));
381
- const export_ = makeExport(options.caller ?? volumeCaller, storageGeneration, limits, identity, options.volume);
376
+ const export_ = makeExport(options.volume, options.caller ?? volumeCaller, limits);
382
377
  const callers = new Map();
383
378
  let writableIdentityKey;
384
379
  const callerFor = policy === undefined ?
@@ -1,61 +1,62 @@
1
- import type { VirtualFileSystem as Vfs } from "@effect-vfs/core";
1
+ import { VirtualFileSystem as Vfs } from "@effect-vfs/core";
2
2
  import * as ByteSize from "effect/ByteSize";
3
3
  import * as Effect from "effect/Effect";
4
+ import * as Scope from "effect/Scope";
4
5
  /** @internal */
5
6
  export interface ExportLimits {
6
- readonly maxFilehandles: number;
7
7
  readonly maxNameBytes: ByteSize.ByteSize;
8
8
  }
9
9
  /** @internal */
10
+ export type ExportVolume = Pick<Vfs.Volume, "identity" | "durability" | "referenceKey" | "resolveReferenceKey" | "limits" | "usage">;
11
+ /** @internal */
10
12
  export interface OpenedFile {
11
13
  readonly handle: Vfs.FileHandle;
12
14
  readonly close: Effect.Effect<void>;
13
15
  }
14
16
  /** @internal */
15
17
  export interface NfsExport {
16
- readonly capacity: Pick<Vfs.Volume, "limits" | "usage"> | undefined;
17
- /** Selects a caller for one compound while retaining the export's filehandle registry. */
18
+ readonly capacity: Pick<Vfs.Volume, "limits" | "usage">;
19
+ /** Whether filehandles outlive the server: the volume's committed state survives at least a process crash. */
20
+ readonly persistentHandles: boolean;
21
+ /** Selects a caller for one compound; filehandles belong to the volume, not the caller. */
18
22
  readonly withCaller: (caller: Vfs.Caller) => NfsExport;
19
- readonly root: Effect.Effect<Vfs.ObjectReference, Vfs.FsError>;
20
- readonly handleFor: (reference: Vfs.ObjectReference) => Effect.Effect<Uint8Array, ExportCapacityError>;
21
- readonly resolve: (handle: Uint8Array) => Effect.Effect<Vfs.ObjectReference, InvalidFilehandleError>;
22
- readonly observeMetadata: (reference: Vfs.ObjectReference) => Effect.Effect<Vfs.ObjectObservation<Vfs.Metadata>, Vfs.FsError>;
23
- readonly observeDirectory: (reference: Vfs.ObjectReference) => Effect.Effect<Vfs.ObjectObservation<ReadonlyArray<Vfs.DirectoryEntry>>, Vfs.FsError>;
24
- readonly lookup: (directory: Vfs.ObjectReference, name: Uint8Array) => Effect.Effect<Vfs.ObjectReference, Vfs.FsError | InvalidNameError>;
25
- readonly parent: (directory: Vfs.ObjectReference) => Effect.Effect<Vfs.ObjectReference, Vfs.FsError>;
26
- readonly readLink: (reference: Vfs.ObjectReference) => Effect.Effect<Uint8Array, Vfs.FsError>;
27
- readonly mkdir: (directory: Vfs.ObjectReference, name: Uint8Array, settings?: Vfs.MkdirReferenceSettings) => Effect.Effect<Vfs.ReferenceEntryResult, Vfs.FsError | InvalidNameError | ExportCapacityError>;
28
- readonly symlink: (target: Vfs.PathInput, directory: Vfs.ObjectReference, name: Uint8Array, settings?: Vfs.SymlinkReferenceSettings) => Effect.Effect<Vfs.ReferenceEntryResult, Vfs.FsError | InvalidNameError | ExportCapacityError>;
29
- readonly link: Vfs.Caller["linkReference"];
30
- readonly remove: Vfs.Caller["removeReference"];
31
- readonly rename: Vfs.Caller["renameReference"];
32
- readonly chmod: Vfs.Caller["chmodReference"];
33
- readonly chown: Vfs.Caller["chownReference"];
34
- readonly utimes: Vfs.Caller["utimesReference"];
35
- readonly truncate: Vfs.Caller["truncateReference"];
36
- readonly open: (reference: Vfs.ObjectReference, access?: Vfs.OpenReferenceSettings["access"]) => Effect.Effect<OpenedFile, Vfs.FsError>;
37
- readonly openChild: (directory: Vfs.ObjectReference, name: Uint8Array, settings: Vfs.OpenChildReferenceSettings) => Effect.Effect<Vfs.OpenChildReferenceResult & {
23
+ readonly root: Effect.Effect<Vfs.ObjectReference, Vfs.VfsError>;
24
+ readonly handleFor: (reference: Vfs.ObjectReference) => Effect.Effect<Uint8Array, Vfs.VfsError>;
25
+ readonly resolve: (handle: Uint8Array) => Effect.Effect<Vfs.ObjectReference, InvalidFilehandleError | Vfs.VfsError>;
26
+ readonly observeMetadata: (reference: Vfs.ObjectReference) => Effect.Effect<Vfs.ObjectObservation<Vfs.Metadata>, Vfs.VfsError>;
27
+ readonly observeDirectory: (reference: Vfs.ObjectReference) => Effect.Effect<Vfs.ObjectObservation<ReadonlyArray<Vfs.DirectoryEntry>>, Vfs.VfsError>;
28
+ readonly lookup: (directory: Vfs.ObjectReference, name: Uint8Array) => Effect.Effect<Vfs.ObjectReference, Vfs.VfsError | InvalidNameError>;
29
+ readonly parent: (directory: Vfs.ObjectReference) => Effect.Effect<Vfs.ObjectReference, Vfs.VfsError>;
30
+ readonly readLink: (reference: Vfs.ObjectReference) => Effect.Effect<Uint8Array, Vfs.VfsError>;
31
+ readonly mkdir: (directory: Vfs.ObjectReference, name: Uint8Array, settings?: Vfs.MkdirOptions) => Effect.Effect<Vfs.ReferenceEntryResult, Vfs.VfsError | InvalidNameError>;
32
+ readonly symlink: (target: Vfs.PathInput, directory: Vfs.ObjectReference, name: Uint8Array, settings?: Vfs.SymlinkOptions) => Effect.Effect<Vfs.ReferenceEntryResult, Vfs.VfsError | InvalidNameError>;
33
+ readonly link: (source: Vfs.ObjectReference, directory: Vfs.ObjectReference, name: Uint8Array) => Effect.Effect<Vfs.ReferenceEntryResult, Vfs.VfsError>;
34
+ readonly remove: (directory: Vfs.ObjectReference, name: Uint8Array) => Effect.Effect<Vfs.DirectoryChange, Vfs.VfsError>;
35
+ readonly rename: (sourceDirectory: Vfs.ObjectReference, sourceName: Uint8Array, destinationDirectory: Vfs.ObjectReference, destinationName: Uint8Array) => Effect.Effect<Vfs.RenameReferenceResult, Vfs.VfsError>;
36
+ readonly setattr: (reference: Vfs.ObjectReference, attributes: Vfs.SetattrOptions) => Effect.Effect<void, Vfs.VfsError>;
37
+ /** The bits of `bits` the caller may exercise on the object. */
38
+ readonly access: (reference: Vfs.ObjectReference, bits: number) => Effect.Effect<number, Vfs.VfsError>;
39
+ /**
40
+ * Opens into a scope forked from the one in context, so closing that scope closes the file, and `close`
41
+ * closes the file early and unregisters it, never failing.
42
+ */
43
+ readonly open: (reference: Vfs.ObjectReference, access?: Vfs.OpenOptions["access"]) => Effect.Effect<OpenedFile, Vfs.VfsError, Scope.Scope>;
44
+ /** Looks up or creates and opens a child, into a forked scope as `open` does. */
45
+ readonly openChild: (directory: Vfs.ObjectReference, name: Uint8Array, settings: Vfs.OpenEntryOptions) => Effect.Effect<Vfs.OpenEntryResult & {
38
46
  readonly close: Effect.Effect<void>;
39
- }, Vfs.FsError | InvalidNameError | ExportCapacityError>;
47
+ }, Vfs.VfsError | InvalidNameError, Scope.Scope>;
40
48
  readonly fsid: readonly [bigint, bigint];
41
49
  }
42
- declare const ExportCapacityError_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").VoidIfEmpty<{ readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }>) => import("effect/Cause").YieldableError & {
43
- readonly _tag: "ExportCapacityError";
44
- } & Readonly<A>;
45
50
  /** @internal */
46
- export declare class ExportCapacityError extends ExportCapacityError_base<{
47
- readonly detail: string;
48
- }> {
49
- constructor(message: string);
50
- }
51
+ export type InvalidFilehandleReason = "Malformed" | "Expired" | "Stale";
51
52
  declare const InvalidFilehandleError_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").VoidIfEmpty<{ readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }>) => import("effect/Cause").YieldableError & {
52
53
  readonly _tag: "InvalidFilehandleError";
53
54
  } & Readonly<A>;
54
55
  /** @internal */
55
56
  export declare class InvalidFilehandleError extends InvalidFilehandleError_base<{
56
- readonly reason: "Malformed" | "WrongGeneration" | "Stale" | "Unknown" | "Unavailable";
57
+ readonly reason: InvalidFilehandleReason;
57
58
  }> {
58
- constructor(reason: "Malformed" | "WrongGeneration" | "Stale" | "Unknown" | "Unavailable");
59
+ constructor(reason: InvalidFilehandleReason);
59
60
  }
60
61
  /** @internal */
61
62
  export type InvalidNameReason = "Empty" | "TooLong" | "ForbiddenByte" | "Encoding" | "Reserved";
@@ -72,6 +73,6 @@ export declare class InvalidNameError extends InvalidNameError_base<{
72
73
  /** @internal */
73
74
  export declare const validateName: (bytes: Uint8Array, maxNameBytes: ByteSize.ByteSize) => string;
74
75
  /** @internal */
75
- export declare const makeExport: (caller: Vfs.Caller, generation: Uint8Array, limits: ExportLimits, identity?: Uint8Array, capacity?: Pick<Vfs.Volume, "limits" | "usage">) => NfsExport;
76
+ export declare const makeExport: (volume: ExportVolume, caller: Vfs.Caller, limits: ExportLimits) => NfsExport;
76
77
  export {};
77
78
  //# sourceMappingURL=export.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"export.d.ts","sourceRoot":"","sources":["../../src/internal/export.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,IAAI,GAAG,EAAE,MAAM,kBAAkB,CAAA;AAChE,OAAO,KAAK,QAAQ,MAAM,iBAAiB,CAAA;AAE3C,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AAUvC,gBAAgB;AAChB,MAAM,WAAW,YAAY;IAC3B,QAAQ,CAAC,cAAc,EAAE,MAAM,CAAA;IAC/B,QAAQ,CAAC,YAAY,EAAE,QAAQ,CAAC,QAAQ,CAAA;CACzC;AAED,gBAAgB;AAChB,MAAM,WAAW,UAAU;IACzB,QAAQ,CAAC,MAAM,EAAE,GAAG,CAAC,UAAU,CAAA;IAC/B,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAA;CACpC;AAED,gBAAgB;AAChB,MAAM,WAAW,SAAS;IACxB,QAAQ,CAAC,QAAQ,EAAE,IAAI,CAAC,GAAG,CAAC,MAAM,EAAE,QAAQ,GAAG,OAAO,CAAC,GAAG,SAAS,CAAA;IACnE,0FAA0F;IAC1F,QAAQ,CAAC,UAAU,EAAE,CAAC,MAAM,EAAE,GA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AQ,CAAC,MAAM,EAAE,uBAAuB,CAAA;CACzC,CAAC;IACA,YAAY,MAAM,EAAE,uBAAuB,EAE1C;CACF;AAED,gBAAgB;AAChB,MAAM,MAAM,iBAAiB,GAAG,OAAO,GAAG,SAAS,GAAG,eAAe,GAAG,UAAU,GAAG,UAAU,CAAA;;;;AAE/F,gBAAgB;AAChB,qBAAa,gBAAiB,SAAQ,sBAAqC;IACzE,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;IACvB,QAAQ,CAAC,MAAM,EAAE,iBAAiB,CAAA;CACnC,CAAC;IACA,YAAY,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,iBAAiB,EAErD;CACF;AAuBD,gBAAgB;AAChB,eAAO,MAAM,YAAY,UAAW,UAAU,gBAAgB,QAAQ,CAAC,QAAQ,KAAG,MAqBjF,CAAA;AAKD,gBAAgB;AAChB,eAAO,MAAM,UAAU,WAAY,YAAY,UAAU,GAAG,CAAC,MAAM,UAAU,YAAY,KAAG,SAyJ3F,CAAA"}
@@ -1,18 +1,22 @@
1
+ import { VirtualFileSystem as Vfs } from "@effect-vfs/core";
1
2
  import * as ByteSize from "effect/ByteSize";
2
3
  import * as Data from "effect/Data";
3
4
  import * as Effect from "effect/Effect";
5
+ import * as Encoding from "effect/Encoding";
4
6
  import * as Exit from "effect/Exit";
5
7
  import * as Result from "effect/Result";
6
8
  import * as Scope from "effect/Scope";
7
- import * as Semaphore from "effect/Semaphore";
8
- const HANDLE_VERSION = 1;
9
- const HANDLE_BYTES = 25;
10
- /** @internal */
11
- export class ExportCapacityError extends Data.TaggedError("ExportCapacityError") {
12
- constructor(message) {
13
- super({ detail: message });
14
- }
15
- }
9
+ // Version 1 handles carried a per-process serial; version 2 carries the object's reference key.
10
+ const HANDLE_VERSION = 2;
11
+ // A reference key's identity, epoch and tag, each 16 bytes.
12
+ const KEY_PART_BYTES = 16;
13
+ const IDENTITY_OFFSET = 1;
14
+ const EPOCH_OFFSET = IDENTITY_OFFSET + KEY_PART_BYTES;
15
+ const INO_OFFSET = EPOCH_OFFSET + KEY_PART_BYTES;
16
+ const TAG_OFFSET = INO_OFFSET + 8;
17
+ // version | identity | epoch | ino | tag: 57 bytes, within NFS4_FHSIZE (128). The tag is what keeps a client that
18
+ // holds one handle from writing another by changing its inode number.
19
+ const HANDLE_BYTES = TAG_OFFSET + KEY_PART_BYTES;
16
20
  /** @internal */
17
21
  export class InvalidFilehandleError extends Data.TaggedError("InvalidFilehandleError") {
18
22
  constructor(reason) {
@@ -37,10 +41,6 @@ const sameBytes = (left, right) => {
37
41
  difference |= left[index] ^ right[index];
38
42
  return difference === 0;
39
43
  };
40
- const validateGeneration = (generation) => {
41
- if (generation.length !== 16)
42
- throw new RangeError("generation must contain exactly 16 bytes");
43
- };
44
44
  const decodeUtf8 = (bytes) => {
45
45
  try {
46
46
  return new TextDecoder("utf-8", { fatal: true }).decode(bytes);
@@ -70,67 +70,42 @@ export const validateName = (bytes, maxNameBytes) => {
70
70
  };
71
71
  const uint64From = (bytes, offset) => new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength).getBigUint64(offset);
72
72
  /** @internal */
73
- export const makeExport = (caller, generation, limits, identity = generation, capacity) => {
74
- validateGeneration(generation);
75
- validateGeneration(identity);
76
- assertPositiveInteger("maxFilehandles", limits.maxFilehandles);
73
+ export const makeExport = (volume, caller, limits) => {
77
74
  assertPositiveInteger("maxNameBytes", ByteSize.toNumberUnsafe(limits.maxNameBytes));
78
- const generationCopy = new Uint8Array(generation);
79
- const identityCopy = new Uint8Array(identity);
80
- const referencesById = new Map();
81
- const idsByReference = new WeakMap();
82
- const registryGate = Semaphore.makeUnsafe(1);
83
- let nextId = 1n;
84
- const admitHandle = Effect.gen(function* () {
85
- if (referencesById.size >= limits.maxFilehandles) {
86
- for (const [candidateId, candidate] of referencesById) {
87
- const result = yield* Effect.result(caller.observeMetadata(candidate));
88
- if (Result.isFailure(result) && result.failure.code === "StaleReference") {
89
- referencesById.delete(candidateId);
90
- // SAFETY: ObjectReference values are opaque object identities created by the core volume.
91
- idsByReference.delete(candidate);
92
- }
93
- }
94
- if (referencesById.size >= limits.maxFilehandles) {
95
- return yield* new ExportCapacityError("Filehandle registry is full");
96
- }
97
- }
98
- });
99
- const registerHandle = (reference) => {
100
- // SAFETY: ObjectReference values are opaque object identities created by the core volume.
101
- let id = idsByReference.get(reference);
102
- if (id === undefined) {
103
- id = nextId++;
104
- // SAFETY: ObjectReference values are opaque object identities created by the core volume.
105
- idsByReference.set(reference, id);
106
- referencesById.set(id, reference);
107
- }
75
+ const identity = Result.getOrThrow(Encoding.decodeHex(volume.identity));
76
+ const persistentHandles = Vfs.isVolumeDurabilityAtLeast(volume.durability, "survives-process-crash");
77
+ const handleFor = (reference) => Effect.map(volume.referenceKey(reference), (key) => {
108
78
  const bytes = new Uint8Array(HANDLE_BYTES);
109
79
  bytes[0] = HANDLE_VERSION;
110
- bytes.set(generationCopy, 1);
111
- new DataView(bytes.buffer).setBigUint64(17, id);
80
+ bytes.set(key.identity, IDENTITY_OFFSET);
81
+ bytes.set(key.epoch, EPOCH_OFFSET);
82
+ new DataView(bytes.buffer).setBigUint64(INO_OFFSET, key.ino);
83
+ bytes.set(key.tag, TAG_OFFSET);
112
84
  return bytes;
113
- };
114
- const handleFor = (reference) => registryGate.withPermit(Effect.gen(function* () {
115
- if (!idsByReference.has(reference))
116
- yield* admitHandle;
117
- return registerHandle(reference);
118
- }));
85
+ });
86
+ // A key the volume did not mint, a forged tag included, is not a handle. One from another volume or epoch expires
87
+ // when handles are volatile (RFC 8881 Section 4.2.3); a persistent handle that names nothing is stale (Section
88
+ // 4.2.2), like one whose object is gone.
89
+ const filehandleFailure = (error) => error.code === "InvalidReference"
90
+ ? new InvalidFilehandleError("Malformed")
91
+ : error.code === "ForeignReference"
92
+ ? new InvalidFilehandleError(persistentHandles ? "Stale" : "Expired")
93
+ : error;
119
94
  const resolve = (handle) => Effect.suspend(() => {
120
95
  if (handle.length !== HANDLE_BYTES || handle[0] !== HANDLE_VERSION) {
121
96
  return Effect.fail(new InvalidFilehandleError("Malformed"));
122
97
  }
123
- if (!sameBytes(handle.subarray(1, 17), generationCopy)) {
124
- return Effect.fail(new InvalidFilehandleError("WrongGeneration"));
125
- }
126
- const reference = referencesById.get(uint64From(handle, 17));
127
- if (reference === undefined)
128
- return Effect.fail(new InvalidFilehandleError("Unknown"));
129
- return caller.observeMetadata(reference).pipe(Effect.as(reference), Effect.mapError((error) => new InvalidFilehandleError(error.code === "StaleReference" ? "Stale" : error.code === "VolumeUnavailable" ? "Unavailable" : "Unknown")));
98
+ const key = {
99
+ identity: handle.slice(IDENTITY_OFFSET, EPOCH_OFFSET),
100
+ epoch: handle.slice(EPOCH_OFFSET, INO_OFFSET),
101
+ ino: uint64From(handle, INO_OFFSET),
102
+ tag: handle.slice(TAG_OFFSET, HANDLE_BYTES)
103
+ };
104
+ return volume.resolveReferenceKey(key).pipe(Effect.mapError(filehandleFailure));
130
105
  });
131
106
  const open = (activeCaller, reference, access = "read") => Effect.uninterruptibleMask((restore) => Effect.gen(function* () {
132
- const scope = yield* Scope.make();
133
- const opened = yield* Effect.exit(restore(activeCaller.openReference(reference, { access }).pipe(Effect.provideService(Scope.Scope, scope))));
107
+ const scope = yield* Scope.fork(yield* Effect.scope);
108
+ const opened = yield* Effect.exit(restore(activeCaller.open(reference, { access }).pipe(Effect.provideService(Scope.Scope, scope))));
134
109
  if (Exit.isFailure(opened)) {
135
110
  yield* Scope.close(scope, opened);
136
111
  return yield* Effect.failCause(opened.cause);
@@ -141,17 +116,18 @@ export const makeExport = (caller, generation, limits, identity = generation, ca
141
116
  };
142
117
  }));
143
118
  const withCaller = (activeCaller) => ({
144
- capacity,
119
+ capacity: volume,
120
+ persistentHandles,
145
121
  withCaller,
146
- root: activeCaller.rootReference,
122
+ root: activeCaller.root,
147
123
  handleFor,
148
124
  resolve,
149
- observeMetadata: activeCaller.observeMetadata,
150
- observeDirectory: activeCaller.observeDirectory,
125
+ observeMetadata: (reference) => Effect.map(activeCaller.stat(reference), (metadata) => ({ value: metadata, revision: metadata.revision })),
126
+ observeDirectory: (reference) => activeCaller.readDirectory(reference),
151
127
  lookup: (directory, name) => Effect.suspend(() => {
152
128
  try {
153
129
  validateName(name, limits.maxNameBytes);
154
- return activeCaller.lookupReference(directory, name);
130
+ return activeCaller.lookup(Vfs.Entry(directory, name));
155
131
  }
156
132
  catch (error) {
157
133
  if (error instanceof InvalidNameError)
@@ -159,9 +135,9 @@ export const makeExport = (caller, generation, limits, identity = generation, ca
159
135
  throw error;
160
136
  }
161
137
  }),
162
- parent: activeCaller.parentReference,
163
- readLink: activeCaller.readLinkReference,
164
- mkdir: (directory, name, settings) => registryGate.withPermit(Effect.gen(function* () {
138
+ parent: (directory) => activeCaller.parent(directory),
139
+ readLink: (reference) => activeCaller.readLink(reference),
140
+ mkdir: (directory, name, settings) => Effect.gen(function* () {
165
141
  yield* Effect.try({
166
142
  try: () => validateName(name, limits.maxNameBytes),
167
143
  catch: (error) => {
@@ -170,12 +146,9 @@ export const makeExport = (caller, generation, limits, identity = generation, ca
170
146
  throw error;
171
147
  }
172
148
  });
173
- yield* admitHandle;
174
- const result = yield* activeCaller.mkdirReference(directory, name, settings);
175
- registerHandle(result.reference);
176
- return result;
177
- })),
178
- symlink: (target, directory, name, settings) => registryGate.withPermit(Effect.gen(function* () {
149
+ return yield* activeCaller.mkdir(Vfs.Entry(directory, name), settings);
150
+ }),
151
+ symlink: (target, directory, name, settings) => Effect.gen(function* () {
179
152
  yield* Effect.try({
180
153
  try: () => validateName(name, limits.maxNameBytes),
181
154
  catch: (error) => {
@@ -184,20 +157,15 @@ export const makeExport = (caller, generation, limits, identity = generation, ca
184
157
  throw error;
185
158
  }
186
159
  });
187
- yield* admitHandle;
188
- const result = yield* activeCaller.symlinkReference(target, directory, name, settings);
189
- registerHandle(result.reference);
190
- return result;
191
- })),
192
- link: activeCaller.linkReference,
193
- remove: activeCaller.removeReference,
194
- rename: activeCaller.renameReference,
195
- chmod: activeCaller.chmodReference,
196
- chown: activeCaller.chownReference,
197
- utimes: activeCaller.utimesReference,
198
- truncate: activeCaller.truncateReference,
160
+ return yield* activeCaller.symlink(target, Vfs.Entry(directory, name), settings);
161
+ }),
162
+ link: (source, directory, name) => activeCaller.link(source, Vfs.Entry(directory, name)),
163
+ remove: (directory, name) => activeCaller.remove(Vfs.Entry(directory, name)),
164
+ rename: (sourceDirectory, sourceName, destinationDirectory, destinationName) => activeCaller.rename(Vfs.Entry(sourceDirectory, sourceName), Vfs.Entry(destinationDirectory, destinationName)),
165
+ setattr: (reference, attributes) => activeCaller.setattr(reference, attributes),
166
+ access: (reference, bits) => activeCaller.access(reference, bits),
199
167
  open: (reference, access) => open(activeCaller, reference, access),
200
- openChild: (directory, name, settings) => registryGate.withPermit(Effect.uninterruptibleMask((restore) => Effect.gen(function* () {
168
+ openChild: (directory, name, settings) => Effect.uninterruptibleMask((restore) => Effect.gen(function* () {
201
169
  yield* Effect.try({
202
170
  try: () => validateName(name, limits.maxNameBytes),
203
171
  catch: (error) => {
@@ -206,19 +174,15 @@ export const makeExport = (caller, generation, limits, identity = generation, ca
206
174
  throw error;
207
175
  }
208
176
  });
209
- const expected = settings.expectedChild;
210
- if (expected == null || !idsByReference.has(expected.reference))
211
- yield* restore(admitHandle);
212
- const scope = yield* Scope.make();
213
- const opened = yield* Effect.exit(restore(activeCaller.openChildReference(directory, name, settings).pipe(Effect.provideService(Scope.Scope, scope))));
177
+ const scope = yield* Scope.fork(yield* Effect.scope);
178
+ const opened = yield* Effect.exit(restore(activeCaller.open(Vfs.Entry(directory, name), settings).pipe(Effect.provideService(Scope.Scope, scope))));
214
179
  if (Exit.isFailure(opened)) {
215
180
  yield* Scope.close(scope, opened);
216
181
  return yield* Effect.failCause(opened.cause);
217
182
  }
218
- registerHandle(opened.value.reference);
219
183
  return { ...opened.value, close: Scope.close(scope, Exit.void).pipe(Effect.orDie) };
220
- }))),
221
- fsid: [uint64From(identityCopy, 0), uint64From(identityCopy, 8)]
184
+ })),
185
+ fsid: [uint64From(identity, 0), uint64From(identity, 8)]
222
186
  });
223
187
  return withCaller(caller);
224
188
  };
@@ -4,8 +4,8 @@ import * as Crypto from "effect/Crypto";
4
4
  import * as Duration from "effect/Duration";
5
5
  import * as Effect from "effect/Effect";
6
6
  import type * as PlatformError from "effect/PlatformError";
7
- import type * as Scope from "effect/Scope";
8
- import { type NfsExport } from "./export.js";
7
+ import * as Scope from "effect/Scope";
8
+ import { InvalidFilehandleError, type NfsExport } from "./export.js";
9
9
  import { type CompoundCall, type Connection, RpcPolicyDenied } from "./rpc.js";
10
10
  import { type DecodeLimits, XdrEncodeError } from "./xdr.js";
11
11
  /** @internal */
@@ -188,7 +188,9 @@ export interface Nfs4Handler {
188
188
  /** @internal */
189
189
  export declare const nextSequenceId: (sequence: number) => number;
190
190
  /** @internal */
191
- export declare const failureForFs: (error: Vfs.FsError) => number;
191
+ export declare const failureForFs: (error: Vfs.VfsError, operation: number) => number;
192
+ /** @internal */
193
+ export declare const putfhFailure: (error: InvalidFilehandleError | Vfs.VfsError) => number;
192
194
  /** @internal */
193
195
  export declare const makeNfs4Handler: (export_: NfsExport, options: Nfs4Options) => Effect.Effect<Nfs4Handler, PlatformError.PlatformError, Scope.Scope | Crypto.Crypto>;
194
196
  //# sourceMappingURL=nfs4.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"nfs4.d.ts","sourceRoot":"","sources":["../../src/internal/nfs4.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,IAAI,GAAG,EAAE,MAAM,kBAAkB,CAAA;AAChE,OAAO,KAAK,QAAQ,MAAM,iBAAiB,CAAA;AAC3C,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AAEvC,OAAO,KAAK,QAAQ,MAAM,iBAAiB,CAAA;AAC3C,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AAEvC,OAAO,KAAK,KAAK,aAAa,MAAM,sBAAsB,CAAA;AAK1D,OAAO,KA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AW,WAAW;IAC1B,QAAQ,CAAC,QAAQ,EAAE,CAAC,IAAI,EAAE,YAAY,KAAK,MAAM,CAAC,MAAM,CAAC,UAAU,EAAE,eAAe,GAAG,cAAc,CAAC,CAAA;IACtG,QAAQ,CAAC,UAAU,EAAE,CAAC,UAAU,EAAE,UAAU,KAAK,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAA;IACpE,QAAQ,CAAC,aAAa,EAAE,CAAC,UAAU,EAAE,UAAU,EAAE,OAAO,EAAE,UAAU,KAAK,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAA;IAC5F;;;OAGG;IACH,QAAQ,CAAC,gBAAgB,EAAE,CAAC,OAAO,EAAE,UAAU,KAAK,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,CAAA;CAC3E;AAED,gBAAgB;AAChB,eAAO,MAAM,cAAc,aAAc,MAAM,KAAG,MAA8B,CAAA;AA61ChF,gBAAgB;AAChB,eAAO,MAAM,YAAY,UAAW,GAAG,CAAC,QAAQ,aAAa,MAAM,KAAG,MAKrE,CAAA;AAaD,gBAAgB;AAChB,eAAO,MAAM,YAAY,UAAW,sBAAsB,GAAG,GAAG,CAAC,QAAQ,KAAG,MAQ3E,CAAA;AA0mBD,gBAAgB;AAChB,eAAO,MAAM,eAAe,YACjB,SAAS,WACT,WAAW,KACnB,MAAM,CAAC,MAAM,CAAC,WAAW,EAAE,aAAa,CAAC,aAAa,EAAE,KAAK,CAAC,KAAK,GAAG,MAAM,CAAC,MAAM,CA6tGrF,CAAA"}
@@ -8,8 +8,9 @@ import * as Predicate from "effect/Predicate";
8
8
  import * as Result from "effect/Result";
9
9
  import * as Schedule from "effect/Schedule";
10
10
  import * as Schema from "effect/Schema";
11
+ import * as Scope from "effect/Scope";
11
12
  import * as Semaphore from "effect/Semaphore";
12
- import { ExportCapacityError, InvalidNameError, validateName } from "./export.js";
13
+ import { InvalidFilehandleError, InvalidNameError, validateName } from "./export.js";
13
14
  import { lockRange, MAX_OFFSET, overlaps } from "./lockRanges.js";
14
15
  import { RpcPolicyDenied } from "./rpc.js";
15
16
  import { make as xdr, XdrCodec, XdrDecodeError, XdrEncodeError } from "./xdr.js";
@@ -209,6 +210,10 @@ const MIN_FORE_REQUEST_BYTES = 40 + 48;
209
210
  const MIN_FORE_RESPONSE_BYTES = 24 + 12 + 8 + 36;
210
211
  /** PERSIST, CONN_BACK_CHAN, and CONN_RDMA are the only defined csa_flags bits. */
211
212
  const CREATE_SESSION4_KNOWN_FLAGS = 0x7;
213
+ // The mode bits knfsd's nfsd_sanitize_attrs strips from a SETATTR that also changes the owner.
214
+ const SET_UID = 0o4000;
215
+ const SET_GID = 0o2000;
216
+ const GROUP_EXECUTE = 0o010;
212
217
  const ACCESS4_READ = 0x01;
213
218
  const ACCESS4_LOOKUP = 0x02;
214
219
  const ACCESS4_MODIFY = 0x04;
@@ -221,6 +226,13 @@ const AUTH_SYS = 1;
221
226
  const MAX_OPAQUE_AUTH_BYTES = 400;
222
227
  /** The export accepts and generates only UTF-8 names (RFC 8881 Section 14.4). */
223
228
  const FSCHARSET_CAP4_ALLOWS_ONLY_UTF8 = 0x2;
229
+ // fh_expire_type (RFC 8881 Section 5.8.1.9): persistent handles never expire; volatile ones here expire only when
230
+ // the server restarts, never while a file is open. RFC 8881 Section 4.2.3 allows FH4_NOEXPIRE_WITH_OPEN only
231
+ // together with FH4_VOLATILE_ANY, so a volatile export sends both.
232
+ const FH4_PERSISTENT = 0x0;
233
+ const FH4_NOEXPIRE_WITH_OPEN = 0x1;
234
+ const FH4_VOLATILE_ANY = 0x2;
235
+ const FH4_VOLATILE_UNTIL_RESTART = FH4_VOLATILE_ANY | FH4_NOEXPIRE_WITH_OPEN;
224
236
  const SP4_NONE = 0;
225
237
  const SP4_MACH_CRED = 1;
226
238
  const SP4_SSV = 2;
@@ -237,7 +249,7 @@ const CLAIM_DELEG_CUR_FH = 5;
237
249
  const CLAIM_DELEG_PREV_FH = 6;
238
250
  /**
239
251
  * Worst-case encoded GETATTR result: the largest attribute set this server can return for a
240
- * 25-byte filehandle and bounded capacity is about 360 bytes; recheck when attributes grow.
252
+ * 57-byte filehandle and bounded capacity is about 390 bytes; recheck when attributes grow.
241
253
  */
242
254
  const MAX_GETATTR_REPLY_BYTES = 512;
243
255
  /** WRITE_LT and WRITEW_LT request exclusive ranges. */
@@ -510,6 +522,77 @@ const setattrAttributes = Effect.fnUntraced(function* (attrs, limits, supportedA
510
522
  yield* reader.finish;
511
523
  return changes;
512
524
  });
525
+ // The one core change a SETATTR's decoded attributes make: owner and group join one owner update, and the two
526
+ // times one times update that omits the one not given.
527
+ const setattrOptions = (changes) => {
528
+ const options = {};
529
+ const owner = {};
530
+ let access;
531
+ let modification;
532
+ for (const change of changes) {
533
+ if (change.kind === "size")
534
+ options.size = change.value;
535
+ else if (change.kind === "mode")
536
+ options.mode = change.value;
537
+ else if (change.kind === "owner" && change.attribute === 36)
538
+ owner.uid = change.value;
539
+ else if (change.kind === "owner")
540
+ owner.gid = change.value;
541
+ else if (change.attribute === 48)
542
+ access = change.value;
543
+ else
544
+ modification = change.value;
545
+ }
546
+ if (Object.keys(owner).length !== 0)
547
+ options.owner = owner;
548
+ if (access !== undefined || modification !== undefined) {
549
+ options.times = { access: access ?? { kind: "omit" }, modification: modification ?? { kind: "omit" } };
550
+ }
551
+ return options;
552
+ };
553
+ // Linux knfsd's SETATTR (fs/nfsd/vfs.c) treats an owner or group equal to the object's current one as no change:
554
+ // notify_change's chown_ok and chgrp_ok (fs/attr.c) let the owner re-send its own uid, and its own gid without
555
+ // membership, and nfsd_sanitize_attrs revokes set-ID bits only when the uid or gid actually differs. Core's chown
556
+ // is POSIX and refuses a gid outside the caller's groups even when it is the current one, so the unchanged ids
557
+ // are dropped here. The owner update itself stays, possibly empty, so core still checks ownership as chown_ok does.
558
+ // For a real change of the owner or group of a non-directory that sets its mode too, nfsd_sanitize_attrs clears
559
+ // setuid from the requested mode, and setgid when the mode grants group execute (without it, setgid marks
560
+ // mandatory locking, not privilege). Core applies a requested mode after the owner, as POSIX chown then chmod
561
+ // does, so the sanitising happens here. An owner change without a mode needs nothing: core's chown already
562
+ // clears both bits on a regular file. The result pins the revision it observed, so core refuses it if another
563
+ // change lands before it applies.
564
+ const sanitizeSetattr = (export_, reference, options) => {
565
+ const { mode, owner } = options;
566
+ if (owner === undefined)
567
+ return Effect.succeed(options);
568
+ return Effect.map(export_.observeMetadata(reference), ({ value, revision }) => {
569
+ const changed = {};
570
+ if (owner.uid !== undefined && owner.uid !== value.uid)
571
+ changed.uid = owner.uid;
572
+ if (owner.gid !== undefined && owner.gid !== value.gid)
573
+ changed.gid = owner.gid;
574
+ const chowned = changed.uid !== undefined || changed.gid !== undefined;
575
+ return mode === undefined || !chowned || value.kind === "directory"
576
+ ? { ...options, owner: changed, expected: { revision } }
577
+ : {
578
+ ...options,
579
+ owner: changed,
580
+ mode: mode & ~(SET_UID | ((mode & GROUP_EXECUTE) === 0 ? 0 : SET_GID)),
581
+ expected: { revision }
582
+ };
583
+ });
584
+ };
585
+ // Re-observations a SETATTR makes when another change overtook the metadata its owner handling read, before
586
+ // answering DELAY so the client retries later.
587
+ const SETATTR_RETRIES = 3;
588
+ // Whether core refused a setattr because the target moved past the revision it was decided from.
589
+ const isStaleObservation = (error) => error.code === "StaleReference" && error.field === "expected";
590
+ // Sanitises and applies a SETATTR's attributes as one core change, re-observing when another change lands
591
+ // between the observation and the change, and failing with DELAY once the retries run out.
592
+ const applySetattr = (export_, reference, options) => {
593
+ const attempt = (retries) => sanitizeSetattr(export_, reference, options).pipe(Effect.flatMap((attributes) => export_.setattr(reference, attributes)), Effect.catchIf(isStaleObservation, () => retries === 0 ? Effect.fail(Status.DELAY) : attempt(retries - 1)));
594
+ return attempt(SETATTR_RETRIES);
595
+ };
513
596
  const readStateOwner = Effect.fnUntraced(function* (reader, limits) {
514
597
  yield* reader.read(XdrCodec.uint64);
515
598
  return yield* reader.read(XdrCodec.opaque(limits.maxOwnerBytes));
@@ -1015,6 +1098,7 @@ const fsStatuses = {
1015
1098
  NotEmpty: Status.NOTEMPTY,
1016
1099
  NotDirectory: Status.NOTDIR,
1017
1100
  AccessDenied: Status.ACCESS,
1101
+ NotPermitted: Status.PERM,
1018
1102
  InvalidHandle: Status.SERVERFAULT,
1019
1103
  ForeignHandle: Status.SERVERFAULT,
1020
1104
  InvalidReference: Status.SERVERFAULT,
@@ -1034,10 +1118,49 @@ const fsStatuses = {
1034
1118
  VolumeBusy: Status.DELAY,
1035
1119
  // NFSv4.1 has no LOOP status. The reference-based NFS read path never follows symbolic links.
1036
1120
  SymlinkLoop: Status.INVAL,
1037
- UnrepresentableName: Status.INVAL
1121
+ UnrepresentableName: Status.INVAL,
1122
+ // Codec and store failures never reach an NFS operation; a server fault says so if one does.
1123
+ InvalidEncoding: Status.SERVERFAULT,
1124
+ UnsupportedVersion: Status.SERVERFAULT,
1125
+ InvalidStructure: Status.SERVERFAULT,
1126
+ LimitExceeded: Status.SERVERFAULT,
1127
+ BaseMismatch: Status.SERVERFAULT,
1128
+ Storage: Status.IO,
1129
+ Ownership: Status.IO,
1130
+ IncompatibleStore: Status.IO,
1131
+ CorruptStore: Status.IO
1038
1132
  };
1133
+ // RFC 8881 Section 15.2 lists NFS4ERR_PERM for CREATE, OPEN and SETATTR only. Core's NotPermitted (EPERM) from
1134
+ // any other operation, such as a sticky-directory REMOVE or RENAME, answers ACCESS, which their Section 15.2 lists
1135
+ // include.
1136
+ const PERM_OPERATIONS = new Set([Operation.CREATE, Operation.OPEN, Operation.SETATTR]);
1137
+ // The table is total over the codes this build knows. The guard is for a core release newer than this server,
1138
+ // whose errors can carry a code added since, which a client should see as a server fault.
1039
1139
  /** @internal */
1040
- export const failureForFs = (error) => Object.hasOwn(fsStatuses, error.code) ? fsStatuses[error.code] : Status.SERVERFAULT;
1140
+ export const failureForFs = (error, operation) => {
1141
+ if (!Object.hasOwn(fsStatuses, error.code))
1142
+ return Status.SERVERFAULT;
1143
+ const status = fsStatuses[error.code];
1144
+ return status === Status.PERM && !PERM_OPERATIONS.has(operation) ? Status.ACCESS : status;
1145
+ };
1146
+ // RFC 8881 Section 15.2 lists these for PUTFH; a volume failure outside them answers SERVERFAULT, which it includes.
1147
+ const PUTFH_STATUSES = new Set([
1148
+ Status.BADHANDLE,
1149
+ Status.DELAY,
1150
+ Status.FHEXPIRED,
1151
+ Status.SERVERFAULT,
1152
+ Status.STALE
1153
+ ]);
1154
+ // A handle the export could not read, or one from another volume or epoch, keeps its filehandle status; any other
1155
+ // volume failure goes through the shared table, so a gone object is STALE and a busy volume DELAY.
1156
+ /** @internal */
1157
+ export const putfhFailure = (error) => {
1158
+ if (error instanceof InvalidFilehandleError) {
1159
+ return error.reason === "Expired" ? Status.FHEXPIRED : error.reason === "Stale" ? Status.STALE : Status.BADHANDLE;
1160
+ }
1161
+ const status = failureForFs(error, Operation.PUTFH);
1162
+ return PUTFH_STATUSES.has(status) ? status : Status.SERVERFAULT;
1163
+ };
1041
1164
  const field = (codec, value) => (writer) => writer.write(codec, value);
1042
1165
  const encodeStatusBody = (limits, fields) => Effect.gen(function* () {
1043
1166
  const writer = yield* xdr.openWriter(limits, ByteSize.toNumberUnsafe(limits.maxRecordBytes));
@@ -1081,10 +1204,7 @@ const baseSupportedAttributes = [
1081
1204
  ];
1082
1205
  const maxUint64 = 0xffffffffffffffffn;
1083
1206
  const supportedAttributesFor = (export_) => {
1084
- const capacity = export_.capacity;
1085
- if (capacity === undefined)
1086
- return baseSupportedAttributes;
1087
- const { maxBytes, maxEntries } = capacity.limits;
1207
+ const { maxBytes, maxEntries } = export_.capacity.limits;
1088
1208
  const additional = [27];
1089
1209
  if (maxEntries !== undefined)
1090
1210
  additional.push(21, 22, 23);
@@ -1147,7 +1267,7 @@ const encodeAttributeValues = (requested, observation, filehandle, export_, opti
1147
1267
  yield* values.write(XdrCodec.uint32, metadata.kind === "file" ? 1 : metadata.kind === "directory" ? 2 : 5);
1148
1268
  break;
1149
1269
  case 2:
1150
- yield* values.write(XdrCodec.uint32, 0x3);
1270
+ yield* values.write(XdrCodec.uint32, export_.persistentHandles ? FH4_PERSISTENT : FH4_VOLATILE_UNTIL_RESTART);
1151
1271
  break;
1152
1272
  case 3:
1153
1273
  yield* values.write(XdrCodec.uint64, BigInt.asUintN(64, observation.revision));
@@ -1424,7 +1544,7 @@ const makeCookieVerifier = (generation, revision) => {
1424
1544
  };
1425
1545
  /**
1426
1546
  * Operations that change server state before the reply size is known. READ belongs here
1427
- * because reading updates the file's access time, which a slot rollback cannot undo.
1547
+ * because reading can update the file's access time, which a slot rollback cannot undo.
1428
1548
  */
1429
1549
  const stateChangingKinds = new Set([
1430
1550
  "Read",
@@ -1728,6 +1848,9 @@ export const makeNfs4Handler = (export_, options) => {
1728
1848
  Effect.repeat(stateGate.withPermit(Effect.uninterruptible(sweepExpired)), {
1729
1849
  schedule: Schedule.spaced(sweepInterval)
1730
1850
  }), handlerScope);
1851
+ // The export forks each open's scope from the handler scope, so closing the handler scope closes them too.
1852
+ // The handler still closes what `opens` holds through each open's own close, since that close is all the
1853
+ // export contract promises; on the built-in export the second close finds a closed scope and does nothing.
1731
1854
  yield* Effect.addFinalizer(() => Effect.forEach(opens.values(), (open) => open.close, { discard: true }));
1732
1855
  /** Reads only the leading SEQUENCE of a compound to find its session, tolerating later decode errors. */
1733
1856
  const sequenceSessionOf = (bytes) => Effect.gen(function* () {
@@ -1941,7 +2064,9 @@ export const makeNfs4Handler = (export_, options) => {
1941
2064
  return response;
1942
2065
  function execute(operation) {
1943
2066
  const noCurrent = () => ({ code: operation.code, status: Status.NOFILEHANDLE });
1944
- const mapFs = (effect) => effect.pipe(Effect.mapError(failureForFs));
2067
+ const mapFs = (effect) => effect.pipe(Effect.mapError((error) => failureForFs(error, operation.code)));
2068
+ // Fails as ACCESS unless every requested bit is granted.
2069
+ const requireAccess = (reference, bits) => mapFs(export_.access(reference, bits)).pipe(Effect.flatMap((granted) => granted === bits ? Effect.void : Effect.fail(Status.ACCESS)));
1945
2070
  const withCurrent = (f) => current === undefined ? Effect.fail(Status.NOFILEHANDLE) : f(current);
1946
2071
  const statusResult = (effect, success = () => undefined) => Effect.flatMap(Effect.result(effect), (outcome) => {
1947
2072
  if (Result.isFailure(outcome)) {
@@ -1955,16 +2080,14 @@ export const makeNfs4Handler = (export_, options) => {
1955
2080
  : { code: operation.code, status: Status.OK, body: encoded });
1956
2081
  });
1957
2082
  const requireAttributes = (attributes) => Effect.filterOrFail(attributes, (value) => value !== undefined, () => Status.SERVERFAULT);
1958
- /** Registers a filehandle only when the `filehandle` attribute (19) is requested. */
1959
- const filehandleFor = (reference, requested) => requested.includes(19)
1960
- ? export_.handleFor(reference).pipe(Effect.mapError(() => Status.SERVERFAULT))
1961
- : Effect.succeed(empty);
2083
+ /** Encodes a filehandle only when the `filehandle` attribute (19) is requested. */
2084
+ const filehandleFor = (reference, requested) => requested.includes(19) ? mapFs(export_.handleFor(reference)) : Effect.succeed(empty);
1962
2085
  /**
1963
2086
  * Requires a directory. Only operations whose Section 15.2 error list includes
1964
2087
  * NFS4ERR_SYMLINK may report a symbolic link as such; the others say NOTDIR.
1965
2088
  */
1966
2089
  const requireDirectory = (reference, symlinkStatus) => mapFs(export_.observeMetadata(reference)).pipe(Effect.filterOrFail((observation) => observation.value.kind === "directory", (observation) => observation.value.kind === "symlink" ? symlinkStatus : Status.NOTDIR), Effect.asVoid);
1967
- const parentOfDirectory = (reference, symlinkStatus) => requireDirectory(reference, symlinkStatus).pipe(Effect.flatMap(() => parentOf(reference)));
2090
+ const parentOfDirectory = (reference, symlinkStatus) => requireDirectory(reference, symlinkStatus).pipe(Effect.flatMap(() => parentOf(reference, operation.code)));
1968
2091
  /** Requires a regular file, naming the offending type as Sections 18.16.4 and 18.22.3 do. */
1969
2092
  const requireRegularFile = (reference) => mapFs(export_.observeMetadata(reference)).pipe(Effect.flatMap((observation) => {
1970
2093
  switch (observation.value.kind) {
@@ -1998,7 +2121,7 @@ export const makeNfs4Handler = (export_, options) => {
1998
2121
  }
1999
2122
  catch (error) {
2000
2123
  if (error instanceof InvalidNameError)
2001
- return Effect.fail(nameStatus(error));
2124
+ return Effect.fail(nameStatus(error, operation.code));
2002
2125
  throw error;
2003
2126
  }
2004
2127
  }
@@ -2010,7 +2133,7 @@ export const makeNfs4Handler = (export_, options) => {
2010
2133
  try: () => {
2011
2134
  validateName(name, options.limits.maxNameBytes);
2012
2135
  },
2013
- catch: (error) => error instanceof InvalidNameError ? nameStatus(error) : Status.SERVERFAULT
2136
+ catch: (error) => error instanceof InvalidNameError ? nameStatus(error, operation.code) : Status.SERVERFAULT
2014
2137
  });
2015
2138
  const writeChangeInfo = (change) => (writer) => Effect.gen(function* () {
2016
2139
  yield* writer.write(XdrCodec.boolean, true);
@@ -2558,20 +2681,11 @@ export const makeNfs4Handler = (export_, options) => {
2558
2681
  return export_.resolve(operation.value).pipe(Effect.map((reference) => {
2559
2682
  setCurrent(reference);
2560
2683
  return { code: operation.code, status: Status.OK };
2561
- }), Effect.catch((error) => Effect.succeed({
2562
- code: operation.code,
2563
- status: error.reason === "WrongGeneration"
2564
- ? Status.FHEXPIRED
2565
- : error.reason === "Stale"
2566
- ? Status.STALE
2567
- : error.reason === "Unavailable"
2568
- ? Status.SERVERFAULT
2569
- : Status.BADHANDLE
2570
- })));
2684
+ }), Effect.catch((error) => Effect.succeed({ code: operation.code, status: putfhFailure(error) })));
2571
2685
  case "Getfh":
2572
2686
  if (current === undefined)
2573
2687
  return Effect.succeed(noCurrent());
2574
- return export_.handleFor(current).pipe(Effect.mapError(() => Status.SERVERFAULT), Effect.flatMap((handle) => Effect.map(encodeBody(handle, XdrCodec.opaque()), (body) => ({ code: operation.code, status: Status.OK, body }))), Effect.catchIf((error) => Predicate.isNumber(error), (status) => Effect.succeed({ code: operation.code, status })));
2688
+ return export_.handleFor(current).pipe(Effect.mapError((error) => failureForFs(error, operation.code)), Effect.flatMap((handle) => Effect.map(encodeBody(handle, XdrCodec.opaque()), (body) => ({ code: operation.code, status: Status.OK, body }))), Effect.catchIf((error) => Predicate.isNumber(error), (status) => Effect.succeed({ code: operation.code, status })));
2575
2689
  case "Savefh":
2576
2690
  if (current === undefined)
2577
2691
  return Effect.succeed(noCurrent());
@@ -2586,13 +2700,13 @@ export const makeNfs4Handler = (export_, options) => {
2586
2700
  return Effect.succeed({ code: operation.code, status: Status.OK });
2587
2701
  case "Lookup":
2588
2702
  // Section 15.1.2.8: a symbolic link as the current filehandle is NFS4ERR_SYMLINK.
2589
- return statusResult(withCurrent((reference) => requireDirectory(reference, Status.SYMLINK).pipe(Effect.andThen(export_.lookup(reference, operation.value).pipe(Effect.mapError(nameStatus))))), (reference) => {
2703
+ return statusResult(withCurrent((reference) => requireDirectory(reference, Status.SYMLINK).pipe(Effect.andThen(export_.lookup(reference, operation.value).pipe(Effect.mapError((error) => nameStatus(error, operation.code)))))), (reference) => {
2590
2704
  setCurrent(reference);
2591
2705
  return undefined;
2592
2706
  });
2593
2707
  case "Secinfo":
2594
2708
  // SECINFO consumes the current filehandle (RFC 8881 Section 18.29.3).
2595
- return statusResult(withCurrent((reference) => export_.lookup(reference, operation.value).pipe(Effect.mapError(nameStatus))), () => {
2709
+ return statusResult(withCurrent((reference) => export_.lookup(reference, operation.value).pipe(Effect.mapError((error) => nameStatus(error, operation.code)))), () => {
2596
2710
  setCurrent(undefined);
2597
2711
  return xdr.encode(options.securityFlavors ?? [AUTH_SYS, AUTH_NONE], XdrCodec.array(XdrCodec.uint32), options.limits, ByteSize.toNumberUnsafe(options.limits.maxRecordBytes));
2598
2712
  });
@@ -2664,9 +2778,7 @@ export const makeNfs4Handler = (export_, options) => {
2664
2778
  ]) {
2665
2779
  if ((supported & flag) === 0)
2666
2780
  continue;
2667
- const allowed = yield* activeCaller.accessReference(reference, bit).pipe(Effect.as(true), Effect.catchTag("FsError", (error) => error.code === "AccessDenied"
2668
- ? Effect.succeed(false)
2669
- : Effect.fail(failureForFs(error))));
2781
+ const allowed = yield* export_.access(reference, bit).pipe(Effect.map((granted) => granted === bit), Effect.mapError((error) => failureForFs(error, operation.code)));
2670
2782
  if (allowed)
2671
2783
  granted |= flag;
2672
2784
  }
@@ -2808,7 +2920,7 @@ export const makeNfs4Handler = (export_, options) => {
2808
2920
  yield* restore(requireDirectory(directory, Status.SYMLINK));
2809
2921
  const create = value.create;
2810
2922
  const found = yield* restore(export_.lookup(directory, value.name).pipe(Effect.catch((error) => error instanceof InvalidNameError || error.code !== "NotFound"
2811
- ? Effect.fail(nameStatus(error)) :
2923
+ ? Effect.fail(nameStatus(error, operation.code)) :
2812
2924
  Effect.void)));
2813
2925
  const observed = found === undefined
2814
2926
  ? undefined
@@ -2858,14 +2970,12 @@ export const makeNfs4Handler = (export_, options) => {
2858
2970
  atimeNs: observed.value.atimeNs,
2859
2971
  mtimeNs: observed.value.mtimeNs
2860
2972
  }
2861
- }).pipe(Effect.mapError((error) => {
2862
- if (error instanceof ExportCapacityError)
2863
- return Status.DELAY;
2973
+ }).pipe(Scope.provide(handlerScope), Effect.mapError((error) => {
2864
2974
  if (error instanceof InvalidNameError)
2865
- return nameStatus(error);
2975
+ return nameStatus(error, operation.code);
2866
2976
  if (error.code === "StaleReference")
2867
2977
  return Status.DELAY;
2868
- return failureForFs(error);
2978
+ return failureForFs(error, operation.code);
2869
2979
  })));
2870
2980
  let id;
2871
2981
  if (existing === undefined) {
@@ -2908,7 +3018,7 @@ export const makeNfs4Handler = (export_, options) => {
2908
3018
  }
2909
3019
  const target = value.claim === 4
2910
3020
  ? Effect.succeed({ revision: 0n, reference: directory })
2911
- : requireDirectory(directory, Status.SYMLINK).pipe(Effect.andThen(mapFs(export_.observeMetadata(directory))), Effect.flatMap((directoryObservation) => export_.lookup(directory, value.name).pipe(Effect.mapError(nameStatus), Effect.map((reference) => ({ revision: directoryObservation.revision, reference })))));
3021
+ : requireDirectory(directory, Status.SYMLINK).pipe(Effect.andThen(mapFs(export_.observeMetadata(directory))), Effect.flatMap((directoryObservation) => export_.lookup(directory, value.name).pipe(Effect.mapError((error) => nameStatus(error, operation.code)), Effect.map((reference) => ({ revision: directoryObservation.revision, reference })))));
2912
3022
  return target.pipe(Effect.tap(({ reference }) => requireRegularFile(reference)),
2913
3023
  // Write access is refused only once the target is known to be a regular file.
2914
3024
  Effect.tap(() => wantsWrite && !options.writable ? Effect.fail(Status.ROFS) : Effect.void), Effect.flatMap(({ revision, reference }) => Effect.uninterruptibleMask((restore) => Effect.suspend(() => {
@@ -2927,14 +3037,15 @@ export const makeNfs4Handler = (export_, options) => {
2927
3037
  const nextAccess = existing.access | accessMode;
2928
3038
  const permission = activeCaller === undefined ?
2929
3039
  Effect.void :
2930
- mapFs(activeCaller.accessReference(reference, (accessMode & 1 ? 0o4 : 0) | (accessMode & 2 ? 0o2 : 0)));
3040
+ requireAccess(reference, (accessMode & 1 ? 0o4 : 0) | (accessMode & 2 ? 0o2 : 0));
2931
3041
  const addedAccess = nextAccess & ~existing.access;
2932
3042
  const heldHandle = addedAccess === OPEN4_SHARE_ACCESS_READ
2933
3043
  ? existing.readFile
2934
3044
  : existing.writeFile;
2935
3045
  const replacement = addedAccess === 0 || heldHandle !== undefined ?
2936
3046
  Effect.succeed(null) :
2937
- mapFs(export_.open(reference, addedAccess === OPEN4_SHARE_ACCESS_READ ? "read" : "write"));
3047
+ mapFs(export_.open(reference, addedAccess === OPEN4_SHARE_ACCESS_READ ? "read" : "write")
3048
+ .pipe(Scope.provide(handlerScope)));
2938
3049
  let transferred = false;
2939
3050
  return restore(permission).pipe(Effect.andThen(Effect.acquireUseRelease(restore(replacement), (opened) => opened === null ? Effect.void : Effect.sync(() => {
2940
3051
  const previousClose = existing.close;
@@ -2956,7 +3067,8 @@ export const makeNfs4Handler = (export_, options) => {
2956
3067
  return Effect.succeed({ code: operation.code, status: Status.DELAY });
2957
3068
  }
2958
3069
  const serial = openSerial++;
2959
- return restore(mapFs(export_.open(reference, accessMode === 3 ? "readWrite" : wantsWrite ? "write" : "read"))).pipe(Effect.flatMap((opened) => {
3070
+ return restore(mapFs(export_.open(reference, accessMode === 3 ? "readWrite" : wantsWrite ? "write" : "read")
3071
+ .pipe(Scope.provide(handlerScope)))).pipe(Effect.flatMap((opened) => {
2960
3072
  const id = makeStateId(options.generation, serial, 1);
2961
3073
  opens.set(stateIdKey(id), {
2962
3074
  id,
@@ -3009,14 +3121,14 @@ export const makeNfs4Handler = (export_, options) => {
3009
3121
  return Effect.succeed(noCurrent());
3010
3122
  const readPermission = activeCaller === undefined
3011
3123
  ? Effect.void
3012
- : activeCaller.accessReference(current, 0o4).pipe(Effect.mapError(failureForFs));
3124
+ : requireAccess(current, 0o4);
3013
3125
  if (isAllZero(value.stateid) || isAllOnes(value.stateid)) {
3014
3126
  const reference = current;
3015
3127
  // Section 9.1.2: the anonymous stateid must still respect a deny-read share
3016
3128
  // reservation; the READ-bypass stateid (all ones) may ignore it.
3017
3129
  const denied = isAllZero(value.stateid) &&
3018
3130
  [...opens.values()].some((open) => open.reference === reference && (open.deny & OPEN4_SHARE_DENY_READ) !== 0);
3019
- return requireRegularFile(reference).pipe(Effect.andThen(denied ? Effect.fail(Status.LOCKED) : Effect.void), Effect.andThen(readPermission), Effect.andThen(Effect.acquireUseRelease(mapFs(export_.open(reference)), (opened) => readFrom(opened.handle), (opened) => opened.close)), Effect.catchIf(Predicate.isNumber, (status) => Effect.succeed({ code: operation.code, status })));
3131
+ return requireRegularFile(reference).pipe(Effect.andThen(denied ? Effect.fail(Status.LOCKED) : Effect.void), Effect.andThen(readPermission), Effect.andThen(Effect.acquireUseRelease(mapFs(Scope.provide(export_.open(reference), handlerScope)), (opened) => readFrom(opened.handle), (opened) => opened.close)), Effect.catchIf(Predicate.isNumber, (status) => Effect.succeed({ code: operation.code, status })));
3020
3132
  }
3021
3133
  const effectiveStateid = isCurrentStateId(value.stateid) ? currentStateid : value.stateid;
3022
3134
  if (effectiveStateid === undefined) {
@@ -3047,10 +3159,10 @@ export const makeNfs4Handler = (export_, options) => {
3047
3159
  }
3048
3160
  return readPermission.pipe(Effect.andThen(readFrom(open.readFile)), Effect.catchIf(Predicate.isNumber, (status) => Effect.succeed({ code: operation.code, status })));
3049
3161
  function readFrom(file) {
3050
- return file.pread(value.count, value.offset).pipe(Effect.flatMap((data) => file.stat.pipe(Effect.map((metadata) => ({ data, metadata })))), Effect.flatMap(({ data, metadata }) => Effect.map(encodeStatusBody(options.limits, [
3051
- field(XdrCodec.boolean, value.offset + BigInt(data.length) >= metadata.size),
3162
+ return file.pread(value.count, value.offset).pipe(Effect.flatMap(({ bytes: data, eof }) => Effect.map(encodeStatusBody(options.limits, [
3163
+ field(XdrCodec.boolean, eof),
3052
3164
  field(XdrCodec.opaque(), data)
3053
- ]), (body) => ({ code: operation.code, status: Status.OK, body }))), Effect.catchTag("FsError", (error) => Effect.succeed({ code: operation.code, status: failureForFs(error) })));
3165
+ ]), (body) => ({ code: operation.code, status: Status.OK, body }))), Effect.catchTag("VfsError", (error) => Effect.succeed({ code: operation.code, status: failureForFs(error, operation.code) })));
3054
3166
  }
3055
3167
  }
3056
3168
  case "OpenDowngrade": {
@@ -3370,7 +3482,7 @@ export const makeNfs4Handler = (export_, options) => {
3370
3482
  const writeFile = open.writeFile;
3371
3483
  return statusResult(requireRegularFile(reference).pipe(Effect.andThen(activeCaller === undefined
3372
3484
  ? Effect.void
3373
- : activeCaller.accessReference(reference, 0o2).pipe(Effect.mapError(failureForFs))), Effect.andThen(mapFs(writeFile.pwrite(value.data, value.offset)))), (count) => encodeStatusBody(options.limits, [
3485
+ : requireAccess(reference, 0o2)), Effect.andThen(mapFs(writeFile.pwrite(value.data, value.offset)))), (count) => encodeStatusBody(options.limits, [
3374
3486
  field(XdrCodec.uint32, count),
3375
3487
  field(XdrCodec.uint32, 2),
3376
3488
  field(XdrCodec.fixedOpaque(8), writeVerifier)
@@ -3387,8 +3499,7 @@ export const makeNfs4Handler = (export_, options) => {
3387
3499
  const reference = current;
3388
3500
  const value = operation.value;
3389
3501
  return Effect.gen(function* () {
3390
- const applied = [];
3391
- const reply = (status) => Effect.map(encodeStatusBody(options.limits, [(writer) => writeBitmap(writer, wordsFor(applied))]), (body) => ({ code: operation.code, status, body }));
3502
+ const reply = (status, attrsset = []) => Effect.map(encodeStatusBody(options.limits, [(writer) => writeBitmap(writer, wordsFor(attrsset))]), (body) => ({ code: operation.code, status, body }));
3392
3503
  const decoded = yield* setattrAttributes(value.attrs, options.limits, supportedAttributes).pipe(Effect.mapError((error) => error instanceof XdrDecodeError ? Status.BADXDR : error), Effect.map((changes) => ({ changes })), Effect.catch((status) => Effect.succeed({ status })));
3393
3504
  if ("status" in decoded)
3394
3505
  return yield* reply(decoded.status);
@@ -3412,29 +3523,12 @@ export const makeNfs4Handler = (export_, options) => {
3412
3523
  if ([...opens.values()].some((state) => state.reference === reference && (state.deny & OPEN4_SHARE_ACCESS_WRITE) !== 0))
3413
3524
  return yield* reply(Status.SHARE_DENIED);
3414
3525
  }
3415
- const accessTime = decoded.changes.find((change) => change.attribute === 48);
3416
- const modificationTime = decoded.changes.find((change) => change.attribute === 54);
3417
- for (const change of decoded.changes) {
3418
- if (change.attribute === 54 && accessTime !== undefined)
3419
- continue;
3420
- const mutation = change.kind === "size"
3421
- ? export_.truncate(reference, change.value)
3422
- : change.kind === "mode"
3423
- ? export_.chmod(reference, change.value)
3424
- : change.kind === "owner"
3425
- ? export_.chown(reference, change.attribute === 36 ? { uid: change.value } : { gid: change.value })
3426
- : export_.utimes(reference, {
3427
- access: change.attribute === 48 ? change.value : { kind: "omit" },
3428
- modification: modificationTime?.kind === "time" ? modificationTime.value : { kind: "omit" }
3429
- });
3430
- const status = yield* mutation.pipe(Effect.as(Status.OK), Effect.catch((error) => Effect.succeed(change.kind === "owner" && error.code === "AccessDenied" ? Status.PERM : failureForFs(error))));
3431
- if (status !== Status.OK)
3432
- return yield* reply(status);
3433
- applied.push(change.attribute);
3434
- if (change.attribute === 48 && modificationTime !== undefined)
3435
- applied.push(54);
3436
- }
3437
- return yield* reply(Status.OK);
3526
+ // RFC 8881 lets a failed SETATTR report some attributes or none; one setattr applies all
3527
+ // of them or none, so attrsset is empty on failure and complete on success.
3528
+ const status = yield* applySetattr(export_, reference, setattrOptions(decoded.changes)).pipe(Effect.as(Status.OK), Effect.catch((error) => Effect.succeed(error === Status.DELAY ? error : failureForFs(error, operation.code))));
3529
+ return yield* reply(status, status === Status.OK
3530
+ ? decoded.changes.map((change) => change.attribute)
3531
+ : []);
3438
3532
  });
3439
3533
  }
3440
3534
  // Section 15.2 lists NFS4ERR_SYMLINK for LINK but not for CREATE, REMOVE, or RENAME.
@@ -3483,11 +3577,9 @@ export const makeNfs4Handler = (export_, options) => {
3483
3577
  yield* reader.finish;
3484
3578
  const result = yield* (value.kind === 2
3485
3579
  ? export_.mkdir(parent, value.name, mode === undefined ? { times } : { mode, times, exactMode: true })
3486
- : export_.symlink(value.target, parent, value.name, { times })).pipe(Effect.mapError((error) => error instanceof ExportCapacityError ?
3487
- Status.DELAY :
3488
- error instanceof InvalidNameError
3489
- ? nameStatus(error)
3490
- : failureForFs(error)));
3580
+ : export_.symlink(value.target, parent, value.name, { times })).pipe(Effect.mapError((error) => error instanceof InvalidNameError
3581
+ ? nameStatus(error, operation.code)
3582
+ : failureForFs(error, operation.code)));
3491
3583
  setCurrent(result.reference);
3492
3584
  return { change: result.directory, attributes };
3493
3585
  }).pipe(Effect.mapError((error) => error instanceof XdrDecodeError ? Status.BADXDR : error)), ({ change, attributes }) => encodeStatusBody(options.limits, [
@@ -3523,7 +3615,7 @@ export const makeNfs4Handler = (export_, options) => {
3523
3615
  return yield* export_.rename(source, operation.value.oldName, destination, operation.value.newName)
3524
3616
  .pipe(Effect.mapError((error) => error.code === "IsDirectory" || error.code === "NotDirectory" || error.code === "NotEmpty"
3525
3617
  ? Status.EXIST
3526
- : failureForFs(error)));
3618
+ : failureForFs(error, operation.code)));
3527
3619
  }), (change) => {
3528
3620
  const sourceChange = Predicate.isTagged(change, "SameDirectory")
3529
3621
  ? change.directory
@@ -3563,11 +3655,11 @@ export const makeNfs4Handler = (export_, options) => {
3563
3655
  current = reference;
3564
3656
  currentStateid = undefined;
3565
3657
  }
3566
- function parentOf(reference) {
3658
+ function parentOf(reference, operation) {
3567
3659
  // The root has no parent in this export (RFC 8881 Section 18.14.3).
3568
- return export_.parent(reference).pipe(Effect.mapError(failureForFs), Effect.filterOrFail((parent) => parent !== reference, () => Status.NOENT));
3660
+ return export_.parent(reference).pipe(Effect.mapError((error) => failureForFs(error, operation)), Effect.filterOrFail((parent) => parent !== reference, () => Status.NOENT));
3569
3661
  }
3570
- function nameStatus(error) {
3662
+ function nameStatus(error, operation) {
3571
3663
  if (error instanceof InvalidNameError) {
3572
3664
  // RFC 8881 Section 14.5: reserved components are BADNAME, over-long names NAMETOOLONG,
3573
3665
  // valid UTF-8 the file system cannot store (a slash or NUL) BADCHAR, and other
@@ -3583,7 +3675,7 @@ export const makeNfs4Handler = (export_, options) => {
3583
3675
  return Status.INVAL;
3584
3676
  }
3585
3677
  }
3586
- return failureForFs(error);
3678
+ return failureForFs(error, operation);
3587
3679
  }
3588
3680
  function isSpecialStateId(stateid) {
3589
3681
  return isAllZero(stateid) || isAllOnes(stateid) || isCurrentStateId(stateid);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@effect-vfs/nfs",
3
- "version": "0.5.0",
3
+ "version": "0.7.0",
4
4
  "description": "NFSv4.1 server for one live Effect VFS volume, with guarded experimental writes.",
5
5
  "homepage": "https://github.com/lloydrichards/effect-virtual-fs#readme",
6
6
  "license": "MIT",
@@ -35,20 +35,20 @@
35
35
  "scripts": {
36
36
  "build": "tsc --project tsconfig.build.json",
37
37
  "clean": "git clean -xdf .cache .turbo dist docs node_modules tsconfig.tsbuildinfo",
38
- "test": "vitest run",
38
+ "test": "bun --bun run vitest run --config ../../vitest.config.ts --project nfs",
39
39
  "type-check": "tsc --noEmit"
40
40
  },
41
41
  "peerDependencies": {
42
- "effect": "4.0.0-rc.115"
42
+ "effect": "4.0.0-rc.117"
43
43
  },
44
44
  "dependencies": {
45
45
  "@effect-vfs/core": "workspace:*"
46
46
  },
47
47
  "devDependencies": {
48
- "@effect/platform-node-shared": "4.0.0-rc.115",
49
- "@effect/vitest": "4.0.0-rc.115",
48
+ "@effect/platform-node-shared": "4.0.0-rc.117",
49
+ "@effect/vitest": "4.0.0-rc.117",
50
50
  "@repo/config-typescript": "workspace:*",
51
- "effect": "4.0.0-rc.115",
52
- "vitest": "^5.0.1"
51
+ "effect": "4.0.0-rc.117",
52
+ "vitest": "^5.0.2"
53
53
  }
54
54
  }