kobako 0.30.0 → 0.32.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 (288) hide show
  1. checksums.yaml +4 -4
  2. data/.githooks/linux-tests.sh +29 -0
  3. data/.release-please-manifest.json +1 -1
  4. data/CHANGELOG.md +460 -0
  5. data/Cargo.lock +868 -447
  6. data/README.md +43 -4
  7. data/ROADMAP.md +1 -2
  8. data/crates/kobako-runtime/CHANGELOG.md +309 -0
  9. data/crates/kobako-runtime/Cargo.toml +58 -11
  10. data/crates/kobako-runtime/README.md +7 -4
  11. data/crates/kobako-runtime/src/cred.rs +136 -0
  12. data/crates/kobako-runtime/src/dispatch.rs +4 -5
  13. data/crates/kobako-runtime/src/endpoint/buffer.rs +153 -44
  14. data/crates/kobako-runtime/src/endpoint/dispatch.rs +80 -41
  15. data/crates/kobako-runtime/src/endpoint/invoke.rs +23 -36
  16. data/crates/kobako-runtime/src/endpoint.rs +137 -36
  17. data/crates/kobako-runtime/src/errno.rs +391 -0
  18. data/crates/kobako-runtime/src/error.rs +31 -10
  19. data/crates/kobako-runtime/src/filesystem/anon_inodes.rs +52 -0
  20. data/crates/kobako-runtime/src/filesystem/bind/fid.rs +300 -22
  21. data/crates/kobako-runtime/src/filesystem/bind/lookup.rs +101 -29
  22. data/crates/kobako-runtime/src/filesystem/bind/unicode.rs +109 -0
  23. data/crates/kobako-runtime/src/filesystem/bind/walk.rs +52 -34
  24. data/crates/kobako-runtime/src/filesystem/bind.rs +812 -447
  25. data/crates/kobako-runtime/src/filesystem/overlay/file.rs +6 -6
  26. data/crates/kobako-runtime/src/filesystem/overlay/path.rs +43 -65
  27. data/crates/kobako-runtime/src/filesystem/overlay/stack/copy_up.rs +11 -16
  28. data/crates/kobako-runtime/src/filesystem/overlay/stack/dir.rs +47 -72
  29. data/crates/kobako-runtime/src/filesystem/overlay/stack/namei.rs +12 -12
  30. data/crates/kobako-runtime/src/filesystem/overlay/stack/readdir.rs +4 -7
  31. data/crates/kobako-runtime/src/filesystem/overlay/stack.rs +120 -37
  32. data/crates/kobako-runtime/src/filesystem/overlay.rs +578 -388
  33. data/crates/kobako-runtime/src/filesystem/pipe.rs +12 -9
  34. data/crates/kobako-runtime/src/filesystem/rdir.rs +14 -50
  35. data/crates/kobako-runtime/src/filesystem/testing.rs +31 -0
  36. data/crates/kobako-runtime/src/filesystem/tmpfs/seed.rs +32 -0
  37. data/crates/kobako-runtime/src/filesystem/tmpfs/tmpfile.rs +3 -3
  38. data/crates/kobako-runtime/src/filesystem/tmpfs/whiteout.rs +57 -35
  39. data/crates/kobako-runtime/src/filesystem/tmpfs/xattr.rs +2 -2
  40. data/crates/kobako-runtime/src/filesystem/tmpfs.rs +219 -173
  41. data/crates/kobako-runtime/src/filesystem/wrap.rs +36 -52
  42. data/crates/kobako-runtime/src/filesystem.rs +8 -3
  43. data/crates/kobako-runtime/src/fork.rs +319 -0
  44. data/crates/kobako-runtime/src/grant.rs +3 -0
  45. data/crates/kobako-runtime/src/hashtable.rs +4 -2
  46. data/crates/kobako-runtime/src/lib.rs +18 -7
  47. data/crates/kobako-runtime/src/limits.rs +171 -0
  48. data/crates/kobako-runtime/src/locking/seqlock.rs +29 -3
  49. data/crates/kobako-runtime/src/locking.rs +518 -113
  50. data/crates/kobako-runtime/src/memcg.rs +306 -0
  51. data/crates/kobako-runtime/src/mount.rs +37 -9
  52. data/crates/kobako-runtime/src/net/backends.rs +43 -0
  53. data/crates/kobako-runtime/src/net/connections.rs +219 -0
  54. data/crates/kobako-runtime/src/net/credential.rs +125 -0
  55. data/crates/kobako-runtime/src/net/egress.rs +180 -0
  56. data/crates/kobako-runtime/src/net/family.rs +181 -0
  57. data/crates/kobako-runtime/src/net/http.rs +3165 -0
  58. data/crates/kobako-runtime/src/net/lookup.rs +385 -0
  59. data/crates/kobako-runtime/src/net/mock.rs +251 -0
  60. data/crates/kobako-runtime/src/net/namespace.rs +1368 -0
  61. data/crates/kobako-runtime/src/net/reactor.rs +626 -0
  62. data/crates/kobako-runtime/src/net/resolv/darwin.rs +280 -0
  63. data/crates/kobako-runtime/src/net/resolv/stub/tests.rs +519 -0
  64. data/crates/kobako-runtime/src/net/resolv/stub.rs +542 -0
  65. data/crates/kobako-runtime/src/net/resolv/windows.rs +218 -0
  66. data/crates/kobako-runtime/src/net/resolv.rs +251 -0
  67. data/crates/kobako-runtime/src/net/skbuff.rs +109 -0
  68. data/crates/kobako-runtime/src/net/socket.rs +869 -0
  69. data/crates/kobako-runtime/src/net/task.rs +223 -0
  70. data/crates/kobako-runtime/src/net/tcp.rs +1840 -0
  71. data/crates/kobako-runtime/src/net/tls.rs +120 -0
  72. data/crates/kobako-runtime/src/net/transport.rs +304 -0
  73. data/crates/kobako-runtime/src/net/udp.rs +1105 -0
  74. data/crates/kobako-runtime/src/net.rs +45 -0
  75. data/crates/kobako-runtime/src/network/builder.rs +177 -0
  76. data/crates/kobako-runtime/src/network/ruleset.rs +777 -0
  77. data/crates/kobako-runtime/src/network.rs +551 -0
  78. data/crates/kobako-runtime/src/policy.rs +16 -0
  79. data/crates/kobako-runtime/src/profile.rs +29 -144
  80. data/crates/kobako-runtime/src/runtime.rs +3 -5
  81. data/crates/kobako-runtime/src/sched.rs +338 -51
  82. data/crates/kobako-runtime/src/security/entry_policy.rs +22 -0
  83. data/crates/kobako-runtime/src/{vfs/cred.rs → security/hooks.rs} +52 -144
  84. data/crates/kobako-runtime/src/security/mount_policy.rs +158 -0
  85. data/crates/kobako-runtime/src/security.rs +125 -209
  86. data/crates/kobako-runtime/src/snapshot.rs +121 -2
  87. data/crates/kobako-runtime/src/vfs/attr.rs +5 -5
  88. data/crates/kobako-runtime/src/vfs/dentry.rs +210 -117
  89. data/crates/kobako-runtime/src/vfs/file.rs +243 -248
  90. data/crates/kobako-runtime/src/vfs/inode.rs +41 -45
  91. data/crates/kobako-runtime/src/vfs/kern_path.rs +62 -53
  92. data/crates/kobako-runtime/src/vfs/mount.rs +10 -9
  93. data/crates/kobako-runtime/src/vfs/namei.rs +1162 -818
  94. data/crates/kobako-runtime/src/vfs/namespace.rs +245 -0
  95. data/crates/kobako-runtime/src/vfs/open_files.rs +69 -0
  96. data/crates/kobako-runtime/src/vfs/openat2.rs +3 -3
  97. data/crates/kobako-runtime/src/vfs/path.rs +6 -6
  98. data/crates/kobako-runtime/src/vfs/readdir.rs +6 -6
  99. data/crates/kobako-runtime/src/vfs/stat.rs +248 -23
  100. data/crates/kobako-runtime/src/vfs/super_block.rs +18 -14
  101. data/crates/kobako-runtime/src/vfs/utimes.rs +37 -27
  102. data/crates/kobako-runtime/src/vfs.rs +10 -6
  103. data/crates/kobako-runtime/src/wait.rs +381 -0
  104. data/crates/kobako-transport/CHANGELOG.md +38 -0
  105. data/crates/kobako-transport/Cargo.toml +1 -1
  106. data/crates/kobako-transport/README.md +3 -4
  107. data/crates/kobako-transport/src/abi.rs +78 -72
  108. data/crates/kobako-transport/src/envelope/bytes.rs +17 -6
  109. data/crates/kobako-transport/src/envelope/call.rs +32 -4
  110. data/crates/kobako-transport/src/envelope/error_record.rs +21 -0
  111. data/crates/kobako-transport/src/envelope/name.rs +99 -0
  112. data/crates/kobako-transport/src/envelope/outcome.rs +9 -9
  113. data/crates/kobako-transport/src/envelope/preamble.rs +24 -21
  114. data/crates/kobako-transport/src/envelope/reply.rs +27 -27
  115. data/crates/kobako-transport/src/envelope/unsupported.rs +10 -10
  116. data/crates/kobako-transport/src/envelope.rs +13 -8
  117. data/crates/kobako-wasmtime/CHANGELOG.md +208 -0
  118. data/crates/kobako-wasmtime/Cargo.toml +47 -7
  119. data/crates/kobako-wasmtime/README.md +4 -3
  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 +18 -37
  123. data/crates/kobako-wasmtime/src/ambient.rs +43 -19
  124. data/crates/kobako-wasmtime/src/cache/unix.rs +95 -0
  125. data/crates/kobako-wasmtime/src/cache/windows.rs +359 -0
  126. data/crates/kobako-wasmtime/src/cache.rs +106 -113
  127. data/crates/kobako-wasmtime/src/config.rs +52 -68
  128. data/crates/kobako-wasmtime/src/driver.rs +80 -82
  129. data/crates/kobako-wasmtime/src/exports.rs +143 -17
  130. data/crates/kobako-wasmtime/src/guest.rs +12 -6
  131. data/crates/kobako-wasmtime/src/guest_binary.rs +14 -0
  132. data/crates/kobako-wasmtime/src/imports.rs +42 -18
  133. data/crates/kobako-wasmtime/src/instance_pre.rs +4 -4
  134. data/crates/kobako-wasmtime/src/invocation.rs +91 -15
  135. data/crates/kobako-wasmtime/src/lib.rs +7 -3
  136. data/crates/kobako-wasmtime/src/limiter.rs +130 -12
  137. data/crates/kobako-wasmtime/src/preview1/descriptors.rs +305 -0
  138. data/crates/kobako-wasmtime/src/preview1/differential/mount.rs +9 -20
  139. data/crates/kobako-wasmtime/src/preview1/differential.rs +27 -31
  140. data/crates/kobako-wasmtime/src/preview1/errno.rs +55 -66
  141. data/crates/kobako-wasmtime/src/preview1/fd.rs +347 -312
  142. data/crates/kobako-wasmtime/src/preview1/memory.rs +21 -12
  143. data/crates/kobako-wasmtime/src/preview1/mount_view/wrap.rs +34 -53
  144. data/crates/kobako-wasmtime/src/preview1/mount_view.rs +335 -388
  145. data/crates/kobako-wasmtime/src/preview1/path.rs +56 -121
  146. data/crates/kobako-wasmtime/src/preview1/poll.rs +255 -125
  147. data/crates/kobako-wasmtime/src/preview1/random.rs +125 -0
  148. data/crates/kobako-wasmtime/src/preview1/sock.rs +10 -8
  149. data/crates/kobako-wasmtime/src/preview1/testing.rs +31 -0
  150. data/crates/kobako-wasmtime/src/preview1/testsuite.rs +5 -15
  151. data/crates/kobako-wasmtime/src/preview1.rs +131 -51
  152. data/crates/kobako-wasmtime/src/preview2/abi.rs +227 -0
  153. data/crates/kobako-wasmtime/src/preview2/error.rs +118 -0
  154. data/crates/kobako-wasmtime/src/preview2/filesystem.rs +122 -0
  155. data/crates/kobako-wasmtime/src/preview2/host.rs +4319 -0
  156. data/crates/kobako-wasmtime/src/preview2/http.rs +1587 -0
  157. data/crates/kobako-wasmtime/src/preview2/io.rs +328 -0
  158. data/crates/kobako-wasmtime/src/preview2/sockets.rs +379 -0
  159. data/crates/kobako-wasmtime/src/preview2/table.rs +257 -0
  160. data/crates/kobako-wasmtime/src/preview2.rs +57 -0
  161. data/crates/kobako-wasmtime/src/trap.rs +88 -28
  162. data/crates/kobako-wasmtime/src/waits.rs +59 -0
  163. data/crates/kobako-wasmtime/src/wasi.rs +291 -81
  164. data/crates/kobako-wasmtime/wit/deps/cli.wit +233 -0
  165. data/crates/kobako-wasmtime/wit/deps/clocks.wit +162 -0
  166. data/crates/kobako-wasmtime/wit/deps/filesystem.wit +589 -0
  167. data/crates/kobako-wasmtime/wit/deps/http.wit +733 -0
  168. data/crates/kobako-wasmtime/wit/deps/io.wit +299 -0
  169. data/crates/kobako-wasmtime/wit/deps/random.wit +92 -0
  170. data/crates/kobako-wasmtime/wit/deps/sockets.wit +949 -0
  171. data/crates/kobako-wasmtime/witx/wasi_snapshot_preview1.witx +13 -0
  172. data/data/kobako.wasm +0 -0
  173. data/ext/kobako/Cargo.toml +6 -2
  174. data/ext/kobako/src/{runtime/errors.rs → errors.rs} +34 -26
  175. data/ext/kobako/src/escape.rs +404 -0
  176. data/ext/kobako/src/{runtime/filesystem → filesystem}/grants.rs +34 -32
  177. data/ext/kobako/src/{runtime/filesystem → filesystem}/ruby.rs +158 -170
  178. data/ext/kobako/src/{runtime/filesystem.rs → filesystem.rs} +71 -23
  179. data/ext/kobako/src/fork.rs +72 -0
  180. data/ext/kobako/src/gvl.rs +729 -0
  181. data/ext/kobako/src/handoff.rs +490 -0
  182. data/ext/kobako/src/lib.rs +74 -3
  183. data/ext/kobako/src/network/mock.rs +187 -0
  184. data/ext/kobako/src/network.rs +593 -0
  185. data/ext/kobako/src/pinned_value.rs +44 -0
  186. data/ext/kobako/src/runtime/bridge.rs +58 -50
  187. data/ext/kobako/src/runtime/snapshot.rs +4 -4
  188. data/ext/kobako/src/runtime.rs +272 -163
  189. data/ext/kobako/src/wire.rs +42 -0
  190. data/lib/kobako/catalog/extensions.rb +14 -2
  191. data/lib/kobako/catalog/flags.rb +3 -5
  192. data/lib/kobako/catalog/grants.rb +5 -4
  193. data/lib/kobako/catalog/handles.rb +14 -32
  194. data/lib/kobako/catalog/mount.rb +11 -3
  195. data/lib/kobako/catalog/network.rb +35 -0
  196. data/lib/kobako/catalog/replacements.rb +28 -0
  197. data/lib/kobako/catalog/services.rb +5 -19
  198. data/lib/kobako/catalog/snippets.rb +3 -18
  199. data/lib/kobako/catalog.rb +3 -0
  200. data/lib/kobako/codec/{utils.rb → boundary.rb} +4 -2
  201. data/lib/kobako/codec/decoder.rb +5 -5
  202. data/lib/kobako/codec/ext_types.rb +3 -3
  203. data/lib/kobako/codec/handle_walk.rb +3 -43
  204. data/lib/kobako/codec/state.rb +2 -18
  205. data/lib/kobako/codec/value_budget.rb +133 -41
  206. data/lib/kobako/codec.rb +6 -7
  207. data/lib/kobako/context.rb +24 -11
  208. data/lib/kobako/errors.rb +18 -18
  209. data/lib/kobako/extension.rb +3 -2
  210. data/lib/kobako/filesystem.rb +10 -3
  211. data/lib/kobako/fork.rb +42 -0
  212. data/lib/kobako/handle.rb +2 -3
  213. data/lib/kobako/names.rb +28 -0
  214. data/lib/kobako/network.rb +210 -0
  215. data/lib/kobako/outcome.rb +7 -7
  216. data/lib/kobako/runtime.rb +3 -2
  217. data/lib/kobako/sandbox.rb +73 -35
  218. data/lib/kobako/sandbox_options.rb +42 -109
  219. data/lib/kobako/transport/argument_wrap.rb +64 -0
  220. data/lib/kobako/transport/block_failure.rb +1 -1
  221. data/lib/kobako/transport/dispatcher.rb +6 -6
  222. data/lib/kobako/transport/exposure.rb +26 -15
  223. data/lib/kobako/transport/reflection.rb +21 -4
  224. data/lib/kobako/transport/run.rb +8 -23
  225. data/lib/kobako/transport/yielder.rb +2 -9
  226. data/lib/kobako/transport.rb +1 -0
  227. data/lib/kobako/usage.rb +4 -2
  228. data/lib/kobako/version.rb +1 -1
  229. data/lib/kobako.rb +8 -4
  230. data/release-please-config.json +15 -0
  231. data/sig/kobako/catalog/extensions.rbs +2 -0
  232. data/sig/kobako/catalog/grants.rbs +7 -4
  233. data/sig/kobako/catalog/handles.rbs +2 -2
  234. data/sig/kobako/catalog/mount.rbs +3 -1
  235. data/sig/kobako/catalog/network.rbs +20 -0
  236. data/sig/kobako/catalog/replacements.rbs +14 -0
  237. data/sig/kobako/catalog/services.rbs +0 -4
  238. data/sig/kobako/catalog/snippets.rbs +0 -2
  239. data/sig/kobako/codec/{utils.rbs → boundary.rbs} +2 -2
  240. data/sig/kobako/codec/handle_walk.rbs +0 -6
  241. data/sig/kobako/codec/state.rbs +0 -4
  242. data/sig/kobako/codec/value_budget.rbs +48 -5
  243. data/sig/kobako/codec.rbs +2 -2
  244. data/sig/kobako/context.rbs +3 -1
  245. data/sig/kobako/errors.rbs +4 -7
  246. data/sig/kobako/filesystem.rbs +21 -3
  247. data/sig/kobako/fork.rbs +17 -0
  248. data/sig/kobako/network.rbs +115 -0
  249. data/sig/kobako/outcome.rbs +1 -1
  250. data/sig/kobako/runtime.rbs +32 -3
  251. data/sig/kobako/sandbox.rbs +10 -2
  252. data/sig/kobako/sandbox_options.rbs +29 -40
  253. data/sig/kobako/transport/argument_wrap.rbs +15 -0
  254. data/sig/kobako/transport/error.rbs +1 -1
  255. data/sig/kobako/transport/exposure.rbs +2 -4
  256. data/sig/kobako/transport/reflection.rbs +10 -0
  257. data/sig/kobako/transport/run.rbs +0 -2
  258. data/sig/kobako/transport/yielder.rbs +0 -3
  259. data/sig/kobako/transport.rbs +1 -1
  260. data/sig/kobako.rbs +13 -0
  261. metadata +97 -37
  262. data/crates/kobako-runtime/src/endpoint/capture.rs +0 -115
  263. data/crates/kobako-runtime/src/endpoint/memory_cap.rs +0 -238
  264. data/crates/kobako-runtime/src/filesystem/path.rs +0 -21
  265. data/crates/kobako-runtime/src/vfs/errno.rs +0 -153
  266. data/crates/kobako-runtime/tests/linux_baseline/calls.rs +0 -171
  267. data/crates/kobako-runtime/tests/linux_baseline/concurrent.rs +0 -276
  268. data/crates/kobako-runtime/tests/linux_baseline/kobako.rs +0 -323
  269. data/crates/kobako-runtime/tests/linux_baseline/linux-baseline-expected.txt +0 -16
  270. data/crates/kobako-runtime/tests/linux_baseline/linux.rs +0 -449
  271. data/crates/kobako-runtime/tests/linux_baseline/main.rs +0 -611
  272. data/crates/kobako-runtime/tests/linux_baseline/permissions.rs +0 -236
  273. data/crates/kobako-wasmtime/src/descriptors.rs +0 -200
  274. data/crates/kobako-wasmtime/tests/integration/compile_posture.rs +0 -43
  275. data/crates/kobako-wasmtime/tests/integration/guest_file.rs +0 -1085
  276. data/crates/kobako-wasmtime/tests/integration/main.rs +0 -29
  277. data/crates/kobako-wasmtime/tests/integration/preamble_flags.rs +0 -70
  278. data/crates/kobako-wasmtime/tests/integration/snippet_compile.rs +0 -95
  279. data/crates/kobako-wasmtime/tests/integration/support/mod.rs +0 -30
  280. data/crates/kobako-wasmtime/tests/integration/unanswered_call.rs +0 -86
  281. data/crates/kobako-wasmtime/tests/integration/unsupported_call.rs +0 -51
  282. data/ext/kobako/src/runtime/escape.rs +0 -67
  283. data/ext/kobako/src/runtime/gvl.rs +0 -147
  284. data/ext/kobako/src/runtime/pinned_value.rs +0 -31
  285. data/lib/kobako/constant_name.rb +0 -8
  286. data/lib/kobako/pool.rb +0 -140
  287. data/sig/kobako/constant_name.rbs +0 -3
  288. data/sig/kobako/pool.rbs +0 -42
@@ -16,16 +16,18 @@ use std::time::{Duration, SystemTime, UNIX_EPOCH};
16
16
 
17
17
  use kobako_runtime::filesystem::Rdir;
18
18
  use kobako_runtime::filesystem::{
19
- DentryOperations, DirEntry, FileOperations, FileSystemType, FileType, Filesystem,
20
- FilesystemError, Finish, Iattr, InodeOperations, Kiocb, Kstat, Lookup, OpenHow, RenameFlag,
19
+ DentryOperations, DirEntry, FileOperations, FileSystemType, FileType, Filesystem, Finish,
20
+ Iattr, InodeOperations, Kiocb, Kstat, Lookup, OpenHow, RenameFlag,
21
21
  };
22
22
  use kobako_runtime::vfs::{
23
- generic_file_llseek, generic_read_dir, generic_write_sync, verify_dirent_name, Dentry,
24
- DirContext, Identity, Inode, Whence, NAME_MAX,
23
+ generic_file_llseek, generic_read_dir, generic_write_sync, get_anon_bdev, verify_dirent_name,
24
+ Dentry, DirContext, Identity, Inode, Whence, NAME_MAX,
25
25
  };
26
+ use kobako_runtime::Errno;
26
27
 
27
- use crate::runtime::pinned_value::PinnedValue;
28
- use crate::runtime::{escape, gvl};
28
+ use crate::errors::errno_of;
29
+ use crate::pinned_value::PinnedValue;
30
+ use crate::{escape, gvl};
29
31
 
30
32
  /// The Ruby object behind a Mount or a Layer. Whatever holds it on the
31
33
  /// Ruby side keeps it alive and in place: the invocation pinning its
@@ -39,39 +41,43 @@ pub(crate) struct RubyFilesystem {
39
41
  /// The device a stat without a `dev` names, the object's own, shared by
40
42
  /// every directory opened beneath it.
41
43
  dev: u64,
44
+ /// Whether the object's `exclusive?` answers true.
45
+ exclusive: bool,
42
46
  }
43
47
 
44
48
  impl RubyFilesystem {
45
- /// The object as a Filesystem, when it answers `open` and `stat`.
46
- pub(crate) fn from_value(value: Value) -> Option<Self> {
49
+ /// The object as a Filesystem, when it answers `open` and `stat`; what
50
+ /// its `exclusive?` raises comes back to the mount.
51
+ pub(crate) fn from_value(value: Value) -> Result<Option<Self>, magnus::Error> {
47
52
  let answers = |name| value.respond_to(name, false).unwrap_or(false);
48
- (answers("open") && answers("stat")).then(|| Self {
53
+ if !(answers("open") && answers("stat")) {
54
+ return Ok(None);
55
+ }
56
+ let exclusive =
57
+ answers("exclusive?") && value.funcall::<_, _, Value>("exclusive?", ())?.to_bool();
58
+ Ok(Some(Self {
49
59
  object: Opaque::from(value),
50
- dev: Kstat::unique_device(),
51
- })
60
+ dev: get_anon_bdev(),
61
+ exclusive,
62
+ }))
52
63
  }
53
64
 
54
65
  /// What the object's `stat` answers for `path`.
55
- fn stat(&self, path: String) -> Result<Kstat, FilesystemError> {
66
+ fn stat(&self, path: String) -> Result<Kstat, Errno> {
56
67
  let own_dev = self.dev;
57
- ask(
58
- self.object,
59
- "stat",
60
- FilesystemError::Unsupported,
61
- |_, fs| {
62
- let stat: Value = fs.funcall("stat", (path,))?;
63
- let kstat = Kstat::new(kind_of(stat)?, stat.funcall("size", ())?);
64
- // A stat names its identity as `File::Stat` does; without a
65
- // `dev` the Filesystem stands for a device of its own, so it
66
- // shares an identity with no other Filesystem.
67
- let dev = if stat.respond_to("dev", false)? {
68
- stat.funcall("dev", ())?
69
- } else {
70
- own_dev
71
- };
72
- with_stat_record(stat, kstat.with_identity(dev, stat.funcall("ino", ())?))
73
- },
74
- )
68
+ ask(self.object, "stat", Errno::Unsupported, |_, fs| {
69
+ let stat: Value = fs.funcall("stat", (path,))?;
70
+ let kstat = Kstat::new(kind_of(stat)?, stat.funcall("size", ())?);
71
+ // A stat names its identity as `File::Stat` does; without a
72
+ // `dev` the Filesystem stands for a device of its own, so it
73
+ // shares an identity with no other Filesystem.
74
+ let dev = if stat.respond_to("dev", false)? {
75
+ stat.funcall("dev", ())?
76
+ } else {
77
+ own_dev
78
+ };
79
+ with_stat_record(stat, kstat.with_identity(dev, stat.funcall("ino", ())?))
80
+ })
75
81
  }
76
82
  }
77
83
 
@@ -115,9 +121,9 @@ fn with_stat_record(stat: Value, kstat: Kstat) -> Result<Kstat, MagnusError> {
115
121
  fn ask<T>(
116
122
  object: Opaque<Value>,
117
123
  name: &str,
118
- missing: FilesystemError,
124
+ missing: Errno,
119
125
  answer: impl FnOnce(&Ruby, Value) -> Result<T, MagnusError>,
120
- ) -> Result<T, FilesystemError> {
126
+ ) -> Result<T, Errno> {
121
127
  ask_or(object, name, Err(missing), answer)
122
128
  }
123
129
 
@@ -125,9 +131,9 @@ fn ask<T>(
125
131
  fn ask_or<T>(
126
132
  object: Opaque<Value>,
127
133
  name: &str,
128
- missing: Result<T, FilesystemError>,
134
+ missing: Result<T, Errno>,
129
135
  answer: impl FnOnce(&Ruby, Value) -> Result<T, MagnusError>,
130
- ) -> Result<T, FilesystemError> {
136
+ ) -> Result<T, Errno> {
131
137
  gvl::reenter(|| {
132
138
  let ruby = Ruby::get().expect("Ruby handle unavailable in a Filesystem call");
133
139
  let object: Value = ruby.get_inner(object);
@@ -137,9 +143,11 @@ fn ask_or<T>(
137
143
  answer(&ruby, object).map_err(|err| match escape::hold(&ruby, err) {
138
144
  Err(err) => to_error(err),
139
145
  // The invocation ends before the guest reads this.
140
- Ok(()) => FilesystemError::Other(String::new()),
146
+ Ok(()) => Errno::Other(String::new()),
141
147
  })
142
148
  })
149
+ // Nothing of the run's caller is left to ask.
150
+ .unwrap_or_else(|| Err(Errno::Other(String::new())))
143
151
  }
144
152
 
145
153
  /// Ask `object` a change, answering nothing more than whether it was made.
@@ -147,8 +155,8 @@ fn change(
147
155
  object: Opaque<Value>,
148
156
  name: &str,
149
157
  args: impl magnus::ArgList,
150
- missing: FilesystemError,
151
- ) -> Result<(), FilesystemError> {
158
+ missing: Errno,
159
+ ) -> Result<(), Errno> {
152
160
  ask(object, name, missing, |_, object| {
153
161
  object.funcall::<_, _, Value>(name, args).map(drop)
154
162
  })
@@ -157,27 +165,18 @@ fn change(
157
165
  /// Ask `object` a change it may lack, an object lacking `name` having
158
166
  /// nothing of its own to change, while one that answers and refuses still
159
167
  /// fails, whatever `Errno` it raises.
160
- fn change_if_answered(object: Opaque<Value>, name: &str) -> Result<(), FilesystemError> {
168
+ fn change_if_answered(object: Opaque<Value>, name: &str) -> Result<(), Errno> {
161
169
  ask_or(object, name, Ok(()), |_, object| {
162
170
  object.funcall::<_, _, Value>(name, ()).map(drop)
163
171
  })
164
172
  }
165
173
 
166
- /// The FilesystemError the nearest `Errno` class of `err` stands for, by
167
- /// its POSIX name; anything else is `Other`, which reaches the guest as
168
- /// `EIO`.
169
- fn to_error(err: MagnusError) -> FilesystemError {
170
- let named = err.value().and_then(|exception| {
171
- exception
172
- .class()
173
- .ancestors()
174
- .into_iter()
175
- .find_map(|module| {
176
- let name: Option<String> = module.funcall("name", ()).ok()?;
177
- FilesystemError::from_posix_name(name?.strip_prefix("Errno::")?)
178
- })
179
- });
180
- named.unwrap_or_else(|| FilesystemError::Other(err.to_string()))
174
+ /// What the nearest Ruby `Errno` class of `err` stands for; anything else is
175
+ /// `Other`, which reaches the guest as `EIO`.
176
+ fn to_error(err: MagnusError) -> Errno {
177
+ err.value()
178
+ .and_then(|exception| errno_of(exception.class()))
179
+ .unwrap_or_else(|| Errno::Other(err.to_string()))
181
180
  }
182
181
 
183
182
  /// `File::Constants` flags for `how`, read from Ruby since their
@@ -245,17 +244,12 @@ impl RubyFilesystem {
245
244
  dentry: &Dentry,
246
245
  how: &OpenHow,
247
246
  create: bool,
248
- ) -> Result<Box<dyn FileOperations>, FilesystemError> {
247
+ ) -> Result<Box<dyn FileOperations>, Errno> {
249
248
  let path = path_of(dentry);
250
- let file = ask(
251
- self.object,
252
- "open",
253
- FilesystemError::Unsupported,
254
- |ruby, fs| {
255
- let file: Value = fs.funcall("open", (path, to_flags(ruby, how, create)?))?;
256
- Ok(RubyFile::pin(ruby, file))
257
- },
258
- )?;
249
+ let file = ask(self.object, "open", Errno::Unsupported, |ruby, fs| {
250
+ let file: Value = fs.funcall("open", (path, to_flags(ruby, how, create)?))?;
251
+ Ok(RubyFile::pin(file))
252
+ })?;
259
253
  match dentry.inode().map(|inode| inode.identity()) {
260
254
  None => {
261
255
  let made = self.stat(path_of(dentry))?;
@@ -265,12 +259,12 @@ impl RubyFilesystem {
265
259
  // another entry than the one judged, as `Bind::open_file` finds.
266
260
  Some(Some(identity)) => {
267
261
  if Identity::of(&self.stat(path_of(dentry))?) != Some(identity) {
268
- return Err(FilesystemError::NotFound);
262
+ return Err(Errno::NotFound);
269
263
  }
270
264
  }
271
265
  Some(None) => {}
272
266
  }
273
- let inode = dentry.inode().ok_or(FilesystemError::NotFound)?;
267
+ let inode = dentry.inode().ok_or(Errno::NotFound)?;
274
268
  let kept = inode
275
269
  .private()
276
270
  .get_or_init(|| Arc::new(OpenRubyFile::default()))
@@ -285,21 +279,19 @@ impl RubyFilesystem {
285
279
  /// about, as it could name a path the object would answer for, and a name
286
280
  /// gone by the time it is asked about is one the listing no longer holds, as
287
281
  /// any listing is a moment that may have passed.
288
- fn entries_at(&self, dentry: &Dentry) -> Result<Vec<DirEntry>, FilesystemError> {
282
+ fn entries_at(&self, dentry: &Dentry) -> Result<Vec<DirEntry>, Errno> {
289
283
  let at = path_of(dentry);
290
- let names: Vec<String> = ask(
291
- self.object,
292
- "children",
293
- FilesystemError::Unsupported,
294
- |_, fs| fs.funcall("children", (at.as_str(),)),
295
- )?;
284
+ let names: Vec<String> = ask(self.object, "children", Errno::Unsupported, |_, fs| {
285
+ fs.funcall("children", (at.as_str(),))
286
+ })?;
296
287
  names.iter().try_for_each(|name| verify_dirent_name(name))?;
297
288
  let mut entries = Vec::with_capacity(names.len());
298
289
  for name in names {
290
+ kobako_runtime::sched::stop_if_fatal()?;
299
291
  match self.stat(join(&at, &name)) {
300
292
  Ok(stat) => entries
301
293
  .push(DirEntry::new(name, stat.file_type).with_identity(stat.dev, stat.ino)),
302
- Err(FilesystemError::NotFound) => {}
294
+ Err(Errno::NotFound) => {}
303
295
  Err(err) => return Err(err),
304
296
  }
305
297
  }
@@ -312,12 +304,12 @@ impl RubyFilesystem {
312
304
  struct RubyLink(RubyFilesystem);
313
305
 
314
306
  impl InodeOperations for RubyLink {
315
- fn getattr(&self, dentry: &Dentry) -> Result<Kstat, FilesystemError> {
307
+ fn getattr(&self, dentry: &Dentry) -> Result<Kstat, Errno> {
316
308
  self.0.stat(path_of(dentry))
317
309
  }
318
310
 
319
- fn get_link(&self, _dentry: &Dentry) -> Result<String, FilesystemError> {
320
- Err(FilesystemError::FilesystemLoop)
311
+ fn get_link(&self, _dentry: &Dentry) -> Result<String, Errno> {
312
+ Err(Errno::FilesystemLoop)
321
313
  }
322
314
  }
323
315
 
@@ -328,23 +320,18 @@ impl InodeOperations for RubyRegular {
328
320
  /// A file open here answers for itself even once its name is gone, as 9p
329
321
  /// asks an open fid: its `size`, and its `stat` where it has one. It stays
330
322
  /// the entry its lookup recorded; anything else is asked by its path.
331
- fn getattr(&self, dentry: &Dentry) -> Result<Kstat, FilesystemError> {
323
+ fn getattr(&self, dentry: &Dentry) -> Result<Kstat, Errno> {
332
324
  let Some(file) = find_open_file(dentry) else {
333
325
  return self.0.stat(path_of(dentry));
334
326
  };
335
- let metadata = ask(
336
- file.get(),
337
- "size",
338
- FilesystemError::Unsupported,
339
- |_, file| {
340
- let metadata = Kstat::new(FileType::RegFile, file.funcall("size", ())?);
341
- if file.respond_to("stat", false)? {
342
- with_stat_record(file.funcall("stat", ())?, metadata)
343
- } else {
344
- Ok(metadata)
345
- }
346
- },
347
- )?;
327
+ let metadata = ask(file.get(), "size", Errno::Unsupported, |_, file| {
328
+ let metadata = Kstat::new(FileType::RegFile, file.funcall("size", ())?);
329
+ if file.respond_to("stat", false)? {
330
+ with_stat_record(file.funcall("stat", ())?, metadata)
331
+ } else {
332
+ Ok(metadata)
333
+ }
334
+ })?;
348
335
  Ok(match dentry.inode().and_then(|inode| inode.identity()) {
349
336
  Some(identity) => identity.onto(metadata),
350
337
  None => metadata,
@@ -354,27 +341,18 @@ impl InodeOperations for RubyRegular {
354
341
  /// A Ruby object was handed `TRUNC` as it opened the file, so an open asking
355
342
  /// to truncate has nothing left to ask, as `fuse_do_setattr` finds with
356
343
  /// `atomic_o_trunc`.
357
- fn setattr(&self, dentry: &Dentry, attr: &Iattr) -> Result<(), FilesystemError> {
344
+ fn setattr(&self, dentry: &Dentry, attr: &Iattr) -> Result<(), Errno> {
358
345
  let Some(len) = attr.size else {
359
- return Err(FilesystemError::Unsupported);
346
+ return Err(Errno::Unsupported);
360
347
  };
361
348
  if attr.open {
362
349
  return Ok(());
363
350
  }
364
- let file = find_open_file(dentry).ok_or(FilesystemError::InvalidInput)?;
365
- change(
366
- file.get(),
367
- "truncate",
368
- (len,),
369
- FilesystemError::ReadOnlyFilesystem,
370
- )
351
+ let file = find_open_file(dentry).ok_or(Errno::InvalidInput)?;
352
+ change(file.get(), "truncate", (len,), Errno::ReadOnlyFilesystem)
371
353
  }
372
354
 
373
- fn open(
374
- &self,
375
- dentry: &Dentry,
376
- how: &OpenHow,
377
- ) -> Result<Box<dyn FileOperations>, FilesystemError> {
355
+ fn open(&self, dentry: &Dentry, how: &OpenHow) -> Result<Box<dyn FileOperations>, Errno> {
378
356
  self.0.open_at(dentry, how, false)
379
357
  }
380
358
  }
@@ -382,7 +360,7 @@ impl InodeOperations for RubyRegular {
382
360
  /// Its root reports no identity without asking the Ruby object, as FUSE makes its
383
361
  /// root from fixed attributes rather than ask the server.
384
362
  impl FileSystemType for RubyFilesystem {
385
- fn fill_super(self: Arc<Self>, sb: &mut Filesystem) -> Result<(), FilesystemError> {
363
+ fn fill_super(self: Arc<Self>, sb: &mut Filesystem) -> Result<(), Errno> {
386
364
  sb.set_default_d_op(self.clone());
387
365
  sb.d_make_root(Inode::new(&Kstat::new(FileType::Dir, 0), self));
388
366
  Ok(())
@@ -392,15 +370,15 @@ impl FileSystemType for RubyFilesystem {
392
370
  /// A directory of a Ruby Filesystem, asked by the path a dentry stands at, the
393
371
  /// path a Policy judges.
394
372
  impl InodeOperations for RubyFilesystem {
395
- fn getattr(&self, dentry: &Dentry) -> Result<Kstat, FilesystemError> {
373
+ fn getattr(&self, dentry: &Dentry) -> Result<Kstat, Errno> {
396
374
  self.stat(path_of(dentry))
397
375
  }
398
376
 
399
377
  /// A Ruby object matches names exactly, as its contract asks. A lookup
400
378
  /// asks its `stat` what stands at the name, as FUSE asks its daemon.
401
- fn lookup(&self, dentry: &Dentry) -> Result<Lookup, FilesystemError> {
379
+ fn lookup(&self, dentry: &Dentry) -> Result<Lookup, Errno> {
402
380
  if dentry.name().len() > NAME_MAX {
403
- return Err(FilesystemError::InvalidFilename);
381
+ return Err(Errno::InvalidFilename);
404
382
  }
405
383
  match self.stat(path_of(dentry)) {
406
384
  Ok(found) => {
@@ -411,18 +389,14 @@ impl InodeOperations for RubyFilesystem {
411
389
  };
412
390
  Ok(Lookup::Found(Inode::new(&found, ops)))
413
391
  }
414
- Err(FilesystemError::NotFound) => Ok(Lookup::Absent),
392
+ Err(Errno::NotFound) => Ok(Lookup::Absent),
415
393
  Err(err) => Err(err),
416
394
  }
417
395
  }
418
396
 
419
397
  /// A directory opens without asking the object anything; it is asked
420
398
  /// for the names only when the guest lists them.
421
- fn open(
422
- &self,
423
- _dentry: &Dentry,
424
- _how: &OpenHow,
425
- ) -> Result<Box<dyn FileOperations>, FilesystemError> {
399
+ fn open(&self, _dentry: &Dentry, _how: &OpenHow) -> Result<Box<dyn FileOperations>, Errno> {
426
400
  Ok(Box::new(RubyDir(*self, Rdir::default())))
427
401
  }
428
402
 
@@ -430,7 +404,7 @@ impl InodeOperations for RubyFilesystem {
430
404
  /// name is left to the runtime unless the open may make it and nothing
431
405
  /// stands there, as FUSE's `fuse_atomic_open` looks the name up before it
432
406
  /// creates.
433
- fn atomic_open(&self, dentry: &Dentry, how: &OpenHow) -> Result<Finish, FilesystemError> {
407
+ fn atomic_open(&self, dentry: &Dentry, how: &OpenHow) -> Result<Finish, Errno> {
434
408
  if dentry.in_lookup() {
435
409
  let found = self.lookup(dentry)?;
436
410
  if !how.create || !matches!(found, Lookup::Absent) {
@@ -447,30 +421,30 @@ impl InodeOperations for RubyFilesystem {
447
421
  })
448
422
  }
449
423
 
450
- fn mkdir(&self, dentry: &Dentry) -> Result<(), FilesystemError> {
424
+ fn mkdir(&self, dentry: &Dentry) -> Result<(), Errno> {
451
425
  change(
452
426
  self.object,
453
427
  "mkdir",
454
428
  (path_of(dentry),),
455
- FilesystemError::ReadOnlyFilesystem,
429
+ Errno::ReadOnlyFilesystem,
456
430
  )
457
431
  }
458
432
 
459
- fn rmdir(&self, dentry: &Dentry) -> Result<(), FilesystemError> {
433
+ fn rmdir(&self, dentry: &Dentry) -> Result<(), Errno> {
460
434
  change(
461
435
  self.object,
462
436
  "rmdir",
463
437
  (path_of(dentry),),
464
- FilesystemError::ReadOnlyFilesystem,
438
+ Errno::ReadOnlyFilesystem,
465
439
  )
466
440
  }
467
441
 
468
- fn unlink(&self, dentry: &Dentry) -> Result<(), FilesystemError> {
442
+ fn unlink(&self, dentry: &Dentry) -> Result<(), Errno> {
469
443
  change(
470
444
  self.object,
471
445
  "unlink",
472
446
  (path_of(dentry),),
473
- FilesystemError::ReadOnlyFilesystem,
447
+ Errno::ReadOnlyFilesystem,
474
448
  )
475
449
  }
476
450
 
@@ -479,19 +453,19 @@ impl InodeOperations for RubyFilesystem {
479
453
  /// directories are of one object, which their shared device names.
480
454
  fn rename(
481
455
  &self,
482
- from: &Dentry,
483
- _to_dir: &dyn InodeOperations,
484
- to: &Dentry,
485
- flag: Option<RenameFlag>,
486
- ) -> Result<(), FilesystemError> {
487
- if flag.is_some() {
488
- return Err(FilesystemError::InvalidInput);
456
+ old: &Dentry,
457
+ _new_dir: &dyn InodeOperations,
458
+ new: &Dentry,
459
+ flags: Option<RenameFlag>,
460
+ ) -> Result<(), Errno> {
461
+ if flags.is_some() {
462
+ return Err(Errno::InvalidInput);
489
463
  }
490
464
  change(
491
465
  self.object,
492
466
  "rename",
493
- (path_of(from), path_of(to)),
494
- FilesystemError::ReadOnlyFilesystem,
467
+ (path_of(old), path_of(new)),
468
+ Errno::ReadOnlyFilesystem,
495
469
  )
496
470
  }
497
471
  }
@@ -507,30 +481,30 @@ impl FileOperations for RubyDir {
507
481
  pos: u64,
508
482
  offset: i64,
509
483
  whence: Whence,
510
- ) -> Result<u64, FilesystemError> {
484
+ ) -> Result<u64, Errno> {
511
485
  generic_file_llseek(dentry, pos, offset, whence)
512
486
  }
513
487
 
514
- fn read_iter(&mut self, _iocb: &mut Kiocb, _buf: &mut [u8]) -> Result<usize, FilesystemError> {
488
+ fn read_iter(&mut self, _iocb: &mut Kiocb, _buf: &mut [u8]) -> Result<usize, Errno> {
515
489
  generic_read_dir()
516
490
  }
517
491
 
492
+ fn has_iterate_shared(&self) -> bool {
493
+ true
494
+ }
495
+
518
496
  /// What a listing began with stays on the open directory until it ends, so
519
497
  /// a caller reading in small steps asks the object once, as FUSE's readdir
520
498
  /// cache spares asking the server each time.
521
- fn iterate_shared(
522
- &mut self,
523
- dentry: &Dentry,
524
- ctx: &mut DirContext<'_>,
525
- ) -> Result<(), FilesystemError> {
499
+ fn iterate_shared(&mut self, dentry: &Dentry, ctx: &mut DirContext<'_>) -> Result<(), Errno> {
526
500
  let filesystem = self.0;
527
501
  self.1
528
- .iterate(dentry, ctx, || filesystem.entries_at(dentry))
502
+ .iterate_shared(dentry, ctx, || filesystem.entries_at(dentry))
529
503
  }
530
504
 
531
505
  /// The object has nothing of a directory's own to flush, as FUSE's
532
506
  /// `fuse_dir_fsync` answers for a server without `fsyncdir`.
533
- fn fsync(&mut self, _datasync: bool) -> Result<(), FilesystemError> {
507
+ fn fsync(&mut self, _datasync: bool) -> Result<(), Errno> {
534
508
  Ok(())
535
509
  }
536
510
  }
@@ -562,37 +536,42 @@ fn find_open_file(dentry: &Dentry) -> Option<Arc<PinnedValue>> {
562
536
 
563
537
  /// The backend changes outside the runtime, so a dentry someone holds is
564
538
  /// asked again, as FUSE compares what a fresh lookup finds, and one no longer
565
- /// naming what it recorded gets a new one. An open file answers for itself,
566
- /// so a walk finding a dentry one is open on takes one of its own.
539
+ /// naming what it recorded gets a new one. An object whose `exclusive?` answers
540
+ /// true vouches that only the guest changes it, so what was found stands, as
541
+ /// gVisor's exclusive mount skips revalidation. An open file answers for
542
+ /// itself, so a walk finding a dentry one is open on takes one of its own.
567
543
  impl DentryOperations for RubyFilesystem {
568
- fn revalidate(
569
- &self,
570
- _dir: &dyn InodeOperations,
571
- dentry: &Dentry,
572
- ) -> Result<bool, FilesystemError> {
573
- let Some(inode) = dentry.inode().filter(|_| find_open_file(dentry).is_none()) else {
544
+ fn revalidate(&self, _dir: &dyn InodeOperations, dentry: &Dentry) -> Result<bool, Errno> {
545
+ if find_open_file(dentry).is_some() {
546
+ return Ok(false);
547
+ }
548
+ if self.exclusive {
549
+ return Ok(true);
550
+ }
551
+ let Some(inode) = dentry.inode() else {
574
552
  return Ok(false);
575
553
  };
576
554
  match self.stat(path_of(dentry)) {
577
- Ok(found) => {
578
- Ok(Identity::of(&found) == inode.identity() && found.file_type == inode.kind())
579
- }
580
- Err(FilesystemError::NotFound | FilesystemError::NotADirectory) => Ok(false),
555
+ Ok(found) => Ok(
556
+ Identity::of(&found) == inode.identity() && found.file_type == inode.file_type()
557
+ ),
558
+ Err(Errno::NotFound | Errno::NotADirectory) => Ok(false),
581
559
  Err(err) => Err(err),
582
560
  }
583
561
  }
584
562
 
585
563
  /// Answering whether a name holds costs a `stat`, as finding it does, so
586
- /// nothing is gained by keeping it, as FUSE's `entry_timeout=0` keeps none.
564
+ /// nothing is gained by keeping it, as FUSE's `entry_timeout=0` keeps none;
565
+ /// an exclusive one keeps every name, as nothing asks again.
587
566
  fn delete(&self, _dentry: &Dentry) -> bool {
588
- true
567
+ !self.exclusive
589
568
  }
590
569
  }
591
570
 
592
571
  impl RubyFile {
593
- fn pin(ruby: &Ruby, file: Value) -> Self {
572
+ fn pin(file: Value) -> Self {
594
573
  Self {
595
- file: Arc::new(PinnedValue::new(ruby, file)),
574
+ file: Arc::new(PinnedValue::new(file)),
596
575
  closed: false,
597
576
  }
598
577
  }
@@ -601,17 +580,17 @@ impl RubyFile {
601
580
  /// answers where the file then ends, as `IO#pos` does after a write to
602
581
  /// a file opened to append. A file lacking it cannot append, since its
603
582
  /// `size` and `pwrite` are two steps another writer can land between.
604
- fn pwrite(&mut self, iocb: &mut Kiocb, buf: &[u8]) -> Result<usize, FilesystemError> {
583
+ fn pwrite(&mut self, iocb: &mut Kiocb, buf: &[u8]) -> Result<usize, Errno> {
605
584
  let pos = iocb.pos;
606
585
  let written = ask(
607
586
  self.file.get(),
608
587
  "pwrite",
609
- FilesystemError::ReadOnlyFilesystem,
588
+ Errno::ReadOnlyFilesystem,
610
589
  |ruby, file| file.funcall("pwrite", (ruby.str_from_slice(buf), pos)),
611
590
  )
612
591
  .and_then(|written: usize| match written {
613
592
  written if written <= buf.len() => Ok(written),
614
- written => Err(FilesystemError::Other(format!(
593
+ written => Err(Errno::Other(format!(
615
594
  "pwrite answered {written} bytes written of the {} it was handed",
616
595
  buf.len()
617
596
  ))),
@@ -620,15 +599,15 @@ impl RubyFile {
620
599
  Ok(written)
621
600
  }
622
601
 
623
- fn append(&mut self, iocb: &mut Kiocb, buf: &[u8]) -> Result<usize, FilesystemError> {
602
+ fn append(&mut self, iocb: &mut Kiocb, buf: &[u8]) -> Result<usize, Errno> {
624
603
  let end: u64 = ask(
625
604
  self.file.get(),
626
605
  "append",
627
- FilesystemError::Unsupported,
606
+ Errno::Unsupported,
628
607
  |ruby, file| file.funcall("append", (ruby.str_from_slice(buf),)),
629
608
  )?;
630
609
  if end < buf.len() as u64 {
631
- return Err(FilesystemError::Other(format!(
610
+ return Err(Errno::Other(format!(
632
611
  "append answered the file ending at {end}, before the {} bytes it wrote",
633
612
  buf.len()
634
613
  )));
@@ -639,7 +618,7 @@ impl RubyFile {
639
618
 
640
619
  /// Ask the file to close, a file lacking `close` having nothing to
641
620
  /// release.
642
- fn close(&mut self) -> Result<(), FilesystemError> {
621
+ fn close(&mut self) -> Result<(), Errno> {
643
622
  self.closed = true;
644
623
  change_if_answered(self.file.get(), "close")
645
624
  }
@@ -652,16 +631,16 @@ impl FileOperations for RubyFile {
652
631
  pos: u64,
653
632
  offset: i64,
654
633
  whence: Whence,
655
- ) -> Result<u64, FilesystemError> {
634
+ ) -> Result<u64, Errno> {
656
635
  generic_file_llseek(dentry, pos, offset, whence)
657
636
  }
658
637
 
659
- fn read_iter(&mut self, iocb: &mut Kiocb, buf: &mut [u8]) -> Result<usize, FilesystemError> {
638
+ fn read_iter(&mut self, iocb: &mut Kiocb, buf: &mut [u8]) -> Result<usize, Errno> {
660
639
  let pos = iocb.pos;
661
640
  let read = ask(
662
641
  self.file.get(),
663
642
  "pread",
664
- FilesystemError::Unsupported,
643
+ Errno::Unsupported,
665
644
  |ruby, file| {
666
645
  // `IO#pread` raises `EOFError` at the end of a file, which reads as nothing.
667
646
  let read: Option<RString> = match file.funcall("pread", (buf.len(), pos)) {
@@ -673,14 +652,23 @@ impl FileOperations for RubyFile {
673
652
  let bytes = unsafe { read.as_slice() };
674
653
  let len = bytes.len().min(buf.len());
675
654
  buf[..len].copy_from_slice(&bytes[..len]);
676
- Ok(len)
655
+ Ok(bytes.len())
677
656
  },
678
- )?;
657
+ )
658
+ // A reply longer than its request fails the read, as FUSE's
659
+ // `fuse_copy_out_args` does, rather than cut to fit.
660
+ .and_then(|read| match read {
661
+ read if read <= buf.len() => Ok(read),
662
+ read => Err(Errno::Other(format!(
663
+ "pread answered {read} bytes of the {} it was asked for",
664
+ buf.len()
665
+ ))),
666
+ })?;
679
667
  iocb.pos += read as u64;
680
668
  Ok(read)
681
669
  }
682
670
 
683
- fn write_iter(&mut self, iocb: &mut Kiocb, buf: &[u8]) -> Result<usize, FilesystemError> {
671
+ fn write_iter(&mut self, iocb: &mut Kiocb, buf: &[u8]) -> Result<usize, Errno> {
684
672
  let written = match iocb.append {
685
673
  true => self.append(iocb, buf)?,
686
674
  false => self.pwrite(iocb, buf)?,
@@ -689,11 +677,11 @@ impl FileOperations for RubyFile {
689
677
  }
690
678
 
691
679
  /// A file lacking `fsync` has nothing of its own to flush.
692
- fn fsync(&mut self, _datasync: bool) -> Result<(), FilesystemError> {
680
+ fn fsync(&mut self, _datasync: bool) -> Result<(), Errno> {
693
681
  change_if_answered(self.file.get(), "fsync")
694
682
  }
695
683
 
696
- fn flush(&mut self) -> Result<(), FilesystemError> {
684
+ fn flush(&mut self) -> Result<(), Errno> {
697
685
  self.close()
698
686
  }
699
687
  }