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.
- checksums.yaml +4 -4
- data/.release-please-manifest.json +1 -1
- data/CHANGELOG.md +335 -0
- data/Cargo.lock +469 -11
- data/README.md +43 -3
- data/ROADMAP.md +1 -1
- data/crates/kobako-runtime/CHANGELOG.md +219 -0
- data/crates/kobako-runtime/Cargo.toml +51 -3
- data/crates/kobako-runtime/README.md +7 -4
- data/crates/kobako-runtime/src/cred.rs +124 -0
- data/crates/kobako-runtime/src/dispatch.rs +4 -5
- data/crates/kobako-runtime/src/endpoint/buffer.rs +153 -44
- data/crates/kobako-runtime/src/endpoint/dispatch.rs +80 -41
- data/crates/kobako-runtime/src/endpoint/invoke.rs +23 -36
- data/crates/kobako-runtime/src/endpoint.rs +137 -36
- data/crates/kobako-runtime/src/errno.rs +391 -0
- data/crates/kobako-runtime/src/error.rs +31 -10
- data/crates/kobako-runtime/src/filesystem/anon_inodes.rs +52 -0
- data/crates/kobako-runtime/src/filesystem/bind/lookup.rs +52 -14
- data/crates/kobako-runtime/src/filesystem/bind/walk.rs +19 -20
- data/crates/kobako-runtime/src/filesystem/bind.rs +437 -245
- data/crates/kobako-runtime/src/filesystem/overlay/file.rs +6 -6
- data/crates/kobako-runtime/src/filesystem/overlay/path.rs +43 -65
- data/crates/kobako-runtime/src/filesystem/overlay/stack/copy_up.rs +9 -16
- data/crates/kobako-runtime/src/filesystem/overlay/stack/dir.rs +47 -72
- data/crates/kobako-runtime/src/filesystem/overlay/stack/namei.rs +12 -12
- data/crates/kobako-runtime/src/filesystem/overlay/stack/readdir.rs +4 -7
- data/crates/kobako-runtime/src/filesystem/overlay/stack.rs +121 -37
- data/crates/kobako-runtime/src/filesystem/overlay.rs +302 -343
- data/crates/kobako-runtime/src/filesystem/pipe.rs +12 -9
- data/crates/kobako-runtime/src/filesystem/rdir.rs +15 -32
- data/crates/kobako-runtime/src/filesystem/tmpfs/seed.rs +32 -0
- data/crates/kobako-runtime/src/filesystem/tmpfs/tmpfile.rs +3 -3
- data/crates/kobako-runtime/src/filesystem/tmpfs/whiteout.rs +57 -35
- data/crates/kobako-runtime/src/filesystem/tmpfs/xattr.rs +2 -2
- data/crates/kobako-runtime/src/filesystem/tmpfs.rs +172 -160
- data/crates/kobako-runtime/src/filesystem/wrap.rs +36 -52
- data/crates/kobako-runtime/src/filesystem.rs +6 -3
- data/crates/kobako-runtime/src/fork.rs +96 -0
- data/crates/kobako-runtime/src/grant.rs +3 -0
- data/crates/kobako-runtime/src/hashtable.rs +4 -2
- data/crates/kobako-runtime/src/lib.rs +18 -7
- data/crates/kobako-runtime/src/limits.rs +195 -0
- data/crates/kobako-runtime/src/locking.rs +10 -0
- data/crates/kobako-runtime/src/memcg.rs +383 -0
- data/crates/kobako-runtime/src/mount.rs +67 -9
- data/crates/kobako-runtime/src/net/backends.rs +43 -0
- data/crates/kobako-runtime/src/net/connections.rs +179 -0
- data/crates/kobako-runtime/src/net/credential.rs +125 -0
- data/crates/kobako-runtime/src/net/egress.rs +160 -0
- data/crates/kobako-runtime/src/net/family.rs +181 -0
- data/crates/kobako-runtime/src/net/http.rs +2733 -0
- data/crates/kobako-runtime/src/net/lookup.rs +285 -0
- data/crates/kobako-runtime/src/net/mock.rs +251 -0
- data/crates/kobako-runtime/src/net/namespace.rs +1366 -0
- data/crates/kobako-runtime/src/net/reactor.rs +531 -0
- data/crates/kobako-runtime/src/net/resolv/darwin.rs +275 -0
- data/crates/kobako-runtime/src/net/resolv/stub/tests.rs +469 -0
- data/crates/kobako-runtime/src/net/resolv/stub.rs +536 -0
- data/crates/kobako-runtime/src/net/resolv/windows.rs +248 -0
- data/crates/kobako-runtime/src/net/resolv.rs +227 -0
- data/crates/kobako-runtime/src/net/socket.rs +870 -0
- data/crates/kobako-runtime/src/net/tcp.rs +1588 -0
- data/crates/kobako-runtime/src/net/tls.rs +58 -0
- data/crates/kobako-runtime/src/net/transport.rs +279 -0
- data/crates/kobako-runtime/src/net/udp.rs +1003 -0
- data/crates/kobako-runtime/src/net.rs +42 -0
- data/crates/kobako-runtime/src/network/builder.rs +177 -0
- data/crates/kobako-runtime/src/network/ruleset.rs +777 -0
- data/crates/kobako-runtime/src/network.rs +551 -0
- data/crates/kobako-runtime/src/policy.rs +16 -0
- data/crates/kobako-runtime/src/profile.rs +29 -144
- data/crates/kobako-runtime/src/runtime.rs +3 -5
- data/crates/kobako-runtime/src/sched.rs +130 -29
- data/crates/kobako-runtime/src/security/entry_policy.rs +22 -0
- data/crates/kobako-runtime/src/{vfs/cred.rs → security/hooks.rs} +52 -144
- data/crates/kobako-runtime/src/security/mount_policy.rs +158 -0
- data/crates/kobako-runtime/src/security.rs +101 -196
- data/crates/kobako-runtime/src/snapshot.rs +121 -2
- data/crates/kobako-runtime/src/vfs/attr.rs +5 -5
- data/crates/kobako-runtime/src/vfs/dentry.rs +143 -89
- data/crates/kobako-runtime/src/vfs/file.rs +199 -203
- data/crates/kobako-runtime/src/vfs/inode.rs +41 -45
- data/crates/kobako-runtime/src/vfs/kern_path.rs +38 -42
- data/crates/kobako-runtime/src/vfs/mount.rs +10 -9
- data/crates/kobako-runtime/src/vfs/namei.rs +829 -700
- data/crates/kobako-runtime/src/vfs/namespace.rs +162 -0
- data/crates/kobako-runtime/src/vfs/open_files.rs +69 -0
- data/crates/kobako-runtime/src/vfs/openat2.rs +3 -3
- data/crates/kobako-runtime/src/vfs/path.rs +6 -6
- data/crates/kobako-runtime/src/vfs/readdir.rs +6 -6
- data/crates/kobako-runtime/src/vfs/stat.rs +159 -23
- data/crates/kobako-runtime/src/vfs/super_block.rs +18 -14
- data/crates/kobako-runtime/src/vfs/utimes.rs +37 -27
- data/crates/kobako-runtime/src/vfs.rs +9 -6
- data/crates/kobako-runtime/src/wait.rs +356 -0
- data/crates/kobako-transport/CHANGELOG.md +31 -0
- data/crates/kobako-transport/Cargo.toml +1 -1
- data/crates/kobako-transport/README.md +3 -4
- data/crates/kobako-transport/src/abi.rs +78 -72
- data/crates/kobako-transport/src/envelope/bytes.rs +17 -6
- data/crates/kobako-transport/src/envelope/call.rs +32 -4
- data/crates/kobako-transport/src/envelope/error_record.rs +21 -0
- data/crates/kobako-transport/src/envelope/name.rs +99 -0
- data/crates/kobako-transport/src/envelope/outcome.rs +9 -9
- data/crates/kobako-transport/src/envelope/preamble.rs +24 -21
- data/crates/kobako-transport/src/envelope/reply.rs +27 -27
- data/crates/kobako-transport/src/envelope/unsupported.rs +10 -10
- data/crates/kobako-transport/src/envelope.rs +13 -8
- data/crates/kobako-wasmtime/CHANGELOG.md +161 -0
- data/crates/kobako-wasmtime/Cargo.toml +26 -7
- data/crates/kobako-wasmtime/README.md +3 -2
- data/crates/kobako-wasmtime/build/preview2.rs +1339 -0
- data/crates/kobako-wasmtime/build.rs +16 -0
- data/crates/kobako-wasmtime/src/abi.rs +17 -37
- data/crates/kobako-wasmtime/src/ambient.rs +33 -18
- data/crates/kobako-wasmtime/src/cache.rs +23 -15
- data/crates/kobako-wasmtime/src/config.rs +52 -68
- data/crates/kobako-wasmtime/src/driver.rs +48 -63
- data/crates/kobako-wasmtime/src/exports.rs +143 -17
- data/crates/kobako-wasmtime/src/guest.rs +12 -6
- data/crates/kobako-wasmtime/src/guest_binary.rs +14 -0
- data/crates/kobako-wasmtime/src/imports.rs +42 -18
- data/crates/kobako-wasmtime/src/instance_pre.rs +4 -4
- data/crates/kobako-wasmtime/src/invocation.rs +74 -12
- data/crates/kobako-wasmtime/src/lib.rs +5 -3
- data/crates/kobako-wasmtime/src/limiter.rs +70 -5
- data/crates/kobako-wasmtime/src/preview1/descriptors.rs +309 -0
- data/crates/kobako-wasmtime/src/preview1/differential/mount.rs +5 -15
- data/crates/kobako-wasmtime/src/preview1/differential.rs +27 -31
- data/crates/kobako-wasmtime/src/preview1/errno.rs +55 -66
- data/crates/kobako-wasmtime/src/preview1/fd.rs +327 -296
- data/crates/kobako-wasmtime/src/preview1/memory.rs +21 -12
- data/crates/kobako-wasmtime/src/preview1/mount_view/wrap.rs +34 -53
- data/crates/kobako-wasmtime/src/preview1/mount_view.rs +231 -217
- data/crates/kobako-wasmtime/src/preview1/path.rs +56 -121
- data/crates/kobako-wasmtime/src/preview1/poll.rs +244 -120
- data/crates/kobako-wasmtime/src/preview1/sock.rs +10 -8
- data/crates/kobako-wasmtime/src/preview1/testsuite.rs +5 -15
- data/crates/kobako-wasmtime/src/preview1.rs +46 -42
- data/crates/kobako-wasmtime/src/preview2/abi.rs +227 -0
- data/crates/kobako-wasmtime/src/preview2/error.rs +118 -0
- data/crates/kobako-wasmtime/src/preview2/filesystem.rs +122 -0
- data/crates/kobako-wasmtime/src/preview2/host.rs +3959 -0
- data/crates/kobako-wasmtime/src/preview2/http.rs +1503 -0
- data/crates/kobako-wasmtime/src/preview2/io.rs +315 -0
- data/crates/kobako-wasmtime/src/preview2/sockets.rs +379 -0
- data/crates/kobako-wasmtime/src/preview2/table.rs +305 -0
- data/crates/kobako-wasmtime/src/preview2.rs +57 -0
- data/crates/kobako-wasmtime/src/trap.rs +24 -9
- data/crates/kobako-wasmtime/src/wasi.rs +210 -81
- data/crates/kobako-wasmtime/wit/deps/cli.wit +233 -0
- data/crates/kobako-wasmtime/wit/deps/clocks.wit +162 -0
- data/crates/kobako-wasmtime/wit/deps/filesystem.wit +589 -0
- data/crates/kobako-wasmtime/wit/deps/http.wit +733 -0
- data/crates/kobako-wasmtime/wit/deps/io.wit +299 -0
- data/crates/kobako-wasmtime/wit/deps/random.wit +92 -0
- data/crates/kobako-wasmtime/wit/deps/sockets.wit +949 -0
- data/data/kobako.wasm +0 -0
- data/ext/kobako/Cargo.toml +1 -1
- data/ext/kobako/src/{runtime/errors.rs → errors.rs} +34 -26
- data/ext/kobako/src/{runtime/escape.rs → escape.rs} +42 -11
- data/ext/kobako/src/{runtime/filesystem → filesystem}/grants.rs +30 -26
- data/ext/kobako/src/{runtime/filesystem → filesystem}/ruby.rs +149 -168
- data/ext/kobako/src/{runtime/filesystem.rs → filesystem.rs} +24 -15
- data/ext/kobako/src/gvl.rs +306 -0
- data/ext/kobako/src/lib.rs +64 -3
- data/ext/kobako/src/network/mock.rs +187 -0
- data/ext/kobako/src/network.rs +591 -0
- data/ext/kobako/src/runtime/bridge.rs +30 -29
- data/ext/kobako/src/runtime/snapshot.rs +4 -4
- data/ext/kobako/src/runtime.rs +221 -143
- data/ext/kobako/src/wire.rs +42 -0
- data/lib/kobako/catalog/extensions.rb +14 -2
- data/lib/kobako/catalog/flags.rb +3 -5
- data/lib/kobako/catalog/grants.rb +5 -4
- data/lib/kobako/catalog/handles.rb +5 -27
- data/lib/kobako/catalog/mount.rb +11 -3
- data/lib/kobako/catalog/network.rb +35 -0
- data/lib/kobako/catalog/replacements.rb +28 -0
- data/lib/kobako/catalog/services.rb +5 -19
- data/lib/kobako/catalog/snippets.rb +3 -18
- data/lib/kobako/catalog.rb +3 -0
- data/lib/kobako/codec/{utils.rb → boundary.rb} +4 -2
- data/lib/kobako/codec/decoder.rb +4 -4
- data/lib/kobako/codec/ext_types.rb +3 -3
- data/lib/kobako/codec/handle_walk.rb +3 -43
- data/lib/kobako/codec/value_budget.rb +132 -40
- data/lib/kobako/codec.rb +1 -1
- data/lib/kobako/context.rb +24 -11
- data/lib/kobako/errors.rb +15 -12
- data/lib/kobako/extension.rb +3 -2
- data/lib/kobako/filesystem.rb +9 -2
- data/lib/kobako/handle.rb +2 -2
- data/lib/kobako/names.rb +28 -0
- data/lib/kobako/network.rb +210 -0
- data/lib/kobako/outcome.rb +7 -7
- data/lib/kobako/pool.rb +45 -23
- data/lib/kobako/runtime.rb +3 -2
- data/lib/kobako/sandbox.rb +92 -35
- data/lib/kobako/sandbox_options.rb +41 -106
- data/lib/kobako/transport/argument_wrap.rb +64 -0
- data/lib/kobako/transport/block_failure.rb +1 -1
- data/lib/kobako/transport/dispatcher.rb +6 -6
- data/lib/kobako/transport/exposure.rb +26 -15
- data/lib/kobako/transport/reflection.rb +21 -4
- data/lib/kobako/transport/run.rb +8 -23
- data/lib/kobako/transport/yielder.rb +2 -9
- data/lib/kobako/transport.rb +1 -0
- data/lib/kobako/version.rb +1 -1
- data/lib/kobako.rb +6 -2
- data/release-please-config.json +15 -0
- data/sig/core/thread.rbs +6 -0
- data/sig/kobako/catalog/extensions.rbs +2 -0
- data/sig/kobako/catalog/grants.rbs +7 -4
- data/sig/kobako/catalog/handles.rbs +0 -2
- data/sig/kobako/catalog/mount.rbs +3 -1
- data/sig/kobako/catalog/network.rbs +20 -0
- data/sig/kobako/catalog/replacements.rbs +14 -0
- data/sig/kobako/catalog/services.rbs +0 -4
- data/sig/kobako/catalog/snippets.rbs +0 -2
- data/sig/kobako/codec/{utils.rbs → boundary.rbs} +2 -2
- data/sig/kobako/codec/handle_walk.rbs +0 -6
- data/sig/kobako/codec/value_budget.rbs +47 -4
- data/sig/kobako/context.rbs +3 -1
- data/sig/kobako/errors.rbs +4 -4
- data/sig/kobako/filesystem.rbs +21 -3
- data/sig/kobako/network.rbs +115 -0
- data/sig/kobako/outcome.rbs +1 -1
- data/sig/kobako/pool.rbs +7 -3
- data/sig/kobako/runtime.rbs +32 -3
- data/sig/kobako/sandbox.rbs +19 -2
- data/sig/kobako/sandbox_options.rbs +29 -38
- data/sig/kobako/transport/argument_wrap.rbs +15 -0
- data/sig/kobako/transport/error.rbs +1 -1
- data/sig/kobako/transport/exposure.rbs +2 -4
- data/sig/kobako/transport/reflection.rbs +10 -0
- data/sig/kobako/transport/run.rbs +0 -2
- data/sig/kobako/transport/yielder.rbs +0 -3
- data/sig/kobako/transport.rbs +1 -1
- data/sig/kobako.rbs +13 -0
- metadata +84 -35
- data/crates/kobako-runtime/src/endpoint/capture.rs +0 -115
- data/crates/kobako-runtime/src/endpoint/memory_cap.rs +0 -238
- data/crates/kobako-runtime/src/filesystem/path.rs +0 -21
- data/crates/kobako-runtime/src/vfs/errno.rs +0 -153
- data/crates/kobako-runtime/tests/linux_baseline/calls.rs +0 -171
- data/crates/kobako-runtime/tests/linux_baseline/concurrent.rs +0 -276
- data/crates/kobako-runtime/tests/linux_baseline/kobako.rs +0 -323
- data/crates/kobako-runtime/tests/linux_baseline/linux-baseline-expected.txt +0 -16
- data/crates/kobako-runtime/tests/linux_baseline/linux.rs +0 -449
- data/crates/kobako-runtime/tests/linux_baseline/main.rs +0 -611
- data/crates/kobako-runtime/tests/linux_baseline/permissions.rs +0 -236
- data/crates/kobako-wasmtime/src/descriptors.rs +0 -200
- data/crates/kobako-wasmtime/tests/integration/compile_posture.rs +0 -43
- data/crates/kobako-wasmtime/tests/integration/guest_file.rs +0 -1085
- data/crates/kobako-wasmtime/tests/integration/main.rs +0 -29
- data/crates/kobako-wasmtime/tests/integration/preamble_flags.rs +0 -70
- data/crates/kobako-wasmtime/tests/integration/snippet_compile.rs +0 -95
- data/crates/kobako-wasmtime/tests/integration/support/mod.rs +0 -30
- data/crates/kobako-wasmtime/tests/integration/unanswered_call.rs +0 -86
- data/crates/kobako-wasmtime/tests/integration/unsupported_call.rs +0 -51
- data/ext/kobako/src/runtime/gvl.rs +0 -147
- data/lib/kobako/constant_name.rb +0 -8
- data/sig/kobako/constant_name.rbs +0 -3
- /data/ext/kobako/src/{runtime/pinned_value.rs → pinned_value.rs} +0 -0
|
@@ -23,9 +23,8 @@ use cap_std::fs::{Dir, OpenOptions as CapOpenOptions};
|
|
|
23
23
|
|
|
24
24
|
use super::rdir::Rdir;
|
|
25
25
|
use super::{
|
|
26
|
-
DentryOperations, DirEntry, FileOperations, FileSystemType, FileType, Filesystem,
|
|
27
|
-
|
|
28
|
-
SetTime,
|
|
26
|
+
DentryOperations, DirEntry, Errno, FileOperations, FileSystemType, FileType, Filesystem,
|
|
27
|
+
Finish, Iattr, InodeOperations, Kiocb, Kstat, Lookup, OpenHow, RenameFlag, SetTime,
|
|
29
28
|
};
|
|
30
29
|
use crate::vfs::{
|
|
31
30
|
generic_file_llseek, generic_read_dir, Dentry, DirContext, Identity, Inode, Whence,
|
|
@@ -45,6 +44,9 @@ pub struct Bind {
|
|
|
45
44
|
/// The host directory the Bind was made at.
|
|
46
45
|
root: Arc<Dir>,
|
|
47
46
|
fids: Arc<FidCache>,
|
|
47
|
+
/// Whether only the guest changes the directory, so a name it found
|
|
48
|
+
/// stays as found without asking the host again.
|
|
49
|
+
exclusive: bool,
|
|
48
50
|
}
|
|
49
51
|
|
|
50
52
|
impl Bind {
|
|
@@ -58,9 +60,18 @@ impl Bind {
|
|
|
58
60
|
Ok(Self {
|
|
59
61
|
root: Arc::new(root),
|
|
60
62
|
fids: Arc::default(),
|
|
63
|
+
exclusive: false,
|
|
61
64
|
})
|
|
62
65
|
}
|
|
63
66
|
|
|
67
|
+
/// This Bind trusting the names it found when `exclusive`, the Host App
|
|
68
|
+
/// vouching that only the guest changes the directory, as gVisor's
|
|
69
|
+
/// exclusive mount skips revalidation. A change made on the host meanwhile
|
|
70
|
+
/// may go unseen.
|
|
71
|
+
pub fn with_exclusive(self, exclusive: bool) -> Self {
|
|
72
|
+
Self { exclusive, ..self }
|
|
73
|
+
}
|
|
74
|
+
|
|
64
75
|
/// The host directory kept for `dentry`, if one is.
|
|
65
76
|
fn find_fid(&self, dentry: &Dentry) -> Option<Arc<Dir>> {
|
|
66
77
|
if dentry.is_root() {
|
|
@@ -74,7 +85,7 @@ impl Bind {
|
|
|
74
85
|
/// kept, read from the dentries as `build_path_from_dentry` reads them.
|
|
75
86
|
/// 9p holds the rename lock through a walk; one here compares what it found
|
|
76
87
|
/// with what the dentry recorded instead, as NFS compares a file handle.
|
|
77
|
-
fn fid_lookup(&self, dentry: &Dentry) -> Result<Arc<Dir>,
|
|
88
|
+
fn fid_lookup(&self, dentry: &Dentry) -> Result<Arc<Dir>, Errno> {
|
|
78
89
|
if let Some(held) = self.find_fid(dentry) {
|
|
79
90
|
return Ok(held);
|
|
80
91
|
}
|
|
@@ -97,7 +108,7 @@ impl Bind {
|
|
|
97
108
|
};
|
|
98
109
|
let dir = walk::walk(&above, &names)?;
|
|
99
110
|
if !stands(&dir) {
|
|
100
|
-
return Err(
|
|
111
|
+
return Err(Errno::NotFound);
|
|
101
112
|
}
|
|
102
113
|
let dir = Arc::new(dir);
|
|
103
114
|
self.fids.put(dentry, &dir);
|
|
@@ -109,8 +120,8 @@ impl Bind {
|
|
|
109
120
|
fn at<T>(
|
|
110
121
|
&self,
|
|
111
122
|
dentry: &Dentry,
|
|
112
|
-
call: impl FnOnce(&Dir, &str) -> Result<T,
|
|
113
|
-
) -> Result<T,
|
|
123
|
+
call: impl FnOnce(&Dir, &str) -> Result<T, Errno>,
|
|
124
|
+
) -> Result<T, Errno> {
|
|
114
125
|
let (parent, name) = dentry.parent_and_name();
|
|
115
126
|
call(&*self.fid_lookup(&parent)?, to_host_name(&name)?)
|
|
116
127
|
}
|
|
@@ -124,7 +135,7 @@ impl Bind {
|
|
|
124
135
|
dentry: &Dentry,
|
|
125
136
|
how: &OpenHow,
|
|
126
137
|
create: bool,
|
|
127
|
-
) -> Result<Box<dyn FileOperations>,
|
|
138
|
+
) -> Result<Box<dyn FileOperations>, Errno> {
|
|
128
139
|
let file = self.at(dentry, |dir, name| open_in(dir, name, how, create))?;
|
|
129
140
|
let opened = to_kstat(cap_std::fs::Metadata::from_file(&file).map_err(to_error)?);
|
|
130
141
|
match dentry.inode().map(|inode| inode.identity()) {
|
|
@@ -136,12 +147,12 @@ impl Bind {
|
|
|
136
147
|
// which only what opened can tell, as NFS's open compares the file
|
|
137
148
|
// handle it gets back.
|
|
138
149
|
Some(Some(identity)) if Identity::of(&opened) != Some(identity) => {
|
|
139
|
-
return Err(
|
|
150
|
+
return Err(Errno::NotFound)
|
|
140
151
|
}
|
|
141
152
|
Some(_) => {}
|
|
142
153
|
}
|
|
143
154
|
let file = Arc::new(file);
|
|
144
|
-
let inode = dentry.inode().ok_or(
|
|
155
|
+
let inode = dentry.inode().ok_or(Errno::NotFound)?;
|
|
145
156
|
let kept = inode
|
|
146
157
|
.private()
|
|
147
158
|
.get_or_init(|| Arc::new(OpenFids::default()))
|
|
@@ -158,7 +169,7 @@ impl Bind {
|
|
|
158
169
|
/// directory above, as a walk asks each name once the one above it stood.
|
|
159
170
|
/// A host may reuse an inode number for what it made in its place, so the
|
|
160
171
|
/// kind must match too, as NFS compares a file handle's attributes.
|
|
161
|
-
fn stands_as_recorded(&self, dentry: &Dentry) -> Result<bool,
|
|
172
|
+
fn stands_as_recorded(&self, dentry: &Dentry) -> Result<bool, Errno> {
|
|
162
173
|
let inode = dentry.inode();
|
|
163
174
|
if inode
|
|
164
175
|
.as_ref()
|
|
@@ -172,25 +183,23 @@ impl Bind {
|
|
|
172
183
|
match (found, inode) {
|
|
173
184
|
(Ok(found), Some(inode)) => {
|
|
174
185
|
let found = to_kstat(found);
|
|
175
|
-
Ok(
|
|
186
|
+
Ok(
|
|
187
|
+
Identity::of(&found) == inode.identity()
|
|
188
|
+
&& found.file_type == inode.file_type(),
|
|
189
|
+
)
|
|
176
190
|
}
|
|
177
191
|
(Ok(_), None) => Ok(false),
|
|
178
|
-
(Err(
|
|
179
|
-
(
|
|
180
|
-
Err(
|
|
181
|
-
FilesystemError::NotFound
|
|
182
|
-
| FilesystemError::NotADirectory
|
|
183
|
-
| FilesystemError::FilesystemLoop,
|
|
184
|
-
),
|
|
185
|
-
_,
|
|
186
|
-
) => Ok(false),
|
|
192
|
+
(Err(Errno::NotFound), None) => Ok(true),
|
|
193
|
+
(Err(Errno::NotFound | Errno::NotADirectory | Errno::FilesystemLoop), _) => Ok(false),
|
|
187
194
|
(Err(err), _) => Err(err),
|
|
188
195
|
}
|
|
189
196
|
}
|
|
190
197
|
}
|
|
191
198
|
|
|
192
|
-
/// The names `dir` holds, each with the kind and the identity a
|
|
193
|
-
|
|
199
|
+
/// The names `dir` holds, each with the kind and the identity a stat names.
|
|
200
|
+
/// A Windows listing carries no file index, so there each name is asked of
|
|
201
|
+
/// a stat; one gone by then lists without an identity.
|
|
202
|
+
fn entries_of(dir: &Dir) -> Result<Vec<DirEntry>, Errno> {
|
|
194
203
|
#[cfg(unix)]
|
|
195
204
|
let dev = {
|
|
196
205
|
use cap_std::fs::MetadataExt;
|
|
@@ -203,13 +212,21 @@ fn entries_of(dir: &Dir) -> Result<Vec<DirEntry>, FilesystemError> {
|
|
|
203
212
|
let name = entry
|
|
204
213
|
.file_name()
|
|
205
214
|
.into_string()
|
|
206
|
-
.map_err(|_|
|
|
215
|
+
.map_err(|_| Errno::IllegalSequence)?;
|
|
207
216
|
let listed = DirEntry::new(name, to_file_type(entry.file_type().map_err(to_error)?));
|
|
208
217
|
#[cfg(unix)]
|
|
209
218
|
let listed = {
|
|
210
219
|
use std::os::unix::fs::DirEntryExt;
|
|
211
220
|
listed.with_identity(dev, entry.ino())
|
|
212
221
|
};
|
|
222
|
+
#[cfg(not(unix))]
|
|
223
|
+
let listed = match dir.symlink_metadata(&listed.name) {
|
|
224
|
+
Ok(found) => {
|
|
225
|
+
use cap_fs_ext::MetadataExt;
|
|
226
|
+
listed.with_identity(found.dev(), found.ino())
|
|
227
|
+
}
|
|
228
|
+
Err(_) => listed,
|
|
229
|
+
};
|
|
213
230
|
Ok(listed)
|
|
214
231
|
})
|
|
215
232
|
.collect()
|
|
@@ -218,7 +235,7 @@ fn entries_of(dir: &Dir) -> Result<Vec<DirEntry>, FilesystemError> {
|
|
|
218
235
|
/// The directory `name` in `dir`, a link there refused as a loop, as
|
|
219
236
|
/// Linux's `RESOLVE_NO_SYMLINKS` refuses one, where the host names it no
|
|
220
237
|
/// directory.
|
|
221
|
-
fn open_dir_nofollow(dir: &Dir, name: &str) -> Result<Dir,
|
|
238
|
+
fn open_dir_nofollow(dir: &Dir, name: &str) -> Result<Dir, Errno> {
|
|
222
239
|
dir.open_dir_nofollow(name)
|
|
223
240
|
.map_err(|err| nofollow_error(dir, name, err))
|
|
224
241
|
}
|
|
@@ -226,9 +243,9 @@ fn open_dir_nofollow(dir: &Dir, name: &str) -> Result<Dir, FilesystemError> {
|
|
|
226
243
|
/// Why an open of `name` in `dir` that follows no link failed, a link there
|
|
227
244
|
/// named a loop, as Linux's `O_NOFOLLOW` answers `ELOOP`, where the host
|
|
228
245
|
/// names it otherwise.
|
|
229
|
-
fn nofollow_error(dir: &Dir, name: &str, err: io::Error) ->
|
|
246
|
+
fn nofollow_error(dir: &Dir, name: &str, err: io::Error) -> Errno {
|
|
230
247
|
match dir.symlink_metadata(name) {
|
|
231
|
-
Ok(metadata) if metadata.file_type().is_symlink() =>
|
|
248
|
+
Ok(metadata) if metadata.file_type().is_symlink() => Errno::FilesystemLoop,
|
|
232
249
|
_ => to_error(err),
|
|
233
250
|
}
|
|
234
251
|
}
|
|
@@ -236,9 +253,9 @@ fn nofollow_error(dir: &Dir, name: &str, err: io::Error) -> FilesystemError {
|
|
|
236
253
|
/// `name` as `cap_std` takes it. Windows reads some names as other names or as
|
|
237
254
|
/// devices, so there one is refused rather than reached as an entry a Mount's
|
|
238
255
|
/// Policy never saw.
|
|
239
|
-
fn to_host_name(name: &str) -> Result<&str,
|
|
256
|
+
fn to_host_name(name: &str) -> Result<&str, Errno> {
|
|
240
257
|
if cfg!(windows) && is_windows_alias(name) {
|
|
241
|
-
return Err(
|
|
258
|
+
return Err(Errno::InvalidInput);
|
|
242
259
|
}
|
|
243
260
|
Ok(name)
|
|
244
261
|
}
|
|
@@ -259,37 +276,15 @@ fn is_windows_alias(name: &str) -> bool {
|
|
|
259
276
|
|| DEVICES.contains(&stem.to_uppercase().as_str())
|
|
260
277
|
}
|
|
261
278
|
|
|
262
|
-
/// The
|
|
279
|
+
/// The Errno a host failure names. cap-std's own refusal of a path
|
|
263
280
|
/// leading out of the directory carries no OS code. A Bind hands it one name and
|
|
264
281
|
/// no `..`, so that refusal only says a move carried the name out of the
|
|
265
282
|
/// directory as it was opened, as `complete_walk` answers EXDEV, and nothing
|
|
266
|
-
/// stands at it now.
|
|
267
|
-
|
|
268
|
-
fn to_error(err: io::Error) -> FilesystemError {
|
|
283
|
+
/// stands at it now.
|
|
284
|
+
fn to_error(err: io::Error) -> Errno {
|
|
269
285
|
match err.kind() {
|
|
270
|
-
io::ErrorKind::PermissionDenied if err.raw_os_error().is_none() =>
|
|
271
|
-
|
|
272
|
-
}
|
|
273
|
-
io::ErrorKind::NotFound => FilesystemError::NotFound,
|
|
274
|
-
io::ErrorKind::AlreadyExists => FilesystemError::AlreadyExists,
|
|
275
|
-
io::ErrorKind::NotADirectory => FilesystemError::NotADirectory,
|
|
276
|
-
io::ErrorKind::IsADirectory => FilesystemError::IsADirectory,
|
|
277
|
-
io::ErrorKind::DirectoryNotEmpty => FilesystemError::DirectoryNotEmpty,
|
|
278
|
-
io::ErrorKind::PermissionDenied => FilesystemError::PermissionDenied,
|
|
279
|
-
io::ErrorKind::ReadOnlyFilesystem => FilesystemError::ReadOnlyFilesystem,
|
|
280
|
-
io::ErrorKind::InvalidInput => FilesystemError::InvalidInput,
|
|
281
|
-
io::ErrorKind::Unsupported => FilesystemError::Unsupported,
|
|
282
|
-
io::ErrorKind::StorageFull => FilesystemError::StorageFull,
|
|
283
|
-
io::ErrorKind::FileTooLarge => FilesystemError::FileTooLarge,
|
|
284
|
-
io::ErrorKind::CrossesDevices => FilesystemError::CrossesDevices,
|
|
285
|
-
io::ErrorKind::Deadlock => FilesystemError::Deadlock,
|
|
286
|
-
io::ErrorKind::ResourceBusy => FilesystemError::ResourceBusy,
|
|
287
|
-
io::ErrorKind::InvalidFilename => FilesystemError::InvalidFilename,
|
|
288
|
-
io::ErrorKind::NotSeekable => FilesystemError::NotSeekable,
|
|
289
|
-
io::ErrorKind::Interrupted => FilesystemError::Interrupted,
|
|
290
|
-
io::ErrorKind::WouldBlock => FilesystemError::WouldBlock,
|
|
291
|
-
io::ErrorKind::OutOfMemory => FilesystemError::OutOfMemory,
|
|
292
|
-
_ => FilesystemError::Other(err.to_string()),
|
|
286
|
+
io::ErrorKind::PermissionDenied if err.raw_os_error().is_none() => Errno::NotFound,
|
|
287
|
+
_ => Errno::from_io_error(&err),
|
|
293
288
|
}
|
|
294
289
|
}
|
|
295
290
|
|
|
@@ -330,8 +325,9 @@ fn to_special_file_type(_host: cap_std::fs::FileType) -> FileType {
|
|
|
330
325
|
}
|
|
331
326
|
|
|
332
327
|
/// What a host entry is, with the size the host reports. The host names
|
|
333
|
-
/// its identity
|
|
334
|
-
///
|
|
328
|
+
/// its identity and link count everywhere, and its times on unix. Windows
|
|
329
|
+
/// names the identity by volume and file index, which cap-std reads from the
|
|
330
|
+
/// handle each of its stats opens.
|
|
335
331
|
fn to_kstat(metadata: cap_std::fs::Metadata) -> Kstat {
|
|
336
332
|
let file_type = to_file_type(metadata.file_type());
|
|
337
333
|
let size = metadata.len();
|
|
@@ -348,7 +344,12 @@ fn to_kstat(metadata: cap_std::fs::Metadata) -> Kstat {
|
|
|
348
344
|
)
|
|
349
345
|
}
|
|
350
346
|
#[cfg(not(unix))]
|
|
351
|
-
|
|
347
|
+
{
|
|
348
|
+
use cap_fs_ext::MetadataExt;
|
|
349
|
+
Kstat::new(file_type, size)
|
|
350
|
+
.with_identity(metadata.dev(), metadata.ino())
|
|
351
|
+
.with_nlink(metadata.nlink())
|
|
352
|
+
}
|
|
352
353
|
}
|
|
353
354
|
|
|
354
355
|
/// The time `seconds` and `nanoseconds` after the Unix epoch, as `stat`
|
|
@@ -386,13 +387,14 @@ fn v9fs_fid_find_inode(dentry: &Dentry, writable: bool) -> Option<Arc<std::fs::F
|
|
|
386
387
|
|
|
387
388
|
/// Open `name` in `dir` as `how` asks, made first where `create` says,
|
|
388
389
|
/// refusing one that already stands.
|
|
389
|
-
fn open_in(
|
|
390
|
-
dir: &Dir,
|
|
391
|
-
name: &str,
|
|
392
|
-
how: &OpenHow,
|
|
393
|
-
create: bool,
|
|
394
|
-
) -> Result<std::fs::File, FilesystemError> {
|
|
390
|
+
fn open_in(dir: &Dir, name: &str, how: &OpenHow, create: bool) -> Result<std::fs::File, Errno> {
|
|
395
391
|
let writes = how.write || how.truncate || create;
|
|
392
|
+
#[cfg(target_os = "linux")]
|
|
393
|
+
if !create {
|
|
394
|
+
if let Some(opened) = open_judged(dir, name, how.read, writes)? {
|
|
395
|
+
return Ok(opened);
|
|
396
|
+
}
|
|
397
|
+
}
|
|
396
398
|
let mut open = CapOpenOptions::new();
|
|
397
399
|
// The host refuses one that creates or truncates without writing; the
|
|
398
400
|
// runtime decides what is written, so such opens write here.
|
|
@@ -414,8 +416,8 @@ fn open_in(
|
|
|
414
416
|
.map_err(|err| nofollow_error(dir, name, err))?;
|
|
415
417
|
match to_file_type(file.metadata().map_err(to_error)?.file_type()) {
|
|
416
418
|
FileType::RegFile => {}
|
|
417
|
-
FileType::Dir => return Err(
|
|
418
|
-
_ => return Err(
|
|
419
|
+
FileType::Dir => return Err(Errno::IsADirectory),
|
|
420
|
+
_ => return Err(Errno::PermissionDenied),
|
|
419
421
|
}
|
|
420
422
|
#[cfg(unix)]
|
|
421
423
|
{
|
|
@@ -430,6 +432,53 @@ fn open_in(
|
|
|
430
432
|
Ok(file.into_std())
|
|
431
433
|
}
|
|
432
434
|
|
|
435
|
+
/// The file standing at `name` in `dir`, held by `O_PATH` first, which opens
|
|
436
|
+
/// nothing, and opened only once it stands as a file, through
|
|
437
|
+
/// `/proc/self/fd`, so what opens is the inode judged and no device swapped
|
|
438
|
+
/// in acts on being opened, as gVisor's directfs reopens its control
|
|
439
|
+
/// descriptor. None where the host has no `/proc` to reopen through.
|
|
440
|
+
#[cfg(target_os = "linux")]
|
|
441
|
+
fn open_judged(
|
|
442
|
+
dir: &Dir,
|
|
443
|
+
name: &str,
|
|
444
|
+
read: bool,
|
|
445
|
+
writes: bool,
|
|
446
|
+
) -> Result<Option<std::fs::File>, Errno> {
|
|
447
|
+
use rustix::fs::{fstat, open, openat, FileType as HostType, Mode, OFlags};
|
|
448
|
+
use std::os::fd::AsRawFd;
|
|
449
|
+
|
|
450
|
+
let held = openat(
|
|
451
|
+
dir,
|
|
452
|
+
name,
|
|
453
|
+
OFlags::PATH | OFlags::NOFOLLOW | OFlags::CLOEXEC,
|
|
454
|
+
Mode::empty(),
|
|
455
|
+
)
|
|
456
|
+
.map_err(io::Error::from)
|
|
457
|
+
.map_err(to_error)?;
|
|
458
|
+
let stat = fstat(&held).map_err(io::Error::from).map_err(to_error)?;
|
|
459
|
+
match HostType::from_raw_mode(stat.st_mode) {
|
|
460
|
+
HostType::RegularFile => {}
|
|
461
|
+
HostType::Directory => return Err(Errno::IsADirectory),
|
|
462
|
+
HostType::Symlink => return Err(Errno::FilesystemLoop),
|
|
463
|
+
_ => return Err(Errno::PermissionDenied),
|
|
464
|
+
}
|
|
465
|
+
let access = match (read, writes) {
|
|
466
|
+
(true, true) => OFlags::RDWR,
|
|
467
|
+
(false, true) => OFlags::WRONLY,
|
|
468
|
+
_ => OFlags::RDONLY,
|
|
469
|
+
};
|
|
470
|
+
let reopened = open(
|
|
471
|
+
format!("/proc/self/fd/{}", held.as_raw_fd()).as_str(),
|
|
472
|
+
access | OFlags::CLOEXEC | OFlags::NOCTTY,
|
|
473
|
+
Mode::empty(),
|
|
474
|
+
);
|
|
475
|
+
match reopened {
|
|
476
|
+
Ok(fd) => Ok(Some(std::fs::File::from(fd))),
|
|
477
|
+
Err(rustix::io::Errno::NOENT) => Ok(None),
|
|
478
|
+
Err(err) => Err(to_error(io::Error::from(err))),
|
|
479
|
+
}
|
|
480
|
+
}
|
|
481
|
+
|
|
433
482
|
/// The host may move or remake what a dentry names behind the runtime's
|
|
434
483
|
/// back, so a dentry recording an identity is valid only while the same
|
|
435
484
|
/// entry stands at the path it stands for, as NFS compares the handle a
|
|
@@ -438,7 +487,7 @@ fn open_in(
|
|
|
438
487
|
impl FileSystemType for Bind {
|
|
439
488
|
/// Its root reports the host directory it holds, as 9p's `fill_super` asks of
|
|
440
489
|
/// the attached fid, and a host that cannot answer makes no instance.
|
|
441
|
-
fn fill_super(self: Arc<Self>, sb: &mut Filesystem) -> Result<(),
|
|
490
|
+
fn fill_super(self: Arc<Self>, sb: &mut Filesystem) -> Result<(), Errno> {
|
|
442
491
|
sb.set_default_d_op(self.clone());
|
|
443
492
|
let root = to_kstat(self.root.dir_metadata().map_err(to_error)?);
|
|
444
493
|
sb.d_make_root(Inode::new(&root, self));
|
|
@@ -447,12 +496,11 @@ impl FileSystemType for Bind {
|
|
|
447
496
|
}
|
|
448
497
|
|
|
449
498
|
impl DentryOperations for Bind {
|
|
450
|
-
fn revalidate(
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
self.stands_as_recorded(dentry)
|
|
499
|
+
fn revalidate(&self, _dir: &dyn InodeOperations, dentry: &Dentry) -> Result<bool, Errno> {
|
|
500
|
+
match self.exclusive {
|
|
501
|
+
true => Ok(true),
|
|
502
|
+
false => self.stands_as_recorded(dentry),
|
|
503
|
+
}
|
|
456
504
|
}
|
|
457
505
|
|
|
458
506
|
fn delete(&self, dentry: &Dentry) -> bool {
|
|
@@ -470,7 +518,7 @@ struct BindRegular(Bind);
|
|
|
470
518
|
struct BindLink(Bind);
|
|
471
519
|
|
|
472
520
|
/// What an entry standing at its name in the directory above reports.
|
|
473
|
-
fn stat_at(bind: &Bind, dentry: &Dentry) -> Result<Kstat,
|
|
521
|
+
fn stat_at(bind: &Bind, dentry: &Dentry) -> Result<Kstat, Errno> {
|
|
474
522
|
bind.at(dentry, |dir, name| {
|
|
475
523
|
Ok(to_kstat(dir.symlink_metadata(name).map_err(to_error)?))
|
|
476
524
|
})
|
|
@@ -479,7 +527,7 @@ fn stat_at(bind: &Bind, dentry: &Dentry) -> Result<Kstat, FilesystemError> {
|
|
|
479
527
|
impl InodeOperations for BindRegular {
|
|
480
528
|
/// A file open anywhere answers from the descriptor that holds it, even
|
|
481
529
|
/// once its name is gone.
|
|
482
|
-
fn getattr(&self, dentry: &Dentry) -> Result<Kstat,
|
|
530
|
+
fn getattr(&self, dentry: &Dentry) -> Result<Kstat, Errno> {
|
|
483
531
|
match v9fs_fid_find_inode(dentry, false) {
|
|
484
532
|
Some(file) => Ok(to_kstat(
|
|
485
533
|
cap_std::fs::Metadata::from_file(&file).map_err(to_error)?,
|
|
@@ -488,7 +536,7 @@ impl InodeOperations for BindRegular {
|
|
|
488
536
|
}
|
|
489
537
|
}
|
|
490
538
|
|
|
491
|
-
fn setattr(&self, dentry: &Dentry, attr: &Iattr) -> Result<(),
|
|
539
|
+
fn setattr(&self, dentry: &Dentry, attr: &Iattr) -> Result<(), Errno> {
|
|
492
540
|
if let Some(len) = attr.size {
|
|
493
541
|
// A truncate made through an open takes that open's descriptor, as
|
|
494
542
|
// 9p takes `ia_file`'s fid; one made by name, one open to write
|
|
@@ -499,7 +547,7 @@ impl InodeOperations for BindRegular {
|
|
|
499
547
|
.map(|opened| opened.file.clone());
|
|
500
548
|
return match through.or_else(|| v9fs_fid_find_inode(dentry, true)) {
|
|
501
549
|
Some(file) => file.set_len(len).map_err(to_error),
|
|
502
|
-
None => Err(
|
|
550
|
+
None => Err(Errno::InvalidInput),
|
|
503
551
|
};
|
|
504
552
|
}
|
|
505
553
|
// A file open anywhere takes them through what holds it, whatever stands
|
|
@@ -520,17 +568,13 @@ impl InodeOperations for BindRegular {
|
|
|
520
568
|
})
|
|
521
569
|
}
|
|
522
570
|
|
|
523
|
-
fn open(
|
|
524
|
-
&self,
|
|
525
|
-
dentry: &Dentry,
|
|
526
|
-
how: &OpenHow,
|
|
527
|
-
) -> Result<Box<dyn FileOperations>, FilesystemError> {
|
|
571
|
+
fn open(&self, dentry: &Dentry, how: &OpenHow) -> Result<Box<dyn FileOperations>, Errno> {
|
|
528
572
|
self.0.open_file(dentry, how, false)
|
|
529
573
|
}
|
|
530
574
|
}
|
|
531
575
|
|
|
532
576
|
impl InodeOperations for BindLink {
|
|
533
|
-
fn getattr(&self, dentry: &Dentry) -> Result<Kstat,
|
|
577
|
+
fn getattr(&self, dentry: &Dentry) -> Result<Kstat, Errno> {
|
|
534
578
|
stat_at(&self.0, dentry)
|
|
535
579
|
}
|
|
536
580
|
|
|
@@ -538,13 +582,13 @@ impl InodeOperations for BindLink {
|
|
|
538
582
|
/// as `->get_link` answers, since the walk judges what a link leads to. A
|
|
539
583
|
/// target that is no valid UTF-8 answers `IllegalSequence`, as a guest path
|
|
540
584
|
/// is one.
|
|
541
|
-
fn get_link(&self, dentry: &Dentry) -> Result<String,
|
|
585
|
+
fn get_link(&self, dentry: &Dentry) -> Result<String, Errno> {
|
|
542
586
|
self.0.at(dentry, |dir, name| {
|
|
543
587
|
dir.read_link_contents(name)
|
|
544
588
|
.map_err(to_error)?
|
|
545
589
|
.into_os_string()
|
|
546
590
|
.into_string()
|
|
547
|
-
.map_err(|_|
|
|
591
|
+
.map_err(|_| Errno::IllegalSequence)
|
|
548
592
|
})
|
|
549
593
|
}
|
|
550
594
|
}
|
|
@@ -552,7 +596,7 @@ impl InodeOperations for BindLink {
|
|
|
552
596
|
impl InodeOperations for Bind {
|
|
553
597
|
/// A directory answers from its own descriptor, which follows it wherever
|
|
554
598
|
/// it moves and keeps its inode taken while it is open.
|
|
555
|
-
fn getattr(&self, dentry: &Dentry) -> Result<Kstat,
|
|
599
|
+
fn getattr(&self, dentry: &Dentry) -> Result<Kstat, Errno> {
|
|
556
600
|
Ok(to_kstat(
|
|
557
601
|
self.fid_lookup(dentry)?.dir_metadata().map_err(to_error)?,
|
|
558
602
|
))
|
|
@@ -560,7 +604,7 @@ impl InodeOperations for Bind {
|
|
|
560
604
|
|
|
561
605
|
/// A directory takes the times through the descriptor that holds it, as it
|
|
562
606
|
/// answers for itself.
|
|
563
|
-
fn setattr(&self, dentry: &Dentry, attr: &Iattr) -> Result<(),
|
|
607
|
+
fn setattr(&self, dentry: &Dentry, attr: &Iattr) -> Result<(), Errno> {
|
|
564
608
|
let (atime, mtime) = (to_host_time(attr.atime), to_host_time(attr.mtime));
|
|
565
609
|
self.fid_lookup(dentry)?
|
|
566
610
|
.set_times(".", atime, mtime)
|
|
@@ -571,7 +615,7 @@ impl InodeOperations for Bind {
|
|
|
571
615
|
/// it, as a lookup hands `d_splice_alias` the inode it found, so
|
|
572
616
|
/// `revalidate` can tell a dentry the host replaced behind the
|
|
573
617
|
/// runtime's back. That costs one host stat a name.
|
|
574
|
-
fn lookup(&self, dentry: &Dentry) -> Result<Lookup,
|
|
618
|
+
fn lookup(&self, dentry: &Dentry) -> Result<Lookup, Errno> {
|
|
575
619
|
self.at(dentry, |dir, name| {
|
|
576
620
|
let stored_name = lookup::lookup(dir, name)?;
|
|
577
621
|
match dir.symlink_metadata(&stored_name).map_err(to_error) {
|
|
@@ -591,17 +635,13 @@ impl InodeOperations for Bind {
|
|
|
591
635
|
}),
|
|
592
636
|
}
|
|
593
637
|
}
|
|
594
|
-
Err(
|
|
638
|
+
Err(Errno::NotFound) => Ok(Lookup::Absent),
|
|
595
639
|
Err(err) => Err(err),
|
|
596
640
|
}
|
|
597
641
|
})
|
|
598
642
|
}
|
|
599
643
|
|
|
600
|
-
fn open(
|
|
601
|
-
&self,
|
|
602
|
-
dentry: &Dentry,
|
|
603
|
-
how: &OpenHow,
|
|
604
|
-
) -> Result<Box<dyn FileOperations>, FilesystemError> {
|
|
644
|
+
fn open(&self, dentry: &Dentry, how: &OpenHow) -> Result<Box<dyn FileOperations>, Errno> {
|
|
605
645
|
let fid = self.fid_lookup(dentry)?;
|
|
606
646
|
if how.read {
|
|
607
647
|
may_read_dir(&fid)?;
|
|
@@ -613,7 +653,7 @@ impl InodeOperations for Bind {
|
|
|
613
653
|
/// A name still in lookup is looked up first, and any name is left to the
|
|
614
654
|
/// VFS unless the open may make it and nothing stands there, as 9p's
|
|
615
655
|
/// `v9fs_vfs_atomic_open_dotl` asks its server before it creates.
|
|
616
|
-
fn atomic_open(&self, dentry: &Dentry, how: &OpenHow) -> Result<Finish,
|
|
656
|
+
fn atomic_open(&self, dentry: &Dentry, how: &OpenHow) -> Result<Finish, Errno> {
|
|
617
657
|
if dentry.in_lookup() {
|
|
618
658
|
let found = self.lookup(dentry)?;
|
|
619
659
|
if !how.create || !matches!(found, Lookup::Absent) {
|
|
@@ -630,15 +670,15 @@ impl InodeOperations for Bind {
|
|
|
630
670
|
})
|
|
631
671
|
}
|
|
632
672
|
|
|
633
|
-
fn mkdir(&self, dentry: &Dentry) -> Result<(),
|
|
673
|
+
fn mkdir(&self, dentry: &Dentry) -> Result<(), Errno> {
|
|
634
674
|
self.at(dentry, |dir, name| dir.create_dir(name).map_err(to_error))
|
|
635
675
|
}
|
|
636
676
|
|
|
637
|
-
fn rmdir(&self, dentry: &Dentry) -> Result<(),
|
|
677
|
+
fn rmdir(&self, dentry: &Dentry) -> Result<(), Errno> {
|
|
638
678
|
self.at(dentry, |dir, name| dir.remove_dir(name).map_err(to_error))
|
|
639
679
|
}
|
|
640
680
|
|
|
641
|
-
fn unlink(&self, dentry: &Dentry) -> Result<(),
|
|
681
|
+
fn unlink(&self, dentry: &Dentry) -> Result<(), Errno> {
|
|
642
682
|
self.at(dentry, |dir, name| dir.remove_file(name).map_err(to_error))
|
|
643
683
|
}
|
|
644
684
|
|
|
@@ -648,21 +688,21 @@ impl InodeOperations for Bind {
|
|
|
648
688
|
/// moves one.
|
|
649
689
|
fn rename(
|
|
650
690
|
&self,
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
) -> Result<(),
|
|
656
|
-
if
|
|
657
|
-
return Err(
|
|
691
|
+
old: &Dentry,
|
|
692
|
+
new_dir: &dyn InodeOperations,
|
|
693
|
+
new: &Dentry,
|
|
694
|
+
flags: Option<RenameFlag>,
|
|
695
|
+
) -> Result<(), Errno> {
|
|
696
|
+
if flags.is_some() {
|
|
697
|
+
return Err(Errno::InvalidInput);
|
|
658
698
|
}
|
|
659
|
-
let target = (
|
|
699
|
+
let target = (new_dir as &dyn Any)
|
|
660
700
|
.downcast_ref::<Self>()
|
|
661
|
-
.ok_or(
|
|
662
|
-
self.at(
|
|
663
|
-
target.at(
|
|
664
|
-
|
|
665
|
-
.rename(
|
|
701
|
+
.ok_or(Errno::CrossesDevices)?;
|
|
702
|
+
self.at(old, |old_dir, old_name| {
|
|
703
|
+
target.at(new, |new_dir, new_name| {
|
|
704
|
+
old_dir
|
|
705
|
+
.rename(old_name, new_dir, new_name)
|
|
666
706
|
.map_err(to_error)
|
|
667
707
|
})
|
|
668
708
|
})
|
|
@@ -681,28 +721,24 @@ impl FileOperations for BindDir {
|
|
|
681
721
|
pos: u64,
|
|
682
722
|
offset: i64,
|
|
683
723
|
whence: Whence,
|
|
684
|
-
) -> Result<u64,
|
|
724
|
+
) -> Result<u64, Errno> {
|
|
685
725
|
generic_file_llseek(dentry, pos, offset, whence)
|
|
686
726
|
}
|
|
687
727
|
|
|
688
|
-
fn read_iter(&mut self, _iocb: &mut Kiocb, _buf: &mut [u8]) -> Result<usize,
|
|
728
|
+
fn read_iter(&mut self, _iocb: &mut Kiocb, _buf: &mut [u8]) -> Result<usize, Errno> {
|
|
689
729
|
generic_read_dir()
|
|
690
730
|
}
|
|
691
731
|
|
|
692
732
|
/// What a listing began with stays on the open directory until it ends, as
|
|
693
733
|
/// 9p's `fid->rdir` holds what the server sent.
|
|
694
|
-
fn iterate_shared(
|
|
695
|
-
&mut self,
|
|
696
|
-
dentry: &Dentry,
|
|
697
|
-
ctx: &mut DirContext<'_>,
|
|
698
|
-
) -> Result<(), FilesystemError> {
|
|
734
|
+
fn iterate_shared(&mut self, dentry: &Dentry, ctx: &mut DirContext<'_>) -> Result<(), Errno> {
|
|
699
735
|
let dir = self.0.clone();
|
|
700
|
-
self.1.
|
|
736
|
+
self.1.iterate_shared(dentry, ctx, || entries_of(&dir))
|
|
701
737
|
}
|
|
702
738
|
|
|
703
739
|
/// Make the host directory's names durable. Windows syncs no directory, so
|
|
704
740
|
/// there the host answers for them itself.
|
|
705
|
-
fn fsync(&mut self, _datasync: bool) -> Result<(),
|
|
741
|
+
fn fsync(&mut self, _datasync: bool) -> Result<(), Errno> {
|
|
706
742
|
sync_dir(&self.0)
|
|
707
743
|
}
|
|
708
744
|
}
|
|
@@ -710,7 +746,7 @@ impl FileOperations for BindDir {
|
|
|
710
746
|
/// `dir` opened to read. cap-std holds a directory for its path alone on Linux,
|
|
711
747
|
/// which reads and syncs nothing, so the host judges reading it only here.
|
|
712
748
|
#[cfg(unix)]
|
|
713
|
-
fn open_to_read(dir: &Dir) -> Result<rustix::fd::OwnedFd,
|
|
749
|
+
fn open_to_read(dir: &Dir) -> Result<rustix::fd::OwnedFd, Errno> {
|
|
714
750
|
use rustix::fs::{openat, Mode, OFlags};
|
|
715
751
|
|
|
716
752
|
let flags = OFlags::RDONLY | OFlags::DIRECTORY | OFlags::CLOEXEC;
|
|
@@ -718,12 +754,12 @@ fn open_to_read(dir: &Dir) -> Result<rustix::fd::OwnedFd, FilesystemError> {
|
|
|
718
754
|
}
|
|
719
755
|
|
|
720
756
|
#[cfg(unix)]
|
|
721
|
-
fn sync_dir(dir: &Dir) -> Result<(),
|
|
757
|
+
fn sync_dir(dir: &Dir) -> Result<(), Errno> {
|
|
722
758
|
rustix::fs::fsync(open_to_read(dir)?).map_err(|err| to_error(io::Error::from(err)))
|
|
723
759
|
}
|
|
724
760
|
|
|
725
761
|
#[cfg(not(unix))]
|
|
726
|
-
fn sync_dir(_dir: &Dir) -> Result<(),
|
|
762
|
+
fn sync_dir(_dir: &Dir) -> Result<(), Errno> {
|
|
727
763
|
Ok(())
|
|
728
764
|
}
|
|
729
765
|
|
|
@@ -731,12 +767,12 @@ fn sync_dir(_dir: &Dir) -> Result<(), FilesystemError> {
|
|
|
731
767
|
/// asks `inode_permission`. A file holds it for what it was opened for, so a
|
|
732
768
|
/// directory reached only for its path answers no such question.
|
|
733
769
|
#[cfg(unix)]
|
|
734
|
-
fn may_read_dir(dir: &Dir) -> Result<(),
|
|
770
|
+
fn may_read_dir(dir: &Dir) -> Result<(), Errno> {
|
|
735
771
|
open_to_read(dir).map(drop)
|
|
736
772
|
}
|
|
737
773
|
|
|
738
774
|
#[cfg(not(unix))]
|
|
739
|
-
fn may_read_dir(_dir: &Dir) -> Result<(),
|
|
775
|
+
fn may_read_dir(_dir: &Dir) -> Result<(), Errno> {
|
|
740
776
|
Ok(())
|
|
741
777
|
}
|
|
742
778
|
|
|
@@ -750,14 +786,14 @@ impl BindFile {
|
|
|
750
786
|
/// Windows has no append to switch one handle to for a single write,
|
|
751
787
|
/// so an append that could land over another writer's is refused.
|
|
752
788
|
#[cfg(not(unix))]
|
|
753
|
-
fn append(&mut self, _iocb: &mut Kiocb, _buf: &[u8]) -> Result<usize,
|
|
754
|
-
Err(
|
|
789
|
+
fn append(&mut self, _iocb: &mut Kiocb, _buf: &[u8]) -> Result<usize, Errno> {
|
|
790
|
+
Err(Errno::Unsupported)
|
|
755
791
|
}
|
|
756
792
|
|
|
757
793
|
/// The host places the write at the file's end as `O_APPEND` does, so
|
|
758
794
|
/// another writer's append lands before or after it, never over it.
|
|
759
795
|
#[cfg(unix)]
|
|
760
|
-
fn append(&mut self, iocb: &mut Kiocb, buf: &[u8]) -> Result<usize,
|
|
796
|
+
fn append(&mut self, iocb: &mut Kiocb, buf: &[u8]) -> Result<usize, Errno> {
|
|
761
797
|
use rustix::fs::{fcntl_getfl, fcntl_setfl, OFlags};
|
|
762
798
|
|
|
763
799
|
let mut file = &*self.file;
|
|
@@ -785,11 +821,11 @@ impl FileOperations for BindFile {
|
|
|
785
821
|
pos: u64,
|
|
786
822
|
offset: i64,
|
|
787
823
|
whence: Whence,
|
|
788
|
-
) -> Result<u64,
|
|
824
|
+
) -> Result<u64, Errno> {
|
|
789
825
|
generic_file_llseek(dentry, pos, offset, whence)
|
|
790
826
|
}
|
|
791
827
|
|
|
792
|
-
fn read_iter(&mut self, iocb: &mut Kiocb, buf: &mut [u8]) -> Result<usize,
|
|
828
|
+
fn read_iter(&mut self, iocb: &mut Kiocb, buf: &mut [u8]) -> Result<usize, Errno> {
|
|
793
829
|
let mut file = &*self.file;
|
|
794
830
|
file.seek(SeekFrom::Start(iocb.pos)).map_err(to_error)?;
|
|
795
831
|
let read = file.read(buf).map_err(to_error)?;
|
|
@@ -797,7 +833,7 @@ impl FileOperations for BindFile {
|
|
|
797
833
|
Ok(read)
|
|
798
834
|
}
|
|
799
835
|
|
|
800
|
-
fn write_iter(&mut self, iocb: &mut Kiocb, buf: &[u8]) -> Result<usize,
|
|
836
|
+
fn write_iter(&mut self, iocb: &mut Kiocb, buf: &[u8]) -> Result<usize, Errno> {
|
|
801
837
|
let written = match iocb.append {
|
|
802
838
|
true => self.append(iocb, buf)?,
|
|
803
839
|
false => {
|
|
@@ -811,7 +847,7 @@ impl FileOperations for BindFile {
|
|
|
811
847
|
crate::vfs::generic_write_sync(self, iocb, written)
|
|
812
848
|
}
|
|
813
849
|
|
|
814
|
-
fn fsync(&mut self, datasync: bool) -> Result<(),
|
|
850
|
+
fn fsync(&mut self, datasync: bool) -> Result<(), Errno> {
|
|
815
851
|
match datasync {
|
|
816
852
|
true => self.file.sync_data(),
|
|
817
853
|
false => self.file.sync_all(),
|
|
@@ -823,7 +859,7 @@ impl FileOperations for BindFile {
|
|
|
823
859
|
/// Linux grows a file in one step without shortening one a peer just grew, so
|
|
824
860
|
/// elsewhere this refuses, as an append that cannot land in one step does.
|
|
825
861
|
#[cfg(target_os = "linux")]
|
|
826
|
-
fn fallocate(&mut self, offset: u64, len: u64) -> Result<(),
|
|
862
|
+
fn fallocate(&mut self, offset: u64, len: u64) -> Result<(), Errno> {
|
|
827
863
|
let flags = rustix::fs::FallocateFlags::empty();
|
|
828
864
|
rustix::fs::fallocate(&*self.file, flags, offset, len)
|
|
829
865
|
.map_err(|err| to_error(io::Error::from(err)))
|
|
@@ -853,7 +889,7 @@ mod tests {
|
|
|
853
889
|
}
|
|
854
890
|
|
|
855
891
|
fn set_modified() -> Iattr<'static> {
|
|
856
|
-
Iattr::
|
|
892
|
+
Iattr::for_times(None, Some(SetTime::At(moment())))
|
|
857
893
|
}
|
|
858
894
|
|
|
859
895
|
/// The root of `filesystem` mounted to change.
|
|
@@ -871,8 +907,8 @@ mod tests {
|
|
|
871
907
|
fn overlay_of(lower: Bind) -> Arc<Overlay> {
|
|
872
908
|
Arc::new(
|
|
873
909
|
Overlay::new(
|
|
874
|
-
vec![Filesystem::new(
|
|
875
|
-
Some(Filesystem::new(
|
|
910
|
+
vec![Filesystem::new(lower).expect("the instance must stand")],
|
|
911
|
+
Some(Filesystem::new(Tmpfs::new()).expect("the instance must stand")),
|
|
876
912
|
)
|
|
877
913
|
.unwrap_or_else(|_| panic!("the Overlay must stack")),
|
|
878
914
|
)
|
|
@@ -959,7 +995,7 @@ mod tests {
|
|
|
959
995
|
false,
|
|
960
996
|
&set_modified(),
|
|
961
997
|
),
|
|
962
|
-
Err(
|
|
998
|
+
Err(Errno::Unsupported),
|
|
963
999
|
"vfs::do_utimes_pathfollowing no link of a Bind's link must answer ENOTSUP"
|
|
964
1000
|
);
|
|
965
1001
|
}
|
|
@@ -1029,6 +1065,37 @@ mod tests {
|
|
|
1029
1065
|
(bind, format!("{path}/f"))
|
|
1030
1066
|
}
|
|
1031
1067
|
|
|
1068
|
+
// The same move behind each Bind, so the one told apart is what each
|
|
1069
|
+
// asks of the host again.
|
|
1070
|
+
// @behavior FS-207
|
|
1071
|
+
#[cfg(unix)]
|
|
1072
|
+
#[test]
|
|
1073
|
+
fn an_exclusive_bind_keeps_the_directory_it_found() {
|
|
1074
|
+
let size_after_a_move = |name: &str, exclusive: bool| {
|
|
1075
|
+
let host = HostDir::new(name);
|
|
1076
|
+
fs::create_dir(host.0.join("d")).expect("the host directory must be made");
|
|
1077
|
+
fs::write(host.0.join("d/f"), "x").expect("the host file must be written");
|
|
1078
|
+
let bind = Bind::new(&host.0)
|
|
1079
|
+
.expect("the host directory must open")
|
|
1080
|
+
.with_exclusive(exclusive);
|
|
1081
|
+
let root = kern_path(Arc::new(bind));
|
|
1082
|
+
root.vfs_lstat("d/f").expect("the file must stand");
|
|
1083
|
+
fs::rename(host.0.join("d"), host.0.join("moved")).expect("the host move must land");
|
|
1084
|
+
fs::create_dir(host.0.join("d")).expect("the host directory must be made");
|
|
1085
|
+
fs::write(host.0.join("d/f"), "xxxxx").expect("the host file must be written");
|
|
1086
|
+
root.vfs_lstat("d/f").map(|stat| stat.size)
|
|
1087
|
+
};
|
|
1088
|
+
assert_eq!(
|
|
1089
|
+
(
|
|
1090
|
+
size_after_a_move("exclusive-moved", true),
|
|
1091
|
+
size_after_a_move("plain-moved", false)
|
|
1092
|
+
),
|
|
1093
|
+
(Ok(1), Ok(5)),
|
|
1094
|
+
"a walk through d/f after the host moved another d into place must reach the d it found \
|
|
1095
|
+
through an exclusive Bind, and the new d through one that is not"
|
|
1096
|
+
);
|
|
1097
|
+
}
|
|
1098
|
+
|
|
1032
1099
|
// Counted on the Bind, as a count of the process's descriptors would see
|
|
1033
1100
|
// every other test's. Past the bound the walk still lands, so nothing a
|
|
1034
1101
|
// guest reaches depends on what was kept.
|
|
@@ -1076,15 +1143,13 @@ mod tests {
|
|
|
1076
1143
|
};
|
|
1077
1144
|
let overlay = crate::filesystem::Overlay::new(
|
|
1078
1145
|
vec![
|
|
1079
|
-
Filesystem::new(
|
|
1080
|
-
|
|
1081
|
-
Filesystem::new(Arc::new(crate::filesystem::Tmpfs::new()))
|
|
1082
|
-
.expect("the instance must stand"),
|
|
1146
|
+
Filesystem::new(crate::filesystem::Tmpfs::new()).expect("the instance must stand"),
|
|
1147
|
+
Filesystem::new(crate::filesystem::Tmpfs::new()).expect("the instance must stand"),
|
|
1083
1148
|
],
|
|
1084
1149
|
None,
|
|
1085
1150
|
)
|
|
1086
1151
|
.expect("the Overlay must stack");
|
|
1087
|
-
let refused = Some(
|
|
1152
|
+
let refused = Some(Errno::IsADirectory);
|
|
1088
1153
|
for answer in [
|
|
1089
1154
|
read(Arc::new(crate::filesystem::Tmpfs::new())),
|
|
1090
1155
|
read(Arc::new(
|
|
@@ -1110,9 +1175,9 @@ mod tests {
|
|
|
1110
1175
|
let host = HostDir::new("kept-absent");
|
|
1111
1176
|
let mount = crate::mount::Mount::new(
|
|
1112
1177
|
"/data",
|
|
1113
|
-
crate::filesystem::Filesystem::new(
|
|
1178
|
+
crate::filesystem::Filesystem::new(
|
|
1114
1179
|
Bind::new(&host.0).expect("the host directory must open"),
|
|
1115
|
-
)
|
|
1180
|
+
)
|
|
1116
1181
|
.expect("the instance must stand"),
|
|
1117
1182
|
crate::mount::Access::ReadWrite,
|
|
1118
1183
|
)
|
|
@@ -1124,7 +1189,7 @@ mod tests {
|
|
|
1124
1189
|
fs::write(host.0.join("x"), "x").expect("the host file must be written");
|
|
1125
1190
|
assert_eq!(
|
|
1126
1191
|
(before, stat()),
|
|
1127
|
-
(Some(
|
|
1192
|
+
(Some(Errno::NotFound), None),
|
|
1128
1193
|
"vfs::vfs_fstatat of a name kept as absent, once the host made a file there, must \
|
|
1129
1194
|
find the file"
|
|
1130
1195
|
);
|
|
@@ -1139,9 +1204,9 @@ mod tests {
|
|
|
1139
1204
|
let host = HostDir::new("made-at-absent");
|
|
1140
1205
|
let mount = crate::mount::Mount::new(
|
|
1141
1206
|
"/data",
|
|
1142
|
-
crate::filesystem::Filesystem::new(
|
|
1207
|
+
crate::filesystem::Filesystem::new(
|
|
1143
1208
|
Bind::new(&host.0).expect("the host directory must open"),
|
|
1144
|
-
)
|
|
1209
|
+
)
|
|
1145
1210
|
.expect("the instance must stand"),
|
|
1146
1211
|
crate::mount::Access::ReadWrite,
|
|
1147
1212
|
)
|
|
@@ -1153,7 +1218,7 @@ mod tests {
|
|
|
1153
1218
|
let after = vfs::vfs_fstatat(&cred, &root, "made", false).map(|made| made.file_type);
|
|
1154
1219
|
assert_eq!(
|
|
1155
1220
|
(before, after),
|
|
1156
|
-
(Some(
|
|
1221
|
+
(Some(Errno::NotFound), Ok(FileType::Dir)),
|
|
1157
1222
|
"vfs::filename_mkdirat at a name kept as absent must leave the next walk finding \
|
|
1158
1223
|
the directory, as d_drop leaves a dentry nothing recorded on"
|
|
1159
1224
|
);
|
|
@@ -1173,18 +1238,19 @@ mod tests {
|
|
|
1173
1238
|
fs::write(host.0.join("m/x/secret"), "s").expect("the host file must be written");
|
|
1174
1239
|
let mount = crate::mount::Mount::new(
|
|
1175
1240
|
"/data",
|
|
1176
|
-
crate::filesystem::Filesystem::new(
|
|
1241
|
+
crate::filesystem::Filesystem::new(
|
|
1177
1242
|
Bind::new(host.0.join("m")).expect("the host directory must open"),
|
|
1178
|
-
)
|
|
1243
|
+
)
|
|
1179
1244
|
.expect("the instance must stand"),
|
|
1180
1245
|
crate::mount::Access::Read,
|
|
1181
1246
|
)
|
|
1182
1247
|
.expect("/data is a guest path");
|
|
1183
1248
|
let root = VfsPath::root(mount.mnt());
|
|
1184
1249
|
let cred = crate::security::restrict_self(
|
|
1185
|
-
&crate::security::
|
|
1186
|
-
[&mount],
|
|
1187
|
-
)
|
|
1250
|
+
&crate::security::prepare_creds(&[], None),
|
|
1251
|
+
[&crate::grant::Grant::Mount(mount.clone())],
|
|
1252
|
+
)
|
|
1253
|
+
.expect("every Mount stands");
|
|
1188
1254
|
let read = OpenHow {
|
|
1189
1255
|
read: true,
|
|
1190
1256
|
..OpenHow::default()
|
|
@@ -1194,7 +1260,7 @@ mod tests {
|
|
|
1194
1260
|
fs::rename(host.0.join("m/x"), host.0.join("outside/x")).expect("the host must move it");
|
|
1195
1261
|
assert_eq!(
|
|
1196
1262
|
(before, open()),
|
|
1197
|
-
(None, Some(
|
|
1263
|
+
(None, Some(Errno::NotFound)),
|
|
1198
1264
|
"vfs::do_file_open through a name kept since the last walk, once the host moved it \
|
|
1199
1265
|
out of the Mount, must answer ENOENT"
|
|
1200
1266
|
);
|
|
@@ -1204,7 +1270,6 @@ mod tests {
|
|
|
1204
1270
|
// file onto where it went, between the judgement and the open, so only
|
|
1205
1271
|
// telling what opened from what was judged keeps the open from reaching it.
|
|
1206
1272
|
// @behavior FS-156
|
|
1207
|
-
#[cfg(unix)]
|
|
1208
1273
|
#[test]
|
|
1209
1274
|
fn an_open_reaches_only_the_entry_it_judged() {
|
|
1210
1275
|
use crate::vfs::{self, OpenHow, Path as VfsPath};
|
|
@@ -1212,8 +1277,8 @@ mod tests {
|
|
|
1212
1277
|
/// Runs what it holds once, as a Policy is asked, then allows it.
|
|
1213
1278
|
struct RunsWhenAsked(std::sync::Mutex<Option<Box<dyn FnOnce() + Send>>>);
|
|
1214
1279
|
|
|
1215
|
-
impl crate::mount::
|
|
1216
|
-
fn allows(&self,
|
|
1280
|
+
impl crate::policy::Policy<crate::mount::MountRequest<'_>> for RunsWhenAsked {
|
|
1281
|
+
fn allows(&self, _request: &crate::mount::MountRequest<'_>) -> bool {
|
|
1217
1282
|
let run = self.0.lock().expect("never poisoned").take();
|
|
1218
1283
|
if let Some(run) = run {
|
|
1219
1284
|
run();
|
|
@@ -1228,9 +1293,9 @@ mod tests {
|
|
|
1228
1293
|
}
|
|
1229
1294
|
fs::write(host.0.join("public/x"), "judged").expect("the host file must be written");
|
|
1230
1295
|
fs::write(host.0.join("archive/secret"), "refused").expect("the host file must be written");
|
|
1231
|
-
let filesystem = crate::filesystem::Filesystem::new(
|
|
1296
|
+
let filesystem = crate::filesystem::Filesystem::new(
|
|
1232
1297
|
Bind::new(&host.0).expect("the host directory must open"),
|
|
1233
|
-
)
|
|
1298
|
+
)
|
|
1234
1299
|
.expect("the instance must stand");
|
|
1235
1300
|
let writer =
|
|
1236
1301
|
crate::mount::Mount::new("/data", filesystem.clone(), crate::mount::Access::ReadWrite)
|
|
@@ -1252,16 +1317,17 @@ mod tests {
|
|
|
1252
1317
|
};
|
|
1253
1318
|
let opened = vfs::kern_path::filp_open(
|
|
1254
1319
|
&crate::security::restrict_self(
|
|
1255
|
-
&crate::security::
|
|
1256
|
-
[&mount],
|
|
1257
|
-
)
|
|
1320
|
+
&crate::security::prepare_creds(&[], None),
|
|
1321
|
+
[&crate::grant::Grant::Mount(mount.clone())],
|
|
1322
|
+
)
|
|
1323
|
+
.expect("every Mount stands"),
|
|
1258
1324
|
&VfsPath::root(mount.mnt()),
|
|
1259
1325
|
"public/x",
|
|
1260
1326
|
&read,
|
|
1261
1327
|
);
|
|
1262
1328
|
assert_eq!(
|
|
1263
1329
|
opened.err(),
|
|
1264
|
-
Some(
|
|
1330
|
+
Some(Errno::NotFound),
|
|
1265
1331
|
"vfs::do_file_open of a file another writer replaced after the Policy judged it must \
|
|
1266
1332
|
answer ENOENT rather than open what stands there now"
|
|
1267
1333
|
);
|
|
@@ -1322,9 +1388,9 @@ mod tests {
|
|
|
1322
1388
|
use crate::vfs::{self, OpenHow};
|
|
1323
1389
|
let host = HostDir::new("remade");
|
|
1324
1390
|
fs::create_dir_all(host.0.join("a")).expect("the host directory must be made");
|
|
1325
|
-
let filesystem = crate::filesystem::Filesystem::new(
|
|
1391
|
+
let filesystem = crate::filesystem::Filesystem::new(
|
|
1326
1392
|
Bind::new(&host.0).expect("the host directory must open"),
|
|
1327
|
-
)
|
|
1393
|
+
)
|
|
1328
1394
|
.expect("the instance must stand");
|
|
1329
1395
|
let mount = Mount::new("/data", filesystem, crate::mount::Access::ReadWrite)
|
|
1330
1396
|
.expect("/data is a guest path");
|
|
@@ -1357,9 +1423,9 @@ mod tests {
|
|
|
1357
1423
|
struct RefusesRefused;
|
|
1358
1424
|
|
|
1359
1425
|
#[cfg(unix)]
|
|
1360
|
-
impl crate::mount::
|
|
1361
|
-
fn allows(&self,
|
|
1362
|
-
!path.starts_with("/data/refused")
|
|
1426
|
+
impl crate::policy::Policy<crate::mount::MountRequest<'_>> for RefusesRefused {
|
|
1427
|
+
fn allows(&self, request: &crate::mount::MountRequest<'_>) -> bool {
|
|
1428
|
+
!request.path.starts_with("/data/refused")
|
|
1363
1429
|
}
|
|
1364
1430
|
}
|
|
1365
1431
|
|
|
@@ -1377,18 +1443,19 @@ mod tests {
|
|
|
1377
1443
|
fs::create_dir_all(host.0.join("a/d")).expect("the host tree must be made");
|
|
1378
1444
|
fs::create_dir_all(host.0.join("refused")).expect("the host tree must be made");
|
|
1379
1445
|
fs::write(host.0.join("a/d/secret"), "s").expect("the host file must be written");
|
|
1380
|
-
let filesystem = crate::filesystem::Filesystem::new(
|
|
1446
|
+
let filesystem = crate::filesystem::Filesystem::new(
|
|
1381
1447
|
Bind::new(&host.0).expect("the host directory must open"),
|
|
1382
|
-
)
|
|
1448
|
+
)
|
|
1383
1449
|
.expect("the instance must stand");
|
|
1384
1450
|
let mount = Mount::new("/data", filesystem, crate::mount::Access::Read)
|
|
1385
1451
|
.expect("/data is a guest path")
|
|
1386
1452
|
.with_policy(Arc::new(RefusesRefused));
|
|
1387
1453
|
let root = vfs::Path::root(mount.mnt());
|
|
1388
1454
|
let cred = crate::security::restrict_self(
|
|
1389
|
-
&crate::security::
|
|
1390
|
-
[&mount],
|
|
1391
|
-
)
|
|
1455
|
+
&crate::security::prepare_creds(&[], None),
|
|
1456
|
+
[&crate::grant::Grant::Mount(mount.clone())],
|
|
1457
|
+
)
|
|
1458
|
+
.expect("every Mount stands");
|
|
1392
1459
|
let directory = OpenHow {
|
|
1393
1460
|
read: true,
|
|
1394
1461
|
directory: true,
|
|
@@ -1405,7 +1472,7 @@ mod tests {
|
|
|
1405
1472
|
};
|
|
1406
1473
|
assert_eq!(
|
|
1407
1474
|
vfs::kern_path::filp_open(&cred, &root, "a/d/secret", &read).err(),
|
|
1408
|
-
Some(
|
|
1475
|
+
Some(Errno::NotFound),
|
|
1409
1476
|
"vfs::do_file_open beneath a Bind Mount with a Policy, through a directory the host moved \
|
|
1410
1477
|
beneath a refused path while a descriptor beneath it was held, must answer NotFound"
|
|
1411
1478
|
);
|
|
@@ -1421,8 +1488,8 @@ mod tests {
|
|
|
1421
1488
|
fs::write(host.0.join("f"), "hello").expect("the host file must be written");
|
|
1422
1489
|
let tmpfs = || [("f", "hello")].into_iter().collect::<Tmpfs>();
|
|
1423
1490
|
let overlay = Overlay::new(
|
|
1424
|
-
vec![Filesystem::new(
|
|
1425
|
-
Some(Filesystem::new(
|
|
1491
|
+
vec![Filesystem::new(tmpfs()).expect("the instance must stand")],
|
|
1492
|
+
Some(Filesystem::new(Tmpfs::new()).expect("the instance must stand")),
|
|
1426
1493
|
)
|
|
1427
1494
|
.expect("the Overlay must stack");
|
|
1428
1495
|
let root = |filesystem: Arc<dyn FileSystemType>| {
|
|
@@ -1547,15 +1614,13 @@ mod tests {
|
|
|
1547
1614
|
use crate::vfs::{self, OpenHow};
|
|
1548
1615
|
let host = HostDir::new("overlay-replaced");
|
|
1549
1616
|
fs::create_dir(host.0.join("a")).expect("the host directory must be made");
|
|
1550
|
-
let lower = Filesystem::new(
|
|
1551
|
-
|
|
1552
|
-
))
|
|
1553
|
-
.expect("the instance must stand");
|
|
1554
|
-
let upper = Filesystem::new(Arc::new(Tmpfs::new())).expect("the instance must stand");
|
|
1617
|
+
let lower = Filesystem::new(Bind::new(&host.0).expect("the host directory must open"))
|
|
1618
|
+
.expect("the instance must stand");
|
|
1619
|
+
let upper = Filesystem::new(Tmpfs::new()).expect("the instance must stand");
|
|
1555
1620
|
let overlay = Overlay::new(vec![lower], Some(upper)).expect("the Overlay must stack");
|
|
1556
1621
|
let mount = Mount::new(
|
|
1557
1622
|
"/data",
|
|
1558
|
-
Filesystem::new(
|
|
1623
|
+
Filesystem::new(overlay).expect("the instance must stand"),
|
|
1559
1624
|
Access::Read,
|
|
1560
1625
|
)
|
|
1561
1626
|
.expect("/data is a guest path");
|
|
@@ -1595,12 +1660,12 @@ mod tests {
|
|
|
1595
1660
|
fn a_directory_that_cannot_open_answers_why() {
|
|
1596
1661
|
let host = HostDir::new("gone-before-open");
|
|
1597
1662
|
fs::create_dir_all(host.0.join("a")).expect("the host directory must be made");
|
|
1598
|
-
let filesystem = crate::filesystem::Filesystem::new(
|
|
1663
|
+
let filesystem = crate::filesystem::Filesystem::new(
|
|
1599
1664
|
Bind::new(&host.0).expect("the host directory must open"),
|
|
1600
|
-
)
|
|
1665
|
+
)
|
|
1601
1666
|
.expect("the instance must stand");
|
|
1602
1667
|
let dentries = filesystem.dentries();
|
|
1603
|
-
let root = filesystem.
|
|
1668
|
+
let root = filesystem.root().expect(crate::vfs::MADE_ROOT).clone();
|
|
1604
1669
|
let dir = dentries
|
|
1605
1670
|
.alloc_parallel(&root, "a")
|
|
1606
1671
|
.expect("no other walk holds the name");
|
|
@@ -1613,7 +1678,7 @@ mod tests {
|
|
|
1613
1678
|
.open(&dir, &OpenHow::default());
|
|
1614
1679
|
assert_eq!(
|
|
1615
1680
|
answer.err(),
|
|
1616
|
-
Some(
|
|
1681
|
+
Some(Errno::NotFound),
|
|
1617
1682
|
"InodeOperations::open of a Bind's directory the host removed must answer ENOENT"
|
|
1618
1683
|
);
|
|
1619
1684
|
}
|
|
@@ -1626,12 +1691,12 @@ mod tests {
|
|
|
1626
1691
|
fn a_directory_the_host_replaced_is_not_walked_to_in_its_place() {
|
|
1627
1692
|
let host = HostDir::new("replaced-before-walk");
|
|
1628
1693
|
fs::create_dir_all(host.0.join("a")).expect("the host directory must be made");
|
|
1629
|
-
let filesystem = crate::filesystem::Filesystem::new(
|
|
1694
|
+
let filesystem = crate::filesystem::Filesystem::new(
|
|
1630
1695
|
Bind::new(&host.0).expect("the host directory must open"),
|
|
1631
|
-
)
|
|
1696
|
+
)
|
|
1632
1697
|
.expect("the instance must stand");
|
|
1633
1698
|
let dentries = filesystem.dentries();
|
|
1634
|
-
let root = filesystem.
|
|
1699
|
+
let root = filesystem.root().expect(crate::vfs::MADE_ROOT).clone();
|
|
1635
1700
|
let dir = dentries
|
|
1636
1701
|
.alloc_parallel(&root, "a")
|
|
1637
1702
|
.expect("no other walk holds the name");
|
|
@@ -1641,7 +1706,7 @@ mod tests {
|
|
|
1641
1706
|
fs::create_dir(host.0.join("a")).expect("the host must make another");
|
|
1642
1707
|
assert_eq!(
|
|
1643
1708
|
dir.getattr().err(),
|
|
1644
|
-
Some(
|
|
1709
|
+
Some(Errno::NotFound),
|
|
1645
1710
|
"InodeOperations::getattr of a Bind directory the host replaced must answer ENOENT \
|
|
1646
1711
|
rather than what stands there now"
|
|
1647
1712
|
);
|
|
@@ -1654,12 +1719,12 @@ mod tests {
|
|
|
1654
1719
|
fn a_filesystem_taking_no_rename_flag_refuses_one() {
|
|
1655
1720
|
let host = HostDir::new("rename-flag");
|
|
1656
1721
|
fs::write(host.0.join("a"), "a").expect("the host file must be written");
|
|
1657
|
-
let filesystem = crate::filesystem::Filesystem::new(
|
|
1722
|
+
let filesystem = crate::filesystem::Filesystem::new(
|
|
1658
1723
|
Bind::new(&host.0).expect("the host directory must open"),
|
|
1659
|
-
)
|
|
1724
|
+
)
|
|
1660
1725
|
.expect("the instance must stand");
|
|
1661
1726
|
let dentries = filesystem.dentries();
|
|
1662
|
-
let root = filesystem.
|
|
1727
|
+
let root = filesystem.root().expect(crate::vfs::MADE_ROOT).clone();
|
|
1663
1728
|
let dir = root.inode().expect("the root stands").ops().clone();
|
|
1664
1729
|
let at = |name| {
|
|
1665
1730
|
dentries
|
|
@@ -1674,7 +1739,7 @@ mod tests {
|
|
|
1674
1739
|
);
|
|
1675
1740
|
assert_eq!(
|
|
1676
1741
|
(answer, host.0.join("a").exists()),
|
|
1677
|
-
(Err(
|
|
1742
|
+
(Err(Errno::InvalidInput), true),
|
|
1678
1743
|
"InodeOperations::rename of a Bind asked for a flag must answer EINVAL and move \
|
|
1679
1744
|
nothing"
|
|
1680
1745
|
);
|
|
@@ -1688,12 +1753,12 @@ mod tests {
|
|
|
1688
1753
|
let host = HostDir::new("named-then-moved");
|
|
1689
1754
|
fs::create_dir_all(host.0.join("a")).expect("the host directory must be made");
|
|
1690
1755
|
fs::write(host.0.join("a/note"), "n").expect("the host file must be written");
|
|
1691
|
-
let filesystem = crate::filesystem::Filesystem::new(
|
|
1756
|
+
let filesystem = crate::filesystem::Filesystem::new(
|
|
1692
1757
|
Bind::new(&host.0).expect("the host directory must open"),
|
|
1693
|
-
)
|
|
1758
|
+
)
|
|
1694
1759
|
.expect("the instance must stand");
|
|
1695
1760
|
let dentries = filesystem.dentries();
|
|
1696
|
-
let root = filesystem.
|
|
1761
|
+
let root = filesystem.root().expect(crate::vfs::MADE_ROOT).clone();
|
|
1697
1762
|
let at = |dir: &Arc<Dentry>, name| {
|
|
1698
1763
|
dentries
|
|
1699
1764
|
.alloc_parallel(dir, name)
|
|
@@ -1706,7 +1771,7 @@ mod tests {
|
|
|
1706
1771
|
assert!(
|
|
1707
1772
|
matches!(
|
|
1708
1773
|
root.inode().expect("the root stands").ops().lookup(¬e),
|
|
1709
|
-
Ok(Lookup::Found(inode)) if inode.
|
|
1774
|
+
Ok(Lookup::Found(inode)) if inode.file_type() == FileType::RegFile
|
|
1710
1775
|
),
|
|
1711
1776
|
"a name looked up through Bind in a directory not yet opened, once its dentry moved \
|
|
1712
1777
|
with it, must be found where the dentry stands"
|
|
@@ -1748,15 +1813,52 @@ mod tests {
|
|
|
1748
1813
|
});
|
|
1749
1814
|
assert_eq!(
|
|
1750
1815
|
answered.recv_timeout(crate::sched::testing::MAX_WAIT),
|
|
1751
|
-
Ok([
|
|
1752
|
-
Some(FilesystemError::PermissionDenied),
|
|
1753
|
-
Some(FilesystemError::PermissionDenied)
|
|
1754
|
-
]),
|
|
1816
|
+
Ok([Some(Errno::PermissionDenied), Some(Errno::PermissionDenied)]),
|
|
1755
1817
|
"a FIFO and a device opened through Bind::open must be refused as permission \
|
|
1756
1818
|
denied without waiting"
|
|
1757
1819
|
);
|
|
1758
1820
|
}
|
|
1759
1821
|
|
|
1822
|
+
// The host reports each open of an entry to a watch on its directory, and
|
|
1823
|
+
// an open by O_PATH opens nothing, so a refusal it reports no open for
|
|
1824
|
+
// never acted on the entry.
|
|
1825
|
+
// @behavior FS-208
|
|
1826
|
+
#[cfg(target_os = "linux")]
|
|
1827
|
+
#[test]
|
|
1828
|
+
fn an_entry_refused_as_no_file_is_never_opened() {
|
|
1829
|
+
use std::os::fd::{AsRawFd, FromRawFd, OwnedFd};
|
|
1830
|
+
|
|
1831
|
+
let host = make_fifo_host("fifo-never-opened");
|
|
1832
|
+
let dir = Dir::open_ambient_dir(&host.0, cap_std::ambient_authority())
|
|
1833
|
+
.expect("the host directory must open");
|
|
1834
|
+
// SAFETY: inotify_init1 answers a descriptor nothing else owns, or -1.
|
|
1835
|
+
let watch = unsafe { libc::inotify_init1(libc::IN_NONBLOCK | libc::IN_CLOEXEC) };
|
|
1836
|
+
assert!(watch >= 0, "the host must give an inotify descriptor");
|
|
1837
|
+
// SAFETY: `watch` was just made and is owned here alone.
|
|
1838
|
+
let watch = unsafe { OwnedFd::from_raw_fd(watch) };
|
|
1839
|
+
let path = std::ffi::CString::new(host.0.as_os_str().as_encoded_bytes())
|
|
1840
|
+
.expect("the host path holds no NUL");
|
|
1841
|
+
// SAFETY: `path` is NUL-terminated and outlives the call.
|
|
1842
|
+
let added =
|
|
1843
|
+
unsafe { libc::inotify_add_watch(watch.as_raw_fd(), path.as_ptr(), libc::IN_OPEN) };
|
|
1844
|
+
assert!(added >= 0, "the host directory must be watched");
|
|
1845
|
+
let read = OpenHow {
|
|
1846
|
+
read: true,
|
|
1847
|
+
..OpenHow::default()
|
|
1848
|
+
};
|
|
1849
|
+
let refused = open_in(&dir, "pipe", &read, false).err();
|
|
1850
|
+
let mut events = [0u8; 256];
|
|
1851
|
+
// SAFETY: `events` is writable for its whole length.
|
|
1852
|
+
let reported =
|
|
1853
|
+
unsafe { libc::read(watch.as_raw_fd(), events.as_mut_ptr().cast(), events.len()) };
|
|
1854
|
+
assert_eq!(
|
|
1855
|
+
(refused, reported),
|
|
1856
|
+
(Some(Errno::PermissionDenied), -1),
|
|
1857
|
+
"a FIFO a Bind is asked to open must be refused as permission denied with no open \
|
|
1858
|
+
of it reported to a watch on its host directory"
|
|
1859
|
+
);
|
|
1860
|
+
}
|
|
1861
|
+
|
|
1760
1862
|
// @behavior FS-091
|
|
1761
1863
|
#[cfg(unix)]
|
|
1762
1864
|
#[test]
|
|
@@ -1818,7 +1920,7 @@ mod tests {
|
|
|
1818
1920
|
.expect("the host file must open");
|
|
1819
1921
|
let mut buf = [0; 16];
|
|
1820
1922
|
let read = file
|
|
1821
|
-
.read_iter(&mut Kiocb::
|
|
1923
|
+
.read_iter(&mut Kiocb::new(0), &mut buf)
|
|
1822
1924
|
.expect("the host file must read");
|
|
1823
1925
|
assert_eq!(
|
|
1824
1926
|
&buf[..read],
|
|
@@ -1841,7 +1943,7 @@ mod tests {
|
|
|
1841
1943
|
},
|
|
1842
1944
|
)
|
|
1843
1945
|
.expect("a new file must be created")
|
|
1844
|
-
.write_iter(&mut Kiocb::
|
|
1946
|
+
.write_iter(&mut Kiocb::new(0), b"written")
|
|
1845
1947
|
.expect("the write must land");
|
|
1846
1948
|
assert_eq!(
|
|
1847
1949
|
fs::read(host.0.join("out.txt")).expect("the host file must exist"),
|
|
@@ -1870,10 +1972,11 @@ mod tests {
|
|
|
1870
1972
|
.expect("the host file must open");
|
|
1871
1973
|
assert_eq!(
|
|
1872
1974
|
(
|
|
1873
|
-
file.write_iter(&mut Kiocb::
|
|
1975
|
+
file.write_iter(&mut Kiocb::new(0).with_append(), b"y")
|
|
1976
|
+
.err(),
|
|
1874
1977
|
fs::read(host.0.join("f")).expect("the host file must read")
|
|
1875
1978
|
),
|
|
1876
|
-
(Some(
|
|
1979
|
+
(Some(Errno::Unsupported), b"x".to_vec()),
|
|
1877
1980
|
"an append through a Bind file on Windows must be refused as unsupported and \
|
|
1878
1981
|
leave the file as it was"
|
|
1879
1982
|
);
|
|
@@ -1892,7 +1995,7 @@ mod tests {
|
|
|
1892
1995
|
assert!(
|
|
1893
1996
|
matches!(
|
|
1894
1997
|
directory.open(r"d\f", &OpenHow::default()),
|
|
1895
|
-
Err(
|
|
1998
|
+
Err(Errno::InvalidInput)
|
|
1896
1999
|
),
|
|
1897
2000
|
"a path holding a backslash opened through a Bind on Windows must be refused as \
|
|
1898
2001
|
invalid input"
|
|
@@ -1946,7 +2049,7 @@ mod tests {
|
|
|
1946
2049
|
.iter()
|
|
1947
2050
|
.all(|name| matches!(
|
|
1948
2051
|
directory.open(name, &OpenHow::default()),
|
|
1949
|
-
Err(
|
|
2052
|
+
Err(Errno::InvalidInput)
|
|
1950
2053
|
)),
|
|
1951
2054
|
"a name Windows reads as another, opened through a Bind on Windows, must be refused \
|
|
1952
2055
|
as invalid input"
|
|
@@ -1969,7 +2072,7 @@ mod tests {
|
|
|
1969
2072
|
);
|
|
1970
2073
|
assert_eq!(
|
|
1971
2074
|
created.map(drop),
|
|
1972
|
-
Err(
|
|
2075
|
+
Err(Errno::InvalidFilename),
|
|
1973
2076
|
"a name past the host's limit created through Bind::open must fail as \
|
|
1974
2077
|
InvalidFilename, not as an unnamed failure"
|
|
1975
2078
|
);
|
|
@@ -1984,12 +2087,114 @@ mod tests {
|
|
|
1984
2087
|
fn a_directory_answers_a_host_file_too_large_as_too_large() {
|
|
1985
2088
|
assert_eq!(
|
|
1986
2089
|
to_error(io::Error::from_raw_os_error(27)),
|
|
1987
|
-
|
|
2090
|
+
Errno::FileTooLarge,
|
|
1988
2091
|
"a host EFBIG through Bind's error mapping must fail as FileTooLarge, \
|
|
1989
2092
|
not as an unnamed failure"
|
|
1990
2093
|
);
|
|
1991
2094
|
}
|
|
1992
2095
|
|
|
2096
|
+
// A host out of descriptors cannot be staged without starving the test
|
|
2097
|
+
// process, so the host's own EMFILE, 24 on Linux and macOS alike, is what
|
|
2098
|
+
// the Bind must name.
|
|
2099
|
+
// @behavior FS-209
|
|
2100
|
+
#[cfg(any(target_os = "linux", target_os = "macos"))]
|
|
2101
|
+
#[test]
|
|
2102
|
+
fn a_directory_answers_a_host_out_of_descriptors_as_too_many_open_files() {
|
|
2103
|
+
assert_eq!(
|
|
2104
|
+
to_error(io::Error::from_raw_os_error(24)),
|
|
2105
|
+
Errno::TooManyOpenFiles,
|
|
2106
|
+
"a host EMFILE through a Bind must fail as too many open files, as a host \
|
|
2107
|
+
socket's does, not as an unnamed failure"
|
|
2108
|
+
);
|
|
2109
|
+
}
|
|
2110
|
+
|
|
2111
|
+
// A host refusal Rust folds into another kind is staged by its errno, as
|
|
2112
|
+
// an unlink in another user's sticky directory needs a second user.
|
|
2113
|
+
// @behavior FS-210
|
|
2114
|
+
#[cfg(unix)]
|
|
2115
|
+
#[test]
|
|
2116
|
+
fn a_directory_answers_a_host_refusal_by_the_errno_it_holds() {
|
|
2117
|
+
use rustix::io::Errno as HostErrno;
|
|
2118
|
+
let answers = [
|
|
2119
|
+
HostErrno::PERM,
|
|
2120
|
+
HostErrno::LOOP,
|
|
2121
|
+
HostErrno::BADF,
|
|
2122
|
+
HostErrno::OVERFLOW,
|
|
2123
|
+
HostErrno::NODEV,
|
|
2124
|
+
HostErrno::STALE,
|
|
2125
|
+
HostErrno::ILSEQ,
|
|
2126
|
+
HostErrno::NOTSUP,
|
|
2127
|
+
HostErrno::OPNOTSUPP,
|
|
2128
|
+
]
|
|
2129
|
+
.map(|errno| to_error(io::Error::from_raw_os_error(errno.raw_os_error())));
|
|
2130
|
+
assert_eq!(
|
|
2131
|
+
answers,
|
|
2132
|
+
[
|
|
2133
|
+
Errno::NotPermitted,
|
|
2134
|
+
Errno::FilesystemLoop,
|
|
2135
|
+
Errno::BadDescriptor,
|
|
2136
|
+
Errno::ValueTooLarge,
|
|
2137
|
+
Errno::NoSuchDevice,
|
|
2138
|
+
Errno::StaleNetworkFileHandle,
|
|
2139
|
+
Errno::IllegalSequence,
|
|
2140
|
+
Errno::Unsupported,
|
|
2141
|
+
Errno::Unsupported,
|
|
2142
|
+
],
|
|
2143
|
+
"a host EPERM, ELOOP, EBADF, EOVERFLOW, ENODEV, ESTALE, EILSEQ, ENOTSUP, or \
|
|
2144
|
+
EOPNOTSUPP through a Bind must fail under that same name, as Linux answers it, \
|
|
2145
|
+
not as permission denied or an unnamed failure"
|
|
2146
|
+
);
|
|
2147
|
+
}
|
|
2148
|
+
|
|
2149
|
+
// A quota, a file's link count, and a running program cannot be staged
|
|
2150
|
+
// on every host, so the host's own errno stands for each.
|
|
2151
|
+
// @behavior FS-212
|
|
2152
|
+
#[cfg(unix)]
|
|
2153
|
+
#[test]
|
|
2154
|
+
fn a_directory_answers_a_host_out_of_quota_links_or_a_busy_program_by_name() {
|
|
2155
|
+
use rustix::io::Errno as HostErrno;
|
|
2156
|
+
let answers = [HostErrno::DQUOT, HostErrno::MLINK, HostErrno::TXTBSY]
|
|
2157
|
+
.map(|errno| to_error(io::Error::from_raw_os_error(errno.raw_os_error())));
|
|
2158
|
+
assert_eq!(
|
|
2159
|
+
answers,
|
|
2160
|
+
[
|
|
2161
|
+
Errno::QuotaExceeded,
|
|
2162
|
+
Errno::TooManyLinks,
|
|
2163
|
+
Errno::ExecutableFileBusy,
|
|
2164
|
+
],
|
|
2165
|
+
"a host EDQUOT, EMLINK, or ETXTBSY through a Bind must fail under that same name, \
|
|
2166
|
+
as Linux answers it, not as an unnamed failure"
|
|
2167
|
+
);
|
|
2168
|
+
}
|
|
2169
|
+
|
|
2170
|
+
// Another process holding the file open is staged by its Win32 code.
|
|
2171
|
+
// @behavior FS-211
|
|
2172
|
+
#[cfg(windows)]
|
|
2173
|
+
#[test]
|
|
2174
|
+
fn a_directory_answers_a_host_file_held_without_sharing_as_permission_denied() {
|
|
2175
|
+
let held = windows_sys::Win32::Foundation::ERROR_SHARING_VIOLATION as i32;
|
|
2176
|
+
assert_eq!(
|
|
2177
|
+
to_error(io::Error::from_raw_os_error(held)),
|
|
2178
|
+
Errno::PermissionDenied,
|
|
2179
|
+
"a Windows host file another process holds without sharing must fail through a \
|
|
2180
|
+
Bind as permission denied, as wasmtime-wasi answers it, not as an unnamed failure"
|
|
2181
|
+
);
|
|
2182
|
+
}
|
|
2183
|
+
|
|
2184
|
+
// A host down reaches a Bind only on a network filesystem, so the host's
|
|
2185
|
+
// own EHOSTDOWN stands for it here.
|
|
2186
|
+
#[cfg(unix)]
|
|
2187
|
+
#[test]
|
|
2188
|
+
fn a_directory_answers_a_host_down_as_ehostdown() {
|
|
2189
|
+
let down = io::Error::from_raw_os_error(rustix::io::Errno::HOSTDOWN.raw_os_error());
|
|
2190
|
+
assert_eq!(
|
|
2191
|
+
to_error(down),
|
|
2192
|
+
Errno::HostDown,
|
|
2193
|
+
"a host EHOSTDOWN through a Bind must fail as EHOSTDOWN, as Linux hands a network \
|
|
2194
|
+
filesystem's failure on, not as the unreachable host a socket's WASI code reads"
|
|
2195
|
+
);
|
|
2196
|
+
}
|
|
2197
|
+
|
|
1993
2198
|
// A Bind's root is the directory cap-std opened for its path alone on Linux,
|
|
1994
2199
|
// so a sync of the descriptor it holds would answer EBADF only there.
|
|
1995
2200
|
// @behavior FS-171
|
|
@@ -1998,10 +2203,8 @@ mod tests {
|
|
|
1998
2203
|
let host = HostDir::new("sync-root");
|
|
1999
2204
|
let mount = crate::mount::Mount::new(
|
|
2000
2205
|
"/data",
|
|
2001
|
-
Filesystem::new(
|
|
2002
|
-
|
|
2003
|
-
))
|
|
2004
|
-
.expect("the instance must stand"),
|
|
2206
|
+
Filesystem::new(Bind::new(&host.0).expect("the host directory must open"))
|
|
2207
|
+
.expect("the instance must stand"),
|
|
2005
2208
|
crate::mount::Access::Read,
|
|
2006
2209
|
)
|
|
2007
2210
|
.expect("/data is a guest path");
|
|
@@ -2024,7 +2227,7 @@ mod tests {
|
|
|
2024
2227
|
let refused = io::Error::new(io::ErrorKind::PermissionDenied, "a path led outside");
|
|
2025
2228
|
assert_eq!(
|
|
2026
2229
|
to_error(refused),
|
|
2027
|
-
|
|
2230
|
+
Errno::NotFound,
|
|
2028
2231
|
"cap-std's refusal of a single name leading out of a Bind's directory must answer \
|
|
2029
2232
|
ENOENT, as a move carried it away"
|
|
2030
2233
|
);
|
|
@@ -2075,10 +2278,8 @@ mod tests {
|
|
|
2075
2278
|
let enforced = fs::read_dir(&dir).is_err();
|
|
2076
2279
|
let mount = crate::mount::Mount::new(
|
|
2077
2280
|
"/data",
|
|
2078
|
-
Filesystem::new(
|
|
2079
|
-
|
|
2080
|
-
))
|
|
2081
|
-
.expect("the instance must stand"),
|
|
2281
|
+
Filesystem::new(Bind::new(&host.0).expect("the host directory must open"))
|
|
2282
|
+
.expect("the instance must stand"),
|
|
2082
2283
|
crate::mount::Access::Read,
|
|
2083
2284
|
)
|
|
2084
2285
|
.expect("/data is a guest path");
|
|
@@ -2093,7 +2294,7 @@ mod tests {
|
|
|
2093
2294
|
if enforced {
|
|
2094
2295
|
assert_eq!(
|
|
2095
2296
|
answer,
|
|
2096
|
-
Some(
|
|
2297
|
+
Some(Errno::PermissionDenied),
|
|
2097
2298
|
"vfs::do_file_open to read a host directory no one may read must answer EACCES"
|
|
2098
2299
|
);
|
|
2099
2300
|
}
|
|
@@ -2139,10 +2340,8 @@ mod tests {
|
|
|
2139
2340
|
.expect("the host directory's mode must be set");
|
|
2140
2341
|
let mount = crate::mount::Mount::new(
|
|
2141
2342
|
"/data",
|
|
2142
|
-
Filesystem::new(
|
|
2143
|
-
|
|
2144
|
-
))
|
|
2145
|
-
.expect("the instance must stand"),
|
|
2343
|
+
Filesystem::new(Bind::new(&host.0).expect("the host directory must open"))
|
|
2344
|
+
.expect("the instance must stand"),
|
|
2146
2345
|
crate::mount::Access::Read,
|
|
2147
2346
|
)
|
|
2148
2347
|
.expect("/data is a guest path");
|
|
@@ -2170,10 +2369,8 @@ mod tests {
|
|
|
2170
2369
|
}
|
|
2171
2370
|
let mount = crate::mount::Mount::new(
|
|
2172
2371
|
"/data",
|
|
2173
|
-
Filesystem::new(
|
|
2174
|
-
|
|
2175
|
-
))
|
|
2176
|
-
.expect("the instance must stand"),
|
|
2372
|
+
Filesystem::new(Bind::new(&host.0).expect("the host directory must open"))
|
|
2373
|
+
.expect("the instance must stand"),
|
|
2177
2374
|
crate::mount::Access::ReadWrite,
|
|
2178
2375
|
)
|
|
2179
2376
|
.expect("/data is a guest path");
|
|
@@ -2186,7 +2383,7 @@ mod tests {
|
|
|
2186
2383
|
// Windows reports no inode, so nothing ties `A` to the stored `a` and
|
|
2187
2384
|
// the spelling is refused rather than followed.
|
|
2188
2385
|
let answered = match cfg!(windows) {
|
|
2189
|
-
true => Err(
|
|
2386
|
+
true => Err(Errno::PermissionDenied),
|
|
2190
2387
|
false => Ok(()),
|
|
2191
2388
|
};
|
|
2192
2389
|
assert_eq!(
|
|
@@ -2217,10 +2414,8 @@ mod tests {
|
|
|
2217
2414
|
let enforced = fs::read_dir(host.0.join("searched")).is_err();
|
|
2218
2415
|
let mount = crate::mount::Mount::new(
|
|
2219
2416
|
"/data",
|
|
2220
|
-
Filesystem::new(
|
|
2221
|
-
|
|
2222
|
-
))
|
|
2223
|
-
.expect("the instance must stand"),
|
|
2417
|
+
Filesystem::new(Bind::new(&host.0).expect("the host directory must open"))
|
|
2418
|
+
.expect("the instance must stand"),
|
|
2224
2419
|
crate::mount::Access::Read,
|
|
2225
2420
|
)
|
|
2226
2421
|
.expect("/data is a guest path");
|
|
@@ -2231,7 +2426,7 @@ mod tests {
|
|
|
2231
2426
|
if enforced {
|
|
2232
2427
|
assert_eq!(
|
|
2233
2428
|
found.err(),
|
|
2234
|
-
Some(
|
|
2429
|
+
Some(Errno::PermissionDenied),
|
|
2235
2430
|
"vfs::vfs_fstatat of a file beneath a host directory only searchable must \
|
|
2236
2431
|
answer EACCES, as the Bind reads the directory to spell the name"
|
|
2237
2432
|
);
|
|
@@ -2251,7 +2446,7 @@ mod tests {
|
|
|
2251
2446
|
let directory = bind_host(&host.0);
|
|
2252
2447
|
assert_eq!(
|
|
2253
2448
|
directory.iterate_dir().map(drop),
|
|
2254
|
-
Err(
|
|
2449
|
+
Err(Errno::IllegalSequence),
|
|
2255
2450
|
"a host name that is not UTF-8 listed through iterate_dir must fail as \
|
|
2256
2451
|
IllegalSequence, not as an unnamed failure"
|
|
2257
2452
|
);
|
|
@@ -2305,7 +2500,7 @@ mod tests {
|
|
|
2305
2500
|
.map(drop);
|
|
2306
2501
|
assert_eq!(
|
|
2307
2502
|
opened,
|
|
2308
|
-
Err(
|
|
2503
|
+
Err(Errno::FilesystemLoop),
|
|
2309
2504
|
"a host link opened through a Bind must be refused as a link, its target unreached"
|
|
2310
2505
|
);
|
|
2311
2506
|
}
|
|
@@ -2326,7 +2521,7 @@ mod tests {
|
|
|
2326
2521
|
};
|
|
2327
2522
|
assert_eq!(
|
|
2328
2523
|
open_in(&dir, "link", &read, false).map(drop),
|
|
2329
|
-
Err(
|
|
2524
|
+
Err(Errno::FilesystemLoop),
|
|
2330
2525
|
"a host link standing where a Bind opens a file must be refused as a link, its \
|
|
2331
2526
|
target unreached"
|
|
2332
2527
|
);
|
|
@@ -2386,7 +2581,7 @@ mod tests {
|
|
|
2386
2581
|
let directory = bind_host(&host.0);
|
|
2387
2582
|
assert_eq!(
|
|
2388
2583
|
directory.vfs_unlink("sub"),
|
|
2389
|
-
Err(
|
|
2584
|
+
Err(Errno::IsADirectory),
|
|
2390
2585
|
"a host directory beneath a Bind removed through vfs_unlink must answer EISDIR"
|
|
2391
2586
|
);
|
|
2392
2587
|
}
|
|
@@ -2416,7 +2611,7 @@ mod tests {
|
|
|
2416
2611
|
let dir = directory.open_dir("dir").expect("the directory must open");
|
|
2417
2612
|
assert_eq!(
|
|
2418
2613
|
dir.open_dir("in").map(drop),
|
|
2419
|
-
Err(
|
|
2614
|
+
Err(Errno::FilesystemLoop),
|
|
2420
2615
|
"a link to a directory opened through Bind::open_dir must be a link loop"
|
|
2421
2616
|
);
|
|
2422
2617
|
}
|
|
@@ -2430,10 +2625,7 @@ mod tests {
|
|
|
2430
2625
|
let dir = directory.open_dir("dir").expect("the directory must open");
|
|
2431
2626
|
assert_eq!(
|
|
2432
2627
|
(dir.vfs_readlink("up"), dir.vfs_readlink("sub")),
|
|
2433
|
-
(
|
|
2434
|
-
Ok("../secret".to_string()),
|
|
2435
|
-
Err(FilesystemError::InvalidInput)
|
|
2436
|
-
),
|
|
2628
|
+
(Ok("../secret".to_string()), Err(Errno::InvalidInput)),
|
|
2437
2629
|
"vfs_readlink beneath a Bind must answer where a link points as stored, and refuse \
|
|
2438
2630
|
a directory with EINVAL"
|
|
2439
2631
|
);
|
|
@@ -2509,7 +2701,7 @@ mod tests {
|
|
|
2509
2701
|
.open("log.txt", &how)
|
|
2510
2702
|
.expect("the host file must open to write");
|
|
2511
2703
|
for _ in 0..10_000 {
|
|
2512
|
-
file.write_iter(&mut Kiocb::
|
|
2704
|
+
file.write_iter(&mut Kiocb::new(0).with_append(), byte)
|
|
2513
2705
|
.expect("the append must succeed");
|
|
2514
2706
|
}
|
|
2515
2707
|
})
|