kobako 0.30.0 → 0.31.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.
Files changed (266) hide show
  1. checksums.yaml +4 -4
  2. data/.release-please-manifest.json +1 -1
  3. data/CHANGELOG.md +335 -0
  4. data/Cargo.lock +469 -11
  5. data/README.md +43 -3
  6. data/ROADMAP.md +1 -1
  7. data/crates/kobako-runtime/CHANGELOG.md +219 -0
  8. data/crates/kobako-runtime/Cargo.toml +51 -3
  9. data/crates/kobako-runtime/README.md +7 -4
  10. data/crates/kobako-runtime/src/cred.rs +124 -0
  11. data/crates/kobako-runtime/src/dispatch.rs +4 -5
  12. data/crates/kobako-runtime/src/endpoint/buffer.rs +153 -44
  13. data/crates/kobako-runtime/src/endpoint/dispatch.rs +80 -41
  14. data/crates/kobako-runtime/src/endpoint/invoke.rs +23 -36
  15. data/crates/kobako-runtime/src/endpoint.rs +137 -36
  16. data/crates/kobako-runtime/src/errno.rs +391 -0
  17. data/crates/kobako-runtime/src/error.rs +31 -10
  18. data/crates/kobako-runtime/src/filesystem/anon_inodes.rs +52 -0
  19. data/crates/kobako-runtime/src/filesystem/bind/lookup.rs +52 -14
  20. data/crates/kobako-runtime/src/filesystem/bind/walk.rs +19 -20
  21. data/crates/kobako-runtime/src/filesystem/bind.rs +437 -245
  22. data/crates/kobako-runtime/src/filesystem/overlay/file.rs +6 -6
  23. data/crates/kobako-runtime/src/filesystem/overlay/path.rs +43 -65
  24. data/crates/kobako-runtime/src/filesystem/overlay/stack/copy_up.rs +9 -16
  25. data/crates/kobako-runtime/src/filesystem/overlay/stack/dir.rs +47 -72
  26. data/crates/kobako-runtime/src/filesystem/overlay/stack/namei.rs +12 -12
  27. data/crates/kobako-runtime/src/filesystem/overlay/stack/readdir.rs +4 -7
  28. data/crates/kobako-runtime/src/filesystem/overlay/stack.rs +121 -37
  29. data/crates/kobako-runtime/src/filesystem/overlay.rs +302 -343
  30. data/crates/kobako-runtime/src/filesystem/pipe.rs +12 -9
  31. data/crates/kobako-runtime/src/filesystem/rdir.rs +15 -32
  32. data/crates/kobako-runtime/src/filesystem/tmpfs/seed.rs +32 -0
  33. data/crates/kobako-runtime/src/filesystem/tmpfs/tmpfile.rs +3 -3
  34. data/crates/kobako-runtime/src/filesystem/tmpfs/whiteout.rs +57 -35
  35. data/crates/kobako-runtime/src/filesystem/tmpfs/xattr.rs +2 -2
  36. data/crates/kobako-runtime/src/filesystem/tmpfs.rs +172 -160
  37. data/crates/kobako-runtime/src/filesystem/wrap.rs +36 -52
  38. data/crates/kobako-runtime/src/filesystem.rs +6 -3
  39. data/crates/kobako-runtime/src/fork.rs +96 -0
  40. data/crates/kobako-runtime/src/grant.rs +3 -0
  41. data/crates/kobako-runtime/src/hashtable.rs +4 -2
  42. data/crates/kobako-runtime/src/lib.rs +18 -7
  43. data/crates/kobako-runtime/src/limits.rs +195 -0
  44. data/crates/kobako-runtime/src/locking.rs +10 -0
  45. data/crates/kobako-runtime/src/memcg.rs +383 -0
  46. data/crates/kobako-runtime/src/mount.rs +67 -9
  47. data/crates/kobako-runtime/src/net/backends.rs +43 -0
  48. data/crates/kobako-runtime/src/net/connections.rs +179 -0
  49. data/crates/kobako-runtime/src/net/credential.rs +125 -0
  50. data/crates/kobako-runtime/src/net/egress.rs +160 -0
  51. data/crates/kobako-runtime/src/net/family.rs +181 -0
  52. data/crates/kobako-runtime/src/net/http.rs +2733 -0
  53. data/crates/kobako-runtime/src/net/lookup.rs +285 -0
  54. data/crates/kobako-runtime/src/net/mock.rs +251 -0
  55. data/crates/kobako-runtime/src/net/namespace.rs +1366 -0
  56. data/crates/kobako-runtime/src/net/reactor.rs +531 -0
  57. data/crates/kobako-runtime/src/net/resolv/darwin.rs +275 -0
  58. data/crates/kobako-runtime/src/net/resolv/stub/tests.rs +469 -0
  59. data/crates/kobako-runtime/src/net/resolv/stub.rs +536 -0
  60. data/crates/kobako-runtime/src/net/resolv/windows.rs +248 -0
  61. data/crates/kobako-runtime/src/net/resolv.rs +227 -0
  62. data/crates/kobako-runtime/src/net/socket.rs +870 -0
  63. data/crates/kobako-runtime/src/net/tcp.rs +1588 -0
  64. data/crates/kobako-runtime/src/net/tls.rs +58 -0
  65. data/crates/kobako-runtime/src/net/transport.rs +279 -0
  66. data/crates/kobako-runtime/src/net/udp.rs +1003 -0
  67. data/crates/kobako-runtime/src/net.rs +42 -0
  68. data/crates/kobako-runtime/src/network/builder.rs +177 -0
  69. data/crates/kobako-runtime/src/network/ruleset.rs +777 -0
  70. data/crates/kobako-runtime/src/network.rs +551 -0
  71. data/crates/kobako-runtime/src/policy.rs +16 -0
  72. data/crates/kobako-runtime/src/profile.rs +29 -144
  73. data/crates/kobako-runtime/src/runtime.rs +3 -5
  74. data/crates/kobako-runtime/src/sched.rs +130 -29
  75. data/crates/kobako-runtime/src/security/entry_policy.rs +22 -0
  76. data/crates/kobako-runtime/src/{vfs/cred.rs → security/hooks.rs} +52 -144
  77. data/crates/kobako-runtime/src/security/mount_policy.rs +158 -0
  78. data/crates/kobako-runtime/src/security.rs +101 -196
  79. data/crates/kobako-runtime/src/snapshot.rs +121 -2
  80. data/crates/kobako-runtime/src/vfs/attr.rs +5 -5
  81. data/crates/kobako-runtime/src/vfs/dentry.rs +143 -89
  82. data/crates/kobako-runtime/src/vfs/file.rs +199 -203
  83. data/crates/kobako-runtime/src/vfs/inode.rs +41 -45
  84. data/crates/kobako-runtime/src/vfs/kern_path.rs +38 -42
  85. data/crates/kobako-runtime/src/vfs/mount.rs +10 -9
  86. data/crates/kobako-runtime/src/vfs/namei.rs +829 -700
  87. data/crates/kobako-runtime/src/vfs/namespace.rs +162 -0
  88. data/crates/kobako-runtime/src/vfs/open_files.rs +69 -0
  89. data/crates/kobako-runtime/src/vfs/openat2.rs +3 -3
  90. data/crates/kobako-runtime/src/vfs/path.rs +6 -6
  91. data/crates/kobako-runtime/src/vfs/readdir.rs +6 -6
  92. data/crates/kobako-runtime/src/vfs/stat.rs +159 -23
  93. data/crates/kobako-runtime/src/vfs/super_block.rs +18 -14
  94. data/crates/kobako-runtime/src/vfs/utimes.rs +37 -27
  95. data/crates/kobako-runtime/src/vfs.rs +9 -6
  96. data/crates/kobako-runtime/src/wait.rs +356 -0
  97. data/crates/kobako-transport/CHANGELOG.md +31 -0
  98. data/crates/kobako-transport/Cargo.toml +1 -1
  99. data/crates/kobako-transport/README.md +3 -4
  100. data/crates/kobako-transport/src/abi.rs +78 -72
  101. data/crates/kobako-transport/src/envelope/bytes.rs +17 -6
  102. data/crates/kobako-transport/src/envelope/call.rs +32 -4
  103. data/crates/kobako-transport/src/envelope/error_record.rs +21 -0
  104. data/crates/kobako-transport/src/envelope/name.rs +99 -0
  105. data/crates/kobako-transport/src/envelope/outcome.rs +9 -9
  106. data/crates/kobako-transport/src/envelope/preamble.rs +24 -21
  107. data/crates/kobako-transport/src/envelope/reply.rs +27 -27
  108. data/crates/kobako-transport/src/envelope/unsupported.rs +10 -10
  109. data/crates/kobako-transport/src/envelope.rs +13 -8
  110. data/crates/kobako-wasmtime/CHANGELOG.md +161 -0
  111. data/crates/kobako-wasmtime/Cargo.toml +26 -7
  112. data/crates/kobako-wasmtime/README.md +3 -2
  113. data/crates/kobako-wasmtime/build/preview2.rs +1339 -0
  114. data/crates/kobako-wasmtime/build.rs +16 -0
  115. data/crates/kobako-wasmtime/src/abi.rs +17 -37
  116. data/crates/kobako-wasmtime/src/ambient.rs +33 -18
  117. data/crates/kobako-wasmtime/src/cache.rs +23 -15
  118. data/crates/kobako-wasmtime/src/config.rs +52 -68
  119. data/crates/kobako-wasmtime/src/driver.rs +48 -63
  120. data/crates/kobako-wasmtime/src/exports.rs +143 -17
  121. data/crates/kobako-wasmtime/src/guest.rs +12 -6
  122. data/crates/kobako-wasmtime/src/guest_binary.rs +14 -0
  123. data/crates/kobako-wasmtime/src/imports.rs +42 -18
  124. data/crates/kobako-wasmtime/src/instance_pre.rs +4 -4
  125. data/crates/kobako-wasmtime/src/invocation.rs +74 -12
  126. data/crates/kobako-wasmtime/src/lib.rs +5 -3
  127. data/crates/kobako-wasmtime/src/limiter.rs +70 -5
  128. data/crates/kobako-wasmtime/src/preview1/descriptors.rs +309 -0
  129. data/crates/kobako-wasmtime/src/preview1/differential/mount.rs +5 -15
  130. data/crates/kobako-wasmtime/src/preview1/differential.rs +27 -31
  131. data/crates/kobako-wasmtime/src/preview1/errno.rs +55 -66
  132. data/crates/kobako-wasmtime/src/preview1/fd.rs +327 -296
  133. data/crates/kobako-wasmtime/src/preview1/memory.rs +21 -12
  134. data/crates/kobako-wasmtime/src/preview1/mount_view/wrap.rs +34 -53
  135. data/crates/kobako-wasmtime/src/preview1/mount_view.rs +231 -217
  136. data/crates/kobako-wasmtime/src/preview1/path.rs +56 -121
  137. data/crates/kobako-wasmtime/src/preview1/poll.rs +244 -120
  138. data/crates/kobako-wasmtime/src/preview1/sock.rs +10 -8
  139. data/crates/kobako-wasmtime/src/preview1/testsuite.rs +5 -15
  140. data/crates/kobako-wasmtime/src/preview1.rs +46 -42
  141. data/crates/kobako-wasmtime/src/preview2/abi.rs +227 -0
  142. data/crates/kobako-wasmtime/src/preview2/error.rs +118 -0
  143. data/crates/kobako-wasmtime/src/preview2/filesystem.rs +122 -0
  144. data/crates/kobako-wasmtime/src/preview2/host.rs +3959 -0
  145. data/crates/kobako-wasmtime/src/preview2/http.rs +1503 -0
  146. data/crates/kobako-wasmtime/src/preview2/io.rs +315 -0
  147. data/crates/kobako-wasmtime/src/preview2/sockets.rs +379 -0
  148. data/crates/kobako-wasmtime/src/preview2/table.rs +305 -0
  149. data/crates/kobako-wasmtime/src/preview2.rs +57 -0
  150. data/crates/kobako-wasmtime/src/trap.rs +24 -9
  151. data/crates/kobako-wasmtime/src/wasi.rs +210 -81
  152. data/crates/kobako-wasmtime/wit/deps/cli.wit +233 -0
  153. data/crates/kobako-wasmtime/wit/deps/clocks.wit +162 -0
  154. data/crates/kobako-wasmtime/wit/deps/filesystem.wit +589 -0
  155. data/crates/kobako-wasmtime/wit/deps/http.wit +733 -0
  156. data/crates/kobako-wasmtime/wit/deps/io.wit +299 -0
  157. data/crates/kobako-wasmtime/wit/deps/random.wit +92 -0
  158. data/crates/kobako-wasmtime/wit/deps/sockets.wit +949 -0
  159. data/data/kobako.wasm +0 -0
  160. data/ext/kobako/Cargo.toml +1 -1
  161. data/ext/kobako/src/{runtime/errors.rs → errors.rs} +34 -26
  162. data/ext/kobako/src/{runtime/escape.rs → escape.rs} +42 -11
  163. data/ext/kobako/src/{runtime/filesystem → filesystem}/grants.rs +30 -26
  164. data/ext/kobako/src/{runtime/filesystem → filesystem}/ruby.rs +149 -168
  165. data/ext/kobako/src/{runtime/filesystem.rs → filesystem.rs} +24 -15
  166. data/ext/kobako/src/gvl.rs +306 -0
  167. data/ext/kobako/src/lib.rs +64 -3
  168. data/ext/kobako/src/network/mock.rs +187 -0
  169. data/ext/kobako/src/network.rs +591 -0
  170. data/ext/kobako/src/runtime/bridge.rs +30 -29
  171. data/ext/kobako/src/runtime/snapshot.rs +4 -4
  172. data/ext/kobako/src/runtime.rs +221 -143
  173. data/ext/kobako/src/wire.rs +42 -0
  174. data/lib/kobako/catalog/extensions.rb +14 -2
  175. data/lib/kobako/catalog/flags.rb +3 -5
  176. data/lib/kobako/catalog/grants.rb +5 -4
  177. data/lib/kobako/catalog/handles.rb +5 -27
  178. data/lib/kobako/catalog/mount.rb +11 -3
  179. data/lib/kobako/catalog/network.rb +35 -0
  180. data/lib/kobako/catalog/replacements.rb +28 -0
  181. data/lib/kobako/catalog/services.rb +5 -19
  182. data/lib/kobako/catalog/snippets.rb +3 -18
  183. data/lib/kobako/catalog.rb +3 -0
  184. data/lib/kobako/codec/{utils.rb → boundary.rb} +4 -2
  185. data/lib/kobako/codec/decoder.rb +4 -4
  186. data/lib/kobako/codec/ext_types.rb +3 -3
  187. data/lib/kobako/codec/handle_walk.rb +3 -43
  188. data/lib/kobako/codec/value_budget.rb +132 -40
  189. data/lib/kobako/codec.rb +1 -1
  190. data/lib/kobako/context.rb +24 -11
  191. data/lib/kobako/errors.rb +15 -12
  192. data/lib/kobako/extension.rb +3 -2
  193. data/lib/kobako/filesystem.rb +9 -2
  194. data/lib/kobako/handle.rb +2 -2
  195. data/lib/kobako/names.rb +28 -0
  196. data/lib/kobako/network.rb +210 -0
  197. data/lib/kobako/outcome.rb +7 -7
  198. data/lib/kobako/pool.rb +45 -23
  199. data/lib/kobako/runtime.rb +3 -2
  200. data/lib/kobako/sandbox.rb +92 -35
  201. data/lib/kobako/sandbox_options.rb +41 -106
  202. data/lib/kobako/transport/argument_wrap.rb +64 -0
  203. data/lib/kobako/transport/block_failure.rb +1 -1
  204. data/lib/kobako/transport/dispatcher.rb +6 -6
  205. data/lib/kobako/transport/exposure.rb +26 -15
  206. data/lib/kobako/transport/reflection.rb +21 -4
  207. data/lib/kobako/transport/run.rb +8 -23
  208. data/lib/kobako/transport/yielder.rb +2 -9
  209. data/lib/kobako/transport.rb +1 -0
  210. data/lib/kobako/version.rb +1 -1
  211. data/lib/kobako.rb +6 -2
  212. data/release-please-config.json +15 -0
  213. data/sig/core/thread.rbs +6 -0
  214. data/sig/kobako/catalog/extensions.rbs +2 -0
  215. data/sig/kobako/catalog/grants.rbs +7 -4
  216. data/sig/kobako/catalog/handles.rbs +0 -2
  217. data/sig/kobako/catalog/mount.rbs +3 -1
  218. data/sig/kobako/catalog/network.rbs +20 -0
  219. data/sig/kobako/catalog/replacements.rbs +14 -0
  220. data/sig/kobako/catalog/services.rbs +0 -4
  221. data/sig/kobako/catalog/snippets.rbs +0 -2
  222. data/sig/kobako/codec/{utils.rbs → boundary.rbs} +2 -2
  223. data/sig/kobako/codec/handle_walk.rbs +0 -6
  224. data/sig/kobako/codec/value_budget.rbs +47 -4
  225. data/sig/kobako/context.rbs +3 -1
  226. data/sig/kobako/errors.rbs +4 -4
  227. data/sig/kobako/filesystem.rbs +21 -3
  228. data/sig/kobako/network.rbs +115 -0
  229. data/sig/kobako/outcome.rbs +1 -1
  230. data/sig/kobako/pool.rbs +7 -3
  231. data/sig/kobako/runtime.rbs +32 -3
  232. data/sig/kobako/sandbox.rbs +19 -2
  233. data/sig/kobako/sandbox_options.rbs +29 -38
  234. data/sig/kobako/transport/argument_wrap.rbs +15 -0
  235. data/sig/kobako/transport/error.rbs +1 -1
  236. data/sig/kobako/transport/exposure.rbs +2 -4
  237. data/sig/kobako/transport/reflection.rbs +10 -0
  238. data/sig/kobako/transport/run.rbs +0 -2
  239. data/sig/kobako/transport/yielder.rbs +0 -3
  240. data/sig/kobako/transport.rbs +1 -1
  241. data/sig/kobako.rbs +13 -0
  242. metadata +84 -35
  243. data/crates/kobako-runtime/src/endpoint/capture.rs +0 -115
  244. data/crates/kobako-runtime/src/endpoint/memory_cap.rs +0 -238
  245. data/crates/kobako-runtime/src/filesystem/path.rs +0 -21
  246. data/crates/kobako-runtime/src/vfs/errno.rs +0 -153
  247. data/crates/kobako-runtime/tests/linux_baseline/calls.rs +0 -171
  248. data/crates/kobako-runtime/tests/linux_baseline/concurrent.rs +0 -276
  249. data/crates/kobako-runtime/tests/linux_baseline/kobako.rs +0 -323
  250. data/crates/kobako-runtime/tests/linux_baseline/linux-baseline-expected.txt +0 -16
  251. data/crates/kobako-runtime/tests/linux_baseline/linux.rs +0 -449
  252. data/crates/kobako-runtime/tests/linux_baseline/main.rs +0 -611
  253. data/crates/kobako-runtime/tests/linux_baseline/permissions.rs +0 -236
  254. data/crates/kobako-wasmtime/src/descriptors.rs +0 -200
  255. data/crates/kobako-wasmtime/tests/integration/compile_posture.rs +0 -43
  256. data/crates/kobako-wasmtime/tests/integration/guest_file.rs +0 -1085
  257. data/crates/kobako-wasmtime/tests/integration/main.rs +0 -29
  258. data/crates/kobako-wasmtime/tests/integration/preamble_flags.rs +0 -70
  259. data/crates/kobako-wasmtime/tests/integration/snippet_compile.rs +0 -95
  260. data/crates/kobako-wasmtime/tests/integration/support/mod.rs +0 -30
  261. data/crates/kobako-wasmtime/tests/integration/unanswered_call.rs +0 -86
  262. data/crates/kobako-wasmtime/tests/integration/unsupported_call.rs +0 -51
  263. data/ext/kobako/src/runtime/gvl.rs +0 -147
  264. data/lib/kobako/constant_name.rb +0 -8
  265. data/sig/kobako/constant_name.rbs +0 -3
  266. /data/ext/kobako/src/{runtime/pinned_value.rs → pinned_value.rs} +0 -0
@@ -11,14 +11,16 @@ use std::time::{SystemTime, UNIX_EPOCH};
11
11
  use kobako_runtime::filesystem::Bind;
12
12
  use kobako_runtime::filesystem::Filesystem;
13
13
  use kobako_runtime::filesystem::{
14
- FileOperations, FileSystemType, FileType, FilesystemError, InodeOperations, Kiocb, Kstat,
15
- Lookup, OpenHow, Overlay, RenameFlag, Tmpfs,
14
+ FileOperations, FileSystemType, FileType, InodeOperations, Kiocb, Kstat, Lookup, OpenHow,
15
+ Overlay, RenameFlag, Tmpfs,
16
16
  };
17
17
  use kobako_runtime::grant::Grant;
18
- use kobako_runtime::mount::{Access, Mount, Policy};
18
+ use kobako_runtime::mount::{Access, Mount, MountRequest};
19
+ use kobako_runtime::policy::Policy;
19
20
  use kobako_runtime::profile::Profile;
20
- use kobako_runtime::security::prepare_creds_within;
21
- use kobako_runtime::vfs::{self, Dentry, Inode, Path, SecurityOperations, SecurityPath, PATH_MAX};
21
+ use kobako_runtime::security::{prepare_creds, SecurityOperations, SecurityPath};
22
+ use kobako_runtime::vfs::{self, Dentry, Inode, Path, PATH_MAX};
23
+ use kobako_runtime::Errno;
22
24
  use wasmtime::{Instance, Module, Store};
23
25
 
24
26
  use crate::cache::load_engine;
@@ -42,14 +44,14 @@ fn host<F: FileSystemType>(filesystem: &Arc<F>) -> Path {
42
44
  }
43
45
 
44
46
  /// The names `filesystem`'s root holds, as the host lists them.
45
- fn host_entries<F: FileSystemType>(filesystem: &Arc<F>) -> Result<Vec<String>, FilesystemError> {
47
+ fn host_entries<F: FileSystemType>(filesystem: &Arc<F>) -> Result<Vec<String>, Errno> {
46
48
  let mount = Mount::new(
47
49
  "/data",
48
50
  Filesystem::new(filesystem.clone()).expect("the instance must stand"),
49
51
  Access::ReadWrite,
50
52
  )
51
53
  .expect("/data is a guest path");
52
- let mut root = vfs::File::root(mount.mnt(), &prepare_creds_within(&[], None))?;
54
+ let mut root = vfs::File::root(mount.mnt(), &prepare_creds(&[], None))?;
53
55
  let mut names = Vec::new();
54
56
  root.llseek(2, vfs::Whence::Set)?;
55
57
  root.iterate_dir(&mut vfs::DirContext::new(0, &mut |emit| {
@@ -70,6 +72,7 @@ const ERRNO_ISDIR: i32 = 31;
70
72
  const ERRNO_LOOP: i32 = 32;
71
73
  const ERRNO_NOENT: i32 = 44;
72
74
  const ERRNO_NOMEM: i32 = 48;
75
+ const ERRNO_OVERFLOW: i32 = 61;
73
76
  const ERRNO_NOTDIR: i32 = 54;
74
77
  const ERRNO_NOTEMPTY: i32 = 55;
75
78
  const ERRNO_NOSPC: i32 = 51;
@@ -91,6 +94,7 @@ const PROBE_WAT: &str = r#"
91
94
  (import "wasi_snapshot_preview1" "path_filestat_get" (func $stat (param i32 i32 i32 i32 i32) (result i32)))
92
95
  (import "wasi_snapshot_preview1" "fd_filestat_get" (func $fstat (param i32 i32) (result i32)))
93
96
  (import "wasi_snapshot_preview1" "fd_read" (func $read (param i32 i32 i32 i32) (result i32)))
97
+ (import "wasi_snapshot_preview1" "fd_close" (func $close (param i32) (result i32)))
94
98
  (import "wasi_snapshot_preview1" "fd_write" (func $write (param i32 i32 i32 i32) (result i32)))
95
99
  (import "wasi_snapshot_preview1" "path_remove_directory" (func $rmdir (param i32 i32 i32) (result i32)))
96
100
  (import "wasi_snapshot_preview1" "path_rename" (func $rename (param i32 i32 i32 i32 i32 i32) (result i32)))
@@ -166,6 +170,14 @@ const PROBE_WAT: &str = r#"
166
170
  (if (local.get $errno) (then (return (local.get $errno))))
167
171
  (call $read (i32.load (i32.const 128)) (i32.const 64) (i32.const 1) (i32.const 132)))
168
172
 
173
+ ;; Open the path read-only and close it again.
174
+ (func (export "open_close") (param $path i32) (param $len i32) (result i32)
175
+ (local $errno i32)
176
+ (local.set $errno (call $open (i32.const 3) (i32.const 0) (local.get $path) (local.get $len)
177
+ (i32.const 0) (i64.const 2) (i64.const 0) (i32.const 0) (i32.const 128)))
178
+ (if (local.get $errno) (then (return (local.get $errno))))
179
+ (call $close (i32.load (i32.const 128))))
180
+
169
181
  ;; Open the path asking no right, with the given oflags, and read from it.
170
182
  (func (export "read_unasked") (param $path i32) (param $len i32) (param $oflags i32) (result i32)
171
183
  (local $errno i32)
@@ -477,7 +489,7 @@ fn build_how(set: impl FnOnce(&mut OpenHow)) -> OpenHow {
477
489
  fn grant(
478
490
  filesystem: Arc<dyn FileSystemType>,
479
491
  access: Access,
480
- policy: Option<Arc<dyn Policy>>,
492
+ policy: Option<Arc<dyn for<'a> Policy<MountRequest<'a>>>>,
481
493
  ) -> Grant {
482
494
  let mount = Mount::new(
483
495
  "/data",
@@ -519,7 +531,7 @@ impl Guest {
519
531
  }
520
532
 
521
533
  /// A guest on `profile`.
522
- fn for_posture(profile: Profile, grants: &[Grant]) -> Self {
534
+ fn for_profile(profile: Profile, grants: &[Grant]) -> Self {
523
535
  Self::build(None, None, profile, Vec::new(), grants)
524
536
  }
525
537
 
@@ -536,19 +548,12 @@ impl Guest {
536
548
  grants: &[Grant],
537
549
  ) -> Self {
538
550
  let engine = load_engine().expect("shared engine must be constructible");
539
- let config = Config {
540
- timeout: None,
541
- setup_timeout: None,
542
- memory_limit,
543
- stdout_limit: None,
544
- stderr_limit: None,
545
- open_file_limit,
546
- profile,
547
- security,
548
- };
549
- let wasi =
550
- Wasi::for_invocation(&config, Vec::new(), grants).expect("WASI context must build");
551
- let mut store = Store::new(engine, Invocation::new(None, wasi));
551
+ let mut config = Config::for_profile(profile);
552
+ config.limits.memory_limit = memory_limit;
553
+ config.limits.open_file_limit = open_file_limit;
554
+ config.security = security;
555
+ let wasi = Wasi::for_invocation(&config, grants).expect("WASI context must build");
556
+ let mut store = Store::new(engine, Invocation::new(wasi));
552
557
  store.set_epoch_deadline(NO_TIMEOUT_EPOCH_DELTA);
553
558
  let module = Module::new(engine, PROBE_WAT).expect("probe module must compile");
554
559
  let instance = imports::linker()
@@ -711,12 +716,8 @@ fn flags_of(how: &OpenHow) -> vfs::OpenFlags {
711
716
  fn contents(root: &Path, path: &str) -> Option<Vec<u8>> {
712
717
  let mut how = OpenHow::default();
713
718
  how.read = true;
714
- let Ok(mut file) = vfs::do_file_open(
715
- &prepare_creds_within(&[], None),
716
- root,
717
- path,
718
- &flags_of(&how),
719
- ) else {
719
+ let Ok(mut file) = vfs::do_file_open(&prepare_creds(&[], None), root, path, &flags_of(&how))
720
+ else {
720
721
  return None;
721
722
  };
722
723
  let mut buf = vec![0; 64];
@@ -730,29 +731,23 @@ fn overwrite(root: &Path, path: &str) {
730
731
  let mut how = OpenHow::default();
731
732
  (how.write, how.create) = (true, true);
732
733
  assert!(
733
- vfs::do_file_open(
734
- &prepare_creds_within(&[], None),
735
- root,
736
- path,
737
- &flags_of(&how)
738
- )
739
- .is_ok(),
734
+ vfs::do_file_open(&prepare_creds(&[], None), root, path, &flags_of(&how)).is_ok(),
740
735
  "the file must be made"
741
736
  );
742
737
  }
743
738
 
744
739
  struct Refuses(&'static str);
745
740
 
746
- impl Policy for Refuses {
747
- fn allows(&self, path: &str, _access: Access) -> bool {
748
- path != self.0
741
+ impl Policy<MountRequest<'_>> for Refuses {
742
+ fn allows(&self, request: &MountRequest<'_>) -> bool {
743
+ request.path != self.0
749
744
  }
750
745
  }
751
746
 
752
747
  struct AllowsAll;
753
748
 
754
- impl Policy for AllowsAll {
755
- fn allows(&self, _path: &str, _access: Access) -> bool {
749
+ impl Policy<MountRequest<'_>> for AllowsAll {
750
+ fn allows(&self, _request: &MountRequest<'_>) -> bool {
756
751
  true
757
752
  }
758
753
  }
@@ -784,7 +779,7 @@ impl StoresUpperCase {
784
779
  }
785
780
 
786
781
  impl FileSystemType for StoresUpperCase {
787
- fn fill_super(self: Arc<Self>, sb: &mut Filesystem) -> Result<(), FilesystemError> {
782
+ fn fill_super(self: Arc<Self>, sb: &mut Filesystem) -> Result<(), Errno> {
788
783
  sb.d_make_root(vfs::Inode::new(
789
784
  &vfs::Kstat::new(vfs::FileType::Dir, 0),
790
785
  self,
@@ -794,12 +789,11 @@ impl FileSystemType for StoresUpperCase {
794
789
  }
795
790
 
796
791
  impl InodeOperations for StoresUpperCase {
797
- fn getattr(&self, dentry: &Dentry) -> Result<Kstat, FilesystemError> {
798
- self.stat(&dentry.path_raw()[1..])
799
- .ok_or(FilesystemError::NotFound)
792
+ fn getattr(&self, dentry: &Dentry) -> Result<Kstat, Errno> {
793
+ self.stat(&dentry.path_raw()[1..]).ok_or(Errno::NotFound)
800
794
  }
801
795
 
802
- fn lookup(&self, dentry: &Dentry) -> Result<Lookup, FilesystemError> {
796
+ fn lookup(&self, dentry: &Dentry) -> Result<Lookup, Errno> {
803
797
  let Some(found) = self.stat(&dentry.path_raw()[1..]) else {
804
798
  return Ok(Lookup::Absent);
805
799
  };
@@ -817,7 +811,7 @@ impl InodeOperations for StoresUpperCase {
817
811
  // @behavior RT-120
818
812
  #[test]
819
813
  fn a_policy_judges_a_path_as_its_filesystem_stores_it() {
820
- let policy: Arc<dyn Policy> = Arc::new(Refuses("/data/FILE.TXT"));
814
+ let policy: Arc<dyn for<'a> Policy<MountRequest<'a>>> = Arc::new(Refuses("/data/FILE.TXT"));
821
815
  let mut guest = Guest::new(&[grant(
822
816
  Arc::new(StoresUpperCase(&["FILE.TXT"])),
823
817
  Access::Read,
@@ -837,7 +831,7 @@ fn a_policy_judges_a_path_as_its_filesystem_stores_it() {
837
831
  #[test]
838
832
  fn a_policy_judges_a_path_beneath_an_opened_directory_as_its_filesystem_stores_it() {
839
833
  const INNER: (i32, i32) = (960, 5);
840
- let policy: Arc<dyn Policy> = Arc::new(Refuses("/data/DIR/INNER"));
834
+ let policy: Arc<dyn for<'a> Policy<MountRequest<'a>>> = Arc::new(Refuses("/data/DIR/INNER"));
841
835
  let mut guest = Guest::new(&[grant(
842
836
  Arc::new(StoresUpperCase(&["DIR/INNER"])),
843
837
  Access::Read,
@@ -875,7 +869,7 @@ fn a_mount_appears_as_a_directory_at_its_path() {
875
869
  /// The inode number the guest reads for `file.txt` from a stat and from a
876
870
  /// listing, and for the Mount's root from `.`.
877
871
  fn inodes_seen(profile: Profile) -> (u64, u64, u64) {
878
- let mut guest = Guest::for_posture(
872
+ let mut guest = Guest::for_profile(
879
873
  profile,
880
874
  &[grant(file_and_directory(), Access::ReadWrite, None)],
881
875
  );
@@ -1026,6 +1020,24 @@ fn a_listing_it_cannot_hold_within_a_guests_memory_answers_enomem() {
1026
1020
  );
1027
1021
  }
1028
1022
 
1023
+ // @behavior RT-400
1024
+ #[test]
1025
+ fn an_open_the_memory_limit_cannot_hold_answers_enomem_whatever_the_path_names() {
1026
+ let mut starved =
1027
+ Guest::with_memory_limit(1, &[grant(file_and_directory(), Access::Read, None)]);
1028
+ let refused = [FILE, THROUGH_MISSING].map(|path| starved.call("open_close", path));
1029
+ let mut held =
1030
+ Guest::with_memory_limit(1 << 20, &[grant(file_and_directory(), Access::Read, None)]);
1031
+ let reopened = (0..10_000).all(|_| held.call("open_close", FILE) == 0);
1032
+ assert_eq!(
1033
+ (refused, reopened),
1034
+ ([ERRNO_NOMEM; 2], true),
1035
+ "path_open through preview1 under a memory_limit that holds no more files must answer \
1036
+ ENOMEM for a file and a missing path alike, as Linux's path_openat allocates the file \
1037
+ before the walk, and a closed file must give its room back for the next open"
1038
+ );
1039
+ }
1040
+
1029
1041
  /// A root whose listing hands `.` and `..`, then fails as a host read would.
1030
1042
  struct FailsPastTheDots;
1031
1043
 
@@ -1036,30 +1048,26 @@ impl FileOperations for FailsPastTheDotsDir {
1036
1048
  &mut self,
1037
1049
  dentry: &Dentry,
1038
1050
  ctx: &mut vfs::DirContext<'_>,
1039
- ) -> Result<(), FilesystemError> {
1051
+ ) -> Result<(), Errno> {
1040
1052
  if !vfs::dir_emit_dots(dentry, ctx) {
1041
1053
  return Ok(());
1042
1054
  }
1043
- Err(FilesystemError::Other("the host read failed".into()))
1055
+ Err(Errno::Other("the host read failed".into()))
1044
1056
  }
1045
1057
  }
1046
1058
 
1047
1059
  impl InodeOperations for FailsPastTheDots {
1048
- fn getattr(&self, _dentry: &Dentry) -> Result<Kstat, FilesystemError> {
1060
+ fn getattr(&self, _dentry: &Dentry) -> Result<Kstat, Errno> {
1049
1061
  Ok(Kstat::new(FileType::Dir, 0))
1050
1062
  }
1051
1063
 
1052
- fn open(
1053
- &self,
1054
- _dentry: &Dentry,
1055
- _how: &OpenHow,
1056
- ) -> Result<Box<dyn FileOperations>, FilesystemError> {
1064
+ fn open(&self, _dentry: &Dentry, _how: &OpenHow) -> Result<Box<dyn FileOperations>, Errno> {
1057
1065
  Ok(Box::new(FailsPastTheDotsDir))
1058
1066
  }
1059
1067
  }
1060
1068
 
1061
1069
  impl FileSystemType for FailsPastTheDots {
1062
- fn fill_super(self: Arc<Self>, sb: &mut Filesystem) -> Result<(), FilesystemError> {
1070
+ fn fill_super(self: Arc<Self>, sb: &mut Filesystem) -> Result<(), Errno> {
1063
1071
  sb.d_make_root(vfs::Inode::new(
1064
1072
  &vfs::Kstat::new(vfs::FileType::Dir, 0),
1065
1073
  self,
@@ -1172,7 +1180,10 @@ fn a_path_above_the_directory_it_is_opened_beneath_is_refused() {
1172
1180
  /// What `stat_inner` answers through `dir` opened, beneath a Mount with
1173
1181
  /// `policy`, before `change` runs on the host's root of the Tmpfs
1174
1182
  /// holding it.
1175
- fn stat_after(policy: Option<Arc<dyn Policy>>, change: impl FnOnce(&Path)) -> i32 {
1183
+ fn stat_after(
1184
+ policy: Option<Arc<dyn for<'a> Policy<MountRequest<'a>>>>,
1185
+ change: impl FnOnce(&Path),
1186
+ ) -> i32 {
1176
1187
  let tmpfs = file_and_directory();
1177
1188
  let mut guest = Guest::new(&[grant(tmpfs.clone(), Access::ReadWrite, policy)]);
1178
1189
  assert_eq!(
@@ -1188,8 +1199,8 @@ fn stat_after(policy: Option<Arc<dyn Policy>>, change: impl FnOnce(&Path)) -> i3
1188
1199
  /// an `inner` of its own, so only where the descriptor reaches decides
1189
1200
  /// whether the lookup finds one.
1190
1201
  fn move_and_replace(root: &Path) {
1191
- vfs::filename_renameat2(&prepare_creds_within(&[], None), root, "dir", root, "moved").unwrap();
1192
- vfs::filename_mkdirat(&prepare_creds_within(&[], None), root, "dir").unwrap();
1202
+ vfs::filename_renameat2(&prepare_creds(&[], None), root, "dir", root, "moved").unwrap();
1203
+ vfs::filename_mkdirat(&prepare_creds(&[], None), root, "dir").unwrap();
1193
1204
  overwrite(root, "dir/inner");
1194
1205
  }
1195
1206
 
@@ -1199,9 +1210,9 @@ fn move_and_replace(root: &Path) {
1199
1210
  #[test]
1200
1211
  fn a_directory_made_in_a_removed_directorys_place_is_not_reached_through_it() {
1201
1212
  let answer = stat_after(None, |root| {
1202
- vfs::filename_unlinkat(&prepare_creds_within(&[], None), root, "dir/inner").unwrap();
1203
- vfs::filename_rmdir(&prepare_creds_within(&[], None), root, "dir").unwrap();
1204
- vfs::filename_mkdirat(&prepare_creds_within(&[], None), root, "dir").unwrap();
1213
+ vfs::filename_unlinkat(&prepare_creds(&[], None), root, "dir/inner").unwrap();
1214
+ vfs::filename_rmdir(&prepare_creds(&[], None), root, "dir").unwrap();
1215
+ vfs::filename_mkdirat(&prepare_creds(&[], None), root, "dir").unwrap();
1205
1216
  overwrite(root, "dir/inner");
1206
1217
  });
1207
1218
  assert_eq!(
@@ -1304,22 +1315,16 @@ fn a_descriptor_moved_beneath_a_policy_still_lists_itself() {
1304
1315
  // @behavior RT-170
1305
1316
  #[test]
1306
1317
  fn a_directory_moved_beneath_another_mount_of_its_instance_is_reached_beneath_a_policy() {
1307
- let open_after_move = |policy: Arc<dyn Policy>| {
1318
+ let open_after_move = |policy: Arc<dyn for<'a> Policy<MountRequest<'a>>>| {
1308
1319
  let instance = Filesystem::new(file_and_directory()).expect("the instance must stand");
1309
1320
  let mount = Mount::new("/data", instance.clone(), Access::ReadWrite)
1310
1321
  .expect("/data is a guest path");
1311
1322
  let mut guest = Guest::new(&[Grant::Mount(mount.clone().with_policy(policy))]);
1312
1323
  assert_eq!(guest.call_bare("open_dir"), 0, "dir must open");
1313
1324
  let other = Path::root(mount.mnt());
1314
- vfs::filename_renameat2(
1315
- &prepare_creds_within(&[], None),
1316
- &other,
1317
- "dir",
1318
- &other,
1319
- "moved",
1320
- )
1321
- .expect("the directory must move");
1322
- vfs::filename_mkdirat(&prepare_creds_within(&[], None), &other, "dir")
1325
+ vfs::filename_renameat2(&prepare_creds(&[], None), &other, "dir", &other, "moved")
1326
+ .expect("the directory must move");
1327
+ vfs::filename_mkdirat(&prepare_creds(&[], None), &other, "dir")
1323
1328
  .expect("another directory must be made");
1324
1329
  guest.call_bare("open_inner")
1325
1330
  };
@@ -1353,11 +1358,7 @@ impl ReusesInodes {
1353
1358
  }
1354
1359
 
1355
1360
  impl Hook for ReusesInodes {
1356
- fn getattr(
1357
- &self,
1358
- inner: &dyn InodeOperations,
1359
- dentry: &Dentry,
1360
- ) -> Result<Kstat, FilesystemError> {
1361
+ fn getattr(&self, inner: &dyn InodeOperations, dentry: &Dentry) -> Result<Kstat, Errno> {
1361
1362
  let found = inner.getattr(dentry)?;
1362
1363
  Ok(match dentry.name().as_str() {
1363
1364
  "dir" => self.dir_kstat(found),
@@ -1365,11 +1366,7 @@ impl Hook for ReusesInodes {
1365
1366
  })
1366
1367
  }
1367
1368
 
1368
- fn lookup(
1369
- &self,
1370
- inner: &dyn InodeOperations,
1371
- dentry: &Dentry,
1372
- ) -> Result<Lookup, FilesystemError> {
1369
+ fn lookup(&self, inner: &dyn InodeOperations, dentry: &Dentry) -> Result<Lookup, Errno> {
1373
1370
  Ok(match inner.lookup(dentry)? {
1374
1371
  Lookup::Found(inode) if dentry.name() == "dir" => {
1375
1372
  self.found.lock().unwrap().push(Arc::downgrade(inode.ops()));
@@ -1381,16 +1378,12 @@ impl Hook for ReusesInodes {
1381
1378
  }
1382
1379
 
1383
1380
  /// Its root answers as the Filesystem's and sets up nothing of it.
1384
- fn fill_super(
1385
- &self,
1386
- fs: Arc<dyn FileSystemType>,
1387
- sb: &mut Filesystem,
1388
- ) -> Result<(), FilesystemError> {
1381
+ fn fill_super(&self, fs: Arc<dyn FileSystemType>, sb: &mut Filesystem) -> Result<(), Errno> {
1389
1382
  let beneath = Filesystem::new(fs)?;
1390
1383
  let root = beneath
1391
1384
  .root()
1392
1385
  .and_then(|root| root.inode())
1393
- .ok_or(FilesystemError::NotFound)?;
1386
+ .ok_or(Errno::NotFound)?;
1394
1387
  sb.d_make_root(vfs::Inode::new(
1395
1388
  &vfs::Kstat::new(vfs::FileType::Dir, 0),
1396
1389
  root.ops().clone(),
@@ -1400,7 +1393,7 @@ impl Hook for ReusesInodes {
1400
1393
 
1401
1394
  /// The call removing it holds what it looked up, so `dir` is open
1402
1395
  /// beyond that only where a descriptor holds it too.
1403
- fn rmdir(&self, inner: &dyn InodeOperations, dentry: &Dentry) -> Result<(), FilesystemError> {
1396
+ fn rmdir(&self, inner: &dyn InodeOperations, dentry: &Dentry) -> Result<(), Errno> {
1404
1397
  let removed = inner.rmdir(dentry);
1405
1398
  let held = self
1406
1399
  .found
@@ -1436,9 +1429,9 @@ fn a_directory_descriptor_holds_its_directory_while_open() {
1436
1429
  "dir must open as a directory"
1437
1430
  );
1438
1431
  let outside = host(&reuses);
1439
- vfs::filename_unlinkat(&prepare_creds_within(&[], None), &outside, "dir/inner").unwrap();
1440
- vfs::filename_rmdir(&prepare_creds_within(&[], None), &outside, "dir").unwrap();
1441
- vfs::filename_mkdirat(&prepare_creds_within(&[], None), &outside, "dir").unwrap();
1432
+ vfs::filename_unlinkat(&prepare_creds(&[], None), &outside, "dir/inner").unwrap();
1433
+ vfs::filename_rmdir(&prepare_creds(&[], None), &outside, "dir").unwrap();
1434
+ vfs::filename_mkdirat(&prepare_creds(&[], None), &outside, "dir").unwrap();
1442
1435
  overwrite(&host(&tmpfs), "dir/inner");
1443
1436
  assert_eq!(
1444
1437
  guest.call_bare("stat_inner"),
@@ -1454,11 +1447,7 @@ fn a_directory_descriptor_holds_its_directory_while_open() {
1454
1447
  struct NamesNoIdentity;
1455
1448
 
1456
1449
  impl Hook for NamesNoIdentity {
1457
- fn lookup(
1458
- &self,
1459
- inner: &dyn InodeOperations,
1460
- dentry: &Dentry,
1461
- ) -> Result<Lookup, FilesystemError> {
1450
+ fn lookup(&self, inner: &dyn InodeOperations, dentry: &Dentry) -> Result<Lookup, Errno> {
1462
1451
  Ok(match inner.lookup(dentry)? {
1463
1452
  Lookup::Found(inode) => {
1464
1453
  let found = inode.ops().getattr(dentry)?;
@@ -1577,10 +1566,8 @@ fn a_directory_two_layers_hold_is_reached_through_its_descriptor() {
1577
1566
  #[test]
1578
1567
  fn a_directory_moved_back_to_its_path_is_reached_through_its_descriptor_again() {
1579
1568
  let answer = stat_after(None, |root| {
1580
- vfs::filename_renameat2(&prepare_creds_within(&[], None), root, "dir", root, "moved")
1581
- .unwrap();
1582
- vfs::filename_renameat2(&prepare_creds_within(&[], None), root, "moved", root, "dir")
1583
- .unwrap();
1569
+ vfs::filename_renameat2(&prepare_creds(&[], None), root, "dir", root, "moved").unwrap();
1570
+ vfs::filename_renameat2(&prepare_creds(&[], None), root, "moved", root, "dir").unwrap();
1584
1571
  });
1585
1572
  assert_eq!(
1586
1573
  answer, 0,
@@ -1593,7 +1580,7 @@ fn a_directory_moved_back_to_its_path_is_reached_through_its_descriptor_again()
1593
1580
  #[test]
1594
1581
  fn a_policy_refusing_an_open_answers_access_denied() {
1595
1582
  let tmpfs: Tmpfs = [("file.txt", "granted")].into_iter().collect();
1596
- let policy: Arc<dyn Policy> = Arc::new(Refuses("/data/file.txt"));
1583
+ let policy: Arc<dyn for<'a> Policy<MountRequest<'a>>> = Arc::new(Refuses("/data/file.txt"));
1597
1584
  let mut guest = Guest::new(&[grant(Arc::new(tmpfs), Access::Read, Some(policy))]);
1598
1585
  assert_eq!(
1599
1586
  guest.call("read_file", FILE),
@@ -1606,7 +1593,7 @@ fn a_policy_refusing_an_open_answers_access_denied() {
1606
1593
  #[test]
1607
1594
  fn a_policy_cannot_widen_a_mounts_access() {
1608
1595
  let tmpfs = Arc::new(Tmpfs::new());
1609
- let policy: Arc<dyn Policy> = Arc::new(AllowsAll);
1596
+ let policy: Arc<dyn for<'a> Policy<MountRequest<'a>>> = Arc::new(AllowsAll);
1610
1597
  let mut guest = Guest::new(&[grant(tmpfs.clone(), Access::Read, Some(policy))]);
1611
1598
  assert_eq!(
1612
1599
  (
@@ -1663,17 +1650,17 @@ impl ChangeCounter {
1663
1650
  }
1664
1651
 
1665
1652
  impl Hook for ChangeCounter {
1666
- fn mkdir(&self, inner: &dyn InodeOperations, dentry: &Dentry) -> Result<(), FilesystemError> {
1653
+ fn mkdir(&self, inner: &dyn InodeOperations, dentry: &Dentry) -> Result<(), Errno> {
1667
1654
  self.change();
1668
1655
  inner.mkdir(dentry)
1669
1656
  }
1670
1657
 
1671
- fn rmdir(&self, inner: &dyn InodeOperations, dentry: &Dentry) -> Result<(), FilesystemError> {
1658
+ fn rmdir(&self, inner: &dyn InodeOperations, dentry: &Dentry) -> Result<(), Errno> {
1672
1659
  self.change();
1673
1660
  inner.rmdir(dentry)
1674
1661
  }
1675
1662
 
1676
- fn unlink(&self, inner: &dyn InodeOperations, dentry: &Dentry) -> Result<(), FilesystemError> {
1663
+ fn unlink(&self, inner: &dyn InodeOperations, dentry: &Dentry) -> Result<(), Errno> {
1677
1664
  self.change();
1678
1665
  inner.unlink(dentry)
1679
1666
  }
@@ -1681,13 +1668,13 @@ impl Hook for ChangeCounter {
1681
1668
  fn rename(
1682
1669
  &self,
1683
1670
  inner: &dyn InodeOperations,
1684
- from: &Dentry,
1685
- to_dir: &dyn InodeOperations,
1686
- to: &Dentry,
1687
- flag: Option<RenameFlag>,
1688
- ) -> Result<(), FilesystemError> {
1671
+ old: &Dentry,
1672
+ new_dir: &dyn InodeOperations,
1673
+ new: &Dentry,
1674
+ flags: Option<RenameFlag>,
1675
+ ) -> Result<(), Errno> {
1689
1676
  self.change();
1690
- inner.rename(from, to_dir, to, flag)
1677
+ inner.rename(old, new_dir, new, flags)
1691
1678
  }
1692
1679
  }
1693
1680
 
@@ -1697,13 +1684,13 @@ impl Hook for ChangeCounter {
1697
1684
  #[test]
1698
1685
  fn a_directory_beneath_a_mount_with_a_policy_does_not_move() {
1699
1686
  let tmpfs = Arc::new([("dir/secret", "x")].into_iter().collect::<Tmpfs>());
1700
- let policy: Arc<dyn Policy> = Arc::new(AllowsAll);
1687
+ let policy: Arc<dyn for<'a> Policy<MountRequest<'a>>> = Arc::new(AllowsAll);
1701
1688
  let mut guest = Guest::new(&[grant(tmpfs.clone(), Access::ReadWrite, Some(policy))]);
1702
1689
  assert_eq!(
1703
1690
  (
1704
1691
  guest.call_pair("rename_paths", DIR, MOVED),
1705
1692
  vfs::vfs_fstatat(
1706
- &prepare_creds_within(&[], None),
1693
+ &prepare_creds(&[], None),
1707
1694
  &host(&tmpfs),
1708
1695
  "dir/secret",
1709
1696
  false
@@ -1727,21 +1714,21 @@ struct AppendedMeanwhileFile {
1727
1714
  }
1728
1715
 
1729
1716
  impl AppendedMeanwhileFile {
1730
- fn other_appends(&self) -> Result<(), FilesystemError> {
1717
+ fn other_appends(&self) -> Result<(), Errno> {
1731
1718
  self.other
1732
1719
  .lock()
1733
1720
  .expect("the other writer's lock must not be poisoned")
1734
- .write_iter(&mut Kiocb::at(0).with_append(), b"bbb")
1721
+ .write_iter(&mut Kiocb::new(0).with_append(), b"bbb")
1735
1722
  .map(drop)
1736
1723
  }
1737
1724
  }
1738
1725
 
1739
1726
  impl FileOperations for AppendedMeanwhileFile {
1740
- fn read_iter(&mut self, iocb: &mut Kiocb, buf: &mut [u8]) -> Result<usize, FilesystemError> {
1727
+ fn read_iter(&mut self, iocb: &mut Kiocb, buf: &mut [u8]) -> Result<usize, Errno> {
1741
1728
  self.file.read_iter(iocb, buf)
1742
1729
  }
1743
1730
 
1744
- fn write_iter(&mut self, iocb: &mut Kiocb, buf: &[u8]) -> Result<usize, FilesystemError> {
1731
+ fn write_iter(&mut self, iocb: &mut Kiocb, buf: &[u8]) -> Result<usize, Errno> {
1745
1732
  if iocb.append {
1746
1733
  self.other_appends()?;
1747
1734
  }
@@ -1755,7 +1742,7 @@ impl Hook for AppendedMeanwhile {
1755
1742
  inner: &dyn InodeOperations,
1756
1743
  dentry: &Dentry,
1757
1744
  how: &OpenHow,
1758
- ) -> Result<Box<dyn FileOperations>, FilesystemError> {
1745
+ ) -> Result<Box<dyn FileOperations>, Errno> {
1759
1746
  let writes = build_how(|how| how.write = true);
1760
1747
  let file = inner.open(dentry, how)?;
1761
1748
  let other = inner.open(dentry, &writes)?;
@@ -1808,7 +1795,7 @@ fn mount_link_under(
1808
1795
  name: &str,
1809
1796
  make_target: fn(&std::path::Path),
1810
1797
  access: Access,
1811
- policy: Option<Arc<dyn Policy>>,
1798
+ policy: Option<Arc<dyn for<'a> Policy<MountRequest<'a>>>>,
1812
1799
  ) -> (std::path::PathBuf, Guest) {
1813
1800
  let host = std::env::temp_dir().join(format!("kobako-granted-{name}-{}", std::process::id()));
1814
1801
  let _ = std::fs::remove_dir_all(&host);
@@ -1947,15 +1934,15 @@ fn a_link_reports_no_size_however_its_filesystem_sizes_it() {
1947
1934
  );
1948
1935
  }
1949
1936
 
1950
- /// One Tmpfs read-write, as an invocation on each posture is handed it.
1937
+ /// One Tmpfs read-write, as an invocation on each profile is handed it.
1951
1938
  fn tmpfs_grant(tmpfs: &Arc<Tmpfs>) -> [Grant; 1] {
1952
1939
  [grant(tmpfs.clone(), Access::ReadWrite, None)]
1953
1940
  }
1954
1941
 
1955
1942
  // @behavior RT-156
1956
1943
  #[test]
1957
- fn the_weaker_posture_sees_the_times_a_filesystem_keeps() {
1958
- let mut guest = Guest::for_posture(Profile::Permissive, &tmpfs_grant(&Arc::new(Tmpfs::new())));
1944
+ fn the_permissive_profile_sees_the_times_a_filesystem_keeps() {
1945
+ let mut guest = Guest::for_profile(Profile::Permissive, &tmpfs_grant(&Arc::new(Tmpfs::new())));
1959
1946
  let before = SystemTime::now()
1960
1947
  .duration_since(UNIX_EPOCH)
1961
1948
  .expect("the host clock stands past the epoch")
@@ -1963,17 +1950,17 @@ fn the_weaker_posture_sees_the_times_a_filesystem_keeps() {
1963
1950
  assert_eq!(guest.call("write_file", FILE), 0, "the write must succeed");
1964
1951
  assert!(
1965
1952
  guest.times_of_path(FILE)[1] >= before,
1966
- "path_filestat_get of a file written beneath a Mount through preview1 on the weaker \
1967
- posture must report a modification time no earlier than the write"
1953
+ "path_filestat_get of a file written beneath a Mount through preview1 on the \
1954
+ permissive profile must report a modification time no earlier than the write"
1968
1955
  );
1969
1956
  }
1970
1957
 
1971
- // A Tmpfs records the host's real time, so only the posture's view turns it
1958
+ // A Tmpfs records the host's real time, so only the profile's view turns it
1972
1959
  // into the epoch.
1973
1960
  // @behavior RT-157
1974
1961
  #[test]
1975
- fn the_strongest_posture_sees_every_time_at_the_unix_epoch() {
1976
- let mut guest = Guest::for_posture(Profile::Hermetic, &tmpfs_grant(&Arc::new(Tmpfs::new())));
1962
+ fn the_hermetic_profile_sees_every_time_at_the_unix_epoch() {
1963
+ let mut guest = Guest::for_profile(Profile::Hermetic, &tmpfs_grant(&Arc::new(Tmpfs::new())));
1977
1964
  assert_eq!(guest.call("write_file", FILE), 0, "the write must succeed");
1978
1965
  let path = guest.times_of_path(FILE);
1979
1966
  assert_eq!(guest.call("stat_opened", FILE), 0, "the stat must succeed");
@@ -1981,22 +1968,78 @@ fn the_strongest_posture_sees_every_time_at_the_unix_epoch() {
1981
1968
  (path, guest.stat_times()),
1982
1969
  ([0; 3], [0; 3]),
1983
1970
  "path_filestat_get and fd_filestat_get of a written file through preview1 on the \
1984
- strongest posture must report each time as the Unix epoch"
1971
+ hermetic profile must report each time as the Unix epoch"
1985
1972
  );
1986
1973
  }
1987
1974
 
1988
1975
  // @behavior RT-158
1989
1976
  #[test]
1990
- fn a_time_another_posture_wrote_reaches_the_strongest_posture_as_the_epoch() {
1977
+ fn a_time_another_profile_wrote_reaches_the_hermetic_profile_as_the_epoch() {
1991
1978
  let tmpfs = Arc::new(Tmpfs::new());
1992
- let mut writer = Guest::for_posture(Profile::Permissive, &tmpfs_grant(&tmpfs));
1979
+ let mut writer = Guest::for_profile(Profile::Permissive, &tmpfs_grant(&tmpfs));
1993
1980
  assert_eq!(writer.call("write_file", FILE), 0, "the write must succeed");
1994
- let mut reader = Guest::for_posture(Profile::Hermetic, &tmpfs_grant(&tmpfs));
1981
+ let mut reader = Guest::for_profile(Profile::Hermetic, &tmpfs_grant(&tmpfs));
1995
1982
  assert_eq!(
1996
1983
  reader.times_of_path(FILE),
1997
1984
  [0; 3],
1998
- "path_filestat_get through preview1 on the strongest posture, of a file the weaker \
1999
- posture wrote into the same Tmpfs, must report each time as the Unix epoch"
1985
+ "path_filestat_get through preview1 on the hermetic profile, of a file the permissive \
1986
+ profile wrote into the same Tmpfs, must report each time as the Unix epoch"
1987
+ );
1988
+ }
1989
+
1990
+ /// A Filesystem holding `file.txt`, modified in the year 2600, more
1991
+ /// nanoseconds after the epoch than a `u64` counts. A guest sets a time in
1992
+ /// those nanoseconds, so only a Filesystem of its own can report one.
1993
+ struct ModifiedIn2600;
1994
+
1995
+ impl ModifiedIn2600 {
1996
+ fn stat(path: &str) -> Option<Kstat> {
1997
+ let year_2600 = std::time::UNIX_EPOCH + std::time::Duration::from_secs(19_880_879_760);
1998
+ match path {
1999
+ "" => Some(Kstat::new(FileType::Dir, 0)),
2000
+ "file.txt" => {
2001
+ Some(Kstat::new(FileType::RegFile, 0).with_times(None, Some(year_2600), None))
2002
+ }
2003
+ _ => None,
2004
+ }
2005
+ }
2006
+ }
2007
+
2008
+ impl FileSystemType for ModifiedIn2600 {
2009
+ fn fill_super(self: Arc<Self>, sb: &mut Filesystem) -> Result<(), Errno> {
2010
+ sb.d_make_root(vfs::Inode::new(
2011
+ &vfs::Kstat::new(vfs::FileType::Dir, 0),
2012
+ self,
2013
+ ));
2014
+ Ok(())
2015
+ }
2016
+ }
2017
+
2018
+ impl InodeOperations for ModifiedIn2600 {
2019
+ fn getattr(&self, dentry: &Dentry) -> Result<Kstat, Errno> {
2020
+ Self::stat(&dentry.path_raw()[1..]).ok_or(Errno::NotFound)
2021
+ }
2022
+
2023
+ fn lookup(&self, dentry: &Dentry) -> Result<Lookup, Errno> {
2024
+ Ok(match Self::stat(&dentry.path_raw()[1..]) {
2025
+ Some(found) => Lookup::Found(Inode::new(&found, Arc::new(Self))),
2026
+ None => Lookup::Absent,
2027
+ })
2028
+ }
2029
+ }
2030
+
2031
+ // @behavior RT-404
2032
+ #[test]
2033
+ fn a_file_time_past_what_a_timestamp_holds_answers_overflow() {
2034
+ let mut guest = Guest::for_profile(
2035
+ Profile::Permissive,
2036
+ &[grant(Arc::new(ModifiedIn2600), Access::Read, None)],
2037
+ );
2038
+ assert_eq!(
2039
+ guest.stat_flagged(FILE, 0),
2040
+ ERRNO_OVERFLOW,
2041
+ "path_filestat_get through preview1 of a file its Filesystem reports modified in the \
2042
+ year 2600 must answer OVERFLOW, as wasmtime-wasi does"
2000
2043
  );
2001
2044
  }
2002
2045
 
@@ -2025,7 +2068,10 @@ fn a_stat_of_a_link_named_with_a_trailing_slash_reports_its_directory() {
2025
2068
  /// `policy`, and whether the link stays; `name` keeps its host directory
2026
2069
  /// its own.
2027
2070
  #[cfg(unix)]
2028
- fn change_link_named_as_directory(name: &str, policy: Option<Arc<dyn Policy>>) -> ([i32; 2], bool) {
2071
+ fn change_link_named_as_directory(
2072
+ name: &str,
2073
+ policy: Option<Arc<dyn for<'a> Policy<MountRequest<'a>>>>,
2074
+ ) -> ([i32; 2], bool) {
2029
2075
  let (host, mut guest) = mount_link_under(name, directory_with_key, Access::ReadWrite, policy);
2030
2076
  let answers = [
2031
2077
  guest.call("unlink_path", FILE_AS_DIRECTORY),
@@ -2103,7 +2149,7 @@ fn a_name_no_filesystem_makes_is_answered_by_what_stands() {
2103
2149
  )
2104
2150
  .expect("/data is a guest path");
2105
2151
  let root = vfs::Path::root(mount.mnt());
2106
- let cred = prepare_creds_within(&[], None);
2152
+ let cred = prepare_creds(&[], None);
2107
2153
  let link = |old, new| vfs::filename_linkat(&cred, &root, old, &root, new, false);
2108
2154
  let symlink = |new| vfs::filename_symlinkat(&cred, "target", &root, new);
2109
2155
  let refused = Err;
@@ -2116,11 +2162,11 @@ fn a_name_no_filesystem_makes_is_answered_by_what_stands() {
2116
2162
  symlink("new"),
2117
2163
  ),
2118
2164
  (
2119
- refused(FilesystemError::NotFound),
2120
- refused(FilesystemError::AlreadyExists),
2121
- refused(FilesystemError::NotPermitted),
2122
- refused(FilesystemError::AlreadyExists),
2123
- refused(FilesystemError::NotPermitted),
2165
+ refused(Errno::NotFound),
2166
+ refused(Errno::AlreadyExists),
2167
+ refused(Errno::NotPermitted),
2168
+ refused(Errno::AlreadyExists),
2169
+ refused(Errno::NotPermitted),
2124
2170
  ),
2125
2171
  "vfs::filename_linkat and filename_symlinkat over a Filesystem making no links must \
2126
2172
  answer ENOENT for a missing source, EEXIST for a name that stands, and otherwise EPERM"
@@ -2144,13 +2190,8 @@ fn an_allocation_grows_a_file_to_where_its_room_ends_and_shortens_none() {
2144
2190
  let tmpfs = tmpfs_with("file.txt", seed);
2145
2191
  let answer = Guest::new(&[grant(tmpfs.clone(), Access::ReadWrite, None)])
2146
2192
  .call("allocate_file", FILE);
2147
- let len = vfs::vfs_fstatat(
2148
- &prepare_creds_within(&[], None),
2149
- &host(&tmpfs),
2150
- "file.txt",
2151
- false,
2152
- )
2153
- .map(|stat| stat.size);
2193
+ let len = vfs::vfs_fstatat(&prepare_creds(&[], None), &host(&tmpfs), "file.txt", false)
2194
+ .map(|stat| stat.size);
2154
2195
  let held = contents(&host(&tmpfs), "file.txt").map(|head| head[7]);
2155
2196
  (answer, len.ok().map(|len| len as usize), held)
2156
2197
  };
@@ -2241,7 +2282,8 @@ fn directory_with_key(target: &std::path::Path) {
2241
2282
  #[cfg(unix)]
2242
2283
  #[test]
2243
2284
  fn a_path_through_a_link_beneath_a_mount_with_a_policy_is_judged_where_it_leads() {
2244
- let refuses_key: Arc<dyn Policy> = Arc::new(Refuses("/data/target/key"));
2285
+ let refuses_key: Arc<dyn for<'a> Policy<MountRequest<'a>>> =
2286
+ Arc::new(Refuses("/data/target/key"));
2245
2287
  let (host, mut guest) = mount_link_under(
2246
2288
  "policy-link-refused",
2247
2289
  directory_with_key,
@@ -2254,7 +2296,7 @@ fn a_path_through_a_link_beneath_a_mount_with_a_policy_is_judged_where_it_leads(
2254
2296
  ];
2255
2297
  let kept = host.join("target/key").exists();
2256
2298
  let _ = std::fs::remove_dir_all(&host);
2257
- let allows: Arc<dyn Policy> = Arc::new(AllowsAll);
2299
+ let allows: Arc<dyn for<'a> Policy<MountRequest<'a>>> = Arc::new(AllowsAll);
2258
2300
  let (host, mut guest) = mount_link_under(
2259
2301
  "policy-link-allowed",
2260
2302
  directory_with_key,
@@ -2302,7 +2344,7 @@ fn a_link_out_of_a_directory_or_into_a_loop_answers_as_without_a_policy() {
2302
2344
  std::os::unix::fs::symlink(target, host.join("file.txt"))
2303
2345
  .expect("the link must be made");
2304
2346
  let directory = Bind::new(&host).expect("the host directory must open");
2305
- let policy: Arc<dyn Policy> = Arc::new(AllowsAll);
2347
+ let policy: Arc<dyn for<'a> Policy<MountRequest<'a>>> = Arc::new(AllowsAll);
2306
2348
  let mut guest =
2307
2349
  Guest::new(&[grant(Arc::new(directory), Access::ReadWrite, Some(policy))]);
2308
2350
  let answers = [
@@ -2339,7 +2381,7 @@ fn a_link_out_of_a_directory_or_into_a_loop_answers_as_without_a_policy() {
2339
2381
  fn a_lookup_that_fails_fails_the_call_beneath_a_policy() {
2340
2382
  let tmpfs: Tmpfs = [("dir/file.txt", "granted")].into_iter().collect();
2341
2383
  let failing = Wrap::new(Arc::new(tmpfs), Arc::new(FailsLookingUpDir));
2342
- let policy: Arc<dyn Policy> = Arc::new(AllowsAll);
2384
+ let policy: Arc<dyn for<'a> Policy<MountRequest<'a>>> = Arc::new(AllowsAll);
2343
2385
  let mut guest = Guest::new(&[grant(failing, Access::Read, Some(policy))]);
2344
2386
  assert_eq!(
2345
2387
  guest.call("read_file", DIR_FILE),
@@ -2354,13 +2396,9 @@ fn a_lookup_that_fails_fails_the_call_beneath_a_policy() {
2354
2396
  struct FailsLookingUpDir;
2355
2397
 
2356
2398
  impl Hook for FailsLookingUpDir {
2357
- fn lookup(
2358
- &self,
2359
- inner: &dyn InodeOperations,
2360
- dentry: &Dentry,
2361
- ) -> Result<Lookup, FilesystemError> {
2399
+ fn lookup(&self, inner: &dyn InodeOperations, dentry: &Dentry) -> Result<Lookup, Errno> {
2362
2400
  match dentry.name().as_str() {
2363
- "dir" => Err(FilesystemError::Other("unreadable".into())),
2401
+ "dir" => Err(Errno::Other("unreadable".into())),
2364
2402
  _ => inner.lookup(dentry),
2365
2403
  }
2366
2404
  }
@@ -2404,8 +2442,8 @@ fn file_and_directory() -> Arc<Tmpfs> {
2404
2442
  struct RefusesMkdir;
2405
2443
 
2406
2444
  impl SecurityOperations for RefusesMkdir {
2407
- fn path_mkdir(&self, _path: SecurityPath<'_>) -> Result<(), FilesystemError> {
2408
- Err(FilesystemError::PermissionDenied)
2445
+ fn path_mkdir(&self, _path: SecurityPath<'_>) -> Result<(), Errno> {
2446
+ Err(Errno::PermissionDenied)
2409
2447
  }
2410
2448
  }
2411
2449
 
@@ -2422,13 +2460,7 @@ fn a_security_module_the_driver_was_built_with_judges_the_guest() {
2422
2460
  assert_eq!(
2423
2461
  (
2424
2462
  guest.call("make_dir", NEW_AS_DIRECTORY),
2425
- vfs::vfs_fstatat(
2426
- &prepare_creds_within(&[], None),
2427
- &host(&tmpfs),
2428
- "new.txt",
2429
- false
2430
- )
2431
- .is_err()
2463
+ vfs::vfs_fstatat(&prepare_creds(&[], None), &host(&tmpfs), "new.txt", false).is_err()
2432
2464
  ),
2433
2465
  (ERRNO_ACCES, true),
2434
2466
  "path_create_directory beneath a Mount through preview1, the Driver built with a \
@@ -2451,13 +2483,7 @@ fn a_path_ending_in_a_dot_makes_nothing_where_no_directory_stands() {
2451
2483
  assert_eq!(
2452
2484
  (
2453
2485
  answers,
2454
- vfs::vfs_fstatat(
2455
- &prepare_creds_within(&[], None),
2456
- &host(&tmpfs),
2457
- "missing",
2458
- false
2459
- )
2460
- .is_err()
2486
+ vfs::vfs_fstatat(&prepare_creds(&[], None), &host(&tmpfs), "missing", false).is_err()
2461
2487
  ),
2462
2488
  ([ERRNO_NOENT, ERRNO_NOENT], true),
2463
2489
  "path_create_directory and path_open with O_CREAT of missing/. beneath a Mount through \
@@ -2483,13 +2509,7 @@ fn a_path_ending_in_a_dot_is_neither_removed_nor_moved() {
2483
2509
  assert_eq!(
2484
2510
  (
2485
2511
  answers,
2486
- vfs::vfs_fstatat(
2487
- &prepare_creds_within(&[], None),
2488
- &host(&tmpfs),
2489
- "dir/inner",
2490
- false
2491
- )
2492
- .is_ok()
2512
+ vfs::vfs_fstatat(&prepare_creds(&[], None), &host(&tmpfs), "dir/inner", false).is_ok()
2493
2513
  ),
2494
2514
  (
2495
2515
  [
@@ -2638,7 +2658,7 @@ fn bind_root(host: &std::path::Path) -> Path {
2638
2658
  let directory = Bind::new(host).expect("the host directory must open");
2639
2659
  let mount = Mount::new(
2640
2660
  "/data",
2641
- Filesystem::new(Arc::new(directory)).expect("the instance must stand"),
2661
+ Filesystem::new(directory).expect("the instance must stand"),
2642
2662
  Access::ReadWrite,
2643
2663
  )
2644
2664
  .expect("/data is a guest path");
@@ -2658,14 +2678,14 @@ fn an_exclusive_create_follows_no_link_at_the_end() {
2658
2678
  how.exclusive = true;
2659
2679
  how.follow = true;
2660
2680
  let answer = vfs::do_file_open(
2661
- &prepare_creds_within(&[], None),
2681
+ &prepare_creds(&[], None),
2662
2682
  &bind_root(&host.0),
2663
2683
  "gone",
2664
2684
  &flags_of(&how),
2665
2685
  );
2666
2686
  assert_eq!(
2667
2687
  (answer.err(), host.0.join("nowhere").exists()),
2668
- (Some(FilesystemError::AlreadyExists), false),
2688
+ (Some(Errno::AlreadyExists), false),
2669
2689
  "vfs::do_file_open with create and exclusive of a link to nothing, asking to follow it, \
2670
2690
  must answer EEXIST, as Linux's O_EXCL does, and make nothing"
2671
2691
  );
@@ -2679,13 +2699,8 @@ fn an_exclusive_create_follows_no_link_at_the_end() {
2679
2699
  fn a_trailing_slash_on_a_link_to_a_directory_reads_no_link() {
2680
2700
  let host = LinkedHost::new("readlink-slash");
2681
2701
  assert_eq!(
2682
- vfs::do_readlinkat(
2683
- &prepare_creds_within(&[], None),
2684
- &bind_root(&host.0),
2685
- "dir/"
2686
- )
2687
- .err(),
2688
- Some(FilesystemError::InvalidInput),
2702
+ vfs::do_readlinkat(&prepare_creds(&[], None), &bind_root(&host.0), "dir/").err(),
2703
+ Some(Errno::InvalidInput),
2689
2704
  "vfs::do_readlinkat of dir/, dir a host link to a directory beneath a Bind Mount, must \
2690
2705
  answer EINVAL, as Linux's does"
2691
2706
  );
@@ -2803,15 +2818,18 @@ fn sizing_a_file_opened_only_to_read_answers_by_its_mount_then_as_linux_does() {
2803
2818
  #[derive(Default)]
2804
2819
  struct RecordsAsks(std::sync::Mutex<Vec<(String, Access)>>);
2805
2820
 
2806
- impl Policy for RecordsAsks {
2807
- fn allows(&self, path: &str, access: Access) -> bool {
2808
- self.0.lock().unwrap().push((path.to_owned(), access));
2821
+ impl Policy<MountRequest<'_>> for RecordsAsks {
2822
+ fn allows(&self, request: &MountRequest<'_>) -> bool {
2823
+ self.0
2824
+ .lock()
2825
+ .unwrap()
2826
+ .push((request.path.to_owned(), request.access));
2809
2827
  true
2810
2828
  }
2811
2829
  }
2812
2830
 
2813
- // The Mount is made read-only, as a Ruby mount with a block is by default,
2814
- // so only a Mount allowing writes lets either through.
2831
+ // The Mount is made read-only, so only a Mount allowing writes lets either
2832
+ // through.
2815
2833
  // Each Policy is asked only by the open before the call, so a wait or a size
2816
2834
  // asking it as well adds an ask the literal lists below do not hold.
2817
2835
  // @behavior RT-139
@@ -2822,7 +2840,7 @@ fn a_mount_whose_policy_decides_may_be_written() {
2822
2840
  let errno = Guest::new(&[grant(
2823
2841
  file_and_directory(),
2824
2842
  Access::ReadWrite,
2825
- Some(policy.clone() as Arc<dyn Policy>),
2843
+ Some(policy.clone() as Arc<dyn for<'a> Policy<MountRequest<'a>>>),
2826
2844
  )])
2827
2845
  .call_at(name, rights);
2828
2846
  let asked = policy.0.lock().unwrap().clone();
@@ -2855,7 +2873,7 @@ fn an_open_that_may_create_asks_to_make_the_file_before_it_finds_what_stands() {
2855
2873
  let errno = Guest::new(&[grant(
2856
2874
  file_and_directory(),
2857
2875
  Access::ReadWrite,
2858
- Some(policy.clone() as Arc<dyn Policy>),
2876
+ Some(policy.clone() as Arc<dyn for<'a> Policy<MountRequest<'a>>>),
2859
2877
  )])
2860
2878
  .call_flagged(path, OFLAGS_CREAT, 0);
2861
2879
  let asked = policy.0.lock().unwrap().clone();
@@ -2884,10 +2902,10 @@ fn an_open_that_may_create_asks_to_make_the_file_before_it_finds_what_stands() {
2884
2902
  #[derive(Default)]
2885
2903
  struct RefusesTheRoot(std::sync::Mutex<Vec<String>>);
2886
2904
 
2887
- impl Policy for RefusesTheRoot {
2888
- fn allows(&self, path: &str, _access: Access) -> bool {
2889
- self.0.lock().unwrap().push(path.to_owned());
2890
- path != "/data"
2905
+ impl Policy<MountRequest<'_>> for RefusesTheRoot {
2906
+ fn allows(&self, request: &MountRequest<'_>) -> bool {
2907
+ self.0.lock().unwrap().push(request.path.to_owned());
2908
+ request.path != "/data"
2891
2909
  }
2892
2910
  }
2893
2911
 
@@ -2901,7 +2919,7 @@ fn a_mount_whose_policy_refuses_its_root_still_reads_beneath_it() {
2901
2919
  let mut guest = Guest::new(&[grant(
2902
2920
  file_and_directory(),
2903
2921
  Access::Read,
2904
- Some(policy.clone() as Arc<dyn Policy>),
2922
+ Some(policy.clone() as Arc<dyn for<'a> Policy<MountRequest<'a>>>),
2905
2923
  )]);
2906
2924
  let read = guest.call("read_file", FILE);
2907
2925
  let asked = policy.0.lock().unwrap().clone();
@@ -2926,7 +2944,7 @@ fn an_open_of_a_missing_path_that_makes_nothing_answers_enoent() {
2926
2944
  let policed = Guest::new(&[grant(
2927
2945
  file_and_directory(),
2928
2946
  Access::Read,
2929
- Some(policy.clone() as Arc<dyn Policy>),
2947
+ Some(policy.clone() as Arc<dyn for<'a> Policy<MountRequest<'a>>>),
2930
2948
  )])
2931
2949
  .call("append_file", NEW);
2932
2950
  let asked = policy.0.lock().unwrap().clone();
@@ -2996,7 +3014,7 @@ const ERRNO_PERM: i32 = 63;
2996
3014
  struct ChangesNothing(Arc<dyn InodeOperations>);
2997
3015
 
2998
3016
  impl FileSystemType for ChangesNothing {
2999
- fn fill_super(self: Arc<Self>, sb: &mut Filesystem) -> Result<(), FilesystemError> {
3017
+ fn fill_super(self: Arc<Self>, sb: &mut Filesystem) -> Result<(), Errno> {
3000
3018
  sb.d_make_root(vfs::Inode::new(
3001
3019
  &vfs::Kstat::new(vfs::FileType::Dir, 0),
3002
3020
  self,
@@ -3006,11 +3024,11 @@ impl FileSystemType for ChangesNothing {
3006
3024
  }
3007
3025
 
3008
3026
  impl InodeOperations for ChangesNothing {
3009
- fn getattr(&self, dentry: &Dentry) -> Result<Kstat, FilesystemError> {
3027
+ fn getattr(&self, dentry: &Dentry) -> Result<Kstat, Errno> {
3010
3028
  self.0.getattr(dentry)
3011
3029
  }
3012
3030
 
3013
- fn lookup(&self, dentry: &Dentry) -> Result<Lookup, FilesystemError> {
3031
+ fn lookup(&self, dentry: &Dentry) -> Result<Lookup, Errno> {
3014
3032
  Ok(match self.0.lookup(dentry)? {
3015
3033
  Lookup::Found(inode) => {
3016
3034
  Lookup::Found(inode.with_ops(Arc::new(Self(inode.ops().clone()))))
@@ -3019,11 +3037,7 @@ impl InodeOperations for ChangesNothing {
3019
3037
  })
3020
3038
  }
3021
3039
 
3022
- fn open(
3023
- &self,
3024
- dentry: &Dentry,
3025
- how: &OpenHow,
3026
- ) -> Result<Box<dyn FileOperations>, FilesystemError> {
3040
+ fn open(&self, dentry: &Dentry, how: &OpenHow) -> Result<Box<dyn FileOperations>, Errno> {
3027
3041
  self.0.open(dentry, how)
3028
3042
  }
3029
3043
  }
@@ -3505,7 +3519,7 @@ impl LinkedBeneath {
3505
3519
  Arc::new(
3506
3520
  Overlay::new(
3507
3521
  vec![Filesystem::new(directory).expect("the instance must stand")],
3508
- Some(Filesystem::new(Arc::new(Tmpfs::new())).expect("the instance must stand")),
3522
+ Some(Filesystem::new(Tmpfs::new()).expect("the instance must stand")),
3509
3523
  )
3510
3524
  .expect("an upper over a lower Layer must make a view"),
3511
3525
  )
@@ -3723,14 +3737,14 @@ const PUB_X: (i32, i32) = (1150, 5);
3723
3737
  struct SwapsWhileAsked(std::path::PathBuf, std::sync::atomic::AtomicBool);
3724
3738
 
3725
3739
  #[cfg(unix)]
3726
- impl Policy for SwapsWhileAsked {
3727
- fn allows(&self, path: &str, _access: Access) -> bool {
3740
+ impl Policy<MountRequest<'_>> for SwapsWhileAsked {
3741
+ fn allows(&self, request: &MountRequest<'_>) -> bool {
3728
3742
  if self.1.swap(false, Ordering::SeqCst) {
3729
3743
  std::fs::rename(self.0.join("pub"), self.0.join("pub_old")).expect("pub must move");
3730
3744
  std::os::unix::fs::symlink("secret", self.0.join("pub"))
3731
3745
  .expect("the link must be made");
3732
3746
  }
3733
- path.starts_with("/data/pub/")
3747
+ request.path.starts_with("/data/pub/")
3734
3748
  }
3735
3749
  }
3736
3750