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
@@ -9,22 +9,21 @@
9
9
  //! started from, as `openat2`'s `RESOLVE_BENEATH` keeps a resolution: one
10
10
  //! leading out of it, or to an absolute path, escapes it.
11
11
 
12
- use std::cell::Cell;
13
12
  use std::collections::VecDeque;
14
- use std::rc::Rc;
15
13
  use std::sync::Arc;
16
14
 
17
15
  use super::attr::notify_change;
18
- use super::cred::{on_path, Cred, FileSecurity};
19
- use super::dentry::{Dentry, RENAME_LOCK};
16
+ use super::dentry::Dentry;
20
17
  use super::file::{do_dentry_open, FMode, File, FileOperations};
21
18
  use super::inode::{Finish, Inode, Mask, RenameFlag};
22
19
  use super::mount::VfsMount;
23
20
  use super::openat2::{OpenFlags, OpenHow};
24
21
  use super::path::{Path, Start};
25
22
  use super::super_block::SuperBlock;
26
- use super::{FileType, FilesystemError, Iattr, Kstat};
23
+ use super::{Errno, FileType, Iattr, Kstat};
24
+ use crate::cred::Cred;
27
25
  use crate::locking::RwSemaphoreGuard;
26
+ use crate::security::{on_path, FileSecurity};
28
27
 
29
28
  use super::PATH_MAX;
30
29
 
@@ -39,6 +38,13 @@ enum LastType {
39
38
  DotDot,
40
39
  }
41
40
 
41
+ /// Where a walk stood when it stepped onto a mount.
42
+ struct Crossed {
43
+ mnt: Arc<VfsMount>,
44
+ dir: Arc<Dentry>,
45
+ r_seq: usize,
46
+ }
47
+
42
48
  /// A path walked beneath a directory, as Linux's `nameidata` carries
43
49
  /// one walk from where it starts to the call it ends in: the directories
44
50
  /// it stands in, the names still to walk, the last name left for the call to
@@ -49,14 +55,26 @@ pub(crate) struct Nameidata {
49
55
  /// The directory the walk started from, which no `..` climbs above, as
50
56
  /// `nd->root` holds it for `RESOLVE_BENEATH`.
51
57
  root: Arc<Dentry>,
52
- /// Where `RENAME_LOCK` stood when the walk began, as `nd->r_seq`.
58
+ /// Where the rename lock of the Filesystem the walk stands on stood when
59
+ /// the walk stepped onto it, as `nd->r_seq`. It is that instance's alone,
60
+ /// since only a move on it carries the directories a `..` reads there.
53
61
  r_seq: usize,
54
62
  /// The directory the walk stands in, which holds the last name.
55
63
  dir: Arc<Dentry>,
64
+ /// Where the walk stood each time it stepped onto a mount, innermost last,
65
+ /// with the `r_seq` it held there, so a `..` from that mount's root climbs
66
+ /// back, as `choose_mountpoint` follows `mnt_parent`. The walk keeps them
67
+ /// itself: a mount may stand where its parent holds no entry for it. Each
68
+ /// keeps its own `r_seq` even where one instance is mounted twice along the
69
+ /// walk, so a move landing between the two is still learned of below.
70
+ crossed: Vec<Crossed>,
56
71
  pending: VecDeque<String>,
57
72
  /// The links followed through every walk of one call, as Linux's
58
73
  /// `total_link_count` carries into a walk made again for ESTALE.
59
- total_link_count: Rc<Cell<usize>>,
74
+ total_link_count: usize,
75
+ /// Whether a link anywhere on the path answers ELOOP instead of being
76
+ /// followed, as `LOOKUP_NO_SYMLINKS`.
77
+ lookup_no_symlinks: bool,
60
78
  /// The last name, as Linux's `nd->last`, empty unless it is a `Norm` one.
61
79
  pub(crate) last: String,
62
80
  last_type: LastType,
@@ -86,24 +104,40 @@ impl Nameidata {
86
104
  /// Refuse what the walk ended on unless it still stands beneath where the
87
105
  /// walk started, as `complete_walk` asks `path_is_under` once a move may have
88
106
  /// carried a directory out from under it.
89
- fn complete_walk(&self) -> Result<(), FilesystemError> {
90
- let ended = self.path.as_ref().unwrap_or(&self.dir);
107
+ fn complete_walk(&self) -> Result<(), Errno> {
108
+ let ended = match self.crossed.first() {
109
+ Some(below_start) => &below_start.dir,
110
+ None => self.path.as_ref().unwrap_or(&self.dir),
111
+ };
91
112
  match ended.is_subdir(&self.root) {
92
113
  true => Ok(()),
93
- false => Err(FilesystemError::Escape),
114
+ false => Err(Errno::Escape),
94
115
  }
95
116
  }
96
117
 
118
+ /// Begin the walk of `path` again from `start`, as Linux's `path_init`
119
+ /// readies the same `nameidata` for a walk made again: the links followed
120
+ /// so far and what the caller asked of the walk carry over.
121
+ fn path_init(&mut self, start: &impl Start, path: &str) -> Result<(), Errno> {
122
+ let again = set_nameidata(&self.cred, start, path)?;
123
+ *self = Nameidata {
124
+ total_link_count: self.total_link_count,
125
+ lookup_no_symlinks: self.lookup_no_symlinks,
126
+ ..again
127
+ };
128
+ Ok(())
129
+ }
130
+
97
131
  /// The dentry the walk ended on, as Linux's `do_open` and `vfs_getattr`
98
132
  /// act on what the walk found without looking it up again, so a change
99
133
  /// made since cannot lead the call anywhere but where the walk stands.
100
- pub(crate) fn path(&self) -> Result<Arc<Dentry>, FilesystemError> {
101
- self.path.clone().ok_or(FilesystemError::NotFound)
134
+ pub(crate) fn path(&self) -> Result<Arc<Dentry>, Errno> {
135
+ self.path.clone().ok_or(Errno::NotFound)
102
136
  }
103
137
 
104
138
  /// Find the last name afresh and keep what stands there, as a call looks
105
139
  /// its name up once it holds the directory's lock.
106
- fn lookup_last_locked(&mut self) -> Result<Arc<Dentry>, FilesystemError> {
140
+ fn lookup_last_locked(&mut self) -> Result<Arc<Dentry>, Errno> {
107
141
  let child = lookup_one_qstr_excl(self.mnt.sb(), self.dentry(), &self.last)?;
108
142
  self.path = Some(child.clone());
109
143
  Ok(child)
@@ -111,13 +145,13 @@ impl Nameidata {
111
145
 
112
146
  /// What kind of entry the walk ended on, a link reported as itself, read
113
147
  /// from the dentry as Linux's `d_is_*` do.
114
- pub(crate) fn kind(&self) -> Result<FileType, FilesystemError> {
115
- self.path()?.kind()
148
+ pub(crate) fn file_type(&self) -> Result<FileType, Errno> {
149
+ self.path()?.file_type()
116
150
  }
117
151
 
118
152
  /// What the walk ended on reports of itself, a link reported as itself, as
119
153
  /// `vfs_getattr` asks the entry the walk found.
120
- pub(crate) fn getattr(&self) -> Result<Kstat, FilesystemError> {
154
+ pub(crate) fn getattr(&self) -> Result<Kstat, Errno> {
121
155
  self.path()?.getattr()
122
156
  }
123
157
  }
@@ -125,18 +159,27 @@ impl Nameidata {
125
159
  /// Whether `dentry`, which a lookup answered for, still names what stands at its
126
160
  /// name in `dir`, asked with or without `dir`'s lock as Linux's `lookup_fast`
127
161
  /// and `lookup_open` ask `d_revalidate`. One that does not is let go of with the
128
- /// names kept beneath it, as `d_invalidate` does.
162
+ /// names kept beneath it, as `d_invalidate` does, unless a move landed while it
163
+ /// was asked: the answer was about a name it no longer stands at, so the walk
164
+ /// looks again, as `lookup_fast` retries once `d_seq` moved.
129
165
  pub(crate) fn d_revalidate(
130
166
  sb: &SuperBlock,
131
167
  dir: &Dentry,
132
168
  dentry: &Arc<Dentry>,
133
- ) -> Result<bool, FilesystemError> {
169
+ ) -> Result<bool, Errno> {
170
+ // A mount point stays whatever its Filesystem answers: Linux's
171
+ // `d_invalidate` detaches the mounts on it, which would show the guest
172
+ // what they hid.
173
+ if dentry.d_mountpoint() {
174
+ return Ok(true);
175
+ }
176
+ let asked = dentry.rename_lock().read_seqbegin();
134
177
  let valid = match dentry.ops() {
135
178
  Some(ops) => ops.revalidate(dir.inode_ops()?.as_ref(), dentry)?,
136
179
  None => true,
137
180
  };
138
181
  if !valid {
139
- sb.dentries().invalidate(dentry);
182
+ sb.dentries().invalidate(dentry, asked);
140
183
  }
141
184
  Ok(valid)
142
185
  }
@@ -148,7 +191,7 @@ pub(crate) fn lookup_one_qstr_excl(
148
191
  sb: &SuperBlock,
149
192
  parent: &Arc<Dentry>,
150
193
  name: &str,
151
- ) -> Result<Arc<Dentry>, FilesystemError> {
194
+ ) -> Result<Arc<Dentry>, Errno> {
152
195
  __lookup_slow(sb, parent, name)
153
196
  }
154
197
 
@@ -159,13 +202,9 @@ pub(crate) fn lookup_one_qstr_excl(
159
202
  /// reaching one entry shares its dentry, and so its lock. A directory removed
160
203
  /// through the VFS is asked about no name, as Linux refuses a dead one. The
161
204
  /// dentry stays for the next walk unless its Filesystem keeps none.
162
- fn __lookup_slow(
163
- sb: &SuperBlock,
164
- parent: &Arc<Dentry>,
165
- name: &str,
166
- ) -> Result<Arc<Dentry>, FilesystemError> {
205
+ fn __lookup_slow(sb: &SuperBlock, parent: &Arc<Dentry>, name: &str) -> Result<Arc<Dentry>, Errno> {
167
206
  if parent.is_deaddir() {
168
- return Err(FilesystemError::NotFound);
207
+ return Err(Errno::NotFound);
169
208
  }
170
209
  let given = d_alloc_parallel(sb, parent, name)?;
171
210
  let dentry = given.lookup_inode(sb, parent)?.unwrap_or(given);
@@ -189,7 +228,7 @@ fn d_alloc_parallel(
189
228
  sb: &SuperBlock,
190
229
  parent: &Arc<Dentry>,
191
230
  name: &str,
192
- ) -> Result<Arc<Dentry>, FilesystemError> {
231
+ ) -> Result<Arc<Dentry>, Errno> {
193
232
  loop {
194
233
  let dentry = sb.dentries().alloc_parallel(parent, name)?;
195
234
  if dentry.in_lookup() || d_revalidate(sb, parent, &dentry)? {
@@ -206,7 +245,7 @@ fn lookup_fast(
206
245
  sb: &SuperBlock,
207
246
  parent: &Arc<Dentry>,
208
247
  name: &str,
209
- ) -> Result<Option<Arc<Dentry>>, FilesystemError> {
248
+ ) -> Result<Option<Arc<Dentry>>, Errno> {
210
249
  let Some(dentry) = sb.dentries().lookup(parent, name) else {
211
250
  return Ok(None);
212
251
  };
@@ -221,11 +260,11 @@ fn lookup_fast(
221
260
  /// dcache holds or, failing that, one found holding that directory's lock
222
261
  /// shared, as Linux's `walk_component` tries `lookup_fast` before
223
262
  /// `lookup_slow`.
224
- fn lookup_dentry(
263
+ pub(super) fn lookup_dentry(
225
264
  sb: &SuperBlock,
226
265
  parent: &Arc<Dentry>,
227
266
  name: &str,
228
- ) -> Result<Arc<Dentry>, FilesystemError> {
267
+ ) -> Result<Arc<Dentry>, Errno> {
229
268
  match lookup_fast(sb, parent, name)? {
230
269
  Some(dentry) => Ok(dentry),
231
270
  None => lookup_slow(sb, parent, name),
@@ -239,9 +278,9 @@ fn lookup_one_common(
239
278
  sb: &SuperBlock,
240
279
  parent: &Dentry,
241
280
  name: &str,
242
- ) -> Result<(), FilesystemError> {
281
+ ) -> Result<(), Errno> {
243
282
  if name.is_empty() || name == "." || name == ".." || name.contains(['/', '\0']) {
244
- return Err(FilesystemError::PermissionDenied);
283
+ return Err(Errno::PermissionDenied);
245
284
  }
246
285
  inode_permission(cred, sb, parent, Mask::EXEC)
247
286
  }
@@ -254,7 +293,7 @@ pub(crate) fn lookup_one_unlocked(
254
293
  sb: &SuperBlock,
255
294
  parent: &Arc<Dentry>,
256
295
  name: &str,
257
- ) -> Result<Arc<Dentry>, FilesystemError> {
296
+ ) -> Result<Arc<Dentry>, Errno> {
258
297
  lookup_one_common(cred, sb, parent, name)?;
259
298
  lookup_dentry(sb, parent, name)
260
299
  }
@@ -267,7 +306,7 @@ pub(crate) fn start_creating(
267
306
  sb: &SuperBlock,
268
307
  parent: &Arc<Dentry>,
269
308
  name: &str,
270
- ) -> Result<(RwSemaphoreGuard, Arc<Dentry>), FilesystemError> {
309
+ ) -> Result<(RwSemaphoreGuard, Arc<Dentry>), Errno> {
271
310
  lookup_one_common(cred, sb, parent, name)?;
272
311
  let held = parent.inode_lock()?;
273
312
  Ok((held, __lookup_slow(sb, parent, name)?))
@@ -281,19 +320,15 @@ pub(crate) fn start_removing(
281
320
  sb: &SuperBlock,
282
321
  parent: &Arc<Dentry>,
283
322
  name: &str,
284
- ) -> Result<(RwSemaphoreGuard, Arc<Dentry>), FilesystemError> {
323
+ ) -> Result<(RwSemaphoreGuard, Arc<Dentry>), Errno> {
285
324
  let (held, child) = start_creating(cred, sb, parent, name)?;
286
- child.inode().ok_or(FilesystemError::NotFound)?;
325
+ child.inode().ok_or(Errno::NotFound)?;
287
326
  Ok((held, child))
288
327
  }
289
328
 
290
329
  /// The dentry of `name` in `parent` for a walk passing through, holding that
291
330
  /// directory's lock shared only to find it, as Linux's `lookup_slow` does.
292
- fn lookup_slow(
293
- sb: &SuperBlock,
294
- parent: &Arc<Dentry>,
295
- name: &str,
296
- ) -> Result<Arc<Dentry>, FilesystemError> {
331
+ fn lookup_slow(sb: &SuperBlock, parent: &Arc<Dentry>, name: &str) -> Result<Arc<Dentry>, Errno> {
297
332
  let _held = parent.inode_lock_shared()?;
298
333
  __lookup_slow(sb, parent, name)
299
334
  }
@@ -304,30 +339,67 @@ fn parts(path: &str) -> VecDeque<String> {
304
339
  }
305
340
 
306
341
  impl Nameidata {
307
- /// Step into the directory `name` names, or follow the link standing there.
308
- fn walk_component(&mut self, name: &str) -> Result<(), FilesystemError> {
342
+ /// The mount standing on the dentry `name` reaches in the directory the walk
343
+ /// stands in, by whatever spelling or link reached that dentry.
344
+ fn lookup_mnt_by_name(&self, name: &str) -> Result<Option<Arc<VfsMount>>, Errno> {
345
+ if !self.cred.mnt_ns().has_children(&self.mnt) {
346
+ return Ok(None);
347
+ }
348
+ let dentry = lookup_dentry(self.mnt.sb(), &self.dir, name)?;
349
+ Ok(self.lookup_mnt(&dentry))
350
+ }
351
+
352
+ /// The mount standing on `dentry` beneath the mount the walk stands on, as
353
+ /// `__traverse_mounts` asks `DCACHE_MOUNTED` before `lookup_mnt`.
354
+ fn lookup_mnt(&self, dentry: &Arc<Dentry>) -> Option<Arc<VfsMount>> {
355
+ match dentry.d_mountpoint() {
356
+ true => self.cred.mnt_ns().__lookup_mnt(&self.mnt, dentry),
357
+ false => None,
358
+ }
359
+ }
360
+
361
+ /// Step onto the root of `mnt`, or of the topmost mount stacked over it,
362
+ /// keeping where the walk stood, as `__traverse_mounts` follows a mount
363
+ /// point down to what is mounted there, however many stand on it.
364
+ fn traverse_mounts(&mut self, mnt: Arc<VfsMount>) {
365
+ let mnt = self.cred.mnt_ns().topmost_overmount(&mnt);
366
+ let r_seq = mnt.root().rename_lock().read_seqbegin();
367
+ self.crossed.push(Crossed {
368
+ dir: std::mem::replace(&mut self.dir, mnt.root().clone()),
369
+ mnt: std::mem::replace(&mut self.mnt, mnt),
370
+ r_seq: std::mem::replace(&mut self.r_seq, r_seq),
371
+ });
372
+ }
373
+
374
+ /// Step into the directory `name` names, or onto the mount standing there,
375
+ /// or follow the link standing there.
376
+ fn walk_component(&mut self, name: &str) -> Result<(), Errno> {
309
377
  let dentry = lookup_dentry(self.mnt.sb(), self.dentry(), name)?;
310
- let inode = dentry.inode().ok_or(FilesystemError::NotFound)?;
311
- match inode.kind() {
378
+ if let Some(mnt) = self.lookup_mnt(&dentry) {
379
+ self.traverse_mounts(mnt);
380
+ return Ok(());
381
+ }
382
+ let inode = dentry.inode().ok_or(Errno::NotFound)?;
383
+ match inode.file_type() {
312
384
  FileType::Symlink => self.pick_link(&dentry),
313
385
  FileType::Dir => {
314
386
  self.dir = dentry;
315
387
  Ok(())
316
388
  }
317
- _ => Err(FilesystemError::NotADirectory),
389
+ _ => Err(Errno::NotADirectory),
318
390
  }
319
391
  }
320
392
 
321
393
  /// Walk on through where the link `dentry` names points, before
322
394
  /// whatever is left of the path.
323
- fn pick_link(&mut self, dentry: &Dentry) -> Result<(), FilesystemError> {
324
- self.total_link_count.set(self.total_link_count.get() + 1);
325
- if self.total_link_count.get() > MAXSYMLINKS {
326
- return Err(FilesystemError::FilesystemLoop);
395
+ fn pick_link(&mut self, dentry: &Arc<Dentry>) -> Result<(), Errno> {
396
+ self.total_link_count += 1;
397
+ if self.lookup_no_symlinks || self.total_link_count > MAXSYMLINKS {
398
+ return Err(Errno::FilesystemLoop);
327
399
  }
328
400
  let target = dentry.get_link()?;
329
401
  if target.starts_with('/') {
330
- return Err(FilesystemError::Escape);
402
+ return Err(Errno::Escape);
331
403
  }
332
404
  // A link pointing nowhere leaves the walk where it stands, as Linux's
333
405
  // `pick_link` makes it a pure jump.
@@ -342,28 +414,41 @@ impl Nameidata {
342
414
  }
343
415
 
344
416
  /// Step to the directory above the one the walk stands in, wherever that
345
- /// one stands now, as `follow_dotdot` reads `d_parent`. Out of the one the
346
- /// walk started from, or the mount's root, no `..` holds a capability, as
347
- /// `RESOLVE_BENEATH` refuses a caller's and a link's alike.
348
- fn follow_dotdot(&mut self) -> Result<(), FilesystemError> {
349
- if Arc::ptr_eq(&self.dir, &self.root) || self.dir.is_root() {
350
- return Err(FilesystemError::Escape);
351
- }
352
- self.dir = self.dir.parent();
353
- // A move along the way may have carried `..` above where the walk started,
354
- // so the caller makes the call again, as `handle_dots` answers a scoped walk.
355
- if RENAME_LOCK.read_seqretry(self.r_seq) {
356
- return Err(FilesystemError::WouldBlock);
417
+ /// one stands now, as `follow_dotdot` reads `d_parent`. From the root of a
418
+ /// mount the walk stepped onto, it climbs back to where the walk stood, as
419
+ /// `choose_mountpoint` leads to the mount point. Out of the one the walk
420
+ /// started from, or a mount's root it never stepped onto, no `..` holds a
421
+ /// capability, as `RESOLVE_BENEATH` refuses a caller's and a link's alike.
422
+ fn follow_dotdot(&mut self) -> Result<(), Errno> {
423
+ // Only the mount the walk started on holds where it started, as
424
+ // `path_equal` compares the mount too: the same Filesystem mounted
425
+ // again beneath has the same root dentry.
426
+ if self.crossed.is_empty() && Arc::ptr_eq(&self.dir, &self.root) {
427
+ return Err(Errno::Escape);
428
+ }
429
+ if self.dir.is_root() {
430
+ let crossed = self.crossed.pop().ok_or(Errno::Escape)?;
431
+ self.mnt = crossed.mnt;
432
+ self.dir = crossed.dir;
433
+ self.r_seq = crossed.r_seq;
434
+ } else {
435
+ self.dir = self.dir.parent();
436
+ }
437
+ // A move on the Filesystem it now stands on may have carried `..` above
438
+ // where the walk started, so the caller makes the call again, as
439
+ // `handle_dots` answers a scoped walk however the `..` was taken.
440
+ if self.dir.rename_lock().read_seqretry(self.r_seq) {
441
+ return Err(Errno::WouldBlock);
357
442
  }
358
443
  Ok(())
359
444
  }
360
445
 
361
446
  /// Walk every name but the last, which is left for the call to act on, as
362
447
  /// Linux's `link_path_walk` leaves `nd->last` and `nd->last_type`.
363
- fn link_path_walk(&mut self) -> Result<(), FilesystemError> {
448
+ fn link_path_walk(&mut self) -> Result<(), Errno> {
364
449
  loop {
365
450
  inode_permission(&self.cred, self.mnt.sb(), self.dentry(), Mask::EXEC)?;
366
- let part = self.pending.pop_front().ok_or(FilesystemError::NotFound)?;
451
+ let part = self.pending.pop_front().ok_or(Errno::NotFound)?;
367
452
  let slashes = self
368
453
  .pending
369
454
  .iter()
@@ -396,8 +481,19 @@ impl Nameidata {
396
481
  self.trailing_slash = trailing_slash;
397
482
  }
398
483
 
484
+ /// Stand on the root of the mount standing on the last name, if one does,
485
+ /// as `step_into` answers a mount point with what is mounted there.
486
+ fn step_onto_last_mount(&mut self) -> Result<bool, Errno> {
487
+ let Some(mnt) = self.lookup_mnt_by_name(&self.last)? else {
488
+ return Ok(false);
489
+ };
490
+ self.traverse_mounts(mnt);
491
+ self.path = Some(self.dir.clone());
492
+ Ok(true)
493
+ }
494
+
399
495
  /// Stand where a last `.` or `..` leads, as Linux's `handle_dots` does.
400
- fn handle_dots(&mut self) -> Result<(), FilesystemError> {
496
+ fn handle_dots(&mut self) -> Result<(), Errno> {
401
497
  if self.last_type == LastType::DotDot {
402
498
  self.follow_dotdot()?;
403
499
  }
@@ -409,7 +505,7 @@ impl Nameidata {
409
505
  /// trailing `/` follows a link there and asks for a directory, a link
410
506
  /// followed leaves another last name to find, and nothing standing there is
411
507
  /// ENOENT, as `step_into` answers before the walk is checked.
412
- fn lookup_last(&mut self, mut follow: bool) -> Result<(), FilesystemError> {
508
+ fn lookup_last(&mut self, mut follow: bool) -> Result<(), Errno> {
413
509
  loop {
414
510
  if self.last_type != LastType::Norm {
415
511
  return self.handle_dots();
@@ -418,12 +514,15 @@ impl Nameidata {
418
514
  follow = true;
419
515
  self.lookup_directory = true;
420
516
  }
517
+ if self.step_onto_last_mount()? {
518
+ return Ok(());
519
+ }
421
520
  let child = lookup_dentry(self.mnt.sb(), self.dentry(), &self.last)?;
422
521
  self.path = Some(child.clone());
423
522
  if child.inode().is_none() {
424
- return Err(FilesystemError::NotFound);
523
+ return Err(Errno::NotFound);
425
524
  }
426
- if !follow || child.kind() != Ok(FileType::Symlink) {
525
+ if !follow || child.file_type() != Ok(FileType::Symlink) {
427
526
  return Ok(());
428
527
  }
429
528
  self.pick_link(&child)?;
@@ -441,7 +540,7 @@ impl Nameidata {
441
540
  how: &OpenHow,
442
541
  mode: FMode,
443
542
  mut follow: bool,
444
- ) -> Result<Open, FilesystemError> {
543
+ ) -> Result<Open, Errno> {
445
544
  loop {
446
545
  if self.last_type != LastType::Norm {
447
546
  self.handle_dots()?;
@@ -449,23 +548,29 @@ impl Nameidata {
449
548
  }
450
549
  if self.trailing_slash {
451
550
  if how.create {
452
- return Err(FilesystemError::IsADirectory);
551
+ return Err(Errno::IsADirectory);
453
552
  }
454
553
  follow = true;
455
554
  self.lookup_directory = true;
456
555
  }
556
+ if self.step_onto_last_mount()? {
557
+ if how.create && how.exclusive {
558
+ return Err(Errno::AlreadyExists);
559
+ }
560
+ return Ok(Open { file: None, mode });
561
+ }
457
562
  let (child, opened) = match self.lookup_fast_for_open(how)? {
458
563
  Some(child) => {
459
564
  self.path = Some(child.clone());
460
565
  if child.inode().is_none() {
461
- return Err(FilesystemError::NotFound);
566
+ return Err(Errno::NotFound);
462
567
  }
463
568
  (child, Open { file: None, mode })
464
569
  }
465
570
  None => self.lookup_open(how, mode)?,
466
571
  };
467
572
  let finished = opened.file.is_some() || opened.mode.contains(FMode::CREATED);
468
- if finished || !follow || child.kind() != Ok(FileType::Symlink) {
573
+ if finished || !follow || child.file_type() != Ok(FileType::Symlink) {
469
574
  return Ok(opened);
470
575
  }
471
576
  self.pick_link(&child)?;
@@ -477,7 +582,7 @@ impl Nameidata {
477
582
  /// `lookup_fast_for_open` takes it without the directory's lock: none for
478
583
  /// an exclusive make, or where nothing stands at a name the open may make,
479
584
  /// as only `lookup_open` makes one.
480
- fn lookup_fast_for_open(&self, how: &OpenHow) -> Result<Option<Arc<Dentry>>, FilesystemError> {
585
+ fn lookup_fast_for_open(&self, how: &OpenHow) -> Result<Option<Arc<Dentry>>, Errno> {
481
586
  if how.create && how.exclusive {
482
587
  return Ok(None);
483
588
  }
@@ -497,14 +602,10 @@ impl Nameidata {
497
602
  /// only where nothing stands, as `create_error` does. A Filesystem opening
498
603
  /// the file too finishes it through `do_dentry_open` here, as its
499
604
  /// `finish_open` does.
500
- fn lookup_open(
501
- &mut self,
502
- how: &OpenHow,
503
- mode: FMode,
504
- ) -> Result<(Arc<Dentry>, Open), FilesystemError> {
605
+ fn lookup_open(&mut self, how: &OpenHow, mode: FMode) -> Result<(Arc<Dentry>, Open), Errno> {
505
606
  let got_write = match how.create || how.truncate || how.write {
506
607
  true => self.mnt.mnt_want_write(),
507
- false => Err(FilesystemError::ReadOnlyFilesystem),
608
+ false => Err(Errno::ReadOnlyFilesystem),
508
609
  };
509
610
  let dir = self.dentry().clone();
510
611
  let _held = match how.create {
@@ -512,7 +613,7 @@ impl Nameidata {
512
613
  false => dir.inode_lock_shared()?,
513
614
  };
514
615
  if dir.is_deaddir() {
515
- return Err(FilesystemError::NotFound);
616
+ return Err(Errno::NotFound);
516
617
  }
517
618
  let mnt = self.mnt.clone();
518
619
  let given = d_alloc_parallel(mnt.sb(), &dir, &self.last)?;
@@ -546,14 +647,14 @@ impl Nameidata {
546
647
  created,
547
648
  spliced,
548
649
  } = match (asked, &create_error) {
549
- (Err(FilesystemError::NotFound), Some(refused)) => return Err(refused.clone()),
650
+ (Err(Errno::NotFound), Some(refused)) => return Err(refused.clone()),
550
651
  (asked, _) => asked?,
551
652
  };
552
653
  let child = spliced.unwrap_or(given);
553
654
  retain(mnt.sb(), &child);
554
655
  self.path = Some(child.clone());
555
656
  if child.inode().is_none() {
556
- return Err(create_error.unwrap_or(FilesystemError::NotFound));
657
+ return Err(create_error.unwrap_or(Errno::NotFound));
557
658
  }
558
659
  let mode = match created {
559
660
  true => mode.with(FMode::CREATED),
@@ -561,7 +662,7 @@ impl Nameidata {
561
662
  };
562
663
  let file = match file {
563
664
  Some(file) => {
564
- let kind = child.kind()?;
665
+ let kind = child.file_type()?;
565
666
  let opened = on_path(&self.mnt, &child, |path| {
566
667
  do_dentry_open(&self.cred, path, kind, mode, how, || Ok(file))
567
668
  })?;
@@ -574,7 +675,7 @@ impl Nameidata {
574
675
 
575
676
  /// Whether the open may make the file `child` names here, as Linux's
576
677
  /// `may_o_create` asks once the mount took a write.
577
- fn may_o_create(&self, child: &Dentry) -> Result<(), FilesystemError> {
678
+ fn may_o_create(&self, child: &Dentry) -> Result<(), Errno> {
578
679
  on_path(&self.mnt, child, |path| self.cred.security_path_mknod(path))?;
579
680
  may_create_dentry(&self.cred, self.mnt.sb(), self.dentry(), child)
580
681
  }
@@ -585,15 +686,15 @@ impl Nameidata {
585
686
  /// terminating NUL is too long, and one holding a NUL names nothing a
586
687
  /// Filesystem can hold. It answers before a walk looks up where it starts, as
587
688
  /// Linux's syscalls take the name before `path_init` takes the descriptor.
588
- fn getname(path: &str) -> Result<(), FilesystemError> {
689
+ fn getname(path: &str) -> Result<(), Errno> {
589
690
  if path.is_empty() {
590
- return Err(FilesystemError::NotFound);
691
+ return Err(Errno::NotFound);
591
692
  }
592
693
  if path.len() >= PATH_MAX {
593
- return Err(FilesystemError::InvalidFilename);
694
+ return Err(Errno::InvalidFilename);
594
695
  }
595
696
  if path.contains('\0') {
596
- return Err(FilesystemError::InvalidInput);
697
+ return Err(Errno::InvalidInput);
597
698
  }
598
699
  Ok(())
599
700
  }
@@ -605,7 +706,7 @@ pub(crate) fn inode_permission(
605
706
  sb: &SuperBlock,
606
707
  dentry: &Dentry,
607
708
  mask: Mask,
608
- ) -> Result<(), FilesystemError> {
709
+ ) -> Result<(), Errno> {
609
710
  sb_permission(sb, dentry, mask)?;
610
711
  dentry.inode_ops()?.permission(dentry, mask)?;
611
712
  cred.security_inode_permission(dentry, mask)
@@ -613,14 +714,12 @@ pub(crate) fn inode_permission(
613
714
 
614
715
  /// Refuse a write to a file, a directory, or a link of a read-only `sb`, as
615
716
  /// Linux's `sb_permission` does before any Filesystem or module is asked.
616
- fn sb_permission(sb: &SuperBlock, dentry: &Dentry, mask: Mask) -> Result<(), FilesystemError> {
717
+ fn sb_permission(sb: &SuperBlock, dentry: &Dentry, mask: Mask) -> Result<(), Errno> {
617
718
  if !mask.contains(Mask::WRITE) || !sb.rdonly() {
618
719
  return Ok(());
619
720
  }
620
- match dentry.kind()? {
621
- FileType::RegFile | FileType::Dir | FileType::Symlink => {
622
- Err(FilesystemError::ReadOnlyFilesystem)
623
- }
721
+ match dentry.file_type()? {
722
+ FileType::RegFile | FileType::Dir | FileType::Symlink => Err(Errno::ReadOnlyFilesystem),
624
723
  _ => Ok(()),
625
724
  }
626
725
  }
@@ -629,29 +728,25 @@ fn sb_permission(sb: &SuperBlock, dentry: &Dentry, mask: Mask) -> Result<(), Fil
629
728
  /// `set_nameidata` and `path_init` make one. A path no call can take answers
630
729
  /// first, wherever it starts; an absolute one is not the caller's to reach, so
631
730
  /// no start is looked for; and a walk starts from nothing but a directory.
632
- /// Each walk of one call counts its links toward `total_link_count`.
633
- fn set_nameidata(
634
- cred: &Arc<Cred>,
635
- start: &impl Start,
636
- path: &str,
637
- total_link_count: &Rc<Cell<usize>>,
638
- ) -> Result<Nameidata, FilesystemError> {
731
+ fn set_nameidata(cred: &Arc<Cred>, start: &impl Start, path: &str) -> Result<Nameidata, Errno> {
639
732
  getname(path)?;
640
733
  if path.starts_with('/') {
641
- return Err(FilesystemError::Escape);
734
+ return Err(Errno::Escape);
642
735
  }
643
736
  let start = start.path_init()?;
644
- if start.dentry().kind()? != FileType::Dir {
645
- return Err(FilesystemError::NotADirectory);
737
+ if start.dentry().file_type()? != FileType::Dir {
738
+ return Err(Errno::NotADirectory);
646
739
  }
647
740
  Ok(Nameidata {
648
741
  mnt: start.mnt().clone(),
649
742
  cred: cred.clone(),
650
743
  root: start.dentry().clone(),
651
- r_seq: RENAME_LOCK.read_seqbegin(),
744
+ r_seq: start.dentry().rename_lock().read_seqbegin(),
652
745
  dir: start.dentry().clone(),
746
+ crossed: Vec::new(),
653
747
  pending: parts(path),
654
- total_link_count: total_link_count.clone(),
748
+ total_link_count: 0,
749
+ lookup_no_symlinks: false,
655
750
  last: String::new(),
656
751
  last_type: LastType::Dot,
657
752
  trailing_slash: false,
@@ -667,25 +762,30 @@ pub(crate) fn filename_parentat(
667
762
  cred: &Arc<Cred>,
668
763
  start: &impl Start,
669
764
  path: &str,
670
- ) -> Result<Nameidata, FilesystemError> {
671
- let total_link_count = Rc::default();
672
- walk_with_reval(|| {
673
- let mut nd = set_nameidata(cred, start, path, &total_link_count)?;
765
+ ) -> Result<Nameidata, Errno> {
766
+ let mut nd = set_nameidata(cred, start, path)?;
767
+ walk_with_reval(&mut nd, start, path, |nd| {
674
768
  nd.link_path_walk()?;
675
- nd.complete_walk()?;
676
- Ok(nd)
677
- })
769
+ nd.complete_walk()
770
+ })?;
771
+ Ok(nd)
678
772
  }
679
773
 
680
- /// What `walk` answers, walked once more where it answers ESTALE, as Linux's
681
- /// `filename_lookup` walks again with `LOOKUP_REVAL`, so a directory found
682
- /// moving meanwhile is reached where it went. Every walk asks `revalidate` of
683
- /// what it holds already, so the second takes no flag.
774
+ /// What `walk` answers on `nd`, walked once more from `start` where it answers
775
+ /// ESTALE, as Linux's `filename_lookup` walks again with `LOOKUP_REVAL`, so a
776
+ /// directory found moving meanwhile is reached where it went. Every walk asks
777
+ /// `revalidate` of what it holds already, so the second takes no flag.
684
778
  fn walk_with_reval<T>(
685
- mut walk: impl FnMut() -> Result<T, FilesystemError>,
686
- ) -> Result<T, FilesystemError> {
687
- match walk() {
688
- Err(FilesystemError::StaleNetworkFileHandle) => walk(),
779
+ nd: &mut Nameidata,
780
+ start: &impl Start,
781
+ path: &str,
782
+ mut walk: impl FnMut(&mut Nameidata) -> Result<T, Errno>,
783
+ ) -> Result<T, Errno> {
784
+ match walk(nd) {
785
+ Err(Errno::StaleNetworkFileHandle) => {
786
+ nd.path_init(start, path)?;
787
+ walk(nd)
788
+ }
689
789
  answered => answered,
690
790
  }
691
791
  }
@@ -695,11 +795,11 @@ fn walk_with_reval<T>(
695
795
  /// allows. The walk's own error returns as it stands, as the walk was made
696
796
  /// again already.
697
797
  pub(super) fn retry_estale<W, T>(
698
- mut walk: impl FnMut() -> Result<W, FilesystemError>,
699
- mut act: impl FnMut(W) -> Result<T, FilesystemError>,
700
- ) -> Result<T, FilesystemError> {
798
+ mut walk: impl FnMut() -> Result<W, Errno>,
799
+ mut act: impl FnMut(W) -> Result<T, Errno>,
800
+ ) -> Result<T, Errno> {
701
801
  match act(walk()?) {
702
- Err(FilesystemError::StaleNetworkFileHandle) => act(walk()?),
802
+ Err(Errno::StaleNetworkFileHandle) => act(walk()?),
703
803
  answered => answered,
704
804
  }
705
805
  }
@@ -713,21 +813,37 @@ pub(crate) fn filename_lookup(
713
813
  start: &impl Start,
714
814
  path: &str,
715
815
  follow: bool,
716
- ) -> Result<Nameidata, FilesystemError> {
717
- let total_link_count = Rc::default();
718
- walk_with_reval(|| path_lookupat(set_nameidata(cred, start, path, &total_link_count)?, follow))
816
+ ) -> Result<Nameidata, Errno> {
817
+ let mut nd = set_nameidata(cred, start, path)?;
818
+ walk_with_reval(&mut nd, start, path, |nd| path_lookupat(nd, follow))?;
819
+ Ok(nd)
820
+ }
821
+
822
+ /// Walk `path` beneath `start` to where a mount is to stand, as `do_mount`
823
+ /// looks its target up, but with `LOOKUP_NO_SYMLINKS`: each Invocation places
824
+ /// the mount by its path again, and a link another Filesystem changed meanwhile
825
+ /// would move it off what it hides.
826
+ pub(crate) fn walk_mountpoint(
827
+ cred: &Arc<Cred>,
828
+ start: &impl Start,
829
+ path: &str,
830
+ ) -> Result<Nameidata, Errno> {
831
+ let mut nd = set_nameidata(cred, start, path)?;
832
+ nd.lookup_no_symlinks = true;
833
+ walk_with_reval(&mut nd, start, path, |nd| path_lookupat(nd, true))?;
834
+ Ok(nd)
719
835
  }
720
836
 
721
837
  /// Walk `nd` to what its path names, as Linux's `path_lookupat`.
722
- fn path_lookupat(mut nd: Nameidata, follow: bool) -> Result<Nameidata, FilesystemError> {
838
+ fn path_lookupat(nd: &mut Nameidata, follow: bool) -> Result<(), Errno> {
723
839
  nd.link_path_walk()?;
724
840
  nd.lookup_last(follow)?;
725
841
  nd.complete_walk()?;
726
- let kind = nd.kind()?;
842
+ let kind = nd.file_type()?;
727
843
  if nd.lookup_directory && kind != FileType::Dir {
728
- return Err(FilesystemError::NotADirectory);
844
+ return Err(Errno::NotADirectory);
729
845
  }
730
- Ok(nd)
846
+ Ok(())
731
847
  }
732
848
 
733
849
  /// Open `path` beneath `start` as `op` asks, as Linux's `do_file_open`
@@ -739,14 +855,14 @@ pub fn do_file_open(
739
855
  start: &impl Start,
740
856
  path: &str,
741
857
  op: &OpenFlags,
742
- ) -> Result<File, FilesystemError> {
743
- let total_link_count = Rc::default();
744
- walk_with_reval(|| path_openat(set_nameidata(cred, start, path, &total_link_count)?, op))
858
+ ) -> Result<File, Errno> {
859
+ let mut nd = set_nameidata(cred, start, path)?;
860
+ walk_with_reval(&mut nd, start, path, |nd| path_openat(nd, op))
745
861
  }
746
862
 
747
863
  /// Walk `nd` to its last name and open it as `op` asks, as Linux's
748
864
  /// `path_openat`.
749
- fn path_openat(mut nd: Nameidata, op: &OpenFlags) -> Result<File, FilesystemError> {
865
+ fn path_openat(nd: &mut Nameidata, op: &OpenFlags) -> Result<File, Errno> {
750
866
  let how = op.open_flag();
751
867
  nd.lookup_directory = op.lookup_directory();
752
868
  let mode = FMode::of(how);
@@ -756,17 +872,17 @@ fn path_openat(mut nd: Nameidata, op: &OpenFlags) -> Result<File, FilesystemErro
756
872
  nd.link_path_walk()?;
757
873
  let opened = nd.open_last_lookups(how, mode, op.lookup_follow())?;
758
874
  let child = nd.path()?;
759
- do_open(&nd, child, opened, op)
875
+ do_open(nd, child, opened, op)
760
876
  }
761
877
 
762
878
  /// Stand for what `nd` names without opening it, as Linux's `do_o_path` walks
763
879
  /// with `path_lookupat` and opens nothing: no permission is asked and nothing
764
880
  /// is made or emptied.
765
- fn do_o_path(nd: Nameidata, op: &OpenFlags) -> Result<File, FilesystemError> {
881
+ fn do_o_path(nd: &mut Nameidata, op: &OpenFlags) -> Result<File, Errno> {
766
882
  let how = op.open_flag();
767
- let nd = path_lookupat(nd, op.lookup_follow())?;
883
+ path_lookupat(nd, op.lookup_follow())?;
768
884
  let child = nd.path()?;
769
- let kind = child.kind()?;
885
+ let kind = child.file_type()?;
770
886
  let (f_op, security) = on_path(&nd.mnt, &child, |path| {
771
887
  do_dentry_open(&nd.cred, path, kind, FMode::PATH, how, || child.open(how))
772
888
  })?;
@@ -799,7 +915,7 @@ fn do_open(
799
915
  child: Arc<Dentry>,
800
916
  opened: Open,
801
917
  op: &OpenFlags,
802
- ) -> Result<File, FilesystemError> {
918
+ ) -> Result<File, Errno> {
803
919
  let how = op.open_flag();
804
920
  let mode = opened.mode;
805
921
  let created = mode.contains(FMode::CREATED);
@@ -808,12 +924,12 @@ fn do_open(
808
924
  }
809
925
  // The walk followed every link the call asked it to, so a link at the
810
926
  // end now is one swapped in since, and is opened as itself.
811
- let kind = child.kind()?;
927
+ let kind = child.file_type()?;
812
928
  let refusal = match kind {
813
- _ if how.create && how.exclusive && !created => Some(FilesystemError::AlreadyExists),
814
- FileType::Dir if how.create => Some(FilesystemError::IsADirectory),
929
+ _ if how.create && how.exclusive && !created => Some(Errno::AlreadyExists),
930
+ FileType::Dir if how.create => Some(Errno::IsADirectory),
815
931
  FileType::Dir => None,
816
- _ if nd.lookup_directory => Some(FilesystemError::NotADirectory),
932
+ _ if nd.lookup_directory => Some(Errno::NotADirectory),
817
933
  _ => None,
818
934
  };
819
935
  if let Some(error) = refusal {
@@ -861,10 +977,10 @@ fn may_open(
861
977
  child: &Dentry,
862
978
  kind: FileType,
863
979
  mask: Mask,
864
- ) -> Result<(), FilesystemError> {
980
+ ) -> Result<(), Errno> {
865
981
  match kind {
866
- FileType::Symlink => return Err(FilesystemError::FilesystemLoop),
867
- FileType::Dir if mask.contains(Mask::WRITE) => return Err(FilesystemError::IsADirectory),
982
+ FileType::Symlink => return Err(Errno::FilesystemLoop),
983
+ FileType::Dir if mask.contains(Mask::WRITE) => return Err(Errno::IsADirectory),
868
984
  _ => {}
869
985
  }
870
986
  inode_permission(cred, sb, child, Mask::OPEN | mask)
@@ -882,7 +998,7 @@ pub fn filename_linkat(
882
998
  new_start: &impl Start,
883
999
  new_path: &str,
884
1000
  follow: bool,
885
- ) -> Result<(), FilesystemError> {
1001
+ ) -> Result<(), Errno> {
886
1002
  retry_estale(
887
1003
  || {
888
1004
  let old = filename_lookup(cred, old_start, old_path, follow)?;
@@ -893,7 +1009,7 @@ pub fn filename_linkat(
893
1009
  },
894
1010
  |(old, target, new, (_held, child))| {
895
1011
  if !Arc::ptr_eq(&old.mnt, &new.mnt) {
896
- return Err(FilesystemError::CrossesDevices);
1012
+ return Err(Errno::CrossesDevices);
897
1013
  }
898
1014
  on_path(&old.mnt, &target, |old| {
899
1015
  on_path(&new.mnt, &child, |new| cred.security_path_link(old, new))
@@ -910,7 +1026,7 @@ pub fn filename_symlinkat(
910
1026
  target: &str,
911
1027
  start: &impl Start,
912
1028
  path: &str,
913
- ) -> Result<(), FilesystemError> {
1029
+ ) -> Result<(), Errno> {
914
1030
  getname(target)?;
915
1031
  retry_estale(
916
1032
  || {
@@ -933,18 +1049,18 @@ pub fn filename_symlinkat(
933
1049
  fn filename_create(
934
1050
  nd: &mut Nameidata,
935
1051
  want_dir: bool,
936
- ) -> Result<(RwSemaphoreGuard, Arc<Dentry>), FilesystemError> {
937
- if nd.last_type != LastType::Norm {
938
- return Err(FilesystemError::AlreadyExists);
1052
+ ) -> Result<(RwSemaphoreGuard, Arc<Dentry>), Errno> {
1053
+ if nd.last_type != LastType::Norm || nd.lookup_mnt_by_name(&nd.last)?.is_some() {
1054
+ return Err(Errno::AlreadyExists);
939
1055
  }
940
1056
  let write = nd.mnt.mnt_want_write();
941
1057
  let held = nd.dentry().inode_lock()?;
942
1058
  let child = nd.lookup_last_locked()?;
943
1059
  if child.inode().is_some() {
944
- return Err(FilesystemError::AlreadyExists);
1060
+ return Err(Errno::AlreadyExists);
945
1061
  }
946
1062
  if nd.trailing_slash && !want_dir {
947
- return Err(FilesystemError::NotFound);
1063
+ return Err(Errno::NotFound);
948
1064
  }
949
1065
  write?;
950
1066
  Ok((held, child))
@@ -952,22 +1068,18 @@ fn filename_create(
952
1068
 
953
1069
  /// Hold the directory a name is removed from and take the name's dentry, as
954
1070
  /// Linux's `start_dirop` does before any security hook is asked.
955
- fn start_dirop(nd: &mut Nameidata) -> Result<(RwSemaphoreGuard, Arc<Dentry>), FilesystemError> {
1071
+ fn start_dirop(nd: &mut Nameidata) -> Result<(RwSemaphoreGuard, Arc<Dentry>), Errno> {
956
1072
  let held = nd.dentry().inode_lock()?;
957
1073
  let child = nd.lookup_last_locked()?;
958
1074
  match child.inode() {
959
1075
  Some(_) => Ok((held, child)),
960
- None => Err(FilesystemError::NotFound),
1076
+ None => Err(Errno::NotFound),
961
1077
  }
962
1078
  }
963
1079
 
964
1080
  /// Make the directory `path` beneath `start`. A trailing `/` asks for the
965
1081
  /// directory being made, so it is no refusal here, as `mkdir(2)` takes it.
966
- pub fn filename_mkdirat(
967
- cred: &Arc<Cred>,
968
- start: &impl Start,
969
- path: &str,
970
- ) -> Result<(), FilesystemError> {
1082
+ pub fn filename_mkdirat(cred: &Arc<Cred>, start: &impl Start, path: &str) -> Result<(), Errno> {
971
1083
  retry_estale(
972
1084
  || {
973
1085
  let mut nd = filename_parentat(cred, start, path)?;
@@ -983,18 +1095,14 @@ pub fn filename_mkdirat(
983
1095
 
984
1096
  /// Remove the empty directory `path` beneath `start`, as Linux's
985
1097
  /// `filename_rmdir` does.
986
- pub fn filename_rmdir(
987
- cred: &Arc<Cred>,
988
- start: &impl Start,
989
- path: &str,
990
- ) -> Result<(), FilesystemError> {
1098
+ pub fn filename_rmdir(cred: &Arc<Cred>, start: &impl Start, path: &str) -> Result<(), Errno> {
991
1099
  retry_estale(
992
1100
  || filename_parentat(cred, start, path),
993
1101
  |mut nd| {
994
1102
  match nd.last_type {
995
1103
  LastType::Norm => {}
996
- LastType::Dot => return Err(FilesystemError::InvalidInput),
997
- LastType::DotDot => return Err(FilesystemError::DirectoryNotEmpty),
1104
+ LastType::Dot => return Err(Errno::InvalidInput),
1105
+ LastType::DotDot => return Err(Errno::DirectoryNotEmpty),
998
1106
  }
999
1107
  nd.mnt.mnt_want_write()?;
1000
1108
  let (_held, child) = start_dirop(&mut nd)?;
@@ -1007,23 +1115,19 @@ pub fn filename_rmdir(
1007
1115
  /// Remove the file `path` beneath `start`, as Linux's `filename_unlinkat` does.
1008
1116
  /// It follows no link at the end, so a trailing `/` is answered by the name
1009
1117
  /// itself once it is found: no file removes as a directory.
1010
- pub fn filename_unlinkat(
1011
- cred: &Arc<Cred>,
1012
- start: &impl Start,
1013
- path: &str,
1014
- ) -> Result<(), FilesystemError> {
1118
+ pub fn filename_unlinkat(cred: &Arc<Cred>, start: &impl Start, path: &str) -> Result<(), Errno> {
1015
1119
  retry_estale(
1016
1120
  || filename_parentat(cred, start, path),
1017
1121
  |mut nd| {
1018
1122
  if nd.last_type != LastType::Norm {
1019
- return Err(FilesystemError::IsADirectory);
1123
+ return Err(Errno::IsADirectory);
1020
1124
  }
1021
1125
  nd.mnt.mnt_want_write()?;
1022
1126
  let (_held, child) = start_dirop(&mut nd)?;
1023
1127
  if nd.trailing_slash {
1024
- return Err(match child.kind() {
1025
- Ok(FileType::Dir) => FilesystemError::IsADirectory,
1026
- _ => FilesystemError::NotADirectory,
1128
+ return Err(match child.file_type() {
1129
+ Ok(FileType::Dir) => Errno::IsADirectory,
1130
+ _ => Errno::NotADirectory,
1027
1131
  });
1028
1132
  }
1029
1133
  on_path(&nd.mnt, &child, |path| cred.security_path_unlink(path))?;
@@ -1042,17 +1146,17 @@ pub fn filename_renameat2(
1042
1146
  from_path: &str,
1043
1147
  to: &impl Start,
1044
1148
  to_path: &str,
1045
- ) -> Result<(), FilesystemError> {
1149
+ ) -> Result<(), Errno> {
1046
1150
  let walk = || {
1047
1151
  let source = filename_parentat(cred, from, from_path)?;
1048
1152
  Ok((source, filename_parentat(cred, to, to_path)?))
1049
1153
  };
1050
1154
  retry_estale(walk, |(source, target)| {
1051
1155
  if !Arc::ptr_eq(&source.mnt, &target.mnt) {
1052
- return Err(FilesystemError::CrossesDevices);
1156
+ return Err(Errno::CrossesDevices);
1053
1157
  }
1054
1158
  if source.last_type != LastType::Norm || target.last_type != LastType::Norm {
1055
- return Err(FilesystemError::ResourceBusy);
1159
+ return Err(Errno::ResourceBusy);
1056
1160
  }
1057
1161
  source.mnt.mnt_want_write()?;
1058
1162
  let mnt = source.mnt.clone();
@@ -1065,9 +1169,9 @@ pub fn filename_renameat2(
1065
1169
  )?;
1066
1170
  // Unless the source is a directory, a trailing `/` on either side is
1067
1171
  // refused, as `filename_renameat2` refuses it.
1068
- let is_dir = rd.old_dentry.kind()? == FileType::Dir;
1172
+ let is_dir = rd.old_dentry.file_type()? == FileType::Dir;
1069
1173
  if !is_dir && (source.trailing_slash || target.trailing_slash) {
1070
- return Err(FilesystemError::NotADirectory);
1174
+ return Err(Errno::NotADirectory);
1071
1175
  }
1072
1176
  on_path(&mnt, &rd.old_dentry, |old| {
1073
1177
  on_path(&mnt, &rd.new_dentry, |new| {
@@ -1087,7 +1191,7 @@ fn lock_rename(
1087
1191
  sb: &SuperBlock,
1088
1192
  old_dir: &Arc<Dentry>,
1089
1193
  new_dir: &Arc<Dentry>,
1090
- ) -> Result<Vec<RwSemaphoreGuard>, FilesystemError> {
1194
+ ) -> Result<Vec<RwSemaphoreGuard>, Errno> {
1091
1195
  if Arc::ptr_eq(old_dir, new_dir) {
1092
1196
  return Ok(vec![old_dir.inode_lock()?]);
1093
1197
  }
@@ -1109,13 +1213,13 @@ pub(crate) struct RenameData {
1109
1213
  pub(crate) old_dentry: Arc<Dentry>,
1110
1214
  pub(crate) new_parent: Arc<Dentry>,
1111
1215
  pub(crate) new_dentry: Arc<Dentry>,
1112
- pub(crate) flag: Option<RenameFlag>,
1216
+ pub(crate) flags: Option<RenameFlag>,
1113
1217
  }
1114
1218
 
1115
1219
  /// Hold both directories of a move and find its names beneath them, as
1116
1220
  /// Linux's `__start_renaming` does through `lock_rename`, so no other move
1117
1221
  /// changes what either name stands for before the call acts on it. Nothing at
1118
- /// the source, and at the target what `flag` will not take, is refused as the
1222
+ /// the source, and at the target what `flags` will not take, is refused as the
1119
1223
  /// flags `__start_renaming` looks each name up with refuse it. So is a move
1120
1224
  /// whose source stands above its target directory, and one whose target stands
1121
1225
  /// above its source directory, which only an exchange may not empty.
@@ -1123,24 +1227,24 @@ pub(crate) fn __start_renaming(
1123
1227
  sb: &SuperBlock,
1124
1228
  (old_dir, old_name): (&Arc<Dentry>, &str),
1125
1229
  (new_dir, new_name): (&Arc<Dentry>, &str),
1126
- flag: Option<RenameFlag>,
1127
- ) -> Result<RenameData, FilesystemError> {
1230
+ flags: Option<RenameFlag>,
1231
+ ) -> Result<RenameData, Errno> {
1128
1232
  let _held = lock_rename(sb, old_dir, new_dir)?;
1129
1233
  let old_dentry = lookup_one_qstr_excl(sb, old_dir, old_name)?;
1130
- old_dentry.kind()?;
1234
+ old_dentry.file_type()?;
1131
1235
  let new_dentry = lookup_one_qstr_excl(sb, new_dir, new_name)?;
1132
- match (flag, new_dentry.inode().is_some()) {
1133
- (Some(RenameFlag::Exchange), false) => return Err(FilesystemError::NotFound),
1134
- (Some(RenameFlag::NoReplace), true) => return Err(FilesystemError::AlreadyExists),
1236
+ match (flags, new_dentry.inode().is_some()) {
1237
+ (Some(RenameFlag::Exchange), false) => return Err(Errno::NotFound),
1238
+ (Some(RenameFlag::NoReplace), true) => return Err(Errno::AlreadyExists),
1135
1239
  _ => {}
1136
1240
  }
1137
1241
  if new_dir.is_subdir(&old_dentry) {
1138
- return Err(FilesystemError::InvalidInput);
1242
+ return Err(Errno::InvalidInput);
1139
1243
  }
1140
1244
  if old_dir.is_subdir(&new_dentry) {
1141
- return Err(match flag {
1142
- Some(RenameFlag::Exchange) => FilesystemError::InvalidInput,
1143
- _ => FilesystemError::DirectoryNotEmpty,
1245
+ return Err(match flags {
1246
+ Some(RenameFlag::Exchange) => Errno::InvalidInput,
1247
+ _ => Errno::DirectoryNotEmpty,
1144
1248
  });
1145
1249
  }
1146
1250
  Ok(RenameData {
@@ -1149,7 +1253,7 @@ pub(crate) fn __start_renaming(
1149
1253
  old_dentry,
1150
1254
  new_parent: new_dir.clone(),
1151
1255
  new_dentry,
1152
- flag,
1256
+ flags,
1153
1257
  })
1154
1258
  }
1155
1259
 
@@ -1161,11 +1265,11 @@ fn lock_moved(
1161
1265
  (old, is_dir): (&Dentry, bool),
1162
1266
  (new, new_is_dir): (&Dentry, bool),
1163
1267
  same_dir: bool,
1164
- flag: Option<RenameFlag>,
1165
- ) -> Result<Vec<RwSemaphoreGuard>, FilesystemError> {
1268
+ flags: Option<RenameFlag>,
1269
+ ) -> Result<Vec<RwSemaphoreGuard>, Errno> {
1166
1270
  let (source, target) = (old.inode(), new.inode());
1167
1271
  let lock_old_subdir = !same_dir;
1168
- let lock_new_subdir = !same_dir || flag != Some(RenameFlag::Exchange);
1272
+ let lock_new_subdir = !same_dir || flags != Some(RenameFlag::Exchange);
1169
1273
  let locks = match (is_dir, new_is_dir) {
1170
1274
  (true, _) => [
1171
1275
  source.filter(|_| lock_old_subdir),
@@ -1186,7 +1290,7 @@ fn lock_moved(
1186
1290
  fn lock_two_nondirectories(
1187
1291
  first: Option<Arc<Inode>>,
1188
1292
  second: Option<Arc<Inode>>,
1189
- ) -> Result<Vec<RwSemaphoreGuard>, FilesystemError> {
1293
+ ) -> Result<Vec<RwSemaphoreGuard>, Errno> {
1190
1294
  let mut inodes: Vec<_> = first.into_iter().chain(second).collect();
1191
1295
  inodes.sort_by_key(Arc::as_ptr);
1192
1296
  inodes.dedup_by(|a, b| Arc::ptr_eq(a, b));
@@ -1199,22 +1303,18 @@ fn lock_two_nondirectories(
1199
1303
  /// side is checked first, as `vfs_rename` asks `may_delete_dentry` and
1200
1304
  /// `may_create_dentry`. A directory replaced at the new name is gone for whoever
1201
1305
  /// holds it, and an exchange swaps the two names' dentries, as `d_exchange` does.
1202
- pub(crate) fn vfs_rename(
1203
- cred: &Cred,
1204
- sb: &SuperBlock,
1205
- rd: &RenameData,
1206
- ) -> Result<(), FilesystemError> {
1306
+ pub(crate) fn vfs_rename(cred: &Cred, sb: &SuperBlock, rd: &RenameData) -> Result<(), Errno> {
1207
1307
  let (old_dir, old) = (&rd.old_parent, &rd.old_dentry);
1208
1308
  let (new_dir, new) = (&rd.new_parent, &rd.new_dentry);
1209
- let flag = rd.flag;
1210
- let moving = old.kind().ok();
1211
- let target = new.kind().ok();
1309
+ let flags = rd.flags;
1310
+ let moving = old.file_type().ok();
1311
+ let target = new.file_type().ok();
1212
1312
  if Arc::ptr_eq(old, new) || old.names_the_entry_of(new) {
1213
1313
  return Ok(());
1214
1314
  }
1215
1315
  let is_dir = moving == Some(FileType::Dir);
1216
1316
  may_delete_dentry(cred, sb, old_dir, moving, is_dir)?;
1217
- match (target, flag) {
1317
+ match (target, flags) {
1218
1318
  (None, _) => may_create_dentry(cred, sb, new_dir, new)?,
1219
1319
  (target, Some(RenameFlag::Exchange)) => {
1220
1320
  may_delete_dentry(cred, sb, new_dir, target, target == Some(FileType::Dir))?
@@ -1226,7 +1326,7 @@ pub(crate) fn vfs_rename(
1226
1326
  if is_dir {
1227
1327
  inode_permission(cred, sb, old, Mask::WRITE)?;
1228
1328
  }
1229
- if flag == Some(RenameFlag::Exchange) && target == Some(FileType::Dir) {
1329
+ if flags == Some(RenameFlag::Exchange) && target == Some(FileType::Dir) {
1230
1330
  inode_permission(cred, sb, new, Mask::WRITE)?;
1231
1331
  }
1232
1332
  }
@@ -1234,13 +1334,17 @@ pub(crate) fn vfs_rename(
1234
1334
  (old, is_dir),
1235
1335
  (new, target == Some(FileType::Dir)),
1236
1336
  Arc::ptr_eq(old_dir, new_dir),
1237
- flag,
1337
+ flags,
1238
1338
  )?;
1339
+ let mnt_ns = cred.mnt_ns();
1340
+ if mnt_ns.pins(old) || mnt_ns.pins(new) {
1341
+ return Err(Errno::ResourceBusy);
1342
+ }
1239
1343
  old_dir
1240
1344
  .inode_ops()?
1241
- .rename(old, new_dir.inode_ops()?.as_ref(), new, flag)?;
1345
+ .rename(old, new_dir.inode_ops()?.as_ref(), new, flags)?;
1242
1346
  let dentries = sb.dentries();
1243
- if flag == Some(RenameFlag::Exchange) {
1347
+ if flags == Some(RenameFlag::Exchange) {
1244
1348
  dentries.exchange(old, new);
1245
1349
  return Ok(());
1246
1350
  }
@@ -1260,9 +1364,12 @@ pub(crate) fn vfs_rmdir(
1260
1364
  sb: &SuperBlock,
1261
1365
  dir: &Dentry,
1262
1366
  victim: &Arc<Dentry>,
1263
- ) -> Result<(), FilesystemError> {
1264
- may_delete_dentry(cred, sb, dir, victim.kind().ok(), true)?;
1367
+ ) -> Result<(), Errno> {
1368
+ may_delete_dentry(cred, sb, dir, victim.file_type().ok(), true)?;
1265
1369
  let _victim = victim.inode_lock()?;
1370
+ if cred.mnt_ns().pins(victim) {
1371
+ return Err(Errno::ResourceBusy);
1372
+ }
1266
1373
  dir.inode_ops()?.rmdir(victim)?;
1267
1374
  sb.dentries().shrink_dcache_parent(victim);
1268
1375
  victim.mark_dead();
@@ -1279,9 +1386,12 @@ pub(crate) fn vfs_unlink(
1279
1386
  sb: &SuperBlock,
1280
1387
  dir: &Dentry,
1281
1388
  victim: &Arc<Dentry>,
1282
- ) -> Result<(), FilesystemError> {
1283
- may_delete_dentry(cred, sb, dir, victim.kind().ok(), false)?;
1389
+ ) -> Result<(), Errno> {
1390
+ may_delete_dentry(cred, sb, dir, victim.file_type().ok(), false)?;
1284
1391
  let _victim = victim.inode_lock()?;
1392
+ if cred.mnt_ns().pins(victim) {
1393
+ return Err(Errno::ResourceBusy);
1394
+ }
1285
1395
  dir.inode_ops()?.unlink(victim)?;
1286
1396
  sb.dentries().unhash(victim);
1287
1397
  Ok(())
@@ -1295,7 +1405,7 @@ pub(crate) fn vfs_mkdir(
1295
1405
  sb: &SuperBlock,
1296
1406
  dir: &Dentry,
1297
1407
  child: &Dentry,
1298
- ) -> Result<(), FilesystemError> {
1408
+ ) -> Result<(), Errno> {
1299
1409
  may_create_dentry(cred, sb, dir, child)?;
1300
1410
  dir.inode_ops()?.mkdir(child)
1301
1411
  }
@@ -1320,7 +1430,7 @@ pub(crate) fn atomic_open(
1320
1430
  dir: &Dentry,
1321
1431
  child: &Dentry,
1322
1432
  how: &OpenHow,
1323
- ) -> Result<AtomicOpen, FilesystemError> {
1433
+ ) -> Result<AtomicOpen, Errno> {
1324
1434
  let (file, created, spliced) = match dir.inode_ops()?.atomic_open(child, how)? {
1325
1435
  Finish::Open { file, created } => (Some(file), created, None),
1326
1436
  Finish::Spelled { file, name, inode } => {
@@ -1343,7 +1453,7 @@ pub(crate) fn vfs_create(
1343
1453
  sb: &SuperBlock,
1344
1454
  dir: &Dentry,
1345
1455
  child: &Dentry,
1346
- ) -> Result<(), FilesystemError> {
1456
+ ) -> Result<(), Errno> {
1347
1457
  may_create_dentry(cred, sb, dir, child)?;
1348
1458
  dir.inode_ops()?.create(child)
1349
1459
  }
@@ -1357,14 +1467,14 @@ fn vfs_link(
1357
1467
  old: &Dentry,
1358
1468
  dir: &Dentry,
1359
1469
  child: &Dentry,
1360
- ) -> Result<(), FilesystemError> {
1470
+ ) -> Result<(), Errno> {
1361
1471
  may_create_dentry(cred, sb, dir, child)?;
1362
- if old.kind()? == FileType::Dir {
1363
- return Err(FilesystemError::NotPermitted);
1472
+ if old.file_type()? == FileType::Dir {
1473
+ return Err(Errno::NotPermitted);
1364
1474
  }
1365
1475
  let _held = old.inode_lock()?;
1366
1476
  if old.getattr()?.nlink == 0 {
1367
- return Err(FilesystemError::NotFound);
1477
+ return Err(Errno::NotFound);
1368
1478
  }
1369
1479
  dir.inode_ops()?.link(old, child)
1370
1480
  }
@@ -1377,7 +1487,7 @@ fn vfs_symlink(
1377
1487
  dir: &Dentry,
1378
1488
  child: &Dentry,
1379
1489
  target: &str,
1380
- ) -> Result<(), FilesystemError> {
1490
+ ) -> Result<(), Errno> {
1381
1491
  may_create_dentry(cred, sb, dir, child)?;
1382
1492
  dir.inode_ops()?.symlink(child, target)
1383
1493
  }
@@ -1389,12 +1499,12 @@ pub(crate) fn may_create_dentry(
1389
1499
  sb: &SuperBlock,
1390
1500
  dir: &Dentry,
1391
1501
  child: &Dentry,
1392
- ) -> Result<(), FilesystemError> {
1502
+ ) -> Result<(), Errno> {
1393
1503
  if child.inode().is_some() {
1394
- return Err(FilesystemError::AlreadyExists);
1504
+ return Err(Errno::AlreadyExists);
1395
1505
  }
1396
1506
  if dir.is_deaddir() {
1397
- return Err(FilesystemError::NotFound);
1507
+ return Err(Errno::NotFound);
1398
1508
  }
1399
1509
  inode_permission(cred, sb, dir, Mask::WRITE | Mask::EXEC)
1400
1510
  }
@@ -1409,18 +1519,18 @@ fn may_delete_dentry(
1409
1519
  dir: &Dentry,
1410
1520
  victim: Option<FileType>,
1411
1521
  is_dir: bool,
1412
- ) -> Result<(), FilesystemError> {
1522
+ ) -> Result<(), Errno> {
1413
1523
  let Some(victim) = victim else {
1414
- return Err(FilesystemError::NotFound);
1524
+ return Err(Errno::NotFound);
1415
1525
  };
1416
1526
  inode_permission(cred, sb, dir, Mask::WRITE | Mask::EXEC)?;
1417
1527
  match (is_dir, victim == FileType::Dir) {
1418
- (true, false) => return Err(FilesystemError::NotADirectory),
1419
- (false, true) => return Err(FilesystemError::IsADirectory),
1528
+ (true, false) => return Err(Errno::NotADirectory),
1529
+ (false, true) => return Err(Errno::IsADirectory),
1420
1530
  _ => {}
1421
1531
  }
1422
1532
  if dir.is_deaddir() {
1423
- return Err(FilesystemError::NotFound);
1533
+ return Err(Errno::NotFound);
1424
1534
  }
1425
1535
  Ok(())
1426
1536
  }
@@ -1433,31 +1543,28 @@ mod tests {
1433
1543
  use std::thread;
1434
1544
  use std::time::Duration;
1435
1545
 
1546
+ use crate::cred::Cred;
1436
1547
  use crate::filesystem::wrap::{self, Wrap};
1437
1548
  use crate::filesystem::{
1438
- DentryOperations, FileOperations, FileSystemType, FileType, Filesystem, FilesystemError,
1439
- Finish, InodeOperations, Kstat, Lookup, Tmpfs,
1549
+ DentryOperations, FileOperations, FileSystemType, FileType, Filesystem, Finish,
1550
+ InodeOperations, Kstat, Lookup, Tmpfs,
1440
1551
  };
1441
- use crate::mount::{Access, Mount, Policy};
1552
+ use crate::mount::{Access, Mount, MountRequest};
1553
+ use crate::policy::Policy;
1442
1554
  use crate::sched::testing::count_waits;
1555
+ use crate::security::{FileSecurity, SecurityOperations, SecurityPath};
1443
1556
  use crate::vfs::kern_path::{kern_path, KernPath};
1444
- use crate::vfs::{
1445
- self, Cred, Dentry, FMode, FileSecurity, Inode, Mask, OpenHow, Path, RenameFlag,
1446
- SecurityOperations, SecurityPath,
1447
- };
1557
+ use crate::vfs::{self, Dentry, FMode, Inode, Mask, OpenHow, Path, RenameFlag};
1558
+ use crate::Errno;
1448
1559
 
1449
- type Hook = Box<dyn Fn() -> Result<(), FilesystemError> + Send + Sync>;
1560
+ type Hook = Box<dyn Fn() -> Result<(), Errno> + Send + Sync>;
1450
1561
 
1451
1562
  /// A test's Filesystem counting what it is asked to look up.
1452
1563
  #[derive(Default)]
1453
1564
  struct CountsAsks(AtomicUsize);
1454
1565
 
1455
1566
  impl wrap::Hook for CountsAsks {
1456
- fn lookup(
1457
- &self,
1458
- inner: &dyn InodeOperations,
1459
- dentry: &Dentry,
1460
- ) -> Result<Lookup, FilesystemError> {
1567
+ fn lookup(&self, inner: &dyn InodeOperations, dentry: &Dentry) -> Result<Lookup, Errno> {
1461
1568
  self.0.fetch_add(1, Ordering::SeqCst);
1462
1569
  inner.lookup(dentry)
1463
1570
  }
@@ -1472,7 +1579,7 @@ mod tests {
1472
1579
  }
1473
1580
 
1474
1581
  impl FileSystemType for LinksFile {
1475
- fn fill_super(self: Arc<Self>, sb: &mut Filesystem) -> Result<(), FilesystemError> {
1582
+ fn fill_super(self: Arc<Self>, sb: &mut Filesystem) -> Result<(), Errno> {
1476
1583
  sb.d_make_root(vfs::Inode::new(
1477
1584
  &Kstat::new(crate::filesystem::FileType::Dir, 0),
1478
1585
  self,
@@ -1482,14 +1589,14 @@ mod tests {
1482
1589
  }
1483
1590
 
1484
1591
  impl InodeOperations for LinksFile {
1485
- fn getattr(&self, dentry: &Dentry) -> Result<Kstat, FilesystemError> {
1592
+ fn getattr(&self, dentry: &Dentry) -> Result<Kstat, Errno> {
1486
1593
  Ok(match dentry.is_root() {
1487
1594
  false => Kstat::new(FileType::RegFile, 0).with_nlink(self.names),
1488
1595
  true => Kstat::new(FileType::Dir, 0),
1489
1596
  })
1490
1597
  }
1491
1598
 
1492
- fn lookup(&self, dentry: &Dentry) -> Result<Lookup, FilesystemError> {
1599
+ fn lookup(&self, dentry: &Dentry) -> Result<Lookup, Errno> {
1493
1600
  if dentry.name() != "file" {
1494
1601
  return Ok(Lookup::Absent);
1495
1602
  }
@@ -1497,7 +1604,7 @@ mod tests {
1497
1604
  Ok(Lookup::Found(Inode::new(&file, Arc::new(self.clone()))))
1498
1605
  }
1499
1606
 
1500
- fn link(&self, _old: &Dentry, _dentry: &Dentry) -> Result<(), FilesystemError> {
1607
+ fn link(&self, _old: &Dentry, _dentry: &Dentry) -> Result<(), Errno> {
1501
1608
  self.linked.fetch_add(1, Ordering::SeqCst);
1502
1609
  Ok(())
1503
1610
  }
@@ -1516,7 +1623,7 @@ mod tests {
1516
1623
  };
1517
1624
  let mount = Mount::new(
1518
1625
  "/data",
1519
- Filesystem::new(Arc::new(ops)).expect("the instance must stand"),
1626
+ Filesystem::new(ops).expect("the instance must stand"),
1520
1627
  Access::ReadWrite,
1521
1628
  )
1522
1629
  .expect("/data is a guest path");
@@ -1534,11 +1641,7 @@ mod tests {
1534
1641
  }
1535
1642
 
1536
1643
  impl DentryOperations for AskedOfAbsent {
1537
- fn revalidate(
1538
- &self,
1539
- _dir: &dyn InodeOperations,
1540
- _dentry: &Dentry,
1541
- ) -> Result<bool, FilesystemError> {
1644
+ fn revalidate(&self, _dir: &dyn InodeOperations, _dentry: &Dentry) -> Result<bool, Errno> {
1542
1645
  self.revalidations.fetch_add(1, Ordering::SeqCst);
1543
1646
  Ok(true)
1544
1647
  }
@@ -1549,7 +1652,7 @@ mod tests {
1549
1652
  }
1550
1653
 
1551
1654
  impl FileSystemType for AskedOfAbsent {
1552
- fn fill_super(self: Arc<Self>, sb: &mut Filesystem) -> Result<(), FilesystemError> {
1655
+ fn fill_super(self: Arc<Self>, sb: &mut Filesystem) -> Result<(), Errno> {
1553
1656
  sb.set_default_d_op(self.clone());
1554
1657
  sb.d_make_root(vfs::Inode::new(
1555
1658
  &Kstat::new(crate::filesystem::FileType::Dir, 0),
@@ -1560,11 +1663,11 @@ mod tests {
1560
1663
  }
1561
1664
 
1562
1665
  impl InodeOperations for AskedOfAbsent {
1563
- fn getattr(&self, _dentry: &Dentry) -> Result<Kstat, FilesystemError> {
1666
+ fn getattr(&self, _dentry: &Dentry) -> Result<Kstat, Errno> {
1564
1667
  Ok(Kstat::new(FileType::Dir, 0))
1565
1668
  }
1566
1669
 
1567
- fn lookup(&self, _dentry: &Dentry) -> Result<Lookup, FilesystemError> {
1670
+ fn lookup(&self, _dentry: &Dentry) -> Result<Lookup, Errno> {
1568
1671
  self.lookups.fetch_add(1, Ordering::SeqCst);
1569
1672
  Ok(match self.stands {
1570
1673
  true => {
@@ -1592,14 +1695,7 @@ mod tests {
1592
1695
  lookups.load(Ordering::SeqCst),
1593
1696
  revalidations.load(Ordering::SeqCst)
1594
1697
  ),
1595
- (
1596
- (
1597
- Some(FilesystemError::NotFound),
1598
- Some(FilesystemError::NotFound)
1599
- ),
1600
- 1,
1601
- 1
1602
- ),
1698
+ ((Some(Errno::NotFound), Some(Errno::NotFound)), 1, 1),
1603
1699
  "vfs::vfs_fstatat twice of a name nothing stands at must ask ->lookup once and \
1604
1700
  revalidate what it kept, as retain_dentry keeps a negative dentry"
1605
1701
  );
@@ -1612,46 +1708,6 @@ mod tests {
1612
1708
  );
1613
1709
  }
1614
1710
 
1615
- // Holding it shared again past the waiting writer stands in for what a walk
1616
- // does when a Ruby Filesystem reaches its own Mount, which must never hang.
1617
- // @behavior RT-253
1618
- #[test]
1619
- fn a_writer_goes_ahead_of_readers_arriving_after_it() {
1620
- use crate::locking::RwSemaphore;
1621
- let rwsem: Arc<RwSemaphore> = Arc::default();
1622
- let order = Arc::new(Mutex::new(Vec::new()));
1623
- let held = rwsem.down_read().expect("the first reader holds it");
1624
- let writer = {
1625
- let (rwsem, order) = (rwsem.clone(), order.clone());
1626
- thread::spawn(move || {
1627
- let _held = rwsem.down_write().expect("the writer holds it");
1628
- order.lock().expect("never poisoned").push("writer");
1629
- })
1630
- };
1631
- crate::sched::testing::wait_until("the writer queueing behind the reader", || {
1632
- rwsem.writer_waits()
1633
- });
1634
- let reader = {
1635
- let (rwsem, order) = (rwsem.clone(), order.clone());
1636
- thread::spawn(move || {
1637
- let _held = rwsem.down_read().expect("the reader holds it");
1638
- order.lock().expect("never poisoned").push("reader");
1639
- })
1640
- };
1641
- let again = rwsem.down_read().map(drop);
1642
- thread::sleep(Duration::from_millis(50));
1643
- let before = order.lock().expect("never poisoned").clone();
1644
- drop(held);
1645
- crate::sched::testing::join("the writer", writer);
1646
- crate::sched::testing::join("the reader", reader);
1647
- assert_eq!(
1648
- (again, before, order.lock().expect("never poisoned").clone()),
1649
- (Ok(()), Vec::new(), vec!["writer", "reader"]),
1650
- "a reader arriving behind a waiting writer must wait for it, as \
1651
- rwsem_down_read_slowpath queues, while one already holding it takes it again"
1652
- );
1653
- }
1654
-
1655
1711
  /// A security module recording the hooks a call reaches, by name.
1656
1712
  #[derive(Default)]
1657
1713
  struct RecordsHooks(Mutex<Vec<String>>);
@@ -1665,49 +1721,49 @@ mod tests {
1665
1721
  }
1666
1722
  }
1667
1723
 
1668
- impl vfs::SecurityOperations for RecordsHooks {
1669
- fn path_mknod(&self, _path: vfs::SecurityPath<'_>) -> Result<(), FilesystemError> {
1724
+ impl crate::security::SecurityOperations for RecordsHooks {
1725
+ fn path_mknod(&self, _path: crate::security::SecurityPath<'_>) -> Result<(), Errno> {
1670
1726
  self.record("path_mknod");
1671
1727
  Ok(())
1672
1728
  }
1673
1729
 
1674
- fn path_mkdir(&self, _path: vfs::SecurityPath<'_>) -> Result<(), FilesystemError> {
1730
+ fn path_mkdir(&self, _path: crate::security::SecurityPath<'_>) -> Result<(), Errno> {
1675
1731
  self.record("path_mkdir");
1676
1732
  Ok(())
1677
1733
  }
1678
1734
 
1679
- fn path_rmdir(&self, _path: vfs::SecurityPath<'_>) -> Result<(), FilesystemError> {
1735
+ fn path_rmdir(&self, _path: crate::security::SecurityPath<'_>) -> Result<(), Errno> {
1680
1736
  self.record("path_rmdir");
1681
1737
  Ok(())
1682
1738
  }
1683
1739
 
1684
- fn path_unlink(&self, _path: vfs::SecurityPath<'_>) -> Result<(), FilesystemError> {
1740
+ fn path_unlink(&self, _path: crate::security::SecurityPath<'_>) -> Result<(), Errno> {
1685
1741
  self.record("path_unlink");
1686
1742
  Ok(())
1687
1743
  }
1688
1744
 
1689
1745
  fn path_rename(
1690
1746
  &self,
1691
- _old: vfs::SecurityPath<'_>,
1692
- _new: vfs::SecurityPath<'_>,
1747
+ _old: crate::security::SecurityPath<'_>,
1748
+ _new: crate::security::SecurityPath<'_>,
1693
1749
  _dentries: (&Arc<Dentry>, &Arc<Dentry>),
1694
- ) -> Result<(), FilesystemError> {
1750
+ ) -> Result<(), Errno> {
1695
1751
  self.record("path_rename");
1696
1752
  Ok(())
1697
1753
  }
1698
1754
 
1699
1755
  fn file_open(
1700
1756
  &self,
1701
- _path: vfs::SecurityPath<'_>,
1757
+ _path: crate::security::SecurityPath<'_>,
1702
1758
  _kind: FileType,
1703
1759
  _mode: vfs::FMode,
1704
1760
  _how: &OpenHow,
1705
- ) -> Result<vfs::FileSecurity, FilesystemError> {
1761
+ ) -> Result<crate::security::FileSecurity, Errno> {
1706
1762
  self.record("file_open");
1707
1763
  Ok(None)
1708
1764
  }
1709
1765
 
1710
- fn file_truncate(&self, _kept: &vfs::FileSecurity) -> Result<(), FilesystemError> {
1766
+ fn file_truncate(&self, _kept: &crate::security::FileSecurity) -> Result<(), Errno> {
1711
1767
  self.record("file_truncate");
1712
1768
  Ok(())
1713
1769
  }
@@ -1717,10 +1773,10 @@ mod tests {
1717
1773
  #[test]
1718
1774
  fn each_call_reaches_the_hook_linux_names_for_it() {
1719
1775
  let hooks = Arc::new(RecordsHooks::default());
1720
- let cred = vfs::Cred::new(vec![hooks.clone()]);
1776
+ let cred = crate::cred::Cred::new(vec![hooks.clone()]);
1721
1777
  let mount = Mount::new(
1722
1778
  "/data",
1723
- Filesystem::new(Arc::new(Tmpfs::new())).expect("the instance must stand"),
1779
+ Filesystem::new(Tmpfs::new()).expect("the instance must stand"),
1724
1780
  Access::ReadWrite,
1725
1781
  )
1726
1782
  .expect("/data is a guest path");
@@ -1770,7 +1826,7 @@ mod tests {
1770
1826
  }
1771
1827
 
1772
1828
  impl SecurityOperations for MovesBeforeOpen {
1773
- fn inode_permission(&self, dentry: &Dentry, _mask: Mask) -> Result<(), FilesystemError> {
1829
+ fn inode_permission(&self, dentry: &Dentry, _mask: Mask) -> Result<(), Errno> {
1774
1830
  let root = match dentry.name() == "f" {
1775
1831
  true => self.root.lock().expect("never poisoned").take(),
1776
1832
  false => None,
@@ -1787,7 +1843,7 @@ mod tests {
1787
1843
  _kind: FileType,
1788
1844
  _mode: FMode,
1789
1845
  _how: &OpenHow,
1790
- ) -> Result<FileSecurity, FilesystemError> {
1846
+ ) -> Result<FileSecurity, Errno> {
1791
1847
  self.opened
1792
1848
  .lock()
1793
1849
  .expect("never poisoned")
@@ -1804,7 +1860,7 @@ mod tests {
1804
1860
  let hooks = Arc::new(MovesBeforeOpen::default());
1805
1861
  let mount = Mount::new(
1806
1862
  "/data",
1807
- Filesystem::new(Arc::new([("f", "x")].into_iter().collect::<Tmpfs>()))
1863
+ Filesystem::new([("f", "x")].into_iter().collect::<Tmpfs>())
1808
1864
  .expect("the instance must stand"),
1809
1865
  Access::ReadWrite,
1810
1866
  )
@@ -1832,10 +1888,10 @@ mod tests {
1832
1888
  fn a_module_refusing_what_a_walk_asks_refuses_the_walk() {
1833
1889
  struct RefusesExec;
1834
1890
 
1835
- impl vfs::SecurityOperations for RefusesExec {
1836
- fn inode_permission(&self, dentry: &Dentry, mask: Mask) -> Result<(), FilesystemError> {
1891
+ impl crate::security::SecurityOperations for RefusesExec {
1892
+ fn inode_permission(&self, dentry: &Dentry, mask: Mask) -> Result<(), Errno> {
1837
1893
  match dentry.name() == "d" && mask.contains(Mask::EXEC) {
1838
- true => Err(FilesystemError::PermissionDenied),
1894
+ true => Err(Errno::PermissionDenied),
1839
1895
  false => Ok(()),
1840
1896
  }
1841
1897
  }
@@ -1844,15 +1900,15 @@ mod tests {
1844
1900
  let tmpfs: Tmpfs = [("d/f", "x")].into_iter().collect();
1845
1901
  let mount = Mount::new(
1846
1902
  "/data",
1847
- Filesystem::new(Arc::new(tmpfs)).expect("the instance must stand"),
1903
+ Filesystem::new(tmpfs).expect("the instance must stand"),
1848
1904
  Access::Read,
1849
1905
  )
1850
1906
  .expect("/data is a guest path");
1851
1907
  let root = Path::root(mount.mnt());
1852
- let cred = vfs::Cred::new(vec![Arc::new(RefusesExec)]);
1908
+ let cred = crate::cred::Cred::new(vec![Arc::new(RefusesExec)]);
1853
1909
  assert_eq!(
1854
1910
  vfs::vfs_fstatat(&cred, &root, "d/f", false).err(),
1855
- Some(FilesystemError::PermissionDenied),
1911
+ Some(Errno::PermissionDenied),
1856
1912
  "vfs_fstatat through a directory a module refuses to pass must answer EACCES, as \
1857
1913
  security_inode_permission answers may_lookup"
1858
1914
  );
@@ -1862,7 +1918,7 @@ mod tests {
1862
1918
  struct NamesItsRoot;
1863
1919
 
1864
1920
  impl FileSystemType for NamesItsRoot {
1865
- fn fill_super(self: Arc<Self>, sb: &mut Filesystem) -> Result<(), FilesystemError> {
1921
+ fn fill_super(self: Arc<Self>, sb: &mut Filesystem) -> Result<(), Errno> {
1866
1922
  let root = Kstat::new(FileType::Dir, 0).with_identity(7, 11);
1867
1923
  sb.d_make_root(Inode::new(&root, self));
1868
1924
  Ok(())
@@ -1870,10 +1926,10 @@ mod tests {
1870
1926
  }
1871
1927
 
1872
1928
  /// A Filesystem that cannot stand, or stands with no root.
1873
- struct NeverStands(Option<FilesystemError>);
1929
+ struct NeverStands(Option<Errno>);
1874
1930
 
1875
1931
  impl FileSystemType for NeverStands {
1876
- fn fill_super(self: Arc<Self>, _sb: &mut Filesystem) -> Result<(), FilesystemError> {
1932
+ fn fill_super(self: Arc<Self>, _sb: &mut Filesystem) -> Result<(), Errno> {
1877
1933
  match &self.0 {
1878
1934
  Some(error) => Err(error.clone()),
1879
1935
  None => Ok(()),
@@ -1884,23 +1940,20 @@ mod tests {
1884
1940
  // @behavior RT-254
1885
1941
  #[test]
1886
1942
  fn an_instance_that_cannot_stand_answers_why() {
1887
- let answer = |fs: NeverStands| Filesystem::new(Arc::new(fs)).err();
1943
+ let answer = |fs: NeverStands| Filesystem::new(fs).err();
1888
1944
  assert_eq!(
1889
1945
  (
1890
- answer(NeverStands(Some(FilesystemError::PermissionDenied))),
1946
+ answer(NeverStands(Some(Errno::PermissionDenied))),
1891
1947
  answer(NeverStands(None)),
1892
1948
  ),
1893
- (
1894
- Some(FilesystemError::PermissionDenied),
1895
- Some(FilesystemError::InvalidInput),
1896
- ),
1949
+ (Some(Errno::PermissionDenied), Some(Errno::InvalidInput),),
1897
1950
  "Filesystem::new must answer what fill_super answers, and EINVAL for a fill_super \
1898
1951
  that made no root, and make no instance, as vfs_get_tree refuses one"
1899
1952
  );
1900
1953
  }
1901
1954
 
1902
1955
  impl InodeOperations for NamesItsRoot {
1903
- fn getattr(&self, _dentry: &Dentry) -> Result<Kstat, FilesystemError> {
1956
+ fn getattr(&self, _dentry: &Dentry) -> Result<Kstat, Errno> {
1904
1957
  Ok(Kstat::new(FileType::Dir, 0))
1905
1958
  }
1906
1959
  }
@@ -1935,7 +1988,7 @@ mod tests {
1935
1988
  struct SharesInode(Arc<OnceLock<Arc<Inode>>>);
1936
1989
 
1937
1990
  impl FileSystemType for SharesInode {
1938
- fn fill_super(self: Arc<Self>, sb: &mut Filesystem) -> Result<(), FilesystemError> {
1991
+ fn fill_super(self: Arc<Self>, sb: &mut Filesystem) -> Result<(), Errno> {
1939
1992
  sb.d_make_root(vfs::Inode::new(
1940
1993
  &Kstat::new(crate::filesystem::FileType::Dir, 0),
1941
1994
  self,
@@ -1945,11 +1998,11 @@ mod tests {
1945
1998
  }
1946
1999
 
1947
2000
  impl InodeOperations for SharesInode {
1948
- fn getattr(&self, _dentry: &Dentry) -> Result<Kstat, FilesystemError> {
2001
+ fn getattr(&self, _dentry: &Dentry) -> Result<Kstat, Errno> {
1949
2002
  Ok(Kstat::new(FileType::RegFile, 0))
1950
2003
  }
1951
2004
 
1952
- fn lookup(&self, _dentry: &Dentry) -> Result<Lookup, FilesystemError> {
2005
+ fn lookup(&self, _dentry: &Dentry) -> Result<Lookup, Errno> {
1953
2006
  let file = Kstat::new(FileType::RegFile, 0);
1954
2007
  let inode = self
1955
2008
  .0
@@ -1963,8 +2016,7 @@ mod tests {
1963
2016
  fn a_filesystem_handing_one_inode_for_two_names_shares_it() {
1964
2017
  let mount = Mount::new(
1965
2018
  "/data",
1966
- Filesystem::new(Arc::new(SharesInode(Arc::default())))
1967
- .expect("the instance must stand"),
2019
+ Filesystem::new(SharesInode(Arc::default())).expect("the instance must stand"),
1968
2020
  Access::ReadWrite,
1969
2021
  )
1970
2022
  .expect("/data is a guest path");
@@ -1992,7 +2044,7 @@ mod tests {
1992
2044
  struct SharesDirectory(Arc<OnceLock<Arc<Inode>>>);
1993
2045
 
1994
2046
  impl FileSystemType for SharesDirectory {
1995
- fn fill_super(self: Arc<Self>, sb: &mut Filesystem) -> Result<(), FilesystemError> {
2047
+ fn fill_super(self: Arc<Self>, sb: &mut Filesystem) -> Result<(), Errno> {
1996
2048
  sb.d_make_root(vfs::Inode::new(
1997
2049
  &Kstat::new(crate::filesystem::FileType::Dir, 0),
1998
2050
  self,
@@ -2002,11 +2054,11 @@ mod tests {
2002
2054
  }
2003
2055
 
2004
2056
  impl InodeOperations for SharesDirectory {
2005
- fn getattr(&self, _dentry: &Dentry) -> Result<Kstat, FilesystemError> {
2057
+ fn getattr(&self, _dentry: &Dentry) -> Result<Kstat, Errno> {
2006
2058
  Ok(Kstat::new(FileType::Dir, 0))
2007
2059
  }
2008
2060
 
2009
- fn lookup(&self, dentry: &Dentry) -> Result<Lookup, FilesystemError> {
2061
+ fn lookup(&self, dentry: &Dentry) -> Result<Lookup, Errno> {
2010
2062
  let dir = Kstat::new(FileType::Dir, 0);
2011
2063
  let above = dentry.parent().name();
2012
2064
  Ok(match (above.as_str(), dentry.name().as_str()) {
@@ -2022,7 +2074,7 @@ mod tests {
2022
2074
  }
2023
2075
  }
2024
2076
 
2025
- fn reach(root: &Path, path: &str) -> Result<Arc<Dentry>, FilesystemError> {
2077
+ fn reach(root: &Path, path: &str) -> Result<Arc<Dentry>, Errno> {
2026
2078
  super::filename_lookup(&Arc::default(), root, path, false)?.path()
2027
2079
  }
2028
2080
 
@@ -2031,9 +2083,8 @@ mod tests {
2031
2083
  // @behavior RT-315
2032
2084
  #[test]
2033
2085
  fn a_directory_found_under_a_second_name_moves_its_dentry_there() {
2034
- let root = root_of(
2035
- Filesystem::new(Arc::new(SharesDirectory::default())).expect("the instance must stand"),
2036
- );
2086
+ let root =
2087
+ root_of(Filesystem::new(SharesDirectory::default()).expect("the instance must stand"));
2037
2088
  let first = reach(&root, "a").expect("a is reached");
2038
2089
  let second = reach(&root, "b").expect("b is reached");
2039
2090
  assert_eq!(
@@ -2047,9 +2098,8 @@ mod tests {
2047
2098
  // @behavior RT-316
2048
2099
  #[test]
2049
2100
  fn a_directory_found_beneath_itself_answers_eloop() {
2050
- let root = root_of(
2051
- Filesystem::new(Arc::new(SharesDirectory::default())).expect("the instance must stand"),
2052
- );
2101
+ let root =
2102
+ root_of(Filesystem::new(SharesDirectory::default()).expect("the instance must stand"));
2053
2103
  let (answered, answer) = mpsc::channel();
2054
2104
  thread::spawn(move || answered.send(reach(&root, "a/loop").err()).ok());
2055
2105
  let answer = answer
@@ -2057,7 +2107,7 @@ mod tests {
2057
2107
  .expect("a walk through a directory moved beneath itself would never end");
2058
2108
  assert_eq!(
2059
2109
  answer,
2060
- Some(FilesystemError::FilesystemLoop),
2110
+ Some(Errno::FilesystemLoop),
2061
2111
  "a walk reaching `a/loop` over a Filesystem handing `a`'s own inode for it must \
2062
2112
  answer ELOOP, as d_splice_alias refuses an alias that is an ancestor"
2063
2113
  );
@@ -2068,9 +2118,8 @@ mod tests {
2068
2118
  // @behavior RT-317
2069
2119
  #[test]
2070
2120
  fn a_directory_whose_move_another_call_holds_up_answers_estale() {
2071
- let root = root_of(
2072
- Filesystem::new(Arc::new(SharesDirectory::default())).expect("the instance must stand"),
2073
- );
2121
+ let root =
2122
+ root_of(Filesystem::new(SharesDirectory::default()).expect("the instance must stand"));
2074
2123
  reach(&root, "a").expect("a is reached");
2075
2124
  let _renaming = root
2076
2125
  .mnt()
@@ -2080,12 +2129,55 @@ mod tests {
2080
2129
  .expect("nothing else holds the rename lock");
2081
2130
  assert_eq!(
2082
2131
  reach(&root, "c/d").err(),
2083
- Some(FilesystemError::StaleNetworkFileHandle),
2132
+ Some(Errno::StaleNetworkFileHandle),
2084
2133
  "a walk reaching `c/d`, the directory standing at `a`, while a call holds the \
2085
2134
  rename lock must answer ESTALE, as __d_unalias only tries the lock"
2086
2135
  );
2087
2136
  }
2088
2137
 
2138
+ /// A Filesystem answering each lookup of `d` with a new inode for the one
2139
+ /// directory it holds there, as a backend keeping no inode of its own.
2140
+ #[derive(Clone, Default)]
2141
+ struct AnswersAnew;
2142
+
2143
+ impl FileSystemType for AnswersAnew {
2144
+ fn fill_super(self: Arc<Self>, sb: &mut Filesystem) -> Result<(), Errno> {
2145
+ sb.d_make_root(vfs::Inode::new(&Kstat::new(FileType::Dir, 0), self));
2146
+ Ok(())
2147
+ }
2148
+ }
2149
+
2150
+ impl InodeOperations for AnswersAnew {
2151
+ fn getattr(&self, _dentry: &Dentry) -> Result<Kstat, Errno> {
2152
+ Ok(Kstat::new(FileType::Dir, 0))
2153
+ }
2154
+
2155
+ fn lookup(&self, dentry: &Dentry) -> Result<Lookup, Errno> {
2156
+ let dir = Kstat::new(FileType::Dir, 0).with_identity(1, 7);
2157
+ Ok(match dentry.name().as_str() {
2158
+ "d" => Lookup::Found(Inode::new(&dir, Arc::new(self.clone()))),
2159
+ _ => Lookup::Absent,
2160
+ })
2161
+ }
2162
+ }
2163
+
2164
+ // A second dentry for one directory would hold none of what stands on
2165
+ // the first, such as a mount, and would lock apart from it.
2166
+ // @behavior RT-393
2167
+ #[test]
2168
+ fn a_directory_a_filesystem_answers_anew_keeps_its_one_dentry() {
2169
+ let root = root_of(Filesystem::new(AnswersAnew).expect("the instance must stand"));
2170
+ let first = reach(&root, "d").expect("d is reached");
2171
+ root.mnt().sb().dentries().unhash(&first);
2172
+ let second = reach(&root, "d").expect("d is reached again");
2173
+ assert!(
2174
+ Arc::ptr_eq(&first, &second),
2175
+ "a walk reaching `d` again, after its held dentry left the name table, over a \
2176
+ Filesystem answering each lookup with a new inode of one identity must find the \
2177
+ dentry it held, as iget5_locked finds the directory's live inode"
2178
+ );
2179
+ }
2180
+
2089
2181
  /// A Filesystem handing one directory's inode for `a` and `b` in its root,
2090
2182
  /// whose lookup of `b` answers once the test lets it, counting each.
2091
2183
  #[derive(Clone, Default)]
@@ -2096,7 +2188,7 @@ mod tests {
2096
2188
  }
2097
2189
 
2098
2190
  impl FileSystemType for HoldsSharedLookup {
2099
- fn fill_super(self: Arc<Self>, sb: &mut Filesystem) -> Result<(), FilesystemError> {
2191
+ fn fill_super(self: Arc<Self>, sb: &mut Filesystem) -> Result<(), Errno> {
2100
2192
  sb.d_make_root(vfs::Inode::new(
2101
2193
  &Kstat::new(crate::filesystem::FileType::Dir, 0),
2102
2194
  self,
@@ -2106,11 +2198,11 @@ mod tests {
2106
2198
  }
2107
2199
 
2108
2200
  impl InodeOperations for HoldsSharedLookup {
2109
- fn getattr(&self, _dentry: &Dentry) -> Result<Kstat, FilesystemError> {
2201
+ fn getattr(&self, _dentry: &Dentry) -> Result<Kstat, Errno> {
2110
2202
  Ok(Kstat::new(FileType::Dir, 0))
2111
2203
  }
2112
2204
 
2113
- fn lookup(&self, dentry: &Dentry) -> Result<Lookup, FilesystemError> {
2205
+ fn lookup(&self, dentry: &Dentry) -> Result<Lookup, Errno> {
2114
2206
  let name = dentry.name();
2115
2207
  if name == "b" {
2116
2208
  self.asked.fetch_add(1, Ordering::SeqCst);
@@ -2157,10 +2249,10 @@ mod tests {
2157
2249
  /// Filesystem was asked about `b` once.
2158
2250
  fn waits_on_a_name_a_directory_moved_onto(
2159
2251
  what: &str,
2160
- second: fn(&Path, &str) -> Result<Arc<Dentry>, FilesystemError>,
2252
+ second: fn(&Path, &str) -> Result<Arc<Dentry>, Errno>,
2161
2253
  ) {
2162
2254
  let fs = HoldsSharedLookup::default();
2163
- let root = root_of(Filesystem::new(Arc::new(fs.clone())).expect("the instance must stand"));
2255
+ let root = root_of(Filesystem::new(fs.clone()).expect("the instance must stand"));
2164
2256
  let first = reach(&root, "a").expect("a is reached");
2165
2257
  let looking = {
2166
2258
  let root = root.clone();
@@ -2222,15 +2314,11 @@ mod tests {
2222
2314
  }
2223
2315
 
2224
2316
  impl wrap::Hook for AnswersStale {
2225
- fn lookup(
2226
- &self,
2227
- inner: &dyn InodeOperations,
2228
- dentry: &Dentry,
2229
- ) -> Result<Lookup, FilesystemError> {
2317
+ fn lookup(&self, inner: &dyn InodeOperations, dentry: &Dentry) -> Result<Lookup, Errno> {
2230
2318
  if *self.stale.lock().expect("unpoisoned") == dentry.name() {
2231
2319
  self.asked.fetch_add(1, Ordering::SeqCst);
2232
2320
  if self.armed.swap(self.always, Ordering::SeqCst) {
2233
- return Err(FilesystemError::StaleNetworkFileHandle);
2321
+ return Err(Errno::StaleNetworkFileHandle);
2234
2322
  }
2235
2323
  }
2236
2324
  inner.lookup(dentry)
@@ -2249,18 +2337,13 @@ mod tests {
2249
2337
  root_of(instance())
2250
2338
  }
2251
2339
 
2252
- type StaleCall = fn(&Arc<Cred>, &Path) -> Result<(), FilesystemError>;
2340
+ type StaleCall = fn(&Arc<Cred>, &Path) -> Result<(), Errno>;
2253
2341
 
2254
2342
  /// Each VFS entry that walks a path beneath `dir`, the name it acts on once
2255
2343
  /// its walk ended, and what it answers where nothing is stale. A Tmpfs makes
2256
2344
  /// no link, so the calls making one answer EPERM.
2257
- fn stale_calls() -> [(
2258
- &'static str,
2259
- &'static str,
2260
- StaleCall,
2261
- Result<(), FilesystemError>,
2262
- ); 10] {
2263
- use FilesystemError::{InvalidInput, NotPermitted};
2345
+ fn stale_calls() -> [(&'static str, &'static str, StaleCall, Result<(), Errno>); 10] {
2346
+ use Errno::{InvalidInput, NotPermitted};
2264
2347
  [
2265
2348
  (
2266
2349
  "vfs_fstatat",
@@ -2328,7 +2411,7 @@ mod tests {
2328
2411
  "do_utimes_path",
2329
2412
  "file",
2330
2413
  |cred, root| {
2331
- let times = vfs::Iattr::times(None, Some(crate::filesystem::SetTime::Now));
2414
+ let times = vfs::Iattr::for_times(None, Some(crate::filesystem::SetTime::Now));
2332
2415
  vfs::do_utimes_path(cred, root, "dir/file", false, &times)
2333
2416
  },
2334
2417
  Ok(()),
@@ -2338,7 +2421,7 @@ mod tests {
2338
2421
 
2339
2422
  /// What `run` answers over a Filesystem answering ESTALE about `name`, once
2340
2423
  /// or `always`, and how many times it was asked about `name`.
2341
- fn run_stale(run: StaleCall, name: &str, always: bool) -> (Result<(), FilesystemError>, usize) {
2424
+ fn run_stale(run: StaleCall, name: &str, always: bool) -> (Result<(), Errno>, usize) {
2342
2425
  let hook = Arc::new(AnswersStale {
2343
2426
  always,
2344
2427
  ..AnswersStale::default()
@@ -2373,7 +2456,7 @@ mod tests {
2373
2456
  for (call, _, run, _) in stale_calls() {
2374
2457
  assert_eq!(
2375
2458
  run_stale(run, "dir", true),
2376
- (Err(FilesystemError::StaleNetworkFileHandle), 2),
2459
+ (Err(Errno::StaleNetworkFileHandle), 2),
2377
2460
  "vfs::{call} over a Filesystem always answering ESTALE about `dir` must answer \
2378
2461
  ESTALE after asking twice, as no caller makes a walk's error again"
2379
2462
  );
@@ -2415,7 +2498,7 @@ mod tests {
2415
2498
  for (call, name, run, _) in calls {
2416
2499
  assert_eq!(
2417
2500
  run_stale(run, name, false),
2418
- (Err(FilesystemError::StaleNetworkFileHandle), 1),
2501
+ (Err(Errno::StaleNetworkFileHandle), 1),
2419
2502
  "vfs::{call} over a Filesystem answering ESTALE the first time it is asked \
2420
2503
  about `{name}` must answer ESTALE after asking once, as filename_create's \
2421
2504
  error returns before retry_estale"
@@ -2427,12 +2510,12 @@ mod tests {
2427
2510
  // entry has is refused before any directory is searched.
2428
2511
  #[test]
2429
2512
  fn a_stacked_lookup_refuses_a_name_no_single_entry_has() {
2430
- let filesystem = Filesystem::new(Arc::new(Tmpfs::new())).expect("the instance must stand");
2431
- let root = filesystem.s_root();
2513
+ let filesystem = Filesystem::new(Tmpfs::new()).expect("the instance must stand");
2514
+ let root = filesystem.root().expect(crate::vfs::MADE_ROOT).clone();
2432
2515
  for name in ["", ".", "..", "a/b", "a\0b"] {
2433
2516
  assert_eq!(
2434
2517
  super::lookup_one_unlocked(&Cred::default(), &filesystem, &root, name).err(),
2435
- Some(FilesystemError::PermissionDenied),
2518
+ Some(Errno::PermissionDenied),
2436
2519
  "lookup_one_unlocked of {name:?} must answer EACCES, as lookup_noperm_common \
2437
2520
  refuses a name no single entry has"
2438
2521
  );
@@ -2451,7 +2534,7 @@ mod tests {
2451
2534
  impl FileOperations for NoOperations {}
2452
2535
 
2453
2536
  impl FileSystemType for CreatesOnly {
2454
- fn fill_super(self: Arc<Self>, sb: &mut Filesystem) -> Result<(), FilesystemError> {
2537
+ fn fill_super(self: Arc<Self>, sb: &mut Filesystem) -> Result<(), Errno> {
2455
2538
  sb.d_make_root(vfs::Inode::new(
2456
2539
  &Kstat::new(crate::filesystem::FileType::Dir, 0),
2457
2540
  self,
@@ -2461,28 +2544,24 @@ mod tests {
2461
2544
  }
2462
2545
 
2463
2546
  impl InodeOperations for CreatesOnly {
2464
- fn getattr(&self, dentry: &Dentry) -> Result<Kstat, FilesystemError> {
2547
+ fn getattr(&self, dentry: &Dentry) -> Result<Kstat, Errno> {
2465
2548
  Ok(match dentry.is_root() {
2466
2549
  false => Kstat::new(FileType::RegFile, 0),
2467
2550
  true => Kstat::new(FileType::Dir, 0),
2468
2551
  })
2469
2552
  }
2470
2553
 
2471
- fn lookup(&self, _dentry: &Dentry) -> Result<Lookup, FilesystemError> {
2554
+ fn lookup(&self, _dentry: &Dentry) -> Result<Lookup, Errno> {
2472
2555
  Ok(Lookup::Absent)
2473
2556
  }
2474
2557
 
2475
- fn create(&self, dentry: &Dentry) -> Result<(), FilesystemError> {
2558
+ fn create(&self, dentry: &Dentry) -> Result<(), Errno> {
2476
2559
  let made = Kstat::new(FileType::RegFile, 0);
2477
2560
  dentry.add(Some(Inode::new(&made, Arc::new(self.clone()))));
2478
2561
  Ok(())
2479
2562
  }
2480
2563
 
2481
- fn open(
2482
- &self,
2483
- _dentry: &Dentry,
2484
- _how: &OpenHow,
2485
- ) -> Result<Box<dyn FileOperations>, FilesystemError> {
2564
+ fn open(&self, _dentry: &Dentry, _how: &OpenHow) -> Result<Box<dyn FileOperations>, Errno> {
2486
2565
  self.opened.fetch_add(1, Ordering::SeqCst);
2487
2566
  Ok(Box::new(NoOperations))
2488
2567
  }
@@ -2494,7 +2573,7 @@ mod tests {
2494
2573
  let filesystem = CreatesOnly::default();
2495
2574
  let mount = Mount::new(
2496
2575
  "/data",
2497
- Filesystem::new(Arc::new(filesystem.clone())).expect("the instance must stand"),
2576
+ Filesystem::new(filesystem.clone()).expect("the instance must stand"),
2498
2577
  Access::ReadWrite,
2499
2578
  )
2500
2579
  .expect("/data is a guest path");
@@ -2527,9 +2606,9 @@ mod tests {
2527
2606
  _kind: FileType,
2528
2607
  mode: FMode,
2529
2608
  _how: &OpenHow,
2530
- ) -> Result<FileSecurity, FilesystemError> {
2609
+ ) -> Result<FileSecurity, Errno> {
2531
2610
  match mode.contains(FMode::CREATED) {
2532
- true => Err(FilesystemError::PermissionDenied),
2611
+ true => Err(Errno::PermissionDenied),
2533
2612
  false => Ok(None),
2534
2613
  }
2535
2614
  }
@@ -2541,7 +2620,7 @@ mod tests {
2541
2620
  let filesystem = CreatesOnly::default();
2542
2621
  let mount = Mount::new(
2543
2622
  "/data",
2544
- Filesystem::new(Arc::new(filesystem.clone())).expect("the instance must stand"),
2623
+ Filesystem::new(filesystem.clone()).expect("the instance must stand"),
2545
2624
  Access::ReadWrite,
2546
2625
  )
2547
2626
  .expect("/data is a guest path");
@@ -2554,7 +2633,7 @@ mod tests {
2554
2633
  let answer = vfs::kern_path::filp_open(&cred, &Path::root(mount.mnt()), "made", &how);
2555
2634
  assert_eq!(
2556
2635
  (answer.err(), filesystem.opened.load(Ordering::SeqCst)),
2557
- (Some(FilesystemError::PermissionDenied), 0),
2636
+ (Some(Errno::PermissionDenied), 0),
2558
2637
  "vfs::do_file_open making a file on a Filesystem with no atomic_open, under a \
2559
2638
  security module refusing the open, must never ask the Filesystem's open, as \
2560
2639
  do_open asks security_file_open before vfs_open reaches f_op->open"
@@ -2568,7 +2647,7 @@ mod tests {
2568
2647
  let made = holds.made.clone();
2569
2648
  let mount = Mount::new(
2570
2649
  "/data",
2571
- Filesystem::new(Arc::new(holds)).expect("the instance must stand"),
2650
+ Filesystem::new(holds).expect("the instance must stand"),
2572
2651
  Access::ReadWrite,
2573
2652
  )
2574
2653
  .expect("/data is a guest path");
@@ -2581,7 +2660,7 @@ mod tests {
2581
2660
  let answer = vfs::kern_path::filp_open(&cred, &Path::root(mount.mnt()), "made", &how);
2582
2661
  assert_eq!(
2583
2662
  (answer.err(), made.load(Ordering::SeqCst)),
2584
- (Some(FilesystemError::PermissionDenied), true),
2663
+ (Some(Errno::PermissionDenied), true),
2585
2664
  "vfs::do_file_open making a file through atomic_open, under a security module \
2586
2665
  refusing the open, must make the file and answer EACCES, as finish_open reaches \
2587
2666
  security_file_open"
@@ -2594,7 +2673,7 @@ mod tests {
2594
2673
  struct OpensWithinItsDirectory(CreatesOnly);
2595
2674
 
2596
2675
  impl FileSystemType for OpensWithinItsDirectory {
2597
- fn fill_super(self: Arc<Self>, sb: &mut Filesystem) -> Result<(), FilesystemError> {
2676
+ fn fill_super(self: Arc<Self>, sb: &mut Filesystem) -> Result<(), Errno> {
2598
2677
  sb.d_make_root(vfs::Inode::new(
2599
2678
  &Kstat::new(crate::filesystem::FileType::Dir, 0),
2600
2679
  self,
@@ -2604,25 +2683,21 @@ mod tests {
2604
2683
  }
2605
2684
 
2606
2685
  impl InodeOperations for OpensWithinItsDirectory {
2607
- fn getattr(&self, dentry: &Dentry) -> Result<Kstat, FilesystemError> {
2686
+ fn getattr(&self, dentry: &Dentry) -> Result<Kstat, Errno> {
2608
2687
  self.0.getattr(dentry)
2609
2688
  }
2610
2689
 
2611
- fn lookup(&self, dentry: &Dentry) -> Result<Lookup, FilesystemError> {
2690
+ fn lookup(&self, dentry: &Dentry) -> Result<Lookup, Errno> {
2612
2691
  self.0.lookup(dentry)
2613
2692
  }
2614
2693
 
2615
- fn create(&self, dentry: &Dentry) -> Result<(), FilesystemError> {
2694
+ fn create(&self, dentry: &Dentry) -> Result<(), Errno> {
2616
2695
  let made = Kstat::new(FileType::RegFile, 0);
2617
2696
  dentry.add(Some(Inode::new(&made, Arc::new(self.clone()))));
2618
2697
  Ok(())
2619
2698
  }
2620
2699
 
2621
- fn open(
2622
- &self,
2623
- dentry: &Dentry,
2624
- how: &OpenHow,
2625
- ) -> Result<Box<dyn FileOperations>, FilesystemError> {
2700
+ fn open(&self, dentry: &Dentry, how: &OpenHow) -> Result<Box<dyn FileOperations>, Errno> {
2626
2701
  let _held = dentry.parent().inode_lock()?;
2627
2702
  self.0.open(dentry, how)
2628
2703
  }
@@ -2634,7 +2709,7 @@ mod tests {
2634
2709
  let filesystem = OpensWithinItsDirectory::default();
2635
2710
  let mount = Mount::new(
2636
2711
  "/data",
2637
- Filesystem::new(Arc::new(filesystem)).expect("the instance must stand"),
2712
+ Filesystem::new(filesystem).expect("the instance must stand"),
2638
2713
  Access::ReadWrite,
2639
2714
  )
2640
2715
  .expect("/data is a guest path");
@@ -2657,7 +2732,7 @@ mod tests {
2657
2732
  struct FindsAFileStanding(CreatesOnly);
2658
2733
 
2659
2734
  impl FileSystemType for FindsAFileStanding {
2660
- fn fill_super(self: Arc<Self>, sb: &mut Filesystem) -> Result<(), FilesystemError> {
2735
+ fn fill_super(self: Arc<Self>, sb: &mut Filesystem) -> Result<(), Errno> {
2661
2736
  sb.d_make_root(vfs::Inode::new(
2662
2737
  &Kstat::new(crate::filesystem::FileType::Dir, 0),
2663
2738
  self,
@@ -2667,15 +2742,15 @@ mod tests {
2667
2742
  }
2668
2743
 
2669
2744
  impl InodeOperations for FindsAFileStanding {
2670
- fn getattr(&self, dentry: &Dentry) -> Result<Kstat, FilesystemError> {
2745
+ fn getattr(&self, dentry: &Dentry) -> Result<Kstat, Errno> {
2671
2746
  self.0.getattr(dentry)
2672
2747
  }
2673
2748
 
2674
- fn lookup(&self, dentry: &Dentry) -> Result<Lookup, FilesystemError> {
2749
+ fn lookup(&self, dentry: &Dentry) -> Result<Lookup, Errno> {
2675
2750
  self.0.lookup(dentry)
2676
2751
  }
2677
2752
 
2678
- fn atomic_open(&self, dentry: &Dentry, _how: &OpenHow) -> Result<Finish, FilesystemError> {
2753
+ fn atomic_open(&self, dentry: &Dentry, _how: &OpenHow) -> Result<Finish, Errno> {
2679
2754
  let found = Kstat::new(FileType::RegFile, 0);
2680
2755
  dentry.add(Some(Inode::new(&found, Arc::new(self.clone()))));
2681
2756
  Ok(Finish::Open {
@@ -2690,8 +2765,7 @@ mod tests {
2690
2765
  fn a_file_atomic_open_found_standing_opens_as_one_that_stood() {
2691
2766
  let mount = Mount::new(
2692
2767
  "/data",
2693
- Filesystem::new(Arc::new(FindsAFileStanding::default()))
2694
- .expect("the instance must stand"),
2768
+ Filesystem::new(FindsAFileStanding::default()).expect("the instance must stand"),
2695
2769
  Access::ReadWrite,
2696
2770
  )
2697
2771
  .expect("/data is a guest path");
@@ -2705,7 +2779,7 @@ mod tests {
2705
2779
  vfs::kern_path::filp_open(&Arc::default(), &Path::root(mount.mnt()), "found", &how);
2706
2780
  assert_eq!(
2707
2781
  answer.err(),
2708
- Some(FilesystemError::AlreadyExists),
2782
+ Some(Errno::AlreadyExists),
2709
2783
  "vfs::do_file_open with create and exclusive, on a Filesystem whose atomic_open \
2710
2784
  found the file standing, must answer EEXIST, as do_open refuses O_EXCL without \
2711
2785
  FMODE_CREATED"
@@ -2720,7 +2794,7 @@ mod tests {
2720
2794
  struct OpensAtOnce(Arc<(AtomicUsize, AtomicUsize, AtomicBool)>);
2721
2795
 
2722
2796
  impl FileSystemType for OpensAtOnce {
2723
- fn fill_super(self: Arc<Self>, sb: &mut Filesystem) -> Result<(), FilesystemError> {
2797
+ fn fill_super(self: Arc<Self>, sb: &mut Filesystem) -> Result<(), Errno> {
2724
2798
  sb.d_make_root(vfs::Inode::new(
2725
2799
  &Kstat::new(crate::filesystem::FileType::Dir, 0),
2726
2800
  self,
@@ -2730,20 +2804,20 @@ mod tests {
2730
2804
  }
2731
2805
 
2732
2806
  impl InodeOperations for OpensAtOnce {
2733
- fn getattr(&self, _dentry: &Dentry) -> Result<Kstat, FilesystemError> {
2807
+ fn getattr(&self, _dentry: &Dentry) -> Result<Kstat, Errno> {
2734
2808
  Ok(Kstat::new(FileType::Dir, 0))
2735
2809
  }
2736
2810
 
2737
- fn lookup(&self, _dentry: &Dentry) -> Result<Lookup, FilesystemError> {
2811
+ fn lookup(&self, _dentry: &Dentry) -> Result<Lookup, Errno> {
2738
2812
  self.0 .0.fetch_add(1, Ordering::SeqCst);
2739
2813
  Ok(Lookup::Absent)
2740
2814
  }
2741
2815
 
2742
- fn atomic_open(&self, dentry: &Dentry, how: &OpenHow) -> Result<Finish, FilesystemError> {
2816
+ fn atomic_open(&self, dentry: &Dentry, how: &OpenHow) -> Result<Finish, Errno> {
2743
2817
  self.0 .1.fetch_add(1, Ordering::SeqCst);
2744
2818
  if how.directory {
2745
2819
  self.0 .2.store(true, Ordering::SeqCst);
2746
- return Err(FilesystemError::NotADirectory);
2820
+ return Err(Errno::NotADirectory);
2747
2821
  }
2748
2822
  let found = Kstat::new(FileType::RegFile, 0);
2749
2823
  dentry.add(Some(Inode::new(&found, Arc::new(self.clone()))));
@@ -2761,7 +2835,7 @@ mod tests {
2761
2835
  struct RecordsTruncate(Arc<Mutex<Option<bool>>>);
2762
2836
 
2763
2837
  impl FileSystemType for RecordsTruncate {
2764
- fn fill_super(self: Arc<Self>, sb: &mut Filesystem) -> Result<(), FilesystemError> {
2838
+ fn fill_super(self: Arc<Self>, sb: &mut Filesystem) -> Result<(), Errno> {
2765
2839
  sb.d_make_root(vfs::Inode::new(
2766
2840
  &Kstat::new(crate::filesystem::FileType::Dir, 0),
2767
2841
  self,
@@ -2771,11 +2845,11 @@ mod tests {
2771
2845
  }
2772
2846
 
2773
2847
  impl InodeOperations for RecordsTruncate {
2774
- fn getattr(&self, _dentry: &Dentry) -> Result<Kstat, FilesystemError> {
2848
+ fn getattr(&self, _dentry: &Dentry) -> Result<Kstat, Errno> {
2775
2849
  Ok(Kstat::new(FileType::Dir, 0))
2776
2850
  }
2777
2851
 
2778
- fn lookup(&self, dentry: &Dentry) -> Result<Lookup, FilesystemError> {
2852
+ fn lookup(&self, dentry: &Dentry) -> Result<Lookup, Errno> {
2779
2853
  let file = Kstat::new(FileType::RegFile, 0);
2780
2854
  Ok(match dentry.name().as_str() {
2781
2855
  "file" => Lookup::Found(Inode::new(&file, Arc::new(self.clone()))),
@@ -2783,7 +2857,7 @@ mod tests {
2783
2857
  })
2784
2858
  }
2785
2859
 
2786
- fn atomic_open(&self, dentry: &Dentry, how: &OpenHow) -> Result<Finish, FilesystemError> {
2860
+ fn atomic_open(&self, dentry: &Dentry, how: &OpenHow) -> Result<Finish, Errno> {
2787
2861
  *self.0.lock().expect("unpoisoned") = Some(how.truncate);
2788
2862
  let found = self.lookup(dentry)?;
2789
2863
  if !how.create || !matches!(found, Lookup::Absent) {
@@ -2803,7 +2877,7 @@ mod tests {
2803
2877
  let fs = RecordsTruncate::default();
2804
2878
  let mount = Mount::new(
2805
2879
  "/data",
2806
- Filesystem::new(Arc::new(fs.clone())).expect("the instance must stand"),
2880
+ Filesystem::new(fs.clone()).expect("the instance must stand"),
2807
2881
  Access::Read,
2808
2882
  )
2809
2883
  .expect("/data is a guest path");
@@ -2820,7 +2894,7 @@ mod tests {
2820
2894
  );
2821
2895
  assert_eq!(
2822
2896
  (answer.err(), *fs.0.lock().expect("unpoisoned")),
2823
- (Some(FilesystemError::ReadOnlyFilesystem), Some(false)),
2897
+ (Some(Errno::ReadOnlyFilesystem), Some(false)),
2824
2898
  "vfs::do_file_open truncating `file` beneath a read-only mount must ask the \
2825
2899
  Filesystem's atomic_open for no truncation and answer EROFS, as lookup_open \
2826
2900
  clears O_TRUNC without got_write"
@@ -2833,7 +2907,7 @@ mod tests {
2833
2907
  #[test]
2834
2908
  fn an_exclusive_create_asks_no_truncation() {
2835
2909
  let fs = RecordsTruncate::default();
2836
- let root = root_of(Filesystem::new(Arc::new(fs.clone())).expect("the instance must stand"));
2910
+ let root = root_of(Filesystem::new(fs.clone()).expect("the instance must stand"));
2837
2911
  let making = OpenHow {
2838
2912
  write: true,
2839
2913
  create: true,
@@ -2857,7 +2931,7 @@ mod tests {
2857
2931
  #[test]
2858
2932
  fn an_open_of_a_name_no_walk_looked_up_asks_atomic_open() {
2859
2933
  let fs = OpensAtOnce::default();
2860
- let root = root_of(Filesystem::new(Arc::new(fs.clone())).expect("the instance must stand"));
2934
+ let root = root_of(Filesystem::new(fs.clone()).expect("the instance must stand"));
2861
2935
  let read = OpenHow {
2862
2936
  read: true,
2863
2937
  ..OpenHow::default()
@@ -2881,7 +2955,7 @@ mod tests {
2881
2955
  #[test]
2882
2956
  fn a_name_with_a_trailing_slash_asks_atomic_open_for_a_directory() {
2883
2957
  let fs = OpensAtOnce::default();
2884
- let root = root_of(Filesystem::new(Arc::new(fs.clone())).expect("the instance must stand"));
2958
+ let root = root_of(Filesystem::new(fs.clone()).expect("the instance must stand"));
2885
2959
  let read = OpenHow {
2886
2960
  read: true,
2887
2961
  ..OpenHow::default()
@@ -2889,7 +2963,7 @@ mod tests {
2889
2963
  let answer = vfs::kern_path::filp_open(&Arc::default(), &root, "file/", &read);
2890
2964
  assert_eq!(
2891
2965
  (answer.err(), fs.0 .2.load(Ordering::SeqCst)),
2892
- (Some(FilesystemError::NotADirectory), true),
2966
+ (Some(Errno::NotADirectory), true),
2893
2967
  "vfs::do_file_open of `file/` over a Filesystem opening in one step must ask its \
2894
2968
  atomic_open for a directory and answer ENOTDIR, as lookup_open adds O_DIRECTORY"
2895
2969
  );
@@ -2902,7 +2976,7 @@ mod tests {
2902
2976
  struct OpensSpelled(Arc<AtomicUsize>);
2903
2977
 
2904
2978
  impl FileSystemType for OpensSpelled {
2905
- fn fill_super(self: Arc<Self>, sb: &mut Filesystem) -> Result<(), FilesystemError> {
2979
+ fn fill_super(self: Arc<Self>, sb: &mut Filesystem) -> Result<(), Errno> {
2906
2980
  sb.d_make_root(vfs::Inode::new(
2907
2981
  &Kstat::new(crate::filesystem::FileType::Dir, 0),
2908
2982
  self,
@@ -2912,16 +2986,16 @@ mod tests {
2912
2986
  }
2913
2987
 
2914
2988
  impl InodeOperations for OpensSpelled {
2915
- fn getattr(&self, _dentry: &Dentry) -> Result<Kstat, FilesystemError> {
2989
+ fn getattr(&self, _dentry: &Dentry) -> Result<Kstat, Errno> {
2916
2990
  Ok(Kstat::new(FileType::Dir, 0))
2917
2991
  }
2918
2992
 
2919
- fn lookup(&self, _dentry: &Dentry) -> Result<Lookup, FilesystemError> {
2993
+ fn lookup(&self, _dentry: &Dentry) -> Result<Lookup, Errno> {
2920
2994
  self.0.fetch_add(1, Ordering::SeqCst);
2921
2995
  Ok(Lookup::Absent)
2922
2996
  }
2923
2997
 
2924
- fn atomic_open(&self, _dentry: &Dentry, _how: &OpenHow) -> Result<Finish, FilesystemError> {
2998
+ fn atomic_open(&self, _dentry: &Dentry, _how: &OpenHow) -> Result<Finish, Errno> {
2925
2999
  let file = Kstat::new(FileType::RegFile, 0);
2926
3000
  Ok(Finish::Spelled {
2927
3001
  file: Box::new(NoOperations),
@@ -2937,7 +3011,7 @@ mod tests {
2937
3011
  #[test]
2938
3012
  fn a_file_atomic_open_opens_under_another_spelling_opens_as_that_spelling() {
2939
3013
  let fs = OpensSpelled::default();
2940
- let root = root_of(Filesystem::new(Arc::new(fs.clone())).expect("the instance must stand"));
3014
+ let root = root_of(Filesystem::new(fs.clone()).expect("the instance must stand"));
2941
3015
  let read = OpenHow {
2942
3016
  read: true,
2943
3017
  ..OpenHow::default()
@@ -2971,7 +3045,7 @@ mod tests {
2971
3045
  root: kern_path(Arc::new(tmpfs)),
2972
3046
  renaming: Arc::new(Box::new(|| Ok(()))),
2973
3047
  };
2974
- let root = root_of(Filesystem::new(Arc::new(folds)).expect("the instance must stand"));
3048
+ let root = root_of(Filesystem::new(folds).expect("the instance must stand"));
2975
3049
  let read = OpenHow {
2976
3050
  read: true,
2977
3051
  ..OpenHow::default()
@@ -3000,11 +3074,11 @@ mod tests {
3000
3074
  _inner: &dyn InodeOperations,
3001
3075
  dentry: &Dentry,
3002
3076
  mask: Mask,
3003
- ) -> Result<(), FilesystemError> {
3077
+ ) -> Result<(), Errno> {
3004
3078
  let mut asked = self.asked.lock().expect("never poisoned");
3005
3079
  asked.push((dentry.name(), mask));
3006
3080
  match self.refuse_writes.load(Ordering::SeqCst) && mask.contains(Mask::WRITE) {
3007
- true => Err(FilesystemError::PermissionDenied),
3081
+ true => Err(Errno::PermissionDenied),
3008
3082
  false => Ok(()),
3009
3083
  }
3010
3084
  }
@@ -3013,8 +3087,8 @@ mod tests {
3013
3087
  /// A security module counting the changes it is asked about.
3014
3088
  struct CountsChanges(Arc<AtomicUsize>);
3015
3089
 
3016
- impl vfs::SecurityOperations for CountsChanges {
3017
- fn inode_permission(&self, _dentry: &Dentry, mask: Mask) -> Result<(), FilesystemError> {
3090
+ impl crate::security::SecurityOperations for CountsChanges {
3091
+ fn inode_permission(&self, _dentry: &Dentry, mask: Mask) -> Result<(), Errno> {
3018
3092
  if mask.contains(Mask::WRITE) {
3019
3093
  self.0.fetch_add(1, Ordering::SeqCst);
3020
3094
  }
@@ -3028,7 +3102,7 @@ mod tests {
3028
3102
  let hook = Arc::new(RecordsPermission::default());
3029
3103
  let root = permission_root(&hook);
3030
3104
  let asked = Arc::new(AtomicUsize::new(0));
3031
- let cred = vfs::Cred::new(vec![Arc::new(CountsChanges(asked.clone()))]);
3105
+ let cred = crate::cred::Cred::new(vec![Arc::new(CountsChanges(asked.clone()))]);
3032
3106
  let how = OpenHow {
3033
3107
  write: true,
3034
3108
  create: true,
@@ -3044,7 +3118,7 @@ mod tests {
3044
3118
  let after_allowed = asked.load(Ordering::SeqCst);
3045
3119
  hook.refuse_writes.store(true, Ordering::SeqCst);
3046
3120
  let refused = make("refused");
3047
- let denied = || Err(FilesystemError::PermissionDenied);
3121
+ let denied = || Err(Errno::PermissionDenied);
3048
3122
  assert_eq!(
3049
3123
  (
3050
3124
  allowed,
@@ -3065,7 +3139,7 @@ mod tests {
3065
3139
  let wrapped = Wrap::new(Arc::new(tmpfs), hook.clone());
3066
3140
  let mount = Mount::new(
3067
3141
  "/data",
3068
- Filesystem::new(Arc::new(wrapped)).expect("the instance must stand"),
3142
+ Filesystem::new(wrapped).expect("the instance must stand"),
3069
3143
  Access::ReadWrite,
3070
3144
  )
3071
3145
  .expect("/data is a guest path");
@@ -3169,7 +3243,7 @@ mod tests {
3169
3243
  struct ReadOnlyRefusingWrites;
3170
3244
 
3171
3245
  impl FileSystemType for ReadOnlyRefusingWrites {
3172
- fn fill_super(self: Arc<Self>, sb: &mut Filesystem) -> Result<(), FilesystemError> {
3246
+ fn fill_super(self: Arc<Self>, sb: &mut Filesystem) -> Result<(), Errno> {
3173
3247
  sb.set_rdonly();
3174
3248
  sb.d_make_root(vfs::Inode::new(
3175
3249
  &Kstat::new(crate::filesystem::FileType::Dir, 0),
@@ -3180,21 +3254,21 @@ mod tests {
3180
3254
  }
3181
3255
 
3182
3256
  impl InodeOperations for ReadOnlyRefusingWrites {
3183
- fn getattr(&self, dentry: &Dentry) -> Result<Kstat, FilesystemError> {
3257
+ fn getattr(&self, dentry: &Dentry) -> Result<Kstat, Errno> {
3184
3258
  Ok(match dentry.is_root() {
3185
3259
  false => Kstat::new(FileType::RegFile, 0),
3186
3260
  true => Kstat::new(FileType::Dir, 0),
3187
3261
  })
3188
3262
  }
3189
3263
 
3190
- fn lookup(&self, _dentry: &Dentry) -> Result<Lookup, FilesystemError> {
3264
+ fn lookup(&self, _dentry: &Dentry) -> Result<Lookup, Errno> {
3191
3265
  let file = Kstat::new(FileType::RegFile, 0);
3192
3266
  Ok(Lookup::Found(Inode::new(&file, Arc::new(Self))))
3193
3267
  }
3194
3268
 
3195
- fn permission(&self, _dentry: &Dentry, mask: Mask) -> Result<(), FilesystemError> {
3269
+ fn permission(&self, _dentry: &Dentry, mask: Mask) -> Result<(), Errno> {
3196
3270
  match mask.contains(Mask::WRITE) {
3197
- true => Err(FilesystemError::PermissionDenied),
3271
+ true => Err(Errno::PermissionDenied),
3198
3272
  false => Ok(()),
3199
3273
  }
3200
3274
  }
@@ -3207,7 +3281,7 @@ mod tests {
3207
3281
  fn a_read_only_filesystem_refuses_a_write_before_its_permission_is_asked() {
3208
3282
  let mount = Mount::new(
3209
3283
  "/data",
3210
- Filesystem::new(Arc::new(ReadOnlyRefusingWrites)).expect("the instance must stand"),
3284
+ Filesystem::new(ReadOnlyRefusingWrites).expect("the instance must stand"),
3211
3285
  Access::ReadWrite,
3212
3286
  )
3213
3287
  .expect("/data is a guest path");
@@ -3218,7 +3292,7 @@ mod tests {
3218
3292
  assert_eq!(
3219
3293
  vfs::kern_path::filp_open(&Arc::default(), &Path::root(mount.mnt()), "file", &how)
3220
3294
  .err(),
3221
- Some(FilesystemError::ReadOnlyFilesystem),
3295
+ Some(Errno::ReadOnlyFilesystem),
3222
3296
  "vfs::do_file_open to write a file of a read-only Filesystem whose permission refuses \
3223
3297
  writes must answer EROFS, as sb_permission answers before ->permission"
3224
3298
  );
@@ -3236,16 +3310,13 @@ mod tests {
3236
3310
  hook.refuse_writes.store(false, Ordering::SeqCst);
3237
3311
  assert_eq!(
3238
3312
  (made, removed),
3239
- (
3240
- Err(FilesystemError::PermissionDenied),
3241
- Err(FilesystemError::PermissionDenied)
3242
- ),
3313
+ (Err(Errno::PermissionDenied), Err(Errno::PermissionDenied)),
3243
3314
  "vfs::filename_mkdirat and filename_unlinkat on a directory whose permission \
3244
3315
  refuses a change must answer EACCES"
3245
3316
  );
3246
3317
  assert_eq!(
3247
3318
  vfs::vfs_fstatat(&cred, &root, "a/made", false).err(),
3248
- Some(FilesystemError::NotFound),
3319
+ Some(Errno::NotFound),
3249
3320
  "a refused mkdir must make nothing"
3250
3321
  );
3251
3322
  assert!(
@@ -3257,18 +3328,18 @@ mod tests {
3257
3328
  /// A link at the name `l`, moving a directory the moment the walk follows it,
3258
3329
  /// when the walk holds no directory's lock, and leading back where it stands.
3259
3330
  struct MovesWhenFollowed {
3260
- cred: Arc<vfs::Cred>,
3331
+ cred: Arc<crate::cred::Cred>,
3261
3332
  root: Arc<OnceLock<Path>>,
3262
3333
  from: &'static str,
3263
3334
  to: &'static str,
3264
3335
  }
3265
3336
 
3266
3337
  impl InodeOperations for MovesWhenFollowed {
3267
- fn getattr(&self, _dentry: &Dentry) -> Result<Kstat, FilesystemError> {
3338
+ fn getattr(&self, _dentry: &Dentry) -> Result<Kstat, Errno> {
3268
3339
  Ok(Kstat::new(FileType::Symlink, 0))
3269
3340
  }
3270
3341
 
3271
- fn get_link(&self, _dentry: &Dentry) -> Result<String, FilesystemError> {
3342
+ fn get_link(&self, _dentry: &Dentry) -> Result<String, Errno> {
3272
3343
  let root = self.root.get().expect("the mount stands by the first walk");
3273
3344
  vfs::filename_renameat2(&self.cred, root, self.from, root, self.to)?;
3274
3345
  Ok(".".to_string())
@@ -3278,11 +3349,7 @@ mod tests {
3278
3349
  struct LinkAtL(Arc<dyn InodeOperations>);
3279
3350
 
3280
3351
  impl wrap::Hook for LinkAtL {
3281
- fn lookup(
3282
- &self,
3283
- inner: &dyn InodeOperations,
3284
- dentry: &Dentry,
3285
- ) -> Result<Lookup, FilesystemError> {
3352
+ fn lookup(&self, inner: &dyn InodeOperations, dentry: &Dentry) -> Result<Lookup, Errno> {
3286
3353
  if dentry.name() != "l" {
3287
3354
  return inner.lookup(dentry);
3288
3355
  }
@@ -3308,7 +3375,7 @@ mod tests {
3308
3375
  let wrapped = Wrap::new(Arc::new(tmpfs), Arc::new(LinkAtL(Arc::new(link))));
3309
3376
  let mount = Mount::new(
3310
3377
  "/data",
3311
- Filesystem::new(Arc::new(wrapped)).expect("the instance must stand"),
3378
+ Filesystem::new(wrapped).expect("the instance must stand"),
3312
3379
  Access::ReadWrite,
3313
3380
  )
3314
3381
  .expect("/data is a guest path");
@@ -3325,21 +3392,200 @@ mod tests {
3325
3392
  let root = moves_as_walked(&[("a/b/keep", "k"), ("z/c", "moved")], "a/b", "z/b");
3326
3393
  let cred = Arc::default();
3327
3394
  let during = vfs::vfs_fstatat(&cred, &root, "a/b/l/../c", false);
3328
- // Any move in the process answers a `..` so, as `rename_lock` is one for all,
3329
- // and tests beside this one make them.
3330
- let mut after = Err(FilesystemError::WouldBlock);
3331
- crate::sched::testing::wait_until("the call made again answering", || {
3332
- after = vfs::vfs_fstatat(&cred, &root, "z/b/../c", false);
3333
- after != Err(FilesystemError::WouldBlock)
3334
- });
3395
+ let after = vfs::vfs_fstatat(&cred, &root, "z/b/../c", false);
3335
3396
  assert_eq!(
3336
3397
  (during.map(|_| ()), after.map(|stat| stat.size)),
3337
- (Err(FilesystemError::WouldBlock), Ok(5)),
3398
+ (Err(Errno::WouldBlock), Ok(5)),
3338
3399
  "vfs_fstatat through `..` with a move landing during the walk must answer EAGAIN, \
3339
3400
  as handle_dots reads r_seq, and the call made again reaches where it stands now"
3340
3401
  );
3341
3402
  }
3342
3403
 
3404
+ // The `..` here leaves the root of a nested mount, which climbs back to where
3405
+ // the walk stepped onto it rather than reading a parent.
3406
+ // @behavior RT-240
3407
+ #[test]
3408
+ fn a_dotdot_out_of_a_nested_mount_a_move_landed_before_asks_the_caller_again() {
3409
+ let outer = Mount::new(
3410
+ "/data",
3411
+ Filesystem::new(
3412
+ [("inner/keep", "k"), ("x/c", "moved")]
3413
+ .into_iter()
3414
+ .collect::<Tmpfs>(),
3415
+ )
3416
+ .expect("the instance must stand"),
3417
+ Access::ReadWrite,
3418
+ )
3419
+ .expect("/data is a guest path");
3420
+ let root = Arc::new(OnceLock::new());
3421
+ let link = MovesWhenFollowed {
3422
+ cred: Arc::default(),
3423
+ root: root.clone(),
3424
+ from: "x",
3425
+ to: "y",
3426
+ };
3427
+ let wrapped = Wrap::new(
3428
+ Arc::new(Tmpfs::default()),
3429
+ Arc::new(LinkAtL(Arc::new(link))),
3430
+ );
3431
+ let inner = Mount::new(
3432
+ "/data/inner",
3433
+ Filesystem::new(wrapped).expect("the instance must stand"),
3434
+ Access::ReadWrite,
3435
+ )
3436
+ .expect("/data/inner is a guest path");
3437
+ let outer_root = Path::root(outer.mnt());
3438
+ root.set(outer_root.clone()).ok().expect("set only here");
3439
+ let cred = crate::security::restrict_self(
3440
+ &Arc::default(),
3441
+ [
3442
+ &crate::grant::Grant::Mount(outer),
3443
+ &crate::grant::Grant::Mount(inner),
3444
+ ],
3445
+ )
3446
+ .expect("every mount stands");
3447
+ let during = vfs::vfs_fstatat(&cred, &outer_root, "inner/l/../y/c", false);
3448
+ let after = vfs::vfs_fstatat(&cred, &outer_root, "inner/../y/c", false);
3449
+ assert_eq!(
3450
+ (during.map(|_| ()), after.map(|stat| stat.size)),
3451
+ (Err(Errno::WouldBlock), Ok(5)),
3452
+ "a stat through a `..` out of a nested mount's root, with a move landing during \
3453
+ the walk, must answer EAGAIN, and made again reach where the moved directory stands"
3454
+ );
3455
+ }
3456
+
3457
+ /// A filesystem of `files` whose link `l` moves `from` to `to` through
3458
+ /// `moved`, which is set once that mount stands.
3459
+ fn moving_link_filesystem(
3460
+ files: &[(&'static str, &'static str)],
3461
+ moved: &Arc<OnceLock<Path>>,
3462
+ from: &'static str,
3463
+ to: &'static str,
3464
+ ) -> Arc<Filesystem> {
3465
+ let link = MovesWhenFollowed {
3466
+ cred: Arc::default(),
3467
+ root: moved.clone(),
3468
+ from,
3469
+ to,
3470
+ };
3471
+ let tmpfs: Tmpfs = files.iter().copied().collect();
3472
+ let wrapped = Wrap::new(Arc::new(tmpfs), Arc::new(LinkAtL(Arc::new(link))));
3473
+ Filesystem::new(wrapped).expect("the instance must stand")
3474
+ }
3475
+
3476
+ fn mount_at(path: &str, filesystem: &Arc<Filesystem>) -> Mount {
3477
+ Mount::new(path, filesystem.clone(), Access::ReadWrite).expect("a guest path")
3478
+ }
3479
+
3480
+ // @behavior RT-409
3481
+ #[test]
3482
+ fn a_dotdot_a_move_on_another_filesystem_landed_before_goes_on() {
3483
+ let elsewhere = mount_at(
3484
+ "/other",
3485
+ &Filesystem::new(Tmpfs::from_iter([("x/k", "k")])).unwrap(),
3486
+ );
3487
+ let moved = Arc::new(OnceLock::new());
3488
+ moved
3489
+ .set(Path::root(elsewhere.mnt()))
3490
+ .ok()
3491
+ .expect("set only here");
3492
+ let walked = mount_at(
3493
+ "/data",
3494
+ &moving_link_filesystem(&[("a/keep", "k"), ("c", "stays")], &moved, "x", "y"),
3495
+ );
3496
+ let stat = vfs::vfs_fstatat(
3497
+ &Arc::default(),
3498
+ &Path::root(walked.mnt()),
3499
+ "a/l/../c",
3500
+ false,
3501
+ );
3502
+ assert_eq!(
3503
+ stat.map(|stat| stat.size),
3504
+ Ok(5),
3505
+ "a stat through `..` with a move landing on another filesystem during the walk \
3506
+ must reach the file, since that move cannot carry any directory the walk stands in"
3507
+ );
3508
+ }
3509
+
3510
+ // A host app may mount one filesystem into two sandboxes; the move here goes
3511
+ // through a mount the walk never touches.
3512
+ // @behavior RT-240
3513
+ #[test]
3514
+ fn a_dotdot_a_move_through_another_mount_of_its_filesystem_landed_before_asks_again() {
3515
+ let moved = Arc::new(OnceLock::new());
3516
+ let shared = moving_link_filesystem(
3517
+ &[("a/keep", "k"), ("x/k", "k"), ("c", "stays")],
3518
+ &moved,
3519
+ "x",
3520
+ "y",
3521
+ );
3522
+ let other_sandbox = mount_at("/data", &shared);
3523
+ moved
3524
+ .set(Path::root(other_sandbox.mnt()))
3525
+ .ok()
3526
+ .expect("set only here");
3527
+ let walked = mount_at("/data", &shared);
3528
+ let stat = vfs::vfs_fstatat(
3529
+ &Arc::default(),
3530
+ &Path::root(walked.mnt()),
3531
+ "a/l/../c",
3532
+ false,
3533
+ );
3534
+ assert_eq!(
3535
+ stat.map(|_| ()),
3536
+ Err(Errno::WouldBlock),
3537
+ "a stat through `..` with a move landing through another mount of the same \
3538
+ filesystem during the walk must answer EAGAIN, as the move may carry its directories"
3539
+ );
3540
+ }
3541
+
3542
+ // `again` mounts the walk's own filesystem a second time, after the link moved
3543
+ // a directory of it, so only the `r_seq` kept for the first mount knows of the
3544
+ // move once the walk climbs back there.
3545
+ // @behavior RT-240
3546
+ #[test]
3547
+ fn a_dotdot_back_onto_a_filesystem_mounted_twice_learns_of_a_move_between() {
3548
+ let outer = Filesystem::new(Tmpfs::from_iter([("inner/keep", "k"), ("x/k", "k")])).unwrap();
3549
+ let moved = Arc::new(OnceLock::new());
3550
+ let inner = moving_link_filesystem(&[("again/keep", "k")], &moved, "x", "y");
3551
+ let mounts = [
3552
+ mount_at("/data", &outer),
3553
+ mount_at("/data/inner", &inner),
3554
+ mount_at("/data/inner/again", &outer),
3555
+ ];
3556
+ let outer_root = Path::root(mounts[0].mnt());
3557
+ moved.set(outer_root.clone()).ok().expect("set only here");
3558
+ let grants: Vec<_> = mounts.into_iter().map(crate::grant::Grant::Mount).collect();
3559
+ let cred = crate::security::restrict_self(&Arc::default(), grants.iter())
3560
+ .expect("every mount stands");
3561
+ let stat = vfs::vfs_fstatat(&cred, &outer_root, "inner/l/again/../../inner", false);
3562
+ assert_eq!(
3563
+ stat.map(|_| ()),
3564
+ Err(Errno::WouldBlock),
3565
+ "a stat through `..` back onto a filesystem mounted twice along the walk, with a \
3566
+ move on it landing between the two mounts, must answer EAGAIN"
3567
+ );
3568
+ }
3569
+
3570
+ // @behavior RT-410
3571
+ #[test]
3572
+ fn a_dotdot_out_of_the_walks_own_filesystem_mounted_again_climbs_back() {
3573
+ let outer =
3574
+ Filesystem::new(Tmpfs::from_iter([("m/keep", "k"), ("note", "the note")])).unwrap();
3575
+ let mounts = [mount_at("/data", &outer), mount_at("/data/m", &outer)];
3576
+ let outer_root = Path::root(mounts[0].mnt());
3577
+ let grants: Vec<_> = mounts.into_iter().map(crate::grant::Grant::Mount).collect();
3578
+ let cred = crate::security::restrict_self(&Arc::default(), grants.iter())
3579
+ .expect("every mount stands");
3580
+ let stat = vfs::vfs_fstatat(&cred, &outer_root, "m/../note", false);
3581
+ assert_eq!(
3582
+ stat.map(|stat| stat.size),
3583
+ Ok(8),
3584
+ "a stat of `m/../note` from a filesystem's root, with that filesystem mounted \
3585
+ again at `m`, must climb back out of `m` and reach `note`"
3586
+ );
3587
+ }
3588
+
3343
3589
  // @behavior RT-241
3344
3590
  #[test]
3345
3591
  fn a_walk_carried_out_from_under_its_start_answers_an_escape() {
@@ -3354,7 +3600,7 @@ mod tests {
3354
3600
  let ended = vfs::vfs_fstatat(&cred, start.path(), "b/l/k", false);
3355
3601
  assert_eq!(
3356
3602
  ended.err(),
3357
- Some(FilesystemError::Escape),
3603
+ Some(Errno::Escape),
3358
3604
  "vfs_fstatat ending on what a move carried out from under its start must \
3359
3605
  answer an escape, as complete_walk asks path_is_under"
3360
3606
  );
@@ -3383,10 +3629,7 @@ mod tests {
3383
3629
  let open = vfs::kern_path::filp_open(&cred, start().path(), "b/l/missing", &read);
3384
3630
  assert_eq!(
3385
3631
  (stat.err(), open.err()),
3386
- (
3387
- Some(FilesystemError::NotFound),
3388
- Some(FilesystemError::NotFound)
3389
- ),
3632
+ (Some(Errno::NotFound), Some(Errno::NotFound)),
3390
3633
  "vfs_fstatat and do_file_open of a name nothing stands at, through a directory a \
3391
3634
  move carried out from under the start, must answer ENOENT, as step_into does \
3392
3635
  before complete_walk"
@@ -3401,10 +3644,10 @@ mod tests {
3401
3644
  fn a_link_to_what_has_no_name_left_answers_enoent() {
3402
3645
  let answers = |names| {
3403
3646
  let linked = Arc::new(AtomicUsize::new(0));
3404
- let filesystem = Filesystem::new(Arc::new(LinksFile {
3647
+ let filesystem = Filesystem::new(LinksFile {
3405
3648
  names,
3406
3649
  linked: linked.clone(),
3407
- }))
3650
+ })
3408
3651
  .expect("the instance must stand");
3409
3652
  let root = root_of(filesystem);
3410
3653
  let answer =
@@ -3413,7 +3656,7 @@ mod tests {
3413
3656
  };
3414
3657
  assert_eq!(
3415
3658
  (answers(0), answers(1)),
3416
- ((Err(FilesystemError::NotFound), 0), (Ok(()), 1)),
3659
+ ((Err(Errno::NotFound), 0), (Ok(()), 1)),
3417
3660
  "vfs::filename_linkat of an entry reporting no names must answer ENOENT and ask for no \
3418
3661
  link, and of one reporting a name must make it"
3419
3662
  );
@@ -3426,9 +3669,8 @@ mod tests {
3426
3669
  #[test]
3427
3670
  fn a_change_asks_a_filesystem_once_for_the_name_it_makes() {
3428
3671
  let counts = Arc::new(CountsAsks::default());
3429
- let filesystem =
3430
- Filesystem::new(Arc::new(Wrap::new(Arc::new(Tmpfs::new()), counts.clone())))
3431
- .expect("the instance must stand");
3672
+ let filesystem = Filesystem::new(Wrap::new(Arc::new(Tmpfs::new()), counts.clone()))
3673
+ .expect("the instance must stand");
3432
3674
  let root = root_of(filesystem);
3433
3675
  let cred = Arc::default();
3434
3676
  let how = OpenHow {
@@ -3480,17 +3722,13 @@ mod tests {
3480
3722
  struct HookedDentry(Arc<AtomicBool>);
3481
3723
 
3482
3724
  impl DentryOperations for HookedDentry {
3483
- fn revalidate(
3484
- &self,
3485
- _dir: &dyn InodeOperations,
3486
- _dentry: &Dentry,
3487
- ) -> Result<bool, FilesystemError> {
3725
+ fn revalidate(&self, _dir: &dyn InodeOperations, _dentry: &Dentry) -> Result<bool, Errno> {
3488
3726
  Ok(!self.0.load(Ordering::SeqCst))
3489
3727
  }
3490
3728
  }
3491
3729
 
3492
3730
  impl FileSystemType for HookedTmpfs {
3493
- fn fill_super(self: Arc<Self>, sb: &mut Filesystem) -> Result<(), FilesystemError> {
3731
+ fn fill_super(self: Arc<Self>, sb: &mut Filesystem) -> Result<(), Errno> {
3494
3732
  sb.set_default_d_op(Arc::new(HookedDentry(self.stale.clone())));
3495
3733
  sb.d_make_root(vfs::Inode::new(
3496
3734
  &Kstat::new(crate::filesystem::FileType::Dir, 0),
@@ -3501,57 +3739,62 @@ mod tests {
3501
3739
  }
3502
3740
 
3503
3741
  impl InodeOperations for HookedTmpfs {
3504
- fn getattr(&self, dentry: &Dentry) -> Result<Kstat, FilesystemError> {
3742
+ fn getattr(&self, dentry: &Dentry) -> Result<Kstat, Errno> {
3505
3743
  self.tmpfs.getattr(dentry)
3506
3744
  }
3507
3745
 
3508
- fn lookup(&self, dentry: &Dentry) -> Result<Lookup, FilesystemError> {
3509
- self.tmpfs.lookup(dentry)
3746
+ /// Once stale, each name stands for another entry than the one it held,
3747
+ /// so what is found there reports an identity of its own.
3748
+ fn lookup(&self, dentry: &Dentry) -> Result<Lookup, Errno> {
3749
+ match self.tmpfs.lookup(dentry)? {
3750
+ Lookup::Found(inode) if self.stale.load(Ordering::SeqCst) => {
3751
+ let replaced =
3752
+ Kstat::new(inode.file_type(), 0).with_identity(u64::MAX, u64::MAX);
3753
+ Ok(Lookup::Found(Inode::new(&replaced, inode.ops().clone())))
3754
+ }
3755
+ found => Ok(found),
3756
+ }
3510
3757
  }
3511
3758
 
3512
- fn create(&self, dentry: &Dentry) -> Result<(), FilesystemError> {
3759
+ fn create(&self, dentry: &Dentry) -> Result<(), Errno> {
3513
3760
  self.tmpfs.create(dentry)
3514
3761
  }
3515
3762
 
3516
- fn open(
3517
- &self,
3518
- dentry: &Dentry,
3519
- how: &OpenHow,
3520
- ) -> Result<Box<dyn FileOperations>, FilesystemError> {
3763
+ fn open(&self, dentry: &Dentry, how: &OpenHow) -> Result<Box<dyn FileOperations>, Errno> {
3521
3764
  self.tmpfs.open(dentry, how)
3522
3765
  }
3523
3766
 
3524
- fn mkdir(&self, dentry: &Dentry) -> Result<(), FilesystemError> {
3767
+ fn mkdir(&self, dentry: &Dentry) -> Result<(), Errno> {
3525
3768
  match &self.making {
3526
3769
  Some(making) => making(),
3527
3770
  None => self.tmpfs.mkdir(dentry),
3528
3771
  }
3529
3772
  }
3530
3773
 
3531
- fn rmdir(&self, dentry: &Dentry) -> Result<(), FilesystemError> {
3774
+ fn rmdir(&self, dentry: &Dentry) -> Result<(), Errno> {
3532
3775
  self.tmpfs.rmdir(dentry)?;
3533
3776
  self.removed.as_ref().map_or(Ok(()), |removed| removed())
3534
3777
  }
3535
3778
 
3536
- fn unlink(&self, dentry: &Dentry) -> Result<(), FilesystemError> {
3779
+ fn unlink(&self, dentry: &Dentry) -> Result<(), Errno> {
3537
3780
  self.tmpfs.unlink(dentry)
3538
3781
  }
3539
3782
 
3540
3783
  fn rename(
3541
3784
  &self,
3542
- from: &Dentry,
3543
- to_dir: &dyn InodeOperations,
3544
- to: &Dentry,
3545
- flag: Option<RenameFlag>,
3546
- ) -> Result<(), FilesystemError> {
3785
+ old: &Dentry,
3786
+ new_dir: &dyn InodeOperations,
3787
+ new: &Dentry,
3788
+ flags: Option<RenameFlag>,
3789
+ ) -> Result<(), Errno> {
3547
3790
  self.renames.fetch_add(1, Ordering::SeqCst);
3548
3791
  if let Some(renaming) = &self.renaming {
3549
3792
  renaming()?;
3550
3793
  }
3551
- let to_dir = (to_dir as &dyn std::any::Any)
3794
+ let new_dir = (new_dir as &dyn std::any::Any)
3552
3795
  .downcast_ref::<Self>()
3553
- .map_or(to_dir, |hooked| &hooked.tmpfs);
3554
- self.tmpfs.rename(from, to_dir, to, flag)
3796
+ .map_or(new_dir, |hooked| &hooked.tmpfs);
3797
+ self.tmpfs.rename(old, new_dir, new, flags)
3555
3798
  }
3556
3799
  }
3557
3800
 
@@ -3573,21 +3816,25 @@ mod tests {
3573
3816
  struct FoldedDir(KernPath);
3574
3817
 
3575
3818
  impl FileOperations for FoldedDir {
3819
+ fn has_iterate_shared(&self) -> bool {
3820
+ true
3821
+ }
3822
+
3576
3823
  fn iterate_shared(
3577
3824
  &mut self,
3578
3825
  dentry: &Dentry,
3579
3826
  ctx: &mut vfs::DirContext<'_>,
3580
- ) -> Result<(), FilesystemError> {
3827
+ ) -> Result<(), Errno> {
3581
3828
  let entries = match folded_path_of(dentry).as_str() {
3582
3829
  "" => self.0.iterate_dir(),
3583
3830
  at => self.0.open_dir(at)?.iterate_dir(),
3584
3831
  }?;
3585
- crate::filesystem::Rdir::default().iterate(dentry, ctx, || Ok(entries))
3832
+ crate::filesystem::Rdir::default().iterate_shared(dentry, ctx, || Ok(entries))
3586
3833
  }
3587
3834
  }
3588
3835
 
3589
3836
  impl FileSystemType for FoldsToUpper {
3590
- fn fill_super(self: Arc<Self>, sb: &mut Filesystem) -> Result<(), FilesystemError> {
3837
+ fn fill_super(self: Arc<Self>, sb: &mut Filesystem) -> Result<(), Errno> {
3591
3838
  sb.d_make_root(vfs::Inode::new(
3592
3839
  &Kstat::new(crate::filesystem::FileType::Dir, 0),
3593
3840
  self,
@@ -3597,11 +3844,11 @@ mod tests {
3597
3844
  }
3598
3845
 
3599
3846
  impl InodeOperations for FoldsToUpper {
3600
- fn getattr(&self, dentry: &Dentry) -> Result<Kstat, FilesystemError> {
3847
+ fn getattr(&self, dentry: &Dentry) -> Result<Kstat, Errno> {
3601
3848
  self.root.vfs_lstat(&folded_path_of(dentry))
3602
3849
  }
3603
3850
 
3604
- fn lookup(&self, dentry: &Dentry) -> Result<Lookup, FilesystemError> {
3851
+ fn lookup(&self, dentry: &Dentry) -> Result<Lookup, Errno> {
3605
3852
  let name = dentry.name();
3606
3853
  let upper = name.to_uppercase();
3607
3854
  match self.root.vfs_lstat(&folded_path_of(dentry)) {
@@ -3610,23 +3857,19 @@ mod tests {
3610
3857
  inode: Inode::new(&found, Arc::new(self.clone())),
3611
3858
  }),
3612
3859
  Ok(found) => Ok(Lookup::Found(Inode::new(&found, Arc::new(self.clone())))),
3613
- Err(FilesystemError::NotFound) => Ok(Lookup::Absent),
3860
+ Err(Errno::NotFound) => Ok(Lookup::Absent),
3614
3861
  Err(err) => Err(err),
3615
3862
  }
3616
3863
  }
3617
3864
 
3618
- fn open(
3619
- &self,
3620
- dentry: &Dentry,
3621
- how: &OpenHow,
3622
- ) -> Result<Box<dyn FileOperations>, FilesystemError> {
3623
- if dentry.kind() == Ok(crate::filesystem::FileType::Dir) {
3865
+ fn open(&self, dentry: &Dentry, how: &OpenHow) -> Result<Box<dyn FileOperations>, Errno> {
3866
+ if dentry.file_type() == Ok(crate::filesystem::FileType::Dir) {
3624
3867
  return Ok(Box::new(FoldedDir(self.root.clone())));
3625
3868
  }
3626
3869
  self.root.open(&folded_path_of(dentry), how)
3627
3870
  }
3628
3871
 
3629
- fn atomic_open(&self, dentry: &Dentry, how: &OpenHow) -> Result<Finish, FilesystemError> {
3872
+ fn atomic_open(&self, dentry: &Dentry, how: &OpenHow) -> Result<Finish, Errno> {
3630
3873
  if dentry.in_lookup() {
3631
3874
  let found = self.lookup(dentry)?;
3632
3875
  if !how.create || !matches!(found, Lookup::Absent) {
@@ -3643,28 +3886,28 @@ mod tests {
3643
3886
  })
3644
3887
  }
3645
3888
 
3646
- fn mkdir(&self, dentry: &Dentry) -> Result<(), FilesystemError> {
3889
+ fn mkdir(&self, dentry: &Dentry) -> Result<(), Errno> {
3647
3890
  self.root.vfs_mkdir(&folded_path_of(dentry))
3648
3891
  }
3649
3892
 
3650
- fn rmdir(&self, dentry: &Dentry) -> Result<(), FilesystemError> {
3893
+ fn rmdir(&self, dentry: &Dentry) -> Result<(), Errno> {
3651
3894
  self.root.vfs_rmdir(&folded_path_of(dentry))
3652
3895
  }
3653
3896
 
3654
- fn unlink(&self, dentry: &Dentry) -> Result<(), FilesystemError> {
3897
+ fn unlink(&self, dentry: &Dentry) -> Result<(), Errno> {
3655
3898
  self.root.vfs_unlink(&folded_path_of(dentry))
3656
3899
  }
3657
3900
 
3658
3901
  fn rename(
3659
3902
  &self,
3660
- from: &Dentry,
3661
- _to_dir: &dyn InodeOperations,
3662
- to: &Dentry,
3663
- _flag: Option<RenameFlag>,
3664
- ) -> Result<(), FilesystemError> {
3903
+ old: &Dentry,
3904
+ _new_dir: &dyn InodeOperations,
3905
+ new: &Dentry,
3906
+ _flags: Option<RenameFlag>,
3907
+ ) -> Result<(), Errno> {
3665
3908
  (self.renaming)()?;
3666
3909
  self.root
3667
- .rename(&folded_path_of(from), &self.root, &folded_path_of(to))
3910
+ .rename(&folded_path_of(old), &self.root, &folded_path_of(new))
3668
3911
  }
3669
3912
  }
3670
3913
 
@@ -3673,7 +3916,7 @@ mod tests {
3673
3916
  struct OpensItsLinks(Arc<AtomicUsize>);
3674
3917
 
3675
3918
  impl FileSystemType for OpensItsLinks {
3676
- fn fill_super(self: Arc<Self>, sb: &mut Filesystem) -> Result<(), FilesystemError> {
3919
+ fn fill_super(self: Arc<Self>, sb: &mut Filesystem) -> Result<(), Errno> {
3677
3920
  sb.d_make_root(vfs::Inode::new(
3678
3921
  &Kstat::new(crate::filesystem::FileType::Dir, 0),
3679
3922
  self,
@@ -3683,21 +3926,17 @@ mod tests {
3683
3926
  }
3684
3927
 
3685
3928
  impl InodeOperations for OpensItsLinks {
3686
- fn getattr(&self, _dentry: &Dentry) -> Result<Kstat, FilesystemError> {
3929
+ fn getattr(&self, _dentry: &Dentry) -> Result<Kstat, Errno> {
3687
3930
  Ok(Kstat::new(crate::filesystem::FileType::Symlink, 0))
3688
3931
  }
3689
3932
 
3690
- fn lookup(&self, _dentry: &Dentry) -> Result<Lookup, FilesystemError> {
3933
+ fn lookup(&self, _dentry: &Dentry) -> Result<Lookup, Errno> {
3691
3934
  let link = Kstat::new(crate::filesystem::FileType::Symlink, 0);
3692
3935
  let ops = Arc::new(Self(self.0.clone()));
3693
3936
  Ok(Lookup::Found(Inode::new(&link, ops)))
3694
3937
  }
3695
3938
 
3696
- fn open(
3697
- &self,
3698
- _dentry: &Dentry,
3699
- _how: &OpenHow,
3700
- ) -> Result<Box<dyn FileOperations>, FilesystemError> {
3939
+ fn open(&self, _dentry: &Dentry, _how: &OpenHow) -> Result<Box<dyn FileOperations>, Errno> {
3701
3940
  struct OpenLink;
3702
3941
  impl FileOperations for OpenLink {}
3703
3942
  self.0.fetch_add(1, Ordering::SeqCst);
@@ -3709,23 +3948,21 @@ mod tests {
3709
3948
  // it shows the VFS is what holds this line for every third party.
3710
3949
  /// What each call answers beneath a mount `prepare` finishes, over a
3711
3950
  /// Tmpfs holding the directory `dir`.
3712
- fn answers(
3713
- prepare: impl Fn(Mount) -> Mount,
3714
- access: Access,
3715
- ) -> [Result<(), FilesystemError>; 3] {
3951
+ fn answers(prepare: impl Fn(Mount) -> Mount, access: Access) -> [Result<(), Errno>; 3] {
3716
3952
  let tmpfs: Tmpfs = [("dir/file", "x")].into_iter().collect();
3717
3953
  let mount = prepare(
3718
3954
  Mount::new(
3719
3955
  "/data",
3720
- Filesystem::new(Arc::new(tmpfs)).expect("the instance must stand"),
3956
+ Filesystem::new(tmpfs).expect("the instance must stand"),
3721
3957
  access,
3722
3958
  )
3723
3959
  .expect("/data is a guest path"),
3724
3960
  );
3725
3961
  let cred = crate::security::restrict_self(
3726
- &crate::security::prepare_creds_within(&[], None),
3727
- [&mount],
3728
- );
3962
+ &crate::security::prepare_creds(&[], None),
3963
+ [&crate::grant::Grant::Mount(mount.clone())],
3964
+ )
3965
+ .expect("every mount stands");
3729
3966
  let root = Path::root(mount.mnt());
3730
3967
  [
3731
3968
  vfs::filename_mkdirat(&cred, &root, "dir"),
@@ -3736,8 +3973,8 @@ mod tests {
3736
3973
 
3737
3974
  struct RefusesAll;
3738
3975
 
3739
- impl Policy for RefusesAll {
3740
- fn allows(&self, _path: &str, _access: Access) -> bool {
3976
+ impl Policy<MountRequest<'_>> for RefusesAll {
3977
+ fn allows(&self, _request: &MountRequest<'_>) -> bool {
3741
3978
  false
3742
3979
  }
3743
3980
  }
@@ -3750,9 +3987,9 @@ mod tests {
3750
3987
  assert_eq!(
3751
3988
  answers(|mount| mount, Access::Read),
3752
3989
  [
3753
- Err(FilesystemError::AlreadyExists),
3754
- Err(FilesystemError::ReadOnlyFilesystem),
3755
- Err(FilesystemError::ReadOnlyFilesystem),
3990
+ Err(Errno::AlreadyExists),
3991
+ Err(Errno::ReadOnlyFilesystem),
3992
+ Err(Errno::ReadOnlyFilesystem),
3756
3993
  ],
3757
3994
  "vfs::filename_mkdirat of what stands beneath a read-only Mount must answer EEXIST, \
3758
3995
  and vfs::filename_rmdir and filename_unlinkat of what does not EROFS"
@@ -3768,9 +4005,9 @@ mod tests {
3768
4005
  Access::ReadWrite
3769
4006
  ),
3770
4007
  [
3771
- Err(FilesystemError::AlreadyExists),
3772
- Err(FilesystemError::NotFound),
3773
- Err(FilesystemError::NotFound),
4008
+ Err(Errno::AlreadyExists),
4009
+ Err(Errno::NotFound),
4010
+ Err(Errno::NotFound),
3774
4011
  ],
3775
4012
  "vfs::filename_mkdirat of what stands, and vfs::filename_rmdir and filename_unlinkat \
3776
4013
  of what does not, beneath a Policy refusing everything, must answer as \
@@ -3784,7 +4021,7 @@ mod tests {
3784
4021
  let mount = |tmpfs: Tmpfs| {
3785
4022
  Mount::new(
3786
4023
  "/data",
3787
- Filesystem::new(Arc::new(tmpfs)).expect("the instance must stand"),
4024
+ Filesystem::new(tmpfs).expect("the instance must stand"),
3788
4025
  Access::ReadWrite,
3789
4026
  )
3790
4027
  .expect("/data is a guest path")
@@ -3798,7 +4035,7 @@ mod tests {
3798
4035
  &Path::root(second.mnt()),
3799
4036
  "moved"
3800
4037
  ),
3801
- Err(FilesystemError::CrossesDevices),
4038
+ Err(Errno::CrossesDevices),
3802
4039
  "vfs::filename_renameat2 of `.` to another Mount must answer EXDEV, as \
3803
4040
  filename_renameat2 answers a move across mounts first"
3804
4041
  );
@@ -3809,7 +4046,7 @@ mod tests {
3809
4046
  struct OneEntry(Arc<AtomicUsize>);
3810
4047
 
3811
4048
  impl FileSystemType for OneEntry {
3812
- fn fill_super(self: Arc<Self>, sb: &mut Filesystem) -> Result<(), FilesystemError> {
4049
+ fn fill_super(self: Arc<Self>, sb: &mut Filesystem) -> Result<(), Errno> {
3813
4050
  sb.d_make_root(vfs::Inode::new(
3814
4051
  &Kstat::new(crate::filesystem::FileType::Dir, 0),
3815
4052
  self,
@@ -3819,11 +4056,11 @@ mod tests {
3819
4056
  }
3820
4057
 
3821
4058
  impl InodeOperations for OneEntry {
3822
- fn getattr(&self, _dentry: &Dentry) -> Result<Kstat, FilesystemError> {
4059
+ fn getattr(&self, _dentry: &Dentry) -> Result<Kstat, Errno> {
3823
4060
  Ok(Kstat::new(crate::filesystem::FileType::Dir, 0))
3824
4061
  }
3825
4062
 
3826
- fn lookup(&self, _dentry: &Dentry) -> Result<Lookup, FilesystemError> {
4063
+ fn lookup(&self, _dentry: &Dentry) -> Result<Lookup, Errno> {
3827
4064
  let entry = Kstat::new(crate::filesystem::FileType::RegFile, 0).with_identity(1, 2);
3828
4065
  Ok(Lookup::Found(Inode::new(
3829
4066
  &entry,
@@ -3833,11 +4070,11 @@ mod tests {
3833
4070
 
3834
4071
  fn rename(
3835
4072
  &self,
3836
- _from: &Dentry,
3837
- _to_dir: &dyn InodeOperations,
3838
- _to: &Dentry,
3839
- _flag: Option<RenameFlag>,
3840
- ) -> Result<(), FilesystemError> {
4073
+ _old: &Dentry,
4074
+ _new_dir: &dyn InodeOperations,
4075
+ _new: &Dentry,
4076
+ _flags: Option<RenameFlag>,
4077
+ ) -> Result<(), Errno> {
3841
4078
  self.0.fetch_add(1, Ordering::SeqCst);
3842
4079
  Ok(())
3843
4080
  }
@@ -3847,9 +4084,8 @@ mod tests {
3847
4084
  #[test]
3848
4085
  fn a_move_between_two_names_of_one_entry_changes_nothing() {
3849
4086
  let moves = Arc::new(AtomicUsize::new(0));
3850
- let root = root_of(
3851
- Filesystem::new(Arc::new(OneEntry(moves.clone()))).expect("the instance must stand"),
3852
- );
4087
+ let root =
4088
+ root_of(Filesystem::new(OneEntry(moves.clone())).expect("the instance must stand"));
3853
4089
  assert_eq!(
3854
4090
  (
3855
4091
  vfs::filename_renameat2(&Arc::default(), &root, "a", &root, "b"),
@@ -3869,21 +4105,24 @@ mod tests {
3869
4105
  let tmpfs: Tmpfs = [("file", "x")].into_iter().collect();
3870
4106
  let plain = Mount::new(
3871
4107
  "/data",
3872
- Filesystem::new(Arc::new(tmpfs)).expect("the instance must stand"),
4108
+ Filesystem::new(tmpfs).expect("the instance must stand"),
3873
4109
  Access::ReadWrite,
3874
4110
  )
3875
4111
  .expect("/data is a guest path");
3876
4112
  let links = Mount::new(
3877
4113
  "/data",
3878
- Filesystem::new(Arc::new(OpensItsLinks(Arc::default())))
3879
- .expect("the instance must stand"),
4114
+ Filesystem::new(OpensItsLinks(Arc::default())).expect("the instance must stand"),
3880
4115
  Access::ReadWrite,
3881
4116
  )
3882
4117
  .expect("/data is a guest path");
3883
4118
  let cred = crate::security::restrict_self(
3884
- &crate::security::prepare_creds_within(&[], None),
3885
- [&plain, &links],
3886
- );
4119
+ &crate::security::prepare_creds(&[], None),
4120
+ [
4121
+ &crate::grant::Grant::Mount(plain.clone()),
4122
+ &crate::grant::Grant::Mount(links.clone()),
4123
+ ],
4124
+ )
4125
+ .expect("every mount stands");
3887
4126
  let (plain, links) = (Path::root(plain.mnt()), Path::root(links.mnt()));
3888
4127
  assert_eq!(
3889
4128
  (
@@ -3892,9 +4131,9 @@ mod tests {
3892
4131
  vfs::do_readlinkat(&cred, &links, "link"),
3893
4132
  ),
3894
4133
  (
3895
- Err(FilesystemError::NotFound),
3896
- Err(FilesystemError::InvalidInput),
3897
- Err(FilesystemError::Unsupported),
4134
+ Err(Errno::NotFound),
4135
+ Err(Errno::InvalidInput),
4136
+ Err(Errno::Unsupported),
3898
4137
  ),
3899
4138
  "vfs::do_readlinkat must answer ENOENT for what does not stand, EINVAL for what is no \
3900
4139
  link, and only a link what the security hook answers"
@@ -3906,8 +4145,7 @@ mod tests {
3906
4145
  fn an_open_refuses_a_link_before_its_filesystem_is_asked() {
3907
4146
  let asked = Arc::new(AtomicUsize::new(0));
3908
4147
  let root = root_of(
3909
- Filesystem::new(Arc::new(OpensItsLinks(asked.clone())))
3910
- .expect("the instance must stand"),
4148
+ Filesystem::new(OpensItsLinks(asked.clone())).expect("the instance must stand"),
3911
4149
  );
3912
4150
  let read = OpenHow {
3913
4151
  read: true,
@@ -3916,7 +4154,7 @@ mod tests {
3916
4154
  let answer = vfs::kern_path::filp_open(&Arc::default(), &root, "link", &read);
3917
4155
  assert_eq!(
3918
4156
  (answer.err(), asked.load(Ordering::SeqCst)),
3919
- (Some(FilesystemError::FilesystemLoop), 0),
4157
+ (Some(Errno::FilesystemLoop), 0),
3920
4158
  "vfs::do_file_open of a link to read following none, over a Filesystem that would \
3921
4159
  open it, must answer ELOOP and leave the Filesystem unasked"
3922
4160
  );
@@ -3927,8 +4165,7 @@ mod tests {
3927
4165
  fn an_open_standing_for_a_path_opens_nothing() {
3928
4166
  let asked = Arc::new(AtomicUsize::new(0));
3929
4167
  let root = root_of(
3930
- Filesystem::new(Arc::new(OpensItsLinks(asked.clone())))
3931
- .expect("the instance must stand"),
4168
+ Filesystem::new(OpensItsLinks(asked.clone())).expect("the instance must stand"),
3932
4169
  );
3933
4170
  let answer = vfs::kern_path::filp_open(&Arc::default(), &root, "link", &OpenHow::default());
3934
4171
  assert_eq!(
@@ -3972,23 +4209,21 @@ mod tests {
3972
4209
  fn an_entry_neither_file_nor_directory_opens_as_access_denied() {
3973
4210
  let tmpfs = Tmpfs::new();
3974
4211
  tmpfs.whiteout("w").expect("the whiteout must be made");
3975
- let root = root_of(Filesystem::new(Arc::new(tmpfs)).expect("the instance must stand"));
4212
+ let root = root_of(Filesystem::new(tmpfs).expect("the instance must stand"));
3976
4213
  let how = OpenHow {
3977
4214
  read: true,
3978
4215
  ..OpenHow::default()
3979
4216
  };
3980
4217
  assert_eq!(
3981
4218
  vfs::kern_path::filp_open(
3982
- &crate::security::restrict_self(
3983
- &crate::security::prepare_creds_within(&[], None),
3984
- []
3985
- ),
4219
+ &crate::security::restrict_self(&crate::security::prepare_creds(&[], None), [])
4220
+ .expect("every mount stands"),
3986
4221
  &root,
3987
4222
  "w",
3988
4223
  &how
3989
4224
  )
3990
4225
  .err(),
3991
- Some(FilesystemError::PermissionDenied),
4226
+ Some(Errno::PermissionDenied),
3992
4227
  "a character device through vfs::do_file_open must answer PermissionDenied"
3993
4228
  );
3994
4229
  }
@@ -4016,21 +4251,23 @@ mod tests {
4016
4251
 
4017
4252
  #[test]
4018
4253
  fn a_directory_made_while_another_is_removed_in_its_place_stays_alive() {
4254
+ let counts = count_waits();
4019
4255
  let (removed, removing) = mpsc::channel();
4020
4256
  let (made, making) = mpsc::channel::<()>();
4021
4257
  let (removed, making) = (Mutex::new(removed), Mutex::new(making));
4022
4258
  let hooked = HookedTmpfs {
4023
4259
  removed: Some(Box::new(move || {
4024
4260
  removed.lock().expect("unpoisoned").send(()).ok();
4025
- let _ = making
4026
- .lock()
4027
- .expect("unpoisoned")
4028
- .recv_timeout(Duration::from_millis(200));
4261
+ let making = making.lock().expect("unpoisoned");
4262
+ crate::sched::testing::wait_until(
4263
+ "the make waiting for the removal, or made",
4264
+ || counts.load(Ordering::SeqCst) > 0 || making.try_recv().is_ok(),
4265
+ );
4029
4266
  Ok(())
4030
4267
  })),
4031
4268
  ..HookedTmpfs::default()
4032
4269
  };
4033
- let root = root_of(Filesystem::new(Arc::new(hooked)).expect("the instance must stand"));
4270
+ let root = root_of(Filesystem::new(hooked).expect("the instance must stand"));
4034
4271
  vfs::filename_mkdirat(&Arc::default(), &root, "d").expect("the directory must be made");
4035
4272
  let remover = {
4036
4273
  let root = root.clone();
@@ -4053,22 +4290,27 @@ mod tests {
4053
4290
  }
4054
4291
 
4055
4292
  /// A Policy allowing everything that holds its first answer until the
4056
- /// test lets it go, or a short while passes.
4293
+ /// removal waits through the `Blocking`, as `waits` counts, or lands.
4057
4294
  struct PausesFirst {
4058
4295
  answered: AtomicBool,
4059
4296
  reached: Mutex<mpsc::Sender<()>>,
4060
- resume: Mutex<mpsc::Receiver<()>>,
4297
+ waits: Arc<OnceLock<Arc<AtomicUsize>>>,
4298
+ removed: Arc<AtomicBool>,
4061
4299
  }
4062
4300
 
4063
- impl Policy for PausesFirst {
4064
- fn allows(&self, _path: &str, _access: Access) -> bool {
4301
+ impl Policy<MountRequest<'_>> for PausesFirst {
4302
+ fn allows(&self, _request: &MountRequest<'_>) -> bool {
4065
4303
  if !self.answered.swap(true, Ordering::SeqCst) {
4066
4304
  self.reached.lock().expect("unpoisoned").send(()).ok();
4067
- let _ = self
4068
- .resume
4069
- .lock()
4070
- .expect("unpoisoned")
4071
- .recv_timeout(Duration::from_millis(200));
4305
+ crate::sched::testing::wait_until(
4306
+ "the removal waiting for the open, or landing",
4307
+ || {
4308
+ self.waits
4309
+ .get()
4310
+ .is_some_and(|waits| waits.load(Ordering::SeqCst) > 0)
4311
+ || self.removed.load(Ordering::SeqCst)
4312
+ },
4313
+ );
4072
4314
  }
4073
4315
  true
4074
4316
  }
@@ -4081,25 +4323,27 @@ mod tests {
4081
4323
  #[test]
4082
4324
  fn a_create_opens_the_file_it_finds_or_makes_one() {
4083
4325
  let (reached, reaching) = mpsc::channel();
4084
- let (removed, resume) = mpsc::channel();
4326
+ let (waits, removed) = (Arc::<OnceLock<_>>::default(), Arc::<AtomicBool>::default());
4085
4327
  let policy = PausesFirst {
4086
4328
  answered: AtomicBool::new(false),
4087
4329
  reached: Mutex::new(reached),
4088
- resume: Mutex::new(resume),
4330
+ waits: waits.clone(),
4331
+ removed: removed.clone(),
4089
4332
  };
4090
4333
  let tmpfs: Tmpfs = [("f", "x")].into_iter().collect();
4091
4334
  let mount = Mount::new(
4092
4335
  "/data",
4093
- Filesystem::new(Arc::new(tmpfs)).expect("the instance must stand"),
4336
+ Filesystem::new(tmpfs).expect("the instance must stand"),
4094
4337
  Access::ReadWrite,
4095
4338
  )
4096
4339
  .expect("/data is a guest path")
4097
4340
  .with_policy(Arc::new(policy));
4098
4341
  let root = Path::root(mount.mnt());
4099
4342
  let cred = crate::security::restrict_self(
4100
- &crate::security::prepare_creds_within(&[], None),
4101
- [&mount],
4102
- );
4343
+ &crate::security::prepare_creds(&[], None),
4344
+ [&crate::grant::Grant::Mount(mount.clone())],
4345
+ )
4346
+ .expect("every mount stands");
4103
4347
  let opener = {
4104
4348
  let (root, cred) = (root.clone(), cred.clone());
4105
4349
  thread::spawn(move || {
@@ -4115,8 +4359,9 @@ mod tests {
4115
4359
  .recv_timeout(crate::sched::testing::MAX_WAIT)
4116
4360
  .expect("the open must reach the Policy");
4117
4361
  let remover = thread::spawn(move || {
4362
+ let _ = waits.set(count_waits());
4118
4363
  let answer = vfs::filename_unlinkat(&cred, &root, "f");
4119
- removed.send(()).ok();
4364
+ removed.store(true, Ordering::SeqCst);
4120
4365
  answer
4121
4366
  });
4122
4367
  let opened = crate::sched::testing::join("the open", opener);
@@ -4145,7 +4390,7 @@ mod tests {
4145
4390
  hooked.renames.load(Ordering::SeqCst)
4146
4391
  ),
4147
4392
  (
4148
- Err(FilesystemError::InvalidInput),
4393
+ Err(Errno::InvalidInput),
4149
4394
  0
4150
4395
  ),
4151
4396
  "vfs::filename_renameat2 of a directory into a directory beneath it must answer InvalidInput \
@@ -4171,11 +4416,11 @@ mod tests {
4171
4416
  })),
4172
4417
  ..HookedTmpfs::default()
4173
4418
  };
4174
- let path = root_of(Filesystem::new(Arc::new(hooked)).expect("the instance must stand"));
4419
+ let path = root_of(Filesystem::new(hooked).expect("the instance must stand"));
4175
4420
  root.set(path.clone()).ok();
4176
4421
  assert_eq!(
4177
4422
  vfs::filename_mkdirat(&Arc::default(), &path, "made"),
4178
- Err(FilesystemError::Deadlock),
4423
+ Err(Errno::Deadlock),
4179
4424
  "vfs::filename_mkdirat called by a Filesystem's own create_dir on the directory the outer \
4180
4425
  vfs::filename_mkdirat holds must answer Deadlock"
4181
4426
  );
@@ -4197,11 +4442,11 @@ mod tests {
4197
4442
  })),
4198
4443
  ..HookedTmpfs::default()
4199
4444
  };
4200
- let path = root_of(Filesystem::new(Arc::new(hooked)).expect("the instance must stand"));
4445
+ let path = root_of(Filesystem::new(hooked).expect("the instance must stand"));
4201
4446
  root.set(path.clone()).ok();
4202
4447
  assert_eq!(
4203
4448
  vfs::filename_mkdirat(&Arc::default(), &path, "made"),
4204
- Err(FilesystemError::Deadlock),
4449
+ Err(Errno::Deadlock),
4205
4450
  "vfs::vfs_fstatat walking through the directory an outer vfs::filename_mkdirat holds \
4206
4451
  must answer Deadlock, as it holds that directory to find the name"
4207
4452
  );
@@ -4225,7 +4470,7 @@ mod tests {
4225
4470
  })),
4226
4471
  ..HookedTmpfs::default()
4227
4472
  };
4228
- let path = root_of(Filesystem::new(Arc::new(hooked)).expect("the instance must stand"));
4473
+ let path = root_of(Filesystem::new(hooked).expect("the instance must stand"));
4229
4474
  let kept = open_dir(&path, "kept");
4230
4475
  root.set(path.clone()).ok();
4231
4476
  assert_eq!(
@@ -4255,18 +4500,15 @@ mod tests {
4255
4500
  renamed.lock().expect("unpoisoned").send(()).ok();
4256
4501
  // Bounded, so a make that never waits fails the assertion
4257
4502
  // rather than hanging the test.
4258
- for _ in 0..2000 {
4259
- if counts.load(Ordering::SeqCst) > 0 {
4260
- break;
4261
- }
4262
- thread::sleep(Duration::from_millis(1));
4263
- }
4503
+ crate::sched::testing::holds_within_max_wait(|| {
4504
+ counts.load(Ordering::SeqCst) > 0
4505
+ });
4264
4506
  Ok(())
4265
4507
  }
4266
4508
  })),
4267
4509
  ..HookedTmpfs::default()
4268
4510
  };
4269
- let root = root_of(Filesystem::new(Arc::new(hooked)).expect("the instance must stand"));
4511
+ let root = root_of(Filesystem::new(hooked).expect("the instance must stand"));
4270
4512
  vfs::filename_mkdirat(&Arc::default(), &root, "b").expect("the directory must be made");
4271
4513
  let replaced = open_dir(&root, "b");
4272
4514
  let mover = {
@@ -4282,7 +4524,7 @@ mod tests {
4282
4524
  let moved = crate::sched::testing::join("the mover", mover);
4283
4525
  assert_eq!(
4284
4526
  (made, moved),
4285
- (Err(FilesystemError::NotFound), Ok(())),
4527
+ (Err(Errno::NotFound), Ok(())),
4286
4528
  "vfs::filename_mkdirat through a directory vfs::filename_renameat2 is replacing must \
4287
4529
  wait for the move, answer NotFound, and leave the move to succeed"
4288
4530
  );
@@ -4301,18 +4543,15 @@ mod tests {
4301
4543
  removed.lock().expect("unpoisoned").send(()).ok();
4302
4544
  // Bounded, so a call that never waits fails the count
4303
4545
  // rather than hanging the test.
4304
- for _ in 0..2000 {
4305
- if counts.load(Ordering::SeqCst) > 0 {
4306
- break;
4307
- }
4308
- thread::sleep(Duration::from_millis(1));
4309
- }
4546
+ crate::sched::testing::holds_within_max_wait(|| {
4547
+ counts.load(Ordering::SeqCst) > 0
4548
+ });
4310
4549
  Ok(())
4311
4550
  }
4312
4551
  })),
4313
4552
  ..HookedTmpfs::default()
4314
4553
  };
4315
- let root = root_of(Filesystem::new(Arc::new(hooked)).expect("the instance must stand"));
4554
+ let root = root_of(Filesystem::new(hooked).expect("the instance must stand"));
4316
4555
  vfs::filename_mkdirat(&Arc::default(), &root, "d").expect("the directory must be made");
4317
4556
  let remover = {
4318
4557
  let root = root.clone();
@@ -4346,12 +4585,7 @@ mod tests {
4346
4585
  reached.lock().expect("unpoisoned").send(()).ok();
4347
4586
  // Bounded, so a removal that never waits fails the count
4348
4587
  // rather than hanging the test.
4349
- for _ in 0..2000 {
4350
- if counts.load(Ordering::SeqCst) > 0 {
4351
- break;
4352
- }
4353
- thread::sleep(Duration::from_millis(1));
4354
- }
4588
+ crate::sched::testing::holds_within_max_wait(|| counts.load(Ordering::SeqCst) > 0);
4355
4589
  Ok(())
4356
4590
  }
4357
4591
  }));
@@ -4360,7 +4594,7 @@ mod tests {
4360
4594
  root: kern_path(Arc::new(tmpfs)),
4361
4595
  renaming,
4362
4596
  };
4363
- let root = root_of(Filesystem::new(Arc::new(folds)).expect("the instance must stand"));
4597
+ let root = root_of(Filesystem::new(folds).expect("the instance must stand"));
4364
4598
  let mover = {
4365
4599
  let root = root.clone();
4366
4600
  thread::spawn(move || {
@@ -4378,7 +4612,7 @@ mod tests {
4378
4612
  (moved, removed, counts.load(Ordering::SeqCst) > 0),
4379
4613
  (
4380
4614
  Ok(()),
4381
- Err(FilesystemError::NotFound),
4615
+ Err(Errno::NotFound),
4382
4616
  true
4383
4617
  ),
4384
4618
  "vfs::filename_unlinkat of `DIR/F` while vfs::filename_renameat2 moves `dir/f`, over a Filesystem \
@@ -4401,16 +4635,12 @@ mod tests {
4401
4635
  ops: &dyn DentryOperations,
4402
4636
  dir: &dyn InodeOperations,
4403
4637
  dentry: &Dentry,
4404
- ) -> Result<bool, FilesystemError> {
4638
+ ) -> Result<bool, Errno> {
4405
4639
  self.revalidated.fetch_add(1, Ordering::SeqCst);
4406
4640
  ops.revalidate(dir, dentry)
4407
4641
  }
4408
4642
 
4409
- fn lookup(
4410
- &self,
4411
- inner: &dyn InodeOperations,
4412
- dentry: &Dentry,
4413
- ) -> Result<Lookup, FilesystemError> {
4643
+ fn lookup(&self, inner: &dyn InodeOperations, dentry: &Dentry) -> Result<Lookup, Errno> {
4414
4644
  self.asked.fetch_add(1, Ordering::SeqCst);
4415
4645
  let stored = dentry.name().to_uppercase();
4416
4646
  Ok(match inner.lookup(dentry)? {
@@ -4431,9 +4661,9 @@ mod tests {
4431
4661
  let tmpfs: Tmpfs = [("f", "x")].into_iter().collect();
4432
4662
  let hook = Arc::new(ReportsUpperCase::default());
4433
4663
  let wrapped = Wrap::new(Arc::new(tmpfs), hook.clone());
4434
- let root = root_of(Filesystem::new(Arc::new(wrapped)).expect("the instance must stand"));
4664
+ let root = root_of(Filesystem::new(wrapped).expect("the instance must stand"));
4435
4665
  let walked = super::filename_lookup(&Arc::default(), &root, "f", false)
4436
- .and_then(|nd| Ok((nd.path()?.name(), nd.kind()?)));
4666
+ .and_then(|nd| Ok((nd.path()?.name(), nd.file_type()?)));
4437
4667
  assert_eq!(
4438
4668
  (walked, hook.asked.load(Ordering::SeqCst)),
4439
4669
  (Ok(("F".to_string(), FileType::RegFile)), 1),
@@ -4450,7 +4680,7 @@ mod tests {
4450
4680
  let tmpfs: Tmpfs = [("f", "x")].into_iter().collect();
4451
4681
  let hook = Arc::new(ReportsUpperCase::default());
4452
4682
  let wrapped = Wrap::new(Arc::new(tmpfs), hook.clone());
4453
- let root = root_of(Filesystem::new(Arc::new(wrapped)).expect("the instance must stand"));
4683
+ let root = root_of(Filesystem::new(wrapped).expect("the instance must stand"));
4454
4684
  let first = reach(&root, "f").expect("f is reached");
4455
4685
  hook.revalidated.store(0, Ordering::SeqCst);
4456
4686
  let second = reach(&root, "f").expect("f is reached again");
@@ -4466,13 +4696,61 @@ mod tests {
4466
4696
  );
4467
4697
  }
4468
4698
 
4699
+ /// A test's Filesystem whose revalidate of `d` lets a move of `d` to `c` land
4700
+ /// and then finds `d` stale, as a walk holding no lock meets a rename ending.
4701
+ #[derive(Default)]
4702
+ struct MovesWhileAsked {
4703
+ root: std::sync::OnceLock<Path>,
4704
+ moved: std::sync::atomic::AtomicBool,
4705
+ }
4706
+
4707
+ impl wrap::Hook for MovesWhileAsked {
4708
+ fn revalidate(
4709
+ &self,
4710
+ ops: &dyn DentryOperations,
4711
+ dir: &dyn InodeOperations,
4712
+ dentry: &Dentry,
4713
+ ) -> Result<bool, Errno> {
4714
+ if dentry.name() != "d" || self.moved.swap(true, Ordering::SeqCst) {
4715
+ return ops.revalidate(dir, dentry);
4716
+ }
4717
+ let root = self
4718
+ .root
4719
+ .get()
4720
+ .expect("the test hands the root before any walk");
4721
+ super::filename_renameat2(&Arc::default(), root, "d", root, "c")?;
4722
+ Ok(false)
4723
+ }
4724
+ }
4725
+
4726
+ // A second dentry for the directory would let a move put it beneath itself,
4727
+ // which no check on dentries could see.
4728
+ // @behavior RT-391
4729
+ #[test]
4730
+ fn a_directory_moved_while_a_walk_finds_it_stale_keeps_its_one_dentry() {
4731
+ let tmpfs: Tmpfs = [("d/.keep", "")].into_iter().collect();
4732
+ let hook = Arc::new(MovesWhileAsked::default());
4733
+ let wrapped = Wrap::new(Arc::new(tmpfs), hook.clone());
4734
+ let root = root_of(Filesystem::new(wrapped).expect("the instance must stand"));
4735
+ let _ = hook.root.set(root.clone());
4736
+ let held = reach(&root, "d").expect("d is reached");
4737
+ let stale = reach(&root, "d").map(|_| ());
4738
+ let moved = reach(&root, "c").expect("c is reached where d moved");
4739
+ assert_eq!(
4740
+ (stale, Arc::ptr_eq(&held, &moved)),
4741
+ (Err(Errno::NotFound), true),
4742
+ "vfs::filename_lookup of `d` finding it stale while vfs::filename_renameat2 moves it \
4743
+ to `c` must leave its dentry at `c`, as lookup_fast retries once d_seq moved"
4744
+ );
4745
+ }
4746
+
4469
4747
  // Called with no Wasm Driver in front, so the VFS is what answers for every ABI.
4470
4748
  // @behavior RT-213
4471
4749
  #[test]
4472
4750
  fn a_path_no_call_can_take_is_refused_before_a_filesystem_is_asked() {
4473
4751
  let mount = Mount::new(
4474
4752
  "/data",
4475
- Filesystem::new(Arc::new(Tmpfs::new())).expect("the instance must stand"),
4753
+ Filesystem::new(Tmpfs::new()).expect("the instance must stand"),
4476
4754
  Access::ReadWrite,
4477
4755
  )
4478
4756
  .expect("/data is a guest path");
@@ -4488,11 +4766,11 @@ mod tests {
4488
4766
  vfs::filename_symlinkat(&cred, "a\0b", &root, "link"),
4489
4767
  ],
4490
4768
  [
4491
- error(FilesystemError::InvalidInput),
4492
- error(FilesystemError::InvalidFilename),
4493
- error(FilesystemError::NotFound),
4494
- error(FilesystemError::NotFound),
4495
- error(FilesystemError::InvalidInput),
4769
+ error(Errno::InvalidInput),
4770
+ error(Errno::InvalidFilename),
4771
+ error(Errno::NotFound),
4772
+ error(Errno::NotFound),
4773
+ error(Errno::InvalidInput),
4496
4774
  ],
4497
4775
  "vfs::filename_mkdirat and filename_symlinkat must answer EINVAL for a NUL, \
4498
4776
  ENAMETOOLONG for a path that fits no PATH_MAX, and ENOENT for an empty path or target"
@@ -4508,11 +4786,7 @@ mod tests {
4508
4786
  }
4509
4787
 
4510
4788
  impl DentryOperations for CountsLookups {
4511
- fn revalidate(
4512
- &self,
4513
- _dir: &dyn InodeOperations,
4514
- _dentry: &Dentry,
4515
- ) -> Result<bool, FilesystemError> {
4789
+ fn revalidate(&self, _dir: &dyn InodeOperations, _dentry: &Dentry) -> Result<bool, Errno> {
4516
4790
  Ok(true)
4517
4791
  }
4518
4792
 
@@ -4522,7 +4796,7 @@ mod tests {
4522
4796
  }
4523
4797
 
4524
4798
  impl InodeOperations for CountsLookups {
4525
- fn getattr(&self, dentry: &Dentry) -> Result<Kstat, FilesystemError> {
4799
+ fn getattr(&self, dentry: &Dentry) -> Result<Kstat, Errno> {
4526
4800
  let kind = match dentry.is_root() {
4527
4801
  false => crate::filesystem::FileType::RegFile,
4528
4802
  true => crate::filesystem::FileType::Dir,
@@ -4530,7 +4804,7 @@ mod tests {
4530
4804
  Ok(Kstat::new(kind, 0))
4531
4805
  }
4532
4806
 
4533
- fn lookup(&self, _dentry: &Dentry) -> Result<Lookup, FilesystemError> {
4807
+ fn lookup(&self, _dentry: &Dentry) -> Result<Lookup, Errno> {
4534
4808
  self.looked_up.fetch_add(1, Ordering::SeqCst);
4535
4809
  let file = Kstat::new(crate::filesystem::FileType::RegFile, 0);
4536
4810
  Ok(Lookup::Found(Inode::new(&file, Arc::new(self.clone()))))
@@ -4538,7 +4812,7 @@ mod tests {
4538
4812
  }
4539
4813
 
4540
4814
  impl FileSystemType for CountsLookups {
4541
- fn fill_super(self: Arc<Self>, sb: &mut Filesystem) -> Result<(), FilesystemError> {
4815
+ fn fill_super(self: Arc<Self>, sb: &mut Filesystem) -> Result<(), Errno> {
4542
4816
  sb.set_default_d_op(self.clone());
4543
4817
  sb.d_make_root(vfs::Inode::new(
4544
4818
  &Kstat::new(crate::filesystem::FileType::Dir, 0),
@@ -4553,10 +4827,10 @@ mod tests {
4553
4827
  fn lookups_of_two_stats(deleted: bool) -> usize {
4554
4828
  let looked_up = Arc::new(AtomicUsize::new(0));
4555
4829
  let root = root_of(
4556
- Filesystem::new(Arc::new(CountsLookups {
4830
+ Filesystem::new(CountsLookups {
4557
4831
  looked_up: looked_up.clone(),
4558
4832
  deleted,
4559
- }))
4833
+ })
4560
4834
  .expect("the instance must stand"),
4561
4835
  );
4562
4836
  for _ in 0..2 {
@@ -4586,7 +4860,7 @@ mod tests {
4586
4860
  impl FileOperations for RecordedFile {}
4587
4861
 
4588
4862
  impl FileSystemType for RecordsCalls {
4589
- fn fill_super(self: Arc<Self>, sb: &mut Filesystem) -> Result<(), FilesystemError> {
4863
+ fn fill_super(self: Arc<Self>, sb: &mut Filesystem) -> Result<(), Errno> {
4590
4864
  sb.d_make_root(vfs::Inode::new(
4591
4865
  &Kstat::new(crate::filesystem::FileType::Dir, 0),
4592
4866
  self,
@@ -4596,11 +4870,11 @@ mod tests {
4596
4870
  }
4597
4871
 
4598
4872
  impl InodeOperations for RecordsCalls {
4599
- fn getattr(&self, _dentry: &Dentry) -> Result<Kstat, FilesystemError> {
4873
+ fn getattr(&self, _dentry: &Dentry) -> Result<Kstat, Errno> {
4600
4874
  Ok(Kstat::new(crate::filesystem::FileType::Dir, 0))
4601
4875
  }
4602
4876
 
4603
- fn lookup(&self, dentry: &Dentry) -> Result<Lookup, FilesystemError> {
4877
+ fn lookup(&self, dentry: &Dentry) -> Result<Lookup, Errno> {
4604
4878
  if dentry.name() == "missing" {
4605
4879
  return Ok(Lookup::Absent);
4606
4880
  }
@@ -4608,11 +4882,7 @@ mod tests {
4608
4882
  Ok(Lookup::Found(Inode::new(&file, Arc::new(self.clone()))))
4609
4883
  }
4610
4884
 
4611
- fn setattr(
4612
- &self,
4613
- _dentry: &Dentry,
4614
- attr: &crate::filesystem::Iattr,
4615
- ) -> Result<(), FilesystemError> {
4885
+ fn setattr(&self, _dentry: &Dentry, attr: &crate::filesystem::Iattr) -> Result<(), Errno> {
4616
4886
  let call = if attr.open {
4617
4887
  "setattr(open)"
4618
4888
  } else {
@@ -4622,16 +4892,12 @@ mod tests {
4622
4892
  Ok(())
4623
4893
  }
4624
4894
 
4625
- fn open(
4626
- &self,
4627
- _dentry: &Dentry,
4628
- _how: &OpenHow,
4629
- ) -> Result<Box<dyn FileOperations>, FilesystemError> {
4895
+ fn open(&self, _dentry: &Dentry, _how: &OpenHow) -> Result<Box<dyn FileOperations>, Errno> {
4630
4896
  self.0.lock().expect("never poisoned").push("open");
4631
4897
  Ok(Box::new(RecordedFile))
4632
4898
  }
4633
4899
 
4634
- fn atomic_open(&self, dentry: &Dentry, how: &OpenHow) -> Result<Finish, FilesystemError> {
4900
+ fn atomic_open(&self, dentry: &Dentry, how: &OpenHow) -> Result<Finish, Errno> {
4635
4901
  if dentry.in_lookup() {
4636
4902
  let found = self.lookup(dentry)?;
4637
4903
  if !how.create || !matches!(found, Lookup::Absent) {
@@ -4655,8 +4921,7 @@ mod tests {
4655
4921
  #[test]
4656
4922
  fn an_open_empties_what_stood_through_setattr_once_it_is_open() {
4657
4923
  let calls = RecordsCalls::default();
4658
- let root =
4659
- root_of(Filesystem::new(Arc::new(calls.clone())).expect("the instance must stand"));
4924
+ let root = root_of(Filesystem::new(calls.clone()).expect("the instance must stand"));
4660
4925
  let cred = Arc::default();
4661
4926
  let truncate = OpenHow {
4662
4927
  write: true,
@@ -4691,7 +4956,7 @@ mod tests {
4691
4956
  let calls = RecordsCalls::default();
4692
4957
  let mount = Mount::new(
4693
4958
  "/data",
4694
- Filesystem::new(Arc::new(calls.clone())).expect("the instance must stand"),
4959
+ Filesystem::new(calls.clone()).expect("the instance must stand"),
4695
4960
  Access::Read,
4696
4961
  )
4697
4962
  .expect("/data is a guest path");
@@ -4711,8 +4976,8 @@ mod tests {
4711
4976
  calls.0.lock().map(|calls| calls.clone()).ok()
4712
4977
  ),
4713
4978
  (
4714
- Some(FilesystemError::NotFound),
4715
- Some(FilesystemError::ReadOnlyFilesystem),
4979
+ Some(Errno::NotFound),
4980
+ Some(Errno::ReadOnlyFilesystem),
4716
4981
  Some(Vec::new())
4717
4982
  ),
4718
4983
  "vfs::do_file_open with O_CREAT of a name a walk found missing, beneath a read-only \
@@ -4726,7 +4991,7 @@ mod tests {
4726
4991
  struct KeepsChanges(Arc<Mutex<Vec<(crate::filesystem::Iattr<'static>, bool)>>>);
4727
4992
 
4728
4993
  impl FileSystemType for KeepsChanges {
4729
- fn fill_super(self: Arc<Self>, sb: &mut Filesystem) -> Result<(), FilesystemError> {
4994
+ fn fill_super(self: Arc<Self>, sb: &mut Filesystem) -> Result<(), Errno> {
4730
4995
  sb.d_make_root(vfs::Inode::new(
4731
4996
  &Kstat::new(crate::filesystem::FileType::Dir, 0),
4732
4997
  self,
@@ -4736,23 +5001,19 @@ mod tests {
4736
5001
  }
4737
5002
 
4738
5003
  impl InodeOperations for KeepsChanges {
4739
- fn getattr(&self, dentry: &Dentry) -> Result<Kstat, FilesystemError> {
5004
+ fn getattr(&self, dentry: &Dentry) -> Result<Kstat, Errno> {
4740
5005
  Ok(match dentry.is_root() {
4741
5006
  false => Kstat::new(FileType::RegFile, 0),
4742
5007
  true => Kstat::new(FileType::Dir, 0),
4743
5008
  })
4744
5009
  }
4745
5010
 
4746
- fn lookup(&self, _dentry: &Dentry) -> Result<Lookup, FilesystemError> {
5011
+ fn lookup(&self, _dentry: &Dentry) -> Result<Lookup, Errno> {
4747
5012
  let file = Kstat::new(FileType::RegFile, 0);
4748
5013
  Ok(Lookup::Found(Inode::new(&file, Arc::new(self.clone()))))
4749
5014
  }
4750
5015
 
4751
- fn setattr(
4752
- &self,
4753
- _dentry: &Dentry,
4754
- attr: &crate::filesystem::Iattr,
4755
- ) -> Result<(), FilesystemError> {
5016
+ fn setattr(&self, _dentry: &Dentry, attr: &crate::filesystem::Iattr) -> Result<(), Errno> {
4756
5017
  self.0.lock().expect("never poisoned").push((
4757
5018
  crate::filesystem::Iattr {
4758
5019
  size: attr.size,
@@ -4773,8 +5034,7 @@ mod tests {
4773
5034
  fn a_truncate_asks_setattr_to_move_the_modification_time_too() {
4774
5035
  use crate::filesystem::SetTime;
4775
5036
  let changes = KeepsChanges::default();
4776
- let root =
4777
- root_of(Filesystem::new(Arc::new(changes.clone())).expect("the instance must stand"));
5037
+ let root = root_of(Filesystem::new(changes.clone()).expect("the instance must stand"));
4778
5038
  let cred = Arc::default();
4779
5039
  let write = OpenHow {
4780
5040
  write: true,
@@ -4809,8 +5069,7 @@ mod tests {
4809
5069
  #[test]
4810
5070
  fn a_truncate_made_through_an_open_hands_setattr_that_open() {
4811
5071
  let changes = KeepsChanges::default();
4812
- let root =
4813
- root_of(Filesystem::new(Arc::new(changes.clone())).expect("the instance must stand"));
5072
+ let root = root_of(Filesystem::new(changes.clone()).expect("the instance must stand"));
4814
5073
  let cred = Arc::default();
4815
5074
  let write = OpenHow {
4816
5075
  write: true,
@@ -4859,7 +5118,7 @@ mod tests {
4859
5118
  }
4860
5119
 
4861
5120
  impl FileSystemType for Holds {
4862
- fn fill_super(self: Arc<Self>, sb: &mut Filesystem) -> Result<(), FilesystemError> {
5121
+ fn fill_super(self: Arc<Self>, sb: &mut Filesystem) -> Result<(), Errno> {
4863
5122
  sb.d_make_root(vfs::Inode::new(
4864
5123
  &Kstat::new(crate::filesystem::FileType::Dir, 0),
4865
5124
  self,
@@ -4869,11 +5128,11 @@ mod tests {
4869
5128
  }
4870
5129
 
4871
5130
  impl InodeOperations for Holds {
4872
- fn getattr(&self, _dentry: &Dentry) -> Result<Kstat, FilesystemError> {
5131
+ fn getattr(&self, _dentry: &Dentry) -> Result<Kstat, Errno> {
4873
5132
  Ok(Kstat::new(crate::filesystem::FileType::Dir, 0))
4874
5133
  }
4875
5134
 
4876
- fn lookup(&self, dentry: &Dentry) -> Result<Lookup, FilesystemError> {
5135
+ fn lookup(&self, dentry: &Dentry) -> Result<Lookup, Errno> {
4877
5136
  if dentry.name() != "f" {
4878
5137
  return Ok(Lookup::Absent);
4879
5138
  }
@@ -4881,26 +5140,22 @@ mod tests {
4881
5140
  Ok(Lookup::Found(Inode::new(&found, Arc::new(self.clone()))))
4882
5141
  }
4883
5142
 
4884
- fn permission(&self, dentry: &Dentry, mask: Mask) -> Result<(), FilesystemError> {
5143
+ fn permission(&self, dentry: &Dentry, mask: Mask) -> Result<(), Errno> {
4885
5144
  match !dentry.is_root() && mask.contains(self.refuses) {
4886
- true => Err(FilesystemError::PermissionDenied),
5145
+ true => Err(Errno::PermissionDenied),
4887
5146
  false => Ok(()),
4888
5147
  }
4889
5148
  }
4890
5149
 
4891
- fn open(
4892
- &self,
4893
- _dentry: &Dentry,
4894
- _how: &OpenHow,
4895
- ) -> Result<Box<dyn FileOperations>, FilesystemError> {
5150
+ fn open(&self, _dentry: &Dentry, _how: &OpenHow) -> Result<Box<dyn FileOperations>, Errno> {
4896
5151
  Ok(Box::new(RecordedFile))
4897
5152
  }
4898
5153
 
4899
- fn setattr(&self, _dentry: &Dentry, _attr: &vfs::Iattr) -> Result<(), FilesystemError> {
5154
+ fn setattr(&self, _dentry: &Dentry, _attr: &vfs::Iattr) -> Result<(), Errno> {
4900
5155
  Ok(())
4901
5156
  }
4902
5157
 
4903
- fn atomic_open(&self, dentry: &Dentry, how: &OpenHow) -> Result<Finish, FilesystemError> {
5158
+ fn atomic_open(&self, dentry: &Dentry, how: &OpenHow) -> Result<Finish, Errno> {
4904
5159
  if dentry.in_lookup() {
4905
5160
  let found = self.lookup(dentry)?;
4906
5161
  if !how.create || !matches!(found, Lookup::Absent) {
@@ -4920,22 +5175,18 @@ mod tests {
4920
5175
  }
4921
5176
  }
4922
5177
 
4923
- fn open_beneath(
4924
- holds: Holds,
4925
- access: Access,
4926
- path: &str,
4927
- how: &OpenHow,
4928
- ) -> Option<FilesystemError> {
5178
+ fn open_beneath(holds: Holds, access: Access, path: &str, how: &OpenHow) -> Option<Errno> {
4929
5179
  let mount = Mount::new(
4930
5180
  "/data",
4931
- Filesystem::new(Arc::new(holds)).expect("the instance must stand"),
5181
+ Filesystem::new(holds).expect("the instance must stand"),
4932
5182
  access,
4933
5183
  )
4934
5184
  .expect("/data is a guest path");
4935
5185
  let cred = crate::security::restrict_self(
4936
- &crate::security::prepare_creds_within(&[], None),
4937
- [&mount],
4938
- );
5186
+ &crate::security::prepare_creds(&[], None),
5187
+ [&crate::grant::Grant::Mount(mount.clone())],
5188
+ )
5189
+ .expect("every mount stands");
4939
5190
  vfs::kern_path::filp_open(&cred, &Path::root(mount.mnt()), path, how).err()
4940
5191
  }
4941
5192
 
@@ -4947,11 +5198,8 @@ mod tests {
4947
5198
  fn an_allocation_or_advice_on_a_fifo_answers_espipe() {
4948
5199
  let mount = Mount::new(
4949
5200
  "/data",
4950
- Filesystem::new(Arc::new(Holds::of(
4951
- crate::filesystem::FileType::Fifo,
4952
- Mask::EXEC,
4953
- )))
4954
- .expect("the instance must stand"),
5201
+ Filesystem::new(Holds::of(crate::filesystem::FileType::Fifo, Mask::EXEC))
5202
+ .expect("the instance must stand"),
4955
5203
  Access::ReadWrite,
4956
5204
  )
4957
5205
  .expect("/data is a guest path");
@@ -4964,10 +5212,7 @@ mod tests {
4964
5212
  .unwrap_or_else(|_| panic!("the FIFO must open"));
4965
5213
  assert_eq!(
4966
5214
  (fifo.fallocate(0, 1).err(), fifo.fadvise(0, 1).err()),
4967
- (
4968
- Some(FilesystemError::NotSeekable),
4969
- Some(FilesystemError::NotSeekable)
4970
- ),
5215
+ (Some(Errno::NotSeekable), Some(Errno::NotSeekable)),
4971
5216
  "File::fallocate and File::fadvise of a FIFO opened to write must answer ESPIPE"
4972
5217
  );
4973
5218
  }
@@ -4980,11 +5225,8 @@ mod tests {
4980
5225
  fn an_allocation_on_a_character_device_answers_enodev() {
4981
5226
  let mount = Mount::new(
4982
5227
  "/data",
4983
- Filesystem::new(Arc::new(Holds::of(
4984
- crate::filesystem::FileType::Chrdev,
4985
- Mask::EXEC,
4986
- )))
4987
- .expect("the instance must stand"),
5228
+ Filesystem::new(Holds::of(crate::filesystem::FileType::Chrdev, Mask::EXEC))
5229
+ .expect("the instance must stand"),
4988
5230
  Access::ReadWrite,
4989
5231
  )
4990
5232
  .expect("/data is a guest path");
@@ -4997,7 +5239,7 @@ mod tests {
4997
5239
  .unwrap_or_else(|_| panic!("the device must open"));
4998
5240
  assert_eq!(
4999
5241
  device.fallocate(0, 1).err(),
5000
- Some(FilesystemError::NoSuchDevice),
5242
+ Some(Errno::NoSuchDevice),
5001
5243
  "File::fallocate of a character device opened to write must answer ENODEV"
5002
5244
  );
5003
5245
  }
@@ -5009,11 +5251,8 @@ mod tests {
5009
5251
  fn sizing_a_character_device_answers_einval() {
5010
5252
  let mount = Mount::new(
5011
5253
  "/data",
5012
- Filesystem::new(Arc::new(Holds::of(
5013
- crate::filesystem::FileType::Chrdev,
5014
- Mask::EXEC,
5015
- )))
5016
- .expect("the instance must stand"),
5254
+ Filesystem::new(Holds::of(crate::filesystem::FileType::Chrdev, Mask::EXEC))
5255
+ .expect("the instance must stand"),
5017
5256
  Access::ReadWrite,
5018
5257
  )
5019
5258
  .expect("/data is a guest path");
@@ -5026,7 +5265,7 @@ mod tests {
5026
5265
  .unwrap_or_else(|_| panic!("the device must open"));
5027
5266
  assert_eq!(
5028
5267
  device.truncate(0).err(),
5029
- Some(FilesystemError::InvalidInput),
5268
+ Some(Errno::InvalidInput),
5030
5269
  "File::truncate of a character device opened to write must answer EINVAL"
5031
5270
  );
5032
5271
  }
@@ -5048,8 +5287,8 @@ mod tests {
5048
5287
  open_beneath(Holds::of(file, Mask::EXEC), Access::Read, "f", &write),
5049
5288
  ),
5050
5289
  (
5051
- Some(FilesystemError::PermissionDenied),
5052
- Some(FilesystemError::ReadOnlyFilesystem)
5290
+ Some(Errno::PermissionDenied),
5291
+ Some(Errno::ReadOnlyFilesystem)
5053
5292
  ),
5054
5293
  "vfs::do_file_open to write beneath a read-only Mount must answer EACCES for a FIFO, \
5055
5294
  as the security module refuses it, and EROFS for a file"
@@ -5069,7 +5308,7 @@ mod tests {
5069
5308
  let file = crate::filesystem::FileType::RegFile;
5070
5309
  assert_eq!(
5071
5310
  open_beneath(Holds::of(file, Mask::WRITE), Access::Read, "f", &truncate),
5072
- Some(FilesystemError::ReadOnlyFilesystem),
5311
+ Some(Errno::ReadOnlyFilesystem),
5073
5312
  "vfs::do_file_open with O_TRUNC of a file its Filesystem refuses to write, beneath a \
5074
5313
  read-only Mount, must answer EROFS"
5075
5314
  );
@@ -5090,7 +5329,7 @@ mod tests {
5090
5329
  open_beneath(holds, Access::ReadWrite, "new", &create),
5091
5330
  made.load(Ordering::SeqCst)
5092
5331
  ),
5093
- (Some(FilesystemError::PermissionDenied), true),
5332
+ (Some(Errno::PermissionDenied), true),
5094
5333
  "vfs::do_file_open with O_CREAT of a missing path whose Filesystem refuses to open what \
5095
5334
  it makes must make the file and answer EACCES"
5096
5335
  );
@@ -5104,7 +5343,7 @@ mod tests {
5104
5343
  }
5105
5344
 
5106
5345
  impl FileSystemType for HoldsLookup {
5107
- fn fill_super(self: Arc<Self>, sb: &mut Filesystem) -> Result<(), FilesystemError> {
5346
+ fn fill_super(self: Arc<Self>, sb: &mut Filesystem) -> Result<(), Errno> {
5108
5347
  sb.d_make_root(vfs::Inode::new(
5109
5348
  &Kstat::new(crate::filesystem::FileType::Dir, 0),
5110
5349
  self,
@@ -5114,11 +5353,11 @@ mod tests {
5114
5353
  }
5115
5354
 
5116
5355
  impl InodeOperations for HoldsLookup {
5117
- fn getattr(&self, _dentry: &Dentry) -> Result<Kstat, FilesystemError> {
5356
+ fn getattr(&self, _dentry: &Dentry) -> Result<Kstat, Errno> {
5118
5357
  Ok(Kstat::new(crate::filesystem::FileType::Dir, 0))
5119
5358
  }
5120
5359
 
5121
- fn lookup(&self, _dentry: &Dentry) -> Result<Lookup, FilesystemError> {
5360
+ fn lookup(&self, _dentry: &Dentry) -> Result<Lookup, Errno> {
5122
5361
  self.asked.fetch_add(1, Ordering::SeqCst);
5123
5362
  self.reached.lock().expect("never poisoned").send(()).ok();
5124
5363
  self.go_on
@@ -5142,7 +5381,7 @@ mod tests {
5142
5381
  }
5143
5382
 
5144
5383
  impl FileSystemType for AsksItsOwnName {
5145
- fn fill_super(self: Arc<Self>, sb: &mut Filesystem) -> Result<(), FilesystemError> {
5384
+ fn fill_super(self: Arc<Self>, sb: &mut Filesystem) -> Result<(), Errno> {
5146
5385
  sb.d_make_root(vfs::Inode::new(
5147
5386
  &Kstat::new(crate::filesystem::FileType::Dir, 0),
5148
5387
  self,
@@ -5152,14 +5391,14 @@ mod tests {
5152
5391
  }
5153
5392
 
5154
5393
  impl InodeOperations for AsksItsOwnName {
5155
- fn getattr(&self, dentry: &Dentry) -> Result<Kstat, FilesystemError> {
5394
+ fn getattr(&self, dentry: &Dentry) -> Result<Kstat, Errno> {
5156
5395
  Ok(match dentry.is_root() {
5157
5396
  false => Kstat::new(FileType::RegFile, 0),
5158
5397
  true => Kstat::new(FileType::Dir, 0),
5159
5398
  })
5160
5399
  }
5161
5400
 
5162
- fn lookup(&self, _dentry: &Dentry) -> Result<Lookup, FilesystemError> {
5401
+ fn lookup(&self, _dentry: &Dentry) -> Result<Lookup, Errno> {
5163
5402
  if self.asked.fetch_add(1, Ordering::SeqCst) == 0 {
5164
5403
  let root = self.root.get().expect("the root is set before any walk");
5165
5404
  vfs::vfs_fstatat(&Arc::default(), root, "x", false)?;
@@ -5230,24 +5469,89 @@ mod tests {
5230
5469
  );
5231
5470
  assert_eq!(
5232
5471
  (answers, holds.asked.load(Ordering::SeqCst)),
5233
- (
5234
- (
5235
- Some(FilesystemError::NotFound),
5236
- Some(FilesystemError::NotFound)
5237
- ),
5238
- 1
5239
- ),
5472
+ ((Some(Errno::NotFound), Some(Errno::NotFound)), 1),
5240
5473
  "vfs::vfs_fstatat of one name from two walks at once must ask the Filesystem's \
5241
5474
  lookup once, the second waiting for the first's answer"
5242
5475
  );
5243
5476
  }
5244
5477
 
5478
+ /// A directory whose first lookup holds until told to go on and then
5479
+ /// panics, every later one finding nothing, counting each lookup.
5480
+ struct PanicsOnce(HoldsLookup);
5481
+
5482
+ impl FileSystemType for PanicsOnce {
5483
+ fn fill_super(self: Arc<Self>, sb: &mut Filesystem) -> Result<(), Errno> {
5484
+ sb.d_make_root(vfs::Inode::new(&Kstat::new(FileType::Dir, 0), self));
5485
+ Ok(())
5486
+ }
5487
+ }
5488
+
5489
+ impl InodeOperations for PanicsOnce {
5490
+ fn getattr(&self, _dentry: &Dentry) -> Result<Kstat, Errno> {
5491
+ Ok(Kstat::new(FileType::Dir, 0))
5492
+ }
5493
+
5494
+ fn lookup(&self, dentry: &Dentry) -> Result<Lookup, Errno> {
5495
+ if self.0.asked.load(Ordering::SeqCst) > 0 {
5496
+ return Ok(Lookup::Absent);
5497
+ }
5498
+ self.0.lookup(dentry)?;
5499
+ panic!("the first lookup panics");
5500
+ }
5501
+ }
5502
+
5503
+ // @behavior RT-406
5504
+ #[test]
5505
+ fn a_walk_waiting_on_a_lookup_that_panics_asks_the_filesystem_itself() {
5506
+ let (reached, reaching) = mpsc::channel();
5507
+ let (go_on, going) = mpsc::channel();
5508
+ let filesystem = Arc::new(PanicsOnce(HoldsLookup {
5509
+ asked: AtomicUsize::new(0),
5510
+ reached: Mutex::new(reached),
5511
+ go_on: Mutex::new(going),
5512
+ }));
5513
+ let root = root_of(Filesystem::new(filesystem.clone()).expect("the instance must stand"));
5514
+ let stat = |root: &Path| vfs::vfs_fstatat(&Arc::default(), root, "x", false).err();
5515
+ let first = {
5516
+ let root = root.clone();
5517
+ thread::spawn(move || stat(&root))
5518
+ };
5519
+ reaching
5520
+ .recv_timeout(crate::sched::testing::MAX_WAIT)
5521
+ .expect("the first walk must ask");
5522
+ let (counted, counting) = mpsc::channel();
5523
+ let second = {
5524
+ let root = root.clone();
5525
+ thread::spawn(move || {
5526
+ counted.send(count_waits()).ok();
5527
+ crate::sched::testing::within_max_wait(|| stat(&root))
5528
+ })
5529
+ };
5530
+ let waits = counting
5531
+ .recv_timeout(crate::sched::testing::MAX_WAIT)
5532
+ .expect("the second walk must start");
5533
+ crate::sched::testing::wait_until("the second walk waiting", || {
5534
+ waits.load(Ordering::SeqCst) > 0
5535
+ });
5536
+ go_on.send(()).ok();
5537
+ crate::sched::testing::wait_until("the first walk ending", || first.is_finished());
5538
+ assert_eq!(
5539
+ (
5540
+ first.join().is_err(),
5541
+ crate::sched::testing::join("the second walk", second),
5542
+ ),
5543
+ (true, Some(Errno::NotFound)),
5544
+ "a stat waiting on another walk's lookup of the name must, once that lookup \
5545
+ panics, ask the filesystem itself and answer, rather than wait on"
5546
+ );
5547
+ }
5548
+
5245
5549
  /// A directory finding nothing at any name, keeping which walk asked.
5246
5550
  #[derive(Default)]
5247
5551
  struct RecordsAsker(Mutex<Vec<thread::ThreadId>>);
5248
5552
 
5249
5553
  impl FileSystemType for RecordsAsker {
5250
- fn fill_super(self: Arc<Self>, sb: &mut Filesystem) -> Result<(), FilesystemError> {
5554
+ fn fill_super(self: Arc<Self>, sb: &mut Filesystem) -> Result<(), Errno> {
5251
5555
  sb.d_make_root(vfs::Inode::new(
5252
5556
  &Kstat::new(crate::filesystem::FileType::Dir, 0),
5253
5557
  self,
@@ -5257,11 +5561,11 @@ mod tests {
5257
5561
  }
5258
5562
 
5259
5563
  impl InodeOperations for RecordsAsker {
5260
- fn getattr(&self, _dentry: &Dentry) -> Result<Kstat, FilesystemError> {
5564
+ fn getattr(&self, _dentry: &Dentry) -> Result<Kstat, Errno> {
5261
5565
  Ok(Kstat::new(FileType::Dir, 0))
5262
5566
  }
5263
5567
 
5264
- fn lookup(&self, _dentry: &Dentry) -> Result<Lookup, FilesystemError> {
5568
+ fn lookup(&self, _dentry: &Dentry) -> Result<Lookup, Errno> {
5265
5569
  self.0
5266
5570
  .lock()
5267
5571
  .expect("never poisoned")
@@ -5318,7 +5622,7 @@ mod tests {
5318
5622
  struct PointsNowhere(crate::filesystem::FileType);
5319
5623
 
5320
5624
  impl FileSystemType for PointsNowhere {
5321
- fn fill_super(self: Arc<Self>, sb: &mut Filesystem) -> Result<(), FilesystemError> {
5625
+ fn fill_super(self: Arc<Self>, sb: &mut Filesystem) -> Result<(), Errno> {
5322
5626
  sb.d_make_root(vfs::Inode::new(
5323
5627
  &Kstat::new(crate::filesystem::FileType::Dir, 0),
5324
5628
  self,
@@ -5328,11 +5632,11 @@ mod tests {
5328
5632
  }
5329
5633
 
5330
5634
  impl InodeOperations for PointsNowhere {
5331
- fn getattr(&self, _dentry: &Dentry) -> Result<Kstat, FilesystemError> {
5635
+ fn getattr(&self, _dentry: &Dentry) -> Result<Kstat, Errno> {
5332
5636
  Ok(Kstat::new(self.0, 0))
5333
5637
  }
5334
5638
 
5335
- fn lookup(&self, dentry: &Dentry) -> Result<Lookup, FilesystemError> {
5639
+ fn lookup(&self, dentry: &Dentry) -> Result<Lookup, Errno> {
5336
5640
  use crate::filesystem::FileType;
5337
5641
  let kind = match dentry.name().as_str() {
5338
5642
  "e" => FileType::Symlink,
@@ -5343,7 +5647,7 @@ mod tests {
5343
5647
  Ok(Lookup::Found(Inode::new(&found, Arc::new(Self(kind)))))
5344
5648
  }
5345
5649
 
5346
- fn get_link(&self, _dentry: &Dentry) -> Result<String, FilesystemError> {
5650
+ fn get_link(&self, _dentry: &Dentry) -> Result<String, Errno> {
5347
5651
  Ok(String::new())
5348
5652
  }
5349
5653
  }
@@ -5356,7 +5660,7 @@ mod tests {
5356
5660
  }
5357
5661
 
5358
5662
  impl FileSystemType for StaleBehindLinks {
5359
- fn fill_super(self: Arc<Self>, sb: &mut Filesystem) -> Result<(), FilesystemError> {
5663
+ fn fill_super(self: Arc<Self>, sb: &mut Filesystem) -> Result<(), Errno> {
5360
5664
  sb.d_make_root(vfs::Inode::new(
5361
5665
  &Kstat::new(crate::filesystem::FileType::Dir, 0),
5362
5666
  self,
@@ -5366,17 +5670,19 @@ mod tests {
5366
5670
  }
5367
5671
 
5368
5672
  impl InodeOperations for StaleBehindLinks {
5369
- fn getattr(&self, dentry: &Dentry) -> Result<Kstat, FilesystemError> {
5673
+ fn getattr(&self, dentry: &Dentry) -> Result<Kstat, Errno> {
5370
5674
  Ok(Kstat::new(
5371
- dentry.inode().map_or(FileType::Dir, |inode| inode.kind()),
5675
+ dentry
5676
+ .inode()
5677
+ .map_or(FileType::Dir, |inode| inode.file_type()),
5372
5678
  0,
5373
5679
  ))
5374
5680
  }
5375
5681
 
5376
- fn lookup(&self, dentry: &Dentry) -> Result<Lookup, FilesystemError> {
5682
+ fn lookup(&self, dentry: &Dentry) -> Result<Lookup, Errno> {
5377
5683
  let kind = match dentry.name().as_str() {
5378
5684
  "f" if !self.answered_stale.swap(true, Ordering::SeqCst) => {
5379
- return Err(FilesystemError::StaleNetworkFileHandle)
5685
+ return Err(Errno::StaleNetworkFileHandle)
5380
5686
  }
5381
5687
  "f" => FileType::RegFile,
5382
5688
  _ => FileType::Symlink,
@@ -5387,7 +5693,7 @@ mod tests {
5387
5693
  )))
5388
5694
  }
5389
5695
 
5390
- fn get_link(&self, dentry: &Dentry) -> Result<String, FilesystemError> {
5696
+ fn get_link(&self, dentry: &Dentry) -> Result<String, Errno> {
5391
5697
  let at: usize = dentry.name()[1..].parse().expect("a link is named l<n>");
5392
5698
  Ok(match at {
5393
5699
  29 => "f".to_string(),
@@ -5401,13 +5707,11 @@ mod tests {
5401
5707
  // @behavior RT-327
5402
5708
  #[test]
5403
5709
  fn a_walk_made_again_for_estale_counts_the_links_the_first_followed() {
5404
- let root = root_of(
5405
- Filesystem::new(Arc::new(StaleBehindLinks::default()))
5406
- .expect("the instance must stand"),
5407
- );
5710
+ let root =
5711
+ root_of(Filesystem::new(StaleBehindLinks::default()).expect("the instance must stand"));
5408
5712
  assert_eq!(
5409
5713
  vfs::vfs_fstatat(&Arc::default(), &root, "l0", true).map(|found| found.file_type),
5410
- Err(FilesystemError::FilesystemLoop),
5714
+ Err(Errno::FilesystemLoop),
5411
5715
  "vfs::vfs_fstatat following thirty links to a name that answers ESTALE once must \
5412
5716
  count the links of both walks toward one budget of forty and answer ELOOP, as \
5413
5717
  Linux's total_link_count carries into the walk made again"
@@ -5421,8 +5725,7 @@ mod tests {
5421
5725
  fn a_link_pointing_nowhere_leaves_the_walk_where_it_stands() {
5422
5726
  use crate::filesystem::FileType;
5423
5727
  let root = root_of(
5424
- Filesystem::new(Arc::new(PointsNowhere(FileType::Dir)))
5425
- .expect("the instance must stand"),
5728
+ Filesystem::new(PointsNowhere(FileType::Dir)).expect("the instance must stand"),
5426
5729
  );
5427
5730
  let kind = |path: &str| {
5428
5731
  vfs::vfs_fstatat(&Arc::default(), &root, path, true).map(|found| found.file_type)
@@ -5437,15 +5740,14 @@ mod tests {
5437
5740
 
5438
5741
  // Linux's waits on a directory and on a name in lookup are killable, so a
5439
5742
  // run whose deadline passed or whose thread was interrupted stops waiting
5440
- // while the holder still holds.
5743
+ // while the owner still holds.
5441
5744
  // @behavior RT-267
5442
5745
  #[test]
5443
5746
  fn a_wait_ends_once_its_run_is_to_stop() {
5444
5747
  use crate::sched::{run_task, Task};
5445
5748
  use std::time::Instant;
5446
5749
 
5447
- let root =
5448
- root_of(Filesystem::new(Arc::new(Tmpfs::new())).expect("the instance must stand"));
5750
+ let root = root_of(Filesystem::new(Tmpfs::new()).expect("the instance must stand"));
5449
5751
  let held = root.dentry().inode_lock().expect("the test holds the root");
5450
5752
  let past_deadline = {
5451
5753
  let root = root.clone();
@@ -5478,15 +5780,51 @@ mod tests {
5478
5780
  past_deadline.join().expect("the wait must not panic"),
5479
5781
  interrupted.join().expect("the wait must not panic"),
5480
5782
  ),
5481
- (
5482
- Err(FilesystemError::Interrupted),
5483
- Err(FilesystemError::Interrupted)
5484
- ),
5783
+ (Err(Errno::Interrupted), Err(Errno::Interrupted)),
5485
5784
  "vfs::filename_mkdirat waiting on a directory another thread holds must answer EINTR \
5486
5785
  once its run's deadline passes, and once its thread is interrupted"
5487
5786
  );
5488
5787
  }
5489
5788
 
5789
+ // A signal the frontend handles without interrupting the task leaves a
5790
+ // killable wait asleep, as Linux restarts a call a handled signal woke.
5791
+ // @behavior RT-405
5792
+ #[test]
5793
+ fn a_wait_goes_on_past_a_signal_that_is_not_fatal() {
5794
+ use crate::sched::testing::{count_signals, join, wait_until};
5795
+ use crate::sched::{run_task, Task};
5796
+
5797
+ let root = root_of(Filesystem::new(Tmpfs::new()).expect("the instance must stand"));
5798
+ let held = root.dentry().inode_lock().expect("the test holds the root");
5799
+ let (task, tasked) = mpsc::channel();
5800
+ let waiting = {
5801
+ let root = root.clone();
5802
+ thread::spawn(move || {
5803
+ let handled = count_signals();
5804
+ run_task(None, || {
5805
+ task.send((Task::current(), handled)).ok();
5806
+ vfs::filename_mkdirat(&Arc::default(), &root, "late")
5807
+ })
5808
+ })
5809
+ };
5810
+ let (task, handled) = tasked
5811
+ .recv_timeout(crate::sched::testing::MAX_WAIT)
5812
+ .expect("the run must start");
5813
+ task.signal();
5814
+ wait_until("the signal being handled", || {
5815
+ handled.load(Ordering::SeqCst) > 0
5816
+ });
5817
+ let woke_early = waiting.is_finished();
5818
+ drop(held);
5819
+ assert_eq!(
5820
+ (woke_early, join("the signalled wait", waiting)),
5821
+ (false, Ok(())),
5822
+ "a mkdir waiting on a directory another thread holds, its thread signalled and \
5823
+ the signal handled without an interrupt, must go on waiting and make the \
5824
+ directory once the other lets go"
5825
+ );
5826
+ }
5827
+
5490
5828
  // @behavior RT-267
5491
5829
  #[test]
5492
5830
  fn a_wait_for_a_name_in_lookup_ends_once_its_run_is_to_stop() {
@@ -5515,7 +5853,7 @@ mod tests {
5515
5853
  crate::sched::testing::join("the first walk", first);
5516
5854
  assert_eq!(
5517
5855
  second,
5518
- Some(FilesystemError::Interrupted),
5856
+ Some(Errno::Interrupted),
5519
5857
  "vfs::vfs_fstatat of a name another walk is looking up must answer EINTR once its \
5520
5858
  run's deadline passes"
5521
5859
  );
@@ -5532,12 +5870,12 @@ mod tests {
5532
5870
  fn rename(
5533
5871
  &self,
5534
5872
  inner: &dyn InodeOperations,
5535
- from: &Dentry,
5536
- to_dir: &dyn InodeOperations,
5537
- to: &Dentry,
5538
- flag: Option<RenameFlag>,
5539
- ) -> Result<(), FilesystemError> {
5540
- if from.name() == "k" {
5873
+ old: &Dentry,
5874
+ new_dir: &dyn InodeOperations,
5875
+ new: &Dentry,
5876
+ flags: Option<RenameFlag>,
5877
+ ) -> Result<(), Errno> {
5878
+ if old.name() == "k" {
5541
5879
  let reached = self.reached.lock().expect("never poisoned");
5542
5880
  reached.send(()).expect("the test waits to hear");
5543
5881
  let go_on = self.go_on.lock().expect("never poisoned");
@@ -5545,16 +5883,16 @@ mod tests {
5545
5883
  .recv_timeout(crate::sched::testing::MAX_WAIT)
5546
5884
  .expect("the test says when to go on");
5547
5885
  }
5548
- inner.rename(from, to_dir, to, flag)
5886
+ inner.rename(old, new_dir, new, flags)
5549
5887
  }
5550
5888
  }
5551
5889
 
5552
5890
  /// Refuses every change to the one path the move may not touch.
5553
5891
  struct RefusesMovedName;
5554
5892
 
5555
- impl Policy for RefusesMovedName {
5556
- fn allows(&self, path: &str, _access: Access) -> bool {
5557
- path != "/data/a/moved"
5893
+ impl Policy<MountRequest<'_>> for RefusesMovedName {
5894
+ fn allows(&self, request: &MountRequest<'_>) -> bool {
5895
+ request.path != "/data/a/moved"
5558
5896
  }
5559
5897
  }
5560
5898
 
@@ -5562,8 +5900,7 @@ mod tests {
5562
5900
  // to `a/x`. A writer with no Policy renames it within `a` meanwhile, which
5563
5901
  // takes no rename lock. A dentry taken before the wait would follow it to
5564
5902
  // the name the Policy refuses, so only a name found under the lock answers
5565
- // ENOENT. The wait can only be slept for; a move not yet waiting is one the
5566
- // assertion passes on, never one it fails.
5903
+ // ENOENT. The writer renames only once the move waits through the `Blocking`.
5567
5904
  // @behavior RT-211
5568
5905
  #[test]
5569
5906
  fn a_move_acts_on_what_stands_at_its_names_once_it_holds_them() {
@@ -5578,18 +5915,18 @@ mod tests {
5578
5915
  });
5579
5916
  let mount = Mount::new(
5580
5917
  "/data",
5581
- Filesystem::new(Arc::new(Wrap::new(Arc::new(tmpfs), hook)))
5582
- .expect("the instance must stand"),
5918
+ Filesystem::new(Wrap::new(Arc::new(tmpfs), hook)).expect("the instance must stand"),
5583
5919
  Access::ReadWrite,
5584
5920
  )
5585
5921
  .expect("/data is a guest path")
5586
5922
  .with_policy(Arc::new(RefusesMovedName));
5587
5923
  let cred = crate::security::restrict_self(
5588
- &crate::security::prepare_creds_within(&[], None),
5589
- [&mount],
5590
- );
5924
+ &crate::security::prepare_creds(&[], None),
5925
+ [&crate::grant::Grant::Mount(mount.clone())],
5926
+ )
5927
+ .expect("every mount stands");
5591
5928
  let root = Path::root(mount.mnt());
5592
- let holder = {
5929
+ let owner = {
5593
5930
  let root = root.clone();
5594
5931
  thread::spawn(move || {
5595
5932
  vfs::filename_renameat2(&Arc::default(), &root, "c/k", &root, "d/k")
@@ -5598,20 +5935,29 @@ mod tests {
5598
5935
  reaching
5599
5936
  .recv_timeout(crate::sched::testing::MAX_WAIT)
5600
5937
  .expect("the held move must reach its Filesystem");
5938
+ let (counted, counts) = mpsc::channel();
5601
5939
  let mover = {
5602
5940
  let (cred, root) = (cred.clone(), root.clone());
5603
- thread::spawn(move || vfs::filename_renameat2(&cred, &root, "a/x", &root, "b/y"))
5941
+ thread::spawn(move || {
5942
+ counted
5943
+ .send(count_waits())
5944
+ .expect("the test takes the count");
5945
+ vfs::filename_renameat2(&cred, &root, "a/x", &root, "b/y")
5946
+ })
5604
5947
  };
5605
- thread::sleep(Duration::from_millis(200));
5948
+ let waits = counts.recv().expect("the move counts its waits");
5949
+ crate::sched::testing::wait_until("the move waiting for the rename lock", || {
5950
+ waits.load(Ordering::SeqCst) > 0
5951
+ });
5606
5952
  let renamed = vfs::filename_renameat2(&Arc::default(), &root, "a/x", &root, "a/moved");
5607
5953
  go_on.send(()).expect("the held move must be waiting");
5608
- crate::sched::testing::join("the holder", holder)
5954
+ crate::sched::testing::join("the owner", owner)
5609
5955
  .unwrap_or_else(|_| panic!("the held move must land"));
5610
5956
  let moved = crate::sched::testing::join("the mover", mover);
5611
5957
  let stands = |path| vfs::vfs_fstatat(&cred, &root, path, false).is_ok();
5612
5958
  assert_eq!(
5613
5959
  (renamed, moved, stands("a/moved"), stands("b/y")),
5614
- (Ok(()), Err(FilesystemError::NotFound), true, false),
5960
+ (Ok(()), Err(Errno::NotFound), true, false),
5615
5961
  "vfs::filename_renameat2 of `a/x` that waited while another writer renamed it must \
5616
5962
  answer ENOENT and leave `a/moved`, which the Policy refuses, where it stands"
5617
5963
  );
@@ -5626,10 +5972,9 @@ mod tests {
5626
5972
  use std::thread;
5627
5973
 
5628
5974
  use super::{reach, root_of};
5629
- use crate::filesystem::{
5630
- FileType, Filesystem, FilesystemError, InodeOperations, Kstat, Lookup,
5631
- };
5975
+ use crate::filesystem::{FileType, Filesystem, InodeOperations, Kstat, Lookup};
5632
5976
  use crate::vfs::{self, Dentry, FileSystemType, Inode};
5977
+ use crate::Errno;
5633
5978
 
5634
5979
  /// A Filesystem handing one directory's inode for `a` in its root and
5635
5980
  /// `d` in its directory `c`, whose two lookups answer only once both
@@ -5641,7 +5986,7 @@ mod tests {
5641
5986
  }
5642
5987
 
5643
5988
  impl FileSystemType for AnswersAtOnce {
5644
- fn fill_super(self: Arc<Self>, sb: &mut Filesystem) -> Result<(), FilesystemError> {
5989
+ fn fill_super(self: Arc<Self>, sb: &mut Filesystem) -> Result<(), Errno> {
5645
5990
  sb.d_make_root(vfs::Inode::new(
5646
5991
  &Kstat::new(crate::filesystem::FileType::Dir, 0),
5647
5992
  self,
@@ -5651,11 +5996,11 @@ mod tests {
5651
5996
  }
5652
5997
 
5653
5998
  impl InodeOperations for AnswersAtOnce {
5654
- fn getattr(&self, _dentry: &Dentry) -> Result<Kstat, FilesystemError> {
5999
+ fn getattr(&self, _dentry: &Dentry) -> Result<Kstat, Errno> {
5655
6000
  Ok(Kstat::new(FileType::Dir, 0))
5656
6001
  }
5657
6002
 
5658
- fn lookup(&self, dentry: &Dentry) -> Result<Lookup, FilesystemError> {
6003
+ fn lookup(&self, dentry: &Dentry) -> Result<Lookup, Errno> {
5659
6004
  let dir = Kstat::new(FileType::Dir, 0);
5660
6005
  Ok(match dentry.name().as_str() {
5661
6006
  "a" | "d" => {
@@ -5683,8 +6028,7 @@ mod tests {
5683
6028
  let split = (0..20_000)
5684
6029
  .filter(|_| {
5685
6030
  let root = root_of(
5686
- Filesystem::new(Arc::new(AnswersAtOnce::default()))
5687
- .expect("the instance must stand"),
6031
+ Filesystem::new(AnswersAtOnce::default()).expect("the instance must stand"),
5688
6032
  );
5689
6033
  reach(&root, "c").expect("c is reached");
5690
6034
  let walks = ["a", "c/d"].map(|path| {