kobako 0.30.0 → 0.31.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (266) hide show
  1. checksums.yaml +4 -4
  2. data/.release-please-manifest.json +1 -1
  3. data/CHANGELOG.md +335 -0
  4. data/Cargo.lock +469 -11
  5. data/README.md +43 -3
  6. data/ROADMAP.md +1 -1
  7. data/crates/kobako-runtime/CHANGELOG.md +219 -0
  8. data/crates/kobako-runtime/Cargo.toml +51 -3
  9. data/crates/kobako-runtime/README.md +7 -4
  10. data/crates/kobako-runtime/src/cred.rs +124 -0
  11. data/crates/kobako-runtime/src/dispatch.rs +4 -5
  12. data/crates/kobako-runtime/src/endpoint/buffer.rs +153 -44
  13. data/crates/kobako-runtime/src/endpoint/dispatch.rs +80 -41
  14. data/crates/kobako-runtime/src/endpoint/invoke.rs +23 -36
  15. data/crates/kobako-runtime/src/endpoint.rs +137 -36
  16. data/crates/kobako-runtime/src/errno.rs +391 -0
  17. data/crates/kobako-runtime/src/error.rs +31 -10
  18. data/crates/kobako-runtime/src/filesystem/anon_inodes.rs +52 -0
  19. data/crates/kobako-runtime/src/filesystem/bind/lookup.rs +52 -14
  20. data/crates/kobako-runtime/src/filesystem/bind/walk.rs +19 -20
  21. data/crates/kobako-runtime/src/filesystem/bind.rs +437 -245
  22. data/crates/kobako-runtime/src/filesystem/overlay/file.rs +6 -6
  23. data/crates/kobako-runtime/src/filesystem/overlay/path.rs +43 -65
  24. data/crates/kobako-runtime/src/filesystem/overlay/stack/copy_up.rs +9 -16
  25. data/crates/kobako-runtime/src/filesystem/overlay/stack/dir.rs +47 -72
  26. data/crates/kobako-runtime/src/filesystem/overlay/stack/namei.rs +12 -12
  27. data/crates/kobako-runtime/src/filesystem/overlay/stack/readdir.rs +4 -7
  28. data/crates/kobako-runtime/src/filesystem/overlay/stack.rs +121 -37
  29. data/crates/kobako-runtime/src/filesystem/overlay.rs +302 -343
  30. data/crates/kobako-runtime/src/filesystem/pipe.rs +12 -9
  31. data/crates/kobako-runtime/src/filesystem/rdir.rs +15 -32
  32. data/crates/kobako-runtime/src/filesystem/tmpfs/seed.rs +32 -0
  33. data/crates/kobako-runtime/src/filesystem/tmpfs/tmpfile.rs +3 -3
  34. data/crates/kobako-runtime/src/filesystem/tmpfs/whiteout.rs +57 -35
  35. data/crates/kobako-runtime/src/filesystem/tmpfs/xattr.rs +2 -2
  36. data/crates/kobako-runtime/src/filesystem/tmpfs.rs +172 -160
  37. data/crates/kobako-runtime/src/filesystem/wrap.rs +36 -52
  38. data/crates/kobako-runtime/src/filesystem.rs +6 -3
  39. data/crates/kobako-runtime/src/fork.rs +96 -0
  40. data/crates/kobako-runtime/src/grant.rs +3 -0
  41. data/crates/kobako-runtime/src/hashtable.rs +4 -2
  42. data/crates/kobako-runtime/src/lib.rs +18 -7
  43. data/crates/kobako-runtime/src/limits.rs +195 -0
  44. data/crates/kobako-runtime/src/locking.rs +10 -0
  45. data/crates/kobako-runtime/src/memcg.rs +383 -0
  46. data/crates/kobako-runtime/src/mount.rs +67 -9
  47. data/crates/kobako-runtime/src/net/backends.rs +43 -0
  48. data/crates/kobako-runtime/src/net/connections.rs +179 -0
  49. data/crates/kobako-runtime/src/net/credential.rs +125 -0
  50. data/crates/kobako-runtime/src/net/egress.rs +160 -0
  51. data/crates/kobako-runtime/src/net/family.rs +181 -0
  52. data/crates/kobako-runtime/src/net/http.rs +2733 -0
  53. data/crates/kobako-runtime/src/net/lookup.rs +285 -0
  54. data/crates/kobako-runtime/src/net/mock.rs +251 -0
  55. data/crates/kobako-runtime/src/net/namespace.rs +1366 -0
  56. data/crates/kobako-runtime/src/net/reactor.rs +531 -0
  57. data/crates/kobako-runtime/src/net/resolv/darwin.rs +275 -0
  58. data/crates/kobako-runtime/src/net/resolv/stub/tests.rs +469 -0
  59. data/crates/kobako-runtime/src/net/resolv/stub.rs +536 -0
  60. data/crates/kobako-runtime/src/net/resolv/windows.rs +248 -0
  61. data/crates/kobako-runtime/src/net/resolv.rs +227 -0
  62. data/crates/kobako-runtime/src/net/socket.rs +870 -0
  63. data/crates/kobako-runtime/src/net/tcp.rs +1588 -0
  64. data/crates/kobako-runtime/src/net/tls.rs +58 -0
  65. data/crates/kobako-runtime/src/net/transport.rs +279 -0
  66. data/crates/kobako-runtime/src/net/udp.rs +1003 -0
  67. data/crates/kobako-runtime/src/net.rs +42 -0
  68. data/crates/kobako-runtime/src/network/builder.rs +177 -0
  69. data/crates/kobako-runtime/src/network/ruleset.rs +777 -0
  70. data/crates/kobako-runtime/src/network.rs +551 -0
  71. data/crates/kobako-runtime/src/policy.rs +16 -0
  72. data/crates/kobako-runtime/src/profile.rs +29 -144
  73. data/crates/kobako-runtime/src/runtime.rs +3 -5
  74. data/crates/kobako-runtime/src/sched.rs +130 -29
  75. data/crates/kobako-runtime/src/security/entry_policy.rs +22 -0
  76. data/crates/kobako-runtime/src/{vfs/cred.rs → security/hooks.rs} +52 -144
  77. data/crates/kobako-runtime/src/security/mount_policy.rs +158 -0
  78. data/crates/kobako-runtime/src/security.rs +101 -196
  79. data/crates/kobako-runtime/src/snapshot.rs +121 -2
  80. data/crates/kobako-runtime/src/vfs/attr.rs +5 -5
  81. data/crates/kobako-runtime/src/vfs/dentry.rs +143 -89
  82. data/crates/kobako-runtime/src/vfs/file.rs +199 -203
  83. data/crates/kobako-runtime/src/vfs/inode.rs +41 -45
  84. data/crates/kobako-runtime/src/vfs/kern_path.rs +38 -42
  85. data/crates/kobako-runtime/src/vfs/mount.rs +10 -9
  86. data/crates/kobako-runtime/src/vfs/namei.rs +829 -700
  87. data/crates/kobako-runtime/src/vfs/namespace.rs +162 -0
  88. data/crates/kobako-runtime/src/vfs/open_files.rs +69 -0
  89. data/crates/kobako-runtime/src/vfs/openat2.rs +3 -3
  90. data/crates/kobako-runtime/src/vfs/path.rs +6 -6
  91. data/crates/kobako-runtime/src/vfs/readdir.rs +6 -6
  92. data/crates/kobako-runtime/src/vfs/stat.rs +159 -23
  93. data/crates/kobako-runtime/src/vfs/super_block.rs +18 -14
  94. data/crates/kobako-runtime/src/vfs/utimes.rs +37 -27
  95. data/crates/kobako-runtime/src/vfs.rs +9 -6
  96. data/crates/kobako-runtime/src/wait.rs +356 -0
  97. data/crates/kobako-transport/CHANGELOG.md +31 -0
  98. data/crates/kobako-transport/Cargo.toml +1 -1
  99. data/crates/kobako-transport/README.md +3 -4
  100. data/crates/kobako-transport/src/abi.rs +78 -72
  101. data/crates/kobako-transport/src/envelope/bytes.rs +17 -6
  102. data/crates/kobako-transport/src/envelope/call.rs +32 -4
  103. data/crates/kobako-transport/src/envelope/error_record.rs +21 -0
  104. data/crates/kobako-transport/src/envelope/name.rs +99 -0
  105. data/crates/kobako-transport/src/envelope/outcome.rs +9 -9
  106. data/crates/kobako-transport/src/envelope/preamble.rs +24 -21
  107. data/crates/kobako-transport/src/envelope/reply.rs +27 -27
  108. data/crates/kobako-transport/src/envelope/unsupported.rs +10 -10
  109. data/crates/kobako-transport/src/envelope.rs +13 -8
  110. data/crates/kobako-wasmtime/CHANGELOG.md +161 -0
  111. data/crates/kobako-wasmtime/Cargo.toml +26 -7
  112. data/crates/kobako-wasmtime/README.md +3 -2
  113. data/crates/kobako-wasmtime/build/preview2.rs +1339 -0
  114. data/crates/kobako-wasmtime/build.rs +16 -0
  115. data/crates/kobako-wasmtime/src/abi.rs +17 -37
  116. data/crates/kobako-wasmtime/src/ambient.rs +33 -18
  117. data/crates/kobako-wasmtime/src/cache.rs +23 -15
  118. data/crates/kobako-wasmtime/src/config.rs +52 -68
  119. data/crates/kobako-wasmtime/src/driver.rs +48 -63
  120. data/crates/kobako-wasmtime/src/exports.rs +143 -17
  121. data/crates/kobako-wasmtime/src/guest.rs +12 -6
  122. data/crates/kobako-wasmtime/src/guest_binary.rs +14 -0
  123. data/crates/kobako-wasmtime/src/imports.rs +42 -18
  124. data/crates/kobako-wasmtime/src/instance_pre.rs +4 -4
  125. data/crates/kobako-wasmtime/src/invocation.rs +74 -12
  126. data/crates/kobako-wasmtime/src/lib.rs +5 -3
  127. data/crates/kobako-wasmtime/src/limiter.rs +70 -5
  128. data/crates/kobako-wasmtime/src/preview1/descriptors.rs +309 -0
  129. data/crates/kobako-wasmtime/src/preview1/differential/mount.rs +5 -15
  130. data/crates/kobako-wasmtime/src/preview1/differential.rs +27 -31
  131. data/crates/kobako-wasmtime/src/preview1/errno.rs +55 -66
  132. data/crates/kobako-wasmtime/src/preview1/fd.rs +327 -296
  133. data/crates/kobako-wasmtime/src/preview1/memory.rs +21 -12
  134. data/crates/kobako-wasmtime/src/preview1/mount_view/wrap.rs +34 -53
  135. data/crates/kobako-wasmtime/src/preview1/mount_view.rs +231 -217
  136. data/crates/kobako-wasmtime/src/preview1/path.rs +56 -121
  137. data/crates/kobako-wasmtime/src/preview1/poll.rs +244 -120
  138. data/crates/kobako-wasmtime/src/preview1/sock.rs +10 -8
  139. data/crates/kobako-wasmtime/src/preview1/testsuite.rs +5 -15
  140. data/crates/kobako-wasmtime/src/preview1.rs +46 -42
  141. data/crates/kobako-wasmtime/src/preview2/abi.rs +227 -0
  142. data/crates/kobako-wasmtime/src/preview2/error.rs +118 -0
  143. data/crates/kobako-wasmtime/src/preview2/filesystem.rs +122 -0
  144. data/crates/kobako-wasmtime/src/preview2/host.rs +3959 -0
  145. data/crates/kobako-wasmtime/src/preview2/http.rs +1503 -0
  146. data/crates/kobako-wasmtime/src/preview2/io.rs +315 -0
  147. data/crates/kobako-wasmtime/src/preview2/sockets.rs +379 -0
  148. data/crates/kobako-wasmtime/src/preview2/table.rs +305 -0
  149. data/crates/kobako-wasmtime/src/preview2.rs +57 -0
  150. data/crates/kobako-wasmtime/src/trap.rs +24 -9
  151. data/crates/kobako-wasmtime/src/wasi.rs +210 -81
  152. data/crates/kobako-wasmtime/wit/deps/cli.wit +233 -0
  153. data/crates/kobako-wasmtime/wit/deps/clocks.wit +162 -0
  154. data/crates/kobako-wasmtime/wit/deps/filesystem.wit +589 -0
  155. data/crates/kobako-wasmtime/wit/deps/http.wit +733 -0
  156. data/crates/kobako-wasmtime/wit/deps/io.wit +299 -0
  157. data/crates/kobako-wasmtime/wit/deps/random.wit +92 -0
  158. data/crates/kobako-wasmtime/wit/deps/sockets.wit +949 -0
  159. data/data/kobako.wasm +0 -0
  160. data/ext/kobako/Cargo.toml +1 -1
  161. data/ext/kobako/src/{runtime/errors.rs → errors.rs} +34 -26
  162. data/ext/kobako/src/{runtime/escape.rs → escape.rs} +42 -11
  163. data/ext/kobako/src/{runtime/filesystem → filesystem}/grants.rs +30 -26
  164. data/ext/kobako/src/{runtime/filesystem → filesystem}/ruby.rs +149 -168
  165. data/ext/kobako/src/{runtime/filesystem.rs → filesystem.rs} +24 -15
  166. data/ext/kobako/src/gvl.rs +306 -0
  167. data/ext/kobako/src/lib.rs +64 -3
  168. data/ext/kobako/src/network/mock.rs +187 -0
  169. data/ext/kobako/src/network.rs +591 -0
  170. data/ext/kobako/src/runtime/bridge.rs +30 -29
  171. data/ext/kobako/src/runtime/snapshot.rs +4 -4
  172. data/ext/kobako/src/runtime.rs +221 -143
  173. data/ext/kobako/src/wire.rs +42 -0
  174. data/lib/kobako/catalog/extensions.rb +14 -2
  175. data/lib/kobako/catalog/flags.rb +3 -5
  176. data/lib/kobako/catalog/grants.rb +5 -4
  177. data/lib/kobako/catalog/handles.rb +5 -27
  178. data/lib/kobako/catalog/mount.rb +11 -3
  179. data/lib/kobako/catalog/network.rb +35 -0
  180. data/lib/kobako/catalog/replacements.rb +28 -0
  181. data/lib/kobako/catalog/services.rb +5 -19
  182. data/lib/kobako/catalog/snippets.rb +3 -18
  183. data/lib/kobako/catalog.rb +3 -0
  184. data/lib/kobako/codec/{utils.rb → boundary.rb} +4 -2
  185. data/lib/kobako/codec/decoder.rb +4 -4
  186. data/lib/kobako/codec/ext_types.rb +3 -3
  187. data/lib/kobako/codec/handle_walk.rb +3 -43
  188. data/lib/kobako/codec/value_budget.rb +132 -40
  189. data/lib/kobako/codec.rb +1 -1
  190. data/lib/kobako/context.rb +24 -11
  191. data/lib/kobako/errors.rb +15 -12
  192. data/lib/kobako/extension.rb +3 -2
  193. data/lib/kobako/filesystem.rb +9 -2
  194. data/lib/kobako/handle.rb +2 -2
  195. data/lib/kobako/names.rb +28 -0
  196. data/lib/kobako/network.rb +210 -0
  197. data/lib/kobako/outcome.rb +7 -7
  198. data/lib/kobako/pool.rb +45 -23
  199. data/lib/kobako/runtime.rb +3 -2
  200. data/lib/kobako/sandbox.rb +92 -35
  201. data/lib/kobako/sandbox_options.rb +41 -106
  202. data/lib/kobako/transport/argument_wrap.rb +64 -0
  203. data/lib/kobako/transport/block_failure.rb +1 -1
  204. data/lib/kobako/transport/dispatcher.rb +6 -6
  205. data/lib/kobako/transport/exposure.rb +26 -15
  206. data/lib/kobako/transport/reflection.rb +21 -4
  207. data/lib/kobako/transport/run.rb +8 -23
  208. data/lib/kobako/transport/yielder.rb +2 -9
  209. data/lib/kobako/transport.rb +1 -0
  210. data/lib/kobako/version.rb +1 -1
  211. data/lib/kobako.rb +6 -2
  212. data/release-please-config.json +15 -0
  213. data/sig/core/thread.rbs +6 -0
  214. data/sig/kobako/catalog/extensions.rbs +2 -0
  215. data/sig/kobako/catalog/grants.rbs +7 -4
  216. data/sig/kobako/catalog/handles.rbs +0 -2
  217. data/sig/kobako/catalog/mount.rbs +3 -1
  218. data/sig/kobako/catalog/network.rbs +20 -0
  219. data/sig/kobako/catalog/replacements.rbs +14 -0
  220. data/sig/kobako/catalog/services.rbs +0 -4
  221. data/sig/kobako/catalog/snippets.rbs +0 -2
  222. data/sig/kobako/codec/{utils.rbs → boundary.rbs} +2 -2
  223. data/sig/kobako/codec/handle_walk.rbs +0 -6
  224. data/sig/kobako/codec/value_budget.rbs +47 -4
  225. data/sig/kobako/context.rbs +3 -1
  226. data/sig/kobako/errors.rbs +4 -4
  227. data/sig/kobako/filesystem.rbs +21 -3
  228. data/sig/kobako/network.rbs +115 -0
  229. data/sig/kobako/outcome.rbs +1 -1
  230. data/sig/kobako/pool.rbs +7 -3
  231. data/sig/kobako/runtime.rbs +32 -3
  232. data/sig/kobako/sandbox.rbs +19 -2
  233. data/sig/kobako/sandbox_options.rbs +29 -38
  234. data/sig/kobako/transport/argument_wrap.rbs +15 -0
  235. data/sig/kobako/transport/error.rbs +1 -1
  236. data/sig/kobako/transport/exposure.rbs +2 -4
  237. data/sig/kobako/transport/reflection.rbs +10 -0
  238. data/sig/kobako/transport/run.rbs +0 -2
  239. data/sig/kobako/transport/yielder.rbs +0 -3
  240. data/sig/kobako/transport.rbs +1 -1
  241. data/sig/kobako.rbs +13 -0
  242. metadata +84 -35
  243. data/crates/kobako-runtime/src/endpoint/capture.rs +0 -115
  244. data/crates/kobako-runtime/src/endpoint/memory_cap.rs +0 -238
  245. data/crates/kobako-runtime/src/filesystem/path.rs +0 -21
  246. data/crates/kobako-runtime/src/vfs/errno.rs +0 -153
  247. data/crates/kobako-runtime/tests/linux_baseline/calls.rs +0 -171
  248. data/crates/kobako-runtime/tests/linux_baseline/concurrent.rs +0 -276
  249. data/crates/kobako-runtime/tests/linux_baseline/kobako.rs +0 -323
  250. data/crates/kobako-runtime/tests/linux_baseline/linux-baseline-expected.txt +0 -16
  251. data/crates/kobako-runtime/tests/linux_baseline/linux.rs +0 -449
  252. data/crates/kobako-runtime/tests/linux_baseline/main.rs +0 -611
  253. data/crates/kobako-runtime/tests/linux_baseline/permissions.rs +0 -236
  254. data/crates/kobako-wasmtime/src/descriptors.rs +0 -200
  255. data/crates/kobako-wasmtime/tests/integration/compile_posture.rs +0 -43
  256. data/crates/kobako-wasmtime/tests/integration/guest_file.rs +0 -1085
  257. data/crates/kobako-wasmtime/tests/integration/main.rs +0 -29
  258. data/crates/kobako-wasmtime/tests/integration/preamble_flags.rs +0 -70
  259. data/crates/kobako-wasmtime/tests/integration/snippet_compile.rs +0 -95
  260. data/crates/kobako-wasmtime/tests/integration/support/mod.rs +0 -30
  261. data/crates/kobako-wasmtime/tests/integration/unanswered_call.rs +0 -86
  262. data/crates/kobako-wasmtime/tests/integration/unsupported_call.rs +0 -51
  263. data/ext/kobako/src/runtime/gvl.rs +0 -147
  264. data/lib/kobako/constant_name.rb +0 -8
  265. data/sig/kobako/constant_name.rbs +0 -3
  266. /data/ext/kobako/src/{runtime/pinned_value.rs → pinned_value.rs} +0 -0
@@ -15,7 +15,6 @@ use std::rc::Rc;
15
15
  use std::sync::Arc;
16
16
 
17
17
  use super::attr::notify_change;
18
- use super::cred::{on_path, Cred, FileSecurity};
19
18
  use super::dentry::{Dentry, RENAME_LOCK};
20
19
  use super::file::{do_dentry_open, FMode, File, FileOperations};
21
20
  use super::inode::{Finish, Inode, Mask, RenameFlag};
@@ -23,8 +22,10 @@ use super::mount::VfsMount;
23
22
  use super::openat2::{OpenFlags, OpenHow};
24
23
  use super::path::{Path, Start};
25
24
  use super::super_block::SuperBlock;
26
- use super::{FileType, FilesystemError, Iattr, Kstat};
25
+ use super::{Errno, FileType, Iattr, Kstat};
26
+ use crate::cred::Cred;
27
27
  use crate::locking::RwSemaphoreGuard;
28
+ use crate::security::{on_path, FileSecurity};
28
29
 
29
30
  use super::PATH_MAX;
30
31
 
@@ -53,10 +54,22 @@ pub(crate) struct Nameidata {
53
54
  r_seq: usize,
54
55
  /// The directory the walk stands in, which holds the last name.
55
56
  dir: Arc<Dentry>,
57
+ /// Where the walk stood each time it stepped onto a mount, innermost last,
58
+ /// so a `..` from that mount's root climbs back, as `choose_mountpoint`
59
+ /// follows `mnt_parent`. The walk keeps them itself: a mount may stand where
60
+ /// its parent holds no entry for it.
61
+ crossed: Vec<(Arc<VfsMount>, Arc<Dentry>)>,
56
62
  pending: VecDeque<String>,
57
63
  /// The links followed through every walk of one call, as Linux's
58
64
  /// `total_link_count` carries into a walk made again for ESTALE.
59
65
  total_link_count: Rc<Cell<usize>>,
66
+ /// Each dentry this walk stepped onto by a name, a link it followed
67
+ /// included, kept only for a walk placing a mount, so the mount holds the
68
+ /// names its path leads through.
69
+ pub(crate) trail: Vec<Arc<Dentry>>,
70
+ /// Whether this walk keeps its `trail`, as only one placing a mount
71
+ /// reads it.
72
+ keeps_trail: bool,
60
73
  /// The last name, as Linux's `nd->last`, empty unless it is a `Norm` one.
61
74
  pub(crate) last: String,
62
75
  last_type: LastType,
@@ -86,24 +99,27 @@ impl Nameidata {
86
99
  /// Refuse what the walk ended on unless it still stands beneath where the
87
100
  /// walk started, as `complete_walk` asks `path_is_under` once a move may have
88
101
  /// 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);
102
+ fn complete_walk(&self) -> Result<(), Errno> {
103
+ let ended = match self.crossed.first() {
104
+ Some((_, below_start)) => below_start,
105
+ None => self.path.as_ref().unwrap_or(&self.dir),
106
+ };
91
107
  match ended.is_subdir(&self.root) {
92
108
  true => Ok(()),
93
- false => Err(FilesystemError::Escape),
109
+ false => Err(Errno::Escape),
94
110
  }
95
111
  }
96
112
 
97
113
  /// The dentry the walk ended on, as Linux's `do_open` and `vfs_getattr`
98
114
  /// act on what the walk found without looking it up again, so a change
99
115
  /// 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)
116
+ pub(crate) fn path(&self) -> Result<Arc<Dentry>, Errno> {
117
+ self.path.clone().ok_or(Errno::NotFound)
102
118
  }
103
119
 
104
120
  /// Find the last name afresh and keep what stands there, as a call looks
105
121
  /// its name up once it holds the directory's lock.
106
- fn lookup_last_locked(&mut self) -> Result<Arc<Dentry>, FilesystemError> {
122
+ fn lookup_last_locked(&mut self) -> Result<Arc<Dentry>, Errno> {
107
123
  let child = lookup_one_qstr_excl(self.mnt.sb(), self.dentry(), &self.last)?;
108
124
  self.path = Some(child.clone());
109
125
  Ok(child)
@@ -111,13 +127,13 @@ impl Nameidata {
111
127
 
112
128
  /// What kind of entry the walk ended on, a link reported as itself, read
113
129
  /// from the dentry as Linux's `d_is_*` do.
114
- pub(crate) fn kind(&self) -> Result<FileType, FilesystemError> {
115
- self.path()?.kind()
130
+ pub(crate) fn file_type(&self) -> Result<FileType, Errno> {
131
+ self.path()?.file_type()
116
132
  }
117
133
 
118
134
  /// What the walk ended on reports of itself, a link reported as itself, as
119
135
  /// `vfs_getattr` asks the entry the walk found.
120
- pub(crate) fn getattr(&self) -> Result<Kstat, FilesystemError> {
136
+ pub(crate) fn getattr(&self) -> Result<Kstat, Errno> {
121
137
  self.path()?.getattr()
122
138
  }
123
139
  }
@@ -125,18 +141,27 @@ impl Nameidata {
125
141
  /// Whether `dentry`, which a lookup answered for, still names what stands at its
126
142
  /// name in `dir`, asked with or without `dir`'s lock as Linux's `lookup_fast`
127
143
  /// 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.
144
+ /// names kept beneath it, as `d_invalidate` does, unless a move landed while it
145
+ /// was asked: the answer was about a name it no longer stands at, so the walk
146
+ /// looks again, as `lookup_fast` retries once `d_seq` moved.
129
147
  pub(crate) fn d_revalidate(
130
148
  sb: &SuperBlock,
131
149
  dir: &Dentry,
132
150
  dentry: &Arc<Dentry>,
133
- ) -> Result<bool, FilesystemError> {
151
+ ) -> Result<bool, Errno> {
152
+ // A mount point stays whatever its Filesystem answers: Linux's
153
+ // `d_invalidate` detaches the mounts on it, which would show the guest
154
+ // what they hid.
155
+ if dentry.d_mountpoint() {
156
+ return Ok(true);
157
+ }
158
+ let asked = RENAME_LOCK.read_seqbegin();
134
159
  let valid = match dentry.ops() {
135
160
  Some(ops) => ops.revalidate(dir.inode_ops()?.as_ref(), dentry)?,
136
161
  None => true,
137
162
  };
138
163
  if !valid {
139
- sb.dentries().invalidate(dentry);
164
+ sb.dentries().invalidate(dentry, asked);
140
165
  }
141
166
  Ok(valid)
142
167
  }
@@ -148,7 +173,7 @@ pub(crate) fn lookup_one_qstr_excl(
148
173
  sb: &SuperBlock,
149
174
  parent: &Arc<Dentry>,
150
175
  name: &str,
151
- ) -> Result<Arc<Dentry>, FilesystemError> {
176
+ ) -> Result<Arc<Dentry>, Errno> {
152
177
  __lookup_slow(sb, parent, name)
153
178
  }
154
179
 
@@ -159,13 +184,9 @@ pub(crate) fn lookup_one_qstr_excl(
159
184
  /// reaching one entry shares its dentry, and so its lock. A directory removed
160
185
  /// through the VFS is asked about no name, as Linux refuses a dead one. The
161
186
  /// 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> {
187
+ fn __lookup_slow(sb: &SuperBlock, parent: &Arc<Dentry>, name: &str) -> Result<Arc<Dentry>, Errno> {
167
188
  if parent.is_deaddir() {
168
- return Err(FilesystemError::NotFound);
189
+ return Err(Errno::NotFound);
169
190
  }
170
191
  let given = d_alloc_parallel(sb, parent, name)?;
171
192
  let dentry = given.lookup_inode(sb, parent)?.unwrap_or(given);
@@ -189,7 +210,7 @@ fn d_alloc_parallel(
189
210
  sb: &SuperBlock,
190
211
  parent: &Arc<Dentry>,
191
212
  name: &str,
192
- ) -> Result<Arc<Dentry>, FilesystemError> {
213
+ ) -> Result<Arc<Dentry>, Errno> {
193
214
  loop {
194
215
  let dentry = sb.dentries().alloc_parallel(parent, name)?;
195
216
  if dentry.in_lookup() || d_revalidate(sb, parent, &dentry)? {
@@ -206,7 +227,7 @@ fn lookup_fast(
206
227
  sb: &SuperBlock,
207
228
  parent: &Arc<Dentry>,
208
229
  name: &str,
209
- ) -> Result<Option<Arc<Dentry>>, FilesystemError> {
230
+ ) -> Result<Option<Arc<Dentry>>, Errno> {
210
231
  let Some(dentry) = sb.dentries().lookup(parent, name) else {
211
232
  return Ok(None);
212
233
  };
@@ -221,11 +242,11 @@ fn lookup_fast(
221
242
  /// dcache holds or, failing that, one found holding that directory's lock
222
243
  /// shared, as Linux's `walk_component` tries `lookup_fast` before
223
244
  /// `lookup_slow`.
224
- fn lookup_dentry(
245
+ pub(super) fn lookup_dentry(
225
246
  sb: &SuperBlock,
226
247
  parent: &Arc<Dentry>,
227
248
  name: &str,
228
- ) -> Result<Arc<Dentry>, FilesystemError> {
249
+ ) -> Result<Arc<Dentry>, Errno> {
229
250
  match lookup_fast(sb, parent, name)? {
230
251
  Some(dentry) => Ok(dentry),
231
252
  None => lookup_slow(sb, parent, name),
@@ -239,9 +260,9 @@ fn lookup_one_common(
239
260
  sb: &SuperBlock,
240
261
  parent: &Dentry,
241
262
  name: &str,
242
- ) -> Result<(), FilesystemError> {
263
+ ) -> Result<(), Errno> {
243
264
  if name.is_empty() || name == "." || name == ".." || name.contains(['/', '\0']) {
244
- return Err(FilesystemError::PermissionDenied);
265
+ return Err(Errno::PermissionDenied);
245
266
  }
246
267
  inode_permission(cred, sb, parent, Mask::EXEC)
247
268
  }
@@ -254,7 +275,7 @@ pub(crate) fn lookup_one_unlocked(
254
275
  sb: &SuperBlock,
255
276
  parent: &Arc<Dentry>,
256
277
  name: &str,
257
- ) -> Result<Arc<Dentry>, FilesystemError> {
278
+ ) -> Result<Arc<Dentry>, Errno> {
258
279
  lookup_one_common(cred, sb, parent, name)?;
259
280
  lookup_dentry(sb, parent, name)
260
281
  }
@@ -267,7 +288,7 @@ pub(crate) fn start_creating(
267
288
  sb: &SuperBlock,
268
289
  parent: &Arc<Dentry>,
269
290
  name: &str,
270
- ) -> Result<(RwSemaphoreGuard, Arc<Dentry>), FilesystemError> {
291
+ ) -> Result<(RwSemaphoreGuard, Arc<Dentry>), Errno> {
271
292
  lookup_one_common(cred, sb, parent, name)?;
272
293
  let held = parent.inode_lock()?;
273
294
  Ok((held, __lookup_slow(sb, parent, name)?))
@@ -281,19 +302,15 @@ pub(crate) fn start_removing(
281
302
  sb: &SuperBlock,
282
303
  parent: &Arc<Dentry>,
283
304
  name: &str,
284
- ) -> Result<(RwSemaphoreGuard, Arc<Dentry>), FilesystemError> {
305
+ ) -> Result<(RwSemaphoreGuard, Arc<Dentry>), Errno> {
285
306
  let (held, child) = start_creating(cred, sb, parent, name)?;
286
- child.inode().ok_or(FilesystemError::NotFound)?;
307
+ child.inode().ok_or(Errno::NotFound)?;
287
308
  Ok((held, child))
288
309
  }
289
310
 
290
311
  /// The dentry of `name` in `parent` for a walk passing through, holding that
291
312
  /// 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> {
313
+ fn lookup_slow(sb: &SuperBlock, parent: &Arc<Dentry>, name: &str) -> Result<Arc<Dentry>, Errno> {
297
314
  let _held = parent.inode_lock_shared()?;
298
315
  __lookup_slow(sb, parent, name)
299
316
  }
@@ -304,30 +321,74 @@ fn parts(path: &str) -> VecDeque<String> {
304
321
  }
305
322
 
306
323
  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> {
324
+ /// The mount standing on the dentry `name` reaches in the directory the walk
325
+ /// stands in, by whatever spelling or link reached that dentry.
326
+ fn lookup_mnt_by_name(&self, name: &str) -> Result<Option<Arc<VfsMount>>, Errno> {
327
+ if !self.cred.mnt_ns().has_children(&self.mnt) {
328
+ return Ok(None);
329
+ }
330
+ let dentry = lookup_dentry(self.mnt.sb(), &self.dir, name)?;
331
+ Ok(self.lookup_mnt(&dentry))
332
+ }
333
+
334
+ /// The mount standing on `dentry` beneath the mount the walk stands on, as
335
+ /// `__traverse_mounts` asks `DCACHE_MOUNTED` before `lookup_mnt`.
336
+ fn lookup_mnt(&self, dentry: &Arc<Dentry>) -> Option<Arc<VfsMount>> {
337
+ match dentry.d_mountpoint() {
338
+ true => self.cred.mnt_ns().__lookup_mnt(&self.mnt, dentry),
339
+ false => None,
340
+ }
341
+ }
342
+
343
+ /// Step onto the root of `mnt`, or of the topmost mount stacked over it,
344
+ /// keeping where the walk stood, as `__traverse_mounts` follows a mount
345
+ /// point down to what is mounted there, however many stand on it.
346
+ fn traverse_mounts(&mut self, mnt: Arc<VfsMount>) {
347
+ let mnt = self.cred.mnt_ns().topmost_overmount(&mnt);
348
+ let dir = std::mem::replace(&mut self.dir, mnt.root().clone());
349
+ self.crossed
350
+ .push((std::mem::replace(&mut self.mnt, mnt), dir));
351
+ }
352
+
353
+ /// Step into the directory `name` names, or onto the mount standing there,
354
+ /// or follow the link standing there.
355
+ fn walk_component(&mut self, name: &str) -> Result<(), Errno> {
309
356
  let dentry = lookup_dentry(self.mnt.sb(), self.dentry(), name)?;
310
- let inode = dentry.inode().ok_or(FilesystemError::NotFound)?;
311
- match inode.kind() {
357
+ if let Some(mnt) = self.lookup_mnt(&dentry) {
358
+ self.record_step(&dentry);
359
+ self.traverse_mounts(mnt);
360
+ return Ok(());
361
+ }
362
+ let inode = dentry.inode().ok_or(Errno::NotFound)?;
363
+ match inode.file_type() {
312
364
  FileType::Symlink => self.pick_link(&dentry),
313
365
  FileType::Dir => {
366
+ self.record_step(&dentry);
314
367
  self.dir = dentry;
315
368
  Ok(())
316
369
  }
317
- _ => Err(FilesystemError::NotADirectory),
370
+ _ => Err(Errno::NotADirectory),
371
+ }
372
+ }
373
+
374
+ /// Add `dentry` to the trail of a walk that keeps one.
375
+ fn record_step(&mut self, dentry: &Arc<Dentry>) {
376
+ if self.keeps_trail {
377
+ self.trail.push(Arc::clone(dentry));
318
378
  }
319
379
  }
320
380
 
321
381
  /// Walk on through where the link `dentry` names points, before
322
382
  /// whatever is left of the path.
323
- fn pick_link(&mut self, dentry: &Dentry) -> Result<(), FilesystemError> {
383
+ fn pick_link(&mut self, dentry: &Arc<Dentry>) -> Result<(), Errno> {
324
384
  self.total_link_count.set(self.total_link_count.get() + 1);
385
+ self.record_step(dentry);
325
386
  if self.total_link_count.get() > MAXSYMLINKS {
326
- return Err(FilesystemError::FilesystemLoop);
387
+ return Err(Errno::FilesystemLoop);
327
388
  }
328
389
  let target = dentry.get_link()?;
329
390
  if target.starts_with('/') {
330
- return Err(FilesystemError::Escape);
391
+ return Err(Errno::Escape);
331
392
  }
332
393
  // A link pointing nowhere leaves the walk where it stands, as Linux's
333
394
  // `pick_link` makes it a pure jump.
@@ -342,28 +403,37 @@ impl Nameidata {
342
403
  }
343
404
 
344
405
  /// 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();
406
+ /// one stands now, as `follow_dotdot` reads `d_parent`. From the root of a
407
+ /// mount the walk stepped onto, it climbs back to where the walk stood, as
408
+ /// `choose_mountpoint` leads to the mount point. Out of the one the walk
409
+ /// started from, or a mount's root it never stepped onto, no `..` holds a
410
+ /// capability, as `RESOLVE_BENEATH` refuses a caller's and a link's alike.
411
+ fn follow_dotdot(&mut self) -> Result<(), Errno> {
412
+ if Arc::ptr_eq(&self.dir, &self.root) {
413
+ return Err(Errno::Escape);
414
+ }
415
+ if self.dir.is_root() {
416
+ let (mnt, dir) = self.crossed.pop().ok_or(Errno::Escape)?;
417
+ self.mnt = mnt;
418
+ self.dir = dir;
419
+ } else {
420
+ self.dir = self.dir.parent();
421
+ }
353
422
  // 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.
423
+ // so the caller makes the call again, as `handle_dots` answers a scoped walk
424
+ // however the `..` was taken.
355
425
  if RENAME_LOCK.read_seqretry(self.r_seq) {
356
- return Err(FilesystemError::WouldBlock);
426
+ return Err(Errno::WouldBlock);
357
427
  }
358
428
  Ok(())
359
429
  }
360
430
 
361
431
  /// Walk every name but the last, which is left for the call to act on, as
362
432
  /// Linux's `link_path_walk` leaves `nd->last` and `nd->last_type`.
363
- fn link_path_walk(&mut self) -> Result<(), FilesystemError> {
433
+ fn link_path_walk(&mut self) -> Result<(), Errno> {
364
434
  loop {
365
435
  inode_permission(&self.cred, self.mnt.sb(), self.dentry(), Mask::EXEC)?;
366
- let part = self.pending.pop_front().ok_or(FilesystemError::NotFound)?;
436
+ let part = self.pending.pop_front().ok_or(Errno::NotFound)?;
367
437
  let slashes = self
368
438
  .pending
369
439
  .iter()
@@ -396,8 +466,19 @@ impl Nameidata {
396
466
  self.trailing_slash = trailing_slash;
397
467
  }
398
468
 
469
+ /// Stand on the root of the mount standing on the last name, if one does,
470
+ /// as `step_into` answers a mount point with what is mounted there.
471
+ fn step_onto_last_mount(&mut self) -> Result<bool, Errno> {
472
+ let Some(mnt) = self.lookup_mnt_by_name(&self.last)? else {
473
+ return Ok(false);
474
+ };
475
+ self.traverse_mounts(mnt);
476
+ self.path = Some(self.dir.clone());
477
+ Ok(true)
478
+ }
479
+
399
480
  /// Stand where a last `.` or `..` leads, as Linux's `handle_dots` does.
400
- fn handle_dots(&mut self) -> Result<(), FilesystemError> {
481
+ fn handle_dots(&mut self) -> Result<(), Errno> {
401
482
  if self.last_type == LastType::DotDot {
402
483
  self.follow_dotdot()?;
403
484
  }
@@ -409,7 +490,7 @@ impl Nameidata {
409
490
  /// trailing `/` follows a link there and asks for a directory, a link
410
491
  /// followed leaves another last name to find, and nothing standing there is
411
492
  /// ENOENT, as `step_into` answers before the walk is checked.
412
- fn lookup_last(&mut self, mut follow: bool) -> Result<(), FilesystemError> {
493
+ fn lookup_last(&mut self, mut follow: bool) -> Result<(), Errno> {
413
494
  loop {
414
495
  if self.last_type != LastType::Norm {
415
496
  return self.handle_dots();
@@ -418,12 +499,15 @@ impl Nameidata {
418
499
  follow = true;
419
500
  self.lookup_directory = true;
420
501
  }
502
+ if self.step_onto_last_mount()? {
503
+ return Ok(());
504
+ }
421
505
  let child = lookup_dentry(self.mnt.sb(), self.dentry(), &self.last)?;
422
506
  self.path = Some(child.clone());
423
507
  if child.inode().is_none() {
424
- return Err(FilesystemError::NotFound);
508
+ return Err(Errno::NotFound);
425
509
  }
426
- if !follow || child.kind() != Ok(FileType::Symlink) {
510
+ if !follow || child.file_type() != Ok(FileType::Symlink) {
427
511
  return Ok(());
428
512
  }
429
513
  self.pick_link(&child)?;
@@ -441,7 +525,7 @@ impl Nameidata {
441
525
  how: &OpenHow,
442
526
  mode: FMode,
443
527
  mut follow: bool,
444
- ) -> Result<Open, FilesystemError> {
528
+ ) -> Result<Open, Errno> {
445
529
  loop {
446
530
  if self.last_type != LastType::Norm {
447
531
  self.handle_dots()?;
@@ -449,23 +533,29 @@ impl Nameidata {
449
533
  }
450
534
  if self.trailing_slash {
451
535
  if how.create {
452
- return Err(FilesystemError::IsADirectory);
536
+ return Err(Errno::IsADirectory);
453
537
  }
454
538
  follow = true;
455
539
  self.lookup_directory = true;
456
540
  }
541
+ if self.step_onto_last_mount()? {
542
+ if how.create && how.exclusive {
543
+ return Err(Errno::AlreadyExists);
544
+ }
545
+ return Ok(Open { file: None, mode });
546
+ }
457
547
  let (child, opened) = match self.lookup_fast_for_open(how)? {
458
548
  Some(child) => {
459
549
  self.path = Some(child.clone());
460
550
  if child.inode().is_none() {
461
- return Err(FilesystemError::NotFound);
551
+ return Err(Errno::NotFound);
462
552
  }
463
553
  (child, Open { file: None, mode })
464
554
  }
465
555
  None => self.lookup_open(how, mode)?,
466
556
  };
467
557
  let finished = opened.file.is_some() || opened.mode.contains(FMode::CREATED);
468
- if finished || !follow || child.kind() != Ok(FileType::Symlink) {
558
+ if finished || !follow || child.file_type() != Ok(FileType::Symlink) {
469
559
  return Ok(opened);
470
560
  }
471
561
  self.pick_link(&child)?;
@@ -477,7 +567,7 @@ impl Nameidata {
477
567
  /// `lookup_fast_for_open` takes it without the directory's lock: none for
478
568
  /// an exclusive make, or where nothing stands at a name the open may make,
479
569
  /// as only `lookup_open` makes one.
480
- fn lookup_fast_for_open(&self, how: &OpenHow) -> Result<Option<Arc<Dentry>>, FilesystemError> {
570
+ fn lookup_fast_for_open(&self, how: &OpenHow) -> Result<Option<Arc<Dentry>>, Errno> {
481
571
  if how.create && how.exclusive {
482
572
  return Ok(None);
483
573
  }
@@ -497,14 +587,10 @@ impl Nameidata {
497
587
  /// only where nothing stands, as `create_error` does. A Filesystem opening
498
588
  /// the file too finishes it through `do_dentry_open` here, as its
499
589
  /// `finish_open` does.
500
- fn lookup_open(
501
- &mut self,
502
- how: &OpenHow,
503
- mode: FMode,
504
- ) -> Result<(Arc<Dentry>, Open), FilesystemError> {
590
+ fn lookup_open(&mut self, how: &OpenHow, mode: FMode) -> Result<(Arc<Dentry>, Open), Errno> {
505
591
  let got_write = match how.create || how.truncate || how.write {
506
592
  true => self.mnt.mnt_want_write(),
507
- false => Err(FilesystemError::ReadOnlyFilesystem),
593
+ false => Err(Errno::ReadOnlyFilesystem),
508
594
  };
509
595
  let dir = self.dentry().clone();
510
596
  let _held = match how.create {
@@ -512,7 +598,7 @@ impl Nameidata {
512
598
  false => dir.inode_lock_shared()?,
513
599
  };
514
600
  if dir.is_deaddir() {
515
- return Err(FilesystemError::NotFound);
601
+ return Err(Errno::NotFound);
516
602
  }
517
603
  let mnt = self.mnt.clone();
518
604
  let given = d_alloc_parallel(mnt.sb(), &dir, &self.last)?;
@@ -546,14 +632,14 @@ impl Nameidata {
546
632
  created,
547
633
  spliced,
548
634
  } = match (asked, &create_error) {
549
- (Err(FilesystemError::NotFound), Some(refused)) => return Err(refused.clone()),
635
+ (Err(Errno::NotFound), Some(refused)) => return Err(refused.clone()),
550
636
  (asked, _) => asked?,
551
637
  };
552
638
  let child = spliced.unwrap_or(given);
553
639
  retain(mnt.sb(), &child);
554
640
  self.path = Some(child.clone());
555
641
  if child.inode().is_none() {
556
- return Err(create_error.unwrap_or(FilesystemError::NotFound));
642
+ return Err(create_error.unwrap_or(Errno::NotFound));
557
643
  }
558
644
  let mode = match created {
559
645
  true => mode.with(FMode::CREATED),
@@ -561,7 +647,7 @@ impl Nameidata {
561
647
  };
562
648
  let file = match file {
563
649
  Some(file) => {
564
- let kind = child.kind()?;
650
+ let kind = child.file_type()?;
565
651
  let opened = on_path(&self.mnt, &child, |path| {
566
652
  do_dentry_open(&self.cred, path, kind, mode, how, || Ok(file))
567
653
  })?;
@@ -574,7 +660,7 @@ impl Nameidata {
574
660
 
575
661
  /// Whether the open may make the file `child` names here, as Linux's
576
662
  /// `may_o_create` asks once the mount took a write.
577
- fn may_o_create(&self, child: &Dentry) -> Result<(), FilesystemError> {
663
+ fn may_o_create(&self, child: &Dentry) -> Result<(), Errno> {
578
664
  on_path(&self.mnt, child, |path| self.cred.security_path_mknod(path))?;
579
665
  may_create_dentry(&self.cred, self.mnt.sb(), self.dentry(), child)
580
666
  }
@@ -585,15 +671,15 @@ impl Nameidata {
585
671
  /// terminating NUL is too long, and one holding a NUL names nothing a
586
672
  /// Filesystem can hold. It answers before a walk looks up where it starts, as
587
673
  /// Linux's syscalls take the name before `path_init` takes the descriptor.
588
- fn getname(path: &str) -> Result<(), FilesystemError> {
674
+ fn getname(path: &str) -> Result<(), Errno> {
589
675
  if path.is_empty() {
590
- return Err(FilesystemError::NotFound);
676
+ return Err(Errno::NotFound);
591
677
  }
592
678
  if path.len() >= PATH_MAX {
593
- return Err(FilesystemError::InvalidFilename);
679
+ return Err(Errno::InvalidFilename);
594
680
  }
595
681
  if path.contains('\0') {
596
- return Err(FilesystemError::InvalidInput);
682
+ return Err(Errno::InvalidInput);
597
683
  }
598
684
  Ok(())
599
685
  }
@@ -605,7 +691,7 @@ pub(crate) fn inode_permission(
605
691
  sb: &SuperBlock,
606
692
  dentry: &Dentry,
607
693
  mask: Mask,
608
- ) -> Result<(), FilesystemError> {
694
+ ) -> Result<(), Errno> {
609
695
  sb_permission(sb, dentry, mask)?;
610
696
  dentry.inode_ops()?.permission(dentry, mask)?;
611
697
  cred.security_inode_permission(dentry, mask)
@@ -613,14 +699,12 @@ pub(crate) fn inode_permission(
613
699
 
614
700
  /// Refuse a write to a file, a directory, or a link of a read-only `sb`, as
615
701
  /// Linux's `sb_permission` does before any Filesystem or module is asked.
616
- fn sb_permission(sb: &SuperBlock, dentry: &Dentry, mask: Mask) -> Result<(), FilesystemError> {
702
+ fn sb_permission(sb: &SuperBlock, dentry: &Dentry, mask: Mask) -> Result<(), Errno> {
617
703
  if !mask.contains(Mask::WRITE) || !sb.rdonly() {
618
704
  return Ok(());
619
705
  }
620
- match dentry.kind()? {
621
- FileType::RegFile | FileType::Dir | FileType::Symlink => {
622
- Err(FilesystemError::ReadOnlyFilesystem)
623
- }
706
+ match dentry.file_type()? {
707
+ FileType::RegFile | FileType::Dir | FileType::Symlink => Err(Errno::ReadOnlyFilesystem),
624
708
  _ => Ok(()),
625
709
  }
626
710
  }
@@ -635,14 +719,14 @@ fn set_nameidata(
635
719
  start: &impl Start,
636
720
  path: &str,
637
721
  total_link_count: &Rc<Cell<usize>>,
638
- ) -> Result<Nameidata, FilesystemError> {
722
+ ) -> Result<Nameidata, Errno> {
639
723
  getname(path)?;
640
724
  if path.starts_with('/') {
641
- return Err(FilesystemError::Escape);
725
+ return Err(Errno::Escape);
642
726
  }
643
727
  let start = start.path_init()?;
644
- if start.dentry().kind()? != FileType::Dir {
645
- return Err(FilesystemError::NotADirectory);
728
+ if start.dentry().file_type()? != FileType::Dir {
729
+ return Err(Errno::NotADirectory);
646
730
  }
647
731
  Ok(Nameidata {
648
732
  mnt: start.mnt().clone(),
@@ -650,8 +734,11 @@ fn set_nameidata(
650
734
  root: start.dentry().clone(),
651
735
  r_seq: RENAME_LOCK.read_seqbegin(),
652
736
  dir: start.dentry().clone(),
737
+ crossed: Vec::new(),
653
738
  pending: parts(path),
654
739
  total_link_count: total_link_count.clone(),
740
+ trail: Vec::new(),
741
+ keeps_trail: false,
655
742
  last: String::new(),
656
743
  last_type: LastType::Dot,
657
744
  trailing_slash: false,
@@ -667,7 +754,7 @@ pub(crate) fn filename_parentat(
667
754
  cred: &Arc<Cred>,
668
755
  start: &impl Start,
669
756
  path: &str,
670
- ) -> Result<Nameidata, FilesystemError> {
757
+ ) -> Result<Nameidata, Errno> {
671
758
  let total_link_count = Rc::default();
672
759
  walk_with_reval(|| {
673
760
  let mut nd = set_nameidata(cred, start, path, &total_link_count)?;
@@ -681,11 +768,9 @@ pub(crate) fn filename_parentat(
681
768
  /// `filename_lookup` walks again with `LOOKUP_REVAL`, so a directory found
682
769
  /// moving meanwhile is reached where it went. Every walk asks `revalidate` of
683
770
  /// what it holds already, so the second takes no flag.
684
- fn walk_with_reval<T>(
685
- mut walk: impl FnMut() -> Result<T, FilesystemError>,
686
- ) -> Result<T, FilesystemError> {
771
+ fn walk_with_reval<T>(mut walk: impl FnMut() -> Result<T, Errno>) -> Result<T, Errno> {
687
772
  match walk() {
688
- Err(FilesystemError::StaleNetworkFileHandle) => walk(),
773
+ Err(Errno::StaleNetworkFileHandle) => walk(),
689
774
  answered => answered,
690
775
  }
691
776
  }
@@ -695,11 +780,11 @@ fn walk_with_reval<T>(
695
780
  /// allows. The walk's own error returns as it stands, as the walk was made
696
781
  /// again already.
697
782
  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> {
783
+ mut walk: impl FnMut() -> Result<W, Errno>,
784
+ mut act: impl FnMut(W) -> Result<T, Errno>,
785
+ ) -> Result<T, Errno> {
701
786
  match act(walk()?) {
702
- Err(FilesystemError::StaleNetworkFileHandle) => act(walk()?),
787
+ Err(Errno::StaleNetworkFileHandle) => act(walk()?),
703
788
  answered => answered,
704
789
  }
705
790
  }
@@ -713,19 +798,35 @@ pub(crate) fn filename_lookup(
713
798
  start: &impl Start,
714
799
  path: &str,
715
800
  follow: bool,
716
- ) -> Result<Nameidata, FilesystemError> {
801
+ ) -> Result<Nameidata, Errno> {
717
802
  let total_link_count = Rc::default();
718
803
  walk_with_reval(|| path_lookupat(set_nameidata(cred, start, path, &total_link_count)?, follow))
719
804
  }
720
805
 
806
+ /// Walk `path` beneath `start` to where a mount is to stand, following a last
807
+ /// link, as `do_mount` looks its target up, keeping each dentry the walk steps
808
+ /// onto by a name.
809
+ pub(crate) fn walk_mountpoint(
810
+ cred: &Arc<Cred>,
811
+ start: &impl Start,
812
+ path: &str,
813
+ ) -> Result<Nameidata, Errno> {
814
+ let total_link_count = Rc::default();
815
+ walk_with_reval(|| {
816
+ let mut nd = set_nameidata(cred, start, path, &total_link_count)?;
817
+ nd.keeps_trail = true;
818
+ path_lookupat(nd, true)
819
+ })
820
+ }
821
+
721
822
  /// Walk `nd` to what its path names, as Linux's `path_lookupat`.
722
- fn path_lookupat(mut nd: Nameidata, follow: bool) -> Result<Nameidata, FilesystemError> {
823
+ fn path_lookupat(mut nd: Nameidata, follow: bool) -> Result<Nameidata, Errno> {
723
824
  nd.link_path_walk()?;
724
825
  nd.lookup_last(follow)?;
725
826
  nd.complete_walk()?;
726
- let kind = nd.kind()?;
827
+ let kind = nd.file_type()?;
727
828
  if nd.lookup_directory && kind != FileType::Dir {
728
- return Err(FilesystemError::NotADirectory);
829
+ return Err(Errno::NotADirectory);
729
830
  }
730
831
  Ok(nd)
731
832
  }
@@ -739,14 +840,14 @@ pub fn do_file_open(
739
840
  start: &impl Start,
740
841
  path: &str,
741
842
  op: &OpenFlags,
742
- ) -> Result<File, FilesystemError> {
843
+ ) -> Result<File, Errno> {
743
844
  let total_link_count = Rc::default();
744
845
  walk_with_reval(|| path_openat(set_nameidata(cred, start, path, &total_link_count)?, op))
745
846
  }
746
847
 
747
848
  /// Walk `nd` to its last name and open it as `op` asks, as Linux's
748
849
  /// `path_openat`.
749
- fn path_openat(mut nd: Nameidata, op: &OpenFlags) -> Result<File, FilesystemError> {
850
+ fn path_openat(mut nd: Nameidata, op: &OpenFlags) -> Result<File, Errno> {
750
851
  let how = op.open_flag();
751
852
  nd.lookup_directory = op.lookup_directory();
752
853
  let mode = FMode::of(how);
@@ -762,11 +863,11 @@ fn path_openat(mut nd: Nameidata, op: &OpenFlags) -> Result<File, FilesystemErro
762
863
  /// Stand for what `nd` names without opening it, as Linux's `do_o_path` walks
763
864
  /// with `path_lookupat` and opens nothing: no permission is asked and nothing
764
865
  /// is made or emptied.
765
- fn do_o_path(nd: Nameidata, op: &OpenFlags) -> Result<File, FilesystemError> {
866
+ fn do_o_path(nd: Nameidata, op: &OpenFlags) -> Result<File, Errno> {
766
867
  let how = op.open_flag();
767
868
  let nd = path_lookupat(nd, op.lookup_follow())?;
768
869
  let child = nd.path()?;
769
- let kind = child.kind()?;
870
+ let kind = child.file_type()?;
770
871
  let (f_op, security) = on_path(&nd.mnt, &child, |path| {
771
872
  do_dentry_open(&nd.cred, path, kind, FMode::PATH, how, || child.open(how))
772
873
  })?;
@@ -799,7 +900,7 @@ fn do_open(
799
900
  child: Arc<Dentry>,
800
901
  opened: Open,
801
902
  op: &OpenFlags,
802
- ) -> Result<File, FilesystemError> {
903
+ ) -> Result<File, Errno> {
803
904
  let how = op.open_flag();
804
905
  let mode = opened.mode;
805
906
  let created = mode.contains(FMode::CREATED);
@@ -808,12 +909,12 @@ fn do_open(
808
909
  }
809
910
  // The walk followed every link the call asked it to, so a link at the
810
911
  // end now is one swapped in since, and is opened as itself.
811
- let kind = child.kind()?;
912
+ let kind = child.file_type()?;
812
913
  let refusal = match kind {
813
- _ if how.create && how.exclusive && !created => Some(FilesystemError::AlreadyExists),
814
- FileType::Dir if how.create => Some(FilesystemError::IsADirectory),
914
+ _ if how.create && how.exclusive && !created => Some(Errno::AlreadyExists),
915
+ FileType::Dir if how.create => Some(Errno::IsADirectory),
815
916
  FileType::Dir => None,
816
- _ if nd.lookup_directory => Some(FilesystemError::NotADirectory),
917
+ _ if nd.lookup_directory => Some(Errno::NotADirectory),
817
918
  _ => None,
818
919
  };
819
920
  if let Some(error) = refusal {
@@ -861,10 +962,10 @@ fn may_open(
861
962
  child: &Dentry,
862
963
  kind: FileType,
863
964
  mask: Mask,
864
- ) -> Result<(), FilesystemError> {
965
+ ) -> Result<(), Errno> {
865
966
  match kind {
866
- FileType::Symlink => return Err(FilesystemError::FilesystemLoop),
867
- FileType::Dir if mask.contains(Mask::WRITE) => return Err(FilesystemError::IsADirectory),
967
+ FileType::Symlink => return Err(Errno::FilesystemLoop),
968
+ FileType::Dir if mask.contains(Mask::WRITE) => return Err(Errno::IsADirectory),
868
969
  _ => {}
869
970
  }
870
971
  inode_permission(cred, sb, child, Mask::OPEN | mask)
@@ -882,7 +983,7 @@ pub fn filename_linkat(
882
983
  new_start: &impl Start,
883
984
  new_path: &str,
884
985
  follow: bool,
885
- ) -> Result<(), FilesystemError> {
986
+ ) -> Result<(), Errno> {
886
987
  retry_estale(
887
988
  || {
888
989
  let old = filename_lookup(cred, old_start, old_path, follow)?;
@@ -893,7 +994,7 @@ pub fn filename_linkat(
893
994
  },
894
995
  |(old, target, new, (_held, child))| {
895
996
  if !Arc::ptr_eq(&old.mnt, &new.mnt) {
896
- return Err(FilesystemError::CrossesDevices);
997
+ return Err(Errno::CrossesDevices);
897
998
  }
898
999
  on_path(&old.mnt, &target, |old| {
899
1000
  on_path(&new.mnt, &child, |new| cred.security_path_link(old, new))
@@ -910,7 +1011,7 @@ pub fn filename_symlinkat(
910
1011
  target: &str,
911
1012
  start: &impl Start,
912
1013
  path: &str,
913
- ) -> Result<(), FilesystemError> {
1014
+ ) -> Result<(), Errno> {
914
1015
  getname(target)?;
915
1016
  retry_estale(
916
1017
  || {
@@ -933,18 +1034,18 @@ pub fn filename_symlinkat(
933
1034
  fn filename_create(
934
1035
  nd: &mut Nameidata,
935
1036
  want_dir: bool,
936
- ) -> Result<(RwSemaphoreGuard, Arc<Dentry>), FilesystemError> {
937
- if nd.last_type != LastType::Norm {
938
- return Err(FilesystemError::AlreadyExists);
1037
+ ) -> Result<(RwSemaphoreGuard, Arc<Dentry>), Errno> {
1038
+ if nd.last_type != LastType::Norm || nd.lookup_mnt_by_name(&nd.last)?.is_some() {
1039
+ return Err(Errno::AlreadyExists);
939
1040
  }
940
1041
  let write = nd.mnt.mnt_want_write();
941
1042
  let held = nd.dentry().inode_lock()?;
942
1043
  let child = nd.lookup_last_locked()?;
943
1044
  if child.inode().is_some() {
944
- return Err(FilesystemError::AlreadyExists);
1045
+ return Err(Errno::AlreadyExists);
945
1046
  }
946
1047
  if nd.trailing_slash && !want_dir {
947
- return Err(FilesystemError::NotFound);
1048
+ return Err(Errno::NotFound);
948
1049
  }
949
1050
  write?;
950
1051
  Ok((held, child))
@@ -952,22 +1053,18 @@ fn filename_create(
952
1053
 
953
1054
  /// Hold the directory a name is removed from and take the name's dentry, as
954
1055
  /// Linux's `start_dirop` does before any security hook is asked.
955
- fn start_dirop(nd: &mut Nameidata) -> Result<(RwSemaphoreGuard, Arc<Dentry>), FilesystemError> {
1056
+ fn start_dirop(nd: &mut Nameidata) -> Result<(RwSemaphoreGuard, Arc<Dentry>), Errno> {
956
1057
  let held = nd.dentry().inode_lock()?;
957
1058
  let child = nd.lookup_last_locked()?;
958
1059
  match child.inode() {
959
1060
  Some(_) => Ok((held, child)),
960
- None => Err(FilesystemError::NotFound),
1061
+ None => Err(Errno::NotFound),
961
1062
  }
962
1063
  }
963
1064
 
964
1065
  /// Make the directory `path` beneath `start`. A trailing `/` asks for the
965
1066
  /// 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> {
1067
+ pub fn filename_mkdirat(cred: &Arc<Cred>, start: &impl Start, path: &str) -> Result<(), Errno> {
971
1068
  retry_estale(
972
1069
  || {
973
1070
  let mut nd = filename_parentat(cred, start, path)?;
@@ -983,18 +1080,14 @@ pub fn filename_mkdirat(
983
1080
 
984
1081
  /// Remove the empty directory `path` beneath `start`, as Linux's
985
1082
  /// `filename_rmdir` does.
986
- pub fn filename_rmdir(
987
- cred: &Arc<Cred>,
988
- start: &impl Start,
989
- path: &str,
990
- ) -> Result<(), FilesystemError> {
1083
+ pub fn filename_rmdir(cred: &Arc<Cred>, start: &impl Start, path: &str) -> Result<(), Errno> {
991
1084
  retry_estale(
992
1085
  || filename_parentat(cred, start, path),
993
1086
  |mut nd| {
994
1087
  match nd.last_type {
995
1088
  LastType::Norm => {}
996
- LastType::Dot => return Err(FilesystemError::InvalidInput),
997
- LastType::DotDot => return Err(FilesystemError::DirectoryNotEmpty),
1089
+ LastType::Dot => return Err(Errno::InvalidInput),
1090
+ LastType::DotDot => return Err(Errno::DirectoryNotEmpty),
998
1091
  }
999
1092
  nd.mnt.mnt_want_write()?;
1000
1093
  let (_held, child) = start_dirop(&mut nd)?;
@@ -1007,23 +1100,19 @@ pub fn filename_rmdir(
1007
1100
  /// Remove the file `path` beneath `start`, as Linux's `filename_unlinkat` does.
1008
1101
  /// It follows no link at the end, so a trailing `/` is answered by the name
1009
1102
  /// 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> {
1103
+ pub fn filename_unlinkat(cred: &Arc<Cred>, start: &impl Start, path: &str) -> Result<(), Errno> {
1015
1104
  retry_estale(
1016
1105
  || filename_parentat(cred, start, path),
1017
1106
  |mut nd| {
1018
1107
  if nd.last_type != LastType::Norm {
1019
- return Err(FilesystemError::IsADirectory);
1108
+ return Err(Errno::IsADirectory);
1020
1109
  }
1021
1110
  nd.mnt.mnt_want_write()?;
1022
1111
  let (_held, child) = start_dirop(&mut nd)?;
1023
1112
  if nd.trailing_slash {
1024
- return Err(match child.kind() {
1025
- Ok(FileType::Dir) => FilesystemError::IsADirectory,
1026
- _ => FilesystemError::NotADirectory,
1113
+ return Err(match child.file_type() {
1114
+ Ok(FileType::Dir) => Errno::IsADirectory,
1115
+ _ => Errno::NotADirectory,
1027
1116
  });
1028
1117
  }
1029
1118
  on_path(&nd.mnt, &child, |path| cred.security_path_unlink(path))?;
@@ -1042,17 +1131,17 @@ pub fn filename_renameat2(
1042
1131
  from_path: &str,
1043
1132
  to: &impl Start,
1044
1133
  to_path: &str,
1045
- ) -> Result<(), FilesystemError> {
1134
+ ) -> Result<(), Errno> {
1046
1135
  let walk = || {
1047
1136
  let source = filename_parentat(cred, from, from_path)?;
1048
1137
  Ok((source, filename_parentat(cred, to, to_path)?))
1049
1138
  };
1050
1139
  retry_estale(walk, |(source, target)| {
1051
1140
  if !Arc::ptr_eq(&source.mnt, &target.mnt) {
1052
- return Err(FilesystemError::CrossesDevices);
1141
+ return Err(Errno::CrossesDevices);
1053
1142
  }
1054
1143
  if source.last_type != LastType::Norm || target.last_type != LastType::Norm {
1055
- return Err(FilesystemError::ResourceBusy);
1144
+ return Err(Errno::ResourceBusy);
1056
1145
  }
1057
1146
  source.mnt.mnt_want_write()?;
1058
1147
  let mnt = source.mnt.clone();
@@ -1065,9 +1154,9 @@ pub fn filename_renameat2(
1065
1154
  )?;
1066
1155
  // Unless the source is a directory, a trailing `/` on either side is
1067
1156
  // refused, as `filename_renameat2` refuses it.
1068
- let is_dir = rd.old_dentry.kind()? == FileType::Dir;
1157
+ let is_dir = rd.old_dentry.file_type()? == FileType::Dir;
1069
1158
  if !is_dir && (source.trailing_slash || target.trailing_slash) {
1070
- return Err(FilesystemError::NotADirectory);
1159
+ return Err(Errno::NotADirectory);
1071
1160
  }
1072
1161
  on_path(&mnt, &rd.old_dentry, |old| {
1073
1162
  on_path(&mnt, &rd.new_dentry, |new| {
@@ -1087,7 +1176,7 @@ fn lock_rename(
1087
1176
  sb: &SuperBlock,
1088
1177
  old_dir: &Arc<Dentry>,
1089
1178
  new_dir: &Arc<Dentry>,
1090
- ) -> Result<Vec<RwSemaphoreGuard>, FilesystemError> {
1179
+ ) -> Result<Vec<RwSemaphoreGuard>, Errno> {
1091
1180
  if Arc::ptr_eq(old_dir, new_dir) {
1092
1181
  return Ok(vec![old_dir.inode_lock()?]);
1093
1182
  }
@@ -1109,13 +1198,13 @@ pub(crate) struct RenameData {
1109
1198
  pub(crate) old_dentry: Arc<Dentry>,
1110
1199
  pub(crate) new_parent: Arc<Dentry>,
1111
1200
  pub(crate) new_dentry: Arc<Dentry>,
1112
- pub(crate) flag: Option<RenameFlag>,
1201
+ pub(crate) flags: Option<RenameFlag>,
1113
1202
  }
1114
1203
 
1115
1204
  /// Hold both directories of a move and find its names beneath them, as
1116
1205
  /// Linux's `__start_renaming` does through `lock_rename`, so no other move
1117
1206
  /// 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
1207
+ /// the source, and at the target what `flags` will not take, is refused as the
1119
1208
  /// flags `__start_renaming` looks each name up with refuse it. So is a move
1120
1209
  /// whose source stands above its target directory, and one whose target stands
1121
1210
  /// above its source directory, which only an exchange may not empty.
@@ -1123,24 +1212,24 @@ pub(crate) fn __start_renaming(
1123
1212
  sb: &SuperBlock,
1124
1213
  (old_dir, old_name): (&Arc<Dentry>, &str),
1125
1214
  (new_dir, new_name): (&Arc<Dentry>, &str),
1126
- flag: Option<RenameFlag>,
1127
- ) -> Result<RenameData, FilesystemError> {
1215
+ flags: Option<RenameFlag>,
1216
+ ) -> Result<RenameData, Errno> {
1128
1217
  let _held = lock_rename(sb, old_dir, new_dir)?;
1129
1218
  let old_dentry = lookup_one_qstr_excl(sb, old_dir, old_name)?;
1130
- old_dentry.kind()?;
1219
+ old_dentry.file_type()?;
1131
1220
  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),
1221
+ match (flags, new_dentry.inode().is_some()) {
1222
+ (Some(RenameFlag::Exchange), false) => return Err(Errno::NotFound),
1223
+ (Some(RenameFlag::NoReplace), true) => return Err(Errno::AlreadyExists),
1135
1224
  _ => {}
1136
1225
  }
1137
1226
  if new_dir.is_subdir(&old_dentry) {
1138
- return Err(FilesystemError::InvalidInput);
1227
+ return Err(Errno::InvalidInput);
1139
1228
  }
1140
1229
  if old_dir.is_subdir(&new_dentry) {
1141
- return Err(match flag {
1142
- Some(RenameFlag::Exchange) => FilesystemError::InvalidInput,
1143
- _ => FilesystemError::DirectoryNotEmpty,
1230
+ return Err(match flags {
1231
+ Some(RenameFlag::Exchange) => Errno::InvalidInput,
1232
+ _ => Errno::DirectoryNotEmpty,
1144
1233
  });
1145
1234
  }
1146
1235
  Ok(RenameData {
@@ -1149,7 +1238,7 @@ pub(crate) fn __start_renaming(
1149
1238
  old_dentry,
1150
1239
  new_parent: new_dir.clone(),
1151
1240
  new_dentry,
1152
- flag,
1241
+ flags,
1153
1242
  })
1154
1243
  }
1155
1244
 
@@ -1161,11 +1250,11 @@ fn lock_moved(
1161
1250
  (old, is_dir): (&Dentry, bool),
1162
1251
  (new, new_is_dir): (&Dentry, bool),
1163
1252
  same_dir: bool,
1164
- flag: Option<RenameFlag>,
1165
- ) -> Result<Vec<RwSemaphoreGuard>, FilesystemError> {
1253
+ flags: Option<RenameFlag>,
1254
+ ) -> Result<Vec<RwSemaphoreGuard>, Errno> {
1166
1255
  let (source, target) = (old.inode(), new.inode());
1167
1256
  let lock_old_subdir = !same_dir;
1168
- let lock_new_subdir = !same_dir || flag != Some(RenameFlag::Exchange);
1257
+ let lock_new_subdir = !same_dir || flags != Some(RenameFlag::Exchange);
1169
1258
  let locks = match (is_dir, new_is_dir) {
1170
1259
  (true, _) => [
1171
1260
  source.filter(|_| lock_old_subdir),
@@ -1186,7 +1275,7 @@ fn lock_moved(
1186
1275
  fn lock_two_nondirectories(
1187
1276
  first: Option<Arc<Inode>>,
1188
1277
  second: Option<Arc<Inode>>,
1189
- ) -> Result<Vec<RwSemaphoreGuard>, FilesystemError> {
1278
+ ) -> Result<Vec<RwSemaphoreGuard>, Errno> {
1190
1279
  let mut inodes: Vec<_> = first.into_iter().chain(second).collect();
1191
1280
  inodes.sort_by_key(Arc::as_ptr);
1192
1281
  inodes.dedup_by(|a, b| Arc::ptr_eq(a, b));
@@ -1199,22 +1288,18 @@ fn lock_two_nondirectories(
1199
1288
  /// side is checked first, as `vfs_rename` asks `may_delete_dentry` and
1200
1289
  /// `may_create_dentry`. A directory replaced at the new name is gone for whoever
1201
1290
  /// 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> {
1291
+ pub(crate) fn vfs_rename(cred: &Cred, sb: &SuperBlock, rd: &RenameData) -> Result<(), Errno> {
1207
1292
  let (old_dir, old) = (&rd.old_parent, &rd.old_dentry);
1208
1293
  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();
1294
+ let flags = rd.flags;
1295
+ let moving = old.file_type().ok();
1296
+ let target = new.file_type().ok();
1212
1297
  if Arc::ptr_eq(old, new) || old.names_the_entry_of(new) {
1213
1298
  return Ok(());
1214
1299
  }
1215
1300
  let is_dir = moving == Some(FileType::Dir);
1216
1301
  may_delete_dentry(cred, sb, old_dir, moving, is_dir)?;
1217
- match (target, flag) {
1302
+ match (target, flags) {
1218
1303
  (None, _) => may_create_dentry(cred, sb, new_dir, new)?,
1219
1304
  (target, Some(RenameFlag::Exchange)) => {
1220
1305
  may_delete_dentry(cred, sb, new_dir, target, target == Some(FileType::Dir))?
@@ -1226,7 +1311,7 @@ pub(crate) fn vfs_rename(
1226
1311
  if is_dir {
1227
1312
  inode_permission(cred, sb, old, Mask::WRITE)?;
1228
1313
  }
1229
- if flag == Some(RenameFlag::Exchange) && target == Some(FileType::Dir) {
1314
+ if flags == Some(RenameFlag::Exchange) && target == Some(FileType::Dir) {
1230
1315
  inode_permission(cred, sb, new, Mask::WRITE)?;
1231
1316
  }
1232
1317
  }
@@ -1234,13 +1319,17 @@ pub(crate) fn vfs_rename(
1234
1319
  (old, is_dir),
1235
1320
  (new, target == Some(FileType::Dir)),
1236
1321
  Arc::ptr_eq(old_dir, new_dir),
1237
- flag,
1322
+ flags,
1238
1323
  )?;
1324
+ let mnt_ns = cred.mnt_ns();
1325
+ if mnt_ns.pins(old) || mnt_ns.pins(new) {
1326
+ return Err(Errno::ResourceBusy);
1327
+ }
1239
1328
  old_dir
1240
1329
  .inode_ops()?
1241
- .rename(old, new_dir.inode_ops()?.as_ref(), new, flag)?;
1330
+ .rename(old, new_dir.inode_ops()?.as_ref(), new, flags)?;
1242
1331
  let dentries = sb.dentries();
1243
- if flag == Some(RenameFlag::Exchange) {
1332
+ if flags == Some(RenameFlag::Exchange) {
1244
1333
  dentries.exchange(old, new);
1245
1334
  return Ok(());
1246
1335
  }
@@ -1260,9 +1349,12 @@ pub(crate) fn vfs_rmdir(
1260
1349
  sb: &SuperBlock,
1261
1350
  dir: &Dentry,
1262
1351
  victim: &Arc<Dentry>,
1263
- ) -> Result<(), FilesystemError> {
1264
- may_delete_dentry(cred, sb, dir, victim.kind().ok(), true)?;
1352
+ ) -> Result<(), Errno> {
1353
+ may_delete_dentry(cred, sb, dir, victim.file_type().ok(), true)?;
1265
1354
  let _victim = victim.inode_lock()?;
1355
+ if cred.mnt_ns().pins(victim) {
1356
+ return Err(Errno::ResourceBusy);
1357
+ }
1266
1358
  dir.inode_ops()?.rmdir(victim)?;
1267
1359
  sb.dentries().shrink_dcache_parent(victim);
1268
1360
  victim.mark_dead();
@@ -1279,9 +1371,12 @@ pub(crate) fn vfs_unlink(
1279
1371
  sb: &SuperBlock,
1280
1372
  dir: &Dentry,
1281
1373
  victim: &Arc<Dentry>,
1282
- ) -> Result<(), FilesystemError> {
1283
- may_delete_dentry(cred, sb, dir, victim.kind().ok(), false)?;
1374
+ ) -> Result<(), Errno> {
1375
+ may_delete_dentry(cred, sb, dir, victim.file_type().ok(), false)?;
1284
1376
  let _victim = victim.inode_lock()?;
1377
+ if cred.mnt_ns().pins(victim) {
1378
+ return Err(Errno::ResourceBusy);
1379
+ }
1285
1380
  dir.inode_ops()?.unlink(victim)?;
1286
1381
  sb.dentries().unhash(victim);
1287
1382
  Ok(())
@@ -1295,7 +1390,7 @@ pub(crate) fn vfs_mkdir(
1295
1390
  sb: &SuperBlock,
1296
1391
  dir: &Dentry,
1297
1392
  child: &Dentry,
1298
- ) -> Result<(), FilesystemError> {
1393
+ ) -> Result<(), Errno> {
1299
1394
  may_create_dentry(cred, sb, dir, child)?;
1300
1395
  dir.inode_ops()?.mkdir(child)
1301
1396
  }
@@ -1320,7 +1415,7 @@ pub(crate) fn atomic_open(
1320
1415
  dir: &Dentry,
1321
1416
  child: &Dentry,
1322
1417
  how: &OpenHow,
1323
- ) -> Result<AtomicOpen, FilesystemError> {
1418
+ ) -> Result<AtomicOpen, Errno> {
1324
1419
  let (file, created, spliced) = match dir.inode_ops()?.atomic_open(child, how)? {
1325
1420
  Finish::Open { file, created } => (Some(file), created, None),
1326
1421
  Finish::Spelled { file, name, inode } => {
@@ -1343,7 +1438,7 @@ pub(crate) fn vfs_create(
1343
1438
  sb: &SuperBlock,
1344
1439
  dir: &Dentry,
1345
1440
  child: &Dentry,
1346
- ) -> Result<(), FilesystemError> {
1441
+ ) -> Result<(), Errno> {
1347
1442
  may_create_dentry(cred, sb, dir, child)?;
1348
1443
  dir.inode_ops()?.create(child)
1349
1444
  }
@@ -1357,14 +1452,14 @@ fn vfs_link(
1357
1452
  old: &Dentry,
1358
1453
  dir: &Dentry,
1359
1454
  child: &Dentry,
1360
- ) -> Result<(), FilesystemError> {
1455
+ ) -> Result<(), Errno> {
1361
1456
  may_create_dentry(cred, sb, dir, child)?;
1362
- if old.kind()? == FileType::Dir {
1363
- return Err(FilesystemError::NotPermitted);
1457
+ if old.file_type()? == FileType::Dir {
1458
+ return Err(Errno::NotPermitted);
1364
1459
  }
1365
1460
  let _held = old.inode_lock()?;
1366
1461
  if old.getattr()?.nlink == 0 {
1367
- return Err(FilesystemError::NotFound);
1462
+ return Err(Errno::NotFound);
1368
1463
  }
1369
1464
  dir.inode_ops()?.link(old, child)
1370
1465
  }
@@ -1377,7 +1472,7 @@ fn vfs_symlink(
1377
1472
  dir: &Dentry,
1378
1473
  child: &Dentry,
1379
1474
  target: &str,
1380
- ) -> Result<(), FilesystemError> {
1475
+ ) -> Result<(), Errno> {
1381
1476
  may_create_dentry(cred, sb, dir, child)?;
1382
1477
  dir.inode_ops()?.symlink(child, target)
1383
1478
  }
@@ -1389,12 +1484,12 @@ pub(crate) fn may_create_dentry(
1389
1484
  sb: &SuperBlock,
1390
1485
  dir: &Dentry,
1391
1486
  child: &Dentry,
1392
- ) -> Result<(), FilesystemError> {
1487
+ ) -> Result<(), Errno> {
1393
1488
  if child.inode().is_some() {
1394
- return Err(FilesystemError::AlreadyExists);
1489
+ return Err(Errno::AlreadyExists);
1395
1490
  }
1396
1491
  if dir.is_deaddir() {
1397
- return Err(FilesystemError::NotFound);
1492
+ return Err(Errno::NotFound);
1398
1493
  }
1399
1494
  inode_permission(cred, sb, dir, Mask::WRITE | Mask::EXEC)
1400
1495
  }
@@ -1409,18 +1504,18 @@ fn may_delete_dentry(
1409
1504
  dir: &Dentry,
1410
1505
  victim: Option<FileType>,
1411
1506
  is_dir: bool,
1412
- ) -> Result<(), FilesystemError> {
1507
+ ) -> Result<(), Errno> {
1413
1508
  let Some(victim) = victim else {
1414
- return Err(FilesystemError::NotFound);
1509
+ return Err(Errno::NotFound);
1415
1510
  };
1416
1511
  inode_permission(cred, sb, dir, Mask::WRITE | Mask::EXEC)?;
1417
1512
  match (is_dir, victim == FileType::Dir) {
1418
- (true, false) => return Err(FilesystemError::NotADirectory),
1419
- (false, true) => return Err(FilesystemError::IsADirectory),
1513
+ (true, false) => return Err(Errno::NotADirectory),
1514
+ (false, true) => return Err(Errno::IsADirectory),
1420
1515
  _ => {}
1421
1516
  }
1422
1517
  if dir.is_deaddir() {
1423
- return Err(FilesystemError::NotFound);
1518
+ return Err(Errno::NotFound);
1424
1519
  }
1425
1520
  Ok(())
1426
1521
  }
@@ -1433,31 +1528,28 @@ mod tests {
1433
1528
  use std::thread;
1434
1529
  use std::time::Duration;
1435
1530
 
1531
+ use crate::cred::Cred;
1436
1532
  use crate::filesystem::wrap::{self, Wrap};
1437
1533
  use crate::filesystem::{
1438
- DentryOperations, FileOperations, FileSystemType, FileType, Filesystem, FilesystemError,
1439
- Finish, InodeOperations, Kstat, Lookup, Tmpfs,
1534
+ DentryOperations, FileOperations, FileSystemType, FileType, Filesystem, Finish,
1535
+ InodeOperations, Kstat, Lookup, Tmpfs,
1440
1536
  };
1441
- use crate::mount::{Access, Mount, Policy};
1537
+ use crate::mount::{Access, Mount, MountRequest};
1538
+ use crate::policy::Policy;
1442
1539
  use crate::sched::testing::count_waits;
1540
+ use crate::security::{FileSecurity, SecurityOperations, SecurityPath};
1443
1541
  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
- };
1542
+ use crate::vfs::{self, Dentry, FMode, Inode, Mask, OpenHow, Path, RenameFlag};
1543
+ use crate::Errno;
1448
1544
 
1449
- type Hook = Box<dyn Fn() -> Result<(), FilesystemError> + Send + Sync>;
1545
+ type Hook = Box<dyn Fn() -> Result<(), Errno> + Send + Sync>;
1450
1546
 
1451
1547
  /// A test's Filesystem counting what it is asked to look up.
1452
1548
  #[derive(Default)]
1453
1549
  struct CountsAsks(AtomicUsize);
1454
1550
 
1455
1551
  impl wrap::Hook for CountsAsks {
1456
- fn lookup(
1457
- &self,
1458
- inner: &dyn InodeOperations,
1459
- dentry: &Dentry,
1460
- ) -> Result<Lookup, FilesystemError> {
1552
+ fn lookup(&self, inner: &dyn InodeOperations, dentry: &Dentry) -> Result<Lookup, Errno> {
1461
1553
  self.0.fetch_add(1, Ordering::SeqCst);
1462
1554
  inner.lookup(dentry)
1463
1555
  }
@@ -1472,7 +1564,7 @@ mod tests {
1472
1564
  }
1473
1565
 
1474
1566
  impl FileSystemType for LinksFile {
1475
- fn fill_super(self: Arc<Self>, sb: &mut Filesystem) -> Result<(), FilesystemError> {
1567
+ fn fill_super(self: Arc<Self>, sb: &mut Filesystem) -> Result<(), Errno> {
1476
1568
  sb.d_make_root(vfs::Inode::new(
1477
1569
  &Kstat::new(crate::filesystem::FileType::Dir, 0),
1478
1570
  self,
@@ -1482,14 +1574,14 @@ mod tests {
1482
1574
  }
1483
1575
 
1484
1576
  impl InodeOperations for LinksFile {
1485
- fn getattr(&self, dentry: &Dentry) -> Result<Kstat, FilesystemError> {
1577
+ fn getattr(&self, dentry: &Dentry) -> Result<Kstat, Errno> {
1486
1578
  Ok(match dentry.is_root() {
1487
1579
  false => Kstat::new(FileType::RegFile, 0).with_nlink(self.names),
1488
1580
  true => Kstat::new(FileType::Dir, 0),
1489
1581
  })
1490
1582
  }
1491
1583
 
1492
- fn lookup(&self, dentry: &Dentry) -> Result<Lookup, FilesystemError> {
1584
+ fn lookup(&self, dentry: &Dentry) -> Result<Lookup, Errno> {
1493
1585
  if dentry.name() != "file" {
1494
1586
  return Ok(Lookup::Absent);
1495
1587
  }
@@ -1497,7 +1589,7 @@ mod tests {
1497
1589
  Ok(Lookup::Found(Inode::new(&file, Arc::new(self.clone()))))
1498
1590
  }
1499
1591
 
1500
- fn link(&self, _old: &Dentry, _dentry: &Dentry) -> Result<(), FilesystemError> {
1592
+ fn link(&self, _old: &Dentry, _dentry: &Dentry) -> Result<(), Errno> {
1501
1593
  self.linked.fetch_add(1, Ordering::SeqCst);
1502
1594
  Ok(())
1503
1595
  }
@@ -1516,7 +1608,7 @@ mod tests {
1516
1608
  };
1517
1609
  let mount = Mount::new(
1518
1610
  "/data",
1519
- Filesystem::new(Arc::new(ops)).expect("the instance must stand"),
1611
+ Filesystem::new(ops).expect("the instance must stand"),
1520
1612
  Access::ReadWrite,
1521
1613
  )
1522
1614
  .expect("/data is a guest path");
@@ -1534,11 +1626,7 @@ mod tests {
1534
1626
  }
1535
1627
 
1536
1628
  impl DentryOperations for AskedOfAbsent {
1537
- fn revalidate(
1538
- &self,
1539
- _dir: &dyn InodeOperations,
1540
- _dentry: &Dentry,
1541
- ) -> Result<bool, FilesystemError> {
1629
+ fn revalidate(&self, _dir: &dyn InodeOperations, _dentry: &Dentry) -> Result<bool, Errno> {
1542
1630
  self.revalidations.fetch_add(1, Ordering::SeqCst);
1543
1631
  Ok(true)
1544
1632
  }
@@ -1549,7 +1637,7 @@ mod tests {
1549
1637
  }
1550
1638
 
1551
1639
  impl FileSystemType for AskedOfAbsent {
1552
- fn fill_super(self: Arc<Self>, sb: &mut Filesystem) -> Result<(), FilesystemError> {
1640
+ fn fill_super(self: Arc<Self>, sb: &mut Filesystem) -> Result<(), Errno> {
1553
1641
  sb.set_default_d_op(self.clone());
1554
1642
  sb.d_make_root(vfs::Inode::new(
1555
1643
  &Kstat::new(crate::filesystem::FileType::Dir, 0),
@@ -1560,11 +1648,11 @@ mod tests {
1560
1648
  }
1561
1649
 
1562
1650
  impl InodeOperations for AskedOfAbsent {
1563
- fn getattr(&self, _dentry: &Dentry) -> Result<Kstat, FilesystemError> {
1651
+ fn getattr(&self, _dentry: &Dentry) -> Result<Kstat, Errno> {
1564
1652
  Ok(Kstat::new(FileType::Dir, 0))
1565
1653
  }
1566
1654
 
1567
- fn lookup(&self, _dentry: &Dentry) -> Result<Lookup, FilesystemError> {
1655
+ fn lookup(&self, _dentry: &Dentry) -> Result<Lookup, Errno> {
1568
1656
  self.lookups.fetch_add(1, Ordering::SeqCst);
1569
1657
  Ok(match self.stands {
1570
1658
  true => {
@@ -1592,14 +1680,7 @@ mod tests {
1592
1680
  lookups.load(Ordering::SeqCst),
1593
1681
  revalidations.load(Ordering::SeqCst)
1594
1682
  ),
1595
- (
1596
- (
1597
- Some(FilesystemError::NotFound),
1598
- Some(FilesystemError::NotFound)
1599
- ),
1600
- 1,
1601
- 1
1602
- ),
1683
+ ((Some(Errno::NotFound), Some(Errno::NotFound)), 1, 1),
1603
1684
  "vfs::vfs_fstatat twice of a name nothing stands at must ask ->lookup once and \
1604
1685
  revalidate what it kept, as retain_dentry keeps a negative dentry"
1605
1686
  );
@@ -1665,49 +1746,49 @@ mod tests {
1665
1746
  }
1666
1747
  }
1667
1748
 
1668
- impl vfs::SecurityOperations for RecordsHooks {
1669
- fn path_mknod(&self, _path: vfs::SecurityPath<'_>) -> Result<(), FilesystemError> {
1749
+ impl crate::security::SecurityOperations for RecordsHooks {
1750
+ fn path_mknod(&self, _path: crate::security::SecurityPath<'_>) -> Result<(), Errno> {
1670
1751
  self.record("path_mknod");
1671
1752
  Ok(())
1672
1753
  }
1673
1754
 
1674
- fn path_mkdir(&self, _path: vfs::SecurityPath<'_>) -> Result<(), FilesystemError> {
1755
+ fn path_mkdir(&self, _path: crate::security::SecurityPath<'_>) -> Result<(), Errno> {
1675
1756
  self.record("path_mkdir");
1676
1757
  Ok(())
1677
1758
  }
1678
1759
 
1679
- fn path_rmdir(&self, _path: vfs::SecurityPath<'_>) -> Result<(), FilesystemError> {
1760
+ fn path_rmdir(&self, _path: crate::security::SecurityPath<'_>) -> Result<(), Errno> {
1680
1761
  self.record("path_rmdir");
1681
1762
  Ok(())
1682
1763
  }
1683
1764
 
1684
- fn path_unlink(&self, _path: vfs::SecurityPath<'_>) -> Result<(), FilesystemError> {
1765
+ fn path_unlink(&self, _path: crate::security::SecurityPath<'_>) -> Result<(), Errno> {
1685
1766
  self.record("path_unlink");
1686
1767
  Ok(())
1687
1768
  }
1688
1769
 
1689
1770
  fn path_rename(
1690
1771
  &self,
1691
- _old: vfs::SecurityPath<'_>,
1692
- _new: vfs::SecurityPath<'_>,
1772
+ _old: crate::security::SecurityPath<'_>,
1773
+ _new: crate::security::SecurityPath<'_>,
1693
1774
  _dentries: (&Arc<Dentry>, &Arc<Dentry>),
1694
- ) -> Result<(), FilesystemError> {
1775
+ ) -> Result<(), Errno> {
1695
1776
  self.record("path_rename");
1696
1777
  Ok(())
1697
1778
  }
1698
1779
 
1699
1780
  fn file_open(
1700
1781
  &self,
1701
- _path: vfs::SecurityPath<'_>,
1782
+ _path: crate::security::SecurityPath<'_>,
1702
1783
  _kind: FileType,
1703
1784
  _mode: vfs::FMode,
1704
1785
  _how: &OpenHow,
1705
- ) -> Result<vfs::FileSecurity, FilesystemError> {
1786
+ ) -> Result<crate::security::FileSecurity, Errno> {
1706
1787
  self.record("file_open");
1707
1788
  Ok(None)
1708
1789
  }
1709
1790
 
1710
- fn file_truncate(&self, _kept: &vfs::FileSecurity) -> Result<(), FilesystemError> {
1791
+ fn file_truncate(&self, _kept: &crate::security::FileSecurity) -> Result<(), Errno> {
1711
1792
  self.record("file_truncate");
1712
1793
  Ok(())
1713
1794
  }
@@ -1717,10 +1798,10 @@ mod tests {
1717
1798
  #[test]
1718
1799
  fn each_call_reaches_the_hook_linux_names_for_it() {
1719
1800
  let hooks = Arc::new(RecordsHooks::default());
1720
- let cred = vfs::Cred::new(vec![hooks.clone()]);
1801
+ let cred = crate::cred::Cred::new(vec![hooks.clone()]);
1721
1802
  let mount = Mount::new(
1722
1803
  "/data",
1723
- Filesystem::new(Arc::new(Tmpfs::new())).expect("the instance must stand"),
1804
+ Filesystem::new(Tmpfs::new()).expect("the instance must stand"),
1724
1805
  Access::ReadWrite,
1725
1806
  )
1726
1807
  .expect("/data is a guest path");
@@ -1770,7 +1851,7 @@ mod tests {
1770
1851
  }
1771
1852
 
1772
1853
  impl SecurityOperations for MovesBeforeOpen {
1773
- fn inode_permission(&self, dentry: &Dentry, _mask: Mask) -> Result<(), FilesystemError> {
1854
+ fn inode_permission(&self, dentry: &Dentry, _mask: Mask) -> Result<(), Errno> {
1774
1855
  let root = match dentry.name() == "f" {
1775
1856
  true => self.root.lock().expect("never poisoned").take(),
1776
1857
  false => None,
@@ -1787,7 +1868,7 @@ mod tests {
1787
1868
  _kind: FileType,
1788
1869
  _mode: FMode,
1789
1870
  _how: &OpenHow,
1790
- ) -> Result<FileSecurity, FilesystemError> {
1871
+ ) -> Result<FileSecurity, Errno> {
1791
1872
  self.opened
1792
1873
  .lock()
1793
1874
  .expect("never poisoned")
@@ -1804,7 +1885,7 @@ mod tests {
1804
1885
  let hooks = Arc::new(MovesBeforeOpen::default());
1805
1886
  let mount = Mount::new(
1806
1887
  "/data",
1807
- Filesystem::new(Arc::new([("f", "x")].into_iter().collect::<Tmpfs>()))
1888
+ Filesystem::new([("f", "x")].into_iter().collect::<Tmpfs>())
1808
1889
  .expect("the instance must stand"),
1809
1890
  Access::ReadWrite,
1810
1891
  )
@@ -1832,10 +1913,10 @@ mod tests {
1832
1913
  fn a_module_refusing_what_a_walk_asks_refuses_the_walk() {
1833
1914
  struct RefusesExec;
1834
1915
 
1835
- impl vfs::SecurityOperations for RefusesExec {
1836
- fn inode_permission(&self, dentry: &Dentry, mask: Mask) -> Result<(), FilesystemError> {
1916
+ impl crate::security::SecurityOperations for RefusesExec {
1917
+ fn inode_permission(&self, dentry: &Dentry, mask: Mask) -> Result<(), Errno> {
1837
1918
  match dentry.name() == "d" && mask.contains(Mask::EXEC) {
1838
- true => Err(FilesystemError::PermissionDenied),
1919
+ true => Err(Errno::PermissionDenied),
1839
1920
  false => Ok(()),
1840
1921
  }
1841
1922
  }
@@ -1844,15 +1925,15 @@ mod tests {
1844
1925
  let tmpfs: Tmpfs = [("d/f", "x")].into_iter().collect();
1845
1926
  let mount = Mount::new(
1846
1927
  "/data",
1847
- Filesystem::new(Arc::new(tmpfs)).expect("the instance must stand"),
1928
+ Filesystem::new(tmpfs).expect("the instance must stand"),
1848
1929
  Access::Read,
1849
1930
  )
1850
1931
  .expect("/data is a guest path");
1851
1932
  let root = Path::root(mount.mnt());
1852
- let cred = vfs::Cred::new(vec![Arc::new(RefusesExec)]);
1933
+ let cred = crate::cred::Cred::new(vec![Arc::new(RefusesExec)]);
1853
1934
  assert_eq!(
1854
1935
  vfs::vfs_fstatat(&cred, &root, "d/f", false).err(),
1855
- Some(FilesystemError::PermissionDenied),
1936
+ Some(Errno::PermissionDenied),
1856
1937
  "vfs_fstatat through a directory a module refuses to pass must answer EACCES, as \
1857
1938
  security_inode_permission answers may_lookup"
1858
1939
  );
@@ -1862,7 +1943,7 @@ mod tests {
1862
1943
  struct NamesItsRoot;
1863
1944
 
1864
1945
  impl FileSystemType for NamesItsRoot {
1865
- fn fill_super(self: Arc<Self>, sb: &mut Filesystem) -> Result<(), FilesystemError> {
1946
+ fn fill_super(self: Arc<Self>, sb: &mut Filesystem) -> Result<(), Errno> {
1866
1947
  let root = Kstat::new(FileType::Dir, 0).with_identity(7, 11);
1867
1948
  sb.d_make_root(Inode::new(&root, self));
1868
1949
  Ok(())
@@ -1870,10 +1951,10 @@ mod tests {
1870
1951
  }
1871
1952
 
1872
1953
  /// A Filesystem that cannot stand, or stands with no root.
1873
- struct NeverStands(Option<FilesystemError>);
1954
+ struct NeverStands(Option<Errno>);
1874
1955
 
1875
1956
  impl FileSystemType for NeverStands {
1876
- fn fill_super(self: Arc<Self>, _sb: &mut Filesystem) -> Result<(), FilesystemError> {
1957
+ fn fill_super(self: Arc<Self>, _sb: &mut Filesystem) -> Result<(), Errno> {
1877
1958
  match &self.0 {
1878
1959
  Some(error) => Err(error.clone()),
1879
1960
  None => Ok(()),
@@ -1884,23 +1965,20 @@ mod tests {
1884
1965
  // @behavior RT-254
1885
1966
  #[test]
1886
1967
  fn an_instance_that_cannot_stand_answers_why() {
1887
- let answer = |fs: NeverStands| Filesystem::new(Arc::new(fs)).err();
1968
+ let answer = |fs: NeverStands| Filesystem::new(fs).err();
1888
1969
  assert_eq!(
1889
1970
  (
1890
- answer(NeverStands(Some(FilesystemError::PermissionDenied))),
1971
+ answer(NeverStands(Some(Errno::PermissionDenied))),
1891
1972
  answer(NeverStands(None)),
1892
1973
  ),
1893
- (
1894
- Some(FilesystemError::PermissionDenied),
1895
- Some(FilesystemError::InvalidInput),
1896
- ),
1974
+ (Some(Errno::PermissionDenied), Some(Errno::InvalidInput),),
1897
1975
  "Filesystem::new must answer what fill_super answers, and EINVAL for a fill_super \
1898
1976
  that made no root, and make no instance, as vfs_get_tree refuses one"
1899
1977
  );
1900
1978
  }
1901
1979
 
1902
1980
  impl InodeOperations for NamesItsRoot {
1903
- fn getattr(&self, _dentry: &Dentry) -> Result<Kstat, FilesystemError> {
1981
+ fn getattr(&self, _dentry: &Dentry) -> Result<Kstat, Errno> {
1904
1982
  Ok(Kstat::new(FileType::Dir, 0))
1905
1983
  }
1906
1984
  }
@@ -1935,7 +2013,7 @@ mod tests {
1935
2013
  struct SharesInode(Arc<OnceLock<Arc<Inode>>>);
1936
2014
 
1937
2015
  impl FileSystemType for SharesInode {
1938
- fn fill_super(self: Arc<Self>, sb: &mut Filesystem) -> Result<(), FilesystemError> {
2016
+ fn fill_super(self: Arc<Self>, sb: &mut Filesystem) -> Result<(), Errno> {
1939
2017
  sb.d_make_root(vfs::Inode::new(
1940
2018
  &Kstat::new(crate::filesystem::FileType::Dir, 0),
1941
2019
  self,
@@ -1945,11 +2023,11 @@ mod tests {
1945
2023
  }
1946
2024
 
1947
2025
  impl InodeOperations for SharesInode {
1948
- fn getattr(&self, _dentry: &Dentry) -> Result<Kstat, FilesystemError> {
2026
+ fn getattr(&self, _dentry: &Dentry) -> Result<Kstat, Errno> {
1949
2027
  Ok(Kstat::new(FileType::RegFile, 0))
1950
2028
  }
1951
2029
 
1952
- fn lookup(&self, _dentry: &Dentry) -> Result<Lookup, FilesystemError> {
2030
+ fn lookup(&self, _dentry: &Dentry) -> Result<Lookup, Errno> {
1953
2031
  let file = Kstat::new(FileType::RegFile, 0);
1954
2032
  let inode = self
1955
2033
  .0
@@ -1963,8 +2041,7 @@ mod tests {
1963
2041
  fn a_filesystem_handing_one_inode_for_two_names_shares_it() {
1964
2042
  let mount = Mount::new(
1965
2043
  "/data",
1966
- Filesystem::new(Arc::new(SharesInode(Arc::default())))
1967
- .expect("the instance must stand"),
2044
+ Filesystem::new(SharesInode(Arc::default())).expect("the instance must stand"),
1968
2045
  Access::ReadWrite,
1969
2046
  )
1970
2047
  .expect("/data is a guest path");
@@ -1992,7 +2069,7 @@ mod tests {
1992
2069
  struct SharesDirectory(Arc<OnceLock<Arc<Inode>>>);
1993
2070
 
1994
2071
  impl FileSystemType for SharesDirectory {
1995
- fn fill_super(self: Arc<Self>, sb: &mut Filesystem) -> Result<(), FilesystemError> {
2072
+ fn fill_super(self: Arc<Self>, sb: &mut Filesystem) -> Result<(), Errno> {
1996
2073
  sb.d_make_root(vfs::Inode::new(
1997
2074
  &Kstat::new(crate::filesystem::FileType::Dir, 0),
1998
2075
  self,
@@ -2002,11 +2079,11 @@ mod tests {
2002
2079
  }
2003
2080
 
2004
2081
  impl InodeOperations for SharesDirectory {
2005
- fn getattr(&self, _dentry: &Dentry) -> Result<Kstat, FilesystemError> {
2082
+ fn getattr(&self, _dentry: &Dentry) -> Result<Kstat, Errno> {
2006
2083
  Ok(Kstat::new(FileType::Dir, 0))
2007
2084
  }
2008
2085
 
2009
- fn lookup(&self, dentry: &Dentry) -> Result<Lookup, FilesystemError> {
2086
+ fn lookup(&self, dentry: &Dentry) -> Result<Lookup, Errno> {
2010
2087
  let dir = Kstat::new(FileType::Dir, 0);
2011
2088
  let above = dentry.parent().name();
2012
2089
  Ok(match (above.as_str(), dentry.name().as_str()) {
@@ -2022,7 +2099,7 @@ mod tests {
2022
2099
  }
2023
2100
  }
2024
2101
 
2025
- fn reach(root: &Path, path: &str) -> Result<Arc<Dentry>, FilesystemError> {
2102
+ fn reach(root: &Path, path: &str) -> Result<Arc<Dentry>, Errno> {
2026
2103
  super::filename_lookup(&Arc::default(), root, path, false)?.path()
2027
2104
  }
2028
2105
 
@@ -2031,9 +2108,8 @@ mod tests {
2031
2108
  // @behavior RT-315
2032
2109
  #[test]
2033
2110
  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
- );
2111
+ let root =
2112
+ root_of(Filesystem::new(SharesDirectory::default()).expect("the instance must stand"));
2037
2113
  let first = reach(&root, "a").expect("a is reached");
2038
2114
  let second = reach(&root, "b").expect("b is reached");
2039
2115
  assert_eq!(
@@ -2047,9 +2123,8 @@ mod tests {
2047
2123
  // @behavior RT-316
2048
2124
  #[test]
2049
2125
  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
- );
2126
+ let root =
2127
+ root_of(Filesystem::new(SharesDirectory::default()).expect("the instance must stand"));
2053
2128
  let (answered, answer) = mpsc::channel();
2054
2129
  thread::spawn(move || answered.send(reach(&root, "a/loop").err()).ok());
2055
2130
  let answer = answer
@@ -2057,7 +2132,7 @@ mod tests {
2057
2132
  .expect("a walk through a directory moved beneath itself would never end");
2058
2133
  assert_eq!(
2059
2134
  answer,
2060
- Some(FilesystemError::FilesystemLoop),
2135
+ Some(Errno::FilesystemLoop),
2061
2136
  "a walk reaching `a/loop` over a Filesystem handing `a`'s own inode for it must \
2062
2137
  answer ELOOP, as d_splice_alias refuses an alias that is an ancestor"
2063
2138
  );
@@ -2068,9 +2143,8 @@ mod tests {
2068
2143
  // @behavior RT-317
2069
2144
  #[test]
2070
2145
  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
- );
2146
+ let root =
2147
+ root_of(Filesystem::new(SharesDirectory::default()).expect("the instance must stand"));
2074
2148
  reach(&root, "a").expect("a is reached");
2075
2149
  let _renaming = root
2076
2150
  .mnt()
@@ -2080,12 +2154,55 @@ mod tests {
2080
2154
  .expect("nothing else holds the rename lock");
2081
2155
  assert_eq!(
2082
2156
  reach(&root, "c/d").err(),
2083
- Some(FilesystemError::StaleNetworkFileHandle),
2157
+ Some(Errno::StaleNetworkFileHandle),
2084
2158
  "a walk reaching `c/d`, the directory standing at `a`, while a call holds the \
2085
2159
  rename lock must answer ESTALE, as __d_unalias only tries the lock"
2086
2160
  );
2087
2161
  }
2088
2162
 
2163
+ /// A Filesystem answering each lookup of `d` with a new inode for the one
2164
+ /// directory it holds there, as a backend keeping no inode of its own.
2165
+ #[derive(Clone, Default)]
2166
+ struct AnswersAnew;
2167
+
2168
+ impl FileSystemType for AnswersAnew {
2169
+ fn fill_super(self: Arc<Self>, sb: &mut Filesystem) -> Result<(), Errno> {
2170
+ sb.d_make_root(vfs::Inode::new(&Kstat::new(FileType::Dir, 0), self));
2171
+ Ok(())
2172
+ }
2173
+ }
2174
+
2175
+ impl InodeOperations for AnswersAnew {
2176
+ fn getattr(&self, _dentry: &Dentry) -> Result<Kstat, Errno> {
2177
+ Ok(Kstat::new(FileType::Dir, 0))
2178
+ }
2179
+
2180
+ fn lookup(&self, dentry: &Dentry) -> Result<Lookup, Errno> {
2181
+ let dir = Kstat::new(FileType::Dir, 0).with_identity(1, 7);
2182
+ Ok(match dentry.name().as_str() {
2183
+ "d" => Lookup::Found(Inode::new(&dir, Arc::new(self.clone()))),
2184
+ _ => Lookup::Absent,
2185
+ })
2186
+ }
2187
+ }
2188
+
2189
+ // A second dentry for one directory would hold none of what stands on
2190
+ // the first, such as a mount, and would lock apart from it.
2191
+ // @behavior RT-393
2192
+ #[test]
2193
+ fn a_directory_a_filesystem_answers_anew_keeps_its_one_dentry() {
2194
+ let root = root_of(Filesystem::new(AnswersAnew).expect("the instance must stand"));
2195
+ let first = reach(&root, "d").expect("d is reached");
2196
+ root.mnt().sb().dentries().unhash(&first);
2197
+ let second = reach(&root, "d").expect("d is reached again");
2198
+ assert!(
2199
+ Arc::ptr_eq(&first, &second),
2200
+ "a walk reaching `d` again, after its held dentry left the name table, over a \
2201
+ Filesystem answering each lookup with a new inode of one identity must find the \
2202
+ dentry it held, as iget5_locked finds the directory's live inode"
2203
+ );
2204
+ }
2205
+
2089
2206
  /// A Filesystem handing one directory's inode for `a` and `b` in its root,
2090
2207
  /// whose lookup of `b` answers once the test lets it, counting each.
2091
2208
  #[derive(Clone, Default)]
@@ -2096,7 +2213,7 @@ mod tests {
2096
2213
  }
2097
2214
 
2098
2215
  impl FileSystemType for HoldsSharedLookup {
2099
- fn fill_super(self: Arc<Self>, sb: &mut Filesystem) -> Result<(), FilesystemError> {
2216
+ fn fill_super(self: Arc<Self>, sb: &mut Filesystem) -> Result<(), Errno> {
2100
2217
  sb.d_make_root(vfs::Inode::new(
2101
2218
  &Kstat::new(crate::filesystem::FileType::Dir, 0),
2102
2219
  self,
@@ -2106,11 +2223,11 @@ mod tests {
2106
2223
  }
2107
2224
 
2108
2225
  impl InodeOperations for HoldsSharedLookup {
2109
- fn getattr(&self, _dentry: &Dentry) -> Result<Kstat, FilesystemError> {
2226
+ fn getattr(&self, _dentry: &Dentry) -> Result<Kstat, Errno> {
2110
2227
  Ok(Kstat::new(FileType::Dir, 0))
2111
2228
  }
2112
2229
 
2113
- fn lookup(&self, dentry: &Dentry) -> Result<Lookup, FilesystemError> {
2230
+ fn lookup(&self, dentry: &Dentry) -> Result<Lookup, Errno> {
2114
2231
  let name = dentry.name();
2115
2232
  if name == "b" {
2116
2233
  self.asked.fetch_add(1, Ordering::SeqCst);
@@ -2157,10 +2274,10 @@ mod tests {
2157
2274
  /// Filesystem was asked about `b` once.
2158
2275
  fn waits_on_a_name_a_directory_moved_onto(
2159
2276
  what: &str,
2160
- second: fn(&Path, &str) -> Result<Arc<Dentry>, FilesystemError>,
2277
+ second: fn(&Path, &str) -> Result<Arc<Dentry>, Errno>,
2161
2278
  ) {
2162
2279
  let fs = HoldsSharedLookup::default();
2163
- let root = root_of(Filesystem::new(Arc::new(fs.clone())).expect("the instance must stand"));
2280
+ let root = root_of(Filesystem::new(fs.clone()).expect("the instance must stand"));
2164
2281
  let first = reach(&root, "a").expect("a is reached");
2165
2282
  let looking = {
2166
2283
  let root = root.clone();
@@ -2222,15 +2339,11 @@ mod tests {
2222
2339
  }
2223
2340
 
2224
2341
  impl wrap::Hook for AnswersStale {
2225
- fn lookup(
2226
- &self,
2227
- inner: &dyn InodeOperations,
2228
- dentry: &Dentry,
2229
- ) -> Result<Lookup, FilesystemError> {
2342
+ fn lookup(&self, inner: &dyn InodeOperations, dentry: &Dentry) -> Result<Lookup, Errno> {
2230
2343
  if *self.stale.lock().expect("unpoisoned") == dentry.name() {
2231
2344
  self.asked.fetch_add(1, Ordering::SeqCst);
2232
2345
  if self.armed.swap(self.always, Ordering::SeqCst) {
2233
- return Err(FilesystemError::StaleNetworkFileHandle);
2346
+ return Err(Errno::StaleNetworkFileHandle);
2234
2347
  }
2235
2348
  }
2236
2349
  inner.lookup(dentry)
@@ -2249,18 +2362,13 @@ mod tests {
2249
2362
  root_of(instance())
2250
2363
  }
2251
2364
 
2252
- type StaleCall = fn(&Arc<Cred>, &Path) -> Result<(), FilesystemError>;
2365
+ type StaleCall = fn(&Arc<Cred>, &Path) -> Result<(), Errno>;
2253
2366
 
2254
2367
  /// Each VFS entry that walks a path beneath `dir`, the name it acts on once
2255
2368
  /// its walk ended, and what it answers where nothing is stale. A Tmpfs makes
2256
2369
  /// 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};
2370
+ fn stale_calls() -> [(&'static str, &'static str, StaleCall, Result<(), Errno>); 10] {
2371
+ use Errno::{InvalidInput, NotPermitted};
2264
2372
  [
2265
2373
  (
2266
2374
  "vfs_fstatat",
@@ -2328,7 +2436,7 @@ mod tests {
2328
2436
  "do_utimes_path",
2329
2437
  "file",
2330
2438
  |cred, root| {
2331
- let times = vfs::Iattr::times(None, Some(crate::filesystem::SetTime::Now));
2439
+ let times = vfs::Iattr::for_times(None, Some(crate::filesystem::SetTime::Now));
2332
2440
  vfs::do_utimes_path(cred, root, "dir/file", false, &times)
2333
2441
  },
2334
2442
  Ok(()),
@@ -2338,7 +2446,7 @@ mod tests {
2338
2446
 
2339
2447
  /// What `run` answers over a Filesystem answering ESTALE about `name`, once
2340
2448
  /// or `always`, and how many times it was asked about `name`.
2341
- fn run_stale(run: StaleCall, name: &str, always: bool) -> (Result<(), FilesystemError>, usize) {
2449
+ fn run_stale(run: StaleCall, name: &str, always: bool) -> (Result<(), Errno>, usize) {
2342
2450
  let hook = Arc::new(AnswersStale {
2343
2451
  always,
2344
2452
  ..AnswersStale::default()
@@ -2373,7 +2481,7 @@ mod tests {
2373
2481
  for (call, _, run, _) in stale_calls() {
2374
2482
  assert_eq!(
2375
2483
  run_stale(run, "dir", true),
2376
- (Err(FilesystemError::StaleNetworkFileHandle), 2),
2484
+ (Err(Errno::StaleNetworkFileHandle), 2),
2377
2485
  "vfs::{call} over a Filesystem always answering ESTALE about `dir` must answer \
2378
2486
  ESTALE after asking twice, as no caller makes a walk's error again"
2379
2487
  );
@@ -2415,7 +2523,7 @@ mod tests {
2415
2523
  for (call, name, run, _) in calls {
2416
2524
  assert_eq!(
2417
2525
  run_stale(run, name, false),
2418
- (Err(FilesystemError::StaleNetworkFileHandle), 1),
2526
+ (Err(Errno::StaleNetworkFileHandle), 1),
2419
2527
  "vfs::{call} over a Filesystem answering ESTALE the first time it is asked \
2420
2528
  about `{name}` must answer ESTALE after asking once, as filename_create's \
2421
2529
  error returns before retry_estale"
@@ -2427,12 +2535,12 @@ mod tests {
2427
2535
  // entry has is refused before any directory is searched.
2428
2536
  #[test]
2429
2537
  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();
2538
+ let filesystem = Filesystem::new(Tmpfs::new()).expect("the instance must stand");
2539
+ let root = filesystem.root().expect(crate::vfs::MADE_ROOT).clone();
2432
2540
  for name in ["", ".", "..", "a/b", "a\0b"] {
2433
2541
  assert_eq!(
2434
2542
  super::lookup_one_unlocked(&Cred::default(), &filesystem, &root, name).err(),
2435
- Some(FilesystemError::PermissionDenied),
2543
+ Some(Errno::PermissionDenied),
2436
2544
  "lookup_one_unlocked of {name:?} must answer EACCES, as lookup_noperm_common \
2437
2545
  refuses a name no single entry has"
2438
2546
  );
@@ -2451,7 +2559,7 @@ mod tests {
2451
2559
  impl FileOperations for NoOperations {}
2452
2560
 
2453
2561
  impl FileSystemType for CreatesOnly {
2454
- fn fill_super(self: Arc<Self>, sb: &mut Filesystem) -> Result<(), FilesystemError> {
2562
+ fn fill_super(self: Arc<Self>, sb: &mut Filesystem) -> Result<(), Errno> {
2455
2563
  sb.d_make_root(vfs::Inode::new(
2456
2564
  &Kstat::new(crate::filesystem::FileType::Dir, 0),
2457
2565
  self,
@@ -2461,28 +2569,24 @@ mod tests {
2461
2569
  }
2462
2570
 
2463
2571
  impl InodeOperations for CreatesOnly {
2464
- fn getattr(&self, dentry: &Dentry) -> Result<Kstat, FilesystemError> {
2572
+ fn getattr(&self, dentry: &Dentry) -> Result<Kstat, Errno> {
2465
2573
  Ok(match dentry.is_root() {
2466
2574
  false => Kstat::new(FileType::RegFile, 0),
2467
2575
  true => Kstat::new(FileType::Dir, 0),
2468
2576
  })
2469
2577
  }
2470
2578
 
2471
- fn lookup(&self, _dentry: &Dentry) -> Result<Lookup, FilesystemError> {
2579
+ fn lookup(&self, _dentry: &Dentry) -> Result<Lookup, Errno> {
2472
2580
  Ok(Lookup::Absent)
2473
2581
  }
2474
2582
 
2475
- fn create(&self, dentry: &Dentry) -> Result<(), FilesystemError> {
2583
+ fn create(&self, dentry: &Dentry) -> Result<(), Errno> {
2476
2584
  let made = Kstat::new(FileType::RegFile, 0);
2477
2585
  dentry.add(Some(Inode::new(&made, Arc::new(self.clone()))));
2478
2586
  Ok(())
2479
2587
  }
2480
2588
 
2481
- fn open(
2482
- &self,
2483
- _dentry: &Dentry,
2484
- _how: &OpenHow,
2485
- ) -> Result<Box<dyn FileOperations>, FilesystemError> {
2589
+ fn open(&self, _dentry: &Dentry, _how: &OpenHow) -> Result<Box<dyn FileOperations>, Errno> {
2486
2590
  self.opened.fetch_add(1, Ordering::SeqCst);
2487
2591
  Ok(Box::new(NoOperations))
2488
2592
  }
@@ -2494,7 +2598,7 @@ mod tests {
2494
2598
  let filesystem = CreatesOnly::default();
2495
2599
  let mount = Mount::new(
2496
2600
  "/data",
2497
- Filesystem::new(Arc::new(filesystem.clone())).expect("the instance must stand"),
2601
+ Filesystem::new(filesystem.clone()).expect("the instance must stand"),
2498
2602
  Access::ReadWrite,
2499
2603
  )
2500
2604
  .expect("/data is a guest path");
@@ -2527,9 +2631,9 @@ mod tests {
2527
2631
  _kind: FileType,
2528
2632
  mode: FMode,
2529
2633
  _how: &OpenHow,
2530
- ) -> Result<FileSecurity, FilesystemError> {
2634
+ ) -> Result<FileSecurity, Errno> {
2531
2635
  match mode.contains(FMode::CREATED) {
2532
- true => Err(FilesystemError::PermissionDenied),
2636
+ true => Err(Errno::PermissionDenied),
2533
2637
  false => Ok(None),
2534
2638
  }
2535
2639
  }
@@ -2541,7 +2645,7 @@ mod tests {
2541
2645
  let filesystem = CreatesOnly::default();
2542
2646
  let mount = Mount::new(
2543
2647
  "/data",
2544
- Filesystem::new(Arc::new(filesystem.clone())).expect("the instance must stand"),
2648
+ Filesystem::new(filesystem.clone()).expect("the instance must stand"),
2545
2649
  Access::ReadWrite,
2546
2650
  )
2547
2651
  .expect("/data is a guest path");
@@ -2554,7 +2658,7 @@ mod tests {
2554
2658
  let answer = vfs::kern_path::filp_open(&cred, &Path::root(mount.mnt()), "made", &how);
2555
2659
  assert_eq!(
2556
2660
  (answer.err(), filesystem.opened.load(Ordering::SeqCst)),
2557
- (Some(FilesystemError::PermissionDenied), 0),
2661
+ (Some(Errno::PermissionDenied), 0),
2558
2662
  "vfs::do_file_open making a file on a Filesystem with no atomic_open, under a \
2559
2663
  security module refusing the open, must never ask the Filesystem's open, as \
2560
2664
  do_open asks security_file_open before vfs_open reaches f_op->open"
@@ -2568,7 +2672,7 @@ mod tests {
2568
2672
  let made = holds.made.clone();
2569
2673
  let mount = Mount::new(
2570
2674
  "/data",
2571
- Filesystem::new(Arc::new(holds)).expect("the instance must stand"),
2675
+ Filesystem::new(holds).expect("the instance must stand"),
2572
2676
  Access::ReadWrite,
2573
2677
  )
2574
2678
  .expect("/data is a guest path");
@@ -2581,7 +2685,7 @@ mod tests {
2581
2685
  let answer = vfs::kern_path::filp_open(&cred, &Path::root(mount.mnt()), "made", &how);
2582
2686
  assert_eq!(
2583
2687
  (answer.err(), made.load(Ordering::SeqCst)),
2584
- (Some(FilesystemError::PermissionDenied), true),
2688
+ (Some(Errno::PermissionDenied), true),
2585
2689
  "vfs::do_file_open making a file through atomic_open, under a security module \
2586
2690
  refusing the open, must make the file and answer EACCES, as finish_open reaches \
2587
2691
  security_file_open"
@@ -2594,7 +2698,7 @@ mod tests {
2594
2698
  struct OpensWithinItsDirectory(CreatesOnly);
2595
2699
 
2596
2700
  impl FileSystemType for OpensWithinItsDirectory {
2597
- fn fill_super(self: Arc<Self>, sb: &mut Filesystem) -> Result<(), FilesystemError> {
2701
+ fn fill_super(self: Arc<Self>, sb: &mut Filesystem) -> Result<(), Errno> {
2598
2702
  sb.d_make_root(vfs::Inode::new(
2599
2703
  &Kstat::new(crate::filesystem::FileType::Dir, 0),
2600
2704
  self,
@@ -2604,25 +2708,21 @@ mod tests {
2604
2708
  }
2605
2709
 
2606
2710
  impl InodeOperations for OpensWithinItsDirectory {
2607
- fn getattr(&self, dentry: &Dentry) -> Result<Kstat, FilesystemError> {
2711
+ fn getattr(&self, dentry: &Dentry) -> Result<Kstat, Errno> {
2608
2712
  self.0.getattr(dentry)
2609
2713
  }
2610
2714
 
2611
- fn lookup(&self, dentry: &Dentry) -> Result<Lookup, FilesystemError> {
2715
+ fn lookup(&self, dentry: &Dentry) -> Result<Lookup, Errno> {
2612
2716
  self.0.lookup(dentry)
2613
2717
  }
2614
2718
 
2615
- fn create(&self, dentry: &Dentry) -> Result<(), FilesystemError> {
2719
+ fn create(&self, dentry: &Dentry) -> Result<(), Errno> {
2616
2720
  let made = Kstat::new(FileType::RegFile, 0);
2617
2721
  dentry.add(Some(Inode::new(&made, Arc::new(self.clone()))));
2618
2722
  Ok(())
2619
2723
  }
2620
2724
 
2621
- fn open(
2622
- &self,
2623
- dentry: &Dentry,
2624
- how: &OpenHow,
2625
- ) -> Result<Box<dyn FileOperations>, FilesystemError> {
2725
+ fn open(&self, dentry: &Dentry, how: &OpenHow) -> Result<Box<dyn FileOperations>, Errno> {
2626
2726
  let _held = dentry.parent().inode_lock()?;
2627
2727
  self.0.open(dentry, how)
2628
2728
  }
@@ -2634,7 +2734,7 @@ mod tests {
2634
2734
  let filesystem = OpensWithinItsDirectory::default();
2635
2735
  let mount = Mount::new(
2636
2736
  "/data",
2637
- Filesystem::new(Arc::new(filesystem)).expect("the instance must stand"),
2737
+ Filesystem::new(filesystem).expect("the instance must stand"),
2638
2738
  Access::ReadWrite,
2639
2739
  )
2640
2740
  .expect("/data is a guest path");
@@ -2657,7 +2757,7 @@ mod tests {
2657
2757
  struct FindsAFileStanding(CreatesOnly);
2658
2758
 
2659
2759
  impl FileSystemType for FindsAFileStanding {
2660
- fn fill_super(self: Arc<Self>, sb: &mut Filesystem) -> Result<(), FilesystemError> {
2760
+ fn fill_super(self: Arc<Self>, sb: &mut Filesystem) -> Result<(), Errno> {
2661
2761
  sb.d_make_root(vfs::Inode::new(
2662
2762
  &Kstat::new(crate::filesystem::FileType::Dir, 0),
2663
2763
  self,
@@ -2667,15 +2767,15 @@ mod tests {
2667
2767
  }
2668
2768
 
2669
2769
  impl InodeOperations for FindsAFileStanding {
2670
- fn getattr(&self, dentry: &Dentry) -> Result<Kstat, FilesystemError> {
2770
+ fn getattr(&self, dentry: &Dentry) -> Result<Kstat, Errno> {
2671
2771
  self.0.getattr(dentry)
2672
2772
  }
2673
2773
 
2674
- fn lookup(&self, dentry: &Dentry) -> Result<Lookup, FilesystemError> {
2774
+ fn lookup(&self, dentry: &Dentry) -> Result<Lookup, Errno> {
2675
2775
  self.0.lookup(dentry)
2676
2776
  }
2677
2777
 
2678
- fn atomic_open(&self, dentry: &Dentry, _how: &OpenHow) -> Result<Finish, FilesystemError> {
2778
+ fn atomic_open(&self, dentry: &Dentry, _how: &OpenHow) -> Result<Finish, Errno> {
2679
2779
  let found = Kstat::new(FileType::RegFile, 0);
2680
2780
  dentry.add(Some(Inode::new(&found, Arc::new(self.clone()))));
2681
2781
  Ok(Finish::Open {
@@ -2690,8 +2790,7 @@ mod tests {
2690
2790
  fn a_file_atomic_open_found_standing_opens_as_one_that_stood() {
2691
2791
  let mount = Mount::new(
2692
2792
  "/data",
2693
- Filesystem::new(Arc::new(FindsAFileStanding::default()))
2694
- .expect("the instance must stand"),
2793
+ Filesystem::new(FindsAFileStanding::default()).expect("the instance must stand"),
2695
2794
  Access::ReadWrite,
2696
2795
  )
2697
2796
  .expect("/data is a guest path");
@@ -2705,7 +2804,7 @@ mod tests {
2705
2804
  vfs::kern_path::filp_open(&Arc::default(), &Path::root(mount.mnt()), "found", &how);
2706
2805
  assert_eq!(
2707
2806
  answer.err(),
2708
- Some(FilesystemError::AlreadyExists),
2807
+ Some(Errno::AlreadyExists),
2709
2808
  "vfs::do_file_open with create and exclusive, on a Filesystem whose atomic_open \
2710
2809
  found the file standing, must answer EEXIST, as do_open refuses O_EXCL without \
2711
2810
  FMODE_CREATED"
@@ -2720,7 +2819,7 @@ mod tests {
2720
2819
  struct OpensAtOnce(Arc<(AtomicUsize, AtomicUsize, AtomicBool)>);
2721
2820
 
2722
2821
  impl FileSystemType for OpensAtOnce {
2723
- fn fill_super(self: Arc<Self>, sb: &mut Filesystem) -> Result<(), FilesystemError> {
2822
+ fn fill_super(self: Arc<Self>, sb: &mut Filesystem) -> Result<(), Errno> {
2724
2823
  sb.d_make_root(vfs::Inode::new(
2725
2824
  &Kstat::new(crate::filesystem::FileType::Dir, 0),
2726
2825
  self,
@@ -2730,20 +2829,20 @@ mod tests {
2730
2829
  }
2731
2830
 
2732
2831
  impl InodeOperations for OpensAtOnce {
2733
- fn getattr(&self, _dentry: &Dentry) -> Result<Kstat, FilesystemError> {
2832
+ fn getattr(&self, _dentry: &Dentry) -> Result<Kstat, Errno> {
2734
2833
  Ok(Kstat::new(FileType::Dir, 0))
2735
2834
  }
2736
2835
 
2737
- fn lookup(&self, _dentry: &Dentry) -> Result<Lookup, FilesystemError> {
2836
+ fn lookup(&self, _dentry: &Dentry) -> Result<Lookup, Errno> {
2738
2837
  self.0 .0.fetch_add(1, Ordering::SeqCst);
2739
2838
  Ok(Lookup::Absent)
2740
2839
  }
2741
2840
 
2742
- fn atomic_open(&self, dentry: &Dentry, how: &OpenHow) -> Result<Finish, FilesystemError> {
2841
+ fn atomic_open(&self, dentry: &Dentry, how: &OpenHow) -> Result<Finish, Errno> {
2743
2842
  self.0 .1.fetch_add(1, Ordering::SeqCst);
2744
2843
  if how.directory {
2745
2844
  self.0 .2.store(true, Ordering::SeqCst);
2746
- return Err(FilesystemError::NotADirectory);
2845
+ return Err(Errno::NotADirectory);
2747
2846
  }
2748
2847
  let found = Kstat::new(FileType::RegFile, 0);
2749
2848
  dentry.add(Some(Inode::new(&found, Arc::new(self.clone()))));
@@ -2761,7 +2860,7 @@ mod tests {
2761
2860
  struct RecordsTruncate(Arc<Mutex<Option<bool>>>);
2762
2861
 
2763
2862
  impl FileSystemType for RecordsTruncate {
2764
- fn fill_super(self: Arc<Self>, sb: &mut Filesystem) -> Result<(), FilesystemError> {
2863
+ fn fill_super(self: Arc<Self>, sb: &mut Filesystem) -> Result<(), Errno> {
2765
2864
  sb.d_make_root(vfs::Inode::new(
2766
2865
  &Kstat::new(crate::filesystem::FileType::Dir, 0),
2767
2866
  self,
@@ -2771,11 +2870,11 @@ mod tests {
2771
2870
  }
2772
2871
 
2773
2872
  impl InodeOperations for RecordsTruncate {
2774
- fn getattr(&self, _dentry: &Dentry) -> Result<Kstat, FilesystemError> {
2873
+ fn getattr(&self, _dentry: &Dentry) -> Result<Kstat, Errno> {
2775
2874
  Ok(Kstat::new(FileType::Dir, 0))
2776
2875
  }
2777
2876
 
2778
- fn lookup(&self, dentry: &Dentry) -> Result<Lookup, FilesystemError> {
2877
+ fn lookup(&self, dentry: &Dentry) -> Result<Lookup, Errno> {
2779
2878
  let file = Kstat::new(FileType::RegFile, 0);
2780
2879
  Ok(match dentry.name().as_str() {
2781
2880
  "file" => Lookup::Found(Inode::new(&file, Arc::new(self.clone()))),
@@ -2783,7 +2882,7 @@ mod tests {
2783
2882
  })
2784
2883
  }
2785
2884
 
2786
- fn atomic_open(&self, dentry: &Dentry, how: &OpenHow) -> Result<Finish, FilesystemError> {
2885
+ fn atomic_open(&self, dentry: &Dentry, how: &OpenHow) -> Result<Finish, Errno> {
2787
2886
  *self.0.lock().expect("unpoisoned") = Some(how.truncate);
2788
2887
  let found = self.lookup(dentry)?;
2789
2888
  if !how.create || !matches!(found, Lookup::Absent) {
@@ -2803,7 +2902,7 @@ mod tests {
2803
2902
  let fs = RecordsTruncate::default();
2804
2903
  let mount = Mount::new(
2805
2904
  "/data",
2806
- Filesystem::new(Arc::new(fs.clone())).expect("the instance must stand"),
2905
+ Filesystem::new(fs.clone()).expect("the instance must stand"),
2807
2906
  Access::Read,
2808
2907
  )
2809
2908
  .expect("/data is a guest path");
@@ -2820,7 +2919,7 @@ mod tests {
2820
2919
  );
2821
2920
  assert_eq!(
2822
2921
  (answer.err(), *fs.0.lock().expect("unpoisoned")),
2823
- (Some(FilesystemError::ReadOnlyFilesystem), Some(false)),
2922
+ (Some(Errno::ReadOnlyFilesystem), Some(false)),
2824
2923
  "vfs::do_file_open truncating `file` beneath a read-only mount must ask the \
2825
2924
  Filesystem's atomic_open for no truncation and answer EROFS, as lookup_open \
2826
2925
  clears O_TRUNC without got_write"
@@ -2833,7 +2932,7 @@ mod tests {
2833
2932
  #[test]
2834
2933
  fn an_exclusive_create_asks_no_truncation() {
2835
2934
  let fs = RecordsTruncate::default();
2836
- let root = root_of(Filesystem::new(Arc::new(fs.clone())).expect("the instance must stand"));
2935
+ let root = root_of(Filesystem::new(fs.clone()).expect("the instance must stand"));
2837
2936
  let making = OpenHow {
2838
2937
  write: true,
2839
2938
  create: true,
@@ -2857,7 +2956,7 @@ mod tests {
2857
2956
  #[test]
2858
2957
  fn an_open_of_a_name_no_walk_looked_up_asks_atomic_open() {
2859
2958
  let fs = OpensAtOnce::default();
2860
- let root = root_of(Filesystem::new(Arc::new(fs.clone())).expect("the instance must stand"));
2959
+ let root = root_of(Filesystem::new(fs.clone()).expect("the instance must stand"));
2861
2960
  let read = OpenHow {
2862
2961
  read: true,
2863
2962
  ..OpenHow::default()
@@ -2881,7 +2980,7 @@ mod tests {
2881
2980
  #[test]
2882
2981
  fn a_name_with_a_trailing_slash_asks_atomic_open_for_a_directory() {
2883
2982
  let fs = OpensAtOnce::default();
2884
- let root = root_of(Filesystem::new(Arc::new(fs.clone())).expect("the instance must stand"));
2983
+ let root = root_of(Filesystem::new(fs.clone()).expect("the instance must stand"));
2885
2984
  let read = OpenHow {
2886
2985
  read: true,
2887
2986
  ..OpenHow::default()
@@ -2889,7 +2988,7 @@ mod tests {
2889
2988
  let answer = vfs::kern_path::filp_open(&Arc::default(), &root, "file/", &read);
2890
2989
  assert_eq!(
2891
2990
  (answer.err(), fs.0 .2.load(Ordering::SeqCst)),
2892
- (Some(FilesystemError::NotADirectory), true),
2991
+ (Some(Errno::NotADirectory), true),
2893
2992
  "vfs::do_file_open of `file/` over a Filesystem opening in one step must ask its \
2894
2993
  atomic_open for a directory and answer ENOTDIR, as lookup_open adds O_DIRECTORY"
2895
2994
  );
@@ -2902,7 +3001,7 @@ mod tests {
2902
3001
  struct OpensSpelled(Arc<AtomicUsize>);
2903
3002
 
2904
3003
  impl FileSystemType for OpensSpelled {
2905
- fn fill_super(self: Arc<Self>, sb: &mut Filesystem) -> Result<(), FilesystemError> {
3004
+ fn fill_super(self: Arc<Self>, sb: &mut Filesystem) -> Result<(), Errno> {
2906
3005
  sb.d_make_root(vfs::Inode::new(
2907
3006
  &Kstat::new(crate::filesystem::FileType::Dir, 0),
2908
3007
  self,
@@ -2912,16 +3011,16 @@ mod tests {
2912
3011
  }
2913
3012
 
2914
3013
  impl InodeOperations for OpensSpelled {
2915
- fn getattr(&self, _dentry: &Dentry) -> Result<Kstat, FilesystemError> {
3014
+ fn getattr(&self, _dentry: &Dentry) -> Result<Kstat, Errno> {
2916
3015
  Ok(Kstat::new(FileType::Dir, 0))
2917
3016
  }
2918
3017
 
2919
- fn lookup(&self, _dentry: &Dentry) -> Result<Lookup, FilesystemError> {
3018
+ fn lookup(&self, _dentry: &Dentry) -> Result<Lookup, Errno> {
2920
3019
  self.0.fetch_add(1, Ordering::SeqCst);
2921
3020
  Ok(Lookup::Absent)
2922
3021
  }
2923
3022
 
2924
- fn atomic_open(&self, _dentry: &Dentry, _how: &OpenHow) -> Result<Finish, FilesystemError> {
3023
+ fn atomic_open(&self, _dentry: &Dentry, _how: &OpenHow) -> Result<Finish, Errno> {
2925
3024
  let file = Kstat::new(FileType::RegFile, 0);
2926
3025
  Ok(Finish::Spelled {
2927
3026
  file: Box::new(NoOperations),
@@ -2937,7 +3036,7 @@ mod tests {
2937
3036
  #[test]
2938
3037
  fn a_file_atomic_open_opens_under_another_spelling_opens_as_that_spelling() {
2939
3038
  let fs = OpensSpelled::default();
2940
- let root = root_of(Filesystem::new(Arc::new(fs.clone())).expect("the instance must stand"));
3039
+ let root = root_of(Filesystem::new(fs.clone()).expect("the instance must stand"));
2941
3040
  let read = OpenHow {
2942
3041
  read: true,
2943
3042
  ..OpenHow::default()
@@ -2971,7 +3070,7 @@ mod tests {
2971
3070
  root: kern_path(Arc::new(tmpfs)),
2972
3071
  renaming: Arc::new(Box::new(|| Ok(()))),
2973
3072
  };
2974
- let root = root_of(Filesystem::new(Arc::new(folds)).expect("the instance must stand"));
3073
+ let root = root_of(Filesystem::new(folds).expect("the instance must stand"));
2975
3074
  let read = OpenHow {
2976
3075
  read: true,
2977
3076
  ..OpenHow::default()
@@ -3000,11 +3099,11 @@ mod tests {
3000
3099
  _inner: &dyn InodeOperations,
3001
3100
  dentry: &Dentry,
3002
3101
  mask: Mask,
3003
- ) -> Result<(), FilesystemError> {
3102
+ ) -> Result<(), Errno> {
3004
3103
  let mut asked = self.asked.lock().expect("never poisoned");
3005
3104
  asked.push((dentry.name(), mask));
3006
3105
  match self.refuse_writes.load(Ordering::SeqCst) && mask.contains(Mask::WRITE) {
3007
- true => Err(FilesystemError::PermissionDenied),
3106
+ true => Err(Errno::PermissionDenied),
3008
3107
  false => Ok(()),
3009
3108
  }
3010
3109
  }
@@ -3013,8 +3112,8 @@ mod tests {
3013
3112
  /// A security module counting the changes it is asked about.
3014
3113
  struct CountsChanges(Arc<AtomicUsize>);
3015
3114
 
3016
- impl vfs::SecurityOperations for CountsChanges {
3017
- fn inode_permission(&self, _dentry: &Dentry, mask: Mask) -> Result<(), FilesystemError> {
3115
+ impl crate::security::SecurityOperations for CountsChanges {
3116
+ fn inode_permission(&self, _dentry: &Dentry, mask: Mask) -> Result<(), Errno> {
3018
3117
  if mask.contains(Mask::WRITE) {
3019
3118
  self.0.fetch_add(1, Ordering::SeqCst);
3020
3119
  }
@@ -3028,7 +3127,7 @@ mod tests {
3028
3127
  let hook = Arc::new(RecordsPermission::default());
3029
3128
  let root = permission_root(&hook);
3030
3129
  let asked = Arc::new(AtomicUsize::new(0));
3031
- let cred = vfs::Cred::new(vec![Arc::new(CountsChanges(asked.clone()))]);
3130
+ let cred = crate::cred::Cred::new(vec![Arc::new(CountsChanges(asked.clone()))]);
3032
3131
  let how = OpenHow {
3033
3132
  write: true,
3034
3133
  create: true,
@@ -3044,7 +3143,7 @@ mod tests {
3044
3143
  let after_allowed = asked.load(Ordering::SeqCst);
3045
3144
  hook.refuse_writes.store(true, Ordering::SeqCst);
3046
3145
  let refused = make("refused");
3047
- let denied = || Err(FilesystemError::PermissionDenied);
3146
+ let denied = || Err(Errno::PermissionDenied);
3048
3147
  assert_eq!(
3049
3148
  (
3050
3149
  allowed,
@@ -3065,7 +3164,7 @@ mod tests {
3065
3164
  let wrapped = Wrap::new(Arc::new(tmpfs), hook.clone());
3066
3165
  let mount = Mount::new(
3067
3166
  "/data",
3068
- Filesystem::new(Arc::new(wrapped)).expect("the instance must stand"),
3167
+ Filesystem::new(wrapped).expect("the instance must stand"),
3069
3168
  Access::ReadWrite,
3070
3169
  )
3071
3170
  .expect("/data is a guest path");
@@ -3169,7 +3268,7 @@ mod tests {
3169
3268
  struct ReadOnlyRefusingWrites;
3170
3269
 
3171
3270
  impl FileSystemType for ReadOnlyRefusingWrites {
3172
- fn fill_super(self: Arc<Self>, sb: &mut Filesystem) -> Result<(), FilesystemError> {
3271
+ fn fill_super(self: Arc<Self>, sb: &mut Filesystem) -> Result<(), Errno> {
3173
3272
  sb.set_rdonly();
3174
3273
  sb.d_make_root(vfs::Inode::new(
3175
3274
  &Kstat::new(crate::filesystem::FileType::Dir, 0),
@@ -3180,21 +3279,21 @@ mod tests {
3180
3279
  }
3181
3280
 
3182
3281
  impl InodeOperations for ReadOnlyRefusingWrites {
3183
- fn getattr(&self, dentry: &Dentry) -> Result<Kstat, FilesystemError> {
3282
+ fn getattr(&self, dentry: &Dentry) -> Result<Kstat, Errno> {
3184
3283
  Ok(match dentry.is_root() {
3185
3284
  false => Kstat::new(FileType::RegFile, 0),
3186
3285
  true => Kstat::new(FileType::Dir, 0),
3187
3286
  })
3188
3287
  }
3189
3288
 
3190
- fn lookup(&self, _dentry: &Dentry) -> Result<Lookup, FilesystemError> {
3289
+ fn lookup(&self, _dentry: &Dentry) -> Result<Lookup, Errno> {
3191
3290
  let file = Kstat::new(FileType::RegFile, 0);
3192
3291
  Ok(Lookup::Found(Inode::new(&file, Arc::new(Self))))
3193
3292
  }
3194
3293
 
3195
- fn permission(&self, _dentry: &Dentry, mask: Mask) -> Result<(), FilesystemError> {
3294
+ fn permission(&self, _dentry: &Dentry, mask: Mask) -> Result<(), Errno> {
3196
3295
  match mask.contains(Mask::WRITE) {
3197
- true => Err(FilesystemError::PermissionDenied),
3296
+ true => Err(Errno::PermissionDenied),
3198
3297
  false => Ok(()),
3199
3298
  }
3200
3299
  }
@@ -3207,7 +3306,7 @@ mod tests {
3207
3306
  fn a_read_only_filesystem_refuses_a_write_before_its_permission_is_asked() {
3208
3307
  let mount = Mount::new(
3209
3308
  "/data",
3210
- Filesystem::new(Arc::new(ReadOnlyRefusingWrites)).expect("the instance must stand"),
3309
+ Filesystem::new(ReadOnlyRefusingWrites).expect("the instance must stand"),
3211
3310
  Access::ReadWrite,
3212
3311
  )
3213
3312
  .expect("/data is a guest path");
@@ -3218,7 +3317,7 @@ mod tests {
3218
3317
  assert_eq!(
3219
3318
  vfs::kern_path::filp_open(&Arc::default(), &Path::root(mount.mnt()), "file", &how)
3220
3319
  .err(),
3221
- Some(FilesystemError::ReadOnlyFilesystem),
3320
+ Some(Errno::ReadOnlyFilesystem),
3222
3321
  "vfs::do_file_open to write a file of a read-only Filesystem whose permission refuses \
3223
3322
  writes must answer EROFS, as sb_permission answers before ->permission"
3224
3323
  );
@@ -3236,16 +3335,13 @@ mod tests {
3236
3335
  hook.refuse_writes.store(false, Ordering::SeqCst);
3237
3336
  assert_eq!(
3238
3337
  (made, removed),
3239
- (
3240
- Err(FilesystemError::PermissionDenied),
3241
- Err(FilesystemError::PermissionDenied)
3242
- ),
3338
+ (Err(Errno::PermissionDenied), Err(Errno::PermissionDenied)),
3243
3339
  "vfs::filename_mkdirat and filename_unlinkat on a directory whose permission \
3244
3340
  refuses a change must answer EACCES"
3245
3341
  );
3246
3342
  assert_eq!(
3247
3343
  vfs::vfs_fstatat(&cred, &root, "a/made", false).err(),
3248
- Some(FilesystemError::NotFound),
3344
+ Some(Errno::NotFound),
3249
3345
  "a refused mkdir must make nothing"
3250
3346
  );
3251
3347
  assert!(
@@ -3257,18 +3353,18 @@ mod tests {
3257
3353
  /// A link at the name `l`, moving a directory the moment the walk follows it,
3258
3354
  /// when the walk holds no directory's lock, and leading back where it stands.
3259
3355
  struct MovesWhenFollowed {
3260
- cred: Arc<vfs::Cred>,
3356
+ cred: Arc<crate::cred::Cred>,
3261
3357
  root: Arc<OnceLock<Path>>,
3262
3358
  from: &'static str,
3263
3359
  to: &'static str,
3264
3360
  }
3265
3361
 
3266
3362
  impl InodeOperations for MovesWhenFollowed {
3267
- fn getattr(&self, _dentry: &Dentry) -> Result<Kstat, FilesystemError> {
3363
+ fn getattr(&self, _dentry: &Dentry) -> Result<Kstat, Errno> {
3268
3364
  Ok(Kstat::new(FileType::Symlink, 0))
3269
3365
  }
3270
3366
 
3271
- fn get_link(&self, _dentry: &Dentry) -> Result<String, FilesystemError> {
3367
+ fn get_link(&self, _dentry: &Dentry) -> Result<String, Errno> {
3272
3368
  let root = self.root.get().expect("the mount stands by the first walk");
3273
3369
  vfs::filename_renameat2(&self.cred, root, self.from, root, self.to)?;
3274
3370
  Ok(".".to_string())
@@ -3278,11 +3374,7 @@ mod tests {
3278
3374
  struct LinkAtL(Arc<dyn InodeOperations>);
3279
3375
 
3280
3376
  impl wrap::Hook for LinkAtL {
3281
- fn lookup(
3282
- &self,
3283
- inner: &dyn InodeOperations,
3284
- dentry: &Dentry,
3285
- ) -> Result<Lookup, FilesystemError> {
3377
+ fn lookup(&self, inner: &dyn InodeOperations, dentry: &Dentry) -> Result<Lookup, Errno> {
3286
3378
  if dentry.name() != "l" {
3287
3379
  return inner.lookup(dentry);
3288
3380
  }
@@ -3308,7 +3400,7 @@ mod tests {
3308
3400
  let wrapped = Wrap::new(Arc::new(tmpfs), Arc::new(LinkAtL(Arc::new(link))));
3309
3401
  let mount = Mount::new(
3310
3402
  "/data",
3311
- Filesystem::new(Arc::new(wrapped)).expect("the instance must stand"),
3403
+ Filesystem::new(wrapped).expect("the instance must stand"),
3312
3404
  Access::ReadWrite,
3313
3405
  )
3314
3406
  .expect("/data is a guest path");
@@ -3327,19 +3419,78 @@ mod tests {
3327
3419
  let during = vfs::vfs_fstatat(&cred, &root, "a/b/l/../c", false);
3328
3420
  // Any move in the process answers a `..` so, as `rename_lock` is one for all,
3329
3421
  // and tests beside this one make them.
3330
- let mut after = Err(FilesystemError::WouldBlock);
3422
+ let mut after = Err(Errno::WouldBlock);
3331
3423
  crate::sched::testing::wait_until("the call made again answering", || {
3332
3424
  after = vfs::vfs_fstatat(&cred, &root, "z/b/../c", false);
3333
- after != Err(FilesystemError::WouldBlock)
3425
+ after != Err(Errno::WouldBlock)
3334
3426
  });
3335
3427
  assert_eq!(
3336
3428
  (during.map(|_| ()), after.map(|stat| stat.size)),
3337
- (Err(FilesystemError::WouldBlock), Ok(5)),
3429
+ (Err(Errno::WouldBlock), Ok(5)),
3338
3430
  "vfs_fstatat through `..` with a move landing during the walk must answer EAGAIN, \
3339
3431
  as handle_dots reads r_seq, and the call made again reaches where it stands now"
3340
3432
  );
3341
3433
  }
3342
3434
 
3435
+ // The `..` here leaves the root of a nested mount, which climbs back to where
3436
+ // the walk stepped onto it rather than reading a parent.
3437
+ // @behavior RT-240
3438
+ #[test]
3439
+ fn a_dotdot_out_of_a_nested_mount_a_move_landed_before_asks_the_caller_again() {
3440
+ let outer = Mount::new(
3441
+ "/data",
3442
+ Filesystem::new(
3443
+ [("inner/keep", "k"), ("x/c", "moved")]
3444
+ .into_iter()
3445
+ .collect::<Tmpfs>(),
3446
+ )
3447
+ .expect("the instance must stand"),
3448
+ Access::ReadWrite,
3449
+ )
3450
+ .expect("/data is a guest path");
3451
+ let root = Arc::new(OnceLock::new());
3452
+ let link = MovesWhenFollowed {
3453
+ cred: Arc::default(),
3454
+ root: root.clone(),
3455
+ from: "x",
3456
+ to: "y",
3457
+ };
3458
+ let wrapped = Wrap::new(
3459
+ Arc::new(Tmpfs::default()),
3460
+ Arc::new(LinkAtL(Arc::new(link))),
3461
+ );
3462
+ let inner = Mount::new(
3463
+ "/data/inner",
3464
+ Filesystem::new(wrapped).expect("the instance must stand"),
3465
+ Access::ReadWrite,
3466
+ )
3467
+ .expect("/data/inner is a guest path");
3468
+ let outer_root = Path::root(outer.mnt());
3469
+ root.set(outer_root.clone()).ok().expect("set only here");
3470
+ let cred = crate::security::restrict_self(
3471
+ &Arc::default(),
3472
+ [
3473
+ &crate::grant::Grant::Mount(outer),
3474
+ &crate::grant::Grant::Mount(inner),
3475
+ ],
3476
+ )
3477
+ .expect("every Mount stands");
3478
+ let during = vfs::vfs_fstatat(&cred, &outer_root, "inner/l/../y/c", false);
3479
+ // Any move in the process answers a `..` so, and tests beside this one
3480
+ // make them.
3481
+ let mut after = Err(Errno::WouldBlock);
3482
+ crate::sched::testing::wait_until("the call made again answering", || {
3483
+ after = vfs::vfs_fstatat(&cred, &outer_root, "inner/../y/c", false);
3484
+ after != Err(Errno::WouldBlock)
3485
+ });
3486
+ assert_eq!(
3487
+ (during.map(|_| ()), after.map(|stat| stat.size)),
3488
+ (Err(Errno::WouldBlock), Ok(5)),
3489
+ "a stat through a `..` out of a nested mount's root, with a move landing during \
3490
+ the walk, must answer EAGAIN, and made again reach where the moved directory stands"
3491
+ );
3492
+ }
3493
+
3343
3494
  // @behavior RT-241
3344
3495
  #[test]
3345
3496
  fn a_walk_carried_out_from_under_its_start_answers_an_escape() {
@@ -3354,7 +3505,7 @@ mod tests {
3354
3505
  let ended = vfs::vfs_fstatat(&cred, start.path(), "b/l/k", false);
3355
3506
  assert_eq!(
3356
3507
  ended.err(),
3357
- Some(FilesystemError::Escape),
3508
+ Some(Errno::Escape),
3358
3509
  "vfs_fstatat ending on what a move carried out from under its start must \
3359
3510
  answer an escape, as complete_walk asks path_is_under"
3360
3511
  );
@@ -3383,10 +3534,7 @@ mod tests {
3383
3534
  let open = vfs::kern_path::filp_open(&cred, start().path(), "b/l/missing", &read);
3384
3535
  assert_eq!(
3385
3536
  (stat.err(), open.err()),
3386
- (
3387
- Some(FilesystemError::NotFound),
3388
- Some(FilesystemError::NotFound)
3389
- ),
3537
+ (Some(Errno::NotFound), Some(Errno::NotFound)),
3390
3538
  "vfs_fstatat and do_file_open of a name nothing stands at, through a directory a \
3391
3539
  move carried out from under the start, must answer ENOENT, as step_into does \
3392
3540
  before complete_walk"
@@ -3401,10 +3549,10 @@ mod tests {
3401
3549
  fn a_link_to_what_has_no_name_left_answers_enoent() {
3402
3550
  let answers = |names| {
3403
3551
  let linked = Arc::new(AtomicUsize::new(0));
3404
- let filesystem = Filesystem::new(Arc::new(LinksFile {
3552
+ let filesystem = Filesystem::new(LinksFile {
3405
3553
  names,
3406
3554
  linked: linked.clone(),
3407
- }))
3555
+ })
3408
3556
  .expect("the instance must stand");
3409
3557
  let root = root_of(filesystem);
3410
3558
  let answer =
@@ -3413,7 +3561,7 @@ mod tests {
3413
3561
  };
3414
3562
  assert_eq!(
3415
3563
  (answers(0), answers(1)),
3416
- ((Err(FilesystemError::NotFound), 0), (Ok(()), 1)),
3564
+ ((Err(Errno::NotFound), 0), (Ok(()), 1)),
3417
3565
  "vfs::filename_linkat of an entry reporting no names must answer ENOENT and ask for no \
3418
3566
  link, and of one reporting a name must make it"
3419
3567
  );
@@ -3426,9 +3574,8 @@ mod tests {
3426
3574
  #[test]
3427
3575
  fn a_change_asks_a_filesystem_once_for_the_name_it_makes() {
3428
3576
  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");
3577
+ let filesystem = Filesystem::new(Wrap::new(Arc::new(Tmpfs::new()), counts.clone()))
3578
+ .expect("the instance must stand");
3432
3579
  let root = root_of(filesystem);
3433
3580
  let cred = Arc::default();
3434
3581
  let how = OpenHow {
@@ -3480,17 +3627,13 @@ mod tests {
3480
3627
  struct HookedDentry(Arc<AtomicBool>);
3481
3628
 
3482
3629
  impl DentryOperations for HookedDentry {
3483
- fn revalidate(
3484
- &self,
3485
- _dir: &dyn InodeOperations,
3486
- _dentry: &Dentry,
3487
- ) -> Result<bool, FilesystemError> {
3630
+ fn revalidate(&self, _dir: &dyn InodeOperations, _dentry: &Dentry) -> Result<bool, Errno> {
3488
3631
  Ok(!self.0.load(Ordering::SeqCst))
3489
3632
  }
3490
3633
  }
3491
3634
 
3492
3635
  impl FileSystemType for HookedTmpfs {
3493
- fn fill_super(self: Arc<Self>, sb: &mut Filesystem) -> Result<(), FilesystemError> {
3636
+ fn fill_super(self: Arc<Self>, sb: &mut Filesystem) -> Result<(), Errno> {
3494
3637
  sb.set_default_d_op(Arc::new(HookedDentry(self.stale.clone())));
3495
3638
  sb.d_make_root(vfs::Inode::new(
3496
3639
  &Kstat::new(crate::filesystem::FileType::Dir, 0),
@@ -3501,57 +3644,62 @@ mod tests {
3501
3644
  }
3502
3645
 
3503
3646
  impl InodeOperations for HookedTmpfs {
3504
- fn getattr(&self, dentry: &Dentry) -> Result<Kstat, FilesystemError> {
3647
+ fn getattr(&self, dentry: &Dentry) -> Result<Kstat, Errno> {
3505
3648
  self.tmpfs.getattr(dentry)
3506
3649
  }
3507
3650
 
3508
- fn lookup(&self, dentry: &Dentry) -> Result<Lookup, FilesystemError> {
3509
- self.tmpfs.lookup(dentry)
3651
+ /// Once stale, each name stands for another entry than the one it held,
3652
+ /// so what is found there reports an identity of its own.
3653
+ fn lookup(&self, dentry: &Dentry) -> Result<Lookup, Errno> {
3654
+ match self.tmpfs.lookup(dentry)? {
3655
+ Lookup::Found(inode) if self.stale.load(Ordering::SeqCst) => {
3656
+ let replaced =
3657
+ Kstat::new(inode.file_type(), 0).with_identity(u64::MAX, u64::MAX);
3658
+ Ok(Lookup::Found(Inode::new(&replaced, inode.ops().clone())))
3659
+ }
3660
+ found => Ok(found),
3661
+ }
3510
3662
  }
3511
3663
 
3512
- fn create(&self, dentry: &Dentry) -> Result<(), FilesystemError> {
3664
+ fn create(&self, dentry: &Dentry) -> Result<(), Errno> {
3513
3665
  self.tmpfs.create(dentry)
3514
3666
  }
3515
3667
 
3516
- fn open(
3517
- &self,
3518
- dentry: &Dentry,
3519
- how: &OpenHow,
3520
- ) -> Result<Box<dyn FileOperations>, FilesystemError> {
3668
+ fn open(&self, dentry: &Dentry, how: &OpenHow) -> Result<Box<dyn FileOperations>, Errno> {
3521
3669
  self.tmpfs.open(dentry, how)
3522
3670
  }
3523
3671
 
3524
- fn mkdir(&self, dentry: &Dentry) -> Result<(), FilesystemError> {
3672
+ fn mkdir(&self, dentry: &Dentry) -> Result<(), Errno> {
3525
3673
  match &self.making {
3526
3674
  Some(making) => making(),
3527
3675
  None => self.tmpfs.mkdir(dentry),
3528
3676
  }
3529
3677
  }
3530
3678
 
3531
- fn rmdir(&self, dentry: &Dentry) -> Result<(), FilesystemError> {
3679
+ fn rmdir(&self, dentry: &Dentry) -> Result<(), Errno> {
3532
3680
  self.tmpfs.rmdir(dentry)?;
3533
3681
  self.removed.as_ref().map_or(Ok(()), |removed| removed())
3534
3682
  }
3535
3683
 
3536
- fn unlink(&self, dentry: &Dentry) -> Result<(), FilesystemError> {
3684
+ fn unlink(&self, dentry: &Dentry) -> Result<(), Errno> {
3537
3685
  self.tmpfs.unlink(dentry)
3538
3686
  }
3539
3687
 
3540
3688
  fn rename(
3541
3689
  &self,
3542
- from: &Dentry,
3543
- to_dir: &dyn InodeOperations,
3544
- to: &Dentry,
3545
- flag: Option<RenameFlag>,
3546
- ) -> Result<(), FilesystemError> {
3690
+ old: &Dentry,
3691
+ new_dir: &dyn InodeOperations,
3692
+ new: &Dentry,
3693
+ flags: Option<RenameFlag>,
3694
+ ) -> Result<(), Errno> {
3547
3695
  self.renames.fetch_add(1, Ordering::SeqCst);
3548
3696
  if let Some(renaming) = &self.renaming {
3549
3697
  renaming()?;
3550
3698
  }
3551
- let to_dir = (to_dir as &dyn std::any::Any)
3699
+ let new_dir = (new_dir as &dyn std::any::Any)
3552
3700
  .downcast_ref::<Self>()
3553
- .map_or(to_dir, |hooked| &hooked.tmpfs);
3554
- self.tmpfs.rename(from, to_dir, to, flag)
3701
+ .map_or(new_dir, |hooked| &hooked.tmpfs);
3702
+ self.tmpfs.rename(old, new_dir, new, flags)
3555
3703
  }
3556
3704
  }
3557
3705
 
@@ -3577,17 +3725,17 @@ mod tests {
3577
3725
  &mut self,
3578
3726
  dentry: &Dentry,
3579
3727
  ctx: &mut vfs::DirContext<'_>,
3580
- ) -> Result<(), FilesystemError> {
3728
+ ) -> Result<(), Errno> {
3581
3729
  let entries = match folded_path_of(dentry).as_str() {
3582
3730
  "" => self.0.iterate_dir(),
3583
3731
  at => self.0.open_dir(at)?.iterate_dir(),
3584
3732
  }?;
3585
- crate::filesystem::Rdir::default().iterate(dentry, ctx, || Ok(entries))
3733
+ crate::filesystem::Rdir::default().iterate_shared(dentry, ctx, || Ok(entries))
3586
3734
  }
3587
3735
  }
3588
3736
 
3589
3737
  impl FileSystemType for FoldsToUpper {
3590
- fn fill_super(self: Arc<Self>, sb: &mut Filesystem) -> Result<(), FilesystemError> {
3738
+ fn fill_super(self: Arc<Self>, sb: &mut Filesystem) -> Result<(), Errno> {
3591
3739
  sb.d_make_root(vfs::Inode::new(
3592
3740
  &Kstat::new(crate::filesystem::FileType::Dir, 0),
3593
3741
  self,
@@ -3597,11 +3745,11 @@ mod tests {
3597
3745
  }
3598
3746
 
3599
3747
  impl InodeOperations for FoldsToUpper {
3600
- fn getattr(&self, dentry: &Dentry) -> Result<Kstat, FilesystemError> {
3748
+ fn getattr(&self, dentry: &Dentry) -> Result<Kstat, Errno> {
3601
3749
  self.root.vfs_lstat(&folded_path_of(dentry))
3602
3750
  }
3603
3751
 
3604
- fn lookup(&self, dentry: &Dentry) -> Result<Lookup, FilesystemError> {
3752
+ fn lookup(&self, dentry: &Dentry) -> Result<Lookup, Errno> {
3605
3753
  let name = dentry.name();
3606
3754
  let upper = name.to_uppercase();
3607
3755
  match self.root.vfs_lstat(&folded_path_of(dentry)) {
@@ -3610,23 +3758,19 @@ mod tests {
3610
3758
  inode: Inode::new(&found, Arc::new(self.clone())),
3611
3759
  }),
3612
3760
  Ok(found) => Ok(Lookup::Found(Inode::new(&found, Arc::new(self.clone())))),
3613
- Err(FilesystemError::NotFound) => Ok(Lookup::Absent),
3761
+ Err(Errno::NotFound) => Ok(Lookup::Absent),
3614
3762
  Err(err) => Err(err),
3615
3763
  }
3616
3764
  }
3617
3765
 
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) {
3766
+ fn open(&self, dentry: &Dentry, how: &OpenHow) -> Result<Box<dyn FileOperations>, Errno> {
3767
+ if dentry.file_type() == Ok(crate::filesystem::FileType::Dir) {
3624
3768
  return Ok(Box::new(FoldedDir(self.root.clone())));
3625
3769
  }
3626
3770
  self.root.open(&folded_path_of(dentry), how)
3627
3771
  }
3628
3772
 
3629
- fn atomic_open(&self, dentry: &Dentry, how: &OpenHow) -> Result<Finish, FilesystemError> {
3773
+ fn atomic_open(&self, dentry: &Dentry, how: &OpenHow) -> Result<Finish, Errno> {
3630
3774
  if dentry.in_lookup() {
3631
3775
  let found = self.lookup(dentry)?;
3632
3776
  if !how.create || !matches!(found, Lookup::Absent) {
@@ -3643,28 +3787,28 @@ mod tests {
3643
3787
  })
3644
3788
  }
3645
3789
 
3646
- fn mkdir(&self, dentry: &Dentry) -> Result<(), FilesystemError> {
3790
+ fn mkdir(&self, dentry: &Dentry) -> Result<(), Errno> {
3647
3791
  self.root.vfs_mkdir(&folded_path_of(dentry))
3648
3792
  }
3649
3793
 
3650
- fn rmdir(&self, dentry: &Dentry) -> Result<(), FilesystemError> {
3794
+ fn rmdir(&self, dentry: &Dentry) -> Result<(), Errno> {
3651
3795
  self.root.vfs_rmdir(&folded_path_of(dentry))
3652
3796
  }
3653
3797
 
3654
- fn unlink(&self, dentry: &Dentry) -> Result<(), FilesystemError> {
3798
+ fn unlink(&self, dentry: &Dentry) -> Result<(), Errno> {
3655
3799
  self.root.vfs_unlink(&folded_path_of(dentry))
3656
3800
  }
3657
3801
 
3658
3802
  fn rename(
3659
3803
  &self,
3660
- from: &Dentry,
3661
- _to_dir: &dyn InodeOperations,
3662
- to: &Dentry,
3663
- _flag: Option<RenameFlag>,
3664
- ) -> Result<(), FilesystemError> {
3804
+ old: &Dentry,
3805
+ _new_dir: &dyn InodeOperations,
3806
+ new: &Dentry,
3807
+ _flags: Option<RenameFlag>,
3808
+ ) -> Result<(), Errno> {
3665
3809
  (self.renaming)()?;
3666
3810
  self.root
3667
- .rename(&folded_path_of(from), &self.root, &folded_path_of(to))
3811
+ .rename(&folded_path_of(old), &self.root, &folded_path_of(new))
3668
3812
  }
3669
3813
  }
3670
3814
 
@@ -3673,7 +3817,7 @@ mod tests {
3673
3817
  struct OpensItsLinks(Arc<AtomicUsize>);
3674
3818
 
3675
3819
  impl FileSystemType for OpensItsLinks {
3676
- fn fill_super(self: Arc<Self>, sb: &mut Filesystem) -> Result<(), FilesystemError> {
3820
+ fn fill_super(self: Arc<Self>, sb: &mut Filesystem) -> Result<(), Errno> {
3677
3821
  sb.d_make_root(vfs::Inode::new(
3678
3822
  &Kstat::new(crate::filesystem::FileType::Dir, 0),
3679
3823
  self,
@@ -3683,21 +3827,17 @@ mod tests {
3683
3827
  }
3684
3828
 
3685
3829
  impl InodeOperations for OpensItsLinks {
3686
- fn getattr(&self, _dentry: &Dentry) -> Result<Kstat, FilesystemError> {
3830
+ fn getattr(&self, _dentry: &Dentry) -> Result<Kstat, Errno> {
3687
3831
  Ok(Kstat::new(crate::filesystem::FileType::Symlink, 0))
3688
3832
  }
3689
3833
 
3690
- fn lookup(&self, _dentry: &Dentry) -> Result<Lookup, FilesystemError> {
3834
+ fn lookup(&self, _dentry: &Dentry) -> Result<Lookup, Errno> {
3691
3835
  let link = Kstat::new(crate::filesystem::FileType::Symlink, 0);
3692
3836
  let ops = Arc::new(Self(self.0.clone()));
3693
3837
  Ok(Lookup::Found(Inode::new(&link, ops)))
3694
3838
  }
3695
3839
 
3696
- fn open(
3697
- &self,
3698
- _dentry: &Dentry,
3699
- _how: &OpenHow,
3700
- ) -> Result<Box<dyn FileOperations>, FilesystemError> {
3840
+ fn open(&self, _dentry: &Dentry, _how: &OpenHow) -> Result<Box<dyn FileOperations>, Errno> {
3701
3841
  struct OpenLink;
3702
3842
  impl FileOperations for OpenLink {}
3703
3843
  self.0.fetch_add(1, Ordering::SeqCst);
@@ -3709,23 +3849,21 @@ mod tests {
3709
3849
  // it shows the VFS is what holds this line for every third party.
3710
3850
  /// What each call answers beneath a mount `prepare` finishes, over a
3711
3851
  /// Tmpfs holding the directory `dir`.
3712
- fn answers(
3713
- prepare: impl Fn(Mount) -> Mount,
3714
- access: Access,
3715
- ) -> [Result<(), FilesystemError>; 3] {
3852
+ fn answers(prepare: impl Fn(Mount) -> Mount, access: Access) -> [Result<(), Errno>; 3] {
3716
3853
  let tmpfs: Tmpfs = [("dir/file", "x")].into_iter().collect();
3717
3854
  let mount = prepare(
3718
3855
  Mount::new(
3719
3856
  "/data",
3720
- Filesystem::new(Arc::new(tmpfs)).expect("the instance must stand"),
3857
+ Filesystem::new(tmpfs).expect("the instance must stand"),
3721
3858
  access,
3722
3859
  )
3723
3860
  .expect("/data is a guest path"),
3724
3861
  );
3725
3862
  let cred = crate::security::restrict_self(
3726
- &crate::security::prepare_creds_within(&[], None),
3727
- [&mount],
3728
- );
3863
+ &crate::security::prepare_creds(&[], None),
3864
+ [&crate::grant::Grant::Mount(mount.clone())],
3865
+ )
3866
+ .expect("every Mount stands");
3729
3867
  let root = Path::root(mount.mnt());
3730
3868
  [
3731
3869
  vfs::filename_mkdirat(&cred, &root, "dir"),
@@ -3736,8 +3874,8 @@ mod tests {
3736
3874
 
3737
3875
  struct RefusesAll;
3738
3876
 
3739
- impl Policy for RefusesAll {
3740
- fn allows(&self, _path: &str, _access: Access) -> bool {
3877
+ impl Policy<MountRequest<'_>> for RefusesAll {
3878
+ fn allows(&self, _request: &MountRequest<'_>) -> bool {
3741
3879
  false
3742
3880
  }
3743
3881
  }
@@ -3750,9 +3888,9 @@ mod tests {
3750
3888
  assert_eq!(
3751
3889
  answers(|mount| mount, Access::Read),
3752
3890
  [
3753
- Err(FilesystemError::AlreadyExists),
3754
- Err(FilesystemError::ReadOnlyFilesystem),
3755
- Err(FilesystemError::ReadOnlyFilesystem),
3891
+ Err(Errno::AlreadyExists),
3892
+ Err(Errno::ReadOnlyFilesystem),
3893
+ Err(Errno::ReadOnlyFilesystem),
3756
3894
  ],
3757
3895
  "vfs::filename_mkdirat of what stands beneath a read-only Mount must answer EEXIST, \
3758
3896
  and vfs::filename_rmdir and filename_unlinkat of what does not EROFS"
@@ -3768,9 +3906,9 @@ mod tests {
3768
3906
  Access::ReadWrite
3769
3907
  ),
3770
3908
  [
3771
- Err(FilesystemError::AlreadyExists),
3772
- Err(FilesystemError::NotFound),
3773
- Err(FilesystemError::NotFound),
3909
+ Err(Errno::AlreadyExists),
3910
+ Err(Errno::NotFound),
3911
+ Err(Errno::NotFound),
3774
3912
  ],
3775
3913
  "vfs::filename_mkdirat of what stands, and vfs::filename_rmdir and filename_unlinkat \
3776
3914
  of what does not, beneath a Policy refusing everything, must answer as \
@@ -3784,7 +3922,7 @@ mod tests {
3784
3922
  let mount = |tmpfs: Tmpfs| {
3785
3923
  Mount::new(
3786
3924
  "/data",
3787
- Filesystem::new(Arc::new(tmpfs)).expect("the instance must stand"),
3925
+ Filesystem::new(tmpfs).expect("the instance must stand"),
3788
3926
  Access::ReadWrite,
3789
3927
  )
3790
3928
  .expect("/data is a guest path")
@@ -3798,7 +3936,7 @@ mod tests {
3798
3936
  &Path::root(second.mnt()),
3799
3937
  "moved"
3800
3938
  ),
3801
- Err(FilesystemError::CrossesDevices),
3939
+ Err(Errno::CrossesDevices),
3802
3940
  "vfs::filename_renameat2 of `.` to another Mount must answer EXDEV, as \
3803
3941
  filename_renameat2 answers a move across mounts first"
3804
3942
  );
@@ -3809,7 +3947,7 @@ mod tests {
3809
3947
  struct OneEntry(Arc<AtomicUsize>);
3810
3948
 
3811
3949
  impl FileSystemType for OneEntry {
3812
- fn fill_super(self: Arc<Self>, sb: &mut Filesystem) -> Result<(), FilesystemError> {
3950
+ fn fill_super(self: Arc<Self>, sb: &mut Filesystem) -> Result<(), Errno> {
3813
3951
  sb.d_make_root(vfs::Inode::new(
3814
3952
  &Kstat::new(crate::filesystem::FileType::Dir, 0),
3815
3953
  self,
@@ -3819,11 +3957,11 @@ mod tests {
3819
3957
  }
3820
3958
 
3821
3959
  impl InodeOperations for OneEntry {
3822
- fn getattr(&self, _dentry: &Dentry) -> Result<Kstat, FilesystemError> {
3960
+ fn getattr(&self, _dentry: &Dentry) -> Result<Kstat, Errno> {
3823
3961
  Ok(Kstat::new(crate::filesystem::FileType::Dir, 0))
3824
3962
  }
3825
3963
 
3826
- fn lookup(&self, _dentry: &Dentry) -> Result<Lookup, FilesystemError> {
3964
+ fn lookup(&self, _dentry: &Dentry) -> Result<Lookup, Errno> {
3827
3965
  let entry = Kstat::new(crate::filesystem::FileType::RegFile, 0).with_identity(1, 2);
3828
3966
  Ok(Lookup::Found(Inode::new(
3829
3967
  &entry,
@@ -3833,11 +3971,11 @@ mod tests {
3833
3971
 
3834
3972
  fn rename(
3835
3973
  &self,
3836
- _from: &Dentry,
3837
- _to_dir: &dyn InodeOperations,
3838
- _to: &Dentry,
3839
- _flag: Option<RenameFlag>,
3840
- ) -> Result<(), FilesystemError> {
3974
+ _old: &Dentry,
3975
+ _new_dir: &dyn InodeOperations,
3976
+ _new: &Dentry,
3977
+ _flags: Option<RenameFlag>,
3978
+ ) -> Result<(), Errno> {
3841
3979
  self.0.fetch_add(1, Ordering::SeqCst);
3842
3980
  Ok(())
3843
3981
  }
@@ -3847,9 +3985,8 @@ mod tests {
3847
3985
  #[test]
3848
3986
  fn a_move_between_two_names_of_one_entry_changes_nothing() {
3849
3987
  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
- );
3988
+ let root =
3989
+ root_of(Filesystem::new(OneEntry(moves.clone())).expect("the instance must stand"));
3853
3990
  assert_eq!(
3854
3991
  (
3855
3992
  vfs::filename_renameat2(&Arc::default(), &root, "a", &root, "b"),
@@ -3869,21 +4006,24 @@ mod tests {
3869
4006
  let tmpfs: Tmpfs = [("file", "x")].into_iter().collect();
3870
4007
  let plain = Mount::new(
3871
4008
  "/data",
3872
- Filesystem::new(Arc::new(tmpfs)).expect("the instance must stand"),
4009
+ Filesystem::new(tmpfs).expect("the instance must stand"),
3873
4010
  Access::ReadWrite,
3874
4011
  )
3875
4012
  .expect("/data is a guest path");
3876
4013
  let links = Mount::new(
3877
4014
  "/data",
3878
- Filesystem::new(Arc::new(OpensItsLinks(Arc::default())))
3879
- .expect("the instance must stand"),
4015
+ Filesystem::new(OpensItsLinks(Arc::default())).expect("the instance must stand"),
3880
4016
  Access::ReadWrite,
3881
4017
  )
3882
4018
  .expect("/data is a guest path");
3883
4019
  let cred = crate::security::restrict_self(
3884
- &crate::security::prepare_creds_within(&[], None),
3885
- [&plain, &links],
3886
- );
4020
+ &crate::security::prepare_creds(&[], None),
4021
+ [
4022
+ &crate::grant::Grant::Mount(plain.clone()),
4023
+ &crate::grant::Grant::Mount(links.clone()),
4024
+ ],
4025
+ )
4026
+ .expect("every Mount stands");
3887
4027
  let (plain, links) = (Path::root(plain.mnt()), Path::root(links.mnt()));
3888
4028
  assert_eq!(
3889
4029
  (
@@ -3892,9 +4032,9 @@ mod tests {
3892
4032
  vfs::do_readlinkat(&cred, &links, "link"),
3893
4033
  ),
3894
4034
  (
3895
- Err(FilesystemError::NotFound),
3896
- Err(FilesystemError::InvalidInput),
3897
- Err(FilesystemError::Unsupported),
4035
+ Err(Errno::NotFound),
4036
+ Err(Errno::InvalidInput),
4037
+ Err(Errno::Unsupported),
3898
4038
  ),
3899
4039
  "vfs::do_readlinkat must answer ENOENT for what does not stand, EINVAL for what is no \
3900
4040
  link, and only a link what the security hook answers"
@@ -3906,8 +4046,7 @@ mod tests {
3906
4046
  fn an_open_refuses_a_link_before_its_filesystem_is_asked() {
3907
4047
  let asked = Arc::new(AtomicUsize::new(0));
3908
4048
  let root = root_of(
3909
- Filesystem::new(Arc::new(OpensItsLinks(asked.clone())))
3910
- .expect("the instance must stand"),
4049
+ Filesystem::new(OpensItsLinks(asked.clone())).expect("the instance must stand"),
3911
4050
  );
3912
4051
  let read = OpenHow {
3913
4052
  read: true,
@@ -3916,7 +4055,7 @@ mod tests {
3916
4055
  let answer = vfs::kern_path::filp_open(&Arc::default(), &root, "link", &read);
3917
4056
  assert_eq!(
3918
4057
  (answer.err(), asked.load(Ordering::SeqCst)),
3919
- (Some(FilesystemError::FilesystemLoop), 0),
4058
+ (Some(Errno::FilesystemLoop), 0),
3920
4059
  "vfs::do_file_open of a link to read following none, over a Filesystem that would \
3921
4060
  open it, must answer ELOOP and leave the Filesystem unasked"
3922
4061
  );
@@ -3927,8 +4066,7 @@ mod tests {
3927
4066
  fn an_open_standing_for_a_path_opens_nothing() {
3928
4067
  let asked = Arc::new(AtomicUsize::new(0));
3929
4068
  let root = root_of(
3930
- Filesystem::new(Arc::new(OpensItsLinks(asked.clone())))
3931
- .expect("the instance must stand"),
4069
+ Filesystem::new(OpensItsLinks(asked.clone())).expect("the instance must stand"),
3932
4070
  );
3933
4071
  let answer = vfs::kern_path::filp_open(&Arc::default(), &root, "link", &OpenHow::default());
3934
4072
  assert_eq!(
@@ -3972,23 +4110,21 @@ mod tests {
3972
4110
  fn an_entry_neither_file_nor_directory_opens_as_access_denied() {
3973
4111
  let tmpfs = Tmpfs::new();
3974
4112
  tmpfs.whiteout("w").expect("the whiteout must be made");
3975
- let root = root_of(Filesystem::new(Arc::new(tmpfs)).expect("the instance must stand"));
4113
+ let root = root_of(Filesystem::new(tmpfs).expect("the instance must stand"));
3976
4114
  let how = OpenHow {
3977
4115
  read: true,
3978
4116
  ..OpenHow::default()
3979
4117
  };
3980
4118
  assert_eq!(
3981
4119
  vfs::kern_path::filp_open(
3982
- &crate::security::restrict_self(
3983
- &crate::security::prepare_creds_within(&[], None),
3984
- []
3985
- ),
4120
+ &crate::security::restrict_self(&crate::security::prepare_creds(&[], None), [])
4121
+ .expect("every Mount stands"),
3986
4122
  &root,
3987
4123
  "w",
3988
4124
  &how
3989
4125
  )
3990
4126
  .err(),
3991
- Some(FilesystemError::PermissionDenied),
4127
+ Some(Errno::PermissionDenied),
3992
4128
  "a character device through vfs::do_file_open must answer PermissionDenied"
3993
4129
  );
3994
4130
  }
@@ -4030,7 +4166,7 @@ mod tests {
4030
4166
  })),
4031
4167
  ..HookedTmpfs::default()
4032
4168
  };
4033
- let root = root_of(Filesystem::new(Arc::new(hooked)).expect("the instance must stand"));
4169
+ let root = root_of(Filesystem::new(hooked).expect("the instance must stand"));
4034
4170
  vfs::filename_mkdirat(&Arc::default(), &root, "d").expect("the directory must be made");
4035
4171
  let remover = {
4036
4172
  let root = root.clone();
@@ -4060,8 +4196,8 @@ mod tests {
4060
4196
  resume: Mutex<mpsc::Receiver<()>>,
4061
4197
  }
4062
4198
 
4063
- impl Policy for PausesFirst {
4064
- fn allows(&self, _path: &str, _access: Access) -> bool {
4199
+ impl Policy<MountRequest<'_>> for PausesFirst {
4200
+ fn allows(&self, _request: &MountRequest<'_>) -> bool {
4065
4201
  if !self.answered.swap(true, Ordering::SeqCst) {
4066
4202
  self.reached.lock().expect("unpoisoned").send(()).ok();
4067
4203
  let _ = self
@@ -4090,16 +4226,17 @@ mod tests {
4090
4226
  let tmpfs: Tmpfs = [("f", "x")].into_iter().collect();
4091
4227
  let mount = Mount::new(
4092
4228
  "/data",
4093
- Filesystem::new(Arc::new(tmpfs)).expect("the instance must stand"),
4229
+ Filesystem::new(tmpfs).expect("the instance must stand"),
4094
4230
  Access::ReadWrite,
4095
4231
  )
4096
4232
  .expect("/data is a guest path")
4097
4233
  .with_policy(Arc::new(policy));
4098
4234
  let root = Path::root(mount.mnt());
4099
4235
  let cred = crate::security::restrict_self(
4100
- &crate::security::prepare_creds_within(&[], None),
4101
- [&mount],
4102
- );
4236
+ &crate::security::prepare_creds(&[], None),
4237
+ [&crate::grant::Grant::Mount(mount.clone())],
4238
+ )
4239
+ .expect("every Mount stands");
4103
4240
  let opener = {
4104
4241
  let (root, cred) = (root.clone(), cred.clone());
4105
4242
  thread::spawn(move || {
@@ -4145,7 +4282,7 @@ mod tests {
4145
4282
  hooked.renames.load(Ordering::SeqCst)
4146
4283
  ),
4147
4284
  (
4148
- Err(FilesystemError::InvalidInput),
4285
+ Err(Errno::InvalidInput),
4149
4286
  0
4150
4287
  ),
4151
4288
  "vfs::filename_renameat2 of a directory into a directory beneath it must answer InvalidInput \
@@ -4171,11 +4308,11 @@ mod tests {
4171
4308
  })),
4172
4309
  ..HookedTmpfs::default()
4173
4310
  };
4174
- let path = root_of(Filesystem::new(Arc::new(hooked)).expect("the instance must stand"));
4311
+ let path = root_of(Filesystem::new(hooked).expect("the instance must stand"));
4175
4312
  root.set(path.clone()).ok();
4176
4313
  assert_eq!(
4177
4314
  vfs::filename_mkdirat(&Arc::default(), &path, "made"),
4178
- Err(FilesystemError::Deadlock),
4315
+ Err(Errno::Deadlock),
4179
4316
  "vfs::filename_mkdirat called by a Filesystem's own create_dir on the directory the outer \
4180
4317
  vfs::filename_mkdirat holds must answer Deadlock"
4181
4318
  );
@@ -4197,11 +4334,11 @@ mod tests {
4197
4334
  })),
4198
4335
  ..HookedTmpfs::default()
4199
4336
  };
4200
- let path = root_of(Filesystem::new(Arc::new(hooked)).expect("the instance must stand"));
4337
+ let path = root_of(Filesystem::new(hooked).expect("the instance must stand"));
4201
4338
  root.set(path.clone()).ok();
4202
4339
  assert_eq!(
4203
4340
  vfs::filename_mkdirat(&Arc::default(), &path, "made"),
4204
- Err(FilesystemError::Deadlock),
4341
+ Err(Errno::Deadlock),
4205
4342
  "vfs::vfs_fstatat walking through the directory an outer vfs::filename_mkdirat holds \
4206
4343
  must answer Deadlock, as it holds that directory to find the name"
4207
4344
  );
@@ -4225,7 +4362,7 @@ mod tests {
4225
4362
  })),
4226
4363
  ..HookedTmpfs::default()
4227
4364
  };
4228
- let path = root_of(Filesystem::new(Arc::new(hooked)).expect("the instance must stand"));
4365
+ let path = root_of(Filesystem::new(hooked).expect("the instance must stand"));
4229
4366
  let kept = open_dir(&path, "kept");
4230
4367
  root.set(path.clone()).ok();
4231
4368
  assert_eq!(
@@ -4266,7 +4403,7 @@ mod tests {
4266
4403
  })),
4267
4404
  ..HookedTmpfs::default()
4268
4405
  };
4269
- let root = root_of(Filesystem::new(Arc::new(hooked)).expect("the instance must stand"));
4406
+ let root = root_of(Filesystem::new(hooked).expect("the instance must stand"));
4270
4407
  vfs::filename_mkdirat(&Arc::default(), &root, "b").expect("the directory must be made");
4271
4408
  let replaced = open_dir(&root, "b");
4272
4409
  let mover = {
@@ -4282,7 +4419,7 @@ mod tests {
4282
4419
  let moved = crate::sched::testing::join("the mover", mover);
4283
4420
  assert_eq!(
4284
4421
  (made, moved),
4285
- (Err(FilesystemError::NotFound), Ok(())),
4422
+ (Err(Errno::NotFound), Ok(())),
4286
4423
  "vfs::filename_mkdirat through a directory vfs::filename_renameat2 is replacing must \
4287
4424
  wait for the move, answer NotFound, and leave the move to succeed"
4288
4425
  );
@@ -4312,7 +4449,7 @@ mod tests {
4312
4449
  })),
4313
4450
  ..HookedTmpfs::default()
4314
4451
  };
4315
- let root = root_of(Filesystem::new(Arc::new(hooked)).expect("the instance must stand"));
4452
+ let root = root_of(Filesystem::new(hooked).expect("the instance must stand"));
4316
4453
  vfs::filename_mkdirat(&Arc::default(), &root, "d").expect("the directory must be made");
4317
4454
  let remover = {
4318
4455
  let root = root.clone();
@@ -4360,7 +4497,7 @@ mod tests {
4360
4497
  root: kern_path(Arc::new(tmpfs)),
4361
4498
  renaming,
4362
4499
  };
4363
- let root = root_of(Filesystem::new(Arc::new(folds)).expect("the instance must stand"));
4500
+ let root = root_of(Filesystem::new(folds).expect("the instance must stand"));
4364
4501
  let mover = {
4365
4502
  let root = root.clone();
4366
4503
  thread::spawn(move || {
@@ -4378,7 +4515,7 @@ mod tests {
4378
4515
  (moved, removed, counts.load(Ordering::SeqCst) > 0),
4379
4516
  (
4380
4517
  Ok(()),
4381
- Err(FilesystemError::NotFound),
4518
+ Err(Errno::NotFound),
4382
4519
  true
4383
4520
  ),
4384
4521
  "vfs::filename_unlinkat of `DIR/F` while vfs::filename_renameat2 moves `dir/f`, over a Filesystem \
@@ -4401,16 +4538,12 @@ mod tests {
4401
4538
  ops: &dyn DentryOperations,
4402
4539
  dir: &dyn InodeOperations,
4403
4540
  dentry: &Dentry,
4404
- ) -> Result<bool, FilesystemError> {
4541
+ ) -> Result<bool, Errno> {
4405
4542
  self.revalidated.fetch_add(1, Ordering::SeqCst);
4406
4543
  ops.revalidate(dir, dentry)
4407
4544
  }
4408
4545
 
4409
- fn lookup(
4410
- &self,
4411
- inner: &dyn InodeOperations,
4412
- dentry: &Dentry,
4413
- ) -> Result<Lookup, FilesystemError> {
4546
+ fn lookup(&self, inner: &dyn InodeOperations, dentry: &Dentry) -> Result<Lookup, Errno> {
4414
4547
  self.asked.fetch_add(1, Ordering::SeqCst);
4415
4548
  let stored = dentry.name().to_uppercase();
4416
4549
  Ok(match inner.lookup(dentry)? {
@@ -4431,9 +4564,9 @@ mod tests {
4431
4564
  let tmpfs: Tmpfs = [("f", "x")].into_iter().collect();
4432
4565
  let hook = Arc::new(ReportsUpperCase::default());
4433
4566
  let wrapped = Wrap::new(Arc::new(tmpfs), hook.clone());
4434
- let root = root_of(Filesystem::new(Arc::new(wrapped)).expect("the instance must stand"));
4567
+ let root = root_of(Filesystem::new(wrapped).expect("the instance must stand"));
4435
4568
  let walked = super::filename_lookup(&Arc::default(), &root, "f", false)
4436
- .and_then(|nd| Ok((nd.path()?.name(), nd.kind()?)));
4569
+ .and_then(|nd| Ok((nd.path()?.name(), nd.file_type()?)));
4437
4570
  assert_eq!(
4438
4571
  (walked, hook.asked.load(Ordering::SeqCst)),
4439
4572
  (Ok(("F".to_string(), FileType::RegFile)), 1),
@@ -4450,7 +4583,7 @@ mod tests {
4450
4583
  let tmpfs: Tmpfs = [("f", "x")].into_iter().collect();
4451
4584
  let hook = Arc::new(ReportsUpperCase::default());
4452
4585
  let wrapped = Wrap::new(Arc::new(tmpfs), hook.clone());
4453
- let root = root_of(Filesystem::new(Arc::new(wrapped)).expect("the instance must stand"));
4586
+ let root = root_of(Filesystem::new(wrapped).expect("the instance must stand"));
4454
4587
  let first = reach(&root, "f").expect("f is reached");
4455
4588
  hook.revalidated.store(0, Ordering::SeqCst);
4456
4589
  let second = reach(&root, "f").expect("f is reached again");
@@ -4466,13 +4599,61 @@ mod tests {
4466
4599
  );
4467
4600
  }
4468
4601
 
4602
+ /// A test's Filesystem whose revalidate of `d` lets a move of `d` to `c` land
4603
+ /// and then finds `d` stale, as a walk holding no lock meets a rename ending.
4604
+ #[derive(Default)]
4605
+ struct MovesWhileAsked {
4606
+ root: std::sync::OnceLock<Path>,
4607
+ moved: std::sync::atomic::AtomicBool,
4608
+ }
4609
+
4610
+ impl wrap::Hook for MovesWhileAsked {
4611
+ fn revalidate(
4612
+ &self,
4613
+ ops: &dyn DentryOperations,
4614
+ dir: &dyn InodeOperations,
4615
+ dentry: &Dentry,
4616
+ ) -> Result<bool, Errno> {
4617
+ if dentry.name() != "d" || self.moved.swap(true, Ordering::SeqCst) {
4618
+ return ops.revalidate(dir, dentry);
4619
+ }
4620
+ let root = self
4621
+ .root
4622
+ .get()
4623
+ .expect("the test hands the root before any walk");
4624
+ super::filename_renameat2(&Arc::default(), root, "d", root, "c")?;
4625
+ Ok(false)
4626
+ }
4627
+ }
4628
+
4629
+ // A second dentry for the directory would let a move put it beneath itself,
4630
+ // which no check on dentries could see.
4631
+ // @behavior RT-391
4632
+ #[test]
4633
+ fn a_directory_moved_while_a_walk_finds_it_stale_keeps_its_one_dentry() {
4634
+ let tmpfs: Tmpfs = [("d/.keep", "")].into_iter().collect();
4635
+ let hook = Arc::new(MovesWhileAsked::default());
4636
+ let wrapped = Wrap::new(Arc::new(tmpfs), hook.clone());
4637
+ let root = root_of(Filesystem::new(wrapped).expect("the instance must stand"));
4638
+ let _ = hook.root.set(root.clone());
4639
+ let held = reach(&root, "d").expect("d is reached");
4640
+ let stale = reach(&root, "d").map(|_| ());
4641
+ let moved = reach(&root, "c").expect("c is reached where d moved");
4642
+ assert_eq!(
4643
+ (stale, Arc::ptr_eq(&held, &moved)),
4644
+ (Err(Errno::NotFound), true),
4645
+ "vfs::filename_lookup of `d` finding it stale while vfs::filename_renameat2 moves it \
4646
+ to `c` must leave its dentry at `c`, as lookup_fast retries once d_seq moved"
4647
+ );
4648
+ }
4649
+
4469
4650
  // Called with no Wasm Driver in front, so the VFS is what answers for every ABI.
4470
4651
  // @behavior RT-213
4471
4652
  #[test]
4472
4653
  fn a_path_no_call_can_take_is_refused_before_a_filesystem_is_asked() {
4473
4654
  let mount = Mount::new(
4474
4655
  "/data",
4475
- Filesystem::new(Arc::new(Tmpfs::new())).expect("the instance must stand"),
4656
+ Filesystem::new(Tmpfs::new()).expect("the instance must stand"),
4476
4657
  Access::ReadWrite,
4477
4658
  )
4478
4659
  .expect("/data is a guest path");
@@ -4488,11 +4669,11 @@ mod tests {
4488
4669
  vfs::filename_symlinkat(&cred, "a\0b", &root, "link"),
4489
4670
  ],
4490
4671
  [
4491
- error(FilesystemError::InvalidInput),
4492
- error(FilesystemError::InvalidFilename),
4493
- error(FilesystemError::NotFound),
4494
- error(FilesystemError::NotFound),
4495
- error(FilesystemError::InvalidInput),
4672
+ error(Errno::InvalidInput),
4673
+ error(Errno::InvalidFilename),
4674
+ error(Errno::NotFound),
4675
+ error(Errno::NotFound),
4676
+ error(Errno::InvalidInput),
4496
4677
  ],
4497
4678
  "vfs::filename_mkdirat and filename_symlinkat must answer EINVAL for a NUL, \
4498
4679
  ENAMETOOLONG for a path that fits no PATH_MAX, and ENOENT for an empty path or target"
@@ -4508,11 +4689,7 @@ mod tests {
4508
4689
  }
4509
4690
 
4510
4691
  impl DentryOperations for CountsLookups {
4511
- fn revalidate(
4512
- &self,
4513
- _dir: &dyn InodeOperations,
4514
- _dentry: &Dentry,
4515
- ) -> Result<bool, FilesystemError> {
4692
+ fn revalidate(&self, _dir: &dyn InodeOperations, _dentry: &Dentry) -> Result<bool, Errno> {
4516
4693
  Ok(true)
4517
4694
  }
4518
4695
 
@@ -4522,7 +4699,7 @@ mod tests {
4522
4699
  }
4523
4700
 
4524
4701
  impl InodeOperations for CountsLookups {
4525
- fn getattr(&self, dentry: &Dentry) -> Result<Kstat, FilesystemError> {
4702
+ fn getattr(&self, dentry: &Dentry) -> Result<Kstat, Errno> {
4526
4703
  let kind = match dentry.is_root() {
4527
4704
  false => crate::filesystem::FileType::RegFile,
4528
4705
  true => crate::filesystem::FileType::Dir,
@@ -4530,7 +4707,7 @@ mod tests {
4530
4707
  Ok(Kstat::new(kind, 0))
4531
4708
  }
4532
4709
 
4533
- fn lookup(&self, _dentry: &Dentry) -> Result<Lookup, FilesystemError> {
4710
+ fn lookup(&self, _dentry: &Dentry) -> Result<Lookup, Errno> {
4534
4711
  self.looked_up.fetch_add(1, Ordering::SeqCst);
4535
4712
  let file = Kstat::new(crate::filesystem::FileType::RegFile, 0);
4536
4713
  Ok(Lookup::Found(Inode::new(&file, Arc::new(self.clone()))))
@@ -4538,7 +4715,7 @@ mod tests {
4538
4715
  }
4539
4716
 
4540
4717
  impl FileSystemType for CountsLookups {
4541
- fn fill_super(self: Arc<Self>, sb: &mut Filesystem) -> Result<(), FilesystemError> {
4718
+ fn fill_super(self: Arc<Self>, sb: &mut Filesystem) -> Result<(), Errno> {
4542
4719
  sb.set_default_d_op(self.clone());
4543
4720
  sb.d_make_root(vfs::Inode::new(
4544
4721
  &Kstat::new(crate::filesystem::FileType::Dir, 0),
@@ -4553,10 +4730,10 @@ mod tests {
4553
4730
  fn lookups_of_two_stats(deleted: bool) -> usize {
4554
4731
  let looked_up = Arc::new(AtomicUsize::new(0));
4555
4732
  let root = root_of(
4556
- Filesystem::new(Arc::new(CountsLookups {
4733
+ Filesystem::new(CountsLookups {
4557
4734
  looked_up: looked_up.clone(),
4558
4735
  deleted,
4559
- }))
4736
+ })
4560
4737
  .expect("the instance must stand"),
4561
4738
  );
4562
4739
  for _ in 0..2 {
@@ -4586,7 +4763,7 @@ mod tests {
4586
4763
  impl FileOperations for RecordedFile {}
4587
4764
 
4588
4765
  impl FileSystemType for RecordsCalls {
4589
- fn fill_super(self: Arc<Self>, sb: &mut Filesystem) -> Result<(), FilesystemError> {
4766
+ fn fill_super(self: Arc<Self>, sb: &mut Filesystem) -> Result<(), Errno> {
4590
4767
  sb.d_make_root(vfs::Inode::new(
4591
4768
  &Kstat::new(crate::filesystem::FileType::Dir, 0),
4592
4769
  self,
@@ -4596,11 +4773,11 @@ mod tests {
4596
4773
  }
4597
4774
 
4598
4775
  impl InodeOperations for RecordsCalls {
4599
- fn getattr(&self, _dentry: &Dentry) -> Result<Kstat, FilesystemError> {
4776
+ fn getattr(&self, _dentry: &Dentry) -> Result<Kstat, Errno> {
4600
4777
  Ok(Kstat::new(crate::filesystem::FileType::Dir, 0))
4601
4778
  }
4602
4779
 
4603
- fn lookup(&self, dentry: &Dentry) -> Result<Lookup, FilesystemError> {
4780
+ fn lookup(&self, dentry: &Dentry) -> Result<Lookup, Errno> {
4604
4781
  if dentry.name() == "missing" {
4605
4782
  return Ok(Lookup::Absent);
4606
4783
  }
@@ -4608,11 +4785,7 @@ mod tests {
4608
4785
  Ok(Lookup::Found(Inode::new(&file, Arc::new(self.clone()))))
4609
4786
  }
4610
4787
 
4611
- fn setattr(
4612
- &self,
4613
- _dentry: &Dentry,
4614
- attr: &crate::filesystem::Iattr,
4615
- ) -> Result<(), FilesystemError> {
4788
+ fn setattr(&self, _dentry: &Dentry, attr: &crate::filesystem::Iattr) -> Result<(), Errno> {
4616
4789
  let call = if attr.open {
4617
4790
  "setattr(open)"
4618
4791
  } else {
@@ -4622,16 +4795,12 @@ mod tests {
4622
4795
  Ok(())
4623
4796
  }
4624
4797
 
4625
- fn open(
4626
- &self,
4627
- _dentry: &Dentry,
4628
- _how: &OpenHow,
4629
- ) -> Result<Box<dyn FileOperations>, FilesystemError> {
4798
+ fn open(&self, _dentry: &Dentry, _how: &OpenHow) -> Result<Box<dyn FileOperations>, Errno> {
4630
4799
  self.0.lock().expect("never poisoned").push("open");
4631
4800
  Ok(Box::new(RecordedFile))
4632
4801
  }
4633
4802
 
4634
- fn atomic_open(&self, dentry: &Dentry, how: &OpenHow) -> Result<Finish, FilesystemError> {
4803
+ fn atomic_open(&self, dentry: &Dentry, how: &OpenHow) -> Result<Finish, Errno> {
4635
4804
  if dentry.in_lookup() {
4636
4805
  let found = self.lookup(dentry)?;
4637
4806
  if !how.create || !matches!(found, Lookup::Absent) {
@@ -4655,8 +4824,7 @@ mod tests {
4655
4824
  #[test]
4656
4825
  fn an_open_empties_what_stood_through_setattr_once_it_is_open() {
4657
4826
  let calls = RecordsCalls::default();
4658
- let root =
4659
- root_of(Filesystem::new(Arc::new(calls.clone())).expect("the instance must stand"));
4827
+ let root = root_of(Filesystem::new(calls.clone()).expect("the instance must stand"));
4660
4828
  let cred = Arc::default();
4661
4829
  let truncate = OpenHow {
4662
4830
  write: true,
@@ -4691,7 +4859,7 @@ mod tests {
4691
4859
  let calls = RecordsCalls::default();
4692
4860
  let mount = Mount::new(
4693
4861
  "/data",
4694
- Filesystem::new(Arc::new(calls.clone())).expect("the instance must stand"),
4862
+ Filesystem::new(calls.clone()).expect("the instance must stand"),
4695
4863
  Access::Read,
4696
4864
  )
4697
4865
  .expect("/data is a guest path");
@@ -4711,8 +4879,8 @@ mod tests {
4711
4879
  calls.0.lock().map(|calls| calls.clone()).ok()
4712
4880
  ),
4713
4881
  (
4714
- Some(FilesystemError::NotFound),
4715
- Some(FilesystemError::ReadOnlyFilesystem),
4882
+ Some(Errno::NotFound),
4883
+ Some(Errno::ReadOnlyFilesystem),
4716
4884
  Some(Vec::new())
4717
4885
  ),
4718
4886
  "vfs::do_file_open with O_CREAT of a name a walk found missing, beneath a read-only \
@@ -4726,7 +4894,7 @@ mod tests {
4726
4894
  struct KeepsChanges(Arc<Mutex<Vec<(crate::filesystem::Iattr<'static>, bool)>>>);
4727
4895
 
4728
4896
  impl FileSystemType for KeepsChanges {
4729
- fn fill_super(self: Arc<Self>, sb: &mut Filesystem) -> Result<(), FilesystemError> {
4897
+ fn fill_super(self: Arc<Self>, sb: &mut Filesystem) -> Result<(), Errno> {
4730
4898
  sb.d_make_root(vfs::Inode::new(
4731
4899
  &Kstat::new(crate::filesystem::FileType::Dir, 0),
4732
4900
  self,
@@ -4736,23 +4904,19 @@ mod tests {
4736
4904
  }
4737
4905
 
4738
4906
  impl InodeOperations for KeepsChanges {
4739
- fn getattr(&self, dentry: &Dentry) -> Result<Kstat, FilesystemError> {
4907
+ fn getattr(&self, dentry: &Dentry) -> Result<Kstat, Errno> {
4740
4908
  Ok(match dentry.is_root() {
4741
4909
  false => Kstat::new(FileType::RegFile, 0),
4742
4910
  true => Kstat::new(FileType::Dir, 0),
4743
4911
  })
4744
4912
  }
4745
4913
 
4746
- fn lookup(&self, _dentry: &Dentry) -> Result<Lookup, FilesystemError> {
4914
+ fn lookup(&self, _dentry: &Dentry) -> Result<Lookup, Errno> {
4747
4915
  let file = Kstat::new(FileType::RegFile, 0);
4748
4916
  Ok(Lookup::Found(Inode::new(&file, Arc::new(self.clone()))))
4749
4917
  }
4750
4918
 
4751
- fn setattr(
4752
- &self,
4753
- _dentry: &Dentry,
4754
- attr: &crate::filesystem::Iattr,
4755
- ) -> Result<(), FilesystemError> {
4919
+ fn setattr(&self, _dentry: &Dentry, attr: &crate::filesystem::Iattr) -> Result<(), Errno> {
4756
4920
  self.0.lock().expect("never poisoned").push((
4757
4921
  crate::filesystem::Iattr {
4758
4922
  size: attr.size,
@@ -4773,8 +4937,7 @@ mod tests {
4773
4937
  fn a_truncate_asks_setattr_to_move_the_modification_time_too() {
4774
4938
  use crate::filesystem::SetTime;
4775
4939
  let changes = KeepsChanges::default();
4776
- let root =
4777
- root_of(Filesystem::new(Arc::new(changes.clone())).expect("the instance must stand"));
4940
+ let root = root_of(Filesystem::new(changes.clone()).expect("the instance must stand"));
4778
4941
  let cred = Arc::default();
4779
4942
  let write = OpenHow {
4780
4943
  write: true,
@@ -4809,8 +4972,7 @@ mod tests {
4809
4972
  #[test]
4810
4973
  fn a_truncate_made_through_an_open_hands_setattr_that_open() {
4811
4974
  let changes = KeepsChanges::default();
4812
- let root =
4813
- root_of(Filesystem::new(Arc::new(changes.clone())).expect("the instance must stand"));
4975
+ let root = root_of(Filesystem::new(changes.clone()).expect("the instance must stand"));
4814
4976
  let cred = Arc::default();
4815
4977
  let write = OpenHow {
4816
4978
  write: true,
@@ -4859,7 +5021,7 @@ mod tests {
4859
5021
  }
4860
5022
 
4861
5023
  impl FileSystemType for Holds {
4862
- fn fill_super(self: Arc<Self>, sb: &mut Filesystem) -> Result<(), FilesystemError> {
5024
+ fn fill_super(self: Arc<Self>, sb: &mut Filesystem) -> Result<(), Errno> {
4863
5025
  sb.d_make_root(vfs::Inode::new(
4864
5026
  &Kstat::new(crate::filesystem::FileType::Dir, 0),
4865
5027
  self,
@@ -4869,11 +5031,11 @@ mod tests {
4869
5031
  }
4870
5032
 
4871
5033
  impl InodeOperations for Holds {
4872
- fn getattr(&self, _dentry: &Dentry) -> Result<Kstat, FilesystemError> {
5034
+ fn getattr(&self, _dentry: &Dentry) -> Result<Kstat, Errno> {
4873
5035
  Ok(Kstat::new(crate::filesystem::FileType::Dir, 0))
4874
5036
  }
4875
5037
 
4876
- fn lookup(&self, dentry: &Dentry) -> Result<Lookup, FilesystemError> {
5038
+ fn lookup(&self, dentry: &Dentry) -> Result<Lookup, Errno> {
4877
5039
  if dentry.name() != "f" {
4878
5040
  return Ok(Lookup::Absent);
4879
5041
  }
@@ -4881,26 +5043,22 @@ mod tests {
4881
5043
  Ok(Lookup::Found(Inode::new(&found, Arc::new(self.clone()))))
4882
5044
  }
4883
5045
 
4884
- fn permission(&self, dentry: &Dentry, mask: Mask) -> Result<(), FilesystemError> {
5046
+ fn permission(&self, dentry: &Dentry, mask: Mask) -> Result<(), Errno> {
4885
5047
  match !dentry.is_root() && mask.contains(self.refuses) {
4886
- true => Err(FilesystemError::PermissionDenied),
5048
+ true => Err(Errno::PermissionDenied),
4887
5049
  false => Ok(()),
4888
5050
  }
4889
5051
  }
4890
5052
 
4891
- fn open(
4892
- &self,
4893
- _dentry: &Dentry,
4894
- _how: &OpenHow,
4895
- ) -> Result<Box<dyn FileOperations>, FilesystemError> {
5053
+ fn open(&self, _dentry: &Dentry, _how: &OpenHow) -> Result<Box<dyn FileOperations>, Errno> {
4896
5054
  Ok(Box::new(RecordedFile))
4897
5055
  }
4898
5056
 
4899
- fn setattr(&self, _dentry: &Dentry, _attr: &vfs::Iattr) -> Result<(), FilesystemError> {
5057
+ fn setattr(&self, _dentry: &Dentry, _attr: &vfs::Iattr) -> Result<(), Errno> {
4900
5058
  Ok(())
4901
5059
  }
4902
5060
 
4903
- fn atomic_open(&self, dentry: &Dentry, how: &OpenHow) -> Result<Finish, FilesystemError> {
5061
+ fn atomic_open(&self, dentry: &Dentry, how: &OpenHow) -> Result<Finish, Errno> {
4904
5062
  if dentry.in_lookup() {
4905
5063
  let found = self.lookup(dentry)?;
4906
5064
  if !how.create || !matches!(found, Lookup::Absent) {
@@ -4920,22 +5078,18 @@ mod tests {
4920
5078
  }
4921
5079
  }
4922
5080
 
4923
- fn open_beneath(
4924
- holds: Holds,
4925
- access: Access,
4926
- path: &str,
4927
- how: &OpenHow,
4928
- ) -> Option<FilesystemError> {
5081
+ fn open_beneath(holds: Holds, access: Access, path: &str, how: &OpenHow) -> Option<Errno> {
4929
5082
  let mount = Mount::new(
4930
5083
  "/data",
4931
- Filesystem::new(Arc::new(holds)).expect("the instance must stand"),
5084
+ Filesystem::new(holds).expect("the instance must stand"),
4932
5085
  access,
4933
5086
  )
4934
5087
  .expect("/data is a guest path");
4935
5088
  let cred = crate::security::restrict_self(
4936
- &crate::security::prepare_creds_within(&[], None),
4937
- [&mount],
4938
- );
5089
+ &crate::security::prepare_creds(&[], None),
5090
+ [&crate::grant::Grant::Mount(mount.clone())],
5091
+ )
5092
+ .expect("every Mount stands");
4939
5093
  vfs::kern_path::filp_open(&cred, &Path::root(mount.mnt()), path, how).err()
4940
5094
  }
4941
5095
 
@@ -4947,11 +5101,8 @@ mod tests {
4947
5101
  fn an_allocation_or_advice_on_a_fifo_answers_espipe() {
4948
5102
  let mount = Mount::new(
4949
5103
  "/data",
4950
- Filesystem::new(Arc::new(Holds::of(
4951
- crate::filesystem::FileType::Fifo,
4952
- Mask::EXEC,
4953
- )))
4954
- .expect("the instance must stand"),
5104
+ Filesystem::new(Holds::of(crate::filesystem::FileType::Fifo, Mask::EXEC))
5105
+ .expect("the instance must stand"),
4955
5106
  Access::ReadWrite,
4956
5107
  )
4957
5108
  .expect("/data is a guest path");
@@ -4964,10 +5115,7 @@ mod tests {
4964
5115
  .unwrap_or_else(|_| panic!("the FIFO must open"));
4965
5116
  assert_eq!(
4966
5117
  (fifo.fallocate(0, 1).err(), fifo.fadvise(0, 1).err()),
4967
- (
4968
- Some(FilesystemError::NotSeekable),
4969
- Some(FilesystemError::NotSeekable)
4970
- ),
5118
+ (Some(Errno::NotSeekable), Some(Errno::NotSeekable)),
4971
5119
  "File::fallocate and File::fadvise of a FIFO opened to write must answer ESPIPE"
4972
5120
  );
4973
5121
  }
@@ -4980,11 +5128,8 @@ mod tests {
4980
5128
  fn an_allocation_on_a_character_device_answers_enodev() {
4981
5129
  let mount = Mount::new(
4982
5130
  "/data",
4983
- Filesystem::new(Arc::new(Holds::of(
4984
- crate::filesystem::FileType::Chrdev,
4985
- Mask::EXEC,
4986
- )))
4987
- .expect("the instance must stand"),
5131
+ Filesystem::new(Holds::of(crate::filesystem::FileType::Chrdev, Mask::EXEC))
5132
+ .expect("the instance must stand"),
4988
5133
  Access::ReadWrite,
4989
5134
  )
4990
5135
  .expect("/data is a guest path");
@@ -4997,7 +5142,7 @@ mod tests {
4997
5142
  .unwrap_or_else(|_| panic!("the device must open"));
4998
5143
  assert_eq!(
4999
5144
  device.fallocate(0, 1).err(),
5000
- Some(FilesystemError::NoSuchDevice),
5145
+ Some(Errno::NoSuchDevice),
5001
5146
  "File::fallocate of a character device opened to write must answer ENODEV"
5002
5147
  );
5003
5148
  }
@@ -5009,11 +5154,8 @@ mod tests {
5009
5154
  fn sizing_a_character_device_answers_einval() {
5010
5155
  let mount = Mount::new(
5011
5156
  "/data",
5012
- Filesystem::new(Arc::new(Holds::of(
5013
- crate::filesystem::FileType::Chrdev,
5014
- Mask::EXEC,
5015
- )))
5016
- .expect("the instance must stand"),
5157
+ Filesystem::new(Holds::of(crate::filesystem::FileType::Chrdev, Mask::EXEC))
5158
+ .expect("the instance must stand"),
5017
5159
  Access::ReadWrite,
5018
5160
  )
5019
5161
  .expect("/data is a guest path");
@@ -5026,7 +5168,7 @@ mod tests {
5026
5168
  .unwrap_or_else(|_| panic!("the device must open"));
5027
5169
  assert_eq!(
5028
5170
  device.truncate(0).err(),
5029
- Some(FilesystemError::InvalidInput),
5171
+ Some(Errno::InvalidInput),
5030
5172
  "File::truncate of a character device opened to write must answer EINVAL"
5031
5173
  );
5032
5174
  }
@@ -5048,8 +5190,8 @@ mod tests {
5048
5190
  open_beneath(Holds::of(file, Mask::EXEC), Access::Read, "f", &write),
5049
5191
  ),
5050
5192
  (
5051
- Some(FilesystemError::PermissionDenied),
5052
- Some(FilesystemError::ReadOnlyFilesystem)
5193
+ Some(Errno::PermissionDenied),
5194
+ Some(Errno::ReadOnlyFilesystem)
5053
5195
  ),
5054
5196
  "vfs::do_file_open to write beneath a read-only Mount must answer EACCES for a FIFO, \
5055
5197
  as the security module refuses it, and EROFS for a file"
@@ -5069,7 +5211,7 @@ mod tests {
5069
5211
  let file = crate::filesystem::FileType::RegFile;
5070
5212
  assert_eq!(
5071
5213
  open_beneath(Holds::of(file, Mask::WRITE), Access::Read, "f", &truncate),
5072
- Some(FilesystemError::ReadOnlyFilesystem),
5214
+ Some(Errno::ReadOnlyFilesystem),
5073
5215
  "vfs::do_file_open with O_TRUNC of a file its Filesystem refuses to write, beneath a \
5074
5216
  read-only Mount, must answer EROFS"
5075
5217
  );
@@ -5090,7 +5232,7 @@ mod tests {
5090
5232
  open_beneath(holds, Access::ReadWrite, "new", &create),
5091
5233
  made.load(Ordering::SeqCst)
5092
5234
  ),
5093
- (Some(FilesystemError::PermissionDenied), true),
5235
+ (Some(Errno::PermissionDenied), true),
5094
5236
  "vfs::do_file_open with O_CREAT of a missing path whose Filesystem refuses to open what \
5095
5237
  it makes must make the file and answer EACCES"
5096
5238
  );
@@ -5104,7 +5246,7 @@ mod tests {
5104
5246
  }
5105
5247
 
5106
5248
  impl FileSystemType for HoldsLookup {
5107
- fn fill_super(self: Arc<Self>, sb: &mut Filesystem) -> Result<(), FilesystemError> {
5249
+ fn fill_super(self: Arc<Self>, sb: &mut Filesystem) -> Result<(), Errno> {
5108
5250
  sb.d_make_root(vfs::Inode::new(
5109
5251
  &Kstat::new(crate::filesystem::FileType::Dir, 0),
5110
5252
  self,
@@ -5114,11 +5256,11 @@ mod tests {
5114
5256
  }
5115
5257
 
5116
5258
  impl InodeOperations for HoldsLookup {
5117
- fn getattr(&self, _dentry: &Dentry) -> Result<Kstat, FilesystemError> {
5259
+ fn getattr(&self, _dentry: &Dentry) -> Result<Kstat, Errno> {
5118
5260
  Ok(Kstat::new(crate::filesystem::FileType::Dir, 0))
5119
5261
  }
5120
5262
 
5121
- fn lookup(&self, _dentry: &Dentry) -> Result<Lookup, FilesystemError> {
5263
+ fn lookup(&self, _dentry: &Dentry) -> Result<Lookup, Errno> {
5122
5264
  self.asked.fetch_add(1, Ordering::SeqCst);
5123
5265
  self.reached.lock().expect("never poisoned").send(()).ok();
5124
5266
  self.go_on
@@ -5142,7 +5284,7 @@ mod tests {
5142
5284
  }
5143
5285
 
5144
5286
  impl FileSystemType for AsksItsOwnName {
5145
- fn fill_super(self: Arc<Self>, sb: &mut Filesystem) -> Result<(), FilesystemError> {
5287
+ fn fill_super(self: Arc<Self>, sb: &mut Filesystem) -> Result<(), Errno> {
5146
5288
  sb.d_make_root(vfs::Inode::new(
5147
5289
  &Kstat::new(crate::filesystem::FileType::Dir, 0),
5148
5290
  self,
@@ -5152,14 +5294,14 @@ mod tests {
5152
5294
  }
5153
5295
 
5154
5296
  impl InodeOperations for AsksItsOwnName {
5155
- fn getattr(&self, dentry: &Dentry) -> Result<Kstat, FilesystemError> {
5297
+ fn getattr(&self, dentry: &Dentry) -> Result<Kstat, Errno> {
5156
5298
  Ok(match dentry.is_root() {
5157
5299
  false => Kstat::new(FileType::RegFile, 0),
5158
5300
  true => Kstat::new(FileType::Dir, 0),
5159
5301
  })
5160
5302
  }
5161
5303
 
5162
- fn lookup(&self, _dentry: &Dentry) -> Result<Lookup, FilesystemError> {
5304
+ fn lookup(&self, _dentry: &Dentry) -> Result<Lookup, Errno> {
5163
5305
  if self.asked.fetch_add(1, Ordering::SeqCst) == 0 {
5164
5306
  let root = self.root.get().expect("the root is set before any walk");
5165
5307
  vfs::vfs_fstatat(&Arc::default(), root, "x", false)?;
@@ -5230,13 +5372,7 @@ mod tests {
5230
5372
  );
5231
5373
  assert_eq!(
5232
5374
  (answers, holds.asked.load(Ordering::SeqCst)),
5233
- (
5234
- (
5235
- Some(FilesystemError::NotFound),
5236
- Some(FilesystemError::NotFound)
5237
- ),
5238
- 1
5239
- ),
5375
+ ((Some(Errno::NotFound), Some(Errno::NotFound)), 1),
5240
5376
  "vfs::vfs_fstatat of one name from two walks at once must ask the Filesystem's \
5241
5377
  lookup once, the second waiting for the first's answer"
5242
5378
  );
@@ -5247,7 +5383,7 @@ mod tests {
5247
5383
  struct RecordsAsker(Mutex<Vec<thread::ThreadId>>);
5248
5384
 
5249
5385
  impl FileSystemType for RecordsAsker {
5250
- fn fill_super(self: Arc<Self>, sb: &mut Filesystem) -> Result<(), FilesystemError> {
5386
+ fn fill_super(self: Arc<Self>, sb: &mut Filesystem) -> Result<(), Errno> {
5251
5387
  sb.d_make_root(vfs::Inode::new(
5252
5388
  &Kstat::new(crate::filesystem::FileType::Dir, 0),
5253
5389
  self,
@@ -5257,11 +5393,11 @@ mod tests {
5257
5393
  }
5258
5394
 
5259
5395
  impl InodeOperations for RecordsAsker {
5260
- fn getattr(&self, _dentry: &Dentry) -> Result<Kstat, FilesystemError> {
5396
+ fn getattr(&self, _dentry: &Dentry) -> Result<Kstat, Errno> {
5261
5397
  Ok(Kstat::new(FileType::Dir, 0))
5262
5398
  }
5263
5399
 
5264
- fn lookup(&self, _dentry: &Dentry) -> Result<Lookup, FilesystemError> {
5400
+ fn lookup(&self, _dentry: &Dentry) -> Result<Lookup, Errno> {
5265
5401
  self.0
5266
5402
  .lock()
5267
5403
  .expect("never poisoned")
@@ -5318,7 +5454,7 @@ mod tests {
5318
5454
  struct PointsNowhere(crate::filesystem::FileType);
5319
5455
 
5320
5456
  impl FileSystemType for PointsNowhere {
5321
- fn fill_super(self: Arc<Self>, sb: &mut Filesystem) -> Result<(), FilesystemError> {
5457
+ fn fill_super(self: Arc<Self>, sb: &mut Filesystem) -> Result<(), Errno> {
5322
5458
  sb.d_make_root(vfs::Inode::new(
5323
5459
  &Kstat::new(crate::filesystem::FileType::Dir, 0),
5324
5460
  self,
@@ -5328,11 +5464,11 @@ mod tests {
5328
5464
  }
5329
5465
 
5330
5466
  impl InodeOperations for PointsNowhere {
5331
- fn getattr(&self, _dentry: &Dentry) -> Result<Kstat, FilesystemError> {
5467
+ fn getattr(&self, _dentry: &Dentry) -> Result<Kstat, Errno> {
5332
5468
  Ok(Kstat::new(self.0, 0))
5333
5469
  }
5334
5470
 
5335
- fn lookup(&self, dentry: &Dentry) -> Result<Lookup, FilesystemError> {
5471
+ fn lookup(&self, dentry: &Dentry) -> Result<Lookup, Errno> {
5336
5472
  use crate::filesystem::FileType;
5337
5473
  let kind = match dentry.name().as_str() {
5338
5474
  "e" => FileType::Symlink,
@@ -5343,7 +5479,7 @@ mod tests {
5343
5479
  Ok(Lookup::Found(Inode::new(&found, Arc::new(Self(kind)))))
5344
5480
  }
5345
5481
 
5346
- fn get_link(&self, _dentry: &Dentry) -> Result<String, FilesystemError> {
5482
+ fn get_link(&self, _dentry: &Dentry) -> Result<String, Errno> {
5347
5483
  Ok(String::new())
5348
5484
  }
5349
5485
  }
@@ -5356,7 +5492,7 @@ mod tests {
5356
5492
  }
5357
5493
 
5358
5494
  impl FileSystemType for StaleBehindLinks {
5359
- fn fill_super(self: Arc<Self>, sb: &mut Filesystem) -> Result<(), FilesystemError> {
5495
+ fn fill_super(self: Arc<Self>, sb: &mut Filesystem) -> Result<(), Errno> {
5360
5496
  sb.d_make_root(vfs::Inode::new(
5361
5497
  &Kstat::new(crate::filesystem::FileType::Dir, 0),
5362
5498
  self,
@@ -5366,17 +5502,19 @@ mod tests {
5366
5502
  }
5367
5503
 
5368
5504
  impl InodeOperations for StaleBehindLinks {
5369
- fn getattr(&self, dentry: &Dentry) -> Result<Kstat, FilesystemError> {
5505
+ fn getattr(&self, dentry: &Dentry) -> Result<Kstat, Errno> {
5370
5506
  Ok(Kstat::new(
5371
- dentry.inode().map_or(FileType::Dir, |inode| inode.kind()),
5507
+ dentry
5508
+ .inode()
5509
+ .map_or(FileType::Dir, |inode| inode.file_type()),
5372
5510
  0,
5373
5511
  ))
5374
5512
  }
5375
5513
 
5376
- fn lookup(&self, dentry: &Dentry) -> Result<Lookup, FilesystemError> {
5514
+ fn lookup(&self, dentry: &Dentry) -> Result<Lookup, Errno> {
5377
5515
  let kind = match dentry.name().as_str() {
5378
5516
  "f" if !self.answered_stale.swap(true, Ordering::SeqCst) => {
5379
- return Err(FilesystemError::StaleNetworkFileHandle)
5517
+ return Err(Errno::StaleNetworkFileHandle)
5380
5518
  }
5381
5519
  "f" => FileType::RegFile,
5382
5520
  _ => FileType::Symlink,
@@ -5387,7 +5525,7 @@ mod tests {
5387
5525
  )))
5388
5526
  }
5389
5527
 
5390
- fn get_link(&self, dentry: &Dentry) -> Result<String, FilesystemError> {
5528
+ fn get_link(&self, dentry: &Dentry) -> Result<String, Errno> {
5391
5529
  let at: usize = dentry.name()[1..].parse().expect("a link is named l<n>");
5392
5530
  Ok(match at {
5393
5531
  29 => "f".to_string(),
@@ -5401,13 +5539,11 @@ mod tests {
5401
5539
  // @behavior RT-327
5402
5540
  #[test]
5403
5541
  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
- );
5542
+ let root =
5543
+ root_of(Filesystem::new(StaleBehindLinks::default()).expect("the instance must stand"));
5408
5544
  assert_eq!(
5409
5545
  vfs::vfs_fstatat(&Arc::default(), &root, "l0", true).map(|found| found.file_type),
5410
- Err(FilesystemError::FilesystemLoop),
5546
+ Err(Errno::FilesystemLoop),
5411
5547
  "vfs::vfs_fstatat following thirty links to a name that answers ESTALE once must \
5412
5548
  count the links of both walks toward one budget of forty and answer ELOOP, as \
5413
5549
  Linux's total_link_count carries into the walk made again"
@@ -5421,8 +5557,7 @@ mod tests {
5421
5557
  fn a_link_pointing_nowhere_leaves_the_walk_where_it_stands() {
5422
5558
  use crate::filesystem::FileType;
5423
5559
  let root = root_of(
5424
- Filesystem::new(Arc::new(PointsNowhere(FileType::Dir)))
5425
- .expect("the instance must stand"),
5560
+ Filesystem::new(PointsNowhere(FileType::Dir)).expect("the instance must stand"),
5426
5561
  );
5427
5562
  let kind = |path: &str| {
5428
5563
  vfs::vfs_fstatat(&Arc::default(), &root, path, true).map(|found| found.file_type)
@@ -5444,8 +5579,7 @@ mod tests {
5444
5579
  use crate::sched::{run_task, Task};
5445
5580
  use std::time::Instant;
5446
5581
 
5447
- let root =
5448
- root_of(Filesystem::new(Arc::new(Tmpfs::new())).expect("the instance must stand"));
5582
+ let root = root_of(Filesystem::new(Tmpfs::new()).expect("the instance must stand"));
5449
5583
  let held = root.dentry().inode_lock().expect("the test holds the root");
5450
5584
  let past_deadline = {
5451
5585
  let root = root.clone();
@@ -5478,10 +5612,7 @@ mod tests {
5478
5612
  past_deadline.join().expect("the wait must not panic"),
5479
5613
  interrupted.join().expect("the wait must not panic"),
5480
5614
  ),
5481
- (
5482
- Err(FilesystemError::Interrupted),
5483
- Err(FilesystemError::Interrupted)
5484
- ),
5615
+ (Err(Errno::Interrupted), Err(Errno::Interrupted)),
5485
5616
  "vfs::filename_mkdirat waiting on a directory another thread holds must answer EINTR \
5486
5617
  once its run's deadline passes, and once its thread is interrupted"
5487
5618
  );
@@ -5515,7 +5646,7 @@ mod tests {
5515
5646
  crate::sched::testing::join("the first walk", first);
5516
5647
  assert_eq!(
5517
5648
  second,
5518
- Some(FilesystemError::Interrupted),
5649
+ Some(Errno::Interrupted),
5519
5650
  "vfs::vfs_fstatat of a name another walk is looking up must answer EINTR once its \
5520
5651
  run's deadline passes"
5521
5652
  );
@@ -5532,12 +5663,12 @@ mod tests {
5532
5663
  fn rename(
5533
5664
  &self,
5534
5665
  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" {
5666
+ old: &Dentry,
5667
+ new_dir: &dyn InodeOperations,
5668
+ new: &Dentry,
5669
+ flags: Option<RenameFlag>,
5670
+ ) -> Result<(), Errno> {
5671
+ if old.name() == "k" {
5541
5672
  let reached = self.reached.lock().expect("never poisoned");
5542
5673
  reached.send(()).expect("the test waits to hear");
5543
5674
  let go_on = self.go_on.lock().expect("never poisoned");
@@ -5545,16 +5676,16 @@ mod tests {
5545
5676
  .recv_timeout(crate::sched::testing::MAX_WAIT)
5546
5677
  .expect("the test says when to go on");
5547
5678
  }
5548
- inner.rename(from, to_dir, to, flag)
5679
+ inner.rename(old, new_dir, new, flags)
5549
5680
  }
5550
5681
  }
5551
5682
 
5552
5683
  /// Refuses every change to the one path the move may not touch.
5553
5684
  struct RefusesMovedName;
5554
5685
 
5555
- impl Policy for RefusesMovedName {
5556
- fn allows(&self, path: &str, _access: Access) -> bool {
5557
- path != "/data/a/moved"
5686
+ impl Policy<MountRequest<'_>> for RefusesMovedName {
5687
+ fn allows(&self, request: &MountRequest<'_>) -> bool {
5688
+ request.path != "/data/a/moved"
5558
5689
  }
5559
5690
  }
5560
5691
 
@@ -5578,16 +5709,16 @@ mod tests {
5578
5709
  });
5579
5710
  let mount = Mount::new(
5580
5711
  "/data",
5581
- Filesystem::new(Arc::new(Wrap::new(Arc::new(tmpfs), hook)))
5582
- .expect("the instance must stand"),
5712
+ Filesystem::new(Wrap::new(Arc::new(tmpfs), hook)).expect("the instance must stand"),
5583
5713
  Access::ReadWrite,
5584
5714
  )
5585
5715
  .expect("/data is a guest path")
5586
5716
  .with_policy(Arc::new(RefusesMovedName));
5587
5717
  let cred = crate::security::restrict_self(
5588
- &crate::security::prepare_creds_within(&[], None),
5589
- [&mount],
5590
- );
5718
+ &crate::security::prepare_creds(&[], None),
5719
+ [&crate::grant::Grant::Mount(mount.clone())],
5720
+ )
5721
+ .expect("every Mount stands");
5591
5722
  let root = Path::root(mount.mnt());
5592
5723
  let holder = {
5593
5724
  let root = root.clone();
@@ -5611,7 +5742,7 @@ mod tests {
5611
5742
  let stands = |path| vfs::vfs_fstatat(&cred, &root, path, false).is_ok();
5612
5743
  assert_eq!(
5613
5744
  (renamed, moved, stands("a/moved"), stands("b/y")),
5614
- (Ok(()), Err(FilesystemError::NotFound), true, false),
5745
+ (Ok(()), Err(Errno::NotFound), true, false),
5615
5746
  "vfs::filename_renameat2 of `a/x` that waited while another writer renamed it must \
5616
5747
  answer ENOENT and leave `a/moved`, which the Policy refuses, where it stands"
5617
5748
  );
@@ -5626,10 +5757,9 @@ mod tests {
5626
5757
  use std::thread;
5627
5758
 
5628
5759
  use super::{reach, root_of};
5629
- use crate::filesystem::{
5630
- FileType, Filesystem, FilesystemError, InodeOperations, Kstat, Lookup,
5631
- };
5760
+ use crate::filesystem::{FileType, Filesystem, InodeOperations, Kstat, Lookup};
5632
5761
  use crate::vfs::{self, Dentry, FileSystemType, Inode};
5762
+ use crate::Errno;
5633
5763
 
5634
5764
  /// A Filesystem handing one directory's inode for `a` in its root and
5635
5765
  /// `d` in its directory `c`, whose two lookups answer only once both
@@ -5641,7 +5771,7 @@ mod tests {
5641
5771
  }
5642
5772
 
5643
5773
  impl FileSystemType for AnswersAtOnce {
5644
- fn fill_super(self: Arc<Self>, sb: &mut Filesystem) -> Result<(), FilesystemError> {
5774
+ fn fill_super(self: Arc<Self>, sb: &mut Filesystem) -> Result<(), Errno> {
5645
5775
  sb.d_make_root(vfs::Inode::new(
5646
5776
  &Kstat::new(crate::filesystem::FileType::Dir, 0),
5647
5777
  self,
@@ -5651,11 +5781,11 @@ mod tests {
5651
5781
  }
5652
5782
 
5653
5783
  impl InodeOperations for AnswersAtOnce {
5654
- fn getattr(&self, _dentry: &Dentry) -> Result<Kstat, FilesystemError> {
5784
+ fn getattr(&self, _dentry: &Dentry) -> Result<Kstat, Errno> {
5655
5785
  Ok(Kstat::new(FileType::Dir, 0))
5656
5786
  }
5657
5787
 
5658
- fn lookup(&self, dentry: &Dentry) -> Result<Lookup, FilesystemError> {
5788
+ fn lookup(&self, dentry: &Dentry) -> Result<Lookup, Errno> {
5659
5789
  let dir = Kstat::new(FileType::Dir, 0);
5660
5790
  Ok(match dentry.name().as_str() {
5661
5791
  "a" | "d" => {
@@ -5683,8 +5813,7 @@ mod tests {
5683
5813
  let split = (0..20_000)
5684
5814
  .filter(|_| {
5685
5815
  let root = root_of(
5686
- Filesystem::new(Arc::new(AnswersAtOnce::default()))
5687
- .expect("the instance must stand"),
5816
+ Filesystem::new(AnswersAtOnce::default()).expect("the instance must stand"),
5688
5817
  );
5689
5818
  reach(&root, "c").expect("c is reached");
5690
5819
  let walks = ["a", "c/d"].map(|path| {