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
@@ -7,7 +7,6 @@ use std::ops::BitOr;
7
7
  use std::sync::Arc;
8
8
 
9
9
  use super::attr::notify_change;
10
- use super::cred::{on_path, Cred, FileSecurity, SecurityPath};
11
10
  use super::dentry::Dentry;
12
11
  use super::inode::{EmptyFops, Inode};
13
12
  use super::mount::VfsMount;
@@ -17,11 +16,14 @@ use super::readdir::DirContext;
17
16
  #[cfg(test)]
18
17
  use super::readdir::{DirEmit, DirEntry};
19
18
  use super::stat::special_file;
20
- use super::{FileType, FilesystemError, Iattr, Kstat};
19
+ use super::{Errno, FileType, Iattr, Kstat};
20
+ use crate::cred::Cred;
21
+ use crate::security::{on_path, FileSecurity, SecurityPath};
22
+ use crate::wait::PollTable;
21
23
 
22
24
  /// The largest offset a file holds, as Linux's `OFFSET_MAX` ends its signed
23
25
  /// `loff_t`.
24
- const OFFSET_MAX: u64 = i64::MAX as u64;
26
+ pub const OFFSET_MAX: u64 = i64::MAX as u64;
25
27
 
26
28
  /// The most one read or write takes, as Linux's `MAX_RW_COUNT`, the largest
27
29
  /// signed 32-bit count rounded down to a page.
@@ -47,7 +49,7 @@ pub struct Kiocb {
47
49
 
48
50
  impl Kiocb {
49
51
  /// A call landing at `pos`.
50
- pub fn at(pos: u64) -> Self {
52
+ pub fn new(pos: u64) -> Self {
51
53
  Self {
52
54
  pos,
53
55
  append: false,
@@ -73,7 +75,7 @@ pub fn generic_write_sync<F: FileOperations + ?Sized>(
73
75
  file: &mut F,
74
76
  iocb: &Kiocb,
75
77
  written: usize,
76
- ) -> Result<usize, FilesystemError> {
78
+ ) -> Result<usize, Errno> {
77
79
  if iocb.dsync && written > 0 {
78
80
  file.fsync(!iocb.sync)?;
79
81
  }
@@ -95,16 +97,16 @@ pub trait FileOperations: Any + Send + Sync {
95
97
  _pos: u64,
96
98
  _offset: i64,
97
99
  _whence: Whence,
98
- ) -> Result<u64, FilesystemError> {
99
- Err(FilesystemError::NotSeekable)
100
+ ) -> Result<u64, Errno> {
101
+ Err(Errno::NotSeekable)
100
102
  }
101
103
 
102
104
  /// Read into `buf` from where `iocb` lands, moving it past what was read
103
105
  /// unless the file has no positions. A file without it refuses as Linux's
104
106
  /// `vfs_read` refuses one without `f_op->read_iter`. A directory answers
105
107
  /// through `generic_read_dir`, so its read is refused as a directory's.
106
- fn read_iter(&mut self, _iocb: &mut Kiocb, _buf: &mut [u8]) -> Result<usize, FilesystemError> {
107
- Err(FilesystemError::InvalidInput)
108
+ fn read_iter(&mut self, _iocb: &mut Kiocb, _buf: &mut [u8]) -> Result<usize, Errno> {
109
+ Err(Errno::InvalidInput)
108
110
  }
109
111
 
110
112
  /// Write `buf` where `iocb` lands, moving it past what was written unless
@@ -115,8 +117,8 @@ pub trait FileOperations: Any + Send + Sync {
115
117
  /// writer's from landing over it, as `generic_file_write_iter` reads the
116
118
  /// end under the inode's lock, so a file that cannot read its end and
117
119
  /// write there in one step answers `Unsupported`.
118
- fn write_iter(&mut self, _iocb: &mut Kiocb, _buf: &[u8]) -> Result<usize, FilesystemError> {
119
- Err(FilesystemError::InvalidInput)
120
+ fn write_iter(&mut self, _iocb: &mut Kiocb, _buf: &[u8]) -> Result<usize, Errno> {
121
+ Err(Errno::InvalidInput)
120
122
  }
121
123
 
122
124
  /// Hand `ctx` the entries of this directory, which `dentry` names, from
@@ -124,24 +126,29 @@ pub trait FileOperations: Any + Send + Sync {
124
126
  /// `dir_emit_dots` and `dir_emit`. One reading the whole directory at once
125
127
  /// answers through the `Rdir` that `filesystem` provides. A file without
126
128
  /// it answers `NotADirectory`, as Linux's `iterate_dir` does.
127
- fn iterate_shared(
128
- &mut self,
129
- _dentry: &Dentry,
130
- _ctx: &mut DirContext<'_>,
131
- ) -> Result<(), FilesystemError> {
132
- Err(FilesystemError::NotADirectory)
129
+ fn iterate_shared(&mut self, _dentry: &Dentry, _ctx: &mut DirContext<'_>) -> Result<(), Errno> {
130
+ Err(Errno::NotADirectory)
131
+ }
132
+
133
+ /// Whether this file has `iterate_shared`, as Linux's `iterate_dir` asks
134
+ /// whether `f_op->iterate_shared` is set before it locks the directory and
135
+ /// Rust-for-Linux's `#[vtable]` answers `HAS_` for each operation. A file
136
+ /// implementing `iterate_shared` answers true here too.
137
+ fn has_iterate_shared(&self) -> bool {
138
+ false
133
139
  }
134
140
 
135
141
  /// Reserve `len` bytes from `offset`, as `f_op->fallocate` does. A file
136
142
  /// without it refuses as Linux's `vfs_fallocate` refuses one without it.
137
- fn fallocate(&mut self, _offset: u64, _len: u64) -> Result<(), FilesystemError> {
138
- Err(FilesystemError::Unsupported)
143
+ fn fallocate(&mut self, _offset: u64, _len: u64) -> Result<(), Errno> {
144
+ Err(Errno::Unsupported)
139
145
  }
140
146
 
141
147
  /// What a call would find ready on this end, opened for `mode`, as
142
- /// `f_op->poll` answers. A file without it is always ready, as Linux's
143
- /// `vfs_poll` answers `DEFAULT_POLLMASK`.
144
- fn poll(&self, _mode: FMode) -> PollMask {
148
+ /// `f_op->poll` answers; a file that can become ready later registers
149
+ /// its wait queue on `table` through `poll_wait`. A file without it is
150
+ /// always ready, as Linux's `vfs_poll` answers `DEFAULT_POLLMASK`.
151
+ fn poll(&self, _mode: FMode, _table: Option<&mut PollTable>) -> PollMask {
145
152
  PollMask::IN | PollMask::OUT
146
153
  }
147
154
 
@@ -149,15 +156,15 @@ pub trait FileOperations: Any + Send + Sync {
149
156
  /// `datasync` asks, as `f_op->fsync` takes it. A file with nothing to flush
150
157
  /// answers success itself, as tmpfs names `noop_fsync`; one without it refuses
151
158
  /// as Linux's `vfs_fsync_range` refuses one without `f_op->fsync`.
152
- fn fsync(&mut self, _datasync: bool) -> Result<(), FilesystemError> {
153
- Err(FilesystemError::InvalidInput)
159
+ fn fsync(&mut self, _datasync: bool) -> Result<(), Errno> {
160
+ Err(Errno::InvalidInput)
154
161
  }
155
162
 
156
163
  /// Answer, as the file is closed, whether what it held was kept, as
157
164
  /// `f_op->flush` answers `close(2)`. The default has nothing to flush.
158
165
  /// What the file holds goes when it is dropped, as `->release` runs and
159
166
  /// no caller reads its answer, so a file never closed still lets go of it.
160
- fn flush(&mut self) -> Result<(), FilesystemError> {
167
+ fn flush(&mut self) -> Result<(), Errno> {
161
168
  Ok(())
162
169
  }
163
170
 
@@ -177,7 +184,7 @@ pub fn generic_file_llseek(
177
184
  pos: u64,
178
185
  offset: i64,
179
186
  whence: Whence,
180
- ) -> Result<u64, FilesystemError> {
187
+ ) -> Result<u64, Errno> {
181
188
  let base = match whence {
182
189
  Whence::Set => 0,
183
190
  Whence::Cur => pos,
@@ -185,7 +192,7 @@ pub fn generic_file_llseek(
185
192
  };
186
193
  base.checked_add_signed(offset)
187
194
  .filter(|pos| *pos <= OFFSET_MAX)
188
- .ok_or(FilesystemError::InvalidInput)
195
+ .ok_or(Errno::InvalidInput)
189
196
  }
190
197
 
191
198
  /// What an open file was opened for and what it can do, as Linux's `fmode_t`.
@@ -251,8 +258,9 @@ impl FMode {
251
258
  }
252
259
  }
253
260
 
254
- /// What a file would find ready, as Linux's `__poll_t`.
255
- #[derive(Clone, Copy, Debug, PartialEq, Eq)]
261
+ /// What a file would find ready, as Linux's `__poll_t`; the default finds
262
+ /// nothing ready.
263
+ #[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
256
264
  pub struct PollMask(u8);
257
265
 
258
266
  impl PollMask {
@@ -260,11 +268,22 @@ impl PollMask {
260
268
  pub const IN: Self = Self(1);
261
269
  /// A write would not wait, as `EPOLLOUT`.
262
270
  pub const OUT: Self = Self(1 << 1);
271
+ /// The file failed, and a call would answer its error, as `EPOLLERR`.
272
+ pub const ERR: Self = Self(1 << 2);
273
+ /// The peer hung up, and a read would answer the end, as `EPOLLHUP`.
274
+ pub const HUP: Self = Self(1 << 3);
263
275
 
264
276
  /// Whether this holds all of `mask`.
265
277
  pub fn contains(self, mask: Self) -> bool {
266
278
  self.0 & mask.0 == mask.0
267
279
  }
280
+
281
+ /// Whether a poll asking `asked` finds this ready: it holds what was
282
+ /// asked, or an error or a hang-up whatever was asked, as `do_pollfd`
283
+ /// adds `EPOLLERR` and `EPOLLHUP` to every poll's events.
284
+ pub fn is_ready_for(self, asked: Self) -> bool {
285
+ self.contains(asked) || self.contains(Self::ERR) || self.contains(Self::HUP)
286
+ }
268
287
  }
269
288
 
270
289
  impl BitOr for PollMask {
@@ -294,8 +313,8 @@ pub(super) fn do_dentry_open(
294
313
  kind: FileType,
295
314
  mode: FMode,
296
315
  how: &OpenHow,
297
- open: impl FnOnce() -> Result<Box<dyn FileOperations>, FilesystemError>,
298
- ) -> Result<(Box<dyn FileOperations>, Vec<FileSecurity>), FilesystemError> {
316
+ open: impl FnOnce() -> Result<Box<dyn FileOperations>, Errno>,
317
+ ) -> Result<(Box<dyn FileOperations>, Vec<FileSecurity>), Errno> {
299
318
  if mode.contains(FMode::PATH) {
300
319
  return Ok((Box::new(EmptyFops), cred.security_file_alloc()));
301
320
  }
@@ -319,7 +338,7 @@ pub struct File {
319
338
  mode: FMode,
320
339
  /// Whether each write lands at the end, as `O_APPEND` in `f_flags`.
321
340
  append: bool,
322
- /// Whether it asked not to wait, as `O_NONBLOCK` in `f_flags`. Nothing
341
+ /// Whether it asked not to wait, as `O_NONBLOCK` in `f_flags`. No file
323
342
  /// here waits, so it only reports back.
324
343
  nonblock: bool,
325
344
  /// Whether what each write needs read back is durable before it answers, as
@@ -416,12 +435,8 @@ impl File {
416
435
  /// What stands at `path`, opened as `how` asks for `cred`, as Linux's
417
436
  /// `dentry_open` asks the security modules before `f_op->open` and walks no
418
437
  /// path.
419
- pub(super) fn dentry_open(
420
- path: Path,
421
- how: &OpenHow,
422
- cred: &Arc<Cred>,
423
- ) -> Result<Self, FilesystemError> {
424
- let kind = path.dentry().kind()?;
438
+ pub(super) fn dentry_open(path: Path, how: &OpenHow, cred: &Arc<Cred>) -> Result<Self, Errno> {
439
+ let kind = path.dentry().file_type()?;
425
440
  let mode = FMode::of(how);
426
441
  let (ops, security) = on_path(path.mnt(), path.dentry(), |at| {
427
442
  do_dentry_open(cred, at, kind, mode, how, || path.dentry().open(how))
@@ -429,10 +444,10 @@ impl File {
429
444
  Ok(Self::new(path, ops, mode, how, cred, security))
430
445
  }
431
446
 
432
- /// The root of `mnt` opened as a directory for `cred`. A Wasm Driver opens each
433
- /// Mount's root with the Cred its Policies are added to afterwards, as a
447
+ /// The root of `mnt` opened as a directory for `cred`. A Wasm Driver opens
448
+ /// each outermost Mount's root with the Cred its Policies are added to afterwards, as a
434
449
  /// Linux task opens what it keeps before `landlock_restrict_self`.
435
- pub fn root(mnt: &Arc<VfsMount>, cred: &Arc<Cred>) -> Result<Self, FilesystemError> {
450
+ pub fn root(mnt: &Arc<VfsMount>, cred: &Arc<Cred>) -> Result<Self, Errno> {
436
451
  let read = OpenHow {
437
452
  read: true,
438
453
  ..OpenHow::default()
@@ -452,12 +467,12 @@ impl File {
452
467
 
453
468
  /// Whether it is a directory, as `S_ISDIR(file_inode(file))`.
454
469
  pub fn is_directory(&self) -> bool {
455
- self.kind() == FileType::Dir
470
+ self.file_type() == FileType::Dir
456
471
  }
457
472
 
458
473
  /// What kind of entry it is, as `file_inode(file)->i_mode` says.
459
- pub fn kind(&self) -> FileType {
460
- self.inode.kind()
474
+ pub fn file_type(&self) -> FileType {
475
+ self.inode.file_type()
461
476
  }
462
477
 
463
478
  /// What it was opened for.
@@ -467,12 +482,12 @@ impl File {
467
482
  }
468
483
 
469
484
  /// Whether it was opened to read.
470
- pub fn readable(&self) -> bool {
485
+ pub fn is_readable(&self) -> bool {
471
486
  self.mode.contains(FMode::READ)
472
487
  }
473
488
 
474
489
  /// Whether it was opened to write.
475
- pub fn writable(&self) -> bool {
490
+ pub fn is_writable(&self) -> bool {
476
491
  self.mode.contains(FMode::WRITE)
477
492
  }
478
493
 
@@ -484,22 +499,22 @@ impl File {
484
499
  }
485
500
 
486
501
  /// Whether each write lands at the end.
487
- pub fn append(&self) -> bool {
502
+ pub fn is_append(&self) -> bool {
488
503
  self.append
489
504
  }
490
505
 
491
506
  /// Whether it asked not to wait.
492
- pub fn nonblock(&self) -> bool {
507
+ pub fn is_nonblock(&self) -> bool {
493
508
  self.nonblock
494
509
  }
495
510
 
496
511
  /// Whether what each write needs read back is durable before it answers.
497
- pub fn dsync(&self) -> bool {
512
+ pub fn is_dsync(&self) -> bool {
498
513
  self.dsync
499
514
  }
500
515
 
501
516
  /// Whether everything each write changed is durable before it answers.
502
- pub fn sync(&self) -> bool {
517
+ pub fn is_sync(&self) -> bool {
503
518
  self.sync
504
519
  }
505
520
 
@@ -512,9 +527,9 @@ impl File {
512
527
 
513
528
  /// Move its position, answering where it now stands, as `vfs_llseek` refuses
514
529
  /// a file with no position and asks `f_op->llseek` of the rest.
515
- pub fn llseek(&mut self, offset: i64, whence: Whence) -> Result<u64, FilesystemError> {
530
+ pub fn llseek(&mut self, offset: i64, whence: Whence) -> Result<u64, Errno> {
516
531
  if !self.mode.contains(FMode::LSEEK) {
517
- return Err(FilesystemError::NotSeekable);
532
+ return Err(Errno::NotSeekable);
518
533
  }
519
534
  let dentry = self.path.dentry().clone();
520
535
  self.pos = self.ops.llseek(&dentry, self.pos, offset, whence)?;
@@ -524,12 +539,12 @@ impl File {
524
539
  /// Take a hint about `len` bytes from `offset`, as `generic_fadvise`
525
540
  /// refuses a FIFO, then a negative offset or length, and ignores the rest.
526
541
  /// Every Filesystem is still correct without one.
527
- pub fn fadvise(&self, offset: u64, len: u64) -> Result<(), FilesystemError> {
528
- if self.kind() == FileType::Fifo {
529
- return Err(FilesystemError::NotSeekable);
542
+ pub fn fadvise(&self, offset: u64, len: u64) -> Result<(), Errno> {
543
+ if self.file_type() == FileType::Fifo {
544
+ return Err(Errno::NotSeekable);
530
545
  }
531
546
  match offset > OFFSET_MAX || len > OFFSET_MAX {
532
- true => Err(FilesystemError::InvalidInput),
547
+ true => Err(Errno::InvalidInput),
533
548
  false => Ok(()),
534
549
  }
535
550
  }
@@ -538,26 +553,27 @@ impl File {
538
553
  /// order before it asks `f_op->fallocate`: what the call asks, the open's
539
554
  /// mode, a FIFO, a directory, and then anything but a regular file or a
540
555
  /// block device.
541
- pub fn fallocate(&mut self, offset: u64, len: u64) -> Result<(), FilesystemError> {
556
+ pub fn fallocate(&mut self, offset: u64, len: u64) -> Result<(), Errno> {
542
557
  if offset > OFFSET_MAX || len == 0 || len > OFFSET_MAX {
543
- return Err(FilesystemError::InvalidInput);
558
+ return Err(Errno::InvalidInput);
544
559
  }
545
560
  self.may_write()?;
546
- match self.kind() {
547
- FileType::Fifo => return Err(FilesystemError::NotSeekable),
548
- FileType::Dir => return Err(FilesystemError::IsADirectory),
561
+ match self.file_type() {
562
+ FileType::Fifo => return Err(Errno::NotSeekable),
563
+ FileType::Dir => return Err(Errno::IsADirectory),
549
564
  FileType::RegFile | FileType::Blkdev => {}
550
- _ => return Err(FilesystemError::NoSuchDevice),
565
+ _ => return Err(Errno::NoSuchDevice),
551
566
  }
552
567
  if offset + len > OFFSET_MAX {
553
- return Err(FilesystemError::FileTooLarge);
568
+ return Err(Errno::FileTooLarge);
554
569
  }
555
570
  self.ops.fallocate(offset, len)
556
571
  }
557
572
 
558
- /// What a call would find ready, as `vfs_poll` asks `f_op->poll`.
559
- pub fn poll(&self) -> PollMask {
560
- self.ops.poll(self.mode)
573
+ /// What a call would find ready, as `vfs_poll` asks `f_op->poll`,
574
+ /// registering on `table` for a poll that will sleep.
575
+ pub fn poll(&self, table: Option<&mut PollTable>) -> PollMask {
576
+ self.ops.poll(self.mode, table)
561
577
  }
562
578
 
563
579
  /// Whether it reads and writes what comes next, with no position.
@@ -572,7 +588,7 @@ impl File {
572
588
  let iocb = Kiocb {
573
589
  dsync: self.dsync,
574
590
  sync: self.sync,
575
- ..Kiocb::at(pos)
591
+ ..Kiocb::new(pos)
576
592
  };
577
593
  match self.append {
578
594
  true => iocb.with_append(),
@@ -582,43 +598,43 @@ impl File {
582
598
 
583
599
  /// Whether a read may reach it, as `vfs_read` asks of `f_mode` before it
584
600
  /// touches the caller's buffer.
585
- pub fn may_read(&self) -> Result<(), FilesystemError> {
586
- match self.readable() {
601
+ pub fn may_read(&self) -> Result<(), Errno> {
602
+ match self.is_readable() {
587
603
  true => Ok(()),
588
- false => Err(FilesystemError::BadDescriptor),
604
+ false => Err(Errno::BadDescriptor),
589
605
  }
590
606
  }
591
607
 
592
608
  /// Whether a write may reach it, as `vfs_write` asks of `f_mode` before
593
609
  /// it touches the caller's buffer.
594
- pub fn may_write(&self) -> Result<(), FilesystemError> {
595
- match self.writable() {
610
+ pub fn may_write(&self) -> Result<(), Errno> {
611
+ match self.is_writable() {
596
612
  true => Ok(()),
597
- false => Err(FilesystemError::BadDescriptor),
613
+ false => Err(Errno::BadDescriptor),
598
614
  }
599
615
  }
600
616
 
601
617
  /// Whether a read from `pos` may reach it, as `pread` refuses a negative
602
618
  /// offset, then a file without one.
603
- pub fn may_pread(&self, pos: u64) -> Result<(), FilesystemError> {
619
+ pub fn may_pread(&self, pos: u64) -> Result<(), Errno> {
604
620
  self.may_at(pos, FMode::PREAD)?;
605
621
  self.may_read()
606
622
  }
607
623
 
608
624
  /// Whether a write at `pos` may reach it, as `pwrite` refuses a negative
609
625
  /// offset, then a file without one.
610
- pub fn may_pwrite(&self, pos: u64) -> Result<(), FilesystemError> {
626
+ pub fn may_pwrite(&self, pos: u64) -> Result<(), Errno> {
611
627
  self.may_at(pos, FMode::PWRITE)?;
612
628
  self.may_write()
613
629
  }
614
630
 
615
- fn may_at(&self, pos: u64, mode: FMode) -> Result<(), FilesystemError> {
631
+ fn may_at(&self, pos: u64, mode: FMode) -> Result<(), Errno> {
616
632
  if pos > OFFSET_MAX {
617
- return Err(FilesystemError::InvalidInput);
633
+ return Err(Errno::InvalidInput);
618
634
  }
619
635
  match self.mode.contains(mode) {
620
636
  true => Ok(()),
621
- false => Err(FilesystemError::NotSeekable),
637
+ false => Err(Errno::NotSeekable),
622
638
  }
623
639
  }
624
640
 
@@ -630,20 +646,20 @@ impl File {
630
646
 
631
647
  /// Refuse a call of `count` bytes from `ppos` if it would end past the
632
648
  /// largest offset, as `rw_verify_area` does; a call landing nowhere passes.
633
- fn rw_verify_area(&self, ppos: Option<u64>, count: usize) -> Result<(), FilesystemError> {
649
+ fn rw_verify_area(&self, ppos: Option<u64>, count: usize) -> Result<(), Errno> {
634
650
  let Some(pos) = ppos else {
635
651
  return Ok(());
636
652
  };
637
653
  match pos.checked_add(count as u64) {
638
654
  Some(end) if end <= OFFSET_MAX => Ok(()),
639
- _ => Err(FilesystemError::InvalidInput),
655
+ _ => Err(Errno::InvalidInput),
640
656
  }
641
657
  }
642
658
 
643
659
  /// Read from its position, moving it past what was read, as `vfs_read`
644
660
  /// does; a stream starts from no position and keeps none, as
645
661
  /// `new_sync_read` hands it `ki_pos` 0.
646
- pub fn read(&mut self, buf: &mut [u8]) -> Result<usize, FilesystemError> {
662
+ pub fn read(&mut self, buf: &mut [u8]) -> Result<usize, Errno> {
647
663
  self.may_read()?;
648
664
  let ppos = self.file_ppos();
649
665
  self.rw_verify_area(ppos, buf.len())?;
@@ -657,7 +673,7 @@ impl File {
657
673
  }
658
674
 
659
675
  /// Read from `pos`, leaving its position, as `pread` does.
660
- pub fn pread(&mut self, buf: &mut [u8], pos: u64) -> Result<usize, FilesystemError> {
676
+ pub fn pread(&mut self, buf: &mut [u8], pos: u64) -> Result<usize, Errno> {
661
677
  self.may_pread(pos)?;
662
678
  self.rw_verify_area(Some(pos), buf.len())?;
663
679
  let count = buf.len().min(MAX_RW_COUNT);
@@ -667,7 +683,7 @@ impl File {
667
683
  /// Write at its position, moving it past what was written, as `vfs_write`
668
684
  /// does; a stream starts from no position and keeps none, as
669
685
  /// `new_sync_write` hands it `ki_pos` 0.
670
- pub fn write(&mut self, buf: &[u8]) -> Result<usize, FilesystemError> {
686
+ pub fn write(&mut self, buf: &[u8]) -> Result<usize, Errno> {
671
687
  self.may_write()?;
672
688
  let ppos = self.file_ppos();
673
689
  self.rw_verify_area(ppos, buf.len())?;
@@ -683,7 +699,7 @@ impl File {
683
699
 
684
700
  /// Write at `pos`, leaving its position, as `pwrite` does. Opened to
685
701
  /// append, it lands at the end whatever `pos` says.
686
- pub fn pwrite(&mut self, buf: &[u8], pos: u64) -> Result<usize, FilesystemError> {
702
+ pub fn pwrite(&mut self, buf: &[u8], pos: u64) -> Result<usize, Errno> {
687
703
  self.may_pwrite(pos)?;
688
704
  self.rw_verify_area(Some(pos), buf.len())?;
689
705
  self.ops
@@ -692,37 +708,45 @@ impl File {
692
708
 
693
709
  /// Make what was written durable, as `vfs_fsync` does, and `vfs_fsync_range`
694
710
  /// passes `datasync` through.
695
- pub fn fsync(&mut self, datasync: bool) -> Result<(), FilesystemError> {
711
+ pub fn fsync(&mut self, datasync: bool) -> Result<(), Errno> {
696
712
  self.ops.fsync(datasync)
697
713
  }
698
714
 
699
715
  /// What it reports of itself, as `vfs_getattr` answers.
700
- pub fn getattr(&self) -> Result<Kstat, FilesystemError> {
716
+ pub fn getattr(&self) -> Result<Kstat, Errno> {
701
717
  self.path.dentry().getattr()
702
718
  }
703
719
 
704
720
  /// Truncate or extend it through what it was opened on, as `do_ftruncate`
705
721
  /// refuses anything but a file open to write, and reaches `->setattr`.
706
- pub fn truncate(&mut self, len: u64) -> Result<(), FilesystemError> {
707
- if self.kind() != FileType::RegFile || !self.writable() || len > OFFSET_MAX {
708
- return Err(FilesystemError::InvalidInput);
722
+ pub fn truncate(&mut self, len: u64) -> Result<(), Errno> {
723
+ if self.file_type() != FileType::RegFile || !self.is_writable() || len > OFFSET_MAX {
724
+ return Err(Errno::InvalidInput);
709
725
  }
710
726
  self.cred.security_file_truncate(&self.security)?;
711
727
  let dentry = self.path.dentry();
712
728
  let held = dentry.inode_lock()?;
713
- notify_change(dentry, &held, &Iattr::size(len).through(self.ops.as_ref()))
729
+ notify_change(
730
+ dentry,
731
+ &held,
732
+ &Iattr::for_size(len).through(self.ops.as_ref()),
733
+ )
714
734
  }
715
735
 
716
736
  /// Hand `ctx` the entries of the directory from where it stands until the
717
- /// actor stops, leaving it past each taken, as `iterate_dir` moves `f_pos`. It
737
+ /// actor stops, leaving it past each taken, as `iterate_dir` moves `f_pos`. A
738
+ /// file without `iterate_shared` answers not a directory before it locks. It
718
739
  /// holds the directory's lock shared, so a removal through the VFS lands
719
740
  /// before or after, and a removed directory answers not found, as it asks
720
741
  /// `IS_DEADDIR`.
721
- pub fn iterate_dir(&mut self, ctx: &mut DirContext<'_>) -> Result<(), FilesystemError> {
742
+ pub fn iterate_dir(&mut self, ctx: &mut DirContext<'_>) -> Result<(), Errno> {
743
+ if !self.ops.has_iterate_shared() {
744
+ return Err(Errno::NotADirectory);
745
+ }
722
746
  let dentry = self.path.dentry().clone();
723
747
  let _held = dentry.inode_lock_shared()?;
724
748
  if dentry.is_deaddir() {
725
- return Err(FilesystemError::NotFound);
749
+ return Err(Errno::NotFound);
726
750
  }
727
751
  ctx.pos = self.pos;
728
752
  ctx.cred = self.cred.clone();
@@ -734,7 +758,7 @@ impl File {
734
758
  /// What its Filesystem lists past `.` and `..`, for a test of what the
735
759
  /// Filesystem answers beneath the VFS.
736
760
  #[cfg(test)]
737
- pub(crate) fn iterate_shared(&mut self) -> Result<Vec<DirEntry>, FilesystemError> {
761
+ pub(crate) fn iterate_shared(&mut self) -> Result<Vec<DirEntry>, Errno> {
738
762
  let dentry = self.path.dentry().clone();
739
763
  let mut entries = Vec::new();
740
764
  let mut actor = |emit: &DirEmit<'_>| {
@@ -748,7 +772,7 @@ impl File {
748
772
 
749
773
  /// Close it once the last descriptor goes, answering what its flush
750
774
  /// answers, as `filp_close` does; dropping it is what `->release` does.
751
- pub fn close(mut self) -> Result<(), FilesystemError> {
775
+ pub fn close(mut self) -> Result<(), Errno> {
752
776
  self.ops.flush()
753
777
  }
754
778
  }
@@ -775,7 +799,7 @@ mod tests {
775
799
  _pos: u64,
776
800
  _offset: i64,
777
801
  _whence: Whence,
778
- ) -> Result<u64, FilesystemError> {
802
+ ) -> Result<u64, Errno> {
779
803
  Ok(9)
780
804
  }
781
805
  }
@@ -785,18 +809,18 @@ mod tests {
785
809
  struct Opens(fn() -> Box<dyn FileOperations>);
786
810
 
787
811
  impl crate::vfs::FileSystemType for Opens {
788
- fn fill_super(self: Arc<Self>, sb: &mut Filesystem) -> Result<(), FilesystemError> {
812
+ fn fill_super(self: Arc<Self>, sb: &mut Filesystem) -> Result<(), Errno> {
789
813
  sb.d_make_root(Inode::new(&Kstat::new(FileType::Dir, 0), self));
790
814
  Ok(())
791
815
  }
792
816
  }
793
817
 
794
818
  impl InodeOperations for Opens {
795
- fn getattr(&self, _dentry: &Dentry) -> Result<Kstat, FilesystemError> {
819
+ fn getattr(&self, _dentry: &Dentry) -> Result<Kstat, Errno> {
796
820
  Ok(Kstat::new(FileType::RegFile, 0))
797
821
  }
798
822
 
799
- fn lookup(&self, _dentry: &Dentry) -> Result<Lookup, FilesystemError> {
823
+ fn lookup(&self, _dentry: &Dentry) -> Result<Lookup, Errno> {
800
824
  let found = Kstat::new(FileType::RegFile, 0);
801
825
  Ok(Lookup::Found(Inode::new(&found, Arc::new(Self(self.0)))))
802
826
  }
@@ -805,7 +829,7 @@ mod tests {
805
829
  &self,
806
830
  _dentry: &Dentry,
807
831
  _options: &OpenHow,
808
- ) -> Result<Box<dyn FileOperations>, FilesystemError> {
832
+ ) -> Result<Box<dyn FileOperations>, Errno> {
809
833
  Ok((self.0)())
810
834
  }
811
835
  }
@@ -815,7 +839,7 @@ mod tests {
815
839
  fn open_one(opens: fn() -> Box<dyn FileOperations>) -> File {
816
840
  let mount = Mount::new(
817
841
  "/data",
818
- Filesystem::new(Arc::new(Opens(opens))).expect("the instance must stand"),
842
+ Filesystem::new(Opens(opens)).expect("the instance must stand"),
819
843
  Access::Read,
820
844
  )
821
845
  .expect("/data is a guest path");
@@ -835,17 +859,48 @@ mod tests {
835
859
  true
836
860
  }
837
861
 
838
- fn read_iter(
839
- &mut self,
840
- iocb: &mut Kiocb,
841
- buf: &mut [u8],
842
- ) -> Result<usize, FilesystemError> {
862
+ fn read_iter(&mut self, iocb: &mut Kiocb, buf: &mut [u8]) -> Result<usize, Errno> {
843
863
  buf[0] = iocb.pos as u8;
844
864
  iocb.pos += buf.len() as u64;
845
865
  Ok(buf.len())
846
866
  }
847
867
  }
848
868
 
869
+ /// A file its filesystem opens with no operations of its own.
870
+ struct ListsNothing;
871
+
872
+ impl FileOperations for ListsNothing {}
873
+
874
+ // @behavior RT-408
875
+ #[test]
876
+ fn a_listing_of_a_file_that_lists_nothing_waits_on_no_lock() {
877
+ use std::sync::mpsc;
878
+ let mut file = open_one(|| Box::new(ListsNothing));
879
+ let dentry = file.path.dentry().clone();
880
+ let (held, holding) = mpsc::channel();
881
+ let (release, releasing) = mpsc::channel::<()>();
882
+ let owner = std::thread::spawn(move || {
883
+ let _held = dentry.inode_lock().expect("the lock is free");
884
+ held.send(()).ok();
885
+ releasing.recv_timeout(crate::sched::testing::MAX_WAIT).ok();
886
+ });
887
+ holding
888
+ .recv_timeout(crate::sched::testing::MAX_WAIT)
889
+ .expect("the other thread must hold the lock");
890
+ let waits = crate::sched::testing::count_waits();
891
+ let listed = crate::sched::testing::within_max_wait(|| {
892
+ file.iterate_dir(&mut DirContext::new(0, &mut |_| true))
893
+ });
894
+ release.send(()).ok();
895
+ crate::sched::testing::join("the owner", owner);
896
+ assert_eq!(
897
+ (listed, waits.load(Ordering::SeqCst)),
898
+ (Err(Errno::NotADirectory), 0),
899
+ "a listing of a file its filesystem gives no way to list must answer ENOTDIR \
900
+ without waiting on the lock another thread holds on it"
901
+ );
902
+ }
903
+
849
904
  // The stream's own read moves the position handed to it, so only handing
850
905
  // none and keeping none leaves each read at 0, as file_ppos answers NULL
851
906
  // for FMODE_STREAM.
@@ -878,11 +933,7 @@ mod tests {
878
933
  file.pread(&mut [0], 0),
879
934
  file.is_stream()
880
935
  ),
881
- (
882
- Err(FilesystemError::NotSeekable),
883
- Err(FilesystemError::NotSeekable),
884
- true
885
- ),
936
+ (Err(Errno::NotSeekable), Err(Errno::NotSeekable), true),
886
937
  "File::llseek and File::pread on a file its Filesystem's open marks a stream must \
887
938
  answer ESPIPE, as stream_open clears FMODE_LSEEK and FMODE_PREAD"
888
939
  );
@@ -915,7 +966,7 @@ mod tests {
915
966
  let mut file = open_one(|| Box::new(NoSeek));
916
967
  assert_eq!(
917
968
  (file.llseek(0, Whence::Set), file.pos()),
918
- (Err(FilesystemError::NotSeekable), 0),
969
+ (Err(Errno::NotSeekable), 0),
919
970
  "File::llseek of a file whose Filesystem answers no llseek must answer ESPIPE and \
920
971
  leave its position, as Linux clears FMODE_LSEEK for one"
921
972
  );
@@ -937,21 +988,21 @@ mod tests {
937
988
  struct OpensNothing;
938
989
 
939
990
  impl crate::vfs::FileSystemType for OpensNothing {
940
- fn fill_super(self: Arc<Self>, sb: &mut Filesystem) -> Result<(), FilesystemError> {
991
+ fn fill_super(self: Arc<Self>, sb: &mut Filesystem) -> Result<(), Errno> {
941
992
  sb.d_make_root(Inode::new(&Kstat::new(FileType::Dir, 0), self));
942
993
  Ok(())
943
994
  }
944
995
  }
945
996
 
946
997
  impl InodeOperations for OpensNothing {
947
- fn getattr(&self, dentry: &Dentry) -> Result<Kstat, FilesystemError> {
998
+ fn getattr(&self, dentry: &Dentry) -> Result<Kstat, Errno> {
948
999
  Ok(match dentry.is_root() {
949
1000
  false => Kstat::new(FileType::RegFile, 0),
950
1001
  true => Kstat::new(FileType::Dir, 0),
951
1002
  })
952
1003
  }
953
1004
 
954
- fn lookup(&self, _dentry: &Dentry) -> Result<Lookup, FilesystemError> {
1005
+ fn lookup(&self, _dentry: &Dentry) -> Result<Lookup, Errno> {
955
1006
  let found = Kstat::new(FileType::RegFile, 0);
956
1007
  Ok(Lookup::Found(Inode::new(&found, Arc::new(Self))))
957
1008
  }
@@ -965,7 +1016,7 @@ mod tests {
965
1016
  let tmpfs: Tmpfs = [("d/f", "x")].into_iter().collect();
966
1017
  let mount = Mount::new(
967
1018
  "/data",
968
- Filesystem::new(Arc::new(tmpfs)).expect("the instance must stand"),
1019
+ Filesystem::new(tmpfs).expect("the instance must stand"),
969
1020
  Access::Read,
970
1021
  )
971
1022
  .expect("/data is a guest path");
@@ -978,7 +1029,7 @@ mod tests {
978
1029
  };
979
1030
  assert_eq!(
980
1031
  dir.read(&mut [0; 1]),
981
- Err(FilesystemError::BadDescriptor),
1032
+ Err(Errno::BadDescriptor),
982
1033
  "File::read of a directory opened for neither reading nor writing must answer EBADF"
983
1034
  );
984
1035
  }
@@ -991,7 +1042,7 @@ mod tests {
991
1042
  fn a_write_of_nothing_leaves_an_appending_file_where_it_stands() {
992
1043
  let mount = Mount::new(
993
1044
  "/data",
994
- Filesystem::new(Arc::new(Tmpfs::new())).expect("the instance must stand"),
1045
+ Filesystem::new(Tmpfs::new()).expect("the instance must stand"),
995
1046
  Access::ReadWrite,
996
1047
  )
997
1048
  .expect("/data is a guest path");
@@ -1021,7 +1072,7 @@ mod tests {
1021
1072
  fn an_entry_without_open_opens_with_no_operations() {
1022
1073
  let mount = Mount::new(
1023
1074
  "/data",
1024
- Filesystem::new(Arc::new(OpensNothing)).expect("the instance must stand"),
1075
+ Filesystem::new(OpensNothing).expect("the instance must stand"),
1025
1076
  Access::Read,
1026
1077
  )
1027
1078
  .expect("/data is a guest path");
@@ -1035,7 +1086,7 @@ mod tests {
1035
1086
  .map(|mut file| file.read(&mut [0; 1]));
1036
1087
  assert_eq!(
1037
1088
  read,
1038
- Ok(Err(FilesystemError::InvalidInput)),
1089
+ Ok(Err(Errno::InvalidInput)),
1039
1090
  "vfs::do_file_open of a file whose Filesystem has no open must succeed, and File::read \
1040
1091
  of it must answer EINVAL, as Linux's opens with no f_op->open"
1041
1092
  );
@@ -1046,7 +1097,7 @@ mod tests {
1046
1097
  let tmpfs = Tmpfs::try_from_iter([("file.txt", "granted")]).expect("the seed must fit");
1047
1098
  let mount = Mount::new(
1048
1099
  "/data",
1049
- Filesystem::new(Arc::new(tmpfs)).expect("the instance must stand"),
1100
+ Filesystem::new(tmpfs).expect("the instance must stand"),
1050
1101
  Access::ReadWrite,
1051
1102
  )
1052
1103
  .expect("/data is a guest path");
@@ -1067,7 +1118,7 @@ mod tests {
1067
1118
  let tmpfs = Tmpfs::try_from_iter([("file.txt", "granted")]).expect("the seed must fit");
1068
1119
  let mount = Mount::new(
1069
1120
  "/data",
1070
- Filesystem::new(Arc::new(tmpfs)).expect("the instance must stand"),
1121
+ Filesystem::new(tmpfs).expect("the instance must stand"),
1071
1122
  Access::Read,
1072
1123
  )
1073
1124
  .expect("/data is a guest path");
@@ -1085,7 +1136,7 @@ mod tests {
1085
1136
  .clone();
1086
1137
  assert_eq!(
1087
1138
  File::dentry_open(path, &write, &Arc::default()).err(),
1088
- Some(FilesystemError::ReadOnlyFilesystem),
1139
+ Some(Errno::ReadOnlyFilesystem),
1089
1140
  "File::dentry_open to write a file beneath a read-only Mount must answer EROFS"
1090
1141
  );
1091
1142
  }
@@ -1104,10 +1155,10 @@ mod tests {
1104
1155
  open(false, true).pread(&mut buf, 0),
1105
1156
  ),
1106
1157
  (
1107
- Err(FilesystemError::BadDescriptor),
1108
- Err(FilesystemError::BadDescriptor),
1109
- Err(FilesystemError::BadDescriptor),
1110
- Err(FilesystemError::BadDescriptor),
1158
+ Err(Errno::BadDescriptor),
1159
+ Err(Errno::BadDescriptor),
1160
+ Err(Errno::BadDescriptor),
1161
+ Err(Errno::BadDescriptor),
1111
1162
  ),
1112
1163
  "File::write and pwrite on a file opened to read, and File::read and pread on one \
1113
1164
  opened to write, must answer EBADF, as vfs_read and vfs_write do"
@@ -1145,16 +1196,20 @@ mod tests {
1145
1196
  pos: u64,
1146
1197
  offset: i64,
1147
1198
  whence: Whence,
1148
- ) -> Result<u64, FilesystemError> {
1199
+ ) -> Result<u64, Errno> {
1149
1200
  generic_file_llseek(dentry, pos, offset, whence)
1150
1201
  }
1151
1202
 
1203
+ fn has_iterate_shared(&self) -> bool {
1204
+ true
1205
+ }
1206
+
1152
1207
  fn iterate_shared(
1153
1208
  &mut self,
1154
1209
  dentry: &Dentry,
1155
1210
  ctx: &mut DirContext<'_>,
1156
- ) -> Result<(), FilesystemError> {
1157
- self.0.iterate(dentry, ctx, || {
1211
+ ) -> Result<(), Errno> {
1212
+ self.0.iterate_shared(dentry, ctx, || {
1158
1213
  Ok(vec![
1159
1214
  DirEntry::new("a", FileType::RegFile),
1160
1215
  DirEntry::new("b", FileType::RegFile),
@@ -1164,14 +1219,14 @@ mod tests {
1164
1219
  }
1165
1220
 
1166
1221
  impl crate::vfs::FileSystemType for ReadsWhole {
1167
- fn fill_super(self: Arc<Self>, sb: &mut Filesystem) -> Result<(), FilesystemError> {
1222
+ fn fill_super(self: Arc<Self>, sb: &mut Filesystem) -> Result<(), Errno> {
1168
1223
  sb.d_make_root(Inode::new(&Kstat::new(FileType::Dir, 0), self));
1169
1224
  Ok(())
1170
1225
  }
1171
1226
  }
1172
1227
 
1173
1228
  impl InodeOperations for ReadsWhole {
1174
- fn getattr(&self, _dentry: &Dentry) -> Result<Kstat, FilesystemError> {
1229
+ fn getattr(&self, _dentry: &Dentry) -> Result<Kstat, Errno> {
1175
1230
  Ok(Kstat::new(FileType::Dir, 0))
1176
1231
  }
1177
1232
 
@@ -1179,7 +1234,7 @@ mod tests {
1179
1234
  &self,
1180
1235
  _dentry: &Dentry,
1181
1236
  _options: &OpenHow,
1182
- ) -> Result<Box<dyn FileOperations>, FilesystemError> {
1237
+ ) -> Result<Box<dyn FileOperations>, Errno> {
1183
1238
  Ok(Box::new(ReadsWholeDir(crate::filesystem::Rdir::default())))
1184
1239
  }
1185
1240
  }
@@ -1188,22 +1243,22 @@ mod tests {
1188
1243
  struct CannotStat;
1189
1244
 
1190
1245
  impl crate::vfs::FileSystemType for CannotStat {
1191
- fn fill_super(self: Arc<Self>, sb: &mut Filesystem) -> Result<(), FilesystemError> {
1246
+ fn fill_super(self: Arc<Self>, sb: &mut Filesystem) -> Result<(), Errno> {
1192
1247
  sb.d_make_root(Inode::new(&Kstat::new(FileType::Dir, 0), self));
1193
1248
  Ok(())
1194
1249
  }
1195
1250
  }
1196
1251
 
1197
1252
  impl InodeOperations for CannotStat {
1198
- fn getattr(&self, _dentry: &Dentry) -> Result<Kstat, FilesystemError> {
1199
- Err(FilesystemError::Other("no stat".into()))
1253
+ fn getattr(&self, _dentry: &Dentry) -> Result<Kstat, Errno> {
1254
+ Err(Errno::Other("no stat".into()))
1200
1255
  }
1201
1256
 
1202
1257
  fn open(
1203
1258
  &self,
1204
1259
  _dentry: &Dentry,
1205
1260
  _options: &OpenHow,
1206
- ) -> Result<Box<dyn FileOperations>, FilesystemError> {
1261
+ ) -> Result<Box<dyn FileOperations>, Errno> {
1207
1262
  Ok(Box::new(ReadsWholeDir(crate::filesystem::Rdir::default())))
1208
1263
  }
1209
1264
  }
@@ -1212,14 +1267,14 @@ mod tests {
1212
1267
  struct StatsAsOne;
1213
1268
 
1214
1269
  impl crate::vfs::FileSystemType for StatsAsOne {
1215
- fn fill_super(self: Arc<Self>, sb: &mut Filesystem) -> Result<(), FilesystemError> {
1270
+ fn fill_super(self: Arc<Self>, sb: &mut Filesystem) -> Result<(), Errno> {
1216
1271
  sb.d_make_root(Inode::new(&Kstat::new(FileType::Dir, 0), self));
1217
1272
  Ok(())
1218
1273
  }
1219
1274
  }
1220
1275
 
1221
1276
  impl InodeOperations for StatsAsOne {
1222
- fn getattr(&self, _dentry: &Dentry) -> Result<Kstat, FilesystemError> {
1277
+ fn getattr(&self, _dentry: &Dentry) -> Result<Kstat, Errno> {
1223
1278
  Ok(Kstat::new(FileType::Dir, 0).with_identity(7, 9))
1224
1279
  }
1225
1280
 
@@ -1227,7 +1282,7 @@ mod tests {
1227
1282
  &self,
1228
1283
  _dentry: &Dentry,
1229
1284
  _options: &OpenHow,
1230
- ) -> Result<Box<dyn FileOperations>, FilesystemError> {
1285
+ ) -> Result<Box<dyn FileOperations>, Errno> {
1231
1286
  Ok(Box::new(ReadsWholeDir(crate::filesystem::Rdir::default())))
1232
1287
  }
1233
1288
  }
@@ -1252,7 +1307,7 @@ mod tests {
1252
1307
  fn a_listing_read_whole_names_its_dots_as_a_stat_does() {
1253
1308
  let mount = Mount::new(
1254
1309
  "/data",
1255
- Filesystem::new(Arc::new(StatsAsOne)).expect("the instance must stand"),
1310
+ Filesystem::new(StatsAsOne).expect("the instance must stand"),
1256
1311
  Access::Read,
1257
1312
  )
1258
1313
  .expect("/data is a guest path");
@@ -1274,7 +1329,7 @@ mod tests {
1274
1329
  let tmpfs: Tmpfs = [("d/f", "x")].into_iter().collect();
1275
1330
  let mount = Mount::new(
1276
1331
  "/data",
1277
- Filesystem::new(Arc::new(tmpfs)).expect("the instance must stand"),
1332
+ Filesystem::new(tmpfs).expect("the instance must stand"),
1278
1333
  Access::Read,
1279
1334
  )
1280
1335
  .expect("/data is a guest path");
@@ -1307,7 +1362,7 @@ mod tests {
1307
1362
  fn a_listing_whose_directory_cannot_be_stated_hands_nothing() {
1308
1363
  let mount = Mount::new(
1309
1364
  "/data",
1310
- Filesystem::new(Arc::new(CannotStat)).expect("the instance must stand"),
1365
+ Filesystem::new(CannotStat).expect("the instance must stand"),
1311
1366
  Access::Read,
1312
1367
  )
1313
1368
  .expect("/data is a guest path");
@@ -1321,35 +1376,25 @@ mod tests {
1321
1376
  }));
1322
1377
  assert_eq!(
1323
1378
  (answer, seen),
1324
- (Err(FilesystemError::Other("no stat".into())), 0),
1379
+ (Err(Errno::Other("no stat".into())), 0),
1325
1380
  "File::iterate_dir through Rdir of a directory its Filesystem cannot stat must answer \
1326
1381
  that failure and hand no entry, as ovl_cache_update fails the listing"
1327
1382
  );
1328
1383
  }
1329
1384
 
1330
- /// A listing of `file` from the start, its actor stopping after `room`
1331
- /// entries.
1332
- fn begin_listing(file: &mut File, room: usize) -> Result<(), FilesystemError> {
1333
- let mut seen = 0;
1334
- file.iterate_dir(&mut DirContext::new(0, &mut |_| {
1335
- seen += 1;
1336
- seen < room
1337
- }))
1338
- }
1339
-
1340
1385
  /// A security module refusing to open any directory.
1341
1386
  struct RefusesDirectories;
1342
1387
 
1343
- impl crate::vfs::SecurityOperations for RefusesDirectories {
1388
+ impl crate::security::SecurityOperations for RefusesDirectories {
1344
1389
  fn file_open(
1345
1390
  &self,
1346
- _path: crate::vfs::SecurityPath<'_>,
1391
+ _path: crate::security::SecurityPath<'_>,
1347
1392
  kind: FileType,
1348
1393
  _mode: FMode,
1349
1394
  _how: &OpenHow,
1350
- ) -> Result<FileSecurity, FilesystemError> {
1395
+ ) -> Result<FileSecurity, Errno> {
1351
1396
  match kind {
1352
- FileType::Dir => Err(FilesystemError::PermissionDenied),
1397
+ FileType::Dir => Err(Errno::PermissionDenied),
1353
1398
  _ => Ok(None),
1354
1399
  }
1355
1400
  }
@@ -1362,59 +1407,19 @@ mod tests {
1362
1407
  fn opening_a_mounts_root_asks_the_security_modules() {
1363
1408
  let mount = Mount::new(
1364
1409
  "/data",
1365
- Filesystem::new(Arc::new(Tmpfs::default())).expect("the instance must stand"),
1410
+ Filesystem::new(Tmpfs::default()).expect("the instance must stand"),
1366
1411
  Access::Read,
1367
1412
  )
1368
1413
  .expect("/data is a guest path");
1369
1414
  let cred = Cred::new(vec![Arc::new(RefusesDirectories)]);
1370
1415
  assert_eq!(
1371
1416
  File::root(mount.mnt(), &cred).err(),
1372
- Some(FilesystemError::PermissionDenied),
1417
+ Some(Errno::PermissionDenied),
1373
1418
  "File::root under a security module refusing to open a directory must answer as \
1374
1419
  the module refuses, as dentry_open asks security_file_open"
1375
1420
  );
1376
1421
  }
1377
1422
 
1378
- // Every descriptor holds a listing of its own, so only counting them together
1379
- // keeps a guest from multiplying a directory by its open files.
1380
- // @behavior RT-237
1381
- #[test]
1382
- fn listings_held_between_calls_count_against_their_limit() {
1383
- let mount = Mount::new(
1384
- "/data",
1385
- Filesystem::new(Arc::new(ReadsWhole)).expect("the instance must stand"),
1386
- Access::Read,
1387
- )
1388
- .expect("/data is a guest path");
1389
- // `.`, `..`, and two one-letter names.
1390
- let one_listing = 4 * size_of::<DirEntry>() + 1 + 2 + 2;
1391
- let cred = crate::security::prepare_creds_within(&[], Some(one_listing));
1392
- // A Wasm Driver opens the root before the Policies apply and lists through
1393
- // the Cred they were added to, so both must count against one limit.
1394
- let restricted = crate::security::restrict_self(&cred, [&mount]);
1395
- let open = |cred: &Arc<Cred>| {
1396
- File::root(mount.mnt(), cred).unwrap_or_else(|_| panic!("the root must open"))
1397
- };
1398
- let (mut first, mut second, mut whole) = (open(&cred), open(&restricted), open(&cred));
1399
- let held = begin_listing(&mut first, 1);
1400
- let refused = begin_listing(&mut second, 1);
1401
- let read_whole = begin_listing(&mut whole, usize::MAX);
1402
- drop(first);
1403
- let after_close = begin_listing(&mut second, 1);
1404
- assert_eq!(
1405
- (held, refused, read_whole, after_close),
1406
- (
1407
- Ok(()),
1408
- Err(FilesystemError::OutOfMemory),
1409
- Err(FilesystemError::OutOfMemory),
1410
- Ok(())
1411
- ),
1412
- "File::iterate_dir of a second listing past its caller's memory limit, stopped part \
1413
- way or read whole, must answer ENOMEM, as ovl_cache_get allocates before dir_emit, \
1414
- and closing the first must give its bytes back"
1415
- );
1416
- }
1417
-
1418
1423
  /// Each entry of the root of `filesystem` with what a listing names it
1419
1424
  /// and what a stat of it names it.
1420
1425
  fn identities<F: crate::vfs::FileSystemType>(
@@ -1422,7 +1427,7 @@ mod tests {
1422
1427
  ) -> Vec<(String, Option<Identity>, Option<Identity>)> {
1423
1428
  let mount = Mount::new(
1424
1429
  "/data",
1425
- Filesystem::new(Arc::new(filesystem)).expect("the instance must stand"),
1430
+ Filesystem::new(filesystem).expect("the instance must stand"),
1426
1431
  Access::ReadWrite,
1427
1432
  )
1428
1433
  .expect("/data is a guest path");
@@ -1471,16 +1476,14 @@ mod tests {
1471
1476
  let lower: Tmpfs = [("a", "x"), ("d/b", "y")].into_iter().collect();
1472
1477
  let upper = Tmpfs::new();
1473
1478
  let overlay = Overlay::new(
1474
- vec![Filesystem::new(Arc::new(lower)).expect("the instance must stand")],
1475
- Some(Filesystem::new(Arc::new(upper)).expect("the instance must stand")),
1479
+ vec![Filesystem::new(lower).expect("the instance must stand")],
1480
+ Some(Filesystem::new(upper).expect("the instance must stand")),
1476
1481
  )
1477
1482
  .unwrap_or_else(|_| panic!("the Overlay must make"));
1478
1483
  assert_named_alike("Overlay", identities(overlay));
1479
1484
  }
1480
1485
 
1481
- // A host names no identity through a Bind beyond unix.
1482
1486
  // @behavior RT-183
1483
- #[cfg(unix)]
1484
1487
  #[test]
1485
1488
  fn a_bind_lists_each_entry_as_a_stat_names_it() {
1486
1489
  let dir = std::env::temp_dir().join(format!("kobako-listed-{}", std::process::id()));
@@ -1523,7 +1526,7 @@ mod tests {
1523
1526
  fn a_listing_read_whole_goes_on_past_the_last_entry_taken() {
1524
1527
  let mount = Mount::new(
1525
1528
  "/data",
1526
- Filesystem::new(Arc::new(ReadsWhole)).expect("the instance must stand"),
1529
+ Filesystem::new(ReadsWhole).expect("the instance must stand"),
1527
1530
  Access::Read,
1528
1531
  )
1529
1532
  .expect("/data is a guest path");
@@ -1546,11 +1549,11 @@ mod tests {
1546
1549
  struct CountsSyncs(Arc<AtomicUsize>);
1547
1550
 
1548
1551
  impl FileOperations for CountsSyncs {
1549
- fn write_iter(&mut self, iocb: &mut Kiocb, buf: &[u8]) -> Result<usize, FilesystemError> {
1552
+ fn write_iter(&mut self, iocb: &mut Kiocb, buf: &[u8]) -> Result<usize, Errno> {
1550
1553
  generic_write_sync(self, iocb, buf.len())
1551
1554
  }
1552
1555
 
1553
- fn fsync(&mut self, _datasync: bool) -> Result<(), FilesystemError> {
1556
+ fn fsync(&mut self, _datasync: bool) -> Result<(), Errno> {
1554
1557
  self.0.fetch_add(1, Ordering::SeqCst);
1555
1558
  Ok(())
1556
1559
  }
@@ -1564,42 +1567,38 @@ mod tests {
1564
1567
  }
1565
1568
 
1566
1569
  impl FileOperations for RecordsCalls {
1567
- fn read_iter(
1568
- &mut self,
1569
- _iocb: &mut Kiocb,
1570
- buf: &mut [u8],
1571
- ) -> Result<usize, FilesystemError> {
1570
+ fn read_iter(&mut self, _iocb: &mut Kiocb, buf: &mut [u8]) -> Result<usize, Errno> {
1572
1571
  self.taken.store(buf.len(), Ordering::SeqCst);
1573
1572
  Ok(0)
1574
1573
  }
1575
1574
 
1576
- fn write_iter(&mut self, iocb: &mut Kiocb, buf: &[u8]) -> Result<usize, FilesystemError> {
1575
+ fn write_iter(&mut self, iocb: &mut Kiocb, buf: &[u8]) -> Result<usize, Errno> {
1577
1576
  self.taken.store(buf.len(), Ordering::SeqCst);
1578
1577
  generic_write_sync(self, iocb, buf.len())
1579
1578
  }
1580
1579
 
1581
- fn fsync(&mut self, datasync: bool) -> Result<(), FilesystemError> {
1580
+ fn fsync(&mut self, datasync: bool) -> Result<(), Errno> {
1582
1581
  self.syncs.lock().expect("never poisoned").push(datasync);
1583
1582
  Ok(())
1584
1583
  }
1585
1584
  }
1586
1585
 
1587
1586
  impl crate::vfs::FileSystemType for RecordsCalls {
1588
- fn fill_super(self: Arc<Self>, sb: &mut Filesystem) -> Result<(), FilesystemError> {
1587
+ fn fill_super(self: Arc<Self>, sb: &mut Filesystem) -> Result<(), Errno> {
1589
1588
  sb.d_make_root(Inode::new(&Kstat::new(FileType::Dir, 0), self));
1590
1589
  Ok(())
1591
1590
  }
1592
1591
  }
1593
1592
 
1594
1593
  impl InodeOperations for RecordsCalls {
1595
- fn getattr(&self, dentry: &Dentry) -> Result<Kstat, FilesystemError> {
1594
+ fn getattr(&self, dentry: &Dentry) -> Result<Kstat, Errno> {
1596
1595
  Ok(match dentry.is_root() {
1597
1596
  false => Kstat::new(FileType::RegFile, 0),
1598
1597
  true => Kstat::new(FileType::Dir, 0),
1599
1598
  })
1600
1599
  }
1601
1600
 
1602
- fn lookup(&self, _dentry: &Dentry) -> Result<Lookup, FilesystemError> {
1601
+ fn lookup(&self, _dentry: &Dentry) -> Result<Lookup, Errno> {
1603
1602
  let found = Kstat::new(FileType::RegFile, 0);
1604
1603
  Ok(Lookup::Found(Inode::new(&found, Arc::new(self.clone()))))
1605
1604
  }
@@ -1608,7 +1607,7 @@ mod tests {
1608
1607
  &self,
1609
1608
  _dentry: &Dentry,
1610
1609
  _options: &OpenHow,
1611
- ) -> Result<Box<dyn FileOperations>, FilesystemError> {
1610
+ ) -> Result<Box<dyn FileOperations>, Errno> {
1612
1611
  Ok(Box::new(self.clone()))
1613
1612
  }
1614
1613
  }
@@ -1617,7 +1616,7 @@ mod tests {
1617
1616
  fn open_recording(calls: &RecordsCalls, how: OpenHow) -> File {
1618
1617
  let mount = Mount::new(
1619
1618
  "/data",
1620
- Filesystem::new(Arc::new(calls.clone())).expect("the instance must stand"),
1619
+ Filesystem::new(calls.clone()).expect("the instance must stand"),
1621
1620
  Access::ReadWrite,
1622
1621
  )
1623
1622
  .expect("/data is a guest path");
@@ -1689,18 +1688,18 @@ mod tests {
1689
1688
  struct HoldsCountsSyncs(Arc<AtomicUsize>);
1690
1689
 
1691
1690
  impl crate::vfs::FileSystemType for HoldsCountsSyncs {
1692
- fn fill_super(self: Arc<Self>, sb: &mut Filesystem) -> Result<(), FilesystemError> {
1691
+ fn fill_super(self: Arc<Self>, sb: &mut Filesystem) -> Result<(), Errno> {
1693
1692
  sb.d_make_root(Inode::new(&Kstat::new(FileType::Dir, 0), self));
1694
1693
  Ok(())
1695
1694
  }
1696
1695
  }
1697
1696
 
1698
1697
  impl InodeOperations for HoldsCountsSyncs {
1699
- fn getattr(&self, _dentry: &Dentry) -> Result<Kstat, FilesystemError> {
1698
+ fn getattr(&self, _dentry: &Dentry) -> Result<Kstat, Errno> {
1700
1699
  Ok(Kstat::new(FileType::Dir, 0))
1701
1700
  }
1702
1701
 
1703
- fn lookup(&self, _dentry: &Dentry) -> Result<Lookup, FilesystemError> {
1702
+ fn lookup(&self, _dentry: &Dentry) -> Result<Lookup, Errno> {
1704
1703
  let found = Kstat::new(FileType::RegFile, 0);
1705
1704
  let ops = Arc::new(Self(self.0.clone()));
1706
1705
  Ok(Lookup::Found(Inode::new(&found, ops)))
@@ -1710,7 +1709,7 @@ mod tests {
1710
1709
  &self,
1711
1710
  _dentry: &Dentry,
1712
1711
  _options: &OpenHow,
1713
- ) -> Result<Box<dyn FileOperations>, FilesystemError> {
1712
+ ) -> Result<Box<dyn FileOperations>, Errno> {
1714
1713
  Ok(Box::new(CountsSyncs(self.0.clone())))
1715
1714
  }
1716
1715
  }
@@ -1721,8 +1720,7 @@ mod tests {
1721
1720
  let syncs = Arc::new(AtomicUsize::new(0));
1722
1721
  let mount = Mount::new(
1723
1722
  "/data",
1724
- Filesystem::new(Arc::new(HoldsCountsSyncs(syncs.clone())))
1725
- .expect("the instance must stand"),
1723
+ Filesystem::new(HoldsCountsSyncs(syncs.clone())).expect("the instance must stand"),
1726
1724
  Access::ReadWrite,
1727
1725
  )
1728
1726
  .expect("/data is a guest path");
@@ -1771,7 +1769,7 @@ mod tests {
1771
1769
  let dir = filp_open(&Arc::default(), &Path::root(mount.mnt()), "dir", &how)
1772
1770
  .unwrap_or_else(|_| panic!("the directory must open"));
1773
1771
  assert_eq!(
1774
- (dir.nonblock(), dir.sync()),
1772
+ (dir.is_nonblock(), dir.is_sync()),
1775
1773
  (true, true),
1776
1774
  "File::nonblock and File::sync on a directory do_file_open opened with both must \
1777
1775
  report them, as F_GETFL does"
@@ -1803,12 +1801,12 @@ mod tests {
1803
1801
  dir.fadvise(0, 0),
1804
1802
  ),
1805
1803
  (
1806
- Err(FilesystemError::IsADirectory),
1807
- Err(FilesystemError::IsADirectory),
1808
- Err(FilesystemError::BadDescriptor),
1809
- Err(FilesystemError::BadDescriptor),
1810
- Err(FilesystemError::InvalidInput),
1811
- Err(FilesystemError::BadDescriptor),
1804
+ Err(Errno::IsADirectory),
1805
+ Err(Errno::IsADirectory),
1806
+ Err(Errno::BadDescriptor),
1807
+ Err(Errno::BadDescriptor),
1808
+ Err(Errno::InvalidInput),
1809
+ Err(Errno::BadDescriptor),
1812
1810
  Ok(()),
1813
1811
  Ok(()),
1814
1812
  ),
@@ -1834,10 +1832,7 @@ mod tests {
1834
1832
  alloc_file_pseudo(inode, &mnt, &how, Box::new(NoOperations), &Arc::default());
1835
1833
  assert_eq!(
1836
1834
  (file.pread(&mut [0], 0), file.pwrite(b"x", 0)),
1837
- (
1838
- Err(FilesystemError::NotSeekable),
1839
- Err(FilesystemError::NotSeekable)
1840
- ),
1835
+ (Err(Errno::NotSeekable), Err(Errno::NotSeekable)),
1841
1836
  "File::pread and File::pwrite on a file alloc_file_pseudo made must answer ESPIPE, \
1842
1837
  as file_init_path gives no FMODE_PREAD or FMODE_PWRITE"
1843
1838
  );
@@ -1870,10 +1865,10 @@ mod tests {
1870
1865
  pipe.fallocate(0, 1),
1871
1866
  ),
1872
1867
  (
1873
- Err(FilesystemError::InvalidInput),
1874
- Err(FilesystemError::BadDescriptor),
1875
- Err(FilesystemError::Unsupported),
1876
- Err(FilesystemError::NotSeekable),
1868
+ Err(Errno::InvalidInput),
1869
+ Err(Errno::BadDescriptor),
1870
+ Err(Errno::Unsupported),
1871
+ Err(Errno::NotSeekable),
1877
1872
  ),
1878
1873
  "File::fallocate must answer an empty range EINVAL, a file not open to write EBADF, \
1879
1874
  a file without fallocate ENOTSUP, and a pipe ESPIPE, as vfs_fallocate does"
@@ -1899,13 +1894,13 @@ mod tests {
1899
1894
  file.pwrite(b"", OFFSET_MAX),
1900
1895
  ),
1901
1896
  (
1902
- Err(FilesystemError::InvalidInput),
1903
- Err(FilesystemError::InvalidInput),
1904
- Err(FilesystemError::InvalidInput),
1905
- Err(FilesystemError::InvalidInput),
1906
- Err(FilesystemError::InvalidInput),
1907
- Err(FilesystemError::InvalidInput),
1908
- Err(FilesystemError::InvalidInput),
1897
+ Err(Errno::InvalidInput),
1898
+ Err(Errno::InvalidInput),
1899
+ Err(Errno::InvalidInput),
1900
+ Err(Errno::InvalidInput),
1901
+ Err(Errno::InvalidInput),
1902
+ Err(Errno::InvalidInput),
1903
+ Err(Errno::InvalidInput),
1909
1904
  Ok(0),
1910
1905
  ),
1911
1906
  "File calls ending past the largest signed offset must answer EINVAL, as \