kobako 0.29.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 (291) hide show
  1. checksums.yaml +4 -4
  2. data/.release-please-manifest.json +1 -1
  3. data/CHANGELOG.md +552 -10
  4. data/Cargo.lock +595 -139
  5. data/README.md +126 -564
  6. data/ROADMAP.md +3 -2
  7. data/crates/kobako-runtime/CHANGELOG.md +488 -1
  8. data/crates/kobako-runtime/Cargo.toml +73 -15
  9. data/crates/kobako-runtime/README.md +11 -4
  10. data/crates/kobako-runtime/src/cred.rs +124 -0
  11. data/crates/kobako-runtime/src/dispatch.rs +5 -6
  12. data/crates/kobako-runtime/src/endpoint/buffer.rs +301 -0
  13. data/crates/kobako-runtime/src/endpoint/dispatch.rs +292 -0
  14. data/crates/kobako-runtime/src/endpoint/invoke.rs +181 -0
  15. data/crates/kobako-runtime/src/endpoint.rs +267 -0
  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/fid.rs +82 -0
  20. data/crates/kobako-runtime/src/filesystem/bind/lookup.rs +274 -0
  21. data/crates/kobako-runtime/src/filesystem/bind/walk.rs +248 -0
  22. data/crates/kobako-runtime/src/filesystem/bind.rs +2857 -0
  23. data/crates/kobako-runtime/src/filesystem/overlay/file.rs +89 -0
  24. data/crates/kobako-runtime/src/filesystem/overlay/inode.rs +106 -0
  25. data/crates/kobako-runtime/src/filesystem/overlay/path.rs +263 -0
  26. data/crates/kobako-runtime/src/filesystem/overlay/stack/copy_up.rs +128 -0
  27. data/crates/kobako-runtime/src/filesystem/overlay/stack/dir.rs +238 -0
  28. data/crates/kobako-runtime/src/filesystem/overlay/stack/namei.rs +135 -0
  29. data/crates/kobako-runtime/src/filesystem/overlay/stack/readdir.rs +54 -0
  30. data/crates/kobako-runtime/src/filesystem/overlay/stack.rs +316 -739
  31. data/crates/kobako-runtime/src/filesystem/overlay.rs +2627 -1154
  32. data/crates/kobako-runtime/src/filesystem/pipe.rs +224 -0
  33. data/crates/kobako-runtime/src/filesystem/rdir.rs +84 -0
  34. data/crates/kobako-runtime/src/filesystem/tmpfs/seed.rs +32 -0
  35. data/crates/kobako-runtime/src/filesystem/tmpfs/tmpfile.rs +32 -0
  36. data/crates/kobako-runtime/src/filesystem/tmpfs/whiteout.rs +107 -0
  37. data/crates/kobako-runtime/src/filesystem/tmpfs/xattr.rs +22 -0
  38. data/crates/kobako-runtime/src/filesystem/tmpfs.rs +1997 -0
  39. data/crates/kobako-runtime/src/filesystem/wrap.rs +208 -0
  40. data/crates/kobako-runtime/src/filesystem.rs +25 -388
  41. data/crates/kobako-runtime/src/fork.rs +96 -0
  42. data/crates/kobako-runtime/src/grant.rs +3 -0
  43. data/crates/kobako-runtime/src/hashtable.rs +46 -0
  44. data/crates/kobako-runtime/src/lib.rs +27 -11
  45. data/crates/kobako-runtime/src/limits.rs +195 -0
  46. data/crates/kobako-runtime/src/locking/seqlock.rs +66 -0
  47. data/crates/kobako-runtime/src/locking.rs +228 -0
  48. data/crates/kobako-runtime/src/memcg.rs +383 -0
  49. data/crates/kobako-runtime/src/mount.rs +86 -101
  50. data/crates/kobako-runtime/src/net/backends.rs +43 -0
  51. data/crates/kobako-runtime/src/net/connections.rs +179 -0
  52. data/crates/kobako-runtime/src/net/credential.rs +125 -0
  53. data/crates/kobako-runtime/src/net/egress.rs +160 -0
  54. data/crates/kobako-runtime/src/net/family.rs +181 -0
  55. data/crates/kobako-runtime/src/net/http.rs +2733 -0
  56. data/crates/kobako-runtime/src/net/lookup.rs +285 -0
  57. data/crates/kobako-runtime/src/net/mock.rs +251 -0
  58. data/crates/kobako-runtime/src/net/namespace.rs +1366 -0
  59. data/crates/kobako-runtime/src/net/reactor.rs +531 -0
  60. data/crates/kobako-runtime/src/net/resolv/darwin.rs +275 -0
  61. data/crates/kobako-runtime/src/net/resolv/stub/tests.rs +469 -0
  62. data/crates/kobako-runtime/src/net/resolv/stub.rs +536 -0
  63. data/crates/kobako-runtime/src/net/resolv/windows.rs +248 -0
  64. data/crates/kobako-runtime/src/net/resolv.rs +227 -0
  65. data/crates/kobako-runtime/src/net/socket.rs +870 -0
  66. data/crates/kobako-runtime/src/net/tcp.rs +1588 -0
  67. data/crates/kobako-runtime/src/net/tls.rs +58 -0
  68. data/crates/kobako-runtime/src/net/transport.rs +279 -0
  69. data/crates/kobako-runtime/src/net/udp.rs +1003 -0
  70. data/crates/kobako-runtime/src/net.rs +42 -0
  71. data/crates/kobako-runtime/src/network/builder.rs +177 -0
  72. data/crates/kobako-runtime/src/network/ruleset.rs +777 -0
  73. data/crates/kobako-runtime/src/network.rs +551 -0
  74. data/crates/kobako-runtime/src/policy.rs +16 -0
  75. data/crates/kobako-runtime/src/profile.rs +37 -16
  76. data/crates/kobako-runtime/src/runtime.rs +3 -5
  77. data/crates/kobako-runtime/src/sched.rs +311 -0
  78. data/crates/kobako-runtime/src/security/entry_policy.rs +22 -0
  79. data/crates/kobako-runtime/src/security/hooks.rs +242 -0
  80. data/crates/kobako-runtime/src/security/mount_policy.rs +158 -0
  81. data/crates/kobako-runtime/src/security.rs +601 -0
  82. data/crates/kobako-runtime/src/snapshot.rs +121 -2
  83. data/crates/kobako-runtime/src/vfs/attr.rs +162 -0
  84. data/crates/kobako-runtime/src/vfs/dentry.rs +1466 -0
  85. data/crates/kobako-runtime/src/vfs/file.rs +1911 -0
  86. data/crates/kobako-runtime/src/vfs/inode.rs +425 -0
  87. data/crates/kobako-runtime/src/vfs/kern_path.rs +213 -0
  88. data/crates/kobako-runtime/src/vfs/mount.rs +60 -0
  89. data/crates/kobako-runtime/src/vfs/namei.rs +5837 -0
  90. data/crates/kobako-runtime/src/vfs/namespace.rs +162 -0
  91. data/crates/kobako-runtime/src/vfs/open_files.rs +69 -0
  92. data/crates/kobako-runtime/src/vfs/openat2.rs +116 -0
  93. data/crates/kobako-runtime/src/vfs/path.rs +64 -0
  94. data/crates/kobako-runtime/src/vfs/readdir.rs +163 -0
  95. data/crates/kobako-runtime/src/vfs/stat.rs +293 -0
  96. data/crates/kobako-runtime/src/vfs/super_block.rs +126 -0
  97. data/crates/kobako-runtime/src/vfs/utimes.rs +299 -0
  98. data/crates/kobako-runtime/src/vfs.rs +63 -0
  99. data/crates/kobako-runtime/src/wait.rs +356 -0
  100. data/crates/kobako-transport/CHANGELOG.md +39 -2
  101. data/crates/kobako-transport/Cargo.toml +3 -3
  102. data/crates/kobako-transport/README.md +8 -8
  103. data/crates/kobako-transport/src/abi.rs +78 -72
  104. data/crates/kobako-transport/src/envelope/bytes.rs +49 -30
  105. data/crates/kobako-transport/src/envelope/call.rs +37 -9
  106. data/crates/kobako-transport/src/envelope/compile_reply.rs +2 -2
  107. data/crates/kobako-transport/src/envelope/error_record.rs +24 -3
  108. data/crates/kobako-transport/src/envelope/fault.rs +2 -2
  109. data/crates/kobako-transport/src/envelope/name.rs +99 -0
  110. data/crates/kobako-transport/src/envelope/outcome.rs +11 -11
  111. data/crates/kobako-transport/src/envelope/preamble.rs +34 -31
  112. data/crates/kobako-transport/src/envelope/reply.rs +29 -29
  113. data/crates/kobako-transport/src/envelope/request.rs +2 -2
  114. data/crates/kobako-transport/src/envelope/run.rs +1 -1
  115. data/crates/kobako-transport/src/envelope/unsupported.rs +12 -12
  116. data/crates/kobako-transport/src/envelope.rs +15 -10
  117. data/crates/kobako-wasmtime/CHANGELOG.md +315 -8
  118. data/crates/kobako-wasmtime/Cargo.toml +35 -15
  119. data/crates/kobako-wasmtime/README.md +11 -6
  120. data/crates/kobako-wasmtime/build/preview2.rs +1339 -0
  121. data/crates/kobako-wasmtime/build.rs +16 -0
  122. data/crates/kobako-wasmtime/src/abi.rs +19 -47
  123. data/crates/kobako-wasmtime/src/ambient.rs +33 -19
  124. data/crates/kobako-wasmtime/src/cache.rs +28 -20
  125. data/crates/kobako-wasmtime/src/config.rs +59 -60
  126. data/crates/kobako-wasmtime/src/driver.rs +63 -145
  127. data/crates/kobako-wasmtime/src/exports.rs +147 -32
  128. data/crates/kobako-wasmtime/src/guest.rs +44 -0
  129. data/crates/kobako-wasmtime/src/guest_binary.rs +14 -0
  130. data/crates/kobako-wasmtime/src/imports.rs +48 -18
  131. data/crates/kobako-wasmtime/src/instance_pre.rs +7 -7
  132. data/crates/kobako-wasmtime/src/invocation.rs +93 -51
  133. data/crates/kobako-wasmtime/src/lib.rs +6 -7
  134. data/crates/kobako-wasmtime/src/limiter.rs +52 -211
  135. data/crates/kobako-wasmtime/src/preview1/descriptors.rs +309 -0
  136. data/crates/kobako-wasmtime/src/preview1/differential/mount.rs +70 -57
  137. data/crates/kobako-wasmtime/src/preview1/differential.rs +137 -27
  138. data/crates/kobako-wasmtime/src/preview1/errno.rs +90 -233
  139. data/crates/kobako-wasmtime/src/preview1/fd.rs +1301 -522
  140. data/crates/kobako-wasmtime/src/preview1/memory.rs +126 -150
  141. data/crates/kobako-wasmtime/src/preview1/mount_view/wrap.rs +192 -0
  142. data/crates/kobako-wasmtime/src/preview1/mount_view.rs +1989 -708
  143. data/crates/kobako-wasmtime/src/preview1/path.rs +181 -365
  144. data/crates/kobako-wasmtime/src/preview1/poll.rs +345 -173
  145. data/crates/kobako-wasmtime/src/preview1/sock.rs +10 -25
  146. data/crates/kobako-wasmtime/src/preview1/testsuite-expected.txt +6 -0
  147. data/crates/kobako-wasmtime/src/preview1/testsuite.rs +147 -0
  148. data/crates/kobako-wasmtime/src/preview1.rs +471 -416
  149. data/crates/kobako-wasmtime/src/preview2/abi.rs +227 -0
  150. data/crates/kobako-wasmtime/src/preview2/error.rs +118 -0
  151. data/crates/kobako-wasmtime/src/preview2/filesystem.rs +122 -0
  152. data/crates/kobako-wasmtime/src/preview2/host.rs +3959 -0
  153. data/crates/kobako-wasmtime/src/preview2/http.rs +1503 -0
  154. data/crates/kobako-wasmtime/src/preview2/io.rs +315 -0
  155. data/crates/kobako-wasmtime/src/preview2/sockets.rs +379 -0
  156. data/crates/kobako-wasmtime/src/preview2/table.rs +305 -0
  157. data/crates/kobako-wasmtime/src/preview2.rs +57 -0
  158. data/crates/kobako-wasmtime/src/trap.rs +31 -16
  159. data/crates/kobako-wasmtime/src/wasi.rs +238 -93
  160. data/crates/kobako-wasmtime/wit/deps/cli.wit +233 -0
  161. data/crates/kobako-wasmtime/wit/deps/clocks.wit +162 -0
  162. data/crates/kobako-wasmtime/wit/deps/filesystem.wit +589 -0
  163. data/crates/kobako-wasmtime/wit/deps/http.wit +733 -0
  164. data/crates/kobako-wasmtime/wit/deps/io.wit +299 -0
  165. data/crates/kobako-wasmtime/wit/deps/random.wit +92 -0
  166. data/crates/kobako-wasmtime/wit/deps/sockets.wit +949 -0
  167. data/crates/kobako-wasmtime/witx/typenames.witx +750 -0
  168. data/crates/kobako-wasmtime/witx/wasi_snapshot_preview1.witx +441 -0
  169. data/data/kobako.wasm +0 -0
  170. data/ext/kobako/Cargo.toml +1 -1
  171. data/ext/kobako/src/{runtime/errors.rs → errors.rs} +35 -27
  172. data/ext/kobako/src/escape.rs +98 -0
  173. data/ext/kobako/src/{runtime/filesystem → filesystem}/grants.rs +36 -16
  174. data/ext/kobako/src/filesystem/ruby.rs +689 -0
  175. data/ext/kobako/src/filesystem.rs +217 -0
  176. data/ext/kobako/src/gvl.rs +306 -0
  177. data/ext/kobako/src/lib.rs +64 -3
  178. data/ext/kobako/src/network/mock.rs +187 -0
  179. data/ext/kobako/src/network.rs +591 -0
  180. data/ext/kobako/src/runtime/bridge.rs +31 -30
  181. data/ext/kobako/src/runtime/snapshot.rs +5 -5
  182. data/ext/kobako/src/runtime.rs +221 -138
  183. data/ext/kobako/src/wire.rs +42 -0
  184. data/lib/kobako/catalog/extensions.rb +19 -7
  185. data/lib/kobako/catalog/flags.rb +4 -6
  186. data/lib/kobako/catalog/grants.rb +5 -4
  187. data/lib/kobako/catalog/handles.rb +9 -31
  188. data/lib/kobako/catalog/mount.rb +12 -12
  189. data/lib/kobako/catalog/network.rb +35 -0
  190. data/lib/kobako/catalog/replacements.rb +28 -0
  191. data/lib/kobako/catalog/services.rb +7 -21
  192. data/lib/kobako/catalog/snippets.rb +10 -25
  193. data/lib/kobako/catalog.rb +4 -1
  194. data/lib/kobako/codec/{utils.rb → boundary.rb} +5 -3
  195. data/lib/kobako/codec/decoder.rb +12 -12
  196. data/lib/kobako/codec/ext_types.rb +5 -7
  197. data/lib/kobako/codec/handle_walk.rb +5 -47
  198. data/lib/kobako/codec/nesting.rb +7 -7
  199. data/lib/kobako/codec/value_budget.rb +134 -42
  200. data/lib/kobako/codec.rb +1 -1
  201. data/lib/kobako/context.rb +28 -15
  202. data/lib/kobako/errors.rb +15 -12
  203. data/lib/kobako/extension.rb +3 -2
  204. data/lib/kobako/filesystem.rb +53 -15
  205. data/lib/kobako/handle.rb +2 -2
  206. data/lib/kobako/names.rb +28 -0
  207. data/lib/kobako/network.rb +210 -0
  208. data/lib/kobako/outcome.rb +7 -7
  209. data/lib/kobako/payload/arguments.rb +2 -2
  210. data/lib/kobako/pool.rb +47 -25
  211. data/lib/kobako/runtime.rb +3 -2
  212. data/lib/kobako/sandbox.rb +113 -56
  213. data/lib/kobako/sandbox_options.rb +41 -107
  214. data/lib/kobako/snippet/bytecode.rb +1 -1
  215. data/lib/kobako/snippet/source.rb +1 -1
  216. data/lib/kobako/transport/argument_wrap.rb +64 -0
  217. data/lib/kobako/transport/block_failure.rb +1 -1
  218. data/lib/kobako/transport/dispatcher.rb +10 -10
  219. data/lib/kobako/transport/exposure.rb +28 -17
  220. data/lib/kobako/transport/reflection.rb +28 -11
  221. data/lib/kobako/transport/run.rb +13 -28
  222. data/lib/kobako/transport/yielder.rb +3 -10
  223. data/lib/kobako/transport.rb +1 -0
  224. data/lib/kobako/version.rb +1 -1
  225. data/lib/kobako.rb +38 -0
  226. data/release-please-config.json +16 -0
  227. data/sig/core/thread.rbs +6 -0
  228. data/sig/kobako/catalog/extensions.rbs +5 -3
  229. data/sig/kobako/catalog/grants.rbs +7 -4
  230. data/sig/kobako/catalog/handles.rbs +2 -4
  231. data/sig/kobako/catalog/mount.rbs +3 -5
  232. data/sig/kobako/catalog/network.rbs +20 -0
  233. data/sig/kobako/catalog/replacements.rbs +14 -0
  234. data/sig/kobako/catalog/services.rbs +1 -5
  235. data/sig/kobako/catalog/snippets.rbs +3 -5
  236. data/sig/kobako/catalog.rbs +1 -1
  237. data/sig/kobako/codec/boundary.rbs +9 -0
  238. data/sig/kobako/codec/decoder.rbs +1 -1
  239. data/sig/kobako/codec/handle_walk.rbs +0 -6
  240. data/sig/kobako/codec/nesting.rbs +2 -2
  241. data/sig/kobako/codec/value_budget.rbs +48 -5
  242. data/sig/kobako/codec.rbs +1 -2
  243. data/sig/kobako/context.rbs +4 -2
  244. data/sig/kobako/errors.rbs +4 -4
  245. data/sig/kobako/filesystem.rbs +38 -15
  246. data/sig/kobako/guest_yielder.rbs +1 -1
  247. data/sig/kobako/network.rbs +115 -0
  248. data/sig/kobako/outcome.rbs +1 -1
  249. data/sig/kobako/payload/arguments.rbs +1 -1
  250. data/sig/kobako/pool.rbs +8 -4
  251. data/sig/kobako/runtime.rbs +32 -3
  252. data/sig/kobako/sandbox.rbs +22 -7
  253. data/sig/kobako/sandbox_options.rbs +29 -38
  254. data/sig/kobako/transport/argument_wrap.rbs +15 -0
  255. data/sig/kobako/transport/dispatcher.rbs +2 -2
  256. data/sig/kobako/transport/error.rbs +1 -1
  257. data/sig/kobako/transport/exposure.rbs +3 -5
  258. data/sig/kobako/transport/reflection.rbs +12 -2
  259. data/sig/kobako/transport/run.rbs +3 -5
  260. data/sig/kobako/transport/yielder.rbs +0 -3
  261. data/sig/kobako/transport.rbs +2 -2
  262. data/sig/kobako.rbs +13 -0
  263. metadata +131 -34
  264. data/crates/kobako-runtime/src/filesystem/directory/spelling.rs +0 -194
  265. data/crates/kobako-runtime/src/filesystem/directory.rs +0 -1082
  266. data/crates/kobako-runtime/src/filesystem/memory.rs +0 -1100
  267. data/crates/kobako-runtime/src/filesystem/overlay/exclusive.rs +0 -88
  268. data/crates/kobako-runtime/src/filesystem/path.rs +0 -60
  269. data/crates/kobako-runtime/src/filesystem/temporary.rs +0 -167
  270. data/crates/kobako-wasmtime/src/capture.rs +0 -96
  271. data/crates/kobako-wasmtime/src/descriptors.rs +0 -167
  272. data/crates/kobako-wasmtime/src/dispatch.rs +0 -125
  273. data/crates/kobako-wasmtime/src/guest_mem.rs +0 -271
  274. data/crates/kobako-wasmtime/src/io.rs +0 -89
  275. data/crates/kobako-wasmtime/src/preview1/args.rs +0 -60
  276. data/crates/kobako-wasmtime/src/preview1/beneath.rs +0 -188
  277. data/crates/kobako-wasmtime/tests/compile_posture.rs +0 -43
  278. data/crates/kobako-wasmtime/tests/guest_file.rs +0 -1054
  279. data/crates/kobako-wasmtime/tests/preamble_flags.rs +0 -70
  280. data/crates/kobako-wasmtime/tests/snippet_compile.rs +0 -95
  281. data/crates/kobako-wasmtime/tests/support/mod.rs +0 -30
  282. data/crates/kobako-wasmtime/tests/unanswered_call.rs +0 -86
  283. data/crates/kobako-wasmtime/tests/unsupported_call.rs +0 -51
  284. data/ext/kobako/src/runtime/escape.rs +0 -53
  285. data/ext/kobako/src/runtime/filesystem/ruby.rs +0 -400
  286. data/ext/kobako/src/runtime/filesystem.rs +0 -236
  287. data/ext/kobako/src/runtime/gvl.rs +0 -112
  288. data/lib/kobako/constant_name.rb +0 -8
  289. data/sig/kobako/codec/utils.rbs +0 -9
  290. data/sig/kobako/constant_name.rbs +0 -3
  291. /data/ext/kobako/src/{runtime/pinned_value.rs → pinned_value.rs} +0 -0
@@ -0,0 +1,208 @@
1
+ //! A test's Filesystem over another: every call forwards to the entry it
2
+ //! wraps unless its `Hook` steps in, and every entry a lookup finds is
3
+ //! wrapped too, as a Filesystem wrapping another must. It makes a file
4
+ //! through `create` and leaves the open to the VFS, as overlayfs does, so an
5
+ //! open's lookup reaches the `Hook` as any lookup does. It hands the
6
+ //! Filesystem beneath the dentry it is handed, where overlayfs hands a real
7
+ //! one, so what that Filesystem makes is recorded unwrapped and later calls
8
+ //! on it reach that Filesystem past the `Hook`.
9
+
10
+ use std::any::Any;
11
+ use std::sync::Arc;
12
+
13
+ use super::{
14
+ DentryOperations, Errno, FileOperations, FileSystemType, Filesystem, Iattr, InodeOperations,
15
+ Kstat, Lookup, Mask, OpenHow, RenameFlag,
16
+ };
17
+ use crate::vfs::{Dentry, Inode};
18
+
19
+ /// What a test changes of the Filesystem beneath it.
20
+ pub(crate) trait Hook: Send + Sync + 'static {
21
+ fn permission(
22
+ &self,
23
+ inner: &dyn InodeOperations,
24
+ dentry: &Dentry,
25
+ mask: Mask,
26
+ ) -> Result<(), Errno> {
27
+ inner.permission(dentry, mask)
28
+ }
29
+
30
+ fn revalidate(
31
+ &self,
32
+ ops: &dyn DentryOperations,
33
+ dir: &dyn InodeOperations,
34
+ dentry: &Dentry,
35
+ ) -> Result<bool, Errno> {
36
+ ops.revalidate(dir, dentry)
37
+ }
38
+
39
+ fn getattr(&self, inner: &dyn InodeOperations, dentry: &Dentry) -> Result<Kstat, Errno> {
40
+ inner.getattr(dentry)
41
+ }
42
+
43
+ fn lookup(&self, inner: &dyn InodeOperations, dentry: &Dentry) -> Result<Lookup, Errno> {
44
+ inner.lookup(dentry)
45
+ }
46
+
47
+ fn open(
48
+ &self,
49
+ inner: &dyn InodeOperations,
50
+ dentry: &Dentry,
51
+ how: &OpenHow,
52
+ ) -> Result<Box<dyn FileOperations>, Errno> {
53
+ inner.open(dentry, how)
54
+ }
55
+
56
+ fn mkdir(&self, inner: &dyn InodeOperations, dentry: &Dentry) -> Result<(), Errno> {
57
+ inner.mkdir(dentry)
58
+ }
59
+
60
+ fn rmdir(&self, inner: &dyn InodeOperations, dentry: &Dentry) -> Result<(), Errno> {
61
+ inner.rmdir(dentry)
62
+ }
63
+
64
+ fn unlink(&self, inner: &dyn InodeOperations, dentry: &Dentry) -> Result<(), Errno> {
65
+ inner.unlink(dentry)
66
+ }
67
+
68
+ fn rename(
69
+ &self,
70
+ inner: &dyn InodeOperations,
71
+ old: &Dentry,
72
+ new_dir: &dyn InodeOperations,
73
+ new: &Dentry,
74
+ flags: Option<RenameFlag>,
75
+ ) -> Result<(), Errno> {
76
+ inner.rename(old, new_dir, new, flags)
77
+ }
78
+ }
79
+
80
+ /// A Filesystem over the one `fs` makes, with `hook` stepping in.
81
+ pub(crate) struct Wrap<H> {
82
+ fs: Arc<dyn FileSystemType>,
83
+ hook: Arc<H>,
84
+ }
85
+
86
+ impl<H: Hook> Wrap<H> {
87
+ pub(crate) fn new(fs: Arc<dyn FileSystemType>, hook: Arc<H>) -> Self {
88
+ Self { fs, hook }
89
+ }
90
+ }
91
+
92
+ impl<H: Hook> FileSystemType for Wrap<H> {
93
+ fn fill_super(self: Arc<Self>, sb: &mut Filesystem) -> Result<(), Errno> {
94
+ self.fs.clone().fill_super(sb)?;
95
+ if let Some(ops) = sb.d_op().cloned() {
96
+ sb.set_default_d_op(Arc::new(WrapDentry {
97
+ ops,
98
+ hook: self.hook.clone(),
99
+ }));
100
+ }
101
+ if let Some(root) = sb.root().and_then(|root| root.inode()) {
102
+ let wrapped = WrapInode {
103
+ inner: root.ops().clone(),
104
+ hook: self.hook.clone(),
105
+ };
106
+ sb.d_make_root(root.with_ops(Arc::new(wrapped)));
107
+ }
108
+ Ok(())
109
+ }
110
+ }
111
+
112
+ /// `inner`, an entry of the Filesystem beneath, with `hook` stepping in.
113
+ struct WrapInode<H> {
114
+ inner: Arc<dyn InodeOperations>,
115
+ hook: Arc<H>,
116
+ }
117
+
118
+ impl<H: Hook> WrapInode<H> {
119
+ /// `found` with the entry it names wrapped too.
120
+ fn wrap(&self, found: Lookup) -> Lookup {
121
+ let wrapped = |inode: Arc<Inode>| {
122
+ let ops = Self {
123
+ inner: inode.ops().clone(),
124
+ hook: self.hook.clone(),
125
+ };
126
+ inode.with_ops(Arc::new(ops))
127
+ };
128
+ match found {
129
+ Lookup::Found(inode) => Lookup::Found(wrapped(inode)),
130
+ Lookup::Spelled { name, inode } => Lookup::Spelled {
131
+ name,
132
+ inode: wrapped(inode),
133
+ },
134
+ Lookup::Absent => Lookup::Absent,
135
+ }
136
+ }
137
+ }
138
+
139
+ /// `ops`, handed the directory a `WrapInode<H>` wraps.
140
+ struct WrapDentry<H> {
141
+ ops: Arc<dyn DentryOperations>,
142
+ hook: Arc<H>,
143
+ }
144
+
145
+ impl<H: Hook> DentryOperations for WrapDentry<H> {
146
+ fn revalidate(&self, dir: &dyn InodeOperations, dentry: &Dentry) -> Result<bool, Errno> {
147
+ let dir = (dir as &dyn Any)
148
+ .downcast_ref::<WrapInode<H>>()
149
+ .map_or(dir, |wrap| wrap.inner.as_ref());
150
+ self.hook.revalidate(self.ops.as_ref(), dir, dentry)
151
+ }
152
+ }
153
+
154
+ impl<H: Hook> InodeOperations for WrapInode<H> {
155
+ fn permission(&self, dentry: &Dentry, mask: Mask) -> Result<(), Errno> {
156
+ self.hook.permission(self.inner.as_ref(), dentry, mask)
157
+ }
158
+
159
+ fn getattr(&self, dentry: &Dentry) -> Result<Kstat, Errno> {
160
+ self.hook.getattr(self.inner.as_ref(), dentry)
161
+ }
162
+
163
+ fn lookup(&self, dentry: &Dentry) -> Result<Lookup, Errno> {
164
+ Ok(self.wrap(self.hook.lookup(self.inner.as_ref(), dentry)?))
165
+ }
166
+
167
+ fn setattr(&self, dentry: &Dentry, attr: &Iattr) -> Result<(), Errno> {
168
+ self.inner.setattr(dentry, attr)
169
+ }
170
+
171
+ fn get_link(&self, dentry: &Dentry) -> Result<String, Errno> {
172
+ self.inner.get_link(dentry)
173
+ }
174
+
175
+ fn open(&self, dentry: &Dentry, how: &OpenHow) -> Result<Box<dyn FileOperations>, Errno> {
176
+ self.hook.open(self.inner.as_ref(), dentry, how)
177
+ }
178
+
179
+ fn create(&self, dentry: &Dentry) -> Result<(), Errno> {
180
+ self.inner.create(dentry)
181
+ }
182
+
183
+ fn mkdir(&self, dentry: &Dentry) -> Result<(), Errno> {
184
+ self.hook.mkdir(self.inner.as_ref(), dentry)
185
+ }
186
+
187
+ fn rmdir(&self, dentry: &Dentry) -> Result<(), Errno> {
188
+ self.hook.rmdir(self.inner.as_ref(), dentry)
189
+ }
190
+
191
+ fn unlink(&self, dentry: &Dentry) -> Result<(), Errno> {
192
+ self.hook.unlink(self.inner.as_ref(), dentry)
193
+ }
194
+
195
+ fn rename(
196
+ &self,
197
+ old: &Dentry,
198
+ new_dir: &dyn InodeOperations,
199
+ new: &Dentry,
200
+ flags: Option<RenameFlag>,
201
+ ) -> Result<(), Errno> {
202
+ let target = (new_dir as &dyn Any)
203
+ .downcast_ref::<Self>()
204
+ .ok_or(Errno::CrossesDevices)?;
205
+ self.hook
206
+ .rename(self.inner.as_ref(), old, target.inner.as_ref(), new, flags)
207
+ }
208
+ }
@@ -1,392 +1,29 @@
1
- //! The Filesystem behind a Mount: what answers every call a
2
- //! guest makes beneath that Mount's path.
1
+ //! The Filesystem kinds kobako ships, each built on the VFS as a Linux
2
+ //! filesystem is: what answers every call a guest makes beneath a Mount.
3
3
  //!
4
- //! A runtime owns the descriptors and path resolution, and the Mount
5
- //! decides access; a `Filesystem` only answers for the files and directories
6
- //! themselves, so a third party brings one without implementing any of
7
- //! that. Every path a runtime hands over is relative to the Filesystem's
8
- //! own root, its components joined by `/`, with no `.` or `..` left and
9
- //! no leading `/`; the empty path is the root, which a runtime never asks
10
- //! to remove or move.
4
+ //! A third party implements the same tables to bring its own, so they are
5
+ //! named here too; the VFS, which calls them, owns them.
11
6
 
12
- mod directory;
13
- mod memory;
7
+ mod anon_inodes;
8
+ mod bind;
14
9
  mod overlay;
15
- mod path;
16
- mod temporary;
17
-
18
- use std::sync::atomic::{AtomicU64, Ordering};
19
- use std::sync::Arc;
20
-
21
- pub use directory::Directory;
22
- pub use memory::{Memory, SeedError};
23
- pub use overlay::{Blocking, Overlay};
24
- pub use temporary::Temporary;
25
-
26
- /// What the guest may do beneath a Mount, or an Overlay in one of its
27
- /// Layers.
28
- #[derive(Clone, Copy, Debug, PartialEq, Eq)]
29
- pub enum Access {
30
- Read,
31
- ReadWrite,
32
- }
33
-
34
- /// The files and directories behind a Mount. One may wrap
35
- /// another and answer by delegating, so it sees every call on the way
36
- /// through.
37
- ///
38
- /// Six methods keep a guarantee the runtime gives the guest, so each
39
- /// Filesystem answers them itself and a wrapper forwards them:
40
- /// `symlink_metadata` keeps a link from being followed where a Mount
41
- /// refuses links, `stored_path` keeps a Policy judging the spelling the
42
- /// host stores, `canonicalize_beneath` keeps a link within the directory
43
- /// a descriptor opened, `hold_directory` keeps an open directory's
44
- /// identity its own, `for_invocation` keeps one Invocation's changes
45
- /// from the next, and `for_policy` keeps a call to the path a Policy
46
- /// judged.
47
- pub trait Filesystem: Send + Sync {
48
- /// Open the file at `path` as `options` asks, creating or truncating it
49
- /// where they say to.
50
- fn open(&self, path: &str, options: &OpenOptions) -> Result<Box<dyn File>, FilesystemError>;
51
-
52
- fn metadata(&self, path: &str) -> Result<Metadata, FilesystemError>;
53
-
54
- /// What `path` names without following a link standing there, as
55
- /// `lstat` answers. A link is reported as one and nothing of where it
56
- /// points: no size, and no way to read it. A Filesystem holding no
57
- /// links answers `metadata`.
58
- fn symlink_metadata(&self, path: &str) -> Result<Metadata, FilesystemError>;
59
-
60
- /// `path` with each name this Filesystem holds spelled as it stores
61
- /// it, so a name a host reaches by more than one spelling is judged by
62
- /// one; names past the last it holds stay as given. A Filesystem
63
- /// matching names exactly answers `path`.
64
- fn stored_path(&self, path: &str) -> Result<String, FilesystemError>;
65
-
66
- /// `path`, relative to the directory at `base`, with every link on it
67
- /// followed, as cap-std's `Dir::canonicalize` answers: still relative
68
- /// to `base`, `NotPermitted` where a link leads out of `base`, and
69
- /// `NotFound` where nothing stands. A descriptor opened on `base`
70
- /// reaches nothing above it, as a capability never widens. A
71
- /// Filesystem holding no links answers `path`.
72
- fn canonicalize_beneath(&self, base: &str, path: &str) -> Result<String, FilesystemError>;
73
-
74
- /// Keep the directory at `path` from handing its identity to another
75
- /// while the Hold lives, as an open descriptor keeps a host's inode
76
- /// from being reused. A Filesystem whose identities never repeat
77
- /// holds nothing.
78
- fn hold_directory(&self, path: &str) -> Result<Option<Hold>, FilesystemError>;
79
-
80
- /// The entries of the directory at `path`, without `.` or `..`.
81
- fn read_dir(&self, path: &str) -> Result<Vec<DirEntry>, FilesystemError>;
82
-
83
- fn create_dir(&self, path: &str) -> Result<(), FilesystemError>;
84
-
85
- /// Remove the empty directory at `path`.
86
- fn remove_dir(&self, path: &str) -> Result<(), FilesystemError>;
87
-
88
- fn remove_file(&self, path: &str) -> Result<(), FilesystemError>;
89
-
90
- /// Move the entry at `from` to `to`, refusing one `rename` does not
91
- /// allow; a move onto its own path changes nothing and is allowed.
92
- /// The Filesystem checks what stands at `from` as it moves it, under
93
- /// the same lock, so nothing replaces it in between.
94
- fn rename(&self, from: &str, to: &str, rename: Rename) -> Result<(), FilesystemError>;
95
-
96
- /// The Filesystem a new Invocation starts from in this one's place, or
97
- /// `None` when every Invocation shares this one.
98
- fn for_invocation(&self) -> Option<Arc<dyn Filesystem>>;
99
-
100
- /// The Filesystem a Mount with a Policy hands its calls in this one's
101
- /// place, following no link anywhere on a path, each name reached
102
- /// from the directory already held, so a link another writer swaps in
103
- /// after the Policy judged the path is a link loop rather than
104
- /// followed. A Filesystem holding no links answers `None`.
105
- fn for_policy(&self) -> Option<Arc<dyn Filesystem>>;
106
- }
107
-
108
- /// One open file. The runtime keeps its position, so every read and write
109
- /// names the offset it starts at.
110
- pub trait File: Send {
111
- fn read_at(&mut self, buf: &mut [u8], offset: u64) -> Result<usize, FilesystemError>;
112
-
113
- fn write_at(&mut self, buf: &[u8], offset: u64) -> Result<usize, FilesystemError>;
114
-
115
- /// Write `buf` at the file's end as it stands when the write lands,
116
- /// answering the offset it landed at and how much was written. It
117
- /// keeps another writer's append from landing over this one, as Linux
118
- /// takes an append under the file's lock, so a file that cannot read
119
- /// its end and write there in one step answers `Unsupported`.
120
- fn append(&mut self, buf: &[u8]) -> Result<(u64, usize), FilesystemError>;
121
-
122
- fn metadata(&self) -> Result<Metadata, FilesystemError>;
123
-
124
- /// Truncate or extend the file to `len` bytes, extending with zeros.
125
- fn set_len(&mut self, len: u64) -> Result<(), FilesystemError>;
126
-
127
- /// Make what was written durable. The default has nothing to flush,
128
- /// which is the truthful answer of a file with no durability of its
129
- /// own.
130
- fn sync(&mut self) -> Result<(), FilesystemError> {
131
- Ok(())
132
- }
133
-
134
- /// Release the file once the guest closes it, answering whether what
135
- /// it held was kept. The default has nothing to release; a file the
136
- /// guest never closes is dropped instead.
137
- fn close(self: Box<Self>) -> Result<(), FilesystemError> {
138
- Ok(())
139
- }
140
- }
141
-
142
- /// How `Filesystem::open` opens a file.
143
- #[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
144
- #[non_exhaustive]
145
- pub struct OpenOptions {
146
- pub read: bool,
147
- pub write: bool,
148
- /// Create the file when it does not exist.
149
- pub create: bool,
150
- /// Create the file, refusing one that already exists.
151
- pub create_new: bool,
152
- /// Empty the file once it is open.
153
- pub truncate: bool,
154
- /// Refuse a symbolic link standing at the path, as `O_NOFOLLOW` does;
155
- /// a Filesystem holding no links has none to refuse.
156
- pub nofollow: bool,
157
- }
158
-
159
- /// What `Filesystem::rename` may move, as `renameat2` flags ask more of
160
- /// a rename than its two paths.
161
- #[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
162
- #[non_exhaustive]
163
- pub enum Rename {
164
- /// Whatever stands at the source.
165
- #[default]
166
- Any,
167
- /// Only a file. A directory is refused as `CrossesDevices`, so a
168
- /// caller copies what is beneath it one entry at a time instead.
169
- File,
170
- /// Only a directory, as a trailing `/` asks. A file is refused as
171
- /// `NotADirectory`.
172
- Directory,
173
- }
174
-
175
- impl Rename {
176
- /// Refuse moving an entry of `file_type` this rename may not move.
177
- pub fn check(self, file_type: FileType) -> Result<(), FilesystemError> {
178
- match (self, file_type) {
179
- (Self::File, FileType::Directory) => Err(FilesystemError::CrossesDevices),
180
- (Self::Directory, file_type) if file_type != FileType::Directory => {
181
- Err(FilesystemError::NotADirectory)
182
- }
183
- _ => Ok(()),
184
- }
185
- }
186
- }
187
-
188
- /// What a path names.
189
- #[derive(Clone, Copy, Debug, PartialEq, Eq)]
190
- #[non_exhaustive]
191
- pub enum FileType {
192
- File,
193
- Directory,
194
- /// A link, as only `symlink_metadata` and a listing report one.
195
- Symlink,
196
- /// Anything else a host holds, such as a FIFO, a socket, or a device,
197
- /// which no Filesystem opens.
198
- Unknown,
199
- }
200
-
201
- #[derive(Clone, Copy, Debug, PartialEq, Eq)]
202
- #[non_exhaustive]
203
- pub struct Metadata {
204
- pub file_type: FileType,
205
- /// The length in bytes; zero for a directory or a link.
206
- pub len: u64,
207
- /// The device and inode numbers naming what the path holds, as
208
- /// `st_dev` and `st_ino` do. An `ino` of zero reports none, so a
209
- /// descriptor of such a directory follows its path alone.
210
- pub dev: u64,
211
- pub ino: u64,
212
- }
213
-
214
- impl Metadata {
215
- /// Metadata reporting no identity.
216
- pub fn new(file_type: FileType, len: u64) -> Self {
217
- Self {
218
- file_type,
219
- len,
220
- dev: 0,
221
- ino: 0,
222
- }
223
- }
224
-
225
- /// This metadata naming `dev` and `ino` as what the path holds.
226
- pub fn with_identity(self, dev: u64, ino: u64) -> Self {
227
- Self { dev, ino, ..self }
228
- }
229
-
230
- /// A device number for a Filesystem with none of its own, as each
231
- /// tmpfs mount takes one: no earlier call returned it, and its top bit,
232
- /// which no host's `st_dev` sets, keeps it apart from a host's.
233
- pub fn unique_device() -> u64 {
234
- static NEXT: AtomicU64 = AtomicU64::new(1);
235
- (1 << 63) | NEXT.fetch_add(1, Ordering::Relaxed)
236
- }
237
- }
238
-
239
- /// What keeps a directory's identity its own while a descriptor has the
240
- /// directory open, released when it drops.
241
- pub struct Hold {
242
- _kept: Box<dyn Send + Sync>,
243
- }
244
-
245
- impl Hold {
246
- /// A Hold keeping `kept`, such as a host directory's descriptor, until
247
- /// it drops.
248
- pub fn new(kept: impl Send + Sync + 'static) -> Self {
249
- Self {
250
- _kept: Box::new(kept),
251
- }
252
- }
253
- }
254
-
255
- #[derive(Clone, Debug, PartialEq, Eq)]
256
- #[non_exhaustive]
257
- pub struct DirEntry {
258
- pub name: String,
259
- pub file_type: FileType,
260
- }
261
-
262
- impl DirEntry {
263
- /// The entry `name` in its directory, naming a `file_type`.
264
- pub fn new(name: impl Into<String>, file_type: FileType) -> Self {
265
- Self {
266
- name: name.into(),
267
- file_type,
268
- }
269
- }
270
- }
271
-
272
- /// Why a Filesystem call failed. The runtime hands the guest the matching
273
- /// error code.
274
- #[derive(Clone, Debug, PartialEq, Eq)]
275
- #[non_exhaustive]
276
- pub enum FilesystemError {
277
- NotFound,
278
- AlreadyExists,
279
- NotADirectory,
280
- IsADirectory,
281
- DirectoryNotEmpty,
282
- PermissionDenied,
283
- ReadOnlyFilesystem,
284
- InvalidInput,
285
- Unsupported,
286
- /// A change past what the Filesystem can hold.
287
- StorageFull,
288
- /// A file grown past the largest the Filesystem keeps.
289
- FileTooLarge,
290
- /// A move that cannot happen in one step, as between two devices.
291
- CrossesDevices,
292
- /// A call that would wait on a lock its own thread holds.
293
- Deadlock,
294
- /// A symbolic link where the call asked to follow none.
295
- FilesystemLoop,
296
- /// A call only a privileged caller may make, as apart from one the
297
- /// file's permissions deny.
298
- NotPermitted,
299
- BadDescriptor,
300
- ResourceBusy,
301
- /// Bytes that are no valid character where the call needs one.
302
- IllegalSequence,
303
- Interrupted,
304
- TooManyOpenFiles,
305
- /// A name too long for the Filesystem.
306
- InvalidFilename,
307
- OutOfMemory,
308
- NotASocket,
309
- /// A value too large for the type the call answers in.
310
- ValueTooLarge,
311
- NotSeekable,
312
- /// Any other failure, with what the Filesystem knows of it.
313
- Other(String),
314
- }
315
-
316
- /// Each failure under the POSIX error name it stands for. `ENOTSUP` comes
317
- /// before `EOPNOTSUPP`, a name some hosts give the same error, so
318
- /// `Unsupported` answers to the first.
319
- const POSIX_NAMES: [(&str, FilesystemError); 26] = [
320
- ("ENOENT", FilesystemError::NotFound),
321
- ("EEXIST", FilesystemError::AlreadyExists),
322
- ("ENOTDIR", FilesystemError::NotADirectory),
323
- ("EISDIR", FilesystemError::IsADirectory),
324
- ("ENOTEMPTY", FilesystemError::DirectoryNotEmpty),
325
- ("EACCES", FilesystemError::PermissionDenied),
326
- ("EROFS", FilesystemError::ReadOnlyFilesystem),
327
- ("EINVAL", FilesystemError::InvalidInput),
328
- ("ENOTSUP", FilesystemError::Unsupported),
329
- ("EOPNOTSUPP", FilesystemError::Unsupported),
330
- ("ENOSPC", FilesystemError::StorageFull),
331
- ("EFBIG", FilesystemError::FileTooLarge),
332
- ("EXDEV", FilesystemError::CrossesDevices),
333
- ("EDEADLK", FilesystemError::Deadlock),
334
- ("ELOOP", FilesystemError::FilesystemLoop),
335
- ("EPERM", FilesystemError::NotPermitted),
336
- ("EBADF", FilesystemError::BadDescriptor),
337
- ("EBUSY", FilesystemError::ResourceBusy),
338
- ("EILSEQ", FilesystemError::IllegalSequence),
339
- ("EINTR", FilesystemError::Interrupted),
340
- ("EMFILE", FilesystemError::TooManyOpenFiles),
341
- ("ENAMETOOLONG", FilesystemError::InvalidFilename),
342
- ("ENOMEM", FilesystemError::OutOfMemory),
343
- ("ENOTSOCK", FilesystemError::NotASocket),
344
- ("EOVERFLOW", FilesystemError::ValueTooLarge),
345
- ("ESPIPE", FilesystemError::NotSeekable),
346
- ];
347
-
348
- impl FilesystemError {
349
- /// The POSIX error name this failure stands for, as `ENOENT`. `Other`
350
- /// has none.
351
- pub fn posix_name(&self) -> Option<&'static str> {
352
- POSIX_NAMES
353
- .iter()
354
- .find(|(_, error)| error == self)
355
- .map(|(name, _)| *name)
356
- }
357
-
358
- /// The failure a POSIX error name stands for, if it is one of these.
359
- pub fn from_posix_name(name: &str) -> Option<Self> {
360
- POSIX_NAMES
361
- .iter()
362
- .find(|(known, _)| *known == name)
363
- .map(|(_, error)| error.clone())
364
- }
365
- }
366
-
10
+ mod pipe;
11
+ mod rdir;
12
+ mod tmpfs;
367
13
  #[cfg(test)]
368
- mod tests {
369
- use super::*;
370
-
371
- #[test]
372
- fn every_posix_name_answers_back_to_its_failure() {
373
- for (name, error) in &POSIX_NAMES {
374
- assert_eq!(
375
- FilesystemError::from_posix_name(name)
376
- .as_ref()
377
- .and_then(FilesystemError::posix_name)
378
- .and_then(FilesystemError::from_posix_name),
379
- Some(error.clone()),
380
- "{name} through FilesystemError::from_posix_name and posix_name must name {error:?} again"
381
- );
382
- }
383
- assert_eq!(
384
- (
385
- FilesystemError::Unsupported.posix_name(),
386
- FilesystemError::Other("x".into()).posix_name()
387
- ),
388
- (Some("ENOTSUP"), None),
389
- "Unsupported through FilesystemError::posix_name must answer ENOTSUP, and Other none"
390
- );
391
- }
392
- }
14
+ pub(crate) mod wrap;
15
+
16
+ pub(crate) use anon_inodes::anon_inode_getfile;
17
+ pub use bind::Bind;
18
+ pub use overlay::Overlay;
19
+ pub use pipe::{create_pipe_files, PipeInodeInfo};
20
+ pub use rdir::Rdir;
21
+ pub use tmpfs::{SeedError, Tmpfs};
22
+
23
+ pub use crate::vfs::{
24
+ get_anon_bdev, Dentry, DentryOperations, DirContext, DirEntry, FMode, FileOperations,
25
+ FileSystemType, FileType, Finish, Iattr, Inode, InodeOperations, Kiocb, Kstat, Lookup, Mask,
26
+ OpenHow, PollMask, RenameFlag, SetTime, SuperBlock as Filesystem, Whence,
27
+ };
28
+
29
+ use crate::Errno;